summaryrefslogtreecommitdiffstats
path: root/net/packet
diff options
context:
space:
mode:
authorMaxim Mikityanskiy <maximmi@mellanox.com>2019-02-21 07:40:01 -0500
committerDavid S. Miller <davem@davemloft.net>2019-02-22 15:55:31 -0500
commit75c65772c3d18447d62d3aca5f91b06c16cc25e4 (patch)
tree490828ee061c92fe9fccd578de540b5983a23ed3 /net/packet
parentace53b2e2945c83850964070af158be01d564e67 (diff)
net/packet: Ask driver for protocol if not provided by user
If a socket was created with socket(AF_PACKET, SOCK_RAW, 0), the protocol number is unavailable. Try to ask the driver to extract it from the L2 header in order for skb_try_probe_transport_header to succeed. Signed-off-by: Maxim Mikityanskiy <maximmi@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/packet')
-rw-r--r--net/packet/af_packet.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 6afd6369d19e..cac4c1a3f807 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1850,6 +1850,15 @@ oom:
1850 return 0; 1850 return 0;
1851} 1851}
1852 1852
1853static void packet_parse_headers(struct sk_buff *skb, struct socket *sock)
1854{
1855 if (!skb->protocol && sock->type == SOCK_RAW) {
1856 skb_reset_mac_header(skb);
1857 skb->protocol = dev_parse_header_protocol(skb);
1858 }
1859
1860 skb_probe_transport_header(skb);
1861}
1853 1862
1854/* 1863/*
1855 * Output a raw packet to a device layer. This bypasses all the other 1864 * Output a raw packet to a device layer. This bypasses all the other
@@ -1970,7 +1979,7 @@ retry:
1970 if (unlikely(extra_len == 4)) 1979 if (unlikely(extra_len == 4))
1971 skb->no_fcs = 1; 1980 skb->no_fcs = 1;
1972 1981
1973 skb_probe_transport_header(skb); 1982 packet_parse_headers(skb, sock);
1974 1983
1975 dev_queue_xmit(skb); 1984 dev_queue_xmit(skb);
1976 rcu_read_unlock(); 1985 rcu_read_unlock();
@@ -2519,7 +2528,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
2519 len = ((to_write > len_max) ? len_max : to_write); 2528 len = ((to_write > len_max) ? len_max : to_write);
2520 } 2529 }
2521 2530
2522 skb_probe_transport_header(skb); 2531 packet_parse_headers(skb, sock);
2523 2532
2524 return tp_len; 2533 return tp_len;
2525} 2534}
@@ -2925,7 +2934,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
2925 virtio_net_hdr_set_proto(skb, &vnet_hdr); 2934 virtio_net_hdr_set_proto(skb, &vnet_hdr);
2926 } 2935 }
2927 2936
2928 skb_probe_transport_header(skb); 2937 packet_parse_headers(skb, sock);
2929 2938
2930 if (unlikely(extra_len == 4)) 2939 if (unlikely(extra_len == 4))
2931 skb->no_fcs = 1; 2940 skb->no_fcs = 1;