lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1518087027-1291-3-git-send-email-serhe.popovych@gmail.com>
Date:   Thu,  8 Feb 2018 12:50:26 +0200
From:   Serhey Popovych <serhe.popovych@...il.com>
To:     netdev@...r.kernel.org
Subject: [PATCH iproute2-next 2/3] gre/gre6: Unify gre_print_help()

Reduce diff lines between gre and gre6 help printing code.

Use @struct link_util ->id field to print correct link help:
all callers now pass this data structure to gre_print_help().

Get rid of custom print_usage() and usage() functions and use
gre_print_help() directly, return from function on "... type
<help|garbage>" instead of exit(2).

Signed-off-by: Serhey Popovych <serhe.popovych@...il.com>
---
 ip/link_gre.c  |   73 +++++++++++++++++++++++++------------------------------
 ip/link_gre6.c |   74 ++++++++++++++++++++++++++------------------------------
 2 files changed, 67 insertions(+), 80 deletions(-)

diff --git a/ip/link_gre.c b/ip/link_gre.c
index b2573a1..e972a10 100644
--- a/ip/link_gre.c
+++ b/ip/link_gre.c
@@ -23,34 +23,38 @@
 #include "ip_common.h"
 #include "tunnel.h"
 
-static void print_usage(FILE *f)
+static void gre_print_help(struct link_util *lu, int argc, char **argv, FILE *f)
 {
 	fprintf(f,
-		"Usage: ... { gre | gretap | erspan } [ remote ADDR ]\n"
-		"                            [ local ADDR ]\n"
-		"                            [ [i|o]seq ]\n"
-		"                            [ [i|o]key KEY ]\n"
-		"                            [ [i|o]csum ]\n"
-		"                            [ ttl TTL ]\n"
-		"                            [ tos TOS ]\n"
-		"                            [ [no]pmtudisc ]\n"
-		"                            [ [no]ignore-df ]\n"
-		"                            [ dev PHYS_DEV ]\n"
-		"                            [ noencap ]\n"
-		"                            [ encap { fou | gue | none } ]\n"
-		"                            [ encap-sport PORT ]\n"
-		"                            [ encap-dport PORT ]\n"
-		"                            [ [no]encap-csum ]\n"
-		"                            [ [no]encap-csum6 ]\n"
-		"                            [ [no]encap-remcsum ]\n"
-		"                            [ external ]\n"
-		"                            [ fwmark MARK ]\n"
-		"                            [ erspan_ver version ]\n"
-		"                            [ erspan IDX ]\n"
-		"                            [ erspan_dir { ingress | egress } ]\n"
-		"                            [ erspan_hwid hwid ]\n"
-		"                            [ external ]\n"
+		"Usage: ... %-9s [ remote ADDR ]\n",
+		lu->id
+	);
+	fprintf(f,
+		"                     [ local ADDR ]\n"
+		"                     [ [i|o]seq ]\n"
+		"                     [ [i|o]key KEY ]\n"
+		"                     [ [i|o]csum ]\n"
+		"                     [ ttl TTL ]\n"
+		"                     [ tos TOS ]\n"
+		"                     [ [no]pmtudisc ]\n"
+		"                     [ [no]ignore-df ]\n"
+		"                     [ dev PHYS_DEV ]\n"
+		"                     [ fwmark MARK ]\n"
+		"                     [ external ]\n"
+		"                     [ noencap ]\n"
+		"                     [ encap { fou | gue | none } ]\n"
+		"                     [ encap-sport PORT ]\n"
+		"                     [ encap-dport PORT ]\n"
+		"                     [ [no]encap-csum ]\n"
+		"                     [ [no]encap-csum6 ]\n"
+		"                     [ [no]encap-remcsum ]\n"
+		"                     [ erspan_ver version ]\n"
+		"                     [ erspan IDX ]\n"
+		"                     [ erspan_dir { ingress | egress } ]\n"
+		"                     [ erspan_hwid hwid ]\n"
 		"\n"
+	);
+	fprintf(f,
 		"Where: ADDR := { IP_ADDRESS | any }\n"
 		"       TOS  := { NUMBER | inherit }\n"
 		"       TTL  := { 1..255 | inherit }\n"
@@ -59,13 +63,6 @@ static void print_usage(FILE *f)
 	);
 }
 
-static void usage(void) __attribute__((noreturn));
-static void usage(void)
-{
-	print_usage(stderr);
-	exit(-1);
-}
-
 static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
 			 struct nlmsghdr *n)
 {
@@ -336,8 +333,10 @@ get_failed:
 			NEXT_ARG();
 			if (get_u16(&erspan_hwid, *argv, 0))
 				invarg("invalid erspan hwid\n", *argv);
-		} else
-			usage();
+		} else {
+			gre_print_help(lu, argc, argv, stderr);
+			return -1;
+		}
 		argc--; argv++;
 	}
 
