Blame view

include/net/neighbour.h 15.8 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
  #ifndef _NET_NEIGHBOUR_H
  #define _NET_NEIGHBOUR_H
9067c722c   Thomas Graf   [NEIGH]: Move net...
4
  #include <linux/neighbour.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
6
7
8
9
10
11
12
13
14
15
16
  /*
   *	Generic neighbour manipulation
   *
   *	Authors:
   *	Pedro Roque		<roque@di.fc.ul.pt>
   *	Alexey Kuznetsov	<kuznet@ms2.inr.ac.ru>
   *
   * 	Changes:
   *
   *	Harald Welte:		<laforge@gnumonks.org>
   *		- Add neighbour cache statistics like rtstat
   */
60063497a   Arun Sharma   atomic: use <linu...
17
  #include <linux/atomic.h>
9f2374301   Reshetova, Elena   net: convert neig...
18
  #include <linux/refcount.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
  #include <linux/netdevice.h>
14c850212   Arnaldo Carvalho de Melo   [INET_SOCK]: Move...
20
  #include <linux/skbuff.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
22
  #include <linux/rcupdate.h>
  #include <linux/seq_file.h>
1d4c8c298   Jiri Pirko   neigh: restore ol...
23
  #include <linux/bitmap.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
25
26
  
  #include <linux/err.h>
  #include <linux/sysctl.h>
e4c4e448c   Eric Dumazet   neigh: Convert ga...
27
  #include <linux/workqueue.h>
c8822a4e0   Thomas Graf   [NEIGH]: Use rtnl...
28
  #include <net/rtnetlink.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29

39971554d   Pavel Emelyanov   [NEIGH]: Add a co...
30
31
32
  /*
   * NUD stands for "neighbor unreachability detection"
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
33
34
35
36
37
  #define NUD_IN_TIMER	(NUD_INCOMPLETE|NUD_REACHABLE|NUD_DELAY|NUD_PROBE)
  #define NUD_VALID	(NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE|NUD_PROBE|NUD_STALE|NUD_DELAY)
  #define NUD_CONNECTED	(NUD_PERMANENT|NUD_NOARP|NUD_REACHABLE)
  
  struct neighbour;
1f9248e56   Jiri Pirko   neigh: convert pa...
38
39
40
41
  enum {
  	NEIGH_VAR_MCAST_PROBES,
  	NEIGH_VAR_UCAST_PROBES,
  	NEIGH_VAR_APP_PROBES,
8da86466b   YOSHIFUJI Hideaki/吉藤英明   net: neighbour: A...
42
  	NEIGH_VAR_MCAST_REPROBES,
1f9248e56   Jiri Pirko   neigh: convert pa...
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  	NEIGH_VAR_RETRANS_TIME,
  	NEIGH_VAR_BASE_REACHABLE_TIME,
  	NEIGH_VAR_DELAY_PROBE_TIME,
  	NEIGH_VAR_GC_STALETIME,
  	NEIGH_VAR_QUEUE_LEN_BYTES,
  	NEIGH_VAR_PROXY_QLEN,
  	NEIGH_VAR_ANYCAST_DELAY,
  	NEIGH_VAR_PROXY_DELAY,
  	NEIGH_VAR_LOCKTIME,
  #define NEIGH_VAR_DATA_MAX (NEIGH_VAR_LOCKTIME + 1)
  	/* Following are used as a second way to access one of the above */
  	NEIGH_VAR_QUEUE_LEN, /* same data as NEIGH_VAR_QUEUE_LEN_BYTES */
  	NEIGH_VAR_RETRANS_TIME_MS, /* same data as NEIGH_VAR_RETRANS_TIME */
  	NEIGH_VAR_BASE_REACHABLE_TIME_MS, /* same data as NEIGH_VAR_BASE_REACHABLE_TIME */
  	/* Following are used by "default" only */
  	NEIGH_VAR_GC_INTERVAL,
  	NEIGH_VAR_GC_THRESH1,
  	NEIGH_VAR_GC_THRESH2,
  	NEIGH_VAR_GC_THRESH3,
  	NEIGH_VAR_MAX
  };
