| @@ -1058,6 +1058,7 @@ static unsigned int run_ebpf_filter(struct tun_struct *tun, · 1057 unmodified lines |
| 1058 | static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev) | 1058 | static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev) |
| 1059 | { | 1059 | { |
| 1060 | struct tun_struct *tun = netdev_priv(dev); | 1060 | struct tun_struct *tun = netdev_priv(dev); |
| | 1061 | enum skb_drop_reason drop_reason; |
| 1061 | int txq = skb->queue_mapping; | 1062 | int txq = skb->queue_mapping; |
| 1062 | struct netdev_queue *queue; | 1063 | struct netdev_queue *queue; |
| 1063 | struct tun_file *tfile; | 1064 | struct tun_file *tfile; |
| @@ -1067,8 +1068,10 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev) · 3 unmodified lines |
| 1067 | tfile = rcu_dereference(tun->tfiles[txq]); | 1068 | tfile = rcu_dereference(tun->tfiles[txq]); |
| 1068 | | 1069 | |
| 1069 | /* Drop packet if interface is not attached */ | 1070 | /* Drop packet if interface is not attached */ |
| 1070 | if (!tfile) | 1071 | if (!tfile) { |
| | 1072 | drop_reason = SKB_DROP_REASON_DEV_READY; |
| 1071 | goto drop; | 1073 | goto drop; |
| | 1074 | } |
| 1072 | | 1075 | |
| 1073 | if (!rcu_dereference(tun->steering_prog)) | 1076 | if (!rcu_dereference(tun->steering_prog)) |
| 1074 | tun_automq_xmit(tun, skb); | 1077 | tun_automq_xmit(tun, skb); |
| @@ -1078,22 +1081,32 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev) · 3 unmodified lines |
| 1078 | /* Drop if the filter does not like it. | 1081 | /* Drop if the filter does not like it. |
| 1079 | * This is a noop if the filter is disabled. | 1082 | * This is a noop if the filter is disabled. |
| 1080 | * Filter can be enabled only for the TAP devices. */ | 1083 | * Filter can be enabled only for the TAP devices. */ |
| 1081 | if (!check_filter(&tun->txflt, skb)) | 1084 | if (!check_filter(&tun->txflt, skb)) { |
| | 1085 | drop_reason = SKB_DROP_REASON_TAP_TXFILTER; |
| 1082 | goto drop; | 1086 | goto drop; |
| | 1087 | } |
| 1083 | | 1088 | |
| 1084 | if (tfile->socket.sk->sk_filter && | 1089 | if (tfile->socket.sk->sk_filter && |
| 1085 | sk_filter(tfile->socket.sk, skb)) | 1090 | sk_filter(tfile->socket.sk, skb)) { |
| | 1091 | drop_reason = SKB_DROP_REASON_SOCKET_FILTER; |
| 1086 | goto drop; | 1092 | goto drop; |
| | 1093 | } |
| 1087 | | 1094 | |
| 1088 | len = run_ebpf_filter(tun, skb, len); | 1095 | len = run_ebpf_filter(tun, skb, len); |
| 1089 | if (len == 0) | 1096 | if (len == 0) { |
| | 1097 | drop_reason = SKB_DROP_REASON_TAP_FILTER; |
| 1090 | goto drop; | 1098 | goto drop; |
| | 1099 | } |
| 1091 | | 1100 | |
| 1092 | if (pskb_trim(skb, len)) | 1101 | if (pskb_trim(skb, len)) { |
| | 1102 | drop_reason = SKB_DROP_REASON_NOMEM; |
| 1093 | goto drop; | 1103 | goto drop; |
| | 1104 | } |
| 1094 | | 1105 | |
| 1095 | if (unlikely(skb_orphan_frags_rx(skb, GFP_ATOMIC))) | 1106 | if (unlikely(skb_orphan_frags_rx(skb, GFP_ATOMIC))) { |
| | 1107 | drop_reason = SKB_DROP_REASON_SKB_UCOPY_FAULT; |
| 1096 | goto drop; | 1108 | goto drop; |
| | 1109 | } |
| 1097 | | 1110 | |
| 1098 | skb_tx_timestamp(skb); | 1111 | skb_tx_timestamp(skb); |
| 1099 | | 1112 | |
| @@ -1104,8 +1117,10 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev) · 4 unmodified lines |
| 1104 | | 1117 | |
| 1105 | nf_reset_ct(skb); | 1118 | nf_reset_ct(skb); |
| 1106 | | 1119 | |
| 1107 | if (ptr_ring_produce(&tfile->tx_ring, skb)) | 1120 | if (ptr_ring_produce(&tfile->tx_ring, skb)) { |
| | 1121 | drop_reason = SKB_DROP_REASON_FULL_RING; |
| 1108 | goto drop; | 1122 | goto drop; |
| | 1123 | } |
| 1109 | | 1124 | |
| 1110 | /* NETIF_F_LLTX requires to do our own update of trans_start */ | 1125 | /* NETIF_F_LLTX requires to do our own update of trans_start */ |
| 1111 | queue = netdev_get_tx_queue(dev, txq); | 1126 | queue = netdev_get_tx_queue(dev, txq); |
| @@ -1122,7 +1137,7 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev) · 10 unmodified lines |
| 1122 | drop: | 1137 | drop: |
| 1123 | atomic_long_inc(&dev->tx_dropped); | 1138 | atomic_long_inc(&dev->tx_dropped); |
| 1124 | skb_tx_error(skb); | 1139 | skb_tx_error(skb); |
| 1125 | kfree_skb(skb); | 1140 | kfree_skb_reason(skb, drop_reason); |
| 1126 | rcu_read_unlock(); | 1141 | rcu_read_unlock(); |
| 1127 | return NET_XMIT_DROP; | 1142 | return NET_XMIT_DROP; |
| 1128 | } | 1143 | } |
| @@ -1720,6 +1735,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, · 591 unmodified lines |
| 1720 | u32 rxhash = 0; | 1735 | u32 rxhash = 0; |
| 1721 | int skb_xdp = 1; | 1736 | int skb_xdp = 1; |
| 1722 | bool frags = tun_napi_frags_enabled(tfile); | 1737 | bool frags = tun_napi_frags_enabled(tfile); |
| | 1738 | enum skb_drop_reason drop_reason; |
| 1723 | | 1739 | |
| 1724 | if (!(tun->flags & IFF_NO_PI)) { | 1740 | if (!(tun->flags & IFF_NO_PI)) { |
| 1725 | if (len < sizeof(pi)) | 1741 | if (len < sizeof(pi)) |
| @@ -1823,9 +1839,10 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, · 97 unmodified lines |
| 1823 | | 1839 | |
| 1824 | if (err) { | 1840 | if (err) { |
| 1825 | err = -EFAULT; | 1841 | err = -EFAULT; |
| | 1842 | drop_reason = SKB_DROP_REASON_SKB_UCOPY_FAULT; |
| 1826 | drop: | 1843 | drop: |
| 1827 | atomic_long_inc(&tun->dev->rx_dropped); | 1844 | atomic_long_inc(&tun->dev->rx_dropped); |
| 1828 | kfree_skb(skb); | 1845 | kfree_skb_reason(skb, drop_reason); |
| 1829 | if (frags) { | 1846 | if (frags) { |
| 1830 | tfile->napi.skb = NULL; | 1847 | tfile->napi.skb = NULL; |
| 1831 | mutex_unlock(&tfile->napi_mutex); | 1848 | mutex_unlock(&tfile->napi_mutex); |
| @@ -1872,6 +1889,7 @@ drop: · 40 unmodified lines |
| 1872 | case IFF_TAP: | 1889 | case IFF_TAP: |
| 1873 | if (frags && !pskb_may_pull(skb, ETH_HLEN)) { | 1890 | if (frags && !pskb_may_pull(skb, ETH_HLEN)) { |
| 1874 | err = -ENOMEM; | 1891 | err = -ENOMEM; |
| | 1892 | drop_reason = SKB_DROP_REASON_HDR_TRUNC; |
| 1875 | goto drop; | 1893 | goto drop; |
| 1876 | } | 1894 | } |
| 1877 | skb->protocol = eth_type_trans(skb, tun->dev); | 1895 | skb->protocol = eth_type_trans(skb, tun->dev); |
| @@ -1925,6 +1943,7 @@ drop: · 47 unmodified lines |
| 1925 | if (unlikely(!(tun->dev->flags & IFF_UP))) { | 1943 | if (unlikely(!(tun->dev->flags & IFF_UP))) { |
| 1926 | err = -EIO; | 1944 | err = -EIO; |
| 1927 | rcu_read_unlock(); | 1945 | rcu_read_unlock(); |
| | 1946 | drop_reason = SKB_DROP_REASON_DEV_READY; |
| 1928 | goto drop; | 1947 | goto drop; |
| 1929 | } | 1948 | } |
| 1930 | | 1949 | |