ip/tunnels: Reuse code, vti6 zero endpoint support and minor cleanup
Subsystems (2)
cover ip/tunnels: Reuse code, vti6 zero endpoint support and minor cleanup
In this series I present next set of improvements:
1) Use tnl_parse_key() to avoid code duplication in tunnel configuration via netlink code.
2) Trivial: use IN6ADDR_ANY_INIT instead of open coded initialization of local/remote endpoint in ip6tnl code.
3) Trivial: drop additional checks for zero endpoint in vti6 code. This completes and unifies support for unconfiguring local/remote endpoint for tunnel.
See individual patch description message for details.
Thanks,
Serhii
Serhey Popovych (3):
ip/tunnel: Use tnl_parse_key() to parse tunnel key
link_ip6tnl: Use IN6ADDR_ANY_INIT to initialize local/remote
endpoints
link_vti6: Always add local/remote endpoint attributes
ip/link_gre.c | 45 +++++---------------------------------------- ip/link_gre6.c | 45 +++++---------------------------------------- ip/link_ip6tnl.c | 4 ++-- ip/link_vti.c | 45 +++++---------------------------------------- ip/link_vti6.c | 51 +++++++-------------------------------------------- ip/tunnel.c | 5 +++-- 6 files changed, 27 insertions(+), 168 deletions(-)
Signature · 1 line
1.7.10.4
PATCH 1/3 ip/tunnel: Use tnl_parse_key() to parse tunnel key
It is added with commit a7ed1520ee96 (ip/tunnel:
introduce tnl_parse_key()) to avoid code duplication in ip6?tunnel.c.
Reuse it for gre/gre6 and vti/vti6 tunnel rtnl configuration interface with the same purpose it is used in tunnel ioctl interface in ip6?tunnel.c.
While there change type of key variables from unsigned integer to __be32 to reflect nature of the value they store and place error message in tnl_parse_key() on a single line to make single call to fprintf().
--- ip/link_gre.c | 45 +++++---------------------------------------- ip/link_gre6.c | 45 +++++---------------------------------------- ip/link_vti.c | 45 +++++---------------------------------------- ip/link_vti6.c | 45 +++++---------------------------------------- ip/tunnel.c | 5 +++-- 5 files changed, 23 insertions(+), 162 deletions(-)
ip/link_gre.c +5 -40
@@ -81,8 +81,8 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,struct rtattr *greinfo[IFLA_GRE_MAX +1 ];__u16 iflags =0 ;__u16 oflags =0 ; -unsigned int ikey =0 ; -unsigned int okey =0 ; +__be32 ikey =0 ; +__be32 okey =0 ;unsigned int saddr =0 ;unsigned int daddr =0 ;unsigned int link =0 ;
@@ -184,53 +184,18 @@ get_failed:while (argc >0 ) {if (!matches (*argv,"key" )) { -unsigned int uval; -NEXT_ARG (); iflags |=GRE_KEY ; oflags |=GRE_KEY ; -if (strchr (*argv,'.' )) - uval =get_addr32 (*argv); -else { -if (get_unsigned (&uval, *argv,0 ) <0 ) { -fprintf (stderr, -"Invalid value for \"key\": \"%s\"; it should be an unsigned integer\n" , *argv); -exit (-1 ); - } - uval =htonl (uval); - } - - ikey = okey = uval; + ikey = okey =tnl_parse_key ("key" , *argv); }else if (!matches (*argv,"ikey" )) { -unsigned int uval; -NEXT_ARG (); iflags |=GRE_KEY ; -if (strchr (*argv,'.' )) - uval =get_addr32 (*argv); -else { -if (get_unsigned (&uval, *argv,0 ) <0 ) { -fprintf (stderr,"invalid value for \"ikey\": \"%s\"; it should be an unsigned integer\n" , *argv); -exit (-1 ); - } - uval =htonl (uval); - } - ikey = uval; + ikey =tnl_parse_key ("ikey" , *argv); }else if (!matches (*argv,"okey" )) { -unsigned int uval; -NEXT_ARG (); oflags |=GRE_KEY ; -if (strchr (*argv,'.' )) - uval =get_addr32 (*argv); -else { -if (get_unsigned (&uval, *argv,0 ) <0 ) { -fprintf (stderr,"invalid value for \"okey\": \"%s\"; it should be an unsigned integer\n" , *argv); -exit (-1 ); - } - uval =htonl (uval); - } - okey = uval; + okey =tnl_parse_key ("okey" , *argv); }else if (!matches (*argv,"seq" )) { iflags |=GRE_SEQ ; oflags |=GRE_SEQ ;
ip/link_gre6.c +5 -40
66 lines not on this page · raw message
ip/link_vti.c +5 -40
62 lines not on this page · raw message
ip/link_vti6.c +5 -40
62 lines not on this page · raw message
ip/tunnel.c +3 -2
@@ -192,8 +192,9 @@ __be32 tnl_parse_key(const char *name, const char *key)return get_addr32 (key);if (get_unsigned (&uval, key,0 ) <0 ) { -fprintf (stderr,"invalid value for \"%s\": \"%s\";" , name, key); -fprintf (stderr," it should be an unsigned integer\n" ); +fprintf (stderr, +"invalid value for \"%s\": \"%s\"; it should be an unsigned integer\n" , + name, key);exit (-1 ); }return htonl (uval);
Signature · 1 line
1.7.10.4
PATCH 2/3 link_ip6tnl: Use IN6ADDR_ANY_INIT to initialize local/remote endpoints
In reply to Serhey PopovychUse specialized helper to initialize endpoint addresses with zeros instead of open coding this. This unifies initialization style with other ipv6 tunnel variants (i.e. gre6 and vti6).
--- ip/link_ip6tnl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
ip/link_ip6tnl.c +2 -2
@@ -88,8 +88,8 @@ static int ip6tunnel_parse_opt(struct link_util *lu, int argc, char **argv,struct rtattr *linkinfo[IFLA_INFO_MAX +1 ];struct rtattr *iptuninfo[IFLA_IPTUN_MAX +1 ];int len; -struct in6_addr laddr = {}; -struct in6_addr raddr = {}; +struct in6_addr laddr =IN6ADDR_ANY_INIT ; +struct in6_addr raddr =IN6ADDR_ANY_INIT ;__u8 hop_limit =DEFAULT_TNL_HOP_LIMIT ;__u8 encap_limit =IPV6_DEFAULT_TNL_ENCAP_LIMIT ;__u32 flowinfo =0 ;
Signature · 1 line
1.7.10.4
PATCH 3/3 link_vti6: Always add local/remote endpoint attributes
In reply to Serhey PopovychAll tunnels already support for parsing/adding zero endpoints and vti6 isn't an exception.
This check was added as part of commit 2a80154fde40 (vti6: fix local/remote any addr handling) and looks too restrictive as purpose of change is to avoid endpoint configuration from uninitialized data.
--- ip/link_vti6.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
ip/link_vti6.c +2 -4
@@ -154,10 +154,8 @@ get_failed:addattr32 (n,1024 ,IFLA_VTI_IKEY , ikey);addattr32 (n,1024 ,IFLA_VTI_OKEY , okey); -if (memcmp (&saddr, &in6addr_any,sizeof (in6addr_any))) -addattr_l (n,1024 ,IFLA_VTI_LOCAL , &saddr,sizeof (saddr)); -if (memcmp (&daddr, &in6addr_any,sizeof (in6addr_any))) -addattr_l (n,1024 ,IFLA_VTI_REMOTE , &daddr,sizeof (daddr)); +addattr_l (n,1024 ,IFLA_VTI_LOCAL , &saddr,sizeof (saddr)); +addattr_l (n,1024 ,IFLA_VTI_REMOTE , &daddr,sizeof (daddr));addattr32 (n,1024 ,IFLA_VTI_FWMARK , fwmark);if (link)addattr32 (n,1024 ,IFLA_VTI_LINK , link);
Signature · 1 line
1.7.10.4
Stephen Hemminger
AppliedQuoted 23 lines · On Mon, 18 Dec 2017 19:48:02 +0200 Serhey Popovych <[email protected]>…
In this series I present next set of improvements:
1) Use
tnl_parse_key()to avoid code duplication in tunnel configuration via netlink code.2) Trivial: use
IN6ADDR_ANY_INITinstead of open coded initialization of local/remote endpoint in ip6tnl code.3) Trivial: drop additional checks for zero endpoint in vti6 code. This completes and unifies support for unconfiguring local/remote endpoint for tunnel.
See individual patch description message for details.
Thanks,
SerhiiSerhey Popovych (3):
ip/tunnel: Usetnl_parse_key()to parse tunnel key
link_ip6tnl: UseIN6ADDR_ANY_INITto initialize local/remote
endpoints
link_vti6: Always add local/remote endpoint attributes
Quoted 8 lines
ip/link_gre.c | 45 +++++---------------------------------------- ip/link_gre6.c | 45 +++++---------------------------------------- ip/link_ip6tnl.c | 4 ++-- ip/link_vti.c | 45 +++++---------------------------------------- ip/link_vti6.c | 51 +++++++-------------------------------------------- ip/tunnel.c | 5 +++-- 6 files changed, 27 insertions(+), 168 deletions(-)
Applied, thanks