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" |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 23 | |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 24 | static int __get_num_vlan_infos(struct net_bridge_vlan_group *vg, |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 25 | u32 filter_mask) |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 26 | { |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 27 | struct net_bridge_vlan *v; |
| 28 | 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] | 29 | u16 flags, pvid; |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 30 | int num_vlans = 0; |
| 31 | |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 32 | if (!(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)) |
| 33 | return 0; |
| 34 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 35 | pvid = br_get_pvid(vg); |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 36 | /* Count number of vlan infos */ |
Nikolay Aleksandrov | 586c2b5 | 2015-10-02 15:05:10 +0200 | [diff] [blame] | 37 | list_for_each_entry_rcu(v, &vg->vlan_list, vlist) { |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 38 | flags = 0; |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 39 | /* only a context, bridge vlan not activated */ |
| 40 | if (!br_vlan_should_use(v)) |
| 41 | continue; |
| 42 | if (v->vid == pvid) |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 43 | flags |= BRIDGE_VLAN_INFO_PVID; |
| 44 | |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 45 | if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED) |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 46 | flags |= BRIDGE_VLAN_INFO_UNTAGGED; |
| 47 | |
| 48 | if (vid_range_start == 0) { |
| 49 | goto initvars; |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 50 | } else if ((v->vid - vid_range_end) == 1 && |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 51 | flags == vid_range_flags) { |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 52 | vid_range_end = v->vid; |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 53 | continue; |
| 54 | } else { |
| 55 | if ((vid_range_end - vid_range_start) > 0) |
| 56 | num_vlans += 2; |
| 57 | else |
| 58 | num_vlans += 1; |
| 59 | } |
| 60 | initvars: |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 61 | vid_range_start = v->vid; |
| 62 | vid_range_end = v->vid; |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 63 | vid_range_flags = flags; |
| 64 | } |
| 65 | |
| 66 | if (vid_range_start != 0) { |
| 67 | if ((vid_range_end - vid_range_start) > 0) |
| 68 | num_vlans += 2; |
| 69 | else |
| 70 | num_vlans += 1; |
| 71 | } |
| 72 | |
| 73 | return num_vlans; |
| 74 | } |
| 75 | |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 76 | 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] | 77 | u32 filter_mask) |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 78 | { |
Nikolay Aleksandrov | 586c2b5 | 2015-10-02 15:05:10 +0200 | [diff] [blame] | 79 | int num_vlans; |
| 80 | |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 81 | if (!vg) |
| 82 | return 0; |
| 83 | |
| 84 | if (filter_mask & RTEXT_FILTER_BRVLAN) |
| 85 | return vg->num_vlans; |
| 86 | |
Nikolay Aleksandrov | 586c2b5 | 2015-10-02 15:05:10 +0200 | [diff] [blame] | 87 | rcu_read_lock(); |
| 88 | num_vlans = __get_num_vlan_infos(vg, filter_mask); |
| 89 | rcu_read_unlock(); |
| 90 | |
| 91 | return num_vlans; |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 92 | } |
| 93 | |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 94 | static size_t br_get_link_af_size_filtered(const struct net_device *dev, |
| 95 | u32 filter_mask) |
Roopa Prabhu | b7853d7 | 2015-02-21 20:21:51 -0800 | [diff] [blame] | 96 | { |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 97 | struct net_bridge_vlan_group *vg = NULL; |
| 98 | struct net_bridge_port *p; |
| 99 | struct net_bridge *br; |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 100 | int num_vlan_infos; |
Roopa Prabhu | b7853d7 | 2015-02-21 20:21:51 -0800 | [diff] [blame] | 101 | |
Johannes Berg | 2f56f6b | 2015-03-03 16:02:16 +0100 | [diff] [blame] | 102 | rcu_read_lock(); |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 103 | if (br_port_exists(dev)) { |
| 104 | p = br_port_get_rcu(dev); |
| 105 | vg = nbp_vlan_group(p); |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 106 | } else if (dev->priv_flags & IFF_EBRIDGE) { |
| 107 | br = netdev_priv(dev); |
| 108 | vg = br_vlan_group(br); |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 109 | } |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 110 | num_vlan_infos = br_get_num_vlan_infos(vg, filter_mask); |
Johannes Berg | 2f56f6b | 2015-03-03 16:02:16 +0100 | [diff] [blame] | 111 | rcu_read_unlock(); |
Roopa Prabhu | b7853d7 | 2015-02-21 20:21:51 -0800 | [diff] [blame] | 112 | |
Roopa Prabhu | b7853d7 | 2015-02-21 20:21:51 -0800 | [diff] [blame] | 113 | /* Each VLAN is returned in bridge_vlan_info along with flags */ |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 114 | return num_vlan_infos * nla_total_size(sizeof(struct bridge_vlan_info)); |
Roopa Prabhu | b7853d7 | 2015-02-21 20:21:51 -0800 | [diff] [blame] | 115 | } |
| 116 | |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 117 | static inline size_t br_port_info_size(void) |
| 118 | { |
| 119 | return nla_total_size(1) /* IFLA_BRPORT_STATE */ |
| 120 | + nla_total_size(2) /* IFLA_BRPORT_PRIORITY */ |
| 121 | + nla_total_size(4) /* IFLA_BRPORT_COST */ |
| 122 | + nla_total_size(1) /* IFLA_BRPORT_MODE */ |
stephen hemminger | a2e01a6 | 2012-11-13 07:53:07 +0000 | [diff] [blame] | 123 | + nla_total_size(1) /* IFLA_BRPORT_GUARD */ |
stephen hemminger | 1007dd1 | 2012-11-13 07:53:08 +0000 | [diff] [blame] | 124 | + nla_total_size(1) /* IFLA_BRPORT_PROTECT */ |
stephen hemminger | 3da889b | 2013-03-11 13:52:17 +0000 | [diff] [blame] | 125 | + nla_total_size(1) /* IFLA_BRPORT_FAST_LEAVE */ |
Vlad Yasevich | 9ba1889 | 2013-06-05 10:08:00 -0400 | [diff] [blame] | 126 | + nla_total_size(1) /* IFLA_BRPORT_LEARNING */ |
Vlad Yasevich | 867a594 | 2013-06-05 10:08:01 -0400 | [diff] [blame] | 127 | + nla_total_size(1) /* IFLA_BRPORT_UNICAST_FLOOD */ |
Nikolay Aleksandrov | 355b9f9 | 2015-08-04 19:06:32 +0200 | [diff] [blame] | 128 | + nla_total_size(1) /* IFLA_BRPORT_PROXYARP */ |
Nikolay Aleksandrov | 786c207 | 2015-08-04 19:06:33 +0200 | [diff] [blame] | 129 | + nla_total_size(1) /* IFLA_BRPORT_PROXYARP_WIFI */ |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 130 | + 0; |
| 131 | } |
| 132 | |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 133 | 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] | 134 | { |
| 135 | return NLMSG_ALIGN(sizeof(struct ifinfomsg)) |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 136 | + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */ |
| 137 | + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */ |
| 138 | + nla_total_size(4) /* IFLA_MASTER */ |
| 139 | + nla_total_size(4) /* IFLA_MTU */ |
| 140 | + nla_total_size(4) /* IFLA_LINK */ |
| 141 | + nla_total_size(1) /* IFLA_OPERSTATE */ |
Roopa Prabhu | b7853d7 | 2015-02-21 20:21:51 -0800 | [diff] [blame] | 142 | + nla_total_size(br_port_info_size()) /* IFLA_PROTINFO */ |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 143 | + nla_total_size(br_get_link_af_size_filtered(dev, |
| 144 | filter_mask)); /* IFLA_AF_SPEC */ |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static int br_port_fill_attrs(struct sk_buff *skb, |
| 148 | const struct net_bridge_port *p) |
| 149 | { |
| 150 | u8 mode = !!(p->flags & BR_HAIRPIN_MODE); |
| 151 | |
| 152 | if (nla_put_u8(skb, IFLA_BRPORT_STATE, p->state) || |
| 153 | nla_put_u16(skb, IFLA_BRPORT_PRIORITY, p->priority) || |
| 154 | nla_put_u32(skb, IFLA_BRPORT_COST, p->path_cost) || |
stephen hemminger | a2e01a6 | 2012-11-13 07:53:07 +0000 | [diff] [blame] | 155 | nla_put_u8(skb, IFLA_BRPORT_MODE, mode) || |
stephen hemminger | 1007dd1 | 2012-11-13 07:53:08 +0000 | [diff] [blame] | 156 | nla_put_u8(skb, IFLA_BRPORT_GUARD, !!(p->flags & BR_BPDU_GUARD)) || |
David S. Miller | c2d3bab | 2012-12-05 16:24:45 -0500 | [diff] [blame] | 157 | nla_put_u8(skb, IFLA_BRPORT_PROTECT, !!(p->flags & BR_ROOT_BLOCK)) || |
Vlad Yasevich | 9ba1889 | 2013-06-05 10:08:00 -0400 | [diff] [blame] | 158 | nla_put_u8(skb, IFLA_BRPORT_FAST_LEAVE, !!(p->flags & BR_MULTICAST_FAST_LEAVE)) || |
Vlad Yasevich | 867a594 | 2013-06-05 10:08:01 -0400 | [diff] [blame] | 159 | nla_put_u8(skb, IFLA_BRPORT_LEARNING, !!(p->flags & BR_LEARNING)) || |
Kyeyoon Park | 9585011 | 2014-10-23 14:49:17 -0700 | [diff] [blame] | 160 | nla_put_u8(skb, IFLA_BRPORT_UNICAST_FLOOD, !!(p->flags & BR_FLOOD)) || |
Jouni Malinen | 842a9ae | 2015-03-04 12:54:21 +0200 | [diff] [blame] | 161 | nla_put_u8(skb, IFLA_BRPORT_PROXYARP, !!(p->flags & BR_PROXYARP)) || |
| 162 | nla_put_u8(skb, IFLA_BRPORT_PROXYARP_WIFI, |
| 163 | !!(p->flags & BR_PROXYARP_WIFI))) |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 164 | return -EMSGSIZE; |
| 165 | |
| 166 | return 0; |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 169 | static int br_fill_ifvlaninfo_range(struct sk_buff *skb, u16 vid_start, |
| 170 | u16 vid_end, u16 flags) |
| 171 | { |
| 172 | struct bridge_vlan_info vinfo; |
| 173 | |
| 174 | if ((vid_end - vid_start) > 0) { |
| 175 | /* add range to skb */ |
| 176 | vinfo.vid = vid_start; |
| 177 | vinfo.flags = flags | BRIDGE_VLAN_INFO_RANGE_BEGIN; |
| 178 | if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO, |
| 179 | sizeof(vinfo), &vinfo)) |
| 180 | goto nla_put_failure; |
| 181 | |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 182 | vinfo.vid = vid_end; |
| 183 | vinfo.flags = flags | BRIDGE_VLAN_INFO_RANGE_END; |
| 184 | if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO, |
| 185 | sizeof(vinfo), &vinfo)) |
| 186 | goto nla_put_failure; |
| 187 | } else { |
| 188 | vinfo.vid = vid_start; |
| 189 | vinfo.flags = flags; |
| 190 | if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO, |
| 191 | sizeof(vinfo), &vinfo)) |
| 192 | goto nla_put_failure; |
| 193 | } |
| 194 | |
| 195 | return 0; |
| 196 | |
| 197 | nla_put_failure: |
| 198 | return -EMSGSIZE; |
| 199 | } |
| 200 | |
| 201 | static int br_fill_ifvlaninfo_compressed(struct sk_buff *skb, |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 202 | struct net_bridge_vlan_group *vg) |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 203 | { |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 204 | struct net_bridge_vlan *v; |
| 205 | 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] | 206 | u16 flags, pvid; |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 207 | int err = 0; |
| 208 | |
| 209 | /* Pack IFLA_BRIDGE_VLAN_INFO's for every vlan |
| 210 | * and mark vlan info with begin and end flags |
| 211 | * if vlaninfo represents a range |
| 212 | */ |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 213 | pvid = br_get_pvid(vg); |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 214 | list_for_each_entry(v, &vg->vlan_list, vlist) { |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 215 | flags = 0; |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 216 | if (!br_vlan_should_use(v)) |
| 217 | continue; |
| 218 | if (v->vid == pvid) |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 219 | flags |= BRIDGE_VLAN_INFO_PVID; |
| 220 | |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 221 | if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED) |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 222 | flags |= BRIDGE_VLAN_INFO_UNTAGGED; |
| 223 | |
| 224 | if (vid_range_start == 0) { |
| 225 | goto initvars; |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 226 | } else if ((v->vid - vid_range_end) == 1 && |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 227 | flags == vid_range_flags) { |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 228 | vid_range_end = v->vid; |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 229 | continue; |
| 230 | } else { |
| 231 | err = br_fill_ifvlaninfo_range(skb, vid_range_start, |
| 232 | vid_range_end, |
| 233 | vid_range_flags); |
| 234 | if (err) |
| 235 | return err; |
| 236 | } |
| 237 | |
| 238 | initvars: |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 239 | vid_range_start = v->vid; |
| 240 | vid_range_end = v->vid; |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 241 | vid_range_flags = flags; |
| 242 | } |
| 243 | |
Roopa Prabhu | 0fe6de4 | 2015-01-12 16:25:28 -0800 | [diff] [blame] | 244 | if (vid_range_start != 0) { |
| 245 | /* Call it once more to send any left over vlans */ |
| 246 | err = br_fill_ifvlaninfo_range(skb, vid_range_start, |
| 247 | vid_range_end, |
| 248 | vid_range_flags); |
| 249 | if (err) |
| 250 | return err; |
| 251 | } |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | static int br_fill_ifvlaninfo(struct sk_buff *skb, |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 257 | struct net_bridge_vlan_group *vg) |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 258 | { |
| 259 | struct bridge_vlan_info vinfo; |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 260 | struct net_bridge_vlan *v; |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 261 | u16 pvid; |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 262 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 263 | pvid = br_get_pvid(vg); |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 264 | list_for_each_entry(v, &vg->vlan_list, vlist) { |
| 265 | if (!br_vlan_should_use(v)) |
| 266 | continue; |
| 267 | |
| 268 | vinfo.vid = v->vid; |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 269 | vinfo.flags = 0; |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 270 | if (v->vid == pvid) |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 271 | vinfo.flags |= BRIDGE_VLAN_INFO_PVID; |
| 272 | |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 273 | if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED) |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 274 | vinfo.flags |= BRIDGE_VLAN_INFO_UNTAGGED; |
| 275 | |
| 276 | if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO, |
| 277 | sizeof(vinfo), &vinfo)) |
| 278 | goto nla_put_failure; |
| 279 | } |
| 280 | |
| 281 | return 0; |
| 282 | |
| 283 | nla_put_failure: |
| 284 | return -EMSGSIZE; |
| 285 | } |
| 286 | |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 287 | /* |
| 288 | * Create one netlink message for one interface |
| 289 | * Contains port and master info as well as carrier and bridge state. |
| 290 | */ |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 291 | static int br_fill_ifinfo(struct sk_buff *skb, |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 292 | struct net_bridge_port *port, |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 293 | u32 pid, u32 seq, int event, unsigned int flags, |
| 294 | u32 filter_mask, const struct net_device *dev) |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 295 | { |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 296 | struct net_bridge *br; |
Thomas Graf | 7468596 | 2006-11-20 16:20:22 -0800 | [diff] [blame] | 297 | struct ifinfomsg *hdr; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 298 | struct nlmsghdr *nlh; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 299 | u8 operstate = netif_running(dev) ? dev->operstate : IF_OPER_DOWN; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 300 | |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 301 | if (port) |
| 302 | br = port->br; |
| 303 | else |
| 304 | br = netdev_priv(dev); |
| 305 | |
stephen hemminger | 28a16c9 | 2010-05-10 09:31:09 +0000 | [diff] [blame] | 306 | br_debug(br, "br_fill_info event %d port %s master %s\n", |
| 307 | event, dev->name, br->dev->name); |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 308 | |
Thomas Graf | 7468596 | 2006-11-20 16:20:22 -0800 | [diff] [blame] | 309 | nlh = nlmsg_put(skb, pid, seq, event, sizeof(*hdr), flags); |
| 310 | if (nlh == NULL) |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 311 | return -EMSGSIZE; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 312 | |
Thomas Graf | 7468596 | 2006-11-20 16:20:22 -0800 | [diff] [blame] | 313 | hdr = nlmsg_data(nlh); |
| 314 | hdr->ifi_family = AF_BRIDGE; |
| 315 | hdr->__ifi_pad = 0; |
| 316 | hdr->ifi_type = dev->type; |
| 317 | hdr->ifi_index = dev->ifindex; |
| 318 | hdr->ifi_flags = dev_get_flags(dev); |
| 319 | hdr->ifi_change = 0; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 320 | |
David S. Miller | 2eb812e | 2012-04-01 20:49:54 -0400 | [diff] [blame] | 321 | if (nla_put_string(skb, IFLA_IFNAME, dev->name) || |
| 322 | nla_put_u32(skb, IFLA_MASTER, br->dev->ifindex) || |
| 323 | nla_put_u32(skb, IFLA_MTU, dev->mtu) || |
| 324 | nla_put_u8(skb, IFLA_OPERSTATE, operstate) || |
| 325 | (dev->addr_len && |
| 326 | nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) || |
Nicolas Dichtel | a54acb3 | 2015-04-02 17:07:00 +0200 | [diff] [blame] | 327 | (dev->ifindex != dev_get_iflink(dev) && |
| 328 | nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev)))) |
David S. Miller | 2eb812e | 2012-04-01 20:49:54 -0400 | [diff] [blame] | 329 | goto nla_put_failure; |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 330 | |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 331 | if (event == RTM_NEWLINK && port) { |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 332 | struct nlattr *nest |
| 333 | = nla_nest_start(skb, IFLA_PROTINFO | NLA_F_NESTED); |
| 334 | |
| 335 | if (nest == NULL || br_port_fill_attrs(skb, port) < 0) |
| 336 | goto nla_put_failure; |
| 337 | nla_nest_end(skb, nest); |
| 338 | } |
| 339 | |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 340 | /* Check if the VID information is requested */ |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 341 | if ((filter_mask & RTEXT_FILTER_BRVLAN) || |
| 342 | (filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)) { |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 343 | struct net_bridge_vlan_group *vg; |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 344 | struct nlattr *af; |
| 345 | int err; |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 346 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 347 | if (port) |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 348 | vg = nbp_vlan_group(port); |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 349 | else |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 350 | vg = br_vlan_group(br); |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 351 | |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 352 | if (!vg || !vg->num_vlans) |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 353 | goto done; |
| 354 | |
| 355 | af = nla_nest_start(skb, IFLA_AF_SPEC); |
| 356 | if (!af) |
| 357 | goto nla_put_failure; |
| 358 | |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 359 | if (filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED) |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 360 | err = br_fill_ifvlaninfo_compressed(skb, vg); |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 361 | else |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 362 | err = br_fill_ifvlaninfo(skb, vg); |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 363 | if (err) |
| 364 | goto nla_put_failure; |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 365 | nla_nest_end(skb, af); |
| 366 | } |
| 367 | |
| 368 | done: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 369 | nlmsg_end(skb, nlh); |
| 370 | return 0; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 371 | |
Thomas Graf | 7468596 | 2006-11-20 16:20:22 -0800 | [diff] [blame] | 372 | nla_put_failure: |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 373 | nlmsg_cancel(skb, nlh); |
| 374 | return -EMSGSIZE; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | /* |
| 378 | * Notify listeners of a change in port information |
| 379 | */ |
| 380 | void br_ifinfo_notify(int event, struct net_bridge_port *port) |
| 381 | { |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 382 | struct net *net; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 383 | struct sk_buff *skb; |
Thomas Graf | 280a306 | 2006-08-15 00:36:28 -0700 | [diff] [blame] | 384 | int err = -ENOBUFS; |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 385 | u32 filter = RTEXT_FILTER_BRVLAN_COMPRESSED; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 386 | |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 387 | if (!port) |
| 388 | return; |
| 389 | |
| 390 | net = dev_net(port->dev); |
stephen hemminger | 28a16c9 | 2010-05-10 09:31:09 +0000 | [diff] [blame] | 391 | br_debug(port->br, "port %u(%s) event %d\n", |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 392 | (unsigned int)port->port_no, port->dev->name, event); |
stephen hemminger | 28a16c9 | 2010-05-10 09:31:09 +0000 | [diff] [blame] | 393 | |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 394 | skb = nlmsg_new(br_nlmsg_size(port->dev, filter), GFP_ATOMIC); |
Thomas Graf | 280a306 | 2006-08-15 00:36:28 -0700 | [diff] [blame] | 395 | if (skb == NULL) |
| 396 | goto errout; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 397 | |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 398 | 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] | 399 | if (err < 0) { |
| 400 | /* -EMSGSIZE implies BUG in br_nlmsg_size() */ |
| 401 | WARN_ON(err == -EMSGSIZE); |
| 402 | kfree_skb(skb); |
| 403 | goto errout; |
| 404 | } |
Pablo Neira Ayuso | 1ce85fe | 2009-02-24 23:18:28 -0800 | [diff] [blame] | 405 | rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC); |
| 406 | return; |
Thomas Graf | 280a306 | 2006-08-15 00:36:28 -0700 | [diff] [blame] | 407 | errout: |
tanxiaojun | 87e823b | 2013-12-19 13:28:10 +0800 | [diff] [blame] | 408 | rtnl_set_sk_err(net, RTNLGRP_LINK, err); |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 411 | |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 412 | /* |
| 413 | * Dump information about all ports, in response to GETLINK |
| 414 | */ |
John Fastabend | e5a55a8 | 2012-10-24 08:12:57 +0000 | [diff] [blame] | 415 | int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 416 | struct net_device *dev, u32 filter_mask, int nlflags) |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 417 | { |
Hong Zhiguo | 1fb1754 | 2013-09-14 22:42:27 +0800 | [diff] [blame] | 418 | struct net_bridge_port *port = br_port_get_rtnl(dev); |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 419 | |
Roopa Prabhu | 36cd0ff | 2015-01-10 07:31:14 -0800 | [diff] [blame] | 420 | if (!port && !(filter_mask & RTEXT_FILTER_BRVLAN) && |
| 421 | !(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)) |
Dan Carpenter | 1b846f9 | 2015-01-21 12:22:35 +0300 | [diff] [blame] | 422 | return 0; |
stephen hemminger | b5ed54e | 2010-11-15 06:38:13 +0000 | [diff] [blame] | 423 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 424 | return br_fill_ifinfo(skb, port, pid, seq, RTM_NEWLINK, nlflags, |
Dan Carpenter | 1b846f9 | 2015-01-21 12:22:35 +0300 | [diff] [blame] | 425 | filter_mask, dev); |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 428 | static int br_vlan_info(struct net_bridge *br, struct net_bridge_port *p, |
| 429 | int cmd, struct bridge_vlan_info *vinfo) |
| 430 | { |
| 431 | int err = 0; |
| 432 | |
| 433 | switch (cmd) { |
| 434 | case RTM_SETLINK: |
| 435 | if (p) { |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 436 | /* if the MASTER flag is set this will act on the global |
| 437 | * per-VLAN entry as well |
| 438 | */ |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 439 | err = nbp_vlan_add(p, vinfo->vid, vinfo->flags); |
| 440 | if (err) |
| 441 | break; |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 442 | } else { |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 443 | vinfo->flags |= BRIDGE_VLAN_INFO_BRENTRY; |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 444 | err = br_vlan_add(br, vinfo->vid, vinfo->flags); |
| 445 | } |
| 446 | break; |
| 447 | |
| 448 | case RTM_DELLINK: |
| 449 | if (p) { |
| 450 | nbp_vlan_delete(p, vinfo->vid); |
| 451 | if (vinfo->flags & BRIDGE_VLAN_INFO_MASTER) |
| 452 | br_vlan_delete(p->br, vinfo->vid); |
| 453 | } else { |
| 454 | br_vlan_delete(br, vinfo->vid); |
| 455 | } |
| 456 | break; |
| 457 | } |
| 458 | |
| 459 | return err; |
| 460 | } |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 461 | |
| 462 | static int br_afspec(struct net_bridge *br, |
| 463 | struct net_bridge_port *p, |
| 464 | struct nlattr *af_spec, |
| 465 | int cmd) |
| 466 | { |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 467 | struct bridge_vlan_info *vinfo_start = NULL; |
| 468 | struct bridge_vlan_info *vinfo = NULL; |
| 469 | struct nlattr *attr; |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 470 | int err = 0; |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 471 | int rem; |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 472 | |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 473 | nla_for_each_nested(attr, af_spec, rem) { |
| 474 | if (nla_type(attr) != IFLA_BRIDGE_VLAN_INFO) |
| 475 | continue; |
| 476 | if (nla_len(attr) != sizeof(struct bridge_vlan_info)) |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 477 | return -EINVAL; |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 478 | vinfo = nla_data(attr); |
Nikolay Aleksandrov | 462e1ea | 2015-07-02 05:48:17 -0700 | [diff] [blame] | 479 | if (!vinfo->vid || vinfo->vid >= VLAN_VID_MASK) |
| 480 | return -EINVAL; |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 481 | if (vinfo->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) { |
| 482 | if (vinfo_start) |
| 483 | return -EINVAL; |
| 484 | vinfo_start = vinfo; |
| 485 | continue; |
| 486 | } |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 487 | |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 488 | if (vinfo_start) { |
| 489 | struct bridge_vlan_info tmp_vinfo; |
| 490 | int v; |
| 491 | |
| 492 | if (!(vinfo->flags & BRIDGE_VLAN_INFO_RANGE_END)) |
| 493 | return -EINVAL; |
| 494 | |
| 495 | if (vinfo->vid <= vinfo_start->vid) |
| 496 | return -EINVAL; |
| 497 | |
| 498 | memcpy(&tmp_vinfo, vinfo_start, |
| 499 | sizeof(struct bridge_vlan_info)); |
| 500 | |
| 501 | for (v = vinfo_start->vid; v <= vinfo->vid; v++) { |
| 502 | tmp_vinfo.vid = v; |
| 503 | err = br_vlan_info(br, p, cmd, &tmp_vinfo); |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 504 | if (err) |
| 505 | break; |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 506 | } |
| 507 | vinfo_start = NULL; |
| 508 | } else { |
| 509 | err = br_vlan_info(br, p, cmd, vinfo); |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 510 | } |
Roopa Prabhu | bdced7e | 2015-01-10 07:31:12 -0800 | [diff] [blame] | 511 | if (err) |
| 512 | break; |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | return err; |
| 516 | } |
| 517 | |
Jiri Pirko | 3ac636b | 2014-09-05 15:51:30 +0200 | [diff] [blame] | 518 | static const struct nla_policy br_port_policy[IFLA_BRPORT_MAX + 1] = { |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 519 | [IFLA_BRPORT_STATE] = { .type = NLA_U8 }, |
| 520 | [IFLA_BRPORT_COST] = { .type = NLA_U32 }, |
| 521 | [IFLA_BRPORT_PRIORITY] = { .type = NLA_U16 }, |
| 522 | [IFLA_BRPORT_MODE] = { .type = NLA_U8 }, |
stephen hemminger | a2e01a6 | 2012-11-13 07:53:07 +0000 | [diff] [blame] | 523 | [IFLA_BRPORT_GUARD] = { .type = NLA_U8 }, |
stephen hemminger | 1007dd1 | 2012-11-13 07:53:08 +0000 | [diff] [blame] | 524 | [IFLA_BRPORT_PROTECT] = { .type = NLA_U8 }, |
Thomas Graf | 6f705d8 | 2014-11-26 13:42:19 +0100 | [diff] [blame] | 525 | [IFLA_BRPORT_FAST_LEAVE]= { .type = NLA_U8 }, |
Vlad Yasevich | 9ba1889 | 2013-06-05 10:08:00 -0400 | [diff] [blame] | 526 | [IFLA_BRPORT_LEARNING] = { .type = NLA_U8 }, |
Vlad Yasevich | 867a594 | 2013-06-05 10:08:01 -0400 | [diff] [blame] | 527 | [IFLA_BRPORT_UNICAST_FLOOD] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | 355b9f9 | 2015-08-04 19:06:32 +0200 | [diff] [blame] | 528 | [IFLA_BRPORT_PROXYARP] = { .type = NLA_U8 }, |
Nikolay Aleksandrov | 786c207 | 2015-08-04 19:06:33 +0200 | [diff] [blame] | 529 | [IFLA_BRPORT_PROXYARP_WIFI] = { .type = NLA_U8 }, |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 530 | }; |
| 531 | |
| 532 | /* Change the state of the port and notify spanning tree */ |
| 533 | 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] | 534 | { |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 535 | if (state > BR_STATE_BLOCKING) |
stephen hemminger | b5ed54e | 2010-11-15 06:38:13 +0000 | [diff] [blame] | 536 | return -EINVAL; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 537 | |
| 538 | /* if kernel STP is running, don't allow changes */ |
Stephen Hemminger | 9cde070 | 2007-03-21 14:22:44 -0700 | [diff] [blame] | 539 | if (p->br->stp_enabled == BR_KERNEL_STP) |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 540 | return -EBUSY; |
| 541 | |
stephen hemminger | 576eb62 | 2012-12-28 18:15:22 +0000 | [diff] [blame] | 542 | /* if device is not up, change is not allowed |
| 543 | * if link is not present, only allowable state is disabled |
| 544 | */ |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 545 | if (!netif_running(p->dev) || |
stephen hemminger | 576eb62 | 2012-12-28 18:15:22 +0000 | [diff] [blame] | 546 | (!netif_oper_up(p->dev) && state != BR_STATE_DISABLED)) |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 547 | return -ENETDOWN; |
| 548 | |
Florian Fainelli | 775dd69 | 2014-09-30 16:13:19 -0700 | [diff] [blame] | 549 | br_set_state(p, state); |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 550 | br_log_state(p); |
Vitalii Demianets | b03b6dd | 2011-11-25 00:16:37 +0000 | [diff] [blame] | 551 | br_port_state_selection(p->br); |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 552 | return 0; |
| 553 | } |
| 554 | |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 555 | /* Set/clear or port flags based on attribute */ |
| 556 | static void br_set_port_flag(struct net_bridge_port *p, struct nlattr *tb[], |
| 557 | int attrtype, unsigned long mask) |
| 558 | { |
| 559 | if (tb[attrtype]) { |
| 560 | u8 flag = nla_get_u8(tb[attrtype]); |
| 561 | if (flag) |
| 562 | p->flags |= mask; |
| 563 | else |
| 564 | p->flags &= ~mask; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | /* Process bridge protocol info on port */ |
| 569 | static int br_setport(struct net_bridge_port *p, struct nlattr *tb[]) |
| 570 | { |
| 571 | int err; |
Vlad Yasevich | e028e4b | 2014-05-16 09:59:16 -0400 | [diff] [blame] | 572 | unsigned long old_flags = p->flags; |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 573 | |
| 574 | br_set_port_flag(p, tb, IFLA_BRPORT_MODE, BR_HAIRPIN_MODE); |
stephen hemminger | a2e01a6 | 2012-11-13 07:53:07 +0000 | [diff] [blame] | 575 | 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] | 576 | 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] | 577 | br_set_port_flag(p, tb, IFLA_BRPORT_PROTECT, BR_ROOT_BLOCK); |
Vlad Yasevich | 9ba1889 | 2013-06-05 10:08:00 -0400 | [diff] [blame] | 578 | br_set_port_flag(p, tb, IFLA_BRPORT_LEARNING, BR_LEARNING); |
Vlad Yasevich | 867a594 | 2013-06-05 10:08:01 -0400 | [diff] [blame] | 579 | br_set_port_flag(p, tb, IFLA_BRPORT_UNICAST_FLOOD, BR_FLOOD); |
Kyeyoon Park | 9585011 | 2014-10-23 14:49:17 -0700 | [diff] [blame] | 580 | br_set_port_flag(p, tb, IFLA_BRPORT_PROXYARP, BR_PROXYARP); |
Jouni Malinen | 842a9ae | 2015-03-04 12:54:21 +0200 | [diff] [blame] | 581 | 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] | 582 | |
| 583 | if (tb[IFLA_BRPORT_COST]) { |
| 584 | err = br_stp_set_path_cost(p, nla_get_u32(tb[IFLA_BRPORT_COST])); |
| 585 | if (err) |
| 586 | return err; |
| 587 | } |
| 588 | |
| 589 | if (tb[IFLA_BRPORT_PRIORITY]) { |
| 590 | err = br_stp_set_port_priority(p, nla_get_u16(tb[IFLA_BRPORT_PRIORITY])); |
| 591 | if (err) |
| 592 | return err; |
| 593 | } |
| 594 | |
| 595 | if (tb[IFLA_BRPORT_STATE]) { |
| 596 | err = br_set_port_state(p, nla_get_u8(tb[IFLA_BRPORT_STATE])); |
| 597 | if (err) |
| 598 | return err; |
| 599 | } |
Vlad Yasevich | e028e4b | 2014-05-16 09:59:16 -0400 | [diff] [blame] | 600 | |
| 601 | br_port_flags_change(p, old_flags ^ p->flags); |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 602 | return 0; |
| 603 | } |
| 604 | |
| 605 | /* Change state and parameters on port. */ |
Roopa Prabhu | add511b | 2015-01-29 22:40:12 -0800 | [diff] [blame] | 606 | int br_setlink(struct net_device *dev, struct nlmsghdr *nlh, u16 flags) |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 607 | { |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 608 | struct nlattr *protinfo; |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 609 | struct nlattr *afspec; |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 610 | struct net_bridge_port *p; |
Dan Carpenter | 2062cc2 | 2012-12-07 01:10:46 +0000 | [diff] [blame] | 611 | struct nlattr *tb[IFLA_BRPORT_MAX + 1]; |
Scott Feldman | 41c498b | 2015-05-10 09:47:59 -0700 | [diff] [blame] | 612 | int err = 0; |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 613 | |
Hong zhi guo | c60ee67 | 2013-03-28 06:21:22 +0000 | [diff] [blame] | 614 | protinfo = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_PROTINFO); |
| 615 | afspec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 616 | if (!protinfo && !afspec) |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 617 | return 0; |
| 618 | |
| 619 | p = br_port_get_rtnl(dev); |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 620 | /* We want to accept dev as bridge itself if the AF_SPEC |
stephen hemminger | 8e3bff9 | 2013-12-08 12:15:44 -0800 | [diff] [blame] | 621 | * 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] | 622 | */ |
Hong zhi guo | 7b99a99 | 2013-03-24 03:26:47 +0000 | [diff] [blame] | 623 | if (!p && !afspec) |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 624 | return -EINVAL; |
| 625 | |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 626 | if (p && protinfo) { |
| 627 | if (protinfo->nla_type & NLA_F_NESTED) { |
| 628 | err = nla_parse_nested(tb, IFLA_BRPORT_MAX, |
Jiri Pirko | 3ac636b | 2014-09-05 15:51:30 +0200 | [diff] [blame] | 629 | protinfo, br_port_policy); |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 630 | if (err) |
| 631 | return err; |
| 632 | |
| 633 | spin_lock_bh(&p->br->lock); |
| 634 | err = br_setport(p, tb); |
| 635 | spin_unlock_bh(&p->br->lock); |
| 636 | } else { |
stephen hemminger | 8e3bff9 | 2013-12-08 12:15:44 -0800 | [diff] [blame] | 637 | /* Binary compatibility with old RSTP */ |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 638 | if (nla_len(protinfo) < sizeof(u8)) |
| 639 | return -EINVAL; |
| 640 | |
| 641 | spin_lock_bh(&p->br->lock); |
| 642 | err = br_set_port_state(p, nla_get_u8(protinfo)); |
| 643 | spin_unlock_bh(&p->br->lock); |
| 644 | } |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 645 | if (err) |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 646 | goto out; |
| 647 | } |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 648 | |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 649 | if (afspec) { |
| 650 | err = br_afspec((struct net_bridge *)netdev_priv(dev), p, |
| 651 | afspec, RTM_SETLINK); |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | if (err == 0) |
| 655 | br_ifinfo_notify(RTM_NEWLINK, p); |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 656 | out: |
stephen hemminger | 25c71c7 | 2012-11-13 07:53:05 +0000 | [diff] [blame] | 657 | return err; |
| 658 | } |
| 659 | |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 660 | /* Delete port information */ |
Roopa Prabhu | add511b | 2015-01-29 22:40:12 -0800 | [diff] [blame] | 661 | int br_dellink(struct net_device *dev, struct nlmsghdr *nlh, u16 flags) |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 662 | { |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 663 | struct nlattr *afspec; |
| 664 | struct net_bridge_port *p; |
Scott Feldman | 8508025 | 2015-05-10 09:48:03 -0700 | [diff] [blame] | 665 | int err = 0; |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 666 | |
Hong zhi guo | c60ee67 | 2013-03-28 06:21:22 +0000 | [diff] [blame] | 667 | afspec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 668 | if (!afspec) |
| 669 | return 0; |
| 670 | |
| 671 | p = br_port_get_rtnl(dev); |
| 672 | /* We want to accept dev as bridge itself as well */ |
| 673 | if (!p && !(dev->priv_flags & IFF_EBRIDGE)) |
| 674 | return -EINVAL; |
| 675 | |
| 676 | err = br_afspec((struct net_bridge *)netdev_priv(dev), p, |
| 677 | afspec, RTM_DELLINK); |
Roopa Prabhu | 02dba43 | 2015-01-14 20:02:25 -0800 | [diff] [blame] | 678 | if (err == 0) |
| 679 | /* Send RTM_NEWLINK because userspace |
| 680 | * expects RTM_NEWLINK for vlan dels |
| 681 | */ |
| 682 | br_ifinfo_notify(RTM_NEWLINK, p); |
Vlad Yasevich | 407af32 | 2013-02-13 12:00:12 +0000 | [diff] [blame] | 683 | |
| 684 | return err; |
| 685 | } |
stephen hemminger | bb900b2 | 2011-04-04 14:03:32 +0000 | [diff] [blame] | 686 | static int br_validate(struct nlattr *tb[], struct nlattr *data[]) |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 687 | { |
stephen hemminger | bb900b2 | 2011-04-04 14:03:32 +0000 | [diff] [blame] | 688 | if (tb[IFLA_ADDRESS]) { |
| 689 | if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) |
| 690 | return -EINVAL; |
| 691 | if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) |
| 692 | return -EADDRNOTAVAIL; |
| 693 | } |
Thomas Graf | 32fe21c | 2007-03-22 11:59:03 -0700 | [diff] [blame] | 694 | |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 695 | if (!data) |
| 696 | return 0; |
| 697 | |
| 698 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING |
| 699 | if (data[IFLA_BR_VLAN_PROTOCOL]) { |
| 700 | switch (nla_get_be16(data[IFLA_BR_VLAN_PROTOCOL])) { |
| 701 | case htons(ETH_P_8021Q): |
| 702 | case htons(ETH_P_8021AD): |
| 703 | break; |
| 704 | default: |
| 705 | return -EPROTONOSUPPORT; |
| 706 | } |
| 707 | } |
| 708 | #endif |
| 709 | |
Thomas Graf | 32fe21c | 2007-03-22 11:59:03 -0700 | [diff] [blame] | 710 | return 0; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 711 | } |
| 712 | |
Toshiaki Makita | 30313a3 | 2014-04-25 17:01:18 +0900 | [diff] [blame] | 713 | static int br_dev_newlink(struct net *src_net, struct net_device *dev, |
| 714 | struct nlattr *tb[], struct nlattr *data[]) |
| 715 | { |
| 716 | struct net_bridge *br = netdev_priv(dev); |
| 717 | |
| 718 | if (tb[IFLA_ADDRESS]) { |
| 719 | spin_lock_bh(&br->lock); |
| 720 | br_stp_change_bridge_id(br, nla_data(tb[IFLA_ADDRESS])); |
| 721 | spin_unlock_bh(&br->lock); |
| 722 | } |
| 723 | |
| 724 | return register_netdevice(dev); |
| 725 | } |
| 726 | |
Jiri Pirko | 3ac636b | 2014-09-05 15:51:30 +0200 | [diff] [blame] | 727 | static int br_port_slave_changelink(struct net_device *brdev, |
| 728 | struct net_device *dev, |
| 729 | struct nlattr *tb[], |
| 730 | struct nlattr *data[]) |
| 731 | { |
Nikolay Aleksandrov | 963ad94 | 2015-07-22 13:03:40 +0200 | [diff] [blame] | 732 | struct net_bridge *br = netdev_priv(brdev); |
| 733 | int ret; |
| 734 | |
Jiri Pirko | 3ac636b | 2014-09-05 15:51:30 +0200 | [diff] [blame] | 735 | if (!data) |
| 736 | return 0; |
Nikolay Aleksandrov | 963ad94 | 2015-07-22 13:03:40 +0200 | [diff] [blame] | 737 | |
| 738 | spin_lock_bh(&br->lock); |
| 739 | ret = br_setport(br_port_get_rtnl(dev), data); |
| 740 | spin_unlock_bh(&br->lock); |
| 741 | |
| 742 | return ret; |
Jiri Pirko | 3ac636b | 2014-09-05 15:51:30 +0200 | [diff] [blame] | 743 | } |
| 744 | |
Jiri Pirko | ced8283 | 2014-09-05 15:51:29 +0200 | [diff] [blame] | 745 | static int br_port_fill_slave_info(struct sk_buff *skb, |
| 746 | const struct net_device *brdev, |
| 747 | const struct net_device *dev) |
| 748 | { |
| 749 | return br_port_fill_attrs(skb, br_port_get_rtnl(dev)); |
| 750 | } |
| 751 | |
| 752 | static size_t br_port_get_slave_size(const struct net_device *brdev, |
| 753 | const struct net_device *dev) |
| 754 | { |
| 755 | return br_port_info_size(); |
| 756 | } |
| 757 | |
Jiri Pirko | 1332351 | 2014-09-05 15:51:32 +0200 | [diff] [blame] | 758 | static const struct nla_policy br_policy[IFLA_BR_MAX + 1] = { |
| 759 | [IFLA_BR_FORWARD_DELAY] = { .type = NLA_U32 }, |
| 760 | [IFLA_BR_HELLO_TIME] = { .type = NLA_U32 }, |
| 761 | [IFLA_BR_MAX_AGE] = { .type = NLA_U32 }, |
Jörg Thalheim | af61576 | 2015-03-18 10:06:58 +0100 | [diff] [blame] | 762 | [IFLA_BR_AGEING_TIME] = { .type = NLA_U32 }, |
| 763 | [IFLA_BR_STP_STATE] = { .type = NLA_U32 }, |
| 764 | [IFLA_BR_PRIORITY] = { .type = NLA_U16 }, |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 765 | [IFLA_BR_VLAN_FILTERING] = { .type = NLA_U8 }, |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 766 | [IFLA_BR_VLAN_PROTOCOL] = { .type = NLA_U16 }, |
Nikolay Aleksandrov | 7910228 | 2015-10-04 14:23:28 +0200 | [diff] [blame] | 767 | [IFLA_BR_GROUP_FWD_MASK] = { .type = NLA_U16 }, |
Nikolay Aleksandrov | 111189a | 2015-10-04 14:23:35 +0200 | [diff] [blame] | 768 | [IFLA_BR_GROUP_ADDR] = { .type = NLA_BINARY, |
| 769 | .len = ETH_ALEN }, |
Nikolay Aleksandrov | a9a6bc7 | 2015-10-04 14:23:37 +0200 | [diff] [blame^] | 770 | [IFLA_BR_MCAST_ROUTER] = { .type = NLA_U8 }, |
Jiri Pirko | 1332351 | 2014-09-05 15:51:32 +0200 | [diff] [blame] | 771 | }; |
| 772 | |
| 773 | static int br_changelink(struct net_device *brdev, struct nlattr *tb[], |
| 774 | struct nlattr *data[]) |
| 775 | { |
| 776 | struct net_bridge *br = netdev_priv(brdev); |
| 777 | int err; |
| 778 | |
| 779 | if (!data) |
| 780 | return 0; |
| 781 | |
| 782 | if (data[IFLA_BR_FORWARD_DELAY]) { |
| 783 | err = br_set_forward_delay(br, nla_get_u32(data[IFLA_BR_FORWARD_DELAY])); |
| 784 | if (err) |
| 785 | return err; |
| 786 | } |
| 787 | |
| 788 | if (data[IFLA_BR_HELLO_TIME]) { |
| 789 | err = br_set_hello_time(br, nla_get_u32(data[IFLA_BR_HELLO_TIME])); |
| 790 | if (err) |
| 791 | return err; |
| 792 | } |
| 793 | |
| 794 | if (data[IFLA_BR_MAX_AGE]) { |
| 795 | err = br_set_max_age(br, nla_get_u32(data[IFLA_BR_MAX_AGE])); |
| 796 | if (err) |
| 797 | return err; |
| 798 | } |
| 799 | |
Jörg Thalheim | af61576 | 2015-03-18 10:06:58 +0100 | [diff] [blame] | 800 | if (data[IFLA_BR_AGEING_TIME]) { |
| 801 | u32 ageing_time = nla_get_u32(data[IFLA_BR_AGEING_TIME]); |
| 802 | |
| 803 | br->ageing_time = clock_t_to_jiffies(ageing_time); |
| 804 | } |
| 805 | |
| 806 | if (data[IFLA_BR_STP_STATE]) { |
| 807 | u32 stp_enabled = nla_get_u32(data[IFLA_BR_STP_STATE]); |
| 808 | |
| 809 | br_stp_set_enabled(br, stp_enabled); |
| 810 | } |
| 811 | |
| 812 | if (data[IFLA_BR_PRIORITY]) { |
| 813 | u32 priority = nla_get_u16(data[IFLA_BR_PRIORITY]); |
| 814 | |
| 815 | br_stp_set_bridge_priority(br, priority); |
| 816 | } |
| 817 | |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 818 | if (data[IFLA_BR_VLAN_FILTERING]) { |
| 819 | u8 vlan_filter = nla_get_u8(data[IFLA_BR_VLAN_FILTERING]); |
| 820 | |
| 821 | err = __br_vlan_filter_toggle(br, vlan_filter); |
| 822 | if (err) |
| 823 | return err; |
| 824 | } |
| 825 | |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 826 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING |
| 827 | if (data[IFLA_BR_VLAN_PROTOCOL]) { |
| 828 | __be16 vlan_proto = nla_get_be16(data[IFLA_BR_VLAN_PROTOCOL]); |
| 829 | |
| 830 | err = __br_vlan_set_proto(br, vlan_proto); |
| 831 | if (err) |
| 832 | return err; |
| 833 | } |
| 834 | #endif |
| 835 | |
Nikolay Aleksandrov | 7910228 | 2015-10-04 14:23:28 +0200 | [diff] [blame] | 836 | if (data[IFLA_BR_GROUP_FWD_MASK]) { |
| 837 | u16 fwd_mask = nla_get_u16(data[IFLA_BR_GROUP_FWD_MASK]); |
| 838 | |
| 839 | if (fwd_mask & BR_GROUPFWD_RESTRICTED) |
| 840 | return -EINVAL; |
| 841 | br->group_fwd_mask = fwd_mask; |
| 842 | } |
| 843 | |
Nikolay Aleksandrov | 111189a | 2015-10-04 14:23:35 +0200 | [diff] [blame] | 844 | if (data[IFLA_BR_GROUP_ADDR]) { |
| 845 | u8 new_addr[ETH_ALEN]; |
| 846 | |
| 847 | if (nla_len(data[IFLA_BR_GROUP_ADDR]) != ETH_ALEN) |
| 848 | return -EINVAL; |
| 849 | memcpy(new_addr, nla_data(data[IFLA_BR_GROUP_ADDR]), ETH_ALEN); |
| 850 | if (!is_link_local_ether_addr(new_addr)) |
| 851 | return -EINVAL; |
| 852 | if (new_addr[5] == 1 || /* 802.3x Pause address */ |
| 853 | new_addr[5] == 2 || /* 802.3ad Slow protocols */ |
| 854 | new_addr[5] == 3) /* 802.1X PAE address */ |
| 855 | return -EINVAL; |
| 856 | spin_lock_bh(&br->lock); |
| 857 | memcpy(br->group_addr, new_addr, sizeof(br->group_addr)); |
| 858 | spin_unlock_bh(&br->lock); |
| 859 | br->group_addr_set = true; |
| 860 | br_recalculate_fwd_mask(br); |
| 861 | } |
| 862 | |
Nikolay Aleksandrov | 150217c | 2015-10-04 14:23:36 +0200 | [diff] [blame] | 863 | if (data[IFLA_BR_FDB_FLUSH]) |
| 864 | br_fdb_flush(br); |
| 865 | |
Nikolay Aleksandrov | a9a6bc7 | 2015-10-04 14:23:37 +0200 | [diff] [blame^] | 866 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 867 | if (data[IFLA_BR_MCAST_ROUTER]) { |
| 868 | u8 multicast_router = nla_get_u8(data[IFLA_BR_MCAST_ROUTER]); |
| 869 | |
| 870 | err = br_multicast_set_router(br, multicast_router); |
| 871 | if (err) |
| 872 | return err; |
| 873 | } |
| 874 | #endif |
| 875 | |
Jiri Pirko | 1332351 | 2014-09-05 15:51:32 +0200 | [diff] [blame] | 876 | return 0; |
| 877 | } |
| 878 | |
Jiri Pirko | e5c3ea5 | 2014-09-05 15:51:31 +0200 | [diff] [blame] | 879 | static size_t br_get_size(const struct net_device *brdev) |
| 880 | { |
| 881 | return nla_total_size(sizeof(u32)) + /* IFLA_BR_FORWARD_DELAY */ |
| 882 | nla_total_size(sizeof(u32)) + /* IFLA_BR_HELLO_TIME */ |
| 883 | nla_total_size(sizeof(u32)) + /* IFLA_BR_MAX_AGE */ |
Jörg Thalheim | af61576 | 2015-03-18 10:06:58 +0100 | [diff] [blame] | 884 | nla_total_size(sizeof(u32)) + /* IFLA_BR_AGEING_TIME */ |
| 885 | nla_total_size(sizeof(u32)) + /* IFLA_BR_STP_STATE */ |
| 886 | nla_total_size(sizeof(u16)) + /* IFLA_BR_PRIORITY */ |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 887 | nla_total_size(sizeof(u8)) + /* IFLA_BR_VLAN_FILTERING */ |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 888 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING |
| 889 | nla_total_size(sizeof(__be16)) + /* IFLA_BR_VLAN_PROTOCOL */ |
| 890 | #endif |
Nikolay Aleksandrov | 7910228 | 2015-10-04 14:23:28 +0200 | [diff] [blame] | 891 | nla_total_size(sizeof(u16)) + /* IFLA_BR_GROUP_FWD_MASK */ |
Nikolay Aleksandrov | 5127c81 | 2015-10-04 14:23:29 +0200 | [diff] [blame] | 892 | nla_total_size(sizeof(struct ifla_bridge_id)) + /* IFLA_BR_ROOT_ID */ |
Nikolay Aleksandrov | 7599a22 | 2015-10-04 14:23:30 +0200 | [diff] [blame] | 893 | nla_total_size(sizeof(struct ifla_bridge_id)) + /* IFLA_BR_BRIDGE_ID */ |
Nikolay Aleksandrov | 8762ba6 | 2015-10-04 14:23:31 +0200 | [diff] [blame] | 894 | nla_total_size(sizeof(u16)) + /* IFLA_BR_ROOT_PORT */ |
Nikolay Aleksandrov | 684dd24 | 2015-10-04 14:23:32 +0200 | [diff] [blame] | 895 | nla_total_size(sizeof(u32)) + /* IFLA_BR_ROOT_PATH_COST */ |
Nikolay Aleksandrov | ed41630 | 2015-10-04 14:23:33 +0200 | [diff] [blame] | 896 | nla_total_size(sizeof(u8)) + /* IFLA_BR_TOPOLOGY_CHANGE */ |
| 897 | nla_total_size(sizeof(u8)) + /* IFLA_BR_TOPOLOGY_CHANGE_DETECTED */ |
Nikolay Aleksandrov | d76bd14 | 2015-10-04 14:23:34 +0200 | [diff] [blame] | 898 | nla_total_size(sizeof(u64)) + /* IFLA_BR_HELLO_TIMER */ |
| 899 | nla_total_size(sizeof(u64)) + /* IFLA_BR_TCN_TIMER */ |
| 900 | nla_total_size(sizeof(u64)) + /* IFLA_BR_TOPOLOGY_CHANGE_TIMER */ |
| 901 | nla_total_size(sizeof(u64)) + /* IFLA_BR_GC_TIMER */ |
Nikolay Aleksandrov | 111189a | 2015-10-04 14:23:35 +0200 | [diff] [blame] | 902 | nla_total_size(ETH_ALEN) + /* IFLA_BR_GROUP_ADDR */ |
Nikolay Aleksandrov | a9a6bc7 | 2015-10-04 14:23:37 +0200 | [diff] [blame^] | 903 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 904 | nla_total_size(sizeof(u8)) + /* IFLA_BR_MCAST_ROUTER */ |
| 905 | #endif |
Jiri Pirko | e5c3ea5 | 2014-09-05 15:51:31 +0200 | [diff] [blame] | 906 | 0; |
| 907 | } |
| 908 | |
| 909 | static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev) |
| 910 | { |
| 911 | struct net_bridge *br = netdev_priv(brdev); |
Nikolay Aleksandrov | d76bd14 | 2015-10-04 14:23:34 +0200 | [diff] [blame] | 912 | u64 hello_timer, tcn_timer, topology_change_timer, gc_timer; |
Jiri Pirko | e5c3ea5 | 2014-09-05 15:51:31 +0200 | [diff] [blame] | 913 | u32 forward_delay = jiffies_to_clock_t(br->forward_delay); |
| 914 | u32 hello_time = jiffies_to_clock_t(br->hello_time); |
| 915 | u32 age_time = jiffies_to_clock_t(br->max_age); |
Jörg Thalheim | af61576 | 2015-03-18 10:06:58 +0100 | [diff] [blame] | 916 | u32 ageing_time = jiffies_to_clock_t(br->ageing_time); |
| 917 | u32 stp_enabled = br->stp_enabled; |
| 918 | u16 priority = (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]; |
Nikolay Aleksandrov | 7910228 | 2015-10-04 14:23:28 +0200 | [diff] [blame] | 919 | u16 group_fwd_mask = br->group_fwd_mask; |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 920 | u8 vlan_enabled = br_vlan_enabled(br); |
Nikolay Aleksandrov | 7599a22 | 2015-10-04 14:23:30 +0200 | [diff] [blame] | 921 | struct ifla_bridge_id root_id, bridge_id; |
Nikolay Aleksandrov | 5127c81 | 2015-10-04 14:23:29 +0200 | [diff] [blame] | 922 | |
Nikolay Aleksandrov | 7599a22 | 2015-10-04 14:23:30 +0200 | [diff] [blame] | 923 | memset(&bridge_id, 0, sizeof(bridge_id)); |
Nikolay Aleksandrov | 5127c81 | 2015-10-04 14:23:29 +0200 | [diff] [blame] | 924 | memset(&root_id, 0, sizeof(root_id)); |
| 925 | memcpy(root_id.prio, br->designated_root.prio, sizeof(root_id.prio)); |
| 926 | memcpy(root_id.addr, br->designated_root.addr, sizeof(root_id.addr)); |
Nikolay Aleksandrov | 7599a22 | 2015-10-04 14:23:30 +0200 | [diff] [blame] | 927 | memcpy(bridge_id.prio, br->bridge_id.prio, sizeof(bridge_id.prio)); |
| 928 | memcpy(bridge_id.addr, br->bridge_id.addr, sizeof(bridge_id.addr)); |
Nikolay Aleksandrov | d76bd14 | 2015-10-04 14:23:34 +0200 | [diff] [blame] | 929 | hello_timer = br_timer_value(&br->hello_timer); |
| 930 | tcn_timer = br_timer_value(&br->tcn_timer); |
| 931 | topology_change_timer = br_timer_value(&br->topology_change_timer); |
| 932 | gc_timer = br_timer_value(&br->gc_timer); |
Jiri Pirko | e5c3ea5 | 2014-09-05 15:51:31 +0200 | [diff] [blame] | 933 | |
| 934 | if (nla_put_u32(skb, IFLA_BR_FORWARD_DELAY, forward_delay) || |
| 935 | nla_put_u32(skb, IFLA_BR_HELLO_TIME, hello_time) || |
Jörg Thalheim | af61576 | 2015-03-18 10:06:58 +0100 | [diff] [blame] | 936 | nla_put_u32(skb, IFLA_BR_MAX_AGE, age_time) || |
| 937 | nla_put_u32(skb, IFLA_BR_AGEING_TIME, ageing_time) || |
| 938 | nla_put_u32(skb, IFLA_BR_STP_STATE, stp_enabled) || |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 939 | nla_put_u16(skb, IFLA_BR_PRIORITY, priority) || |
Nikolay Aleksandrov | 7910228 | 2015-10-04 14:23:28 +0200 | [diff] [blame] | 940 | nla_put_u8(skb, IFLA_BR_VLAN_FILTERING, vlan_enabled) || |
Nikolay Aleksandrov | 5127c81 | 2015-10-04 14:23:29 +0200 | [diff] [blame] | 941 | nla_put_u16(skb, IFLA_BR_GROUP_FWD_MASK, group_fwd_mask) || |
Nikolay Aleksandrov | 7599a22 | 2015-10-04 14:23:30 +0200 | [diff] [blame] | 942 | nla_put(skb, IFLA_BR_ROOT_ID, sizeof(root_id), &root_id) || |
Nikolay Aleksandrov | 8762ba6 | 2015-10-04 14:23:31 +0200 | [diff] [blame] | 943 | nla_put(skb, IFLA_BR_BRIDGE_ID, sizeof(bridge_id), &bridge_id) || |
Nikolay Aleksandrov | 684dd24 | 2015-10-04 14:23:32 +0200 | [diff] [blame] | 944 | nla_put_u16(skb, IFLA_BR_ROOT_PORT, br->root_port) || |
Nikolay Aleksandrov | ed41630 | 2015-10-04 14:23:33 +0200 | [diff] [blame] | 945 | nla_put_u32(skb, IFLA_BR_ROOT_PATH_COST, br->root_path_cost) || |
| 946 | nla_put_u8(skb, IFLA_BR_TOPOLOGY_CHANGE, br->topology_change) || |
| 947 | nla_put_u8(skb, IFLA_BR_TOPOLOGY_CHANGE_DETECTED, |
Nikolay Aleksandrov | d76bd14 | 2015-10-04 14:23:34 +0200 | [diff] [blame] | 948 | br->topology_change_detected) || |
| 949 | nla_put_u64(skb, IFLA_BR_HELLO_TIMER, hello_timer) || |
| 950 | nla_put_u64(skb, IFLA_BR_TCN_TIMER, tcn_timer) || |
| 951 | nla_put_u64(skb, IFLA_BR_TOPOLOGY_CHANGE_TIMER, |
| 952 | topology_change_timer) || |
Nikolay Aleksandrov | 111189a | 2015-10-04 14:23:35 +0200 | [diff] [blame] | 953 | nla_put_u64(skb, IFLA_BR_GC_TIMER, gc_timer) || |
| 954 | nla_put(skb, IFLA_BR_GROUP_ADDR, ETH_ALEN, br->group_addr)) |
Jiri Pirko | e5c3ea5 | 2014-09-05 15:51:31 +0200 | [diff] [blame] | 955 | return -EMSGSIZE; |
| 956 | |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 957 | #ifdef CONFIG_BRIDGE_VLAN_FILTERING |
| 958 | if (nla_put_be16(skb, IFLA_BR_VLAN_PROTOCOL, br->vlan_proto)) |
| 959 | return -EMSGSIZE; |
| 960 | #endif |
| 961 | |
Nikolay Aleksandrov | a9a6bc7 | 2015-10-04 14:23:37 +0200 | [diff] [blame^] | 962 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 963 | if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER, br->multicast_router)) |
| 964 | return -EMSGSIZE; |
| 965 | #endif |
| 966 | |
Jiri Pirko | e5c3ea5 | 2014-09-05 15:51:31 +0200 | [diff] [blame] | 967 | return 0; |
| 968 | } |
| 969 | |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 970 | static size_t br_get_link_af_size(const struct net_device *dev) |
| 971 | { |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 972 | struct net_bridge_port *p; |
| 973 | struct net_bridge *br; |
| 974 | int num_vlans = 0; |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 975 | |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 976 | if (br_port_exists(dev)) { |
| 977 | p = br_port_get_rtnl(dev); |
| 978 | num_vlans = br_get_num_vlan_infos(nbp_vlan_group(p), |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 979 | RTEXT_FILTER_BRVLAN); |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 980 | } else if (dev->priv_flags & IFF_EBRIDGE) { |
| 981 | br = netdev_priv(dev); |
| 982 | num_vlans = br_get_num_vlan_infos(br_vlan_group(br), |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 983 | RTEXT_FILTER_BRVLAN); |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 984 | } |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 985 | |
| 986 | /* Each VLAN is returned in bridge_vlan_info along with flags */ |
Nikolay Aleksandrov | 2594e90 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 987 | return num_vlans * nla_total_size(sizeof(struct bridge_vlan_info)); |
Roopa Prabhu | fed0a15 | 2015-02-25 23:55:40 -0800 | [diff] [blame] | 988 | } |
| 989 | |
Daniel Borkmann | 207895f | 2015-01-29 12:15:03 +0100 | [diff] [blame] | 990 | static struct rtnl_af_ops br_af_ops __read_mostly = { |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 991 | .family = AF_BRIDGE, |
| 992 | .get_link_af_size = br_get_link_af_size, |
| 993 | }; |
| 994 | |
stephen hemminger | 149ddd8 | 2012-06-26 05:48:45 +0000 | [diff] [blame] | 995 | struct rtnl_link_ops br_link_ops __read_mostly = { |
Jiri Pirko | ced8283 | 2014-09-05 15:51:29 +0200 | [diff] [blame] | 996 | .kind = "bridge", |
| 997 | .priv_size = sizeof(struct net_bridge), |
| 998 | .setup = br_dev_setup, |
Scott Feldman | eb4cb85 | 2015-08-19 11:29:35 -0700 | [diff] [blame] | 999 | .maxtype = IFLA_BR_MAX, |
Jiri Pirko | 1332351 | 2014-09-05 15:51:32 +0200 | [diff] [blame] | 1000 | .policy = br_policy, |
Jiri Pirko | ced8283 | 2014-09-05 15:51:29 +0200 | [diff] [blame] | 1001 | .validate = br_validate, |
| 1002 | .newlink = br_dev_newlink, |
Jiri Pirko | 1332351 | 2014-09-05 15:51:32 +0200 | [diff] [blame] | 1003 | .changelink = br_changelink, |
Jiri Pirko | ced8283 | 2014-09-05 15:51:29 +0200 | [diff] [blame] | 1004 | .dellink = br_dev_delete, |
Jiri Pirko | e5c3ea5 | 2014-09-05 15:51:31 +0200 | [diff] [blame] | 1005 | .get_size = br_get_size, |
| 1006 | .fill_info = br_fill_info, |
Jiri Pirko | 3ac636b | 2014-09-05 15:51:30 +0200 | [diff] [blame] | 1007 | |
| 1008 | .slave_maxtype = IFLA_BRPORT_MAX, |
| 1009 | .slave_policy = br_port_policy, |
| 1010 | .slave_changelink = br_port_slave_changelink, |
Jiri Pirko | ced8283 | 2014-09-05 15:51:29 +0200 | [diff] [blame] | 1011 | .get_slave_size = br_port_get_slave_size, |
| 1012 | .fill_slave_info = br_port_fill_slave_info, |
stephen hemminger | bb900b2 | 2011-04-04 14:03:32 +0000 | [diff] [blame] | 1013 | }; |
| 1014 | |
| 1015 | int __init br_netlink_init(void) |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 1016 | { |
Vlad Yasevich | 3ec8e9f | 2013-01-02 09:41:25 +0000 | [diff] [blame] | 1017 | int err; |
| 1018 | |
| 1019 | br_mdb_init(); |
stephen hemminger | 3678a9d | 2013-12-30 10:41:32 -0800 | [diff] [blame] | 1020 | rtnl_af_register(&br_af_ops); |
Vlad Yasevich | 3ec8e9f | 2013-01-02 09:41:25 +0000 | [diff] [blame] | 1021 | |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 1022 | err = rtnl_link_register(&br_link_ops); |
| 1023 | if (err) |
| 1024 | goto out_af; |
| 1025 | |
Vlad Yasevich | 3ec8e9f | 2013-01-02 09:41:25 +0000 | [diff] [blame] | 1026 | return 0; |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 1027 | |
| 1028 | out_af: |
| 1029 | rtnl_af_unregister(&br_af_ops); |
Vlad Yasevich | 3ec8e9f | 2013-01-02 09:41:25 +0000 | [diff] [blame] | 1030 | br_mdb_uninit(); |
| 1031 | return err; |
Stephen Hemminger | 11dc1f3 | 2006-05-25 16:00:12 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
Pablo Neira Ayuso | 34666d4 | 2014-09-18 11:29:03 +0200 | [diff] [blame] | 1034 | void br_netlink_fini(void) |
stephen hemminger | bb900b2 | 2011-04-04 14:03:32 +0000 | [diff] [blame] | 1035 | { |
Vlad Yasevich | 3ec8e9f | 2013-01-02 09:41:25 +0000 | [diff] [blame] | 1036 | br_mdb_uninit(); |
Vlad Yasevich | 6cbdcee | 2013-02-13 12:00:13 +0000 | [diff] [blame] | 1037 | rtnl_af_unregister(&br_af_ops); |
stephen hemminger | bb900b2 | 2011-04-04 14:03:32 +0000 | [diff] [blame] | 1038 | rtnl_link_unregister(&br_link_ops); |
stephen hemminger | bb900b2 | 2011-04-04 14:03:32 +0000 | [diff] [blame] | 1039 | } |