Commit 7013ec30e0e2bc5b1e602e19a4e0668f9b7c0a72
Committed by
David S. Miller
1 parent
07fb0f1799
Exists in
master
and in
39 other branches
netns PF_KEY: per-netns /proc/pfkey
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 1 changed file with 17 additions and 17 deletions Side-by-side Diff
net/key/af_key.c
... | ... | @@ -3673,7 +3673,7 @@ |
3673 | 3673 | |
3674 | 3674 | static void *pfkey_seq_start(struct seq_file *f, loff_t *ppos) |
3675 | 3675 | { |
3676 | - struct net *net = &init_net; | |
3676 | + struct net *net = seq_file_net(f); | |
3677 | 3677 | struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id); |
3678 | 3678 | struct sock *s; |
3679 | 3679 | struct hlist_node *node; |
... | ... | @@ -3692,7 +3692,7 @@ |
3692 | 3692 | |
3693 | 3693 | static void *pfkey_seq_next(struct seq_file *f, void *v, loff_t *ppos) |
3694 | 3694 | { |
3695 | - struct net *net = &init_net; | |
3695 | + struct net *net = seq_file_net(f); | |
3696 | 3696 | struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id); |
3697 | 3697 | |
3698 | 3698 | ++*ppos; |
3699 | 3699 | |
3700 | 3700 | |
3701 | 3701 | |
3702 | 3702 | |
3703 | 3703 | |
3704 | 3704 | |
3705 | 3705 | |
... | ... | @@ -3715,38 +3715,39 @@ |
3715 | 3715 | |
3716 | 3716 | static int pfkey_seq_open(struct inode *inode, struct file *file) |
3717 | 3717 | { |
3718 | - return seq_open(file, &pfkey_seq_ops); | |
3718 | + return seq_open_net(inode, file, &pfkey_seq_ops, | |
3719 | + sizeof(struct seq_net_private)); | |
3719 | 3720 | } |
3720 | 3721 | |
3721 | 3722 | static struct file_operations pfkey_proc_ops = { |
3722 | 3723 | .open = pfkey_seq_open, |
3723 | 3724 | .read = seq_read, |
3724 | 3725 | .llseek = seq_lseek, |
3725 | - .release = seq_release, | |
3726 | + .release = seq_release_net, | |
3726 | 3727 | }; |
3727 | 3728 | |
3728 | -static int pfkey_init_proc(void) | |
3729 | +static int __net_init pfkey_init_proc(struct net *net) | |
3729 | 3730 | { |
3730 | 3731 | struct proc_dir_entry *e; |
3731 | 3732 | |
3732 | - e = proc_net_fops_create(&init_net, "pfkey", 0, &pfkey_proc_ops); | |
3733 | + e = proc_net_fops_create(net, "pfkey", 0, &pfkey_proc_ops); | |
3733 | 3734 | if (e == NULL) |
3734 | 3735 | return -ENOMEM; |
3735 | 3736 | |
3736 | 3737 | return 0; |
3737 | 3738 | } |
3738 | 3739 | |
3739 | -static void pfkey_exit_proc(void) | |
3740 | +static void pfkey_exit_proc(struct net *net) | |
3740 | 3741 | { |
3741 | - proc_net_remove(&init_net, "pfkey"); | |
3742 | + proc_net_remove(net, "pfkey"); | |
3742 | 3743 | } |
3743 | 3744 | #else |
3744 | -static inline int pfkey_init_proc(void) | |
3745 | +static int __net_init pfkey_init_proc(struct net *net) | |
3745 | 3746 | { |
3746 | 3747 | return 0; |
3747 | 3748 | } |
3748 | 3749 | |
3749 | -static inline void pfkey_exit_proc(void) | |
3750 | +static void pfkey_exit_proc(struct net *net) | |
3750 | 3751 | { |
3751 | 3752 | } |
3752 | 3753 | #endif |
3753 | 3754 | |
... | ... | @@ -3777,8 +3778,12 @@ |
3777 | 3778 | rv = net_assign_generic(net, pfkey_net_id, net_pfkey); |
3778 | 3779 | if (rv < 0) |
3779 | 3780 | goto out_assign; |
3781 | + rv = pfkey_init_proc(net); | |
3782 | + if (rv < 0) | |
3783 | + goto out_proc; | |
3780 | 3784 | return 0; |
3781 | 3785 | |
3786 | +out_proc: | |
3782 | 3787 | out_assign: |
3783 | 3788 | kfree(net_pfkey); |
3784 | 3789 | out_kmalloc: |
... | ... | @@ -3789,6 +3794,7 @@ |
3789 | 3794 | { |
3790 | 3795 | struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id); |
3791 | 3796 | |
3797 | + pfkey_exit_proc(net); | |
3792 | 3798 | BUG_ON(!hlist_empty(&net_pfkey->table)); |
3793 | 3799 | kfree(net_pfkey); |
3794 | 3800 | } |
... | ... | @@ -3802,7 +3808,6 @@ |
3802 | 3808 | { |
3803 | 3809 | unregister_pernet_gen_subsys(pfkey_net_id, &pfkey_net_ops); |
3804 | 3810 | xfrm_unregister_km(&pfkeyv2_mgr); |
3805 | - pfkey_exit_proc(); | |
3806 | 3811 | sock_unregister(PF_KEY); |
3807 | 3812 | proto_unregister(&key_proto); |
3808 | 3813 | } |
3809 | 3814 | |
... | ... | @@ -3817,12 +3822,9 @@ |
3817 | 3822 | err = sock_register(&pfkey_family_ops); |
3818 | 3823 | if (err != 0) |
3819 | 3824 | goto out_unregister_key_proto; |
3820 | - err = pfkey_init_proc(); | |
3821 | - if (err != 0) | |
3822 | - goto out_sock_unregister; | |
3823 | 3825 | err = xfrm_register_km(&pfkeyv2_mgr); |
3824 | 3826 | if (err != 0) |
3825 | - goto out_remove_proc_entry; | |
3827 | + goto out_sock_unregister; | |
3826 | 3828 | err = register_pernet_gen_subsys(&pfkey_net_id, &pfkey_net_ops); |
3827 | 3829 | if (err != 0) |
3828 | 3830 | goto out_xfrm_unregister_km; |
... | ... | @@ -3830,8 +3832,6 @@ |
3830 | 3832 | return err; |
3831 | 3833 | out_xfrm_unregister_km: |
3832 | 3834 | xfrm_unregister_km(&pfkeyv2_mgr); |
3833 | -out_remove_proc_entry: | |
3834 | - pfkey_exit_proc(); | |
3835 | 3835 | out_sock_unregister: |
3836 | 3836 | sock_unregister(PF_KEY); |
3837 | 3837 | out_unregister_key_proto: |