Skip to contentSkip to conversation

geneve: fix ttl inherit behavior

PATCH Superseded Hangbin Liu 3 participants 7 messages Sep 27, 2018 – Oct 24, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 geneve: fix ttl inherit behavior

Currently when we add geneve with "ttl inherit", we set ttl to 0, which is actually use whatever default value instead of inherit the inner protocol's ttl value.

To respect compatibility with old behavior and make a difference between ttl inherit and ttl == 0, we add an attribute IFLA_GENEVE_TTL_INHERIT in kernel commit 52d0d404d39dd ("geneve: add ttl inherit support").

Now let's use "ttl inherit" to inherit the inner protocol's ttl, and use "ttl auto" to means "use whatever default value", the same behavior with ttl == 0.

---
 include/uapi/linux/if_link.h |  1 +
 ip/iplink_geneve.c           | 20 +++++++++++++-------
 2 files changed, 14 insertions(+), 7 deletions(-)
include/uapi/linux/if_link.h +1 -0
index f4a9715..02d7bdf 100644
@@ -552,6 +552,7 @@ enum {
 	IFLA_GENEVE_UDP_ZERO_CSUM6_TX,
 	IFLA_GENEVE_UDP_ZERO_CSUM6_RX,
 	IFLA_GENEVE_LABEL,
+	IFLA_GENEVE_TTL_INHERIT,
 	__IFLA_GENEVE_MAX
 };
 #define IFLA_GENEVE_MAX	(__IFLA_GENEVE_MAX - 1)
ip/iplink_geneve.c +13 -7
index 26e70ff..c417842 100644
@@ -34,7 +34,7 @@ static void print_explain(FILE *f)
 		"Where: VNI   := 0-16777215\n"
 		"       ADDR  := IP_ADDRESS\n"
 		"       TOS   := { NUMBER | inherit }\n"
-		"       TTL   := { 1..255 | inherit }\n"
+		"       TTL   := { 1..255 | auto | inherit }\n"
 		"       LABEL := 0-1048575\n"
 	);
 }
@@ -94,7 +94,9 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
 
 			NEXT_ARG();
 			check_duparg(&attrs, IFLA_GENEVE_TTL, "ttl", *argv);
-			if (strcmp(*argv, "inherit") != 0) {
+			if (strcmp(*argv, "inherit") == 0) {
+				addattr8(n, 1024, IFLA_GENEVE_TTL_INHERIT, 1);
+			} else if (strcmp(*argv, "auto") != 0) {
 				if (get_unsigned(&uval, *argv, 0))
 					invarg("invalid TTL", *argv);
 				if (uval > 255)
@@ -265,12 +267,16 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 		}
 	}
 
-	if (tb[IFLA_GENEVE_TTL])
-		ttl = rta_getattr_u8(tb[IFLA_GENEVE_TTL]);
-	if (is_json_context() || ttl)
-		print_uint(PRINT_ANY, "ttl", "ttl %u ", ttl);
-	else
+	if (tb[IFLA_GENEVE_TTL_INHERIT] &&
+	    rta_getattr_u8(tb[IFLA_GENEVE_TTL_INHERIT])) {
 		print_string(PRINT_FP, NULL, "ttl %s ", "inherit");
+	} else if (tb[IFLA_GENEVE_TTL]) {
+		ttl = rta_getattr_u8(tb[IFLA_GENEVE_TTL]);
+		if (is_json_context() || ttl)
+			print_uint(PRINT_ANY, "ttl", "ttl %u ", ttl);
+		else
+			print_string(PRINT_FP, NULL, "ttl %s ", "auto");
+	}
 
 	if (tb[IFLA_GENEVE_TOS])
 		tos = rta_getattr_u8(tb[IFLA_GENEVE_TOS]);
Signature · 1 line
2.5.5
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Hangbin Liu

Currently when we add geneve with "ttl inherit", we set ttl to 0, which is actually use whatever default value instead of inherit the inner protocol's ttl value.

To respect compatibility with old behavior and make a difference between ttl inherit and ttl == 0, we add an attribute IFLA_GENEVE_TTL_INHERIT in kernel commit 52d0d404d39dd ("geneve: add ttl inherit support").

Quoted 6 lines

Now let's use "ttl inherit" to inherit the inner protocol's ttl, and use "ttl auto" to means "use whatever default value", the same behavior with ttl == 0.

#2 lore raw
Quoted 9 lines · Phil Sutter
Quoted 8 lines · Hangbin Liu

Currently when we add geneve with "ttl inherit", we set ttl to 0, which is actually use whatever default value instead of inherit the inner protocol's ttl value.

