Skip to content

Commit 545dbcd

Browse files
edumazetkuba-moo
authored andcommitted
ipv6: icmp6: add drop reason support to ndisc_rcv()
Creates three new drop reasons: SKB_DROP_REASON_IPV6_NDISC_FRAG: invalid frag (suppress_frag_ndisc). SKB_DROP_REASON_IPV6_NDISC_HOP_LIMIT: invalid hop limit. SKB_DROP_REASON_IPV6_NDISC_BAD_CODE: invalid NDISC icmp6 code. Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: David Ahern <dsahern@kernel.org> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 30c89ba commit 545dbcd

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

include/net/dropreason.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
FN(FRAG_TOO_FAR) \
7474
FN(TCP_MINTTL) \
7575
FN(IPV6_BAD_EXTHDR) \
76+
FN(IPV6_NDISC_FRAG) \
77+
FN(IPV6_NDISC_HOP_LIMIT) \
78+
FN(IPV6_NDISC_BAD_CODE) \
7679
FNe(MAX)
7780

7881
/**
@@ -321,6 +324,12 @@ enum skb_drop_reason {
321324
SKB_DROP_REASON_TCP_MINTTL,
322325
/** @SKB_DROP_REASON_IPV6_BAD_EXTHDR: Bad IPv6 extension header. */
323326
SKB_DROP_REASON_IPV6_BAD_EXTHDR,
327+
/** @SKB_DROP_REASON_IPV6_NDISC_FRAG: invalid frag (suppress_frag_ndisc). */
328+
SKB_DROP_REASON_IPV6_NDISC_FRAG,
329+
/** @SKB_DROP_REASON_IPV6_NDISC_HOP_LIMIT: invalid hop limit. */
330+
SKB_DROP_REASON_IPV6_NDISC_HOP_LIMIT,
331+
/** @SKB_DROP_REASON_IPV6_NDISC_BAD_CODE: invalid NDISC icmp6 code. */
332+
SKB_DROP_REASON_IPV6_NDISC_BAD_CODE,
324333
/**
325334
* @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be
326335
* used as a real 'reason'

include/net/ndisc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ int ndisc_late_init(void);
445445
void ndisc_late_cleanup(void);
446446
void ndisc_cleanup(void);
447447

448-
int ndisc_rcv(struct sk_buff *skb);
448+
enum skb_drop_reason ndisc_rcv(struct sk_buff *skb);
449449

450450
struct sk_buff *ndisc_ns_create(struct net_device *dev, const struct in6_addr *solicit,
451451
const struct in6_addr *saddr, u64 nonce);

net/ipv6/icmp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ static int icmpv6_rcv(struct sk_buff *skb)
969969
case NDISC_NEIGHBOUR_SOLICITATION:
970970
case NDISC_NEIGHBOUR_ADVERTISEMENT:
971971
case NDISC_REDIRECT:
972-
ndisc_rcv(skb);
972+
reason = ndisc_rcv(skb);
973973
break;
974974

975975
case ICMPV6_MGM_QUERY:

net/ipv6/ndisc.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,15 +1804,16 @@ static bool ndisc_suppress_frag_ndisc(struct sk_buff *skb)
18041804
return false;
18051805
}
18061806

1807-
int ndisc_rcv(struct sk_buff *skb)
1807+
enum skb_drop_reason ndisc_rcv(struct sk_buff *skb)
18081808
{
18091809
struct nd_msg *msg;
1810+
SKB_DR(reason);
18101811

18111812
if (ndisc_suppress_frag_ndisc(skb))
1812-
return 0;
1813+
return SKB_DROP_REASON_IPV6_NDISC_FRAG;
18131814

18141815
if (skb_linearize(skb))
1815-
return 0;
1816+
return SKB_DROP_REASON_NOMEM;
18161817

18171818
msg = (struct nd_msg *)skb_transport_header(skb);
18181819

@@ -1821,13 +1822,13 @@ int ndisc_rcv(struct sk_buff *skb)
18211822
if (ipv6_hdr(skb)->hop_limit != 255) {
18221823
ND_PRINTK(2, warn, "NDISC: invalid hop-limit: %d\n",
18231824
ipv6_hdr(skb)->hop_limit);
1824-
return 0;
1825+
return SKB_DROP_REASON_IPV6_NDISC_HOP_LIMIT;
18251826
}
18261827

18271828
if (msg->icmph.icmp6_code != 0) {
18281829
ND_PRINTK(2, warn, "NDISC: invalid ICMPv6 code: %d\n",
18291830
msg->icmph.icmp6_code);
1830-
return 0;
1831+
return SKB_DROP_REASON_IPV6_NDISC_BAD_CODE;
18311832
}
18321833

18331834
switch (msg->icmph.icmp6_type) {
@@ -1853,7 +1854,7 @@ int ndisc_rcv(struct sk_buff *skb)
18531854
break;
18541855
}
18551856

1856-
return 0;
1857+
return reason;
18571858
}
18581859

18591860
static int ndisc_netdev_event(struct notifier_block *this, unsigned long event, void *ptr)

0 commit comments

Comments
 (0)