fd2c3ef76   Eric Dumazet   net: cleanup incl...
64
  struct neigh_parms {
0c5c9fb55   Eric W. Biederman   net: Introduce po...
65
  	possible_net_t net;
c7fb64db0   Thomas Graf   [NETLINK]: Neighb...
66
  	struct net_device *dev;
75fbfd332   Nicolas Dichtel   neigh: optimize n...
67
  	struct list_head list;
447f21919   David S. Miller   Revert "net: Remo...
68
  	int	(*neigh_setup)(struct neighbour *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69
  	struct neigh_table *tbl;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
70
71
72
73
  
  	void	*sysctl_table;
  
  	int dead;
6343944bc   Reshetova, Elena   net: convert neig...
74
  	refcount_t refcnt;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
75
  	struct rcu_head rcu_head;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
76
  	int	reachable_time;
1f9248e56   Jiri Pirko   neigh: convert pa...
77
  	int	data[NEIGH_VAR_DATA_MAX];
1d4c8c298   Jiri Pirko   neigh: restore ol...
78
  	DECLARE_BITMAP(data_state, NEIGH_VAR_DATA_MAX);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79
  };
1f9248e56   Jiri Pirko   neigh: convert pa...
80
81
  static inline void neigh_var_set(struct neigh_parms *p, int index, int val)
  {
1d4c8c298   Jiri Pirko   neigh: restore ol...
82
  	set_bit(index, p->data_state);
1f9248e56   Jiri Pirko   neigh: convert pa...
83
84
85
86
  	p->data[index] = val;
  }
  
  #define NEIGH_VAR(p, attr) ((p)->data[NEIGH_VAR_ ## attr])
89740ca74   Jiri Pirko   neigh: use NEIGH_...
87
88
89
90
91
  
  /* In ndo_neigh_setup, NEIGH_VAR_INIT should be used.
   * In other cases, NEIGH_VAR_SET should be used.
   */
  #define NEIGH_VAR_INIT(p, attr, val) (NEIGH_VAR(p, attr) = val)
1f9248e56   Jiri Pirko   neigh: convert pa...
92
  #define NEIGH_VAR_SET(p, attr, val) neigh_var_set(p, NEIGH_VAR_ ## attr, val)
1d4c8c298   Jiri Pirko   neigh: restore ol...
93
94
95
96
97
98
99
100
101
  static inline void neigh_parms_data_state_setall(struct neigh_parms *p)
  {
  	bitmap_fill(p->data_state, NEIGH_VAR_DATA_MAX);
  }
  
  static inline void neigh_parms_data_state_cleanall(struct neigh_parms *p)
  {
  	bitmap_zero(p->data_state, NEIGH_VAR_DATA_MAX);
  }
fd2c3ef76   Eric Dumazet   net: cleanup incl...
102
  struct neigh_statistics {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
104
105
  	unsigned long allocs;		/* number of allocated neighs */
  	unsigned long destroys;		/* number of destroyed neighs */
  	unsigned long hash_grows;	/* number of hash resizes */
9a6d276e8   Neil Horman   core: add stat to...
106
  	unsigned long res_failed;	/* number of failed resolutions */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
107
108
109
110
111
112
113
114
115
  
  	unsigned long lookups;		/* number of lookups */
  	unsigned long hits;		/* number of hits (among lookups) */
  
  	unsigned long rcv_probes_mcast;	/* number of received mcast ipv6 */
  	unsigned long rcv_probes_ucast; /* number of received ucast ipv6 */
  
  	unsigned long periodic_gc_runs;	/* number of periodic GC runs */
  	unsigned long forced_gc_runs;	/* number of forced GC runs */
9a6d276e8   Neil Horman   core: add stat to...
116
117
  
  	unsigned long unres_discards;	/* number of unresolved drops */
fb811395c   Rick Jones   net: add explicit...
118
  	unsigned long table_fulls;      /* times even gc couldn't help */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
119
  };
4ea7334b6   Christoph Lameter   this_cpu: Use thi...
120
  #define NEIGH_CACHE_STAT_INC(tbl, field) this_cpu_inc((tbl)->stats->field)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
121

fd2c3ef76   Eric Dumazet   net: cleanup incl...
122
  struct neighbour {
767e97e1e   Eric Dumazet   neigh: RCU conver...
123
  	struct neighbour __rcu	*next;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
124
125
  	struct neigh_table	*tbl;
  	struct neigh_parms	*parms;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
126
127
  	unsigned long		confirmed;
  	unsigned long		updated;
46b13fc5c   Eric Dumazet   neigh: reorder st...
128
  	rwlock_t		lock;
9f2374301   Reshetova, Elena   net: convert neig...
129
  	refcount_t		refcnt;
8b5c171bb   Eric Dumazet   neigh: new unreso...
130
  	unsigned int		arp_queue_len_bytes;
4b7cd11f2   David Ahern   neighbor: Improve...
131
  	struct sk_buff_head	arp_queue;
e37ef961e   Eric Dumazet   neigh: reorder st...
132
133
  	struct timer_list	timer;
  	unsigned long		used;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
134
  	atomic_t		probes;
46b13fc5c   Eric Dumazet   neigh: reorder st...
135
136
137
138
  	__u8			flags;
  	__u8			nud_state;
  	__u8			type;
  	__u8			dead;
df9b0e30d   David Ahern   neighbor: Add pro...
139
  	u8			protocol;
0ed8ddf40   Eric Dumazet   neigh: Protect ne...
140
  	seqlock_t		ha_lock;
4b7cd11f2   David Ahern   neighbor: Improve...
141
  	unsigned char		ha[ALIGN(MAX_ADDR_LEN, sizeof(unsigned long))] __aligned(8);
f6b72b621   David S. Miller   net: Embed hh_cac...
142
  	struct hh_cache		hh;
8f40b161d   David S. Miller   neigh: Pass neigh...
143
  	int			(*output)(struct neighbour *, struct sk_buff *);
89d69d2b7   Stephen Hemminger   net: make neigh_o...
144
  	const struct neigh_ops	*ops;
58956317c   David Ahern   neighbor: Improve...
145
  	struct list_head	gc_list;
767e97e1e   Eric Dumazet   neigh: RCU conver...
146
  	struct rcu_head		rcu;
e37ef961e   Eric Dumazet   neigh: reorder st...
147
  	struct net_device	*dev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
148
  	u8			primary_key[0];
3859a271a   Kees Cook   randstruct: Mark ...
149
  } __randomize_layout;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
150

fd2c3ef76   Eric Dumazet   net: cleanup incl...
151
  struct neigh_ops {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
152
  	int			family;
8f40b161d   David S. Miller   neigh: Pass neigh...
153
154
155
156
  	void			(*solicit)(struct neighbour *, struct sk_buff *);
  	void			(*error_report)(struct neighbour *, struct sk_buff *);
  	int			(*output)(struct neighbour *, struct sk_buff *);
  	int			(*connected_output)(struct neighbour *, struct sk_buff *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
157
  };
fd2c3ef76   Eric Dumazet   net: cleanup incl...
158
  struct pneigh_entry {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
159
  	struct pneigh_entry	*next;
0c5c9fb55   Eric W. Biederman   net: Introduce po...
160
  	possible_net_t		net;
426b5303e   Eric W. Biederman   [NETNS]: Modify t...
161
  	struct net_device	*dev;
62dd93181   Ville Nuorvala   [IPV6] NDISC: Set...
162
  	u8			flags;
df9b0e30d   David Ahern   neighbor: Add pro...
163
  	u8			protocol;
08ca27d02   Gustavo A. R. Silva   neighbour: Replac...
164
  	u8			key[];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
165
166
167
168
169
  };
  
  /*
   *	neighbour table manipulation
   */
2c2aba6c5   David S. Miller   ipv6: Use univers...
170
  #define NEIGH_NUM_HASH_RND	4
d6bf78171   Eric Dumazet   net neigh: RCU co...
171
  struct neigh_hash_table {
767e97e1e   Eric Dumazet   neigh: RCU conver...
172
  	struct neighbour __rcu	**hash_buckets;
cd0893369   David S. Miller   neigh: Store hash...
173
  	unsigned int		hash_shift;
2c2aba6c5   David S. Miller   ipv6: Use univers...
174
  	__u32			hash_rnd[NEIGH_NUM_HASH_RND];
d6bf78171   Eric Dumazet   net neigh: RCU co...
175
176
  	struct rcu_head		rcu;
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
177

fd2c3ef76   Eric Dumazet   net: cleanup incl...
178
  struct neigh_table {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
179
  	int			family;
e451ae8e4   Alexey Dobriyan   neigh: make struc...
180
  	unsigned int		entry_size;
01ccdf126   Alexey Dobriyan   neigh: make struc...
181
  	unsigned int		key_len;
bdf53c584   Eric W. Biederman   neigh: Don't requ...
182
  	__be16			protocol;
d6bf78171   Eric Dumazet   net neigh: RCU co...
183
184
  	__u32			(*hash)(const void *pkey,
  					const struct net_device *dev,
2c2aba6c5   David S. Miller   ipv6: Use univers...
185
  					__u32 *hash_rnd);
60395a20f   Eric W. Biederman   neigh: Factor out...
186
  	bool			(*key_eq)(const struct neighbour *, const void *pkey);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
187
188
189
190
  	int			(*constructor)(struct neighbour *);
  	int			(*pconstructor)(struct pneigh_entry *);
  	void			(*pdestructor)(struct pneigh_entry *);
  	void			(*proxy_redo)(struct sk_buff *skb);
8cf8821e1   Jeff Dike   net: Exempt multi...
191
  	int			(*is_multicast)(const void *pkey);
b8fb1ab46   David Ahern   net ipv6: Prevent...
192
193
  	bool			(*allow_add)(const struct net_device *dev,
  					     struct netlink_ext_ack *extack);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
194
195
  	char			*id;
  	struct neigh_parms	parms;
75fbfd332   Nicolas Dichtel   neigh: optimize n...
196
  	struct list_head	parms_list;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
197
198
199
200
201
  	int			gc_interval;
  	int			gc_thresh1;
  	int			gc_thresh2;
  	int			gc_thresh3;
  	unsigned long		last_flush;
e4c4e448c   Eric Dumazet   neigh: Convert ga...
202
  	struct delayed_work	gc_work;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
203
204
205
  	struct timer_list 	proxy_timer;
  	struct sk_buff_head	proxy_queue;
  	atomic_t		entries;
58956317c   David Ahern   neighbor: Improve...
206
207
  	atomic_t		gc_entries;
  	struct list_head	gc_list;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
208
209
  	rwlock_t		lock;
  	unsigned long		last_rand;
7d720c3e4   Tejun Heo   percpu: add __per...
210
  	struct neigh_statistics	__percpu *stats;
d6bf78171   Eric Dumazet   net neigh: RCU co...
211
  	struct neigh_hash_table __rcu *nht;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
212
  	struct pneigh_entry	**phash_buckets;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
213
  };
d7480fd3b   WANG Cong   neigh: remove dyn...
214
215
216
217
218
  enum {
  	NEIGH_ARP_TABLE = 0,
  	NEIGH_ND_TABLE = 1,
  	NEIGH_DN_TABLE = 2,
  	NEIGH_NR_TABLES,
b79bda3d3   Eric W. Biederman   neigh: Use neigh ...
219
  	NEIGH_LINK_TABLE = NEIGH_NR_TABLES /* Pseudo table for neigh_xmit */
d7480fd3b   WANG Cong   neigh: remove dyn...
220
  };
73af614ae   Jiri Pirko   neigh: use tbl->f...
221
222
223
224
  static inline int neigh_parms_family(struct neigh_parms *p)
  {
  	return p->tbl->family;
  }
1026fec87   David Miller   neigh: Create mec...
225
  #define NEIGH_PRIV_ALIGN	sizeof(long long)
daaba4fa1   YOSHIFUJI Hideaki / 吉藤英明   net neighbour, de...
226
  #define NEIGH_ENTRY_SIZE(size)	ALIGN((size), NEIGH_PRIV_ALIGN)
1026fec87   David Miller   neigh: Create mec...
227
228
229
  
  static inline void *neighbour_priv(const struct neighbour *n)
  {
08433eff2   YOSHIFUJI Hideaki / 吉藤英明   net neigh: Optimi...
230
  	return (char *)n + n->tbl->entry_size;
1026fec87   David Miller   neigh: Create mec...
231
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
232
233
234
235
  /* flags for neigh_update() */
  #define NEIGH_UPDATE_F_OVERRIDE			0x00000001
  #define NEIGH_UPDATE_F_WEAK_OVERRIDE		0x00000002
  #define NEIGH_UPDATE_F_OVERRIDE_ISROUTER	0x00000004
9ce33e465   Roopa Prabhu   neighbour: suppor...
236
  #define NEIGH_UPDATE_F_EXT_LEARNED		0x20000000
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
237
238
  #define NEIGH_UPDATE_F_ISROUTER			0x40000000
  #define NEIGH_UPDATE_F_ADMIN			0x80000000
82cbb5c63   Roopa Prabhu   neighbour: regist...
239
  extern const struct nla_policy nda_policy[];
60395a20f   Eric W. Biederman   neigh: Factor out...
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
  
  static inline bool neigh_key_eq16(const struct neighbour *n, const void *pkey)
  {
  	return *(const u16 *)n->primary_key == *(const u16 *)pkey;
  }
  
  static inline bool neigh_key_eq32(const struct neighbour *n, const void *pkey)
  {
  	return *(const u32 *)n->primary_key == *(const u32 *)pkey;
  }
  
  static inline bool neigh_key_eq128(const struct neighbour *n, const void *pkey)
  {
  	const u32 *n32 = (const u32 *)n->primary_key;
  	const u32 *p32 = pkey;
  
  	return ((n32[0] ^ p32[0]) | (n32[1] ^ p32[1]) |
  		(n32[2] ^ p32[2]) | (n32[3] ^ p32[3])) == 0;
  }
  
  static inline struct neighbour *___neigh_lookup_noref(
  	struct neigh_table *tbl,
  	bool (*key_eq)(const struct neighbour *n, const void *pkey),
  	__u32 (*hash)(const void *pkey,
  		      const struct net_device *dev,
  		      __u32 *hash_rnd),
  	const void *pkey,
  	struct net_device *dev)
  {
  	struct neigh_hash_table *nht = rcu_dereference_bh(tbl->nht);
  	struct neighbour *n;
  	u32 hash_val;
  
  	hash_val = hash(pkey, dev, nht->hash_rnd) >> (32 - nht->hash_shift);
  	for (n = rcu_dereference_bh(nht->hash_buckets[hash_val]);
  	     n != NULL;
  	     n = rcu_dereference_bh(n->next)) {
  		if (n->dev == dev && key_eq(n, pkey))
  			return n;
  	}
  
  	return NULL;
  }
  
  static inline struct neighbour *__neigh_lookup_noref(struct neigh_table *tbl,
  						     const void *pkey,
  						     struct net_device *dev)
  {
  	return ___neigh_lookup_noref(tbl, tbl->key_eq, tbl->hash, pkey, dev);
  }
d7480fd3b   WANG Cong   neigh: remove dyn...
290
291
  void neigh_table_init(int index, struct neigh_table *tbl);
  int neigh_table_clear(int index, struct neigh_table *tbl);
90972b221   Joe Perches   arp/neighbour.h: ...
292
293
294
295
296
297
  struct neighbour *neigh_lookup(struct neigh_table *tbl, const void *pkey,
  			       struct net_device *dev);
  struct neighbour *neigh_lookup_nodev(struct neigh_table *tbl, struct net *net,
  				     const void *pkey);
  struct neighbour *__neigh_create(struct neigh_table *tbl, const void *pkey,
  				 struct net_device *dev, bool want_ref);
a263b3093   David S. Miller   ipv4: Make neigh ...
298
  static inline struct neighbour *neigh_create(struct neigh_table *tbl,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
299
  					     const void *pkey,
a263b3093   David S. Miller   ipv4: Make neigh ...
300
301
302
303
  					     struct net_device *dev)
  {
  	return __neigh_create(tbl, pkey, dev, true);
  }
90972b221   Joe Perches   arp/neighbour.h: ...
304
305
  void neigh_destroy(struct neighbour *neigh);
  int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb);
7b8f7a402   Roopa Prabhu   neighbour: fix nl...
306
307
  int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new, u32 flags,
  		 u32 nlmsg_pid);
7e9805696   Jiri Benc   ipv6: router reac...
308
  void __neigh_set_probe_once(struct neighbour *neigh);
5071034e4   Sowmini Varadhan   neigh: Really del...
309
  bool neigh_remove_one(struct neighbour *ndel, struct neigh_table *tbl);
90972b221   Joe Perches   arp/neighbour.h: ...
310
311
  void neigh_changeaddr(struct neigh_table *tbl, struct net_device *dev);
  int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev);
859bd2ef1   David Ahern   net: Evict neighb...
312
  int neigh_carrier_down(struct neigh_table *tbl, struct net_device *dev);
90972b221   Joe Perches   arp/neighbour.h: ...
313
314
  int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb);
  int neigh_connected_output(struct neighbour *neigh, struct sk_buff *skb);
