Skip to content

Commit 4aaa489

Browse files
committed
Merge branch 'ip-neigh-skb-reason'
Menglong Dong says: ==================== net: use kfree_skb_reason() for ip/neighbour In the series "net: use kfree_skb_reason() for ip/udp packet receive", reasons for skb drops are added to the packet receive process of IP layer. Link: https://lore.kernel.org/netdev/[email protected]/ And in the first patch of this series, skb drop reasons are added to the packet egress path of IP layer. As kfree_skb() is not used frequent, I commit these changes at once and didn't create a patch for every functions that involed. Following functions are handled: __ip_queue_xmit() ip_finish_output() ip_mc_finish_output() ip6_output() ip6_finish_output() ip6_finish_output2() Following new drop reasons are introduced (what they mean can be seen in the document of them): SKB_DROP_REASON_IP_OUTNOROUTES SKB_DROP_REASON_BPF_CGROUP_EGRESS SKB_DROP_REASON_IPV6DISABLED SKB_DROP_REASON_NEIGH_CREATEFAIL In the 2th and 3th patches, kfree_skb_reason() is used in neighbour subsystem instead of kfree_skb(). __neigh_event_send() and arp_error_report() are involed, and following new drop reasons are introduced: SKB_DROP_REASON_NEIGH_FAILED SKB_DROP_REASON_NEIGH_QUEUEFULL SKB_DROP_REASON_NEIGH_DEAD Changes since v2: - fix typo in the 1th patch of 'SKB_DROP_REASON_IPV6DSIABLED' reported by Roman Changes since v1: - introduce SKB_DROP_REASON_NEIGH_CREATEFAIL for some path in the 1th patch - introduce SKB_DROP_REASON_NEIGH_DEAD in the 2th patch - simplify the document for the new drop reasons, as David Ahern suggested ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 0cc70c6 + 56d4b4e commit 4aaa489

File tree

6 files changed

+33
-11
lines changed

6 files changed

+33
-11
lines changed

include/linux/skbuff.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,20 @@ enum skb_drop_reason {
380380
* the ofo queue, corresponding to
381381
* LINUX_MIB_TCPOFOMERGE
382382
*/
383+
SKB_DROP_REASON_IP_OUTNOROUTES, /* route lookup failed */
384+
SKB_DROP_REASON_BPF_CGROUP_EGRESS, /* dropped by
385+
* BPF_PROG_TYPE_CGROUP_SKB
386+
* eBPF program
387+
*/
388+
SKB_DROP_REASON_IPV6DISABLED, /* IPv6 is disabled on the device */
389+
SKB_DROP_REASON_NEIGH_CREATEFAIL, /* failed to create neigh
390+
* entry
391+
*/
392+
SKB_DROP_REASON_NEIGH_FAILED, /* neigh entry in failed state */
393+
SKB_DROP_REASON_NEIGH_QUEUEFULL, /* arp_queue for neigh
394+
* entry is full
395+
*/
396+
SKB_DROP_REASON_NEIGH_DEAD, /* neigh entry is dead */
383397
SKB_DROP_REASON_MAX,
384398
};
385399

include/trace/events/skb.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@
3737
EM(SKB_DROP_REASON_TCP_OLD_DATA, TCP_OLD_DATA) \
3838
EM(SKB_DROP_REASON_TCP_OVERWINDOW, TCP_OVERWINDOW) \
3939
EM(SKB_DROP_REASON_TCP_OFOMERGE, TCP_OFOMERGE) \
40+
EM(SKB_DROP_REASON_IP_OUTNOROUTES, IP_OUTNOROUTES) \
41+
EM(SKB_DROP_REASON_BPF_CGROUP_EGRESS, \
42+
BPF_CGROUP_EGRESS) \
43+
EM(SKB_DROP_REASON_IPV6DISABLED, IPV6DISABLED) \
44+
EM(SKB_DROP_REASON_NEIGH_CREATEFAIL, NEIGH_CREATEFAIL) \
45+
EM(SKB_DROP_REASON_NEIGH_FAILED, NEIGH_FAILED) \
46+
EM(SKB_DROP_REASON_NEIGH_QUEUEFULL, NEIGH_QUEUEFULL) \
47+
EM(SKB_DROP_REASON_NEIGH_DEAD, NEIGH_DEAD) \
4048
EMe(SKB_DROP_REASON_MAX, MAX)
4149

