VirtualBox

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


Ignore:
Timestamp:
May 19, 2009 7:01:23 PM (16 years ago)
Author:
vboxsync
Message:

NAT: Slirp don't use ether address of guest anymore
instead it calculates ethernet address of destination
with lookup operation. Currently it's very simple looks
over send addresses via dhcp or assume destination in outer
network and gets Slirp's ethernet address.

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

Legend:

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

    r19748 r19839  
    4141            bc->allocated = 1;
    4242            paddr->s_addr = htonl(ntohl(special_addr.s_addr) | (i + START_ADDR));
     43#ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
     44            bc->addr.s_addr = paddr->s_addr;
     45#endif
    4346            return bc;
    4447        }
     
    127130}
    128131
    129 #ifndef VBOX_WITH_NAT_SERVICE
     132#ifndef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
    130133static void bootp_reply(PNATState pData, struct bootp_t *bp)
    131134#else
     
    135138    BOOTPClient *bc;
    136139    struct mbuf *m; /* XXX: @todo vasily - it'd be better to reuse this mbuf here */
    137 #ifdef VBOX_WITH_NAT_SERVICE
     140#ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
    138141    struct bootp_t *bp = mtod(m0, struct bootp_t *);
    139142    struct ethhdr *eh;
     
    189192        return;
    190193
    191 #ifndef VBOX_WITH_NAT_SERVICE
     194#ifndef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
    192195    /* XXX: this is a hack to get the client mac address */
    193196    memcpy(client_ethaddr, bp->bp_hwaddr, 6);
     
    196199    if ((m = m_get(pData)) == NULL)
    197200        return;
    198 #ifdef VBOX_WITH_NAT_SERVICE
     201#ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
    199202    eh = mtod(m, struct ethhdr *);
    200203    memcpy(eh->h_source, bp->bp_hwaddr, ETH_ALEN); /* XXX: if_encap just swap source with dest*/
     
    218221                return;
    219222            }
    220 #ifdef VBOX_WITH_NAT_SERVICE
     223#ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
    221224            memcpy(bc->macaddr, bp->bp_hwaddr, 6);
    222225#else
     
    242245
    243246    /* Address/port of the DHCP server. */
    244 #ifndef VBOX_WITH_NAT_SERVICE
     247#ifndef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
    245248    saddr.sin_addr.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_ALIAS);
    246249#else
     
    398401
    399402    if (bp->bp_op == BOOTP_REQUEST)
    400 #ifndef VBOX_WITH_NAT_SERVICE
     403#ifndef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
    401404        bootp_reply(pData, bp);
    402405#else
  • trunk/src/VBox/Devices/Network/slirp/ip_icmp.c

    r19313 r19839  
    539539    {
    540540        int new_m_size;
    541 #ifdef VBOX_WITH_NAT_SERVICE
    542         struct ethhdr *eh, *eh0;
    543         eh0 = (struct ethhdr *)msrc->m_dat;
    544         eh = (struct ethhdr *)m->m_dat;
    545         memcpy(eh->h_source, eh0->h_source, ETH_ALEN);
    546 #endif
    547         m->m_data += if_maxlinkhdr;
     541        m_adj(m, if_maxlinkhdr);
    548542        new_m_size = sizeof(struct ip) + ICMP_MINLEN + msrc->m_len + ICMP_MAXDATALEN;
    549543        if (new_m_size>m->m_size)
    550544            m_inc(m, new_m_size);
    551545    }
     546    /* XXX (vasily - r) not very safe code here add M_EXT assertion,
     547     * need replace code here with more safe constructions
     548     */
     549    Assert((m->m_flags & M_EXT) == 0 && (msrc->m_flags & M_EXT) == 0);
    552550    memcpy(m->m_data, msrc->m_data, msrc->m_len);
    553551    m->m_len = msrc->m_len;                /* copy msrc to m */
  • trunk/src/VBox/Devices/Network/slirp/ip_output.c

    r19525 r19839  
    4545#include <slirp.h>
    4646
     47#ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
     48char * rt_lookup_in_cache(PNATState pData, uint32_t dst)
     49{
     50    int i;
     51   /* temporary do for dhcp client */
     52    for(i = 0; i < NB_ADDR; i++)
     53    {
     54        if (    bootp_clients[i].allocated
     55            && bootp_clients[i].addr.s_addr == dst)
     56        {
     57            return &bootp_clients[i].macaddr[0];
     58        }
     59    }
     60    if (dst != 0)
     61    {
     62        return pData->slirp_ethaddr;
     63    }
     64   return NULL;
     65}
     66#endif
    4767
    4868/*
     
    107127        ip->ip_sum = 0;
    108128        ip->ip_sum = cksum(m, hlen);
    109 
    110 #ifdef VBOX_WITH_NAT_SERVICE
    111         {
    112             struct ethhdr *eh, *eh0;
    113             eh = (struct ethhdr *)m->m_dat;
    114             eh0 = (struct ethhdr *)m0->m_dat;
    115             memcpy(eh->h_source, eh0->h_source, ETH_ALEN);
    116         }
    117 #endif
     129#ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
     130        /* Current TCP/IP stack hasn't routing information at
     131         * all so we need to calculate destination ethernet address
     132         */
     133        {
     134            extern uint8_t zerro_ethaddr[ETH_ALEN];
     135            struct ethhdr *eh;
     136            eh = (struct ethhdr *)MBUF_HEAD(m);
     137            if (memcmp(eh->h_source, zerro_ethaddr, ETH_ALEN) == 0) {
     138                char *dst = rt_lookup_in_cache(pData, ip->ip_dst.s_addr);
     139                if (dst != NULL) {
     140                    memcpy(eh->h_source, dst, ETH_ALEN);
     141                }
     142            }
     143        }
     144#endif
     145
    118146        if_output(pData, so, m);
    119147        goto done;
     
    150178        for (off = hlen + len; off < (u_int16_t)ip->ip_len; off += len)
    151179        {
    152 #ifdef VBOX_WITH_NAT_SERVICE
     180#ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
    153181            struct ethhdr *eh0;
    154182            struct ethhdr *eh;
     
    163191            }
    164192#ifdef VBOX_WITH_NAT_SERVICE
    165             eh0 = (struct ethhdr *)m0->m_dat;
    166             eh = (struct ethhdr *)m->m_dat;
     193            eh0 = (struct ethhdr *)MBUF_HEAD(m0);
     194            eh = (struct ethhdr *)MBUF_HEAD(m);
    167195            memcpy(eh->h_source, eh0->h_source, ETH_ALEN);
    168196#endif
    169             m->m_data += if_maxlinkhdr;
     197            m_adj(m, if_maxlinkhdr);
    170198            mhip = mtod(m, struct ip *);
    171199            *mhip = *ip;
  • trunk/src/VBox/Devices/Network/slirp/slirp.c

    r19689 r19839  
    201201};
    202202
    203 static const uint8_t zerro_ethaddr[6] =
     203const uint8_t zerro_ethaddr[6] =
    204204{
    205205    0x0, 0x0, 0x0, 0x0, 0x0, 0x0
     
    660660#else
    661661    special_addr.s_addr = u32NetAddr;
     662#endif
     663#ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
     664    pData->slirp_ethaddr = &special_ethaddr;
    662665#endif
    663666    alias_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS);
     
    13991402}
    14001403
    1401 #ifndef VBOX_WITH_NAT_SERVICE
     1404#ifndef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
    14021405#define ETH_ALEN        6
    14031406#define ETH_HLEN        14
     
    14501453
    14511454    mr = m_get(pData);
    1452 #ifdef VBOX_WITH_NAT_SERVICE
     1455#ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
    14531456    reh = mtod(mr, struct ethhdr *);
    14541457    memcpy(reh->h_source, eh->h_source, ETH_ALEN); /* XXX: if_encap will swap src and dst*/
    1455     Log4(("NAT: arp:[%hhx:%hhx:%hhx:%hhx:%hhx:%hhx]->[%hhx:%hhx:%hhx:%hhx:%hhx:%hhx]\n",
    1456         reh->h_source[0], reh->h_source[1], reh->h_source[2], reh->h_source[3], reh->h_source[4], reh->h_source[5],
    1457         reh->h_dest[0], reh->h_dest[1], reh->h_dest[2], reh->h_dest[3], reh->h_dest[4], reh->h_dest[5]));
     1458    Log4(("NAT: arp:%R[ether]->%R[ether]\n",
     1459        reh->h_source, reh->h_dest));
    14581460    Log4(("NAT: arp: %R[IP4]\n", &tip));
    14591461#endif
     
    15241526        return;
    15251527    }
    1526     Log4(("NAT: in:[%hhx:%hhx:%hhx:%hhx:%hhx:%hhx]->[%hhx:%hhx:%hhx:%hhx:%hhx:%hhx]\n",
    1527         eh->h_source[0], eh->h_source[1], eh->h_source[2], eh->h_source[3], eh->h_source[4], eh->h_source[5],
    1528         eh->h_dest[0], eh->h_dest[1], eh->h_dest[2], eh->h_dest[3], eh->h_dest[4], eh->h_dest[5]));
    1529 #ifdef VBOX_WITH_NAT_SERVICE
     1528    Log4(("NAT: in:%R[ether]->%R[ether]\n", eh->h_source, eh->h_dest));
     1529#ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
    15301530    if (memcmp(eh->h_source, special_ethaddr, ETH_ALEN) == 0)
    15311531    {
     
    15981598    }
    15991599
    1600 #ifndef VBOX_WITH_NAT_SERVICE
     1600#ifndef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
    16011601    memcpy(eh->h_dest, client_ethaddr, ETH_ALEN);
    16021602    memcpy(eh->h_source, special_ethaddr, ETH_ALEN - 1);
     
    16501650void slirp_set_ethaddr(PNATState pData, const uint8_t *ethaddr)
    16511651{
    1652 #ifndef VBOX_WITH_NAT_SERVICE
     1652#ifndef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
    16531653    memcpy(client_ethaddr, ethaddr, ETH_ALEN);
    16541654#endif
  • trunk/src/VBox/Devices/Network/slirp/slirp.h

    r19313 r19839  
    358358
    359359
    360 # ifdef VBOX_WITH_NAT_SERVICE
     360# ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
    361361#  define ETH_ALEN        6
    362362#  define ETH_HLEN        14
  • trunk/src/VBox/Devices/Network/slirp/slirp_state.h

    r19313 r19839  
    4141    bool allocated;
    4242    uint8_t macaddr[6];
     43#ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
     44    struct in_addr addr;
     45#endif
    4346} BOOTPClient;
    4447
     
    126129    struct in_addr loopback_addr;
    127130    uint32_t netmask;
    128 #ifndef VBOX_WITH_NAT_SERVICE
     131#ifndef VBOX_WITHOUT_SLIRP_CLIENT_ETHER
    129132    uint8_t client_ethaddr[6];
     133#else
     134    uint8_t *slirp_ethaddr;
    130135#endif
    131136    struct ex_list *exec_list;
  • trunk/src/VBox/Devices/Network/slirp/socket.c

    r19545 r19839  
    593593             * make it look like that's where it came from, done by udp_output
    594594             */
    595 #ifdef VBOX_WITH_NAT_SERVICE
    596             {
    597                 struct ethhdr *eh0;
    598                 struct ethhdr *eh;
    599                 Assert(so->so_m);
    600                 eh0 = (struct ethhdr *)so->so_m->m_dat;
    601                 eh = (struct ethhdr *)m->m_dat;
    602 
    603                 memcpy(eh->h_source, eh0->h_source, ETH_ALEN);
    604             }
    605 #endif
    606595            udp_output(pData, so, m, &addr);
    607596            SOCKET_UNLOCK(so);
  • trunk/src/VBox/Devices/Network/slirp/tcp_input.c

    r19801 r19839  
    294294        tp = sototcpcb(so);
    295295        m = so->so_m;
    296 #ifdef VBOX_WITH_NAT_SERVICE
    297         {
    298             struct ethhdr *eh;
    299 
    300             Assert(m);
    301             eh = (struct ethhdr *)m->m_dat;
    302             memcpy(so->so_ethaddr, eh->h_source, ETH_ALEN);
    303         }
    304 #endif
     296
    305297        so->so_m = 0;
    306298        ti = so->so_ti;
     
    483475            goto dropwithreset;
    484476        }
    485 #ifdef VBOX_WITH_NAT_SERVICE
    486         Assert(m);
    487         so->so_m = m; /* save the initial packet */
    488         {
    489             struct ethhdr *eh0;
    490             eh0 = (struct ethhdr *)m->m_dat;
    491         }
    492 #endif       
    493477        SOCKET_LOCK(so);
    494478        sbreserve(&so->so_snd, tcp_sndspace);
  • trunk/src/VBox/Devices/Network/slirp/tcp_output.c

    r19318 r19839  
    378378            goto out;
    379379        }
    380 #ifdef VBOX_WITH_NAT_SERVICE
    381         {
    382             struct ethhdr *eh, *eh0;
    383             eh = (struct ethhdr *)m->m_dat;
    384             if (so->so_m)
    385             {
    386                 eh0 = (struct ethhdr *)so->so_m->m_dat;
    387                 memcpy(eh->h_source, eh0->h_source, ETH_ALEN);
    388             }
    389             else
    390             {
    391                 memcpy(eh->h_source, so->so_ethaddr, ETH_ALEN);
    392             }
    393         }
    394 #endif
    395380        m->m_data += if_maxlinkhdr;
    396381        m->m_len = hdrlen;
     
    442427            goto out;
    443428        }
    444 #ifdef VBOX_WITH_NAT_SERVICE
    445         {
    446             struct ethhdr *eh;
    447             eh = (struct ethhdr *)m->m_dat;
    448             memcpy(eh->h_source, so->so_ethaddr, ETH_ALEN);
    449         }
    450 #endif
    451429        m->m_data += if_maxlinkhdr;
    452430        m->m_len = hdrlen;
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