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

ndisc: Introduce ndisc_alloc_skb() helper.

Signed-off-by: default avatarYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9c86dafe
...@@ -366,6 +366,29 @@ static void pndisc_destructor(struct pneigh_entry *n) ...@@ -366,6 +366,29 @@ static void pndisc_destructor(struct pneigh_entry *n)
ipv6_dev_mc_dec(dev, &maddr); ipv6_dev_mc_dec(dev, &maddr);
} }
static struct sk_buff *ndisc_alloc_skb(struct net_device *dev,
int len)
{
int hlen = LL_RESERVED_SPACE(dev);
int tlen = dev->needed_tailroom;
struct sock *sk = dev_net(dev)->ipv6.ndisc_sk;
struct sk_buff *skb;
int err;
skb = sock_alloc_send_skb(sk,
hlen + sizeof(struct ipv6hdr) + len + tlen,
1, &err);
if (!skb) {
ND_PRINTK(0, err, "ndisc: %s failed to allocate an skb, err=%d\n",
__func__, err);
return NULL;
}
skb_reserve(skb, hlen);
return skb;
}
static struct sk_buff *ndisc_build_skb(struct net_device *dev, static struct sk_buff *ndisc_build_skb(struct net_device *dev,
const struct in6_addr *daddr, const struct in6_addr *daddr,
const struct in6_addr *saddr, const struct in6_addr *saddr,
...@@ -377,10 +400,7 @@ static struct sk_buff *ndisc_build_skb(struct net_device *dev, ...@@ -377,10 +400,7 @@ static struct sk_buff *ndisc_build_skb(struct net_device *dev,
struct sock *sk = net->ipv6.ndisc_sk; struct sock *sk = net->ipv6.ndisc_sk;
struct sk_buff *skb; struct sk_buff *skb;
struct icmp6hdr *hdr; struct icmp6hdr *hdr;
int hlen = LL_RESERVED_SPACE(dev);
int tlen = dev->needed_tailroom;
int len; int len;
int err;
u8 *opt; u8 *opt;
if (!dev->addr_len) if (!dev->addr_len)
...@@ -390,17 +410,10 @@ static struct sk_buff *ndisc_build_skb(struct net_device *dev, ...@@ -390,17 +410,10 @@ static struct sk_buff *ndisc_build_skb(struct net_device *dev,
if (llinfo) if (llinfo)
len += ndisc_opt_addr_space(dev); len += ndisc_opt_addr_space(dev);
skb = sock_alloc_send_skb(sk, skb = ndisc_alloc_skb(dev, len);
(sizeof(struct ipv6hdr) + if (!skb)
len + hlen + tlen),
1, &err);
if (!skb) {
ND_PRINTK(0, err, "ND: %s failed to allocate an skb, err=%d\n",
__func__, err);
return NULL; return NULL;
}
skb_reserve(skb, hlen);
ip6_nd_hdr(sk, skb, dev, saddr, daddr, IPPROTO_ICMPV6, len); ip6_nd_hdr(sk, skb, dev, saddr, daddr, IPPROTO_ICMPV6, len);
skb->transport_header = skb->tail; skb->transport_header = skb->tail;
...@@ -1369,7 +1382,6 @@ void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target) ...@@ -1369,7 +1382,6 @@ void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target)
struct inet6_dev *idev; struct inet6_dev *idev;
struct flowi6 fl6; struct flowi6 fl6;
u8 *opt; u8 *opt;
int hlen, tlen;
int rd_len; int rd_len;
int err; int err;
u8 ha_buf[MAX_ADDR_LEN], *ha = NULL; u8 ha_buf[MAX_ADDR_LEN], *ha = NULL;
...@@ -1439,20 +1451,10 @@ void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target) ...@@ -1439,20 +1451,10 @@ void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target)
rd_len &= ~0x7; rd_len &= ~0x7;
len += rd_len; len += rd_len;
hlen = LL_RESERVED_SPACE(dev); buff = ndisc_alloc_skb(dev, len);
tlen = dev->needed_tailroom; if (!buff)
buff = sock_alloc_send_skb(sk,
(sizeof(struct ipv6hdr) +
len + hlen + tlen),
1, &err);
if (buff == NULL) {
ND_PRINTK(0, err,
"Redirect: %s failed to allocate an skb, err=%d\n",
__func__, err);
goto release; goto release;
}
skb_reserve(buff, hlen);
ip6_nd_hdr(sk, buff, dev, &saddr_buf, &ipv6_hdr(skb)->saddr, ip6_nd_hdr(sk, buff, dev, &saddr_buf, &ipv6_hdr(skb)->saddr,
IPPROTO_ICMPV6, len); IPPROTO_ICMPV6, len);
......
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