@@ -517,12 +516,6 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 			IFLA_GRE_ENCAP_DPORT);
 }
 
-static void gre_print_help(struct link_util *lu, int argc, char **argv,
-			   FILE *f)
-{
-	print_usage(f);
-}
-
 struct link_util gre_link_util = {
 	.id = "gre",
 	.maxattr = IFLA_GRE_MAX,
diff --git a/ip/link_gre6.c b/ip/link_gre6.c
index 880b75d..1354f88 100644
--- a/ip/link_gre6.c
+++ b/ip/link_gre6.c
@@ -30,34 +30,39 @@
 
 #define DEFAULT_TNL_HOP_LIMIT	(64)
 
-static void print_usage(FILE *f)
+static void gre_print_help(struct link_util *lu, int argc, char **argv, FILE *f)
 {
 	fprintf(f,
-		"Usage: ... { ip6gre | ip6gretap | ip6erspan} [ remote ADDR ]\n"
-		"                                  [ local ADDR ]\n"
-		"                                  [ [i|o]seq ]\n"
-		"                                  [ [i|o]key KEY ]\n"
-		"                                  [ [i|o]csum ]\n"
-		"                                  [ hoplimit TTL ]\n"
-		"                                  [ encaplimit ELIM ]\n"
-		"                                  [ tclass TCLASS ]\n"
-		"                                  [ flowlabel FLOWLABEL ]\n"
-		"                                  [ dscp inherit ]\n"
-		"                                  [ fwmark MARK ]\n"
-		"                                  [ dev PHYS_DEV ]\n"
-		"                                  [ noencap ]\n"
-		"                                  [ encap { fou | gue | none } ]\n"
-		"                                  [ encap-sport PORT ]\n"
-		"                                  [ encap-dport PORT ]\n"
-		"                                  [ [no]encap-csum ]\n"
-		"                                  [ [no]encap-csum6 ]\n"
-		"                                  [ [no]encap-remcsum ]\n"
-		"                                  [ erspan_ver version ]\n"
-		"                                  [ erspan IDX ]\n"
-		"                                  [ erspan_dir { ingress | egress } ]\n"
-		"                                  [ erspan_hwid hwid ]\n"
-		"                                  [ external ]\n"
+		"Usage: ... %-9s [ remote ADDR ]\n",
+		lu->id
+	);
+	fprintf(f,
+		"                     [ local ADDR ]\n"
+		"                     [ [i|o]seq ]\n"
+		"                     [ [i|o]key KEY ]\n"
+		"                     [ [i|o]csum ]\n"
+		"                     [ hoplimit TTL ]\n"
+		"                     [ encaplimit ELIM ]\n"
+		"                     [ tclass TCLASS ]\n"
+		"                     [ flowlabel FLOWLABEL ]\n"
+		"                     [ dscp inherit ]\n"
+		"                     [ dev PHYS_DEV ]\n"
+		"                     [ fwmark MARK ]\n"
+		"                     [ external ]\n"
+		"                     [ noencap ]\n"
+		"                     [ encap { fou | gue | none } ]\n"
+		"                     [ encap-sport PORT ]\n"
+		"                     [ encap-dport PORT ]\n"
+		"                     [ [no]encap-csum ]\n"
+		"                     [ [no]encap-csum6 ]\n"
+		"                     [ [no]encap-remcsum ]\n"
+		"                     [ erspan_ver version ]\n"
+		"                     [ erspan IDX ]\n"
+		"                     [ erspan_dir { ingress | egress } ]\n"
+		"                     [ erspan_hwid hwid ]\n"
 		"\n"
+	);
+	fprintf(f,
 		"Where: ADDR      := IPV6_ADDRESS\n"
 		"       TTL       := { 0..255 } (default=%d)\n"
 		"       KEY       := { DOTTED_QUAD | NUMBER }\n"
@@ -69,13 +74,6 @@ static void print_usage(FILE *f)
 	);
 }
 
-static void usage(void) __attribute__((noreturn));
-static void usage(void)
-{
-	print_usage(stderr);
-	exit(-1);
-}
-
 static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
 			 struct nlmsghdr *n)
 {
@@ -384,8 +382,10 @@ get_failed:
 			NEXT_ARG();
 			if (get_u16(&erspan_hwid, *argv, 0))
 				invarg("invalid erspan hwid\n", *argv);
-		} else
-			usage();
+		} else {
+			gre_print_help(lu, argc, argv, stderr);
+			return -1;
+		}
 		argc--; argv++;
 	}
 
@@ -584,12 +584,6 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 			IFLA_GRE_ENCAP_DPORT);
 }
 
-static void gre_print_help(struct link_util *lu, int argc, char **argv,
-			   FILE *f)
-{
-	print_usage(f);
-}
-
 struct link_util ip6gre_link_util = {
 	.id = "ip6gre",
 	.maxattr = IFLA_GRE_MAX,
-- 
1.7.10.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