blob: 9e57c4411734915a83c8c5fdc52ae334e22e8452 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Linux ethernet bridge
4 *
5 * Authors:
6 * Lennert Buytenhek <buytenh@gnu.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#ifndef _LINUX_IF_BRIDGE_H
9#define _LINUX_IF_BRIDGE_H
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
12#include <linux/netdevice.h>
David Howells607ca462012-10-13 10:46:48 +010013#include <uapi/linux/if_bridge.h>
Scott Feldman065c2122014-11-28 14:34:22 +010014#include <linux/bitops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Linus Lüssing07f8ac42014-06-07 18:26:28 +020016struct br_ip {
17 union {
18 __be32 ip4;
19#if IS_ENABLED(CONFIG_IPV6)
20 struct in6_addr ip6;
21#endif
22 } u;
23 __be16 proto;
24 __u16 vid;
25};
26
27struct br_ip_list {
28 struct list_head list;
29 struct br_ip addr;
30};
31
Scott Feldman065c2122014-11-28 14:34:22 +010032#define BR_HAIRPIN_MODE BIT(0)
33#define BR_BPDU_GUARD BIT(1)
34#define BR_ROOT_BLOCK BIT(2)
35#define BR_MULTICAST_FAST_LEAVE BIT(3)
36#define BR_ADMIN_COST BIT(4)
37#define BR_LEARNING BIT(5)
38#define BR_FLOOD BIT(6)
39#define BR_AUTO_MASK (BR_FLOOD | BR_LEARNING)
40#define BR_PROMISC BIT(7)
41#define BR_PROXYARP BIT(8)
Scott Feldmanefacacd2014-11-28 14:34:23 +010042#define BR_LEARNING_SYNC BIT(9)
Jouni Malinen842a9ae2015-03-04 12:54:21 +020043#define BR_PROXYARP_WIFI BIT(10)
Nikolay Aleksandrovb6cb5ac2016-08-31 15:36:52 +020044#define BR_MCAST_FLOOD BIT(11)
Felix Fietkau6db6f0e2017-01-21 21:01:32 +010045#define BR_MULTICAST_TO_UNICAST BIT(12)
Roopa Prabhub3c7ef02017-01-31 22:59:53 -080046#define BR_VLAN_TUNNEL BIT(13)
Mike Manning99f906e2017-04-26 14:48:09 +010047#define BR_BCAST_FLOOD BIT(14)
Roopa Prabhu821f1b22017-10-06 22:12:37 -070048#define BR_NEIGH_SUPPRESS BIT(15)
Nikolay Aleksandrov7d850ab2018-05-24 11:56:48 +030049#define BR_ISOLATED BIT(16)
Scott Feldman065c2122014-11-28 14:34:22 +010050
Scott Feldmana79e88d2015-09-23 08:39:16 -070051#define BR_DEFAULT_AGEING_TIME (300 * HZ)
52
Eric W. Biederman881d9662007-09-17 11:56:21 -070053extern void brioctl_set(int (*ioctl_hook)(struct net *, unsigned int, void __user *));
Eric Dumazeta386f992010-11-15 06:38:11 +000054
Linus Lüssingf941a6d2014-07-07 05:41:16 +020055#if IS_ENABLED(CONFIG_BRIDGE) && IS_ENABLED(CONFIG_BRIDGE_IGMP_SNOOPING)
Linus Lüssing07f8ac42014-06-07 18:26:28 +020056int br_multicast_list_adjacent(struct net_device *dev,
57 struct list_head *br_ip_list);
Linus Lüssingc34963e2014-07-07 05:41:17 +020058bool br_multicast_has_querier_anywhere(struct net_device *dev, int proto);
Linus Lüssing2cd41432014-06-07 18:26:29 +020059bool br_multicast_has_querier_adjacent(struct net_device *dev, int proto);
Ido Schimmel9341b982017-05-26 08:37:24 +020060bool br_multicast_enabled(const struct net_device *dev);
Yotam Gigi0912bda2017-10-09 11:15:32 +020061bool br_multicast_router(const struct net_device *dev);
Linus Lüssingf941a6d2014-07-07 05:41:16 +020062#else
63static inline int br_multicast_list_adjacent(struct net_device *dev,
64 struct list_head *br_ip_list)
65{
66 return 0;
67}
Linus Lüssingc34963e2014-07-07 05:41:17 +020068static inline bool br_multicast_has_querier_anywhere(struct net_device *dev,
69 int proto)
70{
71 return false;
72}
Linus Lüssingf941a6d2014-07-07 05:41:16 +020073static inline bool br_multicast_has_querier_adjacent(struct net_device *dev,
74 int proto)
75{
76 return false;
77}
Ido Schimmel9341b982017-05-26 08:37:24 +020078static inline bool br_multicast_enabled(const struct net_device *dev)
79{
80 return false;
81}
Yotam Gigi0912bda2017-10-09 11:15:32 +020082static inline bool br_multicast_router(const struct net_device *dev)
83{
84 return false;
85}
Linus Lüssingf941a6d2014-07-07 05:41:16 +020086#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Ido Schimmel1f514452017-05-26 08:37:23 +020088#if IS_ENABLED(CONFIG_BRIDGE) && IS_ENABLED(CONFIG_BRIDGE_VLAN_FILTERING)
89bool br_vlan_enabled(const struct net_device *dev);
Petr Machata4d4fd362018-04-29 10:56:08 +030090int br_vlan_get_pvid(const struct net_device *dev, u16 *p_pvid);
Pablo Neira Ayuso7582f5b2019-07-05 21:16:34 +080091int br_vlan_get_pvid_rcu(const struct net_device *dev, u16 *p_pvid);
wenxu31aed462019-07-05 21:16:36 +080092int br_vlan_get_proto(const struct net_device *dev, u16 *p_proto);
Petr Machata4d4fd362018-04-29 10:56:08 +030093int br_vlan_get_info(const struct net_device *dev, u16 vid,
94 struct bridge_vlan_info *p_vinfo);
Ido Schimmel1f514452017-05-26 08:37:23 +020095#else
96static inline bool br_vlan_enabled(const struct net_device *dev)
97{
98 return false;
99}
Petr Machata4d4fd362018-04-29 10:56:08 +0300100
101static inline int br_vlan_get_pvid(const struct net_device *dev, u16 *p_pvid)
102{
Arnd Bergmann000244d2018-07-06 14:44:02 +0200103 return -EINVAL;
Petr Machata4d4fd362018-04-29 10:56:08 +0300104}
105
wenxu31aed462019-07-05 21:16:36 +0800106static inline int br_vlan_get_proto(const struct net_device *dev, u16 *p_proto)
107{
108 return -EINVAL;
109}
110
Pablo Neira Ayuso7582f5b2019-07-05 21:16:34 +0800111static inline int br_vlan_get_pvid_rcu(const struct net_device *dev, u16 *p_pvid)
112{
113 return -EINVAL;
114}
115
Petr Machata4d4fd362018-04-29 10:56:08 +0300116static inline int br_vlan_get_info(const struct net_device *dev, u16 vid,
117 struct bridge_vlan_info *p_vinfo)
118{
Arnd Bergmann000244d2018-07-06 14:44:02 +0200119 return -EINVAL;
Petr Machata4d4fd362018-04-29 10:56:08 +0300120}
121#endif
122
123#if IS_ENABLED(CONFIG_BRIDGE)
124struct net_device *br_fdb_find_port(const struct net_device *br_dev,
125 const unsigned char *addr,
126 __u16 vid);
Petr Machata43920ed2018-12-07 19:55:07 +0000127void br_fdb_clear_offload(const struct net_device *dev, u16 vid);
Ido Schimmel085ddc82018-11-21 08:02:41 +0000128bool br_port_flag_is_set(const struct net_device *dev, unsigned long flag);
Petr Machata4d4fd362018-04-29 10:56:08 +0300129#else
130static inline struct net_device *
131br_fdb_find_port(const struct net_device *br_dev,
132 const unsigned char *addr,
133 __u16 vid)
134{
135 return NULL;
136}
Petr Machata43920ed2018-12-07 19:55:07 +0000137
138static inline void br_fdb_clear_offload(const struct net_device *dev, u16 vid)
139{
140}
141
Ido Schimmel085ddc82018-11-21 08:02:41 +0000142static inline bool
143br_port_flag_is_set(const struct net_device *dev, unsigned long flag)
144{
145 return false;
146}
Ido Schimmel1f514452017-05-26 08:37:23 +0200147#endif
148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#endif