iproute: fix a bug where "ip r flush table main" was rejected,
add "ip r flush cache" (however I'm unsure it is really valid syntax) Add a few comments and stop mixing params and params' keywords.
This commit is contained in:
parent
30297a5b83
commit
186c2b3d0e
@ -111,11 +111,11 @@ static int print_route(struct sockaddr_nl *who ATTRIBUTE_UNUSED,
|
|||||||
if (r->rtm_family == AF_INET6) {
|
if (r->rtm_family == AF_INET6) {
|
||||||
if (filter.tb) {
|
if (filter.tb) {
|
||||||
if (filter.tb < 0) {
|
if (filter.tb < 0) {
|
||||||
if (!(r->rtm_flags&RTM_F_CLONED)) {
|
if (!(r->rtm_flags & RTM_F_CLONED)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (r->rtm_flags&RTM_F_CLONED) {
|
if (r->rtm_flags & RTM_F_CLONED) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (filter.tb == RT_TABLE_LOCAL) {
|
if (filter.tb == RT_TABLE_LOCAL) {
|
||||||
@ -366,7 +366,7 @@ USE_FEATURE_IP_RULE(ARG_table,)
|
|||||||
unsigned mtu;
|
unsigned mtu;
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
if (index_in_strings(keywords, *argv) == PARM_lock) {
|
if (index_in_strings(keywords, *argv) == PARM_lock) {
|
||||||
mxlock |= (1<<RTAX_MTU);
|
mxlock |= (1 << RTAX_MTU);
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
}
|
}
|
||||||
if (get_unsigned(&mtu, *argv, 0))
|
if (get_unsigned(&mtu, *argv, 0))
|
||||||
@ -398,7 +398,7 @@ USE_FEATURE_IP_RULE(ARG_table,)
|
|||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
}
|
}
|
||||||
if ((**argv < '0' || **argv > '9')
|
if ((**argv < '0' || **argv > '9')
|
||||||
&& rtnl_rtntype_a2n(&type, *argv) == 0) {
|
&& rtnl_rtntype_a2n(&type, *argv) == 0) {
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
req.r.rtm_type = type;
|
req.r.rtm_type = type;
|
||||||
ok |= type_ok;
|
ok |= type_ok;
|
||||||
@ -518,19 +518,30 @@ static int iproute_list_or_flush(char **argv, int flush)
|
|||||||
char *id = NULL;
|
char *id = NULL;
|
||||||
char *od = NULL;
|
char *od = NULL;
|
||||||
static const char keywords[] ALIGN1 =
|
static const char keywords[] ALIGN1 =
|
||||||
"protocol\0""all\0""dev\0""oif\0""iif\0""via\0""table\0""cache\0" /*all*/
|
/* "ip route list/flush" parameters: */
|
||||||
"from\0""root\0""match\0""exact\0""to\0"/*root match exact*/;
|
"protocol\0" "dev\0" "oif\0" "iif\0"
|
||||||
|
"via\0" "table\0" "cache\0"
|
||||||
|
"from\0" "to\0"
|
||||||
|
/* and possible further keywords */
|
||||||
|
"all\0"
|
||||||
|
"root\0"
|
||||||
|
"match\0"
|
||||||
|
"exact\0"
|
||||||
|
"main\0"
|
||||||
|
;
|
||||||
enum {
|
enum {
|
||||||
ARG_proto, PARM_all,
|
KW_proto, KW_dev, KW_oif, KW_iif,
|
||||||
ARG_dev,
|
KW_via, KW_table, KW_cache,
|
||||||
ARG_oif,
|
KW_from, KW_to,
|
||||||
ARG_iif,
|
/* */
|
||||||
ARG_via,
|
KW_all,
|
||||||
ARG_table, PARM_cache, /*PARM_all,*/
|
KW_root,
|
||||||
ARG_from, PARM_root, PARM_match, PARM_exact,
|
KW_match,
|
||||||
ARG_to /*PARM_root, PARM_match, PARM_exact*/
|
KW_exact,
|
||||||
|
KW_main,
|
||||||
};
|
};
|
||||||
int arg, parm;
|
int arg, parm;
|
||||||
|
|
||||||
iproute_reset_filter();
|
iproute_reset_filter();
|
||||||
filter.tb = RT_TABLE_MAIN;
|
filter.tb = RT_TABLE_MAIN;
|
||||||
|
|
||||||
@ -539,64 +550,66 @@ static int iproute_list_or_flush(char **argv, int flush)
|
|||||||
|
|
||||||
while (*argv) {
|
while (*argv) {
|
||||||
arg = index_in_substrings(keywords, *argv);
|
arg = index_in_substrings(keywords, *argv);
|
||||||
if (arg == ARG_proto) {
|
if (arg == KW_proto) {
|
||||||
uint32_t prot = 0;
|
uint32_t prot = 0;
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
filter.protocolmask = -1;
|
filter.protocolmask = -1;
|
||||||
if (rtnl_rtprot_a2n(&prot, *argv)) {
|
if (rtnl_rtprot_a2n(&prot, *argv)) {
|
||||||
if (index_in_strings(keywords, *argv) != PARM_all)
|
if (index_in_strings(keywords, *argv) != KW_all)
|
||||||
invarg(*argv, "protocol");
|
invarg(*argv, "protocol");
|
||||||
prot = 0;
|
prot = 0;
|
||||||
filter.protocolmask = 0;
|
filter.protocolmask = 0;
|
||||||
}
|
}
|
||||||
filter.protocol = prot;
|
filter.protocol = prot;
|
||||||
} else if (arg == ARG_dev || arg == ARG_oif) {
|
} else if (arg == KW_dev || arg == KW_oif) {
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
od = *argv;
|
od = *argv;
|
||||||
} else if (arg == ARG_iif) {
|
} else if (arg == KW_iif) {
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
id = *argv;
|
id = *argv;
|
||||||
} else if (arg == ARG_via) {
|
} else if (arg == KW_via) {
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
get_prefix(&filter.rvia, *argv, do_ipv6);
|
get_prefix(&filter.rvia, *argv, do_ipv6);
|
||||||
} else if (arg == ARG_table) {
|
} else if (arg == KW_table) { /* table all/cache/main */
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
parm = index_in_substrings(keywords, *argv);
|
parm = index_in_substrings(keywords, *argv);
|
||||||
if (parm == PARM_cache)
|
if (parm == KW_cache)
|
||||||
filter.tb = -1;
|
filter.tb = -1;
|
||||||
else if (parm == PARM_all)
|
else if (parm == KW_all)
|
||||||
filter.tb = 0;
|
filter.tb = 0;
|
||||||
else
|
else if (parm != KW_main)
|
||||||
invarg(*argv, "table");
|
invarg(*argv, "table");
|
||||||
} else if (arg == ARG_from) {
|
} else if (arg == KW_cache) { // hmm is it valid - "ip r flush cache"?
|
||||||
|
filter.tb = -1;
|
||||||
|
} else if (arg == KW_from) {
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
parm = index_in_substrings(keywords, *argv);
|
parm = index_in_substrings(keywords, *argv);
|
||||||
if (parm == PARM_root) {
|
if (parm == KW_root) {
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
get_prefix(&filter.rsrc, *argv, do_ipv6);
|
get_prefix(&filter.rsrc, *argv, do_ipv6);
|
||||||
} else if (parm == PARM_match) {
|
} else if (parm == KW_match) {
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
get_prefix(&filter.msrc, *argv, do_ipv6);
|
get_prefix(&filter.msrc, *argv, do_ipv6);
|
||||||
} else {
|
} else {
|
||||||
if (parm == PARM_exact)
|
if (parm == KW_exact)
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
get_prefix(&filter.msrc, *argv, do_ipv6);
|
get_prefix(&filter.msrc, *argv, do_ipv6);
|
||||||
filter.rsrc = filter.msrc;
|
filter.rsrc = filter.msrc;
|
||||||
}
|
}
|
||||||
} else {
|
} else { /* "to" is the default parameter */
|
||||||
/* parm = arg; // would be more plausible, we reuse arg here */
|
if (arg == KW_to) {
|
||||||
if (arg == ARG_to) {
|
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
arg = index_in_substrings(keywords, *argv);
|
arg = index_in_substrings(keywords, *argv);
|
||||||
}
|
}
|
||||||
if (arg == PARM_root) {
|
/* parm = arg; - would be more plausible, but we reuse 'arg' here */
|
||||||
|
if (arg == KW_root) {
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
get_prefix(&filter.rdst, *argv, do_ipv6);
|
get_prefix(&filter.rdst, *argv, do_ipv6);
|
||||||
} else if (arg == PARM_match) {
|
} else if (arg == KW_match) {
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
get_prefix(&filter.mdst, *argv, do_ipv6);
|
get_prefix(&filter.mdst, *argv, do_ipv6);
|
||||||
} else {
|
} else { /* "to exact" is the default */
|
||||||
if (arg == PARM_exact)
|
if (arg == KW_exact)
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
get_prefix(&filter.mdst, *argv, do_ipv6);
|
get_prefix(&filter.mdst, *argv, do_ipv6);
|
||||||
filter.rdst = filter.mdst;
|
filter.rdst = filter.mdst;
|
||||||
@ -610,7 +623,6 @@ static int iproute_list_or_flush(char **argv, int flush)
|
|||||||
}
|
}
|
||||||
|
|
||||||
xrtnl_open(&rth);
|
xrtnl_open(&rth);
|
||||||
|
|
||||||
ll_init_map(&rth);
|
ll_init_map(&rth);
|
||||||
|
|
||||||
if (id || od) {
|
if (id || od) {
|
||||||
@ -631,7 +643,7 @@ static int iproute_list_or_flush(char **argv, int flush)
|
|||||||
if (flush) {
|
if (flush) {
|
||||||
char flushb[4096-512];
|
char flushb[4096-512];
|
||||||
|
|
||||||
if (filter.tb == -1) {
|
if (filter.tb == -1) { /* "flush table cache" */
|
||||||
if (do_ipv6 != AF_INET6)
|
if (do_ipv6 != AF_INET6)
|
||||||
iproute_flush_cache();
|
iproute_flush_cache();
|
||||||
if (do_ipv6 == AF_INET)
|
if (do_ipv6 == AF_INET)
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
//#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <netinet/ip.h>
|
#include <netinet/ip.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
Loading…
Reference in New Issue
Block a user