Commit | Line | Data |
---|---|---|
2874c5fd | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
1da177e4 LT |
2 | /* |
3 | * Device handling code | |
4 | * Linux ethernet bridge | |
5 | * | |
6 | * Authors: | |
7 | * Lennert Buytenhek <buytenh@gnu.org> | |
1da177e4 LT |
8 | */ |
9 | ||
10 | #include <linux/kernel.h> | |
11 | #include <linux/netdevice.h> | |
c06ee961 | 12 | #include <linux/netpoll.h> |
4505a3ef | 13 | #include <linux/etherdevice.h> |
edb5e46f | 14 | #include <linux/ethtool.h> |
c06ee961 | 15 | #include <linux/list.h> |
ea2d9b41 | 16 | #include <linux/netfilter_bridge.h> |
4505a3ef | 17 | |
7c0f6ba6 | 18 | #include <linux/uaccess.h> |
1da177e4 LT |
19 | #include "br_private.h" |
20 | ||
161f65ba VY |
21 | #define COMMON_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HIGHDMA | \ |
22 | NETIF_F_GSO_MASK | NETIF_F_HW_CSUM) | |
23 | ||
1a4ba64d PNA |
24 | const struct nf_br_ops __rcu *nf_br_ops __read_mostly; |
25 | EXPORT_SYMBOL_GPL(nf_br_ops); | |
26 | ||
eeaf61d8 | 27 | /* net device transmit always called with BH disabled */ |
6fef4c0c | 28 | netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev) |
1da177e4 | 29 | { |
f4b7002a | 30 | struct net_bridge_mcast_port *pmctx_null = NULL; |
1da177e4 | 31 | struct net_bridge *br = netdev_priv(dev); |
adc47037 | 32 | struct net_bridge_mcast *brmctx = &br->multicast_ctx; |
1da177e4 | 33 | struct net_bridge_fdb_entry *dst; |
c4fcb78c | 34 | struct net_bridge_mdb_entry *mdst; |
1a4ba64d | 35 | const struct nf_br_ops *nf_ops; |
a580c76d | 36 | u8 state = BR_STATE_FORWARDING; |
f4b7002a | 37 | struct net_bridge_vlan *vlan; |
31a4562d | 38 | const unsigned char *dest; |
78851988 | 39 | u16 vid = 0; |
1da177e4 | 40 | |
fd65e5a9 NA |
41 | memset(skb->cb, 0, sizeof(struct br_input_skb_cb)); |
42 | ||
c03307ea | 43 | rcu_read_lock(); |
1a4ba64d PNA |
44 | nf_ops = rcu_dereference(nf_br_ops); |
45 | if (nf_ops && nf_ops->br_dev_xmit_hook(skb)) { | |
c03307ea | 46 | rcu_read_unlock(); |
ea2d9b41 BDS |
47 | return NETDEV_TX_OK; |
48 | } | |
ea2d9b41 | 49 | |
7609ecb2 | 50 | dev_sw_netstats_tx_add(dev, 1, skb->len); |
6088a539 | 51 | |
f1c2eddf | 52 | br_switchdev_frame_unmark(skb); |
14bb4789 | 53 | BR_INPUT_SKB_CB(skb)->brdev = dev; |
3c171f49 | 54 | BR_INPUT_SKB_CB(skb)->frag_max_size = 0; |
1da177e4 | 55 | |
459a98ed | 56 | skb_reset_mac_header(skb); |
1da177e4 LT |
57 | skb_pull(skb, ETH_HLEN); |
58 | ||
f4b7002a NA |
59 | if (!br_allowed_ingress(br, br_vlan_group_rcu(br), skb, &vid, |
60 | &state, &vlan)) | |
12464bb8 TM |
61 | goto out; |
62 | ||
057658cb | 63 | if (IS_ENABLED(CONFIG_INET) && |
823d81b0 NA |
64 | (eth_hdr(skb)->h_proto == htons(ETH_P_ARP) || |
65 | eth_hdr(skb)->h_proto == htons(ETH_P_RARP)) && | |
c69c2cd4 | 66 | br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED)) { |
057658cb | 67 | br_do_proxy_suppress_arp(skb, br, vid, NULL); |
ed842fae RP |
68 | } else if (IS_ENABLED(CONFIG_IPV6) && |
69 | skb->protocol == htons(ETH_P_IPV6) && | |
c69c2cd4 | 70 | br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED) && |
ed842fae RP |
71 | pskb_may_pull(skb, sizeof(struct ipv6hdr) + |
72 | sizeof(struct nd_msg)) && | |
73 | ipv6_hdr(skb)->nexthdr == IPPROTO_ICMPV6) { | |
74 | struct nd_msg *msg, _msg; | |
75 | ||
76 | msg = br_is_nd_neigh_msg(skb, &_msg); | |
77 | if (msg) | |
78 | br_do_suppress_nd(skb, br, vid, NULL, msg); | |
057658cb RP |
79 | } |
80 | ||
31a4562d | 81 | dest = eth_hdr(skb)->h_dest; |
37b090e6 | 82 | if (is_broadcast_ether_addr(dest)) { |
8addd5e7 | 83 | br_flood(br, skb, BR_PKT_BROADCAST, false, true); |
37b090e6 | 84 | } else if (is_multicast_ether_addr(dest)) { |
91d2c34a | 85 | if (unlikely(netpoll_tx_running(dev))) { |
8addd5e7 | 86 | br_flood(br, skb, BR_PKT_MULTICAST, false, true); |
91d2c34a HX |
87 | goto out; |
88 | } | |
f4b7002a | 89 | if (br_multicast_rcv(&brmctx, &pmctx_null, vlan, skb, vid)) { |
6d1d1d39 | 90 | kfree_skb(skb); |
c4fcb78c | 91 | goto out; |
6d1d1d39 | 92 | } |
c4fcb78c | 93 | |
adc47037 | 94 | mdst = br_mdb_get(brmctx, skb, vid); |
b00589af | 95 | if ((mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb)) && |
adc47037 NA |
96 | br_multicast_querier_exists(brmctx, eth_hdr(skb), mdst)) |
97 | br_multicast_flood(mdst, skb, brmctx, false, true); | |
c4fcb78c | 98 | else |
8addd5e7 | 99 | br_flood(br, skb, BR_PKT_MULTICAST, false, true); |
bfd0aeac | 100 | } else if ((dst = br_fdb_find_rcu(br, dest, vid)) != NULL) { |
37b090e6 NA |
101 | br_forward(dst->dst, skb, false, true); |
102 | } else { | |
8addd5e7 | 103 | br_flood(br, skb, BR_PKT_UNICAST, false, true); |
37b090e6 | 104 | } |
c4fcb78c | 105 | out: |
eeaf61d8 | 106 | rcu_read_unlock(); |
6ed10654 | 107 | return NETDEV_TX_OK; |
1da177e4 LT |
108 | } |
109 | ||
845e0ebb CW |
110 | static struct lock_class_key bridge_netdev_addr_lock_key; |
111 | ||
112 | static void br_set_lockdep_class(struct net_device *dev) | |
113 | { | |
114 | lockdep_set_class(&dev->addr_list_lock, &bridge_netdev_addr_lock_key); | |
115 | } | |
116 | ||
bb900b27 | 117 | static int br_dev_init(struct net_device *dev) |
118 | { | |
119 | struct net_bridge *br = netdev_priv(dev); | |
5be5a2df | 120 | int err; |
bb900b27 | 121 | |
7609ecb2 HK |
122 | dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats); |
123 | if (!dev->tstats) | |
bb900b27 | 124 | return -ENOMEM; |
125 | ||
eb793583 NA |
126 | err = br_fdb_hash_init(br); |
127 | if (err) { | |
7609ecb2 | 128 | free_percpu(dev->tstats); |
eb793583 NA |
129 | return err; |
130 | } | |
131 | ||
19e3a9c9 NA |
132 | err = br_mdb_hash_init(br); |
133 | if (err) { | |
7609ecb2 | 134 | free_percpu(dev->tstats); |
19e3a9c9 NA |
135 | br_fdb_hash_fini(br); |
136 | return err; | |
137 | } | |
138 | ||
5be5a2df | 139 | err = br_vlan_init(br); |
1080ab95 | 140 | if (err) { |
7609ecb2 | 141 | free_percpu(dev->tstats); |
19e3a9c9 | 142 | br_mdb_hash_fini(br); |
eb793583 | 143 | br_fdb_hash_fini(br); |
1080ab95 NA |
144 | return err; |
145 | } | |
146 | ||
147 | err = br_multicast_init_stats(br); | |
148 | if (err) { | |
7609ecb2 | 149 | free_percpu(dev->tstats); |
1080ab95 | 150 | br_vlan_flush(br); |
19e3a9c9 | 151 | br_mdb_hash_fini(br); |
eb793583 | 152 | br_fdb_hash_fini(br); |
1080ab95 | 153 | } |
5be5a2df | 154 | |
845e0ebb | 155 | br_set_lockdep_class(dev); |
5be5a2df | 156 | return err; |
bb900b27 | 157 | } |
158 | ||
b6fe0440 IS |
159 | static void br_dev_uninit(struct net_device *dev) |
160 | { | |
161 | struct net_bridge *br = netdev_priv(dev); | |
162 | ||
b1b9d366 | 163 | br_multicast_dev_del(br); |
b6fe0440 IS |
164 | br_multicast_uninit_stats(br); |
165 | br_vlan_flush(br); | |
19e3a9c9 | 166 | br_mdb_hash_fini(br); |
eb793583 | 167 | br_fdb_hash_fini(br); |
7609ecb2 | 168 | free_percpu(dev->tstats); |
b6fe0440 IS |
169 | } |
170 | ||
1da177e4 LT |
171 | static int br_dev_open(struct net_device *dev) |
172 | { | |
81d35307 | 173 | struct net_bridge *br = netdev_priv(dev); |
1da177e4 | 174 | |
c4d27ef9 | 175 | netdev_update_features(dev); |
81d35307 SH |
176 | netif_start_queue(dev); |
177 | br_stp_enable_bridge(br); | |
3fe2d7c7 | 178 | br_multicast_open(br); |
1da177e4 | 179 | |
851d0a73 JH |
180 | if (br_opt_get(br, BROPT_MULTICAST_ENABLED)) |
181 | br_multicast_join_snoopers(br); | |
182 | ||
1da177e4 LT |
183 | return 0; |
184 | } | |
185 | ||
186 | static void br_dev_set_multicast_list(struct net_device *dev) | |
187 | { | |
188 | } | |
189 | ||
2796d0c6 VY |
190 | static void br_dev_change_rx_flags(struct net_device *dev, int change) |
191 | { | |
192 | if (change & IFF_PROMISC) | |
193 | br_manage_promisc(netdev_priv(dev)); | |
194 | } | |
195 | ||
1da177e4 LT |
196 | static int br_dev_stop(struct net_device *dev) |
197 | { | |
3fe2d7c7 HX |
198 | struct net_bridge *br = netdev_priv(dev); |
199 | ||
200 | br_stp_disable_bridge(br); | |
201 | br_multicast_stop(br); | |
1da177e4 | 202 | |
851d0a73 JH |
203 | if (br_opt_get(br, BROPT_MULTICAST_ENABLED)) |
204 | br_multicast_leave_snoopers(br); | |
205 | ||
1da177e4 LT |
206 | netif_stop_queue(dev); |
207 | ||
208 | return 0; | |
209 | } | |
210 | ||
211 | static int br_change_mtu(struct net_device *dev, int new_mtu) | |
212 | { | |
4adf0af6 | 213 | struct net_bridge *br = netdev_priv(dev); |
f40aa233 | 214 | |
1da177e4 | 215 | dev->mtu = new_mtu; |
4adf0af6 | 216 | |
804b854d | 217 | /* this flag will be cleared if the MTU was automatically adjusted */ |
3341d917 | 218 | br_opt_toggle(br, BROPT_MTU_SET_BY_USER, true); |
34666d46 | 219 | #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
4adf0af6 | 220 | /* remember the MTU in the rtable for PMTU */ |
defb3519 | 221 | dst_metric_set(&br->fake_rtable.dst, RTAX_MTU, new_mtu); |
4adf0af6 SW |
222 | #endif |
223 | ||
1da177e4 LT |
224 | return 0; |
225 | } | |
226 | ||
ffe1d49c | 227 | /* Allow setting mac address to any valid ethernet address. */ |
4505a3ef SH |
228 | static int br_set_mac_address(struct net_device *dev, void *p) |
229 | { | |
230 | struct net_bridge *br = netdev_priv(dev); | |
231 | struct sockaddr *addr = p; | |
ffe1d49c SH |
232 | |
233 | if (!is_valid_ether_addr(addr->sa_data)) | |
7ca1e11a | 234 | return -EADDRNOTAVAIL; |
4505a3ef | 235 | |
c4b4c421 NA |
236 | /* dev_set_mac_addr() can be called by a master device on bridge's |
237 | * NETDEV_UNREGISTER, but since it's being destroyed do nothing | |
238 | */ | |
239 | if (dev->reg_state != NETREG_REGISTERED) | |
240 | return -EBUSY; | |
241 | ||
4505a3ef | 242 | spin_lock_bh(&br->lock); |
9a7b6ef9 | 243 | if (!ether_addr_equal(dev->dev_addr, addr->sa_data)) { |
a3ebb7ef | 244 | /* Mac address will be changed in br_stp_change_bridge_id(). */ |
43598813 | 245 | br_stp_change_bridge_id(br, addr->sa_data); |
246 | } | |
4505a3ef SH |
247 | spin_unlock_bh(&br->lock); |
248 | ||
ffe1d49c | 249 | return 0; |
4505a3ef SH |
250 | } |
251 | ||
edb5e46f SH |
252 | static void br_getinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
253 | { | |
993e1634 WS |
254 | strscpy(info->driver, "bridge", sizeof(info->driver)); |
255 | strscpy(info->version, BR_VERSION, sizeof(info->version)); | |
256 | strscpy(info->fw_version, "N/A", sizeof(info->fw_version)); | |
257 | strscpy(info->bus_info, "N/A", sizeof(info->bus_info)); | |
edb5e46f SH |
258 | } |
259 | ||
542575fe MS |
260 | static int br_get_link_ksettings(struct net_device *dev, |
261 | struct ethtool_link_ksettings *cmd) | |
262 | { | |
263 | struct net_bridge *br = netdev_priv(dev); | |
264 | struct net_bridge_port *p; | |
265 | ||
266 | cmd->base.duplex = DUPLEX_UNKNOWN; | |
267 | cmd->base.port = PORT_OTHER; | |
268 | cmd->base.speed = SPEED_UNKNOWN; | |
269 | ||
270 | list_for_each_entry(p, &br->port_list, list) { | |
271 | struct ethtool_link_ksettings ecmd; | |
272 | struct net_device *pdev = p->dev; | |
273 | ||
274 | if (!netif_running(pdev) || !netif_oper_up(pdev)) | |
275 | continue; | |
276 | ||
277 | if (__ethtool_get_link_ksettings(pdev, &ecmd)) | |
278 | continue; | |
279 | ||
280 | if (ecmd.base.speed == (__u32)SPEED_UNKNOWN) | |
281 | continue; | |
282 | ||
283 | if (cmd->base.speed == (__u32)SPEED_UNKNOWN || | |
284 | cmd->base.speed < ecmd.base.speed) | |
285 | cmd->base.speed = ecmd.base.speed; | |
286 | } | |
287 | ||
288 | return 0; | |
289 | } | |
290 | ||
c8f44aff MM |
291 | static netdev_features_t br_fix_features(struct net_device *dev, |
292 | netdev_features_t features) | |
edb5e46f SH |
293 | { |
294 | struct net_bridge *br = netdev_priv(dev); | |
295 | ||
c4d27ef9 | 296 | return br_features_recompute(br, features); |
361ff8a6 JG |
297 | } |
298 | ||
c06ee961 | 299 | #ifdef CONFIG_NET_POLL_CONTROLLER |
91d2c34a | 300 | static void br_poll_controller(struct net_device *br_dev) |
c06ee961 | 301 | { |
c06ee961 WC |
302 | } |
303 | ||
91d2c34a | 304 | static void br_netpoll_cleanup(struct net_device *dev) |
c06ee961 | 305 | { |
91d2c34a | 306 | struct net_bridge *br = netdev_priv(dev); |
4e3828c4 | 307 | struct net_bridge_port *p; |
c06ee961 | 308 | |
4e3828c4 | 309 | list_for_each_entry(p, &br->port_list, list) |
91d2c34a | 310 | br_netpoll_disable(p); |
c06ee961 WC |
311 | } |
312 | ||
a8779ec1 | 313 | static int __br_netpoll_enable(struct net_bridge_port *p) |
dbe17307 CW |
314 | { |
315 | struct netpoll *np; | |
316 | int err; | |
317 | ||
a8779ec1 | 318 | np = kzalloc(sizeof(*p->np), GFP_KERNEL); |
dbe17307 CW |
319 | if (!np) |
320 | return -ENOMEM; | |
321 | ||
a8779ec1 | 322 | err = __netpoll_setup(np, p->dev); |
dbe17307 CW |
323 | if (err) { |
324 | kfree(np); | |
325 | return err; | |
326 | } | |
327 | ||
328 | p->np = np; | |
329 | return err; | |
330 | } | |
331 | ||
a8779ec1 | 332 | int br_netpoll_enable(struct net_bridge_port *p) |
dbe17307 CW |
333 | { |
334 | if (!p->br->dev->npinfo) | |
335 | return 0; | |
336 | ||
a8779ec1 | 337 | return __br_netpoll_enable(p); |
dbe17307 CW |
338 | } |
339 | ||
a8779ec1 | 340 | static int br_netpoll_setup(struct net_device *dev, struct netpoll_info *ni) |
c06ee961 | 341 | { |
cfb478da | 342 | struct net_bridge *br = netdev_priv(dev); |
4e3828c4 | 343 | struct net_bridge_port *p; |
91d2c34a | 344 | int err = 0; |
c06ee961 | 345 | |
4e3828c4 | 346 | list_for_each_entry(p, &br->port_list, list) { |
91d2c34a HX |
347 | if (!p->dev) |
348 | continue; | |
a8779ec1 | 349 | err = __br_netpoll_enable(p); |
91d2c34a HX |
350 | if (err) |
351 | goto fail; | |
c06ee961 | 352 | } |
91d2c34a HX |
353 | |
354 | out: | |
355 | return err; | |
356 | ||
357 | fail: | |
358 | br_netpoll_cleanup(dev); | |
359 | goto out; | |
c06ee961 WC |
360 | } |
361 | ||
91d2c34a | 362 | void br_netpoll_disable(struct net_bridge_port *p) |
c06ee961 | 363 | { |
91d2c34a HX |
364 | struct netpoll *np = p->np; |
365 | ||
366 | if (!np) | |
367 | return; | |
368 | ||
369 | p->np = NULL; | |
370 | ||
c9fbd71f | 371 | __netpoll_free(np); |
c06ee961 WC |
372 | } |
373 | ||
374 | #endif | |
375 | ||
33eaf2a6 DA |
376 | static int br_add_slave(struct net_device *dev, struct net_device *slave_dev, |
377 | struct netlink_ext_ack *extack) | |
afc6151a JP |
378 | |
379 | { | |
380 | struct net_bridge *br = netdev_priv(dev); | |
381 | ||
ca752be0 | 382 | return br_add_if(br, slave_dev, extack); |
afc6151a JP |
383 | } |
384 | ||
385 | static int br_del_slave(struct net_device *dev, struct net_device *slave_dev) | |
386 | { | |
387 | struct net_bridge *br = netdev_priv(dev); | |
388 | ||
389 | return br_del_if(br, slave_dev); | |
390 | } | |
391 | ||
ec9d16ba PNA |
392 | static int br_fill_forward_path(struct net_device_path_ctx *ctx, |
393 | struct net_device_path *path) | |
394 | { | |
395 | struct net_bridge_fdb_entry *f; | |
396 | struct net_bridge_port *dst; | |
397 | struct net_bridge *br; | |
398 | ||
399 | if (netif_is_bridge_port(ctx->dev)) | |
400 | return -1; | |
401 | ||
402 | br = netdev_priv(ctx->dev); | |
bcf2766b FF |
403 | |
404 | br_vlan_fill_forward_path_pvid(br, ctx, path); | |
405 | ||
406 | f = br_fdb_find_rcu(br, ctx->daddr, path->bridge.vlan_id); | |
ec9d16ba PNA |
407 | if (!f || !f->dst) |
408 | return -1; | |
409 | ||
410 | dst = READ_ONCE(f->dst); | |
411 | if (!dst) | |
412 | return -1; | |
413 | ||
bcf2766b FF |
414 | if (br_vlan_fill_forward_path_mode(br, dst, path)) |
415 | return -1; | |
416 | ||
ec9d16ba PNA |
417 | path->type = DEV_PATH_BRIDGE; |
418 | path->dev = dst->br->dev; | |
419 | ctx->dev = dst->dev; | |
420 | ||
bcf2766b FF |
421 | switch (path->bridge.vlan_mode) { |
422 | case DEV_PATH_BR_VLAN_TAG: | |
423 | if (ctx->num_vlans >= ARRAY_SIZE(ctx->vlan)) | |
424 | return -ENOSPC; | |
425 | ctx->vlan[ctx->num_vlans].id = path->bridge.vlan_id; | |
426 | ctx->vlan[ctx->num_vlans].proto = path->bridge.vlan_proto; | |
427 | ctx->num_vlans++; | |
428 | break; | |
26267bf9 | 429 | case DEV_PATH_BR_VLAN_UNTAG_HW: |
bcf2766b FF |
430 | case DEV_PATH_BR_VLAN_UNTAG: |
431 | ctx->num_vlans--; | |
432 | break; | |
433 | case DEV_PATH_BR_VLAN_KEEP: | |
434 | break; | |
435 | } | |
436 | ||
ec9d16ba PNA |
437 | return 0; |
438 | } | |
439 | ||
a2dbb882 | 440 | static const struct ethtool_ops br_ethtool_ops = { |
542575fe MS |
441 | .get_drvinfo = br_getinfo, |
442 | .get_link = ethtool_op_get_link, | |
443 | .get_link_ksettings = br_get_link_ksettings, | |
edb5e46f SH |
444 | }; |
445 | ||
a2dbb882 SH |
446 | static const struct net_device_ops br_netdev_ops = { |
447 | .ndo_open = br_dev_open, | |
448 | .ndo_stop = br_dev_stop, | |
bb900b27 | 449 | .ndo_init = br_dev_init, |
b6fe0440 | 450 | .ndo_uninit = br_dev_uninit, |
00829823 | 451 | .ndo_start_xmit = br_dev_xmit, |
7609ecb2 | 452 | .ndo_get_stats64 = dev_get_tstats64, |
00829823 | 453 | .ndo_set_mac_address = br_set_mac_address, |
afc4b13d | 454 | .ndo_set_rx_mode = br_dev_set_multicast_list, |
2796d0c6 | 455 | .ndo_change_rx_flags = br_dev_change_rx_flags, |
00829823 | 456 | .ndo_change_mtu = br_change_mtu, |
561d8352 | 457 | .ndo_siocdevprivate = br_dev_siocdevprivate, |
c06ee961 | 458 | #ifdef CONFIG_NET_POLL_CONTROLLER |
91d2c34a | 459 | .ndo_netpoll_setup = br_netpoll_setup, |
c06ee961 WC |
460 | .ndo_netpoll_cleanup = br_netpoll_cleanup, |
461 | .ndo_poll_controller = br_poll_controller, | |
462 | #endif | |
afc6151a JP |
463 | .ndo_add_slave = br_add_slave, |
464 | .ndo_del_slave = br_del_slave, | |
c4d27ef9 | 465 | .ndo_fix_features = br_fix_features, |
77162022 JF |
466 | .ndo_fdb_add = br_fdb_add, |
467 | .ndo_fdb_del = br_fdb_delete, | |
edaef191 | 468 | .ndo_fdb_del_bulk = br_fdb_delete_bulk, |
77162022 | 469 | .ndo_fdb_dump = br_fdb_dump, |
47674562 | 470 | .ndo_fdb_get = br_fdb_get, |
e5a55a89 JF |
471 | .ndo_bridge_getlink = br_getlink, |
472 | .ndo_bridge_setlink = br_setlink, | |
407af329 | 473 | .ndo_bridge_dellink = br_dellink, |
66780530 | 474 | .ndo_features_check = passthru_features_check, |
ec9d16ba | 475 | .ndo_fill_forward_path = br_fill_forward_path, |
a2dbb882 SH |
476 | }; |
477 | ||
bb900b27 | 478 | static struct device_type br_type = { |
479 | .name = "bridge", | |
480 | }; | |
481 | ||
1da177e4 LT |
482 | void br_dev_setup(struct net_device *dev) |
483 | { | |
bb900b27 | 484 | struct net_bridge *br = netdev_priv(dev); |
485 | ||
7ce5d222 | 486 | eth_hw_addr_random(dev); |
1da177e4 LT |
487 | ether_setup(dev); |
488 | ||
a2dbb882 | 489 | dev->netdev_ops = &br_netdev_ops; |
cf124db5 | 490 | dev->needs_free_netdev = true; |
7ad24ea4 | 491 | dev->ethtool_ops = &br_ethtool_ops; |
bb900b27 | 492 | SET_NETDEV_DEVTYPE(dev, &br_type); |
ccecb2a4 | 493 | dev->priv_flags = IFF_EBRIDGE | IFF_NO_QUEUE; |
edb5e46f | 494 | |
161f65ba | 495 | dev->features = COMMON_FEATURES | NETIF_F_LLTX | NETIF_F_NETNS_LOCAL | |
1c5abb6c TM |
496 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX; |
497 | dev->hw_features = COMMON_FEATURES | NETIF_F_HW_VLAN_CTAG_TX | | |
498 | NETIF_F_HW_VLAN_STAG_TX; | |
161f65ba | 499 | dev->vlan_features = COMMON_FEATURES; |
bb900b27 | 500 | |
501 | br->dev = dev; | |
502 | spin_lock_init(&br->lock); | |
503 | INIT_LIST_HEAD(&br->port_list); | |
eb793583 | 504 | INIT_HLIST_HEAD(&br->fdb_list); |
90c628dd | 505 | INIT_HLIST_HEAD(&br->frame_type_list); |
65369933 | 506 | #if IS_ENABLED(CONFIG_BRIDGE_MRP) |
0169b820 | 507 | INIT_HLIST_HEAD(&br->mrp_list); |
f323aa54 HB |
508 | #endif |
509 | #if IS_ENABLED(CONFIG_BRIDGE_CFM) | |
510 | INIT_HLIST_HEAD(&br->mep_list); | |
65369933 | 511 | #endif |
bb900b27 | 512 | spin_lock_init(&br->hash_lock); |
513 | ||
514 | br->bridge_id.prio[0] = 0x80; | |
515 | br->bridge_id.prio[1] = 0x00; | |
516 | ||
05428729 | 517 | ether_addr_copy(br->group_addr, eth_stp_addr); |
bb900b27 | 518 | |
bb900b27 | 519 | br->stp_enabled = BR_NO_STP; |
515853cc | 520 | br->group_fwd_mask = BR_GROUPFWD_DEFAULT; |
f2808d22 | 521 | br->group_fwd_mask_required = BR_GROUPFWD_DEFAULT; |
515853cc | 522 | |
bb900b27 | 523 | br->designated_root = br->bridge_id; |
524 | br->bridge_max_age = br->max_age = 20 * HZ; | |
525 | br->bridge_hello_time = br->hello_time = 2 * HZ; | |
526 | br->bridge_forward_delay = br->forward_delay = 15 * HZ; | |
34d8acd8 | 527 | br->bridge_ageing_time = br->ageing_time = BR_DEFAULT_AGEING_TIME; |
91572088 | 528 | dev->max_mtu = ETH_MAX_MTU; |
bb900b27 | 529 | |
530 | br_netfilter_rtable_init(br); | |
531 | br_stp_timer_init(br); | |
532 | br_multicast_init(br); | |
f7cdee8a | 533 | INIT_DELAYED_WORK(&br->gc_work, br_fdb_cleanup); |
1da177e4 | 534 | } |