Linux-net-bridge网桥-br.c

2021/9/21 7:30:17

本文主要是介绍Linux-net-bridge网桥-br.c,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

/net/bridge/br.c

一、介绍

br.c是Linux网桥实现的核心文件,定义了最基本的网桥操作,包括初始化、反初始化、修改属性等。

二、重要结构体

(一)net_bridge

定义了网桥所需要的数据,一个net_bridge变量就代表了一个网桥。

struct net_bridge {
	spinlock_t			lock;
	spinlock_t			hash_lock;
	struct hlist_head		frame_type_list;
	struct net_device		*dev;
	unsigned long			options;
	/* These fields are accessed on each packet */
#ifdef CONFIG_BRIDGE_VLAN_FILTERING
	__be16				vlan_proto;
	u16				default_pvid;
	struct net_bridge_vlan_group	__rcu *vlgrp;
#endif

	struct rhashtable		fdb_hash_tbl;       /* FDB表哈希 */
	struct list_head		port_list;          /* 网桥端口列表 */
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
	union {
		struct rtable		fake_rtable;
		struct rt6_info		fake_rt6_info;
	};
#endif
	u16				group_fwd_mask;
	u16				group_fwd_mask_required;

	/* STP */
	bridge_id			designated_root;
	bridge_id			bridge_id;
	unsigned char			topology_change;
	unsigned char			topology_change_detected;
	u16				root_port;
	unsigned long			max_age;
	unsigned long			hello_time;
	unsigned long			forward_delay;
	unsigned long			ageing_time;
	unsigned long			bridge_max_age;
	unsigned long			bridge_hello_time;
	unsigned long			bridge_forward_delay;
	unsigned long			bridge_ageing_time;
	u32				root_path_cost;

	u8				group_addr[ETH_ALEN];

	enum {
		BR_NO_STP, 		/* no spanning tree */
		BR_KERNEL_STP,		/* old STP in kernel */
		BR_USER_STP,		/* new RSTP in userspace */
	} stp_enabled;

#ifdef CONFIG_BRIDGE_IGMP_SNOOPING

	u32				hash_max;

	u32				multicast_last_member_count;
	u32				multicast_startup_query_count;

	u8				multicast_igmp_version;
	u8				multicast_router;
#if IS_ENABLED(CONFIG_IPV6)
	u8				multicast_mld_version;
#endif
	spinlock_t			multicast_lock;
	unsigned long			multicast_last_member_interval;
	unsigned long			multicast_membership_interval;
	unsigned long			multicast_querier_interval;
	unsigned long			multicast_query_interval;
	unsigned long			multicast_query_response_interval;
	unsigned long			multicast_startup_query_interval;

	struct rhashtable		mdb_hash_tbl;
	struct rhashtable		sg_port_tbl;

	struct hlist_head		mcast_gc_list;
	struct hlist_head		mdb_list;

	struct hlist_head		ip4_mc_router_list;
	struct timer_list		ip4_mc_router_timer;
	struct bridge_mcast_other_query	ip4_other_query;
	struct bridge_mcast_own_query	ip4_own_query;
	struct bridge_mcast_querier	ip4_querier;
	struct bridge_mcast_stats	__percpu *mcast_stats;
#if IS_ENABLED(CONFIG_IPV6)
	struct hlist_head		ip6_mc_router_list;
	struct timer_list		ip6_mc_router_timer;
	struct bridge_mcast_other_query	ip6_other_query;
	struct bridge_mcast_own_query	ip6_own_query;
	struct bridge_mcast_querier	ip6_querier;
#endif /* IS_ENABLED(CONFIG_IPV6) */
	struct work_struct		mcast_gc_work;
#endif

	struct timer_list		hello_timer;
	struct timer_list		tcn_timer;
	struct timer_list		topology_change_timer;
	struct delayed_work		gc_work;
	struct kobject			*ifobj;
	u32				auto_cnt;

#ifdef CONFIG_NET_SWITCHDEV
	int offload_fwd_mark;
#endif
	struct hlist_head		fdb_list;

#if IS_ENABLED(CONFIG_BRIDGE_MRP)
	struct hlist_head		mrp_list;
#endif
#if IS_ENABLED(CONFIG_BRIDGE_CFM)
	struct hlist_head		mep_list;
#endif
};

三、函数

  1. br_device_event:响应端口属性变化事件,包括NETDEV_CHANGEMTUNETDEV_PRE_CHANGEADDR等,调用对应函数对更改进行落实。
    static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr)
  2. br_switchdev_event:响应网桥变化事件,包括新增端口,删除端口等。
    static int br_switchdev_event(struct notifier_block *unused, unsigned long event, void *ptr)
  3. br_boolopt_toggle:修改网桥属性中布尔类型的值,目前只支持BR_BOOLOPT_NO_LL_LEARN选项。
    int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on, struct netlink_ext_ack *extack)
  4. br_boolopt_get:获取网桥属性中布尔类型的值,目前只支持BR_BOOLOPT_NO_LL_LEARN选项。
    int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt)
  5. br_boolopt_multi_toggle:调用br_boolopt_toggle进行设置多个位。
    int br_boolopt_multi_toggle(struct net_bridge *br, struct br_boolopt_multi *bm, struct netlink_ext_ack *extack)
  6. br_boolopt_multi_get:调用br_boolopt_get,获取多个位的设置。
    void br_boolopt_multi_get(const struct net_bridge *br, struct br_boolopt_multi *bm)
  7. br_opt_toggle:对网桥属性某一位进行设置。
    void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on)
  8. br_net_exit:调用br_dev_deleteunregister_netdevice_many,销毁某一网络下的网桥。
    static void __net_exit br_net_exit(struct net *net)
  9. br_init:初始化网桥。
    static int __init br_init(void)
  10. br_deinit:网桥反初始化。
    static void __exit br_deinit(void)


这篇关于Linux-net-bridge网桥-br.c的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程