ipnetns: don't print unassigned nsid in json export

Don't output the nsid and current-nsid json keys if they're not set.
Otherwise a parser would have to special case the "not-assigned"
string.

Signed-off-by: Guillaume Nault <gnault@redhat.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
Guillaume Nault 2019-11-08 18:00:18 +01:00 committed by David Ahern
parent 08ba67db7b
commit 1c9b69276c
1 changed files with 3 additions and 3 deletions

View File

@ -329,15 +329,15 @@ int print_nsid(struct nlmsghdr *n, void *arg)
nsid = rta_getattr_s32(tb[NETNSA_NSID]);
if (nsid < 0)
print_string(PRINT_ANY, "nsid", "nsid %s ", "not-assigned");
print_string(PRINT_FP, NULL, "nsid unassigned ", NULL);
else
print_int(PRINT_ANY, "nsid", "nsid %d ", nsid);
if (tb[NETNSA_CURRENT_NSID]) {
current = rta_getattr_s32(tb[NETNSA_CURRENT_NSID]);
if (current < 0)
print_string(PRINT_ANY, "current-nsid",
"current-nsid %s ", "not-assigned");
print_string(PRINT_FP, NULL,
"current-nsid unassigned ", NULL);
else
print_int(PRINT_ANY, "current-nsid",
"current-nsid %d ", current);