Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Bridge netlink control interface |
| 4 | * |
| 5 | * Authors: |
| 6 | * Stephen Hemminger <shemminger@osdl.org> |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
stephen hemminger | bb900b2 | 2011-04-04 14:03:32 +0000 | [diff] [blame] | 11 | #include <linux/etherdevice.h> |
Thomas Graf | 32fe21c | 2007-03-22 11:59:03 -0700 | [diff] [blame] | 12 | #include <net/rtnetlink.h> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 13 | #include <net/net_namespace.h> |
Denis V. Lunev | b854272 | 2007-12-01 00:21:31 +1100 | [diff] [blame] | 14 | #include <net/sock.h> |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 15 | #include <uapi/linux/if_bridge.h> |
stephen hemminger | bb900b2 | 2011-04-04 14:03:32 +0000 | [diff] [blame] | 16 | |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 17 | #include "br_private.h" |
Vitalii Demianets | b03b6dd | 2011-11-25 00:16:37 +0000 | [diff] [blame] | 18 | #include "br_private_stp.h" |
Henrik Bjoernlund | 5e312fc | 2020-10-27 10:02:49 +0000 | [diff] [blame] | 19 | #include "br_private_cfm.h" |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 20 | #include "br_private_tunnel.h" |
Nikolay Aleksandrov | 2dba407 | 2021-01-26 11:35:33 +0200 | [diff] [blame] | 21 | #include "br_private_mcast_eht.h" |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 22 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 23 | static int __get_num_vlan_infos(struct net_bridge_vlan_group *vg, |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 24 | u32 filter_mask) |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 25 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 26 | struct net_bridge_vlan *v; |
| 27 | u16 vid_range_start = 0, vid_range_end = 0, vid_range_flags = 0; |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 28 | u16 flags, pvid; |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 29 | int num_vlans = 0; |
| 30 | |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 31 | if (!(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)) |
| 32 | return 0; |
| 33 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 34 | pvid = br_get_pvid(vg); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 35 | /* Count number of vlan infos */ |
Nikolay Aleksandrov | 586c2b5 | 2015-10-02 15:05:10 +0200 | [diff] [blame] | 36 | list_for_each_entry_rcu(v, &vg->vlan_list, vlist) { |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 37 | flags = 0; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 38 | /* only a context, bridge vlan not activated */ |
| 39 | if (!br_vlan_should_use(v)) |
| 40 | continue; |
| 41 | if (v->vid == pvid) |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 42 | flags |= BRIDGE_VLAN_INFO_PVID; |
| 43 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 44 | if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED) |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 45 | flags |= BRIDGE_VLAN_INFO_UNTAGGED; |
| 46 | |
| 47 | if (vid_range_start == 0) { |
| 48 | goto initvars; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 49 | } else if ((v->vid - vid_range_end) == 1 && |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 50 | flags == vid_range_flags) { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 51 | vid_range_end = v->vid; |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 52 | continue; |
| 53 | } else { |
| 54 | if ((vid_range_end - vid_range_start) > 0) |
| 55 | num_vlans += 2; |
| 56 | else |
| 57 | num_vlans += 1; |
| 58 | } |
| 59 | initvars: |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 60 | vid_range_start = v->vid; |
| 61 | vid_range_end = v->vid; |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 62 | vid_range_flags = flags; |
| 63 | } |
| 64 | |
| 65 | if (vid_range_start != 0) { |
| 66 | if ((vid_range_end - vid_range_start) > 0) |
| 67 | num_vlans += 2; |
| 68 | else |
| 69 | num_vlans += 1; |
| 70 | } |
| 71 | |
| 72 | return num_vlans; |
| 73 | } |
| 74 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 75 | static int br_get_num_vlan_infos(struct net_bridge_vlan_group *vg, |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 76 | u32 filter_mask) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 77 | { |
Nikolay Aleksandrov | 586c2b5 | 2015-10-02 15:05:10 +0200 | [diff] [blame] | 78 | int num_vlans; |
| 79 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 80 | if (!vg) |
| 81 | return 0; |
| 82 | |
| 83 | if (filter_mask & RTEXT_FILTER_BRVLAN) |
| 84 | return vg->num_vlans; |
| 85 | |
Nikolay Aleksandrov | 586c2b5 | 2015-10-02 15:05:10 +0200 | [diff] [blame] | 86 | rcu_read_lock(); |
| 87 | num_vlans = __get_num_vlan_infos(vg, filter_mask); |
| 88 | rcu_read_unlock(); |
| 89 | |
| 90 | return num_vlans; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 91 | } |
| 92 | |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 93 | static size_t br_get_link_af_size_filtered(const struct net_device *dev, |
| 94 | u32 filter_mask) |
Roopa Prabhu | b7853d7 | 2015-02-21 20:21:51 -0800 | [diff] [blame] | 95 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 96 | struct net_bridge_vlan_group *vg = NULL; |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 97 | struct net_bridge_port *p = NULL; |
Henrik Bjoernlund | b6d0425 | 2020-10-27 10:02:51 +0000 | [diff] [blame] | 98 | struct net_bridge *br = NULL; |
| 99 | u32 num_cfm_peer_mep_infos; |
| 100 | u32 num_cfm_mep_infos; |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 101 | size_t vinfo_sz = 0; |
Henrik Bjoernlund | b6d0425 | 2020-10-27 10:02:51 +0000 | [diff] [blame] | 102 | int num_vlan_infos; |
Roopa Prabhu | b7853d7 | 2015-02-21 20:21:51 -0800 | [diff] [blame] | 103 | |
Johannes Berg | 2f56f6b | 2015-03-03 16:02:16 +0100 | [diff] [blame] | 104 | rcu_read_lock(); |
Julian Wiedmann | 35f861e | 2019-03-29 14:38:19 +0100 | [diff] [blame] | 105 | if (netif_is_bridge_port(dev)) { |
Zhang Zhengming | 59259ff | 2021-04-28 22:38:14 +0800 | [diff] [blame] | 106 | p = br_port_get_check_rcu(dev); |
| 107 | if (p) |
| 108 | vg = nbp_vlan_group_rcu(p); |
Kyungrok Chung | 254ec03 | 2021-10-16 20:21:36 +0900 | [diff] [blame] | 109 | } else if (netif_is_bridge_master(dev)) { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 110 | br = netdev_priv(dev); |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 111 | vg = br_vlan_group_rcu(br); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 112 | } |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 113 | num_vlan_infos = br_get_num_vlan_infos(vg, filter_mask); |
Johannes Berg | 2f56f6b | 2015-03-03 16:02:16 +0100 | [diff] [blame] | 114 | rcu_read_unlock(); |
Roopa Prabhu | b7853d7 | 2015-02-21 20:21:51 -0800 | [diff] [blame] | 115 | |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 116 | if (p && (p->flags & BR_VLAN_TUNNEL)) |
| 117 | vinfo_sz += br_get_vlan_tunnel_info_size(vg); |
| 118 | |
Roopa Prabhu | b7853d7 | 2015-02-21 20:21:51 -0800 | [diff] [blame] | 119 | /* Each VLAN is returned in bridge_vlan_info along with flags */ |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 120 | vinfo_sz += num_vlan_infos * nla_total_size(sizeof(struct bridge_vlan_info)); |
| 121 | |
Henrik Bjoernlund | b6d0425 | 2020-10-27 10:02:51 +0000 | [diff] [blame] | 122 | if (!(filter_mask & RTEXT_FILTER_CFM_STATUS)) |
| 123 | return vinfo_sz; |
| 124 | |
| 125 | if (!br) |
| 126 | return vinfo_sz; |
| 127 | |
| 128 | /* CFM status info must be added */ |
| 129 | br_cfm_mep_count(br, &num_cfm_mep_infos); |
| 130 | br_cfm_peer_mep_count(br, &num_cfm_peer_mep_infos); |
| 131 | |
| 132 | vinfo_sz += nla_total_size(0); /* IFLA_BRIDGE_CFM */ |
| 133 | /* For each status struct the MEP instance (u32) is added */ |
| 134 | /* MEP instance (u32) + br_cfm_mep_status */ |
| 135 | vinfo_sz += num_cfm_mep_infos * |
| 136 | /*IFLA_BRIDGE_CFM_MEP_STATUS_INSTANCE */ |
| 137 | (nla_total_size(sizeof(u32)) |
| 138 | /* IFLA_BRIDGE_CFM_MEP_STATUS_OPCODE_UNEXP_SEEN */ |
| 139 | + nla_total_size(sizeof(u32)) |
| 140 | /* IFLA_BRIDGE_CFM_MEP_STATUS_VERSION_UNEXP_SEEN */ |
| 141 | + nla_total_size(sizeof(u32)) |
| 142 | /* IFLA_BRIDGE_CFM_MEP_STATUS_RX_LEVEL_LOW_SEEN */ |
| 143 | + nla_total_size(sizeof(u32))); |
| 144 | /* MEP instance (u32) + br_cfm_cc_peer_status */ |
| 145 | vinfo_sz += num_cfm_peer_mep_infos * |
| 146 | /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_INSTANCE */ |
| 147 | (nla_total_size(sizeof(u32)) |
| 148 | /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_PEER_MEPID */ |
| 149 | + nla_total_size(sizeof(u32)) |
| 150 | /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_CCM_DEFECT */ |
| 151 | + nla_total_size(sizeof(u32)) |
| 152 | /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_RDI */ |
| 153 | + nla_total_size(sizeof(u32)) |
| 154 | /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_PORT_TLV_VALUE */ |
| 155 | + nla_total_size(sizeof(u8)) |
| 156 | /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_IF_TLV_VALUE */ |
| 157 | + nla_total_size(sizeof(u8)) |
| 158 | /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_SEEN */ |
| 159 | + nla_total_size(sizeof(u32)) |
| 160 | /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_TLV_SEEN */ |
| 161 | + nla_total_size(sizeof(u32)) |
| 162 | /* IFLA_BRIDGE_CFM_CC_PEER_STATUS_SEQ_UNEXP_SEEN */ |
| 163 | + nla_total_size(sizeof(u32))); |
| 164 | |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 165 | return vinfo_sz; |
Roopa Prabhu | b7853d7 | 2015-02-21 20:21:51 -0800 | [diff] [blame] | 166 | } |
| 167 | |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 168 | static inline size_t br_port_info_size(void) |
| 169 | { |
| 170 | return nla_total_size(1) /* IFLA_BRPORT_STATE */ |
| 171 | + nla_total_size(2) /* IFLA_BRPORT_PRIORITY */ |
| 172 | + nla_total_size(4) /* IFLA_BRPORT_COST */ |
| 173 | + nla_total_size(1) /* IFLA_BRPORT_MODE */ |
stephen hemminger | a2e01a6 | 2012-11-13 07:53:07 +0000 | [diff] [blame] | 174 | + nla_total_size(1) /* IFLA_BRPORT_GUARD */ |
stephen hemminger | 1007dd1 | 2012-11-13 07:53:08 +0000 | [diff] [blame] | 175 | + nla_total_size(1) /* IFLA_BRPORT_PROTECT */ |
stephen hemminger | 3da889b | 2013-03-11 13:52:17 +0000 | [diff] [blame] | 176 | + nla_total_size(1) /* IFLA_BRPORT_FAST_LEAVE */ |
Felix Fietkau | 6db6f0e | 2017-01-21 21:01:32 +0100 | [diff] [blame] | 177 | + nla_total_size(1) /* IFLA_BRPORT_MCAST_TO_UCAST */ |
Vlad Yasevich | 9ba1889 | 2013-06-05 10:08:00 -0400 | [diff] [blame] | 178 | + nla_total_size(1) /* IFLA_BRPORT_LEARNING */ |
Vlad Yasevich | 867a594 | 2013-06-05 10:08:01 -0400 | [diff] [blame] | 179 | + nla_total_size(1) /* IFLA_BRPORT_UNICAST_FLOOD */ |
Tobias Klauser | 9051247 | 2017-05-05 16:36:53 +0200 | [diff] [blame] | 180 | + nla_total_size(1) /* IFLA_BRPORT_MCAST_FLOOD */ |
| 181 | + nla_total_size(1) /* IFLA_BRPORT_BCAST_FLOOD */ |
Nikolay Aleksandrov | 355b9f9 | 2015-08-04 19:06:32 +0200 | [diff] [blame] | 182 | + nla_total_size(1) /* IFLA_BRPORT_PROXYARP */ |
Nikolay Aleksandrov | 786c207 | 2015-08-04 19:06:33 +0200 | [diff] [blame] | 183 | + nla_total_size(1) /* IFLA_BRPORT_PROXYARP_WIFI */ |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 184 | + nla_total_size(1) /* IFLA_BRPORT_VLAN_TUNNEL */ |
Roopa Prabhu | 821f1b2 | 2017-10-06 22:12:37 -0700 | [diff] [blame] | 185 | + nla_total_size(1) /* IFLA_BRPORT_NEIGH_SUPPRESS */ |
Nikolay Aleksandrov | 7d850ab | 2018-05-24 11:56:48 +0300 | [diff] [blame] | 186 | + nla_total_size(1) /* IFLA_BRPORT_ISOLATED */ |
Nikolay Aleksandrov | 4ebc766 | 2015-10-06 14:11:55 +0200 | [diff] [blame] | 187 | + nla_total_size(sizeof(struct ifla_bridge_id)) /* IFLA_BRPORT_ROOT_ID */ |
Nikolay Aleksandrov | 80df9a2 | 2015-10-06 14:11:56 +0200 | [diff] [blame] | 188 | + nla_total_size(sizeof(struct ifla_bridge_id)) /* IFLA_BRPORT_BRIDGE_ID */ |
Nikolay Aleksandrov | 96f94e7 | 2015-10-06 14:11:57 +0200 | [diff] [blame] | 189 | + nla_total_size(sizeof(u16)) /* IFLA_BRPORT_DESIGNATED_PORT */ |
| 190 | + nla_total_size(sizeof(u16)) /* IFLA_BRPORT_DESIGNATED_COST */ |
Nikolay Aleksandrov | 42d452c | 2015-10-06 14:11:58 +0200 | [diff] [blame] | 191 | + nla_total_size(sizeof(u16)) /* IFLA_BRPORT_ID */ |
| 192 | + nla_total_size(sizeof(u16)) /* IFLA_BRPORT_NO */ |
Nikolay Aleksandrov | e08e838 | 2015-10-06 14:11:59 +0200 | [diff] [blame] | 193 | + nla_total_size(sizeof(u8)) /* IFLA_BRPORT_TOPOLOGY_CHANGE_ACK */ |
| 194 | + nla_total_size(sizeof(u8)) /* IFLA_BRPORT_CONFIG_PENDING */ |
Nicolas Dichtel | 12a0faa | 2016-04-25 10:25:18 +0200 | [diff] [blame] | 195 | + nla_total_size_64bit(sizeof(u64)) /* IFLA_BRPORT_MESSAGE_AGE_TIMER */ |
| 196 | + nla_total_size_64bit(sizeof(u64)) /* IFLA_BRPORT_FORWARD_DELAY_TIMER */ |
| 197 | + nla_total_size_64bit(sizeof(u64)) /* IFLA_BRPORT_HOLD_TIMER */ |
Nikolay Aleksandrov | 5d6ae47 | 2015-10-06 14:12:02 +0200 | [diff] [blame] | 198 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 199 | + nla_total_size(sizeof(u8)) /* IFLA_BRPORT_MULTICAST_ROUTER */ |
| 200 | #endif |
Nikolay Aleksandrov | 5af48b5 | 2017-09-27 16:12:44 +0300 | [diff] [blame] | 201 | + nla_total_size(sizeof(u16)) /* IFLA_BRPORT_GROUP_FWD_MASK */ |
Horatiu Vultur | 3e54442 | 2020-04-26 15:22:01 +0200 | [diff] [blame] | 202 | + nla_total_size(sizeof(u8)) /* IFLA_BRPORT_MRP_RING_OPEN */ |
Horatiu Vultur | ffb3adb | 2020-07-14 09:34:58 +0200 | [diff] [blame] | 203 | + nla_total_size(sizeof(u8)) /* IFLA_BRPORT_MRP_IN_OPEN */ |
Nikolay Aleksandrov | 2dba407 | 2021-01-26 11:35:33 +0200 | [diff] [blame] | 204 | + nla_total_size(sizeof(u32)) /* IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT */ |
| 205 | + nla_total_size(sizeof(u32)) /* IFLA_BRPORT_MCAST_EHT_HOSTS_CNT */ |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 206 | + 0; |
| 207 | } |
| 208 | |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 209 | static inline size_t br_nlmsg_size(struct net_device *dev, u32 filter_mask) |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 210 | { |
| 211 | return NLMSG_ALIGN(sizeof(struct ifinfomsg)) |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 212 | + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */ |
| 213 | + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */ |
| 214 | + nla_total_size(4) /* IFLA_MASTER */ |
| 215 | + nla_total_size(4) /* IFLA_MTU */ |
| 216 | + nla_total_size(4) /* IFLA_LINK */ |
| 217 | + nla_total_size(1) /* IFLA_OPERSTATE */ |
Roopa Prabhu | b7853d7 | 2015-02-21 20:21:51 -0800 | [diff] [blame] | 218 | + nla_total_size(br_port_info_size()) /* IFLA_PROTINFO */ |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 219 | + nla_total_size(br_get_link_af_size_filtered(dev, |
Nikolay Aleksandrov | 2756f68 | 2018-07-23 11:16:59 +0300 | [diff] [blame] | 220 | filter_mask)) /* IFLA_AF_SPEC */ |
| 221 | + nla_total_size(4); /* IFLA_BRPORT_BACKUP_PORT */ |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | static int br_port_fill_attrs(struct sk_buff *skb, |
| 225 | const struct net_bridge_port *p) |
| 226 | { |
| 227 | u8 mode = !!(p->flags & BR_HAIRPIN_MODE); |
Nikolay Aleksandrov | 2756f68 | 2018-07-23 11:16:59 +0300 | [diff] [blame] | 228 | struct net_bridge_port *backup_p; |
Nikolay Aleksandrov | 61c0a9a | 2015-10-06 14:12:00 +0200 | [diff] [blame] | 229 | u64 timerval; |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 230 | |
| 231 | if (nla_put_u8(skb, IFLA_BRPORT_STATE, p->state) || |
| 232 | nla_put_u16(skb, IFLA_BRPORT_PRIORITY, p->priority) || |
| 233 | nla_put_u32(skb, IFLA_BRPORT_COST, p->path_cost) || |
stephen hemminger | a2e01a6 | 2012-11-13 07:53:07 +0000 | [diff] [blame] | 234 | nla_put_u8(skb, IFLA_BRPORT_MODE, mode) || |
stephen hemminger | 1007dd1 | 2012-11-13 07:53:08 +0000 | [diff] [blame] | 235 | nla_put_u8(skb, IFLA_BRPORT_GUARD, !!(p->flags & BR_BPDU_GUARD)) || |
Nikolay Aleksandrov | b6cb5ac | 2016-08-31 15:36:52 +0200 | [diff] [blame] | 236 | nla_put_u8(skb, IFLA_BRPORT_PROTECT, |
| 237 | !!(p->flags & BR_ROOT_BLOCK)) || |
| 238 | nla_put_u8(skb, IFLA_BRPORT_FAST_LEAVE, |
| 239 | !!(p->flags & BR_MULTICAST_FAST_LEAVE)) || |
Felix Fietkau | 6db6f0e | 2017-01-21 21:01:32 +0100 | [diff] [blame] | 240 | nla_put_u8(skb, IFLA_BRPORT_MCAST_TO_UCAST, |
| 241 | !!(p->flags & BR_MULTICAST_TO_UNICAST)) || |
Vlad Yasevich | 867a594 | 2013-06-05 10:08:01 -0400 | [diff] [blame] | 242 | nla_put_u8(skb, IFLA_BRPORT_LEARNING, !!(p->flags & BR_LEARNING)) || |
Nikolay Aleksandrov | b6cb5ac | 2016-08-31 15:36:52 +0200 | [diff] [blame] | 243 | nla_put_u8(skb, IFLA_BRPORT_UNICAST_FLOOD, |
| 244 | !!(p->flags & BR_FLOOD)) || |
| 245 | nla_put_u8(skb, IFLA_BRPORT_MCAST_FLOOD, |
| 246 | !!(p->flags & BR_MCAST_FLOOD)) || |
Mike Manning | 99f906e | 2017-04-26 14:48:09 +0100 | [diff] [blame] | 247 | nla_put_u8(skb, IFLA_BRPORT_BCAST_FLOOD, |
| 248 | !!(p->flags & BR_BCAST_FLOOD)) || |
Jouni Malinen | 842a9ae | 2015-03-04 12:54:21 +0200 | [diff] [blame] | 249 | nla_put_u8(skb, IFLA_BRPORT_PROXYARP, !!(p->flags & BR_PROXYARP)) || |
| 250 | nla_put_u8(skb, IFLA_BRPORT_PROXYARP_WIFI, |
Nikolay Aleksandrov | 4ebc766 | 2015-10-06 14:11:55 +0200 | [diff] [blame] | 251 | !!(p->flags & BR_PROXYARP_WIFI)) || |
| 252 | nla_put(skb, IFLA_BRPORT_ROOT_ID, sizeof(struct ifla_bridge_id), |
Nikolay Aleksandrov | 80df9a2 | 2015-10-06 14:11:56 +0200 | [diff] [blame] | 253 | &p->designated_root) || |
| 254 | nla_put(skb, IFLA_BRPORT_BRIDGE_ID, sizeof(struct ifla_bridge_id), |
Nikolay Aleksandrov | 96f94e7 | 2015-10-06 14:11:57 +0200 | [diff] [blame] | 255 | &p->designated_bridge) || |
| 256 | nla_put_u16(skb, IFLA_BRPORT_DESIGNATED_PORT, p->designated_port) || |
Nikolay Aleksandrov | 42d452c | 2015-10-06 14:11:58 +0200 | [diff] [blame] | 257 | nla_put_u16(skb, IFLA_BRPORT_DESIGNATED_COST, p->designated_cost) || |
| 258 | nla_put_u16(skb, IFLA_BRPORT_ID, p->port_id) || |
Nikolay Aleksandrov | e08e838 | 2015-10-06 14:11:59 +0200 | [diff] [blame] | 259 | nla_put_u16(skb, IFLA_BRPORT_NO, p->port_no) || |
| 260 | nla_put_u8(skb, IFLA_BRPORT_TOPOLOGY_CHANGE_ACK, |
| 261 | p->topology_change_ack) || |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 262 | nla_put_u8(skb, IFLA_BRPORT_CONFIG_PENDING, p->config_pending) || |
| 263 | nla_put_u8(skb, IFLA_BRPORT_VLAN_TUNNEL, !!(p->flags & |
Nikolay Aleksandrov | 5af48b5 | 2017-09-27 16:12:44 +0300 | [diff] [blame] | 264 | BR_VLAN_TUNNEL)) || |
Roopa Prabhu | 821f1b2 | 2017-10-06 22:12:37 -0700 | [diff] [blame] | 265 | nla_put_u16(skb, IFLA_BRPORT_GROUP_FWD_MASK, p->group_fwd_mask) || |
| 266 | nla_put_u8(skb, IFLA_BRPORT_NEIGH_SUPPRESS, |
Nikolay Aleksandrov | 7d850ab | 2018-05-24 11:56:48 +0300 | [diff] [blame] | 267 | !!(p->flags & BR_NEIGH_SUPPRESS)) || |
Horatiu Vultur | 3e54442 | 2020-04-26 15:22:01 +0200 | [diff] [blame] | 268 | nla_put_u8(skb, IFLA_BRPORT_MRP_RING_OPEN, !!(p->flags & |
| 269 | BR_MRP_LOST_CONT)) || |
Horatiu Vultur | ffb3adb | 2020-07-14 09:34:58 +0200 | [diff] [blame] | 270 | nla_put_u8(skb, IFLA_BRPORT_MRP_IN_OPEN, |
| 271 | !!(p->flags & BR_MRP_LOST_IN_CONT)) || |
Nikolay Aleksandrov | 7d850ab | 2018-05-24 11:56:48 +0300 | [diff] [blame] | 272 | nla_put_u8(skb, IFLA_BRPORT_ISOLATED, !!(p->flags & BR_ISOLATED))) |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 273 | return -EMSGSIZE; |
| 274 | |
Nikolay Aleksandrov | 61c0a9a | 2015-10-06 14:12:00 +0200 | [diff] [blame] | 275 | timerval = br_timer_value(&p->message_age_timer); |
Nicolas Dichtel | 12a0faa | 2016-04-25 10:25:18 +0200 | [diff] [blame] | 276 | if (nla_put_u64_64bit(skb, IFLA_BRPORT_MESSAGE_AGE_TIMER, timerval, |
| 277 | IFLA_BRPORT_PAD)) |
Nikolay Aleksandrov | 61c0a9a | 2015-10-06 14:12:00 +0200 | [diff] [blame] | 278 | return -EMSGSIZE; |
| 279 | timerval = br_timer_value(&p->forward_delay_timer); |
Nicolas Dichtel | 12a0faa | 2016-04-25 10:25:18 +0200 | [diff] [blame] | 280 | if (nla_put_u64_64bit(skb, IFLA_BRPORT_FORWARD_DELAY_TIMER, timerval, |
| 281 | IFLA_BRPORT_PAD)) |
Nikolay Aleksandrov | 61c0a9a | 2015-10-06 14:12:00 +0200 | [diff] [blame] | 282 | return -EMSGSIZE; |
| 283 | timerval = br_timer_value(&p->hold_timer); |
Nicolas Dichtel | 12a0faa | 2016-04-25 10:25:18 +0200 | [diff] [blame] | 284 | if (nla_put_u64_64bit(skb, IFLA_BRPORT_HOLD_TIMER, timerval, |
| 285 | IFLA_BRPORT_PAD)) |
Nikolay Aleksandrov | 61c0a9a | 2015-10-06 14:12:00 +0200 | [diff] [blame] | 286 | return -EMSGSIZE; |
| 287 | |
Nikolay Aleksandrov | 5d6ae47 | 2015-10-06 14:12:02 +0200 | [diff] [blame] | 288 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 289 | if (nla_put_u8(skb, IFLA_BRPORT_MULTICAST_ROUTER, |
Nikolay Aleksandrov | 9632233 | 2021-07-19 20:06:23 +0300 | [diff] [blame] | 290 | p->multicast_ctx.multicast_router) || |
Nikolay Aleksandrov | 2dba407 | 2021-01-26 11:35:33 +0200 | [diff] [blame] | 291 | nla_put_u32(skb, IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT, |
| 292 | p->multicast_eht_hosts_limit) || |
| 293 | nla_put_u32(skb, IFLA_BRPORT_MCAST_EHT_HOSTS_CNT, |
| 294 | p->multicast_eht_hosts_cnt)) |
Nikolay Aleksandrov | 5d6ae47 | 2015-10-06 14:12:02 +0200 | [diff] [blame] | 295 | return -EMSGSIZE; |
| 296 | #endif |
| 297 | |
Nikolay Aleksandrov | 2756f68 | 2018-07-23 11:16:59 +0300 | [diff] [blame] | 298 | /* we might be called only with br->lock */ |
| 299 | rcu_read_lock(); |
| 300 | backup_p = rcu_dereference(p->backup_port); |
| 301 | if (backup_p) |
| 302 | nla_put_u32(skb, IFLA_BRPORT_BACKUP_PORT, |
| 303 | backup_p->dev->ifindex); |
| 304 | rcu_read_unlock(); |
| 305 | |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 306 | return 0; |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 307 | } |
| 308 | |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 309 | static int br_fill_ifvlaninfo_range(struct sk_buff *skb, u16 vid_start, |
| 310 | u16 vid_end, u16 flags) |
| 311 | { |
| 312 | struct bridge_vlan_info vinfo; |
| 313 | |
| 314 | if ((vid_end - vid_start) > 0) { |
| 315 | /* add range to skb */ |
| 316 | vinfo.vid = vid_start; |
| 317 | vinfo.flags = flags | BRIDGE_VLAN_INFO_RANGE_BEGIN; |
| 318 | if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO, |
| 319 | sizeof(vinfo), &vinfo)) |
| 320 | goto nla_put_failure; |
| 321 | |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 322 | vinfo.vid = vid_end; |
| 323 | vinfo.flags = flags | BRIDGE_VLAN_INFO_RANGE_END; |
| 324 | if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO, |
| 325 | sizeof(vinfo), &vinfo)) |
| 326 | goto nla_put_failure; |
| 327 | } else { |
| 328 | vinfo.vid = vid_start; |
| 329 | vinfo.flags = flags; |
| 330 | if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO, |
| 331 | sizeof(vinfo), &vinfo)) |
| 332 | goto nla_put_failure; |
| 333 | } |
| 334 | |
| 335 | return 0; |
| 336 | |
| 337 | nla_put_failure: |
| 338 | return -EMSGSIZE; |
| 339 | } |
| 340 | |
| 341 | static int br_fill_ifvlaninfo_compressed(struct sk_buff *skb, |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 342 | struct net_bridge_vlan_group *vg) |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 343 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 344 | struct net_bridge_vlan *v; |
| 345 | u16 vid_range_start = 0, vid_range_end = 0, vid_range_flags = 0; |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 346 | u16 flags, pvid; |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 347 | int err = 0; |
| 348 | |
| 349 | /* Pack IFLA_BRIDGE_VLAN_INFO's for every vlan |
| 350 | * and mark vlan info with begin and end flags |
| 351 | * if vlaninfo represents a range |
| 352 | */ |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 353 | pvid = br_get_pvid(vg); |
Nikolay Aleksandrov | e9c953e | 2015-10-12 21:47:03 +0200 | [diff] [blame] | 354 | list_for_each_entry_rcu(v, &vg->vlan_list, vlist) { |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 355 | flags = 0; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 356 | if (!br_vlan_should_use(v)) |
| 357 | continue; |
| 358 | if (v->vid == pvid) |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 359 | flags |= BRIDGE_VLAN_INFO_PVID; |
| 360 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 361 | if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED) |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 362 | flags |= BRIDGE_VLAN_INFO_UNTAGGED; |
| 363 | |
| 364 | if (vid_range_start == 0) { |
| 365 | goto initvars; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 366 | } else if ((v->vid - vid_range_end) == 1 && |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 367 | flags == vid_range_flags) { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 368 | vid_range_end = v->vid; |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 369 | continue; |
| 370 | } else { |
| 371 | err = br_fill_ifvlaninfo_range(skb, vid_range_start, |
| 372 | vid_range_end, |
| 373 | vid_range_flags); |
| 374 | if (err) |
| 375 | return err; |
| 376 | } |
| 377 | |
| 378 | initvars: |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 379 | vid_range_start = v->vid; |
| 380 | vid_range_end = v->vid; |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 381 | vid_range_flags = flags; |
| 382 | } |
| 383 | |
Roopa Prabhu | 0fe6de4 | 2015-01-12 16:25:28 -0800 | [diff] [blame] | 384 | if (vid_range_start != 0) { |
| 385 | /* Call it once more to send any left over vlans */ |
| 386 | err = br_fill_ifvlaninfo_range(skb, vid_range_start, |
| 387 | vid_range_end, |
| 388 | vid_range_flags); |
| 389 | if (err) |
| 390 | return err; |
| 391 | } |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | static int br_fill_ifvlaninfo(struct sk_buff *skb, |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 397 | struct net_bridge_vlan_group *vg) |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 398 | { |
| 399 | struct bridge_vlan_info vinfo; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 400 | struct net_bridge_vlan *v; |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 401 | u16 pvid; |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 402 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 403 | pvid = br_get_pvid(vg); |
Nikolay Aleksandrov | e9c953e | 2015-10-12 21:47:03 +0200 | [diff] [blame] | 404 | list_for_each_entry_rcu(v, &vg->vlan_list, vlist) { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 405 | if (!br_vlan_should_use(v)) |
| 406 | continue; |
| 407 | |
| 408 | vinfo.vid = v->vid; |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 409 | vinfo.flags = 0; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 410 | if (v->vid == pvid) |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 411 | vinfo.flags |= BRIDGE_VLAN_INFO_PVID; |
| 412 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 413 | if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED) |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 414 | vinfo.flags |= BRIDGE_VLAN_INFO_UNTAGGED; |
| 415 | |
| 416 | if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO, |
| 417 | sizeof(vinfo), &vinfo)) |
| 418 | goto nla_put_failure; |
| 419 | } |
| 420 | |
| 421 | return 0; |
| 422 | |
| 423 | nla_put_failure: |
| 424 | return -EMSGSIZE; |
| 425 | } |
| 426 | |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 427 | /* |
| 428 | * Create one netlink message for one interface |
| 429 | * Contains port and master info as well as carrier and bridge state. |
| 430 | */ |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 431 | static int br_fill_ifinfo(struct sk_buff *skb, |
Nikolay Aleksandrov | 9289906 | 2017-11-01 12:18:13 +0200 | [diff] [blame] | 432 | const struct net_bridge_port *port, |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 433 | u32 pid, u32 seq, int event, unsigned int flags, |
Henrik Bjoernlund | b6d0425 | 2020-10-27 10:02:51 +0000 | [diff] [blame] | 434 | u32 filter_mask, const struct net_device *dev, |
| 435 | bool getlink) |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 436 | { |
Nikolay Aleksandrov | 9289906 | 2017-11-01 12:18:13 +0200 | [diff] [blame] | 437 | u8 operstate = netif_running(dev) ? dev->operstate : IF_OPER_DOWN; |
Henrik Bjoernlund | b6c02ef | 2020-10-07 12:07:00 +0000 | [diff] [blame] | 438 | struct nlattr *af = NULL; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 439 | struct net_bridge *br; |
Thomas Graf | 7468596 | 2006-11-20 16:20:22 -0800 | [diff] [blame] | 440 | struct ifinfomsg *hdr; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 441 | struct nlmsghdr *nlh; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 442 | |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 443 | if (port) |
| 444 | br = port->br; |
| 445 | else |
| 446 | br = netdev_priv(dev); |
| 447 | |
stephen hemminger | 28a16c9 | 2010-05-10 09:31:09 +0000 | [diff] [blame] | 448 | br_debug(br, "br_fill_info event %d port %s master %s\n", |
| 449 | event, dev->name, br->dev->name); |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 450 | |
Thomas Graf | 7468596 | 2006-11-20 16:20:22 -0800 | [diff] [blame] | 451 | nlh = nlmsg_put(skb, pid, seq, event, sizeof(*hdr), flags); |
| 452 | if (nlh == NULL) |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 453 | return -EMSGSIZE; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 454 | |
Thomas Graf | 7468596 | 2006-11-20 16:20:22 -0800 | [diff] [blame] | 455 | hdr = nlmsg_data(nlh); |
| 456 | hdr->ifi_family = AF_BRIDGE; |
| 457 | hdr->__ifi_pad = 0; |
| 458 | hdr->ifi_type = dev->type; |
| 459 | hdr->ifi_index = dev->ifindex; |
| 460 | hdr->ifi_flags = dev_get_flags(dev); |
| 461 | hdr->ifi_change = 0; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 462 | |
David S. Miller | 2eb812e | 2012-04-01 20:49:54 -0400 | [diff] [blame] | 463 | if (nla_put_string(skb, IFLA_IFNAME, dev->name) || |
| 464 | nla_put_u32(skb, IFLA_MASTER, br->dev->ifindex) || |
| 465 | nla_put_u32(skb, IFLA_MTU, dev->mtu) || |
| 466 | nla_put_u8(skb, IFLA_OPERSTATE, operstate) || |
| 467 | (dev->addr_len && |
| 468 | nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) || |
Nicolas Dichtel | a54acb3 | 2015-04-02 17:07:00 +0200 | [diff] [blame] | 469 | (dev->ifindex != dev_get_iflink(dev) && |
| 470 | nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev)))) |
David S. Miller | 2eb812e | 2012-04-01 20:49:54 -0400 | [diff] [blame] | 471 | goto nla_put_failure; |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 472 | |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 473 | if (event == RTM_NEWLINK && port) { |
Michal Kubecek | f78c603 | 2019-04-26 11:13:12 +0200 | [diff] [blame] | 474 | struct nlattr *nest; |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 475 | |
Michal Kubecek | f78c603 | 2019-04-26 11:13:12 +0200 | [diff] [blame] | 476 | nest = nla_nest_start(skb, IFLA_PROTINFO); |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 477 | if (nest == NULL || br_port_fill_attrs(skb, port) < 0) |
| 478 | goto nla_put_failure; |
| 479 | nla_nest_end(skb, nest); |
| 480 | } |
| 481 | |
Henrik Bjoernlund | b6c02ef | 2020-10-07 12:07:00 +0000 | [diff] [blame] | 482 | if (filter_mask & (RTEXT_FILTER_BRVLAN | |
| 483 | RTEXT_FILTER_BRVLAN_COMPRESSED | |
Henrik Bjoernlund | 5e312fc | 2020-10-27 10:02:49 +0000 | [diff] [blame] | 484 | RTEXT_FILTER_MRP | |
Henrik Bjoernlund | e77824d | 2020-10-27 10:02:50 +0000 | [diff] [blame] | 485 | RTEXT_FILTER_CFM_CONFIG | |
| 486 | RTEXT_FILTER_CFM_STATUS)) { |
Henrik Bjoernlund | b6c02ef | 2020-10-07 12:07:00 +0000 | [diff] [blame] | 487 | af = nla_nest_start_noflag(skb, IFLA_AF_SPEC); |
| 488 | if (!af) |
| 489 | goto nla_put_failure; |
| 490 | } |
| 491 | |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 492 | /* Check if the VID information is requested */ |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 493 | if ((filter_mask & RTEXT_FILTER_BRVLAN) || |
| 494 | (filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)) { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 495 | struct net_bridge_vlan_group *vg; |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 496 | int err; |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 497 | |
Nikolay Aleksandrov | e9c953e | 2015-10-12 21:47:03 +0200 | [diff] [blame] | 498 | /* RCU needed because of the VLAN locking rules (rcu || rtnl) */ |
| 499 | rcu_read_lock(); |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 500 | if (port) |
Nikolay Aleksandrov | e9c953e | 2015-10-12 21:47:03 +0200 | [diff] [blame] | 501 | vg = nbp_vlan_group_rcu(port); |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 502 | else |
Nikolay Aleksandrov | e9c953e | 2015-10-12 21:47:03 +0200 | [diff] [blame] | 503 | vg = br_vlan_group_rcu(br); |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 504 | |
Nikolay Aleksandrov | e9c953e | 2015-10-12 21:47:03 +0200 | [diff] [blame] | 505 | if (!vg || !vg->num_vlans) { |
| 506 | rcu_read_unlock(); |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 507 | goto done; |
Nikolay Aleksandrov | e9c953e | 2015-10-12 21:47:03 +0200 | [diff] [blame] | 508 | } |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 509 | if (filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED) |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 510 | err = br_fill_ifvlaninfo_compressed(skb, vg); |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 511 | else |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 512 | err = br_fill_ifvlaninfo(skb, vg); |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 513 | |
| 514 | if (port && (port->flags & BR_VLAN_TUNNEL)) |
| 515 | err = br_fill_vlan_tunnel_info(skb, vg); |
Nikolay Aleksandrov | e9c953e | 2015-10-12 21:47:03 +0200 | [diff] [blame] | 516 | rcu_read_unlock(); |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 517 | if (err) |
| 518 | goto nla_put_failure; |
Horatiu Vultur | 36a8e8e | 2020-07-02 10:13:07 +0200 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | if (filter_mask & RTEXT_FILTER_MRP) { |
Horatiu Vultur | 36a8e8e | 2020-07-02 10:13:07 +0200 | [diff] [blame] | 522 | int err; |
| 523 | |
| 524 | if (!br_mrp_enabled(br) || port) |
| 525 | goto done; |
| 526 | |
Horatiu Vultur | 36a8e8e | 2020-07-02 10:13:07 +0200 | [diff] [blame] | 527 | rcu_read_lock(); |
| 528 | err = br_mrp_fill_info(skb, br); |
| 529 | rcu_read_unlock(); |
| 530 | |
| 531 | if (err) |
| 532 | goto nla_put_failure; |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 533 | } |
| 534 | |
Henrik Bjoernlund | e77824d | 2020-10-27 10:02:50 +0000 | [diff] [blame] | 535 | if (filter_mask & (RTEXT_FILTER_CFM_CONFIG | RTEXT_FILTER_CFM_STATUS)) { |
Henrik Bjoernlund | 5e312fc | 2020-10-27 10:02:49 +0000 | [diff] [blame] | 536 | struct nlattr *cfm_nest = NULL; |
| 537 | int err; |
| 538 | |
| 539 | if (!br_cfm_created(br) || port) |
| 540 | goto done; |
| 541 | |
| 542 | cfm_nest = nla_nest_start(skb, IFLA_BRIDGE_CFM); |
| 543 | if (!cfm_nest) |
| 544 | goto nla_put_failure; |
| 545 | |
| 546 | if (filter_mask & RTEXT_FILTER_CFM_CONFIG) { |
| 547 | rcu_read_lock(); |
| 548 | err = br_cfm_config_fill_info(skb, br); |
| 549 | rcu_read_unlock(); |
| 550 | if (err) |
| 551 | goto nla_put_failure; |
| 552 | } |
| 553 | |
Henrik Bjoernlund | e77824d | 2020-10-27 10:02:50 +0000 | [diff] [blame] | 554 | if (filter_mask & RTEXT_FILTER_CFM_STATUS) { |
| 555 | rcu_read_lock(); |
Henrik Bjoernlund | b6d0425 | 2020-10-27 10:02:51 +0000 | [diff] [blame] | 556 | err = br_cfm_status_fill_info(skb, br, getlink); |
Henrik Bjoernlund | e77824d | 2020-10-27 10:02:50 +0000 | [diff] [blame] | 557 | rcu_read_unlock(); |
| 558 | if (err) |
| 559 | goto nla_put_failure; |
| 560 | } |
| 561 | |
Henrik Bjoernlund | 5e312fc | 2020-10-27 10:02:49 +0000 | [diff] [blame] | 562 | nla_nest_end(skb, cfm_nest); |
| 563 | } |
| 564 | |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 565 | done: |
Henrik Bjoernlund | b6c02ef | 2020-10-07 12:07:00 +0000 | [diff] [blame] | 566 | if (af) |
| 567 | nla_nest_end(skb, af); |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 568 | nlmsg_end(skb, nlh); |
| 569 | return 0; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 570 | |
Thomas Graf | 7468596 | 2006-11-20 16:20:22 -0800 | [diff] [blame] | 571 | nla_put_failure: |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 572 | nlmsg_cancel(skb, nlh); |
| 573 | return -EMSGSIZE; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Henrik Bjoernlund | b6d0425 | 2020-10-27 10:02:51 +0000 | [diff] [blame] | 576 | void br_info_notify(int event, const struct net_bridge *br, |
| 577 | const struct net_bridge_port *port, u32 filter) |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 578 | { |
Nikolay Aleksandrov | 9289906 | 2017-11-01 12:18:13 +0200 | [diff] [blame] | 579 | struct net_device *dev; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 580 | struct sk_buff *skb; |
Thomas Graf | 280a306 | 2006-08-15 00:36:28 -0700 | [diff] [blame] | 581 | int err = -ENOBUFS; |
Nikolay Aleksandrov | 9289906 | 2017-11-01 12:18:13 +0200 | [diff] [blame] | 582 | struct net *net; |
| 583 | u16 port_no = 0; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 584 | |
Nikolay Aleksandrov | 9289906 | 2017-11-01 12:18:13 +0200 | [diff] [blame] | 585 | if (WARN_ON(!port && !br)) |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 586 | return; |
| 587 | |
Nikolay Aleksandrov | 9289906 | 2017-11-01 12:18:13 +0200 | [diff] [blame] | 588 | if (port) { |
| 589 | dev = port->dev; |
| 590 | br = port->br; |
| 591 | port_no = port->port_no; |
| 592 | } else { |
| 593 | dev = br->dev; |
| 594 | } |
stephen hemminger | 28a16c9 | 2010-05-10 09:31:09 +0000 | [diff] [blame] | 595 | |
Nikolay Aleksandrov | 9289906 | 2017-11-01 12:18:13 +0200 | [diff] [blame] | 596 | net = dev_net(dev); |
| 597 | br_debug(br, "port %u(%s) event %d\n", port_no, dev->name, event); |
| 598 | |
| 599 | skb = nlmsg_new(br_nlmsg_size(dev, filter), GFP_ATOMIC); |
Thomas Graf | 280a306 | 2006-08-15 00:36:28 -0700 | [diff] [blame] | 600 | if (skb == NULL) |
| 601 | goto errout; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 602 | |
Henrik Bjoernlund | b6d0425 | 2020-10-27 10:02:51 +0000 | [diff] [blame] | 603 | err = br_fill_ifinfo(skb, port, 0, 0, event, 0, filter, dev, false); |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 604 | if (err < 0) { |
| 605 | /* -EMSGSIZE implies BUG in br_nlmsg_size() */ |
| 606 | WARN_ON(err == -EMSGSIZE); |
| 607 | kfree_skb(skb); |
| 608 | goto errout; |
| 609 | } |
Pablo Neira Ayuso | 1ce85fe | 2009-02-24 23:18:28 -0800 | [diff] [blame] | 610 | rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC); |
| 611 | return; |
Thomas Graf | 280a306 | 2006-08-15 00:36:28 -0700 | [diff] [blame] | 612 | errout: |
tanxiaojun | 87e823b | 2013-12-19 13:28:10 +0800 | [diff] [blame] | 613 | rtnl_set_sk_err(net, RTNLGRP_LINK, err); |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Henrik Bjoernlund | b6d0425 | 2020-10-27 10:02:51 +0000 | [diff] [blame] | 616 | /* Notify listeners of a change in bridge or port information */ |
| 617 | void br_ifinfo_notify(int event, const struct net_bridge *br, |
| 618 | const struct net_bridge_port *port) |
| 619 | { |
| 620 | u32 filter = RTEXT_FILTER_BRVLAN_COMPRESSED; |
| 621 | |
| 622 | return br_info_notify(event, br, port, filter); |
| 623 | } |
| 624 | |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 625 | /* |
| 626 | * Dump information about all ports, in response to GETLINK |
| 627 | */ |
John Fastabend | e5a55a8 | 2012-10-24 08:12:57 +0000 | [diff] [blame] | 628 | int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 629 | struct net_device *dev, u32 filter_mask, int nlflags) |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 630 | { |
Hong Zhiguo | 1fb1754 | 2013-09-14 22:42:27 +0800 | [diff] [blame] | 631 | struct net_bridge_port *port = br_port_get_rtnl(dev); |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 632 | |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 633 | if (!port && !(filter_mask & RTEXT_FILTER_BRVLAN) && |
Horatiu Vultur | 36a8e8e | 2020-07-02 10:13:07 +0200 | [diff] [blame] | 634 | !(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED) && |
Henrik Bjoernlund | 5e312fc | 2020-10-27 10:02:49 +0000 | [diff] [blame] | 635 | !(filter_mask & RTEXT_FILTER_MRP) && |
Henrik Bjoernlund | e77824d | 2020-10-27 10:02:50 +0000 | [diff] [blame] | 636 | !(filter_mask & RTEXT_FILTER_CFM_CONFIG) && |
| 637 | !(filter_mask & RTEXT_FILTER_CFM_STATUS)) |
Dan Carpenter | 1b846f9 | 2015-01-21 12:22:35 +0300 | [diff] [blame] | 638 | return 0; |
stephen hemminger | b5ed54e | 2010-11-15 06:38:13 +0000 | [diff] [blame] | 639 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 640 | return br_fill_ifinfo(skb, port, pid, seq, RTM_NEWLINK, nlflags, |
Henrik Bjoernlund | b6d0425 | 2020-10-27 10:02:51 +0000 | [diff] [blame] | 641 | filter_mask, dev, true); |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 642 | } |
| 643 | |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 644 | static int br_vlan_info(struct net_bridge *br, struct net_bridge_port *p, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 645 | int cmd, struct bridge_vlan_info *vinfo, bool *changed, |
| 646 | struct netlink_ext_ack *extack) |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 647 | { |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 648 | bool curr_change; |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 649 | int err = 0; |
| 650 | |
| 651 | switch (cmd) { |
| 652 | case RTM_SETLINK: |
| 653 | if (p) { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 654 | /* if the MASTER flag is set this will act on the global |
| 655 | * per-VLAN entry as well |
| 656 | */ |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 657 | err = nbp_vlan_add(p, vinfo->vid, vinfo->flags, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 658 | &curr_change, extack); |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 659 | } else { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 660 | vinfo->flags |= BRIDGE_VLAN_INFO_BRENTRY; |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 661 | err = br_vlan_add(br, vinfo->vid, vinfo->flags, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 662 | &curr_change, extack); |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 663 | } |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 664 | if (curr_change) |
Nikolay Aleksandrov | e19b42a | 2017-10-27 13:19:36 +0300 | [diff] [blame] | 665 | *changed = true; |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 666 | break; |
| 667 | |
| 668 | case RTM_DELLINK: |
| 669 | if (p) { |
Nikolay Aleksandrov | e19b42a | 2017-10-27 13:19:36 +0300 | [diff] [blame] | 670 | if (!nbp_vlan_delete(p, vinfo->vid)) |
| 671 | *changed = true; |
| 672 | |
| 673 | if ((vinfo->flags & BRIDGE_VLAN_INFO_MASTER) && |
| 674 | !br_vlan_delete(p->br, vinfo->vid)) |
| 675 | *changed = true; |
| 676 | } else if (!br_vlan_delete(br, vinfo->vid)) { |
| 677 | *changed = true; |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 678 | } |
| 679 | break; |
| 680 | } |
| 681 | |
| 682 | return err; |
| 683 | } |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 684 | |
Nikolay Aleksandrov | f26b296 | 2020-01-14 19:56:10 +0200 | [diff] [blame] | 685 | int br_process_vlan_info(struct net_bridge *br, |
| 686 | struct net_bridge_port *p, int cmd, |
| 687 | struct bridge_vlan_info *vinfo_curr, |
| 688 | struct bridge_vlan_info **vinfo_last, |
| 689 | bool *changed, |
| 690 | struct netlink_ext_ack *extack) |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 691 | { |
Nikolay Aleksandrov | f545923 | 2020-01-14 19:56:14 +0200 | [diff] [blame] | 692 | int err, rtm_cmd; |
| 693 | |
Nikolay Aleksandrov | 8f4cc94 | 2020-01-14 19:56:08 +0200 | [diff] [blame] | 694 | if (!br_vlan_valid_id(vinfo_curr->vid, extack)) |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 695 | return -EINVAL; |
| 696 | |
Nikolay Aleksandrov | f545923 | 2020-01-14 19:56:14 +0200 | [diff] [blame] | 697 | /* needed for vlan-only NEWVLAN/DELVLAN notifications */ |
| 698 | rtm_cmd = br_afspec_cmd_to_rtm(cmd); |
| 699 | |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 700 | if (vinfo_curr->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) { |
Nikolay Aleksandrov | 8f4cc94 | 2020-01-14 19:56:08 +0200 | [diff] [blame] | 701 | if (!br_vlan_valid_range(vinfo_curr, *vinfo_last, extack)) |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 702 | return -EINVAL; |
| 703 | *vinfo_last = vinfo_curr; |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 704 | return 0; |
| 705 | } |
| 706 | |
| 707 | if (*vinfo_last) { |
| 708 | struct bridge_vlan_info tmp_vinfo; |
Nikolay Aleksandrov | f545923 | 2020-01-14 19:56:14 +0200 | [diff] [blame] | 709 | int v, v_change_start = 0; |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 710 | |
Nikolay Aleksandrov | 8f4cc94 | 2020-01-14 19:56:08 +0200 | [diff] [blame] | 711 | if (!br_vlan_valid_range(vinfo_curr, *vinfo_last, extack)) |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 712 | return -EINVAL; |
| 713 | |
| 714 | memcpy(&tmp_vinfo, *vinfo_last, |
| 715 | sizeof(struct bridge_vlan_info)); |
| 716 | for (v = (*vinfo_last)->vid; v <= vinfo_curr->vid; v++) { |
Nikolay Aleksandrov | f545923 | 2020-01-14 19:56:14 +0200 | [diff] [blame] | 717 | bool curr_change = false; |
| 718 | |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 719 | tmp_vinfo.vid = v; |
Nikolay Aleksandrov | f545923 | 2020-01-14 19:56:14 +0200 | [diff] [blame] | 720 | err = br_vlan_info(br, p, cmd, &tmp_vinfo, &curr_change, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 721 | extack); |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 722 | if (err) |
| 723 | break; |
Nikolay Aleksandrov | f545923 | 2020-01-14 19:56:14 +0200 | [diff] [blame] | 724 | if (curr_change) { |
| 725 | *changed = curr_change; |
| 726 | if (!v_change_start) |
| 727 | v_change_start = v; |
| 728 | } else { |
| 729 | /* nothing to notify yet */ |
| 730 | if (!v_change_start) |
| 731 | continue; |
| 732 | br_vlan_notify(br, p, v_change_start, |
| 733 | v - 1, rtm_cmd); |
| 734 | v_change_start = 0; |
| 735 | } |
Ido Schimmel | 7979457 | 2020-04-30 22:38:45 +0300 | [diff] [blame] | 736 | cond_resched(); |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 737 | } |
Nikolay Aleksandrov | f545923 | 2020-01-14 19:56:14 +0200 | [diff] [blame] | 738 | /* v_change_start is set only if the last/whole range changed */ |
| 739 | if (v_change_start) |
| 740 | br_vlan_notify(br, p, v_change_start, |
| 741 | v - 1, rtm_cmd); |
| 742 | |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 743 | *vinfo_last = NULL; |
| 744 | |
Nikolay Aleksandrov | 66c5451 | 2017-10-19 20:17:32 +0300 | [diff] [blame] | 745 | return err; |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 746 | } |
| 747 | |
Nikolay Aleksandrov | f545923 | 2020-01-14 19:56:14 +0200 | [diff] [blame] | 748 | err = br_vlan_info(br, p, cmd, vinfo_curr, changed, extack); |
| 749 | if (*changed) |
| 750 | br_vlan_notify(br, p, vinfo_curr->vid, 0, rtm_cmd); |
| 751 | |
| 752 | return err; |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 753 | } |
| 754 | |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 755 | static int br_afspec(struct net_bridge *br, |
| 756 | struct net_bridge_port *p, |
| 757 | struct nlattr *af_spec, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 758 | int cmd, bool *changed, |
| 759 | struct netlink_ext_ack *extack) |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 760 | { |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 761 | struct bridge_vlan_info *vinfo_curr = NULL; |
| 762 | struct bridge_vlan_info *vinfo_last = NULL; |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 763 | struct nlattr *attr; |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 764 | struct vtunnel_info tinfo_last = {}; |
| 765 | struct vtunnel_info tinfo_curr = {}; |
| 766 | int err = 0, rem; |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 767 | |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 768 | nla_for_each_nested(attr, af_spec, rem) { |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 769 | err = 0; |
| 770 | switch (nla_type(attr)) { |
| 771 | case IFLA_BRIDGE_VLAN_TUNNEL_INFO: |
Nikolay Aleksandrov | 1020ce3 | 2017-06-06 01:26:24 +0300 | [diff] [blame] | 772 | if (!p || !(p->flags & BR_VLAN_TUNNEL)) |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 773 | return -EINVAL; |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 774 | err = br_parse_vlan_tunnel_info(attr, &tinfo_curr); |
| 775 | if (err) |
| 776 | return err; |
| 777 | err = br_process_vlan_tunnel_info(br, p, cmd, |
| 778 | &tinfo_curr, |
Nikolay Aleksandrov | e19b42a | 2017-10-27 13:19:36 +0300 | [diff] [blame] | 779 | &tinfo_last, |
| 780 | changed); |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 781 | if (err) |
| 782 | return err; |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 783 | break; |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 784 | case IFLA_BRIDGE_VLAN_INFO: |
| 785 | if (nla_len(attr) != sizeof(struct bridge_vlan_info)) |
| 786 | return -EINVAL; |
| 787 | vinfo_curr = nla_data(attr); |
| 788 | err = br_process_vlan_info(br, p, cmd, vinfo_curr, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 789 | &vinfo_last, changed, |
| 790 | extack); |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 791 | if (err) |
| 792 | return err; |
| 793 | break; |
Horatiu Vultur | 6536993 | 2020-04-26 15:22:07 +0200 | [diff] [blame] | 794 | case IFLA_BRIDGE_MRP: |
| 795 | err = br_mrp_parse(br, p, attr, cmd, extack); |
| 796 | if (err) |
| 797 | return err; |
| 798 | break; |
Henrik Bjoernlund | 2be665c | 2020-10-27 10:02:48 +0000 | [diff] [blame] | 799 | case IFLA_BRIDGE_CFM: |
| 800 | err = br_cfm_parse(br, p, attr, cmd, extack); |
| 801 | if (err) |
| 802 | return err; |
| 803 | break; |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 804 | } |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | return err; |
| 808 | } |
| 809 | |
Jiri Pirko | 3ac636b | 2014-09-05 15:51:30 +0200 | [diff] [blame] | 810 | static const struct nla_policy br_port_policy[IFLA_BRPORT_MAX + 1] = { |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 811 | [IFLA_BRPORT_STATE] = { .type = NLA_U8 }, |
| 812 | [IFLA_BRPORT_COST] = { .type = NLA_U32 }, |
| 813 | [IFLA_BRPORT_PRIORITY] = { .type = NLA_U16 }, |
| 814 | [IFLA_BRPORT_MODE] = { .type = NLA_U8 }, |
stephen hemminger | a2e01a6 | 2012-11-13 07:53:07 +0000 | [diff] [blame] | 815 | [IFLA_BRPORT_GUARD] = { .type = NLA_U8 }, |
stephen hemminger | 1007dd1 | 2012-11-13 07:53:08 +0000 | [diff] [blame] | 816 | [IFLA_BRPORT_PROTECT] = { .type = NLA_U8 }, |
Thomas Graf | 6f705d8 | 2014-11-26 13:42:19 +0100 | [diff] [blame] | 817 | [IFLA_BRPORT_FAST_LEAVE]= { .type = NLA_U8 }, |
Vlad Yasevich | 9ba1889 | 2013-06-05 10:08:00 -0400 | [diff] [blame] | 818 | [IFLA_BRPORT_LEARNING] = { .type = NLA_U8 }, |
Vlad Yasevich | 867a594 | 2013-06-05 10:08:01 -0400 | [diff] [blame] | 819 | [IFLA_BRPORT_UNICAST_FLOOD] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | 355b9f9 | 2015-08-04 19:06:32 +0200 | [diff] [blame] | 820 | [IFLA_BRPORT_PROXYARP] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | 786c207 | 2015-08-04 19:06:33 +0200 | [diff] [blame] | 821 | [IFLA_BRPORT_PROXYARP_WIFI] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | 5d6ae47 | 2015-10-06 14:12:02 +0200 | [diff] [blame] | 822 | [IFLA_BRPORT_MULTICAST_ROUTER] = { .type = NLA_U8 }, |
Felix Fietkau | 6db6f0e | 2017-01-21 21:01:32 +0100 | [diff] [blame] | 823 | [IFLA_BRPORT_MCAST_TO_UCAST] = { .type = NLA_U8 }, |
Tobias Klauser | 9051247 | 2017-05-05 16:36:53 +0200 | [diff] [blame] | 824 | [IFLA_BRPORT_MCAST_FLOOD] = { .type = NLA_U8 }, |
| 825 | [IFLA_BRPORT_BCAST_FLOOD] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | fbec443 | 2017-11-13 18:30:55 +0200 | [diff] [blame] | 826 | [IFLA_BRPORT_VLAN_TUNNEL] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | 5af48b5 | 2017-09-27 16:12:44 +0300 | [diff] [blame] | 827 | [IFLA_BRPORT_GROUP_FWD_MASK] = { .type = NLA_U16 }, |
Nikolay Aleksandrov | 1a3fbd3 | 2017-10-30 12:56:33 +0200 | [diff] [blame] | 828 | [IFLA_BRPORT_NEIGH_SUPPRESS] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | 7d850ab | 2018-05-24 11:56:48 +0300 | [diff] [blame] | 829 | [IFLA_BRPORT_ISOLATED] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | 2756f68 | 2018-07-23 11:16:59 +0300 | [diff] [blame] | 830 | [IFLA_BRPORT_BACKUP_PORT] = { .type = NLA_U32 }, |
Nikolay Aleksandrov | 2dba407 | 2021-01-26 11:35:33 +0200 | [diff] [blame] | 831 | [IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT] = { .type = NLA_U32 }, |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 832 | }; |
| 833 | |
| 834 | /* Change the state of the port and notify spanning tree */ |
| 835 | static int br_set_port_state(struct net_bridge_port *p, u8 state) |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 836 | { |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 837 | if (state > BR_STATE_BLOCKING) |
stephen hemminger | b5ed54e | 2010-11-15 06:38:13 +0000 | [diff] [blame] | 838 | return -EINVAL; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 839 | |
| 840 | /* if kernel STP is running, don't allow changes */ |
Stephen Hemminger | 9cde070 | 2007-03-21 14:22:44 -0700 | [diff] [blame] | 841 | if (p->br->stp_enabled == BR_KERNEL_STP) |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 842 | return -EBUSY; |
| 843 | |
stephen hemminger | 576eb62 | 2012-12-28 18:15:22 +0000 | [diff] [blame] | 844 | /* if device is not up, change is not allowed |
| 845 | * if link is not present, only allowable state is disabled |
| 846 | */ |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 847 | if (!netif_running(p->dev) || |
stephen hemminger | 576eb62 | 2012-12-28 18:15:22 +0000 | [diff] [blame] | 848 | (!netif_oper_up(p->dev) && state != BR_STATE_DISABLED)) |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 849 | return -ENETDOWN; |
| 850 | |
Florian Fainelli | 775dd69 | 2014-09-30 16:13:19 -0700 | [diff] [blame] | 851 | br_set_state(p, state); |
Vitalii Demianets | b03b6dd | 2011-11-25 00:16:37 +0000 | [diff] [blame] | 852 | br_port_state_selection(p->br); |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 853 | return 0; |
| 854 | } |
| 855 | |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 856 | /* Set/clear or port flags based on attribute */ |
Vladimir Oltean | 304ae3b | 2021-02-12 17:15:52 +0200 | [diff] [blame] | 857 | static void br_set_port_flag(struct net_bridge_port *p, struct nlattr *tb[], |
| 858 | int attrtype, unsigned long mask) |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 859 | { |
Arkadi Sharshevsky | 3922285 | 2017-06-08 08:44:11 +0200 | [diff] [blame] | 860 | if (!tb[attrtype]) |
Vladimir Oltean | 304ae3b | 2021-02-12 17:15:52 +0200 | [diff] [blame] | 861 | return; |
Arkadi Sharshevsky | 3922285 | 2017-06-08 08:44:11 +0200 | [diff] [blame] | 862 | |
| 863 | if (nla_get_u8(tb[attrtype])) |
Vladimir Oltean | 304ae3b | 2021-02-12 17:15:52 +0200 | [diff] [blame] | 864 | p->flags |= mask; |
Arkadi Sharshevsky | 3922285 | 2017-06-08 08:44:11 +0200 | [diff] [blame] | 865 | else |
Vladimir Oltean | 304ae3b | 2021-02-12 17:15:52 +0200 | [diff] [blame] | 866 | p->flags &= ~mask; |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | /* Process bridge protocol info on port */ |
Vladimir Oltean | 078bbb8 | 2021-02-12 17:15:53 +0200 | [diff] [blame] | 870 | static int br_setport(struct net_bridge_port *p, struct nlattr *tb[], |
| 871 | struct netlink_ext_ack *extack) |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 872 | { |
Vladimir Oltean | 304ae3b | 2021-02-12 17:15:52 +0200 | [diff] [blame] | 873 | unsigned long old_flags, changed_mask; |
| 874 | bool br_vlan_tunnel_old; |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 875 | int err; |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 876 | |
Vladimir Oltean | 304ae3b | 2021-02-12 17:15:52 +0200 | [diff] [blame] | 877 | old_flags = p->flags; |
| 878 | br_vlan_tunnel_old = (old_flags & BR_VLAN_TUNNEL) ? true : false; |
Arkadi Sharshevsky | 3922285 | 2017-06-08 08:44:11 +0200 | [diff] [blame] | 879 | |
Vladimir Oltean | 304ae3b | 2021-02-12 17:15:52 +0200 | [diff] [blame] | 880 | br_set_port_flag(p, tb, IFLA_BRPORT_MODE, BR_HAIRPIN_MODE); |
| 881 | br_set_port_flag(p, tb, IFLA_BRPORT_GUARD, BR_BPDU_GUARD); |
| 882 | br_set_port_flag(p, tb, IFLA_BRPORT_FAST_LEAVE, |
| 883 | BR_MULTICAST_FAST_LEAVE); |
| 884 | br_set_port_flag(p, tb, IFLA_BRPORT_PROTECT, BR_ROOT_BLOCK); |
| 885 | br_set_port_flag(p, tb, IFLA_BRPORT_LEARNING, BR_LEARNING); |
| 886 | br_set_port_flag(p, tb, IFLA_BRPORT_UNICAST_FLOOD, BR_FLOOD); |
| 887 | br_set_port_flag(p, tb, IFLA_BRPORT_MCAST_FLOOD, BR_MCAST_FLOOD); |
| 888 | br_set_port_flag(p, tb, IFLA_BRPORT_MCAST_TO_UCAST, |
| 889 | BR_MULTICAST_TO_UNICAST); |
| 890 | br_set_port_flag(p, tb, IFLA_BRPORT_BCAST_FLOOD, BR_BCAST_FLOOD); |
| 891 | br_set_port_flag(p, tb, IFLA_BRPORT_PROXYARP, BR_PROXYARP); |
| 892 | br_set_port_flag(p, tb, IFLA_BRPORT_PROXYARP_WIFI, BR_PROXYARP_WIFI); |
| 893 | br_set_port_flag(p, tb, IFLA_BRPORT_VLAN_TUNNEL, BR_VLAN_TUNNEL); |
| 894 | br_set_port_flag(p, tb, IFLA_BRPORT_NEIGH_SUPPRESS, BR_NEIGH_SUPPRESS); |
| 895 | br_set_port_flag(p, tb, IFLA_BRPORT_ISOLATED, BR_ISOLATED); |
Arkadi Sharshevsky | 3922285 | 2017-06-08 08:44:11 +0200 | [diff] [blame] | 896 | |
Vladimir Oltean | 304ae3b | 2021-02-12 17:15:52 +0200 | [diff] [blame] | 897 | changed_mask = old_flags ^ p->flags; |
Arkadi Sharshevsky | 3922285 | 2017-06-08 08:44:11 +0200 | [diff] [blame] | 898 | |
Vladimir Oltean | 078bbb8 | 2021-02-12 17:15:53 +0200 | [diff] [blame] | 899 | err = br_switchdev_set_port_flag(p, p->flags, changed_mask, extack); |
Vladimir Oltean | 304ae3b | 2021-02-12 17:15:52 +0200 | [diff] [blame] | 900 | if (err) { |
| 901 | p->flags = old_flags; |
Arkadi Sharshevsky | 3922285 | 2017-06-08 08:44:11 +0200 | [diff] [blame] | 902 | return err; |
Vladimir Oltean | 304ae3b | 2021-02-12 17:15:52 +0200 | [diff] [blame] | 903 | } |
Arkadi Sharshevsky | 3922285 | 2017-06-08 08:44:11 +0200 | [diff] [blame] | 904 | |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 905 | if (br_vlan_tunnel_old && !(p->flags & BR_VLAN_TUNNEL)) |
| 906 | nbp_vlan_tunnel_info_flush(p); |
| 907 | |
Vladimir Oltean | 304ae3b | 2021-02-12 17:15:52 +0200 | [diff] [blame] | 908 | br_port_flags_change(p, changed_mask); |
| 909 | |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 910 | if (tb[IFLA_BRPORT_COST]) { |
| 911 | err = br_stp_set_path_cost(p, nla_get_u32(tb[IFLA_BRPORT_COST])); |
| 912 | if (err) |
| 913 | return err; |
| 914 | } |
| 915 | |
| 916 | if (tb[IFLA_BRPORT_PRIORITY]) { |
| 917 | err = br_stp_set_port_priority(p, nla_get_u16(tb[IFLA_BRPORT_PRIORITY])); |
| 918 | if (err) |
| 919 | return err; |
| 920 | } |
| 921 | |
| 922 | if (tb[IFLA_BRPORT_STATE]) { |
| 923 | err = br_set_port_state(p, nla_get_u8(tb[IFLA_BRPORT_STATE])); |
| 924 | if (err) |
| 925 | return err; |
| 926 | } |
Vlad Yasevich | e028e4b | 2014-05-16 09:59:16 -0400 | [diff] [blame] | 927 | |
Nikolay Aleksandrov | 9b0c6e4 | 2015-10-06 14:12:01 +0200 | [diff] [blame] | 928 | if (tb[IFLA_BRPORT_FLUSH]) |
| 929 | br_fdb_delete_by_port(p->br, p, 0, 0); |
| 930 | |
Nikolay Aleksandrov | 5d6ae47 | 2015-10-06 14:12:02 +0200 | [diff] [blame] | 931 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 932 | if (tb[IFLA_BRPORT_MULTICAST_ROUTER]) { |
| 933 | u8 mcast_router = nla_get_u8(tb[IFLA_BRPORT_MULTICAST_ROUTER]); |
| 934 | |
Nikolay Aleksandrov | a53581d | 2021-08-20 15:42:54 +0300 | [diff] [blame] | 935 | err = br_multicast_set_port_router(&p->multicast_ctx, |
| 936 | mcast_router); |
Nikolay Aleksandrov | 5d6ae47 | 2015-10-06 14:12:02 +0200 | [diff] [blame] | 937 | if (err) |
| 938 | return err; |
| 939 | } |
Nikolay Aleksandrov | 2dba407 | 2021-01-26 11:35:33 +0200 | [diff] [blame] | 940 | |
| 941 | if (tb[IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT]) { |
| 942 | u32 hlimit; |
| 943 | |
| 944 | hlimit = nla_get_u32(tb[IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT]); |
| 945 | err = br_multicast_eht_set_hosts_limit(p, hlimit); |
| 946 | if (err) |
| 947 | return err; |
| 948 | } |
Nikolay Aleksandrov | 5d6ae47 | 2015-10-06 14:12:02 +0200 | [diff] [blame] | 949 | #endif |
Nikolay Aleksandrov | 5af48b5 | 2017-09-27 16:12:44 +0300 | [diff] [blame] | 950 | |
| 951 | if (tb[IFLA_BRPORT_GROUP_FWD_MASK]) { |
| 952 | u16 fwd_mask = nla_get_u16(tb[IFLA_BRPORT_GROUP_FWD_MASK]); |
| 953 | |
| 954 | if (fwd_mask & BR_GROUPFWD_MACPAUSE) |
| 955 | return -EINVAL; |
| 956 | p->group_fwd_mask = fwd_mask; |
| 957 | } |
| 958 | |
Nikolay Aleksandrov | 2756f68 | 2018-07-23 11:16:59 +0300 | [diff] [blame] | 959 | if (tb[IFLA_BRPORT_BACKUP_PORT]) { |
| 960 | struct net_device *backup_dev = NULL; |
| 961 | u32 backup_ifindex; |
| 962 | |
| 963 | backup_ifindex = nla_get_u32(tb[IFLA_BRPORT_BACKUP_PORT]); |
| 964 | if (backup_ifindex) { |
| 965 | backup_dev = __dev_get_by_index(dev_net(p->dev), |
| 966 | backup_ifindex); |
| 967 | if (!backup_dev) |
| 968 | return -ENOENT; |
| 969 | } |
| 970 | |
| 971 | err = nbp_backup_change(p, backup_dev); |
| 972 | if (err) |
| 973 | return err; |
| 974 | } |
| 975 | |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 976 | return 0; |
| 977 | } |
| 978 | |
| 979 | /* Change state and parameters on port. */ |
Petr Machata | 2fd527b | 2018-12-12 17:02:48 +0000 | [diff] [blame] | 980 | int br_setlink(struct net_device *dev, struct nlmsghdr *nlh, u16 flags, |
| 981 | struct netlink_ext_ack *extack) |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 982 | { |
Nikolay Aleksandrov | 9289906 | 2017-11-01 12:18:13 +0200 | [diff] [blame] | 983 | struct net_bridge *br = (struct net_bridge *)netdev_priv(dev); |
| 984 | struct nlattr *tb[IFLA_BRPORT_MAX + 1]; |
| 985 | struct net_bridge_port *p; |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 986 | struct nlattr *protinfo; |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 987 | struct nlattr *afspec; |
Nikolay Aleksandrov | e19b42a | 2017-10-27 13:19:36 +0300 | [diff] [blame] | 988 | bool changed = false; |
Scott Feldman | 41c498b | 2015-05-10 09:47:59 -0700 | [diff] [blame] | 989 | int err = 0; |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 990 | |
Hong zhi guo | c60ee67 | 2013-03-28 06:21:22 +0000 | [diff] [blame] | 991 | protinfo = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_PROTINFO); |
| 992 | afspec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 993 | if (!protinfo && !afspec) |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 994 | return 0; |
| 995 | |
| 996 | p = br_port_get_rtnl(dev); |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 997 | /* We want to accept dev as bridge itself if the AF_SPEC |
stephen hemminger | 8e3bff9 | 2013-12-08 12:15:44 -0800 | [diff] [blame] | 998 | * is set to see if someone is setting vlan info on the bridge |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 999 | */ |
Hong zhi guo | 7b99a99 | 2013-03-24 03:26:47 +0000 | [diff] [blame] | 1000 | if (!p && !afspec) |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 1001 | return -EINVAL; |
| 1002 | |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 1003 | if (p && protinfo) { |
| 1004 | if (protinfo->nla_type & NLA_F_NESTED) { |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1005 | err = nla_parse_nested_deprecated(tb, IFLA_BRPORT_MAX, |
| 1006 | protinfo, |
| 1007 | br_port_policy, |
| 1008 | NULL); |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 1009 | if (err) |
| 1010 | return err; |
| 1011 | |
| 1012 | spin_lock_bh(&p->br->lock); |
Vladimir Oltean | 078bbb8 | 2021-02-12 17:15:53 +0200 | [diff] [blame] | 1013 | err = br_setport(p, tb, extack); |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 1014 | spin_unlock_bh(&p->br->lock); |
| 1015 | } else { |
stephen hemminger | 8e3bff9 | 2013-12-08 12:15:44 -0800 | [diff] [blame] | 1016 | /* Binary compatibility with old RSTP */ |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 1017 | if (nla_len(protinfo) < sizeof(u8)) |
| 1018 | return -EINVAL; |
| 1019 | |
| 1020 | spin_lock_bh(&p->br->lock); |
| 1021 | err = br_set_port_state(p, nla_get_u8(protinfo)); |
| 1022 | spin_unlock_bh(&p->br->lock); |
| 1023 | } |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 1024 | if (err) |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 1025 | goto out; |
Nikolay Aleksandrov | e19b42a | 2017-10-27 13:19:36 +0300 | [diff] [blame] | 1026 | changed = true; |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 1027 | } |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 1028 | |
Nikolay Aleksandrov | 9289906 | 2017-11-01 12:18:13 +0200 | [diff] [blame] | 1029 | if (afspec) |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1030 | err = br_afspec(br, p, afspec, RTM_SETLINK, &changed, extack); |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 1031 | |
Nikolay Aleksandrov | e19b42a | 2017-10-27 13:19:36 +0300 | [diff] [blame] | 1032 | if (changed) |
Nikolay Aleksandrov | 9289906 | 2017-11-01 12:18:13 +0200 | [diff] [blame] | 1033 | br_ifinfo_notify(RTM_NEWLINK, br, p); |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 1034 | out: |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 1035 | return err; |
| 1036 | } |
| 1037 | |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 1038 | /* Delete port information */ |
Roopa Prabhu | add511b | 2015-01-29 22:40:12 -0800 | [diff] [blame] | 1039 | int br_dellink(struct net_device *dev, struct nlmsghdr *nlh, u16 flags) |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 1040 | { |
Nikolay Aleksandrov | 9289906 | 2017-11-01 12:18:13 +0200 | [diff] [blame] | 1041 | struct net_bridge *br = (struct net_bridge *)netdev_priv(dev); |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 1042 | struct net_bridge_port *p; |
Nikolay Aleksandrov | 9289906 | 2017-11-01 12:18:13 +0200 | [diff] [blame] | 1043 | struct nlattr *afspec; |
Nikolay Aleksandrov | e19b42a | 2017-10-27 13:19:36 +0300 | [diff] [blame] | 1044 | bool changed = false; |
Scott Feldman | 8508025 | 2015-05-10 09:48:03 -0700 | [diff] [blame] | 1045 | int err = 0; |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 1046 | |
Hong zhi guo | c60ee67 | 2013-03-28 06:21:22 +0000 | [diff] [blame] | 1047 | afspec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 1048 | if (!afspec) |
| 1049 | return 0; |
| 1050 | |
| 1051 | p = br_port_get_rtnl(dev); |
| 1052 | /* We want to accept dev as bridge itself as well */ |
Kyungrok Chung | 254ec03 | 2021-10-16 20:21:36 +0900 | [diff] [blame] | 1053 | if (!p && !netif_is_bridge_master(dev)) |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 1054 | return -EINVAL; |
| 1055 | |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1056 | err = br_afspec(br, p, afspec, RTM_DELLINK, &changed, NULL); |
Nikolay Aleksandrov | e19b42a | 2017-10-27 13:19:36 +0300 | [diff] [blame] | 1057 | if (changed) |
Roopa Prabhu | 02dba43 | 2015-01-14 20:02:25 -0800 | [diff] [blame] | 1058 | /* Send RTM_NEWLINK because userspace |
| 1059 | * expects RTM_NEWLINK for vlan dels |
| 1060 | */ |
Nikolay Aleksandrov | 9289906 | 2017-11-01 12:18:13 +0200 | [diff] [blame] | 1061 | br_ifinfo_notify(RTM_NEWLINK, br, p); |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 1062 | |
| 1063 | return err; |
| 1064 | } |
Matthias Schiffer | a8b8a889 | 2017-06-25 23:56:01 +0200 | [diff] [blame] | 1065 | |
| 1066 | static int br_validate(struct nlattr *tb[], struct nlattr *data[], |
| 1067 | struct netlink_ext_ack *extack) |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 1068 | { |
stephen hemminger | bb900b2 | 2011-04-04 14:03:32 +0000 | [diff] [blame] | 1069 | if (tb[IFLA_ADDRESS]) { |
| 1070 | if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) |
| 1071 | return -EINVAL; |
| 1072 | if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) |
| 1073 | return -EADDRNOTAVAIL; |
| 1074 | } |
Thomas Graf | 32fe21c | 2007-03-22 11:59:03 -0700 | [diff] [blame] | 1075 | |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 1076 | if (!data) |
| 1077 | return 0; |
| 1078 | |
| 1079 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING |
Menglong Dong | a98c0c4 | 2021-01-17 16:09:50 +0800 | [diff] [blame] | 1080 | if (data[IFLA_BR_VLAN_PROTOCOL] && |
| 1081 | !eth_type_vlan(nla_get_be16(data[IFLA_BR_VLAN_PROTOCOL]))) |
| 1082 | return -EPROTONOSUPPORT; |
Tobias Jungel | a285860 | 2017-05-17 09:29:12 +0200 | [diff] [blame] | 1083 | |
| 1084 | if (data[IFLA_BR_VLAN_DEFAULT_PVID]) { |
| 1085 | __u16 defpvid = nla_get_u16(data[IFLA_BR_VLAN_DEFAULT_PVID]); |
| 1086 | |
| 1087 | if (defpvid >= VLAN_VID_MASK) |
| 1088 | return -EINVAL; |
| 1089 | } |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 1090 | #endif |
| 1091 | |
Thomas Graf | 32fe21c | 2007-03-22 11:59:03 -0700 | [diff] [blame] | 1092 | return 0; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 1093 | } |
| 1094 | |
Jiri Pirko | 3ac636b | 2014-09-05 15:51:30 +0200 | [diff] [blame] | 1095 | static int br_port_slave_changelink(struct net_device *brdev, |
| 1096 | struct net_device *dev, |
| 1097 | struct nlattr *tb[], |
Matthias Schiffer | 17dd0ec | 2017-06-25 23:56:02 +0200 | [diff] [blame] | 1098 | struct nlattr *data[], |
| 1099 | struct netlink_ext_ack *extack) |
Jiri Pirko | 3ac636b | 2014-09-05 15:51:30 +0200 | [diff] [blame] | 1100 | { |
Nikolay Aleksandrov | 963ad94 | 2015-07-22 13:03:40 +0200 | [diff] [blame] | 1101 | struct net_bridge *br = netdev_priv(brdev); |
| 1102 | int ret; |
| 1103 | |
Jiri Pirko | 3ac636b | 2014-09-05 15:51:30 +0200 | [diff] [blame] | 1104 | if (!data) |
| 1105 | return 0; |
Nikolay Aleksandrov | 963ad94 | 2015-07-22 13:03:40 +0200 | [diff] [blame] | 1106 | |
| 1107 | spin_lock_bh(&br->lock); |
Vladimir Oltean | 078bbb8 | 2021-02-12 17:15:53 +0200 | [diff] [blame] | 1108 | ret = br_setport(br_port_get_rtnl(dev), data, extack); |
Nikolay Aleksandrov | 963ad94 | 2015-07-22 13:03:40 +0200 | [diff] [blame] | 1109 | spin_unlock_bh(&br->lock); |
| 1110 | |
| 1111 | return ret; |
Jiri Pirko | 3ac636b | 2014-09-05 15:51:30 +0200 | [diff] [blame] | 1112 | } |
| 1113 | |
Jiri Pirko | ced8283 | 2014-09-05 15:51:29 +0200 | [diff] [blame] | 1114 | static int br_port_fill_slave_info(struct sk_buff *skb, |
| 1115 | const struct net_device *brdev, |
| 1116 | const struct net_device *dev) |
| 1117 | { |
| 1118 | return br_port_fill_attrs(skb, br_port_get_rtnl(dev)); |
| 1119 | } |
| 1120 | |
| 1121 | static size_t br_port_get_slave_size(const struct net_device *brdev, |
| 1122 | const struct net_device *dev) |
| 1123 | { |
| 1124 | return br_port_info_size(); |
| 1125 | } |
| 1126 | |
Jiri Pirko | 1332351 | 2014-09-05 15:51:32 +0200 | [diff] [blame] | 1127 | static const struct nla_policy br_policy[IFLA_BR_MAX + 1] = { |
| 1128 | [IFLA_BR_FORWARD_DELAY] = { .type = NLA_U32 }, |
| 1129 | [IFLA_BR_HELLO_TIME] = { .type = NLA_U32 }, |
| 1130 | [IFLA_BR_MAX_AGE] = { .type = NLA_U32 }, |
Jörg Thalheim | af61576 | 2015-03-18 10:06:58 +0100 | [diff] [blame] | 1131 | [IFLA_BR_AGEING_TIME] = { .type = NLA_U32 }, |
| 1132 | [IFLA_BR_STP_STATE] = { .type = NLA_U32 }, |
| 1133 | [IFLA_BR_PRIORITY] = { .type = NLA_U16 }, |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 1134 | [IFLA_BR_VLAN_FILTERING] = { .type = NLA_U8 }, |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 1135 | [IFLA_BR_VLAN_PROTOCOL] = { .type = NLA_U16 }, |
Nikolay Aleksandrov | 7910228 | 2015-10-04 14:23:28 +0200 | [diff] [blame] | 1136 | [IFLA_BR_GROUP_FWD_MASK] = { .type = NLA_U16 }, |
Nikolay Aleksandrov | 111189a | 2015-10-04 14:23:35 +0200 | [diff] [blame] | 1137 | [IFLA_BR_GROUP_ADDR] = { .type = NLA_BINARY, |
| 1138 | .len = ETH_ALEN }, |
Nikolay Aleksandrov | a9a6bc7 | 2015-10-04 14:23:37 +0200 | [diff] [blame] | 1139 | [IFLA_BR_MCAST_ROUTER] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | 8912632 | 2015-10-04 14:23:38 +0200 | [diff] [blame] | 1140 | [IFLA_BR_MCAST_SNOOPING] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | 295141d | 2015-10-04 14:23:39 +0200 | [diff] [blame] | 1141 | [IFLA_BR_MCAST_QUERY_USE_IFADDR] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | ba062d7c | 2015-10-04 14:23:40 +0200 | [diff] [blame] | 1142 | [IFLA_BR_MCAST_QUERIER] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | 431db3c | 2015-10-04 14:23:41 +0200 | [diff] [blame] | 1143 | [IFLA_BR_MCAST_HASH_ELASTICITY] = { .type = NLA_U32 }, |
Nikolay Aleksandrov | 858079f | 2015-10-04 14:23:42 +0200 | [diff] [blame] | 1144 | [IFLA_BR_MCAST_HASH_MAX] = { .type = NLA_U32 }, |
Nikolay Aleksandrov | 79b859f | 2015-10-04 14:23:43 +0200 | [diff] [blame] | 1145 | [IFLA_BR_MCAST_LAST_MEMBER_CNT] = { .type = NLA_U32 }, |
Nikolay Aleksandrov | b89e6ba | 2015-10-04 14:23:44 +0200 | [diff] [blame] | 1146 | [IFLA_BR_MCAST_STARTUP_QUERY_CNT] = { .type = NLA_U32 }, |
Nikolay Aleksandrov | 7e4df51 | 2015-10-04 14:23:45 +0200 | [diff] [blame] | 1147 | [IFLA_BR_MCAST_LAST_MEMBER_INTVL] = { .type = NLA_U64 }, |
| 1148 | [IFLA_BR_MCAST_MEMBERSHIP_INTVL] = { .type = NLA_U64 }, |
| 1149 | [IFLA_BR_MCAST_QUERIER_INTVL] = { .type = NLA_U64 }, |
| 1150 | [IFLA_BR_MCAST_QUERY_INTVL] = { .type = NLA_U64 }, |
| 1151 | [IFLA_BR_MCAST_QUERY_RESPONSE_INTVL] = { .type = NLA_U64 }, |
| 1152 | [IFLA_BR_MCAST_STARTUP_QUERY_INTVL] = { .type = NLA_U64 }, |
Nikolay Aleksandrov | 93870cc | 2015-10-04 14:23:46 +0200 | [diff] [blame] | 1153 | [IFLA_BR_NF_CALL_IPTABLES] = { .type = NLA_U8 }, |
| 1154 | [IFLA_BR_NF_CALL_IP6TABLES] = { .type = NLA_U8 }, |
| 1155 | [IFLA_BR_NF_CALL_ARPTABLES] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | 0f963b7 | 2015-10-04 14:23:47 +0200 | [diff] [blame] | 1156 | [IFLA_BR_VLAN_DEFAULT_PVID] = { .type = NLA_U16 }, |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 1157 | [IFLA_BR_VLAN_STATS_ENABLED] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1158 | [IFLA_BR_MCAST_STATS_ENABLED] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | 5e92358 | 2016-11-21 13:03:24 +0100 | [diff] [blame] | 1159 | [IFLA_BR_MCAST_IGMP_VERSION] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | aa2ae3e | 2016-11-21 13:03:25 +0100 | [diff] [blame] | 1160 | [IFLA_BR_MCAST_MLD_VERSION] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | 9163a0f | 2018-10-12 13:41:16 +0300 | [diff] [blame] | 1161 | [IFLA_BR_VLAN_STATS_PER_PORT] = { .type = NLA_U8 }, |
Johannes Berg | 8140860 | 2020-08-18 10:17:31 +0200 | [diff] [blame] | 1162 | [IFLA_BR_MULTI_BOOLOPT] = |
| 1163 | NLA_POLICY_EXACT_LEN(sizeof(struct br_boolopt_multi)), |
Jiri Pirko | 1332351 | 2014-09-05 15:51:32 +0200 | [diff] [blame] | 1164 | }; |
| 1165 | |
| 1166 | static int br_changelink(struct net_device *brdev, struct nlattr *tb[], |
Matthias Schiffer | ad744b2 | 2017-06-25 23:56:00 +0200 | [diff] [blame] | 1167 | struct nlattr *data[], |
| 1168 | struct netlink_ext_ack *extack) |
Jiri Pirko | 1332351 | 2014-09-05 15:51:32 +0200 | [diff] [blame] | 1169 | { |
| 1170 | struct net_bridge *br = netdev_priv(brdev); |
| 1171 | int err; |
| 1172 | |
| 1173 | if (!data) |
| 1174 | return 0; |
| 1175 | |
| 1176 | if (data[IFLA_BR_FORWARD_DELAY]) { |
| 1177 | err = br_set_forward_delay(br, nla_get_u32(data[IFLA_BR_FORWARD_DELAY])); |
| 1178 | if (err) |
| 1179 | return err; |
| 1180 | } |
| 1181 | |
| 1182 | if (data[IFLA_BR_HELLO_TIME]) { |
| 1183 | err = br_set_hello_time(br, nla_get_u32(data[IFLA_BR_HELLO_TIME])); |
| 1184 | if (err) |
| 1185 | return err; |
| 1186 | } |
| 1187 | |
| 1188 | if (data[IFLA_BR_MAX_AGE]) { |
| 1189 | err = br_set_max_age(br, nla_get_u32(data[IFLA_BR_MAX_AGE])); |
| 1190 | if (err) |
| 1191 | return err; |
| 1192 | } |
| 1193 | |
Jörg Thalheim | af61576 | 2015-03-18 10:06:58 +0100 | [diff] [blame] | 1194 | if (data[IFLA_BR_AGEING_TIME]) { |
Scott Feldman | c62987b | 2015-10-08 19:23:19 -0700 | [diff] [blame] | 1195 | err = br_set_ageing_time(br, nla_get_u32(data[IFLA_BR_AGEING_TIME])); |
| 1196 | if (err) |
| 1197 | return err; |
Jörg Thalheim | af61576 | 2015-03-18 10:06:58 +0100 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | if (data[IFLA_BR_STP_STATE]) { |
| 1201 | u32 stp_enabled = nla_get_u32(data[IFLA_BR_STP_STATE]); |
| 1202 | |
Horatiu Vultur | 419dba8a | 2020-04-26 15:22:08 +0200 | [diff] [blame] | 1203 | err = br_stp_set_enabled(br, stp_enabled, extack); |
| 1204 | if (err) |
| 1205 | return err; |
Jörg Thalheim | af61576 | 2015-03-18 10:06:58 +0100 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | if (data[IFLA_BR_PRIORITY]) { |
| 1209 | u32 priority = nla_get_u16(data[IFLA_BR_PRIORITY]); |
| 1210 | |
| 1211 | br_stp_set_bridge_priority(br, priority); |
| 1212 | } |
| 1213 | |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 1214 | if (data[IFLA_BR_VLAN_FILTERING]) { |
| 1215 | u8 vlan_filter = nla_get_u8(data[IFLA_BR_VLAN_FILTERING]); |
| 1216 | |
Vladimir Oltean | 9e78140 | 2021-02-13 22:43:16 +0200 | [diff] [blame] | 1217 | err = br_vlan_filter_toggle(br, vlan_filter, extack); |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 1218 | if (err) |
| 1219 | return err; |
| 1220 | } |
| 1221 | |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 1222 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING |
| 1223 | if (data[IFLA_BR_VLAN_PROTOCOL]) { |
| 1224 | __be16 vlan_proto = nla_get_be16(data[IFLA_BR_VLAN_PROTOCOL]); |
| 1225 | |
Vladimir Oltean | dcbdf13 | 2021-02-13 22:43:17 +0200 | [diff] [blame] | 1226 | err = __br_vlan_set_proto(br, vlan_proto, extack); |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 1227 | if (err) |
| 1228 | return err; |
| 1229 | } |
Nikolay Aleksandrov | 0f963b7 | 2015-10-04 14:23:47 +0200 | [diff] [blame] | 1230 | |
| 1231 | if (data[IFLA_BR_VLAN_DEFAULT_PVID]) { |
| 1232 | __u16 defpvid = nla_get_u16(data[IFLA_BR_VLAN_DEFAULT_PVID]); |
| 1233 | |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1234 | err = __br_vlan_set_default_pvid(br, defpvid, extack); |
Nikolay Aleksandrov | 0f963b7 | 2015-10-04 14:23:47 +0200 | [diff] [blame] | 1235 | if (err) |
| 1236 | return err; |
| 1237 | } |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 1238 | |
| 1239 | if (data[IFLA_BR_VLAN_STATS_ENABLED]) { |
| 1240 | __u8 vlan_stats = nla_get_u8(data[IFLA_BR_VLAN_STATS_ENABLED]); |
| 1241 | |
| 1242 | err = br_vlan_set_stats(br, vlan_stats); |
| 1243 | if (err) |
| 1244 | return err; |
| 1245 | } |
Nikolay Aleksandrov | 9163a0f | 2018-10-12 13:41:16 +0300 | [diff] [blame] | 1246 | |
| 1247 | if (data[IFLA_BR_VLAN_STATS_PER_PORT]) { |
| 1248 | __u8 per_port = nla_get_u8(data[IFLA_BR_VLAN_STATS_PER_PORT]); |
| 1249 | |
| 1250 | err = br_vlan_set_stats_per_port(br, per_port); |
| 1251 | if (err) |
| 1252 | return err; |
| 1253 | } |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 1254 | #endif |
| 1255 | |
Nikolay Aleksandrov | 7910228 | 2015-10-04 14:23:28 +0200 | [diff] [blame] | 1256 | if (data[IFLA_BR_GROUP_FWD_MASK]) { |
| 1257 | u16 fwd_mask = nla_get_u16(data[IFLA_BR_GROUP_FWD_MASK]); |
| 1258 | |
| 1259 | if (fwd_mask & BR_GROUPFWD_RESTRICTED) |
| 1260 | return -EINVAL; |
| 1261 | br->group_fwd_mask = fwd_mask; |
| 1262 | } |
| 1263 | |
Nikolay Aleksandrov | 111189a | 2015-10-04 14:23:35 +0200 | [diff] [blame] | 1264 | if (data[IFLA_BR_GROUP_ADDR]) { |
| 1265 | u8 new_addr[ETH_ALEN]; |
| 1266 | |
| 1267 | if (nla_len(data[IFLA_BR_GROUP_ADDR]) != ETH_ALEN) |
| 1268 | return -EINVAL; |
| 1269 | memcpy(new_addr, nla_data(data[IFLA_BR_GROUP_ADDR]), ETH_ALEN); |
| 1270 | if (!is_link_local_ether_addr(new_addr)) |
| 1271 | return -EINVAL; |
| 1272 | if (new_addr[5] == 1 || /* 802.3x Pause address */ |
| 1273 | new_addr[5] == 2 || /* 802.3ad Slow protocols */ |
| 1274 | new_addr[5] == 3) /* 802.1X PAE address */ |
| 1275 | return -EINVAL; |
| 1276 | spin_lock_bh(&br->lock); |
| 1277 | memcpy(br->group_addr, new_addr, sizeof(br->group_addr)); |
| 1278 | spin_unlock_bh(&br->lock); |
Nikolay Aleksandrov | be3664a | 2018-09-26 17:01:02 +0300 | [diff] [blame] | 1279 | br_opt_toggle(br, BROPT_GROUP_ADDR_SET, true); |
Nikolay Aleksandrov | 111189a | 2015-10-04 14:23:35 +0200 | [diff] [blame] | 1280 | br_recalculate_fwd_mask(br); |
| 1281 | } |
| 1282 | |
Nikolay Aleksandrov | 150217c | 2015-10-04 14:23:36 +0200 | [diff] [blame] | 1283 | if (data[IFLA_BR_FDB_FLUSH]) |
| 1284 | br_fdb_flush(br); |
| 1285 | |
Nikolay Aleksandrov | a9a6bc7 | 2015-10-04 14:23:37 +0200 | [diff] [blame] | 1286 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 1287 | if (data[IFLA_BR_MCAST_ROUTER]) { |
| 1288 | u8 multicast_router = nla_get_u8(data[IFLA_BR_MCAST_ROUTER]); |
| 1289 | |
Nikolay Aleksandrov | a97df08 | 2021-08-10 18:29:31 +0300 | [diff] [blame] | 1290 | err = br_multicast_set_router(&br->multicast_ctx, |
| 1291 | multicast_router); |
Nikolay Aleksandrov | a9a6bc7 | 2015-10-04 14:23:37 +0200 | [diff] [blame] | 1292 | if (err) |
| 1293 | return err; |
| 1294 | } |
Nikolay Aleksandrov | 8912632 | 2015-10-04 14:23:38 +0200 | [diff] [blame] | 1295 | |
| 1296 | if (data[IFLA_BR_MCAST_SNOOPING]) { |
| 1297 | u8 mcast_snooping = nla_get_u8(data[IFLA_BR_MCAST_SNOOPING]); |
| 1298 | |
Florian Fainelli | ae1ea84 | 2021-04-14 22:22:57 +0300 | [diff] [blame] | 1299 | err = br_multicast_toggle(br, mcast_snooping, extack); |
| 1300 | if (err) |
| 1301 | return err; |
Nikolay Aleksandrov | 8912632 | 2015-10-04 14:23:38 +0200 | [diff] [blame] | 1302 | } |
Nikolay Aleksandrov | 295141d | 2015-10-04 14:23:39 +0200 | [diff] [blame] | 1303 | |
| 1304 | if (data[IFLA_BR_MCAST_QUERY_USE_IFADDR]) { |
| 1305 | u8 val; |
| 1306 | |
| 1307 | val = nla_get_u8(data[IFLA_BR_MCAST_QUERY_USE_IFADDR]); |
Nikolay Aleksandrov | 675779a | 2018-09-26 17:01:04 +0300 | [diff] [blame] | 1308 | br_opt_toggle(br, BROPT_MULTICAST_QUERY_USE_IFADDR, !!val); |
Nikolay Aleksandrov | 295141d | 2015-10-04 14:23:39 +0200 | [diff] [blame] | 1309 | } |
Nikolay Aleksandrov | ba062d7c | 2015-10-04 14:23:40 +0200 | [diff] [blame] | 1310 | |
| 1311 | if (data[IFLA_BR_MCAST_QUERIER]) { |
| 1312 | u8 mcast_querier = nla_get_u8(data[IFLA_BR_MCAST_QUERIER]); |
| 1313 | |
Nikolay Aleksandrov | 6293818 | 2021-08-10 18:29:30 +0300 | [diff] [blame] | 1314 | err = br_multicast_set_querier(&br->multicast_ctx, |
| 1315 | mcast_querier); |
Nikolay Aleksandrov | ba062d7c | 2015-10-04 14:23:40 +0200 | [diff] [blame] | 1316 | if (err) |
| 1317 | return err; |
| 1318 | } |
Nikolay Aleksandrov | 431db3c | 2015-10-04 14:23:41 +0200 | [diff] [blame] | 1319 | |
Nikolay Aleksandrov | cf332bca | 2018-12-05 15:14:26 +0200 | [diff] [blame] | 1320 | if (data[IFLA_BR_MCAST_HASH_ELASTICITY]) |
| 1321 | br_warn(br, "the hash_elasticity option has been deprecated and is always %u\n", |
| 1322 | RHT_ELASTICITY); |
Nikolay Aleksandrov | 858079f | 2015-10-04 14:23:42 +0200 | [diff] [blame] | 1323 | |
Nikolay Aleksandrov | 19e3a9c | 2018-12-05 15:14:24 +0200 | [diff] [blame] | 1324 | if (data[IFLA_BR_MCAST_HASH_MAX]) |
| 1325 | br->hash_max = nla_get_u32(data[IFLA_BR_MCAST_HASH_MAX]); |
Nikolay Aleksandrov | 79b859f | 2015-10-04 14:23:43 +0200 | [diff] [blame] | 1326 | |
| 1327 | if (data[IFLA_BR_MCAST_LAST_MEMBER_CNT]) { |
| 1328 | u32 val = nla_get_u32(data[IFLA_BR_MCAST_LAST_MEMBER_CNT]); |
| 1329 | |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1330 | br->multicast_ctx.multicast_last_member_count = val; |
Nikolay Aleksandrov | 79b859f | 2015-10-04 14:23:43 +0200 | [diff] [blame] | 1331 | } |
Nikolay Aleksandrov | b89e6ba | 2015-10-04 14:23:44 +0200 | [diff] [blame] | 1332 | |
| 1333 | if (data[IFLA_BR_MCAST_STARTUP_QUERY_CNT]) { |
| 1334 | u32 val = nla_get_u32(data[IFLA_BR_MCAST_STARTUP_QUERY_CNT]); |
| 1335 | |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1336 | br->multicast_ctx.multicast_startup_query_count = val; |
Nikolay Aleksandrov | b89e6ba | 2015-10-04 14:23:44 +0200 | [diff] [blame] | 1337 | } |
Nikolay Aleksandrov | 7e4df51 | 2015-10-04 14:23:45 +0200 | [diff] [blame] | 1338 | |
| 1339 | if (data[IFLA_BR_MCAST_LAST_MEMBER_INTVL]) { |
| 1340 | u64 val = nla_get_u64(data[IFLA_BR_MCAST_LAST_MEMBER_INTVL]); |
| 1341 | |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1342 | br->multicast_ctx.multicast_last_member_interval = clock_t_to_jiffies(val); |
Nikolay Aleksandrov | 7e4df51 | 2015-10-04 14:23:45 +0200 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | if (data[IFLA_BR_MCAST_MEMBERSHIP_INTVL]) { |
| 1346 | u64 val = nla_get_u64(data[IFLA_BR_MCAST_MEMBERSHIP_INTVL]); |
| 1347 | |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1348 | br->multicast_ctx.multicast_membership_interval = clock_t_to_jiffies(val); |
Nikolay Aleksandrov | 7e4df51 | 2015-10-04 14:23:45 +0200 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | if (data[IFLA_BR_MCAST_QUERIER_INTVL]) { |
| 1352 | u64 val = nla_get_u64(data[IFLA_BR_MCAST_QUERIER_INTVL]); |
| 1353 | |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1354 | br->multicast_ctx.multicast_querier_interval = clock_t_to_jiffies(val); |
Nikolay Aleksandrov | 7e4df51 | 2015-10-04 14:23:45 +0200 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | if (data[IFLA_BR_MCAST_QUERY_INTVL]) { |
| 1358 | u64 val = nla_get_u64(data[IFLA_BR_MCAST_QUERY_INTVL]); |
| 1359 | |
Nikolay Aleksandrov | 99b4061 | 2021-12-27 19:21:15 +0200 | [diff] [blame] | 1360 | br_multicast_set_query_intvl(&br->multicast_ctx, val); |
Nikolay Aleksandrov | 7e4df51 | 2015-10-04 14:23:45 +0200 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | if (data[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL]) { |
| 1364 | u64 val = nla_get_u64(data[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL]); |
| 1365 | |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1366 | br->multicast_ctx.multicast_query_response_interval = clock_t_to_jiffies(val); |
Nikolay Aleksandrov | 7e4df51 | 2015-10-04 14:23:45 +0200 | [diff] [blame] | 1367 | } |
| 1368 | |
| 1369 | if (data[IFLA_BR_MCAST_STARTUP_QUERY_INTVL]) { |
| 1370 | u64 val = nla_get_u64(data[IFLA_BR_MCAST_STARTUP_QUERY_INTVL]); |
| 1371 | |
Nikolay Aleksandrov | f83a112 | 2021-12-27 19:21:16 +0200 | [diff] [blame] | 1372 | br_multicast_set_startup_query_intvl(&br->multicast_ctx, val); |
Nikolay Aleksandrov | 7e4df51 | 2015-10-04 14:23:45 +0200 | [diff] [blame] | 1373 | } |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1374 | |
| 1375 | if (data[IFLA_BR_MCAST_STATS_ENABLED]) { |
| 1376 | __u8 mcast_stats; |
| 1377 | |
| 1378 | mcast_stats = nla_get_u8(data[IFLA_BR_MCAST_STATS_ENABLED]); |
Nikolay Aleksandrov | 675779a | 2018-09-26 17:01:04 +0300 | [diff] [blame] | 1379 | br_opt_toggle(br, BROPT_MULTICAST_STATS_ENABLED, !!mcast_stats); |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1380 | } |
Nikolay Aleksandrov | 5e92358 | 2016-11-21 13:03:24 +0100 | [diff] [blame] | 1381 | |
| 1382 | if (data[IFLA_BR_MCAST_IGMP_VERSION]) { |
| 1383 | __u8 igmp_version; |
| 1384 | |
| 1385 | igmp_version = nla_get_u8(data[IFLA_BR_MCAST_IGMP_VERSION]); |
Nikolay Aleksandrov | df271cd | 2021-08-10 18:29:19 +0300 | [diff] [blame] | 1386 | err = br_multicast_set_igmp_version(&br->multicast_ctx, |
| 1387 | igmp_version); |
Nikolay Aleksandrov | 5e92358 | 2016-11-21 13:03:24 +0100 | [diff] [blame] | 1388 | if (err) |
| 1389 | return err; |
| 1390 | } |
Nikolay Aleksandrov | aa2ae3e | 2016-11-21 13:03:25 +0100 | [diff] [blame] | 1391 | |
| 1392 | #if IS_ENABLED(CONFIG_IPV6) |
| 1393 | if (data[IFLA_BR_MCAST_MLD_VERSION]) { |
| 1394 | __u8 mld_version; |
| 1395 | |
| 1396 | mld_version = nla_get_u8(data[IFLA_BR_MCAST_MLD_VERSION]); |
Nikolay Aleksandrov | df271cd | 2021-08-10 18:29:19 +0300 | [diff] [blame] | 1397 | err = br_multicast_set_mld_version(&br->multicast_ctx, |
| 1398 | mld_version); |
Nikolay Aleksandrov | aa2ae3e | 2016-11-21 13:03:25 +0100 | [diff] [blame] | 1399 | if (err) |
| 1400 | return err; |
| 1401 | } |
| 1402 | #endif |
Nikolay Aleksandrov | a9a6bc7 | 2015-10-04 14:23:37 +0200 | [diff] [blame] | 1403 | #endif |
Nikolay Aleksandrov | 93870cc | 2015-10-04 14:23:46 +0200 | [diff] [blame] | 1404 | #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
| 1405 | if (data[IFLA_BR_NF_CALL_IPTABLES]) { |
| 1406 | u8 val = nla_get_u8(data[IFLA_BR_NF_CALL_IPTABLES]); |
| 1407 | |
Nikolay Aleksandrov | 8df3510 | 2018-09-26 17:01:01 +0300 | [diff] [blame] | 1408 | br_opt_toggle(br, BROPT_NF_CALL_IPTABLES, !!val); |
Nikolay Aleksandrov | 93870cc | 2015-10-04 14:23:46 +0200 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | if (data[IFLA_BR_NF_CALL_IP6TABLES]) { |
| 1412 | u8 val = nla_get_u8(data[IFLA_BR_NF_CALL_IP6TABLES]); |
| 1413 | |
Nikolay Aleksandrov | 8df3510 | 2018-09-26 17:01:01 +0300 | [diff] [blame] | 1414 | br_opt_toggle(br, BROPT_NF_CALL_IP6TABLES, !!val); |
Nikolay Aleksandrov | 93870cc | 2015-10-04 14:23:46 +0200 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | if (data[IFLA_BR_NF_CALL_ARPTABLES]) { |
| 1418 | u8 val = nla_get_u8(data[IFLA_BR_NF_CALL_ARPTABLES]); |
| 1419 | |
Nikolay Aleksandrov | 8df3510 | 2018-09-26 17:01:01 +0300 | [diff] [blame] | 1420 | br_opt_toggle(br, BROPT_NF_CALL_ARPTABLES, !!val); |
Nikolay Aleksandrov | 93870cc | 2015-10-04 14:23:46 +0200 | [diff] [blame] | 1421 | } |
| 1422 | #endif |
Nikolay Aleksandrov | a9a6bc7 | 2015-10-04 14:23:37 +0200 | [diff] [blame] | 1423 | |
Nikolay Aleksandrov | a428afe | 2018-11-24 04:34:20 +0200 | [diff] [blame] | 1424 | if (data[IFLA_BR_MULTI_BOOLOPT]) { |
| 1425 | struct br_boolopt_multi *bm; |
| 1426 | |
| 1427 | bm = nla_data(data[IFLA_BR_MULTI_BOOLOPT]); |
| 1428 | err = br_boolopt_multi_toggle(br, bm, extack); |
| 1429 | if (err) |
| 1430 | return err; |
| 1431 | } |
| 1432 | |
Jiri Pirko | 1332351 | 2014-09-05 15:51:32 +0200 | [diff] [blame] | 1433 | return 0; |
| 1434 | } |
| 1435 | |
Ivan Vecera | b667744 | 2017-01-20 18:12:17 +0100 | [diff] [blame] | 1436 | static int br_dev_newlink(struct net *src_net, struct net_device *dev, |
Matthias Schiffer | 7a3f4a1 | 2017-06-25 23:55:59 +0200 | [diff] [blame] | 1437 | struct nlattr *tb[], struct nlattr *data[], |
| 1438 | struct netlink_ext_ack *extack) |
Ivan Vecera | b667744 | 2017-01-20 18:12:17 +0100 | [diff] [blame] | 1439 | { |
| 1440 | struct net_bridge *br = netdev_priv(dev); |
| 1441 | int err; |
| 1442 | |
Nikolay Aleksandrov | 84aeb43 | 2017-12-18 17:35:09 +0200 | [diff] [blame] | 1443 | err = register_netdevice(dev); |
| 1444 | if (err) |
| 1445 | return err; |
| 1446 | |
Ivan Vecera | b667744 | 2017-01-20 18:12:17 +0100 | [diff] [blame] | 1447 | if (tb[IFLA_ADDRESS]) { |
| 1448 | spin_lock_bh(&br->lock); |
| 1449 | br_stp_change_bridge_id(br, nla_data(tb[IFLA_ADDRESS])); |
| 1450 | spin_unlock_bh(&br->lock); |
| 1451 | } |
| 1452 | |
Matthias Schiffer | ad744b2 | 2017-06-25 23:56:00 +0200 | [diff] [blame] | 1453 | err = br_changelink(dev, tb, data, extack); |
Ido Schimmel | 5b8d542 | 2017-04-10 14:59:28 +0300 | [diff] [blame] | 1454 | if (err) |
Nikolay Aleksandrov | 84aeb43 | 2017-12-18 17:35:09 +0200 | [diff] [blame] | 1455 | br_dev_delete(dev, NULL); |
| 1456 | |
Ido Schimmel | 5b8d542 | 2017-04-10 14:59:28 +0300 | [diff] [blame] | 1457 | return err; |
Ivan Vecera | b667744 | 2017-01-20 18:12:17 +0100 | [diff] [blame] | 1458 | } |
| 1459 | |
Jiri Pirko | e5c3ea5 | 2014-09-05 15:51:31 +0200 | [diff] [blame] | 1460 | static size_t br_get_size(const struct net_device *brdev) |
| 1461 | { |
| 1462 | return nla_total_size(sizeof(u32)) + /* IFLA_BR_FORWARD_DELAY */ |
| 1463 | nla_total_size(sizeof(u32)) + /* IFLA_BR_HELLO_TIME */ |
| 1464 | nla_total_size(sizeof(u32)) + /* IFLA_BR_MAX_AGE */ |
Jörg Thalheim | af61576 | 2015-03-18 10:06:58 +0100 | [diff] [blame] | 1465 | nla_total_size(sizeof(u32)) + /* IFLA_BR_AGEING_TIME */ |
| 1466 | nla_total_size(sizeof(u32)) + /* IFLA_BR_STP_STATE */ |
| 1467 | nla_total_size(sizeof(u16)) + /* IFLA_BR_PRIORITY */ |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 1468 | nla_total_size(sizeof(u8)) + /* IFLA_BR_VLAN_FILTERING */ |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 1469 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING |
| 1470 | nla_total_size(sizeof(__be16)) + /* IFLA_BR_VLAN_PROTOCOL */ |
Nikolay Aleksandrov | 0f963b7 | 2015-10-04 14:23:47 +0200 | [diff] [blame] | 1471 | nla_total_size(sizeof(u16)) + /* IFLA_BR_VLAN_DEFAULT_PVID */ |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 1472 | nla_total_size(sizeof(u8)) + /* IFLA_BR_VLAN_STATS_ENABLED */ |
Nikolay Aleksandrov | 9163a0f | 2018-10-12 13:41:16 +0300 | [diff] [blame] | 1473 | nla_total_size(sizeof(u8)) + /* IFLA_BR_VLAN_STATS_PER_PORT */ |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 1474 | #endif |
Nikolay Aleksandrov | 7910228 | 2015-10-04 14:23:28 +0200 | [diff] [blame] | 1475 | nla_total_size(sizeof(u16)) + /* IFLA_BR_GROUP_FWD_MASK */ |
Nikolay Aleksandrov | 5127c81 | 2015-10-04 14:23:29 +0200 | [diff] [blame] | 1476 | nla_total_size(sizeof(struct ifla_bridge_id)) + /* IFLA_BR_ROOT_ID */ |
Nikolay Aleksandrov | 7599a22 | 2015-10-04 14:23:30 +0200 | [diff] [blame] | 1477 | nla_total_size(sizeof(struct ifla_bridge_id)) + /* IFLA_BR_BRIDGE_ID */ |
Nikolay Aleksandrov | 8762ba6 | 2015-10-04 14:23:31 +0200 | [diff] [blame] | 1478 | nla_total_size(sizeof(u16)) + /* IFLA_BR_ROOT_PORT */ |
Nikolay Aleksandrov | 684dd24 | 2015-10-04 14:23:32 +0200 | [diff] [blame] | 1479 | nla_total_size(sizeof(u32)) + /* IFLA_BR_ROOT_PATH_COST */ |
Nikolay Aleksandrov | b89e6ba | 2015-10-04 14:23:44 +0200 | [diff] [blame] | 1480 | nla_total_size(sizeof(u8)) + /* IFLA_BR_TOPOLOGY_CHANGE */ |
| 1481 | nla_total_size(sizeof(u8)) + /* IFLA_BR_TOPOLOGY_CHANGE_DETECTED */ |
Nicolas Dichtel | 12a0faa | 2016-04-25 10:25:18 +0200 | [diff] [blame] | 1482 | nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_HELLO_TIMER */ |
| 1483 | nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_TCN_TIMER */ |
| 1484 | nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_TOPOLOGY_CHANGE_TIMER */ |
| 1485 | nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_GC_TIMER */ |
Nikolay Aleksandrov | 111189a | 2015-10-04 14:23:35 +0200 | [diff] [blame] | 1486 | nla_total_size(ETH_ALEN) + /* IFLA_BR_GROUP_ADDR */ |
Nikolay Aleksandrov | a9a6bc7 | 2015-10-04 14:23:37 +0200 | [diff] [blame] | 1487 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 1488 | nla_total_size(sizeof(u8)) + /* IFLA_BR_MCAST_ROUTER */ |
Nikolay Aleksandrov | 8912632 | 2015-10-04 14:23:38 +0200 | [diff] [blame] | 1489 | nla_total_size(sizeof(u8)) + /* IFLA_BR_MCAST_SNOOPING */ |
Nikolay Aleksandrov | 295141d | 2015-10-04 14:23:39 +0200 | [diff] [blame] | 1490 | nla_total_size(sizeof(u8)) + /* IFLA_BR_MCAST_QUERY_USE_IFADDR */ |
Nikolay Aleksandrov | ba062d7c | 2015-10-04 14:23:40 +0200 | [diff] [blame] | 1491 | nla_total_size(sizeof(u8)) + /* IFLA_BR_MCAST_QUERIER */ |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1492 | nla_total_size(sizeof(u8)) + /* IFLA_BR_MCAST_STATS_ENABLED */ |
Nikolay Aleksandrov | b89e6ba | 2015-10-04 14:23:44 +0200 | [diff] [blame] | 1493 | nla_total_size(sizeof(u32)) + /* IFLA_BR_MCAST_HASH_ELASTICITY */ |
| 1494 | nla_total_size(sizeof(u32)) + /* IFLA_BR_MCAST_HASH_MAX */ |
| 1495 | nla_total_size(sizeof(u32)) + /* IFLA_BR_MCAST_LAST_MEMBER_CNT */ |
| 1496 | nla_total_size(sizeof(u32)) + /* IFLA_BR_MCAST_STARTUP_QUERY_CNT */ |
Nicolas Dichtel | 12a0faa | 2016-04-25 10:25:18 +0200 | [diff] [blame] | 1497 | nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_MCAST_LAST_MEMBER_INTVL */ |
| 1498 | nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_MCAST_MEMBERSHIP_INTVL */ |
| 1499 | nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_MCAST_QUERIER_INTVL */ |
| 1500 | nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_MCAST_QUERY_INTVL */ |
| 1501 | nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_MCAST_QUERY_RESPONSE_INTVL */ |
| 1502 | nla_total_size_64bit(sizeof(u64)) + /* IFLA_BR_MCAST_STARTUP_QUERY_INTVL */ |
Nikolay Aleksandrov | 5e92358 | 2016-11-21 13:03:24 +0100 | [diff] [blame] | 1503 | nla_total_size(sizeof(u8)) + /* IFLA_BR_MCAST_IGMP_VERSION */ |
Nikolay Aleksandrov | aa2ae3e | 2016-11-21 13:03:25 +0100 | [diff] [blame] | 1504 | nla_total_size(sizeof(u8)) + /* IFLA_BR_MCAST_MLD_VERSION */ |
Nikolay Aleksandrov | c7fa1d9 | 2021-08-13 18:00:00 +0300 | [diff] [blame] | 1505 | br_multicast_querier_state_size() + /* IFLA_BR_MCAST_QUERIER_STATE */ |
Nikolay Aleksandrov | a9a6bc7 | 2015-10-04 14:23:37 +0200 | [diff] [blame] | 1506 | #endif |
Nikolay Aleksandrov | 93870cc | 2015-10-04 14:23:46 +0200 | [diff] [blame] | 1507 | #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
| 1508 | nla_total_size(sizeof(u8)) + /* IFLA_BR_NF_CALL_IPTABLES */ |
| 1509 | nla_total_size(sizeof(u8)) + /* IFLA_BR_NF_CALL_IP6TABLES */ |
| 1510 | nla_total_size(sizeof(u8)) + /* IFLA_BR_NF_CALL_ARPTABLES */ |
| 1511 | #endif |
Nikolay Aleksandrov | a428afe | 2018-11-24 04:34:20 +0200 | [diff] [blame] | 1512 | nla_total_size(sizeof(struct br_boolopt_multi)) + /* IFLA_BR_MULTI_BOOLOPT */ |
Jiri Pirko | e5c3ea5 | 2014-09-05 15:51:31 +0200 | [diff] [blame] | 1513 | 0; |
| 1514 | } |
| 1515 | |
| 1516 | static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev) |
| 1517 | { |
| 1518 | struct net_bridge *br = netdev_priv(brdev); |
| 1519 | u32 forward_delay = jiffies_to_clock_t(br->forward_delay); |
| 1520 | u32 hello_time = jiffies_to_clock_t(br->hello_time); |
| 1521 | u32 age_time = jiffies_to_clock_t(br->max_age); |
Jörg Thalheim | af61576 | 2015-03-18 10:06:58 +0100 | [diff] [blame] | 1522 | u32 ageing_time = jiffies_to_clock_t(br->ageing_time); |
| 1523 | u32 stp_enabled = br->stp_enabled; |
| 1524 | u16 priority = (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]; |
Ido Schimmel | 1f51445 | 2017-05-26 08:37:23 +0200 | [diff] [blame] | 1525 | u8 vlan_enabled = br_vlan_enabled(br->dev); |
Nikolay Aleksandrov | a428afe | 2018-11-24 04:34:20 +0200 | [diff] [blame] | 1526 | struct br_boolopt_multi bm; |
Nikolay Aleksandrov | 4917a15 | 2015-10-05 12:11:21 +0200 | [diff] [blame] | 1527 | u64 clockval; |
Nikolay Aleksandrov | 5127c81 | 2015-10-04 14:23:29 +0200 | [diff] [blame] | 1528 | |
Nikolay Aleksandrov | 4917a15 | 2015-10-05 12:11:21 +0200 | [diff] [blame] | 1529 | clockval = br_timer_value(&br->hello_timer); |
Nicolas Dichtel | 12a0faa | 2016-04-25 10:25:18 +0200 | [diff] [blame] | 1530 | if (nla_put_u64_64bit(skb, IFLA_BR_HELLO_TIMER, clockval, IFLA_BR_PAD)) |
Nikolay Aleksandrov | 4917a15 | 2015-10-05 12:11:21 +0200 | [diff] [blame] | 1531 | return -EMSGSIZE; |
| 1532 | clockval = br_timer_value(&br->tcn_timer); |
Nicolas Dichtel | 12a0faa | 2016-04-25 10:25:18 +0200 | [diff] [blame] | 1533 | if (nla_put_u64_64bit(skb, IFLA_BR_TCN_TIMER, clockval, IFLA_BR_PAD)) |
Nikolay Aleksandrov | 4917a15 | 2015-10-05 12:11:21 +0200 | [diff] [blame] | 1534 | return -EMSGSIZE; |
| 1535 | clockval = br_timer_value(&br->topology_change_timer); |
Nicolas Dichtel | 12a0faa | 2016-04-25 10:25:18 +0200 | [diff] [blame] | 1536 | if (nla_put_u64_64bit(skb, IFLA_BR_TOPOLOGY_CHANGE_TIMER, clockval, |
| 1537 | IFLA_BR_PAD)) |
Nikolay Aleksandrov | 4917a15 | 2015-10-05 12:11:21 +0200 | [diff] [blame] | 1538 | return -EMSGSIZE; |
Nikolay Aleksandrov | f7cdee8 | 2017-02-04 18:05:07 +0100 | [diff] [blame] | 1539 | clockval = br_timer_value(&br->gc_work.timer); |
Nicolas Dichtel | 12a0faa | 2016-04-25 10:25:18 +0200 | [diff] [blame] | 1540 | if (nla_put_u64_64bit(skb, IFLA_BR_GC_TIMER, clockval, IFLA_BR_PAD)) |
Nikolay Aleksandrov | 4917a15 | 2015-10-05 12:11:21 +0200 | [diff] [blame] | 1541 | return -EMSGSIZE; |
Jiri Pirko | e5c3ea5 | 2014-09-05 15:51:31 +0200 | [diff] [blame] | 1542 | |
Nikolay Aleksandrov | a428afe | 2018-11-24 04:34:20 +0200 | [diff] [blame] | 1543 | br_boolopt_multi_get(br, &bm); |
Jiri Pirko | e5c3ea5 | 2014-09-05 15:51:31 +0200 | [diff] [blame] | 1544 | if (nla_put_u32(skb, IFLA_BR_FORWARD_DELAY, forward_delay) || |
| 1545 | nla_put_u32(skb, IFLA_BR_HELLO_TIME, hello_time) || |
Jörg Thalheim | af61576 | 2015-03-18 10:06:58 +0100 | [diff] [blame] | 1546 | nla_put_u32(skb, IFLA_BR_MAX_AGE, age_time) || |
| 1547 | nla_put_u32(skb, IFLA_BR_AGEING_TIME, ageing_time) || |
| 1548 | nla_put_u32(skb, IFLA_BR_STP_STATE, stp_enabled) || |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 1549 | nla_put_u16(skb, IFLA_BR_PRIORITY, priority) || |
Nikolay Aleksandrov | 7910228 | 2015-10-04 14:23:28 +0200 | [diff] [blame] | 1550 | nla_put_u8(skb, IFLA_BR_VLAN_FILTERING, vlan_enabled) || |
Nikolay Aleksandrov | 4917a15 | 2015-10-05 12:11:21 +0200 | [diff] [blame] | 1551 | nla_put_u16(skb, IFLA_BR_GROUP_FWD_MASK, br->group_fwd_mask) || |
| 1552 | nla_put(skb, IFLA_BR_BRIDGE_ID, sizeof(struct ifla_bridge_id), |
| 1553 | &br->bridge_id) || |
| 1554 | nla_put(skb, IFLA_BR_ROOT_ID, sizeof(struct ifla_bridge_id), |
| 1555 | &br->designated_root) || |
Nikolay Aleksandrov | 684dd24 | 2015-10-04 14:23:32 +0200 | [diff] [blame] | 1556 | nla_put_u16(skb, IFLA_BR_ROOT_PORT, br->root_port) || |
Nikolay Aleksandrov | ed41630 | 2015-10-04 14:23:33 +0200 | [diff] [blame] | 1557 | nla_put_u32(skb, IFLA_BR_ROOT_PATH_COST, br->root_path_cost) || |
| 1558 | nla_put_u8(skb, IFLA_BR_TOPOLOGY_CHANGE, br->topology_change) || |
| 1559 | nla_put_u8(skb, IFLA_BR_TOPOLOGY_CHANGE_DETECTED, |
Nikolay Aleksandrov | d76bd14 | 2015-10-04 14:23:34 +0200 | [diff] [blame] | 1560 | br->topology_change_detected) || |
Nikolay Aleksandrov | a428afe | 2018-11-24 04:34:20 +0200 | [diff] [blame] | 1561 | nla_put(skb, IFLA_BR_GROUP_ADDR, ETH_ALEN, br->group_addr) || |
| 1562 | nla_put(skb, IFLA_BR_MULTI_BOOLOPT, sizeof(bm), &bm)) |
Jiri Pirko | e5c3ea5 | 2014-09-05 15:51:31 +0200 | [diff] [blame] | 1563 | return -EMSGSIZE; |
| 1564 | |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 1565 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING |
Nikolay Aleksandrov | 0f963b7 | 2015-10-04 14:23:47 +0200 | [diff] [blame] | 1566 | if (nla_put_be16(skb, IFLA_BR_VLAN_PROTOCOL, br->vlan_proto) || |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 1567 | nla_put_u16(skb, IFLA_BR_VLAN_DEFAULT_PVID, br->default_pvid) || |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 1568 | nla_put_u8(skb, IFLA_BR_VLAN_STATS_ENABLED, |
Nikolay Aleksandrov | 9163a0f | 2018-10-12 13:41:16 +0300 | [diff] [blame] | 1569 | br_opt_get(br, BROPT_VLAN_STATS_ENABLED)) || |
| 1570 | nla_put_u8(skb, IFLA_BR_VLAN_STATS_PER_PORT, |
Nikolay Aleksandrov | 600bea7 | 2019-04-16 16:15:56 +0300 | [diff] [blame] | 1571 | br_opt_get(br, BROPT_VLAN_STATS_PER_PORT))) |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 1572 | return -EMSGSIZE; |
| 1573 | #endif |
Nikolay Aleksandrov | a9a6bc7 | 2015-10-04 14:23:37 +0200 | [diff] [blame] | 1574 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1575 | if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER, |
| 1576 | br->multicast_ctx.multicast_router) || |
Nikolay Aleksandrov | 13cefad | 2018-09-26 17:01:03 +0300 | [diff] [blame] | 1577 | nla_put_u8(skb, IFLA_BR_MCAST_SNOOPING, |
| 1578 | br_opt_get(br, BROPT_MULTICAST_ENABLED)) || |
Nikolay Aleksandrov | 295141d | 2015-10-04 14:23:39 +0200 | [diff] [blame] | 1579 | nla_put_u8(skb, IFLA_BR_MCAST_QUERY_USE_IFADDR, |
Nikolay Aleksandrov | 675779a | 2018-09-26 17:01:04 +0300 | [diff] [blame] | 1580 | br_opt_get(br, BROPT_MULTICAST_QUERY_USE_IFADDR)) || |
| 1581 | nla_put_u8(skb, IFLA_BR_MCAST_QUERIER, |
Nikolay Aleksandrov | 6293818 | 2021-08-10 18:29:30 +0300 | [diff] [blame] | 1582 | br->multicast_ctx.multicast_querier) || |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1583 | nla_put_u8(skb, IFLA_BR_MCAST_STATS_ENABLED, |
Nikolay Aleksandrov | 675779a | 2018-09-26 17:01:04 +0300 | [diff] [blame] | 1584 | br_opt_get(br, BROPT_MULTICAST_STATS_ENABLED)) || |
Nikolay Aleksandrov | cf332bca | 2018-12-05 15:14:26 +0200 | [diff] [blame] | 1585 | nla_put_u32(skb, IFLA_BR_MCAST_HASH_ELASTICITY, RHT_ELASTICITY) || |
Nikolay Aleksandrov | 79b859f | 2015-10-04 14:23:43 +0200 | [diff] [blame] | 1586 | nla_put_u32(skb, IFLA_BR_MCAST_HASH_MAX, br->hash_max) || |
| 1587 | nla_put_u32(skb, IFLA_BR_MCAST_LAST_MEMBER_CNT, |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1588 | br->multicast_ctx.multicast_last_member_count) || |
Nikolay Aleksandrov | b89e6ba | 2015-10-04 14:23:44 +0200 | [diff] [blame] | 1589 | nla_put_u32(skb, IFLA_BR_MCAST_STARTUP_QUERY_CNT, |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1590 | br->multicast_ctx.multicast_startup_query_count) || |
Nikolay Aleksandrov | 5e92358 | 2016-11-21 13:03:24 +0100 | [diff] [blame] | 1591 | nla_put_u8(skb, IFLA_BR_MCAST_IGMP_VERSION, |
Nikolay Aleksandrov | c7fa1d9 | 2021-08-13 18:00:00 +0300 | [diff] [blame] | 1592 | br->multicast_ctx.multicast_igmp_version) || |
| 1593 | br_multicast_dump_querier_state(skb, &br->multicast_ctx, |
| 1594 | IFLA_BR_MCAST_QUERIER_STATE)) |
Nikolay Aleksandrov | a9a6bc7 | 2015-10-04 14:23:37 +0200 | [diff] [blame] | 1595 | return -EMSGSIZE; |
Nikolay Aleksandrov | aa2ae3e | 2016-11-21 13:03:25 +0100 | [diff] [blame] | 1596 | #if IS_ENABLED(CONFIG_IPV6) |
| 1597 | if (nla_put_u8(skb, IFLA_BR_MCAST_MLD_VERSION, |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1598 | br->multicast_ctx.multicast_mld_version)) |
Nikolay Aleksandrov | aa2ae3e | 2016-11-21 13:03:25 +0100 | [diff] [blame] | 1599 | return -EMSGSIZE; |
| 1600 | #endif |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1601 | clockval = jiffies_to_clock_t(br->multicast_ctx.multicast_last_member_interval); |
Nicolas Dichtel | 12a0faa | 2016-04-25 10:25:18 +0200 | [diff] [blame] | 1602 | if (nla_put_u64_64bit(skb, IFLA_BR_MCAST_LAST_MEMBER_INTVL, clockval, |
| 1603 | IFLA_BR_PAD)) |
Nikolay Aleksandrov | 7e4df51 | 2015-10-04 14:23:45 +0200 | [diff] [blame] | 1604 | return -EMSGSIZE; |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1605 | clockval = jiffies_to_clock_t(br->multicast_ctx.multicast_membership_interval); |
Nicolas Dichtel | 12a0faa | 2016-04-25 10:25:18 +0200 | [diff] [blame] | 1606 | if (nla_put_u64_64bit(skb, IFLA_BR_MCAST_MEMBERSHIP_INTVL, clockval, |
| 1607 | IFLA_BR_PAD)) |
Nikolay Aleksandrov | 7e4df51 | 2015-10-04 14:23:45 +0200 | [diff] [blame] | 1608 | return -EMSGSIZE; |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1609 | clockval = jiffies_to_clock_t(br->multicast_ctx.multicast_querier_interval); |
Nicolas Dichtel | 12a0faa | 2016-04-25 10:25:18 +0200 | [diff] [blame] | 1610 | if (nla_put_u64_64bit(skb, IFLA_BR_MCAST_QUERIER_INTVL, clockval, |
| 1611 | IFLA_BR_PAD)) |
Nikolay Aleksandrov | 7e4df51 | 2015-10-04 14:23:45 +0200 | [diff] [blame] | 1612 | return -EMSGSIZE; |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1613 | clockval = jiffies_to_clock_t(br->multicast_ctx.multicast_query_interval); |
Nicolas Dichtel | 12a0faa | 2016-04-25 10:25:18 +0200 | [diff] [blame] | 1614 | if (nla_put_u64_64bit(skb, IFLA_BR_MCAST_QUERY_INTVL, clockval, |
| 1615 | IFLA_BR_PAD)) |
Nikolay Aleksandrov | 7e4df51 | 2015-10-04 14:23:45 +0200 | [diff] [blame] | 1616 | return -EMSGSIZE; |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1617 | clockval = jiffies_to_clock_t(br->multicast_ctx.multicast_query_response_interval); |
Nicolas Dichtel | 12a0faa | 2016-04-25 10:25:18 +0200 | [diff] [blame] | 1618 | if (nla_put_u64_64bit(skb, IFLA_BR_MCAST_QUERY_RESPONSE_INTVL, clockval, |
| 1619 | IFLA_BR_PAD)) |
Nikolay Aleksandrov | 7e4df51 | 2015-10-04 14:23:45 +0200 | [diff] [blame] | 1620 | return -EMSGSIZE; |
Nikolay Aleksandrov | d3d065c | 2021-07-19 20:06:24 +0300 | [diff] [blame] | 1621 | clockval = jiffies_to_clock_t(br->multicast_ctx.multicast_startup_query_interval); |
Nicolas Dichtel | 12a0faa | 2016-04-25 10:25:18 +0200 | [diff] [blame] | 1622 | if (nla_put_u64_64bit(skb, IFLA_BR_MCAST_STARTUP_QUERY_INTVL, clockval, |
| 1623 | IFLA_BR_PAD)) |
Nikolay Aleksandrov | 7e4df51 | 2015-10-04 14:23:45 +0200 | [diff] [blame] | 1624 | return -EMSGSIZE; |
Nikolay Aleksandrov | a9a6bc7 | 2015-10-04 14:23:37 +0200 | [diff] [blame] | 1625 | #endif |
Nikolay Aleksandrov | 93870cc | 2015-10-04 14:23:46 +0200 | [diff] [blame] | 1626 | #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
| 1627 | if (nla_put_u8(skb, IFLA_BR_NF_CALL_IPTABLES, |
Nikolay Aleksandrov | 8df3510 | 2018-09-26 17:01:01 +0300 | [diff] [blame] | 1628 | br_opt_get(br, BROPT_NF_CALL_IPTABLES) ? 1 : 0) || |
Nikolay Aleksandrov | 93870cc | 2015-10-04 14:23:46 +0200 | [diff] [blame] | 1629 | nla_put_u8(skb, IFLA_BR_NF_CALL_IP6TABLES, |
Nikolay Aleksandrov | 8df3510 | 2018-09-26 17:01:01 +0300 | [diff] [blame] | 1630 | br_opt_get(br, BROPT_NF_CALL_IP6TABLES) ? 1 : 0) || |
Nikolay Aleksandrov | 93870cc | 2015-10-04 14:23:46 +0200 | [diff] [blame] | 1631 | nla_put_u8(skb, IFLA_BR_NF_CALL_ARPTABLES, |
Nikolay Aleksandrov | 8df3510 | 2018-09-26 17:01:01 +0300 | [diff] [blame] | 1632 | br_opt_get(br, BROPT_NF_CALL_ARPTABLES) ? 1 : 0)) |
Nikolay Aleksandrov | 93870cc | 2015-10-04 14:23:46 +0200 | [diff] [blame] | 1633 | return -EMSGSIZE; |
| 1634 | #endif |
Nikolay Aleksandrov | a9a6bc7 | 2015-10-04 14:23:37 +0200 | [diff] [blame] | 1635 | |
Jiri Pirko | e5c3ea5 | 2014-09-05 15:51:31 +0200 | [diff] [blame] | 1636 | return 0; |
| 1637 | } |
| 1638 | |
Nikolay Aleksandrov | d5ff8c4 | 2016-08-17 12:53:09 +0200 | [diff] [blame] | 1639 | static size_t br_get_linkxstats_size(const struct net_device *dev, int attr) |
Nikolay Aleksandrov | a60c090 | 2016-04-30 10:25:29 +0200 | [diff] [blame] | 1640 | { |
Nikolay Aleksandrov | d5ff8c4 | 2016-08-17 12:53:09 +0200 | [diff] [blame] | 1641 | struct net_bridge_port *p = NULL; |
Nikolay Aleksandrov | a60c090 | 2016-04-30 10:25:29 +0200 | [diff] [blame] | 1642 | struct net_bridge_vlan_group *vg; |
| 1643 | struct net_bridge_vlan *v; |
Nikolay Aleksandrov | d5ff8c4 | 2016-08-17 12:53:09 +0200 | [diff] [blame] | 1644 | struct net_bridge *br; |
Nikolay Aleksandrov | a60c090 | 2016-04-30 10:25:29 +0200 | [diff] [blame] | 1645 | int numvls = 0; |
| 1646 | |
Nikolay Aleksandrov | d5ff8c4 | 2016-08-17 12:53:09 +0200 | [diff] [blame] | 1647 | switch (attr) { |
| 1648 | case IFLA_STATS_LINK_XSTATS: |
| 1649 | br = netdev_priv(dev); |
| 1650 | vg = br_vlan_group(br); |
| 1651 | break; |
| 1652 | case IFLA_STATS_LINK_XSTATS_SLAVE: |
| 1653 | p = br_port_get_rtnl(dev); |
| 1654 | if (!p) |
| 1655 | return 0; |
Nikolay Aleksandrov | d5ff8c4 | 2016-08-17 12:53:09 +0200 | [diff] [blame] | 1656 | vg = nbp_vlan_group(p); |
| 1657 | break; |
| 1658 | default: |
| 1659 | return 0; |
| 1660 | } |
| 1661 | |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1662 | if (vg) { |
| 1663 | /* we need to count all, even placeholder entries */ |
| 1664 | list_for_each_entry(v, &vg->vlan_list, vlist) |
| 1665 | numvls++; |
| 1666 | } |
Nikolay Aleksandrov | a60c090 | 2016-04-30 10:25:29 +0200 | [diff] [blame] | 1667 | |
Nikolay Aleksandrov | a60c090 | 2016-04-30 10:25:29 +0200 | [diff] [blame] | 1668 | return numvls * nla_total_size(sizeof(struct bridge_vlan_xstats)) + |
Eric Dumazet | dbe0b88 | 2021-10-04 18:05:07 -0700 | [diff] [blame] | 1669 | nla_total_size_64bit(sizeof(struct br_mcast_stats)) + |
Eric Dumazet | 0854a051 | 2021-10-04 18:05:08 -0700 | [diff] [blame] | 1670 | (p ? nla_total_size_64bit(sizeof(p->stp_xstats)) : 0) + |
Nikolay Aleksandrov | a60c090 | 2016-04-30 10:25:29 +0200 | [diff] [blame] | 1671 | nla_total_size(0); |
| 1672 | } |
| 1673 | |
Nikolay Aleksandrov | d5ff8c4 | 2016-08-17 12:53:09 +0200 | [diff] [blame] | 1674 | static int br_fill_linkxstats(struct sk_buff *skb, |
| 1675 | const struct net_device *dev, |
| 1676 | int *prividx, int attr) |
Nikolay Aleksandrov | 80e73cc | 2016-06-28 16:57:05 +0200 | [diff] [blame] | 1677 | { |
Nikolay Aleksandrov | d5ff8c4 | 2016-08-17 12:53:09 +0200 | [diff] [blame] | 1678 | struct nlattr *nla __maybe_unused; |
| 1679 | struct net_bridge_port *p = NULL; |
| 1680 | struct net_bridge_vlan_group *vg; |
| 1681 | struct net_bridge_vlan *v; |
| 1682 | struct net_bridge *br; |
| 1683 | struct nlattr *nest; |
| 1684 | int vl_idx = 0; |
Nikolay Aleksandrov | 80e73cc | 2016-06-28 16:57:05 +0200 | [diff] [blame] | 1685 | |
| 1686 | switch (attr) { |
| 1687 | case IFLA_STATS_LINK_XSTATS: |
Nikolay Aleksandrov | d5ff8c4 | 2016-08-17 12:53:09 +0200 | [diff] [blame] | 1688 | br = netdev_priv(dev); |
| 1689 | vg = br_vlan_group(br); |
Nikolay Aleksandrov | 80e73cc | 2016-06-28 16:57:05 +0200 | [diff] [blame] | 1690 | break; |
| 1691 | case IFLA_STATS_LINK_XSTATS_SLAVE: |
Nikolay Aleksandrov | d5ff8c4 | 2016-08-17 12:53:09 +0200 | [diff] [blame] | 1692 | p = br_port_get_rtnl(dev); |
| 1693 | if (!p) |
| 1694 | return 0; |
| 1695 | br = p->br; |
| 1696 | vg = nbp_vlan_group(p); |
Nikolay Aleksandrov | 80e73cc | 2016-06-28 16:57:05 +0200 | [diff] [blame] | 1697 | break; |
Nikolay Aleksandrov | d5ff8c4 | 2016-08-17 12:53:09 +0200 | [diff] [blame] | 1698 | default: |
| 1699 | return -EINVAL; |
Nikolay Aleksandrov | 80e73cc | 2016-06-28 16:57:05 +0200 | [diff] [blame] | 1700 | } |
| 1701 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1702 | nest = nla_nest_start_noflag(skb, LINK_XSTATS_TYPE_BRIDGE); |
Nikolay Aleksandrov | a60c090 | 2016-04-30 10:25:29 +0200 | [diff] [blame] | 1703 | if (!nest) |
| 1704 | return -EMSGSIZE; |
Nikolay Aleksandrov | a60c090 | 2016-04-30 10:25:29 +0200 | [diff] [blame] | 1705 | |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1706 | if (vg) { |
Nikolay Aleksandrov | 72f4af4 | 2016-08-25 14:27:51 +0200 | [diff] [blame] | 1707 | u16 pvid; |
| 1708 | |
| 1709 | pvid = br_get_pvid(vg); |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1710 | list_for_each_entry(v, &vg->vlan_list, vlist) { |
| 1711 | struct bridge_vlan_xstats vxi; |
Heiner Kallweit | 281cc28 | 2020-11-17 21:25:42 +0100 | [diff] [blame] | 1712 | struct pcpu_sw_netstats stats; |
Nikolay Aleksandrov | a60c090 | 2016-04-30 10:25:29 +0200 | [diff] [blame] | 1713 | |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1714 | if (++vl_idx < *prividx) |
| 1715 | continue; |
| 1716 | memset(&vxi, 0, sizeof(vxi)); |
| 1717 | vxi.vid = v->vid; |
Nikolay Aleksandrov | 61ba1a2 | 2016-08-17 12:53:10 +0200 | [diff] [blame] | 1718 | vxi.flags = v->flags; |
Nikolay Aleksandrov | 72f4af4 | 2016-08-25 14:27:51 +0200 | [diff] [blame] | 1719 | if (v->vid == pvid) |
| 1720 | vxi.flags |= BRIDGE_VLAN_INFO_PVID; |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1721 | br_vlan_get_stats(v, &stats); |
| 1722 | vxi.rx_bytes = stats.rx_bytes; |
| 1723 | vxi.rx_packets = stats.rx_packets; |
| 1724 | vxi.tx_bytes = stats.tx_bytes; |
| 1725 | vxi.tx_packets = stats.tx_packets; |
| 1726 | |
| 1727 | if (nla_put(skb, BRIDGE_XSTATS_VLAN, sizeof(vxi), &vxi)) |
| 1728 | goto nla_put_failure; |
| 1729 | } |
Nikolay Aleksandrov | a60c090 | 2016-04-30 10:25:29 +0200 | [diff] [blame] | 1730 | } |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1731 | |
| 1732 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 1733 | if (++vl_idx >= *prividx) { |
| 1734 | nla = nla_reserve_64bit(skb, BRIDGE_XSTATS_MCAST, |
| 1735 | sizeof(struct br_mcast_stats), |
| 1736 | BRIDGE_XSTATS_PAD); |
| 1737 | if (!nla) |
| 1738 | goto nla_put_failure; |
Nikolay Aleksandrov | d5ff8c4 | 2016-08-17 12:53:09 +0200 | [diff] [blame] | 1739 | br_multicast_get_stats(br, p, nla_data(nla)); |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1740 | } |
| 1741 | #endif |
Vivien Didelot | de17996 | 2019-12-11 20:07:10 -0500 | [diff] [blame] | 1742 | |
| 1743 | if (p) { |
| 1744 | nla = nla_reserve_64bit(skb, BRIDGE_XSTATS_STP, |
| 1745 | sizeof(p->stp_xstats), |
| 1746 | BRIDGE_XSTATS_PAD); |
| 1747 | if (!nla) |
| 1748 | goto nla_put_failure; |
| 1749 | |
| 1750 | spin_lock_bh(&br->lock); |
| 1751 | memcpy(nla_data(nla), &p->stp_xstats, sizeof(p->stp_xstats)); |
| 1752 | spin_unlock_bh(&br->lock); |
| 1753 | } |
| 1754 | |
Nikolay Aleksandrov | a60c090 | 2016-04-30 10:25:29 +0200 | [diff] [blame] | 1755 | nla_nest_end(skb, nest); |
| 1756 | *prividx = 0; |
Nikolay Aleksandrov | 1080ab9 | 2016-06-28 16:57:06 +0200 | [diff] [blame] | 1757 | |
Nikolay Aleksandrov | a60c090 | 2016-04-30 10:25:29 +0200 | [diff] [blame] | 1758 | return 0; |
| 1759 | |
| 1760 | nla_put_failure: |
| 1761 | nla_nest_end(skb, nest); |
| 1762 | *prividx = vl_idx; |
| 1763 | |
| 1764 | return -EMSGSIZE; |
| 1765 | } |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 1766 | |
Daniel Borkmann | 207895fd3 | 2015-01-29 12:15:03 +0100 | [diff] [blame] | 1767 | static struct rtnl_af_ops br_af_ops __read_mostly = { |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 1768 | .family = AF_BRIDGE, |
Arad, Ronen | b1974ed | 2015-10-19 09:23:28 -0700 | [diff] [blame] | 1769 | .get_link_af_size = br_get_link_af_size_filtered, |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 1770 | }; |
| 1771 | |
stephen hemminger | 149ddd8 | 2012-06-26 05:48:45 +0000 | [diff] [blame] | 1772 | struct rtnl_link_ops br_link_ops __read_mostly = { |
Jiri Pirko | ced8283 | 2014-09-05 15:51:29 +0200 | [diff] [blame] | 1773 | .kind = "bridge", |
| 1774 | .priv_size = sizeof(struct net_bridge), |
| 1775 | .setup = br_dev_setup, |
Scott Feldman | eb4cb85 | 2015-08-19 11:29:35 -0700 | [diff] [blame] | 1776 | .maxtype = IFLA_BR_MAX, |
Jiri Pirko | 1332351 | 2014-09-05 15:51:32 +0200 | [diff] [blame] | 1777 | .policy = br_policy, |
Jiri Pirko | ced8283 | 2014-09-05 15:51:29 +0200 | [diff] [blame] | 1778 | .validate = br_validate, |
| 1779 | .newlink = br_dev_newlink, |
Jiri Pirko | 1332351 | 2014-09-05 15:51:32 +0200 | [diff] [blame] | 1780 | .changelink = br_changelink, |
Jiri Pirko | ced8283 | 2014-09-05 15:51:29 +0200 | [diff] [blame] | 1781 | .dellink = br_dev_delete, |
Jiri Pirko | e5c3ea5 | 2014-09-05 15:51:31 +0200 | [diff] [blame] | 1782 | .get_size = br_get_size, |
| 1783 | .fill_info = br_fill_info, |
Nikolay Aleksandrov | a60c090 | 2016-04-30 10:25:29 +0200 | [diff] [blame] | 1784 | .fill_linkxstats = br_fill_linkxstats, |
| 1785 | .get_linkxstats_size = br_get_linkxstats_size, |
Jiri Pirko | 3ac636b | 2014-09-05 15:51:30 +0200 | [diff] [blame] | 1786 | |
| 1787 | .slave_maxtype = IFLA_BRPORT_MAX, |
| 1788 | .slave_policy = br_port_policy, |
| 1789 | .slave_changelink = br_port_slave_changelink, |
Jiri Pirko | ced8283 | 2014-09-05 15:51:29 +0200 | [diff] [blame] | 1790 | .get_slave_size = br_port_get_slave_size, |
| 1791 | .fill_slave_info = br_port_fill_slave_info, |
stephen hemminger | bb900b2 | 2011-04-04 14:03:32 +0000 | [diff] [blame] | 1792 | }; |
| 1793 | |
| 1794 | int __init br_netlink_init(void) |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 1795 | { |
Vlad Yasevich | 3ec8e9f | 2013-01-02 09:41:25 +0000 | [diff] [blame] | 1796 | int err; |
| 1797 | |
| 1798 | br_mdb_init(); |
Nikolay Aleksandrov | 8dcea18 | 2020-01-14 19:56:09 +0200 | [diff] [blame] | 1799 | br_vlan_rtnl_init(); |
stephen hemminger | 3678a9d | 2013-12-30 10:41:32 -0800 | [diff] [blame] | 1800 | rtnl_af_register(&br_af_ops); |
Vlad Yasevich | 3ec8e9f | 2013-01-02 09:41:25 +0000 | [diff] [blame] | 1801 | |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 1802 | err = rtnl_link_register(&br_link_ops); |
| 1803 | if (err) |
| 1804 | goto out_af; |
| 1805 | |
Vlad Yasevich | 3ec8e9f | 2013-01-02 09:41:25 +0000 | [diff] [blame] | 1806 | return 0; |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 1807 | |
| 1808 | out_af: |
| 1809 | rtnl_af_unregister(&br_af_ops); |
Vlad Yasevich | 3ec8e9f | 2013-01-02 09:41:25 +0000 | [diff] [blame] | 1810 | br_mdb_uninit(); |
| 1811 | return err; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
Pablo Neira Ayuso | 34666d4 | 2014-09-18 11:29:03 +0200 | [diff] [blame] | 1814 | void br_netlink_fini(void) |
stephen hemminger | bb900b2 | 2011-04-04 14:03:32 +0000 | [diff] [blame] | 1815 | { |
Vlad Yasevich | 3ec8e9f | 2013-01-02 09:41:25 +0000 | [diff] [blame] | 1816 | br_mdb_uninit(); |
Nikolay Aleksandrov | 8dcea18 | 2020-01-14 19:56:09 +0200 | [diff] [blame] | 1817 | br_vlan_rtnl_uninit(); |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 1818 | rtnl_af_unregister(&br_af_ops); |
stephen hemminger | bb900b2 | 2011-04-04 14:03:32 +0000 | [diff] [blame] | 1819 | rtnl_link_unregister(&br_link_ops); |
stephen hemminger | bb900b2 | 2011-04-04 14:03:32 +0000 | [diff] [blame] | 1820 | } |