Commit 9fce67dd authored by Stephen Hemminger's avatar Stephen Hemminger

Remove goto chain

The selector logic is clearer with if / else if
parent e48f73d6
......@@ -47,7 +47,7 @@ static void explain(void)
#define usage() return(-1)
int get_u32_handle(__u32 *handle, char *str)
int get_u32_handle(__u32 *handle, const char *str)
{
__u32 htid=0, hash=0, nodeid=0;
char *tmp = strchr(str, ':');
......@@ -417,77 +417,49 @@ static int parse_ip(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
if (strcmp(*argv, "src") == 0) {
NEXT_ARG();
res = parse_ip_addr(&argc, &argv, sel, 12);
goto done;
}
if (strcmp(*argv, "dst") == 0) {
} else if (strcmp(*argv, "dst") == 0) {
NEXT_ARG();
res = parse_ip_addr(&argc, &argv, sel, 16);
goto done;
}
if (strcmp(*argv, "tos") == 0 ||
} else if (strcmp(*argv, "tos") == 0 ||
matches(*argv, "dsfield") == 0) {
NEXT_ARG();
res = parse_u8(&argc, &argv, sel, 1, 0);
goto done;
}
if (strcmp(*argv, "ihl") == 0) {
} else if (strcmp(*argv, "ihl") == 0) {
NEXT_ARG();
res = parse_u8(&argc, &argv, sel, 0, 0);
goto done;
}
if (strcmp(*argv, "protocol") == 0) {
} else if (strcmp(*argv, "protocol") == 0) {
NEXT_ARG();
res = parse_u8(&argc, &argv, sel, 9, 0);
goto done;
}
if (matches(*argv, "precedence") == 0) {
} else if (matches(*argv, "precedence") == 0) {
NEXT_ARG();
res = parse_u8(&argc, &argv, sel, 1, 0);
goto done;
}
if (strcmp(*argv, "nofrag") == 0) {
} else if (strcmp(*argv, "nofrag") == 0) {
argc--; argv++;
res = pack_key16(sel, 0, 0x3FFF, 6, 0);
goto done;
}
if (strcmp(*argv, "firstfrag") == 0) {
} else if (strcmp(*argv, "firstfrag") == 0) {
argc--; argv++;
res = pack_key16(sel, 0, 0x1FFF, 6, 0);
goto done;
}
if (strcmp(*argv, "df") == 0) {
} else if (strcmp(*argv, "df") == 0) {
argc--; argv++;
res = pack_key16(sel, 0x4000, 0x4000, 6, 0);
goto done;
}
if (strcmp(*argv, "mf") == 0) {
} else if (strcmp(*argv, "mf") == 0) {
argc--; argv++;
res = pack_key16(sel, 0x2000, 0x2000, 6, 0);
goto done;
}
if (strcmp(*argv, "dport") == 0) {
} else if (strcmp(*argv, "dport") == 0) {
NEXT_ARG();
res = parse_u16(&argc, &argv, sel, 22, 0);
goto done;
}
if (strcmp(*argv, "sport") == 0) {
} else if (strcmp(*argv, "sport") == 0) {
NEXT_ARG();
res = parse_u16(&argc, &argv, sel, 20, 0);
goto done;
}
if (strcmp(*argv, "icmp_type") == 0) {
} else if (strcmp(*argv, "icmp_type") == 0) {
NEXT_ARG();
res = parse_u8(&argc, &argv, sel, 20, 0);
goto done;
}
if (strcmp(*argv, "icmp_code") == 0) {
} else if (strcmp(*argv, "icmp_code") == 0) {
NEXT_ARG();
res = parse_u8(&argc, &argv, sel, 20, 1);
goto done;
}
return -1;
} else
return -1;
done:
*argc_p = argc;
*argv_p = argv;
return res;
......@@ -505,51 +477,33 @@ static int parse_ip6(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
if (strcmp(*argv, "src") == 0) {
NEXT_ARG();
res = parse_ip6_addr(&argc, &argv, sel, 8);
goto done;
}
if (strcmp(*argv, "dst") == 0) {
} else if (strcmp(*argv, "dst") == 0) {
NEXT_ARG();
res = parse_ip6_addr(&argc, &argv, sel, 24);
goto done;
}
if (strcmp(*argv, "priority") == 0) {
} else if (strcmp(*argv, "priority") == 0) {
NEXT_ARG();
res = parse_u8(&argc, &argv, sel, 4, 0);
goto done;
}
if (strcmp(*argv, "protocol") == 0) {
} else if (strcmp(*argv, "protocol") == 0) {
NEXT_ARG();
res = parse_u8(&argc, &argv, sel, 6, 0);
goto done;
}
if (strcmp(*argv, "flowlabel") == 0) {
} else if (strcmp(*argv, "flowlabel") == 0) {
NEXT_ARG();
res = parse_u32(&argc, &argv, sel, 0, 0);
goto done;
}
if (strcmp(*argv, "dport") == 0) {
} else if (strcmp(*argv, "dport") == 0) {
NEXT_ARG();
res = parse_u16(&argc, &argv, sel, 42, 0);
goto done;
}
if (strcmp(*argv, "sport") == 0) {
} else if (strcmp(*argv, "sport") == 0) {
NEXT_ARG();
res = parse_u16(&argc, &argv, sel, 40, 0);
goto done;
}
if (strcmp(*argv, "icmp_type") == 0) {
} else if (strcmp(*argv, "icmp_type") == 0) {
NEXT_ARG();
res = parse_u8(&argc, &argv, sel, 40, 0);
goto done;
}
if (strcmp(*argv, "icmp_code") == 0) {
} else if (strcmp(*argv, "icmp_code") == 0) {
NEXT_ARG();
res = parse_u8(&argc, &argv, sel, 41, 1);
goto done;
}
return -1;
} else
return -1;
done:
*argc_p = argc;
*argv_p = argv;
return res;
......@@ -568,16 +522,12 @@ static int parse_udp(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
if (strcmp(*argv, "src") == 0) {
NEXT_ARG();
res = parse_u16(&argc, &argv, sel, 0, -1);
goto done;
}
if (strcmp(*argv, "dst") == 0) {
} else if (strcmp(*argv, "dst") == 0) {
NEXT_ARG();
res = parse_u16(&argc, &argv, sel, 2, -1);
goto done;
}
return -1;
} else
return -1;
done:
*argc_p = argc;
*argv_p = argv;
return res;
......@@ -596,16 +546,12 @@ static int parse_icmp(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
if (strcmp(*argv, "type") == 0) {
NEXT_ARG();
res = parse_u8(&argc, &argv, sel, 0, -1);
goto done;
}
if (strcmp(*argv, "code") == 0) {
} else if (strcmp(*argv, "code") == 0) {
NEXT_ARG();
res = parse_u8(&argc, &argv, sel, 1, -1);
goto done;
}
return -1;
} else
return -1;
done:
*argc_p = argc;
*argv_p = argv;
return res;
......@@ -659,52 +605,33 @@ static int parse_selector(int *argc_p, char ***argv_p,
if (matches(*argv, "u32") == 0) {
NEXT_ARG();
res = parse_u32(&argc, &argv, sel, 0, 0);
goto done;
}
if (matches(*argv, "u16") == 0) {
} else if (matches(*argv, "u16") == 0) {
NEXT_ARG();
res = parse_u16(&argc, &argv, sel, 0, 0);
goto done;
}
if (matches(*argv, "u8") == 0) {
} else if (matches(*argv, "u8") == 0) {
NEXT_ARG();
res = parse_u8(&argc, &argv, sel, 0, 0);
goto done;
}
if (matches(*argv, "ip") == 0) {
} else if (matches(*argv, "ip") == 0) {
NEXT_ARG();
res = parse_ip(&argc, &argv, sel);
goto done;
}
if (matches(*argv, "ip6") == 0) {
} else if (matches(*argv, "ip6") == 0) {
NEXT_ARG();
res = parse_ip6(&argc, &argv, sel);
goto done;
}
if (matches(*argv, "udp") == 0) {
} else if (matches(*argv, "udp") == 0) {
NEXT_ARG();
res = parse_udp(&argc, &argv, sel);
goto done;
}
if (matches(*argv, "tcp") == 0) {
} else if (matches(*argv, "tcp") == 0) {
NEXT_ARG();
res = parse_tcp(&argc, &argv, sel);
goto done;
}
if (matches(*argv, "icmp") == 0) {
} else if (matches(*argv, "icmp") == 0) {
NEXT_ARG();
res = parse_icmp(&argc, &argv, sel);
goto done;
}
if (matches(*argv, "mark") == 0) {
} else if (matches(*argv, "mark") == 0) {
NEXT_ARG();
res = parse_mark(&argc, &argv, n);
goto done;
}
return -1;
} else
return -1;
done:
*argc_p = argc;
*argv_p = argv;
return res;
......
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