90972b221   Joe Perches   arp/neighbour.h: ...
315
316
  int neigh_direct_output(struct neighbour *neigh, struct sk_buff *skb);
  struct neighbour *neigh_event_ns(struct neigh_table *tbl,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
317
318
  						u8 *lladdr, void *saddr,
  						struct net_device *dev);
90972b221   Joe Perches   arp/neighbour.h: ...
319
320
321
  struct neigh_parms *neigh_parms_alloc(struct net_device *dev,
  				      struct neigh_table *tbl);
  void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms);
57da52c1e   YOSHIFUJI Hideaki   [NET] NETNS: Omit...
322
323
  
  static inline
90972b221   Joe Perches   arp/neighbour.h: ...
324
  struct net *neigh_parms_net(const struct neigh_parms *parms)
57da52c1e   YOSHIFUJI Hideaki   [NET] NETNS: Omit...
325
  {
e42ea986e   Eric Dumazet   net: Cleanup of n...
326
  	return read_pnet(&parms->net);
57da52c1e   YOSHIFUJI Hideaki   [NET] NETNS: Omit...
327
  }
90972b221   Joe Perches   arp/neighbour.h: ...
328
  unsigned long neigh_rand_reach_time(unsigned long base);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
329

90972b221   Joe Perches   arp/neighbour.h: ...
330
331
332
333
334
335
336
337
338
  void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
  		    struct sk_buff *skb);
  struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, struct net *net,
  				   const void *key, struct net_device *dev,
  				   int creat);
  struct pneigh_entry *__pneigh_lookup(struct neigh_table *tbl, struct net *net,
  				     const void *key, struct net_device *dev);
  int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *key,
  		  struct net_device *dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
