udp: Flow dissection for tunnels
Subsystems (3)
cover udp: Flow dissection for tunnels
Now that we have a means to perform a UDP socket lookup without taking a reference, it is feasible to have flow dissector crack open UDP encapsulated packets. Generally, we would expect that the UDP source port or the flow label in IPv6 would contain enough entropy about the encapsulated flow. However, there will be cases, such as a static UDP tunnel with fixed ports, where dissecting the encapsulated packet is valuable.
The model is here is similar to that implemented for UDP GRO. A tunnel implementation (e.g. GUE) may set a flow_dissect function in the udp_sk. In __skb_flow_dissect a case has been added for UDP to check if there is a socket with flow_dissect set. If there is the function is called. The (per tunnel implementation) function can parse the encapsulation headers and return the next protocol for __skb_flow_dissect to process and it's position in nhoff.
Since performing a UDP lookup on every packet might be expensive I added a static key check to bypass the lookup if there are no sockets with flow_dissect set. I should mention that doing the lookup wasn't particularly a big hit anyway.
Fou/gue was modified to perform tunnel dissection. This is enabled on each listener socket via a netlink configuration option.
Tested:
Running 200 streams with TCP_RR.
GRE/GUE variable source port (baseline)
RSS distributes packets, RFS is effective
1211702 tps
147/241/442 50/90/99% latencies
87.95 CPU utilization
GRE/GUE fixed source port
All packets to one CPU, RFS is ineffective
173680 tps
1170/1377/1853 50/90/99% latencies
7.42 CPU utilization
GRE/GUE fixed source port with deep hash enabled All packets to one CPU, but now RFS is effective 730359 tps
263/325/464 50/90/99% latencies
38.25% CPU utilization (Interrupting CPU is maxed out)
Tom Herbert (5):
udp: Add socket lookup functions with noref
udp: UDP flow dissector
udp: Add UDP flow dissection functions to IPv4 and IPv6
udp: UDP tunnel flow dissection infrastructure
fou: Support flow dissection
include/linux/netdevice.h | 5 +++ include/linux/udp.h | 7 +++++ include/net/flow_dissector.h | 8 +++++ include/net/udp.h | 12 ++++++++ include/net/udp_tunnel.h | 5 +++ include/uapi/linux/fou.h | 1 + net/core/flow_dissector.c | 73 ++++++++++++++++++++++++++++++++++++++++++-- net/ipv4/fou.c | 68 ++++++++++++++++++++++++++++++++++++++++- net/ipv4/udp.c | 11 +++++++ net/ipv4/udp_offload.c | 39 +++++++++++++++++++++++ net/ipv4/udp_tunnel.c | 5 +++ net/ipv6/udp.c | 10 ++++++ net/ipv6/udp_offload.c | 38 +++++++++++++++++++++++ 13 files changed, 279 insertions(+), 3 deletions(-)
Signature · 1 line
2.9.3
PATCH 1/5 udp: Add socket lookup functions with noref
Create udp4_lib_lookup_noref and udp6_lib_lookup_noref. These perfrom a socket lookup on addresses and ports without taking a reference.
--- include/net/udp.h | 8 ++++++++ net/ipv4/udp.c | 8 ++++++++ net/ipv6/udp.c | 10 ++++++++++ 3 files changed, 26 insertions(+)
include/net/udp.h +8 -0
@@ -275,6 +275,10 @@ struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport, struct udp_table *tbl, struct sk_buff *skb);struct sock *udp4_lib_lookup_skb (struct sk_buff *skb,__be16 sport,__be16 dport); +struct sock *udp4_lib_lookup_noref (struct net *net, +__be32 saddr,__be16 sport, +__be32 daddr,__be16 dport, +int dif); struct sock *udp6_lib_lookup(struct net *net, const struct in6_addr *saddr, __be16 sport, const struct in6_addr *daddr, __be16 dport,
@@ -286,6 +290,10 @@ struct sock *__udp6_lib_lookup(struct net *net, struct sk_buff *skb);struct sock *udp6_lib_lookup_skb (struct sk_buff *skb,__be16 sport,__be16 dport); +struct sock *udp6_lib_lookup_noref (struct net *net, +const struct in6_addr *saddr,__be16 sport, +const struct in6_addr *daddr,__be16 dport, +int dif);/* * SNMP statistics for UDP and UDP-Lite
net/ipv4/udp.c +8 -0
@@ -595,6 +595,14 @@ struct sock *udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport,EXPORT_SYMBOL_GPL (udp4_lib_lookup);#endif +struct sock *udp4_lib_lookup_noref (struct net *net,__be32 saddr,__be16 sport, +__be32 daddr,__be16 dport,int dif) +{ +return __udp4_lib_lookup (net, saddr, sport, daddr, dport, + dif, &udp_table,NULL ); +} +EXPORT_SYMBOL_GPL (udp4_lib_lookup_noref); + static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk, __be16 loc_port, __be32 loc_addr, __be16 rmt_port, __be32 rmt_addr,
net/ipv6/udp.c +10 -0
@@ -317,6 +317,16 @@ struct sock *udp6_lib_lookup(struct net *net, const struct in6_addr *saddr, __beEXPORT_SYMBOL_GPL (udp6_lib_lookup);#endif +struct sock *udp6_lib_lookup_noref (struct net *net, +const struct in6_addr *saddr,__be16 sport, +const struct in6_addr *daddr,__be16 dport, +int dif) +{ +return __udp6_lib_lookup (net, saddr, sport, daddr, dport, + dif, &udp_table,NULL ); +} +EXPORT_SYMBOL_GPL (udp6_lib_lookup_noref); +/* * This should be easy, if there is something there we * return it, otherwise we block.
Signature · 1 line
2.9.3
PATCH 2/5 udp: UDP flow dissector
In reply to Tom HerbertAdd infrastructure for performing per protocol flow dissection and support flow dissection in UDP payloads (e.g. flow dissection on a UDP encapsulated tunnel.
The per protocol flow dissector is called by flow_dissect function in the offload_callbacks of a protocol. The arguments of this function include the necessary information to do flow dissection as derived from __skb_flow_dissect which is where the callback is intended to be called from. There are return codes from the callback in the form FLOW_DIS_RET_* that indicate the result. FLOW_DIS_RET_IPPROTO means that the payload should be dissected as an IP proto, the specific protocol is returned in a pointer argument. Likewise, FLOW_DIS_RET_PROTO indicate the payload should be processed as an ethertype which is returned in another argument.
A case for IPPROTO_UDP was added to __skb_flow_dissect. Since UDP flow dissector involves a relatively expensive socket lookup there is a static key check first to see if there are any sockets that have enabled flow dissection. After this check, the offload ops for UDP for either IPv4 or IPv6 is considered. If the flow_dissect function is it is called. Upon return the result is processed (pass, out_bad, process as IP protocol, process as ethertype). Note that if the result indicates a protocol must be processed it is expected that nhoff has been updated to the encapsulated protocol header.
--- include/linux/netdevice.h | 5 +++ include/linux/udp.h | 7 +++++ include/net/flow_dissector.h | 8 +++++ include/net/udp.h | 4 +++ net/core/flow_dissector.c | 73 ++++++++++++++++++++++++++++++++++++++++++-- net/ipv4/udp.c | 3 ++ 6 files changed, 98 insertions(+), 2 deletions(-)
include/linux/netdevice.h +5 -0
@@ -2199,6 +2199,11 @@ struct offload_callbacks {struct sk_buff **(*gro_receive)(struct sk_buff **head,struct sk_buff *skb);int (*gro_complete)(struct sk_buff *skb,int nhoff); +int (*flow_dissect)(const struct sk_buff *skb, +void *data,int hlen, +int *nhoff,u8 *ip_proto, +__be16 *proto, +struct flow_dissector_key_addrs *key_addrs); };struct packet_offload {
include/linux/udp.h +7 -0
@@ -79,6 +79,13 @@ struct udp_sock {int (*gro_complete)(struct sock *sk,struct sk_buff *skb,int nhoff); + +/* Flow dissector function for UDP socket */ +int (*flow_dissect)(struct sock *sk, +const struct sk_buff *skb, +void *data,int hlen, +int *nhoff,u8 *ip_proto, +__be16 *proto); };static inline struct udp_sock *udp_sk (const struct sock *sk)
include/net/flow_dissector.h +8 -0
@@ -203,4 +203,12 @@ static inline void *skb_flow_dissector_target(struct flow_dissector *flow_dissec return ((char *)target_container) + flow_dissector->offset[key_id]; } +/* Return codes from per socket flow dissector (e.g. UDP) */ +enum { +FLOW_DIS_RET_PASS =0 , +FLOW_DIS_RET_BAD , +FLOW_DIS_RET_IPPROTO , +FLOW_DIS_RET_PROTO , +}; +#endif
include/net/udp.h +4 -0
@@ -360,4 +360,8 @@ void udp_encap_enable(void);#if IS_ENABLED (CONFIG_IPV6 )void udpv6_encap_enable (void );#endif + +void udp_flow_dissect_enable (void ); +void udp_flow_dissect_disable (void ); +#endif /* _UDP_H */
net/core/flow_dissector.c +71 -2
103 lines not on this page · raw message
net/ipv4/udp.c +3 -0
@@ -1977,6 +1977,9 @@ void udp_destroy_sock(struct sock *sk)if (encap_destroy)encap_destroy (sk); } + +if (up->flow_dissect) +udp_flow_dissect_disable (); }/*
Signature · 1 line
2.9.3
PATCH 3/5 udp: Add UDP flow dissection functions to IPv4 and IPv6
In reply to Tom HerbertAdd per protocol offload callbacks for flow_dissect to UDP for IPv4 and IPv6. The callback functions extract the port number information and with the packet addresses (given in an argument with type flow_dissector_key_addrs) it performs a lookup on the UDP socket. If a socket is found and flow_dissect is set for the socket then that function is called.
--- net/ipv4/udp_offload.c | 39 +++++++++++++++++++++++++++++++++++++++ net/ipv6/udp_offload.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+)
net/ipv4/udp_offload.c +39 -0
@@ -377,11 +377,50 @@ static int udp4_gro_complete(struct sk_buff *skb, int nhoff)return udp_gro_complete (skb, nhoff, udp4_lib_lookup_skb); } +/* Assumes rcu lock is held */ +static int udp4_flow_dissect (const struct sk_buff *skb,void *data,int hlen, +int *nhoff,u8 *ip_proto,__be16 *proto, +struct flow_dissector_key_addrs *key_addrs) +{ +u16 _ports[2 ], *ports; +struct net *net; +struct sock *sk; +int dif =-1 ; + +/* See if there is a flow dissector in the UDP socket */ + +if (skb->dev) { + net =dev_net (skb->dev); + dif = skb->dev->ifindex; + }else if (skb->sk) { + net =sock_net (skb->sk); + }else { +return FLOW_DIS_RET_PASS ; + } + + ports =__skb_header_pointer (skb, *nhoff,sizeof (_ports), + data, hlen, &_ports); +if (!ports) +return FLOW_DIS_RET_BAD ; + + sk =udp4_lib_lookup_noref (net, + key_addrs->v4addrs.src, ports[0 ], + key_addrs->v4addrs.dst, ports[1 ], + dif); + +if (sk &&udp_sk (sk)->flow_dissect) +return udp_sk (sk)->flow_dissect (sk, skb, data, hlen, nhoff, + ip_proto, proto); +else +return FLOW_DIS_RET_PASS ; +} +static const struct net_offload udpv4_offload = { .callbacks = { .gso_segment = udp4_ufo_fragment, .gro_receive = udp4_gro_receive, .gro_complete = udp4_gro_complete, + .flow_dissect = udp4_flow_dissect, }, };
net/ipv6/udp_offload.c +38 -0
@@ -163,11 +163,49 @@ static int udp6_gro_complete(struct sk_buff *skb, int nhoff)return udp_gro_complete (skb, nhoff, udp6_lib_lookup_skb); } +/* Assumes rcu lock is held */ +static int udp6_flow_dissect (const struct sk_buff *skb,void *data,int hlen, +int *nhoff,u8 *ip_proto,__be16 *proto, +const struct flow_dissector_key_addrs *key_addrs) +{ +u16 _ports[2 ], *ports; +struct net *net; +struct sock *sk; +int dif =-1 ; + +/* See if there is a flow dissector in the UDP socket */ + +if (skb->dev) { + net =dev_net (skb->dev); + dif = skb->dev->ifindex; + }else if (skb->sk) { + net =sock_net (skb->sk); + }else { +return FLOW_DIS_RET_PASS ; + } + + ports =__skb_header_pointer (skb, *nhoff,sizeof (_ports), + data, hlen, &_ports); +if (!ports) +return FLOW_DIS_RET_BAD ; + + sk =udp6_lib_lookup_noref (net, + &key_addrs->v6addrs.src, ports[0 ], + &key_addrs->v6addrs.dst, ports[1 ], + dif); + +if (sk &&udp_sk (sk)->flow_dissect) +return udp_sk (sk)->flow_dissect (sk, skb, data, hlen, nhoff, + ip_proto, proto); +return FLOW_DIS_RET_PASS ; +} +static const struct net_offload udpv6_offload = { .callbacks = { .gso_segment = udp6_ufo_fragment, .gro_receive = udp6_gro_receive, .gro_complete = udp6_gro_complete, + .flow_dissect = udp6_flow_dissect, }, };
Signature · 1 line
2.9.3
PATCH 4/5 udp: UDP tunnel flow dissection infrastructure
In reply to Tom HerbertAdd infrastructure to allow UDP tunnels to setup flow dissection.
--- include/net/udp_tunnel.h | 5 +++++ net/ipv4/udp_tunnel.c | 5 +++++ 2 files changed, 10 insertions(+)
include/net/udp_tunnel.h +5 -0
@@ -69,6 +69,10 @@ typedef struct sk_buff **(*udp_tunnel_gro_receive_t)(struct sock *sk, struct sk_buff *skb);typedef int (*udp_tunnel_gro_complete_t )(struct sock *sk,struct sk_buff *skb,int nhoff); +typedef int (*udp_tunnel_flow_dissect_t )(struct sock *sk, +const struct sk_buff *skb, +void *data,int hlen,int *nhoff, +u8 *ip_proto,__be16 *proto);struct udp_tunnel_sock_cfg {void *sk_user_data;/* user data used by encap_rcv call back */
@@ -78,6 +82,7 @@ struct udp_tunnel_sock_cfg {udp_tunnel_encap_destroy_t encap_destroy;udp_tunnel_gro_receive_t gro_receive;udp_tunnel_gro_complete_t gro_complete; +udp_tunnel_flow_dissect_t flow_dissect; };/* Setup the given (UDP) sock to receive UDP encapsulated packets */
net/ipv4/udp_tunnel.c +5 -0
@@ -72,6 +72,11 @@ void setup_udp_tunnel_sock(struct net *net, struct socket *sock,udp_sk (sk)->gro_receive = cfg->gro_receive;udp_sk (sk)->gro_complete = cfg->gro_complete; +if (cfg->flow_dissect) { +udp_sk (sk)->flow_dissect = cfg->flow_dissect; +udp_flow_dissect_enable (); + } +udp_tunnel_encap_enable (sock); }EXPORT_SYMBOL_GPL (setup_udp_tunnel_sock);
Signature · 1 line
2.9.3
PATCH 5/5 fou: Support flow dissection
In reply to Tom HerbertThis patch performs flow dissection for GUE and FOU. This is an optional feature on the receiver and is set by FOU_ATTR_DEEP_HASH netlink configuration. When enable the UDP socket flow_dissect function is set to fou_flow_dissect or gue_flow_dissect as appropriate. These functions return FLOW_DIS_RET_IPPROTO and set ip protocol argument. In the case of GUE the header is parsed to find the protocol number.
--- include/uapi/linux/fou.h | 1 + net/ipv4/fou.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-)
include/uapi/linux/fou.h +1 -0
@@ -15,6 +15,7 @@ enum {FOU_ATTR_IPPROTO ,/* u8 */ FOU_ATTR_TYPE ,/* u8 */ FOU_ATTR_REMCSUM_NOPARTIAL ,/* flag */ +FOU_ATTR_DEEP_HASH ,/* flag */ __FOU_ATTR_MAX, };
net/ipv4/fou.c +67 -1
116 lines not on this page · raw message
Signature · 1 line
2.9.3
David Miller
maintainerFrom: Tom Herbert <[email protected]>
Date: Wed, 12 Oct 2016 16:25:42 -0700
Quoted 4 lines
Since performing a UDP lookup on every packet might be expensive I added a static key check to bypass the lookup if there are no sockets with
flow_dissectset. I should mention that doing the lookup wasn't particularly a big hit anyway.
I think this new static key is unnecessary, as it is equivalent
to: (udp_encap_needed + udpv6_encap_needed)
This socket lookup is very heavy handed, and I realize that you need this because we no longer store the encapsulation socket in skb->sk these days.
Can you talk about the various code paths that lead into the flow dissector and why the UDP socket lookup is needed? Maybe we can propagate it another way, at least on TX.
Thanks.
Quoted 11 lines · David Miller
From: Tom Herbert <[email protected]>
Date: Wed, 12 Oct 2016 16:25:42 -0700Quoted 4 lines
Since performing a UDP lookup on every packet might be expensive I added a static key check to bypass the lookup if there are no sockets with
flow_dissectset. I should mention that doing the lookup wasn't particularly a big hit anyway.I think this new static key is unnecessary, as it is equivalent
to: (udp_encap_needed+udpv6_encap_needed)
Good point.
Quoted 4 lines
This socket lookup is very heavy handed, and I realize that you need this because we no longer store the encapsulation socket in
skb->skthese days.
I don't quite understand your point about the encapsulation socket. The reason we do the socket lookup is the same as why we do it this way in GRO already, identifying UDP encapsulation by just port is insufficient and may lead to incorrect results. Once we removed the atomic operation from the UDP socket lookup (thanks Eric!) it becomes feasible to do the lookup in critical paths and so the special per port offloads lookup was removed. In my testing I didn't see a noticeable hit in performing the lookup, but it still seems prudent to use the static key since UDP tunnels are a relatively narrow use case.
Quoted 4 lines
Can you talk about the various code paths that lead into the flow dissector and why the UDP socket lookup is needed? Maybe we can propagate it another way, at least on TX.
The code path I'm interested in simple RX, particularly in the case where UDP is being used as static tunnel for many flows in IPv4 (assuming in IPv6 we have flow label to provide entropy). For getting the flow hash on TX we are already using sk->tx_hash if it's available.
Tom
Quoted 1 line
Thanks.
David Miller
maintainerFrom: Tom Herbert <[email protected]>
Date: Thu, 13 Oct 2016 12:29:46 -0700
Quoted 6 lines · David Miller
Quoted 4 lines
This socket lookup is very heavy handed, and I realize that you need this because we no longer store the encapsulation socket in
skb->skthese days.I don't quite understand your point about the encapsulation socket.
On the transmit side we used to have an issue wrt. what socket lives on skb->sk when encapsulation is involved.
The problem is that we need skb->sk to be the transport level socket, but in the output path we used to make tests on "skb->sk" to determine things such as the multicast loopback flag. But we should be looking at the tunnel socket for that, otherwise we could do crazy things like dereference an AF_PACKET socket as if it were an inet socket one.
As such we modified the output path to pass the inner tunnel socket 'sk' down through the call chain, as an argument to functions such as ip_queue_xmit(), ip_local_out*(), etc.