Skip to content

Commit f09f7ee

Browse files
Ang Way Chuangdavem330
authored andcommitted
tun: Proper handling of IPv6 header in tun driver when TUN_NO_PI is set
By default, tun.c running in TUN_TUN_DEV mode will set the protocol of packet to IPv4 if TUN_NO_PI is set. My program failed to work when I assumed that the driver will check the first nibble of packet, determine IP version and set the appropriate protocol. Signed-off-by: Ang Way Chuang <[email protected]> Acked-by: Max Krasnyansky <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fe833fc commit f09f7ee

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

drivers/net/tun.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,21 @@ static __inline__ ssize_t tun_get_user(struct tun_struct *tun, struct iovec *iv,
313313

314314
switch (tun->flags & TUN_TYPE_MASK) {
315315
case TUN_TUN_DEV:
316+
if (tun->flags & TUN_NO_PI) {
317+
switch (skb->data[0] & 0xf0) {
318+
case 0x40:
319+
pi.proto = htons(ETH_P_IP);
320+
break;
321+
case 0x60:
322+
pi.proto = htons(ETH_P_IPV6);
323+
break;
324+
default:
325+
tun->dev->stats.rx_dropped++;
326+
kfree_skb(skb);
327+
return -EINVAL;
328+
}
329+
}
330+
316331
skb_reset_mac_header(skb);
317332
skb->protocol = pi.proto;
318333
skb->dev = tun->dev;

0 commit comments

Comments
 (0)