netfilter: ipvs: remove unneeded hook wrappers
Subsystems (3)
Florian Westphal
maintainerv2 cover netfilter: ipvs: remove unneeded hook wrappers
V2: Patch 4/4 had a bug that would enter ipv6 branch for ipv4 packets, fix that.
This series reduces the number of different hook function implementations by merging the ipv4 and ipv6 hooks into common code.
selftests/netfilter/ipvs.sh passes.
Florian Westphal (4):
netfilter: ipvs: prepare for hook function reduction
netfilter: ipvs: remove unneeded output wrappers
netfilter: ipvs: remove unneeded input wrappers
netfilter: ipvs: merge ipv4 + ipv6 icmp reply handlers
net/netfilter/ipvs/ip_vs_core.c | 166 ++++++-------------------------- 1 file changed, 32 insertions(+), 134 deletions(-)
Signature · 1 line
2.32.0
Florian Westphal
maintainerPATCH v2 1/4 netfilter: ipvs: prepare for hook function reduction
ipvs has multiple one-line wrappers for hooks, compact them.
To avoid a large patch make the two most common helpers use the same function signature as hooks.
Next patches can then remove the oneline wrappers.
--- net/netfilter/ipvs/ip_vs_core.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +16 -10
@@ -1330,12 +1330,15 @@ handle_response(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,* Check if outgoing packet belongs to the established ip_vs_conn. */ static unsigned int -ip_vs_out (struct netns_ipvs *ipvs,unsigned int hooknum,struct sk_buff *skb,int af) +ip_vs_out_hook (void *priv,struct sk_buff *skb,const struct nf_hook_state *state) { +struct netns_ipvs *ipvs =net_ipvs (state->net); +unsigned int hooknum = state->hook;struct ip_vs_iphdr iph;struct ip_vs_protocol *pp;struct ip_vs_proto_data *pd;struct ip_vs_conn *cp; +int af = state->pf;struct sock *sk;EnterFunction (11 );
@@ -1477,7 +1480,7 @@ static unsigned int ip_vs_reply4(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -return ip_vs_out (net_ipvs (state->net), state->hook, skb,AF_INET ); +return ip_vs_out_hook (priv, skb, state); }/*
@@ -1488,7 +1491,7 @@ static unsigned int ip_vs_local_reply4(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -return ip_vs_out (net_ipvs (state->net), state->hook, skb,AF_INET ); +return ip_vs_out_hook (priv, skb, state); }#ifdef CONFIG_IP_VS_IPV6
@@ -1502,7 +1505,7 @@ static unsigned int ip_vs_reply6(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -return ip_vs_out (net_ipvs (state->net), state->hook, skb,AF_INET6 ); +return ip_vs_out_hook (priv, skb, state); }/*
@@ -1513,7 +1516,7 @@ static unsigned int ip_vs_local_reply6(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -return ip_vs_out (net_ipvs (state->net), state->hook, skb,AF_INET6 ); +return ip_vs_out_hook (priv, skb, state); }#endif
@@ -1957,8 +1960,10 @@ static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,* and send it on its way... */ static unsigned int -ip_vs_in (struct netns_ipvs *ipvs,unsigned int hooknum,struct sk_buff *skb,int af) +ip_vs_in_hook (void *priv,struct sk_buff *skb,const struct nf_hook_state *state) { +struct netns_ipvs *ipvs =net_ipvs (state->net); +unsigned int hooknum = state->hook;struct ip_vs_iphdr iph;struct ip_vs_protocol *pp;struct ip_vs_proto_data *pd;
@@ -1966,6 +1971,7 @@ ip_vs_in(struct netns_ipvs *ipvs, unsigned int hooknum, struct sk_buff *skb, intint ret, pkts;int conn_reuse_mode;struct sock *sk; +int af = state->pf;/* Already marked as IPVS request or reply? */ if (skb->ipvs_property)
@@ -2145,7 +2151,7 @@ static unsigned int ip_vs_remote_request4(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -return ip_vs_in (net_ipvs (state->net), state->hook, skb,AF_INET ); +return ip_vs_in_hook (priv, skb, state); }/*
@@ -2156,7 +2162,7 @@ static unsigned int ip_vs_local_request4(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -return ip_vs_in (net_ipvs (state->net), state->hook, skb,AF_INET ); +return ip_vs_in_hook (priv, skb, state); }#ifdef CONFIG_IP_VS_IPV6
@@ -2169,7 +2175,7 @@ static unsigned int ip_vs_remote_request6(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -return ip_vs_in (net_ipvs (state->net), state->hook, skb,AF_INET6 ); +return ip_vs_in_hook (priv, skb, state); }/*
@@ -2180,7 +2186,7 @@ static unsigned int ip_vs_local_request6(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -return ip_vs_in (net_ipvs (state->net), state->hook, skb,AF_INET6 ); +return ip_vs_in_hook (priv, skb, state); }#endif
Signature · 1 line
2.32.0
Florian Westphal
maintainerPATCH v2 2/4 netfilter: ipvs: remove unneeded output wrappers
In reply to Florian WestphalAfter earlier patch we can use ip_vs_out_hook directly.
--- net/netfilter/ipvs/ip_vs_core.c | 62 ++++----------------------------- 1 file changed, 6 insertions(+), 56 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +6 -56
@@ -1471,56 +1471,6 @@ ip_vs_out_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *statreturn NF_ACCEPT ; } -/* -* It is hooked at the NF_INET_FORWARD and NF_INET_LOCAL_IN chain, -* used only for VS/NAT. -* Check if packet is reply for established ip_vs_conn. -*/ -static unsigned int -ip_vs_reply4 (void *priv,struct sk_buff *skb, -const struct nf_hook_state *state) -{ -return ip_vs_out_hook (priv, skb, state); -} - -/* -* It is hooked at the NF_INET_LOCAL_OUT chain, used only for VS/NAT. -* Check if packet is reply for established ip_vs_conn. -*/ -static unsigned int -ip_vs_local_reply4 (void *priv,struct sk_buff *skb, -const struct nf_hook_state *state) -{ -return ip_vs_out_hook (priv, skb, state); -} - -#ifdef CONFIG_IP_VS_IPV6 - -/* -* It is hooked at the NF_INET_FORWARD and NF_INET_LOCAL_IN chain, -* used only for VS/NAT. -* Check if packet is reply for established ip_vs_conn. -*/ -static unsigned int -ip_vs_reply6 (void *priv,struct sk_buff *skb, -const struct nf_hook_state *state) -{ -return ip_vs_out_hook (priv, skb, state); -} - -/* -* It is hooked at the NF_INET_LOCAL_OUT chain, used only for VS/NAT. -* Check if packet is reply for established ip_vs_conn. -*/ -static unsigned int -ip_vs_local_reply6 (void *priv,struct sk_buff *skb, -const struct nf_hook_state *state) -{ -return ip_vs_out_hook (priv, skb, state); -} - -#endif - static unsigned int ip_vs_try_to_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,
@@ -2243,7 +2193,7 @@ ip_vs_forward_icmp_v6(void *priv, struct sk_buff *skb,static const struct nf_hook_ops ip_vs_ops4[] = {/* After packet filtering, change source only for VS/NAT */ { - .hook = ip_vs_reply4, + .hook = ip_vs_out_hook, .pf =NFPROTO_IPV4 , .hooknum =NF_INET_LOCAL_IN , .priority =NF_IP_PRI_NAT_SRC -2 ,
@@ -2259,7 +2209,7 @@ static const struct nf_hook_ops ip_vs_ops4[] = { },/* Before ip_vs_in, change source only for VS/NAT */ { - .hook = ip_vs_local_reply4, + .hook = ip_vs_out_hook, .pf = NFPROTO_IPV4, .hooknum = NF_INET_LOCAL_OUT, .priority = NF_IP_PRI_NAT_DST + 1,
@@ -2281,7 +2231,7 @@ static const struct nf_hook_ops ip_vs_ops4[] = { },/* After packet filtering, change source only for VS/NAT */ { - .hook = ip_vs_reply4, + .hook = ip_vs_out_hook, .pf = NFPROTO_IPV4, .hooknum = NF_INET_FORWARD, .priority = 100,
@@ -2292,7 +2242,7 @@ static const struct nf_hook_ops ip_vs_ops4[] = {static const struct nf_hook_ops ip_vs_ops6[] = {/* After packet filtering, change source only for VS/NAT */ { - .hook = ip_vs_reply6, + .hook = ip_vs_out_hook, .pf =NFPROTO_IPV6 , .hooknum =NF_INET_LOCAL_IN , .priority =NF_IP6_PRI_NAT_SRC -2 ,
@@ -2308,7 +2258,7 @@ static const struct nf_hook_ops ip_vs_ops6[] = { },/* Before ip_vs_in, change source only for VS/NAT */ { - .hook = ip_vs_local_reply6, + .hook = ip_vs_out_hook, .pf = NFPROTO_IPV6, .hooknum = NF_INET_LOCAL_OUT, .priority = NF_IP6_PRI_NAT_DST + 1,
@@ -2330,7 +2280,7 @@ static const struct nf_hook_ops ip_vs_ops6[] = { },/* After packet filtering, change source only for VS/NAT */ { - .hook = ip_vs_reply6, + .hook = ip_vs_out_hook, .pf = NFPROTO_IPV6, .hooknum = NF_INET_FORWARD, .priority = 100,
Signature · 1 line
2.32.0
Florian Westphal
maintainerPATCH v2 3/4 netfilter: ipvs: remove unneeded input wrappers
In reply to Florian WestphalAfter earlier patch ip_vs_hook_in can be used directly.
--- net/netfilter/ipvs/ip_vs_core.c | 57 +++------------------------------ 1 file changed, 4 insertions(+), 53 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +4 -53
@@ -2093,55 +2093,6 @@ ip_vs_in_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *statereturn ret; } -/* -* AF_INET handler in NF_INET_LOCAL_IN chain -* Schedule and forward packets from remote clients -*/ -static unsigned int -ip_vs_remote_request4 (void *priv,struct sk_buff *skb, -const struct nf_hook_state *state) -{ -return ip_vs_in_hook (priv, skb, state); -} - -/* -* AF_INET handler in NF_INET_LOCAL_OUT chain -* Schedule and forward packets from local clients -*/ -static unsigned int -ip_vs_local_request4 (void *priv,struct sk_buff *skb, -const struct nf_hook_state *state) -{ -return ip_vs_in_hook (priv, skb, state); -} - -#ifdef CONFIG_IP_VS_IPV6 - -/* -* AF_INET6 handler in NF_INET_LOCAL_IN chain -* Schedule and forward packets from remote clients -*/ -static unsigned int -ip_vs_remote_request6 (void *priv,struct sk_buff *skb, -const struct nf_hook_state *state) -{ -return ip_vs_in_hook (priv, skb, state); -} - -/* -* AF_INET6 handler in NF_INET_LOCAL_OUT chain -* Schedule and forward packets from local clients -*/ -static unsigned int -ip_vs_local_request6 (void *priv,struct sk_buff *skb, -const struct nf_hook_state *state) -{ -return ip_vs_in_hook (priv, skb, state); -} - -#endif - -/* * It is hooked at the NF_INET_FORWARD chain, in order to catch ICMP * related packets destined for 0.0.0.0/0.
@@ -2202,7 +2153,7 @@ static const struct nf_hook_ops ip_vs_ops4[] = {* or VS/NAT(change destination), so that filtering rules can be * applied to IPVS. */ { - .hook = ip_vs_remote_request4, + .hook = ip_vs_in_hook, .pf = NFPROTO_IPV4, .hooknum = NF_INET_LOCAL_IN, .priority = NF_IP_PRI_NAT_SRC - 1,
@@ -2216,7 +2167,7 @@ static const struct nf_hook_ops ip_vs_ops4[] = { },/* After mangle, schedule and forward local requests */ { - .hook = ip_vs_local_request4, + .hook = ip_vs_in_hook, .pf = NFPROTO_IPV4, .hooknum = NF_INET_LOCAL_OUT, .priority = NF_IP_PRI_NAT_DST + 2,
@@ -2251,7 +2202,7 @@ static const struct nf_hook_ops ip_vs_ops6[] = {* or VS/NAT(change destination), so that filtering rules can be * applied to IPVS. */ { - .hook = ip_vs_remote_request6, + .hook = ip_vs_in_hook, .pf = NFPROTO_IPV6, .hooknum = NF_INET_LOCAL_IN, .priority = NF_IP6_PRI_NAT_SRC - 1,
@@ -2265,7 +2216,7 @@ static const struct nf_hook_ops ip_vs_ops6[] = { },/* After mangle, schedule and forward local requests */ { - .hook = ip_vs_local_request6, + .hook = ip_vs_in_hook, .pf = NFPROTO_IPV6, .hooknum = NF_INET_LOCAL_OUT, .priority = NF_IP6_PRI_NAT_DST + 2,
Signature · 1 line
2.32.0
Florian Westphal
maintainerPATCH v2 4/4 netfilter: ipvs: merge ipv4 + ipv6 icmp reply handlers
In reply to Florian WestphalSimilar to earlier patches: allow ipv4 and ipv6 to use the same handler. ipv4 and ipv6 specific actions can be done by checking state->pf.
v2: split the pf == NFPROTO_IPV4 check (Julian Anastasov)
--- net/netfilter/ipvs/ip_vs_core.c | 37 +++++++++++++-------------------- 1 file changed, 14 insertions(+), 23 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +14 -23
@@ -2106,40 +2106,31 @@ static unsigned int ip_vs_forward_icmp(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { -int r;struct netns_ipvs *ipvs =net_ipvs (state->net); - -if (ip_hdr (skb)->protocol !=IPPROTO_ICMP ) -return NF_ACCEPT ; +int r;/* ipvs enabled in this netns ? */ if (unlikely (sysctl_backup_only (ipvs) || !ipvs->enable))return NF_ACCEPT ; -return ip_vs_in_icmp (ipvs, skb, &r, state->hook); -} - +if (state->pf ==NFPROTO_IPV4 ) { +if (ip_hdr (skb)->protocol !=IPPROTO_ICMP ) +return NF_ACCEPT ; #ifdef CONFIG_IP_VS_IPV6 -static unsigned int -ip_vs_forward_icmp_v6 (void *priv,struct sk_buff *skb, -const struct nf_hook_state *state) -{ -int r; -struct netns_ipvs *ipvs =net_ipvs (state->net); -struct ip_vs_iphdr iphdr; + }else { +struct ip_vs_iphdr iphdr; -ip_vs_fill_iph_skb (AF_INET6 , skb, false, &iphdr); -if (iphdr.protocol !=IPPROTO_ICMPV6 ) -return NF_ACCEPT ; +ip_vs_fill_iph_skb (AF_INET6 , skb, false, &iphdr); -/* ipvs enabled in this netns ? */ -if (unlikely (sysctl_backup_only (ipvs) || !ipvs->enable)) -return NF_ACCEPT ; +if (iphdr.protocol !=IPPROTO_ICMPV6 ) +return NF_ACCEPT ; -return ip_vs_in_icmp_v6 (ipvs, skb, &r, state->hook, &iphdr); -} +return ip_vs_in_icmp_v6 (ipvs, skb, &r, state->hook, &iphdr);#endif + } +return ip_vs_in_icmp (ipvs, skb, &r, state->hook); +}static const struct nf_hook_ops ip_vs_ops4[] = {/* After packet filtering, change source only for VS/NAT */
@@ -2224,7 +2215,7 @@ static const struct nf_hook_ops ip_vs_ops6[] = {/* After packet filtering (but before ip_vs_out_icmp), catch icmp * destined for 0.0.0.0/0, which is for incoming IPVS connections */ { - .hook = ip_vs_forward_icmp_v6, + .hook = ip_vs_forward_icmp, .pf = NFPROTO_IPV6, .hooknum = NF_INET_FORWARD, .priority = 99,
Signature · 1 line
2.32.0
Hello,
Quoted 7 lines · Florian Westphal
V2: Patch 4/4 had a bug that would enter ipv6 branch for ipv4 packets, fix that.
This series reduces the number of different hook function implementations by merging the ipv4 and ipv6 hooks into common code.
Quoted 7 lines
selftests/netfilter/ipvs.shpasses.Florian Westphal (4):
netfilter: ipvs: prepare for hook function reduction
netfilter: ipvs: remove unneeded output wrappers
netfilter: ipvs: remove unneeded input wrappers
netfilter: ipvs: merge ipv4 + ipv6 icmp reply handlers
Patchset v2 looks good to me, thanks!
Quoted 5 lines
net/netfilter/ipvs/ip_vs_core.c | 166 ++++++-------------------------- 1 file changed, 32 insertions(+), 134 deletions(-)Signature · 1 line
2.32.0
Regards
--
Julian Anastasov <[email protected]>
Pablo Neira Ayuso
maintainerQuoted 6 lines · Florian Westphal
V2: Patch 4/4 had a bug that would enter ipv6 branch for ipv4 packets, fix that.
This series reduces the number of different hook function implementations by merging the ipv4 and ipv6 hooks into common code.
Series applied, thanks.
Quoted 20 lines · Julian Anastasov
Hello,
Quoted 7 lines · Florian Westphal
V2: Patch 4/4 had a bug that would enter ipv6 branch for ipv4 packets, fix that.
This series reduces the number of different hook function implementations by merging the ipv4 and ipv6 hooks into common code.
Quoted 7 lines
selftests/netfilter/ipvs.shpasses.Florian Westphal (4):
netfilter: ipvs: prepare for hook function reduction
netfilter: ipvs: remove unneeded output wrappers
netfilter: ipvs: remove unneeded input wrappers
netfilter: ipvs: merge ipv4 + ipv6 icmp reply handlers
Quoted 3 lines
Patchset v2 looks good to me, thanks!
Acked-by Julian Anastasov <[email protected]>
Thanks Florian,
looks good.
Pablo, please consider picking up this series.