Skip to content

Commit 6f7b841

Browse files
Vadim Fedorenkoummakynes
authored andcommitted
ipvs: allow tunneling with gre encapsulation
windows real servers can handle gre tunnels, this patch allows gre encapsulation with the tunneling method, thereby letting ipvs be load balancer for windows-based services Signed-off-by: Vadim Fedorenko <[email protected]> Acked-by: Julian Anastasov <[email protected]> Signed-off-by: Simon Horman <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 0d9cb30 commit 6f7b841

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

include/uapi/linux/ip_vs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
enum {
129129
IP_VS_CONN_F_TUNNEL_TYPE_IPIP = 0, /* IPIP */
130130
IP_VS_CONN_F_TUNNEL_TYPE_GUE, /* GUE */
131+
IP_VS_CONN_F_TUNNEL_TYPE_GRE, /* GRE */
131132
IP_VS_CONN_F_TUNNEL_TYPE_MAX,
132133
};
133134

net/netfilter/ipvs/ip_vs_ctl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ static void ip_vs_rs_hash(struct netns_ipvs *ipvs, struct ip_vs_dest *dest)
525525
port = dest->tun_port;
526526
break;
527527
case IP_VS_CONN_F_TUNNEL_TYPE_IPIP:
528+
case IP_VS_CONN_F_TUNNEL_TYPE_GRE:
528529
port = 0;
529530
break;
530531
default:

net/netfilter/ipvs/ip_vs_xmit.c

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/tcp.h> /* for tcphdr */
3030
#include <net/ip.h>
3131
#include <net/gue.h>
32+
#include <net/gre.h>
3233
#include <net/tcp.h> /* for csum_tcpudp_magic */
3334
#include <net/udp.h>
3435
#include <net/icmp.h> /* for icmp_send */
@@ -388,6 +389,12 @@ __ip_vs_get_out_rt(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb,
388389
IP_VS_TUNNEL_ENCAP_FLAG_REMCSUM) &&
389390
skb->ip_summed == CHECKSUM_PARTIAL)
390391
mtu -= GUE_PLEN_REMCSUM + GUE_LEN_PRIV;
392+
} else if (dest->tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GRE) {
393+
__be16 tflags = 0;
394+
395+
if (dest->tun_flags & IP_VS_TUNNEL_ENCAP_FLAG_CSUM)
396+
tflags |= TUNNEL_CSUM;
397+
mtu -= gre_calc_hlen(tflags);
391398
}
392399
if (mtu < 68) {
393400
IP_VS_DBG_RL("%s(): mtu less than 68\n", __func__);
@@ -548,6 +555,12 @@ __ip_vs_get_out_rt_v6(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb,
548555
IP_VS_TUNNEL_ENCAP_FLAG_REMCSUM) &&
549556
skb->ip_summed == CHECKSUM_PARTIAL)
550557
mtu -= GUE_PLEN_REMCSUM + GUE_LEN_PRIV;
558+
} else if (dest->tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GRE) {
559+
__be16 tflags = 0;
560+
561+
if (dest->tun_flags & IP_VS_TUNNEL_ENCAP_FLAG_CSUM)
562+
tflags |= TUNNEL_CSUM;
563+
mtu -= gre_calc_hlen(tflags);
551564
}
552565
if (mtu < IPV6_MIN_MTU) {
553566
IP_VS_DBG_RL("%s(): mtu less than %d\n", __func__,
@@ -1079,6 +1092,24 @@ ipvs_gue_encap(struct net *net, struct sk_buff *skb,
10791092
return 0;
10801093
}
10811094

1095+
static void
1096+
ipvs_gre_encap(struct net *net, struct sk_buff *skb,
1097+
struct ip_vs_conn *cp, __u8 *next_protocol)
1098+
{
1099+
__be16 proto = *next_protocol == IPPROTO_IPIP ?
1100+
htons(ETH_P_IP) : htons(ETH_P_IPV6);
1101+
__be16 tflags = 0;
1102+
size_t hdrlen;
1103+
1104+
if (cp->dest->tun_flags & IP_VS_TUNNEL_ENCAP_FLAG_CSUM)
1105+
tflags |= TUNNEL_CSUM;
1106+
1107+
hdrlen = gre_calc_hlen(tflags);
1108+
gre_build_header(skb, hdrlen, tflags, proto, 0, 0);
1109+
1110+
*next_protocol = IPPROTO_GRE;
1111+
}
1112+
10821113
/*
10831114
* IP Tunneling transmitter
10841115
*
@@ -1151,6 +1182,15 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
11511182
gue_hdrlen = sizeof(struct guehdr) + gue_optlen;
11521183

11531184
max_headroom += sizeof(struct udphdr) + gue_hdrlen;
1185+
} else if (tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GRE) {
1186+
size_t gre_hdrlen;
1187+
__be16 tflags = 0;
1188+
1189+
if (tun_flags & IP_VS_TUNNEL_ENCAP_FLAG_CSUM)
1190+
tflags |= TUNNEL_CSUM;
1191+
gre_hdrlen = gre_calc_hlen(tflags);
1192+
1193+
max_headroom += gre_hdrlen;
11541194
}
11551195

11561196
/* We only care about the df field if sysctl_pmtu_disc(ipvs) is set */
@@ -1172,6 +1212,11 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
11721212
skb->ip_summed == CHECKSUM_PARTIAL) {
11731213
gso_type |= SKB_GSO_TUNNEL_REMCSUM;
11741214
}
1215+
} else if (tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GRE) {
1216+
if (tun_flags & IP_VS_TUNNEL_ENCAP_FLAG_CSUM)
1217+
gso_type |= SKB_GSO_GRE_CSUM;
1218+
else
1219+
gso_type |= SKB_GSO_GRE;
11751220
}
11761221

