diff options
Diffstat (limited to 'net/key/af_key.c')
-rw-r--r-- | net/key/af_key.c | 117 |
1 files changed, 79 insertions, 38 deletions
diff --git a/net/key/af_key.c b/net/key/af_key.c index 45c3c27d279a..b3ac85e808ac 100644 --- a/net/key/af_key.c +++ b/net/key/af_key.c | |||
@@ -3734,21 +3734,15 @@ static struct net_proto_family pfkey_family_ops = { | |||
3734 | }; | 3734 | }; |
3735 | 3735 | ||
3736 | #ifdef CONFIG_PROC_FS | 3736 | #ifdef CONFIG_PROC_FS |
3737 | static int pfkey_read_proc(char *buffer, char **start, off_t offset, | 3737 | static int pfkey_seq_show(struct seq_file *f, void *v) |
3738 | int length, int *eof, void *data) | ||
3739 | { | 3738 | { |
3740 | off_t pos = 0; | ||
3741 | off_t begin = 0; | ||
3742 | int len = 0; | ||
3743 | struct sock *s; | 3739 | struct sock *s; |
3744 | struct hlist_node *node; | ||
3745 | |||
3746 | len += sprintf(buffer,"sk RefCnt Rmem Wmem User Inode\n"); | ||
3747 | |||
3748 | read_lock(&pfkey_table_lock); | ||
3749 | 3740 | ||
3750 | sk_for_each(s, node, &pfkey_table) { | 3741 | s = (struct sock *)v; |
3751 | len += sprintf(buffer+len,"%p %-6d %-6u %-6u %-6u %-6lu", | 3742 | if (v == SEQ_START_TOKEN) |
3743 | seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n"); | ||
3744 | else | ||
3745 | seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n", | ||
3752 | s, | 3746 | s, |
3753 | atomic_read(&s->sk_refcnt), | 3747 | atomic_read(&s->sk_refcnt), |
3754 | atomic_read(&s->sk_rmem_alloc), | 3748 | atomic_read(&s->sk_rmem_alloc), |
@@ -3756,31 +3750,82 @@ static int pfkey_read_proc(char *buffer, char **start, off_t offset, | |||
3756 | sock_i_uid(s), | 3750 | sock_i_uid(s), |
3757 | sock_i_ino(s) | 3751 | sock_i_ino(s) |
3758 | ); | 3752 | ); |
3753 | return 0; | ||
3754 | } | ||
3759 | 3755 | ||
3760 | buffer[len++] = '\n'; | 3756 | static void *pfkey_seq_start(struct seq_file *f, loff_t *ppos) |
3757 | { | ||
3758 | struct sock *s; | ||
3759 | struct hlist_node *node; | ||
3760 | loff_t pos = *ppos; | ||
3761 | 3761 | ||
3762 | pos = begin + len; | 3762 | read_lock(&pfkey_table_lock); |
3763 | if (pos < offset) { | 3763 | if (pos == 0) |
3764 | len = 0; | 3764 | return SEQ_START_TOKEN; |
3765 | begin = pos; | ||
3766 | } | ||
3767 | if(pos > offset + length) | ||
3768 | goto done; | ||
3769 | } | ||
3770 | *eof = 1; | ||
3771 | 3765 | ||
3772 | done: | 3766 | sk_for_each(s, node, &pfkey_table) |
3767 | if (pos-- == 1) | ||
3768 | return s; | ||
3769 | |||
3770 | return NULL; | ||
3771 | } | ||
3772 | |||
3773 | static void *pfkey_seq_next(struct seq_file *f, void *v, loff_t *ppos) | ||
3774 | { | ||
3775 | ++*ppos; | ||
3776 | return (v == SEQ_START_TOKEN) ? | ||
3777 | sk_head(&pfkey_table) : | ||
3778 | sk_next((struct sock *)v); | ||
3779 | } | ||
3780 | |||
3781 | static void pfkey_seq_stop(struct seq_file *f, void *v) | ||
3782 | { | ||
3773 | read_unlock(&pfkey_table_lock); | 3783 | read_unlock(&pfkey_table_lock); |
3784 | } | ||
3785 | |||
3786 | static struct seq_operations pfkey_seq_ops = { | ||
3787 | .start = pfkey_seq_start, | ||
3788 | .next = pfkey_seq_next, | ||
3789 | .stop = pfkey_seq_stop, | ||
3790 | .show = pfkey_seq_show, | ||
3791 | }; | ||
3792 | |||
3793 | static int pfkey_seq_open(struct inode *inode, struct file *file) | ||
3794 | { | ||
3795 | return seq_open(file, &pfkey_seq_ops); | ||
3796 | } | ||
3774 | 3797 | ||
3775 | *start = buffer + (offset - begin); | 3798 | static struct file_operations pfkey_proc_ops = { |
3776 | len -= (offset - begin); | 3799 | .open = pfkey_seq_open, |
3800 | .read = seq_read, | ||
3801 | .llseek = seq_lseek, | ||
3802 | .release = seq_release, | ||
3803 | }; | ||
3777 | 3804 | ||
3778 | if (len > length) | 3805 | static int pfkey_init_proc(void) |
3779 | len = length; | 3806 | { |
3780 | if (len < 0) | 3807 | struct proc_dir_entry *e; |
3781 | len = 0; | ||
3782 | 3808 | ||
3783 | return len; | 3809 | e = create_proc_entry("pfkey", 0, init_net.proc_net); |
3810 | if (e == NULL) | ||
3811 | return -ENOMEM; | ||
3812 | |||
3813 | e->proc_fops = &pfkey_proc_ops; | ||
3814 | return 0; | ||
3815 | } | ||
3816 | |||
3817 | static void pfkey_exit_proc(void) | ||
3818 | { | ||
3819 | remove_proc_entry("net/pfkey", NULL); | ||
3820 | } | ||
3821 | #else | ||
3822 | static inline int pfkey_init_proc(void) | ||
3823 | { | ||
3824 | return 0; | ||
3825 | } | ||
3826 | |||
3827 | static inline void pfkey_exit_proc(void) | ||
3828 | { | ||
3784 | } | 3829 | } |
3785 | #endif | 3830 | #endif |
3786 | 3831 | ||
@@ -3798,7 +3843,7 @@ static struct xfrm_mgr pfkeyv2_mgr = | |||
3798 | static void __exit ipsec_pfkey_exit(void) | 3843 | static void __exit ipsec_pfkey_exit(void) |
3799 | { | 3844 | { |
3800 | xfrm_unregister_km(&pfkeyv2_mgr); | 3845 | xfrm_unregister_km(&pfkeyv2_mgr); |
3801 | remove_proc_entry("pfkey", init_net.proc_net); | 3846 | pfkey_exit_proc(); |
3802 | sock_unregister(PF_KEY); | 3847 | sock_unregister(PF_KEY); |
3803 | proto_unregister(&key_proto); | 3848 | proto_unregister(&key_proto); |
3804 | } | 3849 | } |
@@ -3813,21 +3858,17 @@ static int __init ipsec_pfkey_init(void) | |||
3813 | err = sock_register(&pfkey_family_ops); | 3858 | err = sock_register(&pfkey_family_ops); |
3814 | if (err != 0) | 3859 | if (err != 0) |
3815 | goto out_unregister_key_proto; | 3860 | goto out_unregister_key_proto; |
3816 | #ifdef CONFIG_PROC_FS | 3861 | err = pfkey_init_proc(); |
3817 | err = -ENOMEM; | 3862 | if (err != 0) |
3818 | if (create_proc_read_entry("pfkey", 0, init_net.proc_net, pfkey_read_proc, NULL) == NULL) | ||
3819 | goto out_sock_unregister; | 3863 | goto out_sock_unregister; |
3820 | #endif | ||
3821 | err = xfrm_register_km(&pfkeyv2_mgr); | 3864 | err = xfrm_register_km(&pfkeyv2_mgr); |
3822 | if (err != 0) | 3865 | if (err != 0) |
3823 | goto out_remove_proc_entry; | 3866 | goto out_remove_proc_entry; |
3824 | out: | 3867 | out: |
3825 | return err; | 3868 | return err; |
3826 | out_remove_proc_entry: | 3869 | out_remove_proc_entry: |
3827 | #ifdef CONFIG_PROC_FS | 3870 | pfkey_exit_proc(); |
3828 | remove_proc_entry("net/pfkey", NULL); | ||
3829 | out_sock_unregister: | 3871 | out_sock_unregister: |
3830 | #endif | ||
3831 | sock_unregister(PF_KEY); | 3872 | sock_unregister(PF_KEY); |
3832 | out_unregister_key_proto: | 3873 | out_unregister_key_proto: |
3833 | proto_unregister(&key_proto); | 3874 | proto_unregister(&key_proto); |