Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #ifndef _NET_NEIGHBOUR_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #define _NET_NEIGHBOUR_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/neighbour.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *	Generic neighbour manipulation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *	Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *	Pedro Roque		<roque@di.fc.ul.pt>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *	Alexey Kuznetsov	<kuznet@ms2.inr.ac.ru>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * 	Changes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *	Harald Welte:		<laforge@gnumonks.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *		- Add neighbour cache statistics like rtstat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/refcount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/bitmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/sysctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/android_kabi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <net/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * NUD stands for "neighbor unreachability detection"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define NUD_IN_TIMER	(NUD_INCOMPLETE|NUD_REACHABLE|NUD_DELAY|NUD_PROBE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define NUD_VALID	(NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE|NUD_PROBE|NUD_STALE|NUD_DELAY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define NUD_CONNECTED	(NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) struct neighbour;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	NEIGH_VAR_MCAST_PROBES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	NEIGH_VAR_UCAST_PROBES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	NEIGH_VAR_APP_PROBES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	NEIGH_VAR_MCAST_REPROBES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	NEIGH_VAR_RETRANS_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	NEIGH_VAR_BASE_REACHABLE_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	NEIGH_VAR_DELAY_PROBE_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	NEIGH_VAR_GC_STALETIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	NEIGH_VAR_QUEUE_LEN_BYTES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	NEIGH_VAR_PROXY_QLEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	NEIGH_VAR_ANYCAST_DELAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	NEIGH_VAR_PROXY_DELAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	NEIGH_VAR_LOCKTIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define NEIGH_VAR_DATA_MAX (NEIGH_VAR_LOCKTIME + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	/* Following are used as a second way to access one of the above */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	NEIGH_VAR_QUEUE_LEN, /* same data as NEIGH_VAR_QUEUE_LEN_BYTES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	NEIGH_VAR_RETRANS_TIME_MS, /* same data as NEIGH_VAR_RETRANS_TIME */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	NEIGH_VAR_BASE_REACHABLE_TIME_MS, /* same data as NEIGH_VAR_BASE_REACHABLE_TIME */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	/* Following are used by "default" only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	NEIGH_VAR_GC_INTERVAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	NEIGH_VAR_GC_THRESH1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	NEIGH_VAR_GC_THRESH2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	NEIGH_VAR_GC_THRESH3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	NEIGH_VAR_MAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) struct neigh_parms {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	possible_net_t net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	int	(*neigh_setup)(struct neighbour *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct neigh_table *tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	void	*sysctl_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	int dead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	refcount_t refcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct rcu_head rcu_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	int	reachable_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	int	data[NEIGH_VAR_DATA_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	DECLARE_BITMAP(data_state, NEIGH_VAR_DATA_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	ANDROID_KABI_RESERVE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static inline void neigh_var_set(struct neigh_parms *p, int index, int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	set_bit(index, p->data_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	p->data[index] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) #define NEIGH_VAR(p, attr) ((p)->data[NEIGH_VAR_ ## attr])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) /* In ndo_neigh_setup, NEIGH_VAR_INIT should be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * In other cases, NEIGH_VAR_SET should be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define NEIGH_VAR_INIT(p, attr, val) (NEIGH_VAR(p, attr) = val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define NEIGH_VAR_SET(p, attr, val) neigh_var_set(p, NEIGH_VAR_ ## attr, val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static inline void neigh_parms_data_state_setall(struct neigh_parms *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	bitmap_fill(p->data_state, NEIGH_VAR_DATA_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static inline void neigh_parms_data_state_cleanall(struct neigh_parms *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	bitmap_zero(p->data_state, NEIGH_VAR_DATA_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct neigh_statistics {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	unsigned long allocs;		/* number of allocated neighs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	unsigned long destroys;		/* number of destroyed neighs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	unsigned long hash_grows;	/* number of hash resizes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	unsigned long res_failed;	/* number of failed resolutions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	unsigned long lookups;		/* number of lookups */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	unsigned long hits;		/* number of hits (among lookups) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	unsigned long rcv_probes_mcast;	/* number of received mcast ipv6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	unsigned long rcv_probes_ucast; /* number of received ucast ipv6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	unsigned long periodic_gc_runs;	/* number of periodic GC runs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	unsigned long forced_gc_runs;	/* number of forced GC runs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	unsigned long unres_discards;	/* number of unresolved drops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	unsigned long table_fulls;      /* times even gc couldn't help */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #define NEIGH_CACHE_STAT_INC(tbl, field) this_cpu_inc((tbl)->stats->field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct neighbour {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	struct neighbour __rcu	*next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	struct neigh_table	*tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct neigh_parms	*parms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	unsigned long		confirmed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	unsigned long		updated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	rwlock_t		lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	refcount_t		refcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	unsigned int		arp_queue_len_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct sk_buff_head	arp_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	struct timer_list	timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	unsigned long		used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	atomic_t		probes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	__u8			flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	__u8			nud_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	__u8			type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	__u8			dead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	u8			protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	seqlock_t		ha_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	unsigned char		ha[ALIGN(MAX_ADDR_LEN, sizeof(unsigned long))] __aligned(8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	struct hh_cache		hh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	int			(*output)(struct neighbour *, struct sk_buff *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	const struct neigh_ops	*ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct list_head	gc_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct rcu_head		rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct net_device	*dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	ANDROID_KABI_RESERVE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	u8			primary_key[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) } __randomize_layout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct neigh_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	int			family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	void			(*solicit)(struct neighbour *, struct sk_buff *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	void			(*error_report)(struct neighbour *, struct sk_buff *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	int			(*output)(struct neighbour *, struct sk_buff *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	int			(*connected_output)(struct neighbour *, struct sk_buff *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct pneigh_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	struct pneigh_entry	*next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	possible_net_t		net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct net_device	*dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	u8			flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	u8			protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	u8			key[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  *	neighbour table manipulation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) #define NEIGH_NUM_HASH_RND	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct neigh_hash_table {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	struct neighbour __rcu	**hash_buckets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	unsigned int		hash_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	__u32			hash_rnd[NEIGH_NUM_HASH_RND];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	struct rcu_head		rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct neigh_table {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	int			family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	unsigned int		entry_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	unsigned int		key_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	__be16			protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	__u32			(*hash)(const void *pkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 					const struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 					__u32 *hash_rnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	bool			(*key_eq)(const struct neighbour *, const void *pkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	int			(*constructor)(struct neighbour *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	int			(*pconstructor)(struct pneigh_entry *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	void			(*pdestructor)(struct pneigh_entry *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	void			(*proxy_redo)(struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	int			(*is_multicast)(const void *pkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	bool			(*allow_add)(const struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 					     struct netlink_ext_ack *extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	char			*id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct neigh_parms	parms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct list_head	parms_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	int			gc_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	int			gc_thresh1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	int			gc_thresh2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	int			gc_thresh3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	unsigned long		last_flush;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	struct delayed_work	gc_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct timer_list 	proxy_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	struct sk_buff_head	proxy_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	atomic_t		entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	atomic_t		gc_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	struct list_head	gc_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	rwlock_t		lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	unsigned long		last_rand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	struct neigh_statistics	__percpu *stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct neigh_hash_table __rcu *nht;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	struct pneigh_entry	**phash_buckets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	ANDROID_KABI_RESERVE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	NEIGH_ARP_TABLE = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	NEIGH_ND_TABLE = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	NEIGH_DN_TABLE = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	NEIGH_NR_TABLES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	NEIGH_LINK_TABLE = NEIGH_NR_TABLES /* Pseudo table for neigh_xmit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static inline int neigh_parms_family(struct neigh_parms *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	return p->tbl->family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) #define NEIGH_PRIV_ALIGN	sizeof(long long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) #define NEIGH_ENTRY_SIZE(size)	ALIGN((size), NEIGH_PRIV_ALIGN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static inline void *neighbour_priv(const struct neighbour *n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	return (char *)n + n->tbl->entry_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /* flags for neigh_update() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) #define NEIGH_UPDATE_F_OVERRIDE			0x00000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) #define NEIGH_UPDATE_F_WEAK_OVERRIDE		0x00000002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) #define NEIGH_UPDATE_F_OVERRIDE_ISROUTER	0x00000004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #define NEIGH_UPDATE_F_USE			0x10000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #define NEIGH_UPDATE_F_EXT_LEARNED		0x20000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) #define NEIGH_UPDATE_F_ISROUTER			0x40000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) #define NEIGH_UPDATE_F_ADMIN			0x80000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) extern const struct nla_policy nda_policy[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static inline bool neigh_key_eq16(const struct neighbour *n, const void *pkey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	return *(const u16 *)n->primary_key == *(const u16 *)pkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static inline bool neigh_key_eq32(const struct neighbour *n, const void *pkey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	return *(const u32 *)n->primary_key == *(const u32 *)pkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static inline bool neigh_key_eq128(const struct neighbour *n, const void *pkey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	const u32 *n32 = (const u32 *)n->primary_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	const u32 *p32 = pkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	return ((n32[0] ^ p32[0]) | (n32[1] ^ p32[1]) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		(n32[2] ^ p32[2]) | (n32[3] ^ p32[3])) == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static inline struct neighbour *___neigh_lookup_noref(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	struct neigh_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	bool (*key_eq)(const struct neighbour *n, const void *pkey),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	__u32 (*hash)(const void *pkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		      const struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		      __u32 *hash_rnd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	const void *pkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	struct neigh_hash_table *nht = rcu_dereference_bh(tbl->nht);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	struct neighbour *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	u32 hash_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	hash_val = hash(pkey, dev, nht->hash_rnd) >> (32 - nht->hash_shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	for (n = rcu_dereference_bh(nht->hash_buckets[hash_val]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	     n != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	     n = rcu_dereference_bh(n->next)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		if (n->dev == dev && key_eq(n, pkey))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static inline struct neighbour *__neigh_lookup_noref(struct neigh_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 						     const void *pkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 						     struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	return ___neigh_lookup_noref(tbl, tbl->key_eq, tbl->hash, pkey, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) void neigh_table_init(int index, struct neigh_table *tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) int neigh_table_clear(int index, struct neigh_table *tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) struct neighbour *neigh_lookup(struct neigh_table *tbl, const void *pkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			       struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) struct neighbour *neigh_lookup_nodev(struct neigh_table *tbl, struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 				     const void *pkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) struct neighbour *__neigh_create(struct neigh_table *tbl, const void *pkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 				 struct net_device *dev, bool want_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static inline struct neighbour *neigh_create(struct neigh_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 					     const void *pkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 					     struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	return __neigh_create(tbl, pkey, dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) void neigh_destroy(struct neighbour *neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new, u32 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		 u32 nlmsg_pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) void __neigh_set_probe_once(struct neighbour *neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) bool neigh_remove_one(struct neighbour *ndel, struct neigh_table *tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) void neigh_changeaddr(struct neigh_table *tbl, struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) int neigh_carrier_down(struct neigh_table *tbl, struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) int neigh_connected_output(struct neighbour *neigh, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) int neigh_direct_output(struct neighbour *neigh, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct neighbour *neigh_event_ns(struct neigh_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 						u8 *lladdr, void *saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 						struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct neigh_parms *neigh_parms_alloc(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 				      struct neigh_table *tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) struct net *neigh_parms_net(const struct neigh_parms *parms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	return read_pnet(&parms->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) unsigned long neigh_rand_reach_time(unsigned long base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		    struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 				   const void *key, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 				   int creat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) struct pneigh_entry *__pneigh_lookup(struct neigh_table *tbl, struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 				     const void *key, struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		  struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) static inline struct net *pneigh_net(const struct pneigh_entry *pneigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	return read_pnet(&pneigh->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) void neigh_app_ns(struct neighbour *n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) void neigh_for_each(struct neigh_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		    void (*cb)(struct neighbour *, void *), void *cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) void __neigh_for_each_release(struct neigh_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 			      int (*cb)(struct neighbour *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) int neigh_xmit(int fam, struct net_device *, const void *, struct sk_buff *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) void pneigh_for_each(struct neigh_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		     void (*cb)(struct pneigh_entry *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) struct neigh_seq_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	struct seq_net_private p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	struct neigh_table *tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	struct neigh_hash_table *nht;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	void *(*neigh_sub_iter)(struct neigh_seq_state *state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 				struct neighbour *n, loff_t *pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	unsigned int bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) #define NEIGH_SEQ_NEIGH_ONLY	0x00000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) #define NEIGH_SEQ_IS_PNEIGH	0x00000002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) #define NEIGH_SEQ_SKIP_NOARP	0x00000004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) void *neigh_seq_start(struct seq_file *, loff_t *, struct neigh_table *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		      unsigned int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) void *neigh_seq_next(struct seq_file *, void *, loff_t *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) void neigh_seq_stop(struct seq_file *, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) int neigh_proc_dointvec(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			void *buffer, size_t *lenp, loff_t *ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) int neigh_proc_dointvec_jiffies(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 				void *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 				size_t *lenp, loff_t *ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) int neigh_proc_dointvec_ms_jiffies(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 				   void *buffer, size_t *lenp, loff_t *ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 			  proc_handler *proc_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) void neigh_sysctl_unregister(struct neigh_parms *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static inline void __neigh_parms_put(struct neigh_parms *parms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	refcount_dec(&parms->refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) static inline struct neigh_parms *neigh_parms_clone(struct neigh_parms *parms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	refcount_inc(&parms->refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	return parms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)  *	Neighbour references
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) static inline void neigh_release(struct neighbour *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	if (refcount_dec_and_test(&neigh->refcnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		neigh_destroy(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static inline struct neighbour * neigh_clone(struct neighbour *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	if (neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		refcount_inc(&neigh->refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	return neigh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) #define neigh_hold(n)	refcount_inc(&(n)->refcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) static inline int neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	unsigned long now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	if (READ_ONCE(neigh->used) != now)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		WRITE_ONCE(neigh->used, now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	if (!(neigh->nud_state&(NUD_CONNECTED|NUD_DELAY|NUD_PROBE)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		return __neigh_event_send(neigh, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static inline int neigh_hh_bridge(struct hh_cache *hh, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	unsigned int seq, hh_alen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		seq = read_seqbegin(&hh->hh_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		hh_alen = HH_DATA_ALIGN(ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		memcpy(skb->data - hh_alen, hh->hh_data, ETH_ALEN + hh_alen - ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	} while (read_seqretry(&hh->hh_lock, seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) static inline int neigh_hh_output(const struct hh_cache *hh, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	unsigned int hh_alen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	unsigned int seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	unsigned int hh_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		seq = read_seqbegin(&hh->hh_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		hh_len = READ_ONCE(hh->hh_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		if (likely(hh_len <= HH_DATA_MOD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 			hh_alen = HH_DATA_MOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 			/* skb_push() would proceed silently if we have room for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 			 * the unaligned size but not for the aligned size:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 			 * check headroom explicitly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 			if (likely(skb_headroom(skb) >= HH_DATA_MOD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 				/* this is inlined by gcc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 				memcpy(skb->data - HH_DATA_MOD, hh->hh_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 				       HH_DATA_MOD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 			hh_alen = HH_DATA_ALIGN(hh_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 			if (likely(skb_headroom(skb) >= hh_alen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 				memcpy(skb->data - hh_alen, hh->hh_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 				       hh_alen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	} while (read_seqretry(&hh->hh_lock, seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	if (WARN_ON_ONCE(skb_headroom(skb) < hh_alen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		return NET_XMIT_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	__skb_push(skb, hh_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	return dev_queue_xmit(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) static inline int neigh_output(struct neighbour *n, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 			       bool skip_cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	const struct hh_cache *hh = &n->hh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	/* n->nud_state and hh->hh_len could be changed under us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	 * neigh_hh_output() is taking care of the race later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	if (!skip_cache &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	    (READ_ONCE(n->nud_state) & NUD_CONNECTED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	    READ_ONCE(hh->hh_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		return neigh_hh_output(hh, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	return n->output(n, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) static inline struct neighbour *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) __neigh_lookup(struct neigh_table *tbl, const void *pkey, struct net_device *dev, int creat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	struct neighbour *n = neigh_lookup(tbl, pkey, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	if (n || !creat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	n = neigh_create(tbl, pkey, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	return IS_ERR(n) ? NULL : n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) static inline struct neighbour *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) __neigh_lookup_errno(struct neigh_table *tbl, const void *pkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)   struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	struct neighbour *n = neigh_lookup(tbl, pkey, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	if (n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	return neigh_create(tbl, pkey, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) struct neighbour_cb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	unsigned long sched_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) #define LOCALLY_ENQUEUED 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) #define NEIGH_CB(skb)	((struct neighbour_cb *)(skb)->cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) static inline void neigh_ha_snapshot(char *dst, const struct neighbour *n,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 				     const struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	unsigned int seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		seq = read_seqbegin(&n->ha_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 		memcpy(dst, n->ha, dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	} while (read_seqretry(&n->ha_lock, seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) static inline void neigh_update_is_router(struct neighbour *neigh, u32 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 					  int *notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	u8 ndm_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	ndm_flags |= (flags & NEIGH_UPDATE_F_ISROUTER) ? NTF_ROUTER : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	if ((neigh->flags ^ ndm_flags) & NTF_ROUTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		if (ndm_flags & NTF_ROUTER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 			neigh->flags |= NTF_ROUTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 			neigh->flags &= ~NTF_ROUTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		*notify = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) #endif