11771222
if (iptunnel_handle_offloads(skb, gso_type))
@@ -1192,8 +1237,8 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
11921237
check = true;
11931238

11941239
udp_set_csum(!check, skb, saddr, cp->daddr.ip, skb->len);
1195-
}
1196-
1240+
} else if (tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GRE)
1241+
ipvs_gre_encap(net, skb, cp, &next_protocol);
11971242

11981243
skb_push(skb, sizeof(struct iphdr));
11991244
skb_reset_network_header(skb);
@@ -1287,6 +1332,15 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
12871332
gue_hdrlen = sizeof(struct guehdr) + gue_optlen;
12881333

12891334
max_headroom += sizeof(struct udphdr) + gue_hdrlen;
1335+
} else if (tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GRE) {
1336+
size_t gre_hdrlen;
1337+
__be16 tflags = 0;
1338+
1339+
if (tun_flags & IP_VS_TUNNEL_ENCAP_FLAG_CSUM)
1340+
tflags |= TUNNEL_CSUM;
1341+
gre_hdrlen = gre_calc_hlen(tflags);
1342+
1343+
max_headroom += gre_hdrlen;
12901344
}
12911345

12921346
skb = ip_vs_prepare_tunneled_skb(skb, cp->af, max_headroom,
@@ -1306,6 +1360,11 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
13061360
skb->ip_summed == CHECKSUM_PARTIAL) {
13071361
gso_type |= SKB_GSO_TUNNEL_REMCSUM;
13081362
}
1363+
} else if (tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GRE) {
1364+
if (tun_flags & IP_VS_TUNNEL_ENCAP_FLAG_CSUM)
1365+
gso_type |= SKB_GSO_GRE_CSUM;
1366+
else
1367+
gso_type |= SKB_GSO_GRE;
13091368
}
13101369

13111370
if (iptunnel_handle_offloads(skb, gso_type))
@@ -1326,7 +1385,8 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
13261385
check = true;
13271386

13281387
udp6_set_csum(!check, skb, &saddr, &cp->daddr.in6, skb->len);
1329-
}
1388+
} else if (tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GRE)
1389+
ipvs_gre_encap(net, skb, cp, &next_protocol);
13301390

13311391
skb_push(skb, sizeof(struct ipv6hdr));
13321392
skb_reset_network_header(skb);

0 commit comments

Comments
 (0)