From mboxrd@z Thu Jan 1 00:00:00 1970 From: Maxim Mikityanskiy Subject: [PATCH 4/7] net/packet: Ask driver for protocol if not provided by user Date: Mon, 14 Jan 2019 13:19:02 +0000 Message-ID: <20190114131841.1932-5-maximmi@mellanox.com> References: <20190114131841.1932-1-maximmi@mellanox.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Cc: "netdev@vger.kernel.org" , Eran Ben Elisha , Tariq Toukan , Maxim Mikityanskiy To: "David S. Miller" , Saeed Mahameed , Willem de Bruijn , Jason Wang , Eric Dumazet Return-path: Received: from mail-eopbgr00063.outbound.protection.outlook.com ([40.107.0.63]:16205 "EHLO EUR02-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726580AbfANNTF (ORCPT ); Mon, 14 Jan 2019 08:19:05 -0500 In-Reply-To: <20190114131841.1932-1-maximmi@mellanox.com> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: 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 --- net/packet/af_packet.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 8fc76e68777a..d1d89749a17a 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -1850,6 +1850,15 @@ static int packet_rcv_spkt(struct sk_buff *skb, stru= ct net_device *dev, return 0; } =20 +static void packet_parse_headers(struct sk_buff *skb, struct socket *sock) +{ + if (!skb->protocol && sock->type =3D=3D SOCK_RAW) { + skb_reset_mac_header(skb); + skb->protocol =3D dev_parse_header_protocol(skb); + } + + skb_try_probe_transport_header(skb); +} =20 /* * Output a raw packet to a device layer. This bypasses all the other @@ -1970,7 +1979,7 @@ static int packet_sendmsg_spkt(struct socket *sock, s= truct msghdr *msg, if (unlikely(extra_len =3D=3D 4)) skb->no_fcs =3D 1; =20 - skb_try_probe_transport_header(skb); + packet_parse_headers(skb, sock); =20 dev_queue_xmit(skb); rcu_read_unlock(); @@ -2519,7 +2528,7 @@ static int tpacket_fill_skb(struct packet_sock *po, s= truct sk_buff *skb, len =3D ((to_write > len_max) ? len_max : to_write); } =20 - skb_try_probe_transport_header(skb); + packet_parse_headers(skb, sock); =20 return tp_len; } @@ -2924,7 +2933,7 @@ static int packet_snd(struct socket *sock, struct msg= hdr *msg, size_t len) virtio_net_hdr_set_proto(skb, &vnet_hdr); } =20 - skb_try_probe_transport_header(skb); + packet_parse_headers(skb, sock); =20 if (unlikely(extra_len =3D=3D 4)) skb->no_fcs =3D 1; --=20 2.19.1