ipvs: allow tunneling with gue encapsulation
Subsystems (5)
PATCH v6 1/1 ipvs: allow tunneling with gue encapsulation
ipip packets are blocked in some public cloud environments, this patch allows gue encapsulation with the tunneling method, which would make tunneling working in those environments.
--- include/net/ip_vs.h | 5 ++ include/uapi/linux/ip_vs.h | 11 +++++ net/netfilter/ipvs/ip_vs_ctl.c | 35 +++++++++++++- net/netfilter/ipvs/ip_vs_xmit.c | 86 +++++++++++++++++++++++++++++++-- 4 files changed, 132 insertions(+), 5 deletions(-)
include/net/ip_vs.h +5 -0
@@ -603,6 +603,9 @@ struct ip_vs_dest_user_kern {/* Address family of addr */ u16 af; + +u16 tun_type;/* tunnel type */ +__be16 tun_port;/* tunnel port */ };
@@ -663,6 +666,8 @@ struct ip_vs_dest {atomic_t conn_flags;/* flags to copy to conn */ atomic_t weight;/* server weight */ atomic_t last_weight;/* server latest weight */ +__u16 tun_type;/* tunnel type */ +__be16 tun_port;/* tunnel port */ refcount_t refcnt;/* reference counter */ struct ip_vs_stats stats;/* statistics */
include/uapi/linux/ip_vs.h +11 -0
@@ -124,6 +124,13 @@#define IP_VS_PEDATA_MAXLEN 255 +/* Tunnel types */ +enum { +IP_VS_CONN_F_TUNNEL_TYPE_IPIP =0 ,/* IPIP */ +IP_VS_CONN_F_TUNNEL_TYPE_GUE ,/* GUE */ +IP_VS_CONN_F_TUNNEL_TYPE_MAX , +}; +/* * The struct ip_vs_service_user and struct ip_vs_dest_user are * used to set IPVS rules through setsockopt.
@@ -392,6 +399,10 @@ enum {IPVS_DEST_ATTR_STATS64 ,/* nested attribute for dest stats */ +IPVS_DEST_ATTR_TUN_TYPE ,/* tunnel type */ + +IPVS_DEST_ATTR_TUN_PORT ,/* tunnel port */ + __IPVS_DEST_ATTR_MAX, };
net/netfilter/ipvs/ip_vs_ctl.c +34 -1
@@ -830,6 +830,10 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest, conn_flags = udest->conn_flags &IP_VS_CONN_F_DEST_MASK ; conn_flags |=IP_VS_CONN_F_INACTIVE ; +/* set the tunnel info */ + dest->tun_type = udest->tun_type; + dest->tun_port = udest->tun_port; +/* set the IP_VS_CONN_F_NOOUTPUT flag if not masquerading/NAT */ if ((conn_flags &IP_VS_CONN_F_FWD_MASK ) !=IP_VS_CONN_F_MASQ ) { conn_flags |=IP_VS_CONN_F_NOOUTPUT ;
@@ -980,6 +984,13 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)return -ERANGE ; } +if (udest->tun_type ==IP_VS_CONN_F_TUNNEL_TYPE_GUE ) { +if (udest->tun_port ==0 ) { +pr_err ("%s(): tunnel port is zero\n" , __func__); +return -EINVAL ; + } + } +ip_vs_addr_copy (udest->af, &daddr, &udest->addr);/* We use function that requires RCU lock */
@@ -1044,6 +1055,13 @@ ip_vs_edit_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)return -ERANGE ; } +if (udest->tun_type ==IP_VS_CONN_F_TUNNEL_TYPE_GUE ) { +if (udest->tun_port ==0 ) { +pr_err ("%s(): tunnel port is zero\n" , __func__); +return -EINVAL ; + } + } +ip_vs_addr_copy (udest->af, &daddr, &udest->addr);/* We use function that requires RCU lock */
@@ -2310,6 +2328,7 @@ static void ip_vs_copy_udest_compat(struct ip_vs_dest_user_kern *udest, udest->u_threshold = udest_compat->u_threshold; udest->l_threshold = udest_compat->l_threshold; udest->af =AF_INET ; + udest->tun_type =IP_VS_CONN_F_TUNNEL_TYPE_IPIP ; } static int
@@ -2869,6 +2888,8 @@ static const struct nla_policy ip_vs_dest_policy[IPVS_DEST_ATTR_MAX + 1] = { [IPVS_DEST_ATTR_PERSIST_CONNS] = { .type = NLA_U32 }, [IPVS_DEST_ATTR_STATS] = { .type = NLA_NESTED }, [IPVS_DEST_ATTR_ADDR_FAMILY] = { .type = NLA_U16 }, + [IPVS_DEST_ATTR_TUN_TYPE] = { .type = NLA_U8 }, + [IPVS_DEST_ATTR_TUN_PORT] = { .type = NLA_U16 }, }; static int ip_vs_genl_fill_stats(struct sk_buff *skb, int container_type,
@@ -3172,6 +3193,10 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest) IP_VS_CONN_F_FWD_MASK)) ||nla_put_u32 (skb,IPVS_DEST_ATTR_WEIGHT ,atomic_read (&dest->weight)) || +nla_put_u8 (skb,IPVS_DEST_ATTR_TUN_TYPE , + dest->tun_type) || +nla_put_be16 (skb,IPVS_DEST_ATTR_TUN_PORT , + dest->tun_port) ||nla_put_u32 (skb,IPVS_DEST_ATTR_U_THRESH , dest->u_threshold) ||nla_put_u32 (skb,IPVS_DEST_ATTR_L_THRESH , dest->l_threshold) || nla_put_u32(skb, IPVS_DEST_ATTR_ACTIVE_CONNS,
@@ -3294,12 +3319,14 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,/* If a full entry was requested, check for the additional fields */ if (full_entry) {struct nlattr *nla_fwd, *nla_weight, *nla_u_thresh, - *nla_l_thresh; + *nla_l_thresh, *nla_tun_type, *nla_tun_port; nla_fwd = attrs[IPVS_DEST_ATTR_FWD_METHOD ]; nla_weight = attrs[IPVS_DEST_ATTR_WEIGHT ]; nla_u_thresh = attrs[IPVS_DEST_ATTR_U_THRESH ]; nla_l_thresh = attrs[IPVS_DEST_ATTR_L_THRESH ]; + nla_tun_type = attrs[IPVS_DEST_ATTR_TUN_TYPE ]; + nla_tun_port = attrs[IPVS_DEST_ATTR_TUN_PORT ];if (!(nla_fwd && nla_weight && nla_u_thresh && nla_l_thresh))return -EINVAL ;
@@ -3309,6 +3336,12 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest, udest->weight =nla_get_u32 (nla_weight); udest->u_threshold =nla_get_u32 (nla_u_thresh); udest->l_threshold =nla_get_u32 (nla_l_thresh); + +if (nla_tun_type) + udest->tun_type =nla_get_u8 (nla_tun_type); + +if (nla_tun_port) + udest->tun_port =nla_get_be16 (nla_tun_port); }return 0 ;
net/netfilter/ipvs/ip_vs_xmit.c +82 -4
169 lines not on this page · raw message
Signature · 1 line
2.21.0
Julian Anastasov
maintainerHello,
Quoted 19 lines · Jacky Hu
ipip packets are blocked in some public cloud environments, this patch allows gue encapsulation with the tunneling method, which would make tunneling working in those environments.
Signed-off-by Jacky Hu <[email protected]>--- include/net/ip_vs.h | 5 ++ include/uapi/linux/ip_vs.h | 11 +++++ net/netfilter/ipvs/ip_vs_ctl.c | 35 +++++++++++++- net/netfilter/ipvs/ip_vs_xmit.c | 86 +++++++++++++++++++++++++++++++-- 4 files changed, 132 insertions(+), 5 deletions(-)net/netfilter/ipvs/ip_vs_xmit.c +0
-0
net/netfilter/ipvs/ip_vs_xmit.c ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, · line 1110
Quoted 8 lines
net/netfilter/ipvs/ip_vs_xmit.c +4
-1@@ -1054,11 +1104,21 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,if (IS_ERR (skb)) goto tx_error; -if (iptunnel_handle_offloads (skb,__tun_gso_type_mask (AF_INET , cp->af))) +if (tun_type ==IP_VS_CONN_F_TUNNEL_TYPE_GUE ) + gso_type =SKB_GSO_UDP_TUNNEL ; +else + gso_type =__tun_gso_type_mask (AF_INET , cp->af);
Looks like we should request the IP segmentation. Looking
at skb_udp_tunnel_segment() we call the proper gso_inner_segment handler but ipip_gso_segment() still requires its bit in gso_type. So, in both functions we should do:
gso_type = __tun_gso_type_mask(); if (tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GUE) gso_type |= SKB_GSO_UDP_TUNNEL; Probably, it can be tested with local client sending large
TCP packets...
Quoted 10 lines
net/netfilter/ipvs/ip_vs_xmit.c +5
-0@@ -1134,17 +1197,32 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,*/ max_headroom =LL_RESERVED_SPACE (tdev) +sizeof (struct ipv6hdr ); + tun_type = cp->dest->tun_type; + +if (tun_type ==IP_VS_CONN_F_TUNNEL_TYPE_GUE ) + max_headroom +=sizeof (struct udphdr ) +sizeof (struct guehdr ); + skb = ip_vs_prepare_tunneled_skb(skb, cp->af, max_headroom,
net/netfilter/ipvs/ip_vs_xmit.c ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, · line 1214
Quoted 10 lines
net/netfilter/ipvs/ip_vs_xmit.c +4
-1&next_protocol, &payload_len, &dsfield, &ttl, NULL);if (IS_ERR (skb)) goto tx_error; -if (iptunnel_handle_offloads (skb,__tun_gso_type_mask (AF_INET6 , cp->af))) +if (tun_type ==IP_VS_CONN_F_TUNNEL_TYPE_GUE ) + gso_type =SKB_GSO_UDP_TUNNEL ; +else + gso_type =__tun_gso_type_mask (AF_INET6 , cp->af);
Here too
net/netfilter/ipvs/ip_vs_xmit.c ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, · line 1216
Quoted 2 lines
net/netfilter/ipvs/ip_vs_xmit.c +1
-0+if (iptunnel_handle_offloads (skb, gso_type)) goto tx_error;
Regards
--
Julian Anastasov <[email protected]>