iptnl/ip6tnl: Unify iptunnel_print_help()
Reduce diff lines between iptnl and ip6tnl help printing code. Use @struct link_util ->id field to print correct link help: all callers now pass this data structure to iptunnel_print_help(). Get rid of custom print_usage() and usage() functions and use iptunnel_print_help() directly, return from function on "... type <help|garbage>" instead of exit(2). Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
parent
ae91205c4d
commit
06e3975f4c
|
|
@ -29,20 +29,26 @@
|
||||||
|
|
||||||
#define DEFAULT_TNL_HOP_LIMIT (64)
|
#define DEFAULT_TNL_HOP_LIMIT (64)
|
||||||
|
|
||||||
static void print_usage(FILE *f)
|
static void ip6tunnel_print_help(struct link_util *lu, int argc, char **argv,
|
||||||
|
FILE *f)
|
||||||
{
|
{
|
||||||
|
const char *mode;
|
||||||
|
|
||||||
|
fprintf(f,
|
||||||
|
"Usage: ... %-6s [ remote ADDR ]\n",
|
||||||
|
lu->id
|
||||||
|
);
|
||||||
fprintf(f,
|
fprintf(f,
|
||||||
"Usage: ... ip6tnl [ mode { ip6ip6 | ipip6 | any } ]\n"
|
|
||||||
" [ remote ADDR ]\n"
|
|
||||||
" [ local ADDR ]\n"
|
" [ local ADDR ]\n"
|
||||||
" [ dev PHYS_DEV ]\n"
|
|
||||||
" [ encaplimit ELIM ]\n"
|
" [ encaplimit ELIM ]\n"
|
||||||
" [ hoplimit HLIM ]\n"
|
" [ hoplimit HLIM ]\n"
|
||||||
" [ tclass TCLASS ]\n"
|
" [ tclass TCLASS ]\n"
|
||||||
" [ flowlabel FLOWLABEL ]\n"
|
" [ flowlabel FLOWLABEL ]\n"
|
||||||
" [ dscp inherit ]\n"
|
" [ dscp inherit ]\n"
|
||||||
" [ fwmark MARK ]\n"
|
|
||||||
" [ [no]allow-localremote ]\n"
|
" [ [no]allow-localremote ]\n"
|
||||||
|
" [ dev PHYS_DEV ]\n"
|
||||||
|
" [ fwmark MARK ]\n"
|
||||||
|
" [ external ]\n"
|
||||||
" [ noencap ]\n"
|
" [ noencap ]\n"
|
||||||
" [ encap { fou | gue | none } ]\n"
|
" [ encap { fou | gue | none } ]\n"
|
||||||
" [ encap-sport PORT ]\n"
|
" [ encap-sport PORT ]\n"
|
||||||
|
|
@ -50,8 +56,14 @@ static void print_usage(FILE *f)
|
||||||
" [ [no]encap-csum ]\n"
|
" [ [no]encap-csum ]\n"
|
||||||
" [ [no]encap-csum6 ]\n"
|
" [ [no]encap-csum6 ]\n"
|
||||||
" [ [no]encap-remcsum ]\n"
|
" [ [no]encap-remcsum ]\n"
|
||||||
" [ external ]\n"
|
);
|
||||||
"\n"
|
mode = "{ ip6ip6 | ipip6 | any }";
|
||||||
|
fprintf(f,
|
||||||
|
" [ mode %s ]\n"
|
||||||
|
"\n",
|
||||||
|
mode
|
||||||
|
);
|
||||||
|
fprintf(f,
|
||||||
"Where: ADDR := IPV6_ADDRESS\n"
|
"Where: ADDR := IPV6_ADDRESS\n"
|
||||||
" ELIM := { none | 0..255 }(default=%d)\n"
|
" ELIM := { none | 0..255 }(default=%d)\n"
|
||||||
" HLIM := 0..255 (default=%d)\n"
|
" HLIM := 0..255 (default=%d)\n"
|
||||||
|
|
@ -62,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 ip6tunnel_parse_opt(struct link_util *lu, int argc, char **argv,
|
static int ip6tunnel_parse_opt(struct link_util *lu, int argc, char **argv,
|
||||||
struct nlmsghdr *n)
|
struct nlmsghdr *n)
|
||||||
{
|
{
|
||||||
|
|
@ -304,8 +309,10 @@ get_failed:
|
||||||
encapflags &= ~TUNNEL_ENCAP_FLAG_REMCSUM;
|
encapflags &= ~TUNNEL_ENCAP_FLAG_REMCSUM;
|
||||||
} else if (strcmp(*argv, "external") == 0) {
|
} else if (strcmp(*argv, "external") == 0) {
|
||||||
metadata = 1;
|
metadata = 1;
|
||||||
} else
|
} else {
|
||||||
usage();
|
ip6tunnel_print_help(lu, argc, argv, stderr);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
argc--, argv++;
|
argc--, argv++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -456,12 +463,6 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
|
||||||
IFLA_IPTUN_ENCAP_DPORT);
|
IFLA_IPTUN_ENCAP_DPORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ip6tunnel_print_help(struct link_util *lu, int argc, char **argv,
|
|
||||||
FILE *f)
|
|
||||||
{
|
|
||||||
print_usage(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct link_util ip6tnl_link_util = {
|
struct link_util ip6tnl_link_util = {
|
||||||
.id = "ip6tnl",
|
.id = "ip6tnl",
|
||||||
.maxattr = IFLA_IPTUN_MAX,
|
.maxattr = IFLA_IPTUN_MAX,
|
||||||
|
|
|
||||||
|
|
@ -24,49 +24,51 @@
|
||||||
#include "ip_common.h"
|
#include "ip_common.h"
|
||||||
#include "tunnel.h"
|
#include "tunnel.h"
|
||||||
|
|
||||||
static void print_usage(FILE *f, int sit)
|
static void iptunnel_print_help(struct link_util *lu, int argc, char **argv,
|
||||||
|
FILE *f)
|
||||||
{
|
{
|
||||||
const char *type = sit ? "sit " : "ipip";
|
const char *mode;
|
||||||
|
|
||||||
fprintf(f,
|
fprintf(f,
|
||||||
"Usage: ... %s [ remote ADDR ]\n"
|
"Usage: ... %-6s [ remote ADDR ]\n",
|
||||||
" [ local ADDR ]\n"
|
lu->id
|
||||||
" [ ttl TTL ]\n"
|
|
||||||
" [ tos TOS ]\n"
|
|
||||||
" [ [no]pmtudisc ]\n"
|
|
||||||
" [ dev PHYS_DEV ]\n"
|
|
||||||
" [ 6rd-prefix ADDR ]\n"
|
|
||||||
" [ 6rd-relay_prefix ADDR ]\n"
|
|
||||||
" [ 6rd-reset ]\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",
|
|
||||||
type
|
|
||||||
);
|
);
|
||||||
if (sit) {
|
fprintf(f,
|
||||||
fprintf(f, " [ mode { ip6ip | ipip | mplsip | any } ]\n");
|
" [ local ADDR ]\n"
|
||||||
fprintf(f, " [ isatap ]\n");
|
" [ ttl TTL ]\n"
|
||||||
|
" [ tos TOS ]\n"
|
||||||
|
" [ [no]pmtudisc ]\n"
|
||||||
|
" [ 6rd-prefix ADDR ]\n"
|
||||||
|
" [ 6rd-relay_prefix ADDR ]\n"
|
||||||
|
" [ 6rd-reset ]\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"
|
||||||
|
);
|
||||||
|
if (strcmp(lu->id, "sit") == 0) {
|
||||||
|
mode = "{ ip6ip | ipip | mplsip | any } ]\n"
|
||||||
|
" [ isatap";
|
||||||
} else {
|
} else {
|
||||||
fprintf(f, " [ mode { ipip | mplsip | any } ]\n");
|
mode = "{ ipip | mplsip | any }";
|
||||||
}
|
}
|
||||||
fprintf(f, " [ external ]\n");
|
fprintf(f,
|
||||||
fprintf(f, " [ fwmark MARK ]\n");
|
" [ mode %s ]\n"
|
||||||
fprintf(f, "\n");
|
"\n",
|
||||||
fprintf(f, "Where: ADDR := { IP_ADDRESS | any }\n");
|
mode
|
||||||
fprintf(f, " TOS := { NUMBER | inherit }\n");
|
);
|
||||||
fprintf(f, " TTL := { 1..255 | inherit }\n");
|
fprintf(f,
|
||||||
fprintf(f, " MARK := { 0x0..0xffffffff }\n");
|
"Where: ADDR := { IP_ADDRESS | any }\n"
|
||||||
}
|
" TOS := { NUMBER | inherit }\n"
|
||||||
|
" TTL := { 1..255 | inherit }\n"
|
||||||
static void usage(int sit) __attribute__((noreturn));
|
" MARK := { 0x0..0xffffffff }\n"
|
||||||
static void usage(int sit)
|
);
|
||||||
{
|
|
||||||
print_usage(stderr, sit);
|
|
||||||
exit(-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int iptunnel_parse_opt(struct link_util *lu, int argc, char **argv,
|
static int iptunnel_parse_opt(struct link_util *lu, int argc, char **argv,
|
||||||
|
|
@ -313,8 +315,10 @@ get_failed:
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
if (get_u32(&fwmark, *argv, 0))
|
if (get_u32(&fwmark, *argv, 0))
|
||||||
invarg("invalid fwmark\n", *argv);
|
invarg("invalid fwmark\n", *argv);
|
||||||
} else
|
} else {
|
||||||
usage(strcmp(lu->id, "sit") == 0);
|
iptunnel_print_help(lu, argc, argv, stderr);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
argc--, argv++;
|
argc--, argv++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -483,12 +487,6 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
|
||||||
IFLA_IPTUN_ENCAP_DPORT);
|
IFLA_IPTUN_ENCAP_DPORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void iptunnel_print_help(struct link_util *lu, int argc, char **argv,
|
|
||||||
FILE *f)
|
|
||||||
{
|
|
||||||
print_usage(f, strcmp(lu->id, "sit") == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct link_util ipip_link_util = {
|
struct link_util ipip_link_util = {
|
||||||
.id = "ipip",
|
.id = "ipip",
|
||||||
.maxattr = IFLA_IPTUN_MAX,
|
.maxattr = IFLA_IPTUN_MAX,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue