From bb803175865dd030420eebbc87298414c7725019 Mon Sep 17 00:00:00 2001 From: "Eric W. Biederman" Date: Fri, 7 Dec 2007 00:46:11 -0800 Subject: [IPV4]: Remove ip_fib_local_table and ip_fib_main_table defines. There are only 2 users and it doesn't hurt to call fib_get_table instead, and it makes it easier to make the fib network namespace aware. Signed-off-by: Eric W. Biederman Signed-off-by: Denis V. Lunev Signed-off-by: David S. Miller --- include/net/ip_fib.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'include/net/ip_fib.h') diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index ed514bf..690fb4d 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -191,9 +191,6 @@ extern void __init fib4_rules_init(void); extern u32 fib_rules_tclass(struct fib_result *res); #endif -#define ip_fib_local_table fib_get_table(RT_TABLE_LOCAL) -#define ip_fib_main_table fib_get_table(RT_TABLE_MAIN) - extern int fib_lookup(struct flowi *flp, struct fib_result *res); extern struct fib_table *fib_new_table(u32 id); -- cgit v1.1 From 971b893e79db0f7dccfcea15dbdebca3ca64a84d Mon Sep 17 00:00:00 2001 From: "Denis V. Lunev" Date: Sat, 8 Dec 2007 00:32:23 -0800 Subject: [IPV4]: last default route is a fib table property Signed-off-by: Denis V. Lunev Acked-by: Alexey Kuznetsov Signed-off-by: David S. Miller --- include/net/ip_fib.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/net/ip_fib.h') diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index 690fb4d..d70b9b4 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -141,6 +141,7 @@ struct fib_table { struct hlist_node tb_hlist; u32 tb_id; unsigned tb_stamp; + int tb_default; int (*tb_lookup)(struct fib_table *tb, const struct flowi *flp, struct fib_result *res); int (*tb_insert)(struct fib_table *, struct fib_config *); int (*tb_delete)(struct fib_table *, struct fib_config *); -- cgit v1.1 From 61a0265344786a548e8a0b26cb668e78a71f9602 Mon Sep 17 00:00:00 2001 From: "Denis V. Lunev" Date: Thu, 10 Jan 2008 03:21:09 -0800 Subject: [NETNS]: Add namespace to API for routing /proc entries creation. This adds netns parameter to fib_proc_init/exit and replaces __init specifier with __net_init. After this, we will not yet have these proc files show info from the specific namespace - this will be done when these tables become namespaced. Acked-by: Benjamin Thery Acked-by: Daniel Lezcano Signed-off-by: Denis V. Lunev Signed-off-by: David S. Miller --- include/net/ip_fib.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/net/ip_fib.h') diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index d70b9b4..f74cbb2 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -253,8 +253,8 @@ static inline void fib_res_put(struct fib_result *res) } #ifdef CONFIG_PROC_FS -extern int fib_proc_init(void); -extern void fib_proc_exit(void); +extern int __net_init fib_proc_init(struct net *net); +extern void __net_exit fib_proc_exit(struct net *net); #endif #endif /* _NET_FIB_H */ -- cgit v1.1 From dbb50165b512f6c9b7aae10af73ae5b6d811f4d0 Mon Sep 17 00:00:00 2001 From: "Denis V. Lunev" Date: Thu, 10 Jan 2008 03:21:49 -0800 Subject: [IPV4]: Check fib4_rules_init failure. This adds error paths into both versions of fib4_rules_init (with/without CONFIG_IP_MULTIPLE_TABLES) and returns error code to the caller. Acked-by: Benjamin Thery Acked-by: Daniel Lezcano Signed-off-by: Denis V. Lunev Signed-off-by: David S. Miller --- include/net/ip_fib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/net/ip_fib.h') diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index f74cbb2..cbff18d 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -186,7 +186,7 @@ static inline void fib_select_default(const struct flowi *flp, struct fib_result } #else /* CONFIG_IP_MULTIPLE_TABLES */ -extern void __init fib4_rules_init(void); +extern int __init fib4_rules_init(void); #ifdef CONFIG_NET_CLS_ROUTE extern u32 fib_rules_tclass(struct fib_result *res); -- cgit v1.1 From 7b1a74fdbb9ec38a9780620fae25519fde4b21ee Mon Sep 17 00:00:00 2001 From: "Denis V. Lunev" Date: Thu, 10 Jan 2008 03:22:17 -0800 Subject: [NETNS]: Refactor fib initialization so it can handle multiple namespaces. This patch makes the fib to be initialized as a subsystem for the network namespaces. The code does not handle several namespaces yet, so in case of a creation of a network namespace, the creation/initialization will not occur. Acked-by: Benjamin Thery Acked-by: Daniel Lezcano Signed-off-by: Denis V. Lunev Signed-off-by: David S. Miller --- include/net/ip_fib.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/net/ip_fib.h') diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index cbff18d..338d3ed 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -186,7 +186,8 @@ static inline void fib_select_default(const struct flowi *flp, struct fib_result } #else /* CONFIG_IP_MULTIPLE_TABLES */ -extern int __init fib4_rules_init(void); +extern int __net_init fib4_rules_init(struct net *net); +extern void __net_exit fib4_rules_exit(struct net *net); #ifdef CONFIG_NET_CLS_ROUTE extern u32 fib_rules_tclass(struct fib_result *res); -- cgit v1.1 From 93456b6d7753def8760b423ac6b986eb9d5a4a95 Mon Sep 17 00:00:00 2001 From: "Denis V. Lunev" Date: Thu, 10 Jan 2008 03:23:38 -0800 Subject: [IPV4]: Unify access to the routing tables. Replace the direct pointers to local and main tables with calls to fib_get_table() with appropriate argument. This doesn't introduce additional dereferences, but makes the access to fib tables uniform in any (CONFIG_IP_MULTIPLE_TABLES) case. Acked-by: Benjamin Thery Acked-by: Daniel Lezcano Signed-off-by: Denis V. Lunev Signed-off-by: David S. Miller --- include/net/ip_fib.h | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'include/net/ip_fib.h') diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index 338d3ed..249af66 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -120,16 +120,22 @@ struct fib_result_nl { int err; }; +extern struct hlist_head fib_table_hash[]; + #ifdef CONFIG_IP_ROUTE_MULTIPATH #define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel]) #define FIB_RES_RESET(res) ((res).nh_sel = 0) +#define FIB_TABLE_HASHSZ 2 + #else /* CONFIG_IP_ROUTE_MULTIPATH */ #define FIB_RES_NH(res) ((res).fi->fib_nh[0]) #define FIB_RES_RESET(res) +#define FIB_TABLE_HASHSZ 256 + #endif /* CONFIG_IP_ROUTE_MULTIPATH */ #define FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __fib_res_prefsrc(&res)) @@ -156,14 +162,17 @@ struct fib_table { #ifndef CONFIG_IP_MULTIPLE_TABLES -extern struct fib_table *ip_fib_local_table; -extern struct fib_table *ip_fib_main_table; +#define TABLE_LOCAL_INDEX 0 +#define TABLE_MAIN_INDEX 1 static inline struct fib_table *fib_get_table(u32 id) { - if (id != RT_TABLE_LOCAL) - return ip_fib_main_table; - return ip_fib_local_table; + struct hlist_head *ptr; + + ptr = id == RT_TABLE_LOCAL ? + &fib_table_hash[TABLE_LOCAL_INDEX] : + &fib_table_hash[TABLE_MAIN_INDEX]; + return hlist_entry(ptr->first, struct fib_table, tb_hlist); } static inline struct fib_table *fib_new_table(u32 id) @@ -173,16 +182,24 @@ static inline struct fib_table *fib_new_table(u32 id) static inline int fib_lookup(const struct flowi *flp, struct fib_result *res) { - if (ip_fib_local_table->tb_lookup(ip_fib_local_table, flp, res) && - ip_fib_main_table->tb_lookup(ip_fib_main_table, flp, res)) - return -ENETUNREACH; - return 0; + struct fib_table *table; + + table = fib_get_table(RT_TABLE_LOCAL); + if (!table->tb_lookup(table, flp, res)) + return 0; + + table = fib_get_table(RT_TABLE_MAIN); + if (!table->tb_lookup(table, flp, res)) + return 0; + return -ENETUNREACH; } -static inline void fib_select_default(const struct flowi *flp, struct fib_result *res) +static inline void fib_select_default(const struct flowi *flp, + struct fib_result *res) { + struct fib_table *table = fib_get_table(RT_TABLE_MAIN); if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK) - ip_fib_main_table->tb_select_default(ip_fib_main_table, flp, res); + table->tb_select_default(table, flp, res); } #else /* CONFIG_IP_MULTIPLE_TABLES */ -- cgit v1.1 From 8ad4942cd5bdad4143f7aa1d1bd4f7b2526c19c5 Mon Sep 17 00:00:00 2001 From: "Denis V. Lunev" Date: Thu, 10 Jan 2008 03:24:11 -0800 Subject: [NETNS]: Add netns parameter to fib_get_table/fib_new_table. This patch extends the fib_get_table and the fib_new_table functions with the network namespace pointer. That will allow to access the table relatively from the network namespace. Acked-by: Benjamin Thery Acked-by: Daniel Lezcano Signed-off-by: Denis V. Lunev Signed-off-by: David S. Miller --- include/net/ip_fib.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'include/net/ip_fib.h') diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index 249af66..dfb95d7 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -165,7 +165,7 @@ struct fib_table { #define TABLE_LOCAL_INDEX 0 #define TABLE_MAIN_INDEX 1 -static inline struct fib_table *fib_get_table(u32 id) +static inline struct fib_table *fib_get_table(struct net *net, u32 id) { struct hlist_head *ptr; @@ -175,20 +175,20 @@ static inline struct fib_table *fib_get_table(u32 id) return hlist_entry(ptr->first, struct fib_table, tb_hlist); } -static inline struct fib_table *fib_new_table(u32 id) +static inline struct fib_table *fib_new_table(struct net *net, u32 id) { - return fib_get_table(id); + return fib_get_table(net, id); } static inline int fib_lookup(const struct flowi *flp, struct fib_result *res) { struct fib_table *table; - table = fib_get_table(RT_TABLE_LOCAL); + table = fib_get_table(&init_net, RT_TABLE_LOCAL); if (!table->tb_lookup(table, flp, res)) return 0; - table = fib_get_table(RT_TABLE_MAIN); + table = fib_get_table(&init_net, RT_TABLE_MAIN); if (!table->tb_lookup(table, flp, res)) return 0; return -ENETUNREACH; @@ -197,7 +197,7 @@ static inline int fib_lookup(const struct flowi *flp, struct fib_result *res) static inline void fib_select_default(const struct flowi *flp, struct fib_result *res) { - struct fib_table *table = fib_get_table(RT_TABLE_MAIN); + struct fib_table *table = fib_get_table(&init_net, RT_TABLE_MAIN); if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK) table->tb_select_default(table, flp, res); } @@ -212,8 +212,8 @@ extern u32 fib_rules_tclass(struct fib_result *res); extern int fib_lookup(struct flowi *flp, struct fib_result *res); -extern struct fib_table *fib_new_table(u32 id); -extern struct fib_table *fib_get_table(u32 id); +extern struct fib_table *fib_new_table(struct net *net, u32 id); +extern struct fib_table *fib_get_table(struct net *net, u32 id); extern void fib_select_default(const struct flowi *flp, struct fib_result *res); #endif /* CONFIG_IP_MULTIPLE_TABLES */ -- cgit v1.1 From e4aef8aea31e6fc61b33a57120968a6e9824d138 Mon Sep 17 00:00:00 2001 From: "Denis V. Lunev" Date: Thu, 10 Jan 2008 03:28:24 -0800 Subject: [NETNS]: Place fib tables into netns. The preparatory work has been done. All we need is to substitute fib_table_hash with net->ipv4.fib_table_hash. Netns context is available when required. Acked-by: Benjamin Thery Acked-by: Daniel Lezcano Signed-off-by: Denis V. Lunev Signed-off-by: David S. Miller --- include/net/ip_fib.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'include/net/ip_fib.h') diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index dfb95d7..025b225 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -120,8 +120,6 @@ struct fib_result_nl { int err; }; -extern struct hlist_head fib_table_hash[]; - #ifdef CONFIG_IP_ROUTE_MULTIPATH #define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel]) @@ -170,8 +168,8 @@ static inline struct fib_table *fib_get_table(struct net *net, u32 id) struct hlist_head *ptr; ptr = id == RT_TABLE_LOCAL ? - &fib_table_hash[TABLE_LOCAL_INDEX] : - &fib_table_hash[TABLE_MAIN_INDEX]; + &net->ipv4.fib_table_hash[TABLE_LOCAL_INDEX] : + &net->ipv4.fib_table_hash[TABLE_MAIN_INDEX]; return hlist_entry(ptr->first, struct fib_table, tb_hlist); } -- cgit v1.1 From 7f9b80529b8a2ad8b3273b15fb444a0e34b760a9 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Mon, 14 Jan 2008 23:14:20 -0800 Subject: [IPV4]: fib hash|trie initialization Initialization of the slab cache's should be done when IP is initialized to make sure of available memory, and that code can be marked __init. Signed-off-by: Stephen Hemminger Signed-off-by: David S. Miller --- include/net/ip_fib.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include/net/ip_fib.h') diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index 025b225..f580542f 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -231,8 +231,9 @@ extern int fib_sync_down(__be32 local, struct net_device *dev, int force); extern int fib_sync_up(struct net_device *dev); extern __be32 __fib_res_prefsrc(struct fib_result *res); -/* Exported by fib_hash.c */ -extern struct fib_table *fib_hash_init(u32 id); +/* Exported by fib_{hash|trie}.c */ +extern void fib_hash_init(void); +extern struct fib_table *fib_hash_table(u32 id); static inline void fib_combine_itag(u32 *itag, struct fib_result *res) { -- cgit v1.1 From da0e28cb68a7e22b47c6ae1a5b12cb538c13c69f Mon Sep 17 00:00:00 2001 From: "Denis V. Lunev" Date: Mon, 21 Jan 2008 17:31:55 -0800 Subject: [NETNS]: Add netns parameter to fib_lookup. Signed-off-by: Denis V. Lunev Signed-off-by: David S. Miller --- include/net/ip_fib.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'include/net/ip_fib.h') diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index f580542f..a859124 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -178,15 +178,16 @@ static inline struct fib_table *fib_new_table(struct net *net, u32 id) return fib_get_table(net, id); } -static inline int fib_lookup(const struct flowi *flp, struct fib_result *res) +static inline int fib_lookup(struct net *net, const struct flowi *flp, + struct fib_result *res) { struct fib_table *table; - table = fib_get_table(&init_net, RT_TABLE_LOCAL); + table = fib_get_table(net, RT_TABLE_LOCAL); if (!table->tb_lookup(table, flp, res)) return 0; - table = fib_get_table(&init_net, RT_TABLE_MAIN); + table = fib_get_table(net, RT_TABLE_MAIN); if (!table->tb_lookup(table, flp, res)) return 0; return -ENETUNREACH; @@ -208,7 +209,7 @@ extern void __net_exit fib4_rules_exit(struct net *net); extern u32 fib_rules_tclass(struct fib_result *res); #endif -extern int fib_lookup(struct flowi *flp, struct fib_result *res); +extern int fib_lookup(struct net *n, struct flowi *flp, struct fib_result *res); extern struct fib_table *fib_new_table(struct net *net, u32 id); extern struct fib_table *fib_get_table(struct net *net, u32 id); -- cgit v1.1 From e30d3a0ccddbd458b3fb14c9b0229b01d97bad5b Mon Sep 17 00:00:00 2001 From: "Denis V. Lunev" Date: Tue, 22 Jan 2008 22:03:03 -0800 Subject: [IPV4]: Declarations cleanup in ip_fib.h. Two small issues fixed: - fib_select_multipath is exported from fib_semantics.c rather than from fib_frontend.c. So, move the declaration below appropriate comment. - struct rt_entry declaration is not used. Drop it. Signed-off-by: Denis V. Lunev Signed-off-by: David S. Miller --- include/net/ip_fib.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'include/net/ip_fib.h') diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index a859124..be70b33 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -222,15 +222,13 @@ extern const struct nla_policy rtm_ipv4_policy[]; extern void ip_fib_init(void); extern int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif, struct net_device *dev, __be32 *spec_dst, u32 *itag); -extern void fib_select_multipath(const struct flowi *flp, struct fib_result *res); - -struct rtentry; /* Exported by fib_semantics.c */ extern int ip_fib_check_default(__be32 gw, struct net_device *dev); extern int fib_sync_down(__be32 local, struct net_device *dev, int force); extern int fib_sync_up(struct net_device *dev); extern __be32 __fib_res_prefsrc(struct fib_result *res); +extern void fib_select_multipath(const struct flowi *flp, struct fib_result *res); /* Exported by fib_{hash|trie}.c */ extern void fib_hash_init(void); -- cgit v1.1 From 64c2d5382954ccf6054424653f4c7f4f04c1ff21 Mon Sep 17 00:00:00 2001 From: "Denis V. Lunev" Date: Tue, 22 Jan 2008 22:03:33 -0800 Subject: [IPV4]: Consolidate fib_select_default. The difference in the implementation of the fib_select_default when CONFIG_IP_MULTIPLE_TABLES is (not) defined looks negligible. Consolidate it and place into fib_frontend.c. Signed-off-by: Denis V. Lunev Signed-off-by: David S. Miller --- include/net/ip_fib.h | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'include/net/ip_fib.h') diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index be70b33..39f944a 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -193,14 +193,6 @@ static inline int fib_lookup(struct net *net, const struct flowi *flp, return -ENETUNREACH; } -static inline void fib_select_default(const struct flowi *flp, - struct fib_result *res) -{ - struct fib_table *table = fib_get_table(&init_net, RT_TABLE_MAIN); - if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK) - table->tb_select_default(table, flp, res); -} - #else /* CONFIG_IP_MULTIPLE_TABLES */ extern int __net_init fib4_rules_init(struct net *net); extern void __net_exit fib4_rules_exit(struct net *net); @@ -213,7 +205,6 @@ extern int fib_lookup(struct net *n, struct flowi *flp, struct fib_result *res); extern struct fib_table *fib_new_table(struct net *net, u32 id); extern struct fib_table *fib_get_table(struct net *net, u32 id); -extern void fib_select_default(const struct flowi *flp, struct fib_result *res); #endif /* CONFIG_IP_MULTIPLE_TABLES */ @@ -222,6 +213,7 @@ extern const struct nla_policy rtm_ipv4_policy[]; extern void ip_fib_init(void); extern int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif, struct net_device *dev, __be32 *spec_dst, u32 *itag); +extern void fib_select_default(const struct flowi *flp, struct fib_result *res); /* Exported by fib_semantics.c */ extern int ip_fib_check_default(__be32 gw, struct net_device *dev); -- cgit v1.1 From 010278ec4cdf404aefc0bbd5e7406674fec95286 Mon Sep 17 00:00:00 2001 From: "Denis V. Lunev" Date: Tue, 22 Jan 2008 22:04:04 -0800 Subject: [NETNS]: Add netns parameter to fib_select_default. Currently fib_select_default calls fib_get_table() with the init_net. Prepare it to provide a correct namespace to lookup default route. Signed-off-by: Denis V. Lunev Signed-off-by: David S. Miller --- include/net/ip_fib.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/net/ip_fib.h') diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index 39f944a..9daa60b 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -213,7 +213,8 @@ extern const struct nla_policy rtm_ipv4_policy[]; extern void ip_fib_init(void); extern int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif, struct net_device *dev, __be32 *spec_dst, u32 *itag); -extern void fib_select_default(const struct flowi *flp, struct fib_result *res); +extern void fib_select_default(struct net *net, const struct flowi *flp, + struct fib_result *res); /* Exported by fib_semantics.c */ extern int ip_fib_check_default(__be32 gw, struct net_device *dev); -- cgit v1.1