[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] Fix the vnet module for Xen 3.1.x.
# HG changeset patch # User kfraser@xxxxxxxxxxxxxxxxxxxxx # Date 1181210760 -3600 # Node ID 9c2322a4c348302b0ca1dcdd9c8364ec3811000f # Parent b090c290d9f8fc579be32ddd68f2bcd96e05aa03 Fix the vnet module for Xen 3.1.x. Signed-off-by: Robert Valentan <R.Valentan@xxxxxxxxxxxxx> --- tools/vnet/vnet-module/esp.c | 10 ++++---- tools/vnet/vnet-module/etherip.c | 41 +++++++++++++++------------------- tools/vnet/vnet-module/skb_util.h | 15 ++++++++++++ tools/vnet/vnet-module/varp.c | 6 ++-- tools/vnet/vnet-module/vnet_forward.c | 15 ++++++++---- 5 files changed, 52 insertions(+), 35 deletions(-) diff -r b090c290d9f8 -r 9c2322a4c348 tools/vnet/vnet-module/esp.c --- a/tools/vnet/vnet-module/esp.c Thu Jun 07 11:02:23 2007 +0100 +++ b/tools/vnet/vnet-module/esp.c Thu Jun 07 11:06:00 2007 +0100 @@ -341,12 +341,12 @@ static int esp_sa_send(SAState *sa, stru dprintf("> ETH header pull...\n"); memmove(skb->data, skb->mac.raw, ETH_HLEN); skb->mac.raw = skb->data; - __skb_pull(skb, ETH_HLEN); + skb_pull_vn(skb, ETH_HLEN); } dprintf("> IP header pull...\n"); memmove(skb->data, skb->nh.raw, ip_n); skb->nh.raw = skb->data; - __skb_pull(skb, ip_n); + skb_pull_vn(skb, ip_n); esph = (void*)skb->data; // Add spi and sequence number. esph->spi = sa->ident.spi; @@ -457,7 +457,7 @@ static int esp_sa_recv(SAState *sa, stru // Move skb->data back to ethernet header. // Do in 2 moves to ensure offsets are +ve, // since args to skb_pull/skb_push are unsigned. - __skb_pull(skb, head_n); + skb_pull_vn(skb, head_n); __skb_push(skb, skb->data - skb->mac.raw); // After this esph is invalid. esph = NULL; @@ -763,7 +763,7 @@ static int esp_protocol_recv(struct sk_b dprintf(">\n"); #ifdef DEBUG dprintf("> recv skb=\n"); - skb_print_bits(skb, 0, skb->len); + skb_print_bits("", skb, 0, skb->len); #endif ip_n = (skb->nh.iph->ihl << 2); if(skb->data == skb->mac.raw){ @@ -773,7 +773,7 @@ static int esp_protocol_recv(struct sk_b err = -EINVAL; goto exit; } - skb_pull(skb, eth_n + ip_n); + skb_pull_vn(skb, eth_n + ip_n); } addr = skb->nh.iph->daddr; err = esp_skb_header(skb, &esph); diff -r b090c290d9f8 -r 9c2322a4c348 tools/vnet/vnet-module/etherip.c --- a/tools/vnet/vnet-module/etherip.c Thu Jun 07 11:02:23 2007 +0100 +++ b/tools/vnet/vnet-module/etherip.c Thu Jun 07 11:06:00 2007 +0100 @@ -270,6 +270,7 @@ int etherip_protocol_recv(struct sk_buff u32 saddr, daddr; char vnetbuf[VNET_ID_BUF]; struct ethhdr *eth; + struct sk_buff *newskb; dprintf(">\n"); saddr = skb->nh.iph->saddr; @@ -293,7 +294,7 @@ int etherip_protocol_recv(struct sk_buff err = -EINVAL; goto exit; } - skb_pull(skb, pull_n); + skb_pull_vn(skb, pull_n); } // Assume skb->data points at etherip header. etheriph = (void*)skb->data; @@ -318,7 +319,18 @@ int etherip_protocol_recv(struct sk_buff goto exit; } // Point at the headers in the contained ethernet frame. - skb->mac.raw = skb_pull(skb, etherip_n); + skb->mac.raw = skb_pull_vn(skb, etherip_n); + + newskb = alloc_skb(skb->len, GFP_ATOMIC); + if (!newskb) { + wprintf("> alloc new sk_buff failed \n"); + goto exit; + } + newskb->mac.raw = skb_put(newskb, skb->len); + skb_copy_bits(skb, 0, newskb->data, skb->len); + kfree_skb(skb); + skb = newskb; + eth = eth_hdr(skb); // Simulate the logic from eth_type_trans() @@ -340,27 +352,12 @@ int etherip_protocol_recv(struct sk_buff // Assuming a standard Ethernet frame. // Should check for protocol? Support ETH_P_8021Q too. - skb->nh.raw = skb_pull(skb, ETH_HLEN); - -#ifdef __KERNEL__ - // Fix IP options, checksum, skb dst, netfilter state. - memset(&(IPCB(skb)->opt), 0, sizeof(struct ip_options)); - if (skb->ip_summed == CHECKSUM_HW){ - skb->ip_summed = CHECKSUM_NONE; - } - dst_release(skb->dst); - skb->dst = NULL; - nf_reset(skb); -#ifdef CONFIG_BRIDGE_NETFILTER - if(skb->nf_bridge){ - // Stop the eth header being clobbered by nf_bridge_maybe_copy_header(). - _nf_bridge_save_header(skb); - } -#endif -#endif // __KERNEL__ - - dprintf("> Unpacked srcaddr=" IPFMT " vnet=%s srcmac=" MACFMT " dstmac=" MACFMT "\n", + skb->nh.raw = skb_pull_vn(skb, ETH_HLEN); + skb->h.raw = newskb->nh.raw + sizeof(struct iphdr); + + dprintf("> Unpacked srcaddr=" IPFMT " dstaddr=" IPFMT " vnet=%s srcmac=" MACFMT " dstmac=" MACFMT "\n", NIPQUAD(skb->nh.iph->saddr), + NIPQUAD(skb->nh.iph->daddr), VnetId_ntoa(&vnet, vnetbuf), MAC6TUPLE(eth->h_source), MAC6TUPLE(eth->h_dest)); diff -r b090c290d9f8 -r 9c2322a4c348 tools/vnet/vnet-module/skb_util.h --- a/tools/vnet/vnet-module/skb_util.h Thu Jun 07 11:02:23 2007 +0100 +++ b/tools/vnet/vnet-module/skb_util.h Thu Jun 07 11:06:00 2007 +0100 @@ -66,6 +66,21 @@ static inline struct ethhdr *eth_hdr(con } #endif + +/* + * It's a copy from {kernel}/include/linux/skbuff.h func '__skb_pull' and 'skb_pull' + * to aviodthe BUG_ON when pulling into the data (getting forwarded ip-frames) + */ +static inline unsigned char *__skb_pull_vn(struct sk_buff *skb, unsigned int len) +{ + skb->len -= len; + //BUG_ON(skb->len < skb->data_len); + return skb->data += len; +} +static inline unsigned char *skb_pull_vn(struct sk_buff *skb, unsigned int len) +{ + return unlikely(len > skb->len) ? NULL : __skb_pull_vn(skb, len); +} #ifdef __KERNEL__ diff -r b090c290d9f8 -r 9c2322a4c348 tools/vnet/vnet-module/varp.c --- a/tools/vnet/vnet-module/varp.c Thu Jun 07 11:02:23 2007 +0100 +++ b/tools/vnet/vnet-module/varp.c Thu Jun 07 11:06:00 2007 +0100 @@ -1365,7 +1365,7 @@ int varp_handle_message(struct sk_buff * goto exit; } } - varph = (void*)skb_pull(skb, sizeof(struct udphdr)); + varph = (void*)skb_pull_vn(skb, sizeof(struct udphdr)); if(skb->len < sizeof(struct VnetMsgHdr)){ wprintf("> Varp msg too short: %d < %d\n", skb->len, sizeof(struct VnetMsgHdr)); goto exit; @@ -1378,11 +1378,11 @@ int varp_handle_message(struct sk_buff * } break; case VUDP_ID: // Etherip-in-udp packet. - skb_pull(skb, sizeof(struct VnetMsgHdr)); + skb_pull_vn(skb, sizeof(struct VnetMsgHdr)); err = etherip_protocol_recv(skb); goto exit; case VFWD_ID: // Forwarded. - skb_pull(skb, sizeof(struct VnetMsgHdr)); + skb_pull_vn(skb, sizeof(struct VnetMsgHdr)); err = vnet_forward_recv(skb); goto exit; default: diff -r b090c290d9f8 -r 9c2322a4c348 tools/vnet/vnet-module/vnet_forward.c --- a/tools/vnet/vnet-module/vnet_forward.c Thu Jun 07 11:02:23 2007 +0100 +++ b/tools/vnet/vnet-module/vnet_forward.c Thu Jun 07 11:06:00 2007 +0100 @@ -186,7 +186,7 @@ static int VnetPeer_forward(VnetPeer *pe printk("\nWrapped packet:\n"); print_iphdr(__FUNCTION__, skb); print_udphdr(__FUNCTION__, skb); - skb_print_bits(__FUNCTION__, skb, 0, 0 * skb->len); + skb_print_bits(__FUNCTION__, skb, 0, skb->len); #endif err = _skb_xmit(skb, saddr); @@ -304,7 +304,7 @@ int vnet_forward_recv(struct sk_buff *sk peer->rx_packets++; skb->mac.raw = NULL; skb->nh.raw = skb->data; - skb->h.raw = (void*)(skb->nh.iph + 1); + skb->h.raw = skb->data + sizeof(struct iphdr); if(!skb->nh.iph->saddr){ skb->nh.iph->saddr = addr.u.ip4.s_addr; } @@ -328,12 +328,17 @@ int vnet_forward_recv(struct sk_buff *sk // Handle (a copy of) it ourselves, because // if it is looped-back by xmit it will be ignored. - //recvskb = skb_clone(skb, GFP_ATOMIC); - recvskb = pskb_copy(skb, GFP_ATOMIC); + recvskb = alloc_skb(skb->len, GFP_ATOMIC); if(recvskb){ + recvskb->protocol = htons(ETH_P_IP); + + recvskb->nh.raw = skb_put(recvskb, skb->len); + recvskb->h.raw = recvskb->data + sizeof(struct iphdr); + skb_copy_bits(skb, 0, recvskb->data, skb->len); + // Data points at the unwrapped iphdr, but varp_handle_message() // expects it to point at the udphdr, so pull. - skb_pull(recvskb, sizeof(struct iphdr)); + skb_pull_vn(recvskb, sizeof(struct iphdr)); if(varp_handle_message(recvskb) <= 0){ kfree_skb(recvskb); } _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |