@@ -1857,10 +1857,16 @@ static int nf_tables_rule_notify(const struct nft_ctx *ctx,
1857
1857
return err ;
1858
1858
}
1859
1859
1860
+ struct nft_rule_dump_ctx {
1861
+ char table [NFT_TABLE_MAXNAMELEN ];
1862
+ char chain [NFT_CHAIN_MAXNAMELEN ];
1863
+ };
1864
+
1860
1865
static int nf_tables_dump_rules (struct sk_buff * skb ,
1861
1866
struct netlink_callback * cb )
1862
1867
{
1863
1868
const struct nfgenmsg * nfmsg = nlmsg_data (cb -> nlh );
1869
+ const struct nft_rule_dump_ctx * ctx = cb -> data ;
1864
1870
const struct nft_af_info * afi ;
1865
1871
const struct nft_table * table ;
1866
1872
const struct nft_chain * chain ;
@@ -1877,7 +1883,15 @@ static int nf_tables_dump_rules(struct sk_buff *skb,
1877
1883
continue ;
1878
1884
1879
1885
list_for_each_entry_rcu (table , & afi -> tables , list ) {
1886
+ if (ctx && ctx -> table [0 ] &&
1887
+ strcmp (ctx -> table , table -> name ) != 0 )
1888
+ continue ;
1889
+
1880
1890
list_for_each_entry_rcu (chain , & table -> chains , list ) {
1891
+ if (ctx && ctx -> chain [0 ] &&
1892
+ strcmp (ctx -> chain , chain -> name ) != 0 )
1893
+ continue ;
1894
+
1881
1895
list_for_each_entry_rcu (rule , & chain -> rules , list ) {
1882
1896
if (!nft_is_active (net , rule ))
1883
1897
goto cont ;
@@ -1907,6 +1921,12 @@ static int nf_tables_dump_rules(struct sk_buff *skb,
1907
1921
return skb -> len ;
1908
1922
}
1909
1923
1924
+ static int nf_tables_dump_rules_done (struct netlink_callback * cb )
1925
+ {
1926
+ kfree (cb -> data );
1927
+ return 0 ;
1928
+ }
1929
+
1910
1930
static int nf_tables_getrule (struct net * net , struct sock * nlsk ,
1911
1931
struct sk_buff * skb , const struct nlmsghdr * nlh ,
1912
1932
const struct nlattr * const nla [])
@@ -1924,7 +1944,25 @@ static int nf_tables_getrule(struct net *net, struct sock *nlsk,
1924
1944
if (nlh -> nlmsg_flags & NLM_F_DUMP ) {
1925
1945
struct netlink_dump_control c = {
1926
1946
.dump = nf_tables_dump_rules ,
1947
+ .done = nf_tables_dump_rules_done ,
1927
1948
};
1949
+
1950
+ if (nla [NFTA_RULE_TABLE ] || nla [NFTA_RULE_CHAIN ]) {
1951
+ struct nft_rule_dump_ctx * ctx ;
1952
+
1953
+ ctx = kzalloc (sizeof (* ctx ), GFP_KERNEL );
1954
+ if (!ctx )
1955
+ return - ENOMEM ;
1956
+
1957
+ if (nla [NFTA_RULE_TABLE ])
1958
+ nla_strlcpy (ctx -> table , nla [NFTA_RULE_TABLE ],
1959
+ sizeof (ctx -> table ));
1960
+ if (nla [NFTA_RULE_CHAIN ])
1961
+ nla_strlcpy (ctx -> chain , nla [NFTA_RULE_CHAIN ],
1962
+ sizeof (ctx -> chain ));
1963
+ c .data = ctx ;
1964
+ }
1965
+
1928
1966
return netlink_dump_start (nlsk , skb , nlh , & c );
1929
1967
}
1930
1968
0 commit comments