ip link gre: fix external mode handling
Subsystems (2)
cover ip link gre: fix external mode handling
Fix two bugs with handling of the 'external' keyword for GRE.
Jiri Benc (2):
ip link gre: create interfaces in external mode correctly ip link gre: print only relevant info in external mode
ip/link_gre.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/2 ip link gre: create interfaces in external mode correctly
For GRE interfaces in 'external' mode, the kernel ignores all manual settings like remote IP address or TTL. However, for some of those attributes, kernel checks their value and does not allow them to be zero (even though they're ignored later).
Currently, 'ip link' always includes all attributes in the netlink message. This leads to problem with creating interfaces in 'external' mode. For example, this command does not work:
ip link add gre1 type gretap external
and needs a bogus remote IP address to be specified, as the kernel enforces remote IP address to be either not present, or not null.
Ignore the parameters that do not make sense in 'external' mode. Unfortunately, we cannot error out, as there may be existing deployments that workarounded the bug by specifying bogus values.
--- ip/link_gre.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
ip/link_gre.c +15 -13
@@ -315,24 +315,26 @@ get_failed:return -1 ; } -addattr32 (n,1024 ,IFLA_GRE_IKEY , ikey); -addattr32 (n,1024 ,IFLA_GRE_OKEY , okey); -addattr_l (n,1024 ,IFLA_GRE_IFLAGS , &iflags,2 ); -addattr_l (n,1024 ,IFLA_GRE_OFLAGS , &oflags,2 ); -addattr_l (n,1024 ,IFLA_GRE_LOCAL , &saddr,4 ); -addattr_l (n,1024 ,IFLA_GRE_REMOTE , &daddr,4 ); -addattr_l (n,1024 ,IFLA_GRE_PMTUDISC , &pmtudisc,1 ); -if (link) -addattr32 (n,1024 ,IFLA_GRE_LINK , link); -addattr_l (n,1024 ,IFLA_GRE_TTL , &ttl,1 ); -addattr_l (n,1024 ,IFLA_GRE_TOS , &tos,1 ); +if (!metadata) { +addattr32 (n,1024 ,IFLA_GRE_IKEY , ikey); +addattr32 (n,1024 ,IFLA_GRE_OKEY , okey); +addattr_l (n,1024 ,IFLA_GRE_IFLAGS , &iflags,2 ); +addattr_l (n,1024 ,IFLA_GRE_OFLAGS , &oflags,2 ); +addattr_l (n,1024 ,IFLA_GRE_LOCAL , &saddr,4 ); +addattr_l (n,1024 ,IFLA_GRE_REMOTE , &daddr,4 ); +addattr_l (n,1024 ,IFLA_GRE_PMTUDISC , &pmtudisc,1 ); +if (link) +addattr32 (n,1024 ,IFLA_GRE_LINK , link); +addattr_l (n,1024 ,IFLA_GRE_TTL , &ttl,1 ); +addattr_l (n,1024 ,IFLA_GRE_TOS , &tos,1 ); + }else { +addattr_l (n,1024 ,IFLA_GRE_COLLECT_METADATA ,NULL ,0 ); + }addattr16 (n,1024 ,IFLA_GRE_ENCAP_TYPE , encaptype);addattr16 (n,1024 ,IFLA_GRE_ENCAP_FLAGS , encapflags);addattr16 (n,1024 ,IFLA_GRE_ENCAP_SPORT ,htons (encapsport));addattr16 (n,1024 ,IFLA_GRE_ENCAP_DPORT ,htons (encapdport)); -if (metadata) -addattr_l (n,1024 ,IFLA_GRE_COLLECT_METADATA ,NULL ,0 );return 0 ; }
Signature · 1 line
1.8.3.1
PATCH 2/2 ip link gre: print only relevant info in external mode
In reply to Jiri BencDisplay only attributes that are relevant when a GRE interface is in 'external' mode instead of the default values (which are ignored by the kernel even if passed back).
--- ip/link_gre.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
ip/link_gre.c +10 -5
@@ -339,7 +339,7 @@ get_failed:return 0 ; } -static void gre_print_opt (struct link_util *lu,FILE *f,struct rtattr *tb[]) +static void gre_print_direct_opt (FILE *f,struct rtattr *tb[]) {char s2[64 ];const char *local ="any" ;
@@ -347,9 +347,6 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])unsigned int iflags =0 ;unsigned int oflags =0 ; -if (!tb) -return ; -if (tb[IFLA_GRE_REMOTE ]) {unsigned int addr =rta_getattr_u32 (tb[IFLA_GRE_REMOTE ]);
@@ -421,8 +418,16 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])fputs ("icsum " , f);if (oflags &GRE_CSUM )fputs ("ocsum " , f); +} -if (tb[IFLA_GRE_COLLECT_METADATA ]) +static void gre_print_opt (struct link_util *lu,FILE *f,struct rtattr *tb[]) +{ +if (!tb) +return ; + +if (!tb[IFLA_GRE_COLLECT_METADATA ]) +gre_print_direct_opt (f, tb); +else fputs ("external " , f); if (tb[IFLA_GRE_ENCAP_TYPE] &&
Signature · 1 line
1.8.3.1
Stephen Hemminger
AppliedQuoted 9 lines · On Wed, 27 Apr 2016 16:11:12 +0200 Jiri Benc <[email protected]> wrote:
Fix two bugs with handling of the 'external' keyword for GRE.
Jiri Benc (2):
ip link gre: create interfaces in external mode correctly ip link gre: print only relevant info in external modeip/link_gre.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-)
Applied