From db77b23a4cf4c140881e68bd1a32fb08508a918e Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 20 Apr 2017 13:30:19 +0200 Subject: [PATCH] ip-route: Prevent some other double spaces in output Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1374446 Upstream Status: iproute2.git commit 5551ed44d394f Conflicts: Adjusted for missing upstream commits: * 194e9b855d053 ("ip: support RFC4191 router preference") * 528c2551cdb27 ("iproute2: add support to print 'linkdown' nexthop flag") * ecc509f9a36be ("ip route: add mpls multipath support") * 93ae283594094 ("add support for the RTA_VIA attribute") * 56f5daac98da0 ("ip: code cleanup") commit 5551ed44d394fac6e9a035dadb259580fbda84d3 Author: Timothy Redaelli Date: Wed Apr 5 19:10:26 2017 +0200 ip-route: Prevent some other double spaces in output Print spaces only after text. CC: Phil Sutter Signed-off-by: Timothy Redaelli Acked-by: Phil Sutter --- ip/iproute.c | 69 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/ip/iproute.c b/ip/iproute.c index 134b146..2b50709 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -292,12 +292,12 @@ static void print_rtax_features(FILE *fp, unsigned int features) unsigned int of = features; if (features & RTAX_FEATURE_ECN) { - fprintf(fp, " ecn"); + fprintf(fp, "ecn "); features &= ~RTAX_FEATURE_ECN; } if (features) - fprintf(fp, " 0x%x", of); + fprintf(fp, "0x%x ", of); } int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) @@ -483,21 +483,21 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) if (!hz) hz = get_user_hz(); if (ci->rta_expires != 0) - fprintf(fp, " expires %dsec", ci->rta_expires/hz); + fprintf(fp, "expires %dsec ", ci->rta_expires/hz); if (ci->rta_error != 0) - fprintf(fp, " error %d", ci->rta_error); + fprintf(fp, "error %d ", ci->rta_error); if (show_stats) { if (ci->rta_clntref) - fprintf(fp, " users %d", ci->rta_clntref); + fprintf(fp, "users %d ", ci->rta_clntref); if (ci->rta_used != 0) - fprintf(fp, " used %d", ci->rta_used); + fprintf(fp, "used %d ", ci->rta_used); if (ci->rta_lastuse != 0) - fprintf(fp, " age %dsec", ci->rta_lastuse/hz); + fprintf(fp, "age %dsec ", ci->rta_lastuse/hz); } if (ci->rta_id) - fprintf(fp, " ipid 0x%04x", ci->rta_id); + fprintf(fp, "ipid 0x%04x ", ci->rta_id); if (ci->rta_ts || ci->rta_tsage) - fprintf(fp, " ts 0x%x tsage %dsec", + fprintf(fp, "ts 0x%x tsage %dsec ", ci->rta_ts, ci->rta_tsage); } } else if (r->rtm_family == AF_INET6) { @@ -510,20 +510,20 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) if (r->rtm_flags & RTM_F_CLONED) fprintf(fp, "%s cache ", _SL_); if (ci->rta_expires) - fprintf(fp, " expires %dsec", ci->rta_expires/hz); + fprintf(fp, "expires %dsec ", ci->rta_expires/hz); if (ci->rta_error != 0) - fprintf(fp, " error %d", ci->rta_error); + fprintf(fp, "error %d ", ci->rta_error); if (show_stats) { if (ci->rta_clntref) - fprintf(fp, " users %d", ci->rta_clntref); + fprintf(fp, "users %d ", ci->rta_clntref); if (ci->rta_used != 0) - fprintf(fp, " used %d", ci->rta_used); + fprintf(fp, "used %d ", ci->rta_used); if (ci->rta_lastuse != 0) - fprintf(fp, " age %dsec", ci->rta_lastuse/hz); + fprintf(fp, "age %dsec ", ci->rta_lastuse/hz); } } else if (ci) { if (ci->rta_error != 0) - fprintf(fp, " error %d", ci->rta_error); + fprintf(fp, "error %d ", ci->rta_error); } } if (tb[RTA_METRICS]) { @@ -549,19 +549,19 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) continue; if (i < sizeof(mx_names)/sizeof(char*) && mx_names[i]) - fprintf(fp, " %s", mx_names[i]); + fprintf(fp, "%s ", mx_names[i]); else - fprintf(fp, " metric %d", i); + fprintf(fp, "metric %d ", i); if (mxlock & (1<= 1000) - fprintf(fp, " %gs", val/1e3); + fprintf(fp, "%gs ", val/1e3); else - fprintf(fp, " %ums", val); + fprintf(fp, "%ums ", val); break; case RTAX_CC_ALGO: - fprintf(fp, " %s", rta_getattr_str(mxrta[i])); + fprintf(fp, "%s ", rta_getattr_str(mxrta[i])); break; } } } if (tb[RTA_IIF] && filter.iifmask != -1) { - fprintf(fp, " iif %s", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_IIF]))); + fprintf(fp, "iif %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_IIF]))); } if (tb[RTA_MULTIPATH]) { struct rtnexthop *nh = RTA_DATA(tb[RTA_MULTIPATH]); @@ -599,11 +599,11 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) break; if (r->rtm_flags&RTM_F_CLONED && r->rtm_type == RTN_MULTICAST) { if (first) - fprintf(fp, " Oifs:"); + fprintf(fp, "Oifs: "); else fprintf(fp, " "); } else - fprintf(fp, "%s\tnexthop", _SL_); + fprintf(fp, "%s\tnexthop ", _SL_); if (nh->rtnh_len > sizeof(*nh)) { parse_rtattr(tb, RTA_MAX, RTNH_DATA(nh), nh->rtnh_len - sizeof(*nh)); if (tb[RTA_GATEWAY]) { @@ -613,7 +613,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) if (nh->rtnh_len > sizeof(*nh)) { parse_rtattr(tb, RTA_MAX, RTNH_DATA(nh), nh->rtnh_len - sizeof(*nh)); if (tb[RTA_GATEWAY]) { - fprintf(fp, " via %s ", + fprintf(fp, "via %s ", format_host(r->rtm_family, RTA_PAYLOAD(tb[RTA_GATEWAY]), RTA_DATA(tb[RTA_GATEWAY]))); @@ -622,29 +622,30 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) __u32 to = rta_getattr_u32(tb[RTA_FLOW]); __u32 from = to>>16; to &= 0xFFFF; - fprintf(fp, " realm%s ", from ? "s" : ""); + fprintf(fp, "realm%s ", from ? "s" : ""); if (from) { fprintf(fp, "%s/", rtnl_rtrealm_n2a(from, b1, sizeof(b1))); } - fprintf(fp, "%s", + fprintf(fp, "%s ", rtnl_rtrealm_n2a(to, b1, sizeof(b1))); } } if (r->rtm_flags&RTM_F_CLONED && r->rtm_type == RTN_MULTICAST) { - fprintf(fp, " %s", ll_index_to_name(nh->rtnh_ifindex)); + fprintf(fp, "%s", ll_index_to_name(nh->rtnh_ifindex)); if (nh->rtnh_hops != 1) fprintf(fp, "(ttl>%d)", nh->rtnh_hops); + fprintf(fp, " "); } else { - fprintf(fp, " dev %s", ll_index_to_name(nh->rtnh_ifindex)); - fprintf(fp, " weight %d", nh->rtnh_hops+1); + fprintf(fp, "dev %s ", ll_index_to_name(nh->rtnh_ifindex)); + fprintf(fp, "weight %d ", nh->rtnh_hops+1); } if (nh->rtnh_flags & RTNH_F_DEAD) - fprintf(fp, " dead"); + fprintf(fp, "dead "); if (nh->rtnh_flags & RTNH_F_ONLINK) - fprintf(fp, " onlink"); + fprintf(fp, "onlink "); if (nh->rtnh_flags & RTNH_F_PERVASIVE) - fprintf(fp, " pervasive"); + fprintf(fp, "pervasive "); len -= NLMSG_ALIGN(nh->rtnh_len); nh = RTNH_NEXT(nh); } -- 1.8.3.1