platform/tests: fix unit test creating ip6gre tunnel with old iproute2

Older versions of iproute2 don't support the "enclimit" argument. Work
around that from the unit tests.

Fixes: 1505ca3626 ('platform/tests: ip6gre & ip6gretap test cases (ip6 tunnel flags)')
(cherry picked from commit 640c82710f)
This commit is contained in:
Thomas Haller 2023-04-07 16:31:54 +02:00 committed by Beniamino Galvani
parent 7f8b73c0d0
commit e720f2f002
2 changed files with 16 additions and 3 deletions

View file

@ -2520,7 +2520,7 @@ nmtstp_link_ip6gre_add(NMPlatform *platform,
gboolean success;
char b1[NM_INET_ADDRSTRLEN];
char b2[NM_INET_ADDRSTRLEN];
char encap[20];
char encap[100];
char tclass[20];
gboolean encap_ignore;
gboolean tclass_inherit;
@ -2532,6 +2532,7 @@ nmtstp_link_ip6gre_add(NMPlatform *platform,
_init_platform(&platform, external_command);
again:
if (external_command) {
gs_free char *dev = NULL;
@ -2543,7 +2544,7 @@ nmtstp_link_ip6gre_add(NMPlatform *platform,
encap_ignore = NM_FLAGS_HAS(lnk->flags, IP6_TNL_F_IGN_ENCAP_LIMIT);
success = !nmtstp_run_command(
"ip link add %s type %s%s%s local %s remote %s ttl %u tclass %s encaplimit %s "
"ip link add %s type %s%s%s local %s remote %s ttl %u tclass %s%s "
"flowlabel %x",
name,
lnk->is_tap ? "ip6gretap" : "ip6gre",
@ -2552,8 +2553,19 @@ nmtstp_link_ip6gre_add(NMPlatform *platform,
nm_inet6_ntop(&lnk->remote, b2),
lnk->ttl,
tclass_inherit ? "inherit" : nm_sprintf_buf(tclass, "%02x", lnk->tclass),
encap_ignore ? "none" : nm_sprintf_buf(encap, "%u", lnk->encap_limit),
encap_ignore
? "encaplimit none"
: (lnk->encap_limit != 4 ? nm_sprintf_buf(encap, "encaplimit %u", lnk->encap_limit)
: ""),
lnk->flow_label);
if (!success && (encap_ignore || lnk->encap_limit != 4)) {
/* The command failed. That might be because iproute2 does not support the
* encaplimit parameter yet. Retry, now with platform code. */
external_command = FALSE;
goto again;
}
if (success) {
pllink = nmtstp_assert_wait_for_link(platform,
name,

View file

@ -1496,6 +1496,7 @@ test_software_detect(gconstpointer user_data)
lnk_ip6tnl.flow_label = 1341;
lnk_ip6tnl.is_gre = TRUE;
lnk_ip6tnl.is_tap = TRUE;
lnk_ip6tnl.encap_limit = 4;
lnk_ip6tnl.flags = IP6_TNL_F_IGN_ENCAP_LIMIT | IP6_TNL_F_USE_ORIG_TCLASS;
break;
}