Commit 967a2af0 authored by Stephen Hemminger's avatar Stephen Hemminger

[NET]: Convert af_netlink.c over to seq_file.

parent 8ab34cfc
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/security.h> #include <linux/security.h>
...@@ -964,27 +965,73 @@ int netlink_post(int unit, struct sk_buff *skb) ...@@ -964,27 +965,73 @@ int netlink_post(int unit, struct sk_buff *skb)
#endif #endif
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
static int netlink_read_proc(char *buffer, char **start, off_t offset, static struct sock *netlink_seq_socket_idx(struct seq_file *seq, loff_t pos)
int length, int *eof, void *data)
{ {
off_t pos=0;
off_t begin=0;
int len=0;
int i; int i;
struct sock *s; struct sock *s;
struct hlist_node *node; struct hlist_node *node;
loff_t off = 0;
len+= sprintf(buffer,"sk Eth Pid Groups "
"Rmem Wmem Dump Locks\n");
for (i=0; i<MAX_LINKS; i++) { for (i=0; i<MAX_LINKS; i++) {
read_lock(&nl_table_lock);
sk_for_each(s, node, &nl_table[i]) { sk_for_each(s, node, &nl_table[i]) {
if (off == pos) {
seq->private = (void *) i;
return s;
}
++off;
}
}
return NULL;
}
static void *netlink_seq_start(struct seq_file *seq, loff_t *pos)
{
read_lock(&nl_table_lock);
return *pos ? netlink_seq_socket_idx(seq, *pos - 1) : (void *) 1;
}
static void *netlink_seq_next(struct seq_file *seq, void *v, loff_t *pos)
{
struct sock *s;
++*pos;
if (v == (void *) 1)
return netlink_seq_socket_idx(seq, 0);
s = sk_next(v);
if (!s) {
int i = (int) seq->private;
while (++i < MAX_LINKS) {
s = sk_head(&nl_table[i]);
if (s) {
seq->private = (void *) i;
break;
}
}
}
return s;
}
static void netlink_seq_stop(struct seq_file *seq, void *v)
{
read_unlock(&nl_table_lock);
}
static int netlink_seq_show(struct seq_file *seq, void *v)
{
if (v == (void *)1)
seq_puts(seq,
"sk Eth Pid Groups "
"Rmem Wmem Dump Locks\n");
else {
struct sock *s = v;
struct netlink_opt *nlk = nlk_sk(s); struct netlink_opt *nlk = nlk_sk(s);
len+=sprintf(buffer+len,"%p %-3d %-6d %08x %-8d %-8d %p %d", seq_printf(seq, "%p %-3d %-6d %08x %-8d %-8d %p %d\n",
s, s,
s->sk_protocol, s->sk_protocol,
nlk->pid, nlk->pid,
...@@ -995,31 +1042,31 @@ static int netlink_read_proc(char *buffer, char **start, off_t offset, ...@@ -995,31 +1042,31 @@ static int netlink_read_proc(char *buffer, char **start, off_t offset,
atomic_read(&s->sk_refcnt) atomic_read(&s->sk_refcnt)
); );
buffer[len++]='\n';
pos=begin+len;
if(pos<offset) {
len=0;
begin=pos;
}
if(pos>offset+length) {
read_unlock(&nl_table_lock);
goto done;
}
}
read_unlock(&nl_table_lock);
} }
*eof = 1; return 0;
}
done:
*start=buffer+(offset-begin); struct seq_operations netlink_seq_ops = {
len-=(offset-begin); .start = netlink_seq_start,
if(len>length) .next = netlink_seq_next,
len=length; .stop = netlink_seq_stop,
if(len<0) .show = netlink_seq_show,
len=0; };
return len;
static int netlink_seq_open(struct inode *inode, struct file *file)
{
return seq_open(file, &netlink_seq_ops);
} }
static struct file_operations netlink_seq_fops = {
.owner = THIS_MODULE,
.open = netlink_seq_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
#endif #endif
int netlink_register_notifier(struct notifier_block *nb) int netlink_register_notifier(struct notifier_block *nb)
...@@ -1069,7 +1116,7 @@ static int __init netlink_proto_init(void) ...@@ -1069,7 +1116,7 @@ static int __init netlink_proto_init(void)
} }
sock_register(&netlink_family_ops); sock_register(&netlink_family_ops);
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
create_proc_read_entry("net/netlink", 0, 0, netlink_read_proc, NULL); proc_net_fops_create("netlink", 0, &netlink_seq_fops);
#endif #endif
/* The netlink device handler may be needed early. */ /* The netlink device handler may be needed early. */
rtnetlink_init(); rtnetlink_init();
...@@ -1079,7 +1126,7 @@ static int __init netlink_proto_init(void) ...@@ -1079,7 +1126,7 @@ static int __init netlink_proto_init(void)
static void __exit netlink_proto_exit(void) static void __exit netlink_proto_exit(void)
{ {
sock_unregister(PF_NETLINK); sock_unregister(PF_NETLINK);
remove_proc_entry("net/netlink", NULL); proc_net_remove("netlink");
} }
core_initcall(netlink_proto_init); core_initcall(netlink_proto_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment