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