net: accept UFO datagrams from tuntap and packet
Subsystems (8)
Willem de Bruijn
maintainerPATCH v2 1/1 net: accept UFO datagrams from tuntap and packet
From: Willem de Bruijn <[email protected]>
Tuntap and similar devices can inject GSO packets. Accept type VIRTIO_NET_HDR_GSO_UDP, even though not generating UFO natively.
Processes are expected to use feature negotiation such as TUNSETOFFLOAD to detect supported offload types and refrain from injecting other packets. This process breaks down with live migration: guest kernels do not renegotiate flags, so destination hosts need to expose all features that the source host does.
Partially revert the UFO removal from 182e0b6b5846~1..d9d30adf5677. This patch introduces nearly(*) no new code to simplify verification. It brings back verbatim tuntap UFO negotiation, VIRTIO_NET_HDR_GSO_UDP insertion and software UFO segmentation.
It does not reinstate protocol stack support, hardware offload (NETIF_F_UFO), SKB_GSO_UDP tunneling in SKB_GSO_SOFTWARE or reception of VIRTIO_NET_HDR_GSO_UDP packets in tuntap.
To support SKB_GSO_UDP reappearing in the stack, also reinstate logic in act_csum and openvswitch. Achieve equivalence with v4.13 HEAD by squashing in commit 939912216fa8 ("net: skb_needs_check() removes CHECKSUM_UNNECESSARY check for tx.") and reverting commit 8d63bee643f1 ("net: avoid skb_warn_bad_offload false positives on UFO").
(*) To avoid having to bring back skb_shinfo(skb)->ip6_frag_id, ipv6_proxy_select_ident is changed to return a __be32 and this is assigned directly to the frag_hdr. Also, SKB_GSO_UDP is inserted at the end of the enum to minimize code churn.
Tested
Booted a v4.13 guest kernel with QEMU. On a host kernel before this patch ethtool -k eth0 shows UFO disabled. After the patch, it is enabled, same as on a v4.13 host kernel.
A UFO packet sent from the guest appears on the tap device:
host:
nc -l -p -u 8000 &
tcpdump -n -i tap0
guest:
dd if=/dev/zero of=payload.txt bs=1 count=2000
nc -u 192.16.1.1 8000 < payload.txt Direct tap to tap transmission of VIRTIO_NET_HDR_GSO_UDP succeeds, packets arriving fragmented:
./with_tap_pair.sh ./tap_send_ufo tap0 tap1
(from https://github.com/wdebruij/kerneltools/tree/master/tests)Changes
v1 -> v2
- simplified set_offload change (review comment)
- documented test procedure
--- drivers/net/tap.c | 2 +- drivers/net/tun.c | 2 + include/linux/netdev_features.h | 4 +- include/linux/netdevice.h | 1 + include/linux/skbuff.h | 2 + include/linux/virtio_net.h | 5 ++- include/net/ipv6.h | 1 + net/core/dev.c | 3 +- net/ipv4/af_inet.c | 12 +++++- net/ipv4/udp_offload.c | 49 ++++++++++++++++++++++-- net/ipv6/output_core.c | 31 +++++++++++++++ net/ipv6/udp_offload.c | 85 +++++++++++++++++++++++++++++++++++++++-- net/openvswitch/datapath.c | 14 +++++++ net/openvswitch/flow.c | 6 ++- net/sched/act_csum.c | 6 +++ 15 files changed, 209 insertions(+), 14 deletions(-)
drivers/net/tap.c +1 -1
@@ -1077,7 +1077,7 @@ static long tap_ioctl(struct file *file, unsigned int cmd,case TUNSETOFFLOAD :/* let the user check for future flags */ if (arg & ~(TUN_F_CSUM |TUN_F_TSO4 |TUN_F_TSO6 | -TUN_F_TSO_ECN )) +TUN_F_TSO_ECN |TUN_F_UFO ))return -EINVAL ;rtnl_lock ();
drivers/net/tun.c +2 -0
@@ -2369,6 +2369,8 @@ static int set_offload(struct tun_struct *tun, unsigned long arg) features |=NETIF_F_TSO6 ; arg &= ~(TUN_F_TSO4 |TUN_F_TSO6 ); } + + arg &= ~TUN_F_UFO ; }/* This gives the user a way to test for new features in future by
include/linux/netdev_features.h +3 -1
@@ -54,8 +54,9 @@ enum {NETIF_F_GSO_TUNNEL_REMCSUM_BIT ,/* ... TUNNEL with TSO & REMCSUM */ NETIF_F_GSO_SCTP_BIT ,/* ... SCTP fragmentation */ NETIF_F_GSO_ESP_BIT ,/* ... ESP with TSO */ +NETIF_F_GSO_UDP_BIT ,/* ... UFO, deprecated except tuntap */ /**/ NETIF_F_GSO_LAST =/* last bit, see GSO_MASK */ -NETIF_F_GSO_ESP_BIT , +NETIF_F_GSO_UDP_BIT ,NETIF_F_FCOE_CRC_BIT ,/* FCoE CRC32 */ NETIF_F_SCTP_CRC_BIT, /* SCTP checksum offload */
@@ -132,6 +133,7 @@ enum {#define NETIF_F_GSO_TUNNEL_REMCSUM __NETIF_F(GSO_TUNNEL_REMCSUM)#define NETIF_F_GSO_SCTP __NETIF_F(GSO_SCTP)#define NETIF_F_GSO_ESP __NETIF_F(GSO_ESP) +#define NETIF_F_GSO_UDP __NETIF_F(GSO_UDP)#define NETIF_F_HW_VLAN_STAG_FILTER __NETIF_F(HW_VLAN_STAG_FILTER)#define NETIF_F_HW_VLAN_STAG_RX __NETIF_F(HW_VLAN_STAG_RX)#define NETIF_F_HW_VLAN_STAG_TX __NETIF_F(HW_VLAN_STAG_TX)
include/linux/netdevice.h +1 -0
@@ -4140,6 +4140,7 @@ static inline bool net_gso_ok(netdev_features_t features, int gso_type)BUILD_BUG_ON (SKB_GSO_TUNNEL_REMCSUM != (NETIF_F_GSO_TUNNEL_REMCSUM >>NETIF_F_GSO_SHIFT ));BUILD_BUG_ON (SKB_GSO_SCTP != (NETIF_F_GSO_SCTP >>NETIF_F_GSO_SHIFT ));BUILD_BUG_ON (SKB_GSO_ESP != (NETIF_F_GSO_ESP >>NETIF_F_GSO_SHIFT )); +BUILD_BUG_ON (SKB_GSO_UDP != (NETIF_F_GSO_UDP >>NETIF_F_GSO_SHIFT ));return (features & feature) == feature; }
include/linux/skbuff.h +2 -0
@@ -569,6 +569,8 @@ enum {SKB_GSO_SCTP =1 <<14 ,SKB_GSO_ESP =1 <<15 , + + SKB_GSO_UDP = 1 << 16, };#if BITS_PER_LONG >32
include/linux/virtio_net.h +4 -1
@@ -9,7 +9,7 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,const struct virtio_net_hdr *hdr, bool little_endian) { - unsigned short gso_type = 0; + unsigned int gso_type = 0;if (hdr->gso_type !=VIRTIO_NET_HDR_GSO_NONE ) {switch (hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN ) {
@@ -19,6 +19,9 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,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 ; }
include/net/ipv6.h +1 -0
@@ -767,6 +767,7 @@ static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_add__be32 ipv6_select_ident (struct net *net,const struct in6_addr *daddr,const struct in6_addr *saddr); +__be32 ipv6_proxy_select_ident (struct net *net,struct sk_buff *skb);int ip6_dst_hoplimit (struct dst_entry *dst);
net/core/dev.c +2 -1
@@ -2746,7 +2746,8 @@ EXPORT_SYMBOL(skb_mac_gso_segment);static inline bool skb_needs_check (struct sk_buff *skb,bool tx_path) {if (tx_path) -return skb->ip_summed !=CHECKSUM_PARTIAL ; +return skb->ip_summed !=CHECKSUM_PARTIAL && + skb->ip_summed !=CHECKSUM_UNNECESSARY ;return skb->ip_summed ==CHECKSUM_NONE ; }
net/ipv4/af_inet.c +10 -2
@@ -1223,9 +1223,10 @@ EXPORT_SYMBOL(inet_sk_rebuild_header);struct sk_buff *inet_gso_segment (struct sk_buff *skb,netdev_features_t features) { -bool fixedid = false, gso_partial, encap; +bool udpfrag = false, fixedid = false, gso_partial, encap;struct sk_buff *segs =ERR_PTR (-EINVAL );const struct net_offload *ops; +unsigned int offset =0 ;struct iphdr *iph;int proto, tot_len;int nhoff;
@@ -1260,6 +1261,7 @@ struct sk_buff *inet_gso_segment(struct sk_buff *skb, segs =ERR_PTR (-EPROTONOSUPPORT );if (!skb->encapsulation || encap) { + udpfrag = !!(skb_shinfo (skb)->gso_type &SKB_GSO_UDP ); fixedid = !!(skb_shinfo (skb)->gso_type &SKB_GSO_TCP_FIXEDID );/* fixed ID is invalid if DF bit is not set */
@@ -1279,7 +1281,13 @@ struct sk_buff *inet_gso_segment(struct sk_buff *skb, skb = segs; do { iph = (struct iphdr *)(skb_mac_header(skb) + nhoff); - if (skb_is_gso(skb)) { + if (udpfrag) { + iph->frag_off = htons(offset >> 3); + if (skb->next) + iph->frag_off |= htons(IP_MF); + offset += skb->len - nhoff - ihl; + tot_len = skb->len - nhoff; + } else if (skb_is_gso(skb)) { if (!fixedid) { iph->id = htons(id); id += skb_shinfo(skb)->gso_segs;
net/ipv4/udp_offload.c +45 -4
68 lines not on this page · raw message
net/ipv6/output_core.c +31 -0
@@ -31,6 +31,37 @@ static u32 __ipv6_select_ident(struct net *net, u32 hashrnd,return id; } +/* This function exists only for tap drivers that must support broken +* clients requesting UFO without specifying an IPv6 fragment ID. +* +* This is similar to ipv6_select_ident() but we use an independent hash +* seed to limit information leakage. +* +* The network header must be set before calling this. +*/ +__be32 ipv6_proxy_select_ident (struct net *net,struct sk_buff *skb) +{ +static u32 ip6_proxy_idents_hashrnd__read_mostly ; +struct in6_addr buf[2 ]; +struct in6_addr *addrs; +u32 id; + + addrs =skb_header_pointer (skb, +skb_network_offset (skb) + + offsetof(struct ipv6hdr , saddr), +sizeof (buf), buf); +if (!addrs) +return 0 ; + +net_get_random_once (&ip6_proxy_idents_hashrnd, +sizeof (ip6_proxy_idents_hashrnd)); + + id =__ipv6_select_ident (net, ip6_proxy_idents_hashrnd, + &addrs[1 ], &addrs[0 ]); +return htonl (id); +} +EXPORT_SYMBOL_GPL (ipv6_proxy_select_ident); +__be32 ipv6_select_ident (struct net *net,const struct in6_addr *daddr,const struct in6_addr *saddr)
net/ipv6/udp_offload.c +82 -3
104 lines not on this page · raw message
net/openvswitch/datapath.c +14 -0
@@ -308,6 +308,8 @@ static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb,const struct dp_upcall_info *upcall_info, uint32_t cutlen) { + unsigned short gso_type = skb_shinfo(skb)->gso_type; +struct sw_flow_key later_key;struct sk_buff *segs, *nskb;int err;
@@ -318,9 +320,21 @@ static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb,if (segs ==NULL )return -EINVAL ; +if (gso_type &SKB_GSO_UDP ) { +/* The initial flow key extracted by ovs_flow_key_extract() +* in this case is for a first fragment, so we need to +* properly mark later fragments. +*/ + later_key = *key; + later_key.ip.frag =OVS_FRAG_TYPE_LATER ; + } +/* Queue all of the segments. */ skb = segs; do { + if (gso_type & SKB_GSO_UDP && skb != segs) + key = &later_key; + err = queue_userspace_packet(dp, skb, key, upcall_info, cutlen); if (err) break;
net/openvswitch/flow.c +5 -1
@@ -631,7 +631,8 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) key->ip.frag =OVS_FRAG_TYPE_LATER ;return 0 ; } -if (nh->frag_off &htons (IP_MF )) +if (nh->frag_off &htons (IP_MF ) || +skb_shinfo (skb)->gso_type &SKB_GSO_UDP ) key->ip.frag =OVS_FRAG_TYPE_FIRST ;else key->ip.frag =OVS_FRAG_TYPE_NONE ;
@@ -747,6 +748,9 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)if (key->ip.frag ==OVS_FRAG_TYPE_LATER )return 0 ; +if (skb_shinfo (skb)->gso_type &SKB_GSO_UDP ) + key->ip.frag =OVS_FRAG_TYPE_FIRST ; +/* Transport layer. */ if (key->ip.proto ==NEXTHDR_TCP ) {if (tcphdr_ok (skb)) {
net/sched/act_csum.c +6 -0
@@ -229,6 +229,9 @@ static int tcf_csum_ipv4_udp(struct sk_buff *skb, unsigned int ihl,const struct iphdr *iph;u16 ul; +if (skb_is_gso (skb) &&skb_shinfo (skb)->gso_type &SKB_GSO_UDP ) +return 1 ; +/* * Support both UDP and UDPLITE checksum algorithms, Don't use * udph->len to get the real length without any protocol check,
@@ -282,6 +285,9 @@ static int tcf_csum_ipv6_udp(struct sk_buff *skb, unsigned int ihl,const struct ipv6hdr *ip6h;u16 ul; +if (skb_is_gso (skb) &&skb_shinfo (skb)->gso_type &SKB_GSO_UDP ) +return 1 ; +/* * Support both UDP and UDPLITE checksum algorithms, Don't use * udph->len to get the real length without any protocol check,
Signature · 1 line
2.15.0.448.gf294e3d99a-goog
Quoted 56 lines · Willem de Bruijn
From: Willem de Bruijn<[email protected]>
Tuntap and similar devices can inject GSO packets. Accept type
VIRTIO_NET_HDR_GSO_UDP, even though not generating UFO natively.Processes are expected to use feature negotiation such as TUNSETOFFLOAD to detect supported offload types and refrain from injecting other packets. This process breaks down with live migration: guest kernels do not renegotiate flags, so destination hosts need to expose all features that the source host does.
Partially revert the UFO removal from 182e0b6b5846~1..d9d30adf5677. This patch introduces
nearly(*)no new code to simplify verification. It brings back verbatim tuntap UFO negotiation,VIRTIO_NET_HDR_GSO_UDPinsertion and software UFO segmentation.It does not reinstate protocol stack support, hardware offload (
NETIF_F_UFO),SKB_GSO_UDPtunneling inSKB_GSO_SOFTWAREor reception ofVIRTIO_NET_HDR_GSO_UDPpackets in tuntap.To support
SKB_GSO_UDPreappearing in the stack, also reinstate logic inact_csumand openvswitch. Achieve equivalence with v4.13 HEAD by squashing in commit939912216fa8("net:skb_needs_check()removesCHECKSUM_UNNECESSARYcheck for tx.") and reverting commit8d63bee643f1("net: avoidskb_warn_bad_offloadfalse positives on UFO").(*) To avoid having to bring back skb_shinfo(skb)->ip6_frag_id,
ipv6_proxy_select_identis changed to return a__be32and this is assigned directly to thefrag_hdr. Also,SKB_GSO_UDPis inserted at the end of the enum to minimize code churn.Tested
Booted a v4.13 guest kernel with QEMU. On a host kernel before this patchethtool -k eth0shows UFO disabled. After the patch, it is enabled, same as on a v4.13 host kernel.A UFO packet sent from the guest appears on the tap device:
host: nc -l -p -u 8000 & tcpdump -n -i tap0 guest: dd if=/dev/zero of=payload.txt bs=1 count=2000 nc -u 192.16.1.1 8000 < payload.txtDirect tap to tap transmission of
VIRTIO_NET_HDR_GSO_UDPsucceeds, packets arriving fragmented:./with_tap_pair.sh ./tap_send_ufo tap0 tap1 (fromhttps://github.com/wdebruij/kerneltools/tree/master/tests)Changes
v1 -> v2
- simplifiedset_offloadchange (review comment)
- documented test procedure
Quoted 5 lines
Link http://lkml.kernel.org/r/<CAF=yD-LuUeDuL9YWPJD9ykOZ0QCjNeznPDr6whqZ9NGMNF12Mw@mail.gmail.com> open hereFixes fb652fdfe837 ("macvlan/macvtap: Remove NETIF_F_UFO advertisement.")Reported-by Michal Kubecek<[email protected]>Signed-off-by Willem de Bruijn<[email protected]>---
Have done netperf UDP_STREAM between two 4.8 guests. The patch works as expected.
Thanks
David Miller
maintainerFrom: Willem de Bruijn <[email protected]>
Date: Tue, 21 Nov 2017 10:22:25 -0500
Quoted 30 lines
From: Willem de Bruijn <[email protected]>
Tuntap and similar devices can inject GSO packets. Accept type
VIRTIO_NET_HDR_GSO_UDP, even though not generating UFO natively.Processes are expected to use feature negotiation such as TUNSETOFFLOAD to detect supported offload types and refrain from injecting other packets. This process breaks down with live migration: guest kernels do not renegotiate flags, so destination hosts need to expose all features that the source host does.
Partially revert the UFO removal from 182e0b6b5846~1..d9d30adf5677. This patch introduces
nearly(*)no new code to simplify verification. It brings back verbatim tuntap UFO negotiation,VIRTIO_NET_HDR_GSO_UDPinsertion and software UFO segmentation.It does not reinstate protocol stack support, hardware offload (
NETIF_F_UFO),SKB_GSO_UDPtunneling inSKB_GSO_SOFTWAREor reception ofVIRTIO_NET_HDR_GSO_UDPpackets in tuntap.To support
SKB_GSO_UDPreappearing in the stack, also reinstate logic inact_csumand openvswitch. Achieve equivalence with v4.13 HEAD by squashing in commit939912216fa8("net:skb_needs_check()removesCHECKSUM_UNNECESSARYcheck for tx.") and reverting commit8d63bee643f1("net: avoidskb_warn_bad_offloadfalse positives on UFO").(*) To avoid having to bring back skb_shinfo(skb)->ip6_frag_id,
ipv6_proxy_select_identis changed to return a__be32and this is assigned directly to thefrag_hdr. Also,SKB_GSO_UDPis inserted at the end of the enum to minimize code churn.
...
Quoted 4 lines
Link http://lkml.kernel.org/r/<CAF=yD-LuUeDuL9YWPJD9ykOZ0QCjNeznPDr6whqZ9NGMNF12Mw@mail.gmail.com> open hereFixes fb652fdfe837 ("macvlan/macvtap: Remove NETIF_F_UFO advertisement.")Reported-by Michal Kubecek <[email protected]>Signed-off-by Willem de Bruijn <[email protected]>
Applied and queued up for -stable, thanks!