aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2018-04-10 15:59:39 -0400
committerChristoph Hellwig <hch@lst.de>2018-05-16 01:24:30 -0400
commit1d98c16d444f99b7869b271c25f23f58c1ac68c1 (patch)
tree1f7896682ee57b12d86a576a91090395c2ced583
parent2ad17b1950cb823f8dc820da801c4e5d7eef8113 (diff)
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>
-rw-r--r--net/netfilter/x_tables.c39
1 files changed, 11 insertions, 28 deletions
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index 71325fef647d..3704101af27f 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -1489,15 +1489,10 @@ void *xt_unregister_table(struct xt_table *table)
1489EXPORT_SYMBOL_GPL(xt_unregister_table); 1489EXPORT_SYMBOL_GPL(xt_unregister_table);
1490 1490
1491#ifdef CONFIG_PROC_FS 1491#ifdef CONFIG_PROC_FS
1492struct xt_names_priv {
1493 struct seq_net_private p;
1494 u_int8_t af;
1495};
1496static void *xt_table_seq_start(struct seq_file *seq, loff_t *pos) 1492static void *xt_table_seq_start(struct seq_file *seq, loff_t *pos)
1497{ 1493{
1498 struct xt_names_priv *priv = seq->private;
1499 struct net *net = seq_file_net(seq); 1494 struct net *net = seq_file_net(seq);
1500 u_int8_t af = priv->af; 1495 u_int8_t af = (unsigned long)PDE_DATA(file_inode(seq->file));
1501 1496
1502 mutex_lock(&xt[af].mutex); 1497 mutex_lock(&xt[af].mutex);
1503 return seq_list_start(&net->xt.tables[af], *pos); 1498 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)
1505 1500
1506static void *xt_table_seq_next(struct seq_file *seq, void *v, loff_t *pos) 1501static void *xt_table_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1507{ 1502{
1508 struct xt_names_priv *priv = seq->private;
1509 struct net *net = seq_file_net(seq); 1503 struct net *net = seq_file_net(seq);
1510 u_int8_t af = priv->af; 1504 u_int8_t af = (unsigned long)PDE_DATA(file_inode(seq->file));
1511 1505
1512 return seq_list_next(v, &net->xt.tables[af], pos); 1506 return seq_list_next(v, &net->xt.tables[af], pos);
1513} 1507}
1514 1508
1515static void xt_table_seq_stop(struct seq_file *seq, void *v) 1509static void xt_table_seq_stop(struct seq_file *seq, void *v)
1516{ 1510{
1517 struct xt_names_priv *priv = seq->private; 1511 u_int8_t af = (unsigned long)PDE_DATA(file_inode(seq->file));
1518 u_int8_t af = priv->af;
1519 1512
1520 mutex_unlock(&xt[af].mutex); 1513 mutex_unlock(&xt[af].mutex);
1521} 1514}
@@ -1538,16 +1531,8 @@ static const struct seq_operations xt_table_seq_ops = {
1538 1531
1539static int xt_table_open(struct inode *inode, struct file *file) 1532static int xt_table_open(struct inode *inode, struct file *file)
1540{ 1533{
1541 int ret; 1534 return seq_open_net(inode, file, &xt_table_seq_ops,
1542 struct xt_names_priv *priv; 1535 sizeof(struct seq_net_private));
1543
1544 ret = seq_open_net(inode, file, &xt_table_seq_ops,
1545 sizeof(struct xt_names_priv));
1546 if (!ret) {
1547 priv = ((struct seq_file *)file->private_data)->private;
1548 priv->af = (unsigned long)PDE_DATA(inode);
1549 }
1550 return ret;
1551} 1536}
1552 1537
1553static const struct file_operations xt_table_ops = { 1538static const struct file_operations xt_table_ops = {
@@ -1563,7 +1548,7 @@ static const struct file_operations xt_table_ops = {
1563 */ 1548 */
1564struct nf_mttg_trav { 1549struct nf_mttg_trav {
1565 struct list_head *head, *curr; 1550 struct list_head *head, *curr;
1566 uint8_t class, nfproto; 1551 uint8_t class;
1567}; 1552};
1568 1553
1569enum { 1554enum {
@@ -1580,6 +1565,7 @@ static void *xt_mttg_seq_next(struct seq_file *seq, void *v, loff_t *ppos,
1580 [MTTG_TRAV_NFP_UNSPEC] = MTTG_TRAV_NFP_SPEC, 1565 [MTTG_TRAV_NFP_UNSPEC] = MTTG_TRAV_NFP_SPEC,
1581 [MTTG_TRAV_NFP_SPEC] = MTTG_TRAV_DONE, 1566 [MTTG_TRAV_NFP_SPEC] = MTTG_TRAV_DONE,
1582 }; 1567 };
1568 uint8_t nfproto = (unsigned long)PDE_DATA(file_inode(seq->file));
1583 struct nf_mttg_trav *trav = seq->private; 1569 struct nf_mttg_trav *trav = seq->private;
1584 1570
1585 switch (trav->class) { 1571 switch (trav->class) {
@@ -1594,9 +1580,9 @@ static void *xt_mttg_seq_next(struct seq_file *seq, void *v, loff_t *ppos,
1594 if (trav->curr != trav->head) 1580 if (trav->curr != trav->head)
1595 break; 1581 break;
1596 mutex_unlock(&xt[NFPROTO_UNSPEC].mutex); 1582 mutex_unlock(&xt[NFPROTO_UNSPEC].mutex);
1597 mutex_lock(&xt[trav->nfproto].mutex); 1583 mutex_lock(&xt[nfproto].mutex);
1598 trav->head = trav->curr = is_target ? 1584 trav->head = trav->curr = is_target ?
1599 &xt[trav->nfproto].target : &xt[trav->nfproto].match; 1585 &xt[nfproto].target : &xt[nfproto].match;
1600 trav->class = next_class[trav->class]; 1586 trav->class = next_class[trav->class];
1601 break; 1587 break;
1602 case MTTG_TRAV_NFP_SPEC: 1588 case MTTG_TRAV_NFP_SPEC:
@@ -1628,6 +1614,7 @@ static void *xt_mttg_seq_start(struct seq_file *seq, loff_t *pos,
1628 1614
1629static void xt_mttg_seq_stop(struct seq_file *seq, void *v) 1615static void xt_mttg_seq_stop(struct seq_file *seq, void *v)
1630{ 1616{
1617 uint8_t nfproto = (unsigned long)PDE_DATA(file_inode(seq->file));
1631 struct nf_mttg_trav *trav = seq->private; 1618 struct nf_mttg_trav *trav = seq->private;
1632 1619
1633 switch (trav->class) { 1620 switch (trav->class) {
@@ -1635,7 +1622,7 @@ static void xt_mttg_seq_stop(struct seq_file *seq, void *v)
1635 mutex_unlock(&xt[NFPROTO_UNSPEC].mutex); 1622 mutex_unlock(&xt[NFPROTO_UNSPEC].mutex);
1636 break; 1623 break;
1637 case MTTG_TRAV_NFP_SPEC: 1624 case MTTG_TRAV_NFP_SPEC:
1638 mutex_unlock(&xt[trav->nfproto].mutex); 1625 mutex_unlock(&xt[nfproto].mutex);
1639 break; 1626 break;
1640 } 1627 }
1641} 1628}
@@ -1680,8 +1667,6 @@ static int xt_match_open(struct inode *inode, struct file *file)
1680 trav = __seq_open_private(file, &xt_match_seq_ops, sizeof(*trav)); 1667 trav = __seq_open_private(file, &xt_match_seq_ops, sizeof(*trav));
1681 if (!trav) 1668 if (!trav)
1682 return -ENOMEM; 1669 return -ENOMEM;
1683
1684 trav->nfproto = (unsigned long)PDE_DATA(inode);
1685 return 0; 1670 return 0;
1686} 1671}
1687 1672
@@ -1732,8 +1717,6 @@ static int xt_target_open(struct inode *inode, struct file *file)
1732 trav = __seq_open_private(file, &xt_target_seq_ops, sizeof(*trav)); 1717 trav = __seq_open_private(file, &xt_target_seq_ops, sizeof(*trav));
1733 if (!trav) 1718 if (!trav)
1734 return -ENOMEM; 1719 return -ENOMEM;
1735
1736 trav->nfproto = (unsigned long)PDE_DATA(inode);
1737 return 0; 1720 return 0;
1738} 1721}
1739 1722