Message ID | 20220315091513.66544-3-pablo@netfilter.org (mailing list archive) |
---|---|
State | Accepted |
Commit | f1082dd31fe461d482d69da2a8eccfeb7bf07ac2 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [nf-next,1/6] Revert "netfilter: conntrack: mark UDP zero checksum as CHECKSUM_UNNECESSARY" | expand |
On Tue, 15 Mar 2022 10:15:09 +0100 Pablo Neira Ayuso wrote: > + return false > +#ifdef CONFIG_NF_TABLES_INET > + || family == NFPROTO_INET > +#endif > +#ifdef CONFIG_NF_TABLES_IPV4 > + || family == NFPROTO_IPV4 > +#endif > +#ifdef CONFIG_NF_TABLES_ARP > + || family == NFPROTO_ARP > +#endif > +#ifdef CONFIG_NF_TABLES_NETDEV > + || family == NFPROTO_NETDEV > +#endif > +#if IS_ENABLED(CONFIG_NF_TABLES_BRIDGE) is there a reason this one is IS_ENABLED() and everything else is ifdef? > + || family == NFPROTO_BRIDGE > +#endif > +#ifdef CONFIG_NF_TABLES_IPV6 > + || family == NFPROTO_IPV6 > +#endif > + ; return (IS_ENABLED(CONFIG_NF_TABLES_INET) && family == NFPROTO_INET)) || (IS_ENABLED(CONFIG_NF_TABLES_IPV4) && family == NFPROTO_IPV4)) || ... would have also been an option, for future reference.
Hi Jakub, On Tue, Mar 15, 2022 at 11:56:44AM -0700, Jakub Kicinski wrote: > On Tue, 15 Mar 2022 10:15:09 +0100 Pablo Neira Ayuso wrote: > > + return false > > +#ifdef CONFIG_NF_TABLES_INET > > + || family == NFPROTO_INET > > +#endif > > +#ifdef CONFIG_NF_TABLES_IPV4 > > + || family == NFPROTO_IPV4 > > +#endif > > +#ifdef CONFIG_NF_TABLES_ARP > > + || family == NFPROTO_ARP > > +#endif > > +#ifdef CONFIG_NF_TABLES_NETDEV > > + || family == NFPROTO_NETDEV > > +#endif > > +#if IS_ENABLED(CONFIG_NF_TABLES_BRIDGE) > > is there a reason this one is IS_ENABLED() and everything else is ifdef? I based my patch on the existing ifdefs in nft_chain_filter.c where these config symbols are checked exactly like above. Looking at git history, the check was changed from a simple ifdef in commit dfee0e99bcff7 ("netfilter: bridge: make NF_TABLES_BRIDGE tristate"). > > + || family == NFPROTO_BRIDGE > > +#endif > > +#ifdef CONFIG_NF_TABLES_IPV6 > > + || family == NFPROTO_IPV6 > > +#endif > > + ; > > return (IS_ENABLED(CONFIG_NF_TABLES_INET) && family == NFPROTO_INET)) || > (IS_ENABLED(CONFIG_NF_TABLES_IPV4) && family == NFPROTO_IPV4)) || > ... > > would have also been an option, for future reference. Yes, that is indeed much cleaner. I wasn't aware of this possibility using IS_ENABLED. What do you think, worth a follow-up? Thanks, Phil
On Tue, Mar 15, 2022 at 09:05:53PM +0100, Phil Sutter wrote: > Hi Jakub, > > On Tue, Mar 15, 2022 at 11:56:44AM -0700, Jakub Kicinski wrote: > > On Tue, 15 Mar 2022 10:15:09 +0100 Pablo Neira Ayuso wrote: > > > + return false > > > +#ifdef CONFIG_NF_TABLES_INET > > > + || family == NFPROTO_INET > > > +#endif > > > +#ifdef CONFIG_NF_TABLES_IPV4 > > > + || family == NFPROTO_IPV4 > > > +#endif > > > +#ifdef CONFIG_NF_TABLES_ARP > > > + || family == NFPROTO_ARP > > > +#endif > > > +#ifdef CONFIG_NF_TABLES_NETDEV > > > + || family == NFPROTO_NETDEV > > > +#endif > > > +#if IS_ENABLED(CONFIG_NF_TABLES_BRIDGE) > > > > is there a reason this one is IS_ENABLED() and everything else is ifdef? > > I based my patch on the existing ifdefs in nft_chain_filter.c where > these config symbols are checked exactly like above. Looking at git > history, the check was changed from a simple ifdef in commit > dfee0e99bcff7 ("netfilter: bridge: make NF_TABLES_BRIDGE tristate"). > > > > + || family == NFPROTO_BRIDGE > > > +#endif > > > +#ifdef CONFIG_NF_TABLES_IPV6 > > > + || family == NFPROTO_IPV6 > > > +#endif > > > + ; > > > > return (IS_ENABLED(CONFIG_NF_TABLES_INET) && family == NFPROTO_INET)) || > > (IS_ENABLED(CONFIG_NF_TABLES_IPV4) && family == NFPROTO_IPV4)) || > > ... > > > > would have also been an option, for future reference. > > Yes, that is indeed much cleaner. I wasn't aware of this possibility > using IS_ENABLED. What do you think, worth a follow-up? CONFIG_NF_TABLES_INET and CONFIG_NF_TABLES_IPV4 are never modules, I think IS_ENABLED is misleading there to the reader.
On Tue, Mar 15, 2022 at 11:56:44AM -0700, Jakub Kicinski wrote: > On Tue, 15 Mar 2022 10:15:09 +0100 Pablo Neira Ayuso wrote: > > + return false > > +#ifdef CONFIG_NF_TABLES_INET > > + || family == NFPROTO_INET > > +#endif > > +#ifdef CONFIG_NF_TABLES_IPV4 > > + || family == NFPROTO_IPV4 > > +#endif > > +#ifdef CONFIG_NF_TABLES_ARP > > + || family == NFPROTO_ARP > > +#endif > > +#ifdef CONFIG_NF_TABLES_NETDEV > > + || family == NFPROTO_NETDEV > > +#endif > > +#if IS_ENABLED(CONFIG_NF_TABLES_BRIDGE) > > is there a reason this one is IS_ENABLED() and everything else is ifdef? bridge might be compiled as a module, if the bridge infrastructure also comes a module as well. Anything else is either built-in or off.
On Tue, 15 Mar 2022 21:10:33 +0100 Pablo Neira Ayuso wrote: > > > return (IS_ENABLED(CONFIG_NF_TABLES_INET) && family == NFPROTO_INET)) || > > > (IS_ENABLED(CONFIG_NF_TABLES_IPV4) && family == NFPROTO_IPV4)) || > > > ... > > > > > > would have also been an option, for future reference. > > > > Yes, that is indeed much cleaner. I wasn't aware of this possibility > > using IS_ENABLED. What do you think, worth a follow-up? > > CONFIG_NF_TABLES_INET and CONFIG_NF_TABLES_IPV4 are never modules, I > think IS_ENABLED is misleading there to the reader. It's not about being a module, IS_ENABLED() is usable in C code, no need to use the pre-processor. But your call, obviously.
On Tue, 15 Mar 2022 21:27:45 +0100 Pablo Neira Ayuso wrote: > > is there a reason this one is IS_ENABLED() and everything else is ifdef? > > bridge might be compiled as a module, if the bridge infrastructure > also comes a module as well. > > Anything else is either built-in or off. :o I thought ifdef works for modules, after checking the code it makes sense, thanks!
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index 9cd1d7a62804..3168ad8cffd1 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -1072,6 +1072,30 @@ static int nft_objname_hash_cmp(struct rhashtable_compare_arg *arg, return strcmp(obj->key.name, k->name); } +static bool nft_supported_family(u8 family) +{ + return false +#ifdef CONFIG_NF_TABLES_INET + || family == NFPROTO_INET +#endif +#ifdef CONFIG_NF_TABLES_IPV4 + || family == NFPROTO_IPV4 +#endif +#ifdef CONFIG_NF_TABLES_ARP + || family == NFPROTO_ARP +#endif +#ifdef CONFIG_NF_TABLES_NETDEV + || family == NFPROTO_NETDEV +#endif +#if IS_ENABLED(CONFIG_NF_TABLES_BRIDGE) + || family == NFPROTO_BRIDGE +#endif +#ifdef CONFIG_NF_TABLES_IPV6 + || family == NFPROTO_IPV6 +#endif + ; +} + static int nf_tables_newtable(struct sk_buff *skb, const struct nfnl_info *info, const struct nlattr * const nla[]) { @@ -1086,6 +1110,9 @@ static int nf_tables_newtable(struct sk_buff *skb, const struct nfnl_info *info, u32 flags = 0; int err; + if (!nft_supported_family(family)) + return -EOPNOTSUPP; + lockdep_assert_held(&nft_net->commit_mutex); attr = nla[NFTA_TABLE_NAME]; table = nft_table_lookup(net, attr, family, genmask,