iproute: make printing IPv4 cache flags a function
More refactoring prior to JSON support. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
parent
8cfc2d4739
commit
daf30f6fde
65
ip/iproute.c
65
ip/iproute.c
|
|
@ -382,6 +382,43 @@ static void print_rt_pref(FILE *fp, unsigned int pref)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void print_cache_flags(FILE *fp, __u32 flags)
|
||||||
|
{
|
||||||
|
flags &= ~0xFFFF;
|
||||||
|
|
||||||
|
fprintf(fp, "%s cache ", _SL_);
|
||||||
|
|
||||||
|
if (flags == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
putc('<', fp);
|
||||||
|
|
||||||
|
#define PRTFL(fl, flname) \
|
||||||
|
if (flags & RTCF_##fl) { \
|
||||||
|
flags &= ~RTCF_##fl; \
|
||||||
|
fprintf(fp, "%s%s", flname, flags ? "," : "> "); \
|
||||||
|
}
|
||||||
|
|
||||||
|
PRTFL(LOCAL, "local");
|
||||||
|
PRTFL(REJECT, "reject");
|
||||||
|
PRTFL(MULTICAST, "mc");
|
||||||
|
PRTFL(BROADCAST, "brd");
|
||||||
|
PRTFL(DNAT, "dst-nat");
|
||||||
|
PRTFL(SNAT, "src-nat");
|
||||||
|
PRTFL(MASQ, "masq");
|
||||||
|
PRTFL(DIRECTDST, "dst-direct");
|
||||||
|
PRTFL(DIRECTSRC, "src-direct");
|
||||||
|
PRTFL(REDIRECTED, "redirected");
|
||||||
|
PRTFL(DOREDIRECT, "redirect");
|
||||||
|
PRTFL(FAST, "fastroute");
|
||||||
|
PRTFL(NOTIFY, "notify");
|
||||||
|
PRTFL(TPROXY, "proxy");
|
||||||
|
#undef PRTFL
|
||||||
|
|
||||||
|
if (flags)
|
||||||
|
fprintf(fp, "%#x> ", flags);
|
||||||
|
}
|
||||||
|
|
||||||
int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
||||||
{
|
{
|
||||||
FILE *fp = (FILE *)arg;
|
FILE *fp = (FILE *)arg;
|
||||||
|
|
@ -544,33 +581,9 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
||||||
if (tb[RTA_UID])
|
if (tb[RTA_UID])
|
||||||
fprintf(fp, "uid %u ", rta_getattr_u32(tb[RTA_UID]));
|
fprintf(fp, "uid %u ", rta_getattr_u32(tb[RTA_UID]));
|
||||||
|
|
||||||
if ((r->rtm_flags&RTM_F_CLONED) && r->rtm_family == AF_INET) {
|
if ((r->rtm_flags & RTM_F_CLONED) && r->rtm_family == AF_INET) {
|
||||||
__u32 flags = r->rtm_flags&~0xFFFF;
|
print_cache_flags(fp, r->rtm_flags);
|
||||||
int first = 1;
|
|
||||||
|
|
||||||
fprintf(fp, "%s cache ", _SL_);
|
|
||||||
|
|
||||||
#define PRTFL(fl, flname) if (flags&RTCF_##fl) { \
|
|
||||||
flags &= ~RTCF_##fl; \
|
|
||||||
fprintf(fp, "%s" flname "%s", first ? "<" : "", flags ? "," : "> "); \
|
|
||||||
first = 0; }
|
|
||||||
PRTFL(LOCAL, "local");
|
|
||||||
PRTFL(REJECT, "reject");
|
|
||||||
PRTFL(MULTICAST, "mc");
|
|
||||||
PRTFL(BROADCAST, "brd");
|
|
||||||
PRTFL(DNAT, "dst-nat");
|
|
||||||
PRTFL(SNAT, "src-nat");
|
|
||||||
PRTFL(MASQ, "masq");
|
|
||||||
PRTFL(DIRECTDST, "dst-direct");
|
|
||||||
PRTFL(DIRECTSRC, "src-direct");
|
|
||||||
PRTFL(REDIRECTED, "redirected");
|
|
||||||
PRTFL(DOREDIRECT, "redirect");
|
|
||||||
PRTFL(FAST, "fastroute");
|
|
||||||
PRTFL(NOTIFY, "notify");
|
|
||||||
PRTFL(TPROXY, "proxy");
|
|
||||||
|
|
||||||
if (flags)
|
|
||||||
fprintf(fp, "%s%x> ", first ? "<" : "", flags);
|
|
||||||
if (tb[RTA_CACHEINFO]) {
|
if (tb[RTA_CACHEINFO]) {
|
||||||
struct rta_cacheinfo *ci = RTA_DATA(tb[RTA_CACHEINFO]);
|
struct rta_cacheinfo *ci = RTA_DATA(tb[RTA_CACHEINFO]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue