lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 27 Aug 2021 10:10:18 -0700
From:   David Ahern <dsahern@...il.com>
To:     Nikolay Aleksandrov <razor@...ckwall.org>, netdev@...r.kernel.org
Cc:     roopa@...dia.com, Joachim Wiberg <troglobit@...il.com>,
        Nikolay Aleksandrov <nikolay@...dia.com>
Subject: Re: [PATCH iproute2-next 02/17] bridge: vlan: add support to show
 global vlan options

On 8/26/21 6:05 AM, Nikolay Aleksandrov wrote:
> From: Nikolay Aleksandrov <nikolay@...dia.com>
> 
> Add support for new bridge vlan command grouping called global which
> operates on global options. The first command it supports is "show".
> Man page and help are also updated with the new command.
> 
> Syntax is: $ bridge vlan global show [ vid VID ] [ dev DEV ]
> 
> Signed-off-by: Nikolay Aleksandrov <nikolay@...dia.com>
> ---
>  bridge/br_common.h |   3 +-
>  bridge/monitor.c   |   2 +-
>  bridge/vlan.c      | 229 ++++++++++++++++++++++++++++++++++-----------
>  man/man8/bridge.8  |  21 +++++
>  4 files changed, 200 insertions(+), 55 deletions(-)
> 
> diff --git a/bridge/br_common.h b/bridge/br_common.h
> index b9adafd98dea..09f42c814918 100644
> --- a/bridge/br_common.h
> +++ b/bridge/br_common.h
> @@ -12,7 +12,8 @@ int print_mdb_mon(struct nlmsghdr *n, void *arg);
>  int print_fdb(struct nlmsghdr *n, void *arg);
>  void print_stp_state(__u8 state);
>  int parse_stp_state(const char *arg);
> -int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor);
> +int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor,
> +		   bool global_only);
>  
>  int do_fdb(int argc, char **argv);
>  int do_mdb(int argc, char **argv);
> diff --git a/bridge/monitor.c b/bridge/monitor.c
> index 88f52f52f084..845e221abb49 100644
> --- a/bridge/monitor.c
> +++ b/bridge/monitor.c
> @@ -71,7 +71,7 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl,
>  	case RTM_DELVLAN:
>  		if (prefix_banner)
>  			fprintf(fp, "[VLAN]");
> -		return print_vlan_rtm(n, arg, true);
> +		return print_vlan_rtm(n, arg, true, false);
>  
>  	default:
>  		return 0;
> diff --git a/bridge/vlan.c b/bridge/vlan.c
> index 9b6511f189ff..9e33995f8f33 100644
> --- a/bridge/vlan.c
> +++ b/bridge/vlan.c
> @@ -36,7 +36,8 @@ static void usage(void)
>  		"                                                     [ self ] [ master ]\n"
>  		"       bridge vlan { set } vid VLAN_ID dev DEV [ state STP_STATE ]\n"
>  		"       bridge vlan { show } [ dev DEV ] [ vid VLAN_ID ]\n"
> -		"       bridge vlan { tunnelshow } [ dev DEV ] [ vid VLAN_ID ]\n");
> +		"       bridge vlan { tunnelshow } [ dev DEV ] [ vid VLAN_ID ]\n"
> +		"       bridge vlan global { show } [ dev DEV ] [ vid VLAN_ID ]\n");
>  	exit(-1);
>  }
>  
> @@ -621,11 +622,89 @@ static int print_vlan_stats(struct nlmsghdr *n, void *arg)
>  	return 0;
>  }
>  
> -int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor)
> +static void print_vlan_global_opts(struct rtattr *a)
> +{
> +	struct rtattr *vtb[BRIDGE_VLANDB_GOPTS_MAX + 1];
> +	__u16 vid, vrange = 0;
> +
> +	if ((a->rta_type & NLA_TYPE_MASK) != BRIDGE_VLANDB_GLOBAL_OPTIONS)
> +		return;
> +
> +	parse_rtattr_flags(vtb, BRIDGE_VLANDB_GOPTS_MAX, RTA_DATA(a),
> +			   RTA_PAYLOAD(a), NLA_F_NESTED);
> +	vid = rta_getattr_u16(vtb[BRIDGE_VLANDB_GOPTS_ID]);
> +	if (vtb[BRIDGE_VLANDB_GOPTS_RANGE])
> +		vrange = rta_getattr_u16(vtb[BRIDGE_VLANDB_GOPTS_RANGE]);
> +	else
> +		vrange = vid;
> +	print_range("vlan", vid, vrange);
> +	print_nl();
> +}
> +
> +static void print_vlan_opts(struct rtattr *a)
> +{
> +	struct rtattr *vtb[BRIDGE_VLANDB_ENTRY_MAX + 1];
> +	struct bridge_vlan_xstats vstats;
> +	struct bridge_vlan_info *vinfo;
> +	__u16 vrange = 0;
> +	__u8 state = 0;
> +
> +	if ((a->rta_type & NLA_TYPE_MASK) != BRIDGE_VLANDB_ENTRY)
> +		return;
> +
> +	parse_rtattr_flags(vtb, BRIDGE_VLANDB_ENTRY_MAX, RTA_DATA(a),
> +			   RTA_PAYLOAD(a), NLA_F_NESTED);
> +	vinfo = RTA_DATA(vtb[BRIDGE_VLANDB_ENTRY_INFO]);
> +
> +	memset(&vstats, 0, sizeof(vstats));
> +	if (vtb[BRIDGE_VLANDB_ENTRY_RANGE])
> +		vrange = rta_getattr_u16(vtb[BRIDGE_VLANDB_ENTRY_RANGE]);
> +	else
> +		vrange = vinfo->vid;
> +
> +	if (vtb[BRIDGE_VLANDB_ENTRY_STATE])
> +		state = rta_getattr_u8(vtb[BRIDGE_VLANDB_ENTRY_STATE]);
> +
> +	if (vtb[BRIDGE_VLANDB_ENTRY_STATS]) {
> +		struct rtattr *stb[BRIDGE_VLANDB_STATS_MAX+1];
> +		struct rtattr *attr;
> +
> +		attr = vtb[BRIDGE_VLANDB_ENTRY_STATS];
> +		parse_rtattr(stb, BRIDGE_VLANDB_STATS_MAX, RTA_DATA(attr),
> +			     RTA_PAYLOAD(attr));
> +
> +		if (stb[BRIDGE_VLANDB_STATS_RX_BYTES]) {
> +			attr = stb[BRIDGE_VLANDB_STATS_RX_BYTES];
> +			vstats.rx_bytes = rta_getattr_u64(attr);
> +		}
> +		if (stb[BRIDGE_VLANDB_STATS_RX_PACKETS]) {
> +			attr = stb[BRIDGE_VLANDB_STATS_RX_PACKETS];
> +			vstats.rx_packets = rta_getattr_u64(attr);
> +		}
> +		if (stb[BRIDGE_VLANDB_STATS_TX_PACKETS]) {
> +			attr = stb[BRIDGE_VLANDB_STATS_TX_PACKETS];
> +			vstats.tx_packets = rta_getattr_u64(attr);
> +		}
> +		if (stb[BRIDGE_VLANDB_STATS_TX_BYTES]) {
> +			attr = stb[BRIDGE_VLANDB_STATS_TX_BYTES];
> +			vstats.tx_bytes = rta_getattr_u64(attr);
> +		}
> +	}
> +	print_range("vlan", vinfo->vid, vrange);
> +	print_vlan_flags(vinfo->flags);
> +	print_nl();
> +	print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s    ", "");
> +	print_stp_state(state);
> +	print_nl();
> +	if (show_stats)
> +		__print_one_vlan_stats(&vstats);
> +}
> +
> +int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor, bool global_only)
>  {
> -	struct rtattr *vtb[BRIDGE_VLANDB_ENTRY_MAX + 1], *a;
>  	struct br_vlan_msg *bvm = NLMSG_DATA(n);
>  	int len = n->nlmsg_len;
> +	struct rtattr *a;
>  	int rem;
>  
>  	if (n->nlmsg_type != RTM_NEWVLAN && n->nlmsg_type != RTM_DELVLAN &&
> @@ -660,49 +739,13 @@ int print_vlan_rtm(struct nlmsghdr *n, void *arg, bool monitor)
>  
>  	rem = len;
>  	for (a = BRVLAN_RTA(bvm); RTA_OK(a, rem); a = RTA_NEXT(a, rem)) {
> -		struct bridge_vlan_xstats vstats;
> -		struct bridge_vlan_info *vinfo;
> -		__u32 vrange = 0;
> -		__u8 state = 0;
> -
> -		parse_rtattr_flags(vtb, BRIDGE_VLANDB_ENTRY_MAX, RTA_DATA(a),
> -				   RTA_PAYLOAD(a), NLA_F_NESTED);
> -		vinfo = RTA_DATA(vtb[BRIDGE_VLANDB_ENTRY_INFO]);
> -
> -		memset(&vstats, 0, sizeof(vstats));
> -		if (vtb[BRIDGE_VLANDB_ENTRY_RANGE])
> -			vrange = rta_getattr_u16(vtb[BRIDGE_VLANDB_ENTRY_RANGE]);
> -		else
> -			vrange = vinfo->vid;
> -
> -		if (vtb[BRIDGE_VLANDB_ENTRY_STATE])
> -			state = rta_getattr_u8(vtb[BRIDGE_VLANDB_ENTRY_STATE]);
> +		unsigned short rta_type = a->rta_type & NLA_TYPE_MASK;
>  
> -		if (vtb[BRIDGE_VLANDB_ENTRY_STATS]) {
> -			struct rtattr *stb[BRIDGE_VLANDB_STATS_MAX+1];
> -			struct rtattr *attr;
> -
> -			attr = vtb[BRIDGE_VLANDB_ENTRY_STATS];
> -			parse_rtattr(stb, BRIDGE_VLANDB_STATS_MAX, RTA_DATA(attr),
> -				     RTA_PAYLOAD(attr));
> +		/* skip unknown attributes */
> +		if (rta_type > BRIDGE_VLANDB_MAX ||
> +		    (global_only && rta_type != BRIDGE_VLANDB_GLOBAL_OPTIONS))
> +			continue;
>  
> -			if (stb[BRIDGE_VLANDB_STATS_RX_BYTES]) {
> -				attr = stb[BRIDGE_VLANDB_STATS_RX_BYTES];
> -				vstats.rx_bytes = rta_getattr_u64(attr);
> -			}
> -			if (stb[BRIDGE_VLANDB_STATS_RX_PACKETS]) {
> -				attr = stb[BRIDGE_VLANDB_STATS_RX_PACKETS];
> -				vstats.rx_packets = rta_getattr_u64(attr);
> -			}
> -			if (stb[BRIDGE_VLANDB_STATS_TX_PACKETS]) {
> -				attr = stb[BRIDGE_VLANDB_STATS_TX_PACKETS];
> -				vstats.tx_packets = rta_getattr_u64(attr);
> -			}
> -			if (stb[BRIDGE_VLANDB_STATS_TX_BYTES]) {
> -				attr = stb[BRIDGE_VLANDB_STATS_TX_BYTES];
> -				vstats.tx_bytes = rta_getattr_u64(attr);
> -			}
> -		}
>  		if (vlan_rtm_cur_ifidx != bvm->ifindex) {
>  			open_vlan_port(bvm->ifindex, VLAN_SHOW_VLAN);
>  			open_json_object(NULL);

Split the refactoring of this code into a separate patch that only does
the refactoring.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