Skip to content

Commit

Permalink
af_packet: fix the tx skb protocol in raw sockets with ETH_P_ALL
Browse files Browse the repository at this point in the history
I am using "protocol ip" filters in TC to manipulate TC flower
classifiers, which are only available with "protocol ip". However,
I faced an issue that packets sent via raw sockets with ETH_P_ALL
did not match the ip filters even if they did satisfy the condition
(e.g., DHCP offer from dhcpd).

I have determined that the behavior was caused by an unexpected
value stored in skb->protocol, namely, ETH_P_ALL instead of ETH_P_IP,
when packets were sent via raw sockets with ETH_P_ALL set.

IMHO, storing ETH_P_ALL in skb->protocol is not appropriate for
packets sent via raw sockets because ETH_P_ALL is not a real ether
type used on wire, but a virtual one.

This patch fixes the tx protocol selection in cases of transmission
via raw sockets created with ETH_P_ALL so that it asks the driver to
extract protocol from the Ethernet header.

Fixes: 75c6577 ("net/packet: Ask driver for protocol if not provided by user")
Signed-off-by: Yoshiki Komachi <[email protected]>
Acked-by: Willem de Bruijn <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Yoshiki Komachi authored and davem330 committed Mar 19, 2019
1 parent a4dc6a4 commit 18bed89
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion net/packet/af_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,8 @@ static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev,

static void packet_parse_headers(struct sk_buff *skb, struct socket *sock)
{
if (!skb->protocol && sock->type == SOCK_RAW) {
if ((!skb->protocol || skb->protocol == htons(ETH_P_ALL)) &&
sock->type == SOCK_RAW) {
skb_reset_mac_header(skb);
skb->protocol = dev_parse_header_protocol(skb);
}
Expand Down

0 comments on commit 18bed89

Please sign in to comment.