339

90972b221   Joe Perches   arp/neighbour.h: ...
340
  static inline struct net *pneigh_net(const struct pneigh_entry *pneigh)
57da52c1e   YOSHIFUJI Hideaki   [NET] NETNS: Omit...
341
  {
e42ea986e   Eric Dumazet   net: Cleanup of n...
342
  	return read_pnet(&pneigh->net);
57da52c1e   YOSHIFUJI Hideaki   [NET] NETNS: Omit...
343
  }
90972b221   Joe Perches   arp/neighbour.h: ...
344
345
346
347
348
  void neigh_app_ns(struct neighbour *n);
  void neigh_for_each(struct neigh_table *tbl,
  		    void (*cb)(struct neighbour *, void *), void *cookie);
  void __neigh_for_each_release(struct neigh_table *tbl,
  			      int (*cb)(struct neighbour *));
4fd3d7d9e   Eric W. Biederman   neigh: Add helper...
349
  int neigh_xmit(int fam, struct net_device *, const void *, struct sk_buff *);
90972b221   Joe Perches   arp/neighbour.h: ...
350
351
  void pneigh_for_each(struct neigh_table *tbl,
  		     void (*cb)(struct pneigh_entry *));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
352
353
  
  struct neigh_seq_state {
425084614   Denis V. Lunev   [NEIGH]: Make /pr...
354
  	struct seq_net_private p;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
355
  	struct neigh_table *tbl;
d6bf78171   Eric Dumazet   net neigh: RCU co...
356
  	struct neigh_hash_table *nht;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
357
358
359
360
361
362
363
364
  	void *(*neigh_sub_iter)(struct neigh_seq_state *state,
  				struct neighbour *n, loff_t *pos);
  	unsigned int bucket;
  	unsigned int flags;
  #define NEIGH_SEQ_NEIGH_ONLY	0x00000001
  #define NEIGH_SEQ_IS_PNEIGH	0x00000002
  #define NEIGH_SEQ_SKIP_NOARP	0x00000004
  };
