aboutsummaryrefslogtreecommitdiffstats
path: root/net/packet/af_packet.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2011-11-17 21:20:04 -0500
committerDavid S. Miller <davem@davemloft.net>2011-11-18 14:37:09 -0500
commitae641949df01b85117845bec45328eab6d6fada1 (patch)
treeed8d5aedd678f86e8554dc0b1c080a43ef4b331d /net/packet/af_packet.c
parenta7ae1992248e5cf9dc5bd35695ab846d27efe15f (diff)
net: Remove all uses of LL_ALLOCATED_SPACE
net: 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 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: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/packet/af_packet.c')
-rw-r--r--net/packet/af_packet.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 82a6f34d39d..71c1a7521d3 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1944,7 +1944,7 @@ static void tpacket_destruct_skb(struct sk_buff *skb)
1944 1944
1945static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb, 1945static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
1946 void *frame, struct net_device *dev, int size_max, 1946 void *frame, struct net_device *dev, int size_max,
1947 __be16 proto, unsigned char *addr) 1947 __be16 proto, unsigned char *addr, int hlen)
1948{ 1948{
1949 union { 1949 union {
1950 struct tpacket_hdr *h1; 1950 struct tpacket_hdr *h1;
@@ -1978,7 +1978,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
1978 return -EMSGSIZE; 1978 return -EMSGSIZE;
1979 } 1979 }
1980 1980
1981 skb_reserve(skb, LL_RESERVED_SPACE(dev)); 1981 skb_reserve(skb, hlen);
1982 skb_reset_network_header(skb); 1982 skb_reset_network_header(skb);
1983 1983
1984 data = ph.raw + po->tp_hdrlen - sizeof(struct sockaddr_ll); 1984 data = ph.raw + po->tp_hdrlen - sizeof(struct sockaddr_ll);
@@ -2053,6 +2053,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
2053 unsigned char *addr; 2053 unsigned char *addr;
2054 int len_sum = 0; 2054 int len_sum = 0;
2055 int status = 0; 2055 int status = 0;
2056 int hlen, tlen;
2056 2057
2057 mutex_lock(&po->pg_vec_lock); 2058 mutex_lock(&po->pg_vec_lock);
2058 2059
@@ -2101,16 +2102,17 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
2101 } 2102 }
2102 2103
2103 status = TP_STATUS_SEND_REQUEST; 2104 status = TP_STATUS_SEND_REQUEST;
2105 hlen = LL_RESERVED_SPACE(dev);
2106 tlen = dev->needed_tailroom;
2104 skb = sock_alloc_send_skb(&po->sk, 2107 skb = sock_alloc_send_skb(&po->sk,
2105 LL_ALLOCATED_SPACE(dev) 2108 hlen + tlen + sizeof(struct sockaddr_ll),
2106 + sizeof(struct sockaddr_ll),
2107 0, &err); 2109 0, &err);
2108 2110
2109 if (unlikely(skb == NULL)) 2111 if (unlikely(skb == NULL))
2110 goto out_status; 2112 goto out_status;
2111 2113
2112 tp_len = tpacket_fill_skb(po, skb, ph, dev, size_max, proto, 2114 tp_len = tpacket_fill_skb(po, skb, ph, dev, size_max, proto,
2113 addr); 2115 addr, hlen);
2114 2116
2115 if (unlikely(tp_len < 0)) { 2117 if (unlikely(tp_len < 0)) {
2116 if (po->tp_loss) { 2118 if (po->tp_loss) {
@@ -2207,6 +2209,7 @@ static int packet_snd(struct socket *sock,
2207 int vnet_hdr_len; 2209 int vnet_hdr_len;
2208 struct packet_sock *po = pkt_sk(sk); 2210 struct packet_sock *po = pkt_sk(sk);
2209 unsigned short gso_type = 0; 2211 unsigned short gso_type = 0;
2212 int hlen, tlen;
2210 2213
2211 /* 2214 /*
2212 * Get and verify the address. 2215 * Get and verify the address.
@@ -2291,8 +2294,9 @@ static int packet_snd(struct socket *sock,
2291 goto out_unlock; 2294 goto out_unlock;
2292 2295
2293 err = -ENOBUFS; 2296 err = -ENOBUFS;
2294 skb = packet_alloc_skb(sk, LL_ALLOCATED_SPACE(dev), 2297 hlen = LL_RESERVED_SPACE(dev);
2295 LL_RESERVED_SPACE(dev), len, vnet_hdr.hdr_len, 2298 tlen = dev->needed_tailroom;
2299 skb = packet_alloc_skb(sk, hlen + tlen, hlen, len, vnet_hdr.hdr_len,
2296 msg->msg_flags & MSG_DONTWAIT, &err); 2300 msg->msg_flags & MSG_DONTWAIT, &err);
2297 if (skb == NULL) 2301 if (skb == NULL)
2298 goto out_unlock; 2302 goto out_unlock;