Blame view

include/net/ip6_fib.h 6.78 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  /*
   *	Linux INET6 implementation 
   *
   *	Authors:
   *	Pedro Roque		<roque@di.fc.ul.pt>	
   *
   *	This program is free software; you can redistribute it and/or
   *      modify it under the terms of the GNU General Public License
   *      as published by the Free Software Foundation; either version
   *      2 of the License, or (at your option) any later version.
   */
  
  #ifndef _IP6_FIB_H
  #define _IP6_FIB_H
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
15
  #include <linux/ipv6_route.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
17
  #include <linux/rtnetlink.h>
  #include <linux/spinlock.h>
86872cb57   Thomas Graf   [IPv6] route: FIB...
18
19
20
  #include <net/dst.h>
  #include <net/flow.h>
  #include <net/netlink.h>
b34193638   David S. Miller   ipv6: Add infrast...
21
  #include <net/inetpeer.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22

a33bc5c15   Neil Horman   xfrm: select sane...
23
24
25
26
27
  #ifdef CONFIG_IPV6_MULTIPLE_TABLES
  #define FIB6_TABLE_HASHSZ 256
  #else
  #define FIB6_TABLE_HASHSZ 1
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
28
  struct rt6_info;
fd2c3ef76   Eric Dumazet   net: cleanup incl...
29
  struct fib6_config {
86872cb57   Thomas Graf   [IPv6] route: FIB...
30
31
32
33
34
35
36
  	u32		fc_table;
  	u32		fc_metric;
  	int		fc_dst_len;
  	int		fc_src_len;
  	int		fc_ifindex;
  	u32		fc_flags;
  	u32		fc_protocol;
ef2c7d7b5   Nicolas Dichtel   ipv6: fix handlin...
37
  	u32		fc_type;	/* only 8 bits are used */
86872cb57   Thomas Graf   [IPv6] route: FIB...
38
39
40
  
  	struct in6_addr	fc_dst;
  	struct in6_addr	fc_src;
c3968a857   Daniel Walter   ipv6: RTA_PREFSRC...
41
  	struct in6_addr	fc_prefsrc;
86872cb57   Thomas Graf   [IPv6] route: FIB...
42
43
44
45
46
  	struct in6_addr	fc_gateway;
  
  	unsigned long	fc_expires;
  	struct nlattr	*fc_mx;
  	int		fc_mx_len;
51ebd3181   Nicolas Dichtel   ipv6: add support...
47
48
  	int		fc_mp_len;
  	struct nlattr	*fc_mp;
86872cb57   Thomas Graf   [IPv6] route: FIB...
49
50
  
  	struct nl_info	fc_nlinfo;
19e42e451   Roopa Prabhu   ipv6: support for...
51
52
  	struct nlattr	*fc_encap;
  	u16		fc_encap_type;
86872cb57   Thomas Graf   [IPv6] route: FIB...
53
  };
fd2c3ef76   Eric Dumazet   net: cleanup incl...
54
  struct fib6_node {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
56
57
  	struct fib6_node	*parent;
  	struct fib6_node	*left;
  	struct fib6_node	*right;
8bce65b95   Kim Nordlund   [IPV6]: Make fib6...
58
  #ifdef CONFIG_IPV6_SUBTREES
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
  	struct fib6_node	*subtree;
8bce65b95   Kim Nordlund   [IPV6]: Make fib6...
60
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61
62
63
64
  	struct rt6_info		*leaf;
  
  	__u16			fn_bit;		/* bit key */
  	__u16			fn_flags;
42b187064   Hannes Frederic Sowa   ipv6: make rt_ser...
65
  	int			fn_sernum;
f11e6659c   David S. Miller   [IPV6]: Fix routi...
66
  	struct rt6_info		*rr_ptr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
67
  };
7fc33165a   YOSHIFUJI Hideaki   [IPV6] ROUTE: Put...
68
69
70
71
72
  #ifndef CONFIG_IPV6_SUBTREES
  #define FIB6_SUBTREE(fn)	NULL
  #else
  #define FIB6_SUBTREE(fn)	((fn)->subtree)
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73

e715b6d3a   Florian Westphal   net: fib6: conver...
74
75
76
77
  struct mx6_config {
  	const u32 *mx;
  	DECLARE_BITMAP(mx_valid, RTAX_MAX);
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78
79
80
81
  /*
   *	routing information
   *
   */
fd2c3ef76   Eric Dumazet   net: cleanup incl...
82
  struct rt6key {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
84
85
  	struct in6_addr	addr;
  	int		plen;
  };
c71099acc   Thomas Graf   [IPV6]: Multiple ...
86
  struct fib6_table;
fd2c3ef76   Eric Dumazet   net: cleanup incl...
87
  struct rt6_info {
d8d1f30b9   Changli Gao   net-next: remove ...
88
  	struct dst_entry		dst;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
89

bd2c77a0a   YOSHIFUJI Hideaki / 吉藤英明   ipv6 fib: Make rt...
90
91
92
93
94
95
  	/*
  	 * Tail elements of dst_entry (__refcnt etc.)
  	 * and these elements (rarely used in hot path) are in
  	 * the same cache line.
  	 */
  	struct fib6_table		*rt6i_table;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96
97
98
  	struct fib6_node		*rt6i_node;
  
  	struct in6_addr			rt6i_gateway;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
99

51ebd3181   Nicolas Dichtel   ipv6: add support...
100
101
102
103
104
105
106
  	/* Multipath routes:
  	 * siblings is a list of rt6_info that have the the same metric/weight,
  	 * destination, but not the same gateway. nsiblings is just a cache
  	 * to speed up lookup.
  	 */
  	struct list_head		rt6i_siblings;
  	unsigned int			rt6i_nsiblings;
bd2c77a0a   YOSHIFUJI Hideaki / 吉藤英明   ipv6 fib: Make rt...
107
  	atomic_t			rt6i_ref;
a47ed4cd8   Noriaki TAKAMIYA   [IPV6] XFRM: Fix ...
108

bd2c77a0a   YOSHIFUJI Hideaki / 吉藤英明   ipv6 fib: Make rt...
109
110
111
112
  	/* These are in a separate cache line. */
  	struct rt6key			rt6i_dst ____cacheline_aligned_in_smp;
  	u32				rt6i_flags;
  	struct rt6key			rt6i_src;
c3968a857   Daniel Walter   ipv6: RTA_PREFSRC...
113
  	struct rt6key			rt6i_prefsrc;
b4ce92775   Herbert Xu   [IPV6]: Move nfhe...
114

8d0b94afd   Martin KaFai Lau   ipv6: Keep track ...
115
116
  	struct list_head		rt6i_uncached;
  	struct uncached_list		*rt6i_uncached_list;
bd2c77a0a   YOSHIFUJI Hideaki / 吉藤英明   ipv6 fib: Make rt...
117
  	struct inet6_dev		*rt6i_idev;
d52d3997f   Martin KaFai Lau   ipv6: Create perc...
118
  	struct rt6_info * __percpu	*rt6i_pcpu;
b4ce92775   Herbert Xu   [IPV6]: Move nfhe...
119

705f1c869   Hannes Frederic Sowa   ipv6: remove rt6i...
120
  	u32				rt6i_metric;
4b32b5ad3   Martin KaFai Lau   ipv6: Stop rt6_in...
121
  	u32				rt6i_pmtu;
bd2c77a0a   YOSHIFUJI Hideaki / 吉藤英明   ipv6 fib: Make rt...
122
123
  	/* more non-fragment space at head required */
  	unsigned short			rt6i_nfheader_len;
bd2c77a0a   YOSHIFUJI Hideaki / 吉藤英明   ipv6 fib: Make rt...
124
  	u8				rt6i_protocol;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
125
  };
7a3025b1b   YOSHIFUJI Hideaki   [IPV6]: Introduce...
126
127
128
129
  static inline struct inet6_dev *ip6_dst_idev(struct dst_entry *dst)
  {
  	return ((struct rt6_info *)dst)->rt6i_idev;
  }
1716a9610   Gao feng   ipv6: fix problem...
130
131
  static inline void rt6_clean_expires(struct rt6_info *rt)
  {
1716a9610   Gao feng   ipv6: fix problem...
132
  	rt->rt6i_flags &= ~RTF_EXPIRES;
01ba16d6e   Hannes Frederic Sowa   ipv6: reset dst.e...
133
  	rt->dst.expires = 0;
1716a9610   Gao feng   ipv6: fix problem...
134
135
136
137
  }
  
  static inline void rt6_set_expires(struct rt6_info *rt, unsigned long expires)
  {
1716a9610   Gao feng   ipv6: fix problem...
138
  	rt->dst.expires = expires;
ecd988372   YOSHIFUJI Hideaki / 吉藤英明   ipv6: fix race co...
139
  	rt->rt6i_flags |= RTF_EXPIRES;
1716a9610   Gao feng   ipv6: fix problem...
140
  }
ecd988372   YOSHIFUJI Hideaki / 吉藤英明   ipv6: fix race co...
141
  static inline void rt6_update_expires(struct rt6_info *rt0, int timeout)
1716a9610   Gao feng   ipv6: fix problem...
142
  {
ecd988372   YOSHIFUJI Hideaki / 吉藤英明   ipv6: fix race co...
143
144
145
146
147
148
149
150
151
  	struct rt6_info *rt;
  
  	for (rt = rt0; rt && !(rt->rt6i_flags & RTF_EXPIRES);
  	     rt = (struct rt6_info *)rt->dst.from);
  	if (rt && rt != rt0)
  		rt0->dst.expires = rt->dst.expires;
  
  	dst_set_expires(&rt0->dst, timeout);
  	rt0->rt6i_flags |= RTF_EXPIRES;
1716a9610   Gao feng   ipv6: fix problem...
152
  }
b197df4f0   Martin KaFai Lau   ipv6: Add rt6_get...
153
154
155
  
  static inline u32 rt6_get_cookie(const struct rt6_info *rt)
  {
02bcf4e08   Martin KaFai Lau   ipv6: Check rt->d...
156
157
  	if (rt->rt6i_flags & RTF_PCPU ||
  	    (unlikely(rt->dst.flags & DST_NOCACHE) && rt->dst.from))
3da59bd94   Martin KaFai Lau   ipv6: Create RTF_...
158
  		rt = (struct rt6_info *)(rt->dst.from);
b197df4f0   Martin KaFai Lau   ipv6: Add rt6_get...
159
160
  	return rt->rt6i_node ? rt->rt6i_node->fn_sernum : 0;
  }
1716a9610   Gao feng   ipv6: fix problem...
161

94e187c01   Amerigo Wang   ipv6: introduce i...
162
163
164
165
166
167
168
169
  static inline void ip6_rt_put(struct rt6_info *rt)
  {
  	/* dst_release() accepts a NULL parameter.
  	 * We rely on dst being first structure in struct rt6_info
  	 */
  	BUILD_BUG_ON(offsetof(struct rt6_info, dst) != 0);
  	dst_release(&rt->dst);
  }
94b2cfe02   Hannes Frederic Sowa   ipv6: minor fib6 ...
170
171
172
173
174
175
176
177
178
179
180
  enum fib6_walk_state {
  #ifdef CONFIG_IPV6_SUBTREES
  	FWS_S,
  #endif
  	FWS_L,
  	FWS_R,
  	FWS_C,
  	FWS_U
  };
  
  struct fib6_walker {
bbef49dac   Alexey Dobriyan   ipv6: use standar...
181
  	struct list_head lh;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
182
183
  	struct fib6_node *root, *node;
  	struct rt6_info *leaf;
94b2cfe02   Hannes Frederic Sowa   ipv6: minor fib6 ...
184
185
  	enum fib6_walk_state state;
  	bool prune;
2bec5a369   Patrick McHardy   ipv6: fib: fix cr...
186
187
  	unsigned int skip;
  	unsigned int count;
94b2cfe02   Hannes Frederic Sowa   ipv6: minor fib6 ...
188
  	int (*func)(struct fib6_walker *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
189
190
  	void *args;
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
  struct rt6_statistics {
  	__u32		fib_nodes;
  	__u32		fib_route_nodes;
  	__u32		fib_rt_alloc;		/* permanent routes	*/
  	__u32		fib_rt_entries;		/* rt entries in table	*/
  	__u32		fib_rt_cache;		/* cache routes		*/
  	__u32		fib_discarded_routes;
  };
  
  #define RTN_TL_ROOT	0x0001
  #define RTN_ROOT	0x0002		/* tree root node		*/
  #define RTN_RTINFO	0x0004		/* node with valid routing info	*/
  
  /*
   *	priority levels (or metrics)
   *
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
208

c71099acc   Thomas Graf   [IPV6]: Multiple ...
209
210
211
212
213
  struct fib6_table {
  	struct hlist_node	tb6_hlist;
  	u32			tb6_id;
  	rwlock_t		tb6_lock;
  	struct fib6_node	tb6_root;
8e7732778   David S. Miller   inet: Add inetpee...
214
  	struct inet_peer_base	tb6_peers;
830218c1a   David Ahern   net: ipv6: Fix pr...
215
216
  	unsigned int		flags;
  #define RT6_TABLE_HAS_DFLT_ROUTER	BIT(0)
c71099acc   Thomas Graf   [IPV6]: Multiple ...
217
218
219
220
  };
  
  #define RT6_TABLE_UNSPEC	RT_TABLE_UNSPEC
  #define RT6_TABLE_MAIN		RT_TABLE_MAIN
c71099acc   Thomas Graf   [IPV6]: Multiple ...
221
222
223
224
225
226
227
  #define RT6_TABLE_DFLT		RT6_TABLE_MAIN
  #define RT6_TABLE_INFO		RT6_TABLE_MAIN
  #define RT6_TABLE_PREFIX	RT6_TABLE_MAIN
  
  #ifdef CONFIG_IPV6_MULTIPLE_TABLES
  #define FIB6_TABLE_MIN		1
  #define FIB6_TABLE_MAX		RT_TABLE_MAX
101367c2f   Thomas Graf   [IPV6]: Policy Ro...
228
  #define RT6_TABLE_LOCAL		RT_TABLE_LOCAL
c71099acc   Thomas Graf   [IPV6]: Multiple ...
229
230
231
  #else
  #define FIB6_TABLE_MIN		RT_TABLE_MAIN
  #define FIB6_TABLE_MAX		FIB6_TABLE_MIN
101367c2f   Thomas Graf   [IPV6]: Policy Ro...
232
  #define RT6_TABLE_LOCAL		RT6_TABLE_MAIN
c71099acc   Thomas Graf   [IPV6]: Multiple ...
233
  #endif
8ed677896   Daniel Lezcano   [NETNS][IPV6] rt6...
234
235
  typedef struct rt6_info *(*pol_lookup_t)(struct net *,
  					 struct fib6_table *,
4c9483b2f   David S. Miller   ipv6: Convert to ...
236
  					 struct flowi6 *, int);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
237
238
239
240
  
  /*
   *	exported functions
   */
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
241
242
243
244
  struct fib6_table *fib6_get_table(struct net *net, u32 id);
  struct fib6_table *fib6_new_table(struct net *net, u32 id);
  struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
  				   int flags, pol_lookup_t lookup);
c71099acc   Thomas Graf   [IPV6]: Multiple ...
245

5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
246
247
248
  struct fib6_node *fib6_lookup(struct fib6_node *root,
  			      const struct in6_addr *daddr,
  			      const struct in6_addr *saddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
249

5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
250
251
252
  struct fib6_node *fib6_locate(struct fib6_node *root,
  			      const struct in6_addr *daddr, int dst_len,
  			      const struct in6_addr *saddr, int src_len);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
253

5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
254
  void fib6_clean_all(struct net *net, int (*func)(struct rt6_info *, void *arg),
0c3584d58   Li RongQing   ipv6: remove prun...
255
  		    void *arg);
c71099acc   Thomas Graf   [IPV6]: Multiple ...
256

e715b6d3a   Florian Westphal   net: fib6: conver...
257
258
  int fib6_add(struct fib6_node *root, struct rt6_info *rt,
  	     struct nl_info *info, struct mx6_config *mxc);
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
259
  int fib6_del(struct rt6_info *rt, struct nl_info *info);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
260

37a1d3611   Roopa Prabhu   ipv6: include NLM...
261
262
  void inet6_rt_notify(int event, struct rt6_info *rt, struct nl_info *info,
  		     unsigned int flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
263

5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
264
  void fib6_run_gc(unsigned long expires, struct net *net, bool force);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
265

5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
266
  void fib6_gc_cleanup(void);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
267

5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
268
  int fib6_init(void);
101367c2f   Thomas Graf   [IPV6]: Policy Ro...
269

8d2ca1d7b   Hannes Frederic Sowa   ipv6: avoid high ...
270
  int ipv6_route_open(struct inode *inode, struct file *file);
7e5449c21   Daniel Lezcano   [IPV6]: route6 re...
271
  #ifdef CONFIG_IPV6_MULTIPLE_TABLES
5c3a0fd7d   Joe Perches   ip*.h: Remove ext...
272
273
  int fib6_rules_init(void);
  void fib6_rules_cleanup(void);
7e5449c21   Daniel Lezcano   [IPV6]: route6 re...
274
275
276
277
278
279
280
281
282
283
  #else
  static inline int               fib6_rules_init(void)
  {
  	return 0;
  }
  static inline void              fib6_rules_cleanup(void)
  {
  	return ;
  }
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
284
  #endif