File: bridge.c

package info (click to toggle)
iproute2 6.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,272 kB
  • sloc: ansic: 125,480; sh: 1,363; cpp: 946; makefile: 697; yacc: 421; lex: 145; python: 43
file content (103 lines) | stat: -rw-r--r-- 3,174 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// SPDX-License-Identifier: GPL-2.0

#include <net/if.h>

#include "utils.h"
#include "bridge.h"

void bridge_print_vlan_flags(__u16 flags)
{
	if (flags == 0)
		return;

	open_json_array(PRINT_JSON, "flags");
	if (flags & BRIDGE_VLAN_INFO_PVID)
		print_string(PRINT_ANY, NULL, " %s", "PVID");

	if (flags & BRIDGE_VLAN_INFO_UNTAGGED)
		print_string(PRINT_ANY, NULL, " %s", "Egress Untagged");
	close_json_array(PRINT_JSON, NULL);
}

void bridge_print_vlan_stats_only(const struct bridge_vlan_xstats *vstats)
{
	print_string(PRINT_FP, NULL, "%-" textify(IFNAMSIZ) "s    ", "");
	print_lluint(PRINT_ANY, "rx_bytes", "RX: %llu bytes",
		     vstats->rx_bytes);
	print_lluint(PRINT_ANY, "rx_packets", " %llu packets\n",
		     vstats->rx_packets);

	print_string(PRINT_FP, NULL, "%-" textify(IFNAMSIZ) "s    ", "");
	print_lluint(PRINT_ANY, "tx_bytes", "TX: %llu bytes",
		     vstats->tx_bytes);
	print_lluint(PRINT_ANY, "tx_packets", " %llu packets\n",
		     vstats->tx_packets);
}

void bridge_print_vlan_stats(const struct bridge_vlan_xstats *vstats)
{
	open_json_object(NULL);

	print_hu(PRINT_ANY, "vid", "%hu", vstats->vid);
	bridge_print_vlan_flags(vstats->flags);
	print_nl();
	bridge_print_vlan_stats_only(vstats);

	close_json_object();
}

void bridge_print_mcast_querier_state(const struct rtattr *vtb)
{
	struct rtattr *bqtb[BRIDGE_QUERIER_MAX + 1];
	const char *querier_ip;
	SPRINT_BUF(other_time);
	__u64 tval;

	parse_rtattr_nested(bqtb, BRIDGE_QUERIER_MAX, vtb);
	memset(other_time, 0, sizeof(other_time));

	open_json_object("mcast_querier_state_ipv4");
	if (bqtb[BRIDGE_QUERIER_IP_ADDRESS]) {
		querier_ip = format_host_rta(AF_INET,
					     bqtb[BRIDGE_QUERIER_IP_ADDRESS]);
		print_string(PRINT_FP, NULL, "%s ",
			     "mcast_querier_ipv4_addr");
		print_color_string(PRINT_ANY, COLOR_INET,
				   "mcast_querier_ipv4_addr", "%s ",
				   querier_ip);
	}
	if (bqtb[BRIDGE_QUERIER_IP_PORT])
		print_uint(PRINT_ANY, "mcast_querier_ipv4_port",
			   "mcast_querier_ipv4_port %u ",
			   rta_getattr_u32(bqtb[BRIDGE_QUERIER_IP_PORT]));
	if (bqtb[BRIDGE_QUERIER_IP_OTHER_TIMER]) {
		tval = rta_getattr_u64(bqtb[BRIDGE_QUERIER_IP_OTHER_TIMER]);
		print_string(PRINT_ANY,
			     "mcast_querier_ipv4_other_timer",
			     "mcast_querier_ipv4_other_timer %s ",
			     sprint_time64(tval, other_time));
	}
	close_json_object();
	open_json_object("mcast_querier_state_ipv6");
	if (bqtb[BRIDGE_QUERIER_IPV6_ADDRESS]) {
		querier_ip = format_host_rta(AF_INET6,
					     bqtb[BRIDGE_QUERIER_IPV6_ADDRESS]);
		print_string(PRINT_FP, NULL, "%s ",
			     "mcast_querier_ipv6_addr");
		print_color_string(PRINT_ANY, COLOR_INET6,
				   "mcast_querier_ipv6_addr", "%s ",
				   querier_ip);
	}
	if (bqtb[BRIDGE_QUERIER_IPV6_PORT])
		print_uint(PRINT_ANY, "mcast_querier_ipv6_port",
			   "mcast_querier_ipv6_port %u ",
			   rta_getattr_u32(bqtb[BRIDGE_QUERIER_IPV6_PORT]));
	if (bqtb[BRIDGE_QUERIER_IPV6_OTHER_TIMER]) {
		tval = rta_getattr_u64(bqtb[BRIDGE_QUERIER_IPV6_OTHER_TIMER]);
		print_string(PRINT_ANY,
			     "mcast_querier_ipv6_other_timer",
			     "mcast_querier_ipv6_other_timer %s ",
			     sprint_time64(tval, other_time));
	}
	close_json_object();
}