From: Serhey Popovych <serhe.popovych@gmail.com>
To: netdev@vger.kernel.org
Subject: [PATCH iproute2-next v2 1/3] vti/vti6: Unify vti_print_help()
Date: Fri, 9 Feb 2018 08:45:00 +0200 [thread overview]
Message-ID: <1518158702-32604-2-git-send-email-serhe.popovych@gmail.com> (raw)
In-Reply-To: <1518158702-32604-1-git-send-email-serhe.popovych@gmail.com>
Reduce diff lines between vti and vti6 help printing code.
Use @struct link_util ->id field to print correct link help:
all callers now pass this data structure to vti_print_help().
Get rid of custom print_usage() and usage() functions and use
vti_print_help() directly, return from function on "... type
<help|garbage>" instead of exit(2).
Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
---
ip/link_vti.c | 42 ++++++++++++++++++------------------------
ip/link_vti6.c | 33 ++++++++++++++-------------------
2 files changed, 32 insertions(+), 43 deletions(-)
diff --git a/ip/link_vti.c b/ip/link_vti.c
index 49b87e9..f128e6b 100644
--- a/ip/link_vti.c
+++ b/ip/link_vti.c
@@ -23,29 +23,27 @@
#include "ip_common.h"
#include "tunnel.h"
-
-static void print_usage(FILE *f)
+static void vti_print_help(struct link_util *lu, int argc, char **argv, FILE *f)
{
fprintf(f,
- "Usage: ... vti [ remote ADDR ]\n"
- " [ local ADDR ]\n"
- " [ [i|o]key KEY ]\n"
- " [ dev PHYS_DEV ]\n"
- " [ fwmark MARK ]\n"
+ "Usage: ... %-4s [ remote ADDR ]\n",
+ lu->id
+ );
+ fprintf(f,
+ " [ local ADDR ]\n"
+ " [ [i|o]key KEY ]\n"
+ " [ dev PHYS_DEV ]\n"
+ " [ fwmark MARK ]\n"
"\n"
- "Where: ADDR := { IP_ADDRESS }\n"
+ );
+ fprintf(f,
+ "Where: ADDR := { IP%s_ADDRESS }\n"
" KEY := { DOTTED_QUAD | NUMBER }\n"
- " MARK := { 0x0..0xffffffff }\n"
+ " MARK := { 0x0..0xffffffff }\n",
+ ""
);
}
-static void usage(void) __attribute__((noreturn));
-static void usage(void)
-{
- print_usage(stderr);
- exit(-1);
-}
-
static int vti_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n)
{
@@ -147,8 +145,10 @@ get_failed:
NEXT_ARG();
if (get_u32(&fwmark, *argv, 0))
invarg("invalid fwmark\n", *argv);
- } else
- usage();
+ } else {
+ vti_print_help(lu, argc, argv, stderr);
+ return -1;
+ }
argc--; argv++;
}
@@ -208,12 +208,6 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
}
}
-static void vti_print_help(struct link_util *lu, int argc, char **argv,
- FILE *f)
-{
- print_usage(f);
-}
-
struct link_util vti_link_util = {
.id = "vti",
.maxattr = IFLA_VTI_MAX,
diff --git a/ip/link_vti6.c b/ip/link_vti6.c
index d1fbec5..18018bd 100644
--- a/ip/link_vti6.c
+++ b/ip/link_vti6.c
@@ -24,28 +24,27 @@
#include "ip_common.h"
#include "tunnel.h"
-static void print_usage(FILE *f)
+static void vti6_print_help(struct link_util *lu, int argc, char **argv, FILE *f)
{
fprintf(f,
- "Usage: ... vti6 [ remote ADDR ]\n"
+ "Usage: ... %-4s [ remote ADDR ]\n",
+ lu->id
+ );
+ fprintf(f,
" [ local ADDR ]\n"
" [ [i|o]key KEY ]\n"
" [ dev PHYS_DEV ]\n"
" [ fwmark MARK ]\n"
"\n"
- "Where: ADDR := { IPV6_ADDRESS }\n"
+ );
+ fprintf(f,
+ "Where: ADDR := { IP%s_ADDRESS }\n"
" KEY := { DOTTED_QUAD | NUMBER }\n"
- " MARK := { 0x0..0xffffffff }\n"
+ " MARK := { 0x0..0xffffffff }\n",
+ "V6"
);
}
-static void usage(void) __attribute__((noreturn));
-static void usage(void)
-{
- print_usage(stderr);
- exit(-1);
-}
-
static int vti6_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n)
{
@@ -153,8 +152,10 @@ get_failed:
NEXT_ARG();
if (get_u32(&fwmark, *argv, 0))
invarg("invalid fwmark\n", *argv);
- } else
- usage();
+ } else {
+ vti6_print_help(lu, argc, argv, stderr);
+ return -1;
+ }
argc--; argv++;
}
@@ -214,12 +215,6 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
}
}
-static void vti6_print_help(struct link_util *lu, int argc, char **argv,
- FILE *f)
-{
- print_usage(f);
-}
-
struct link_util vti6_link_util = {
.id = "vti6",
.maxattr = IFLA_VTI_MAX,
--
1.7.10.4
next prev parent reply other threads:[~2018-02-09 6:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-09 6:44 [PATCH iproute2-next v2 0/3] ip/tunnel: Unify tunnel help message print routines Serhey Popovych
2018-02-09 6:45 ` Serhey Popovych [this message]
2018-02-09 6:45 ` [PATCH iproute2-next v2 2/3] gre/gre6: Unify gre_print_help() Serhey Popovych
2018-02-09 6:45 ` [PATCH iproute2-next v2 3/3] iptnl/ip6tnl: Unify iptunnel_print_help() Serhey Popovych
2018-02-09 7:00 ` [PATCH iproute2-next v2 0/3] ip/tunnel: Unify tunnel help message print routines Serhey Popovych
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1518158702-32604-2-git-send-email-serhe.popovych@gmail.com \
--to=serhe.popovych@gmail.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).