VirtualBox

Changeset 49689 in vbox for trunk/src/VBox/NetworkServices


Ignore:
Timestamp:
Nov 28, 2013 2:34:48 AM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
90959
Message:

Create ICMP sockets for ping proxy.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp

    r49688 r49689  
    6464# include <sys/socket.h>
    6565# include <netinet/in.h>
     66# ifdef RT_OS_LINUX
     67#  include <linux/icmp.h>       /* ICMP_FILTER */
     68# endif
     69# include <netinet/icmp6.h>
    6670#endif
    6771
     
    151155    friend class NATNetworkListener;
    152156  public:
    153     VBoxNetLwipNAT();
     157    VBoxNetLwipNAT(SOCKET icmpsock4, SOCKET icmpsock6);
    154158    virtual ~VBoxNetLwipNAT();
    155159    void usage(){                /* @todo: should be implemented */ };
     
    758762
    759763
    760 VBoxNetLwipNAT::VBoxNetLwipNAT()
     764VBoxNetLwipNAT::VBoxNetLwipNAT(SOCKET icmpsock4, SOCKET icmpsock6)
    761765{
    762766    LogFlowFuncEnter();
     
    764768    m_ProxyOptions.ipv6_enabled = 0;
    765769    m_ProxyOptions.ipv6_defroute = 0;
     770    m_ProxyOptions.icmpsock4 = icmpsock4;
     771    m_ProxyOptions.icmpsock6 = icmpsock6;
    766772    m_ProxyOptions.tftp_root = NULL;
    767773    m_ProxyOptions.src4 = NULL;
     
    12081214#endif
    12091215
     1216    SOCKET icmpsock4 = INVALID_SOCKET;
     1217    SOCKET icmpsock6 = INVALID_SOCKET;
     1218#ifndef RT_OS_DARWIN
     1219    const int icmpstype = SOCK_RAW;
     1220#else
     1221    /* on OS X it's not privileged */
     1222    const int icmpstype = SOCK_DGRAM;
     1223#endif
     1224
     1225    icmpsock4 = socket(AF_INET, icmpstype, IPPROTO_ICMP);
     1226    if (icmpsock4 == INVALID_SOCKET)
     1227    {
     1228        perror("IPPROTO_ICMP");
     1229    }
     1230
     1231    if (icmpsock4 != INVALID_SOCKET)
     1232    {
     1233#ifdef ICMP_FILTER              //  Linux specific; NB: privileged!
     1234        struct icmp_filter flt = {
     1235            ~(uint32_t)(
     1236                  (1U << ICMP_ECHOREPLY)
     1237                | (1U << ICMP_DEST_UNREACH)
     1238                | (1U << ICMP_TIME_EXCEEDED)
     1239            )
     1240        };
     1241
     1242        int status = setsockopt(icmpsock4, icmpstype, ICMP_FILTER,
     1243                                &flt, sizeof(flt));
     1244        if (status < 0)
     1245        {
     1246            perror("ICMP_FILTER");
     1247        }
     1248#endif
     1249    }
     1250
     1251    icmpsock6 = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
     1252    if (icmpsock6 == INVALID_SOCKET)
     1253    {
     1254        perror("IPPROTO_ICMPV6");
     1255    }
     1256
     1257    if (icmpsock6 != INVALID_SOCKET)
     1258    {
     1259#ifdef ICMP6_FILTER             // Windows doesn't support RFC 3542 API
     1260        /*
     1261         * XXX: We do this here for now, not in pxping.c, to avoid
     1262         * name clashes between lwIP and system headers.
     1263         */
     1264        struct icmp6_filter flt;
     1265        ICMP6_FILTER_SETBLOCKALL(&flt);
     1266
     1267        ICMP6_FILTER_SETPASS(ICMP6_ECHO_REPLY, &flt);
     1268
     1269        ICMP6_FILTER_SETPASS(ICMP6_DST_UNREACH, &flt);
     1270        ICMP6_FILTER_SETPASS(ICMP6_PACKET_TOO_BIG, &flt);
     1271        ICMP6_FILTER_SETPASS(ICMP6_TIME_EXCEEDED, &flt);
     1272        ICMP6_FILTER_SETPASS(ICMP6_PARAM_PROB, &flt);
     1273
     1274        int status = setsockopt(icmpsock6, IPPROTO_ICMPV6, ICMP6_FILTER,
     1275                                &flt, sizeof(flt));
     1276        if (status < 0)
     1277        {
     1278            perror("ICMP6_FILTER");
     1279        }
     1280#endif
     1281    }
     1282
    12101283    HRESULT hrc = com::Initialize();
    12111284#ifdef VBOX_WITH_XPCOM
     
    12211294        return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to initialize COM!");
    12221295
    1223     g_pLwipNat = new VBoxNetLwipNAT();
     1296    g_pLwipNat = new VBoxNetLwipNAT(icmpsock4, icmpsock6);
    12241297
    12251298    Log2(("NAT: initialization\n"));
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette