Commit a1e975e1 authored by Vasily Averin's avatar Vasily Averin Committed by David S. Miller

bpf: use skb_expand_head in bpf_out_neigh_v4/6

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: default avatarVasily Averin <vvs@virtuozzo.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 53744a4a
...@@ -2180,18 +2180,10 @@ static int bpf_out_neigh_v6(struct net *net, struct sk_buff *skb, ...@@ -2180,18 +2180,10 @@ static int bpf_out_neigh_v6(struct net *net, struct sk_buff *skb,
skb->tstamp = 0; skb->tstamp = 0;
if (unlikely(skb_headroom(skb) < hh_len && dev->header_ops)) { if (unlikely(skb_headroom(skb) < hh_len && dev->header_ops)) {
struct sk_buff *skb2; skb = skb_expand_head(skb, hh_len);
if (!skb)
skb2 = skb_realloc_headroom(skb, hh_len);
if (unlikely(!skb2)) {
kfree_skb(skb);
return -ENOMEM; return -ENOMEM;
} }
if (skb->sk)
skb_set_owner_w(skb2, skb->sk);
consume_skb(skb);
skb = skb2;
}
rcu_read_lock_bh(); rcu_read_lock_bh();
if (!nh) { if (!nh) {
...@@ -2214,8 +2206,7 @@ static int bpf_out_neigh_v6(struct net *net, struct sk_buff *skb, ...@@ -2214,8 +2206,7 @@ static int bpf_out_neigh_v6(struct net *net, struct sk_buff *skb,
} }
rcu_read_unlock_bh(); rcu_read_unlock_bh();
if (dst) if (dst)
IP6_INC_STATS(dev_net(dst->dev), IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_OUTNOROUTES);
ip6_dst_idev(dst), IPSTATS_MIB_OUTNOROUTES);
out_drop: out_drop:
kfree_skb(skb); kfree_skb(skb);
return -ENETDOWN; return -ENETDOWN;
...@@ -2287,18 +2278,10 @@ static int bpf_out_neigh_v4(struct net *net, struct sk_buff *skb, ...@@ -2287,18 +2278,10 @@ static int bpf_out_neigh_v4(struct net *net, struct sk_buff *skb,
skb->tstamp = 0; skb->tstamp = 0;
if (unlikely(skb_headroom(skb) < hh_len && dev->header_ops)) { if (unlikely(skb_headroom(skb) < hh_len && dev->header_ops)) {
struct sk_buff *skb2; skb = skb_expand_head(skb, hh_len);
if (!skb)
skb2 = skb_realloc_headroom(skb, hh_len);
if (unlikely(!skb2)) {
kfree_skb(skb);
return -ENOMEM; return -ENOMEM;
} }
if (skb->sk)
skb_set_owner_w(skb2, skb->sk);
consume_skb(skb);
skb = skb2;
}
rcu_read_lock_bh(); rcu_read_lock_bh();
if (!nh) { if (!nh) {
......
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