]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
tunnel: factorize printout of GRE key and flags
authorAndrea Claudi <aclaudi@redhat.com>
Fri, 12 Jul 2019 17:02:14 +0000 (19:02 +0200)
committerDavid Ahern <dsahern@gmail.com>
Thu, 18 Jul 2019 17:19:47 +0000 (10:19 -0700)
print_tunnel() functions in ip6tunnel.c and iptunnel.c contains
the same code to print out GRE key and flags

This commit factorize the code in a helper function in tunnel.c

Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
ip/ip6tunnel.c
ip/iptunnel.c
ip/tunnel.c
ip/tunnel.h

index 2e0f099cd7ced950035d595c804d1d42018daa3c..d7684a673fdc4f294834f5362b611a8b3cf0be4a 100644 (file)
@@ -120,26 +120,8 @@ static void print_tunnel(const void *t)
        if (p->flags & IP6_TNL_F_ALLOW_LOCAL_REMOTE)
                printf(" allow-localremote");
 
-       if ((p->i_flags & GRE_KEY) && (p->o_flags & GRE_KEY) &&
-           p->o_key == p->i_key)
-               printf(" key %u", ntohl(p->i_key));
-       else {
-               if (p->i_flags & GRE_KEY)
-                       printf(" ikey %u", ntohl(p->i_key));
-               if (p->o_flags & GRE_KEY)
-                       printf(" okey %u", ntohl(p->o_key));
-       }
-
-       if (p->proto == IPPROTO_GRE) {
-               if (p->i_flags & GRE_SEQ)
-                       printf("%s  Drop packets out of sequence.", _SL_);
-               if (p->i_flags & GRE_CSUM)
-                       printf("%s  Checksum in received packet is required.", _SL_);
-               if (p->o_flags & GRE_SEQ)
-                       printf("%s  Sequence packets on output.", _SL_);
-               if (p->o_flags & GRE_CSUM)
-                       printf("%s  Checksum output packets.", _SL_);
-       }
+       tnl_print_gre_flags(p->proto, p->i_flags, p->o_flags,
+                           p->i_key, p->o_key);
 }
 
 static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
index 92a5cb923b6b02a47766f22af5cfbdbf3401c569..66929e75c744887df40793a717e4192eb0c21315 100644 (file)
@@ -354,23 +354,8 @@ static void print_tunnel(const void *t)
                }
        }
 
-       if ((p->i_flags & GRE_KEY) && (p->o_flags & GRE_KEY) && p->o_key == p->i_key)
-               printf(" key %u", ntohl(p->i_key));
-       else if ((p->i_flags | p->o_flags) & GRE_KEY) {
-               if (p->i_flags & GRE_KEY)
-                       printf(" ikey %u", ntohl(p->i_key));
-               if (p->o_flags & GRE_KEY)
-                       printf(" okey %u", ntohl(p->o_key));
-       }
-
-       if (p->i_flags & GRE_SEQ)
-               printf("%s  Drop packets out of sequence.", _SL_);
-       if (p->i_flags & GRE_CSUM)
-               printf("%s  Checksum in received packet is required.", _SL_);
-       if (p->o_flags & GRE_SEQ)
-               printf("%s  Sequence packets on output.", _SL_);
-       if (p->o_flags & GRE_CSUM)
-               printf("%s  Checksum output packets.", _SL_);
+       tnl_print_gre_flags(p->iph.protocol, p->i_flags, p->o_flags,
+                           p->i_key, p->o_key);
 }
 
 
index d0d55f37169e9f522e39453b894b61f9bbf0200e..41b0ef3165fdc16d7bb65c9b597b006bd1664bef 100644 (file)
@@ -308,6 +308,32 @@ void tnl_print_endpoint(const char *name, const struct rtattr *rta, int family)
        }
 }
 
+void tnl_print_gre_flags(__u8 proto,
+                        __be16 i_flags, __be16 o_flags,
+                        __be32 i_key, __be32 o_key)
+{
+       if ((i_flags & GRE_KEY) && (o_flags & GRE_KEY) &&
+           o_key == i_key) {
+               printf(" key %u", ntohl(i_key));
+       } else {
+               if (i_flags & GRE_KEY)
+                       printf(" ikey %u", ntohl(i_key));
+               if (o_flags & GRE_KEY)
+                       printf(" okey %u", ntohl(o_key));
+       }
+
+       if (proto == IPPROTO_GRE) {
+               if (i_flags & GRE_SEQ)
+                       printf("%s  Drop packets out of sequence.", _SL_);
+               if (i_flags & GRE_CSUM)
+                       printf("%s  Checksum in received packet is required.", _SL_);
+               if (o_flags & GRE_SEQ)
+                       printf("%s  Sequence packets on output.", _SL_);
+               if (o_flags & GRE_CSUM)
+                       printf("%s  Checksum output packets.", _SL_);
+       }
+}
+
 static void tnl_print_stats(const struct rtnl_link_stats64 *s)
 {
        printf("%s", _SL_);
index e530d07cbf6a2f4a7acfef1727f3b441c95f7d85..604f8cbfd6db2164e2bacf5d897937d324138b4a 100644 (file)
@@ -55,5 +55,8 @@ void tnl_print_encap(struct rtattr *tb[],
                     int encap_sport, int encap_dport);
 void tnl_print_endpoint(const char *name,
                        const struct rtattr *rta, int family);
+void tnl_print_gre_flags(__u8 proto,
+                        __be16 i_flags, __be16 o_flags,
+                        __be32 i_key, __be32 o_key);
 
 #endif