History

packet: Revert recent header parsing changes.

This reverts commits: 0f75b09c798ed00c30d7d5551b896be883bc2aeb cbd89acb9eb257ed3b2be867142583fdcf7fdc5b c483e02614551e44ced3fe6eedda8e36d3277ccc Amongst other things, it's modifies the SKB header to pull the ethernet headers off via eth_type_trans() on the output path which is bogus. It's causing serious regressions for people.

David S. Miller committed 13 years ago

Commit 09effa61 parent 16dda491 file · +24 −29Browse files

Unified · Split

net/packet/af_packet.c+24−29
@@ -88,7 +88,6 @@ · 87 unmodified lines
8888 #include <linux/virtio_net.h>
8989 #include <linux/errqueue.h>
9090 #include <linux/net_tstamp.h>
91−#include <linux/if_arp.h>
9291
9392 #ifdef CONFIG_INET
9493 #include <net/inet_common.h>
@@ -1924,7 +1923,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb, · 1829 unmodified lines
19241923 __be16 proto, unsigned char *addr, int hlen)
19251924 {
19261925 union tpacket_uhdr ph;
1927− int to_write, offset, len, tp_len, nr_frags, len_max, max_frame_len;
1926+ int to_write, offset, len, tp_len, nr_frags, len_max;
19281927 struct socket *sock = po->sk.sk_socket;
19291928 struct page *page;
19301929 void *data;
@@ -1947,6 +1946,10 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb, · 16 unmodified lines
19471946 tp_len = ph.h1->tp_len;
19481947 break;
19491948 }
1949+ if (unlikely(tp_len > size_max)) {
1950+ pr_err("packet size is too long (%d > %d)\n", tp_len, size_max);
1951+ return -EMSGSIZE;
1952+ }
19501953
19511954 skb_reserve(skb, hlen);
19521955 skb_reset_network_header(skb);
@@ -2002,25 +2005,10 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb, · 49 unmodified lines
20022005 if (unlikely(err))
20032006 return err;
20042007
2005− if (dev->type == ARPHRD_ETHER)
2006− skb->protocol = eth_type_trans(skb, dev);
2007−
20082008 data += dev->hard_header_len;
20092009 to_write -= dev->hard_header_len;
20102010 }
20112011
2012− max_frame_len = dev->mtu + dev->hard_header_len;
2013− if (skb->protocol == htons(ETH_P_8021Q))
2014− max_frame_len += VLAN_HLEN;
2015−
2016− if (size_max > max_frame_len)
2017− size_max = max_frame_len;
2018−
2019− if (unlikely(tp_len > size_max)) {
2020− pr_err("packet size is too long (%d > %d)\n", tp_len, size_max);
2021− return -EMSGSIZE;
2022− }
2023−
20242012 offset = offset_in_page(data);
20252013 len_max = PAGE_SIZE - offset;
20262014 len = ((to_write > len_max) ? len_max : to_write);
@@ -2059,7 +2047,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg) · 32 unmodified lines
20592047 struct net_device *dev;
20602048 __be16 proto;
20612049 bool need_rls_dev = false;
2062− int err;
2050+ int err, reserve = 0;
20632051 void *ph;
20642052 struct sockaddr_ll *saddr = (struct sockaddr_ll *)msg->msg_name;
20652053 int tp_len, size_max;
@@ -2092,6 +2080,8 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg) · 26 unmodified lines
20922080 if (unlikely(dev == NULL))
20932081 goto out;
20942082
2083+ reserve = dev->hard_header_len;
2084+
20952085 err = -ENETDOWN;
20962086 if (unlikely(!(dev->flags & IFF_UP)))
20972087 goto out_put;
@@ -2099,6 +2089,9 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg) · 1 unmodified line
20992089 size_max = po->tx_ring.frame_size
21002090 - (po->tp_hdrlen - sizeof(struct sockaddr_ll));
21012091
2092+ if (size_max > dev->mtu + reserve)
2093+ size_max = dev->mtu + reserve;
2094+
21022095 do {
21032096 ph = packet_current_frame(po, &po->tx_ring,
21042097 TP_STATUS_SEND_REQUEST);
@@ -2331,20 +2324,22 @@ static int packet_snd(struct socket *sock, · 226 unmodified lines
23312324
23322325 sock_tx_timestamp(sk, &skb_shinfo(skb)->tx_flags);
23332326
2334− if (dev->type == ARPHRD_ETHER) {
2335− skb->protocol = eth_type_trans(skb, dev);
2336− if (skb->protocol == htons(ETH_P_8021Q))
2337− reserve += VLAN_HLEN;
2338− } else {
2339− skb->protocol = proto;
2340− skb->dev = dev;
2341− }
2342−
23432327 if (!gso_type && (len > dev->mtu + reserve + extra_len)) {
2344− err = -EMSGSIZE;
2345− goto out_free;
2328+ /* Earlier code assumed this would be a VLAN pkt,
2329+ * double-check this now that we have the actual
2330+ * packet in hand.
2331+ */
2332+ struct ethhdr *ehdr;
2333+ skb_reset_mac_header(skb);
2334+ ehdr = eth_hdr(skb);
2335+ if (ehdr->h_proto != htons(ETH_P_8021Q)) {
2336+ err = -EMSGSIZE;
2337+ goto out_free;
2338+ }
23462339 }
23472340
2341+ skb->protocol = proto;
2342+ skb->dev = dev;
23482343 skb->priority = sk->sk_priority;
23492344 skb->mark = sk->sk_mark;
23502345