To respect compatibility with old behavior and make a difference between ttl inherit and ttl == 0, we add an attribute IFLA_GENEVE_TTL_INHERIT in kernel commit 52d0d404d39dd ("geneve: add ttl inherit support").

Quoted 8 lines
Quoted 6 lines

Now let's use "ttl inherit" to inherit the inner protocol's ttl, and use "ttl auto" to means "use whatever default value", the same behavior with ttl == 0.

Hi Stephen, David,

Please hold on this path and let me fix the inherit flag issue first.

Thanks
Hangbin

#3 lore raw

PATCH v2 1/1 ip/geneve: fix ttl inherit behavior

In reply to Hangbin Liu

Currently when we add geneve with "ttl inherit", we only set ttl to 0, which is actually use whatever default value instead of inherit the inner protocol's ttl value.

To make a difference with ttl inherit and ttl == 0, we add an attribute IFLA_GENEVE_TTL_INHERIT in kernel commit 52d0d404d39dd ("geneve: add ttl inherit support"). Now let's use "ttl inherit" to inherit the inner protocol's ttl, and use "ttl auto" to means "use whatever default value", the same behavior with ttl == 0.

v2:
1) remove IFLA_GENEVE_TTL_INHERIT defination in if_link.h as it's already updated.
2) Still use addattr8() so we can enable/disable ttl inherit, as Michal suggested.

---
 ip/iplink_geneve.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
ip/iplink_geneve.c +13 -7
index 26e70ff..c417842 100644
@@ -34,7 +34,7 @@ static void print_explain(FILE *f)
 		"Where: VNI   := 0-16777215\n"
 		"       ADDR  := IP_ADDRESS\n"
 		"       TOS   := { NUMBER | inherit }\n"
-		"       TTL   := { 1..255 | inherit }\n"
+		"       TTL   := { 1..255 | auto | inherit }\n"
 		"       LABEL := 0-1048575\n"
 	);
 }
@@ -94,7 +94,9 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
 
 			NEXT_ARG();
 			check_duparg(&attrs, IFLA_GENEVE_TTL, "ttl", *argv);
-			if (strcmp(*argv, "inherit") != 0) {
+			if (strcmp(*argv, "inherit") == 0) {
+				addattr8(n, 1024, IFLA_GENEVE_TTL_INHERIT, 1);
+			} else if (strcmp(*argv, "auto") != 0) {
 				if (get_unsigned(&uval, *argv, 0))
 					invarg("invalid TTL", *argv);
 				if (uval > 255)
@@ -265,12 +267,16 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 		}
 	}
 
-	if (tb[IFLA_GENEVE_TTL])
-		ttl = rta_getattr_u8(tb[IFLA_GENEVE_TTL]);
-	if (is_json_context() || ttl)
-		print_uint(PRINT_ANY, "ttl", "ttl %u ", ttl);
-	else
+	if (tb[IFLA_GENEVE_TTL_INHERIT] &&
+	    rta_getattr_u8(tb[IFLA_GENEVE_TTL_INHERIT])) {
 		print_string(PRINT_FP, NULL, "ttl %s ", "inherit");
+	} else if (tb[IFLA_GENEVE_TTL]) {
+		ttl = rta_getattr_u8(tb[IFLA_GENEVE_TTL]);
+		if (is_json_context() || ttl)
+			print_uint(PRINT_ANY, "ttl", "ttl %u ", ttl);
+		else
+			print_string(PRINT_FP, NULL, "ttl %s ", "auto");
+	}
 
 	if (tb[IFLA_GENEVE_TOS])
 		tos = rta_getattr_u8(tb[IFLA_GENEVE_TOS]);
Signature · 1 line
2.5.5
#4 lore raw

Re: [PATCHv2 iproute2-next] ip/geneve: fix ttl inherit behavior

Quoted 16 lines · Hangbin Liu

Currently when we add geneve with "ttl inherit", we only set ttl to 0, which is actually use whatever default value instead of inherit the inner protocol's ttl value.

To make a difference with ttl inherit and ttl == 0, we add an attribute IFLA_GENEVE_TTL_INHERIT in kernel commit 52d0d404d39dd ("geneve: add ttl inherit support"). Now let's use "ttl inherit" to inherit the inner protocol's ttl, and use "ttl auto" to means "use whatever default value", the same behavior with ttl == 0.

v2:
1) remove IFLA_GENEVE_TTL_INHERIT defination in if_link.h as it's already updated.
2) Still use addattr8() so we can enable/disable ttl inherit, as Michal suggested.

Quoted 6 lines
---
 ip/iplink_geneve.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

please update the man page as well.

#5 lore raw

PATCH v3 1/1 ip/geneve: fix ttl inherit behavior

In reply to Hangbin Liu

Currently when we add geneve with "ttl inherit", we only set ttl to 0, which is actually use whatever default value instead of inherit the inner protocol's ttl value.

