ipvs: pass correct sk to update_pmtu and on tunneling
Subsystems (4)
Julian Anastasov
maintainerPATCH v5 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 tunnels 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. All other sockets can receive the PMTU update via the ICMP replies.
- 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. Still, allow IPv4 packets to update PMTU for IPv6 dual sockets.
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, as done by other tunnels (IPIP/SIT/GRE).
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 v5:
* Match the packet's daddr with the socket's connected address
* IPv6 dual sockets connected to IPv4 mapped address can be updated too
Link to v4:
https://lore.kernel.org/all/[email protected]/
include/net/ip_vs.h | 45 +++++--- net/netfilter/ipvs/ip_vs_conn.c | 16 +-- 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 | 135 +++++++++++++++++------- 8 files changed, 169 insertions(+), 85 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; };
@@ -1871,7 +1873,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);
@@ -1986,32 +1989,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 +8 -8
@@ -1040,13 +1040,13 @@ static inline void ip_vs_bind_xmit(struct ip_vs_conn *cp) cp->packet_xmit = ip_vs_dr_xmit;break ; -case IP_VS_CONN_F_LOCALNODE : - cp->packet_xmit = ip_vs_null_xmit; -break ; -case IP_VS_CONN_F_BYPASS : cp->packet_xmit = ip_vs_bypass_xmit;break ; + +case IP_VS_CONN_F_LOCALNODE : + cp->packet_xmit = ip_vs_null_xmit; +break ; } }
@@ -1069,13 +1069,13 @@ static inline void ip_vs_bind_xmit_v6(struct ip_vs_conn *cp) cp->packet_xmit = ip_vs_dr_xmit_v6;break ; -case IP_VS_CONN_F_LOCALNODE : - cp->packet_xmit = ip_vs_null_xmit; -break ; -case IP_VS_CONN_F_BYPASS : cp->packet_xmit = ip_vs_bypass_xmit_v6;break ; + +case IP_VS_CONN_F_LOCALNODE : + cp->packet_xmit = ip_vs_null_xmit_v6; + break; } }#endif
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;
@@ -71,7 +71,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;
@@ -90,7 +90,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;
@@ -78,7 +78,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 +96 -39
321 lines not on this page · raw message
Signature · 1 line
2.56.1
Julian Anastasov
maintainerHello,
Quoted 48 lines · Julian Anastasov
This commit fixes two cases of providing sk on tunneling, one to the
update_pmtuhandler and the second case is to theip_local_out()call.For local clients, we can see at
LOCAL_OUTa netfilter hook'sstate->skthat is different from the protocol'sskb->sk. This can be the case for tunnels where different sk is provided toip_local_out. If such packet is then forwarded via IPVS tunnel we may need to providestate->skto theupdate_pmtuhandler, notskb->sk.Fix that by passing the netfilter's hook state via the
packet_xmitandconn_schedulehandlers to call theupdate_pmtuhandler withstate->sk.While here, change
maybe_update_pmtu()to be family independent by using dst and do not request neigh confirm via the lastupdate_pmtuarg because we do not generate the event based on remote signal.Sashiko has some warnings for the
update_pmtuhandlers because we provide only sk, not skb:- we do not provide skb because the handlers assume they are called from tunnel transmitters where
skb->devis present but for IPVSskb->devis 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_ESTABLISHEDstate where the sk is connected to destination address. All other sockets can receive the PMTU update via the ICMP replies.- 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 theupdate_pmtuhandler for different family. Still, allow IPv4 packets to update PMTU for IPv6 dual sockets.The second problem is that on tunnel forwarding we call
ip_local_out()withskb->sk. As we push our own outer IP header in ip_vs_tunnel_xmit*(), the right thing is to provide NULL instead, as done by other tunnels (IPIP/SIT/GRE).For consistency, even if we do not walk the netfilter hooks and just pass the packet with
NF_ACCEPT, provideip_vs_null_xmit_v6handler to properly indicate that we are sending IPv6 packet. Before now we usedip_vs_null_xmitfor both families.
Quoted 6 lines
Link https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113011447.2357709-1-pablo%40netfilter.orgFixes 79b16aadea32 ("udp_tunnel: Pass UDP socket down through udp_tunnel{, 6}_xmit_skb().")Fixes 7026b1ddb6b8 ("netfilter: Pass socket pointer down through okfn().")Signed-off-by Julian Anastasov <[email protected]>
Dropping v5 after Sashiko review:
https://sashiko.dev/#/patchset/20261119160650.133060-1-ja%40ssi.bg
Just posted v6.
pw-bot: changes-requested
Quoted 7 lines
---
Changes in v5:
* Match the packet's daddr with the socket's connected address
* IPv6 dual sockets connected to IPv4 mapped address can be updated tooLink to v4:
https://lore.kernel.org/all/[email protected]/
Regards
--
Julian Anastasov <[email protected]>