Commit fd24de89 authored by Christoph Hellwig's avatar Christoph Hellwig

netfilter/xt_hashlimit: switch to proc_create_{seq,single}_data

And use proc private data directly instead of doing a detour
through seq->private.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent 71a5053a
...@@ -57,9 +57,9 @@ static inline struct hashlimit_net *hashlimit_pernet(struct net *net) ...@@ -57,9 +57,9 @@ static inline struct hashlimit_net *hashlimit_pernet(struct net *net)
} }
/* need to declare this at the top */ /* need to declare this at the top */
static const struct file_operations dl_file_ops_v2; static const struct seq_operations dl_seq_ops_v2;
static const struct file_operations dl_file_ops_v1; static const struct seq_operations dl_seq_ops_v1;
static const struct file_operations dl_file_ops; static const struct seq_operations dl_seq_ops;
/* hash table crap */ /* hash table crap */
struct dsthash_dst { struct dsthash_dst {
...@@ -272,7 +272,7 @@ static int htable_create(struct net *net, struct hashlimit_cfg3 *cfg, ...@@ -272,7 +272,7 @@ static int htable_create(struct net *net, struct hashlimit_cfg3 *cfg,
{ {
struct hashlimit_net *hashlimit_net = hashlimit_pernet(net); struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
struct xt_hashlimit_htable *hinfo; struct xt_hashlimit_htable *hinfo;
const struct file_operations *fops; const struct seq_operations *ops;
unsigned int size, i; unsigned int size, i;
int ret; int ret;
...@@ -321,19 +321,19 @@ static int htable_create(struct net *net, struct hashlimit_cfg3 *cfg, ...@@ -321,19 +321,19 @@ static int htable_create(struct net *net, struct hashlimit_cfg3 *cfg,
switch (revision) { switch (revision) {
case 1: case 1:
fops = &dl_file_ops_v1; ops = &dl_seq_ops_v1;
break; break;
case 2: case 2:
fops = &dl_file_ops_v2; ops = &dl_seq_ops_v2;
break; break;
default: default:
fops = &dl_file_ops; ops = &dl_seq_ops;
} }
hinfo->pde = proc_create_data(name, 0, hinfo->pde = proc_create_seq_data(name, 0,
(family == NFPROTO_IPV4) ? (family == NFPROTO_IPV4) ?
hashlimit_net->ipt_hashlimit : hashlimit_net->ip6t_hashlimit, hashlimit_net->ipt_hashlimit : hashlimit_net->ip6t_hashlimit,
fops, hinfo); ops, hinfo);
if (hinfo->pde == NULL) { if (hinfo->pde == NULL) {
kfree(hinfo->name); kfree(hinfo->name);
vfree(hinfo); vfree(hinfo);
...@@ -1057,7 +1057,7 @@ static struct xt_match hashlimit_mt_reg[] __read_mostly = { ...@@ -1057,7 +1057,7 @@ static struct xt_match hashlimit_mt_reg[] __read_mostly = {
static void *dl_seq_start(struct seq_file *s, loff_t *pos) static void *dl_seq_start(struct seq_file *s, loff_t *pos)
__acquires(htable->lock) __acquires(htable->lock)
{ {
struct xt_hashlimit_htable *htable = s->private; struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->private));
unsigned int *bucket; unsigned int *bucket;
spin_lock_bh(&htable->lock); spin_lock_bh(&htable->lock);
...@@ -1074,7 +1074,7 @@ static void *dl_seq_start(struct seq_file *s, loff_t *pos) ...@@ -1074,7 +1074,7 @@ static void *dl_seq_start(struct seq_file *s, loff_t *pos)
static void *dl_seq_next(struct seq_file *s, void *v, loff_t *pos) static void *dl_seq_next(struct seq_file *s, void *v, loff_t *pos)
{ {
struct xt_hashlimit_htable *htable = s->private; struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->private));
unsigned int *bucket = v; unsigned int *bucket = v;
*pos = ++(*bucket); *pos = ++(*bucket);
...@@ -1088,7 +1088,7 @@ static void *dl_seq_next(struct seq_file *s, void *v, loff_t *pos) ...@@ -1088,7 +1088,7 @@ static void *dl_seq_next(struct seq_file *s, void *v, loff_t *pos)
static void dl_seq_stop(struct seq_file *s, void *v) static void dl_seq_stop(struct seq_file *s, void *v)
__releases(htable->lock) __releases(htable->lock)
{ {
struct xt_hashlimit_htable *htable = s->private; struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->private));
unsigned int *bucket = v; unsigned int *bucket = v;
if (!IS_ERR(bucket)) if (!IS_ERR(bucket))
...@@ -1130,7 +1130,7 @@ static void dl_seq_print(struct dsthash_ent *ent, u_int8_t family, ...@@ -1130,7 +1130,7 @@ static void dl_seq_print(struct dsthash_ent *ent, u_int8_t family,
static int dl_seq_real_show_v2(struct dsthash_ent *ent, u_int8_t family, static int dl_seq_real_show_v2(struct dsthash_ent *ent, u_int8_t family,
struct seq_file *s) struct seq_file *s)
{ {
const struct xt_hashlimit_htable *ht = s->private; struct xt_hashlimit_htable *ht = PDE_DATA(file_inode(s->private));
spin_lock(&ent->lock); spin_lock(&ent->lock);
/* recalculate to show accurate numbers */ /* recalculate to show accurate numbers */
...@@ -1145,7 +1145,7 @@ static int dl_seq_real_show_v2(struct dsthash_ent *ent, u_int8_t family, ...@@ -1145,7 +1145,7 @@ static int dl_seq_real_show_v2(struct dsthash_ent *ent, u_int8_t family,
static int dl_seq_real_show_v1(struct dsthash_ent *ent, u_int8_t family, static int dl_seq_real_show_v1(struct dsthash_ent *ent, u_int8_t family,
struct seq_file *s) struct seq_file *s)
{ {
const struct xt_hashlimit_htable *ht = s->private; struct xt_hashlimit_htable *ht = PDE_DATA(file_inode(s->private));
spin_lock(&ent->lock); spin_lock(&ent->lock);
/* recalculate to show accurate numbers */ /* recalculate to show accurate numbers */
...@@ -1160,7 +1160,7 @@ static int dl_seq_real_show_v1(struct dsthash_ent *ent, u_int8_t family, ...@@ -1160,7 +1160,7 @@ static int dl_seq_real_show_v1(struct dsthash_ent *ent, u_int8_t family,
static int dl_seq_real_show(struct dsthash_ent *ent, u_int8_t family, static int dl_seq_real_show(struct dsthash_ent *ent, u_int8_t family,
struct seq_file *s) struct seq_file *s)
{ {
const struct xt_hashlimit_htable *ht = s->private; struct xt_hashlimit_htable *ht = PDE_DATA(file_inode(s->private));
spin_lock(&ent->lock); spin_lock(&ent->lock);
/* recalculate to show accurate numbers */ /* recalculate to show accurate numbers */
...@@ -1174,7 +1174,7 @@ static int dl_seq_real_show(struct dsthash_ent *ent, u_int8_t family, ...@@ -1174,7 +1174,7 @@ static int dl_seq_real_show(struct dsthash_ent *ent, u_int8_t family,
static int dl_seq_show_v2(struct seq_file *s, void *v) static int dl_seq_show_v2(struct seq_file *s, void *v)
{ {
struct xt_hashlimit_htable *htable = s->private; struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->private));
unsigned int *bucket = (unsigned int *)v; unsigned int *bucket = (unsigned int *)v;
struct dsthash_ent *ent; struct dsthash_ent *ent;
...@@ -1188,7 +1188,7 @@ static int dl_seq_show_v2(struct seq_file *s, void *v) ...@@ -1188,7 +1188,7 @@ static int dl_seq_show_v2(struct seq_file *s, void *v)
static int dl_seq_show_v1(struct seq_file *s, void *v) static int dl_seq_show_v1(struct seq_file *s, void *v)
{ {
struct xt_hashlimit_htable *htable = s->private; struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->private));
unsigned int *bucket = v; unsigned int *bucket = v;
struct dsthash_ent *ent; struct dsthash_ent *ent;
...@@ -1202,7 +1202,7 @@ static int dl_seq_show_v1(struct seq_file *s, void *v) ...@@ -1202,7 +1202,7 @@ static int dl_seq_show_v1(struct seq_file *s, void *v)
static int dl_seq_show(struct seq_file *s, void *v) static int dl_seq_show(struct seq_file *s, void *v)
{ {
struct xt_hashlimit_htable *htable = s->private; struct xt_hashlimit_htable *htable = PDE_DATA(file_inode(s->private));
unsigned int *bucket = v; unsigned int *bucket = v;
struct dsthash_ent *ent; struct dsthash_ent *ent;
...@@ -1235,62 +1235,6 @@ static const struct seq_operations dl_seq_ops = { ...@@ -1235,62 +1235,6 @@ static const struct seq_operations dl_seq_ops = {
.show = dl_seq_show .show = dl_seq_show
}; };
static int dl_proc_open_v2(struct inode *inode, struct file *file)
{
int ret = seq_open(file, &dl_seq_ops_v2);
if (!ret) {
struct seq_file *sf = file->private_data;
sf->private = PDE_DATA(inode);
}
return ret;
}
static int dl_proc_open_v1(struct inode *inode, struct file *file)
{
int ret = seq_open(file, &dl_seq_ops_v1);
if (!ret) {
struct seq_file *sf = file->private_data;
sf->private = PDE_DATA(inode);
}
return ret;
}
static int dl_proc_open(struct inode *inode, struct file *file)
{
int ret = seq_open(file, &dl_seq_ops);
if (!ret) {
struct seq_file *sf = file->private_data;
sf->private = PDE_DATA(inode);
}
return ret;
}
static const struct file_operations dl_file_ops_v2 = {
.open = dl_proc_open_v2,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release
};
static const struct file_operations dl_file_ops_v1 = {
.open = dl_proc_open_v1,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release
};
static const struct file_operations dl_file_ops = {
.open = dl_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release
};
static int __net_init hashlimit_proc_net_init(struct net *net) static int __net_init hashlimit_proc_net_init(struct net *net)
{ {
struct hashlimit_net *hashlimit_net = hashlimit_pernet(net); struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
......
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