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