Commit f205f6ff authored by Stephen Hemminger's avatar Stephen Hemminger

[AF_PACKET]: Convert to seq_file.

parent 951fc9df
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/ioctls.h> #include <asm/ioctls.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/poll.h> #include <linux/poll.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
...@@ -1767,23 +1768,47 @@ static struct notifier_block packet_netdev_notifier = { ...@@ -1767,23 +1768,47 @@ static struct notifier_block packet_netdev_notifier = {
}; };
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
static int packet_read_proc(char *buffer, char **start, off_t offset, static inline struct sock *packet_seq_idx(loff_t off)
int length, int *eof, void *data)
{ {
off_t pos=0;
off_t begin=0;
int len=0;
struct sock *s; struct sock *s;
struct hlist_node *node; struct hlist_node *node;
len+= sprintf(buffer,"sk RefCnt Type Proto Iface R Rmem User Inode\n"); sk_for_each(s, node, &packet_sklist) {
if (!off--)
return s;
}
return NULL;
}
static void *packet_seq_start(struct seq_file *seq, loff_t *pos)
{
read_lock(&packet_sklist_lock); read_lock(&packet_sklist_lock);
return *pos ? packet_seq_idx(*pos - 1) : SEQ_START_TOKEN;
}
sk_for_each(s, node, &packet_sklist) { static void *packet_seq_next(struct seq_file *seq, void *v, loff_t *pos)
struct packet_opt *po = pkt_sk(s); {
++*pos;
return (v == SEQ_START_TOKEN)
? sk_head(&packet_sklist)
: sk_next((struct sock*)v) ;
}
len+=sprintf(buffer+len,"%p %-6d %-4d %04x %-5d %1d %-6u %-6u %-6lu", static void packet_seq_stop(struct seq_file *seq, void *v)
{
read_unlock(&packet_sklist_lock);
}
static int packet_seq_show(struct seq_file *seq, void *v)
{
if (v == SEQ_START_TOKEN)
seq_puts(seq, "sk RefCnt Type Proto Iface R Rmem User Inode\n");
else {
struct sock *s = v;
const struct packet_opt *po = pkt_sk(s);
seq_printf(seq,
"%p %-6d %-4d %04x %-5d %1d %-6u %-6u %-6lu\n",
s, s,
atomic_read(&s->sk_refcnt), atomic_read(&s->sk_refcnt),
s->sk_type, s->sk_type,
...@@ -1792,36 +1817,37 @@ static int packet_read_proc(char *buffer, char **start, off_t offset, ...@@ -1792,36 +1817,37 @@ static int packet_read_proc(char *buffer, char **start, off_t offset,
po->running, po->running,
atomic_read(&s->sk_rmem_alloc), atomic_read(&s->sk_rmem_alloc),
sock_i_uid(s), sock_i_uid(s),
sock_i_ino(s) sock_i_ino(s) );
); }
buffer[len++]='\n'; return 0;
}
pos=begin+len; static struct seq_operations packet_seq_ops = {
if(pos<offset) { .start = packet_seq_start,
len=0; .next = packet_seq_next,
begin=pos; .stop = packet_seq_stop,
} .show = packet_seq_show,
if(pos>offset+length) };
goto done;
}
*eof = 1;
done: static int packet_seq_open(struct inode *inode, struct file *file)
read_unlock(&packet_sklist_lock); {
*start=buffer+(offset-begin); return seq_open(file, &packet_seq_ops);
len-=(offset-begin);
if(len>length)
len=length;
if(len<0)
len=0;
return len;
} }
static struct file_operations packet_seq_fops = {
.owner = THIS_MODULE,
.open = packet_seq_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
#endif #endif
static void __exit packet_exit(void) static void __exit packet_exit(void)
{ {
remove_proc_entry("net/packet", 0); proc_net_remove("packet");
unregister_netdevice_notifier(&packet_netdev_notifier); unregister_netdevice_notifier(&packet_netdev_notifier);
sock_unregister(PF_PACKET); sock_unregister(PF_PACKET);
return; return;
...@@ -1831,9 +1857,8 @@ static int __init packet_init(void) ...@@ -1831,9 +1857,8 @@ static int __init packet_init(void)
{ {
sock_register(&packet_family_ops); sock_register(&packet_family_ops);
register_netdevice_notifier(&packet_netdev_notifier); register_netdevice_notifier(&packet_netdev_notifier);
#ifdef CONFIG_PROC_FS proc_net_fops_create("packet", 0, &packet_seq_fops);
create_proc_read_entry("net/packet", 0, 0, packet_read_proc, NULL);
#endif
return 0; return 0;
} }
......
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