Commit 1cb3fe51 authored by YOSHIFUJI Hideaki / 吉藤英明's avatar YOSHIFUJI Hideaki / 吉藤英明 Committed by David S. Miller

ndisc: Break down ndisc_build_skb() and build message directly.

Construct NS/NA/RS message directly using C99 compound literals.
Signed-off-by: default avatarYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b44b5f4a
...@@ -413,47 +413,6 @@ static void ip6_nd_hdr(struct sk_buff *skb, ...@@ -413,47 +413,6 @@ static void ip6_nd_hdr(struct sk_buff *skb,
hdr->daddr = *daddr; hdr->daddr = *daddr;
} }
static struct sk_buff *ndisc_build_skb(struct net_device *dev,
const struct in6_addr *daddr,
const struct in6_addr *saddr,
struct icmp6hdr *icmp6h,
const struct in6_addr *target,
int llinfo)
{
struct sk_buff *skb;
struct icmp6hdr *hdr;
int len;
int optlen = 0;
u8 *opt;
if (!dev->addr_len)
llinfo = 0;
len = sizeof(struct icmp6hdr) + (target ? sizeof(*target) : 0);
if (llinfo)
optlen += ndisc_opt_addr_space(dev);
skb = ndisc_alloc_skb(dev, len + optlen);
if (!skb)
return NULL;
skb_put(skb, len);
hdr = (struct icmp6hdr *)skb_transport_header(skb);
memcpy(hdr, icmp6h, sizeof(*hdr));
opt = skb_transport_header(skb) + sizeof(struct icmp6hdr);
if (target) {
*(struct in6_addr *)opt = *target;
opt += sizeof(*target);
}
if (llinfo)
ndisc_fill_addr_option(skb, llinfo, dev->dev_addr);
return skb;
}
static void ndisc_send_skb(struct sk_buff *skb, static void ndisc_send_skb(struct sk_buff *skb,
const struct in6_addr *daddr, const struct in6_addr *daddr,
const struct in6_addr *saddr) const struct in6_addr *saddr)
...@@ -512,9 +471,8 @@ static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh, ...@@ -512,9 +471,8 @@ static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh,
struct in6_addr tmpaddr; struct in6_addr tmpaddr;
struct inet6_ifaddr *ifp; struct inet6_ifaddr *ifp;
const struct in6_addr *src_addr; const struct in6_addr *src_addr;
struct icmp6hdr icmp6h = { struct nd_msg *msg;
.icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT, int optlen = 0;
};
/* for anycast or proxy, solicited_addr != src_addr */ /* for anycast or proxy, solicited_addr != src_addr */
ifp = ipv6_get_ifaddr(dev_net(dev), solicited_addr, dev, 1); ifp = ipv6_get_ifaddr(dev_net(dev), solicited_addr, dev, 1);
...@@ -532,15 +490,31 @@ static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh, ...@@ -532,15 +490,31 @@ static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh,
src_addr = &tmpaddr; src_addr = &tmpaddr;
} }
icmp6h.icmp6_router = router; if (!dev->addr_len)
icmp6h.icmp6_solicited = solicited; inc_opt = 0;
icmp6h.icmp6_override = override; if (inc_opt)
optlen += ndisc_opt_addr_space(dev);
skb = ndisc_build_skb(dev, daddr, src_addr, &icmp6h, solicited_addr, skb = ndisc_alloc_skb(dev, sizeof(*msg) + optlen);
inc_opt ? ND_OPT_TARGET_LL_ADDR : 0);
if (!skb) if (!skb)
return; return;
msg = (struct nd_msg *)skb_put(skb, sizeof(*msg));
*msg = (struct nd_msg) {
.icmph = {
.icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT,
.icmp6_router = router,
.icmp6_solicited = solicited,
.icmp6_override = override,
},
.target = *solicited_addr,
};
if (inc_opt)
ndisc_fill_addr_option(skb, ND_OPT_TARGET_LL_ADDR,
dev->dev_addr);
ndisc_send_skb(skb, daddr, src_addr); ndisc_send_skb(skb, daddr, src_addr);
} }
...@@ -571,9 +545,9 @@ void ndisc_send_ns(struct net_device *dev, struct neighbour *neigh, ...@@ -571,9 +545,9 @@ void ndisc_send_ns(struct net_device *dev, struct neighbour *neigh,
{ {
struct sk_buff *skb; struct sk_buff *skb;
struct in6_addr addr_buf; struct in6_addr addr_buf;
struct icmp6hdr icmp6h = { int inc_opt = dev->addr_len;
.icmp6_type = NDISC_NEIGHBOUR_SOLICITATION, int optlen = 0;
}; struct nd_msg *msg;
if (saddr == NULL) { if (saddr == NULL) {
if (ipv6_get_lladdr(dev, &addr_buf, if (ipv6_get_lladdr(dev, &addr_buf,
...@@ -582,11 +556,27 @@ void ndisc_send_ns(struct net_device *dev, struct neighbour *neigh, ...@@ -582,11 +556,27 @@ void ndisc_send_ns(struct net_device *dev, struct neighbour *neigh,
saddr = &addr_buf; saddr = &addr_buf;
} }
skb = ndisc_build_skb(dev, daddr, saddr, &icmp6h, solicit, if (ipv6_addr_any(saddr))
!ipv6_addr_any(saddr) ? ND_OPT_SOURCE_LL_ADDR : 0); inc_opt = 0;
if (inc_opt)
optlen += ndisc_opt_addr_space(dev);
skb = ndisc_alloc_skb(dev, sizeof(*msg) + optlen);
if (!skb) if (!skb)
return; return;
msg = (struct nd_msg *)skb_put(skb, sizeof(*msg));
*msg = (struct nd_msg) {
.icmph = {
.icmp6_type = NDISC_NEIGHBOUR_SOLICITATION,
},
.target = *solicit,
};
if (inc_opt)
ndisc_fill_addr_option(skb, ND_OPT_SOURCE_LL_ADDR,
dev->dev_addr);
ndisc_send_skb(skb, daddr, saddr); ndisc_send_skb(skb, daddr, saddr);
} }
...@@ -594,10 +584,9 @@ void ndisc_send_rs(struct net_device *dev, const struct in6_addr *saddr, ...@@ -594,10 +584,9 @@ void ndisc_send_rs(struct net_device *dev, const struct in6_addr *saddr,
const struct in6_addr *daddr) const struct in6_addr *daddr)
{ {
struct sk_buff *skb; struct sk_buff *skb;
struct icmp6hdr icmp6h = { struct rs_msg *msg;
.icmp6_type = NDISC_ROUTER_SOLICITATION,
};
int send_sllao = dev->addr_len; int send_sllao = dev->addr_len;
int optlen = 0;
#ifdef CONFIG_IPV6_OPTIMISTIC_DAD #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
/* /*
...@@ -621,11 +610,26 @@ void ndisc_send_rs(struct net_device *dev, const struct in6_addr *saddr, ...@@ -621,11 +610,26 @@ void ndisc_send_rs(struct net_device *dev, const struct in6_addr *saddr,
} }
} }
#endif #endif
skb = ndisc_build_skb(dev, daddr, saddr, &icmp6h, NULL, if (!dev->addr_len)
send_sllao ? ND_OPT_SOURCE_LL_ADDR : 0); send_sllao = 0;
if (send_sllao)
optlen += ndisc_opt_addr_space(dev);
skb = ndisc_alloc_skb(dev, sizeof(*msg) + optlen);
if (!skb) if (!skb)
return; return;
msg = (struct rs_msg *)skb_put(skb, sizeof(*msg));
*msg = (struct rs_msg) {
.icmph = {
.icmp6_type = NDISC_ROUTER_SOLICITATION,
},
};
if (send_sllao)
ndisc_fill_addr_option(skb, ND_OPT_SOURCE_LL_ADDR,
dev->dev_addr);
ndisc_send_skb(skb, daddr, saddr); ndisc_send_skb(skb, daddr, saddr);
} }
......
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