tun: use pskb_may_pull_reason() and remove SKB_DROP_REASON_HDR_TRUNC
Subsystems (3)
PATCH 1/1 tun: use pskb_may_pull_reason() and remove SKB_DROP_REASON_HDR_TRUNC
tun_get_user() is the only user of SKB_DROP_REASON_HDR_TRUNC. It sets it when pskb_may_pull() fails to pull the Ethernet header of a frame written to a TAP device.
pskb_may_pull_reason() reports why the pull failed: PKT_TOO_SMALL if the packet is shorter than requested, NOMEM if pulling the data into the linear area fails. Use it for the Ethernet header pull in tun_get_user() and remove the now unused SKB_DROP_REASON_HDR_TRUNC.
After a successful pull drop_reason is SKB_NOT_DROPPED_YET. The path that later finds the queue detached has no reason of its own and relied on the SKB_DROP_REASON_NOT_SPECIFIED initializer. Fall back to SKB_DROP_REASON_NOT_SPECIFIED at the free_skb label, as vxlan_rcv() does, so that this path, and any later one without a reason of its own, keeps reporting it.
The error returned to user space does not change.
--- drivers/net/tun.c | 5 +++-- include/net/dropreason-core.h | 7 ------- 2 files changed, 3 insertions(+), 9 deletions(-)
drivers/net/tun.c +3 -2
@@ -1932,9 +1932,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, skb->dev = tun->dev;break ;case IFF_TAP : -if (!pskb_may_pull (skb,ETH_HLEN )) { + drop_reason =pskb_may_pull_reason (skb,ETH_HLEN ); +if (drop_reason) { err = -ENOMEM ; - drop_reason =SKB_DROP_REASON_HDR_TRUNC ; goto drop; } skb->protocol =eth_type_trans (skb, tun->dev);
@@ -2062,6 +2062,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,dev_core_stats_rx_dropped_inc (tun->dev); free_skb: + drop_reason = drop_reason ?:SKB_DROP_REASON_NOT_SPECIFIED ;if (!IS_ERR_OR_NULL (skb))kfree_skb_reason (skb, drop_reason);
include/net/dropreason-core.h +0 -7
@@ -82,7 +82,6 @@ FN(DEV_READY) \ FN(FULL_RING) \ FN(NOMEM) \ - FN(HDR_TRUNC) \ FN(TAP_FILTER) \ FN(TAP_TXFILTER) \ FN(ICMP_CSUM) \
@@ -427,12 +426,6 @@ enum skb_drop_reason {SKB_DROP_REASON_FULL_RING ,/** @SKB_DROP_REASON_NOMEM: error due to OOM */ SKB_DROP_REASON_NOMEM, -/** -* @SKB_DROP_REASON_HDR_TRUNC: failed to trunc/extract the header from -* networking data, e.g., failed to pull the protocol header from -* frags via pskb_may_pull() -*/ - SKB_DROP_REASON_HDR_TRUNC,/** * @SKB_DROP_REASON_TAP_FILTER: dropped by (ebpf) filter directly attached * to tun/tap, e.g., via TUNSETFILTEREBPF
Signature · 1 line
2.47.3
Quoted 16 lines · Anton Danilov
tun_get_user()is the only user ofSKB_DROP_REASON_HDR_TRUNC. It sets it whenpskb_may_pull()fails to pull the Ethernet header of a frame written to a TAP device.
pskb_may_pull_reason()reports why the pull failed:PKT_TOO_SMALLif the packet is shorter than requested, NOMEM if pulling the data into the linear area fails. Use it for the Ethernet header pull intun_get_user()and remove the now unusedSKB_DROP_REASON_HDR_TRUNC.After a successful pull
drop_reasonisSKB_NOT_DROPPED_YET. The path that later finds the queue detached has no reason of its own and relied on theSKB_DROP_REASON_NOT_SPECIFIEDinitializer. Fall back toSKB_DROP_REASON_NOT_SPECIFIEDat thefree_skblabel, asvxlan_rcv()does, so that this path, and any later one without a reason of its own, keeps reporting it.
Quoted 6 lines
The error returned to user space does not change.
Suggested-by Ido Schimmel <[email protected]>Assisted-by LLMSigned-off-by Anton Danilov <[email protected]>
I will check the other series next week.
Quoted 16 lines · Anton Danilov
tun_get_user()is the only user ofSKB_DROP_REASON_HDR_TRUNC. It sets it whenpskb_may_pull()fails to pull the Ethernet header of a frame written to a TAP device.
pskb_may_pull_reason()reports why the pull failed:PKT_TOO_SMALLif the packet is shorter than requested, NOMEM if pulling the data into the linear area fails. Use it for the Ethernet header pull intun_get_user()and remove the now unusedSKB_DROP_REASON_HDR_TRUNC.After a successful pull
drop_reasonisSKB_NOT_DROPPED_YET. The path that later finds the queue detached has no reason of its own and relied on theSKB_DROP_REASON_NOT_SPECIFIEDinitializer. Fall back toSKB_DROP_REASON_NOT_SPECIFIEDat thefree_skblabel, asvxlan_rcv()does, so that this path, and any later one without a reason of its own, keeps reporting it.
Quoted 6 lines
The error returned to user space does not change.
Suggested-by Ido Schimmel <[email protected]>Assisted-by LLMSigned-off-by Anton Danilov <[email protected]>
Quoted 11 lines
--- drivers/net/tun.c | 5 +++-- include/net/dropreason-core.h | 7 ------- 2 files changed, 3 insertions(+), 9 deletions(-)drivers/net/tun.c +0
-0
drivers/net/tun.c static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, · line 1935
Quoted 5 lines
drivers/net/tun.c +1
-1@@ -1932,9 +1932,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, skb->dev = tun->dev;break ;case IFF_TAP : -if (!pskb_may_pull (skb,ETH_HLEN )) { + drop_reason =pskb_may_pull_reason (skb,ETH_HLEN );
Should we update the skb_may_pull in the above IFF_TUN similarly?
Quoted 42 lines
drivers/net/tun.c +2
-1+if (drop_reason) { err = -ENOMEM ; - drop_reason =SKB_DROP_REASON_HDR_TRUNC ; goto drop; } skb->protocol =eth_type_trans (skb, tun->dev);@@ -2062,6 +2062,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,dev_core_stats_rx_dropped_inc (tun->dev); free_skb: + drop_reason = drop_reason ?:SKB_DROP_REASON_NOT_SPECIFIED ;if (!IS_ERR_OR_NULL (skb))kfree_skb_reason (skb, drop_reason);include/net/dropreason-core.h +0
-7@@ -82,7 +82,6 @@ FN(DEV_READY) \ FN(FULL_RING) \ FN(NOMEM) \ - FN(HDR_TRUNC) \ FN(TAP_FILTER) \ FN(TAP_TXFILTER) \ FN(ICMP_CSUM) \@@ -427,12 +426,6 @@ enum skb_drop_reason {SKB_DROP_REASON_FULL_RING ,/** @SKB_DROP_REASON_NOMEM: error due to OOM */ SKB_DROP_REASON_NOMEM, -/** -* @SKB_DROP_REASON_HDR_TRUNC: failed to trunc/extract the header from -* networking data, e.g., failed to pull the protocol header from -* frags via pskb_may_pull() -*/ - SKB_DROP_REASON_HDR_TRUNC,/** * @SKB_DROP_REASON_TAP_FILTER: dropped by (ebpf) filter directly attached * to tun/tap, e.g., via TUNSETFILTEREBPF Signature · 1 line
2.47.3
Quoted 6 lines · Willem de Bruijn
drivers/net/tun.c static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, · line 1935
Quoted 3 lines · Anton Danilov
drivers/net/tun.c +1
-1case IFF_TAP : -if (!pskb_may_pull (skb,ETH_HLEN )) { + drop_reason =pskb_may_pull_reason (skb,ETH_HLEN );Should we update the
skb_may_pullin the aboveIFF_TUNsimilarly?
I left it out because that pull never used HDR_TRUNC, so converting it is a separate change: its drop is reported as NOT_SPECIFIED today, and with pskb_may_pull_reason() it becomes PKT_TOO_SMALL.
I will convert it in v2.