iptnl/ip6tnl: Unify ttl/hoplimit parsing routines

Handle "inherit" case properly for gre6 and ip6tnl.

Use get_u8() in gre to parse ttl/hoplimit.

Be consistent about "hlim" alias to ttl/hoplimit
support.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
Serhey Popovych 2018-01-19 18:44:01 +02:00 committed by Stephen Hemminger
parent b53835de38
commit c4743c4d9b
4 changed files with 19 additions and 21 deletions

View File

@ -229,16 +229,12 @@ get_failed:
exit(-1);
}
} else if (!matches(*argv, "ttl") ||
!matches(*argv, "hoplimit")) {
unsigned int uval;
!matches(*argv, "hoplimit") ||
!matches(*argv, "hlim")) {
NEXT_ARG();
if (strcmp(*argv, "inherit") != 0) {
if (get_unsigned(&uval, *argv, 0))
if (get_u8(&ttl, *argv, 0))
invarg("invalid TTL\n", *argv);
if (uval > 255)
invarg("TTL must be <= 255\n", *argv);
ttl = uval;
} else
ttl = 0;
} else if (!matches(*argv, "tos") ||

View File

@ -238,13 +238,14 @@ get_failed:
exit(-1);
}
} else if (!matches(*argv, "ttl") ||
!matches(*argv, "hoplimit")) {
__u8 uval;
!matches(*argv, "hoplimit") ||
!matches(*argv, "hlim")) {
NEXT_ARG();
if (get_u8(&uval, *argv, 0))
invarg("invalid TTL", *argv);
hop_limit = uval;
if (strcmp(*argv, "inherit") != 0) {
if (get_u8(&hop_limit, *argv, 0))
invarg("invalid HLIM\n", *argv);
} else
hop_limit = 0;
} else if (!matches(*argv, "tos") ||
!matches(*argv, "tclass") ||
!matches(*argv, "dsfield")) {

View File

@ -196,15 +196,15 @@ get_failed:
link = if_nametoindex(*argv);
if (link == 0)
invarg("\"dev\" is invalid", *argv);
} else if (strcmp(*argv, "hoplimit") == 0 ||
strcmp(*argv, "ttl") == 0 ||
} else if (strcmp(*argv, "ttl") == 0 ||
strcmp(*argv, "hoplimit") == 0 ||
strcmp(*argv, "hlim") == 0) {
__u8 uval;
NEXT_ARG();
if (get_u8(&uval, *argv, 0))
invarg("invalid HLIM", *argv);
hop_limit = uval;
if (strcmp(*argv, "inherit") != 0) {
if (get_u8(&hop_limit, *argv, 0))
invarg("invalid HLIM\n", *argv);
} else
hop_limit = 0;
} else if (strcmp(*argv, "encaplimit") == 0) {
NEXT_ARG();
if (strcmp(*argv, "none") == 0) {

View File

@ -204,7 +204,8 @@ get_failed:
if (link == 0)
invarg("\"dev\" is invalid", *argv);
} else if (strcmp(*argv, "ttl") == 0 ||
strcmp(*argv, "hoplimit") == 0) {
strcmp(*argv, "hoplimit") == 0 ||
strcmp(*argv, "hlim") == 0) {
NEXT_ARG();
if (strcmp(*argv, "inherit") != 0) {
if (get_u8(&ttl, *argv, 0))