Commit a96a5d94 authored by Stephen Hemminger's avatar Stephen Hemminger

iptunnel: cleanup code

Make iptunnel pass checkpatch (mostly).
parent cc9c1dfa
...@@ -50,7 +50,8 @@ static void usage(void) ...@@ -50,7 +50,8 @@ static void usage(void)
static void set_tunnel_proto(struct ip_tunnel_parm *p, int proto) static void set_tunnel_proto(struct ip_tunnel_parm *p, int proto)
{ {
if (p->iph.protocol && p->iph.protocol != proto) { if (p->iph.protocol && p->iph.protocol != proto) {
fprintf(stderr,"You managed to ask for more than one tunnel mode.\n"); fprintf(stderr,
"You managed to ask for more than one tunnel mode.\n");
exit(-1); exit(-1);
} }
p->iph.protocol = proto; p->iph.protocol = proto;
...@@ -91,7 +92,8 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p) ...@@ -91,7 +92,8 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
set_tunnel_proto(p, IPPROTO_IPIP); set_tunnel_proto(p, IPPROTO_IPIP);
p->i_flags |= VTI_ISVTI; p->i_flags |= VTI_ISVTI;
} else { } else {
fprintf(stderr,"Unknown tunnel mode \"%s\"\n", *argv); fprintf(stderr,
"Unknown tunnel mode \"%s\"\n", *argv);
exit(-1); exit(-1);
} }
} else if (strcmp(*argv, "key") == 0) { } else if (strcmp(*argv, "key") == 0) {
...@@ -144,6 +146,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p) ...@@ -144,6 +146,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
strcmp(*argv, "hoplimit") == 0 || strcmp(*argv, "hoplimit") == 0 ||
strcmp(*argv, "hlim") == 0) { strcmp(*argv, "hlim") == 0) {
__u8 uval; __u8 uval;
NEXT_ARG(); NEXT_ARG();
if (strcmp(*argv, "inherit") != 0) { if (strcmp(*argv, "inherit") != 0) {
if (get_u8(&uval, *argv, 0)) if (get_u8(&uval, *argv, 0))
...@@ -155,6 +158,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p) ...@@ -155,6 +158,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
matches(*argv, "dsfield") == 0) { matches(*argv, "dsfield") == 0) {
char *dsfield; char *dsfield;
__u32 uval; __u32 uval;
NEXT_ARG(); NEXT_ARG();
dsfield = *argv; dsfield = *argv;
strsep(&dsfield, "/"); strsep(&dsfield, "/");
...@@ -169,15 +173,17 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p) ...@@ -169,15 +173,17 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
p->iph.tos |= uval; p->iph.tos |= uval;
} }
} else { } else {
if (strcmp(*argv, "name") == 0) { if (strcmp(*argv, "name") == 0)
NEXT_ARG(); NEXT_ARG();
} else if (matches(*argv, "help") == 0) else if (matches(*argv, "help") == 0)
usage(); usage();
if (p->name[0]) if (p->name[0])
duparg2("name", *argv); duparg2("name", *argv);
strncpy(p->name, *argv, IFNAMSIZ - 1); strncpy(p->name, *argv, IFNAMSIZ - 1);
if (cmd == SIOCCHGTUNNEL && count == 0) { if (cmd == SIOCCHGTUNNEL && count == 0) {
struct ip_tunnel_parm old_p; struct ip_tunnel_parm old_p;
memset(&old_p, 0, sizeof(old_p)); memset(&old_p, 0, sizeof(old_p));
if (tnl_get_ioctl(*argv, &old_p)) if (tnl_get_ioctl(*argv, &old_p))
return -1; return -1;
...@@ -268,8 +274,10 @@ static int do_add(int cmd, int argc, char **argv) ...@@ -268,8 +274,10 @@ static int do_add(int cmd, int argc, char **argv)
return -1; return -1;
} }
if (!(basedev = tnl_defname(&p))) { basedev = tnl_defname(&p);
fprintf(stderr, "cannot determine tunnel mode (ipip, gre, vti or sit)\n"); if (!basedev) {
fprintf(stderr,
"cannot determine tunnel mode (ipip, gre, vti or sit)\n");
return -1; return -1;
} }
...@@ -312,8 +320,7 @@ static void print_tunnel(struct ip_tunnel_parm *p) ...@@ -312,8 +320,7 @@ static void print_tunnel(struct ip_tunnel_parm *p)
prl[0].addr = htonl(INADDR_ANY); prl[0].addr = htonl(INADDR_ANY);
if (!tnl_prl_ioctl(SIOCGETPRL, p->name, prl)) if (!tnl_prl_ioctl(SIOCGETPRL, p->name, prl))
for (i = 1; i < sizeof(prl) / sizeof(prl[0]); i++) for (i = 1; i < ARRAY_SIZE(prl); i++) {
{
if (prl[i].addr != htonl(INADDR_ANY)) { if (prl[i].addr != htonl(INADDR_ANY)) {
printf(" %s %s ", printf(" %s %s ",
(prl[i].flags & PRL_DEFAULT) ? "pdr" : "pr", (prl[i].flags & PRL_DEFAULT) ? "pdr" : "pr",
...@@ -324,6 +331,7 @@ static void print_tunnel(struct ip_tunnel_parm *p) ...@@ -324,6 +331,7 @@ static void print_tunnel(struct ip_tunnel_parm *p)
if (p->link) { if (p->link) {
const char *n = ll_index_to_name(p->link); const char *n = ll_index_to_name(p->link);
if (n) if (n)
printf(" dev %s", n); printf(" dev %s", n);
} }
...@@ -381,6 +389,7 @@ static int do_tunnels_list(struct ip_tunnel_parm *p) ...@@ -381,6 +389,7 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
char buf[512]; char buf[512];
int err = -1; int err = -1;
FILE *fp = fopen("/proc/net/dev", "r"); FILE *fp = fopen("/proc/net/dev", "r");
if (fp == NULL) { if (fp == NULL) {
perror("fopen"); perror("fopen");
return -1; return -1;
...@@ -404,7 +413,8 @@ static int do_tunnels_list(struct ip_tunnel_parm *p) ...@@ -404,7 +413,8 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
char *ptr; char *ptr;
buf[sizeof(buf) - 1] = 0; buf[sizeof(buf) - 1] = 0;
if ((ptr = strchr(buf, ':')) == NULL || ptr = strchr(buf, ':');
if (ptr == NULL ||
(*ptr++ = 0, sscanf(buf, "%s", name) != 1)) { (*ptr++ = 0, sscanf(buf, "%s", name) != 1)) {
fprintf(stderr, "Wrong format for /proc/net/dev. Giving up.\n"); fprintf(stderr, "Wrong format for /proc/net/dev. Giving up.\n");
goto end; goto end;
...@@ -463,7 +473,8 @@ static int do_show(int argc, char **argv) ...@@ -463,7 +473,8 @@ static int do_show(int argc, char **argv)
if (parse_args(argc, argv, SIOCGETTUNNEL, &p) < 0) if (parse_args(argc, argv, SIOCGETTUNNEL, &p) < 0)
return -1; return -1;
if (!(basedev = tnl_defname(&p))) basedev = tnl_defname(&p);
if (!basedev)
return do_tunnels_list(&p); return do_tunnels_list(&p);
if (tnl_get_ioctl(p.name[0] ? p.name : basedev, &p)) if (tnl_get_ioctl(p.name[0] ? p.name : basedev, &p))
...@@ -507,11 +518,13 @@ static int do_prl(int argc, char **argv) ...@@ -507,11 +518,13 @@ static int do_prl(int argc, char **argv)
strncpy(medium, *argv, IFNAMSIZ-1); strncpy(medium, *argv, IFNAMSIZ-1);
devname++; devname++;
} else { } else {
fprintf(stderr,"Invalid PRL parameter \"%s\"\n", *argv); fprintf(stderr,
"Invalid PRL parameter \"%s\"\n", *argv);
exit(-1); exit(-1);
} }
if (count > 1) { if (count > 1) {
fprintf(stderr,"One PRL entry at a time\n"); fprintf(stderr,
"One PRL entry at a time\n");
exit(-1); exit(-1);
} }
argc--; argv++; argc--; argv++;
...@@ -557,7 +570,8 @@ static int do_6rd(int argc, char **argv) ...@@ -557,7 +570,8 @@ static int do_6rd(int argc, char **argv)
strncpy(medium, *argv, IFNAMSIZ-1); strncpy(medium, *argv, IFNAMSIZ-1);
devname++; devname++;
} else { } else {
fprintf(stderr,"Invalid 6RD parameter \"%s\"\n", *argv); fprintf(stderr,
"Invalid 6RD parameter \"%s\"\n", *argv);
exit(-1); exit(-1);
} }
argc--; argv++; argc--; argv++;
...@@ -570,8 +584,9 @@ static int do_6rd(int argc, char **argv) ...@@ -570,8 +584,9 @@ static int do_6rd(int argc, char **argv)
return tnl_6rd_ioctl(cmd, medium, &ip6rd); return tnl_6rd_ioctl(cmd, medium, &ip6rd);
} }
static int tunnel_mode_is_ipv6(char *tunnel_mode) { static int tunnel_mode_is_ipv6(char *tunnel_mode)
static const char *ipv6_modes[] = { {
static const char * const ipv6_modes[] = {
"ipv6/ipv6", "ip6ip6", "ipv6/ipv6", "ip6ip6",
"vti6", "vti6",
"ip/ipv6", "ipv4/ipv6", "ipip6", "ip4ip6", "ip/ipv6", "ipv4/ipv6", "ipip6", "ip4ip6",
...@@ -580,7 +595,7 @@ static int tunnel_mode_is_ipv6(char *tunnel_mode) { ...@@ -580,7 +595,7 @@ static int tunnel_mode_is_ipv6(char *tunnel_mode) {
}; };
int i; int i;
for (i = 0; i < sizeof(ipv6_modes) / sizeof(ipv6_modes[0]); i++) { for (i = 0; i < ARRAY_SIZE(ipv6_modes); i++) {
if (strcmp(ipv6_modes[i], tunnel_mode) == 0) if (strcmp(ipv6_modes[i], tunnel_mode) == 0)
return 1; return 1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment