ipvs: pass correct sk to update_pmtu and on tunneling
Subsystems (4)
Julian Anastasov
maintainerPATCH v3 1/1 ipvs: pass correct sk to update_pmtu and on tunneling
This commit fixes two cases of providing sk on tunneling, one to the update_pmtu handler and the second case is to the ip_local_out() call.
For local clients, we can see at LOCAL_OUT a netfilter hook's state->sk that is different from the protocol's skb->sk. This can be the case for UDP_TUNNEL where different sk is provided to ip_local_out. If such packet is then forwarded via IPVS tunnel we may need to provide state->sk to the update_pmtu handler, not skb->sk.
Fix that by passing the netfilter's hook state via the packet_xmit and conn_schedule handlers to call the update_pmtu handler with state->sk.
While here, change maybe_update_pmtu() to be family independent by using dst and do not request neigh confirm via the last update_pmtu arg because we do not generate the event based on remote signal.
Sashiko has some warnings for the update_pmtu handlers because we provide only sk, not skb:
- we do not provide skb because the handlers assume they are called from tunnel transmitters where skb->dev is present but for IPVS skb->dev is not set yet
- without skb, the zero destination address for unconnected sockets can be blindly used for FIB nexthop or route exceptions. So, we now restrict the sk to be for TCP_ESTABLISHED state where the sk is connected to destination address.
- as we provide the original sk (from state->sk) for the original IP header, make sure we do not provide sk from one family to the update_pmtu handler for different family.
The second problem is that on tunnel forwarding we call ip_local_out() with skb->sk. As we push our own outer IP header in ip_vs_tunnel_xmit*(), the right thing is to provide NULL instead.
For consistency, even if we do not walk the netfilter hooks and just pass the packet with NF_ACCEPT, provide ip_vs_null_xmit_v6 handler to properly indicate that we are sending IPv6 packet. Before now we used ip_vs_null_xmit for both families.
---
Changes in v3:
* replace the sk_fullsock() check with TCP_ESTABLISHED check and do not use sk_is_inet()
* make sure the called update_pmtu handler matches the family of the provided sk
Link to v2:
https://lore.kernel.org/all/[email protected]/
include/net/ip_vs.h | 45 +++++++--- net/netfilter/ipvs/ip_vs_conn.c | 2 +- net/netfilter/ipvs/ip_vs_core.c | 41 +++++---- net/netfilter/ipvs/ip_vs_proto_ah_esp.c | 2 +- net/netfilter/ipvs/ip_vs_proto_sctp.c | 5 +- net/netfilter/ipvs/ip_vs_proto_tcp.c | 5 +- net/netfilter/ipvs/ip_vs_proto_udp.c | 5 +- net/netfilter/ipvs/ip_vs_xmit.c | 114 ++++++++++++++++-------- 8 files changed, 141 insertions(+), 78 deletions(-)
include/net/ip_vs.h +31 -14
@@ -731,7 +731,8 @@ struct ip_vs_protocol { 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_iphdr *iph, + const struct nf_hook_state *state);struct ip_vs_conn * (*conn_in_get)(struct netns_ipvs *ipvs,
@@ -872,7 +873,8 @@ struct ip_vs_conn {* NF_ACCEPT can be returned when destination is local. */ int (*packet_xmit)(struct sk_buff *skb,struct ip_vs_conn *cp, -struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph); +struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph, +const struct nf_hook_state *state);struct rcu_head rcu_head; };
@@ -1873,7 +1875,8 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb, struct ip_vs_proto_data *pd, int *ignored, struct ip_vs_iphdr *iph);int ip_vs_leave (struct ip_vs_service *svc,struct sk_buff *skb, -struct ip_vs_proto_data *pd,struct ip_vs_iphdr *iph); +struct ip_vs_proto_data *pd,struct ip_vs_iphdr *iph, +const struct nf_hook_state *state);void ip_vs_scheduler_err (struct ip_vs_service *svc,const char *msg);
@@ -1988,32 +1991,46 @@ static inline int ip_vs_est_max_threads(struct netns_ipvs *ipvs)/* Various IPVS packet transmitters (from ip_vs_xmit.c) */ int ip_vs_null_xmit (struct sk_buff *skb,struct ip_vs_conn *cp, -struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph); +struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph, +const struct nf_hook_state *state);int ip_vs_bypass_xmit (struct sk_buff *skb,struct ip_vs_conn *cp, -struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph); +struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph, +const struct nf_hook_state *state);int ip_vs_nat_xmit (struct sk_buff *skb,struct ip_vs_conn *cp, -struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph); +struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph, +const struct nf_hook_state *state);int ip_vs_tunnel_xmit (struct sk_buff *skb,struct ip_vs_conn *cp, -struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph); +struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph, +const struct nf_hook_state *state);int ip_vs_dr_xmit (struct sk_buff *skb,struct ip_vs_conn *cp, -struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph); +struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph, +const struct nf_hook_state *state);int ip_vs_icmp_xmit (struct sk_buff *skb,struct ip_vs_conn *cp,struct ip_vs_protocol *pp,unsigned int toff, -unsigned int hooknum,struct ip_vs_iphdr *ciph); +const struct nf_hook_state *state, +struct ip_vs_iphdr *ciph);void ip_vs_dest_dst_rcu_free (struct rcu_head *head);#ifdef CONFIG_IP_VS_IPV6 +int ip_vs_null_xmit_v6 (struct sk_buff *skb,struct ip_vs_conn *cp, +struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph, +const struct nf_hook_state *state);int ip_vs_bypass_xmit_v6 (struct sk_buff *skb,struct ip_vs_conn *cp, -struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph); +struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph, +const struct nf_hook_state *state);int ip_vs_nat_xmit_v6 (struct sk_buff *skb,struct ip_vs_conn *cp, -struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph); +struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph, +const struct nf_hook_state *state);int ip_vs_tunnel_xmit_v6 (struct sk_buff *skb,struct ip_vs_conn *cp, -struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph); +struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph, +const struct nf_hook_state *state);int ip_vs_dr_xmit_v6 (struct sk_buff *skb,struct ip_vs_conn *cp, -struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph); +struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph, +const struct nf_hook_state *state);int ip_vs_icmp_xmit_v6 (struct sk_buff *skb,struct ip_vs_conn *cp,struct ip_vs_protocol *pp,unsigned int toff, -unsigned int hooknum,struct ip_vs_iphdr *ciph); +const struct nf_hook_state *state, +struct ip_vs_iphdr *ciph);#endif #ifdef CONFIG_SYSCTL
net/netfilter/ipvs/ip_vs_conn.c +1 -1
@@ -1070,7 +1070,7 @@ static inline void ip_vs_bind_xmit_v6(struct ip_vs_conn *cp)break ;case IP_VS_CONN_F_LOCALNODE : - cp->packet_xmit = ip_vs_null_xmit; + cp->packet_xmit = ip_vs_null_xmit_v6;break ;case IP_VS_CONN_F_BYPASS :
net/netfilter/ipvs/ip_vs_core.c +24 -17
140 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_proto_ah_esp.c +1 -1
@@ -102,7 +102,7 @@ static int ah_esp_conn_schedule(struct netns_ipvs *ipvs, 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_iphdr *iph, const struct nf_hook_state *state) {/* * AH/ESP is only related traffic. Pass the packet to IP stack.
net/netfilter/ipvs/ip_vs_proto_sctp.c +3 -2
@@ -17,7 +17,7 @@ static int sctp_conn_schedule(struct netns_ipvs *ipvs, 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_iphdr *iph, const struct nf_hook_state *state) { struct ip_vs_service *svc;struct sctp_chunkhdr _schunkh, *sch;
@@ -78,7 +78,8 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, *cpp =ip_vs_schedule (svc, skb, pd, &ignored, iph);if (!*cpp && ignored <=0 ) {if (!ignored) - *verdict =ip_vs_leave (svc, skb, pd, iph); + *verdict =ip_vs_leave (svc, skb, pd, iph, + state);else *verdict =NF_DROP ;return 0 ;
net/netfilter/ipvs/ip_vs_proto_tcp.c +3 -2
@@ -35,7 +35,7 @@ static int tcp_conn_schedule(struct netns_ipvs *ipvs, 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_iphdr *iph, const struct nf_hook_state *state) { struct ip_vs_service *svc;struct tcphdr _tcph, *th;
@@ -97,7 +97,8 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, *cpp =ip_vs_schedule (svc, skb, pd, &ignored, iph);if (!*cpp && ignored <=0 ) {if (!ignored) - *verdict =ip_vs_leave (svc, skb, pd, iph); + *verdict =ip_vs_leave (svc, skb, pd, iph, + state);else *verdict =NF_DROP ;return 0 ;
net/netfilter/ipvs/ip_vs_proto_udp.c +3 -2
@@ -31,7 +31,7 @@ static int udp_conn_schedule(struct netns_ipvs *ipvs, 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_iphdr *iph, const struct nf_hook_state *state) { struct ip_vs_service *svc;struct udphdr _udph, *uh;
@@ -84,7 +84,8 @@ udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, *cpp =ip_vs_schedule (svc, skb, pd, &ignored, iph);if (!*cpp && ignored <=0 ) {if (!ignored) - *verdict =ip_vs_leave (svc, skb, pd, iph); + *verdict =ip_vs_leave (svc, skb, pd, iph, + state);else *verdict =NF_DROP ;return 0 ;
net/netfilter/ipvs/ip_vs_xmit.c +75 -39
300 lines not on this page · raw message
Signature · 1 line
2.56.0