Skip to contentSkip to conversation

ipvsadm: allow tunneling with gue encapsulation

PATCH Superseded Jacky Hu 1 participant 1 message Mar 16, 2019

Subsystems (2)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Jacky Hu

author
#0 lore raw

PATCH v2 1/1 ipvsadm: allow tunneling with gue encapsulation

Added the following options:
--tun-type with adding and editing destinations for tunneling servers. --tun-port with adding and editing destinations for tunneling servers. --tun-info with listing services.

---
 Makefile          |   2 +-
 ipvsadm.c         | 256 ++++++++++++++++++++++++++++++++++++++++++----
 libipvs/ip_vs.h   |  27 +++++
 libipvs/libipvs.c |  10 ++
 4 files changed, 272 insertions(+), 23 deletions(-)
Makefile +1 -1
index 91a2991..63c4389 100644
@@ -63,7 +63,7 @@ RPMBUILD = $(shell				\
 	fi )
 
 OBJS		= ipvsadm.o config_stream.o dynamic_array.o
-LIBS		= -lpopt
+LIBS		= -lpopt -lm
 ifneq (0,$(HAVE_NL))
 LIBS		+= $(shell \
 		if which pkg-config > /dev/null 2>&1; then \
ipvsadm.c +234 -22

411 lines not on this page · raw message

libipvs/ip_vs.h +27 -0
index ad0141c..209e9a4 100644
@@ -107,6 +107,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,
+};
+
 union nf_inet_addr {
         __u32           all[4];
         __be32          ip;
@@ -162,6 +169,10 @@ struct ip_vs_dest_kern {
 	/* thresholds for active connections */
 	u_int32_t		u_threshold;	/* upper threshold */
 	u_int32_t		l_threshold;	/* lower threshold */
+
+	/* tunnel info */
+	u_int16_t		tun_type;	/* tunnel type */
+	__be16			tun_port;	/* tunnel port */
 };
 
 struct ip_vs_dest_user {
@@ -178,6 +189,10 @@ struct ip_vs_dest_user {
 	u_int32_t		l_threshold;	/* lower threshold */
 	u_int16_t		af;
 	union nf_inet_addr	addr;
+
+	/* tunnel info */
+	u_int16_t		tun_type;	/* tunnel type */
+	__be16			tun_port;	/* tunnel port */
 };
 
 /*
@@ -291,6 +306,10 @@ struct ip_vs_dest_entry_kern {
 
 	/* statistics */
 	struct ip_vs_stats_user stats;
+
+	/* tunnel info */
+	u_int16_t		tun_type;	/* tunnel type */
+	__be16			tun_port;	/* tunnel port */
 };
 
 struct ip_vs_dest_entry {
@@ -313,6 +332,10 @@ struct ip_vs_dest_entry {
 
 	/* statistics, 64-bit */
 	struct ip_vs_stats64	stats64;
+
+	/* tunnel info */
+	u_int16_t		tun_type;	/* tunnel type */
+	__be16			tun_port;	/* tunnel port */
 };
 
 /* The argument to IP_VS_SO_GET_DESTS */
@@ -527,6 +550,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,
 };
 
libipvs/libipvs.c +10 -0
index 9be7700..d3cadaa 100644
@@ -390,6 +390,8 @@ static int ipvs_nl_fill_dest_attr(struct nl_msg *msg, ipvs_dest_t *dst)
 	NLA_PUT_U16(msg, IPVS_DEST_ATTR_PORT, dst->port);
 	NLA_PUT_U32(msg, IPVS_DEST_ATTR_FWD_METHOD, dst->conn_flags & IP_VS_CONN_F_FWD_MASK);
 	NLA_PUT_U32(msg, IPVS_DEST_ATTR_WEIGHT, dst->weight);
+	NLA_PUT_U8(msg, IPVS_DEST_ATTR_TUN_TYPE, dst->tun_type);
+	NLA_PUT_U16(msg, IPVS_DEST_ATTR_TUN_PORT, dst->tun_port);
 	NLA_PUT_U32(msg, IPVS_DEST_ATTR_U_THRESH, dst->u_threshold);
 	NLA_PUT_U32(msg, IPVS_DEST_ATTR_L_THRESH, dst->l_threshold);
 
@@ -856,6 +858,8 @@ static int ipvs_dests_parse_cb(struct nl_msg *msg, void *arg)
 	struct nlattr *attrs[IPVS_CMD_ATTR_MAX + 1];
 	struct nlattr *dest_attrs[IPVS_DEST_ATTR_MAX + 1];
 	struct nlattr *attr_addr_family = NULL;
+	struct nlattr *attr_tun_type = NULL;
+	struct nlattr *attr_tun_port = NULL;
 	struct ip_vs_get_dests **dp = (struct ip_vs_get_dests **)arg;
 	struct ip_vs_get_dests *d = (struct ip_vs_get_dests *)*dp;
 	int i = d->num_dests;
@@ -888,6 +892,12 @@ static int ipvs_dests_parse_cb(struct nl_msg *msg, void *arg)
 	d->entrytable[i].port = nla_get_u16(dest_attrs[IPVS_DEST_ATTR_PORT]);
 	d->entrytable[i].conn_flags = nla_get_u32(dest_attrs[IPVS_DEST_ATTR_FWD_METHOD]);
 	d->entrytable[i].weight = nla_get_u32(dest_attrs[IPVS_DEST_ATTR_WEIGHT]);
+	attr_tun_type = dest_attrs[IPVS_DEST_ATTR_TUN_TYPE];
+	if (attr_tun_type)
+		d->entrytable[i].tun_type = nla_get_u8(attr_tun_type);
+	attr_tun_port = dest_attrs[IPVS_DEST_ATTR_TUN_PORT];
+	if (attr_tun_port)
+		d->entrytable[i].tun_port = nla_get_u16(attr_tun_port);
 	d->entrytable[i].u_threshold = nla_get_u32(dest_attrs[IPVS_DEST_ATTR_U_THRESH]);
 	d->entrytable[i].l_threshold = nla_get_u32(dest_attrs[IPVS_DEST_ATTR_L_THRESH]);
 	d->entrytable[i].activeconns = nla_get_u32(dest_attrs[IPVS_DEST_ATTR_ACTIVE_CONNS]);
Signature · 1 line
2.21.0