Commit 7c9c8913 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

ipv6: icmp6: add drop reason support to ndisc_recv_ns()

Change ndisc_recv_ns() to return a drop reason.

For the moment, return PKT_TOO_SMALL, NOT_SPECIFIED
or SKB_CONSUMED.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent dd1b5278
...@@ -783,7 +783,7 @@ void ndisc_update(const struct net_device *dev, struct neighbour *neigh, ...@@ -783,7 +783,7 @@ void ndisc_update(const struct net_device *dev, struct neighbour *neigh,
ndisc_ops_update(dev, neigh, flags, icmp6_type, ndopts); ndisc_ops_update(dev, neigh, flags, icmp6_type, ndopts);
} }
static void ndisc_recv_ns(struct sk_buff *skb) static enum skb_drop_reason ndisc_recv_ns(struct sk_buff *skb)
{ {
struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb); struct nd_msg *msg = (struct nd_msg *)skb_transport_header(skb);
const struct in6_addr *saddr = &ipv6_hdr(skb)->saddr; const struct in6_addr *saddr = &ipv6_hdr(skb)->saddr;
...@@ -797,18 +797,17 @@ static void ndisc_recv_ns(struct sk_buff *skb) ...@@ -797,18 +797,17 @@ static void ndisc_recv_ns(struct sk_buff *skb)
struct inet6_dev *idev = NULL; struct inet6_dev *idev = NULL;
struct neighbour *neigh; struct neighbour *neigh;
int dad = ipv6_addr_any(saddr); int dad = ipv6_addr_any(saddr);
bool inc;
int is_router = -1; int is_router = -1;
SKB_DR(reason);
u64 nonce = 0; u64 nonce = 0;
bool inc;
if (skb->len < sizeof(struct nd_msg)) { if (skb->len < sizeof(struct nd_msg))
ND_PRINTK(2, warn, "NS: packet too short\n"); return SKB_DROP_REASON_PKT_TOO_SMALL;
return;
}
if (ipv6_addr_is_multicast(&msg->target)) { if (ipv6_addr_is_multicast(&msg->target)) {
ND_PRINTK(2, warn, "NS: multicast target address\n"); ND_PRINTK(2, warn, "NS: multicast target address\n");
return; return reason;
} }
/* /*
...@@ -817,12 +816,12 @@ static void ndisc_recv_ns(struct sk_buff *skb) ...@@ -817,12 +816,12 @@ static void ndisc_recv_ns(struct sk_buff *skb)
*/ */
if (dad && !ipv6_addr_is_solict_mult(daddr)) { if (dad && !ipv6_addr_is_solict_mult(daddr)) {
ND_PRINTK(2, warn, "NS: bad DAD packet (wrong destination)\n"); ND_PRINTK(2, warn, "NS: bad DAD packet (wrong destination)\n");
return; return reason;
} }
if (!ndisc_parse_options(dev, msg->opt, ndoptlen, &ndopts)) { if (!ndisc_parse_options(dev, msg->opt, ndoptlen, &ndopts)) {
ND_PRINTK(2, warn, "NS: invalid ND options\n"); ND_PRINTK(2, warn, "NS: invalid ND options\n");
return; return reason;
} }
if (ndopts.nd_opts_src_lladdr) { if (ndopts.nd_opts_src_lladdr) {
...@@ -830,7 +829,7 @@ static void ndisc_recv_ns(struct sk_buff *skb) ...@@ -830,7 +829,7 @@ static void ndisc_recv_ns(struct sk_buff *skb)
if (!lladdr) { if (!lladdr) {
ND_PRINTK(2, warn, ND_PRINTK(2, warn,
"NS: invalid link-layer address length\n"); "NS: invalid link-layer address length\n");
return; return reason;
} }
/* RFC2461 7.1.1: /* RFC2461 7.1.1:
...@@ -841,7 +840,7 @@ static void ndisc_recv_ns(struct sk_buff *skb) ...@@ -841,7 +840,7 @@ static void ndisc_recv_ns(struct sk_buff *skb)
if (dad) { if (dad) {
ND_PRINTK(2, warn, ND_PRINTK(2, warn,
"NS: bad DAD packet (link-layer address option)\n"); "NS: bad DAD packet (link-layer address option)\n");
return; return reason;
} }
} }
if (ndopts.nd_opts_nonce && ndopts.nd_opts_nonce->nd_opt_len == 1) if (ndopts.nd_opts_nonce && ndopts.nd_opts_nonce->nd_opt_len == 1)
...@@ -869,7 +868,7 @@ static void ndisc_recv_ns(struct sk_buff *skb) ...@@ -869,7 +868,7 @@ static void ndisc_recv_ns(struct sk_buff *skb)
* so fail our DAD process * so fail our DAD process
*/ */
addrconf_dad_failure(skb, ifp); addrconf_dad_failure(skb, ifp);
return; return reason;
} else { } else {
/* /*
* This is not a dad solicitation. * This is not a dad solicitation.
...@@ -901,7 +900,7 @@ static void ndisc_recv_ns(struct sk_buff *skb) ...@@ -901,7 +900,7 @@ static void ndisc_recv_ns(struct sk_buff *skb)
idev = in6_dev_get(dev); idev = in6_dev_get(dev);
if (!idev) { if (!idev) {
/* XXX: count this drop? */ /* XXX: count this drop? */
return; return reason;
} }
if (ipv6_chk_acast_addr(net, dev, &msg->target) || if (ipv6_chk_acast_addr(net, dev, &msg->target) ||
...@@ -958,6 +957,7 @@ static void ndisc_recv_ns(struct sk_buff *skb) ...@@ -958,6 +957,7 @@ static void ndisc_recv_ns(struct sk_buff *skb)
true, (ifp != NULL && inc), inc); true, (ifp != NULL && inc), inc);
if (neigh) if (neigh)
neigh_release(neigh); neigh_release(neigh);
reason = SKB_CONSUMED;
} }
out: out:
...@@ -965,6 +965,7 @@ static void ndisc_recv_ns(struct sk_buff *skb) ...@@ -965,6 +965,7 @@ static void ndisc_recv_ns(struct sk_buff *skb)
in6_ifa_put(ifp); in6_ifa_put(ifp);
else else
in6_dev_put(idev); in6_dev_put(idev);
return reason;
} }
static int accept_untracked_na(struct net_device *dev, struct in6_addr *saddr) static int accept_untracked_na(struct net_device *dev, struct in6_addr *saddr)
...@@ -1781,8 +1782,9 @@ void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target) ...@@ -1781,8 +1782,9 @@ void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target)
static void pndisc_redo(struct sk_buff *skb) static void pndisc_redo(struct sk_buff *skb)
{ {
ndisc_recv_ns(skb); enum skb_drop_reason reason = ndisc_recv_ns(skb);
kfree_skb(skb);
kfree_skb_reason(skb, reason);
} }
static int ndisc_is_multicast(const void *pkey) static int ndisc_is_multicast(const void *pkey)
...@@ -1834,7 +1836,7 @@ enum skb_drop_reason ndisc_rcv(struct sk_buff *skb) ...@@ -1834,7 +1836,7 @@ enum skb_drop_reason ndisc_rcv(struct sk_buff *skb)
switch (msg->icmph.icmp6_type) { switch (msg->icmph.icmp6_type) {
case NDISC_NEIGHBOUR_SOLICITATION: case NDISC_NEIGHBOUR_SOLICITATION:
memset(NEIGH_CB(skb), 0, sizeof(struct neighbour_cb)); memset(NEIGH_CB(skb), 0, sizeof(struct neighbour_cb));
ndisc_recv_ns(skb); reason = ndisc_recv_ns(skb);
break; break;
case NDISC_NEIGHBOUR_ADVERTISEMENT: case NDISC_NEIGHBOUR_ADVERTISEMENT:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment