[IPV4]: struct fib_config IPv4 address fields annotated
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / net / ip_fib.h
CommitLineData
1da177e4
LT
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Definitions for the Forwarding Information Base.
7 *
8 * Authors: A.N.Kuznetsov, <kuznet@ms2.inr.ac.ru>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 */
15
16#ifndef _NET_IP_FIB_H
17#define _NET_IP_FIB_H
18
1da177e4
LT
19#include <net/flow.h>
20#include <linux/seq_file.h>
e1ef4bf2 21#include <net/fib_rules.h>
1da177e4 22
4e902c57
TG
23struct fib_config {
24 u8 fc_family;
25 u8 fc_dst_len;
26 u8 fc_src_len;
27 u8 fc_tos;
28 u8 fc_protocol;
29 u8 fc_scope;
30 u8 fc_type;
31 /* 1 byte unused */
32 u32 fc_table;
6d85c10a
AV
33 __be32 fc_dst;
34 __be32 fc_src;
35 __be32 fc_gw;
4e902c57
TG
36 int fc_oif;
37 u32 fc_flags;
38 u32 fc_priority;
6d85c10a 39 __be32 fc_prefsrc;
4e902c57
TG
40 struct nlattr *fc_mx;
41 struct rtnexthop *fc_mp;
42 int fc_mx_len;
43 int fc_mp_len;
44 u32 fc_flow;
45 u32 fc_mp_alg;
46 u32 fc_nlflags;
47 struct nl_info fc_nlinfo;
48 };
1da177e4
LT
49
50struct fib_info;
51
52struct fib_nh {
53 struct net_device *nh_dev;
54 struct hlist_node nh_hash;
55 struct fib_info *nh_parent;
56 unsigned nh_flags;
57 unsigned char nh_scope;
58#ifdef CONFIG_IP_ROUTE_MULTIPATH
59 int nh_weight;
60 int nh_power;
61#endif
62#ifdef CONFIG_NET_CLS_ROUTE
63 __u32 nh_tclassid;
64#endif
65 int nh_oif;
ed49e3ca 66 __be32 nh_gw;
1da177e4
LT
67};
68
69/*
70 * This structure contains data shared by many of routes.
71 */
72
73struct fib_info {
74 struct hlist_node fib_hash;
75 struct hlist_node fib_lhash;
76 int fib_treeref;
77 atomic_t fib_clntref;
78 int fib_dead;
79 unsigned fib_flags;
80 int fib_protocol;
b83738ae 81 __be32 fib_prefsrc;
1da177e4
LT
82 u32 fib_priority;
83 u32 fib_metrics[RTAX_MAX];
84#define fib_mtu fib_metrics[RTAX_MTU-1]
85#define fib_window fib_metrics[RTAX_WINDOW-1]
86#define fib_rtt fib_metrics[RTAX_RTT-1]
87#define fib_advmss fib_metrics[RTAX_ADVMSS-1]
88 int fib_nhs;
89#ifdef CONFIG_IP_ROUTE_MULTIPATH
90 int fib_power;
91#endif
92#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
93 u32 fib_mp_alg;
94#endif
95 struct fib_nh fib_nh[0];
96#define fib_dev fib_nh[0].nh_dev
97};
98
99
100#ifdef CONFIG_IP_MULTIPLE_TABLES
101struct fib_rule;
102#endif
103
104struct fib_result {
105 unsigned char prefixlen;
106 unsigned char nh_sel;
107 unsigned char type;
108 unsigned char scope;
109#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
110 __u32 network;
111 __u32 netmask;
112#endif
113 struct fib_info *fi;
114#ifdef CONFIG_IP_MULTIPLE_TABLES
115 struct fib_rule *r;
116#endif
117};
118
246955fe
RO
119struct fib_result_nl {
120 u32 fl_addr; /* To be looked up*/
121 u32 fl_fwmark;
122 unsigned char fl_tos;
123 unsigned char fl_scope;
124 unsigned char tb_id_in;
125
126 unsigned char tb_id; /* Results */
127 unsigned char prefixlen;
128 unsigned char nh_sel;
129 unsigned char type;
130 unsigned char scope;
131 int err;
132};
1da177e4
LT
133
134#ifdef CONFIG_IP_ROUTE_MULTIPATH
135
136#define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
137#define FIB_RES_RESET(res) ((res).nh_sel = 0)
138
139#else /* CONFIG_IP_ROUTE_MULTIPATH */
140
141#define FIB_RES_NH(res) ((res).fi->fib_nh[0])
142#define FIB_RES_RESET(res)
143
144#endif /* CONFIG_IP_ROUTE_MULTIPATH */
145
146#define FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __fib_res_prefsrc(&res))
147#define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
148#define FIB_RES_DEV(res) (FIB_RES_NH(res).nh_dev)
149#define FIB_RES_OIF(res) (FIB_RES_NH(res).nh_oif)
150
151#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
152#define FIB_RES_NETWORK(res) ((res).network)
153#define FIB_RES_NETMASK(res) ((res).netmask)
154#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
155#define FIB_RES_NETWORK(res) (0)
156#define FIB_RES_NETMASK(res) (0)
157#endif /* CONFIG_IP_ROUTE_MULTIPATH_WRANDOM */
158
159struct fib_table {
1af5a8c4 160 struct hlist_node tb_hlist;
2dfe55b4 161 u32 tb_id;
1da177e4
LT
162 unsigned tb_stamp;
163 int (*tb_lookup)(struct fib_table *tb, const struct flowi *flp, struct fib_result *res);
4e902c57
TG
164 int (*tb_insert)(struct fib_table *, struct fib_config *);
165 int (*tb_delete)(struct fib_table *, struct fib_config *);
1da177e4
LT
166 int (*tb_dump)(struct fib_table *table, struct sk_buff *skb,
167 struct netlink_callback *cb);
168 int (*tb_flush)(struct fib_table *table);
169 void (*tb_select_default)(struct fib_table *table,
170 const struct flowi *flp, struct fib_result *res);
171
172 unsigned char tb_data[0];
173};
174
175#ifndef CONFIG_IP_MULTIPLE_TABLES
176
177extern struct fib_table *ip_fib_local_table;
178extern struct fib_table *ip_fib_main_table;
179
2dfe55b4 180static inline struct fib_table *fib_get_table(u32 id)
1da177e4
LT
181{
182 if (id != RT_TABLE_LOCAL)
183 return ip_fib_main_table;
184 return ip_fib_local_table;
185}
186
2dfe55b4 187static inline struct fib_table *fib_new_table(u32 id)
1da177e4
LT
188{
189 return fib_get_table(id);
190}
191
192static inline int fib_lookup(const struct flowi *flp, struct fib_result *res)
193{
194 if (ip_fib_local_table->tb_lookup(ip_fib_local_table, flp, res) &&
195 ip_fib_main_table->tb_lookup(ip_fib_main_table, flp, res))
196 return -ENETUNREACH;
197 return 0;
198}
199
200static inline void fib_select_default(const struct flowi *flp, struct fib_result *res)
201{
202 if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
203 ip_fib_main_table->tb_select_default(ip_fib_main_table, flp, res);
204}
205
206#else /* CONFIG_IP_MULTIPLE_TABLES */
1af5a8c4
PM
207#define ip_fib_local_table fib_get_table(RT_TABLE_LOCAL)
208#define ip_fib_main_table fib_get_table(RT_TABLE_MAIN)
1da177e4 209
e1ef4bf2 210extern int fib_lookup(struct flowi *flp, struct fib_result *res);
1da177e4 211
1af5a8c4
PM
212extern struct fib_table *fib_new_table(u32 id);
213extern struct fib_table *fib_get_table(u32 id);
1da177e4
LT
214extern void fib_select_default(const struct flowi *flp, struct fib_result *res);
215
216#endif /* CONFIG_IP_MULTIPLE_TABLES */
217
218/* Exported by fib_frontend.c */
d889ce3b 219extern struct nla_policy rtm_ipv4_policy[];
1da177e4
LT
220extern void ip_fib_init(void);
221extern int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
222extern int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
223extern int inet_rtm_getroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
224extern int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb);
d9c9df8c
AV
225extern int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif,
226 struct net_device *dev, __be32 *spec_dst, u32 *itag);
1da177e4
LT
227extern void fib_select_multipath(const struct flowi *flp, struct fib_result *res);
228
14c85021
ACM
229struct rtentry;
230
1da177e4
LT
231/* Exported by fib_semantics.c */
232extern int ip_fib_check_default(u32 gw, struct net_device *dev);
233extern int fib_sync_down(u32 local, struct net_device *dev, int force);
234extern int fib_sync_up(struct net_device *dev);
b83738ae 235extern __be32 __fib_res_prefsrc(struct fib_result *res);
1da177e4
LT
236
237/* Exported by fib_hash.c */
2dfe55b4 238extern struct fib_table *fib_hash_init(u32 id);
1da177e4
LT
239
240#ifdef CONFIG_IP_MULTIPLE_TABLES
e1ef4bf2
TG
241extern int fib4_rules_dump(struct sk_buff *skb, struct netlink_callback *cb);
242
243extern void __init fib4_rules_init(void);
1da177e4 244
1da177e4
LT
245#ifdef CONFIG_NET_CLS_ROUTE
246extern u32 fib_rules_tclass(struct fib_result *res);
247#endif
e1ef4bf2 248
1da177e4
LT
249#endif
250
251static inline void fib_combine_itag(u32 *itag, struct fib_result *res)
252{
253#ifdef CONFIG_NET_CLS_ROUTE
254#ifdef CONFIG_IP_MULTIPLE_TABLES
255 u32 rtag;
256#endif
257 *itag = FIB_RES_NH(*res).nh_tclassid<<16;
258#ifdef CONFIG_IP_MULTIPLE_TABLES
259 rtag = fib_rules_tclass(res);
260 if (*itag == 0)
261 *itag = (rtag<<16);
262 *itag |= (rtag>>16);
263#endif
264#endif
265}
266
267extern void free_fib_info(struct fib_info *fi);
268
269static inline void fib_info_put(struct fib_info *fi)
270{
271 if (atomic_dec_and_test(&fi->fib_clntref))
272 free_fib_info(fi);
273}
274
275static inline void fib_res_put(struct fib_result *res)
276{
277 if (res->fi)
278 fib_info_put(res->fi);
279#ifdef CONFIG_IP_MULTIPLE_TABLES
280 if (res->r)
281 fib_rule_put(res->r);
282#endif
283}
284
20380731
ACM
285#ifdef CONFIG_PROC_FS
286extern int fib_proc_init(void);
287extern void fib_proc_exit(void);
288#endif
289
1da177e4 290#endif /* _NET_FIB_H */