VirtualBox

Changeset 30363 in vbox


Ignore:
Timestamp:
Jun 22, 2010 11:21:22 AM (14 years ago)
Author:
vboxsync
Message:

NAT: more comments + cosmetics

Location:
trunk/src/VBox/Devices/Network/slirp
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/slirp/bootp.c

    r30016 r30363  
    200200
    201201    eh = mtod(m, struct ethhdr *);
    202     memcpy(eh->h_source, bp->bp_hwaddr, ETH_ALEN); /* XXX: if_encap just swap source with dest*/
     202    memcpy(eh->h_source, bp->bp_hwaddr, ETH_ALEN); /* XXX: if_encap just swap source with dest */
    203203
    204204    m->m_data += if_maxlinkhdr; /*reserve ether header */
     
    650650    p = dhcp_find_option(bp->bp_vend, RFC2132_MSG_TYPE);
    651651    Assert(p);
    652     if (p == NULL)
     652    if (!p)
    653653        return;
    654654    /*
     
    657657     */
    658658    if (   !pData->fUseHostResolver
    659            && (   pData->dnsLastUpdate == 0
    660                || curtime - pData->dnsLastUpdate > 60 * 1000)) /* one minute*/
     659        && (   pData->dnsLastUpdate == 0
     660            || curtime - pData->dnsLastUpdate > 60 * 1000)) /* one minute*/
    661661    {
    662662        uint8_t i = 2; /* i = 0 - tag, i == 1 - length */
     
    674674    }
    675675
    676     if ((m = m_getcl(pData, M_DONTWAIT, MT_HEADER, M_PKTHDR)) == NULL)
     676    m = m_getcl(pData, M_DONTWAIT, MT_HEADER, M_PKTHDR);
     677    if (!m)
    677678    {
    678679        LogRel(("NAT: can't alocate memory for response!\n"));
     
    684685        case DHCPDISCOVER:
    685686            fDhcpDiscover = 1;
    686             /**/
     687            /* fall through */
    687688        case DHCPINFORM:
    688689            rc = dhcp_decode_discover(pData, bp, buf, size, fDhcpDiscover, m);
     
    722723            AssertMsgFailed(("unsupported DHCP message type"));
    723724    }
    724     Assert(m);
    725     /*silently ignore*/
     725    /* silently ignore */
    726726    m_freem(pData, m);
    727727    return;
     
    729729reply:
    730730    bootp_reply(pData, m, rc, bp->bp_flags);
    731     return;
    732731}
    733732
  • trunk/src/VBox/Devices/Network/slirp/ip_icmp.c

    r30016 r30363  
    510510
    511511
    512 /*
     512/**
    513513 * Send an ICMP message in response to a situation
    514514 *
     
    526526 * ICMP fragmentation is illegal.  All machines must accept 576 bytes in one
    527527 * packet.  The maximum payload is 576-20(ip hdr)-8(icmp hdr)=548
     528 *
     529 * @note This function will free msrc!
    528530 */
    529531
     
    544546        M_ASSERTPKTHDR(msrc);
    545547
    546     if (type!=ICMP_UNREACH && type!=ICMP_TIMXCEED && type != ICMP_SOURCEQUENCH)
     548    if (   type != ICMP_UNREACH
     549        && type != ICMP_TIMXCEED
     550        && type != ICMP_SOURCEQUENCH)
    547551        goto end_error;
    548552
     
    560564    }
    561565#endif
    562     if (ip->ip_off & IP_OFFMASK && type != ICMP_SOURCEQUENCH)
     566    if (   ip->ip_off & IP_OFFMASK
     567        && type != ICMP_SOURCEQUENCH)
    563568        goto end_error;    /* Only reply to fragment 0 */
    564569
     
    598603    }
    599604    m = m_getjcl(pData, M_NOWAIT, MT_HEADER, M_PKTHDR, size);
    600 
    601     if (m == NULL)
    602         goto end_error;                    /* get mbuf */
     605    if (!m)
     606        goto end_error;
    603607
    604608    m->m_data += if_maxlinkhdr;
     
    674678end_error_free_m:
    675679    m_freem(pData, m);
     680
    676681end_error:
    677     LogRel(("NAT: error occurred while sending ICMP error message \n"));
     682    LogRel(("NAT: error occurred while sending ICMP error message\n"));
    678683}
    679684#undef ICMP_MAXDATALEN
  • trunk/src/VBox/Devices/Network/slirp/ip_output.c

    r30352 r30363  
    105105}
    106106
     107/* This function will free m0! */
    107108int
    108109ip_output0(PNATState pData, struct socket *so, struct mbuf *m0, int urg)
     
    218219            if (m->m_next != NULL)
    219220            {
    220                 /* we've receives packet in fragments */
     221                /* we've received a packet in fragments */
    221222                tmplen = m_length(m, NULL);
    222223                tmpbuf = RTMemAlloc(tmplen);
     
    269270                error = -1;
    270271                ipstat.ips_odropped++;
    271                 goto sendorfree;
     272                goto send_or_free;
    272273            }
    273274            m->m_data += if_maxlinkhdr;
     
    320321        ip->ip_sum = cksum(m, hlen);
    321322
    322 sendorfree:
     323send_or_free:
    323324        for (m = m0; m; m = m0)
    324325        {
     
    335336            }
    336337            else
    337             {
    338338                m_freem(pData, m);
    339             }
    340339        }
    341340
  • trunk/src/VBox/Devices/Network/slirp/slirp.c

    r30354 r30363  
    13801380AssertCompileSize(struct arphdr, 28);
    13811381
     1382/**
     1383 * @note This function will free m!
     1384 */
    13821385static void arp_input(PNATState pData, struct mbuf *m)
    13831386{
     
    15261529}
    15271530
    1528 /* output the IP packet to the ethernet device */
     1531/**
     1532 * Output the IP packet to the ethernet device.
     1533 *
     1534 * @note This function will free m!
     1535 */
    15291536void if_encap(PNATState pData, uint16_t eth_proto, struct mbuf *m, int flags)
    15301537{
     
    15531560    mlen = m_length(m, NULL);
    15541561    buf = RTMemAlloc(mlen);
    1555     if (buf == NULL)
     1562    if (!buf)
    15561563    {
    15571564        LogRel(("NAT: Can't alloc memory for outgoing buffer\n"));
  • trunk/src/VBox/Devices/Network/slirp/socket.c

    r30047 r30363  
    766766        if (m == NULL)
    767767            return;
     768
    768769        m->m_data += ETH_HLEN;
    769770        m->m_pkthdr.header = mtod(m, void *);
    770771        m->m_data += sizeof(struct udpiphdr);
    771772        ret = recvfrom(so->s, mtod(m, char *), n, 0,
    772                             (struct sockaddr *)&addr, &addrlen);
     773                       (struct sockaddr *)&addr, &addrlen);
    773774        /* @todo (vvl) check which flags and type should be passed */
    774775        m->m_len = ret;
  • trunk/src/VBox/Devices/Network/slirp/tftp.c

    r30016 r30363  
    181181    int nobytes;
    182182
    183     if ((m = m_getcl(pData, M_DONTWAIT, MT_HEADER, M_PKTHDR)) == NULL)
     183    m = m_getcl(pData, M_DONTWAIT, MT_HEADER, M_PKTHDR);
    184184    if (!m)
    185185        return -1;
     
    229229        return -1;
    230230
    231     if ((m = m_getcl(pData, M_DONTWAIT, MT_HEADER, M_PKTHDR)) == NULL)
     231    m = m_getcl(pData, M_DONTWAIT, MT_HEADER, M_PKTHDR);
    232232    if (!m)
    233233        return -1;
  • trunk/src/VBox/Devices/Network/slirp/udp.c

    r30352 r30363  
    298298        *ip = save_ip;
    299299        DEBUG_MISC((dfd,"NAT: UDP tx errno = %d-%s (on sent to %R[IP4])\n", errno,
    300                 strerror(errno), &ip->ip_dst));
     300                   strerror(errno), &ip->ip_dst));
    301301        icmp_error(pData, m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno));
    302302        /* in case we receive ICMP on this socket we'll aware that ICMP has been already sent to host*/
     
    328328
    329329/**
    330  * Output a UDP packet. This function will finally free the mbuf so
    331  * do NOT free any passed mbuf.
     330 * Output a UDP packet.
     331 *
     332 * @note This function will finally free m!
    332333 */
    333334int udp_output2(PNATState pData, struct socket *so, struct mbuf *m,
     
    336337{
    337338    register struct udpiphdr *ui;
    338     int error = 0;
     339    int error;
    339340
    340341    DEBUG_CALL("udp_output");
     
    385386}
    386387
     388/**
     389 * @note This function will free m!
     390 */
    387391int udp_output(PNATState pData, struct socket *so, struct mbuf *m,
    388392               struct sockaddr_in *addr)
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