aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/net/netns/ipv4.h2
-rw-r--r--net/ipv4/fib_frontend.c24
2 files changed, 18 insertions, 8 deletions
diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
index 2dd31937d022..3872aa7e294b 100644
--- a/include/net/netns/ipv4.h
+++ b/include/net/netns/ipv4.h
@@ -9,6 +9,7 @@ struct ctl_table_header;
9struct ipv4_devconf; 9struct ipv4_devconf;
10struct fib_rules_ops; 10struct fib_rules_ops;
11struct hlist_head; 11struct hlist_head;
12struct sock;
12 13
13struct netns_ipv4 { 14struct netns_ipv4 {
14#ifdef CONFIG_SYSCTL 15#ifdef CONFIG_SYSCTL
@@ -20,5 +21,6 @@ struct netns_ipv4 {
20 struct fib_rules_ops *rules_ops; 21 struct fib_rules_ops *rules_ops;
21#endif 22#endif
22 struct hlist_head *fib_table_hash; 23 struct hlist_head *fib_table_hash;
24 struct sock *fibnl;
23}; 25};
24#endif 26#endif
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index 7fe54a3c168b..a5e81677a2b5 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -49,8 +49,6 @@
49 49
50#define FFprint(a...) printk(KERN_DEBUG a) 50#define FFprint(a...) printk(KERN_DEBUG a)
51 51
52static struct sock *fibnl;
53
54#ifndef CONFIG_IP_MULTIPLE_TABLES 52#ifndef CONFIG_IP_MULTIPLE_TABLES
55 53
56static int __net_init fib4_rules_init(struct net *net) 54static int __net_init fib4_rules_init(struct net *net)
@@ -845,11 +843,13 @@ static void nl_fib_lookup(struct fib_result_nl *frn, struct fib_table *tb )
845 843
846static void nl_fib_input(struct sk_buff *skb) 844static void nl_fib_input(struct sk_buff *skb)
847{ 845{
846 struct net *net;
848 struct fib_result_nl *frn; 847 struct fib_result_nl *frn;
849 struct nlmsghdr *nlh; 848 struct nlmsghdr *nlh;
850 struct fib_table *tb; 849 struct fib_table *tb;
851 u32 pid; 850 u32 pid;
852 851
852 net = skb->sk->sk_net;
853 nlh = nlmsg_hdr(skb); 853 nlh = nlmsg_hdr(skb);
854 if (skb->len < NLMSG_SPACE(0) || skb->len < nlh->nlmsg_len || 854 if (skb->len < NLMSG_SPACE(0) || skb->len < nlh->nlmsg_len ||
855 nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*frn))) 855 nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*frn)))
@@ -861,28 +861,36 @@ static void nl_fib_input(struct sk_buff *skb)
861 nlh = nlmsg_hdr(skb); 861 nlh = nlmsg_hdr(skb);
862 862
863 frn = (struct fib_result_nl *) NLMSG_DATA(nlh); 863 frn = (struct fib_result_nl *) NLMSG_DATA(nlh);
864 tb = fib_get_table(&init_net, frn->tb_id_in); 864 tb = fib_get_table(net, frn->tb_id_in);
865 865
866 nl_fib_lookup(frn, tb); 866 nl_fib_lookup(frn, tb);
867 867
868 pid = NETLINK_CB(skb).pid; /* pid of sending process */ 868 pid = NETLINK_CB(skb).pid; /* pid of sending process */
869 NETLINK_CB(skb).pid = 0; /* from kernel */ 869 NETLINK_CB(skb).pid = 0; /* from kernel */
870 NETLINK_CB(skb).dst_group = 0; /* unicast */ 870 NETLINK_CB(skb).dst_group = 0; /* unicast */
871 netlink_unicast(fibnl, skb, pid, MSG_DONTWAIT); 871 netlink_unicast(net->ipv4.fibnl, skb, pid, MSG_DONTWAIT);
872} 872}
873 873
874static int nl_fib_lookup_init(struct net *net) 874static int nl_fib_lookup_init(struct net *net)
875{ 875{
876 fibnl = netlink_kernel_create(net, NETLINK_FIB_LOOKUP, 0, 876 struct sock *sk;
877 nl_fib_input, NULL, THIS_MODULE); 877 sk = netlink_kernel_create(net, NETLINK_FIB_LOOKUP, 0,
878 if (fibnl == NULL) 878 nl_fib_input, NULL, THIS_MODULE);
879 if (sk == NULL)
879 return -EAFNOSUPPORT; 880 return -EAFNOSUPPORT;
881 /* Don't hold an extra reference on the namespace */
882 put_net(sk->sk_net);
883 net->ipv4.fibnl = sk;
880 return 0; 884 return 0;
881} 885}
882 886
883static void nl_fib_lookup_exit(struct net *net) 887static void nl_fib_lookup_exit(struct net *net)
884{ 888{
885 sock_put(fibnl); 889 /* At the last minute lie and say this is a socket for the
890 * initial network namespace. So the socket will be safe to free.
891 */
892 net->ipv4.fibnl->sk_net = get_net(&init_net);
893 sock_put(net->ipv4.fibnl);
886} 894}
887 895
888static void fib_disable_ip(struct net_device *dev, int force) 896static void fib_disable_ip(struct net_device *dev, int force)