diff options
-rw-r--r-- | include/net/netns/ipv4.h | 2 | ||||
-rw-r--r-- | net/ipv4/fib_frontend.c | 24 |
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; | |||
9 | struct ipv4_devconf; | 9 | struct ipv4_devconf; |
10 | struct fib_rules_ops; | 10 | struct fib_rules_ops; |
11 | struct hlist_head; | 11 | struct hlist_head; |
12 | struct sock; | ||
12 | 13 | ||
13 | struct netns_ipv4 { | 14 | struct 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 | ||
52 | static struct sock *fibnl; | ||
53 | |||
54 | #ifndef CONFIG_IP_MULTIPLE_TABLES | 52 | #ifndef CONFIG_IP_MULTIPLE_TABLES |
55 | 53 | ||
56 | static int __net_init fib4_rules_init(struct net *net) | 54 | static 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 | ||
846 | static void nl_fib_input(struct sk_buff *skb) | 844 | static 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 | ||
874 | static int nl_fib_lookup_init(struct net *net) | 874 | static 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 | ||
883 | static void nl_fib_lookup_exit(struct net *net) | 887 | static 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 | ||
888 | static void fib_disable_ip(struct net_device *dev, int force) | 896 | static void fib_disable_ip(struct net_device *dev, int force) |