ipvs: Add icmp scheduling
Subsystems (4)
cover ipvs: Add icmp scheduling
The configuration of ipvs at Facebook is relatively straightforward. All ipvs instances bgp advertise a set of VIPs and the network prefers the nearest one or uses ECMP in the event of a tie. For the uninitiated, ECMP deterministically and statelessly load balances by hashing the packet (usually a 5-tuple of protocol, saddr, daddr, sport, and dport) and using that number as an index (basic hash table type logic).
The problem is that ICMP packets (which contain really important information like whether or not an MTU has been exceeded) will get a different hash value and may end up at a different ipvs instance. With no information about where to route these packets, they are dropped, creating ICMP black holes and breaking Path MTU discovery. Suddenly, my mom's pictures can't load and I'm fielding midday calls that I want nothing to do with.
To address this, this patch set introduces the ability to schedule icmp packets which is gated by a sysctl net.ipv4.vs.schedule_icmp. If set to 0, the old behavior is maintained -- otherwise ICMP packets are scheduled.
Alex Gartrell (12):
ipvs: pull out ip_vs_try_to_schedule function
ipvs: replace ip_vs_fill_ip4hdr with ip_vs_fill_iph_skb_off
ipvs: Add hdr_flags to iphdr
ipvs: drop inverse argument to conn_{in,out}_get
ipvs: Make ip_vs_schedule aware of inverse iph'es
ipvs: add schedule_icmp sysctl
ipvs: Use outer header in ip_vs_bypass_xmit_v6
ipvs: attempt to schedule icmp packets
ipvs: ensure that ICMP cannot be sent in reply to ICMP
ipvs: support scheduling inverse and icmp TCP packets
ipvs: support scheduling inverse and icmp UDP packets
ipvs: support scheduling inverse and icmp SCTP packets
include/net/ip_vs.h | 101 ++++++++++++----- net/netfilter/ipvs/ip_vs_conn.c | 12 +- net/netfilter/ipvs/ip_vs_core.c | 190 +++++++++++++++++++------------- net/netfilter/ipvs/ip_vs_ctl.c | 8 +- net/netfilter/ipvs/ip_vs_proto_ah_esp.c | 17 ++- net/netfilter/ipvs/ip_vs_proto_sctp.c | 35 ++++-- net/netfilter/ipvs/ip_vs_proto_tcp.c | 37 +++++-- net/netfilter/ipvs/ip_vs_proto_udp.c | 26 ++++- net/netfilter/ipvs/ip_vs_xmit.c | 9 +- 9 files changed, 287 insertions(+), 148 deletions(-)
Signature · 1 line
Alex Gartrell <[email protected]>
PATCH 1/12 ipvs: pull out ip_vs_try_to_schedule function
This is necessary as we'll be trying to schedule icmp later and we'll want to share this code.
--- net/netfilter/ipvs/ip_vs_core.c | 57 ++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 20 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +37 -19
@@ -1327,6 +1327,41 @@ ip_vs_local_reply6(const struct nf_hook_ops *ops, struct sk_buff *skb,#endif +static unsigned int +ip_vs_try_to_schedule (int af,struct sk_buff *skb,struct ip_vs_proto_data *pd, +int *verdict,struct ip_vs_conn **cpp, +struct ip_vs_iphdr *iph) +{ +struct ip_vs_protocol *pp = pd->pp; + +if (!iph->fragoffs) { +/* No (second) fragments need to enter here, as nf_defrag_ipv6 +* replayed fragment zero will already have created the cp +*/ + +/* Schedule and create new connection entry into cpp */ +if (!pp->conn_schedule (af, skb, pd, verdict, cpp, iph)) +return 0 ; + } + +if (unlikely (!*cpp)) { +/* sorry, all this trouble for a no-hit :) */ +IP_VS_DBG_PKT (12 , af, pp, skb,0 , +"ip_vs_in: packet continues traversal as normal" ); +if (iph->fragoffs) { +/* Fragment that couldn't be mapped to a conn entry +* is missing module nf_defrag_ipv6 +*/ +IP_VS_DBG_RL ("Unhandled frag, load nf_defrag_ipv6\n" ); +IP_VS_DBG_PKT (7 , af, pp, skb,0 ,"unhandled fragment" ); + } + *verdict =NF_ACCEPT ; +return 0 ; + } + +return 1 ; +} +/* * Handle ICMP messages in the outside-to-inside direction (incoming). * Find any that might be relevant, check against existing connections,
@@ -1700,31 +1735,13 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) cp =NULL ; } -if (unlikely (!cp) && !iph.fragoffs) { -/* No (second) fragments need to enter here, as nf_defrag_ipv6 -* replayed fragment zero will already have created the cp -*/ +if (unlikely (!cp)) {int v; -/* Schedule and create new connection entry into &cp */ -if (!pp->conn_schedule (af, skb, pd, &v, &cp, &iph)) +if (!ip_vs_try_to_schedule (af, skb, pd, &v, &cp, &iph))return v; } -if (unlikely (!cp)) { -/* sorry, all this trouble for a no-hit :) */ -IP_VS_DBG_PKT (12 , af, pp, skb,0 , -"ip_vs_in: packet continues traversal as normal" ); -if (iph.fragoffs) { -/* Fragment that couldn't be mapped to a conn entry -* is missing module nf_defrag_ipv6 -*/ -IP_VS_DBG_RL ("Unhandled frag, load nf_defrag_ipv6\n" ); -IP_VS_DBG_PKT (7 , af, pp, skb,0 ,"unhandled fragment" ); - } -return NF_ACCEPT ; - }
PATCH 2/12 ipvs: replace ip_vs_fill_ip4hdr with ip_vs_fill_iph_skb_off
In reply to Alex GartrellThis removes some duplicated code and makes the ICMPv6 path look more like the ICMP path.
--- include/net/ip_vs.h | 47 +++++++++++++++++++++++------------------ net/netfilter/ipvs/ip_vs_core.c | 41 ++++++++++------------------------- 2 files changed, 38 insertions(+), 50 deletions(-)
include/net/ip_vs.h +27 -20
@@ -120,48 +120,55 @@ static inline void *frag_safe_skb_hp(const struct sk_buff *skb, int offset,return skb_header_pointer (skb, offset, len, buffer); } -static inline void -ip_vs_fill_ip4hdr (const void *nh,struct ip_vs_iphdr *iphdr) -{ -const struct iphdr *iph = nh; - - iphdr->len = iph->ihl *4 ; - iphdr->fragoffs =0 ; - iphdr->protocol = iph->protocol; - iphdr->saddr.ip = iph->saddr; - iphdr->daddr.ip = iph->daddr; -} -/* This function handles filling *ip_vs_iphdr, both for IPv4 and IPv6. * IPv6 requires some extra work, as finding proper header position, * depend on the IPv6 extension headers. */ -static inline void -ip_vs_fill_iph_skb (int af,const struct sk_buff *skb,struct ip_vs_iphdr *iphdr) +static inline int +ip_vs_fill_iph_skb_off (int af,const struct sk_buff *skb,int offset, +struct ip_vs_iphdr *iphdr) {#ifdef CONFIG_IP_VS_IPV6 if (af ==AF_INET6 ) { -const struct ipv6hdr *iph = - (struct ipv6hdr *)skb_network_header (skb); +struct ipv6hdr _iph; +const struct ipv6hdr *iph =skb_header_pointer ( + skb, offset,sizeof (_iph), &_iph); +if (!iph) +return 0 ; + iphdr->saddr.in6 = iph->saddr; iphdr->daddr.in6 = iph->daddr;/* ipv6_find_hdr() updates len, flags */ - iphdr->len =0 ; + iphdr->len = offset; iphdr->flags =0 ; iphdr->protocol =ipv6_find_hdr (skb, &iphdr->len,-1 , &iphdr->fragoffs, &iphdr->flags); +if (iphdr->protocol <0 ) +return 0 ; } else#endif { -const struct iphdr *iph = - (struct iphdr *)skb_network_header (skb); - iphdr->len = iph->ihl *4 ; +struct iphdr _iph; +const struct iphdr *iph =skb_header_pointer ( + skb, offset,sizeof (_iph), &_iph); +if (!iph) +return 0 ; + + iphdr->len = offset + iph->ihl *4 ; iphdr->fragoffs =0 ; iphdr->protocol = iph->protocol; iphdr->saddr.ip = iph->saddr; iphdr->daddr.ip = iph->daddr; } + +return 1 ; +} + +static inline int +ip_vs_fill_iph_skb (int af,const struct sk_buff *skb,struct ip_vs_iphdr *iphdr) +{ +return ip_vs_fill_iph_skb_off (af, skb,skb_network_offset (skb), iphdr); } static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
net/netfilter/ipvs/ip_vs_core.c +11 -30
90 lines not on this page · raw message
Signature · 1 line
Alex Gartrell <[email protected]>
PATCH 3/12 ipvs: Add hdr_flags to iphdr
In reply to Alex GartrellThese flags contain information like whether or not the addresses are inverted or from icmp. The first will allow us to drop an inverse param all over the place, and the second will later be useful in scheduling icmp.
--- include/net/ip_vs.h | 37 ++++++++++++++++++++++++++++++++++--- net/netfilter/ipvs/ip_vs_core.c | 22 ++++++++++++---------- 2 files changed, 46 insertions(+), 13 deletions(-)
include/net/ip_vs.h +34 -3
@@ -29,6 +29,9 @@#endif #include <net/net_namespace.h> /* Netw namespace */ +#define IP_VS_HDR_INVERSE 1 +#define IP_VS_HDR_ICMP 2 +/* Generic access of ipvs struct */ static inline struct netns_ipvs *net_ipvs (struct net * net) {
@@ -104,6 +107,7 @@ static inline struct net *seq_file_single_net(struct seq_file *seq)extern int ip_vs_conn_tab_size;struct ip_vs_iphdr { +int hdr_flags;/* ipvs flags */ __u32 len;/* IPv4 simply where L4 starts * IPv6 where L4 Transport Header starts */ __u16 fragoffs;/* IPv6 fragment offset, 0 if first frag (or not frag)*/
@@ -126,8 +130,14 @@ static inline void *frag_safe_skb_hp(const struct sk_buff *skb, int offset,*/ static inline int ip_vs_fill_iph_skb_off (int af,const struct sk_buff *skb,int offset, -struct ip_vs_iphdr *iphdr) +bool inverse,bool icmp,struct ip_vs_iphdr *iphdr) { + iphdr->hdr_flags =0 ; +if (inverse) + iphdr->hdr_flags |=IP_VS_HDR_INVERSE ; +if (icmp) + iphdr->hdr_flags |=IP_VS_HDR_ICMP ; +#ifdef CONFIG_IP_VS_IPV6 if (af ==AF_INET6 ) {struct ipv6hdr _iph;
@@ -166,9 +176,30 @@ ip_vs_fill_iph_skb_off(int af, const struct sk_buff *skb, int offset, }static inline int -ip_vs_fill_iph_skb (int af,const struct sk_buff *skb,struct ip_vs_iphdr *iphdr) +ip_vs_fill_iph_skb_icmp (int af,const struct sk_buff *skb,int offset, +bool inverse,struct ip_vs_iphdr *iphdr) +{ +return ip_vs_fill_iph_skb_off (af, skb, offset, inverse, true, iphdr); +} + +static inline int +ip_vs_fill_iph_skb (int af,const struct sk_buff *skb,bool inverse, +struct ip_vs_iphdr *iphdr) +{ +return ip_vs_fill_iph_skb_off ( + af, skb,skb_network_offset (skb), inverse, false, iphdr); +} + +static inline bool +ip_vs_iph_inverse (const struct ip_vs_iphdr *iph) +{ +return !!(iph->hdr_flags &IP_VS_HDR_INVERSE ); +} + +static inline bool +ip_vs_iph_icmp (const struct ip_vs_iphdr *iph) { -return ip_vs_fill_iph_skb_off (af, skb,skb_network_offset (skb), iphdr); +return !!(iph->hdr_flags &IP_VS_HDR_ICMP ); } static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
net/netfilter/ipvs/ip_vs_core.c +12 -10
@@ -934,7 +934,7 @@ static int ip_vs_out_icmp(struct sk_buff *skb, int *related,IP_VS_DBG_PKT (11 ,AF_INET , pp, skb, offset,"Checking outgoing ICMP for" ); -ip_vs_fill_iph_skb_off (AF_INET , skb, offset, &ciph); +ip_vs_fill_iph_skb_icmp (AF_INET , skb, offset, true, &ciph);/* The embedded headers contain source and dest in reverse order */ cp = pp->conn_out_get (AF_INET , skb, &ciph,1 );
@@ -983,8 +983,8 @@ static int ip_vs_out_icmp_v6(struct sk_buff *skb, int *related, ic->icmp6_type,ntohs (icmpv6_id (ic)), &ipvsh->saddr, &ipvsh->daddr); -if (!ip_vs_fill_iph_skb_off ( -AF_INET6 , skb, ipvsh->len +sizeof (_icmph), &ciph)) +if (!ip_vs_fill_iph_skb_icmp ( +AF_INET6 , skb, ipvsh->len +sizeof (_icmph), true, &ciph))return NF_ACCEPT ;/* The packet looks wrong, ignore */ pp =ip_vs_proto_get (ciph.protocol);
@@ -1177,7 +1177,7 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)if (!net_ipvs (net)->enable)return NF_ACCEPT ; -ip_vs_fill_iph_skb (af, skb, &iph); +ip_vs_fill_iph_skb (af, skb, false, &iph);#ifdef CONFIG_IP_VS_IPV6 if (af ==AF_INET6 ) {if (unlikely (iph.protocol ==IPPROTO_ICMPV6 )) {
@@ -1212,7 +1212,7 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af) ip_vs_defrag_user(hooknum)))return NF_STOLEN ; -ip_vs_fill_iph_skb (AF_INET , skb, &iph); +ip_vs_fill_iph_skb (AF_INET , skb, false, &iph); }/*
@@ -1433,7 +1433,7 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)return NF_ACCEPT ; pp = pd->pp; -ip_vs_fill_iph_skb_off (AF_INET , skb, offset, &ciph); +ip_vs_fill_iph_skb_icmp (AF_INET , skb, offset, !ipip, &ciph);/* Is the embedded protocol header present? */ if (unlikely(cih->frag_off & htons(IP_OFFSET) &&
@@ -1572,7 +1572,9 @@ static int ip_vs_in_icmp_v6(struct sk_buff *skb, int *related, &iph->saddr, &iph->daddr); offs_ciph = iph->len +sizeof (_icmph); -if (!ip_vs_fill_iph_skb_off (AF_INET6 , skb, offs_ciph, &ciph)) +if (!ip_vs_fill_iph_skb_icmp ( +AF_INET6 , skb, offs_ciph, (hooknum !=NF_INET_LOCAL_OUT ), + &ciph))return NF_ACCEPT ; net =skb_net (skb);
@@ -1649,7 +1651,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)if (unlikely ((skb->pkt_type !=PACKET_HOST && hooknum !=NF_INET_LOCAL_OUT ) || !skb_dst (skb))) { -ip_vs_fill_iph_skb (af, skb, &iph); +ip_vs_fill_iph_skb (af, skb, false, &iph); IP_VS_DBG_BUF(12, "packet type=%d proto=%d daddr=%s" " ignored in hook %u\n", skb->pkt_type, iph.protocol,
@@ -1662,7 +1664,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)if (unlikely (sysctl_backup_only (ipvs) || !ipvs->enable))return NF_ACCEPT ; -ip_vs_fill_iph_skb (af, skb, &iph); +ip_vs_fill_iph_skb (af, skb, false, &iph);/* Bad... Do not break raw sockets */ if (unlikely(skb->sk != NULL && hooknum == NF_INET_LOCAL_OUT &&
@@ -1857,7 +1859,7 @@ ip_vs_forward_icmp_v6(const struct nf_hook_ops *ops, struct sk_buff *skb,struct netns_ipvs *ipvs;struct ip_vs_iphdr iphdr; -ip_vs_fill_iph_skb (AF_INET6 , skb, &iphdr); +ip_vs_fill_iph_skb (AF_INET6 , skb, false, &iphdr);if (iphdr.protocol !=IPPROTO_ICMPV6 )return NF_ACCEPT ;
Signature · 1 line
Alex Gartrell <[email protected]>
PATCH 4/12 ipvs: drop inverse argument to conn_{in,out}_get
In reply to Alex GartrellNo longer necessary since the information is included in the ip_vs_iphdr itself.
--- include/net/ip_vs.h | 12 ++++-------- net/netfilter/ipvs/ip_vs_conn.c | 12 ++++++------ net/netfilter/ipvs/ip_vs_core.c | 15 +++++++-------- net/netfilter/ipvs/ip_vs_proto_ah_esp.c | 17 ++++++++--------- 4 files changed, 25 insertions(+), 31 deletions(-)
include/net/ip_vs.h +4 -8
@@ -487,14 +487,12 @@ struct ip_vs_protocol {struct ip_vs_conn * (*conn_in_get)(int af,const struct sk_buff *skb, -const struct ip_vs_iphdr *iph, -int inverse); +const struct ip_vs_iphdr *iph);struct ip_vs_conn * (*conn_out_get)(int af,const struct sk_buff *skb, -const struct ip_vs_iphdr *iph, -int inverse); +const struct ip_vs_iphdr *iph);int (*snat_handler)(struct sk_buff *skb,struct ip_vs_protocol *pp,struct ip_vs_conn *cp,struct ip_vs_iphdr *iph);
@@ -1218,14 +1216,12 @@ struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p);struct ip_vs_conn *ip_vs_ct_in_get (const struct ip_vs_conn_param *p);struct ip_vs_conn *ip_vs_conn_in_get_proto (int af,const struct sk_buff *skb, -const struct ip_vs_iphdr *iph, -int inverse); +const struct ip_vs_iphdr *iph);struct ip_vs_conn *ip_vs_conn_out_get (const struct ip_vs_conn_param *p);struct ip_vs_conn *ip_vs_conn_out_get_proto (int af,const struct sk_buff *skb, -const struct ip_vs_iphdr *iph, -int inverse); +const struct ip_vs_iphdr *iph);/* Get reference to gain full access to conn. * By default, RCU read-side critical sections have access only to
net/netfilter/ipvs/ip_vs_conn.c +6 -6
@@ -316,7 +316,7 @@ struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p)static int ip_vs_conn_fill_param_proto (int af,const struct sk_buff *skb,const struct ip_vs_iphdr *iph, -int inverse,struct ip_vs_conn_param *p) +struct ip_vs_conn_param *p) {__be16 _ports[2 ], *pptr;struct net *net =skb_net (skb);
@@ -325,7 +325,7 @@ ip_vs_conn_fill_param_proto(int af, const struct sk_buff *skb,if (pptr ==NULL )return 1 ; -if (likely (!inverse)) +if (likely (!ip_vs_iph_inverse (iph)))ip_vs_conn_fill_param (net, af, iph->protocol, &iph->saddr, pptr[0 ], &iph->daddr, pptr[1 ], p);else
@@ -336,11 +336,11 @@ ip_vs_conn_fill_param_proto(int af, const struct sk_buff *skb,struct ip_vs_conn *ip_vs_conn_in_get_proto (int af,const struct sk_buff *skb, -const struct ip_vs_iphdr *iph,int inverse) +const struct ip_vs_iphdr *iph) {struct ip_vs_conn_param p; -if (ip_vs_conn_fill_param_proto (af, skb, iph, inverse, &p)) +if (ip_vs_conn_fill_param_proto (af, skb, iph, &p))return NULL ;return ip_vs_conn_in_get (&p);
@@ -440,11 +440,11 @@ struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p)struct ip_vs_conn *ip_vs_conn_out_get_proto (int af,const struct sk_buff *skb, -const struct ip_vs_iphdr *iph,int inverse) +const struct ip_vs_iphdr *iph) {struct ip_vs_conn_param p; -if (ip_vs_conn_fill_param_proto (af, skb, iph, inverse, &p)) +if (ip_vs_conn_fill_param_proto (af, skb, iph, &p))return NULL ;return ip_vs_conn_out_get (&p);
net/netfilter/ipvs/ip_vs_core.c +7 -8
@@ -445,7 +445,7 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,* Do not schedule replies from local real server. */ if ((!skb->dev || skb->dev->flags &IFF_LOOPBACK ) && - (cp = pp->conn_in_get (svc->af, skb, iph,1 ))) { + (cp = pp->conn_in_get (svc->af, skb, iph))) {IP_VS_DBG_PKT (12 , svc->af, pp, skb,0 ,"Not scheduling reply for existing connection" );__ip_vs_conn_put (cp);
@@ -937,7 +937,7 @@ static int ip_vs_out_icmp(struct sk_buff *skb, int *related,ip_vs_fill_iph_skb_icmp (AF_INET , skb, offset, true, &ciph);/* The embedded headers contain source and dest in reverse order */ - cp = pp->conn_out_get (AF_INET , skb, &ciph,1 ); + cp = pp->conn_out_get (AF_INET , skb, &ciph);if (!cp)return NF_ACCEPT ;
@@ -992,7 +992,7 @@ static int ip_vs_out_icmp_v6(struct sk_buff *skb, int *related,return NF_ACCEPT ;/* The embedded headers contain source and dest in reverse order */ - cp = pp->conn_out_get (AF_INET6 , skb, &ciph,1 ); + cp = pp->conn_out_get (AF_INET6 , skb, &ciph);if (!cp)return NF_ACCEPT ;
@@ -1218,7 +1218,7 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)/* * Check if the packet belongs to an existing entry */ - cp = pp->conn_out_get (af, skb, &iph,0 ); + cp = pp->conn_out_get (af, skb, &iph);if (likely (cp))return handle_response (af, skb, pd, cp, &iph, hooknum);
@@ -1448,7 +1448,7 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)/* The embedded headers contain source and dest in reverse order. * For IPIP this is error for request, not for reply. */ - cp = pp->conn_in_get (AF_INET , skb, &ciph, ipip ?0 :1 ); + cp = pp->conn_in_get (AF_INET , skb, &ciph);if (!cp)return NF_ACCEPT ;
@@ -1593,8 +1593,7 @@ static int ip_vs_in_icmp_v6(struct sk_buff *skb, int *related,/* The embedded headers contain source and dest in reverse order * if not from localhost */ - cp = pp->conn_in_get (AF_INET6 , skb, &ciph, - (hooknum ==NF_INET_LOCAL_OUT ) ?0 :1 ); + cp = pp->conn_in_get (AF_INET6 , skb, &ciph);if (!cp)return NF_ACCEPT ;
@@ -1704,7 +1703,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)/* * Check if the packet belongs to an existing connection entry */ - cp = pp->conn_in_get (af, skb, &iph,0 ); + cp = pp->conn_in_get (af, skb, &iph); conn_reuse_mode =sysctl_conn_reuse_mode (ipvs); if (conn_reuse_mode && !iph.fragoffs &&
net/netfilter/ipvs/ip_vs_proto_ah_esp.c +8 -9
@@ -42,10 +42,10 @@ struct isakmp_hdr {static void ah_esp_conn_fill_param_proto (struct net *net,int af, -const struct ip_vs_iphdr *iph,int inverse, +const struct ip_vs_iphdr *iph,struct ip_vs_conn_param *p) { -if (likely (!inverse)) +if (likely (!ip_vs_iph_inverse (iph)))ip_vs_conn_fill_param (net, af,IPPROTO_UDP , &iph->saddr,htons (PORT_ISAKMP ), &iph->daddr,htons (PORT_ISAKMP ), p);
@@ -57,14 +57,13 @@ ah_esp_conn_fill_param_proto(struct net *net, int af,static struct ip_vs_conn *ah_esp_conn_in_get (int af,const struct sk_buff *skb, -const struct ip_vs_iphdr *iph, -int inverse) +const struct ip_vs_iphdr *iph) {struct ip_vs_conn *cp;struct ip_vs_conn_param p;struct net *net =skb_net (skb); -ah_esp_conn_fill_param_proto (net, af, iph, inverse, &p); +ah_esp_conn_fill_param_proto (net, af, iph, &p); cp =ip_vs_conn_in_get (&p);if (!cp) {/*
@@ -73,7 +72,7 @@ ah_esp_conn_in_get(int af, const struct sk_buff *skb,*/ IP_VS_DBG_BUF (12 ,"Unknown ISAKMP entry for outin packet " "%s%s %s->%s\n" , - inverse ?"ICMP+" :"" , +ip_vs_iph_icmp (iph) ?"ICMP+" :"" ,ip_vs_proto_get (iph->protocol)->name,IP_VS_DBG_ADDR (af, &iph->saddr),IP_VS_DBG_ADDR (af, &iph->daddr));
@@ -85,18 +84,18 @@ ah_esp_conn_in_get(int af, const struct sk_buff *skb,static struct ip_vs_conn *ah_esp_conn_out_get (int af,const struct sk_buff *skb, -const struct ip_vs_iphdr *iph,int inverse) +const struct ip_vs_iphdr *iph) {struct ip_vs_conn *cp;struct ip_vs_conn_param p;struct net *net =skb_net (skb); -ah_esp_conn_fill_param_proto (net, af, iph, inverse, &p); +ah_esp_conn_fill_param_proto (net, af, iph, &p); cp =ip_vs_conn_out_get (&p);if (!cp) {IP_VS_DBG_BUF (12 ,"Unknown ISAKMP entry for inout packet " "%s%s %s->%s\n" , - inverse ?"ICMP+" :"" , +ip_vs_iph_icmp (iph) ?"ICMP+" :"" ,ip_vs_proto_get (iph->protocol)->name,IP_VS_DBG_ADDR (af, &iph->saddr),IP_VS_DBG_ADDR (af, &iph->daddr));
Signature · 1 line
Alex Gartrell <[email protected]>
PATCH 5/12 ipvs: Make ip_vs_schedule aware of inverse iph'es
In reply to Alex GartrellThis is necessary to schedule icmp later.
--- net/netfilter/ipvs/ip_vs_core.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +19 -7
@@ -418,7 +418,8 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,struct ip_vs_conn *cp =NULL ;struct ip_vs_scheduler *sched;struct ip_vs_dest *dest; -__be16 _ports[2 ], *pptr; +__be16 _ports[2 ], *pptr, cport, vport; +const void *caddr, *vaddr;unsigned int flags; *ignored =1 ;
@@ -429,13 +430,25 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,if (pptr ==NULL )return NULL ; +if (likely (!ip_vs_iph_inverse (iph))) { + cport = pptr[0 ]; + caddr = &iph->saddr; + vport = pptr[1 ]; + vaddr = &iph->daddr; + }else { + cport = pptr[1 ]; + caddr = &iph->daddr; + vport = pptr[0 ]; + vaddr = &iph->saddr; + } +/* * FTPDATA needs this check when using local real server. * Never schedule Active FTPDATA connections from real server. * For LVS-NAT they must be already created. For other methods * with persistence the connection is created on SYN+ACK. */ -if (pptr[0 ] ==FTPDATA ) { +if (cport ==FTPDATA ) {IP_VS_DBG_PKT (12 , svc->af, pp, skb,0 ,"Not scheduling FTPDATA" );return NULL ;
@@ -456,7 +469,7 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,* Persistent service */ if (svc->flags &IP_VS_SVC_F_PERSISTENT ) -return ip_vs_sched_persist (svc, skb, pptr[0 ], pptr[1 ], ignored, +return ip_vs_sched_persist (svc, skb, cport, vport, ignored, iph); *ignored =0 ;
@@ -464,7 +477,7 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,/* * Non-persistent service */ -if (!svc->fwmark && pptr[1 ] != svc->port) { +if (!svc->fwmark && vport != svc->port) {if (!svc->port)pr_err ("Schedule: port zero only supported " "in persistent services, "
@@ -496,10 +509,9 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,struct ip_vs_conn_param p;ip_vs_conn_fill_param (svc->net, svc->af, iph->protocol, - &iph->saddr, pptr[0 ], &iph->daddr, - pptr[1 ], &p); + caddr, cport, vaddr, vport, &p); cp =ip_vs_conn_new (&p, dest->af, &dest->addr, - dest->port ? dest->port : pptr[1 ], + dest->port ? dest->port : vport, flags, dest, skb->mark);if (!cp) { *ignored =-1 ;
Signature · 1 line
Alex Gartrell <[email protected]>
PATCH 6/12 ipvs: add schedule_icmp sysctl
In reply to Alex GartrellThis sysctl will be used to enable the scheduling of icmp packets.
--- include/net/ip_vs.h | 11 +++++++++++ net/netfilter/ipvs/ip_vs_ctl.c | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-)
include/net/ip_vs.h +11 -0
@@ -978,6 +978,7 @@ struct netns_ipvs {int sysctl_pmtu_disc;int sysctl_backup_only;int sysctl_conn_reuse_mode; +int sysctl_schedule_icmp;/* ip_vs_lblc */ int sysctl_lblc_expiration;
@@ -1101,6 +1102,11 @@ static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs) return ipvs->sysctl_conn_reuse_mode; } +static inline int sysctl_schedule_icmp (struct netns_ipvs *ipvs) +{ +return ipvs->sysctl_schedule_icmp; +} +#else static inline int sysctl_sync_threshold (struct netns_ipvs *ipvs)
@@ -1173,6 +1179,11 @@ static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs) return 1; } +static inline int sysctl_schedule_icmp (struct netns_ipvs *ipvs) +{ +return 0 ; +} +#endif /* IPVS core functions
net/netfilter/ipvs/ip_vs_ctl.c +6 -0
@@ -1844,6 +1844,12 @@ static struct ctl_table vs_vars[] = { .mode = 0644, .proc_handler = proc_dointvec, }, + { + .procname = "schedule_icmp", + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, #ifdef CONFIG_IP_VS_DEBUG { .procname = "debug_level",
@@ -3818,7 +3824,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net) tbl[idx++].data = &ipvs->sysctl_backup_only; ipvs->sysctl_conn_reuse_mode =1 ; tbl[idx++].data = &ipvs->sysctl_conn_reuse_mode;
PATCH 7/12 ipvs: Use outer header in ip_vs_bypass_xmit_v6
In reply to Alex GartrellThe ip_vs_iphdr may refer to an internal header, so use the outer one instead.
--- net/netfilter/ipvs/ip_vs_xmit.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_xmit.c +3 -1
@@ -656,10 +656,12 @@ int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh) { + struct ipv6hdr *iph = ipv6_hdr(skb); +EnterFunction (10 );rcu_read_lock (); -if (__ip_vs_get_out_rt_v6 (cp->af, skb,NULL , &ipvsh->daddr.in6,NULL , +if (__ip_vs_get_out_rt_v6 (cp->af, skb,NULL , &iph->daddr,NULL , ipvsh,0 ,IP_VS_RT_MODE_NON_LOCAL ) <0 ) goto tx_error;
Signature · 1 line
Alex Gartrell <[email protected]>
PATCH 8/12 ipvs: attempt to schedule icmp packets
In reply to Alex GartrellInvoke the try_to_schedule logic from the icmp path and update it to the appropriate ip_vs_conn_put function. The schedule functions have been updated to reject the packets immediately for now.
--- net/netfilter/ipvs/ip_vs_core.c | 41 +++++++++++++++++++++++++++++------ net/netfilter/ipvs/ip_vs_proto_sctp.c | 6 +++++ net/netfilter/ipvs/ip_vs_proto_tcp.c | 7 ++++++ net/netfilter/ipvs/ip_vs_proto_udp.c | 6 +++++ 4 files changed, 53 insertions(+), 7 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +34 -7
@@ -1383,7 +1383,7 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)struct ip_vs_protocol *pp;struct ip_vs_proto_data *pd;unsigned int offset, offset2, ihl, verdict; -bool ipip; +bool ipip, new_cp = false; *related =1 ;
@@ -1461,7 +1461,16 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)* For IPIP this is error for request, not for reply. */ cp = pp->conn_in_get (AF_INET , skb, &ciph); -if (!cp) + +if (!cp &&sysctl_schedule_icmp (net_ipvs (net))) { +int v; + +if (!ip_vs_try_to_schedule (AF_INET , skb, pd, &v, &cp, &ciph)) +return v; + new_cp = true; + } + +if (unlikely (!cp))return NF_ACCEPT ; verdict =NF_DROP ;
@@ -1539,7 +1548,10 @@ ignore_ipip: verdict =ip_vs_icmp_xmit (skb, cp, pp, offset, hooknum, &ciph); out: -__ip_vs_conn_put (cp); +if (likely (!new_cp)) +__ip_vs_conn_put (cp); +else +ip_vs_conn_put (cp);return verdict; }
@@ -1555,6 +1567,7 @@ static int ip_vs_in_icmp_v6(struct sk_buff *skb, int *related,struct ip_vs_protocol *pp;struct ip_vs_proto_data *pd;unsigned int offs_ciph, writable, verdict; +bool new_cp = false; *related =1 ;
@@ -1607,13 +1620,23 @@ static int ip_vs_in_icmp_v6(struct sk_buff *skb, int *related,*/ cp = pp->conn_in_get (AF_INET6 , skb, &ciph); -if (!cp) +if (!cp &&sysctl_schedule_icmp (net_ipvs (net))) { +int v; + +if (!ip_vs_try_to_schedule (AF_INET6 , skb, pd, &v, &cp, &ciph)) +return v; + + new_cp = true; + } + +if (unlikely (!cp))return NF_ACCEPT ; +/* VS/TUN, VS/DR and LOCALNODE just let it go */ if ((hooknum ==NF_INET_LOCAL_OUT ) && (IP_VS_FWD_METHOD (cp) !=IP_VS_CONN_F_MASQ )) { -__ip_vs_conn_put (cp); -return NF_ACCEPT ; + verdict =NF_ACCEPT ; + goto out; }/* do the statistics and put it back */
@@ -1627,7 +1650,11 @@ static int ip_vs_in_icmp_v6(struct sk_buff *skb, int *related, verdict =ip_vs_icmp_xmit_v6 (skb, cp, pp, writable, hooknum, &ciph); -__ip_vs_conn_put (cp); +out: +if (likely (!new_cp)) +__ip_vs_conn_put (cp); +else +ip_vs_conn_put (cp);return verdict; }
net/netfilter/ipvs/ip_vs_proto_sctp.c +6 -0
@@ -19,6 +19,12 @@ sctp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,sctp_chunkhdr_t _schunkh, *sch;sctp_sctphdr_t *sh, _sctph; +if (ip_vs_iph_icmp (iph)) { +/* TEMPORARY - do not schedule icmp yet */ + *verdict =NF_ACCEPT ; +return 0 ; + } + sh =skb_header_pointer (skb, iph->len,sizeof (_sctph), &_sctph);if (sh ==NULL ) { *verdict =NF_DROP ;
net/netfilter/ipvs/ip_vs_proto_tcp.c +7 -0
@@ -41,6 +41,12 @@ tcp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,struct tcphdr _tcph, *th;struct netns_ipvs *ipvs; +if (ip_vs_iph_icmp (iph)) { +/* TEMPORARY - do not schedule icmp yet */ + *verdict =NF_ACCEPT ; +return 0 ; + } + th =skb_header_pointer (skb, iph->len,sizeof (_tcph), &_tcph);if (th ==NULL ) { *verdict =NF_DROP ;
@@ -48,6 +54,7 @@ tcp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd, } net =skb_net (skb); ipvs =net_ipvs (net); +/* No !th->ack check to allow scheduling on SYN+ACK for Active FTP */ rcu_read_lock (); if ((th->syn || sysctl_sloppy_tcp(ipvs)) && !th->rst &&
net/netfilter/ipvs/ip_vs_proto_udp.c +6 -0
@@ -37,6 +37,12 @@ udp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,struct ip_vs_service *svc;struct udphdr _udph, *uh; +if (ip_vs_iph_icmp (iph)) { +/* TEMPORARY - do not schedule icmp yet */ + *verdict =NF_ACCEPT ; +return 0 ; + } +/* IPv6 fragments, only first fragment will hit this */ uh =skb_header_pointer (skb, iph->len,sizeof (_udph), &_udph);if (uh ==NULL ) {
Signature · 1 line
Alex Gartrell <[email protected]>
PATCH 9/12 ipvs: ensure that ICMP cannot be sent in reply to ICMP
In reply to Alex GartrellCheck the header for icmp before sending a PACKET_TOO_BIG
--- net/netfilter/ipvs/ip_vs_xmit.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/netfilter/ipvs/ip_vs_xmit.c +3 -2
@@ -224,7 +224,7 @@ static inline bool ensure_mtu_is_adequate(int skb_af, int rt_mode,if (!skb->dev) skb->dev = net->loopback_dev;/* only send ICMP too big on first fragment */ -if (!ipvsh->fragoffs) +if (!ipvsh->fragoffs && !ip_vs_iph_icmp (ipvsh))icmpv6_send (skb,ICMPV6_PKT_TOOBIG ,0 , mtu);IP_VS_DBG (1 ,"frag needed for %pI6c\n" , &ipv6_hdr (skb)->saddr);
@@ -242,7 +242,8 @@ static inline bool ensure_mtu_is_adequate(int skb_af, int rt_mode,return true;if (unlikely (ip_hdr (skb)->frag_off &htons (IP_DF ) && - skb->len > mtu && !skb_is_gso (skb))) { + skb->len > mtu && !skb_is_gso (skb) && + !ip_vs_iph_icmp (ipvsh))) {icmp_send (skb,ICMP_DEST_UNREACH ,ICMP_FRAG_NEEDED ,htonl (mtu)); IP_VS_DBG(1, "frag needed for %pI4\n",
Signature · 1 line
Alex Gartrell <[email protected]>
PATCH 10/12 ipvs: support scheduling inverse and icmp TCP packets
In reply to Alex GartrellIn the event of an icmp packet, take only the ports instead of trying to grab the full header.
In the event of an inverse packet, use the source address and port.
--- net/netfilter/ipvs/ip_vs_proto_tcp.c | 40 +++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-)
net/netfilter/ipvs/ip_vs_proto_tcp.c +28 -12
@@ -40,26 +40,42 @@ tcp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,struct ip_vs_service *svc;struct tcphdr _tcph, *th;struct netns_ipvs *ipvs; +__be16 _ports[2 ], *ports =NULL ; -if (ip_vs_iph_icmp (iph)) { -/* TEMPORARY - do not schedule icmp yet */ - *verdict =NF_ACCEPT ; -return 0 ; - } + net =skb_net (skb); + ipvs =net_ipvs (net); + +/* In the event of icmp, we're only guaranteed to have the first 8 +* bytes of the transport header, so we only check the rest of the +* TCP packet for non-ICMP packets +*/ +if (likely (!ip_vs_iph_icmp (iph))) { + th =skb_header_pointer (skb, iph->len,sizeof (_tcph), &_tcph); +if (th) { +if (th->rst || !(sysctl_sloppy_tcp (ipvs) || th->syn)) +return 1 ; + ports = &th->source; + } + }else + ports =skb_header_pointer ( + skb, iph->len,sizeof (_ports), &_ports); - th =skb_header_pointer (skb, iph->len,sizeof (_tcph), &_tcph); -if (th ==NULL ) { +if (!ports) { *verdict =NF_DROP ;return 0 ; } - net =skb_net (skb); - ipvs =net_ipvs (net);/* No !th->ack check to allow scheduling on SYN+ACK for Active FTP */ rcu_read_lock (); -if ((th->syn ||sysctl_sloppy_tcp (ipvs)) && !th->rst && - (svc =ip_vs_service_find (net, af, skb->mark, iph->protocol, - &iph->daddr, th->dest))) { + +if (likely (!ip_vs_iph_inverse (iph))) + svc =ip_vs_service_find (net, af, skb->mark, iph->protocol, + &iph->daddr, ports[1 ]); +else + svc =ip_vs_service_find (net, af, skb->mark, iph->protocol, + &iph->saddr, ports[0 ]); + +if (svc) {int ignored;if (ip_vs_todrop (ipvs)) {
Signature · 1 line
Alex Gartrell <[email protected]>
PATCH 11/12 ipvs: support scheduling inverse and icmp UDP packets
In reply to Alex GartrellIn the event of an icmp packet, take only the ports instead of trying to grab the full header.
In the event of an inverse packet, use the source address and port.
--- net/netfilter/ipvs/ip_vs_proto_udp.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)
net/netfilter/ipvs/ip_vs_proto_udp.c +20 -12
@@ -36,23 +36,31 @@ udp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,struct net *net;struct ip_vs_service *svc;struct udphdr _udph, *uh; - -if (ip_vs_iph_icmp (iph)) { -/* TEMPORARY - do not schedule icmp yet */ - *verdict =NF_ACCEPT ; -return 0 ; - } - -/* IPv6 fragments, only first fragment will hit this */ - uh =skb_header_pointer (skb, iph->len,sizeof (_udph), &_udph); -if (uh ==NULL ) { +__be16 _ports[2 ], *ports =NULL ; + +if (likely (!ip_vs_iph_icmp (iph))) { +/* IPv6 fragments, only first fragment will hit this */ + uh =skb_header_pointer (skb, iph->len,sizeof (_udph), &_udph); +if (uh) + ports = &uh->source; + }else + ports =skb_header_pointer ( + skb, iph->len,sizeof (_ports), &_ports); + +if (!ports) { *verdict =NF_DROP ;return 0 ; } + net =skb_net (skb);rcu_read_lock (); - svc =ip_vs_service_find (net, af, skb->mark, iph->protocol, - &iph->daddr, uh->dest); +if (likely (!ip_vs_iph_inverse (iph))) + svc =ip_vs_service_find (net, af, skb->mark, iph->protocol, + &iph->daddr, ports[1 ]); +else + svc =ip_vs_service_find (net, af, skb->mark, iph->protocol, + &iph->saddr, ports[0 ]); +if (svc) {int ignored;
Signature · 1 line
Alex Gartrell <[email protected]>
PATCH 12/12 ipvs: support scheduling inverse and icmp SCTP packets
In reply to Alex GartrellIn the event of an icmp packet, take only the ports instead of trying to grab the full header.
In the event of an inverse packet, use the source address and port.
--- net/netfilter/ipvs/ip_vs_proto_sctp.c | 41 ++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 18 deletions(-)
net/netfilter/ipvs/ip_vs_proto_sctp.c +23 -18
@@ -18,22 +18,23 @@ sctp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,struct netns_ipvs *ipvs;sctp_chunkhdr_t _schunkh, *sch;sctp_sctphdr_t *sh, _sctph; +__be16 _ports[2 ], *ports =NULL ; + +if (likely (!ip_vs_iph_icmp (iph))) { + sh =skb_header_pointer (skb, iph->len,sizeof (_sctph), &_sctph); +if (sh) { + sch =skb_header_pointer ( + skb, iph->len +sizeof (sctp_sctphdr_t), +sizeof (_schunkh), &_schunkh); +if (sch && (sch->type ==SCTP_CID_INIT || +sysctl_sloppy_sctp (ipvs))) + ports = &sh->source; + } + }else + ports =skb_header_pointer ( + skb, iph->len,sizeof (_ports), &_ports); -if (ip_vs_iph_icmp (iph)) { -/* TEMPORARY - do not schedule icmp yet */ - *verdict =NF_ACCEPT ; -return 0 ; - } - - sh =skb_header_pointer (skb, iph->len,sizeof (_sctph), &_sctph); -if (sh ==NULL ) { - *verdict =NF_DROP ; -return 0 ; - } - - sch =skb_header_pointer (skb, iph->len +sizeof (sctp_sctphdr_t), -sizeof (_schunkh), &_schunkh); -if (sch ==NULL ) { +if (!ports) { *verdict =NF_DROP ;return 0 ; }
@@ -41,9 +42,13 @@ sctp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd, net =skb_net (skb); ipvs =net_ipvs (net);rcu_read_lock (); -if ((sch->type ==SCTP_CID_INIT ||sysctl_sloppy_sctp (ipvs)) && - (svc =ip_vs_service_find (net, af, skb->mark, iph->protocol, - &iph->daddr, sh->dest))) { +if (likely (!ip_vs_iph_inverse (iph))) + svc =ip_vs_service_find (net, af, skb->mark, iph->protocol, + &iph->daddr, ports[1 ]); +else + svc =ip_vs_service_find (net, af, skb->mark, iph->protocol, + &iph->saddr, ports[0 ]); +if (svc) {int ignored;if (ip_vs_todrop (ipvs)) {
Signature · 1 line
Alex Gartrell <[email protected]>
Julian Anastasov
maintainerHello,
Quoted 19 lines · Alex Gartrell
The configuration of ipvs at Facebook is relatively straightforward. All ipvs instances bgp advertise a set of VIPs and the network prefers the nearest one or uses ECMP in the event of a tie. For the uninitiated, ECMP deterministically and statelessly load balances by hashing the packet (usually a 5-tuple of protocol, saddr, daddr, sport, and dport) and using that number as an index (basic hash table type logic).
The problem is that ICMP packets (which contain really important information like whether or not an MTU has been exceeded) will get a different hash value and may end up at a different ipvs instance. With no information about where to route these packets, they are dropped, creating ICMP black holes and breaking Path MTU discovery. Suddenly, my mom's pictures can't load and I'm fielding midday calls that I want nothing to do with.
To address this, this patch set introduces the ability to schedule icmp packets which is gated by a sysctl net.ipv4.vs.schedule_icmp. If set to 0, the old behavior is maintained -- otherwise ICMP packets are scheduled.
Quoted 13 lines
Alex Gartrell (12):
ipvs: pull outip_vs_try_to_schedulefunction
ipvs: replaceip_vs_fill_ip4hdrwithip_vs_fill_iph_skb_off
ipvs: Addhdr_flagsto iphdr
ipvs: drop inverse argument to conn_{in,out}_get
ipvs: Makeip_vs_scheduleaware of inverse iph'es
ipvs: addschedule_icmpsysctl
ipvs: Use outer header inip_vs_bypass_xmit_v6
ipvs: attempt to schedule icmp packets
ipvs: ensure that ICMP cannot be sent in reply to ICMP
ipvs: support scheduling inverse and icmp TCP packets
ipvs: support scheduling inverse and icmp UDP packets
ipvs: support scheduling inverse and icmp SCTP packets
What is missing in this patchset is a change to ip_vs_sh.c
Patch 1:
- we always provide offset 0 here:IP_VS_DBG_PKT(7, af, pp, skb, 0, "unhandled fragment");
We may need to add 'offset' field to struct ip_vs_iphdr,
so that we can provide valid offset to the IP_VS_DBG_PKT and IP_VS_DBG_RL_PKT macros. We do not provide inverse flag to the pp->debug_packet handler but it is not so fatal.
Patch 2:
- ip_vs_out_icmp_v6: first args of ip_vs_fill_iph_skb_off can be on same line
- ip_vs_in_icmp: any good reason the ip_vs_fill_iph_skb_off call to be moved early? Better to keep it at the ip_vs_fill_ip4hdr's place. It is still before the conn_in_get call.
- ip_vs_in_icmp: this line should not be removed:
"- offset = ciph.len;"
because offset is used later as arg to ip_vs_icmp_xmit. offset provides offset to header but we later need to skip this header and to reach the ports in transport header.
- ip_vs_in_icmp_v6: we better to rename offs_ciph to offset and later to use it where 'writable' is used, then code will look like ip_vs_in_icmp
Patch 3:
- breaks compilation of net/netfilter/ipvs/ip_vs_pe_sip.c and net/netfilter/xt_ipvs.c
- do not forget that net/netfilter/xt_ipvs.c has calls to ip_vs_fill_iph_skb and conn_out_get, include it in your .config for building:
make net/netfilter/ipvs/ net/netfilter/xt_ipvs.o
- ip_vs_fill_iph_skb_off: if we later add more flags? Should we provide instead just a hdr_flags arg with IP_VS_HDR_* mask?
- ip_vs_out_icmp_v6: first args for ip_vs_fill_iph_skb_icmp should be on same line
- ip_vs_in_icmp_v6: first args for ip_vs_fill_iph_skb_icmp should be on same line
- ip_vs_in_icmp_v6: I now see that this check from
commit 2f74713d1436 ("ipvs: Complete IPv6 fragment handling for IPVS") '(hooknum == NF_INET_LOCAL_OUT) ? 0 : 1' is simply wrong for local clients, we should always use 'true' instead of (hooknum != NF_INET_LOCAL_OUT).
Patch 4:
- breaks compilation of net/netfilter/xt_ipvs.c
- ip_vs_schedule: first hunk shows that we provide inverse=1 to conn_in_get. This is the only odd place that does such inverse check. May be we can change the bit before and after conn_in_get?:
if (!skb->dev || skb->dev->flags & IFF_LOOPBACK) {
iph->hdr_flags ^= IP_VS_HDR_INVERSE;
cp = pp->conn_in_get(svc->af, skb, iph);
iph->hdr_flags ^= IP_VS_HDR_INVERSE;
if (cp) {
IP_VS_DBG_PKT(12, svc->af, pp, skb, 0,
"Not scheduling reply for existing "
"connection");
__ip_vs_conn_put(cp);
return NULL;
}
}Patch 5:
- ip_vs_schedule: we should provide iph->offset as arg to IP_VS_DBG_PKT
Patch 6: OK
Patch 7: OK
Patch 8:
- ip_vs_in_icmp: may be we can avoid 2nd !cp check as follows?:
if (!cp) {
int v;
if (!sysctl_schedule_icmp(net_ipvs(net)))
return NF_ACCEPT;
if (!ip_vs_try_to_schedule(AF_INET, skb, pd, &v, &cp, &ciph))
return v;
new_cp = true;
}- same for ip_vs_in_icmp_v6
Patch 9: OK
Patch 10:
- use {} after else if the 'if' part has {}
Patch 11:
- use {} after else if the 'if' part has {}
Patch 12:
- use {} after else if the 'if' part has {}
Regards
--
Julian Anastasov <[email protected]>
Thank you again for you comments, Julian
Quoted 2 lines · Julian Anastasov
What is missing in this patchset is a change to
ip_vs_sh.c
+1 -- I'll add it.
Quoted 9 lines
Patch 1:
- we always provide offset 0 here:IP_VS_DBG_PKT(7, af, pp, skb, 0, "unhandled fragment");We may need to add 'offset' field to struct
ip_vs_iphdr,
so that we can provide valid offset to theIP_VS_DBG_PKTandIP_VS_DBG_RL_PKTmacros. We do not provide inverse flag to thepp->debug_packethandler but it is not so fatal.
I'll bump this to patch 3 and then add the offset field for these debug macros.
Quoted 4 lines
Patch 2:
-
ip_vs_out_icmp_v6: first args ofip_vs_fill_iph_skb_offcan be on same line
I'm used the other style, but I'll do this.
Quoted 3 lines
-
ip_vs_in_icmp: any good reason theip_vs_fill_iph_skb_offcall to be moved early? Better to keep it at the ip_vs_fill_ip4hdr's place. It is still before theconn_in_getcall.
I misunderstand the offset/offset2 swapping that was happening here.
Quoted 11 lines
-
ip_vs_in_icmp: this line should not be removed:
"- offset = ciph.len;"because offset is used later as arg to
ip_vs_icmp_xmit. offset provides offset to header but we later need to skip this header and to reach the ports in transport header.-
ip_vs_in_icmp_v6: we better to renameoffs_ciphto offset and later to use it where 'writable' is used, then code will look likeip_vs_in_icmp
I'll incorporate this
Quoted 5 lines
Patch 3:
- breaks compilation of
net/netfilter/ipvs/ip_vs_pe_sip.candnet/netfilter/xt_ipvs.c
Quoted 7 lines
- do not forget that
net/netfilter/xt_ipvs.chas calls toip_vs_fill_iph_skbandconn_out_get, include it in your .config for building:
makenet/netfilter/ipvs/net/netfilter/xt_ipvs.o-
ip_vs_fill_iph_skb_off: if we later add more flags? Should we provide instead just ahdr_flagsarg with IP_VS_HDR_* mask?
Yeah I went with the booleans at first because providing the flags I'll do this.
Quoted 11 lines
-
ip_vs_out_icmp_v6: first args forip_vs_fill_iph_skb_icmpshould be on same line-
ip_vs_in_icmp_v6: first args forip_vs_fill_iph_skb_icmpshould be on same line-
ip_vs_in_icmp_v6: I now see that this check from
commit2f74713d1436("ipvs: Complete IPv6 fragment handling for IPVS") '(hooknum ==NF_INET_LOCAL_OUT) ? 0 : 1' is simply wrong for local clients, we should always use 'true' instead of (hooknum !=NF_INET_LOCAL_OUT).
Ah cool, that makes a lot more sense.
Quoted 44 lines
Patch 4:
- breaks compilation of
net/netfilter/xt_ipvs.c-
ip_vs_schedule: first hunk shows that we provide inverse=1 toconn_in_get. This is the only odd place that does such inverse check. May be we can change the bit before and afterconn_in_get?:if (!skb->dev || skb->dev->flags & IFF_LOOPBACK) { iph->hdr_flags ^= IP_VS_HDR_INVERSE; cp = pp->conn_in_get(svc->af, skb, iph); iph->hdr_flags ^= IP_VS_HDR_INVERSE; if (cp) { IP_VS_DBG_PKT(12, svc->af, pp, skb, 0, "Not scheduling reply for existing " "connection"); __ip_vs_conn_put(cp); return NULL; } }Patch 5:
-
ip_vs_schedule: we should provideiph->offsetas arg toIP_VS_DBG_PKTPatch 6: OK
Patch 7: OK
Patch 8:
-
ip_vs_in_icmp: may be we can avoid 2nd !cp check as follows?:if (!cp) { int v; if (!sysctl_schedule_icmp(net_ipvs(net))) return NF_ACCEPT; if (!ip_vs_try_to_schedule(AF_INET, skb, pd, &v, &cp, &ciph)) return v; new_cp = true; }
Quoted 2 lines
- same for
ip_vs_in_icmp_v6
Yeah I can do this.
new patch set coming. Thanks again for the thorough review!
cheers,
Signature · 1 line
Alex Gartrell <[email protected]>
Quoted 5 lines · Patrick Schaaf
Am 12.08.2015 22:47 schrieb "Alex Gartrell" <[email protected]>:
Sounds like a missing feature in whatever does that ECMP thing, not being able to recognize ICMP / look at the ICMP inner L3/L4 addresses to drive the hashing. If you could get that to change, no partially-working (needing static schedule) IPVS hack would be neccessary, right?
If we were able to get the router to do the right thing, it would definitely deal with the steady state case. There are still two problems though:
1) Doing this in the routers (in hardware) is /really/ hard. Your ASIC has to be able to descend into the icmp payload, which is non-trivial. For an example of where this routinely fails, simply look at how routers and NICs handle ipv6 extension headers -- the major NIC vendors simply give up immediately and omit the ports from the hash.
2) It doesn't address the situation in which you want to swap or restart and IPVS instance (as for sloppy TCP). This will happen if you add or remove next-hops via BGP or if you simply swap one.
tl;dr; it's too hard to change routers and, even if we did, it doesn't address the "sloppy" scheduling case.
Signature · 1 line
Alex Gartrell <[email protected]>