4250
#undef EM

net/core/neighbour.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb,
11711171
neigh->updated = jiffies;
11721172
write_unlock_bh(&neigh->lock);
11731173

1174-
kfree_skb(skb);
1174+
kfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_FAILED);
11751175
return 1;
11761176
}
11771177
} else if (neigh->nud_state & NUD_STALE) {
@@ -1193,7 +1193,7 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb,
11931193
if (!buff)
11941194
break;
11951195
neigh->arp_queue_len_bytes -= buff->truesize;
1196-
kfree_skb(buff);
1196+
kfree_skb_reason(buff, SKB_DROP_REASON_NEIGH_QUEUEFULL);
11971197
NEIGH_CACHE_STAT_INC(neigh->tbl, unres_discards);
11981198
}
11991199
skb_dst_force(skb);
@@ -1215,7 +1215,7 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb,
12151215
if (neigh->nud_state & NUD_STALE)
12161216
goto out_unlock_bh;
12171217
write_unlock_bh(&neigh->lock);
1218-
kfree_skb(skb);
1218+
kfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_DEAD);
12191219
trace_neigh_event_send_dead(neigh, 1);
12201220
return 1;
12211221
}

net/ipv4/arp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ static int arp_constructor(struct neighbour *neigh)
293293
static void arp_error_report(struct neighbour *neigh, struct sk_buff *skb)
294294
{
295295
dst_link_failure(skb);
296-
kfree_skb(skb);
296+
kfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_FAILED);
297297
}
298298

299299
/* Create and send an arp packet. */

net/ipv4/ip_output.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static int ip_finish_output2(struct net *net, struct sock *sk, struct sk_buff *s
233233

234234
net_dbg_ratelimited("%s: No header cache and no neighbour!\n",
235235
__func__);
236-
kfree_skb(skb);
236+
kfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_CREATEFAIL);
237237
return -EINVAL;
238238
}
239239

@@ -317,7 +317,7 @@ static int ip_finish_output(struct net *net, struct sock *sk, struct sk_buff *sk
317317
case NET_XMIT_CN:
318318
return __ip_finish_output(net, sk, skb) ? : ret;
319319
default:
320-
kfree_skb(skb);
320+
kfree_skb_reason(skb, SKB_DROP_REASON_BPF_CGROUP_EGRESS);
321321
return ret;
322322
}
323323
}
@@ -337,7 +337,7 @@ static int ip_mc_finish_output(struct net *net, struct sock *sk,
337337
case NET_XMIT_SUCCESS:
338338
break;
339339
default:
340-
kfree_skb(skb);
340+
kfree_skb_reason(skb, SKB_DROP_REASON_BPF_CGROUP_EGRESS);
341341
return ret;
342342
}
343343

@@ -536,7 +536,7 @@ int __ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
536536
no_route:
537537
rcu_read_unlock();
538538
IP_INC_STATS(net, IPSTATS_MIB_OUTNOROUTES);
539-
kfree_skb(skb);
539+
kfree_skb_reason(skb, SKB_DROP_REASON_IP_OUTNOROUTES);
540540
return -EHOSTUNREACH;
541541
}
542542
EXPORT_SYMBOL(__ip_queue_xmit);

net/ipv6/ip6_output.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff *
130130
rcu_read_unlock_bh();
131131

132132
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTNOROUTES);
133-
kfree_skb(skb);
133+
kfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_CREATEFAIL);
134134
return -EINVAL;
135135
}
136136

@@ -202,7 +202,7 @@ static int ip6_finish_output(struct net *net, struct sock *sk, struct sk_buff *s
202202
case NET_XMIT_CN:
203203
return __ip6_finish_output(net, sk, skb) ? : ret;
204204
default:
205-
kfree_skb(skb);
205+
kfree_skb_reason(skb, SKB_DROP_REASON_BPF_CGROUP_EGRESS);
206206
return ret;
207207
}
208208
}
@@ -217,7 +217,7 @@ int ip6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
217217

218218
if (unlikely(idev->cnf.disable_ipv6)) {
219219
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS);
220-
kfree_skb(skb);
220+
kfree_skb_reason(skb, SKB_DROP_REASON_IPV6DISABLED);
221221
return 0;
222222
}
223223

0 commit comments

Comments
 (0)