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