提交 f7053b6c 编写于 作者: J Jason Wang 提交者: David S. Miller

tuntap: simplify error handling in tun_build_skb()

There's no need to duplicate page get logic in each action. So this
patch tries to get page and calculate the offset before processing XDP
actions (except for XDP_DROP), and undo them when meet errors (we
don't care the performance on errors). This will be used for factoring
out XDP logic.
Signed-off-by: NJason Wang <jasowang@redhat.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 291aeb2b
...@@ -1701,17 +1701,13 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun, ...@@ -1701,17 +1701,13 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
xdp_do_flush_map(); xdp_do_flush_map();
if (err) if (err)
goto err_redirect; goto err_redirect;
rcu_read_unlock(); goto out;
local_bh_enable();
return NULL;
case XDP_TX: case XDP_TX:
get_page(alloc_frag->page); get_page(alloc_frag->page);
alloc_frag->offset += buflen; alloc_frag->offset += buflen;
if (tun_xdp_tx(tun->dev, &xdp) < 0) if (tun_xdp_tx(tun->dev, &xdp) < 0)
goto err_redirect; goto err_redirect;
rcu_read_unlock(); goto out;
local_bh_enable();
return NULL;
case XDP_PASS: case XDP_PASS:
delta = orig_data - xdp.data; delta = orig_data - xdp.data;
len = xdp.data_end - xdp.data; len = xdp.data_end - xdp.data;
...@@ -1742,7 +1738,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun, ...@@ -1742,7 +1738,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
err_redirect: err_redirect:
put_page(alloc_frag->page); put_page(alloc_frag->page);
err_xdp: out:
rcu_read_unlock(); rcu_read_unlock();
local_bh_enable(); local_bh_enable();
this_cpu_inc(tun->pcpu_stats->rx_dropped); this_cpu_inc(tun->pcpu_stats->rx_dropped);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册