* [PATCH net-next] pktgen: Fix position of ip and udp header
@ 2013-06-03 21:18 Thomas Graf
2013-06-03 21:24 ` Thomas Graf
0 siblings, 1 reply; 2+ messages in thread
From: Thomas Graf @ 2013-06-03 21:18 UTC (permalink / raw)
To: davem; +Cc: netdev, Simon Horman
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>
Assisted-by: Daniel Borkmann <dborkmann@redhat.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
---
net/core/pktgen.c | 35 ++++++++++++-----------------------
1 file changed, 12 insertions(+), 23 deletions(-)
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index d2ede89..0f1fc29b 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -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_encapsulated_proto = NULL; /* packet type ID field (or len) for SVLAN tag */
u16 queue_map;
- unsigned long tail_offset;
if (pkt_dev->nr_labels)
protocol = htons(ETH_P_MPLS_UC);
@@ -2709,20 +2708,15 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
*vlan_encapsulated_proto = htons(ETH_P_IP);
}
- tail_offset = skb_tail_offset(skb);
- if (tail_offset > 0xffff) {
- kfree_skb(skb);
- return NULL;
- }
- skb_set_network_header(skb, tail_offset);
- skb->transport_header = skb->network_header + sizeof(struct iphdr);
- skb_put(skb, sizeof(struct iphdr) + sizeof(struct udphdr));
+ skb_set_mac_header(skb, 0);
+ skb_set_network_header(skb, skb->len);
+ iph = (struct iphdr *) skb_put(skb, sizeof(struct iphdr));
+
+ skb_set_transport_header(skb, skb->len);
+ udph = (struct udphdr *) skb_put(skb, sizeof(struct udphdr));
skb_set_queue_mapping(skb, queue_map);
skb->priority = pkt_dev->skb_priority;
- iph = ip_hdr(skb);
- udph = udp_hdr(skb);
-
memcpy(eth, pkt_dev->hh, 12);
*(__be16 *) & eth[12] = protocol;
@@ -2781,7 +2775,6 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
__be16 *svlan_tci = NULL; /* Encapsulates priority and SVLAN ID */
__be16 *svlan_encapsulated_proto = NULL; /* packet type ID field (or len) for SVLAN tag */
u16 queue_map;
- unsigned long tail_offset;
if (pkt_dev->nr_labels)
protocol = htons(ETH_P_MPLS_UC);
@@ -2829,18 +2822,14 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
*vlan_encapsulated_proto = htons(ETH_P_IPV6);
}
- tail_offset = skb_tail_offset(skb);
- if (tail_offset > 0xffff) {
- kfree_skb(skb);
- return NULL;
- }
- skb_set_network_header(skb, tail_offset);
- skb->transport_header = skb->network_header + sizeof(struct ipv6hdr);
- skb_put(skb, sizeof(struct ipv6hdr) + sizeof(struct udphdr));
+ skb_set_mac_header(skb, 0);
+ skb_set_network_header(skb, skb->len);
+ iph = (struct ipv6hdr *) skb_put(skb, sizeof(struct ipv6hdr));
+
+ skb_set_transport_header(skb, skb->len);
+ udph = (struct udphdr *) skb_put(skb, sizeof(struct udphdr));
skb_set_queue_mapping(skb, queue_map);
skb->priority = pkt_dev->skb_priority;
- iph = ipv6_hdr(skb);
- udph = udp_hdr(skb);
memcpy(eth, pkt_dev->hh, 12);
*(__be16 *) ð[12] = protocol;
--
1.7.11.7
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] pktgen: Fix position of ip and udp header
2013-06-03 21:18 [PATCH net-next] pktgen: Fix position of ip and udp header Thomas Graf
@ 2013-06-03 21:24 ` Thomas Graf
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Graf @ 2013-06-03 21:24 UTC (permalink / raw)
To: davem; +Cc: netdev, Simon Horman
On 06/03/13 at 11:18pm, Thomas Graf wrote:
> 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>
> Assisted-by: Daniel Borkmann <dborkmann@redhat.com>
> Signed-off-by: Thomas Graf <tgraf@suug.ch>
FYI: ipmr and netpoll may be affected as well, the code as-is
is only correct if skb->head = skb->data. Will check those
later if nobody beats me to it.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-06-03 21:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-03 21:18 [PATCH net-next] pktgen: Fix position of ip and udp header Thomas Graf
2013-06-03 21:24 ` Thomas Graf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).