[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20231211140732.11475-16-bpoirier@nvidia.com>
Date: Mon, 11 Dec 2023 09:07:27 -0500
From: Benjamin Poirier <bpoirier@...dia.com>
To: netdev@...r.kernel.org
Cc: Petr Machata <petrm@...dia.com>,
Roopa Prabhu <roopa@...dia.com>
Subject: [PATCH iproute2-next 15/20] bridge: vni: Align output columns
Use fixed column widths to improve readability.
These changes are similar to commit e0c457b1a5a2 ("bridge: Align output
columns").
Before:
$ bridge vni
dev vni group/remote
vxlan1 4001
4002 10.0.0.1
5000-5010
16777214-16777215 10.0.0.2
vxlan2 100
After:
$ bridge vni
dev vni group/remote
vxlan1 4001
4002 10.0.0.1
5000-5010
16777214-16777215 10.0.0.2
vxlan2 100
Reviewed-by: Petr Machata <petrm@...dia.com>
Tested-by: Petr Machata <petrm@...dia.com>
Signed-off-by: Benjamin Poirier <bpoirier@...dia.com>
---
bridge/vni.c | 40 +++++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 19 deletions(-)
diff --git a/bridge/vni.c b/bridge/vni.c
index 44781b01..e9943872 100644
--- a/bridge/vni.c
+++ b/bridge/vni.c
@@ -23,7 +23,8 @@
static unsigned int filter_index;
-#define VXLAN_ID_LEN 15
+/* max len of "<start>-<end>" */
+#define VXLAN_ID_LEN 17
#define __stringify_1(x...) #x
#define __stringify(x...) __stringify_1(x)
@@ -162,16 +163,18 @@ static void close_vni_port(void)
close_json_object();
}
-static void print_range(const char *name, __u32 start, __u32 id)
+static unsigned int print_range(const char *name, __u32 start, __u32 id)
{
char end[64];
+ int width;
snprintf(end, sizeof(end), "%sEnd", name);
- print_uint(PRINT_ANY, name, " %u", start);
+ width = print_uint(PRINT_ANY, name, "%u", start);
if (start != id)
- print_uint(PRINT_ANY, end, "-%-14u ", id);
+ width += print_uint(PRINT_ANY, end, "-%u", id);
+ return width;
}
static void print_vnifilter_entry_stats(struct rtattr *stats_attr)
@@ -231,7 +234,8 @@ static void print_vni(struct rtattr *t, int ifindex)
{
struct rtattr *ttb[VXLAN_VNIFILTER_ENTRY_MAX+1];
__u32 vni_start = 0;
- __u32 vni_end = 0;
+ unsigned int width;
+ __u32 vni_end;
parse_rtattr_flags(ttb, VXLAN_VNIFILTER_ENTRY_MAX, RTA_DATA(t),
RTA_PAYLOAD(t), NLA_F_NESTED);
@@ -241,12 +245,13 @@ static void print_vni(struct rtattr *t, int ifindex)
if (ttb[VXLAN_VNIFILTER_ENTRY_END])
vni_end = rta_getattr_u32(ttb[VXLAN_VNIFILTER_ENTRY_END]);
+ else
+ vni_end = vni_start;
open_json_object(NULL);
- if (vni_end)
- print_range("vni", vni_start, vni_end);
- else
- print_uint(PRINT_ANY, "vni", " %-14u", vni_start);
+ width = print_range("vni", vni_start, vni_end);
+ if (!is_json_context())
+ printf("%-*s ", VXLAN_ID_LEN - width, "");
if (ttb[VXLAN_VNIFILTER_ENTRY_GROUP]) {
__be32 addr = rta_getattr_u32(ttb[VXLAN_VNIFILTER_ENTRY_GROUP]);
@@ -255,12 +260,12 @@ static void print_vni(struct rtattr *t, int ifindex)
if (IN_MULTICAST(ntohl(addr)))
print_string(PRINT_ANY,
"group",
- " %s",
+ "%s",
format_host(AF_INET, 4, &addr));
else
print_string(PRINT_ANY,
"remote",
- " %s",
+ "%s",
format_host(AF_INET, 4, &addr));
}
} else if (ttb[VXLAN_VNIFILTER_ENTRY_GROUP6]) {
@@ -271,14 +276,14 @@ static void print_vni(struct rtattr *t, int ifindex)
if (IN6_IS_ADDR_MULTICAST(&addr))
print_string(PRINT_ANY,
"group",
- " %s",
+ "%s",
format_host(AF_INET6,
sizeof(struct in6_addr),
&addr));
else
print_string(PRINT_ANY,
"remote",
- " %s",
+ "%s",
format_host(AF_INET6,
sizeof(struct in6_addr),
&addr));
@@ -382,13 +387,10 @@ static int vni_show(int argc, char **argv)
exit(1);
}
- if (!is_json_context()) {
+ if (!is_json_context())
printf("%-" __stringify(IFNAMSIZ) "s %-"
- __stringify(VXLAN_ID_LEN) "s %-"
- __stringify(15) "s",
- "dev", "vni", "group/remote");
- printf("\n");
- }
+ __stringify(VXLAN_ID_LEN) "s group/remote\n", "dev",
+ "vni");
ret = rtnl_dump_filter(&rth, print_vnifilter_rtm, NULL);
if (ret < 0) {
--
2.43.0
Powered by blists - more mailing lists