blob: 556caed0025849a9cd4b30825d410029c344e41e [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
Nikolay Aleksandrove1ac1182020-09-22 10:30:15 +030022 } src;
23 union {
24 __be32 ip4;
25#if IS_ENABLED(CONFIG_IPV6)
26 struct in6_addr ip6;
27#endif
Nikolay Aleksandroveab32272020-09-22 10:30:17 +030028 } dst;
Linus Lüssing07f8ac42014-06-07 18:26:28 +020029 __be16 proto;
30 __u16 vid;
31};
32
33struct br_ip_list {
34 struct list_head list;
35 struct br_ip addr;
36};
37
Scott Feldman065c2122014-11-28 14:34:22 +010038#define BR_HAIRPIN_MODE BIT(0)
39#define BR_BPDU_GUARD BIT(1)
40#define BR_ROOT_BLOCK BIT(2)
41#define BR_MULTICAST_FAST_LEAVE BIT(3)
42#define BR_ADMIN_COST BIT(4)
43#define BR_LEARNING BIT(5)
44#define BR_FLOOD BIT(6)
45#define BR_AUTO_MASK (BR_FLOOD | BR_LEARNING)
46#define BR_PROMISC BIT(7)
47#define BR_PROXYARP BIT(8)
Scott Feldmanefacacd2014-11-28 14:34:23 +010048#define BR_LEARNING_SYNC BIT(9)
Jouni Malinen842a9ae2015-03-04 12:54:21 +020049#define BR_PROXYARP_WIFI BIT(10)
Nikolay Aleksandrovb6cb5ac2016-08-31 15:36:52 +020050#define BR_MCAST_FLOOD BIT(11)
Felix Fietkau6db6f0e2017-01-21 21:01:32 +010051#define BR_MULTICAST_TO_UNICAST BIT(12)
Roopa Prabhub3c7ef02017-01-31 22:59:53 -080052#define BR_VLAN_TUNNEL BIT(13)
Mike Manning99f906e2017-04-26 14:48:09 +010053#define BR_BCAST_FLOOD BIT(14)
Roopa Prabhu821f1b22017-10-06 22:12:37 -070054#define BR_NEIGH_SUPPRESS BIT(15)
Nikolay Aleksandrov7d850ab2018-05-24 11:56:48 +030055#define BR_ISOLATED BIT(16)
Horatiu Vultur4b8d7d42020-04-26 15:22:00 +020056#define BR_MRP_AWARE BIT(17)
57#define BR_MRP_LOST_CONT BIT(18)
Horatiu Vultur43364ef2020-07-14 09:34:49 +020058#define BR_MRP_LOST_IN_CONT BIT(19)
Scott Feldman065c2122014-11-28 14:34:22 +010059
Scott Feldmana79e88d92015-09-23 08:39:16 -070060#define BR_DEFAULT_AGEING_TIME (300 * HZ)
61
Eric W. Biederman881d9662007-09-17 11:56:21 -070062extern void brioctl_set(int (*ioctl_hook)(struct net *, unsigned int, void __user *));
Eric Dumazeta386f992010-11-15 06:38:11 +000063
Linus Lüssingf941a6d2014-07-07 05:41:16 +020064#if IS_ENABLED(CONFIG_BRIDGE) && IS_ENABLED(CONFIG_BRIDGE_IGMP_SNOOPING)
Linus Lüssing07f8ac42014-06-07 18:26:28 +020065int br_multicast_list_adjacent(struct net_device *dev,
66 struct list_head *br_ip_list);
Linus Lüssingc34963e2014-07-07 05:41:17 +020067bool br_multicast_has_querier_anywhere(struct net_device *dev, int proto);
Linus Lüssing2cd41432014-06-07 18:26:29 +020068bool br_multicast_has_querier_adjacent(struct net_device *dev, int proto);
Ido Schimmel9341b982017-05-26 08:37:24 +020069bool br_multicast_enabled(const struct net_device *dev);
Yotam Gigi0912bda2017-10-09 11:15:32 +020070bool br_multicast_router(const struct net_device *dev);
Linus Lüssingf941a6d2014-07-07 05:41:16 +020071#else
72static inline int br_multicast_list_adjacent(struct net_device *dev,
73 struct list_head *br_ip_list)
74{
75 return 0;
76}
Linus Lüssingc34963e2014-07-07 05:41:17 +020077static inline bool br_multicast_has_querier_anywhere(struct net_device *dev,
78 int proto)
79{
80 return false;
81}
Linus Lüssingf941a6d2014-07-07 05:41:16 +020082static inline bool br_multicast_has_querier_adjacent(struct net_device *dev,
83 int proto)
84{
85 return false;
86}
Ido Schimmel9341b982017-05-26 08:37:24 +020087static inline bool br_multicast_enabled(const struct net_device *dev)
88{
89 return false;
90}
Yotam Gigi0912bda2017-10-09 11:15:32 +020091static inline bool br_multicast_router(const struct net_device *dev)
92{
93 return false;
94}
Linus Lüssingf941a6d2014-07-07 05:41:16 +020095#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Ido Schimmel1f514452017-05-26 08:37:23 +020097#if IS_ENABLED(CONFIG_BRIDGE) && IS_ENABLED(CONFIG_BRIDGE_VLAN_FILTERING)
98bool br_vlan_enabled(const struct net_device *dev);
Petr Machata4d4fd362018-04-29 10:56:08 +030099int br_vlan_get_pvid(const struct net_device *dev, u16 *p_pvid);
Pablo Neira Ayuso7582f5b2019-07-05 21:16:34 +0800100int br_vlan_get_pvid_rcu(const struct net_device *dev, u16 *p_pvid);
wenxu31aed462019-07-05 21:16:36 +0800101int br_vlan_get_proto(const struct net_device *dev, u16 *p_proto);
Petr Machata4d4fd362018-04-29 10:56:08 +0300102int br_vlan_get_info(const struct net_device *dev, u16 vid,
103 struct bridge_vlan_info *p_vinfo);
Ido Schimmel1f514452017-05-26 08:37:23 +0200104#else
105static inline bool br_vlan_enabled(const struct net_device *dev)
106{
107 return false;
108}
Petr Machata4d4fd362018-04-29 10:56:08 +0300109
110static inline int br_vlan_get_pvid(const struct net_device *dev, u16 *p_pvid)
111{
Arnd Bergmann000244d2018-07-06 14:44:02 +0200112 return -EINVAL;
Petr Machata4d4fd362018-04-29 10:56:08 +0300113}
114
wenxu31aed462019-07-05 21:16:36 +0800115static inline int br_vlan_get_proto(const struct net_device *dev, u16 *p_proto)
116{
117 return -EINVAL;
118}
119
Pablo Neira Ayuso7582f5b2019-07-05 21:16:34 +0800120static inline int br_vlan_get_pvid_rcu(const struct net_device *dev, u16 *p_pvid)
121{
122 return -EINVAL;
123}
124
Petr Machata4d4fd362018-04-29 10:56:08 +0300125static inline int br_vlan_get_info(const struct net_device *dev, u16 vid,
126 struct bridge_vlan_info *p_vinfo)
127{
Arnd Bergmann000244d2018-07-06 14:44:02 +0200128 return -EINVAL;
Petr Machata4d4fd362018-04-29 10:56:08 +0300129}
130#endif
131
132#if IS_ENABLED(CONFIG_BRIDGE)
133struct net_device *br_fdb_find_port(const struct net_device *br_dev,
134 const unsigned char *addr,
135 __u16 vid);
Petr Machata43920ed2018-12-07 19:55:07 +0000136void br_fdb_clear_offload(const struct net_device *dev, u16 vid);
Ido Schimmel085ddc82018-11-21 08:02:41 +0000137bool br_port_flag_is_set(const struct net_device *dev, unsigned long flag);
Petr Machata4d4fd362018-04-29 10:56:08 +0300138#else
139static inline struct net_device *
140br_fdb_find_port(const struct net_device *br_dev,
141 const unsigned char *addr,
142 __u16 vid)
143{
144 return NULL;
145}
Petr Machata43920ed2018-12-07 19:55:07 +0000146
147static inline void br_fdb_clear_offload(const struct net_device *dev, u16 vid)
148{
149}
150
Ido Schimmel085ddc82018-11-21 08:02:41 +0000151static inline bool
152br_port_flag_is_set(const struct net_device *dev, unsigned long flag)
153{
154 return false;
155}
Ido Schimmel1f514452017-05-26 08:37:23 +0200156#endif
157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158#endif