ipv6: icmp6: add SKB_DROP_REASON_IPV6_NDISC_BAD_OPTIONS
authorEric Dumazet <edumazet@google.com>
Thu, 16 Feb 2023 16:28:40 +0000 (16:28 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 20 Feb 2023 08:54:23 +0000 (08:54 +0000)
This is a generic drop reason for any error detected
in ndisc_parse_options().

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/dropreason.h
net/ipv6/ndisc.c

index ef3f65d135d375920e88759890947ed0f6e87e10..239a5c0ea83eb6053df55f1ea113f3005ec050b0 100644 (file)
@@ -76,6 +76,7 @@
        FN(IPV6_NDISC_FRAG)             \
        FN(IPV6_NDISC_HOP_LIMIT)        \
        FN(IPV6_NDISC_BAD_CODE)         \
+       FN(IPV6_NDISC_BAD_OPTIONS)      \
        FNe(MAX)
 
 /**
@@ -330,6 +331,8 @@ enum skb_drop_reason {
        SKB_DROP_REASON_IPV6_NDISC_HOP_LIMIT,
        /** @SKB_DROP_REASON_IPV6_NDISC_BAD_CODE: invalid NDISC icmp6 code. */
        SKB_DROP_REASON_IPV6_NDISC_BAD_CODE,
+       /** @SKB_DROP_REASON_IPV6_NDISC_BAD_OPTIONS: invalid NDISC options. */
+       SKB_DROP_REASON_IPV6_NDISC_BAD_OPTIONS,
        /**
         * @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be
         * used as a real 'reason'
index e9776aa6f1675e35273df16e40745779b91d117e..b47e845d66eb8533e2334915fe6f05bed6f84764 100644 (file)
@@ -819,10 +819,8 @@ static enum skb_drop_reason ndisc_recv_ns(struct sk_buff *skb)
                return reason;
        }
 
-       if (!ndisc_parse_options(dev, msg->opt, ndoptlen, &ndopts)) {
-               ND_PRINTK(2, warn, "NS: invalid ND options\n");
-               return reason;
-       }
+       if (!ndisc_parse_options(dev, msg->opt, ndoptlen, &ndopts))
+               return SKB_DROP_REASON_IPV6_NDISC_BAD_OPTIONS;
 
        if (ndopts.nd_opts_src_lladdr) {
                lladdr = ndisc_opt_addr_data(ndopts.nd_opts_src_lladdr, dev);
@@ -1026,10 +1024,9 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb)
            idev->cnf.drop_unsolicited_na)
                return reason;
 
-       if (!ndisc_parse_options(dev, msg->opt, ndoptlen, &ndopts)) {
-               ND_PRINTK(2, warn, "NS: invalid ND option\n");
-               return reason;
-       }
+       if (!ndisc_parse_options(dev, msg->opt, ndoptlen, &ndopts))
+               return SKB_DROP_REASON_IPV6_NDISC_BAD_OPTIONS;
+
        if (ndopts.nd_opts_tgt_lladdr) {
                lladdr = ndisc_opt_addr_data(ndopts.nd_opts_tgt_lladdr, dev);
                if (!lladdr) {
@@ -1159,10 +1156,8 @@ static enum skb_drop_reason ndisc_recv_rs(struct sk_buff *skb)
                goto out;
 
        /* Parse ND options */
-       if (!ndisc_parse_options(skb->dev, rs_msg->opt, ndoptlen, &ndopts)) {
-               ND_PRINTK(2, notice, "NS: invalid ND option, ignored\n");
-               goto out;
-       }
+       if (!ndisc_parse_options(skb->dev, rs_msg->opt, ndoptlen, &ndopts))
+               return SKB_DROP_REASON_IPV6_NDISC_BAD_OPTIONS;
 
        if (ndopts.nd_opts_src_lladdr) {
                lladdr = ndisc_opt_addr_data(ndopts.nd_opts_src_lladdr,
@@ -1280,10 +1275,8 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb)
                return reason;
        }
 
-       if (!ndisc_parse_options(skb->dev, opt, optlen, &ndopts)) {
-               ND_PRINTK(2, warn, "RA: invalid ND options\n");
-               return reason;
-       }
+       if (!ndisc_parse_options(skb->dev, opt, optlen, &ndopts))
+               return SKB_DROP_REASON_IPV6_NDISC_BAD_OPTIONS;
 
        if (!ipv6_accept_ra(in6_dev)) {
                ND_PRINTK(2, info,
@@ -1627,7 +1620,7 @@ static enum skb_drop_reason ndisc_redirect_rcv(struct sk_buff *skb)
        }
 
        if (!ndisc_parse_options(skb->dev, msg->opt, ndoptlen, &ndopts))
-               return reason;
+               return SKB_DROP_REASON_IPV6_NDISC_BAD_OPTIONS;
 
        if (!ndopts.nd_opts_rh) {
                ip6_redirect_no_header(skb, dev_net(skb->dev),