int rem = RTA_PAYLOAD(list);
__u16 last_vid_start = 0;
__u32 last_tunid_start = 0;
-
- open_vlan_port(ifindex, "%s", VLAN_SHOW_TUNNELINFO);
+ bool opened = false;
for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
struct rtattr *ttb[IFLA_BRIDGE_VLAN_TUNNEL_MAX+1];
else if (vcheck_ret == 0)
continue;
+ if (!opened) {
+ open_vlan_port(ifindex, "%s", VLAN_SHOW_TUNNELINFO);
+ opened = true;
+ }
+
open_json_object(NULL);
print_range("vlan", last_vid_start, tunnel_vid);
print_range("tunid", last_tunid_start, tunnel_id);
close_json_object();
print_string(PRINT_FP, NULL, "%s", _SL_);
}
- close_vlan_port();
+
+ if (opened)
+ close_vlan_port();
}
static int print_vlan(struct nlmsghdr *n, void *arg)
return 0;
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifm), len);
-
- /* if AF_SPEC isn't there, vlan table is not preset for this port */
- if (!tb[IFLA_AF_SPEC]) {
- if (!filter_vlan && !is_json_context()) {
- color_fprintf(stdout, COLOR_IFNAME, "%s",
- ll_index_to_name(ifm->ifi_index));
- fprintf(stdout, "\tNone\n");
- }
+ if (!tb[IFLA_AF_SPEC])
return 0;
- }
switch (*subject) {
case VLAN_SHOW_VLAN:
print_vlan_tunnel_info(tb[IFLA_AF_SPEC], ifm->ifi_index);
break;
}
- print_string(PRINT_FP, NULL, "%s", _SL_);
- fflush(stdout);
return 0;
}
struct rtattr *i, *list = tb;
int rem = RTA_PAYLOAD(list);
__u16 last_vid_start = 0;
-
- open_vlan_port(ifindex, "%s", VLAN_SHOW_VLAN);
+ bool opened = false;
for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
struct bridge_vlan_info *vinfo;
else if (vcheck_ret == 0)
continue;
+ if (!opened) {
+ open_vlan_port(ifindex, "%s", VLAN_SHOW_VLAN);
+ opened = true;
+ }
+
open_json_object(NULL);
print_range("vlan", last_vid_start, vinfo->vid);
close_json_object();
print_string(PRINT_FP, NULL, "%s", _SL_);
}
- close_vlan_port();
+
+ if (opened)
+ close_vlan_port();
}
int do_vlan(int argc, char **argv)
--- /dev/null
+#!/bin/sh
+
+. lib/generic.sh
+
+ts_log "[Testing vlan show]"
+
+BR_DEV="$(rand_dev)"
+VX0_DEV="$(rand_dev)"
+VX1_DEV="$(rand_dev)"
+
+ts_ip "$0" "Add $BR_DEV bridge interface" link add $BR_DEV type bridge
+
+ts_ip "$0" "Add $VX0_DEV vxlan interface" \
+ link add $VX0_DEV type vxlan dstport 4789 external
+ts_ip "$0" "Enslave $VX0_DEV under $BR_DEV" \
+ link set dev $VX0_DEV master $BR_DEV
+ts_bridge "$0" "Delete default vlan from $VX0_DEV" \
+ vlan del dev $VX0_DEV vid 1
+ts_ip "$0" "Add $VX1_DEV vxlan interface" \
+ link add $VX1_DEV type vxlan dstport 4790 external
+ts_ip "$0" "Enslave $VX1_DEV under $BR_DEV" \
+ link set dev $VX1_DEV master $BR_DEV
+
+# Test that bridge ports without vlans do not appear in the output
+ts_bridge "$0" "Show vlan" vlan
+test_on_not "$VX0_DEV"
+
+# Test that bridge ports without tunnels do not appear in the output
+ts_bridge "$0" "Show vlan tunnel info" vlan tunnelshow
+test_lines_count 1 # header only