To make a difference with ttl inherit and ttl == 0, we add an attribute IFLA_GENEVE_TTL_INHERIT in kernel commit 52d0d404d39dd ("geneve: add ttl inherit support"). Now let's use "ttl inherit" to inherit the inner protocol's ttl, and use "ttl auto" to means "use whatever default value", the same behavior with ttl == 0.

v2:
1) remove IFLA_GENEVE_TTL_INHERIT defination in if_link.h as it's already updated.
2) Still use addattr8() so we can enable/disable ttl inherit, as Michal suggested.

v3: Update man page

---
 ip/iplink_geneve.c    | 20 +++++++++++++-------
 man/man8/ip-link.8.in |  4 +++-
 2 files changed, 16 insertions(+), 8 deletions(-)
ip/iplink_geneve.c +13 -7
index 26e70ff..c417842 100644
@@ -34,7 +34,7 @@ static void print_explain(FILE *f)
 		"Where: VNI   := 0-16777215\n"
 		"       ADDR  := IP_ADDRESS\n"
 		"       TOS   := { NUMBER | inherit }\n"
-		"       TTL   := { 1..255 | inherit }\n"
+		"       TTL   := { 1..255 | auto | inherit }\n"
 		"       LABEL := 0-1048575\n"
 	);
 }
@@ -94,7 +94,9 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
 
 			NEXT_ARG();
 			check_duparg(&attrs, IFLA_GENEVE_TTL, "ttl", *argv);
-			if (strcmp(*argv, "inherit") != 0) {
+			if (strcmp(*argv, "inherit") == 0) {
+				addattr8(n, 1024, IFLA_GENEVE_TTL_INHERIT, 1);
+			} else if (strcmp(*argv, "auto") != 0) {
 				if (get_unsigned(&uval, *argv, 0))
 					invarg("invalid TTL", *argv);
 				if (uval > 255)
@@ -265,12 +267,16 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 		}
 	}
 
-	if (tb[IFLA_GENEVE_TTL])
-		ttl = rta_getattr_u8(tb[IFLA_GENEVE_TTL]);
-	if (is_json_context() || ttl)
-		print_uint(PRINT_ANY, "ttl", "ttl %u ", ttl);
-	else
+	if (tb[IFLA_GENEVE_TTL_INHERIT] &&
+	    rta_getattr_u8(tb[IFLA_GENEVE_TTL_INHERIT])) {
 		print_string(PRINT_FP, NULL, "ttl %s ", "inherit");
+	} else if (tb[IFLA_GENEVE_TTL]) {
+		ttl = rta_getattr_u8(tb[IFLA_GENEVE_TTL]);
+		if (is_json_context() || ttl)
+			print_uint(PRINT_ANY, "ttl", "ttl %u ", ttl);
+		else
+			print_string(PRINT_FP, NULL, "ttl %s ", "auto");
+	}
 
 	if (tb[IFLA_GENEVE_TOS])
 		tos = rta_getattr_u8(tb[IFLA_GENEVE_TOS]);
man/man8/ip-link.8.in +3 -1
index ecbbd4f..4489162 100644
@@ -1190,7 +1190,9 @@ the following additional arguments are supported:
 
 .sp
 .BI ttl " TTL"
-- specifies the TTL value to use in outgoing packets.
+- specifies the TTL value to use in outgoing packets. "0" or "auto" means
+use whatever default value, "inherit" means inherit the inner protocol's
+ttl. Default option is "0".
 
 .sp
 .BI tos " TOS"
Signature · 1 line
2.5.5
Applied
#6 lore raw

Re: [PATCHv3 iproute2-next] ip/geneve: fix ttl inherit behavior

Quoted 16 lines · Hangbin Liu

Currently when we add geneve with "ttl inherit", we only set ttl to 0, which is actually use whatever default value instead of inherit the inner protocol's ttl value.

To make a difference with ttl inherit and ttl == 0, we add an attribute IFLA_GENEVE_TTL_INHERIT in kernel commit 52d0d404d39dd ("geneve: add ttl inherit support"). Now let's use "ttl inherit" to inherit the inner protocol's ttl, and use "ttl auto" to means "use whatever default value", the same behavior with ttl == 0.

v2:
1) remove IFLA_GENEVE_TTL_INHERIT defination in if_link.h as it's already updated.
2) Still use addattr8() so we can enable/disable ttl inherit, as Michal suggested.

Quoted 9 lines

v3: Update man page

---
 ip/iplink_geneve.c    | 20 +++++++++++++-------
 man/man8/ip-link.8.in |  4 +++-
 2 files changed, 16 insertions(+), 8 deletions(-)

applied to iproute2-next. Thanks