提交 db60eb5f 编写于 作者: J Jarno Rajahalme 提交者: David S. Miller

af_packet: Use virtio_net_hdr_to_skb().

Use the common virtio_net_hdr_to_skb() instead of open coding it.
Other call sites were changed by commit fd2a0437, but this one was
missed, maybe because it is split in two parts of the source code.

Interim comparisons of 'vnet_hdr->gso_type' still work as both the
vnet_hdr and skb notion of gso_type is zero when there is no gso.

Fixes: fd2a0437 ("virtio_net: introduce virtio_net_hdr_{from,to}_skb")
Signed-off-by: NJarno Rajahalme <jarno@ovn.org>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 9403cd7c
...@@ -2388,8 +2388,6 @@ static void tpacket_set_protocol(const struct net_device *dev, ...@@ -2388,8 +2388,6 @@ static void tpacket_set_protocol(const struct net_device *dev,
static int __packet_snd_vnet_parse(struct virtio_net_hdr *vnet_hdr, size_t len) static int __packet_snd_vnet_parse(struct virtio_net_hdr *vnet_hdr, size_t len)
{ {
unsigned short gso_type = 0;
if ((vnet_hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) && if ((vnet_hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) &&
(__virtio16_to_cpu(vio_le(), vnet_hdr->csum_start) + (__virtio16_to_cpu(vio_le(), vnet_hdr->csum_start) +
__virtio16_to_cpu(vio_le(), vnet_hdr->csum_offset) + 2 > __virtio16_to_cpu(vio_le(), vnet_hdr->csum_offset) + 2 >
...@@ -2401,29 +2399,6 @@ static int __packet_snd_vnet_parse(struct virtio_net_hdr *vnet_hdr, size_t len) ...@@ -2401,29 +2399,6 @@ static int __packet_snd_vnet_parse(struct virtio_net_hdr *vnet_hdr, size_t len)
if (__virtio16_to_cpu(vio_le(), vnet_hdr->hdr_len) > len) if (__virtio16_to_cpu(vio_le(), vnet_hdr->hdr_len) > len)
return -EINVAL; return -EINVAL;
if (vnet_hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
switch (vnet_hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
case VIRTIO_NET_HDR_GSO_TCPV4:
gso_type = SKB_GSO_TCPV4;
break;
case VIRTIO_NET_HDR_GSO_TCPV6:
gso_type = SKB_GSO_TCPV6;
break;
case VIRTIO_NET_HDR_GSO_UDP:
gso_type = SKB_GSO_UDP;
break;
default:
return -EINVAL;
}
if (vnet_hdr->gso_type & VIRTIO_NET_HDR_GSO_ECN)
gso_type |= SKB_GSO_TCP_ECN;
if (vnet_hdr->gso_size == 0)
return -EINVAL;
}
vnet_hdr->gso_type = gso_type; /* changes type, temporary storage */
return 0; return 0;
} }
...@@ -2443,27 +2418,6 @@ static int packet_snd_vnet_parse(struct msghdr *msg, size_t *len, ...@@ -2443,27 +2418,6 @@ static int packet_snd_vnet_parse(struct msghdr *msg, size_t *len,
return __packet_snd_vnet_parse(vnet_hdr, *len); return __packet_snd_vnet_parse(vnet_hdr, *len);
} }
static int packet_snd_vnet_gso(struct sk_buff *skb,
struct virtio_net_hdr *vnet_hdr)
{
if (vnet_hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
u16 s = __virtio16_to_cpu(vio_le(), vnet_hdr->csum_start);
u16 o = __virtio16_to_cpu(vio_le(), vnet_hdr->csum_offset);
if (!skb_partial_csum_set(skb, s, o))
return -EINVAL;
}
skb_shinfo(skb)->gso_size =
__virtio16_to_cpu(vio_le(), vnet_hdr->gso_size);
skb_shinfo(skb)->gso_type = vnet_hdr->gso_type;
/* Header must be checked, and gso_segs computed. */
skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY;
skb_shinfo(skb)->gso_segs = 0;
return 0;
}
static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb, static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
void *frame, struct net_device *dev, void *data, int tp_len, void *frame, struct net_device *dev, void *data, int tp_len,
__be16 proto, unsigned char *addr, int hlen, int copylen, __be16 proto, unsigned char *addr, int hlen, int copylen,
...@@ -2723,7 +2677,8 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg) ...@@ -2723,7 +2677,8 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
} }
} }
if (po->has_vnet_hdr && packet_snd_vnet_gso(skb, vnet_hdr)) { if (po->has_vnet_hdr && virtio_net_hdr_to_skb(skb, vnet_hdr,
vio_le())) {
tp_len = -EINVAL; tp_len = -EINVAL;
goto tpacket_error; goto tpacket_error;
} }
...@@ -2914,7 +2869,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len) ...@@ -2914,7 +2869,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
packet_pick_tx_queue(dev, skb); packet_pick_tx_queue(dev, skb);
if (po->has_vnet_hdr) { if (po->has_vnet_hdr) {
err = packet_snd_vnet_gso(skb, &vnet_hdr); err = virtio_net_hdr_to_skb(skb, &vnet_hdr, vio_le());
if (err) if (err)
goto out_free; goto out_free;
len += sizeof(vnet_hdr); len += sizeof(vnet_hdr);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册