[PATCH net-next 1/3] net: gre_demux: add skb drop reasons to gre_rcv()

From: menglong8 . dong
Date: Mon Mar 14 2022 - 09:33:34 EST


From: Menglong Dong <imagedong@xxxxxxxxxxx>

Replace kfree_skb() used in gre_rcv() with kfree_skb_reason(). Following
new drop reasons are added:

SKB_DROP_REASON_GRE_VERSION
SKB_DROP_REASON_GRE_NOHANDLER

Reviewed-by: Hao Peng <flyingpeng@xxxxxxxxxxx>
Reviewed-by: Biao Jiang <benbjiang@xxxxxxxxxxx>
Signed-off-by: Menglong Dong <imagedong@xxxxxxxxxxx>
---
include/linux/skbuff.h | 4 ++++
include/trace/events/skb.h | 2 ++
net/ipv4/gre_demux.c | 12 +++++++++---
3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 26538ceb4b01..5edb704af5bb 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -444,6 +444,10 @@ enum skb_drop_reason {
SKB_DROP_REASON_TAP_TXFILTER, /* dropped by tx filter implemented
* at tun/tap, e.g., check_filter()
*/
+ SKB_DROP_REASON_GRE_VERSION, /* GRE version not supported */
+ SKB_DROP_REASON_GRE_NOHANDLER, /* no handler found (version not
+ * supported?)
+ */
SKB_DROP_REASON_MAX,
};

diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h
index e1670e1e4934..f2bcffdc4bae 100644
--- a/include/trace/events/skb.h
+++ b/include/trace/events/skb.h
@@ -61,6 +61,8 @@
EM(SKB_DROP_REASON_HDR_TRUNC, HDR_TRUNC) \
EM(SKB_DROP_REASON_TAP_FILTER, TAP_FILTER) \
EM(SKB_DROP_REASON_TAP_TXFILTER, TAP_TXFILTER) \
+ EM(SKB_DROP_REASON_GRE_VERSION, GRE_VERSION) \
+ EM(SKB_DROP_REASON_GRE_NOHANDLER, GRE_NOHANDLER) \
EMe(SKB_DROP_REASON_MAX, MAX)

#undef EM
diff --git a/net/ipv4/gre_demux.c b/net/ipv4/gre_demux.c
index cbb2b4bb0dfa..066cbaadc52a 100644
--- a/net/ipv4/gre_demux.c
+++ b/net/ipv4/gre_demux.c
@@ -146,20 +146,26 @@ EXPORT_SYMBOL(gre_parse_header);
static int gre_rcv(struct sk_buff *skb)
{
const struct gre_protocol *proto;
+ enum skb_drop_reason reason;
u8 ver;
int ret;

+ reason = SKB_DROP_REASON_NOT_SPECIFIED;
if (!pskb_may_pull(skb, 12))
goto drop;

ver = skb->data[1]&0x7f;
- if (ver >= GREPROTO_MAX)
+ if (ver >= GREPROTO_MAX) {
+ reason = SKB_DROP_REASON_GRE_VERSION;
goto drop;
+ }

rcu_read_lock();
proto = rcu_dereference(gre_proto[ver]);
- if (!proto || !proto->handler)
+ if (!proto || !proto->handler) {
+ reason = SKB_DROP_REASON_GRE_NOHANDLER;
goto drop_unlock;
+ }
ret = proto->handler(skb);
rcu_read_unlock();
return ret;
@@ -167,7 +173,7 @@ static int gre_rcv(struct sk_buff *skb)
drop_unlock:
rcu_read_unlock();
drop:
- kfree_skb(skb);
+ kfree_skb_reason(skb, reason);
return NET_RX_DROP;
}

--
2.35.1