ia64/xen-unstable

changeset 15286:9c2322a4c348

Fix the vnet module for Xen 3.1.x.
Signed-off-by: Robert Valentan <R.Valentan@solid-soft.at>
author kfraser@localhost.localdomain
date Thu Jun 07 11:06:00 2007 +0100 (2007-06-07)
parents b090c290d9f8
children d47415adf384
files tools/vnet/vnet-module/esp.c tools/vnet/vnet-module/etherip.c tools/vnet/vnet-module/skb_util.h tools/vnet/vnet-module/varp.c tools/vnet/vnet-module/vnet_forward.c
line diff
     1.1 --- a/tools/vnet/vnet-module/esp.c	Thu Jun 07 11:02:23 2007 +0100
     1.2 +++ b/tools/vnet/vnet-module/esp.c	Thu Jun 07 11:06:00 2007 +0100
     1.3 @@ -341,12 +341,12 @@ static int esp_sa_send(SAState *sa, stru
     1.4          dprintf("> ETH header pull...\n");
     1.5          memmove(skb->data, skb->mac.raw, ETH_HLEN);
     1.6          skb->mac.raw = skb->data; 
     1.7 -        __skb_pull(skb, ETH_HLEN);
     1.8 +        skb_pull_vn(skb, ETH_HLEN);
     1.9      }
    1.10      dprintf("> IP header pull...\n");
    1.11      memmove(skb->data, skb->nh.raw, ip_n);
    1.12      skb->nh.raw = skb->data;
    1.13 -    __skb_pull(skb, ip_n);
    1.14 +    skb_pull_vn(skb, ip_n);
    1.15      esph = (void*)skb->data;
    1.16      // Add spi and sequence number.
    1.17      esph->spi = sa->ident.spi;
    1.18 @@ -457,7 +457,7 @@ static int esp_sa_recv(SAState *sa, stru
    1.19      // Move skb->data back to ethernet header.
    1.20      // Do in 2 moves to ensure offsets are +ve,
    1.21      // since args to skb_pull/skb_push are unsigned.
    1.22 -    __skb_pull(skb, head_n);
    1.23 +    skb_pull_vn(skb, head_n);
    1.24      __skb_push(skb, skb->data - skb->mac.raw);
    1.25      // After this esph is invalid.
    1.26      esph = NULL;
    1.27 @@ -763,7 +763,7 @@ static int esp_protocol_recv(struct sk_b
    1.28      dprintf(">\n");
    1.29  #ifdef DEBUG
    1.30      dprintf("> recv skb=\n"); 
    1.31 -    skb_print_bits(skb, 0, skb->len);
    1.32 +    skb_print_bits("", skb, 0, skb->len);
    1.33  #endif
    1.34      ip_n = (skb->nh.iph->ihl << 2);
    1.35      if(skb->data == skb->mac.raw){
    1.36 @@ -773,7 +773,7 @@ static int esp_protocol_recv(struct sk_b
    1.37              err = -EINVAL;
    1.38              goto exit;
    1.39          }
    1.40 -        skb_pull(skb, eth_n + ip_n);
    1.41 +        skb_pull_vn(skb, eth_n + ip_n);
    1.42      }
    1.43      addr = skb->nh.iph->daddr;
    1.44      err = esp_skb_header(skb, &esph);
     2.1 --- a/tools/vnet/vnet-module/etherip.c	Thu Jun 07 11:02:23 2007 +0100
     2.2 +++ b/tools/vnet/vnet-module/etherip.c	Thu Jun 07 11:06:00 2007 +0100
     2.3 @@ -270,6 +270,7 @@ int etherip_protocol_recv(struct sk_buff
     2.4      u32 saddr, daddr;
     2.5      char vnetbuf[VNET_ID_BUF];
     2.6      struct ethhdr *eth;
     2.7 +    struct sk_buff *newskb;
     2.8  
     2.9      dprintf(">\n");
    2.10      saddr = skb->nh.iph->saddr;
    2.11 @@ -293,7 +294,7 @@ int etherip_protocol_recv(struct sk_buff
    2.12              err = -EINVAL;
    2.13              goto exit;
    2.14          }
    2.15 -        skb_pull(skb, pull_n);
    2.16 +        skb_pull_vn(skb, pull_n);
    2.17      }
    2.18      // Assume skb->data points at etherip header.
    2.19      etheriph = (void*)skb->data;
    2.20 @@ -318,7 +319,18 @@ int etherip_protocol_recv(struct sk_buff
    2.21          goto exit;
    2.22      }
    2.23      // Point at the headers in the contained ethernet frame.
    2.24 -    skb->mac.raw = skb_pull(skb, etherip_n);
    2.25 +    skb->mac.raw = skb_pull_vn(skb, etherip_n);
    2.26 +
    2.27 +    newskb = alloc_skb(skb->len, GFP_ATOMIC);
    2.28 +    if (!newskb) {
    2.29 +        wprintf("> alloc new sk_buff failed \n");
    2.30 +        goto exit;
    2.31 +    }
    2.32 +    newskb->mac.raw = skb_put(newskb, skb->len);
    2.33 +    skb_copy_bits(skb, 0, newskb->data, skb->len);
    2.34 +    kfree_skb(skb);
    2.35 +    skb = newskb;
    2.36 +
    2.37      eth = eth_hdr(skb);
    2.38  
    2.39      // Simulate the logic from eth_type_trans()
    2.40 @@ -340,27 +352,12 @@ int etherip_protocol_recv(struct sk_buff
    2.41      
    2.42      // Assuming a standard Ethernet frame.
    2.43      // Should check for protocol? Support ETH_P_8021Q too.
    2.44 -    skb->nh.raw = skb_pull(skb, ETH_HLEN);
    2.45 +    skb->nh.raw = skb_pull_vn(skb, ETH_HLEN);
    2.46 +    skb->h.raw = newskb->nh.raw + sizeof(struct iphdr);
    2.47  
    2.48 -#ifdef __KERNEL__
    2.49 -    // Fix IP options, checksum, skb dst, netfilter state.
    2.50 -    memset(&(IPCB(skb)->opt), 0, sizeof(struct ip_options));
    2.51 -    if (skb->ip_summed == CHECKSUM_HW){
    2.52 -        skb->ip_summed = CHECKSUM_NONE;
    2.53 -    }
    2.54 -    dst_release(skb->dst);
    2.55 -    skb->dst = NULL;
    2.56 -    nf_reset(skb);
    2.57 -#ifdef CONFIG_BRIDGE_NETFILTER
    2.58 -    if(skb->nf_bridge){
    2.59 -        // Stop the eth header being clobbered by nf_bridge_maybe_copy_header().
    2.60 -        _nf_bridge_save_header(skb);
    2.61 -    }
    2.62 -#endif
    2.63 -#endif // __KERNEL__
    2.64 -
    2.65 -    dprintf("> Unpacked srcaddr=" IPFMT " vnet=%s srcmac=" MACFMT " dstmac=" MACFMT "\n",
    2.66 +    dprintf("> Unpacked srcaddr=" IPFMT " dstaddr=" IPFMT " vnet=%s srcmac=" MACFMT " dstmac=" MACFMT "\n",
    2.67              NIPQUAD(skb->nh.iph->saddr),
    2.68 +            NIPQUAD(skb->nh.iph->daddr),
    2.69              VnetId_ntoa(&vnet, vnetbuf),
    2.70              MAC6TUPLE(eth->h_source),
    2.71              MAC6TUPLE(eth->h_dest));
     3.1 --- a/tools/vnet/vnet-module/skb_util.h	Thu Jun 07 11:02:23 2007 +0100
     3.2 +++ b/tools/vnet/vnet-module/skb_util.h	Thu Jun 07 11:06:00 2007 +0100
     3.3 @@ -67,6 +67,21 @@ static inline struct ethhdr *eth_hdr(con
     3.4  
     3.5  #endif
     3.6  
     3.7 +/*
     3.8 + * It's a copy from {kernel}/include/linux/skbuff.h func '__skb_pull' and 'skb_pull'
     3.9 + * to aviodthe BUG_ON when pulling into the data (getting forwarded ip-frames)
    3.10 + */
    3.11 +static inline unsigned char *__skb_pull_vn(struct sk_buff *skb, unsigned int len)
    3.12 +{
    3.13 +        skb->len -= len;
    3.14 +        //BUG_ON(skb->len < skb->data_len);
    3.15 +        return skb->data += len;
    3.16 +}
    3.17 +static inline unsigned char *skb_pull_vn(struct sk_buff *skb, unsigned int len)
    3.18 +{
    3.19 +        return unlikely(len > skb->len) ? NULL : __skb_pull_vn(skb, len);
    3.20 +}
    3.21 +
    3.22  
    3.23  #ifdef __KERNEL__
    3.24  
     4.1 --- a/tools/vnet/vnet-module/varp.c	Thu Jun 07 11:02:23 2007 +0100
     4.2 +++ b/tools/vnet/vnet-module/varp.c	Thu Jun 07 11:06:00 2007 +0100
     4.3 @@ -1365,7 +1365,7 @@ int varp_handle_message(struct sk_buff *
     4.4              goto exit;
     4.5          }
     4.6      }
     4.7 -    varph = (void*)skb_pull(skb, sizeof(struct udphdr));
     4.8 +    varph = (void*)skb_pull_vn(skb, sizeof(struct udphdr));
     4.9      if(skb->len < sizeof(struct VnetMsgHdr)){
    4.10          wprintf("> Varp msg too short: %d < %d\n", skb->len, sizeof(struct VnetMsgHdr));
    4.11          goto exit;
    4.12 @@ -1378,11 +1378,11 @@ int varp_handle_message(struct sk_buff *
    4.13          }
    4.14          break;
    4.15      case VUDP_ID: // Etherip-in-udp packet.
    4.16 -        skb_pull(skb, sizeof(struct VnetMsgHdr));
    4.17 +        skb_pull_vn(skb, sizeof(struct VnetMsgHdr));
    4.18          err = etherip_protocol_recv(skb);
    4.19          goto exit;
    4.20      case VFWD_ID: // Forwarded.
    4.21 -        skb_pull(skb, sizeof(struct VnetMsgHdr));
    4.22 +        skb_pull_vn(skb, sizeof(struct VnetMsgHdr));
    4.23          err = vnet_forward_recv(skb);
    4.24          goto exit;
    4.25      default:
     5.1 --- a/tools/vnet/vnet-module/vnet_forward.c	Thu Jun 07 11:02:23 2007 +0100
     5.2 +++ b/tools/vnet/vnet-module/vnet_forward.c	Thu Jun 07 11:06:00 2007 +0100
     5.3 @@ -186,7 +186,7 @@ static int VnetPeer_forward(VnetPeer *pe
     5.4      printk("\nWrapped packet:\n");
     5.5      print_iphdr(__FUNCTION__, skb);
     5.6      print_udphdr(__FUNCTION__, skb);
     5.7 -    skb_print_bits(__FUNCTION__, skb, 0, 0 * skb->len);
     5.8 +    skb_print_bits(__FUNCTION__, skb, 0, skb->len);
     5.9  #endif
    5.10  
    5.11      err = _skb_xmit(skb, saddr);
    5.12 @@ -304,7 +304,7 @@ int vnet_forward_recv(struct sk_buff *sk
    5.13      peer->rx_packets++;
    5.14      skb->mac.raw = NULL;
    5.15      skb->nh.raw = skb->data;
    5.16 -    skb->h.raw = (void*)(skb->nh.iph + 1);
    5.17 +    skb->h.raw = skb->data + sizeof(struct iphdr);
    5.18      if(!skb->nh.iph->saddr){
    5.19          skb->nh.iph->saddr = addr.u.ip4.s_addr;
    5.20      }
    5.21 @@ -328,12 +328,17 @@ int vnet_forward_recv(struct sk_buff *sk
    5.22  
    5.23      // Handle (a copy of) it ourselves, because
    5.24      // if it is looped-back by xmit it will be ignored.
    5.25 -    //recvskb = skb_clone(skb, GFP_ATOMIC);
    5.26 -    recvskb = pskb_copy(skb, GFP_ATOMIC);
    5.27 +    recvskb = alloc_skb(skb->len, GFP_ATOMIC);
    5.28      if(recvskb){
    5.29 +        recvskb->protocol = htons(ETH_P_IP);
    5.30 +
    5.31 +        recvskb->nh.raw = skb_put(recvskb, skb->len);
    5.32 +        recvskb->h.raw = recvskb->data + sizeof(struct iphdr); 
    5.33 +        skb_copy_bits(skb, 0, recvskb->data, skb->len);
    5.34 +        
    5.35          // Data points at the unwrapped iphdr, but varp_handle_message()
    5.36          // expects it to point at the udphdr, so pull.
    5.37 -        skb_pull(recvskb, sizeof(struct iphdr));
    5.38 +        skb_pull_vn(recvskb, sizeof(struct iphdr));
    5.39          if(varp_handle_message(recvskb) <= 0){
    5.40              kfree_skb(recvskb);
    5.41          }