90972b221   Joe Perches   arp/neighbour.h: ...
365
366
367
368
  void *neigh_seq_start(struct seq_file *, loff_t *, struct neigh_table *,
  		      unsigned int);
  void *neigh_seq_next(struct seq_file *, void *, loff_t *);
  void neigh_seq_stop(struct seq_file *, void *);
cb5b09c17   Jiri Pirko   neigh: wrap proc ...
369
  int neigh_proc_dointvec(struct ctl_table *ctl, int write,
c7388c1f8   Christoph Hellwig   net/sysctl: remov...
370
  			void *buffer, size_t *lenp, loff_t *ppos);
cb5b09c17   Jiri Pirko   neigh: wrap proc ...
371
  int neigh_proc_dointvec_jiffies(struct ctl_table *ctl, int write,
c7388c1f8   Christoph Hellwig   net/sysctl: remov...
372
  				void *buffer,
cb5b09c17   Jiri Pirko   neigh: wrap proc ...
373
374
  				size_t *lenp, loff_t *ppos);
  int neigh_proc_dointvec_ms_jiffies(struct ctl_table *ctl, int write,
c7388c1f8   Christoph Hellwig   net/sysctl: remov...
375
  				   void *buffer, size_t *lenp, loff_t *ppos);
cb5b09c17   Jiri Pirko   neigh: wrap proc ...
376

