More refactoring prior to JSON support.

Signed-off-by: Stephen Hemminger <step...@networkplumber.org>
---
 ip/iproute.c | 63 +++++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 37 insertions(+), 26 deletions(-)

diff --git a/ip/iproute.c b/ip/iproute.c
index 472e4135c5d9..d9c25c05966c 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -383,6 +383,41 @@ static void print_rt_pref(FILE *fp, unsigned int pref)
        }
 }
 
+static void print_ipv4_flags(FILE *fp, __u32 flags)
+{
+       int first = 1;
+
+       flags &= ~0xFFFF;
+
+       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");
+#undef PRTFL
+
+       if (flags)
+               fprintf(fp, "%s%x> ", first ? "<" : "", flags);
+}
+
 int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
        FILE *fp = (FILE *)arg;
@@ -545,33 +580,9 @@ int print_route(const struct sockaddr_nl *who, struct 
nlmsghdr *n, void *arg)
        if (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) {
-               __u32 flags = r->rtm_flags&~0xFFFF;
-               int first = 1;
+       if ((r->rtm_flags & RTM_F_CLONED) && r->rtm_family == AF_INET) {
+               print_ipv4_flags(fp, r->rtm_flags);
 
-               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]) {
                        struct rta_cacheinfo *ci = RTA_DATA(tb[RTA_CACHEINFO]);
 
-- 
2.15.1

Reply via email to