Skip to content

Commit 0c9f227

Browse files
vaverindavem330
authored andcommitted
ipv6: use skb_expand_head in ip6_xmit
Unlike skb_realloc_headroom, new helper skb_expand_head does not allocate a new skb if possible. Additionally this patch replaces commonly used dereferencing with variables. Signed-off-by: Vasily Averin <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e415ed3 commit 0c9f227

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

net/ipv6/ip6_output.c

+11-16
Original file line numberDiff line numberDiff line change
@@ -249,29 +249,25 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
249249
const struct ipv6_pinfo *np = inet6_sk(sk);
250250
struct in6_addr *first_hop = &fl6->daddr;
251251
struct dst_entry *dst = skb_dst(skb);
252+
struct net_device *dev = dst->dev;
253+
struct inet6_dev *idev = ip6_dst_idev(dst);
252254
unsigned int head_room;
253255
struct ipv6hdr *hdr;
254256
u8 proto = fl6->flowi6_proto;
255257
int seg_len = skb->len;
256258
int hlimit = -1;
257259
u32 mtu;
258260

259-
head_room = sizeof(struct ipv6hdr) + LL_RESERVED_SPACE(dst->dev);
261+
head_room = sizeof(struct ipv6hdr) + LL_RESERVED_SPACE(dev);
260262
if (opt)
261263
head_room += opt->opt_nflen + opt->opt_flen;
262264

263-
if (unlikely(skb_headroom(skb) < head_room)) {
264-
struct sk_buff *skb2 = skb_realloc_headroom(skb, head_room);
265-
if (!skb2) {
266-
IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
267-
IPSTATS_MIB_OUTDISCARDS);
268-
kfree_skb(skb);
265+
if (unlikely(head_room > skb_headroom(skb))) {
266+
skb = skb_expand_head(skb, head_room);
267+
if (!skb) {
268+
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS);
269269
return -ENOBUFS;
270270
}
271-
if (skb->sk)
272-
skb_set_owner_w(skb2, skb->sk);
273-
consume_skb(skb);
274-
skb = skb2;
275271
}
276272

277273
if (opt) {
@@ -313,8 +309,7 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
313309

314310
mtu = dst_mtu(dst);
315311
if ((skb->len <= mtu) || skb->ignore_df || skb_is_gso(skb)) {
316-
IP6_UPD_PO_STATS(net, ip6_dst_idev(skb_dst(skb)),
317-
IPSTATS_MIB_OUT, skb->len);
312+
IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_OUT, skb->len);
318313

319314
/* if egress device is enslaved to an L3 master device pass the
320315
* skb to its handler for processing
@@ -327,17 +322,17 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
327322
* we promote our socket to non const
328323
*/
329324
return NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT,
330-
net, (struct sock *)sk, skb, NULL, dst->dev,
325+
net, (struct sock *)sk, skb, NULL, dev,
331326
dst_output);
332327
}
333328

334-
skb->dev = dst->dev;
329+
skb->dev = dev;
335330
/* ipv6_local_error() does not require socket lock,
336331
* we promote our socket to non const
337332
*/
338333
ipv6_local_error((struct sock *)sk, EMSGSIZE, fl6, mtu);
339334

340-
IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_FRAGFAILS);
335+
IP6_INC_STATS(net, idev, IPSTATS_MIB_FRAGFAILS);
341336
kfree_skb(skb);
342337
return -EMSGSIZE;
343338
}

0 commit comments

Comments
 (0)