br_private.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. /*
  2. * Linux ethernet bridge
  3. *
  4. * Authors:
  5. * Lennert Buytenhek <buytenh@gnu.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. #ifndef _BR_PRIVATE_H
  13. #define _BR_PRIVATE_H
  14. #include <linux/netdevice.h>
  15. #include <linux/if_bridge.h>
  16. #include <linux/netpoll.h>
  17. #include <linux/u64_stats_sync.h>
  18. #include <net/route.h>
  19. #include <net/ip6_fib.h>
  20. #include <linux/if_vlan.h>
  21. #include <linux/rhashtable.h>
  22. #define BR_HASH_BITS 8
  23. #define BR_HASH_SIZE (1 << BR_HASH_BITS)
  24. #define BR_HOLD_TIME (1*HZ)
  25. #define BR_PORT_BITS 10
  26. #define BR_MAX_PORTS (1<<BR_PORT_BITS)
  27. #define BR_VERSION "2.3"
  28. /* Control of forwarding link local multicast */
  29. #define BR_GROUPFWD_DEFAULT 0
  30. /* Don't allow forwarding of control protocols like STP, MAC PAUSE and LACP */
  31. #define BR_GROUPFWD_RESTRICTED 0x0007u
  32. /* The Nearest Customer Bridge Group Address, 01-80-C2-00-00-[00,0B,0C,0D,0F] */
  33. #define BR_GROUPFWD_8021AD 0xB801u
  34. /* Path to usermode spanning tree program */
  35. #define BR_STP_PROG "/sbin/bridge-stp"
  36. typedef struct bridge_id bridge_id;
  37. typedef struct mac_addr mac_addr;
  38. typedef __u16 port_id;
  39. struct bridge_id
  40. {
  41. unsigned char prio[2];
  42. unsigned char addr[ETH_ALEN];
  43. };
  44. struct mac_addr
  45. {
  46. unsigned char addr[ETH_ALEN];
  47. };
  48. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
  49. /* our own querier */
  50. struct bridge_mcast_own_query {
  51. struct timer_list timer;
  52. u32 startup_sent;
  53. };
  54. /* other querier */
  55. struct bridge_mcast_other_query {
  56. struct timer_list timer;
  57. unsigned long delay_time;
  58. };
  59. /* selected querier */
  60. struct bridge_mcast_querier {
  61. struct br_ip addr;
  62. struct net_bridge_port __rcu *port;
  63. };
  64. #endif
  65. /**
  66. * struct net_bridge_vlan - per-vlan entry
  67. *
  68. * @vnode: rhashtable member
  69. * @vid: VLAN id
  70. * @flags: bridge vlan flags
  71. * @br: if MASTER flag set, this points to a bridge struct
  72. * @port: if MASTER flag unset, this points to a port struct
  73. * @refcnt: if MASTER flag set, this is bumped for each port referencing it
  74. * @brvlan: if MASTER flag unset, this points to the global per-VLAN context
  75. * for this VLAN entry
  76. * @vlist: sorted list of VLAN entries
  77. * @rcu: used for entry destruction
  78. *
  79. * This structure is shared between the global per-VLAN entries contained in
  80. * the bridge rhashtable and the local per-port per-VLAN entries contained in
  81. * the port's rhashtable. The union entries should be interpreted depending on
  82. * the entry flags that are set.
  83. */
  84. struct net_bridge_vlan {
  85. struct rhash_head vnode;
  86. u16 vid;
  87. u16 flags;
  88. union {
  89. struct net_bridge *br;
  90. struct net_bridge_port *port;
  91. };
  92. union {
  93. atomic_t refcnt;
  94. struct net_bridge_vlan *brvlan;
  95. };
  96. struct list_head vlist;
  97. struct rcu_head rcu;
  98. };
  99. /**
  100. * struct net_bridge_vlan_group
  101. *
  102. * @vlan_hash: VLAN entry rhashtable
  103. * @vlan_list: sorted VLAN entry list
  104. * @num_vlans: number of total VLAN entries
  105. * @pvid: PVID VLAN id
  106. *
  107. * IMPORTANT: Be careful when checking if there're VLAN entries using list
  108. * primitives because the bridge can have entries in its list which
  109. * are just for global context but not for filtering, i.e. they have
  110. * the master flag set but not the brentry flag. If you have to check
  111. * if there're "real" entries in the bridge please test @num_vlans
  112. */
  113. struct net_bridge_vlan_group {
  114. struct rhashtable vlan_hash;
  115. struct list_head vlan_list;
  116. u16 num_vlans;
  117. u16 pvid;
  118. };
  119. struct net_bridge_fdb_entry
  120. {
  121. struct hlist_node hlist;
  122. struct net_bridge_port *dst;
  123. unsigned long updated;
  124. unsigned long used;
  125. mac_addr addr;
  126. __u16 vlan_id;
  127. unsigned char is_local:1,
  128. is_static:1,
  129. added_by_user:1,
  130. added_by_external_learn:1;
  131. struct rcu_head rcu;
  132. };
  133. #define MDB_PG_FLAGS_PERMANENT BIT(0)
  134. #define MDB_PG_FLAGS_OFFLOAD BIT(1)
  135. struct net_bridge_port_group {
  136. struct net_bridge_port *port;
  137. struct net_bridge_port_group __rcu *next;
  138. struct hlist_node mglist;
  139. struct rcu_head rcu;
  140. struct timer_list timer;
  141. struct br_ip addr;
  142. unsigned char flags;
  143. };
  144. struct net_bridge_mdb_entry
  145. {
  146. struct hlist_node hlist[2];
  147. struct net_bridge *br;
  148. struct net_bridge_port_group __rcu *ports;
  149. struct rcu_head rcu;
  150. struct timer_list timer;
  151. struct br_ip addr;
  152. bool mglist;
  153. };
  154. struct net_bridge_mdb_htable
  155. {
  156. struct hlist_head *mhash;
  157. struct rcu_head rcu;
  158. struct net_bridge_mdb_htable *old;
  159. u32 size;
  160. u32 max;
  161. u32 secret;
  162. u32 ver;
  163. };
  164. struct net_bridge_port
  165. {
  166. struct net_bridge *br;
  167. struct net_device *dev;
  168. struct list_head list;
  169. /* STP */
  170. u8 priority;
  171. u8 state;
  172. u16 port_no;
  173. unsigned char topology_change_ack;
  174. unsigned char config_pending;
  175. port_id port_id;
  176. port_id designated_port;
  177. bridge_id designated_root;
  178. bridge_id designated_bridge;
  179. u32 path_cost;
  180. u32 designated_cost;
  181. unsigned long designated_age;
  182. struct timer_list forward_delay_timer;
  183. struct timer_list hold_timer;
  184. struct timer_list message_age_timer;
  185. struct kobject kobj;
  186. struct rcu_head rcu;
  187. unsigned long flags;
  188. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
  189. struct bridge_mcast_own_query ip4_own_query;
  190. #if IS_ENABLED(CONFIG_IPV6)
  191. struct bridge_mcast_own_query ip6_own_query;
  192. #endif /* IS_ENABLED(CONFIG_IPV6) */
  193. unsigned char multicast_router;
  194. struct timer_list multicast_router_timer;
  195. struct hlist_head mglist;
  196. struct hlist_node rlist;
  197. #endif
  198. #ifdef CONFIG_SYSFS
  199. char sysfs_name[IFNAMSIZ];
  200. #endif
  201. #ifdef CONFIG_NET_POLL_CONTROLLER
  202. struct netpoll *np;
  203. #endif
  204. #ifdef CONFIG_BRIDGE_VLAN_FILTERING
  205. struct net_bridge_vlan_group __rcu *vlgrp;
  206. #endif
  207. };
  208. #define br_auto_port(p) ((p)->flags & BR_AUTO_MASK)
  209. #define br_promisc_port(p) ((p)->flags & BR_PROMISC)
  210. #define br_port_exists(dev) (dev->priv_flags & IFF_BRIDGE_PORT)
  211. static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev)
  212. {
  213. return rcu_dereference(dev->rx_handler_data);
  214. }
  215. static inline struct net_bridge_port *br_port_get_rtnl(const struct net_device *dev)
  216. {
  217. return br_port_exists(dev) ?
  218. rtnl_dereference(dev->rx_handler_data) : NULL;
  219. }
  220. struct net_bridge
  221. {
  222. spinlock_t lock;
  223. struct list_head port_list;
  224. struct net_device *dev;
  225. struct pcpu_sw_netstats __percpu *stats;
  226. spinlock_t hash_lock;
  227. struct hlist_head hash[BR_HASH_SIZE];
  228. #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
  229. union {
  230. struct rtable fake_rtable;
  231. struct rt6_info fake_rt6_info;
  232. };
  233. bool nf_call_iptables;
  234. bool nf_call_ip6tables;
  235. bool nf_call_arptables;
  236. #endif
  237. u16 group_fwd_mask;
  238. u16 group_fwd_mask_required;
  239. /* STP */
  240. bridge_id designated_root;
  241. bridge_id bridge_id;
  242. u32 root_path_cost;
  243. unsigned long max_age;
  244. unsigned long hello_time;
  245. unsigned long forward_delay;
  246. unsigned long bridge_max_age;
  247. unsigned long ageing_time;
  248. unsigned long bridge_hello_time;
  249. unsigned long bridge_forward_delay;
  250. u8 group_addr[ETH_ALEN];
  251. bool group_addr_set;
  252. u16 root_port;
  253. enum {
  254. BR_NO_STP, /* no spanning tree */
  255. BR_KERNEL_STP, /* old STP in kernel */
  256. BR_USER_STP, /* new RSTP in userspace */
  257. } stp_enabled;
  258. unsigned char topology_change;
  259. unsigned char topology_change_detected;
  260. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
  261. unsigned char multicast_router;
  262. u8 multicast_disabled:1;
  263. u8 multicast_querier:1;
  264. u8 multicast_query_use_ifaddr:1;
  265. u32 hash_elasticity;
  266. u32 hash_max;
  267. u32 multicast_last_member_count;
  268. u32 multicast_startup_query_count;
  269. unsigned long multicast_last_member_interval;
  270. unsigned long multicast_membership_interval;
  271. unsigned long multicast_querier_interval;
  272. unsigned long multicast_query_interval;
  273. unsigned long multicast_query_response_interval;
  274. unsigned long multicast_startup_query_interval;
  275. spinlock_t multicast_lock;
  276. struct net_bridge_mdb_htable __rcu *mdb;
  277. struct hlist_head router_list;
  278. struct timer_list multicast_router_timer;
  279. struct bridge_mcast_other_query ip4_other_query;
  280. struct bridge_mcast_own_query ip4_own_query;
  281. struct bridge_mcast_querier ip4_querier;
  282. #if IS_ENABLED(CONFIG_IPV6)
  283. struct bridge_mcast_other_query ip6_other_query;
  284. struct bridge_mcast_own_query ip6_own_query;
  285. struct bridge_mcast_querier ip6_querier;
  286. #endif /* IS_ENABLED(CONFIG_IPV6) */
  287. #endif
  288. struct timer_list hello_timer;
  289. struct timer_list tcn_timer;
  290. struct timer_list topology_change_timer;
  291. struct timer_list gc_timer;
  292. struct kobject *ifobj;
  293. u32 auto_cnt;
  294. #ifdef CONFIG_BRIDGE_VLAN_FILTERING
  295. struct net_bridge_vlan_group __rcu *vlgrp;
  296. u8 vlan_enabled;
  297. __be16 vlan_proto;
  298. u16 default_pvid;
  299. #endif
  300. };
  301. struct br_input_skb_cb {
  302. struct net_device *brdev;
  303. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
  304. int igmp;
  305. int mrouters_only;
  306. #endif
  307. bool proxyarp_replied;
  308. #ifdef CONFIG_BRIDGE_VLAN_FILTERING
  309. bool vlan_filtered;
  310. #endif
  311. };
  312. #define BR_INPUT_SKB_CB(__skb) ((struct br_input_skb_cb *)(__skb)->cb)
  313. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
  314. # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (BR_INPUT_SKB_CB(__skb)->mrouters_only)
  315. #else
  316. # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (0)
  317. #endif
  318. #define br_printk(level, br, format, args...) \
  319. printk(level "%s: " format, (br)->dev->name, ##args)
  320. #define br_err(__br, format, args...) \
  321. br_printk(KERN_ERR, __br, format, ##args)
  322. #define br_warn(__br, format, args...) \
  323. br_printk(KERN_WARNING, __br, format, ##args)
  324. #define br_notice(__br, format, args...) \
  325. br_printk(KERN_NOTICE, __br, format, ##args)
  326. #define br_info(__br, format, args...) \
  327. br_printk(KERN_INFO, __br, format, ##args)
  328. #define br_debug(br, format, args...) \
  329. pr_debug("%s: " format, (br)->dev->name, ##args)
  330. /* called under bridge lock */
  331. static inline int br_is_root_bridge(const struct net_bridge *br)
  332. {
  333. return !memcmp(&br->bridge_id, &br->designated_root, 8);
  334. }
  335. /* check if a VLAN entry is global */
  336. static inline bool br_vlan_is_master(const struct net_bridge_vlan *v)
  337. {
  338. return v->flags & BRIDGE_VLAN_INFO_MASTER;
  339. }
  340. /* check if a VLAN entry is used by the bridge */
  341. static inline bool br_vlan_is_brentry(const struct net_bridge_vlan *v)
  342. {
  343. return v->flags & BRIDGE_VLAN_INFO_BRENTRY;
  344. }
  345. /* check if we should use the vlan entry, returns false if it's only context */
  346. static inline bool br_vlan_should_use(const struct net_bridge_vlan *v)
  347. {
  348. if (br_vlan_is_master(v)) {
  349. if (br_vlan_is_brentry(v))
  350. return true;
  351. else
  352. return false;
  353. }
  354. return true;
  355. }
  356. /* br_device.c */
  357. void br_dev_setup(struct net_device *dev);
  358. void br_dev_delete(struct net_device *dev, struct list_head *list);
  359. netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev);
  360. #ifdef CONFIG_NET_POLL_CONTROLLER
  361. static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
  362. struct sk_buff *skb)
  363. {
  364. struct netpoll *np = p->np;
  365. if (np)
  366. netpoll_send_skb(np, skb);
  367. }
  368. int br_netpoll_enable(struct net_bridge_port *p);
  369. void br_netpoll_disable(struct net_bridge_port *p);
  370. #else
  371. static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
  372. struct sk_buff *skb)
  373. {
  374. }
  375. static inline int br_netpoll_enable(struct net_bridge_port *p)
  376. {
  377. return 0;
  378. }
  379. static inline void br_netpoll_disable(struct net_bridge_port *p)
  380. {
  381. }
  382. #endif
  383. /* br_fdb.c */
  384. int br_fdb_init(void);
  385. void br_fdb_fini(void);
  386. void br_fdb_flush(struct net_bridge *br);
  387. void br_fdb_find_delete_local(struct net_bridge *br,
  388. const struct net_bridge_port *p,
  389. const unsigned char *addr, u16 vid);
  390. void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr);
  391. void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr);
  392. void br_fdb_cleanup(unsigned long arg);
  393. void br_fdb_delete_by_port(struct net_bridge *br,
  394. const struct net_bridge_port *p, u16 vid, int do_all);
  395. struct net_bridge_fdb_entry *__br_fdb_get(struct net_bridge *br,
  396. const unsigned char *addr, __u16 vid);
  397. int br_fdb_test_addr(struct net_device *dev, unsigned char *addr);
  398. int br_fdb_fillbuf(struct net_bridge *br, void *buf, unsigned long count,
  399. unsigned long off);
  400. int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
  401. const unsigned char *addr, u16 vid);
  402. void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
  403. const unsigned char *addr, u16 vid, bool added_by_user);
  404. int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
  405. struct net_device *dev, const unsigned char *addr, u16 vid);
  406. int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev,
  407. const unsigned char *addr, u16 vid, u16 nlh_flags);
  408. int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
  409. struct net_device *dev, struct net_device *fdev, int idx);
  410. int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p);
  411. void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p);
  412. int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
  413. const unsigned char *addr, u16 vid);
  414. int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p,
  415. const unsigned char *addr, u16 vid);
  416. /* br_forward.c */
  417. void br_deliver(const struct net_bridge_port *to, struct sk_buff *skb);
  418. int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb);
  419. void br_forward(const struct net_bridge_port *to,
  420. struct sk_buff *skb, struct sk_buff *skb0);
  421. int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
  422. void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb, bool unicast);
  423. void br_flood_forward(struct net_bridge *br, struct sk_buff *skb,
  424. struct sk_buff *skb2, bool unicast);
  425. /* br_if.c */
  426. void br_port_carrier_check(struct net_bridge_port *p);
  427. int br_add_bridge(struct net *net, const char *name);
  428. int br_del_bridge(struct net *net, const char *name);
  429. int br_add_if(struct net_bridge *br, struct net_device *dev);
  430. int br_del_if(struct net_bridge *br, struct net_device *dev);
  431. int br_min_mtu(const struct net_bridge *br);
  432. netdev_features_t br_features_recompute(struct net_bridge *br,
  433. netdev_features_t features);
  434. void br_port_flags_change(struct net_bridge_port *port, unsigned long mask);
  435. void br_manage_promisc(struct net_bridge *br);
  436. /* br_input.c */
  437. int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
  438. rx_handler_result_t br_handle_frame(struct sk_buff **pskb);
  439. static inline bool br_rx_handler_check_rcu(const struct net_device *dev)
  440. {
  441. return rcu_dereference(dev->rx_handler) == br_handle_frame;
  442. }
  443. static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev)
  444. {
  445. return br_rx_handler_check_rcu(dev) ? br_port_get_rcu(dev) : NULL;
  446. }
  447. /* br_ioctl.c */
  448. int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  449. int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd,
  450. void __user *arg);
  451. /* br_multicast.c */
  452. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
  453. extern unsigned int br_mdb_rehash_seq;
  454. int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port,
  455. struct sk_buff *skb, u16 vid);
  456. struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
  457. struct sk_buff *skb, u16 vid);
  458. void br_multicast_add_port(struct net_bridge_port *port);
  459. void br_multicast_del_port(struct net_bridge_port *port);
  460. void br_multicast_enable_port(struct net_bridge_port *port);
  461. void br_multicast_disable_port(struct net_bridge_port *port);
  462. void br_multicast_init(struct net_bridge *br);
  463. void br_multicast_open(struct net_bridge *br);
  464. void br_multicast_stop(struct net_bridge *br);
  465. void br_multicast_dev_del(struct net_bridge *br);
  466. void br_multicast_deliver(struct net_bridge_mdb_entry *mdst,
  467. struct sk_buff *skb);
  468. void br_multicast_forward(struct net_bridge_mdb_entry *mdst,
  469. struct sk_buff *skb, struct sk_buff *skb2);
  470. int br_multicast_set_router(struct net_bridge *br, unsigned long val);
  471. int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val);
  472. int br_multicast_toggle(struct net_bridge *br, unsigned long val);
  473. int br_multicast_set_querier(struct net_bridge *br, unsigned long val);
  474. int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val);
  475. struct net_bridge_mdb_entry *
  476. br_mdb_ip_get(struct net_bridge_mdb_htable *mdb, struct br_ip *dst);
  477. struct net_bridge_mdb_entry *
  478. br_multicast_new_group(struct net_bridge *br, struct net_bridge_port *port,
  479. struct br_ip *group);
  480. void br_multicast_free_pg(struct rcu_head *head);
  481. struct net_bridge_port_group *
  482. br_multicast_new_port_group(struct net_bridge_port *port, struct br_ip *group,
  483. struct net_bridge_port_group __rcu *next,
  484. unsigned char flags);
  485. void br_mdb_init(void);
  486. void br_mdb_uninit(void);
  487. void br_mdb_notify(struct net_device *dev, struct net_bridge_port_group *pg,
  488. int type);
  489. void br_rtr_notify(struct net_device *dev, struct net_bridge_port *port,
  490. int type);
  491. #define mlock_dereference(X, br) \
  492. rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock))
  493. static inline bool br_multicast_is_router(struct net_bridge *br)
  494. {
  495. return br->multicast_router == 2 ||
  496. (br->multicast_router == 1 &&
  497. timer_pending(&br->multicast_router_timer));
  498. }
  499. static inline bool
  500. __br_multicast_querier_exists(struct net_bridge *br,
  501. struct bridge_mcast_other_query *querier)
  502. {
  503. return time_is_before_jiffies(querier->delay_time) &&
  504. (br->multicast_querier || timer_pending(&querier->timer));
  505. }
  506. static inline bool br_multicast_querier_exists(struct net_bridge *br,
  507. struct ethhdr *eth)
  508. {
  509. switch (eth->h_proto) {
  510. case (htons(ETH_P_IP)):
  511. return __br_multicast_querier_exists(br, &br->ip4_other_query);
  512. #if IS_ENABLED(CONFIG_IPV6)
  513. case (htons(ETH_P_IPV6)):
  514. return __br_multicast_querier_exists(br, &br->ip6_other_query);
  515. #endif
  516. default:
  517. return false;
  518. }
  519. }
  520. #else
  521. static inline int br_multicast_rcv(struct net_bridge *br,
  522. struct net_bridge_port *port,
  523. struct sk_buff *skb,
  524. u16 vid)
  525. {
  526. return 0;
  527. }
  528. static inline struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
  529. struct sk_buff *skb, u16 vid)
  530. {
  531. return NULL;
  532. }
  533. static inline void br_multicast_add_port(struct net_bridge_port *port)
  534. {
  535. }
  536. static inline void br_multicast_del_port(struct net_bridge_port *port)
  537. {
  538. }
  539. static inline void br_multicast_enable_port(struct net_bridge_port *port)
  540. {
  541. }
  542. static inline void br_multicast_disable_port(struct net_bridge_port *port)
  543. {
  544. }
  545. static inline void br_multicast_init(struct net_bridge *br)
  546. {
  547. }
  548. static inline void br_multicast_open(struct net_bridge *br)
  549. {
  550. }
  551. static inline void br_multicast_stop(struct net_bridge *br)
  552. {
  553. }
  554. static inline void br_multicast_dev_del(struct net_bridge *br)
  555. {
  556. }
  557. static inline void br_multicast_deliver(struct net_bridge_mdb_entry *mdst,
  558. struct sk_buff *skb)
  559. {
  560. }
  561. static inline void br_multicast_forward(struct net_bridge_mdb_entry *mdst,
  562. struct sk_buff *skb,
  563. struct sk_buff *skb2)
  564. {
  565. }
  566. static inline bool br_multicast_is_router(struct net_bridge *br)
  567. {
  568. return 0;
  569. }
  570. static inline bool br_multicast_querier_exists(struct net_bridge *br,
  571. struct ethhdr *eth)
  572. {
  573. return false;
  574. }
  575. static inline void br_mdb_init(void)
  576. {
  577. }
  578. static inline void br_mdb_uninit(void)
  579. {
  580. }
  581. #endif
  582. /* br_vlan.c */
  583. #ifdef CONFIG_BRIDGE_VLAN_FILTERING
  584. bool br_allowed_ingress(const struct net_bridge *br,
  585. struct net_bridge_vlan_group *vg, struct sk_buff *skb,
  586. u16 *vid);
  587. bool br_allowed_egress(struct net_bridge_vlan_group *vg,
  588. const struct sk_buff *skb);
  589. bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid);
  590. struct sk_buff *br_handle_vlan(struct net_bridge *br,
  591. struct net_bridge_vlan_group *vg,
  592. struct sk_buff *skb);
  593. int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags);
  594. int br_vlan_delete(struct net_bridge *br, u16 vid);
  595. void br_vlan_flush(struct net_bridge *br);
  596. struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid);
  597. void br_recalculate_fwd_mask(struct net_bridge *br);
  598. int __br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
  599. int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
  600. int __br_vlan_set_proto(struct net_bridge *br, __be16 proto);
  601. int br_vlan_set_proto(struct net_bridge *br, unsigned long val);
  602. int br_vlan_init(struct net_bridge *br);
  603. int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val);
  604. int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid);
  605. int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags);
  606. int nbp_vlan_delete(struct net_bridge_port *port, u16 vid);
  607. void nbp_vlan_flush(struct net_bridge_port *port);
  608. int nbp_vlan_init(struct net_bridge_port *port);
  609. int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask);
  610. static inline struct net_bridge_vlan_group *br_vlan_group(
  611. const struct net_bridge *br)
  612. {
  613. return rtnl_dereference(br->vlgrp);
  614. }
  615. static inline struct net_bridge_vlan_group *nbp_vlan_group(
  616. const struct net_bridge_port *p)
  617. {
  618. return rtnl_dereference(p->vlgrp);
  619. }
  620. static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
  621. const struct net_bridge *br)
  622. {
  623. return rcu_dereference(br->vlgrp);
  624. }
  625. static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
  626. const struct net_bridge_port *p)
  627. {
  628. return rcu_dereference(p->vlgrp);
  629. }
  630. /* Since bridge now depends on 8021Q module, but the time bridge sees the
  631. * skb, the vlan tag will always be present if the frame was tagged.
  632. */
  633. static inline int br_vlan_get_tag(const struct sk_buff *skb, u16 *vid)
  634. {
  635. int err = 0;
  636. if (skb_vlan_tag_present(skb)) {
  637. *vid = skb_vlan_tag_get(skb) & VLAN_VID_MASK;
  638. } else {
  639. *vid = 0;
  640. err = -EINVAL;
  641. }
  642. return err;
  643. }
  644. static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
  645. {
  646. if (!vg)
  647. return 0;
  648. smp_rmb();
  649. return vg->pvid;
  650. }
  651. static inline int br_vlan_enabled(struct net_bridge *br)
  652. {
  653. return br->vlan_enabled;
  654. }
  655. #else
  656. static inline bool br_allowed_ingress(const struct net_bridge *br,
  657. struct net_bridge_vlan_group *vg,
  658. struct sk_buff *skb,
  659. u16 *vid)
  660. {
  661. return true;
  662. }
  663. static inline bool br_allowed_egress(struct net_bridge_vlan_group *vg,
  664. const struct sk_buff *skb)
  665. {
  666. return true;
  667. }
  668. static inline bool br_should_learn(struct net_bridge_port *p,
  669. struct sk_buff *skb, u16 *vid)
  670. {
  671. return true;
  672. }
  673. static inline struct sk_buff *br_handle_vlan(struct net_bridge *br,
  674. struct net_bridge_vlan_group *vg,
  675. struct sk_buff *skb)
  676. {
  677. return skb;
  678. }
  679. static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags)
  680. {
  681. return -EOPNOTSUPP;
  682. }
  683. static inline int br_vlan_delete(struct net_bridge *br, u16 vid)
  684. {
  685. return -EOPNOTSUPP;
  686. }
  687. static inline void br_vlan_flush(struct net_bridge *br)
  688. {
  689. }
  690. static inline void br_recalculate_fwd_mask(struct net_bridge *br)
  691. {
  692. }
  693. static inline int br_vlan_init(struct net_bridge *br)
  694. {
  695. return 0;
  696. }
  697. static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags)
  698. {
  699. return -EOPNOTSUPP;
  700. }
  701. static inline int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
  702. {
  703. return -EOPNOTSUPP;
  704. }
  705. static inline void nbp_vlan_flush(struct net_bridge_port *port)
  706. {
  707. }
  708. static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg,
  709. u16 vid)
  710. {
  711. return NULL;
  712. }
  713. static inline int nbp_vlan_init(struct net_bridge_port *port)
  714. {
  715. return 0;
  716. }
  717. static inline u16 br_vlan_get_tag(const struct sk_buff *skb, u16 *tag)
  718. {
  719. return 0;
  720. }
  721. static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg)
  722. {
  723. return 0;
  724. }
  725. static inline int br_vlan_enabled(struct net_bridge *br)
  726. {
  727. return 0;
  728. }
  729. static inline int __br_vlan_filter_toggle(struct net_bridge *br,
  730. unsigned long val)
  731. {
  732. return -EOPNOTSUPP;
  733. }
  734. static inline int nbp_get_num_vlan_infos(struct net_bridge_port *p,
  735. u32 filter_mask)
  736. {
  737. return 0;
  738. }
  739. static inline struct net_bridge_vlan_group *br_vlan_group(
  740. const struct net_bridge *br)
  741. {
  742. return NULL;
  743. }
  744. static inline struct net_bridge_vlan_group *nbp_vlan_group(
  745. const struct net_bridge_port *p)
  746. {
  747. return NULL;
  748. }
  749. static inline struct net_bridge_vlan_group *br_vlan_group_rcu(
  750. const struct net_bridge *br)
  751. {
  752. return NULL;
  753. }
  754. static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu(
  755. const struct net_bridge_port *p)
  756. {
  757. return NULL;
  758. }
  759. #endif
  760. struct nf_br_ops {
  761. int (*br_dev_xmit_hook)(struct sk_buff *skb);
  762. };
  763. extern const struct nf_br_ops __rcu *nf_br_ops;
  764. /* br_netfilter.c */
  765. #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
  766. int br_nf_core_init(void);
  767. void br_nf_core_fini(void);
  768. void br_netfilter_rtable_init(struct net_bridge *);
  769. #else
  770. static inline int br_nf_core_init(void) { return 0; }
  771. static inline void br_nf_core_fini(void) {}
  772. #define br_netfilter_rtable_init(x)
  773. #endif
  774. /* br_stp.c */
  775. void br_set_state(struct net_bridge_port *p, unsigned int state);
  776. struct net_bridge_port *br_get_port(struct net_bridge *br, u16 port_no);
  777. void br_init_port(struct net_bridge_port *p);
  778. void br_become_designated_port(struct net_bridge_port *p);
  779. void __br_set_forward_delay(struct net_bridge *br, unsigned long t);
  780. int br_set_forward_delay(struct net_bridge *br, unsigned long x);
  781. int br_set_hello_time(struct net_bridge *br, unsigned long x);
  782. int br_set_max_age(struct net_bridge *br, unsigned long x);
  783. int br_set_ageing_time(struct net_bridge *br, u32 ageing_time);
  784. /* br_stp_if.c */
  785. void br_stp_enable_bridge(struct net_bridge *br);
  786. void br_stp_disable_bridge(struct net_bridge *br);
  787. void br_stp_set_enabled(struct net_bridge *br, unsigned long val);
  788. void br_stp_enable_port(struct net_bridge_port *p);
  789. void br_stp_disable_port(struct net_bridge_port *p);
  790. bool br_stp_recalculate_bridge_id(struct net_bridge *br);
  791. void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *a);
  792. void br_stp_set_bridge_priority(struct net_bridge *br, u16 newprio);
  793. int br_stp_set_port_priority(struct net_bridge_port *p, unsigned long newprio);
  794. int br_stp_set_path_cost(struct net_bridge_port *p, unsigned long path_cost);
  795. ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id);
  796. /* br_stp_bpdu.c */
  797. struct stp_proto;
  798. void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
  799. struct net_device *dev);
  800. /* br_stp_timer.c */
  801. void br_stp_timer_init(struct net_bridge *br);
  802. void br_stp_port_timer_init(struct net_bridge_port *p);
  803. unsigned long br_timer_value(const struct timer_list *timer);
  804. /* br.c */
  805. #if IS_ENABLED(CONFIG_ATM_LANE)
  806. extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr);
  807. #endif
  808. /* br_netlink.c */
  809. extern struct rtnl_link_ops br_link_ops;
  810. int br_netlink_init(void);
  811. void br_netlink_fini(void);
  812. void br_ifinfo_notify(int event, struct net_bridge_port *port);
  813. int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags);
  814. int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags);
  815. int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev,
  816. u32 filter_mask, int nlflags);
  817. #ifdef CONFIG_SYSFS
  818. /* br_sysfs_if.c */
  819. extern const struct sysfs_ops brport_sysfs_ops;
  820. int br_sysfs_addif(struct net_bridge_port *p);
  821. int br_sysfs_renameif(struct net_bridge_port *p);
  822. /* br_sysfs_br.c */
  823. int br_sysfs_addbr(struct net_device *dev);
  824. void br_sysfs_delbr(struct net_device *dev);
  825. #else
  826. static inline int br_sysfs_addif(struct net_bridge_port *p) { return 0; }
  827. static inline int br_sysfs_renameif(struct net_bridge_port *p) { return 0; }
  828. static inline int br_sysfs_addbr(struct net_device *dev) { return 0; }
  829. static inline void br_sysfs_delbr(struct net_device *dev) { return; }
  830. #endif /* CONFIG_SYSFS */
  831. #endif