netfilter/x_tables: simplify ѕeq_file code
Just use the address family from the proc private data instead of copying it into per-file data. Signed-off-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
parent
2ad17b1950
commit
1d98c16d44
@ -1489,15 +1489,10 @@ void *xt_unregister_table(struct xt_table *table)
|
|||||||
EXPORT_SYMBOL_GPL(xt_unregister_table);
|
EXPORT_SYMBOL_GPL(xt_unregister_table);
|
||||||
|
|
||||||
#ifdef CONFIG_PROC_FS
|
#ifdef CONFIG_PROC_FS
|
||||||
struct xt_names_priv {
|
|
||||||
struct seq_net_private p;
|
|
||||||
u_int8_t af;
|
|
||||||
};
|
|
||||||
static void *xt_table_seq_start(struct seq_file *seq, loff_t *pos)
|
static void *xt_table_seq_start(struct seq_file *seq, loff_t *pos)
|
||||||
{
|
{
|
||||||
struct xt_names_priv *priv = seq->private;
|
|
||||||
struct net *net = seq_file_net(seq);
|
struct net *net = seq_file_net(seq);
|
||||||
u_int8_t af = priv->af;
|
u_int8_t af = (unsigned long)PDE_DATA(file_inode(seq->file));
|
||||||
|
|
||||||
mutex_lock(&xt[af].mutex);
|
mutex_lock(&xt[af].mutex);
|
||||||
return seq_list_start(&net->xt.tables[af], *pos);
|
return seq_list_start(&net->xt.tables[af], *pos);
|
||||||
@ -1505,17 +1500,15 @@ static void *xt_table_seq_start(struct seq_file *seq, loff_t *pos)
|
|||||||
|
|
||||||
static void *xt_table_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
static void *xt_table_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
||||||
{
|
{
|
||||||
struct xt_names_priv *priv = seq->private;
|
|
||||||
struct net *net = seq_file_net(seq);
|
struct net *net = seq_file_net(seq);
|
||||||
u_int8_t af = priv->af;
|
u_int8_t af = (unsigned long)PDE_DATA(file_inode(seq->file));
|
||||||
|
|
||||||
return seq_list_next(v, &net->xt.tables[af], pos);
|
return seq_list_next(v, &net->xt.tables[af], pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xt_table_seq_stop(struct seq_file *seq, void *v)
|
static void xt_table_seq_stop(struct seq_file *seq, void *v)
|
||||||
{
|
{
|
||||||
struct xt_names_priv *priv = seq->private;
|
u_int8_t af = (unsigned long)PDE_DATA(file_inode(seq->file));
|
||||||
u_int8_t af = priv->af;
|
|
||||||
|
|
||||||
mutex_unlock(&xt[af].mutex);
|
mutex_unlock(&xt[af].mutex);
|
||||||
}
|
}
|
||||||
@ -1538,16 +1531,8 @@ static const struct seq_operations xt_table_seq_ops = {
|
|||||||
|
|
||||||
static int xt_table_open(struct inode *inode, struct file *file)
|
static int xt_table_open(struct inode *inode, struct file *file)
|
||||||
{
|
{
|
||||||
int ret;
|
return seq_open_net(inode, file, &xt_table_seq_ops,
|
||||||
struct xt_names_priv *priv;
|
sizeof(struct seq_net_private));
|
||||||
|
|
||||||
ret = seq_open_net(inode, file, &xt_table_seq_ops,
|
|
||||||
sizeof(struct xt_names_priv));
|
|
||||||
if (!ret) {
|
|
||||||
priv = ((struct seq_file *)file->private_data)->private;
|
|
||||||
priv->af = (unsigned long)PDE_DATA(inode);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct file_operations xt_table_ops = {
|
static const struct file_operations xt_table_ops = {
|
||||||
@ -1563,7 +1548,7 @@ static const struct file_operations xt_table_ops = {
|
|||||||
*/
|
*/
|
||||||
struct nf_mttg_trav {
|
struct nf_mttg_trav {
|
||||||
struct list_head *head, *curr;
|
struct list_head *head, *curr;
|
||||||
uint8_t class, nfproto;
|
uint8_t class;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -1580,6 +1565,7 @@ static void *xt_mttg_seq_next(struct seq_file *seq, void *v, loff_t *ppos,
|
|||||||
[MTTG_TRAV_NFP_UNSPEC] = MTTG_TRAV_NFP_SPEC,
|
[MTTG_TRAV_NFP_UNSPEC] = MTTG_TRAV_NFP_SPEC,
|
||||||
[MTTG_TRAV_NFP_SPEC] = MTTG_TRAV_DONE,
|
[MTTG_TRAV_NFP_SPEC] = MTTG_TRAV_DONE,
|
||||||
};
|
};
|
||||||
|
uint8_t nfproto = (unsigned long)PDE_DATA(file_inode(seq->file));
|
||||||
struct nf_mttg_trav *trav = seq->private;
|
struct nf_mttg_trav *trav = seq->private;
|
||||||
|
|
||||||
switch (trav->class) {
|
switch (trav->class) {
|
||||||
@ -1594,9 +1580,9 @@ static void *xt_mttg_seq_next(struct seq_file *seq, void *v, loff_t *ppos,
|
|||||||
if (trav->curr != trav->head)
|
if (trav->curr != trav->head)
|
||||||
break;
|
break;
|
||||||
mutex_unlock(&xt[NFPROTO_UNSPEC].mutex);
|
mutex_unlock(&xt[NFPROTO_UNSPEC].mutex);
|
||||||
mutex_lock(&xt[trav->nfproto].mutex);
|
mutex_lock(&xt[nfproto].mutex);
|
||||||
trav->head = trav->curr = is_target ?
|
trav->head = trav->curr = is_target ?
|
||||||
&xt[trav->nfproto].target : &xt[trav->nfproto].match;
|
&xt[nfproto].target : &xt[nfproto].match;
|
||||||
trav->class = next_class[trav->class];
|
trav->class = next_class[trav->class];
|
||||||
break;
|
break;
|
||||||
case MTTG_TRAV_NFP_SPEC:
|
case MTTG_TRAV_NFP_SPEC:
|
||||||
@ -1628,6 +1614,7 @@ static void *xt_mttg_seq_start(struct seq_file *seq, loff_t *pos,
|
|||||||
|
|
||||||
static void xt_mttg_seq_stop(struct seq_file *seq, void *v)
|
static void xt_mttg_seq_stop(struct seq_file *seq, void *v)
|
||||||
{
|
{
|
||||||
|
uint8_t nfproto = (unsigned long)PDE_DATA(file_inode(seq->file));
|
||||||
struct nf_mttg_trav *trav = seq->private;
|
struct nf_mttg_trav *trav = seq->private;
|
||||||
|
|
||||||
switch (trav->class) {
|
switch (trav->class) {
|
||||||
@ -1635,7 +1622,7 @@ static void xt_mttg_seq_stop(struct seq_file *seq, void *v)
|
|||||||
mutex_unlock(&xt[NFPROTO_UNSPEC].mutex);
|
mutex_unlock(&xt[NFPROTO_UNSPEC].mutex);
|
||||||
break;
|
break;
|
||||||
case MTTG_TRAV_NFP_SPEC:
|
case MTTG_TRAV_NFP_SPEC:
|
||||||
mutex_unlock(&xt[trav->nfproto].mutex);
|
mutex_unlock(&xt[nfproto].mutex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1680,8 +1667,6 @@ static int xt_match_open(struct inode *inode, struct file *file)
|
|||||||
trav = __seq_open_private(file, &xt_match_seq_ops, sizeof(*trav));
|
trav = __seq_open_private(file, &xt_match_seq_ops, sizeof(*trav));
|
||||||
if (!trav)
|
if (!trav)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
trav->nfproto = (unsigned long)PDE_DATA(inode);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1732,8 +1717,6 @@ static int xt_target_open(struct inode *inode, struct file *file)
|
|||||||
trav = __seq_open_private(file, &xt_target_seq_ops, sizeof(*trav));
|
trav = __seq_open_private(file, &xt_target_seq_ops, sizeof(*trav));
|
||||||
if (!trav)
|
if (!trav)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
trav->nfproto = (unsigned long)PDE_DATA(inode);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user