Commit 66088243 authored by Herbert Xu's avatar Herbert Xu Committed by David S. Miller

ipv4: Remove all uses of LL_ALLOCATED_SPACE

ipv4: Remove all uses of LL_ALLOCATED_SPACE

The macro LL_ALLOCATED_SPACE was ill-conceived.  It applies the
alignment to the sum of needed_headroom and needed_tailroom.  As
the amount that is then reserved for head room is needed_headroom
with alignment, this means that the tail room left may be too small.

This patch replaces all uses of LL_ALLOCATED_SPACE in net/ipv4
with the macro LL_RESERVED_SPACE and direct reference to
needed_tailroom.

This also fixes the problem with needed_headroom changing between
allocating the skb and reserving the head room.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 505a467b
...@@ -592,16 +592,18 @@ struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip, ...@@ -592,16 +592,18 @@ struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
struct sk_buff *skb; struct sk_buff *skb;
struct arphdr *arp; struct arphdr *arp;
unsigned char *arp_ptr; unsigned char *arp_ptr;
int hlen = LL_RESERVED_SPACE(dev);
int tlen = dev->needed_tailroom;
/* /*
* Allocate a buffer * Allocate a buffer
*/ */
skb = alloc_skb(arp_hdr_len(dev) + LL_ALLOCATED_SPACE(dev), GFP_ATOMIC); skb = alloc_skb(arp_hdr_len(dev) + hlen + tlen, GFP_ATOMIC);
if (skb == NULL) if (skb == NULL)
return NULL; return NULL;
skb_reserve(skb, LL_RESERVED_SPACE(dev)); skb_reserve(skb, hlen);
skb_reset_network_header(skb); skb_reset_network_header(skb);
arp = (struct arphdr *) skb_put(skb, arp_hdr_len(dev)); arp = (struct arphdr *) skb_put(skb, arp_hdr_len(dev));
skb->dev = dev; skb->dev = dev;
......
...@@ -304,9 +304,11 @@ static struct sk_buff *igmpv3_newpack(struct net_device *dev, int size) ...@@ -304,9 +304,11 @@ static struct sk_buff *igmpv3_newpack(struct net_device *dev, int size)
struct igmpv3_report *pig; struct igmpv3_report *pig;
struct net *net = dev_net(dev); struct net *net = dev_net(dev);
struct flowi4 fl4; struct flowi4 fl4;
int hlen = LL_RESERVED_SPACE(dev);
int tlen = dev->needed_tailroom;
while (1) { while (1) {
skb = alloc_skb(size + LL_ALLOCATED_SPACE(dev), skb = alloc_skb(size + hlen + tlen,
GFP_ATOMIC | __GFP_NOWARN); GFP_ATOMIC | __GFP_NOWARN);
if (skb) if (skb)
break; break;
...@@ -327,7 +329,7 @@ static struct sk_buff *igmpv3_newpack(struct net_device *dev, int size) ...@@ -327,7 +329,7 @@ static struct sk_buff *igmpv3_newpack(struct net_device *dev, int size)
skb_dst_set(skb, &rt->dst); skb_dst_set(skb, &rt->dst);
skb->dev = dev; skb->dev = dev;
skb_reserve(skb, LL_RESERVED_SPACE(dev)); skb_reserve(skb, hlen);
skb_reset_network_header(skb); skb_reset_network_header(skb);
pip = ip_hdr(skb); pip = ip_hdr(skb);
...@@ -647,6 +649,7 @@ static int igmp_send_report(struct in_device *in_dev, struct ip_mc_list *pmc, ...@@ -647,6 +649,7 @@ static int igmp_send_report(struct in_device *in_dev, struct ip_mc_list *pmc,
__be32 group = pmc ? pmc->multiaddr : 0; __be32 group = pmc ? pmc->multiaddr : 0;
struct flowi4 fl4; struct flowi4 fl4;
__be32 dst; __be32 dst;
int hlen, tlen;
if (type == IGMPV3_HOST_MEMBERSHIP_REPORT) if (type == IGMPV3_HOST_MEMBERSHIP_REPORT)
return igmpv3_send_report(in_dev, pmc); return igmpv3_send_report(in_dev, pmc);
...@@ -661,7 +664,9 @@ static int igmp_send_report(struct in_device *in_dev, struct ip_mc_list *pmc, ...@@ -661,7 +664,9 @@ static int igmp_send_report(struct in_device *in_dev, struct ip_mc_list *pmc,
if (IS_ERR(rt)) if (IS_ERR(rt))
return -1; return -1;
skb = alloc_skb(IGMP_SIZE+LL_ALLOCATED_SPACE(dev), GFP_ATOMIC); hlen = LL_RESERVED_SPACE(dev);
tlen = dev->needed_tailroom;
skb = alloc_skb(IGMP_SIZE + hlen + tlen, GFP_ATOMIC);
if (skb == NULL) { if (skb == NULL) {
ip_rt_put(rt); ip_rt_put(rt);
return -1; return -1;
...@@ -669,7 +674,7 @@ static int igmp_send_report(struct in_device *in_dev, struct ip_mc_list *pmc, ...@@ -669,7 +674,7 @@ static int igmp_send_report(struct in_device *in_dev, struct ip_mc_list *pmc,
skb_dst_set(skb, &rt->dst); skb_dst_set(skb, &rt->dst);
skb_reserve(skb, LL_RESERVED_SPACE(dev)); skb_reserve(skb, hlen);
skb_reset_network_header(skb); skb_reset_network_header(skb);
iph = ip_hdr(skb); iph = ip_hdr(skb);
......
...@@ -763,13 +763,15 @@ static void __init ic_bootp_send_if(struct ic_device *d, unsigned long jiffies_d ...@@ -763,13 +763,15 @@ static void __init ic_bootp_send_if(struct ic_device *d, unsigned long jiffies_d
struct sk_buff *skb; struct sk_buff *skb;
struct bootp_pkt *b; struct bootp_pkt *b;
struct iphdr *h; struct iphdr *h;
int hlen = LL_RESERVED_SPACE(dev);
int tlen = dev->needed_tailroom;
/* Allocate packet */ /* Allocate packet */
skb = alloc_skb(sizeof(struct bootp_pkt) + LL_ALLOCATED_SPACE(dev) + 15, skb = alloc_skb(sizeof(struct bootp_pkt) + hlen + tlen + 15,
GFP_KERNEL); GFP_KERNEL);
if (!skb) if (!skb)
return; return;
skb_reserve(skb, LL_RESERVED_SPACE(dev)); skb_reserve(skb, hlen);
b = (struct bootp_pkt *) skb_put(skb, sizeof(struct bootp_pkt)); b = (struct bootp_pkt *) skb_put(skb, sizeof(struct bootp_pkt));
memset(b, 0, sizeof(struct bootp_pkt)); memset(b, 0, sizeof(struct bootp_pkt));
......
...@@ -328,6 +328,7 @@ static int raw_send_hdrinc(struct sock *sk, struct flowi4 *fl4, ...@@ -328,6 +328,7 @@ static int raw_send_hdrinc(struct sock *sk, struct flowi4 *fl4,
unsigned int iphlen; unsigned int iphlen;
int err; int err;
struct rtable *rt = *rtp; struct rtable *rt = *rtp;
int hlen, tlen;
if (length > rt->dst.dev->mtu) { if (length > rt->dst.dev->mtu) {
ip_local_error(sk, EMSGSIZE, fl4->daddr, inet->inet_dport, ip_local_error(sk, EMSGSIZE, fl4->daddr, inet->inet_dport,
...@@ -337,12 +338,14 @@ static int raw_send_hdrinc(struct sock *sk, struct flowi4 *fl4, ...@@ -337,12 +338,14 @@ static int raw_send_hdrinc(struct sock *sk, struct flowi4 *fl4,
if (flags&MSG_PROBE) if (flags&MSG_PROBE)
goto out; goto out;
hlen = LL_RESERVED_SPACE(rt->dst.dev);
tlen = rt->dst.dev->needed_tailroom;
skb = sock_alloc_send_skb(sk, skb = sock_alloc_send_skb(sk,
length + LL_ALLOCATED_SPACE(rt->dst.dev) + 15, length + hlen + tlen + 15,
flags & MSG_DONTWAIT, &err); flags & MSG_DONTWAIT, &err);
if (skb == NULL) if (skb == NULL)
goto error; goto error;
skb_reserve(skb, LL_RESERVED_SPACE(rt->dst.dev)); skb_reserve(skb, hlen);
skb->priority = sk->sk_priority; skb->priority = sk->sk_priority;
skb->mark = sk->sk_mark; skb->mark = sk->sk_mark;
......
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