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,61 +1768,86 @@ static struct notifier_block packet_netdev_notifier = { ...@@ -1767,61 +1768,86 @@ 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;
len+=sprintf(buffer+len,"%p %-6d %-4d %04x %-5d %1d %-6u %-6u %-6lu", return (v == SEQ_START_TOKEN)
s, ? sk_head(&packet_sklist)
atomic_read(&s->sk_refcnt), : sk_next((struct sock*)v) ;
s->sk_type, }
ntohs(po->num),
po->ifindex, static void packet_seq_stop(struct seq_file *seq, void *v)
po->running, {
atomic_read(&s->sk_rmem_alloc), read_unlock(&packet_sklist_lock);
sock_i_uid(s), }
sock_i_ino(s)
); static int packet_seq_show(struct seq_file *seq, void *v)
{
buffer[len++]='\n'; if (v == SEQ_START_TOKEN)
seq_puts(seq, "sk RefCnt Type Proto Iface R Rmem User Inode\n");
pos=begin+len; else {
if(pos<offset) { struct sock *s = v;
len=0; const struct packet_opt *po = pkt_sk(s);
begin=pos;
} seq_printf(seq,
if(pos>offset+length) "%p %-6d %-4d %04x %-5d %1d %-6u %-6u %-6lu\n",
goto done; s,
atomic_read(&s->sk_refcnt),
s->sk_type,
ntohs(po->num),
po->ifindex,
po->running,
atomic_read(&s->sk_rmem_alloc),
sock_i_uid(s),
sock_i_ino(s) );
} }
*eof = 1;
done: return 0;
read_unlock(&packet_sklist_lock); }
*start=buffer+(offset-begin);
len-=(offset-begin); static struct seq_operations packet_seq_ops = {
if(len>length) .start = packet_seq_start,
len=length; .next = packet_seq_next,
if(len<0) .stop = packet_seq_stop,
len=0; .show = packet_seq_show,
return len; };
static int packet_seq_open(struct inode *inode, struct file *file)
{
return seq_open(file, &packet_seq_ops);
} }
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