invarg("not inherit", *argv);
p->flags |= IP6_TNL_F_RCV_DSCP_COPY;
} else if (strcmp(*argv, "key") == 0) {
- unsigned uval;
NEXT_ARG();
p->i_flags |= GRE_KEY;
p->o_flags |= GRE_KEY;
- if (strchr(*argv, '.'))
- p->i_key = p->o_key = get_addr32(*argv);
- else {
- if (get_unsigned(&uval, *argv, 0) < 0) {
- fprintf(stderr, "invalid value of \"key\"\n");
- exit(-1);
- }
- p->i_key = p->o_key = htonl(uval);
- }
+ p->i_key = p->o_key = tnl_parse_key("key", *argv);
} else if (strcmp(*argv, "ikey") == 0) {
- unsigned uval;
NEXT_ARG();
p->i_flags |= GRE_KEY;
- if (strchr(*argv, '.'))
- p->i_key = get_addr32(*argv);
- else {
- if (get_unsigned(&uval, *argv, 0)<0) {
- fprintf(stderr, "invalid value of \"ikey\"\n");
- exit(-1);
- }
- p->i_key = htonl(uval);
- }
+ p->i_key = tnl_parse_key("ikey", *argv);
} else if (strcmp(*argv, "okey") == 0) {
- unsigned uval;
NEXT_ARG();
p->o_flags |= GRE_KEY;
- if (strchr(*argv, '.'))
- p->o_key = get_addr32(*argv);
- else {
- if (get_unsigned(&uval, *argv, 0)<0) {
- fprintf(stderr, "invalid value of \"okey\"\n");
- exit(-1);
- }
- p->o_key = htonl(uval);
- }
+ p->o_key = tnl_parse_key("okey", *argv);
} else if (strcmp(*argv, "seq") == 0) {
p->i_flags |= GRE_SEQ;
p->o_flags |= GRE_SEQ;
exit(-1);
}
} else if (strcmp(*argv, "key") == 0) {
- unsigned uval;
NEXT_ARG();
p->i_flags |= GRE_KEY;
p->o_flags |= GRE_KEY;
- if (strchr(*argv, '.'))
- p->i_key = p->o_key = get_addr32(*argv);
- else {
- if (get_unsigned(&uval, *argv, 0)<0) {
- fprintf(stderr, "invalid value for \"key\": \"%s\"; it should be an unsigned integer\n", *argv);
- exit(-1);
- }
- p->i_key = p->o_key = htonl(uval);
- }
+ p->i_key = p->o_key = tnl_parse_key("key", *argv);
} else if (strcmp(*argv, "ikey") == 0) {
- unsigned uval;
NEXT_ARG();
p->i_flags |= GRE_KEY;
- if (strchr(*argv, '.'))
- p->i_key = get_addr32(*argv);
- else {
- if (get_unsigned(&uval, *argv, 0)<0) {
- fprintf(stderr, "invalid value for \"ikey\": \"%s\"; it should be an unsigned integer\n", *argv);
- exit(-1);
- }
- p->i_key = htonl(uval);
- }
+ p->i_key = tnl_parse_key("ikey", *argv);
} else if (strcmp(*argv, "okey") == 0) {
- unsigned uval;
NEXT_ARG();
p->o_flags |= GRE_KEY;
- if (strchr(*argv, '.'))
- p->o_key = get_addr32(*argv);
- else {
- if (get_unsigned(&uval, *argv, 0)<0) {
- fprintf(stderr, "invalid value for \"okey\": \"%s\"; it should be an unsigned integer\n", *argv);
- exit(-1);
- }
- p->o_key = htonl(uval);
- }
+ p->o_key = tnl_parse_key("okey", *argv);
} else if (strcmp(*argv, "seq") == 0) {
p->i_flags |= GRE_SEQ;
p->o_flags |= GRE_SEQ;
{
return tnl_gen_ioctl(SIOCGET6RD, name, p, EINVAL);
}
+
+__be32 tnl_parse_key(const char *name, const char *key)
+{
+ unsigned uval;
+
+ if (strchr(key, '.'))
+ return get_addr32(key);
+
+ if (get_unsigned(&uval, key, 0) < 0) {
+ fprintf(stderr, "invalid value for \"%s\": \"%s\";", name, key);
+ fprintf(stderr, " it should be an unsigned integer\n");
+ exit(-1);
+ }
+ return htonl(uval);
+}
int tnl_prl_ioctl(int cmd, const char *name, void *p);
int tnl_6rd_ioctl(int cmd, const char *name, void *p);
int tnl_ioctl_get_6rd(const char *name, void *p);
+__be32 tnl_parse_key(const char *name, const char *key);
#endif