br_private.h 29 KB

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