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