aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/fib_frontend.c
diff options
context:
space:
mode:
authorDenis V. Lunev <den@openvz.org>2008-01-10 06:28:55 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 18:01:32 -0500
commit6bd48fcf73019219495f7599028296c65b749bb4 (patch)
tree571e106537727edaf407ac4e43de433b139370f6 /net/ipv4/fib_frontend.c
parente4aef8aea31e6fc61b33a57120968a6e9824d138 (diff)
[NETNS]: Provide correct namespace for fibnl netlink socket.
This patch makes the netlink socket to be per namespace. That allows to have each namespace its own socket for routing queries. Acked-by: Benjamin Thery <benjamin.thery@bull.net> Acked-by: Daniel Lezcano <dlezcano@fr.ibm.com> Signed-off-by: Denis V. Lunev <den@openvz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/fib_frontend.c')
-rw-r--r--net/ipv4/fib_frontend.c24
1 files changed, 16 insertions, 8 deletions
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)