Commit 525cebed authored by Thomas Graf's avatar Thomas Graf Committed by David S. Miller

pktgen: Fix position of ip and udp header

skb_set_network_header() expects an offset based on the data pointer
whereas skb_tail_offset() also includes the headroom. This resulted
in the ip header being written in a wrong location.

Use return values of skb_put() directly and rely on skb->len to
set mac, network, and transport header.

Cc: Simon Horman <horms@verge.net.au>
Cc: Daniel Borkmann <dborkmann@redhat.com>
Assisted-by: default avatarDaniel Borkmann <dborkmann@redhat.com>
Signed-off-by: default avatarThomas Graf <tgraf@suug.ch>
Acked-by: default avatarDaniel Borkmann <dborkmann@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 10e179e3
...@@ -2642,7 +2642,6 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev, ...@@ -2642,7 +2642,6 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
__be16 *svlan_tci = NULL; /* Encapsulates priority and SVLAN ID */ __be16 *svlan_tci = NULL; /* Encapsulates priority and SVLAN ID */
__be16 *svlan_encapsulated_proto = NULL; /* packet type ID field (or len) for SVLAN tag */ __be16 *svlan_encapsulated_proto = NULL; /* packet type ID field (or len) for SVLAN tag */
u16 queue_map; u16 queue_map;
unsigned long tail_offset;
if (pkt_dev->nr_labels) if (pkt_dev->nr_labels)
protocol = htons(ETH_P_MPLS_UC); protocol = htons(ETH_P_MPLS_UC);
...@@ -2709,20 +2708,15 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev, ...@@ -2709,20 +2708,15 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
*vlan_encapsulated_proto = htons(ETH_P_IP); *vlan_encapsulated_proto = htons(ETH_P_IP);
} }
tail_offset = skb_tail_offset(skb); skb_set_mac_header(skb, 0);
if (tail_offset > 0xffff) { skb_set_network_header(skb, skb->len);
kfree_skb(skb); iph = (struct iphdr *) skb_put(skb, sizeof(struct iphdr));
return NULL;
} skb_set_transport_header(skb, skb->len);
skb_set_network_header(skb, tail_offset); udph = (struct udphdr *) skb_put(skb, sizeof(struct udphdr));
skb->transport_header = skb->network_header + sizeof(struct iphdr);
skb_put(skb, sizeof(struct iphdr) + sizeof(struct udphdr));
skb_set_queue_mapping(skb, queue_map); skb_set_queue_mapping(skb, queue_map);
skb->priority = pkt_dev->skb_priority; skb->priority = pkt_dev->skb_priority;
iph = ip_hdr(skb);
udph = udp_hdr(skb);
memcpy(eth, pkt_dev->hh, 12); memcpy(eth, pkt_dev->hh, 12);
*(__be16 *) & eth[12] = protocol; *(__be16 *) & eth[12] = protocol;
...@@ -2752,8 +2746,6 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev, ...@@ -2752,8 +2746,6 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
iph->check = 0; iph->check = 0;
iph->check = ip_fast_csum((void *)iph, iph->ihl); iph->check = ip_fast_csum((void *)iph, iph->ihl);
skb->protocol = protocol; skb->protocol = protocol;
skb->mac_header = (skb->network_header - ETH_HLEN -
pkt_dev->pkt_overhead);
skb->dev = odev; skb->dev = odev;
skb->pkt_type = PACKET_HOST; skb->pkt_type = PACKET_HOST;
pktgen_finalize_skb(pkt_dev, skb, datalen); pktgen_finalize_skb(pkt_dev, skb, datalen);
...@@ -2781,7 +2773,6 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev, ...@@ -2781,7 +2773,6 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
__be16 *svlan_tci = NULL; /* Encapsulates priority and SVLAN ID */ __be16 *svlan_tci = NULL; /* Encapsulates priority and SVLAN ID */
__be16 *svlan_encapsulated_proto = NULL; /* packet type ID field (or len) for SVLAN tag */ __be16 *svlan_encapsulated_proto = NULL; /* packet type ID field (or len) for SVLAN tag */
u16 queue_map; u16 queue_map;
unsigned long tail_offset;
if (pkt_dev->nr_labels) if (pkt_dev->nr_labels)
protocol = htons(ETH_P_MPLS_UC); protocol = htons(ETH_P_MPLS_UC);
...@@ -2829,18 +2820,14 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev, ...@@ -2829,18 +2820,14 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
*vlan_encapsulated_proto = htons(ETH_P_IPV6); *vlan_encapsulated_proto = htons(ETH_P_IPV6);
} }
tail_offset = skb_tail_offset(skb); skb_set_mac_header(skb, 0);
if (tail_offset > 0xffff) { skb_set_network_header(skb, skb->len);
kfree_skb(skb); iph = (struct ipv6hdr *) skb_put(skb, sizeof(struct ipv6hdr));
return NULL;
} skb_set_transport_header(skb, skb->len);
skb_set_network_header(skb, tail_offset); udph = (struct udphdr *) skb_put(skb, sizeof(struct udphdr));
skb->transport_header = skb->network_header + sizeof(struct ipv6hdr);
skb_put(skb, sizeof(struct ipv6hdr) + sizeof(struct udphdr));
skb_set_queue_mapping(skb, queue_map); skb_set_queue_mapping(skb, queue_map);
skb->priority = pkt_dev->skb_priority; skb->priority = pkt_dev->skb_priority;
iph = ipv6_hdr(skb);
udph = udp_hdr(skb);
memcpy(eth, pkt_dev->hh, 12); memcpy(eth, pkt_dev->hh, 12);
*(__be16 *) &eth[12] = protocol; *(__be16 *) &eth[12] = protocol;
...@@ -2875,8 +2862,6 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev, ...@@ -2875,8 +2862,6 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
iph->daddr = pkt_dev->cur_in6_daddr; iph->daddr = pkt_dev->cur_in6_daddr;
iph->saddr = pkt_dev->cur_in6_saddr; iph->saddr = pkt_dev->cur_in6_saddr;
skb->mac_header = (skb->network_header - ETH_HLEN -
pkt_dev->pkt_overhead);
skb->protocol = protocol; skb->protocol = protocol;
skb->dev = odev; skb->dev = odev;
skb->pkt_type = PACKET_HOST; skb->pkt_type = PACKET_HOST;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment