Skip to content

Commit dfed913

Browse files
liuhangbinPaolo Abeni
authored andcommitted
net/af_packet: add VLAN support for AF_PACKET SOCK_RAW GSO
Currently, the kernel drops GSO VLAN tagged packet if it's created with socket(AF_PACKET, SOCK_RAW, 0) plus virtio_net_hdr. The reason is AF_PACKET doesn't adjust the skb network header if there is a VLAN tag. Then after virtio_net_hdr_set_proto() called, the skb->protocol will be set to ETH_P_IP/IPv6. And in later inet/ipv6_gso_segment() the skb is dropped as network header position is invalid. Let's handle VLAN packets by adjusting network header position in packet_parse_headers(). The adjustment is safe and does not affect the later xmit as tap device also did that. In packet_snd(), packet_parse_headers() need to be moved before calling virtio_net_hdr_set_proto(), so we can set correct skb->protocol and network header first. There is no need to update tpacket_snd() as it calls packet_parse_headers() in tpacket_fill_skb(), which is already before calling virtio_net_hdr_* functions. skb->no_fcs setting is also moved upper to make all skb settings together and keep consistency with function packet_sendmsg_spkt(). Signed-off-by: Hangbin Liu <[email protected]> Acked-by: Willem de Bruijn <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent de6dd62 commit dfed913

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

net/packet/af_packet.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,12 +1924,20 @@ static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev,
19241924

19251925
static void packet_parse_headers(struct sk_buff *skb, struct socket *sock)
19261926
{
1927+
int depth;
1928+
19271929
if ((!skb->protocol || skb->protocol == htons(ETH_P_ALL)) &&
19281930
sock->type == SOCK_RAW) {
19291931
skb_reset_mac_header(skb);
19301932
skb->protocol = dev_parse_header_protocol(skb);
19311933
}
19321934

1935+
/* Move network header to the right position for VLAN tagged packets */
1936+
if (likely(skb->dev->type == ARPHRD_ETHER) &&
1937+
eth_type_vlan(skb->protocol) &&
1938+
__vlan_get_protocol(skb, skb->protocol, &depth) != 0)
1939+
skb_set_network_header(skb, depth);
1940+
19331941
skb_probe_transport_header(skb);
19341942
}
19351943

@@ -3047,6 +3055,11 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
30473055
skb->mark = sockc.mark;
30483056
skb->tstamp = sockc.transmit_time;
30493057

3058+
if (unlikely(extra_len == 4))
3059+
skb->no_fcs = 1;
3060+
3061+
packet_parse_headers(skb, sock);
3062+
30503063
if (has_vnet_hdr) {
30513064
err = virtio_net_hdr_to_skb(skb, &vnet_hdr, vio_le());
30523065
if (err)
@@ -3055,11 +3068,6 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
30553068
virtio_net_hdr_set_proto(skb, &vnet_hdr);
30563069
}
30573070

3058-
packet_parse_headers(skb, sock);
3059-
3060-
if (unlikely(extra_len == 4))
3061-
skb->no_fcs = 1;
3062-
30633071
err = po->xmit(skb);
30643072
if (unlikely(err != 0)) {
30653073
if (err > 0)

0 commit comments

Comments
 (0)