90972b221   Joe Perches   arp/neighbour.h: ...
377
  int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
73af614ae   Jiri Pirko   neigh: use tbl->f...
378
  			  proc_handler *proc_handler);
90972b221   Joe Perches   arp/neighbour.h: ...
379
  void neigh_sysctl_unregister(struct neigh_parms *p);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
380
381
382
  
  static inline void __neigh_parms_put(struct neigh_parms *parms)
  {
6343944bc   Reshetova, Elena   net: convert neig...
383
  	refcount_dec(&parms->refcnt);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
384
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
385
386
  static inline struct neigh_parms *neigh_parms_clone(struct neigh_parms *parms)
  {
6343944bc   Reshetova, Elena   net: convert neig...
387
  	refcount_inc(&parms->refcnt);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
388
389
390
391
392
393
394
395
396
  	return parms;
  }
  
  /*
   *	Neighbour references
   */
  
  static inline void neigh_release(struct neighbour *neigh)
  {
9f2374301   Reshetova, Elena   net: convert neig...
397
  	if (refcount_dec_and_test(&neigh->refcnt))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
398
399
400
401
402
403
  		neigh_destroy(neigh);
  }
  
  static inline struct neighbour * neigh_clone(struct neighbour *neigh)
  {
  	if (neigh)
9f2374301   Reshetova, Elena   net: convert neig...
404
  		refcount_inc(&neigh->refcnt);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
405
406
  	return neigh;
  }
9f2374301   Reshetova, Elena   net: convert neig...
407
  #define neigh_hold(n)	refcount_inc(&(n)->refcnt)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
408

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
409
410
  static inline int neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
  {
ef22b7b65   Tetsuo Handa   net: Fix duplicat...
411
  	unsigned long now = jiffies;
0ed8ddf40   Eric Dumazet   neigh: Protect ne...
412
  	
1b53d6443   Eric Dumazet   net: fix data-rac...
413
414
  	if (READ_ONCE(neigh->used) != now)
  		WRITE_ONCE(neigh->used, now);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
415
416
417
418
  	if (!(neigh->nud_state&(NUD_CONNECTED|NUD_DELAY|NUD_PROBE)))
  		return __neigh_event_send(neigh, skb);
  	return 0;
  }
34666d467   Pablo Neira Ayuso   netfilter: bridge...
419
  #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
e179e6322   Bart De Schuymer   netfilter: bridge...
420
421
  static inline int neigh_hh_bridge(struct hh_cache *hh, struct sk_buff *skb)
  {
95c961747   Eric Dumazet   net: cleanup unsi...
422
  	unsigned int seq, hh_alen;
e179e6322   Bart De Schuymer   netfilter: bridge...
423
424
425
426
427
428
429
430
431
  
  	do {
  		seq = read_seqbegin(&hh->hh_lock);
  		hh_alen = HH_DATA_ALIGN(ETH_HLEN);
  		memcpy(skb->data - hh_alen, hh->hh_data, ETH_ALEN + hh_alen - ETH_HLEN);
  	} while (read_seqretry(&hh->hh_lock, seq));
  	return 0;
  }
  #endif
425f09ab7   Eric Dumazet   net: output path ...
432
  static inline int neigh_hh_output(const struct hh_cache *hh, struct sk_buff *skb)
3644f0cee   Stephen Hemminger   [NET]: Convert hh...
433
  {
e6ac64d4c   Stefano Brivio   neighbour: Avoid ...
434
  	unsigned int hh_alen = 0;
95c961747   Eric Dumazet   net: cleanup unsi...
435
  	unsigned int seq;
5b3dc2f37   Alexey Dobriyan   net: neigh: make ...
436
  	unsigned int hh_len;
3644f0cee   Stephen Hemminger   [NET]: Convert hh...
437
438
  
  	do {
3644f0cee   Stephen Hemminger   [NET]: Convert hh...
439
  		seq = read_seqbegin(&hh->hh_lock);
c305c6ae7   Eric Dumazet   net: add annotati...
440
  		hh_len = READ_ONCE(hh->hh_len);
425f09ab7   Eric Dumazet   net: output path ...
441
  		if (likely(hh_len <= HH_DATA_MOD)) {
e6ac64d4c   Stefano Brivio   neighbour: Avoid ...
442
443
444
445
446
447
448
449
450
451
452
  			hh_alen = HH_DATA_MOD;
  
  			/* skb_push() would proceed silently if we have room for
  			 * the unaligned size but not for the aligned size:
  			 * check headroom explicitly.
  			 */
  			if (likely(skb_headroom(skb) >= HH_DATA_MOD)) {
  				/* this is inlined by gcc */
  				memcpy(skb->data - HH_DATA_MOD, hh->hh_data,
  				       HH_DATA_MOD);
  			}
425f09ab7   Eric Dumazet   net: output path ...
453
  		} else {
e6ac64d4c   Stefano Brivio   neighbour: Avoid ...
454
  			hh_alen = HH_DATA_ALIGN(hh_len);
425f09ab7   Eric Dumazet   net: output path ...
455

e6ac64d4c   Stefano Brivio   neighbour: Avoid ...
456
457
458
459
  			if (likely(skb_headroom(skb) >= hh_alen)) {
  				memcpy(skb->data - hh_alen, hh->hh_data,
  				       hh_alen);
  			}
425f09ab7   Eric Dumazet   net: output path ...
460
  		}
3644f0cee   Stephen Hemminger   [NET]: Convert hh...
461
  	} while (read_seqretry(&hh->hh_lock, seq));
e6ac64d4c   Stefano Brivio   neighbour: Avoid ...
462
463
464
465
466
467
  	if (WARN_ON_ONCE(skb_headroom(skb) < hh_alen)) {
  		kfree_skb(skb);
  		return NET_XMIT_DROP;
  	}
  
  	__skb_push(skb, hh_len);
b23b5455b   David S. Miller   neigh: Kill hh_ca...
468
  	return dev_queue_xmit(skb);
3644f0cee   Stephen Hemminger   [NET]: Convert hh...
469
  }
0353f2823   David Ahern   neighbor: Add ski...
470
471
  static inline int neigh_output(struct neighbour *n, struct sk_buff *skb,
  			       bool skip_cache)
c16ec1859   Julian Anastasov   net: rename dst_n...
472
473
  {
  	const struct hh_cache *hh = &n->hh;
0353f2823   David Ahern   neighbor: Add ski...
474
  	if ((n->nud_state & NUD_CONNECTED) && hh->hh_len && !skip_cache)
c16ec1859   Julian Anastasov   net: rename dst_n...
475
476
477
478
  		return neigh_hh_output(hh, skb);
  	else
  		return n->output(n, skb);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
  static inline struct neighbour *
  __neigh_lookup(struct neigh_table *tbl, const void *pkey, struct net_device *dev, int creat)
  {
  	struct neighbour *n = neigh_lookup(tbl, pkey, dev);
  
  	if (n || !creat)
  		return n;
  
  	n = neigh_create(tbl, pkey, dev);
  	return IS_ERR(n) ? NULL : n;
  }
  
  static inline struct neighbour *
  __neigh_lookup_errno(struct neigh_table *tbl, const void *pkey,
    struct net_device *dev)
  {
  	struct neighbour *n = neigh_lookup(tbl, pkey, dev);
  
  	if (n)
  		return n;
  
  	return neigh_create(tbl, pkey, dev);
  }
a61bbcf28   Patrick McHardy   [NET]: Store skb-...
502
503
504
505
506
507
508
509
  struct neighbour_cb {
  	unsigned long sched_next;
  	unsigned int flags;
  };
  
  #define LOCALLY_ENQUEUED 0x1
  
  #define NEIGH_CB(skb)	((struct neighbour_cb *)(skb)->cb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
510

0ed8ddf40   Eric Dumazet   neigh: Protect ne...
511
512
513
514
515
516
517
518
519
520
  static inline void neigh_ha_snapshot(char *dst, const struct neighbour *n,
  				     const struct net_device *dev)
  {
  	unsigned int seq;
  
  	do {
  		seq = read_seqbegin(&n->ha_lock);
  		memcpy(dst, n->ha, dev->addr_len);
  	} while (read_seqretry(&n->ha_lock, seq));
  }
4fd3d7d9e   Eric W. Biederman   neigh: Add helper...
521

fc6e8073f   Roopa Prabhu   neighbour: send n...
522
523
524
525
526
527
528
529
530
531
532
533
534
535
  static inline void neigh_update_is_router(struct neighbour *neigh, u32 flags,
  					  int *notify)
  {
  	u8 ndm_flags = 0;
  
  	ndm_flags |= (flags & NEIGH_UPDATE_F_ISROUTER) ? NTF_ROUTER : 0;
  	if ((neigh->flags ^ ndm_flags) & NTF_ROUTER) {
  		if (ndm_flags & NTF_ROUTER)
  			neigh->flags |= NTF_ROUTER;
  		else
  			neigh->flags &= ~NTF_ROUTER;
  		*notify = 1;
  	}
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
536
  #endif