VirtualBox

Changeset 11125 in vbox for trunk/src/VBox/Devices/Network


Ignore:
Timestamp:
Aug 4, 2008 9:25:49 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
34063
Message:

intnet: Optimized intnetR0TrunkIfSnoopAddr for the non-segmented case.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/SrvIntNetR0.cpp

    r11124 r11125  
    12801280        case RTNET_ETHERTYPE_IPV4:
    12811281        {
     1282            uint32_t    cbIpHdr;
     1283            uint8_t     b;
     1284
    12821285            Assert(pSG->cbTotal >= sizeof(RTNETETHERHDR) + RTNETIPV4_MIN_LEN + RTNETUDP_MIN_LEN + RTNETBOOTP_DHCP_MIN_LEN);
    1283 /** @todo optimize for the case where we can expect both the IP and UDP header to be in the first segment. */
    1284 
    1285             /* check if the protocol is UDP */
    1286             if (    intnetR0SgReadByte(pSG, sizeof(RTNETETHERHDR) + RT_OFFSETOF(RTNETIPV4, ip_p))
    1287                 !=  RTNETIPV4_PROT_UDP)
    1288                 return;
    1289 
    1290             /* get the TCP header length */
    1291             uint8_t b = intnetR0SgReadByte(pSG, sizeof(RTNETETHERHDR) + 0); /* (IPv4 first byte, a bitfield) */
    1292             uint32_t cbIpHdr = (b & 0x0f) * 4;
     1286            if (pSG->aSegs[0].cb >= sizeof(RTNETETHERHDR) + RTNETIPV4_MIN_LEN)
     1287            {
     1288                /* check if the protocol is UDP */
     1289                PCRTNETIPV4 pIpHdr = (PCRTNETIPV4)((uint8_t const *)pSG->aSegs[0].pv + sizeof(RTNETETHERHDR));
     1290                if (pIpHdr->ip_p != RTNETIPV4_PROT_UDP)
     1291                    return;
     1292
     1293                /* get the TCP header length */
     1294                cbIpHdr = pIpHdr->ip_hl * 4;
     1295            }
     1296            else
     1297            {
     1298                /* check if the protocol is UDP */
     1299                if (    intnetR0SgReadByte(pSG, sizeof(RTNETETHERHDR) + RT_OFFSETOF(RTNETIPV4, ip_p))
     1300                    !=  RTNETIPV4_PROT_UDP)
     1301                    return;
     1302
     1303                /* get the TCP header length */
     1304                b = intnetR0SgReadByte(pSG, sizeof(RTNETETHERHDR) + 0); /* (IPv4 first byte, a bitfield) */
     1305                cbIpHdr = (b & 0x0f) * 4;
     1306            }
    12931307            if (cbIpHdr < RTNETIPV4_MIN_LEN)
    12941308                return;
    12951309
    1296             /* get the lower byte of the UDP source port number. */
    1297             b = intnetR0SgReadByte(pSG, sizeof(RTNETETHERHDR) + cbIpHdr + RT_OFFSETOF(RTNETUDP, uh_sport) + 1);
    1298             if (    b != RTNETIPV4_PORT_BOOTPS
    1299                 &&  b != RTNETIPV4_PORT_BOOTPC)
    1300                 return;
    1301             b = intnetR0SgReadByte(pSG, sizeof(RTNETETHERHDR) + cbIpHdr + RT_OFFSETOF(RTNETUDP, uh_sport));
    1302             if (b)
    1303                 return;
    1304 
    1305             /* get the lower byte of the UDP destination port number. */
    1306             b = intnetR0SgReadByte(pSG, sizeof(RTNETETHERHDR) + cbIpHdr + RT_OFFSETOF(RTNETUDP, uh_dport) + 1);
    1307             if (    b != RTNETIPV4_PORT_BOOTPS
    1308                 &&  b != RTNETIPV4_PORT_BOOTPC)
    1309                 return;
    1310             b = intnetR0SgReadByte(pSG, sizeof(RTNETETHERHDR) + cbIpHdr + RT_OFFSETOF(RTNETUDP, uh_dport));
    1311             if (b)
    1312                 return;
     1310            /* compare the ports. */
     1311            if (pSG->aSegs[0].cb >= sizeof(RTNETETHERHDR) + cbIpHdr + RTNETUDP_MIN_LEN)
     1312            {
     1313                PCRTNETUDP pUdpHdr = (PCRTNETUDP)((uint8_t const *)pSG->aSegs[0].pv + sizeof(RTNETETHERHDR) + cbIpHdr);
     1314                if (    (   RT_BE2H_U16(pUdpHdr->uh_sport) != RTNETIPV4_PORT_BOOTPS
     1315                         && RT_BE2H_U16(pUdpHdr->uh_dport) != RTNETIPV4_PORT_BOOTPS)
     1316                    ||  (   RT_BE2H_U16(pUdpHdr->uh_dport) != RTNETIPV4_PORT_BOOTPC
     1317                         && RT_BE2H_U16(pUdpHdr->uh_sport) != RTNETIPV4_PORT_BOOTPC))
     1318                    return;
     1319            }
     1320            else
     1321            {
     1322                /* get the lower byte of the UDP source port number. */
     1323                b = intnetR0SgReadByte(pSG, sizeof(RTNETETHERHDR) + cbIpHdr + RT_OFFSETOF(RTNETUDP, uh_sport) + 1);
     1324                if (    b != RTNETIPV4_PORT_BOOTPS
     1325                    &&  b != RTNETIPV4_PORT_BOOTPC)
     1326                    return;
     1327                uint8_t SrcPort = b;
     1328                b = intnetR0SgReadByte(pSG, sizeof(RTNETETHERHDR) + cbIpHdr + RT_OFFSETOF(RTNETUDP, uh_sport));
     1329                if (b)
     1330                    return;
     1331
     1332                /* get the lower byte of the UDP destination port number. */
     1333                b = intnetR0SgReadByte(pSG, sizeof(RTNETETHERHDR) + cbIpHdr + RT_OFFSETOF(RTNETUDP, uh_dport) + 1);
     1334                if (    b != RTNETIPV4_PORT_BOOTPS
     1335                    &&  b != RTNETIPV4_PORT_BOOTPC)
     1336                    return;
     1337                if (b == SrcPort)
     1338                    return;
     1339                b = intnetR0SgReadByte(pSG, sizeof(RTNETETHERHDR) + cbIpHdr + RT_OFFSETOF(RTNETUDP, uh_dport));
     1340                if (b)
     1341                    return;
     1342            }
    13131343            intnetR0TrunkIfSnoopDhcp(pNetwork, pSG);
    13141344            break;
Note: See TracChangeset for help on using the changeset viewer.

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