udp: Flow dissection for tunnels
Subsystems (6)
v4 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.
v2:
- davem suggested that we don't need udp_flow_dissect and that udp{v6}_encap_needed could be used. Problem is that those are in respective udp.c and flow_dissector.c is in net/core. Keep udp_flow_dissect as more generic item.
- Fixed Makefile issue where we were using CONFIG_NET instead of CONFIG_INET.
- Added limits inf flow dissector from controlling number of nested encapsulations or EHs that are dissected.
- Added CONFIG_INET around use of inet_offloads in flow_dissector.c.
v3:
- Fix build issues with modules that call IPv6 functions and CONFIG_INET is not set.
- Fix compilation error in init'ing .flow_dissect in IPv6 UDP offload.
v4:
- Fix compilation error in init'ing .flow_dissect in IPv6 UDP offload. (hopefully for real this time).
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 (7):
ipv6: Fix Makefile conditional to use CONFIG_INET
flow_dissector: Limit processing of next encaps and extensions
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
drivers/net/usb/cdc_mbim.c | 4 ++ include/linux/netdevice.h | 5 ++ include/linux/udp.h | 7 +++ include/net/flow_dissector.h | 8 +++ include/net/ipv6.h | 15 ++++++ include/net/net_namespace.h | 2 + include/net/udp.h | 12 +++++ include/net/udp_tunnel.h | 5 ++ include/uapi/linux/fou.h | 1 + net/Makefile | 2 +- net/core/flow_dissector.c | 122 ++++++++++++++++++++++++++++++++++++++----- 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 | 40 +++++++++++++- 17 files changed, 341 insertions(+), 15 deletions(-)
Signature · 1 line
2.9.3
PATCH v4 1/7 ipv6: Fix Makefile conditional to use CONFIG_INET
ipv6 directory was being built based on CONFIG_NET not CONFIG_INET.
--- drivers/net/usb/cdc_mbim.c | 4 ++++ include/net/ipv6.h | 15 +++++++++++++++ include/net/net_namespace.h | 2 ++ net/Makefile | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-)
drivers/net/usb/cdc_mbim.c +4 -0
@@ -301,6 +301,7 @@ static struct sk_buff *cdc_mbim_tx_fixup(struct usbnet *dev, struct sk_buff *skbreturn NULL ; } +#ifdef CONFIG_INET /* Some devices are known to send Neigbor Solicitation messages and * require Neigbor Advertisement replies. The IPv6 core will not * respond since IFF_NOARP is set, so we must handle them ourselves.
@@ -350,6 +351,7 @@ static void do_neigh_solicit(struct usbnet *dev, u8 *buf, u16 tci) out: dev_put(netdev); } +#endif static bool is_neigh_solicit (u8 *buf,size_t len) {
@@ -377,8 +379,10 @@ static struct sk_buff *cdc_mbim_process_dgram(struct usbnet *dev, u8 *buf, size_ proto =htons (ETH_P_IP );break ;case 0x60 : +#ifdef CONFIG_INET if (is_neigh_solicit (buf, len))do_neigh_solicit (dev, buf, tci); +#endif proto =htons (ETH_P_IPV6 );break ;default :
include/net/ipv6.h +15 -0
@@ -936,8 +936,15 @@ void ipv6_push_nfrag_opts(struct sk_buff *skb, struct ipv6_txoptions *opt,void ipv6_push_frag_opts (struct sk_buff *skb,struct ipv6_txoptions *opt,u8 *proto); +#ifdef CONFIG_INET int ipv6_skip_exthdr (const struct sk_buff *,int start,u8 *nexthdrp,__be16 *frag_offp); +#else +static inline int ipv6_skip_exthdr (const struct sk_buff *skb,int start, +u8 *nexthdrp,__be16 *frag_offp) { +return -1 ; +} +#endif bool ipv6_ext_hdr (u8 nexthdr);
@@ -948,8 +955,16 @@ enum { };/* find specified header and get offset to it */ +#ifdef CONFIG_INET int ipv6_find_hdr (const struct sk_buff *skb,unsigned int *offset,int target,unsigned short *fragoff,int *fragflg); +#else +static inline int ipv6_find_hdr (const struct sk_buff *skb,unsigned int *offset, +int target,unsigned short *fragoff, +int *fragflg) { +return -EPROTONOSUPPORT ; +} +#endif int ipv6_find_tlv (const struct sk_buff *skb,int offset,int type);
include/net/net_namespace.h +2 -0
@@ -352,8 +352,10 @@ static inline void rt_genid_bump_ipv4(struct net *net)extern void (*__fib6_flush_trees)(struct net *net);static inline void rt_genid_bump_ipv6 (struct net *net) { +#ifdef CONFIG_INET if (__fib6_flush_trees)__fib6_flush_trees (net); +#endif }#if IS_ENABLED (CONFIG_IEEE802154_6LOWPAN )
net/Makefile +1 -1
@@ -17,7 +17,7 @@ obj-$(CONFIG_NETFILTER) += netfilter/ obj-$(CONFIG_INET) += ipv4/ obj-$(CONFIG_XFRM) += xfrm/ obj-$(CONFIG_UNIX) += unix/ -obj-$(CONFIG_NET) += ipv6/ +obj-$(CONFIG_INET) += ipv6/ obj-$(CONFIG_PACKET) += packet/ obj-$(CONFIG_NET_KEY) += key/ obj-$(CONFIG_BRIDGE) += bridge/
Signature · 1 line
2.9.3
Re: [PATCH v4 net-next 1/7] ipv6: Fix Makefile conditional to use CONFIG_INET
Dave,
Please don't apply this. It's like whack-a-mole trying to resolve all the dependencies. I'll resubmit the series without this.
Tom
Quoted 109 lines · Tom Herbert
ipv6 directory was being built based on
CONFIG_NETnotCONFIG_INET.Signed-off-by Tom Herbert <[email protected]>--- drivers/net/usb/cdc_mbim.c | 4 ++++ include/net/ipv6.h | 15 +++++++++++++++ include/net/net_namespace.h | 2 ++ net/Makefile | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-)drivers/net/usb/cdc_mbim.c +4
-0@@ -301,6 +301,7 @@ static struct sk_buff *cdc_mbim_tx_fixup(struct usbnet *dev, struct sk_buff *skbreturn NULL ; } +#ifdef CONFIG_INET /* Some devices are known to send Neigbor Solicitation messages and * require Neigbor Advertisement replies. The IPv6 core will not * respond since IFF_NOARP is set, so we must handle them ourselves. @@ -350,6 +351,7 @@ static void do_neigh_solicit(struct usbnet *dev, u8 *buf, u16 tci) out: dev_put(netdev); } +#endif static bool is_neigh_solicit (u8 *buf,size_t len) {@@ -377,8 +379,10 @@ static struct sk_buff *cdc_mbim_process_dgram(struct usbnet *dev, u8 *buf, size_ proto =htons (ETH_P_IP );break ;case 0x60 : +#ifdef CONFIG_INET if (is_neigh_solicit (buf, len))do_neigh_solicit (dev, buf, tci); +#endif proto =htons (ETH_P_IPV6 );break ;default :include/net/ipv6.h +15
-0@@ -936,8 +936,15 @@ void ipv6_push_nfrag_opts(struct sk_buff *skb, struct ipv6_txoptions *opt,void ipv6_push_frag_opts (struct sk_buff *skb,struct ipv6_txoptions *opt,u8 *proto); +#ifdef CONFIG_INET int ipv6_skip_exthdr (const struct sk_buff *,int start,u8 *nexthdrp,__be16 *frag_offp); +#else +static inline int ipv6_skip_exthdr (const struct sk_buff *skb,int start, +u8 *nexthdrp,__be16 *frag_offp) { +return -1 ; +} +#endif bool ipv6_ext_hdr (u8 nexthdr);@@ -948,8 +955,16 @@ enum { };/* find specified header and get offset to it */ +#ifdef CONFIG_INET int ipv6_find_hdr (const struct sk_buff *skb,unsigned int *offset,int target,unsigned short *fragoff,int *fragflg); +#else +static inline int ipv6_find_hdr (const struct sk_buff *skb,unsigned int *offset, +int target,unsigned short *fragoff, +int *fragflg) { +return -EPROTONOSUPPORT ; +} +#endif int ipv6_find_tlv (const struct sk_buff *skb,int offset,int type);include/net/net_namespace.h +2
-0@@ -352,8 +352,10 @@ static inline void rt_genid_bump_ipv4(struct net *net)extern void (*__fib6_flush_trees)(struct net *net);static inline void rt_genid_bump_ipv6 (struct net *net) { +#ifdef CONFIG_INET if (__fib6_flush_trees)__fib6_flush_trees (net); +#endif }#if IS_ENABLED (CONFIG_IEEE802154_6LOWPAN )net/Makefile +1
-2@@ -17,7 +17,7 @@ obj-$(CONFIG_NETFILTER) += netfilter/ obj-$(CONFIG_INET) += ipv4/ obj-$(CONFIG_XFRM) += xfrm/ obj-$(CONFIG_UNIX) += unix/ -obj-$(CONFIG_NET) += ipv6/ +obj-$(CONFIG_INET) += ipv6/ obj-$(CONFIG_PACKET) += packet/ obj-$(CONFIG_NET_KEY) += key/ obj-$(CONFIG_BRIDGE) += bridge/ --2.9.3
David Miller
maintainerRe: [PATCH v4 net-next 1/7] ipv6: Fix Makefile conditional to use CONFIG_INET
From: Tom Herbert <[email protected]>
Date: Wed, 19 Oct 2016 20:16:01 -0700
Quoted 2 lines
Please don't apply this. It's like whack-a-mole trying to resolve all the dependencies. I'll resubmit the series without this.
Ok.
PATCH v4 2/7 flow_dissector: Limit processing of next encaps and extensions
In reply to Tom HerbertFlow dissector does not limit the number of encapsulated packets or IPv6 header extensions that will be processed. This could easily be suceptible to DOS attack-- for instance a 1500 byte packet could contain 75 IPIP headers.
This patch places limits on the number of encapsulations and IPv6 extension headers that are processed in flow dissector
--- net/core/flow_dissector.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-)
net/core/flow_dissector.c +27 -10
@@ -91,6 +91,22 @@ __be32 __skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto, }EXPORT_SYMBOL (__skb_flow_get_ports); +#define MAX_DISSECT_DEPTH 10 +#define MAX_DISSECT_EXT 10 + +#define __DISSECT_AGAIN (_target, _depth, _limit) do { \ + (_depth)++; \ + if ((_depth) > (_limit)) \ + goto out_good; \ + else \ + goto _target; \ +} while (0) + +#define DISSECT_AGAIN (target) \ + __DISSECT_AGAIN(target, depth, MAX_DISSECT_DEPTH) +#define DISSECT_AGAIN_EXT (target) \ + __DISSECT_AGAIN(target, ext_cnt, MAX_DISSECT_EXT) +/** * __skb_flow_dissect - extract the flow_keys struct and return it * @skb: sk_buff to extract the flow from, can be NULL if the rest are specified
@@ -123,6 +139,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,bool skip_vlan = false;u8 ip_proto =0 ;bool ret = false; +int depth =0 , ext_cnt =0 ;if (!data) { data = skb->data;
@@ -262,7 +279,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, proto = vlan->h_vlan_encapsulated_proto; nhoff +=sizeof (*vlan);if (skip_vlan) - goto again; +DISSECT_AGAIN (again); } skip_vlan = true;
@@ -285,7 +302,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, } } - goto again; +DISSECT_AGAIN (again); }case htons (ETH_P_PPP_SES ): {struct {
@@ -299,9 +316,9 @@ bool __skb_flow_dissect(const struct sk_buff *skb, nhoff +=PPPOE_SES_HLEN ;switch (proto) {case htons (PPP_IP ): - goto ip; +DISSECT_AGAIN (ip);case htons (PPP_IPV6 ): - goto ipv6; +DISSECT_AGAIN (ipv6);default : goto out_bad; }
@@ -472,7 +489,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,if (flags &FLOW_DISSECTOR_F_STOP_AT_ENCAP ) goto out_good; - goto again; +DISSECT_AGAIN (again); }case NEXTHDR_HOP :case NEXTHDR_ROUTING :
@@ -490,7 +507,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ip_proto = opthdr[0 ]; nhoff += (opthdr[1 ] +1 ) <<3 ; - goto ip_proto_again; +DISSECT_AGAIN_EXT (ip_proto_again); }case NEXTHDR_FRAGMENT : {struct frag_hdr _fh, *fh;
@@ -512,7 +529,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,if (!(fh->frag_off &htons (IP6_OFFSET ))) { key_control->flags |=FLOW_DIS_FIRST_FRAG ;if (flags &FLOW_DISSECTOR_F_PARSE_1ST_FRAG ) - goto ip_proto_again; +DISSECT_AGAIN_EXT (ip_proto_again); } goto out_good; }
@@ -523,7 +540,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,if (flags &FLOW_DISSECTOR_F_STOP_AT_ENCAP ) goto out_good; - goto ip; +DISSECT_AGAIN (ip);case IPPROTO_IPV6 : proto =htons (ETH_P_IPV6 );
@@ -531,10 +548,10 @@ bool __skb_flow_dissect(const struct sk_buff *skb,if (flags &FLOW_DISSECTOR_F_STOP_AT_ENCAP ) goto out_good; - goto ipv6; +DISSECT_AGAIN (ipv6);case IPPROTO_MPLS : proto =htons (ETH_P_MPLS_UC ); - goto mpls; +DISSECT_AGAIN (mpls);default :break ; }
Signature · 1 line
2.9.3
PATCH v4 3/7 udp: Add socket lookup functions with noref
In reply to Tom HerbertCreate 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 v4 4/7 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 | 85 ++++++++++++++++++++++++++++++++++++++++++-- net/ipv4/udp.c | 3 ++ 6 files changed, 110 insertions(+), 2 deletions(-)
include/linux/netdevice.h +5 -0
@@ -2203,6 +2203,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, +const 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 +83 -2
115 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 v4 5/7 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 | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-)
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, +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 =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 +39 -1
@@ -1,5 +1,5 @@/* -* IPV6 GSO/GRO offload support +* ipv6 gso/gro offload support * Linux INET6 implementation * * This program is free software; you can redistribute it and/or
@@ -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 v4 6/7 udp: UDP tunnel flow dissection infrastructure
In reply to Tom HerbertAdd infrastructure to allow UDP tunnels to setup flow dissecion.
--- 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 v4 7/7 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