Linux-net-bridge网桥-br_arp_nd_proxy.c

2021/9/21 7:28:52

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

/net/bridge/br_arp_nd_proxy.c

一、介绍

br_arp_nd_proxy.c包括网桥上的ARP协议与IP6的邻居发现协议相关操作。

二、重要结构体

(一)net_bridge

br.c解析

(二)net_bridge_port

网桥端口数据结构,代表某一个端口。

struct net_bridge_port {
	struct net_bridge		*br;
	struct net_device		*dev;
	struct list_head		list;

	unsigned long			flags;
#ifdef CONFIG_BRIDGE_VLAN_FILTERING
	struct net_bridge_vlan_group	__rcu *vlgrp;
#endif
	struct net_bridge_port		__rcu *backup_port;

	/* STP */
	u8				priority;
	u8				state;
	u16				port_no;
	unsigned char			topology_change_ack;
	unsigned char			config_pending;
	port_id				port_id;
	port_id				designated_port;
	bridge_id			designated_root;
	bridge_id			designated_bridge;
	u32				path_cost;
	u32				designated_cost;
	unsigned long			designated_age;

	struct timer_list		forward_delay_timer;
	struct timer_list		hold_timer;
	struct timer_list		message_age_timer;
	struct kobject			kobj;
	struct rcu_head			rcu;

#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
	struct bridge_mcast_own_query	ip4_own_query;
	struct timer_list		ip4_mc_router_timer;
	struct hlist_node		ip4_rlist;
#if IS_ENABLED(CONFIG_IPV6)
	struct bridge_mcast_own_query	ip6_own_query;
	struct timer_list		ip6_mc_router_timer;
	struct hlist_node		ip6_rlist;
#endif /* IS_ENABLED(CONFIG_IPV6) */
	u32				multicast_eht_hosts_limit;
	u32				multicast_eht_hosts_cnt;
	unsigned char			multicast_router;
	struct bridge_mcast_stats	__percpu *mcast_stats;
	struct hlist_head		mglist;
#endif

#ifdef CONFIG_SYSFS
	char				sysfs_name[IFNAMSIZ];
#endif

#ifdef CONFIG_NET_POLL_CONTROLLER
	struct netpoll			*np;
#endif
#ifdef CONFIG_NET_SWITCHDEV
	int				offload_fwd_mark;
#endif
	u16				group_fwd_mask;
	u16				backup_redirected_cnt;

	struct bridge_stp_xstats	stp_xstats;
};

(三)sk_buff

sk_buff的定义在/include/linux/skbuff.h里,内容发非常多。

简单的说,一个skb_buff变量就代表了一个数据报,可以在系统中流转。完整地包含了一个数据报所需的全部内容和相关信息与属性。

三、函数

  1. br_recalculate_neigh_suppress_enabled:设置是否允许进行流控。
    void br_recalculate_neigh_suppress_enabled(struct net_bridge *br)

  2. br_arp_send:通过src_ipdest_ip数据发送ARP报文。

static void br_arp_send(struct net_bridge *br, struct net_bridge_port *p,
			struct net_device *dev, __be32 dest_ip, __be32 src_ip,
			const unsigned char *dest_hw,
			const unsigned char *src_hw,
			const unsigned char *target_hw,
			__be16 vlan_proto, u16 vlan_tci)
  1. br_chk_addr_ip:判断指定设备于IP是否相符。
    static int br_chk_addr_ip(struct net_device *dev, struct netdev_nested_priv *priv)

  2. br_is_local_ip:检查IP是否是该设备或上层设备的IP。
    static bool br_is_local_ip(struct net_device *dev, __be32 ip)

  3. br_do_proxy_suppress_arp:向支持BR_NEIGH_SUPPRESSBR_PROXYARP_WIFI的端口发送ARP报文。

void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,
			      u16 vid, struct net_bridge_port *p)
  1. br_is_nd_neigh_msg:打开CONFIG_IPV6才有效。判断是否是IP6的邻居发现协议。
    struct nd_msg *br_is_nd_neigh_msg(struct sk_buff *skb, struct nd_msg *msg)

  2. br_nd_send:发送IP6的邻居发现协议报文。

static void br_nd_send(struct net_bridge *br, struct net_bridge_port *p,
		       struct sk_buff *request, struct neighbour *n,
		       __be16 vlan_proto, u16 vlan_tci, struct nd_msg *ns)
  1. br_chk_addr_ip6:检查设备与IP6的地址是否相符。
    static int br_chk_addr_ip6(struct net_device *dev, struct netdev_nested_priv *priv)

  2. br_is_local_ip6:检查IP6地址是否是本设备地址或上层设备地址。
    static bool br_is_local_ip6(struct net_device *dev, struct in6_addr *addr)

  3. br_do_suppress_nd:发送IP6的流控帧。

void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,
		       u16 vid, struct net_bridge_port *p, struct nd_msg *msg)


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


扫一扫关注最新编程教程