aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/net/udp.h8
-rw-r--r--net/ipv4/udp.c82
-rw-r--r--net/ipv4/udplite.c10
-rw-r--r--net/ipv6/udp.c10
-rw-r--r--net/ipv6/udplite.c10
5 files changed, 46 insertions, 74 deletions
diff --git a/include/net/udp.h b/include/net/udp.h
index 635940d374a..24a41fa3164 100644
--- a/include/net/udp.h
+++ b/include/net/udp.h
@@ -185,20 +185,18 @@ DECLARE_SNMP_STAT(struct udp_mib, udplite_stats_in6);
/* /proc */
struct udp_seq_afinfo {
- struct module *owner;
char *name;
sa_family_t family;
struct hlist_head *hashtable;
- int (*seq_show) (struct seq_file *m, void *v);
- struct file_operations *seq_fops;
+ struct file_operations seq_fops;
+ struct seq_operations seq_ops;
};
struct udp_iter_state {
- struct net *net;
+ struct seq_net_private p;
sa_family_t family;
struct hlist_head *hashtable;
int bucket;
- struct seq_operations seq_ops;
};
#ifdef CONFIG_PROC_FS
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 0255f373b3e..9143645f9a1 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1503,7 +1503,7 @@ static struct sock *udp_get_first(struct seq_file *seq)
{
struct sock *sk;
struct udp_iter_state *state = seq->private;
- struct net *net = state->net;
+ struct net *net = seq_file_net(seq);
for (state->bucket = 0; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) {
struct hlist_node *node;
@@ -1522,7 +1522,7 @@ found:
static struct sock *udp_get_next(struct seq_file *seq, struct sock *sk)
{
struct udp_iter_state *state = seq->private;
- struct net *net = state->net;
+ struct net *net = seq_file_net(seq);
do {
sk = sk_next(sk);
@@ -1576,50 +1576,18 @@ static void udp_seq_stop(struct seq_file *seq, void *v)
static int udp_seq_open(struct inode *inode, struct file *file)
{
struct udp_seq_afinfo *afinfo = PDE(inode)->data;
- struct seq_file *seq;
- struct net *net;
- int rc = -ENOMEM;
- struct udp_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
-
- if (!s)
- goto out;
+ struct udp_iter_state *s;
+ int err;
- rc = -ENXIO;
- net = get_proc_net(inode);
- if (!net)
- goto out_kfree;
+ err = seq_open_net(inode, file, &afinfo->seq_ops,
+ sizeof(struct udp_iter_state));
+ if (err < 0)
+ return err;
+ s = ((struct seq_file *)file->private_data)->private;
s->family = afinfo->family;
s->hashtable = afinfo->hashtable;
- s->seq_ops.start = udp_seq_start;
- s->seq_ops.next = udp_seq_next;
- s->seq_ops.show = afinfo->seq_show;
- s->seq_ops.stop = udp_seq_stop;
- s->net = net;
-
- rc = seq_open(file, &s->seq_ops);
- if (rc)
- goto out_put_net;
-
- seq = file->private_data;
- seq->private = s;
-out:
- return rc;
-out_put_net:
- put_net(net);
-out_kfree:
- kfree(s);
- goto out;
-}
-
-static int udp_seq_release(struct inode *inode, struct file *file)
-{
- struct seq_file *seq = file->private_data;
- struct udp_iter_state *s = seq->private;
-
- put_net(s->net);
- seq_release_private(inode, file);
- return 0;
+ return err;
}
/* ------------------------------------------------------------------------ */
@@ -1628,15 +1596,16 @@ int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo)
struct proc_dir_entry *p;
int rc = 0;
- if (!afinfo)
- return -EINVAL;
- afinfo->seq_fops->owner = afinfo->owner;
- afinfo->seq_fops->open = udp_seq_open;
- afinfo->seq_fops->read = seq_read;
- afinfo->seq_fops->llseek = seq_lseek;
- afinfo->seq_fops->release = udp_seq_release;
+ afinfo->seq_fops.open = udp_seq_open;
+ afinfo->seq_fops.read = seq_read;
+ afinfo->seq_fops.llseek = seq_lseek;
+ afinfo->seq_fops.release = seq_release_net;
+
+ afinfo->seq_ops.start = udp_seq_start;
+ afinfo->seq_ops.next = udp_seq_next;
+ afinfo->seq_ops.stop = udp_seq_stop;
- p = proc_net_fops_create(net, afinfo->name, S_IRUGO, afinfo->seq_fops);
+ p = proc_net_fops_create(net, afinfo->name, S_IRUGO, &afinfo->seq_fops);
if (p)
p->data = afinfo;
else
@@ -1646,10 +1615,7 @@ int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo)
void udp_proc_unregister(struct net *net, struct udp_seq_afinfo *afinfo)
{
- if (!afinfo)
- return;
proc_net_remove(net, afinfo->name);
- memset(afinfo->seq_fops, 0, sizeof(*afinfo->seq_fops));
}
/* ------------------------------------------------------------------------ */
@@ -1688,14 +1654,16 @@ int udp4_seq_show(struct seq_file *seq, void *v)
}
/* ------------------------------------------------------------------------ */
-static struct file_operations udp4_seq_fops;
static struct udp_seq_afinfo udp4_seq_afinfo = {
- .owner = THIS_MODULE,
.name = "udp",
.family = AF_INET,
.hashtable = udp_hash,
- .seq_show = udp4_seq_show,
- .seq_fops = &udp4_seq_fops,
+ .seq_fops = {
+ .owner = THIS_MODULE,
+ },
+ .seq_ops = {
+ .show = udp4_seq_show,
+ },
};
static int udp4_proc_init_net(struct net *net)
diff --git a/net/ipv4/udplite.c b/net/ipv4/udplite.c
index 7c1e0271c0d..72ce26b6c4d 100644
--- a/net/ipv4/udplite.c
+++ b/net/ipv4/udplite.c
@@ -71,14 +71,16 @@ static struct inet_protosw udplite4_protosw = {
};
#ifdef CONFIG_PROC_FS
-static struct file_operations udplite4_seq_fops;
static struct udp_seq_afinfo udplite4_seq_afinfo = {
- .owner = THIS_MODULE,
.name = "udplite",
.family = AF_INET,
.hashtable = udplite_hash,
- .seq_show = udp4_seq_show,
- .seq_fops = &udplite4_seq_fops,
+ .seq_fops = {
+ .owner = THIS_MODULE,
+ },
+ .seq_ops = {
+ .show = udp4_seq_show,
+ },
};
static int udplite4_proc_init_net(struct net *net)
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 463ae4d448a..30ef7dc5d40 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -977,14 +977,16 @@ int udp6_seq_show(struct seq_file *seq, void *v)
return 0;
}
-static struct file_operations udp6_seq_fops;
static struct udp_seq_afinfo udp6_seq_afinfo = {
- .owner = THIS_MODULE,
.name = "udp6",
.family = AF_INET6,
.hashtable = udp_hash,
- .seq_show = udp6_seq_show,
- .seq_fops = &udp6_seq_fops,
+ .seq_fops = {
+ .owner = THIS_MODULE,
+ },
+ .seq_ops = {
+ .show = udp6_seq_show,
+ },
};
int udp6_proc_init(struct net *net)
diff --git a/net/ipv6/udplite.c b/net/ipv6/udplite.c
index c5f5357d115..491efd00a86 100644
--- a/net/ipv6/udplite.c
+++ b/net/ipv6/udplite.c
@@ -96,14 +96,16 @@ void udplitev6_exit(void)
}
#ifdef CONFIG_PROC_FS
-static struct file_operations udplite6_seq_fops;
static struct udp_seq_afinfo udplite6_seq_afinfo = {
- .owner = THIS_MODULE,
.name = "udplite6",
.family = AF_INET6,
.hashtable = udplite_hash,
- .seq_show = udp6_seq_show,
- .seq_fops = &udplite6_seq_fops,
+ .seq_fops = {
+ .owner = THIS_MODULE,
+ },
+ .seq_ops = {
+ .show = udp6_seq_show,
+ },
};
static int udplite6_proc_init_net(struct net *net)