ip/tunnel: Minor cleanups
Subsystems (2)
PATCH 1/1 ip/tunnel: Minor cleanups
Few minor changes to reduce diffs between ip and ipv6 tunnel code:
1) reduce intendation by one level when adding attributes in gre and gre6; reorder addattr*() calls to simplify diff
2) reorder local variables definition; change their type (e.g. for IFLA_LINK) to match ones returned by rta_getattr_*()
3) move "mode" parameter parsing in link_iptnl.c to the similar position as in link_ip6tnl.c
4) handle "tc" as shortcut for "tclass"/"tos" in link_iptnl.c
5) add whitespace where required
--- ip/link_gre.c | 91 +++++++++++++++++++++++++++--------------------------- ip/link_gre6.c | 83 ++++++++++++++++++++++++------------------------- ip/link_ip6tnl.c | 13 ++++---- ip/link_iptnl.c | 61 ++++++++++++++++++------------------ ip/link_vti.c | 2 +- ip/link_vti6.c | 2 +- 6 files changed, 127 insertions(+), 125 deletions(-)
ip/link_gre.c +46 -45
@@ -84,23 +84,23 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,struct rtattr *tb[IFLA_MAX +1 ];struct rtattr *linkinfo[IFLA_INFO_MAX +1 ];struct rtattr *greinfo[IFLA_GRE_MAX +1 ]; +int len;__u16 iflags =0 ;__u16 oflags =0 ;__be32 ikey =0 ;__be32 okey =0 ;unsigned int saddr =0 ;unsigned int daddr =0 ; -unsigned int link =0 ;__u8 pmtudisc =1 ; -__u8 ttl =0 ; +__u8 ignore_df =0 ;__u8 tos =0 ; -int len; +__u8 ttl =0 ; +__u32 link =0 ;__u16 encaptype =0 ;__u16 encapflags =0 ;__u16 encapsport =0 ;__u16 encapdport =0 ;__u8 metadata =0 ; -__u8 ignore_df =0 ;__u32 fwmark =0 ;__u32 erspan_idx =0 ;__u8 erspan_ver =0 ;
@@ -155,31 +155,34 @@ get_failed: pmtudisc =rta_getattr_u8 ( greinfo[IFLA_GRE_PMTUDISC ]); -if (greinfo[IFLA_GRE_TTL ]) - ttl =rta_getattr_u8 (greinfo[IFLA_GRE_TTL ]); +if (greinfo[IFLA_GRE_IGNORE_DF ]) + ignore_df = + !!rta_getattr_u8 (greinfo[IFLA_GRE_IGNORE_DF ]);if (greinfo[IFLA_GRE_TOS ]) tos =rta_getattr_u8 (greinfo[IFLA_GRE_TOS ]); +if (greinfo[IFLA_GRE_TTL ]) + ttl =rta_getattr_u8 (greinfo[IFLA_GRE_TTL ]); +if (greinfo[IFLA_GRE_LINK ]) link =rta_getattr_u32 (greinfo[IFLA_GRE_LINK ]);if (greinfo[IFLA_GRE_ENCAP_TYPE ]) encaptype =rta_getattr_u16 (greinfo[IFLA_GRE_ENCAP_TYPE ]); +if (greinfo[IFLA_GRE_ENCAP_FLAGS ]) encapflags =rta_getattr_u16 (greinfo[IFLA_GRE_ENCAP_FLAGS ]); +if (greinfo[IFLA_GRE_ENCAP_SPORT ]) encapsport =rta_getattr_u16 (greinfo[IFLA_GRE_ENCAP_SPORT ]); +if (greinfo[IFLA_GRE_ENCAP_DPORT ]) encapdport =rta_getattr_u16 (greinfo[IFLA_GRE_ENCAP_DPORT ]);if (greinfo[IFLA_GRE_COLLECT_METADATA ]) metadata =1 ; -if (greinfo[IFLA_GRE_IGNORE_DF ]) - ignore_df = - !!rta_getattr_u8 (greinfo[IFLA_GRE_IGNORE_DF ]); -if (greinfo[IFLA_GRE_FWMARK ]) fwmark =rta_getattr_u32 (greinfo[IFLA_GRE_FWMARK ]);
@@ -354,49 +357,47 @@ get_failed:return -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 (ignore_df) -addattr8 (n,1024 ,IFLA_GRE_IGNORE_DF , ignore_df &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 ); -addattr32 (n,1024 ,IFLA_GRE_FWMARK , fwmark); -if (erspan_ver) { -addattr8 (n,1024 ,IFLA_GRE_ERSPAN_VER , erspan_ver); -if (erspan_ver ==1 && erspan_idx !=0 ) { -addattr32 (n,1024 , -IFLA_GRE_ERSPAN_INDEX , erspan_idx); - }else if (erspan_ver ==2 ) { -addattr8 (n,1024 , -IFLA_GRE_ERSPAN_DIR , erspan_dir); -addattr16 (n,1024 , -IFLA_GRE_ERSPAN_HWID , erspan_hwid); - } - } -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)); - }else { +if (metadata) {addattr_l (n,1024 ,IFLA_GRE_COLLECT_METADATA ,NULL ,0 ); +return 0 ; } +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 (ignore_df) +addattr8 (n,1024 ,IFLA_GRE_IGNORE_DF , ignore_df &1 ); +addattr_l (n,1024 ,IFLA_GRE_TOS , &tos,1 ); +if (link) +addattr32 (n,1024 ,IFLA_GRE_LINK , link); +addattr_l (n,1024 ,IFLA_GRE_TTL , &ttl,1 ); +addattr32 (n,1024 ,IFLA_GRE_FWMARK , fwmark); +if (erspan_ver) { +addattr8 (n,1024 ,IFLA_GRE_ERSPAN_VER , erspan_ver); +if (erspan_ver ==1 && erspan_idx !=0 ) { +addattr32 (n,1024 ,IFLA_GRE_ERSPAN_INDEX , erspan_idx); + }else if (erspan_ver ==2 ) { +addattr8 (n,1024 ,IFLA_GRE_ERSPAN_DIR , erspan_dir); +addattr16 (n,1024 ,IFLA_GRE_ERSPAN_HWID , erspan_hwid); + } + } +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)); +return 0 ; }static void gre_print_opt (struct link_util *lu,FILE *f,struct rtattr *tb[]) {char s2[64 ]; -unsigned int iflags =0 ; -unsigned int oflags =0 ; +__u16 iflags =0 ; +__u16 oflags =0 ;__u8 ttl =0 ;__u8 tos =0 ;
@@ -412,7 +413,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])tnl_print_endpoint ("local" , tb[IFLA_GRE_LOCAL ],AF_INET );if (tb[IFLA_GRE_LINK ]) { -unsigned int link =rta_getattr_u32 (tb[IFLA_GRE_LINK ]); +__u32 link =rta_getattr_u32 (tb[IFLA_GRE_LINK ]);if (link) { print_string(PRINT_ANY, "link", "dev %s ",
ip/link_gre6.c +41 -42
137 lines not on this page · raw message
ip/link_ip6tnl.c +7 -6
@@ -94,8 +94,8 @@ static int ip6tunnel_parse_opt(struct link_util *lu, int argc, char **argv,__u8 encap_limit =IPV6_DEFAULT_TNL_ENCAP_LIMIT ;__u32 flowinfo =0 ;__u32 flags =0 ; -__u32 link =0 ;__u8 proto =0 ; +__u32 link =0 ;__u16 encaptype =0 ;__u16 encapflags =TUNNEL_ENCAP_FLAG_CSUM6 ;__u16 encapsport =0 ;
@@ -164,7 +164,7 @@ get_failed: }while (argc >0 ) { -if (matches (*argv,"mode" ) ==0 ) { +if (strcmp (*argv,"mode" ) ==0 ) {NEXT_ARG ();if (strcmp (*argv,"ipv6/ipv6" ) ==0 ||strcmp (*argv,"ip6ip6" ) ==0 )
@@ -217,9 +217,9 @@ get_failed: encap_limit = uval; flags &= ~IP6_TNL_F_IGN_ENCAP_LIMIT ; } - }else if (strcmp (*argv,"tclass" ) ==0 || + }else if (strcmp (*argv,"tos" ) ==0 || +strcmp (*argv,"tclass" ) ==0 ||strcmp (*argv,"tc" ) ==0 || -strcmp (*argv,"tos" ) ==0 ||matches (*argv,"dsfield" ) ==0 ) {__u8 uval;
@@ -314,6 +314,7 @@ get_failed:addattr_l (n,1024 ,IFLA_IPTUN_COLLECT_METADATA ,NULL ,0 );return 0 ; } +addattr_l (n,1024 ,IFLA_IPTUN_LOCAL , &laddr,sizeof (laddr));addattr_l (n,1024 ,IFLA_IPTUN_REMOTE , &raddr,sizeof (raddr));addattr8 (n,1024 ,IFLA_IPTUN_TTL , hop_limit);
@@ -334,7 +335,7 @@ get_failed:static void ip6tunnel_print_opt (struct link_util *lu,FILE *f,struct rtattr *tb[]) {char s2[64 ]; -int flags =0 ; +__u32 flags =0 ;__u32 flowinfo =0 ;__u8 ttl =0 ;
@@ -370,7 +371,7 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tbtnl_print_endpoint ("local" , tb[IFLA_IPTUN_LOCAL ],AF_INET6 );if (tb[IFLA_IPTUN_LINK ]) { -unsigned int link =rta_getattr_u32 (tb[IFLA_IPTUN_LINK ]); +__u32 link =rta_getattr_u32 (tb[IFLA_IPTUN_LINK ]);if (link) { print_string(PRINT_ANY, "link", "dev %s ",
ip/link_iptnl.c +31 -30
118 lines not on this page · raw message
ip/link_vti.c +1 -1
@@ -174,7 +174,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])tnl_print_endpoint ("local" , tb[IFLA_VTI_LOCAL ],AF_INET );if (tb[IFLA_VTI_LINK ]) { -unsigned int link =rta_getattr_u32 (tb[IFLA_VTI_LINK ]); +__u32 link =rta_getattr_u32 (tb[IFLA_VTI_LINK ]);if (link) { print_string(PRINT_ANY, "link", "dev %s ",
ip/link_vti6.c +1 -1
@@ -180,7 +180,7 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])tnl_print_endpoint ("local" , tb[IFLA_VTI_LOCAL ],AF_INET6 );if (tb[IFLA_VTI_LINK ]) { -unsigned int link =rta_getattr_u32 (tb[IFLA_VTI_LINK ]); +__u32 link =rta_getattr_u32 (tb[IFLA_VTI_LINK ]);if (link) { print_string(PRINT_ANY, "link", "dev %s ",
Signature · 1 line
1.7.10.4
David Ahern
AppliedQuoted 16 lines · Serhey Popovych
Few minor changes to reduce diffs between ip and ipv6 tunnel code:
1) reduce intendation by one level when adding attributes in gre and gre6; reorder addattr*() calls to simplify diff
2) reorder local variables definition; change their type (e.g. for
IFLA_LINK) to match ones returned by rta_getattr_*()3) move "mode" parameter parsing in
link_iptnl.cto the similar position as inlink_ip6tnl.c4) handle "tc" as shortcut for "tclass"/"tos" in
link_iptnl.c5) add whitespace where required
Signed-off-by Serhey Popovych <[email protected]>
Quoted 9 lines
--- ip/link_gre.c | 91 +++++++++++++++++++++++++++--------------------------- ip/link_gre6.c | 83 ++++++++++++++++++++++++------------------------- ip/link_ip6tnl.c | 13 ++++---- ip/link_iptnl.c | 61 ++++++++++++++++++------------------ ip/link_vti.c | 2 +- ip/link_vti6.c | 2 +- 6 files changed, 127 insertions(+), 125 deletions(-)
applied to iproute2-next.
That is a large change for a single patch. Please send future cleanups with grouped changes like you have done for other patches. gre/gr6 in one patch, vti /vti6 in a second, etc.
Quoted 27 lines · David Ahern
Quoted 16 lines · Serhey Popovych
Few minor changes to reduce diffs between ip and ipv6 tunnel code:
1) reduce intendation by one level when adding attributes in gre and gre6; reorder addattr*() calls to simplify diff
2) reorder local variables definition; change their type (e.g. for
IFLA_LINK) to match ones returned by rta_getattr_*()3) move "mode" parameter parsing in
link_iptnl.cto the similar position as inlink_ip6tnl.c4) handle "tc" as shortcut for "tclass"/"tos" in
link_iptnl.c5) add whitespace where required
Signed-off-by Serhey Popovych <[email protected]>Quoted 9 lines
--- ip/link_gre.c | 91 +++++++++++++++++++++++++++--------------------------- ip/link_gre6.c | 83 ++++++++++++++++++++++++------------------------- ip/link_ip6tnl.c | 13 ++++---- ip/link_iptnl.c | 61 ++++++++++++++++++------------------ ip/link_vti.c | 2 +- ip/link_vti6.c | 2 +- 6 files changed, 127 insertions(+), 125 deletions(-)
Quoted 6 lines
applied to iproute2-next.
That is a large change for a single patch. Please send future cleanups with grouped changes like you have done for other patches. gre/gr6 in one patch, vti /vti6 in a second, etc.
Accepted. Thank you!