netfilter updates: nf_tables pull request
Subsystems (6)
Pablo Neira Ayuso
maintainercover netfilter updates: nf_tables pull request
From: Pablo Neira Ayuso <[email protected]>
Hi David,
The following patchset contains the current original nf_tables tree condensed in 17 patches. I have organized them by chronogical order since the original nf_tables code was released in 2009 and by dependencies between the different patches.
The patches are:
1) Adapt all existing hooks in the tree to pass hook ops to the hook callback function, required by nf_tables, from Patrick McHardy.
2) Move alloc_null_binding to nf_nat_core, as it is now also needed by nf_tables and ip_tables, original patch from Patrick McHardy but required major changes to adapt it to the current tree that I made.
3) Add nf_tables core, including the netlink API, the packet filtering engine, expressions and built-in tables, from Patrick McHardy. This patch includes accumulated fixes since 2009 and minor enhancements. The patch description contains a list of references to the original patches for the record. For those that are not familiar to the original work, see [1], [2] and [3].
4) Add netlink set API, this replaces the original set infrastructure to introduce a netlink API to add/delete sets and to add/delete set elements. This includes two set types: the hash and the rb-tree sets (used for interval based matching). The main difference with ipset is that this infrastructure is data type agnostic. Patch from Patrick McHardy.
5) Allow expression operation overload, this API change allows us to provide define expression subtypes depending on the configuration that is received from user-space via Netlink. It is used by follow up patches to provide optimized versions of the payload and cmp expressions and the x_tables compatibility layer, from Patrick McHardy.
6) Add optimized data comparison operation, it requires the previous patch, from Patrick McHardy.
7) Add optimized payload implementation, it requires patch 5, from Patrick McHardy.
8) Convert built-in tables to chain types. Each chain type have special semantics (filter, route and nat) that are used by userspace to configure the chain behaviour. The main chain regarding iptables is that tables become containers of chain, with no specific semantics. However, you may still configure your tables and chains to retain iptables like semantics, patch from me.
9) Add compatibility layer for x_tables. This patch adds support to use all existing x_tables extensions from nf_tables, this is used to provide a userspace utility that accepts iptables syntax but used internally the nf_tables kernel core. This patch includes missing features in the nf_tables core such as the per-chain stats, default chain policy and number of chain references, which are required by the iptables compatibility userspace tool. Patch from me.
10) Fix transport protocol matching, this fix is a side effect of the x_tables compatibility layer, which now provides a pointer to the transport header, from me.
11) Add support for dormant tables, this feature allows you to disable all chains and rules that are contained in one table, from me.
12) Add IPv6 NAT support. At the time nf_tables was made, there was no NAT IPv6 support yet, from Tomasz Bursztyka.
13) Complete net namespace support. This patch register the protocol family per net namespace, so tables (thus, other objects contained in tables such as sets, chains and rules) are only visible from the corresponding net namespace, from me.
14) Add the insert operation to the nf_tables netlink API, this requires adding a new position attribute that allow us to locate where in the ruleset a rule needs to be inserted, from Eric Leblond.
15) Add rule batching support, including atomic rule-set updates by using rule-set generations. This patch includes a change to nfnetlink to include two new control messages to indicate the beginning and the end of a batch. The end message is interpreted as the commit message, if it's missing, then the rule-set updates contained in the batch are aborted, from me.
16) Add trace support to the nf_tables packet filtering core, from me.
17) Add ARP filtering support, original patch from Patrick McHardy, but adapted to fit into the chain type infrastructure. This was recovered to be used by nft userspace tool and our compatibility arptables userspace tool.
There is still work to do to fully replace x_tables [4] [5] but that can be done incrementally by extending our netlink API. Moreover, looking at netfilter-devel and the amount of contributions to nf_tables we've been getting, I think it would be good to have it mainstream to avoid accumulating large patchsets skip continuous rebases.
I tried to provide a reasonable patchset, we have more than 100 accumulated patches in the original nf_tables tree, so I collapsed many of the small fixes to the main patch we had since 2009 and provide a small batch for review to netdev, while trying to retain part of the history.
For those who didn't give a try to nf_tables yet, there's a quick howto available from Eric Leblond that describes how to get things working [6].
Comments/reviews welcome.
Thanks!
[1] http://lwn.net/Articles/324251/
[2] http://workshop.netfilter.org/2013/wiki/images/e/ee/Nftables-osd-2013-developer.pdf
[3] http://lwn.net/Articles/564095/
[4] http://people.netfilter.org/pablo/map-pending-work.txt
[4] http://people.netfilter.org/pablo/nftables-todo.txt
[5] https://home.regit.org/netfilter-en/nftables-quick-howto/
----------------------------------------------------------------
The following changes since commit ccdbb6e96beca362db876d820ac1e560ff6d9579:
tcp: tcp_transmit_skb() optimizations (2013-10-11 17:48:18 -0400)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nftables.git net-next
for you to fetch changes up to ed683f138b3dbc8a5e878e24a0bfa0bb61043a09:
netfilter: nf_tables: add ARP filtering support (2013-10-14 18:01:03 +0200)
----------------------------------------------------------------
Eric Leblond (1):
netfilter: nf_tables: add insert operation
Pablo Neira Ayuso (9):
netfilter: nf_nat: move alloc_null_binding to nf_nat_core.c
netfilter: nf_tables: convert built-in tables/chains to chain types
netfilter: nf_tables: add compatibility layer for x_tables
netfilter: nf_tables: nft_payload: fix transport header base
netfilter: nf_tables: add support for dormant tables
netfilter: nf_tables: complete net namespace support
netfilter: nfnetlink: add batch support and use it from nf_tables
netfilter: nf_tables: add trace support
netfilter: nf_tables: add ARP filtering support
Patrick McHardy (6):
netfilter: pass hook ops to hookfn
netfilter: add nftables
netfilter: nf_tables: add netlink set API
netfilter: nf_tables: expression ops overloading
netfilter: nf_tables: add optimized data comparison for small values
netfilter: nft_payload: add optimized payload implementation for small loads
Tomasz Bursztyka (1):
netfilter: nf_tables: Add support for IPv6 NAT
include/linux/netfilter.h | 14 +- include/linux/netfilter/nfnetlink.h | 5 + include/net/net_namespace.h | 4 + include/net/netfilter/nf_nat.h | 3 + include/net/netfilter/nf_tables.h | 522 ++++ include/net/netfilter/nf_tables_core.h | 42 + include/net/netfilter/nf_tables_ipv4.h | 23 + include/net/netfilter/nf_tables_ipv6.h | 30 + include/net/netns/nftables.h | 19 + include/uapi/linux/netfilter/Kbuild | 2 + include/uapi/linux/netfilter/nf_conntrack_common.h | 4 + include/uapi/linux/netfilter/nf_tables.h | 718 +++++ include/uapi/linux/netfilter/nf_tables_compat.h | 38 + include/uapi/linux/netfilter/nfnetlink.h | 10 +- net/bridge/br_netfilter.c | 22 +- net/bridge/netfilter/Kconfig | 3 + net/bridge/netfilter/Makefile | 2 + net/bridge/netfilter/ebtable_filter.c | 16 +- net/bridge/netfilter/ebtable_nat.c | 16 +- net/bridge/netfilter/nf_tables_bridge.c | 65 + net/decnet/netfilter/dn_rtmsg.c | 2 +- net/ipv4/netfilter/Kconfig | 21 + net/ipv4/netfilter/Makefile | 6 + net/ipv4/netfilter/arptable_filter.c | 5 +- net/ipv4/netfilter/ipt_CLUSTERIP.c | 2 +- net/ipv4/netfilter/ipt_SYNPROXY.c | 2 +- net/ipv4/netfilter/iptable_filter.c | 7 +- net/ipv4/netfilter/iptable_mangle.c | 10 +- net/ipv4/netfilter/iptable_nat.c | 26 +- net/ipv4/netfilter/iptable_raw.c | 6 +- net/ipv4/netfilter/iptable_security.c | 7 +- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 12 +- net/ipv4/netfilter/nf_defrag_ipv4.c | 6 +- net/ipv4/netfilter/nf_tables_arp.c | 102 + net/ipv4/netfilter/nf_tables_ipv4.c | 128 + net/ipv4/netfilter/nft_chain_nat_ipv4.c | 205 ++ net/ipv4/netfilter/nft_chain_route_ipv4.c | 90 + net/ipv4/netfilter/nft_reject_ipv4.c | 123 + net/ipv6/netfilter/Kconfig | 13 + net/ipv6/netfilter/Makefile | 5 + net/ipv6/netfilter/ip6t_SYNPROXY.c | 2 +- net/ipv6/netfilter/ip6table_filter.c | 5 +- net/ipv6/netfilter/ip6table_mangle.c | 10 +- net/ipv6/netfilter/ip6table_nat.c | 27 +- net/ipv6/netfilter/ip6table_raw.c | 5 +- net/ipv6/netfilter/ip6table_security.c | 5 +- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 14 +- net/ipv6/netfilter/nf_defrag_ipv6_hooks.c | 6 +- net/ipv6/netfilter/nf_tables_ipv6.c | 127 + net/ipv6/netfilter/nft_chain_nat_ipv6.c | 211 ++ net/ipv6/netfilter/nft_chain_route_ipv6.c | 88 + net/netfilter/Kconfig | 52 + net/netfilter/Makefile | 18 + net/netfilter/core.c | 2 +- net/netfilter/ipvs/ip_vs_core.c | 42 +- net/netfilter/nf_nat_core.c | 20 + net/netfilter/nf_tables_api.c | 3275 ++++++++++++++++++++ net/netfilter/nf_tables_core.c | 270 ++ net/netfilter/nfnetlink.c | 175 +- net/netfilter/nft_bitwise.c | 146 + net/netfilter/nft_byteorder.c | 173 ++ net/netfilter/nft_cmp.c | 223 ++ net/netfilter/nft_compat.c | 768 +++++ net/netfilter/nft_counter.c | 113 + net/netfilter/nft_ct.c | 258 ++ net/netfilter/nft_expr_template.c | 94 + net/netfilter/nft_exthdr.c | 133 + net/netfilter/nft_hash.c | 231 ++ net/netfilter/nft_immediate.c | 132 + net/netfilter/nft_limit.c | 119 + net/netfilter/nft_log.c | 146 + net/netfilter/nft_lookup.c | 141 + net/netfilter/nft_meta.c | 228 ++ net/netfilter/nft_meta_target.c | 117 + net/netfilter/nft_nat.c | 220 ++ net/netfilter/nft_payload.c | 160 + net/netfilter/nft_rbtree.c | 247 ++ security/selinux/hooks.c | 10 +- 78 files changed, 10217 insertions(+), 132 deletions(-) create mode 100644 include/net/netfilter/nf_tables.h create mode 100644 include/net/netfilter/nf_tables_core.h create mode 100644 include/net/netfilter/nf_tables_ipv4.h create mode 100644 include/net/netfilter/nf_tables_ipv6.h create mode 100644 include/net/netns/nftables.h create mode 100644 include/uapi/linux/netfilter/nf_tables.h create mode 100644 include/uapi/linux/netfilter/nf_tables_compat.h create mode 100644 net/bridge/netfilter/nf_tables_bridge.c create mode 100644 net/ipv4/netfilter/nf_tables_arp.c create mode 100644 net/ipv4/netfilter/nf_tables_ipv4.c create mode 100644 net/ipv4/netfilter/nft_chain_nat_ipv4.c create mode 100644 net/ipv4/netfilter/nft_chain_route_ipv4.c create mode 100644 net/ipv4/netfilter/nft_reject_ipv4.c create mode 100644 net/ipv6/netfilter/nf_tables_ipv6.c create mode 100644 net/ipv6/netfilter/nft_chain_nat_ipv6.c create mode 100644 net/ipv6/netfilter/nft_chain_route_ipv6.c create mode 100644 net/netfilter/nf_tables_api.c create mode 100644 net/netfilter/nf_tables_core.c create mode 100644 net/netfilter/nft_bitwise.c create mode 100644 net/netfilter/nft_byteorder.c create mode 100644 net/netfilter/nft_cmp.c create mode 100644 net/netfilter/nft_compat.c create mode 100644 net/netfilter/nft_counter.c create mode 100644 net/netfilter/nft_ct.c create mode 100644 net/netfilter/nft_expr_template.c create mode 100644 net/netfilter/nft_exthdr.c create mode 100644 net/netfilter/nft_hash.c create mode 100644 net/netfilter/nft_immediate.c create mode 100644 net/netfilter/nft_limit.c create mode 100644 net/netfilter/nft_log.c create mode 100644 net/netfilter/nft_lookup.c create mode 100644 net/netfilter/nft_meta.c create mode 100644 net/netfilter/nft_meta_target.c create mode 100644 net/netfilter/nft_nat.c create mode 100644 net/netfilter/nft_payload.c create mode 100644 net/netfilter/nft_rbtree.c
Pablo Neira Ayuso
maintainerPATCH 1/17 netfilter: pass hook ops to hookfn
From: Patrick McHardy <[email protected]>
Pass the hook ops to the hookfn to allow for generic hook functions. This change is required by nf_tables.
--- include/linux/netfilter.h | 3 +- net/bridge/br_netfilter.c | 22 ++++++++----- net/bridge/netfilter/ebtable_filter.c | 16 +++++---- net/bridge/netfilter/ebtable_nat.c | 16 +++++---- net/decnet/netfilter/dn_rtmsg.c | 2 +- net/ipv4/netfilter/arptable_filter.c | 5 +-- net/ipv4/netfilter/ipt_CLUSTERIP.c | 2 +- net/ipv4/netfilter/ipt_SYNPROXY.c | 2 +- net/ipv4/netfilter/iptable_filter.c | 7 ++-- net/ipv4/netfilter/iptable_mangle.c | 10 +++--- net/ipv4/netfilter/iptable_nat.c | 26 +++++++-------- net/ipv4/netfilter/iptable_raw.c | 6 ++-- net/ipv4/netfilter/iptable_security.c | 7 ++-- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 12 +++---- net/ipv4/netfilter/nf_defrag_ipv4.c | 6 ++-- net/ipv6/netfilter/ip6t_SYNPROXY.c | 2 +- net/ipv6/netfilter/ip6table_filter.c | 5 +-- net/ipv6/netfilter/ip6table_mangle.c | 10 +++--- net/ipv6/netfilter/ip6table_nat.c | 27 +++++++-------- net/ipv6/netfilter/ip6table_raw.c | 5 +-- net/ipv6/netfilter/ip6table_security.c | 5 +-- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 14 ++++---- net/ipv6/netfilter/nf_defrag_ipv6_hooks.c | 6 ++-- net/netfilter/core.c | 2 +- net/netfilter/ipvs/ip_vs_core.c | 42 ++++++++++++------------ security/selinux/hooks.c | 10 +++--- 26 files changed, 148 insertions(+), 122 deletions(-)
include/linux/netfilter.h +2 -1
@@ -42,7 +42,8 @@ int netfilter_init(void);struct sk_buff ; -typedef unsigned int nf_hookfn(unsigned int hooknum, +struct nf_hook_ops ; +typedef unsigned int nf_hookfn(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
net/bridge/br_netfilter.c +14 -8
@@ -619,7 +619,7 @@ bad:/* Replicate the checks that IPv6 does on packet reception and pass the packet * to ip6tables, which doesn't support NAT, so things are fairly simple. */ -static unsigned int br_nf_pre_routing_ipv6(unsigned int hook, +static unsigned int br_nf_pre_routing_ipv6(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -669,7 +669,8 @@ static unsigned int br_nf_pre_routing_ipv6(unsigned int hook,* receiving device) to make netfilter happy, the REDIRECT * target in particular. Save the original destination IP * address to be able to detect DNAT afterwards. */ -static unsigned int br_nf_pre_routing (unsigned int hook,struct sk_buff *skb, +static unsigned int br_nf_pre_routing (const struct nf_hook_ops *ops, +struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *))
@@ -691,7 +692,7 @@ static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff *skb,return NF_ACCEPT ;nf_bridge_pull_encap_header_rcsum (skb); -return br_nf_pre_routing_ipv6 (hook, skb, in, out, okfn); +return br_nf_pre_routing_ipv6 (ops, skb, in, out, okfn); }if (!brnf_call_iptables && !br->nf_call_iptables)
@@ -727,7 +728,8 @@ static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff *skb,* took place when the packet entered the bridge), but we * register an IPv4 PRE_ROUTING 'sabotage' hook that will * prevent this from happening. */ -static unsigned int br_nf_local_in (unsigned int hook,struct sk_buff *skb, +static unsigned int br_nf_local_in (const struct nf_hook_ops *ops, +struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *))
@@ -765,7 +767,8 @@ static int br_nf_forward_finish(struct sk_buff *skb)* but we are still able to filter on the 'real' indev/outdev * because of the physdev module. For ARP, indev and outdev are the * bridge ports. */ -static unsigned int br_nf_forward_ip (unsigned int hook,struct sk_buff *skb, +static unsigned int br_nf_forward_ip (const struct nf_hook_ops *ops, +struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *))
@@ -818,7 +821,8 @@ static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff *skb,return NF_STOLEN ; } -static unsigned int br_nf_forward_arp (unsigned int hook,struct sk_buff *skb, +static unsigned int br_nf_forward_arp (const struct nf_hook_ops *ops, +struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *))
@@ -878,7 +882,8 @@ static int br_nf_dev_queue_xmit(struct sk_buff *skb)#endif /* PF_BRIDGE/POST_ROUTING ********************************************/ -static unsigned int br_nf_post_routing (unsigned int hook,struct sk_buff *skb, +static unsigned int br_nf_post_routing (const struct nf_hook_ops *ops, +struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *))
@@ -923,7 +928,8 @@ static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff *skb,/* IP/SABOTAGE *****************************************************/ /* Don't hand locally destined packets to PF_INET(6)/PRE_ROUTING * for the second time. */ -static unsigned int ip_sabotage_in (unsigned int hook,struct sk_buff *skb, +static unsigned int ip_sabotage_in (const struct nf_hook_ops *ops, +struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *))
net/bridge/netfilter/ebtable_filter.c +10 -6
@@ -60,17 +60,21 @@ static const struct ebt_table frame_filter = };static unsigned int -ebt_in_hook (unsigned int hook,struct sk_buff *skb,const struct net_device *in, -const struct net_device *out,int (*okfn)(struct sk_buff *)) +ebt_in_hook (const struct nf_hook_ops *ops,struct sk_buff *skb, +const struct net_device *in,const struct net_device *out, +int (*okfn)(struct sk_buff *)) { -return ebt_do_table (hook, skb, in, out,dev_net (in)->xt.frame_filter); +return ebt_do_table (ops->hooknum, skb, in, out, +dev_net (in)->xt.frame_filter); }static unsigned int -ebt_out_hook (unsigned int hook,struct sk_buff *skb,const struct net_device *in, -const struct net_device *out,int (*okfn)(struct sk_buff *)) +ebt_out_hook (const struct nf_hook_ops *ops,struct sk_buff *skb, +const struct net_device *in,const struct net_device *out, +int (*okfn)(struct sk_buff *)) { -return ebt_do_table (hook, skb, in, out,dev_net (out)->xt.frame_filter); +return ebt_do_table (ops->hooknum, skb, in, out, +dev_net (out)->xt.frame_filter); }static struct nf_hook_ops ebt_ops_filter[]__read_mostly = {
net/bridge/netfilter/ebtable_nat.c +10 -6
@@ -60,17 +60,21 @@ static struct ebt_table frame_nat = };static unsigned int -ebt_nat_in (unsigned int hook,struct sk_buff *skb,const struct net_device *in - ,const struct net_device *out,int (*okfn)(struct sk_buff *)) +ebt_nat_in (const struct nf_hook_ops *ops,struct sk_buff *skb, +const struct net_device *in,const struct net_device *out, +int (*okfn)(struct sk_buff *)) { -return ebt_do_table (hook, skb, in, out,dev_net (in)->xt.frame_nat); +return ebt_do_table (ops->hooknum, skb, in, out, +dev_net (in)->xt.frame_nat); }static unsigned int -ebt_nat_out (unsigned int hook,struct sk_buff *skb,const struct net_device *in - ,const struct net_device *out,int (*okfn)(struct sk_buff *)) +ebt_nat_out (const struct nf_hook_ops *ops,struct sk_buff *skb, +const struct net_device *in,const struct net_device *out, +int (*okfn)(struct sk_buff *)) { -return ebt_do_table (hook, skb, in, out,dev_net (out)->xt.frame_nat); +return ebt_do_table (ops->hooknum, skb, in, out, +dev_net (out)->xt.frame_nat); }static struct nf_hook_ops ebt_ops_nat[]__read_mostly = {
net/decnet/netfilter/dn_rtmsg.c +1 -1
@@ -87,7 +87,7 @@ static void dnrmg_send_peer(struct sk_buff *skb) } -static unsigned int dnrmg_hook(unsigned int hook, +static unsigned int dnrmg_hook(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
net/ipv4/netfilter/arptable_filter.c +3 -2
@@ -27,13 +27,14 @@ static const struct xt_table packet_filter = {/* The work comes in here from netfilter.c */ static unsigned int -arptable_filter_hook (unsigned int hook,struct sk_buff *skb, +arptable_filter_hook (const struct nf_hook_ops *ops,struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *)) {const struct net *net =dev_net ((in !=NULL ) ? in : out); -return arpt_do_table (skb, hook, in, out, net->ipv4.arptable_filter); +return arpt_do_table (skb, ops->hooknum, in, out, + net->ipv4.arptable_filter); }static struct nf_hook_ops *arpfilter_ops__read_mostly ;
net/ipv4/netfilter/ipt_CLUSTERIP.c +1 -1
@@ -483,7 +483,7 @@ static void arp_print(struct arp_payload *payload)#endif static unsigned int -arp_mangle(unsigned int hook, +arp_mangle(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
net/ipv4/netfilter/ipt_SYNPROXY.c +1 -1
@@ -297,7 +297,7 @@ synproxy_tg4(struct sk_buff *skb, const struct xt_action_param *par)return XT_CONTINUE ; } -static unsigned int ipv4_synproxy_hook(unsigned int hooknum, +static unsigned int ipv4_synproxy_hook(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
net/ipv4/netfilter/iptable_filter.c +4 -3
@@ -33,20 +33,21 @@ static const struct xt_table packet_filter = { };static unsigned int -iptable_filter_hook (unsigned int hook,struct sk_buff *skb, +iptable_filter_hook (const struct nf_hook_ops *ops,struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *)) {const struct net *net; -if (hook ==NF_INET_LOCAL_OUT && +if (ops->hooknum ==NF_INET_LOCAL_OUT && (skb->len <sizeof (struct iphdr ) ||ip_hdrlen (skb) <sizeof (struct iphdr )))/* root is playing with raw sockets. */ return NF_ACCEPT ; net =dev_net ((in !=NULL ) ? in : out); -return ipt_do_table (skb, hook, in, out, net->ipv4.iptable_filter); +return ipt_do_table (skb, ops->hooknum, in, out, + net->ipv4.iptable_filter); }static struct nf_hook_ops *filter_ops__read_mostly ;
net/ipv4/netfilter/iptable_mangle.c +5 -5
@@ -79,19 +79,19 @@ ipt_mangle_out(struct sk_buff *skb, const struct net_device *out)/* The work comes in here from netfilter.c. */ static unsigned int -iptable_mangle_hook (unsigned int hook, +iptable_mangle_hook (const struct nf_hook_ops *ops,struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *)) { -if (hook ==NF_INET_LOCAL_OUT ) +if (ops->hooknum ==NF_INET_LOCAL_OUT )return ipt_mangle_out (skb, out); -if (hook ==NF_INET_POST_ROUTING ) -return ipt_do_table (skb, hook, in, out, +if (ops->hooknum ==NF_INET_POST_ROUTING ) +return ipt_do_table (skb, ops->hooknum, in, out,dev_net (out)->ipv4.iptable_mangle);/* PREROUTING/INPUT/FORWARD: */ -return ipt_do_table (skb, hook, in, out, +return ipt_do_table (skb, ops->hooknum, in, out,dev_net (in)->ipv4.iptable_mangle); }
net/ipv4/netfilter/iptable_nat.c +13 -13
@@ -61,7 +61,7 @@ static unsigned int nf_nat_rule_find(struct sk_buff *skb, unsigned int hooknum, } static unsigned int -nf_nat_ipv4_fn(unsigned int hooknum, +nf_nat_ipv4_fn(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -71,7 +71,7 @@ nf_nat_ipv4_fn(unsigned int hooknum,enum ip_conntrack_info ctinfo;struct nf_conn_nat *nat;/* maniptype == SRC for postrouting. */ -enum nf_nat_manip_type maniptype =HOOK2MANIP (hooknum); +enum nf_nat_manip_type maniptype =HOOK2MANIP (ops->hooknum);/* We never see fragments: conntrack defrags on pre-routing * and local-out, and nf_nat_out protects post-routing.
@@ -108,7 +108,7 @@ nf_nat_ipv4_fn(unsigned int hooknum,case IP_CT_RELATED_REPLY :if (ip_hdr (skb)->protocol ==IPPROTO_ICMP ) {if (!nf_nat_icmp_reply_translation (skb, ct, ctinfo, - hooknum)) + ops->hooknum))return NF_DROP ;else return NF_ACCEPT ;
@@ -121,14 +121,14 @@ nf_nat_ipv4_fn(unsigned int hooknum,if (!nf_nat_initialized (ct, maniptype)) {unsigned int ret; - ret =nf_nat_rule_find (skb, hooknum, in, out, ct); + ret =nf_nat_rule_find (skb, ops->hooknum, in, out, ct);if (ret !=NF_ACCEPT )return ret; }else {pr_debug ("Already setup manip %s for ct %p\n" , maniptype ==NF_NAT_MANIP_SRC ?"SRC" :"DST" , ct); -if (nf_nat_oif_changed (hooknum, ctinfo, nat, out)) +if (nf_nat_oif_changed (ops->hooknum, ctinfo, nat, out)) goto oif_changed; }break ;
@@ -137,11 +137,11 @@ nf_nat_ipv4_fn(unsigned int hooknum,/* ESTABLISHED */ NF_CT_ASSERT (ctinfo ==IP_CT_ESTABLISHED || ctinfo ==IP_CT_ESTABLISHED_REPLY ); -if (nf_nat_oif_changed (hooknum, ctinfo, nat, out)) +if (nf_nat_oif_changed (ops->hooknum, ctinfo, nat, out)) goto oif_changed; } -return nf_nat_packet (ct, ctinfo, hooknum, skb); +return nf_nat_packet (ct, ctinfo, ops->hooknum, skb); oif_changed:nf_ct_kill_acct (ct, ctinfo, skb);
@@ -149,7 +149,7 @@ oif_changed: } static unsigned int -nf_nat_ipv4_in(unsigned int hooknum, +nf_nat_ipv4_in(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -158,7 +158,7 @@ nf_nat_ipv4_in(unsigned int hooknum,unsigned int ret;__be32 daddr =ip_hdr (skb)->daddr; - ret =nf_nat_ipv4_fn (hooknum, skb, in, out, okfn); + ret =nf_nat_ipv4_fn (ops, skb, in, out, okfn);if (ret !=NF_DROP && ret !=NF_STOLEN && daddr !=ip_hdr (skb)->daddr)skb_dst_drop (skb);
@@ -167,7 +167,7 @@ nf_nat_ipv4_in(unsigned int hooknum, } static unsigned int -nf_nat_ipv4_out(unsigned int hooknum, +nf_nat_ipv4_out(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -185,7 +185,7 @@ nf_nat_ipv4_out(unsigned int hooknum, ip_hdrlen(skb) < sizeof(struct iphdr))return NF_ACCEPT ; - ret =nf_nat_ipv4_fn (hooknum, skb, in, out, okfn); + ret =nf_nat_ipv4_fn (ops, skb, in, out, okfn);#ifdef CONFIG_XFRM if (ret != NF_DROP && ret != NF_STOLEN && !(IPCB(skb)->flags & IPSKB_XFRM_TRANSFORMED) &&
@@ -207,7 +207,7 @@ nf_nat_ipv4_out(unsigned int hooknum, } static unsigned int -nf_nat_ipv4_local_fn(unsigned int hooknum, +nf_nat_ipv4_local_fn(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -223,7 +223,7 @@ nf_nat_ipv4_local_fn(unsigned int hooknum, ip_hdrlen(skb) < sizeof(struct iphdr))return NF_ACCEPT ; - ret =nf_nat_ipv4_fn (hooknum, skb, in, out, okfn); + ret =nf_nat_ipv4_fn (ops, skb, in, out, okfn);if (ret !=NF_DROP && ret !=NF_STOLEN && (ct =nf_ct_get (skb, &ctinfo)) !=NULL ) {enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo);
net/ipv4/netfilter/iptable_raw.c +3 -3
@@ -20,20 +20,20 @@ static const struct xt_table packet_raw = {/* The work comes in here from netfilter.c. */ static unsigned int -iptable_raw_hook (unsigned int hook,struct sk_buff *skb, +iptable_raw_hook (const struct nf_hook_ops *ops,struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *)) {const struct net *net; -if (hook ==NF_INET_LOCAL_OUT && +if (ops->hooknum ==NF_INET_LOCAL_OUT && (skb->len <sizeof (struct iphdr ) ||ip_hdrlen (skb) <sizeof (struct iphdr )))/* root is playing with raw sockets. */ return NF_ACCEPT ; net =dev_net ((in !=NULL ) ? in : out); -return ipt_do_table (skb, hook, in, out, net->ipv4.iptable_raw); +return ipt_do_table (skb, ops->hooknum, in, out, net->ipv4.iptable_raw); }static struct nf_hook_ops *rawtable_ops__read_mostly ;
net/ipv4/netfilter/iptable_security.c +4 -3
@@ -37,21 +37,22 @@ static const struct xt_table security_table = { };static unsigned int -iptable_security_hook (unsigned int hook,struct sk_buff *skb, +iptable_security_hook (const struct nf_hook_ops *ops,struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *)) {const struct net *net; -if (hook ==NF_INET_LOCAL_OUT && +if (ops->hooknum ==NF_INET_LOCAL_OUT && (skb->len <sizeof (struct iphdr ) ||ip_hdrlen (skb) <sizeof (struct iphdr )))/* Somebody is playing with raw sockets. */ return NF_ACCEPT ; net =dev_net ((in !=NULL ) ? in : out); -return ipt_do_table (skb, hook, in, out, net->ipv4.iptable_security); +return ipt_do_table (skb, ops->hooknum, in, out, + net->ipv4.iptable_security); }static struct nf_hook_ops *sectbl_ops__read_mostly ;
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +6 -6
@@ -92,7 +92,7 @@ static int ipv4_get_l4proto(const struct sk_buff *skb, unsigned int nhoff,return NF_ACCEPT ; } -static unsigned int ipv4_helper(unsigned int hooknum, +static unsigned int ipv4_helper(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -121,7 +121,7 @@ static unsigned int ipv4_helper(unsigned int hooknum, ct, ctinfo); } -static unsigned int ipv4_confirm(unsigned int hooknum, +static unsigned int ipv4_confirm(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -147,16 +147,16 @@ out:return nf_conntrack_confirm (skb); } -static unsigned int ipv4_conntrack_in (unsigned int hooknum, +static unsigned int ipv4_conntrack_in (const struct nf_hook_ops *ops,struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *)) { -return nf_conntrack_in (dev_net (in),PF_INET , hooknum, skb); +return nf_conntrack_in (dev_net (in),PF_INET , ops->hooknum, skb); } -static unsigned int ipv4_conntrack_local(unsigned int hooknum, +static unsigned int ipv4_conntrack_local(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -166,7 +166,7 @@ static unsigned int ipv4_conntrack_local(unsigned int hooknum,if (skb->len <sizeof (struct iphdr ) ||ip_hdrlen (skb) <sizeof (struct iphdr ))return NF_ACCEPT ; -return nf_conntrack_in (dev_net (out),PF_INET , hooknum, skb); +return nf_conntrack_in (dev_net (out),PF_INET , ops->hooknum, skb); }/* Connection tracking may drop packets, but never alters them, so
net/ipv4/netfilter/nf_defrag_ipv4.c +4 -2
@@ -60,7 +60,7 @@ static enum ip_defrag_users nf_ct_defrag_user(unsigned int hooknum,return IP_DEFRAG_CONNTRACK_OUT + zone; } -static unsigned int ipv4_conntrack_defrag(unsigned int hooknum, +static unsigned int ipv4_conntrack_defrag(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -83,7 +83,9 @@ static unsigned int ipv4_conntrack_defrag(unsigned int hooknum,#endif /* Gather fragments. */ if (ip_is_fragment (ip_hdr (skb))) { -enum ip_defrag_users user =nf_ct_defrag_user (hooknum, skb); +enum ip_defrag_users user = +nf_ct_defrag_user (ops->hooknum, skb); +if (nf_ct_ipv4_gather_frags (skb, user))return NF_STOLEN ; }
net/ipv6/netfilter/ip6t_SYNPROXY.c +1 -1
@@ -312,7 +312,7 @@ synproxy_tg6(struct sk_buff *skb, const struct xt_action_param *par)return XT_CONTINUE ; } -static unsigned int ipv6_synproxy_hook(unsigned int hooknum, +static unsigned int ipv6_synproxy_hook(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
net/ipv6/netfilter/ip6table_filter.c +3 -2
@@ -32,13 +32,14 @@ static const struct xt_table packet_filter = {/* The work comes in here from netfilter.c. */ static unsigned int -ip6table_filter_hook (unsigned int hook,struct sk_buff *skb, +ip6table_filter_hook (const struct nf_hook_ops *ops,struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *)) {const struct net *net =dev_net ((in !=NULL ) ? in : out); -return ip6t_do_table (skb, hook, in, out, net->ipv6.ip6table_filter); +return ip6t_do_table (skb, ops->hooknum, in, out, + net->ipv6.ip6table_filter); }static struct nf_hook_ops *filter_ops__read_mostly ;
net/ipv6/netfilter/ip6table_mangle.c +5 -5
@@ -76,17 +76,17 @@ ip6t_mangle_out(struct sk_buff *skb, const struct net_device *out)/* The work comes in here from netfilter.c. */ static unsigned int -ip6table_mangle_hook (unsigned int hook,struct sk_buff *skb, +ip6table_mangle_hook (const struct nf_hook_ops *ops,struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *)) { -if (hook ==NF_INET_LOCAL_OUT ) +if (ops->hooknum ==NF_INET_LOCAL_OUT )return ip6t_mangle_out (skb, out); -if (hook ==NF_INET_POST_ROUTING ) -return ip6t_do_table (skb, hook, in, out, +if (ops->hooknum ==NF_INET_POST_ROUTING ) +return ip6t_do_table (skb, ops->hooknum, in, out,dev_net (out)->ipv6.ip6table_mangle);/* INPUT/FORWARD */ -return ip6t_do_table (skb, hook, in, out, +return ip6t_do_table (skb, ops->hooknum, in, out,dev_net (in)->ipv6.ip6table_mangle); }
net/ipv6/netfilter/ip6table_nat.c +14 -13
@@ -63,7 +63,7 @@ static unsigned int nf_nat_rule_find(struct sk_buff *skb, unsigned int hooknum, } static unsigned int -nf_nat_ipv6_fn(unsigned int hooknum, +nf_nat_ipv6_fn(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -72,7 +72,7 @@ nf_nat_ipv6_fn(unsigned int hooknum,struct nf_conn *ct;enum ip_conntrack_info ctinfo;struct nf_conn_nat *nat; -enum nf_nat_manip_type maniptype =HOOK2MANIP (hooknum); +enum nf_nat_manip_type maniptype =HOOK2MANIP (ops->hooknum);__be16 frag_off;int hdrlen;u8 nexthdr;
@@ -111,7 +111,8 @@ nf_nat_ipv6_fn(unsigned int hooknum,if (hdrlen >=0 && nexthdr ==IPPROTO_ICMPV6 ) {if (!nf_nat_icmpv6_reply_translation (skb, ct, ctinfo, - hooknum, hdrlen)) + ops->hooknum, + hdrlen))return NF_DROP ;else return NF_ACCEPT ;
@@ -124,14 +125,14 @@ nf_nat_ipv6_fn(unsigned int hooknum,if (!nf_nat_initialized (ct, maniptype)) {unsigned int ret; - ret =nf_nat_rule_find (skb, hooknum, in, out, ct); + ret =nf_nat_rule_find (skb, ops->hooknum, in, out, ct);if (ret !=NF_ACCEPT )return ret; }else {pr_debug ("Already setup manip %s for ct %p\n" , maniptype ==NF_NAT_MANIP_SRC ?"SRC" :"DST" , ct); -if (nf_nat_oif_changed (hooknum, ctinfo, nat, out)) +if (nf_nat_oif_changed (ops->hooknum, ctinfo, nat, out)) goto oif_changed; }break ;
@@ -140,11 +141,11 @@ nf_nat_ipv6_fn(unsigned int hooknum,/* ESTABLISHED */ NF_CT_ASSERT (ctinfo ==IP_CT_ESTABLISHED || ctinfo ==IP_CT_ESTABLISHED_REPLY ); -if (nf_nat_oif_changed (hooknum, ctinfo, nat, out)) +if (nf_nat_oif_changed (ops->hooknum, ctinfo, nat, out)) goto oif_changed; } -return nf_nat_packet (ct, ctinfo, hooknum, skb); +return nf_nat_packet (ct, ctinfo, ops->hooknum, skb); oif_changed:nf_ct_kill_acct (ct, ctinfo, skb);
@@ -152,7 +153,7 @@ oif_changed: } static unsigned int -nf_nat_ipv6_in(unsigned int hooknum, +nf_nat_ipv6_in(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -161,7 +162,7 @@ nf_nat_ipv6_in(unsigned int hooknum,unsigned int ret;struct in6_addr daddr =ipv6_hdr (skb)->daddr; - ret =nf_nat_ipv6_fn (hooknum, skb, in, out, okfn); + ret =nf_nat_ipv6_fn (ops, skb, in, out, okfn);if (ret !=NF_DROP && ret !=NF_STOLEN &&ipv6_addr_cmp (&daddr, &ipv6_hdr (skb)->daddr))skb_dst_drop (skb);
@@ -170,7 +171,7 @@ nf_nat_ipv6_in(unsigned int hooknum, } static unsigned int -nf_nat_ipv6_out(unsigned int hooknum, +nf_nat_ipv6_out(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -187,7 +188,7 @@ nf_nat_ipv6_out(unsigned int hooknum,if (skb->len <sizeof (struct ipv6hdr ))return NF_ACCEPT ; - ret =nf_nat_ipv6_fn (hooknum, skb, in, out, okfn); + ret =nf_nat_ipv6_fn (ops, skb, in, out, okfn);#ifdef CONFIG_XFRM if (ret != NF_DROP && ret != NF_STOLEN && !(IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED) &&
@@ -209,7 +210,7 @@ nf_nat_ipv6_out(unsigned int hooknum, } static unsigned int -nf_nat_ipv6_local_fn(unsigned int hooknum, +nf_nat_ipv6_local_fn(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -224,7 +225,7 @@ nf_nat_ipv6_local_fn(unsigned int hooknum,if (skb->len <sizeof (struct ipv6hdr ))return NF_ACCEPT ; - ret =nf_nat_ipv6_fn (hooknum, skb, in, out, okfn); + ret =nf_nat_ipv6_fn (ops, skb, in, out, okfn);if (ret !=NF_DROP && ret !=NF_STOLEN && (ct =nf_ct_get (skb, &ctinfo)) !=NULL ) {enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo);
net/ipv6/netfilter/ip6table_raw.c +3 -2
@@ -19,13 +19,14 @@ static const struct xt_table packet_raw = {/* The work comes in here from netfilter.c. */ static unsigned int -ip6table_raw_hook (unsigned int hook,struct sk_buff *skb, +ip6table_raw_hook (const struct nf_hook_ops *ops,struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *)) {const struct net *net =dev_net ((in !=NULL ) ? in : out); -return ip6t_do_table (skb, hook, in, out, net->ipv6.ip6table_raw); +return ip6t_do_table (skb, ops->hooknum, in, out, + net->ipv6.ip6table_raw); }static struct nf_hook_ops *rawtable_ops__read_mostly ;
net/ipv6/netfilter/ip6table_security.c +3 -2
@@ -36,14 +36,15 @@ static const struct xt_table security_table = { };static unsigned int -ip6table_security_hook (unsigned int hook,struct sk_buff *skb, +ip6table_security_hook (const struct nf_hook_ops *ops,struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *)) {const struct net *net =dev_net ((in !=NULL ) ? in : out); -return ip6t_do_table (skb, hook, in, out, net->ipv6.ip6table_security); +return ip6t_do_table (skb, ops->hooknum, in, out, + net->ipv6.ip6table_security); }static struct nf_hook_ops *sectbl_ops__read_mostly ;
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +8 -6
@@ -95,7 +95,7 @@ static int ipv6_get_l4proto(const struct sk_buff *skb, unsigned int nhoff,return NF_ACCEPT ; } -static unsigned int ipv6_helper(unsigned int hooknum, +static unsigned int ipv6_helper(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -133,7 +133,7 @@ static unsigned int ipv6_helper(unsigned int hooknum,return helper->help (skb, protoff, ct, ctinfo); } -static unsigned int ipv6_confirm(unsigned int hooknum, +static unsigned int ipv6_confirm(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -219,16 +219,17 @@ static unsigned int __ipv6_conntrack_in(struct net *net,return nf_conntrack_in (net,PF_INET6 , hooknum, skb); } -static unsigned int ipv6_conntrack_in (unsigned int hooknum, +static unsigned int ipv6_conntrack_in (const struct nf_hook_ops *ops,struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *)) { -return __ipv6_conntrack_in (dev_net (in), hooknum, skb, in, out, okfn); +return __ipv6_conntrack_in (dev_net (in), ops->hooknum, skb, in, out, + okfn); } -static unsigned int ipv6_conntrack_local(unsigned int hooknum, +static unsigned int ipv6_conntrack_local(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -239,7 +240,8 @@ static unsigned int ipv6_conntrack_local(unsigned int hooknum,net_notice_ratelimited ("ipv6_conntrack_local: packet too short\n" );return NF_ACCEPT ; } -return __ipv6_conntrack_in (dev_net (out), hooknum, skb, in, out, okfn); +return __ipv6_conntrack_in (dev_net (out), ops->hooknum, skb, in, out, + okfn); }static struct nf_hook_ops ipv6_conntrack_ops[]__read_mostly = {
net/ipv6/netfilter/nf_defrag_ipv6_hooks.c +3 -3
@@ -52,7 +52,7 @@ static enum ip6_defrag_users nf_ct6_defrag_user(unsigned int hooknum, } -static unsigned int ipv6_defrag(unsigned int hooknum, +static unsigned int ipv6_defrag(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -66,7 +66,7 @@ static unsigned int ipv6_defrag(unsigned int hooknum,return NF_ACCEPT ;#endif - reasm =nf_ct_frag6_gather (skb,nf_ct6_defrag_user (hooknum, skb)); + reasm =nf_ct_frag6_gather (skb,nf_ct6_defrag_user (ops->hooknum, skb));/* queued */ if (reasm ==NULL )return NF_STOLEN ;
@@ -75,7 +75,7 @@ static unsigned int ipv6_defrag(unsigned int hooknum,if (reasm == skb)return NF_ACCEPT ; -nf_ct_frag6_output (hooknum, reasm, (struct net_device *)in, +nf_ct_frag6_output (ops->hooknum, reasm, (struct net_device *)in, (struct net_device *)out, okfn);return NF_STOLEN ;
net/netfilter/core.c +1 -1
@@ -146,7 +146,7 @@ unsigned int nf_iterate(struct list_head *head,/* Optimization: we don't need to hold module reference here, since function can't sleep. --RR */ repeat: - verdict = (*elemp)->hook (hook, skb, indev, outdev, okfn); + verdict = (*elemp)->hook (*elemp, skb, indev, outdev, okfn);if (verdict !=NF_ACCEPT ) {#ifdef CONFIG_NETFILTER_DEBUG if (unlikely((verdict & NF_VERDICT_MASK)
net/netfilter/ipvs/ip_vs_core.c +21 -21
144 lines not on this page · raw message
security/selinux/hooks.c +5 -5
@@ -4668,7 +4668,7 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex,return NF_ACCEPT ; } -static unsigned int selinux_ipv4_forward(unsigned int hooknum, +static unsigned int selinux_ipv4_forward(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -4678,7 +4678,7 @@ static unsigned int selinux_ipv4_forward(unsigned int hooknum, }#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) -static unsigned int selinux_ipv6_forward(unsigned int hooknum, +static unsigned int selinux_ipv6_forward(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -4710,7 +4710,7 @@ static unsigned int selinux_ip_output(struct sk_buff *skb,return NF_ACCEPT ; } -static unsigned int selinux_ipv4_output(unsigned int hooknum, +static unsigned int selinux_ipv4_output(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -4837,7 +4837,7 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,return NF_ACCEPT ; } -static unsigned int selinux_ipv4_postroute(unsigned int hooknum, +static unsigned int selinux_ipv4_postroute(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
@@ -4847,7 +4847,7 @@ static unsigned int selinux_ipv4_postroute(unsigned int hooknum, }#if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE ) -static unsigned int selinux_ipv6_postroute(unsigned int hooknum, +static unsigned int selinux_ipv6_postroute(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/17 netfilter: nf_nat: move alloc_null_binding to nf_nat_core.c
In reply to Pablo Neira AyusoSimilar to nat_decode_session, alloc_null_binding is needed for both ip_tables and nf_tables, so move it to nf_nat_core.c. This change is required by nf_tables.
This is an adapted version of the original patch from Patrick McHardy.
--- include/net/netfilter/nf_nat.h | 3 +++ net/netfilter/nf_nat_core.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+)
include/net/netfilter/nf_nat.h +3 -0
@@ -45,6 +45,9 @@ unsigned int nf_nat_setup_info(struct nf_conn *ct,const struct nf_nat_range *range, enum nf_nat_manip_type maniptype); +extern unsigned int nf_nat_alloc_null_binding (struct nf_conn *ct, +unsigned int hooknum); +/* Is this tuple already taken? (not by us)*/ int nf_nat_used_tuple (const struct nf_conntrack_tuple *tuple,const struct nf_conn *ignored_conntrack);
net/netfilter/nf_nat_core.c +20 -0
@@ -432,6 +432,26 @@ nf_nat_setup_info(struct nf_conn *ct, }EXPORT_SYMBOL (nf_nat_setup_info); +unsigned int +nf_nat_alloc_null_binding (struct nf_conn *ct,unsigned int hooknum) +{ +/* Force range to this IP; let proto decide mapping for +* per-proto parts (hence not IP_NAT_RANGE_PROTO_SPECIFIED). +* Use reply in case it's already been mangled (eg local packet). +*/ +union nf_inet_addr ip = + (HOOK2MANIP (hooknum) ==NF_NAT_MANIP_SRC ? + ct->tuplehash[IP_CT_DIR_REPLY ].tuple.dst.u3 : + ct->tuplehash[IP_CT_DIR_REPLY ].tuple.src.u3); +struct nf_nat_range range = { + .flags =NF_NAT_RANGE_MAP_IPS , + .min_addr = ip, + .max_addr = ip, + }; +return nf_nat_setup_info (ct, &range,HOOK2MANIP (hooknum)); +} +EXPORT_SYMBOL_GPL (nf_nat_alloc_null_binding); +/* Do packet manipulations according to nf_nat_setup_info. */ unsigned int nf_nat_packet(struct nf_conn *ct, enum ip_conntrack_info ctinfo,
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 3/17 netfilter: add nftables
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
This patch adds nftables which is the intended successor of iptables. This packet filtering framework reuses the existing netfilter hooks, the connection tracking system, the NAT subsystem, the transparent proxying engine, the logging infrastructure and the userspace packet queueing facilities.
In a nutshell, nftables provides a pseudo-state machine with 4 general purpose registers of 128 bits and 1 specific purpose register to store verdicts. This pseudo-machine comes with an extensible instruction set, a.k.a. "expressions" in the nftables jargon. The expressions included in this patch provide the basic functionality, they are:
* bitwise: to perform bitwise operations.
* byteorder: to change from host/network endianess.
* cmp: to compare data with the content of the registers.
* counter: to enable counters on rules.
* ct: to store conntrack keys into register.
* exthdr: to match IPv6 extension headers.
* immediate: to load data into registers.
* limit: to limit matching based on packet rate.
* log: to log packets.
* meta: to match metainformation that usually comes with the skbuff.
* nat: to perform Network Address Translation.
* payload: to fetch data from the packet payload and store it into registers.
* reject (IPv4 only): to explicitly close connection, eg. TCP RST.
Using this instruction-set, the userspace utility 'nft' can transform the rules expressed in human-readable text representation (using a new syntax, inspired by tcpdump) to nftables bytecode.
nftables also inherits the table, chain and rule objects from iptables, but in a more configurable way, and it also includes the original datatype-agnostic set infrastructure with mapping support. This set infrastructure is enhanced in the follow up patch (netfilter:nf_tables: add netlink set API).
This patch includes the following components:
* the netlink API: net/netfilter/nf_tables_api.c and include/uapi/netfilter/nf_tables.h
* the packet filter core: net/netfilter/nf_tables_core.c
* the expressions (described above): net/netfilter/nft_*.c
* the filter tables: arp, IPv4, IPv6 and bridge:
net/ipv4/netfilter/nf_tables_ipv4.c net/ipv6/netfilter/nf_tables_ipv6.c net/ipv4/netfilter/nf_tables_arp.c net/bridge/netfilter/nf_tables_bridge.c
* the NAT table (IPv4 only):
net/ipv4/netfilter/nf_table_nat_ipv4.c
* the route table (similar to mangle):
net/ipv4/netfilter/nf_table_route_ipv4.c net/ipv6/netfilter/nf_table_route_ipv6.c
* internal definitions under:
include/net/netfilter/nf_tables.h include/net/netfilter/nf_tables_core.h
* It also includes an skeleton expression:
net/netfilter/nft_expr_template.c
and the preliminary implementation of the meta target net/netfilter/nft_meta_target.c
It also includes a change in struct nf_hook_ops to add a new pointer to store private data to the hook, that is used to store the rule list per chain.
This patch is based on the patch from Patrick McHardy, plus merged accumulated cleanups, fixes and small enhancements to the nftables code that has been done since 2009, which are:
Quoted 1 line
From Patrick McHardy:
* nf_tables: adjust netlink handler function signatures
* nf_tables: only retry table lookup after successful table module load
* nf_tables: fix event notification echo and avoid unnecessary messages
* nft_ct: add l3proto support
* nf_tables: pass expression context to nft_validate_data_load()
* nf_tables: remove redundant definition
* nft_ct: fix maxattr initialization
* nf_tables: fix invalid event type in nf_tables_getrule()
* nf_tables: simplify nft_data_init() usage
* nf_tables: build in more core modules
* nf_tables: fix double lookup expression unregistation
* nf_tables: move expression initialization to nf_tables_core.c
* nf_tables: build in payload module
* nf_tables: use NFPROTO constants
* nf_tables: rename pid variables to portid
* nf_tables: save 48 bits per rule
* nf_tables: introduce chain rename
* nf_tables: check for duplicate names on chain rename
* nf_tables: remove ability to specify handles for new rules
* nf_tables: return error for rule change request
* nf_tables: return error for NLM_F_REPLACE without rule handle
* nf_tables: include NLM_F_APPEND/NLM_F_REPLACE flags in rule notification
* nf_tables: fix NLM_F_MULTI usage in netlink notifications
* nf_tables: include NLM_F_APPEND in rule dumps
Quoted 1 line
From Pablo Neira Ayuso:
* nf_tables: fix stack overflow in nf_tables_newrule
* nf_tables: nft_ct: fix compilation warning
* nf_tables: nft_ct: fix crash with invalid packets
* nft_log: group and qthreshold are 2^16
* nf_tables: nft_meta: fix socket uid,gid handling
* nft_counter: allow to restore counters
* nf_tables: fix module autoload
* nf_tables: allow to remove all rules placed in one chain
* nf_tables: use 64-bits rule handle instead of 16-bits
* nf_tables: fix chain after rule deletion
* nf_tables: improve deletion performance
* nf_tables: add missing code in route chain type
* nf_tables: rise maximum number of expressions from 12 to 128
* nf_tables: don't delete table if in use
* nf_tables: fix basechain release
Quoted 1 line
From Tomasz Bursztyka:
* nf_tables: Add support for changing users chain's name
* nf_tables: Change chain's name to be fixed sized
* nf_tables: Add support for replacing a rule by another one
* nf_tables: Update uapi nftables netlink header documentation
Quoted 1 line
From Florian Westphal:
* nft_log: group is u16, snaplen u32
Quoted 1 line
From Phil Oester:
* nf_tables: operational limit match
--- include/linux/netfilter.h | 11 +- include/net/netfilter/nf_tables.h | 301 ++++ include/net/netfilter/nf_tables_core.h | 25 + include/uapi/linux/netfilter/Kbuild | 1 + include/uapi/linux/netfilter/nf_conntrack_common.h | 4 + include/uapi/linux/netfilter/nf_tables.h | 582 +++++++ include/uapi/linux/netfilter/nfnetlink.h | 5 +- net/bridge/netfilter/Kconfig | 3 + net/bridge/netfilter/Makefile | 2 + net/bridge/netfilter/nf_tables_bridge.c | 37 + net/ipv4/netfilter/Kconfig | 16 + net/ipv4/netfilter/Makefile | 5 + net/ipv4/netfilter/nf_table_nat_ipv4.c | 409 +++++ net/ipv4/netfilter/nf_table_route_ipv4.c | 97 ++ net/ipv4/netfilter/nf_tables_ipv4.c | 59 + net/ipv4/netfilter/nft_reject_ipv4.c | 117 ++ net/ipv6/netfilter/Kconfig | 8 + net/ipv6/netfilter/Makefile | 4 + net/ipv6/netfilter/nf_table_route_ipv6.c | 93 ++ net/ipv6/netfilter/nf_tables_ipv6.c | 57 + net/netfilter/Kconfig | 37 + net/netfilter/Makefile | 16 + net/netfilter/nf_tables_api.c | 1760 ++++++++++++++++++++ net/netfilter/nf_tables_core.c | 152 ++ net/netfilter/nft_bitwise.c | 140 ++ net/netfilter/nft_byteorder.c | 167 ++ net/netfilter/nft_cmp.c | 146 ++ net/netfilter/nft_counter.c | 107 ++ net/netfilter/nft_ct.c | 252 +++ net/netfilter/nft_expr_template.c | 88 + net/netfilter/nft_exthdr.c | 127 ++ net/netfilter/nft_hash.c | 348 ++++ net/netfilter/nft_immediate.c | 113 ++ net/netfilter/nft_limit.c | 113 ++ net/netfilter/nft_log.c | 140 ++ net/netfilter/nft_meta.c | 222 +++ net/netfilter/nft_meta_target.c | 117 ++ net/netfilter/nft_payload.c | 137 ++ net/netfilter/nft_set.c | 381 +++++ 39 files changed, 6393 insertions(+), 6 deletions(-) create mode 100644 include/net/netfilter/nf_tables.h create mode 100644 include/net/netfilter/nf_tables_core.h create mode 100644 include/uapi/linux/netfilter/nf_tables.h create mode 100644 net/bridge/netfilter/nf_tables_bridge.c create mode 100644 net/ipv4/netfilter/nf_table_nat_ipv4.c create mode 100644 net/ipv4/netfilter/nf_table_route_ipv4.c create mode 100644 net/ipv4/netfilter/nf_tables_ipv4.c create mode 100644 net/ipv4/netfilter/nft_reject_ipv4.c create mode 100644 net/ipv6/netfilter/nf_table_route_ipv6.c create mode 100644 net/ipv6/netfilter/nf_tables_ipv6.c create mode 100644 net/netfilter/nf_tables_api.c create mode 100644 net/netfilter/nf_tables_core.c create mode 100644 net/netfilter/nft_bitwise.c create mode 100644 net/netfilter/nft_byteorder.c create mode 100644 net/netfilter/nft_cmp.c create mode 100644 net/netfilter/nft_counter.c create mode 100644 net/netfilter/nft_ct.c create mode 100644 net/netfilter/nft_expr_template.c create mode 100644 net/netfilter/nft_exthdr.c create mode 100644 net/netfilter/nft_hash.c create mode 100644 net/netfilter/nft_immediate.c create mode 100644 net/netfilter/nft_limit.c create mode 100644 net/netfilter/nft_log.c create mode 100644 net/netfilter/nft_meta.c create mode 100644 net/netfilter/nft_meta_target.c create mode 100644 net/netfilter/nft_payload.c create mode 100644 net/netfilter/nft_set.c
include/linux/netfilter.h +6 -5
@@ -53,12 +53,13 @@ struct nf_hook_ops {struct list_head list;/* User fills in from here down. */ -nf_hookfn *hook; -struct module *owner; -u_int8_t pf; -unsigned int hooknum; +nf_hookfn *hook; +struct module *owner; +void *priv; +u_int8_t pf; +unsigned int hooknum;/* Hooks are ordered in ascending priority. */ -int priority; +int priority; };struct nf_sockopt_ops {
include/net/netfilter/nf_tables.h new file +301 -0
301 lines not on this page · raw message
include/net/netfilter/nf_tables_core.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef _NET_NF_TABLES_CORE_H +#define _NET_NF_TABLES_CORE_H + +extern int nf_tables_core_module_init (void ); +extern void nf_tables_core_module_exit (void ); + +extern int nft_immediate_module_init (void ); +extern void nft_immediate_module_exit (void ); + +extern int nft_cmp_module_init (void ); +extern void nft_cmp_module_exit (void ); + +extern int nft_lookup_module_init (void ); +extern void nft_lookup_module_exit (void ); + +extern int nft_bitwise_module_init (void ); +extern void nft_bitwise_module_exit (void ); + +extern int nft_byteorder_module_init (void ); +extern void nft_byteorder_module_exit (void ); + +extern int nft_payload_module_init (void ); +extern void nft_payload_module_exit (void ); + +#endif /* _NET_NF_TABLES_CORE_H */
include/uapi/linux/netfilter/Kbuild +1 -0
@@ -5,6 +5,7 @@ header-y += nf_conntrack_ftp.h header-y += nf_conntrack_sctp.h header-y += nf_conntrack_tcp.h header-y += nf_conntrack_tuple_common.h +header-y += nf_tables.h header-y += nf_nat.h header-y += nfnetlink.h header-y += nfnetlink_acct.h
include/uapi/linux/netfilter/nf_conntrack_common.h +4 -0
@@ -25,6 +25,10 @@ enum ip_conntrack_info {IP_CT_NUMBER =IP_CT_IS_REPLY *2 -1 }; +#define NF_CT_STATE_INVALID_BIT (1 << 0) +#define NF_CT_STATE_BIT (ctinfo) (1 << ((ctinfo) % IP_CT_IS_REPLY + 1)) +#define NF_CT_STATE_UNTRACKED_BIT (1 << (IP_CT_NUMBER + 1)) +/* Bitset representing status of connection. */ enum ip_conntrack_status {/* It's an expected connection: bit 0 set. This bit never changed */
include/uapi/linux/netfilter/nf_tables.h new file +582 -0
582 lines not on this page · raw message
include/uapi/linux/netfilter/nfnetlink.h +4 -1
@@ -18,6 +18,8 @@ enum nfnetlink_groups {#define NFNLGRP_CONNTRACK_EXP_UPDATE NFNLGRP_CONNTRACK_EXP_UPDATE NFNLGRP_CONNTRACK_EXP_DESTROY,#define NFNLGRP_CONNTRACK_EXP_DESTROY NFNLGRP_CONNTRACK_EXP_DESTROY + NFNLGRP_NFTABLES, +#define NFNLGRP_NFTABLES NFNLGRP_NFTABLES __NFNLGRP_MAX, };#define NFNLGRP_MAX (__NFNLGRP_MAX - 1)
@@ -51,6 +53,7 @@ struct nfgenmsg {#define NFNL_SUBSYS_ACCT 7#define NFNL_SUBSYS_CTNETLINK_TIMEOUT 8#define NFNL_SUBSYS_CTHELPER 9 -#define NFNL_SUBSYS_COUNT 10 +#define NFNL_SUBSYS_NFTABLES 10 +#define NFNL_SUBSYS_COUNT 11#endif /* _UAPI_NFNETLINK_H */
net/bridge/netfilter/Kconfig +3 -0
@@ -1,6 +1,9 @@ # # Bridge netfilter configuration # +# +config NF_TABLES_BRIDGE + tristate "Ethernet Bridge nf_tables support" menuconfig BRIDGE_NF_EBTABLES tristate "Ethernet Bridge tables (ebtables) support"
net/bridge/netfilter/Makefile +2 -0
@@ -2,6 +2,8 @@ # Makefile for the netfilter modules for Link Layer filtering on a bridge. # +obj-$(CONFIG_NF_TABLES_BRIDGE) += nf_tables_bridge.o + obj-$(CONFIG_BRIDGE_NF_EBTABLES) += ebtables.o # tables
net/bridge/netfilter/nf_tables_bridge.c new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Copyright (c) 2008 Patrick McHardy <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* Development of this code funded by Astaro AG (http://www.astaro.com/) +*/ + +#include <linux/init.h> +#include <linux/module.h> +#include <linux/netfilter_bridge.h> +#include <net/netfilter/nf_tables.h> + +static struct nft_af_info nft_af_bridge__read_mostly = { + .family =NFPROTO_BRIDGE , + .nhooks =NF_BR_NUMHOOKS , + .owner =THIS_MODULE , +}; + +static int __init nf_tables_bridge_init (void ) +{ +return nft_register_afinfo (&nft_af_bridge); +} + +static void __exit nf_tables_bridge_exit(void) +{ +nft_unregister_afinfo (&nft_af_bridge); +} + +module_init (nf_tables_bridge_init); +module_exit (nf_tables_bridge_exit); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Patrick McHardy <[email protected]>" ); +MODULE_ALIAS_NFT_FAMILY (AF_BRIDGE );
net/ipv4/netfilter/Kconfig +16 -0
@@ -36,6 +36,22 @@ config NF_CONNTRACK_PROC_COMPAT If unsure, say Y. +config NF_TABLES_IPV4 + depends on NF_TABLES + tristate "IPv4 nf_tables support" + +config NFT_REJECT_IPV4 + depends on NF_TABLES_IPV4 + tristate "nf_tables IPv4 reject support" + +config NF_TABLE_ROUTE_IPV4 + depends on NF_TABLES_IPV4 + tristate "IPv4 nf_tables route table support" + +config NF_TABLE_NAT_IPV4 + depends on NF_TABLES_IPV4 + tristate "IPv4 nf_tables nat table support" + config IP_NF_IPTABLES tristate "IP tables support (required for filtering/masq/NAT)" default m if NETFILTER_ADVANCED=n
net/ipv4/netfilter/Makefile +5 -0
@@ -27,6 +27,11 @@ obj-$(CONFIG_NF_NAT_SNMP_BASIC) += nf_nat_snmp_basic.o # NAT protocols (nf_nat) obj-$(CONFIG_NF_NAT_PROTO_GRE) += nf_nat_proto_gre.o +obj-$(CONFIG_NF_TABLES_IPV4) += nf_tables_ipv4.o +obj-$(CONFIG_NFT_REJECT_IPV4) += nft_reject_ipv4.o +obj-$(CONFIG_NF_TABLE_ROUTE_IPV4) += nf_table_route_ipv4.o +obj-$(CONFIG_NF_TABLE_NAT_IPV4) += nf_table_nat_ipv4.o + # generic IP tables obj-$(CONFIG_IP_NF_IPTABLES) += ip_tables.o
net/ipv4/netfilter/nf_table_nat_ipv4.c new file +409 -0
409 lines not on this page · raw message
net/ipv4/netfilter/nf_table_route_ipv4.c new file +97 -0
97 lines not on this page · raw message
net/ipv4/netfilter/nf_tables_ipv4.c new file +59 -0
59 lines not on this page · raw message
net/ipv4/netfilter/nft_reject_ipv4.c new file +117 -0
117 lines not on this page · raw message
net/ipv6/netfilter/Kconfig +8 -0
@@ -25,6 +25,14 @@ config NF_CONNTRACK_IPV6 To compile it as a module, choose M here. If unsure, say N. +config NF_TABLES_IPV6 + depends on NF_TABLES + tristate "IPv6 nf_tables support" + +config NF_TABLE_ROUTE_IPV6 + depends on NF_TABLES_IPV6 + tristate "IPv6 nf_tables route table support" + config IP6_NF_IPTABLES tristate "IP6 tables support (required for filtering)" depends on INET && IPV6
net/ipv6/netfilter/Makefile +4 -0
@@ -23,6 +23,10 @@ obj-$(CONFIG_NF_NAT_IPV6) += nf_nat_ipv6.o nf_defrag_ipv6-y := nf_defrag_ipv6_hooks.o nf_conntrack_reasm.o obj-$(CONFIG_NF_DEFRAG_IPV6) += nf_defrag_ipv6.o +# nf_tables +obj-$(CONFIG_NF_TABLES_IPV6) += nf_tables_ipv6.o +obj-$(CONFIG_NF_TABLE_ROUTE_IPV6) += nf_table_route_ipv6.o + # matches obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o obj-$(CONFIG_IP6_NF_MATCH_EUI64) += ip6t_eui64.o
net/ipv6/netfilter/nf_table_route_ipv6.c new file +93 -0
93 lines not on this page · raw message
net/ipv6/netfilter/nf_tables_ipv6.c new file +57 -0
57 lines not on this page · raw message
net/netfilter/Kconfig +37 -0
@@ -413,6 +413,43 @@ config NETFILTER_SYNPROXY endif # NF_CONNTRACK +config NF_TABLES + depends on NETFILTER_NETLINK + tristate "Netfilter nf_tables support" + +config NFT_EXTHDR + depends on NF_TABLES + tristate "Netfilter nf_tables IPv6 exthdr module" + +config NFT_META + depends on NF_TABLES + tristate "Netfilter nf_tables meta module" + +config NFT_CT + depends on NF_TABLES + depends on NF_CONNTRACK + tristate "Netfilter nf_tables conntrack module" + +config NFT_SET + depends on NF_TABLES + tristate "Netfilter nf_tables set module" + +config NFT_HASH + depends on NF_TABLES + tristate "Netfilter nf_tables hash module" + +config NFT_COUNTER + depends on NF_TABLES + tristate "Netfilter nf_tables counter module" + +config NFT_LOG + depends on NF_TABLES + tristate "Netfilter nf_tables log module" + +config NFT_LIMIT + depends on NF_TABLES + tristate "Netfilter nf_tables limit module" + config NETFILTER_XTABLES tristate "Netfilter Xtables support (required for ip_tables)" default m if NETFILTER_ADVANCED=n
net/netfilter/Makefile +16 -0
@@ -64,6 +64,22 @@ obj-$(CONFIG_NF_NAT_TFTP) += nf_nat_tftp.o # SYNPROXY obj-$(CONFIG_NETFILTER_SYNPROXY) += nf_synproxy_core.o +# nf_tables +nf_tables-objs += nf_tables_core.o nf_tables_api.o +nf_tables-objs += nft_immediate.o nft_cmp.o nft_lookup.o +nf_tables-objs += nft_bitwise.o nft_byteorder.o nft_payload.o + +obj-$(CONFIG_NF_TABLES) += nf_tables.o +obj-$(CONFIG_NFT_EXTHDR) += nft_exthdr.o +obj-$(CONFIG_NFT_META) += nft_meta.o +obj-$(CONFIG_NFT_CT) += nft_ct.o +obj-$(CONFIG_NFT_LIMIT) += nft_limit.o +#nf_tables-objs += nft_meta_target.o +obj-$(CONFIG_NFT_SET) += nft_set.o +obj-$(CONFIG_NFT_HASH) += nft_hash.o +obj-$(CONFIG_NFT_COUNTER) += nft_counter.o +obj-$(CONFIG_NFT_LOG) += nft_log.o + # generic X tables obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
net/netfilter/nf_tables_api.c new file +1760 -0
1,033 lines not on this page · raw message
net/netfilter/nf_tables_core.c new file +152 -0
152 lines not on this page · raw message
net/netfilter/nft_bitwise.c new file +140 -0
140 lines not on this page · raw message
net/netfilter/nft_byteorder.c new file +167 -0
167 lines not on this page · raw message
net/netfilter/nft_cmp.c new file +146 -0
146 lines not on this page · raw message
net/netfilter/nft_counter.c new file +107 -0
107 lines not on this page · raw message
net/netfilter/nft_ct.c new file +252 -0
252 lines not on this page · raw message
net/netfilter/nft_expr_template.c new file +88 -0
88 lines not on this page · raw message
net/netfilter/nft_exthdr.c new file +127 -0
127 lines not on this page · raw message
net/netfilter/nft_hash.c new file +348 -0
348 lines not on this page · raw message
net/netfilter/nft_immediate.c new file +113 -0
113 lines not on this page · raw message
net/netfilter/nft_limit.c new file +113 -0
113 lines not on this page · raw message
net/netfilter/nft_log.c new file +140 -0
140 lines not on this page · raw message
net/netfilter/nft_meta.c new file +222 -0
222 lines not on this page · raw message
net/netfilter/nft_meta_target.c new file +117 -0
117 lines not on this page · raw message
net/netfilter/nft_payload.c new file +137 -0
137 lines not on this page · raw message
net/netfilter/nft_set.c new file +381 -0
381 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.10.4
Part of the diff is not shown here. View the raw message.
Pablo Neira Ayuso
maintainerPATCH 4/17 netfilter: nf_tables: add netlink set API
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
This patch adds the new netlink API for maintaining nf_tables sets independently of the ruleset. The API supports the following operations:
- creation of sets
- deletion of sets
- querying of specific sets
- dumping of all sets
- addition of set elements
- removal of set elements
- dumping of all set elements
Sets are identified by name, each table defines an individual namespace. The name of a set may be allocated automatically, this is mostly useful in combination with the NFT_SET_ANONYMOUS flag, which destroys a set automatically once the last reference has been released.
Sets can be marked constant, meaning they're not allowed to change while linked to a rule. This allows to perform lockless operation for set types that would otherwise require locking.
Additionally, if the implementation supports it, sets can (as before) be used as maps, associating a data value with each key (or range), by specifying the NFT_SET_MAP flag and can be used for interval queries by specifying the NFT_SET_INTERVAL flag.
Set elements are added and removed incrementally. All element operations support batching, reducing netlink message and set lookup overhead.
The old "set" and "hash" expressions are replaced by a generic "lookup" expression, which binds to the specified set. Userspace is not aware of the actual set implementation used by the kernel anymore, all configuration options are generic.
Currently the implementation selection logic is largely missing and the kernel will simply use the first registered implementation supporting the requested operation. Eventually, the plan is to have userspace supply a description of the data characteristics and select the implementation based on expected performance and memory use.
This patch includes the new 'lookup' expression to look up for element matching in the set.
This patch includes kernel-doc descriptions for this set API and it also includes the following fixes.
Quoted 1 line
From Patrick McHardy:
* netfilter: nf_tables: fix set element data type in dumps
* netfilter: nf_tables: fix indentation of struct nft_set_elem comments
* netfilter: nf_tables: fix oops in nft_validate_data_load()
* netfilter: nf_tables: fix oops while listing sets of built-in tables
* netfilter: nf_tables: destroy anonymous sets immediately if binding fails
* netfilter: nf_tables: propagate context to set iter callback
* netfilter: nf_tables: add loop detection
Quoted 1 line
From Pablo Neira Ayuso:
* netfilter: nf_tables: allow to dump all existing sets
* netfilter: nf_tables: fix wrong type for flags variable in newelem
--- include/net/netfilter/nf_tables.h | 149 ++++- include/uapi/linux/netfilter/nf_tables.h | 191 ++++-- net/netfilter/Kconfig | 6 +- net/netfilter/Makefile | 2 +- net/netfilter/nf_tables_api.c | 1078 +++++++++++++++++++++++++++++- net/netfilter/nf_tables_core.c | 2 - net/netfilter/nft_hash.c | 329 +++------ net/netfilter/nft_immediate.c | 11 + net/netfilter/nft_lookup.c | 135 ++++ net/netfilter/nft_rbtree.c | 247 +++++++ net/netfilter/nft_set.c | 381 ----------- 11 files changed, 1854 insertions(+), 677 deletions(-) create mode 100644 net/netfilter/nft_lookup.c create mode 100644 net/netfilter/nft_rbtree.c delete mode 100644 net/netfilter/nft_set.c
include/net/netfilter/nf_tables.h +142 -7
@@ -6,6 +6,8 @@#include <linux/netfilter/nf_tables.h> #include <net/netlink.h> +#define NFT_JUMP_STACK_SIZE 16 +struct nft_pktinfo {struct sk_buff *skb;const struct net_device *in;
@@ -48,23 +50,22 @@ static inline void nft_data_debug(const struct nft_data *data) }/** -* struct nft_ctx - nf_tables rule context +* struct nft_ctx - nf_tables rule/set context * +* @skb: netlink skb +* @nlh: netlink message header * @afi: address family info * @table: the table the chain is contained in * @chain: the chain the rule is contained in */ struct nft_ctx { +const struct sk_buff *skb; +const struct nlmsghdr *nlh;const struct nft_af_info *afi;const struct nft_table *table;const struct nft_chain *chain; }; -enum nft_data_types { -NFT_DATA_VALUE , -NFT_DATA_VERDICT , -}; -struct nft_data_desc {enum nft_data_types type;unsigned int len;
@@ -83,6 +84,11 @@ static inline enum nft_data_types nft_dreg_to_type(enum nft_registers reg)return reg ==NFT_REG_VERDICT ?NFT_DATA_VERDICT :NFT_DATA_VALUE ; } +static inline enum nft_registers nft_type_to_reg (enum nft_data_types type) +{ +return type ==NFT_DATA_VERDICT ?NFT_REG_VERDICT :NFT_REG_1 ; +} +extern int nft_validate_input_register (enum nft_registers reg);extern int nft_validate_output_register (enum nft_registers reg); extern int nft_validate_data_load(const struct nft_ctx *ctx,
@@ -91,6 +97,132 @@ extern int nft_validate_data_load(const struct nft_ctx *ctx, enum nft_data_types type);/** +* struct nft_set_elem - generic representation of set elements +* +* @cookie: implementation specific element cookie +* @key: element key +* @data: element data (maps only) +* @flags: element flags (end of interval) +* +* The cookie can be used to store a handle to the element for subsequent +* removal. +*/ +struct nft_set_elem { +void *cookie; +struct nft_data key; +struct nft_data data; +u32 flags; +}; + +struct nft_set ; +struct nft_set_iter { +unsigned int count; +unsigned int skip; +int err; +int (*fn)(const struct nft_ctx *ctx, +const struct nft_set *set, +const struct nft_set_iter *iter, +const struct nft_set_elem *elem); +}; + +/** +* struct nft_set_ops - nf_tables set operations +* +* @lookup: look up an element within the set +* @insert: insert new element into set +* @remove: remove element from set +* @walk: iterate over all set elemeennts +* @privsize: function to return size of set private data +* @init: initialize private data of new set instance +* @destroy: destroy private data of set instance +* @list: nf_tables_set_ops list node +* @owner: module reference +* @features: features supported by the implementation +*/ +struct nft_set_ops { +bool (*lookup)(const struct nft_set *set, +const struct nft_data *key, +struct nft_data *data); +int (*get)(const struct nft_set *set, +struct nft_set_elem *elem); +int (*insert)(const struct nft_set *set, +const struct nft_set_elem *elem); +void (*remove)(const struct nft_set *set, +const struct nft_set_elem *elem); +void (*walk)(const struct nft_ctx *ctx, +const struct nft_set *set, +struct nft_set_iter *iter); + +unsigned int (*privsize)(const struct nlattr *const nla[]); +int (*init)(const struct nft_set *set, +const struct nlattr *const nla[]); +void (*destroy)(const struct nft_set *set); + +struct list_head list; +struct module *owner; +u32 features; +}; + +extern int nft_register_set (struct nft_set_ops *ops); +extern void nft_unregister_set (struct nft_set_ops *ops); + +/** +* struct nft_set - nf_tables set instance +* +* @list: table set list node +* @bindings: list of set bindings +* @name: name of the set +* @ktype: key type (numeric type defined by userspace, not used in the kernel) +* @dtype: data type (verdict or numeric type defined by userspace) +* @ops: set ops +* @flags: set flags +* @klen: key length +* @dlen: data length +* @data: private set data +*/ +struct nft_set { +struct list_head list; +struct list_head bindings; +char name[IFNAMSIZ ]; +u32 ktype; +u32 dtype; +/* runtime data below here */ +const struct nft_set_ops *ops____cacheline_aligned ; +u16 flags; +u8 klen; +u8 dlen; +unsigned char data[] + __attribute__((aligned (__alignof__(u64 )))); +}; + +static inline void *nft_set_priv (const struct nft_set *set) +{ +return (void *)set->data; +} + +extern struct nft_set *nf_tables_set_lookup (const struct nft_table *table, +const struct nlattr *nla); + +/** +* struct nft_set_binding - nf_tables set binding +* +* @list: set bindings list node +* @chain: chain containing the rule bound to the set +* +* A set binding contains all information necessary for validation +* of new elements added to a bound set. +*/ +struct nft_set_binding { +struct list_head list; +const struct nft_chain *chain; +}; + +extern int nf_tables_bind_set (const struct nft_ctx *ctx,struct nft_set *set, +struct nft_set_binding *binding); +extern void nf_tables_unbind_set (const struct nft_ctx *ctx,struct nft_set *set, +struct nft_set_binding *binding); + +/** * struct nft_expr_ops - nf_tables expression operations * * @eval: Expression evaluation function
@@ -115,7 +247,7 @@ struct nft_expr_ops {void (*destroy)(const struct nft_expr *expr);int (*dump)(struct sk_buff *skb,const struct nft_expr *expr); - +const struct nft_data * (*get_verdict)(const struct nft_expr *expr);struct list_head list;const char *name;struct module *owner;
@@ -298,4 +430,7 @@ extern void nft_unregister_expr(struct nft_expr_ops *);#define MODULE_ALIAS_NFT_EXPR (name) \ MODULE_ALIAS("nft-expr-" name) +#define MODULE_ALIAS_NFT_SET () \ + MODULE_ALIAS("nft-set") +#endif /* _NET_NF_TABLES_H */
include/uapi/linux/netfilter/nf_tables.h +139 -52
218 lines not on this page · raw message
net/netfilter/Kconfig +3 -3
@@ -430,13 +430,13 @@ config NFT_CT depends on NF_CONNTRACK tristate "Netfilter nf_tables conntrack module" -config NFT_SET +config NFT_RBTREE depends on NF_TABLES - tristate "Netfilter nf_tables set module" + tristate "Netfilter nf_tables rbtree set module" config NFT_HASH depends on NF_TABLES - tristate "Netfilter nf_tables hash module" + tristate "Netfilter nf_tables hash set module" config NFT_COUNTER depends on NF_TABLES
net/netfilter/Makefile +1 -1
@@ -75,7 +75,7 @@ obj-$(CONFIG_NFT_META) += nft_meta.o obj-$(CONFIG_NFT_CT) += nft_ct.o obj-$(CONFIG_NFT_LIMIT) += nft_limit.o #nf_tables-objs += nft_meta_target.o -obj-$(CONFIG_NFT_SET) += nft_set.o +obj-$(CONFIG_NFT_RBTREE) += nft_rbtree.o obj-$(CONFIG_NFT_HASH) += nft_hash.o obj-$(CONFIG_NFT_COUNTER) += nft_counter.o obj-$(CONFIG_NFT_LOG) += nft_log.o
net/netfilter/nf_tables_api.c +1070 -8
1,144 lines not on this page · raw message
net/netfilter/nf_tables_core.c +0 -2
@@ -20,8 +20,6 @@#include <net/netfilter/nf_tables_core.h> #include <net/netfilter/nf_tables.h> -#define NFT_JUMP_STACK_SIZE 16 - unsigned int nft_do_chain(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in,
net/netfilter/nft_hash.c +106 -223
424 lines not on this page · raw message
net/netfilter/nft_immediate.c +11 -0
@@ -90,6 +90,16 @@ nla_put_failure:return -1 ; } +static const struct nft_data *nft_immediate_get_verdict (const struct nft_expr *expr) +{ +const struct nft_immediate_expr *priv =nft_expr_priv (expr); + +if (priv->dreg ==NFT_REG_VERDICT ) +return &priv->data; +else +return NULL ; +} +static struct nft_expr_ops nft_imm_ops__read_mostly = { .name ="immediate" , .size =NFT_EXPR_SIZE (sizeof (struct nft_immediate_expr )),
@@ -98,6 +108,7 @@ static struct nft_expr_ops nft_imm_ops __read_mostly = { .init = nft_immediate_init, .destroy = nft_immediate_destroy, .dump = nft_immediate_dump, + .get_verdict = nft_immediate_get_verdict, .policy = nft_immediate_policy, .maxattr = NFTA_IMMEDIATE_MAX, };
net/netfilter/nft_lookup.c new file +135 -0
135 lines not on this page · raw message
net/netfilter/nft_rbtree.c new file +247 -0
247 lines not on this page · raw message
net/netfilter/nft_set.c deleted +0 -381
381 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 5/17 netfilter: nf_tables: expression ops overloading
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
Split the expression ops into two parts and support overloading of the runtime expression ops based on the requested function through a ->select_ops() callback.
This can be used to provide optimized implementations, for instance for loading small aligned amounts of data from the packet or inlining frequently used operations into the main evaluation loop.
--- include/net/netfilter/nf_tables.h | 42 +++++++++---- net/ipv4/netfilter/nf_table_nat_ipv4.c | 18 ++++-- net/ipv4/netfilter/nft_reject_ipv4.c | 18 ++++-- net/netfilter/nf_tables_api.c | 101 ++++++++++++++++++-------------- net/netfilter/nft_bitwise.c | 18 ++++-- net/netfilter/nft_byteorder.c | 18 ++++-- net/netfilter/nft_cmp.c | 18 ++++-- net/netfilter/nft_counter.c | 22 ++++--- net/netfilter/nft_ct.c | 18 ++++-- net/netfilter/nft_expr_template.c | 20 ++++--- net/netfilter/nft_exthdr.c | 16 +++-- net/netfilter/nft_immediate.c | 18 ++++-- net/netfilter/nft_limit.c | 18 ++++-- net/netfilter/nft_log.c | 18 ++++-- net/netfilter/nft_lookup.c | 16 +++-- net/netfilter/nft_meta.c | 18 ++++-- net/netfilter/nft_payload.c | 18 ++++-- 17 files changed, 267 insertions(+), 148 deletions(-)
include/net/netfilter/nf_tables.h +29 -13
@@ -222,25 +222,45 @@ extern int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set,extern void nf_tables_unbind_set (const struct nft_ctx *ctx,struct nft_set *set,struct nft_set_binding *binding); +/** -* struct nft_expr_ops - nf_tables expression operations +* struct nft_expr_type - nf_tables expression type * -* @eval: Expression evaluation function -* @init: initialization function -* @destroy: destruction function -* @dump: function to dump parameters +* @select_ops: function to select nft_expr_ops +* @ops: default ops, used when no select_ops functions is present * @list: used internally * @name: Identifier * @owner: module reference * @policy: netlink attribute policy * @maxattr: highest netlink attribute number +*/ +struct nft_expr_type { +const struct nft_expr_ops *(*select_ops)(const struct nlattr *const tb[]); +const struct nft_expr_ops *ops; +struct list_head list; +const char *name; +struct module *owner; +const struct nla_policy *policy; +unsigned int maxattr; +}; + +/** +* struct nft_expr_ops - nf_tables expression operations +* +* @eval: Expression evaluation function * @size: full expression size, including private data size +* @init: initialization function +* @destroy: destruction function +* @dump: function to dump parameters +* @type: expression type */ struct nft_expr ;struct nft_expr_ops {void (*eval)(const struct nft_expr *expr,struct nft_data data[NFT_REG_MAX +1 ],const struct nft_pktinfo *pkt); +unsigned int size; +int (*init)(const struct nft_ctx *ctx,const struct nft_expr *expr,const struct nlattr *const tb[]);
@@ -248,14 +268,10 @@ struct nft_expr_ops {int (*dump)(struct sk_buff *skb,const struct nft_expr *expr);const struct nft_data * (*get_verdict)(const struct nft_expr *expr); -struct list_head list; -const char *name; -struct module *owner; -const struct nla_policy *policy; -unsigned int maxattr; -unsigned int size; +const struct nft_expr_type *type; }; +#define NFT_EXPR_MAXATTR 16#define NFT_EXPR_SIZE (size) (sizeof(struct nft_expr) + \ ALIGN(size, __alignof__(struct nft_expr)))
@@ -418,8 +434,8 @@ extern void nft_unregister_afinfo(struct nft_af_info *);extern int nft_register_table (struct nft_table *,int family);extern void nft_unregister_table (struct nft_table *,int family); -extern int nft_register_expr (struct nft_expr_ops *); -extern void nft_unregister_expr (struct nft_expr_ops *); +extern int nft_register_expr (struct nft_expr_type *); +extern void nft_unregister_expr (struct nft_expr_type *);#define MODULE_ALIAS_NFT_FAMILY (family) \ MODULE_ALIAS("nft-afinfo-" __stringify(family))
net/ipv4/netfilter/nf_table_nat_ipv4.c +12 -6
@@ -1,5 +1,5 @@/* -* Copyright (c) 2008 Patrick McHardy <[email protected]> +* Copyright (c) 2008-2009 Patrick McHardy <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -149,15 +149,21 @@ nla_put_failure:return -1 ; } -static struct nft_expr_ops nft_nat_ops__read_mostly = { - .name ="nat" , +static struct nft_expr_type nft_nat_type; +static const struct nft_expr_ops nft_nat_ops = { + .type = &nft_nat_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_nat )), - .owner =THIS_MODULE , .eval = nft_nat_eval, .init = nft_nat_init, .dump = nft_nat_dump, +}; + +static struct nft_expr_type nft_nat_type__read_mostly = { + .name ="nat" , + .ops = &nft_nat_ops, .policy = nft_nat_policy, .maxattr =NFTA_NAT_MAX , + .owner =THIS_MODULE , };/*
@@ -382,7 +388,7 @@ static int __init nf_table_nat_init(void)if (err <0 ) goto err1; - err =nft_register_expr (&nft_nat_ops); + err =nft_register_expr (&nft_nat_type);if (err <0 ) goto err2;
@@ -396,7 +402,7 @@ err1: static void __exit nf_table_nat_exit(void) { -nft_unregister_expr (&nft_nat_ops); +nft_unregister_expr (&nft_nat_type);nft_unregister_table (&nf_table_nat_ipv4,AF_INET ); }
net/ipv4/netfilter/nft_reject_ipv4.c +12 -6
@@ -1,5 +1,5 @@/* -* Copyright (c) 2008 Patrick McHardy <[email protected]> +* Copyright (c) 2008-2009 Patrick McHardy <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -88,25 +88,31 @@ nla_put_failure:return -1 ; } -static struct nft_expr_ops reject_ops__read_mostly = { - .name ="reject" , +static struct nft_expr_type nft_reject_type; +static const struct nft_expr_ops nft_reject_ops = { + .type = &nft_reject_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_reject )), - .owner =THIS_MODULE , .eval = nft_reject_eval, .init = nft_reject_init, .dump = nft_reject_dump, +}; + +static struct nft_expr_type nft_reject_type__read_mostly = { + .name ="reject" , + .ops = &nft_reject_ops, .policy = nft_reject_policy, .maxattr =NFTA_REJECT_MAX , + .owner =THIS_MODULE , };static int __init nft_reject_module_init (void ) { -return nft_register_expr (&reject_ops); +return nft_register_expr (&nft_reject_type); } static void __exit nft_reject_module_exit(void) { -nft_unregister_expr (&reject_ops); +nft_unregister_expr (&nft_reject_type); }module_init (nft_reject_module_init);
net/netfilter/nf_tables_api.c +57 -44
199 lines not on this page · raw message
net/netfilter/nft_bitwise.c +12 -6
@@ -1,5 +1,5 @@/* -* Copyright (c) 2008 Patrick McHardy <[email protected]> +* Copyright (c) 2008-2009 Patrick McHardy <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -118,23 +118,29 @@ nla_put_failure:return -1 ; } -static struct nft_expr_ops nft_bitwise_ops__read_mostly = { - .name ="bitwise" , +static struct nft_expr_type nft_bitwise_type; +static const struct nft_expr_ops nft_bitwise_ops = { + .type = &nft_bitwise_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_bitwise )), - .owner =THIS_MODULE , .eval = nft_bitwise_eval, .init = nft_bitwise_init, .dump = nft_bitwise_dump, +}; + +static struct nft_expr_type nft_bitwise_type__read_mostly = { + .name ="bitwise" , + .ops = &nft_bitwise_ops, .policy = nft_bitwise_policy, .maxattr =NFTA_BITWISE_MAX , + .owner =THIS_MODULE , };int __init nft_bitwise_module_init (void ) { -return nft_register_expr (&nft_bitwise_ops); +return nft_register_expr (&nft_bitwise_type); }void nft_bitwise_module_exit (void ) { -nft_unregister_expr (&nft_bitwise_ops); +nft_unregister_expr (&nft_bitwise_type); }
net/netfilter/nft_byteorder.c +12 -6
@@ -1,5 +1,5 @@/* -* Copyright (c) 2008 Patrick McHardy <[email protected]> +* Copyright (c) 2008-2009 Patrick McHardy <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -145,23 +145,29 @@ nla_put_failure:return -1 ; } -static struct nft_expr_ops nft_byteorder_ops__read_mostly = { - .name ="byteorder" , +static struct nft_expr_type nft_byteorder_type; +static const struct nft_expr_ops nft_byteorder_ops = { + .type = &nft_byteorder_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_byteorder )), - .owner =THIS_MODULE , .eval = nft_byteorder_eval, .init = nft_byteorder_init, .dump = nft_byteorder_dump, +}; + +static struct nft_expr_type nft_byteorder_type__read_mostly = { + .name ="byteorder" , + .ops = &nft_byteorder_ops, .policy = nft_byteorder_policy, .maxattr =NFTA_BYTEORDER_MAX , + .owner =THIS_MODULE , };int __init nft_byteorder_module_init (void ) { -return nft_register_expr (&nft_byteorder_ops); +return nft_register_expr (&nft_byteorder_type); }void nft_byteorder_module_exit (void ) { -nft_unregister_expr (&nft_byteorder_ops); +nft_unregister_expr (&nft_byteorder_type); }
net/netfilter/nft_cmp.c +12 -6
@@ -1,5 +1,5 @@/* -* Copyright (c) 2008 Patrick McHardy <[email protected]> +* Copyright (c) 2008-2009 Patrick McHardy <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -124,23 +124,29 @@ nla_put_failure:return -1 ; } -static struct nft_expr_ops nft_cmp_ops__read_mostly = { - .name ="cmp" , +static struct nft_expr_type nft_cmp_type; +static const struct nft_expr_ops nft_cmp_ops = { + .type = &nft_cmp_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_cmp_expr )), - .owner =THIS_MODULE , .eval = nft_cmp_eval, .init = nft_cmp_init, .dump = nft_cmp_dump, +}; + +static struct nft_expr_type nft_cmp_type__read_mostly = { + .name ="cmp" , + .ops = &nft_cmp_ops, .policy = nft_cmp_policy, .maxattr =NFTA_CMP_MAX , + .owner =THIS_MODULE , };int __init nft_cmp_module_init (void ) { -return nft_register_expr (&nft_cmp_ops); +return nft_register_expr (&nft_cmp_type); }void nft_cmp_module_exit (void ) { -nft_unregister_expr (&nft_cmp_ops); +nft_unregister_expr (&nft_cmp_type); }
net/netfilter/nft_counter.c +14 -8
@@ -1,5 +1,5 @@/* -* Copyright (c) 2008 Patrick McHardy <[email protected]> +* Copyright (c) 2008-2009 Patrick McHardy <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -78,25 +78,31 @@ static int nft_counter_init(const struct nft_ctx *ctx,return 0 ; } -static struct nft_expr_ops nft_counter_ops__read_mostly = { - .name ="counter" , +static struct nft_expr_type nft_counter_type; +static const struct nft_expr_ops nft_counter_ops = { + .type = &nft_counter_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_counter )), - .policy = nft_counter_policy, - .maxattr =NFTA_COUNTER_MAX , - .owner =THIS_MODULE , .eval = nft_counter_eval, .init = nft_counter_init, .dump = nft_counter_dump, }; +static struct nft_expr_type nft_counter_type__read_mostly = { + .name ="counter" , + .ops = &nft_counter_ops, + .policy = nft_counter_policy, + .maxattr =NFTA_COUNTER_MAX , + .owner =THIS_MODULE , +}; +static int __init nft_counter_module_init (void ) { -return nft_register_expr (&nft_counter_ops); +return nft_register_expr (&nft_counter_type); } static void __exit nft_counter_module_exit(void) { -nft_unregister_expr (&nft_counter_ops); +nft_unregister_expr (&nft_counter_type); }module_init (nft_counter_module_init);
net/netfilter/nft_ct.c +12 -6
@@ -1,5 +1,5 @@/* -* Copyright (c) 2008 Patrick McHardy <[email protected]> +* Copyright (c) 2008-2009 Patrick McHardy <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -222,26 +222,32 @@ nla_put_failure:return -1 ; } -static struct nft_expr_ops nft_ct_ops__read_mostly = { - .name ="ct" , +static struct nft_expr_type nft_ct_type; +static const struct nft_expr_ops nft_ct_ops = { + .type = &nft_ct_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_ct )), - .owner =THIS_MODULE , .eval = nft_ct_eval, .init = nft_ct_init, .destroy = nft_ct_destroy, .dump = nft_ct_dump, +}; + +static struct nft_expr_type nft_ct_type__read_mostly = { + .name ="ct" , + .ops = &nft_ct_ops, .policy = nft_ct_policy, .maxattr =NFTA_CT_MAX , + .owner =THIS_MODULE , };static int __init nft_ct_module_init (void ) { -return nft_register_expr (&nft_ct_ops); +return nft_register_expr (&nft_ct_type); } static void __exit nft_ct_module_exit(void) { -nft_unregister_expr (&nft_ct_ops); +nft_unregister_expr (&nft_ct_type); }module_init (nft_ct_module_init);
net/netfilter/nft_expr_template.c +13 -7
@@ -1,5 +1,5 @@/* -* Copyright (c) 2008 Patrick McHardy <[email protected]> +* Copyright (c) 2008-2009 Patrick McHardy <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -33,7 +33,7 @@ static const struct nla_policy nft_template_policy[NFTA_TEMPLATE_MAX + 1] = {static int nft_template_init (const struct nft_ctx *ctx,const struct nft_expr *expr, -const struct nlattr *tb[]) +const struct nlattr *const tb[]) {struct nft_template *priv =nft_expr_priv (expr);
@@ -58,26 +58,32 @@ nla_put_failure:return -1 ; } -static struct nft_expr_ops template_ops__read_mostly = { - .name ="template" , +static struct nft_expr_type nft_template_type; +static const struct nft_expr_ops nft_template_ops = { + .type = &nft_template_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_template )), - .owner =THIS_MODULE , .eval = nft_template_eval, .init = nft_template_init, .destroy = nft_template_destroy, .dump = nft_template_dump, +}; + +static struct nft_expr_type nft_template_type__read_mostly = { + .name ="template" , + .ops = &nft_template_ops, .policy = nft_template_policy, .maxattr =NFTA_TEMPLATE_MAX , + .owner =THIS_MODULE , };static int __init nft_template_module_init (void ) { -return nft_register_expr (&template_ops); +return nft_register_expr (&nft_template_type); } static void __exit nft_template_module_exit(void) { -nft_unregister_expr (&template_ops); +nft_unregister_expr (&nft_template_type); }module_init (nft_template_module_init);
net/netfilter/nft_exthdr.c +11 -5
@@ -98,25 +98,31 @@ nla_put_failure:return -1 ; } -static struct nft_expr_ops exthdr_ops__read_mostly = { - .name ="exthdr" , +static struct nft_expr_type nft_exthdr_type; +static const struct nft_expr_ops nft_exthdr_ops = { + .type = &nft_exthdr_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_exthdr )), - .owner =THIS_MODULE , .eval = nft_exthdr_eval, .init = nft_exthdr_init, .dump = nft_exthdr_dump, +}; + +static struct nft_expr_type nft_exthdr_type__read_mostly = { + .name ="exthdr" , + .ops = &nft_exthdr_ops, .policy = nft_exthdr_policy, .maxattr =NFTA_EXTHDR_MAX , + .owner =THIS_MODULE , };static int __init nft_exthdr_module_init (void ) { -return nft_register_expr (&exthdr_ops); +return nft_register_expr (&nft_exthdr_type); } static void __exit nft_exthdr_module_exit(void) { -nft_unregister_expr (&exthdr_ops); +nft_unregister_expr (&nft_exthdr_type); }module_init (nft_exthdr_module_init);
net/netfilter/nft_immediate.c +12 -6
@@ -1,5 +1,5 @@/* -* Copyright (c) 2008 Patrick McHardy <[email protected]> +* Copyright (c) 2008-2009 Patrick McHardy <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -100,25 +100,31 @@ static const struct nft_data *nft_immediate_get_verdict(const struct nft_expr *ereturn NULL ; } -static struct nft_expr_ops nft_imm_ops__read_mostly = { - .name ="immediate" , +static struct nft_expr_type nft_imm_type; +static const struct nft_expr_ops nft_imm_ops = { + .type = &nft_imm_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_immediate_expr )), - .owner =THIS_MODULE , .eval = nft_immediate_eval, .init = nft_immediate_init, .destroy = nft_immediate_destroy, .dump = nft_immediate_dump, .get_verdict = nft_immediate_get_verdict, +}; + +static struct nft_expr_type nft_imm_type__read_mostly = { + .name ="immediate" , + .ops = &nft_imm_ops, .policy = nft_immediate_policy, .maxattr =NFTA_IMMEDIATE_MAX , + .owner =THIS_MODULE , };int __init nft_immediate_module_init (void ) { -return nft_register_expr (&nft_imm_ops); +return nft_register_expr (&nft_imm_type); }void nft_immediate_module_exit (void ) { -nft_unregister_expr (&nft_imm_ops); +nft_unregister_expr (&nft_imm_type); }
net/netfilter/nft_limit.c +12 -6
@@ -1,5 +1,5 @@/* -* Copyright (c) 2008 Patrick McHardy <[email protected]> +* Copyright (c) 2008-2009 Patrick McHardy <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -84,25 +84,31 @@ nla_put_failure:return -1 ; } -static struct nft_expr_ops nft_limit_ops__read_mostly = { - .name ="limit" , +static struct nft_expr_type nft_limit_type; +static const struct nft_expr_ops nft_limit_ops = { + .type = &nft_limit_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_limit )), - .owner =THIS_MODULE , .eval = nft_limit_eval, .init = nft_limit_init, .dump = nft_limit_dump, +}; + +static struct nft_expr_type nft_limit_type__read_mostly = { + .name ="limit" , + .ops = &nft_limit_ops, .policy = nft_limit_policy, .maxattr =NFTA_LIMIT_MAX , + .owner =THIS_MODULE , };static int __init nft_limit_module_init (void ) { -return nft_register_expr (&nft_limit_ops); +return nft_register_expr (&nft_limit_type); } static void __exit nft_limit_module_exit(void) { -nft_unregister_expr (&nft_limit_ops); +nft_unregister_expr (&nft_limit_type); }module_init (nft_limit_module_init);
net/netfilter/nft_log.c +12 -6
@@ -1,5 +1,5 @@/* -* Copyright (c) 2008 Patrick McHardy <[email protected]> +* Copyright (c) 2008-2009 Patrick McHardy <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -110,26 +110,32 @@ nla_put_failure:return -1 ; } -static struct nft_expr_ops nft_log_ops__read_mostly = { - .name ="log" , +static struct nft_expr_type nft_log_type; +static const struct nft_expr_ops nft_log_ops = { + .type = &nft_log_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_log )), - .owner =THIS_MODULE , .eval = nft_log_eval, .init = nft_log_init, .destroy = nft_log_destroy, .dump = nft_log_dump, +}; + +static struct nft_expr_type nft_log_type__read_mostly = { + .name ="log" , + .ops = &nft_log_ops, .policy = nft_log_policy, .maxattr =NFTA_LOG_MAX , + .owner =THIS_MODULE , };static int __init nft_log_module_init (void ) { -return nft_register_expr (&nft_log_ops); +return nft_register_expr (&nft_log_type); } static void __exit nft_log_module_exit(void) { -nft_unregister_expr (&nft_log_ops); +nft_unregister_expr (&nft_log_type); }module_init (nft_log_module_init);
net/netfilter/nft_lookup.c +11 -5
@@ -112,24 +112,30 @@ nla_put_failure:return -1 ; } -static struct nft_expr_ops nft_lookup_ops__read_mostly = { - .name ="lookup" , +static struct nft_expr_type nft_lookup_type; +static const struct nft_expr_ops nft_lookup_ops = { + .type = &nft_lookup_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_lookup )), - .owner =THIS_MODULE , .eval = nft_lookup_eval, .init = nft_lookup_init, .destroy = nft_lookup_destroy, .dump = nft_lookup_dump, +}; + +static struct nft_expr_type nft_lookup_type__read_mostly = { + .name ="lookup" , + .ops = &nft_lookup_ops, .policy = nft_lookup_policy, .maxattr =NFTA_LOOKUP_MAX , + .owner =THIS_MODULE , };int __init nft_lookup_module_init (void ) { -return nft_register_expr (&nft_lookup_ops); +return nft_register_expr (&nft_lookup_type); }void nft_lookup_module_exit (void ) { -nft_unregister_expr (&nft_lookup_ops); +nft_unregister_expr (&nft_lookup_type); }
net/netfilter/nft_meta.c +12 -6
@@ -1,5 +1,5 @@/* -* Copyright (c) 2008 Patrick McHardy <[email protected]> +* Copyright (c) 2008-2009 Patrick McHardy <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -193,25 +193,31 @@ nla_put_failure:return -1 ; } -static struct nft_expr_ops nft_meta_ops__read_mostly = { - .name ="meta" , +static struct nft_expr_type nft_meta_type; +static const struct nft_expr_ops nft_meta_ops = { + .type = &nft_meta_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_meta )), - .owner =THIS_MODULE , .eval = nft_meta_eval, .init = nft_meta_init, .dump = nft_meta_dump, +}; + +static struct nft_expr_type nft_meta_type__read_mostly = { + .name ="meta" , + .ops = &nft_meta_ops, .policy = nft_meta_policy, .maxattr =NFTA_META_MAX , + .owner =THIS_MODULE , };static int __init nft_meta_module_init (void ) { -return nft_register_expr (&nft_meta_ops); +return nft_register_expr (&nft_meta_type); } static void __exit nft_meta_module_exit(void) { -nft_unregister_expr (&nft_meta_ops); +nft_unregister_expr (&nft_meta_type); }module_init (nft_meta_module_init);
net/netfilter/nft_payload.c +12 -6
@@ -1,5 +1,5 @@/* -* Copyright (c) 2008 Patrick McHardy <[email protected]> +* Copyright (c) 2008-2009 Patrick McHardy <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -115,23 +115,29 @@ nla_put_failure:return -1 ; } -static struct nft_expr_ops nft_payload_ops__read_mostly = { - .name ="payload" , +static struct nft_expr_type nft_payload_type; +static const struct nft_expr_ops nft_payload_ops = { + .type = &nft_payload_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_payload )), - .owner =THIS_MODULE , .eval = nft_payload_eval, .init = nft_payload_init, .dump = nft_payload_dump, +}; + +static struct nft_expr_type nft_payload_type__read_mostly = { + .name ="payload" , + .ops = &nft_payload_ops, .policy = nft_payload_policy, .maxattr =NFTA_PAYLOAD_MAX , + .owner =THIS_MODULE , };int __init nft_payload_module_init (void ) { -return nft_register_expr (&nft_payload_ops); +return nft_register_expr (&nft_payload_type); }void nft_payload_module_exit (void ) { -nft_unregister_expr (&nft_payload_ops); +nft_unregister_expr (&nft_payload_type); }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 6/17 netfilter: nf_tables: add optimized data comparison for small values
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
Add an optimized version of nft_data_cmp() that only handles values of to 4 bytes length.
This patch includes original Patrick McHardy's patch entitled (nf_tables:
inline nft_cmp_fast_eval() into main evaluation loop).
--- include/net/netfilter/nf_tables_core.h | 8 +++ net/netfilter/nf_tables_core.c | 18 ++++- net/netfilter/nft_cmp.c | 116 +++++++++++++++++++++++++------- 3 files changed, 118 insertions(+), 24 deletions(-)
include/net/netfilter/nf_tables_core.h +8 -0
@@ -7,6 +7,14 @@ extern void nf_tables_core_module_exit(void);extern int nft_immediate_module_init (void );extern void nft_immediate_module_exit (void ); +struct nft_cmp_fast_expr { +u32 data; +enum nft_registers sreg:8 ; +u8 len; +}; + +extern const struct nft_expr_ops nft_cmp_fast_ops; +extern int nft_cmp_module_init (void );extern void nft_cmp_module_exit (void );
net/netfilter/nf_tables_core.c +17 -1
@@ -20,6 +20,18 @@#include <net/netfilter/nf_tables_core.h> #include <net/netfilter/nf_tables.h> +static void nft_cmp_fast_eval (const struct nft_expr *expr, +struct nft_data data[NFT_REG_MAX +1 ]) +{ +const struct nft_cmp_fast_expr *priv =nft_expr_priv (expr); +u32 mask; + + mask = ~0U >> (sizeof (priv->data) *BITS_PER_BYTE - priv->len); +if ((data[priv->sreg].data[0 ] & mask) == priv->data) +return ; + data[NFT_REG_VERDICT ].verdict =NFT_BREAK ; +} + unsigned int nft_do_chain(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in,
@@ -48,7 +60,11 @@ next_rule: data[NFT_REG_VERDICT ].verdict =NFT_CONTINUE ;list_for_each_entry_continue_rcu (rule, &chain->rules, list) {nft_rule_for_each_expr (expr, last, rule) { - expr->ops->eval (expr, data, &pkt); +if (expr->ops == &nft_cmp_fast_ops) +nft_cmp_fast_eval (expr, data); +else + expr->ops->eval (expr, data, &pkt); +if (data[NFT_REG_VERDICT ].verdict !=NFT_CONTINUE )break ; }
net/netfilter/nft_cmp.c +93 -23
134 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 7/17 netfilter: nft_payload: add optimized payload implementation for small loads
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
Add an optimized payload expression implementation for small (up to 4 bytes) aligned data loads from the linear packet area.
This patch also includes original Patrick McHardy's entitled (nf_tables:
inline nft_payload_fast_eval() into main evaluation loop).
--- include/net/netfilter/nf_tables_core.h | 9 +++++ net/netfilter/nf_tables_core.c | 31 +++++++++++++- net/netfilter/nft_payload.c | 69 +++++++++++++++++++------------- 3 files changed, 81 insertions(+), 28 deletions(-)
include/net/netfilter/nf_tables_core.h +9 -0
@@ -27,6 +27,15 @@ extern void nft_bitwise_module_exit(void);extern int nft_byteorder_module_init (void );extern void nft_byteorder_module_exit (void ); +struct nft_payload { +enum nft_payload_bases base:8 ; +u8 offset; +u8 len; +enum nft_registers dreg:8 ; +}; + +extern const struct nft_expr_ops nft_payload_fast_ops; +extern int nft_payload_module_init (void );extern void nft_payload_module_exit (void );
net/netfilter/nf_tables_core.c +30 -1
@@ -32,6 +32,34 @@ static void nft_cmp_fast_eval(const struct nft_expr *expr, data[NFT_REG_VERDICT ].verdict =NFT_BREAK ; } +static bool nft_payload_fast_eval (const struct nft_expr *expr, +struct nft_data data[NFT_REG_MAX +1 ], +const struct nft_pktinfo *pkt) +{ +const struct nft_payload *priv =nft_expr_priv (expr); +const struct sk_buff *skb = pkt->skb; +struct nft_data *dest = &data[priv->dreg]; +unsigned char *ptr; + +if (priv->base ==NFT_PAYLOAD_NETWORK_HEADER ) + ptr =skb_network_header (skb); +else + ptr =skb_transport_header (skb); + + ptr += priv->offset; + +if (unlikely (ptr + priv->len >=skb_tail_pointer (skb))) +return false; + +if (priv->len ==2 ) + *(u16 *)dest->data = *(u16 *)ptr; +else if (priv->len ==4 ) + *(u32 *)dest->data = *(u32 *)ptr; +else + *(u8 *)dest->data = *(u8 *)ptr; +return true; +} + unsigned int nft_do_chain(const struct nf_hook_ops *ops, struct sk_buff *skb, const struct net_device *in,
@@ -62,7 +90,8 @@ next_rule:nft_rule_for_each_expr (expr, last, rule) {if (expr->ops == &nft_cmp_fast_ops)nft_cmp_fast_eval (expr, data); -else +else if (expr->ops != &nft_payload_fast_ops || + !nft_payload_fast_eval (expr, data, &pkt)) expr->ops->eval (expr, data, &pkt);if (data[NFT_REG_VERDICT ].verdict !=NFT_CONTINUE )
net/netfilter/nft_payload.c +42 -27
91 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 8/17 netfilter: nf_tables: convert built-in tables/chains to chain types
In reply to Pablo Neira AyusoThis patch converts built-in tables/chains to chain types that allows you to deploy customized table and chain configurations from userspace.
After this patch, you have to specify the chain type when creating a new chain:
add chain ip filter output { type filter hook input priority 0; }
^^^^ ------
The existing chain types after this patch are: filter, route and nat. Note that tables are just containers of chains with no specific semantics, which is a significant change with regards to iptables.
---
include/net/netfilter/nf_tables.h | 31 ++-
include/uapi/linux/netfilter/nf_tables.h | 2 +
net/ipv4/netfilter/Kconfig | 8 +-
net/ipv4/netfilter/Makefile | 4 +-
net/ipv4/netfilter/nf_tables_ipv4.c | 21 +++
.../{nf_table_nat_ipv4.c => nft_chain_nat_ipv4.c} | 116 +++---------
...f_table_route_ipv4.c => nft_chain_route_ipv4.c} | 43 ++---
net/ipv6/netfilter/Kconfig | 4 +-
net/ipv6/netfilter/Makefile | 2 +-
net/ipv6/netfilter/nf_tables_ipv6.c | 22 ++-
...f_table_route_ipv6.c => nft_chain_route_ipv6.c} | 45 ++---
net/netfilter/nf_tables_api.c | 197 +++++++++-----------
12 files changed, 221 insertions(+), 274 deletions(-)
rename net/ipv4/netfilter/{nf_table_nat_ipv4.c => nft_chain_nat_ipv4.c} (76%)
rename net/ipv4/netfilter/{nf_table_route_ipv4.c => nft_chain_route_ipv4.c} (61%)
rename net/ipv6/netfilter/{nf_table_route_ipv6.c => nft_chain_route_ipv6.c} (65%)include/net/netfilter/nf_tables.h +22 -9
@@ -336,7 +336,6 @@ static inline struct nft_expr *nft_expr_last(const struct nft_rule *rule)enum nft_chain_flags {NFT_BASE_CHAIN =0x1 , -NFT_CHAIN_BUILTIN =0x2 , };/**
@@ -362,14 +361,23 @@ struct nft_chain {char name[NFT_CHAIN_MAXNAMELEN ]; }; +enum nft_chain_type { +NFT_CHAIN_T_DEFAULT =0 , +NFT_CHAIN_T_ROUTE , +NFT_CHAIN_T_NAT , +NFT_CHAIN_T_MAX +}; +/** * struct nft_base_chain - nf_tables base chain * * @ops: netfilter hook ops +* @type: chain type * @chain: the chain */ struct nft_base_chain {struct nf_hook_ops ops; +enum nft_chain_type type;struct nft_chain chain; };
@@ -384,10 +392,6 @@ extern unsigned int nft_do_chain(const struct nf_hook_ops *ops,const struct net_device *out, int (*okfn)(struct sk_buff *)); -enum nft_table_flags { -NFT_TABLE_BUILTIN =0x1 , -}; -/** * struct nft_table - nf_tables table *
@@ -431,8 +435,17 @@ struct nft_af_info {extern int nft_register_afinfo (struct nft_af_info *);extern void nft_unregister_afinfo (struct nft_af_info *); -extern int nft_register_table (struct nft_table *,int family); -extern void nft_unregister_table (struct nft_table *,int family); +struct nf_chain_type { +unsigned int hook_mask; +const char *name; +enum nft_chain_type type; +nf_hookfn *fn[NF_MAX_HOOKS ]; +struct module *me; +int family; +}; + +extern int nft_register_chain_type (struct nf_chain_type *); +extern void nft_unregister_chain_type (struct nf_chain_type *);extern int nft_register_expr (struct nft_expr_type *);extern void nft_unregister_expr (struct nft_expr_type *);
@@ -440,8 +453,8 @@ extern void nft_unregister_expr(struct nft_expr_type *);#define MODULE_ALIAS_NFT_FAMILY (family) \ MODULE_ALIAS("nft-afinfo-" __stringify(family)) -#define MODULE_ALIAS_NFT_TABLE (family, name) \ - MODULE_ALIAS("nft-table-" __stringify(family) "-" name) +#define MODULE_ALIAS_NFT_CHAIN (family, name) \ + MODULE_ALIAS("nft-chain-" __stringify(family) "-" name)#define MODULE_ALIAS_NFT_EXPR (name) \ MODULE_ALIAS("nft-expr-" name)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -115,6 +115,7 @@ enum nft_table_attributes {* @NFTA_CHAIN_HANDLE: numeric handle of the chain (NLA_U64) * @NFTA_CHAIN_NAME: name of the chain (NLA_STRING) * @NFTA_CHAIN_HOOK: hook specification for basechains (NLA_NESTED: nft_hook_attributes) +* @NFTA_CHAIN_TYPE: type name of the string (NLA_NUL_STRING) */ enum nft_chain_attributes {NFTA_CHAIN_UNSPEC ,
@@ -122,6 +123,7 @@ enum nft_chain_attributes {NFTA_CHAIN_HANDLE ,NFTA_CHAIN_NAME ,NFTA_CHAIN_HOOK , +NFTA_CHAIN_TYPE , __NFTA_CHAIN_MAX };#define NFTA_CHAIN_MAX (__NFTA_CHAIN_MAX - 1)
net/ipv4/netfilter/Kconfig +4 -4
@@ -44,13 +44,13 @@ config NFT_REJECT_IPV4 depends on NF_TABLES_IPV4 tristate "nf_tables IPv4 reject support" -config NF_TABLE_ROUTE_IPV4 +config NFT_CHAIN_ROUTE_IPV4 depends on NF_TABLES_IPV4 - tristate "IPv4 nf_tables route table support" + tristate "IPv4 nf_tables route chain support" -config NF_TABLE_NAT_IPV4 +config NFT_CHAIN_NAT_IPV4 depends on NF_TABLES_IPV4 - tristate "IPv4 nf_tables nat table support" + tristate "IPv4 nf_tables nat chain support" config IP_NF_IPTABLES tristate "IP tables support (required for filtering/masq/NAT)"
net/ipv4/netfilter/Makefile +2 -2
@@ -29,8 +29,8 @@ obj-$(CONFIG_NF_NAT_PROTO_GRE) += nf_nat_proto_gre.o obj-$(CONFIG_NF_TABLES_IPV4) += nf_tables_ipv4.o obj-$(CONFIG_NFT_REJECT_IPV4) += nft_reject_ipv4.o -obj-$(CONFIG_NF_TABLE_ROUTE_IPV4) += nf_table_route_ipv4.o -obj-$(CONFIG_NF_TABLE_NAT_IPV4) += nf_table_nat_ipv4.o +obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV4) += nft_chain_route_ipv4.o +obj-$(CONFIG_NFT_CHAIN_NAT_IPV4) += nft_chain_nat_ipv4.o # generic IP tables obj-$(CONFIG_IP_NF_IPTABLES) += ip_tables.o
net/ipv4/netfilter/nf_tables_ipv4.c +21 -0
@@ -1,5 +1,6 @@/* * Copyright (c) 2008 Patrick McHardy <[email protected]> +* Copyright (c) 2012-2013 Pablo Neira Ayuso <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -41,14 +42,34 @@ static struct nft_af_info nft_af_ipv4 __read_mostly = { }, }; +static struct nf_chain_type filter_ipv4 = { + .family =NFPROTO_IPV4 , + .name ="filter" , + .type =NFT_CHAIN_T_DEFAULT , + .hook_mask = (1 <<NF_INET_LOCAL_IN ) | + (1 <<NF_INET_LOCAL_OUT ) | + (1 <<NF_INET_FORWARD ) | + (1 <<NF_INET_PRE_ROUTING ) | + (1 <<NF_INET_POST_ROUTING ), + .fn = { + [NF_INET_LOCAL_IN ] = nft_do_chain, + [NF_INET_LOCAL_OUT ] = nft_do_chain, + [NF_INET_FORWARD ] = nft_do_chain, + [NF_INET_PRE_ROUTING ] = nft_do_chain, + [NF_INET_POST_ROUTING ] = nft_do_chain, + }, +}; +static int __init nf_tables_ipv4_init (void ) { +nft_register_chain_type (&filter_ipv4);return nft_register_afinfo (&nft_af_ipv4); } static void __exit nf_tables_ipv4_exit(void) {nft_unregister_afinfo (&nft_af_ipv4); +nft_unregister_chain_type (&filter_ipv4); }module_init (nf_tables_ipv4_init);
net/ipv4/netfilter/nft_chain_nat_ipv4.c renamed from net/ipv4/netfilter/nf_table_nat_ipv4.c +27 -89
154 lines not on this page · raw message
net/ipv4/netfilter/nft_chain_route_ipv4.c renamed from net/ipv4/netfilter/nf_table_route_ipv4.c +16 -27
63 lines not on this page · raw message
net/ipv6/netfilter/Kconfig +2 -2
@@ -29,9 +29,9 @@ config NF_TABLES_IPV6 depends on NF_TABLES tristate "IPv6 nf_tables support" -config NF_TABLE_ROUTE_IPV6 +config NFT_CHAIN_ROUTE_IPV6 depends on NF_TABLES_IPV6 - tristate "IPv6 nf_tables route table support" + tristate "IPv6 nf_tables route chain support" config IP6_NF_IPTABLES tristate "IP6 tables support (required for filtering)"
net/ipv6/netfilter/Makefile +1 -1
@@ -25,7 +25,7 @@ obj-$(CONFIG_NF_DEFRAG_IPV6) += nf_defrag_ipv6.o # nf_tables obj-$(CONFIG_NF_TABLES_IPV6) += nf_tables_ipv6.o -obj-$(CONFIG_NF_TABLE_ROUTE_IPV6) += nf_table_route_ipv6.o +obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV6) += nft_chain_route_ipv6.o # matches obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o
net/ipv6/netfilter/nf_tables_ipv6.c +21 -1
@@ -1,5 +1,6 @@/* * Copyright (c) 2008 Patrick McHardy <[email protected]> +* Copyright (c) 2012-2013 Pablo Neira Ayuso <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -39,14 +40,33 @@ static struct nft_af_info nft_af_ipv6 __read_mostly = { }, }; +static struct nf_chain_type filter_ipv6 = { + .family =NFPROTO_IPV6 , + .name ="filter" , + .type =NFT_CHAIN_T_DEFAULT , + .hook_mask = (1 <<NF_INET_LOCAL_IN ) | + (1 <<NF_INET_LOCAL_OUT ) | + (1 <<NF_INET_FORWARD ) | + (1 <<NF_INET_PRE_ROUTING ) | + (1 <<NF_INET_POST_ROUTING ), + .fn = { + [NF_INET_LOCAL_IN ] = nft_do_chain, + [NF_INET_LOCAL_OUT ] = nft_do_chain, + [NF_INET_FORWARD ] = nft_do_chain, + [NF_INET_PRE_ROUTING ] = nft_do_chain, + [NF_INET_POST_ROUTING ] = nft_do_chain, + }, +}; +static int __init nf_tables_ipv6_init (void ) { +nft_register_chain_type (&filter_ipv6);return nft_register_afinfo (&nft_af_ipv6); } - static void __exit nf_tables_ipv6_exit(void) {nft_unregister_afinfo (&nft_af_ipv6); +nft_unregister_chain_type (&filter_ipv6); }module_init (nf_tables_ipv6_init);
net/ipv6/netfilter/nft_chain_route_ipv6.c renamed from net/ipv6/netfilter/nf_table_route_ipv6.c +17 -28
64 lines not on this page · raw message
net/netfilter/nf_tables_api.c +86 -111
351 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 9/17 netfilter: nf_tables: add compatibility layer for x_tables
In reply to Pablo Neira AyusoThis patch adds the x_tables compatibility layer. This allows you to use existing x_tables matches and targets from nf_tables.
This compatibility later allows us to use existing matches/targets for features that are still missing in nf_tables. We can progressively replace them with native nf_tables extensions. It also provides the userspace compatibility software that allows you to express the rule-set using the iptables syntax but using the nf_tables kernel components.
In order to get this compatibility layer working, I've done the following things:
* add NFNL_SUBSYS_NFT_COMPAT: this new nfnetlink subsystem is used to query the x_tables match/target revision, so we don't need to use the native x_table getsockopt interface.
* emulate xt structures: this required extending the struct nft_pktinfo to include the fragment offset, which is already obtained from ip[6]_tables and that is used by some matches/targets.
* add support for default policy to base chains, required to emulate x_tables.
* add NFTA_CHAIN_USE attribute to obtain the number of references to chains, required by x_tables emulation.
* add chain packet/byte counters using per-cpu.
* support 32-64 bits compat.
For historical reasons, this patch includes the following patches that were posted in the netfilter-devel mailing list.
Quoted 1 line
From Pablo Neira Ayuso:
* nf_tables: add default policy to base chains
* netfilter: nf_tables: add NFTA_CHAIN_USE attribute
* nf_tables: nft_compat: private data of target and matches in contiguous area
* nf_tables: validate hooks for compat match/target
* nf_tables: nft_compat: release cached matches/targets
* nf_tables: x_tables support as a compile time option
* nf_tables: fix alias for xtables over nftables module
* nf_tables: add packet and byte counters per chain
* nf_tables: fix per-chain counter stats if no counters are passed
* nf_tables: don't bump chain stats
* nf_tables: add protocol and flags for xtables over nf_tables
* nf_tables: add ip[6]t_entry emulation
* nf_tables: move specific layer 3 compat code to nf_tables_ipv[4|6]
* nf_tables: support 32bits-64bits x_tables compat
* nf_tables: fix compilation if CONFIG_COMPAT is disabled
Quoted 1 line
From Patrick McHardy:
* nf_tables: move policy to struct nft_base_chain
* nf_tables: send notifications for base chain policy changes
Quoted 1 line
From Alexander Primak:
* nf_tables: remove the duplicate NF_INET_LOCAL_OUT
Quoted 1 line
From Nicolas Dichtel:
* nf_tables: fix compilation when nf-netlink is a module
--- include/net/netfilter/nf_tables.h | 44 +- include/net/netfilter/nf_tables_ipv4.h | 23 + include/net/netfilter/nf_tables_ipv6.h | 30 + include/uapi/linux/netfilter/Kbuild | 1 + include/uapi/linux/netfilter/nf_tables.h | 32 + include/uapi/linux/netfilter/nf_tables_compat.h | 38 ++ include/uapi/linux/netfilter/nfnetlink.h | 3 +- net/ipv4/netfilter/nf_tables_ipv4.c | 32 +- net/ipv4/netfilter/nft_chain_nat_ipv4.c | 6 +- net/ipv4/netfilter/nft_chain_route_ipv4.c | 6 +- net/ipv6/netfilter/nf_tables_ipv6.c | 33 +- net/ipv6/netfilter/nft_chain_route_ipv6.c | 8 +- net/netfilter/Kconfig | 9 + net/netfilter/Makefile | 1 + net/netfilter/nf_tables_api.c | 220 ++++++- net/netfilter/nf_tables_core.c | 46 +- net/netfilter/nft_cmp.c | 3 +- net/netfilter/nft_compat.c | 768 +++++++++++++++++++++++ net/netfilter/nft_immediate.c | 12 +- net/netfilter/nft_payload.c | 4 +- 20 files changed, 1241 insertions(+), 78 deletions(-) create mode 100644 include/net/netfilter/nf_tables_ipv4.h create mode 100644 include/net/netfilter/nf_tables_ipv6.h create mode 100644 include/uapi/linux/netfilter/nf_tables_compat.h create mode 100644 net/netfilter/nft_compat.c
include/net/netfilter/nf_tables.h +37 -7
@@ -3,6 +3,7 @@#include <linux/list.h> #include <linux/netfilter.h> +#include <linux/netfilter/x_tables.h> #include <linux/netfilter/nf_tables.h> #include <net/netlink.h>
@@ -15,8 +16,23 @@ struct nft_pktinfo {u8 hooknum;u8 nhoff;u8 thoff; +/* for x_tables compatibility */ +struct xt_action_param xt; }; +static inline void nft_set_pktinfo (struct nft_pktinfo *pkt, +const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out) +{ + pkt->skb = skb; + pkt->in = pkt->xt.in = in; + pkt->out = pkt->xt.out = out; + pkt->hooknum = pkt->xt.hooknum = ops->hooknum; + pkt->xt.family = ops->pf; +} + struct nft_data { union { u32 data[4];
@@ -57,6 +73,7 @@ static inline void nft_data_debug(const struct nft_data *data)* @afi: address family info * @table: the table the chain is contained in * @chain: the chain the rule is contained in +* @nla: netlink attributes */ struct nft_ctx {const struct sk_buff *skb;
@@ -64,6 +81,7 @@ struct nft_ctx {const struct nft_af_info *afi;const struct nft_table *table;const struct nft_chain *chain; +const struct nlattr *const *nla; };struct nft_data_desc {
@@ -235,7 +253,8 @@ extern void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set,* @maxattr: highest netlink attribute number */ struct nft_expr_type { -const struct nft_expr_ops *(*select_ops)(const struct nlattr *const tb[]); +const struct nft_expr_ops *(*select_ops)(const struct nft_ctx *, +const struct nlattr *const tb[]);const struct nft_expr_ops *ops;struct list_head list;const char *name;
@@ -253,6 +272,8 @@ struct nft_expr_type {* @destroy: destruction function * @dump: function to dump parameters * @type: expression type +* @validate: validate expression, called during loop detection +* @data: extra data to attach to this expression operation */ struct nft_expr ;struct nft_expr_ops {
@@ -267,8 +288,11 @@ struct nft_expr_ops {void (*destroy)(const struct nft_expr *expr);int (*dump)(struct sk_buff *skb,const struct nft_expr *expr); -const struct nft_data * (*get_verdict)(const struct nft_expr *expr); +int (*validate)(const struct nft_ctx *ctx, +const struct nft_expr *expr, +const struct nft_data **data);const struct nft_expr_type *type; +void *data; };#define NFT_EXPR_MAXATTR 16
@@ -368,16 +392,25 @@ enum nft_chain_type { NFT_CHAIN_T_MAX }; +struct nft_stats { +u64 bytes; +u64 pkts; +}; +/** * struct nft_base_chain - nf_tables base chain * * @ops: netfilter hook ops * @type: chain type +* @policy: default policy +* @stats: per-cpu chain stats * @chain: the chain */ struct nft_base_chain {struct nf_hook_ops ops;enum nft_chain_type type; +u8 policy; +struct nft_stats __percpu *stats;struct nft_chain chain; };
@@ -386,11 +419,8 @@ static inline struct nft_base_chain *nft_base_chain(const struct nft_chain *chai return container_of(chain, struct nft_base_chain, chain); } -extern unsigned int nft_do_chain (const struct nf_hook_ops *ops, -struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -int (*okfn)(struct sk_buff *)); +extern unsigned int nft_do_chain_pktinfo (struct nft_pktinfo *pkt, +const struct nf_hook_ops *ops);/** * struct nft_table - nf_tables table
include/net/netfilter/nf_tables_ipv4.h new file +23 -0
@@ -0,0 +1,23 @@ +#ifndef _NF_TABLES_IPV4_H_ +#define _NF_TABLES_IPV4_H_ + +#include <net/netfilter/nf_tables.h> +#include <net/ip.h> + +static inline void +nft_set_pktinfo_ipv4 (struct nft_pktinfo *pkt, +const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out) +{ +struct iphdr *ip; + +nft_set_pktinfo (pkt, ops, skb, in, out); + + pkt->xt.thoff =ip_hdrlen (pkt->skb); + ip =ip_hdr (pkt->skb); + pkt->xt.fragoff =ntohs (ip->frag_off) &IP_OFFSET ; +} + +#endif
include/net/netfilter/nf_tables_ipv6.h new file +30 -0
@@ -0,0 +1,30 @@ +#ifndef _NF_TABLES_IPV6_H_ +#define _NF_TABLES_IPV6_H_ + +#include <linux/netfilter_ipv6/ip6_tables.h> +#include <net/ipv6.h> + +static inline int +nft_set_pktinfo_ipv6 (struct nft_pktinfo *pkt, +const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out) +{ +int protohdr, thoff =0 ; +unsigned short frag_off; + +nft_set_pktinfo (pkt, ops, skb, in, out); + + protohdr =ipv6_find_hdr (pkt->skb, &thoff,-1 , &frag_off,NULL ); +/* If malformed, drop it */ +if (protohdr <0 ) +return -1 ; + + pkt->xt.thoff = thoff; + pkt->xt.fragoff = frag_off; + +return 0 ; +} + +#endif
include/uapi/linux/netfilter/Kbuild +1 -0
@@ -6,6 +6,7 @@ header-y += nf_conntrack_sctp.h header-y += nf_conntrack_tcp.h header-y += nf_conntrack_tuple_common.h header-y += nf_tables.h +header-y += nf_tables_compat.h header-y += nf_nat.h header-y += nfnetlink.h header-y += nfnetlink_acct.h
include/uapi/linux/netfilter/nf_tables.h +32 -0
@@ -115,7 +115,10 @@ enum nft_table_attributes {* @NFTA_CHAIN_HANDLE: numeric handle of the chain (NLA_U64) * @NFTA_CHAIN_NAME: name of the chain (NLA_STRING) * @NFTA_CHAIN_HOOK: hook specification for basechains (NLA_NESTED: nft_hook_attributes) +* @NFTA_CHAIN_POLICY: numeric policy of the chain (NLA_U32) +* @NFTA_CHAIN_USE: number of references to this chain (NLA_U32) * @NFTA_CHAIN_TYPE: type name of the string (NLA_NUL_STRING) +* @NFTA_CHAIN_COUNTERS: counter specification of the chain (NLA_NESTED: nft_counter_attributes) */ enum nft_chain_attributes {NFTA_CHAIN_UNSPEC ,
@@ -123,7 +126,10 @@ enum nft_chain_attributes {NFTA_CHAIN_HANDLE ,NFTA_CHAIN_NAME ,NFTA_CHAIN_HOOK , +NFTA_CHAIN_POLICY , +NFTA_CHAIN_USE ,NFTA_CHAIN_TYPE , +NFTA_CHAIN_COUNTERS , __NFTA_CHAIN_MAX };#define NFTA_CHAIN_MAX (__NFTA_CHAIN_MAX - 1)
@@ -135,6 +141,7 @@ enum nft_chain_attributes {* @NFTA_RULE_CHAIN: name of the chain containing the rule (NLA_STRING) * @NFTA_RULE_HANDLE: numeric handle of the rule (NLA_U64) * @NFTA_RULE_EXPRESSIONS: list of expressions (NLA_NESTED: nft_expr_attributes) +* @NFTA_RULE_COMPAT: compatibility specifications of the rule (NLA_NESTED: nft_rule_compat_attributes) */ enum nft_rule_attributes {NFTA_RULE_UNSPEC ,
@@ -142,11 +149,36 @@ enum nft_rule_attributes {NFTA_RULE_CHAIN ,NFTA_RULE_HANDLE ,NFTA_RULE_EXPRESSIONS , +NFTA_RULE_COMPAT , __NFTA_RULE_MAX };#define NFTA_RULE_MAX (__NFTA_RULE_MAX - 1)/** +* enum nft_rule_compat_flags - nf_tables rule compat flags +* +* @NFT_RULE_COMPAT_F_INV: invert the check result +*/ +enum nft_rule_compat_flags { +NFT_RULE_COMPAT_F_INV = (1 <<1 ), +NFT_RULE_COMPAT_F_MASK =NFT_RULE_COMPAT_F_INV , +}; + +/** +* enum nft_rule_compat_attributes - nf_tables rule compat attributes +* +* @NFTA_RULE_COMPAT_PROTO: numerice value of handled protocol (NLA_U32) +* @NFTA_RULE_COMPAT_FLAGS: bitmask of enum nft_rule_compat_flags (NLA_U32) +*/ +enum nft_rule_compat_attributes { +NFTA_RULE_COMPAT_UNSPEC , +NFTA_RULE_COMPAT_PROTO , +NFTA_RULE_COMPAT_FLAGS , + __NFTA_RULE_COMPAT_MAX +}; +#define NFTA_RULE_COMPAT_MAX (__NFTA_RULE_COMPAT_MAX - 1) + +/** * enum nft_set_flags - nf_tables set flags * * @NFT_SET_ANONYMOUS: name allocation, automatic cleanup on unlink
include/uapi/linux/netfilter/nf_tables_compat.h new file +38 -0
@@ -0,0 +1,38 @@ +#ifndef _NFT_COMPAT_NFNETLINK_H_ +#define _NFT_COMPAT_NFNETLINK_H_ + +enum nft_target_attributes { +NFTA_TARGET_UNSPEC , +NFTA_TARGET_NAME , +NFTA_TARGET_REV , +NFTA_TARGET_INFO , + __NFTA_TARGET_MAX +}; +#define NFTA_TARGET_MAX (__NFTA_TARGET_MAX - 1) + +enum nft_match_attributes { +NFTA_MATCH_UNSPEC , +NFTA_MATCH_NAME , +NFTA_MATCH_REV , +NFTA_MATCH_INFO , + __NFTA_MATCH_MAX +}; +#define NFTA_MATCH_MAX (__NFTA_MATCH_MAX - 1) + +#define NFT_COMPAT_NAME_MAX 32 + +enum { +NFNL_MSG_COMPAT_GET , +NFNL_MSG_COMPAT_MAX +}; + +enum { +NFTA_COMPAT_UNSPEC =0 , +NFTA_COMPAT_NAME , +NFTA_COMPAT_REV , +NFTA_COMPAT_TYPE , + __NFTA_COMPAT_MAX, +}; +#define NFTA_COMPAT_MAX (__NFTA_COMPAT_MAX - 1) + +#endif
include/uapi/linux/netfilter/nfnetlink.h +2 -1
@@ -54,6 +54,7 @@ struct nfgenmsg {#define NFNL_SUBSYS_CTNETLINK_TIMEOUT 8#define NFNL_SUBSYS_CTHELPER 9#define NFNL_SUBSYS_NFTABLES 10 -#define NFNL_SUBSYS_COUNT 11 +#define NFNL_SUBSYS_NFT_COMPAT 11 +#define NFNL_SUBSYS_COUNT 12#endif /* _UAPI_NFNETLINK_H */
net/ipv4/netfilter/nf_tables_ipv4.c +26 -6
@@ -15,6 +15,8 @@#include <linux/netfilter_ipv4.h> #include <net/netfilter/nf_tables.h> #include <net/ip.h> +#include <net/net_namespace.h> +#include <net/netfilter/nf_tables_ipv4.h> static unsigned int nft_ipv4_output(const struct nf_hook_ops *ops, struct sk_buff *skb,
@@ -22,6 +24,8 @@ static unsigned int nft_ipv4_output(const struct nf_hook_ops *ops, const struct net_device *out, int (*okfn)(struct sk_buff *)) { + struct nft_pktinfo pkt; +if (unlikely (skb->len <sizeof (struct iphdr ) ||ip_hdr (skb)->ihl <sizeof (struct iphdr ) /4 )) {if (net_ratelimit ())
@@ -29,8 +33,9 @@ static unsigned int nft_ipv4_output(const struct nf_hook_ops *ops, "packet\n");return NF_ACCEPT ; } +nft_set_pktinfo_ipv4 (&pkt, ops, skb, in, out); -return nft_do_chain (ops, skb, in, out, okfn); +return nft_do_chain_pktinfo (&pkt, ops); }static struct nft_af_info nft_af_ipv4__read_mostly = {
@@ -42,6 +47,21 @@ static struct nft_af_info nft_af_ipv4 __read_mostly = { }, }; + +static unsigned int +nft_do_chain_ipv4 (const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +int (*okfn)(struct sk_buff *)) +{ +struct nft_pktinfo pkt; + +nft_set_pktinfo_ipv4 (&pkt, ops, skb, in, out); + +return nft_do_chain_pktinfo (&pkt, ops); +} +static struct nf_chain_type filter_ipv4 = { .family =NFPROTO_IPV4 , .name ="filter" ,
@@ -52,11 +72,11 @@ static struct nf_chain_type filter_ipv4 = { (1 <<NF_INET_PRE_ROUTING ) | (1 << NF_INET_POST_ROUTING), .fn = { - [NF_INET_LOCAL_IN] = nft_do_chain, - [NF_INET_LOCAL_OUT] = nft_do_chain, - [NF_INET_FORWARD] = nft_do_chain, - [NF_INET_PRE_ROUTING] = nft_do_chain, - [NF_INET_POST_ROUTING] = nft_do_chain, + [NF_INET_LOCAL_IN] = nft_do_chain_ipv4, + [NF_INET_LOCAL_OUT] = nft_ipv4_output, + [NF_INET_FORWARD] = nft_do_chain_ipv4, + [NF_INET_PRE_ROUTING] = nft_do_chain_ipv4, + [NF_INET_POST_ROUTING] = nft_do_chain_ipv4, }, };
net/ipv4/netfilter/nft_chain_nat_ipv4.c +5 -1
@@ -23,6 +23,7 @@#include <net/netfilter/nf_nat.h> #include <net/netfilter/nf_nat_core.h> #include <net/netfilter/nf_tables.h> +#include <net/netfilter/nf_tables_ipv4.h> #include <net/netfilter/nf_nat_l3proto.h> #include <net/ip.h>
@@ -181,6 +182,7 @@ static unsigned int nf_nat_fn(const struct nf_hook_ops *ops,struct nf_conn *ct =nf_ct_get (skb, &ctinfo);struct nf_conn_nat *nat;enum nf_nat_manip_type maniptype =HOOK2MANIP (ops->hooknum); +struct nft_pktinfo pkt;unsigned int ret;if (ct ==NULL ||nf_ct_is_untracked (ct))
@@ -213,7 +215,9 @@ static unsigned int nf_nat_fn(const struct nf_hook_ops *ops,if (nf_nat_initialized (ct, maniptype))break ; - ret =nft_do_chain (ops, skb, in, out, okfn); +nft_set_pktinfo_ipv4 (&pkt, ops, skb, in, out); + + ret =nft_do_chain_pktinfo (&pkt, ops);if (ret !=NF_ACCEPT )return ret;if (!nf_nat_initialized (ct, maniptype)) {
net/ipv4/netfilter/nft_chain_route_ipv4.c +5 -1
@@ -17,6 +17,7 @@#include <linux/netfilter/nfnetlink.h> #include <linux/netfilter/nf_tables.h> #include <net/netfilter/nf_tables.h> +#include <net/netfilter/nf_tables_ipv4.h> #include <net/route.h> #include <net/ip.h>
@@ -27,6 +28,7 @@ static unsigned int nf_route_table_hook(const struct nf_hook_ops *ops, int (*okfn)(struct sk_buff *)) {unsigned int ret; +struct nft_pktinfo pkt;u32 mark;__be32 saddr, daddr;u_int8_t tos;
@@ -37,13 +39,15 @@ static unsigned int nf_route_table_hook(const struct nf_hook_ops *ops, ip_hdrlen(skb) < sizeof(struct iphdr))return NF_ACCEPT ; +nft_set_pktinfo_ipv4 (&pkt, ops, skb, in, out); + mark = skb->mark; iph =ip_hdr (skb); saddr = iph->saddr; daddr = iph->daddr; tos = iph->tos; - ret =nft_do_chain (ops, skb, in, out, okfn); + ret =nft_do_chain_pktinfo (&pkt, ops);if (ret !=NF_DROP && ret !=NF_QUEUE ) { iph =ip_hdr (skb);
net/ipv6/netfilter/nf_tables_ipv6.c +27 -6
@@ -14,6 +14,7 @@#include <linux/ipv6.h> #include <linux/netfilter_ipv6.h> #include <net/netfilter/nf_tables.h> +#include <net/netfilter/nf_tables_ipv6.h> static unsigned int nft_ipv6_output(const struct nf_hook_ops *ops, struct sk_buff *skb,
@@ -21,14 +22,18 @@ static unsigned int nft_ipv6_output(const struct nf_hook_ops *ops, const struct net_device *out, int (*okfn)(struct sk_buff *)) { + struct nft_pktinfo pkt; +if (unlikely (skb->len <sizeof (struct ipv6hdr ))) {if (net_ratelimit ())pr_info ("nf_tables_ipv6: ignoring short SOCK_RAW " "packet\n" );return NF_ACCEPT ; } +if (nft_set_pktinfo_ipv6 (&pkt, ops, skb, in, out) <0 ) +return NF_DROP ; - return nft_do_chain(ops, skb, in, out, okfn); +return nft_do_chain_pktinfo (&pkt, ops); } static struct nft_af_info nft_af_ipv6 __read_mostly = {
@@ -40,6 +45,22 @@ static struct nft_af_info nft_af_ipv6 __read_mostly = { }, }; +static unsigned int +nft_do_chain_ipv6 (const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +int (*okfn)(struct sk_buff *)) +{ +struct nft_pktinfo pkt; + +/* malformed packet, drop it */ +if (nft_set_pktinfo_ipv6 (&pkt, ops, skb, in, out) <0 ) +return NF_DROP ; + +return nft_do_chain_pktinfo (&pkt, ops); +} +static struct nf_chain_type filter_ipv6 = { .family =NFPROTO_IPV6 , .name ="filter" ,
@@ -50,11 +71,11 @@ static struct nf_chain_type filter_ipv6 = { (1 <<NF_INET_PRE_ROUTING ) | (1 << NF_INET_POST_ROUTING), .fn = { - [NF_INET_LOCAL_IN] = nft_do_chain, - [NF_INET_LOCAL_OUT] = nft_do_chain, - [NF_INET_FORWARD] = nft_do_chain, - [NF_INET_PRE_ROUTING] = nft_do_chain, - [NF_INET_POST_ROUTING] = nft_do_chain, + [NF_INET_LOCAL_IN] = nft_do_chain_ipv6, + [NF_INET_LOCAL_OUT] = nft_ipv6_output, + [NF_INET_FORWARD] = nft_do_chain_ipv6, + [NF_INET_PRE_ROUTING] = nft_do_chain_ipv6, + [NF_INET_POST_ROUTING] = nft_do_chain_ipv6, }, };
net/ipv6/netfilter/nft_chain_route_ipv6.c +7 -1
@@ -19,6 +19,7 @@#include <linux/netfilter/nfnetlink.h> #include <linux/netfilter/nf_tables.h> #include <net/netfilter/nf_tables.h> +#include <net/netfilter/nf_tables_ipv6.h> #include <net/route.h> static unsigned int nf_route_table_hook(const struct nf_hook_ops *ops,
@@ -28,10 +29,15 @@ static unsigned int nf_route_table_hook(const struct nf_hook_ops *ops, int (*okfn)(struct sk_buff *)) {unsigned int ret; +struct nft_pktinfo pkt;struct in6_addr saddr, daddr;u_int8_t hop_limit;u32 mark, flowlabel; +/* malformed packet, drop it */ +if (nft_set_pktinfo_ipv6 (&pkt, ops, skb, in, out) <0 ) +return NF_DROP ; +/* save source/dest address, mark, hoplimit, flowlabel, priority */ memcpy (&saddr, &ipv6_hdr (skb)->saddr,sizeof (saddr));memcpy (&daddr, &ipv6_hdr (skb)->daddr,sizeof (daddr));
@@ -41,7 +47,7 @@ static unsigned int nf_route_table_hook(const struct nf_hook_ops *ops,/* flowlabel and prio (includes version, which shouldn't change either */ flowlabel = *((u32 *)ipv6_hdr (skb)); - ret =nft_do_chain (ops, skb, in, out, okfn); + ret =nft_do_chain_pktinfo (&pkt, ops); if (ret != NF_DROP && ret != NF_QUEUE && (memcmp(&ipv6_hdr(skb)->saddr, &saddr, sizeof(saddr)) || memcmp(&ipv6_hdr(skb)->daddr, &daddr, sizeof(daddr)) ||
net/netfilter/Kconfig +9 -0
@@ -450,6 +450,15 @@ config NFT_LIMIT depends on NF_TABLES tristate "Netfilter nf_tables limit module" +config NFT_COMPAT + depends on NF_TABLES + depends on NETFILTER_XTABLES + tristate "Netfilter x_tables over nf_tables module" + help + This is required if you intend to use any of existing + x_tables match/target extensions over the nf_tables + framework. + config NETFILTER_XTABLES tristate "Netfilter Xtables support (required for ip_tables)" default m if NETFILTER_ADVANCED=n
net/netfilter/Makefile +1 -0
@@ -70,6 +70,7 @@ nf_tables-objs += nft_immediate.o nft_cmp.o nft_lookup.o nf_tables-objs += nft_bitwise.o nft_byteorder.o nft_payload.o obj-$(CONFIG_NF_TABLES) += nf_tables.o +obj-$(CONFIG_NFT_COMPAT) += nft_compat.o obj-$(CONFIG_NFT_EXTHDR) += nft_exthdr.o obj-$(CONFIG_NFT_META) += nft_meta.o obj-$(CONFIG_NFT_CT) += nft_ct.o
net/netfilter/nf_tables_api.c +191 -29
383 lines not on this page · raw message
net/netfilter/nf_tables_core.c +27 -19
72 lines not on this page · raw message
net/netfilter/nft_cmp.c +2 -1
@@ -162,7 +162,8 @@ const struct nft_expr_ops nft_cmp_fast_ops = { .dump = nft_cmp_fast_dump, }; -static const struct nft_expr_ops *nft_cmp_select_ops (const struct nlattr *const tb[]) +static const struct nft_expr_ops * +nft_cmp_select_ops (const struct nft_ctx *ctx,const struct nlattr *const tb[]) {struct nft_data_desc desc;struct nft_data data;
net/netfilter/nft_compat.c new file +768 -0
768 lines not on this page · raw message
net/netfilter/nft_immediate.c +7 -5
@@ -90,14 +90,16 @@ nla_put_failure:return -1 ; } -static const struct nft_data *nft_immediate_get_verdict (const struct nft_expr *expr) +static int nft_immediate_validate (const struct nft_ctx *ctx, +const struct nft_expr *expr, +const struct nft_data **data) {const struct nft_immediate_expr *priv =nft_expr_priv (expr);if (priv->dreg ==NFT_REG_VERDICT ) -return &priv->data; -else -return NULL ; + *data = &priv->data; + +return 0 ; }static struct nft_expr_type nft_imm_type;
@@ -108,7 +110,7 @@ static const struct nft_expr_ops nft_imm_ops = { .init = nft_immediate_init, .destroy = nft_immediate_destroy, .dump = nft_immediate_dump, - .get_verdict = nft_immediate_get_verdict, + .validate = nft_immediate_validate, };static struct nft_expr_type nft_imm_type__read_mostly = {
net/netfilter/nft_payload.c +3 -1
@@ -107,7 +107,9 @@ const struct nft_expr_ops nft_payload_fast_ops = { .dump = nft_payload_dump, }; -static const struct nft_expr_ops *nft_payload_select_ops (const struct nlattr *const tb[]) +static const struct nft_expr_ops * +nft_payload_select_ops (const struct nft_ctx *ctx, +const struct nlattr *const tb[]) {enum nft_payload_bases base;unsigned int offset, len;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 10/17 netfilter: nf_tables: nft_payload: fix transport header base
In reply to Pablo Neira AyusoWe cannot use skb->transport_header since it's unset, use pkt->xt.thoff instead.
Now possible using information made available through the x_tables compatibility layer.
--- net/netfilter/nf_tables_core.c | 2 +- net/netfilter/nft_payload.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_core.c +1 -1
@@ -44,7 +44,7 @@ static bool nft_payload_fast_eval(const struct nft_expr *expr,if (priv->base ==NFT_PAYLOAD_NETWORK_HEADER ) ptr =skb_network_header (skb);else - ptr =skb_transport_header (skb); + ptr =skb_network_header (skb) + pkt->xt.thoff; ptr += priv->offset;
net/netfilter/nft_payload.c +1 -1
@@ -36,7 +36,7 @@ static void nft_payload_eval(const struct nft_expr *expr, offset =skb_network_offset (skb);break ;case NFT_PAYLOAD_TRANSPORT_HEADER : - offset =skb_transport_offset (skb); + offset = pkt->xt.thoff;break ;default :BUG ();
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 11/17 netfilter: nf_tables: add support for dormant tables
In reply to Pablo Neira AyusoThis patch allows you to temporarily disable an entire table. You can change the state of a dormant table via NFT_MSG_NEWTABLE messages. Using this operation you can wake up a table, so their chains are registered.
This provides atomicity at chain level. Thus, the rule-set of one chain is applied at once, avoiding any possible intermediate state in every chain. Still, the chains that belongs to a table are registered consecutively. This also allows you to have inactive tables in the kernel.
--- include/uapi/linux/netfilter/nf_tables.h | 11 ++++ net/netfilter/nf_tables_api.c | 97 +++++++++++++++++++++++++++--- 2 files changed, 101 insertions(+), 7 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +11 -0
@@ -97,13 +97,24 @@ enum nft_hook_attributes {#define NFTA_HOOK_MAX (__NFTA_HOOK_MAX - 1)/** +* enum nft_table_flags - nf_tables table flags +* +* @NFT_TABLE_F_DORMANT: this table is not active +*/ +enum nft_table_flags { +NFT_TABLE_F_DORMANT =0x1 , +}; + +/** * enum nft_table_attributes - nf_tables table netlink attributes * * @NFTA_TABLE_NAME: name of the table (NLA_STRING) +* @NFTA_TABLE_FLAGS: bitmask of enum nft_table_flags (NLA_U32) */ enum nft_table_attributes {NFTA_TABLE_UNSPEC ,NFTA_TABLE_NAME , +NFTA_TABLE_FLAGS , __NFTA_TABLE_MAX };#define NFTA_TABLE_MAX (__NFTA_TABLE_MAX - 1)
net/netfilter/nf_tables_api.c +90 -7
145 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 12/17 netfilter: nf_tables: Add support for IPv6 NAT
In reply to Pablo Neira AyusoFrom: Tomasz Bursztyka <[email protected]>
This patch generalizes the NAT expression to support both IPv4 and IPv6 using the existing IPv4/IPv6 NAT infrastructure. This also adds the NAT chain type for IPv6.
This patch collapses the following patches that were posted to the netfilter-devel mailing list, from Tomasz:
* nf_tables: Change NFTA_NAT_ attributes to better semantic significance
* nf_tables: Split IPv4 NAT into NAT expression and IPv4 NAT chain
* nf_tables: Add support for IPv6 NAT expression
* nf_tables: Add support for IPv6 NAT chain
* nf_tables: Fix up build issue on IPv6 NAT support
And, from Pablo Neira Ayuso:
* fix missing dependencies in nft_chain_nat
--- include/uapi/linux/netfilter/nf_tables.h | 18 +-- net/ipv4/netfilter/Kconfig | 1 + net/ipv4/netfilter/nft_chain_nat_ipv4.c | 156 +-------------------- net/ipv6/netfilter/Kconfig | 5 + net/ipv6/netfilter/Makefile | 1 + net/ipv6/netfilter/nft_chain_nat_ipv6.c | 211 ++++++++++++++++++++++++++++ net/netfilter/Kconfig | 6 + net/netfilter/Makefile | 1 + net/netfilter/nft_nat.c | 220 ++++++++++++++++++++++++++++++ 9 files changed, 457 insertions(+), 162 deletions(-) create mode 100644 net/ipv6/netfilter/nft_chain_nat_ipv6.c create mode 100644 net/netfilter/nft_nat.c
include/uapi/linux/netfilter/nf_tables.h +10 -8
@@ -695,18 +695,20 @@ enum nft_nat_types {* enum nft_nat_attributes - nf_tables nat expression netlink attributes * * @NFTA_NAT_TYPE: NAT type (NLA_U32: nft_nat_types) -* @NFTA_NAT_ADDR_MIN: source register of address range start (NLA_U32: nft_registers) -* @NFTA_NAT_ADDR_MAX: source register of address range end (NLA_U32: nft_registers) -* @NFTA_NAT_PROTO_MIN: source register of proto range start (NLA_U32: nft_registers) -* @NFTA_NAT_PROTO_MAX: source register of proto range end (NLA_U32: nft_registers) +* @NFTA_NAT_FAMILY: NAT family (NLA_U32) +* @NFTA_NAT_REG_ADDR_MIN: source register of address range start (NLA_U32: nft_registers) +* @NFTA_NAT_REG_ADDR_MAX: source register of address range end (NLA_U32: nft_registers) +* @NFTA_NAT_REG_PROTO_MIN: source register of proto range start (NLA_U32: nft_registers) +* @NFTA_NAT_REG_PROTO_MAX: source register of proto range end (NLA_U32: nft_registers) */ enum nft_nat_attributes {NFTA_NAT_UNSPEC ,NFTA_NAT_TYPE , -NFTA_NAT_ADDR_MIN , -NFTA_NAT_ADDR_MAX , -NFTA_NAT_PROTO_MIN , -NFTA_NAT_PROTO_MAX , +NFTA_NAT_FAMILY , +NFTA_NAT_REG_ADDR_MIN , +NFTA_NAT_REG_ADDR_MAX , +NFTA_NAT_REG_PROTO_MIN , +NFTA_NAT_REG_PROTO_MAX , __NFTA_NAT_MAX };#define NFTA_NAT_MAX (__NFTA_NAT_MAX - 1)
net/ipv4/netfilter/Kconfig +1 -0
@@ -50,6 +50,7 @@ config NFT_CHAIN_ROUTE_IPV4 config NFT_CHAIN_NAT_IPV4 depends on NF_TABLES_IPV4 + depends on NF_NAT_IPV4 && NFT_NAT tristate "IPv4 nf_tables nat chain support" config IP_NF_IPTABLES
net/ipv4/netfilter/nft_chain_nat_ipv4.c +2 -154
196 lines not on this page · raw message
net/ipv6/netfilter/Kconfig +5 -0
@@ -33,6 +33,11 @@ config NFT_CHAIN_ROUTE_IPV6 depends on NF_TABLES_IPV6 tristate "IPv6 nf_tables route chain support" +config NFT_CHAIN_NAT_IPV6 + depends on NF_TABLES_IPV6 + depends on NF_NAT_IPV6 && NFT_NAT + tristate "IPv6 nf_tables nat chain support" + config IP6_NF_IPTABLES tristate "IP6 tables support (required for filtering)" depends on INET && IPV6
net/ipv6/netfilter/Makefile +1 -0
@@ -26,6 +26,7 @@ obj-$(CONFIG_NF_DEFRAG_IPV6) += nf_defrag_ipv6.o # nf_tables obj-$(CONFIG_NF_TABLES_IPV6) += nf_tables_ipv6.o obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV6) += nft_chain_route_ipv6.o +obj-$(CONFIG_NFT_CHAIN_NAT_IPV6) += nft_chain_nat_ipv6.o # matches obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o
net/ipv6/netfilter/nft_chain_nat_ipv6.c new file +211 -0
211 lines not on this page · raw message
net/netfilter/Kconfig +6 -0
@@ -450,6 +450,12 @@ config NFT_LIMIT depends on NF_TABLES tristate "Netfilter nf_tables limit module" +config NFT_NAT + depends on NF_TABLES + depends on NF_CONNTRACK + depends on NF_NAT + tristate "Netfilter nf_tables nat module" + config NFT_COMPAT depends on NF_TABLES depends on NETFILTER_XTABLES
net/netfilter/Makefile +1 -0
@@ -75,6 +75,7 @@ obj-$(CONFIG_NFT_EXTHDR) += nft_exthdr.o obj-$(CONFIG_NFT_META) += nft_meta.o obj-$(CONFIG_NFT_CT) += nft_ct.o obj-$(CONFIG_NFT_LIMIT) += nft_limit.o +obj-$(CONFIG_NFT_NAT) += nft_nat.o #nf_tables-objs += nft_meta_target.o obj-$(CONFIG_NFT_RBTREE) += nft_rbtree.o obj-$(CONFIG_NFT_HASH) += nft_hash.o
net/netfilter/nft_nat.c new file +220 -0
220 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 13/17 netfilter: nf_tables: complete net namespace support
In reply to Pablo Neira AyusoRegister family per netnamespace to ensure that sets are only visible in its approapriate namespace.
--- include/net/net_namespace.h | 4 ++ include/net/netfilter/nf_tables.h | 4 +- include/net/netns/nftables.h | 15 ++++++ net/bridge/netfilter/nf_tables_bridge.c | 32 +++++++++++- net/ipv4/netfilter/nf_tables_ipv4.c | 32 +++++++++++- net/ipv6/netfilter/nf_tables_ipv6.c | 33 +++++++++++- net/netfilter/nf_tables_api.c | 83 ++++++++++++++++++++----------- 7 files changed, 168 insertions(+), 35 deletions(-) create mode 100644 include/net/netns/nftables.h
include/net/net_namespace.h +4 -0
@@ -22,6 +22,7 @@#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )#include <net/netns/conntrack.h> #endif +#include <net/netns/nftables.h> #include <net/netns/xfrm.h> struct user_namespace ;
@@ -101,6 +102,9 @@ struct net {#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )struct netns_ct ct;#endif +#if defined(CONFIG_NF_TABLES ) || defined(CONFIG_NF_TABLES_MODULE ) +struct netns_nftables nft; +#endif #if IS_ENABLED (CONFIG_NF_DEFRAG_IPV6 )struct netns_nf_frag nf_frag;#endif
include/net/netfilter/nf_tables.h +3 -1
@@ -68,6 +68,7 @@ static inline void nft_data_debug(const struct nft_data *data)/** * struct nft_ctx - nf_tables rule/set context * +* @net: net namespace * @skb: netlink skb * @nlh: netlink message header * @afi: address family info
@@ -76,6 +77,7 @@ static inline void nft_data_debug(const struct nft_data *data)* @nla: netlink attributes */ struct nft_ctx { +struct net *net;const struct sk_buff *skb;const struct nlmsghdr *nlh;const struct nft_af_info *afi;
@@ -462,7 +464,7 @@ struct nft_af_info {nf_hookfn *hooks[NF_MAX_HOOKS ]; }; -extern int nft_register_afinfo (struct nft_af_info *); +extern int nft_register_afinfo (struct net *,struct nft_af_info *);extern void nft_unregister_afinfo (struct nft_af_info *);struct nf_chain_type {
include/net/netns/nftables.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef _NETNS_NFTABLES_H_ +#define _NETNS_NFTABLES_H_ + +#include <linux/list.h> + +struct nft_af_info ; + +struct netns_nftables { +struct list_head af_info; +struct nft_af_info *ipv4; +struct nft_af_info *ipv6; +struct nft_af_info *bridge; +}; + +#endif
net/bridge/netfilter/nf_tables_bridge.c +30 -2
@@ -19,14 +19,42 @@ static struct nft_af_info nft_af_bridge __read_mostly = { .owner = THIS_MODULE, }; +static int nf_tables_bridge_init_net (struct net *net) +{ + net->nft.bridge =kmalloc (sizeof (struct nft_af_info ),GFP_KERNEL ); +if (net->nft.bridge ==NULL ) +return -ENOMEM ; + +memcpy (net->nft.bridge, &nft_af_bridge,sizeof (nft_af_bridge)); + +if (nft_register_afinfo (net, net->nft.bridge) <0 ) + goto err; + +return 0 ; +err: +kfree (net->nft.bridge); +return -ENOMEM ; +} + +static void nf_tables_bridge_exit_net (struct net *net) +{ +nft_unregister_afinfo (net->nft.bridge); +kfree (net->nft.bridge); +} + +static struct pernet_operations nf_tables_bridge_net_ops = { + .init = nf_tables_bridge_init_net, + .exit = nf_tables_bridge_exit_net, +}; +static int __init nf_tables_bridge_init (void ) { -return nft_register_afinfo (&nft_af_bridge); +return register_pernet_subsys (&nf_tables_bridge_net_ops); } static void __exit nf_tables_bridge_exit(void) { -nft_unregister_afinfo (&nft_af_bridge); +return unregister_pernet_subsys (&nf_tables_bridge_net_ops); }module_init (nf_tables_bridge_init);
net/ipv4/netfilter/nf_tables_ipv4.c +30 -2
@@ -14,6 +14,7 @@#include <linux/ip.h> #include <linux/netfilter_ipv4.h> #include <net/netfilter/nf_tables.h> +#include <net/net_namespace.h> #include <net/ip.h> #include <net/net_namespace.h> #include <net/netfilter/nf_tables_ipv4.h>
@@ -47,6 +48,33 @@ static struct nft_af_info nft_af_ipv4 __read_mostly = { }, }; +static int nf_tables_ipv4_init_net (struct net *net) +{ + net->nft.ipv4 =kmalloc (sizeof (struct nft_af_info ),GFP_KERNEL ); +if (net->nft.ipv4 ==NULL ) +return -ENOMEM ; + +memcpy (net->nft.ipv4, &nft_af_ipv4,sizeof (nft_af_ipv4)); + +if (nft_register_afinfo (net, net->nft.ipv4) <0 ) + goto err; + +return 0 ; +err: +kfree (net->nft.ipv4); +return -ENOMEM ; +} + +static void nf_tables_ipv4_exit_net (struct net *net) +{ +nft_unregister_afinfo (net->nft.ipv4); +kfree (net->nft.ipv4); +} + +static struct pernet_operations nf_tables_ipv4_net_ops = { + .init = nf_tables_ipv4_init_net, + .exit = nf_tables_ipv4_exit_net, +}; static unsigned int nft_do_chain_ipv4(const struct nf_hook_ops *ops,
@@ -83,12 +111,12 @@ static struct nf_chain_type filter_ipv4 = {static int __init nf_tables_ipv4_init (void ) {nft_register_chain_type (&filter_ipv4); -return nft_register_afinfo (&nft_af_ipv4); +return register_pernet_subsys (&nf_tables_ipv4_net_ops); } static void __exit nf_tables_ipv4_exit(void) { -nft_unregister_afinfo (&nft_af_ipv4); +unregister_pernet_subsys (&nf_tables_ipv4_net_ops);nft_unregister_chain_type (&filter_ipv4); }
net/ipv6/netfilter/nf_tables_ipv6.c +31 -2
@@ -45,6 +45,34 @@ static struct nft_af_info nft_af_ipv6 __read_mostly = { }, }; +static int nf_tables_ipv6_init_net (struct net *net) +{ + net->nft.ipv6 =kmalloc (sizeof (struct nft_af_info ),GFP_KERNEL ); +if (net->nft.ipv6 ==NULL ) +return -ENOMEM ; + +memcpy (net->nft.ipv6, &nft_af_ipv6,sizeof (nft_af_ipv6)); + +if (nft_register_afinfo (net, net->nft.ipv6) <0 ) + goto err; + +return 0 ; +err: +kfree (net->nft.ipv6); +return -ENOMEM ; +} + +static void nf_tables_ipv6_exit_net (struct net *net) +{ +nft_unregister_afinfo (net->nft.ipv6); +kfree (net->nft.ipv6); +} + +static struct pernet_operations nf_tables_ipv6_net_ops = { + .init = nf_tables_ipv6_init_net, + .exit = nf_tables_ipv6_exit_net, +}; + static unsigned int nft_do_chain_ipv6(const struct nf_hook_ops *ops, struct sk_buff *skb,
@@ -82,11 +110,12 @@ static struct nf_chain_type filter_ipv6 = {static int __init nf_tables_ipv6_init (void ) {nft_register_chain_type (&filter_ipv6); -return nft_register_afinfo (&nft_af_ipv6); +return register_pernet_subsys (&nf_tables_ipv6_net_ops); } + static void __exit nf_tables_ipv6_exit(void) { -nft_unregister_afinfo (&nft_af_ipv6); +unregister_pernet_subsys (&nf_tables_ipv6_net_ops);nft_unregister_chain_type (&filter_ipv6); }
net/netfilter/nf_tables_api.c +55 -28
315 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 14/17 netfilter: nf_tables: add insert operation
In reply to Pablo Neira AyusoFrom: Eric Leblond <[email protected]>
This patch adds a new rule attribute NFTA_RULE_POSITION which is used to store the position of a rule relatively to the others. By providing the create command and specifying the position, the rule is inserted after the rule with the handle equal to the provided position.
Regarding notification, the position attribute specifies the handle of the previous rule to make sure we don't point to any stale rule in notifications coming from the commit path.
This patch includes the following fix from Pablo:
* nf_tables: fix rule deletion event reporting
--- include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nf_tables_api.c | 38 +++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 6 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -153,6 +153,7 @@ enum nft_chain_attributes {* @NFTA_RULE_HANDLE: numeric handle of the rule (NLA_U64) * @NFTA_RULE_EXPRESSIONS: list of expressions (NLA_NESTED: nft_expr_attributes) * @NFTA_RULE_COMPAT: compatibility specifications of the rule (NLA_NESTED: nft_rule_compat_attributes) +* @NFTA_RULE_POSITION: numeric handle of the previous rule (NLA_U64) */ enum nft_rule_attributes {NFTA_RULE_UNSPEC ,
@@ -161,6 +162,7 @@ enum nft_rule_attributes {NFTA_RULE_HANDLE ,NFTA_RULE_EXPRESSIONS ,NFTA_RULE_COMPAT , +NFTA_RULE_POSITION , __NFTA_RULE_MAX };#define NFTA_RULE_MAX (__NFTA_RULE_MAX - 1)
net/netfilter/nf_tables_api.c +32 -6
@@ -1273,6 +1273,7 @@ static const struct nla_policy nft_rule_policy[NFTA_RULE_MAX + 1] = { [NFTA_RULE_HANDLE] = { .type = NLA_U64 }, [NFTA_RULE_EXPRESSIONS] = { .type = NLA_NESTED }, [NFTA_RULE_COMPAT] = { .type = NLA_NESTED }, + [NFTA_RULE_POSITION] = { .type = NLA_U64 }, }; static int nf_tables_fill_rule_info(struct sk_buff *skb, u32 portid, u32 seq,
@@ -1285,9 +1286,10 @@ static int nf_tables_fill_rule_info(struct sk_buff *skb, u32 portid, u32 seq,struct nfgenmsg *nfmsg;const struct nft_expr *expr, *next;struct nlattr *list; +const struct nft_rule *prule; +int type = event |NFNL_SUBSYS_NFTABLES <<8 ; - event |=NFNL_SUBSYS_NFTABLES <<8 ; - nlh =nlmsg_put (skb, portid, seq, event,sizeof (struct nfgenmsg ), + nlh =nlmsg_put (skb, portid, seq, type,sizeof (struct nfgenmsg ), flags);if (nlh ==NULL ) goto nla_put_failure;
@@ -1304,6 +1306,13 @@ static int nf_tables_fill_rule_info(struct sk_buff *skb, u32 portid, u32 seq,if (nla_put_be64 (skb,NFTA_RULE_HANDLE ,cpu_to_be64 (rule->handle))) goto nla_put_failure; +if ((event !=NFT_MSG_DELRULE ) && (rule->list.prev != &chain->rules)) { + prule = list_entry(rule->list.prev, struct nft_rule, list); +if (nla_put_be64 (skb,NFTA_RULE_POSITION , +cpu_to_be64 (prule->handle))) + goto nla_put_failure; + } + list =nla_nest_start (skb,NFTA_RULE_EXPRESSIONS );if (list ==NULL ) goto nla_put_failure;
@@ -1499,7 +1508,7 @@ static int nf_tables_newrule(struct sock *nlsk, struct sk_buff *skb,unsigned int size, i, n;int err, rem;bool create; -u64 handle; +u64 handle, pos_handle; create = nlh->nlmsg_flags &NLM_F_CREATE ? true : false;
@@ -1533,6 +1542,16 @@ static int nf_tables_newrule(struct sock *nlsk, struct sk_buff *skb, handle =nf_tables_alloc_handle (table); } +if (nla[NFTA_RULE_POSITION ]) { +if (!(nlh->nlmsg_flags &NLM_F_CREATE )) +return -EOPNOTSUPP ; + + pos_handle =be64_to_cpu (nla_get_be64 (nla[NFTA_RULE_POSITION ])); + old_rule =__nf_tables_rule_lookup (chain, pos_handle); +if (IS_ERR (old_rule)) +return PTR_ERR (old_rule); + } +nft_ctx_init (&ctx, skb, nlh, afi, table, chain, nla); n =0 ;
@@ -1573,9 +1592,16 @@ static int nf_tables_newrule(struct sock *nlsk, struct sk_buff *skb,list_replace_rcu (&old_rule->list, &rule->list);nf_tables_rule_destroy (old_rule); }else if (nlh->nlmsg_flags &NLM_F_APPEND ) -list_add_tail_rcu (&rule->list, &chain->rules); -else -list_add_rcu (&rule->list, &chain->rules); +if (old_rule) +list_add_rcu (&rule->list, &old_rule->list); +else +list_add_tail_rcu (&rule->list, &chain->rules); +else { +if (old_rule) +list_add_tail_rcu (&rule->list, &old_rule->list); +else +list_add_rcu (&rule->list, &chain->rules); + } nf_tables_rule_notify(skb, nlh, table, chain, rule, NFT_MSG_NEWRULE, nlh->nlmsg_flags & (NLM_F_APPEND | NLM_F_REPLACE),
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 15/17 netfilter: nfnetlink: add batch support and use it from nf_tables
In reply to Pablo Neira AyusoThis patch adds a batch support to nfnetlink. Basically, it adds two new control messages:
* NFNL_MSG_BATCH_BEGIN, that indicates the beginning of a batch, the nfgenmsg->res_id indicates the nfnetlink subsystem ID.
* NFNL_MSG_BATCH_END, that results in the invocation of the ss->commit callback function. If not specified or an error ocurred in the batch, the ss->abort function is invoked instead.
The end message represents the commit operation in nftables, the lack of end message results in an abort. This patch also adds the .call_batch function that is only called from the batch receival path.
This patch adds atomic rule updates and dumps based on bitmask generations. This allows to atomically commit a set of rule-set updates incrementally without altering the internal state of existing nf_tables expressions/matches/targets.
The idea consists of using a generation cursor of 1 bit and a bitmask of 2 bits per rule. Assuming the gencursor is 0, then the genmask (expressed as a bitmask) can be interpreted as:
00 active in the present, will be active in the next generation. 01 inactive in the present, will be active in the next generation. 10 active in the present, will be deleted in the next generation.
^
gencursor
Once you invoke the transition to the next generation, the global gencursor is updated:
00 active in the present, will be active in the next generation. 01 active in the present, needs to zero its future, it becomes 00. 10 inactive in the present, delete now.
^
gencursor
If a dump is in progress and nf_tables enters a new generation, the dump will stop and return -EBUSY to let userspace know that it has to retry again. In order to invalidate dumps, a global genctr counter is increased everytime nf_tables enters a new generation.
This new operation can be used from the user-space utility that controls the firewall, eg.
nft -f restore
The rule updates contained in `file' will be applied atomically.
cat file
-----
add filter INPUT ip saddr 1.1.1.1 counter accept #1
del filter INPUT ip daddr 2.2.2.2 counter drop #2
-EOF-
Note that the rule 1 will be inactive until the transition to the next generation, the rule 2 will be evicted in the next generation.
There is a penalty during the rule update due to the branch misprediction in the packet matching framework. But that should be quickly resolved once the iteration over the commit list that contain rules that require updates is finished.
Event notification happens once the rule-set update has been committed. So we skip notifications is case the rule-set update is aborted, which can happen in case that the rule-set is tested to apply correctly.
This patch squashed the following patches from Pablo:
* nf_tables: atomic rule updates and dumps
* nf_tables: get rid of per rule list_head for commits
* nf_tables: use per netns commit list
* nfnetlink: add batch support and use it from nf_tables
* nf_tables: all rule updates are transactional
* nf_tables: attach replacement rule after stale one
* nf_tables: do not allow deletion/replacement of stale rules
* nf_tables: remove unused NFTA_RULE_FLAGS
--- include/linux/netfilter/nfnetlink.h | 5 + include/net/netfilter/nf_tables.h | 25 +++- include/net/netns/nftables.h | 3 + include/uapi/linux/netfilter/nfnetlink.h | 4 + net/netfilter/nf_tables_api.c | 202 +++++++++++++++++++++++++++--- net/netfilter/nf_tables_core.c | 10 ++ net/netfilter/nfnetlink.c | 175 +++++++++++++++++++++++++- 7 files changed, 401 insertions(+), 23 deletions(-)
include/linux/netfilter/nfnetlink.h +5 -0
@@ -14,6 +14,9 @@ struct nfnl_callback {int (*call_rcu)(struct sock *nl,struct sk_buff *skb,const struct nlmsghdr *nlh,const struct nlattr *const cda[]); +int (*call_batch)(struct sock *nl,struct sk_buff *skb, +const struct nlmsghdr *nlh, +const struct nlattr *const cda[]);const struct nla_policy *policy;/* netlink attribute policy */ const u_int16_t attr_count;/* number of nlattr's */ };
@@ -23,6 +26,8 @@ struct nfnetlink_subsystem {__u8 subsys_id;/* nfnetlink subsystem ID */ __u8 cb_count;/* number of callbacks */ const struct nfnl_callback *cb;/* callback for individual types */ +int (*commit)(struct sk_buff *skb); +int (*abort)(struct sk_buff *skb); };int nfnetlink_subsys_register (const struct nfnetlink_subsystem *n);
include/net/netfilter/nf_tables.h +24 -1
@@ -323,18 +323,39 @@ static inline void *nft_expr_priv(const struct nft_expr *expr)* @list: used internally * @rcu_head: used internally for rcu * @handle: rule handle +* @genmask: generation mask * @dlen: length of expression data * @data: expression data */ struct nft_rule {struct list_head list;struct rcu_head rcu_head; -u64 handle:48 , +u64 handle:46 , + genmask:2 , dlen:16 ;unsigned char data[] __attribute__((aligned (__alignof__(struct nft_expr )))); }; +/** +* struct nft_rule_trans - nf_tables rule update in transaction +* +* @list: used internally +* @rule: rule that needs to be updated +* @chain: chain that this rule belongs to +* @table: table for which this chain applies +* @nlh: netlink header of the message that contain this update +* @family: family expressesed as AF_* +*/ +struct nft_rule_trans { +struct list_head list; +struct nft_rule *rule; +const struct nft_chain *chain; +const struct nft_table *table; +const struct nlmsghdr *nlh; +u8 family; +}; +static inline struct nft_expr *nft_expr_first (const struct nft_rule *rule) {return (struct nft_expr *)&rule->data[0 ];
@@ -370,6 +391,7 @@ enum nft_chain_flags {* @rules: list of rules in the chain * @list: used internally * @rcu_head: used internally +* @net: net namespace that this chain belongs to * @handle: chain handle * @flags: bitmask of enum nft_chain_flags * @use: number of jump references to this chain
@@ -380,6 +402,7 @@ struct nft_chain {struct list_head rules;struct list_head list;struct rcu_head rcu_head; +struct net *net;u64 handle;u8 flags;u16 use;
include/net/netns/nftables.h +3 -0
@@ -7,9 +7,12 @@ struct nft_af_info;struct netns_nftables {struct list_head af_info; +struct list_head commit_list;struct nft_af_info *ipv4;struct nft_af_info *ipv6;struct nft_af_info *bridge; +u8 gencursor; +u8 genctr; };#endif
include/uapi/linux/netfilter/nfnetlink.h +4 -0
@@ -57,4 +57,8 @@ struct nfgenmsg {#define NFNL_SUBSYS_NFT_COMPAT 11#define NFNL_SUBSYS_COUNT 12 +/* Reserved control nfnetlink messages */ +#define NFNL_MSG_BATCH_BEGIN NLMSG_MIN_TYPE +#define NFNL_MSG_BATCH_END NLMSG_MIN_TYPE+1 +#endif /* _UAPI_NFNETLINK_H */
net/netfilter/nf_tables_api.c +184 -18
321 lines not on this page · raw message
net/netfilter/nf_tables_core.c +10 -0
@@ -88,12 +88,22 @@ nft_do_chain_pktinfo(struct nft_pktinfo *pkt, const struct nf_hook_ops *ops)struct nft_data data[NFT_REG_MAX +1 ];unsigned int stackptr =0 ;struct nft_jumpstack jumpstack[NFT_JUMP_STACK_SIZE ]; +/* +* Cache cursor to avoid problems in case that the cursor is updated +* while traversing the ruleset. +*/ +unsigned int gencursor =ACCESS_ONCE (chain->net->nft.gencursor); do_chain: rule = list_entry(&chain->rules, struct nft_rule, list); next_rule: data[NFT_REG_VERDICT ].verdict =NFT_CONTINUE ;list_for_each_entry_continue_rcu (rule, &chain->rules, list) { + +/* This rule is not active, skip. */ +if (unlikely (rule->genmask & (1 << gencursor))) +continue ; +nft_rule_for_each_expr (expr, last, rule) {if (expr->ops == &nft_cmp_fast_ops)nft_cmp_fast_eval (expr, data);
net/netfilter/nfnetlink.c +171 -4
189 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 16/17 netfilter: nf_tables: add trace support
In reply to Pablo Neira AyusoThis patch adds support for tracing the packet travel through the ruleset, in a similar fashion to x_tables.
--- include/net/netfilter/nf_tables.h | 2 ++ net/netfilter/nf_tables_api.c | 1 + net/netfilter/nf_tables_core.c | 57 +++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+)
include/net/netfilter/nf_tables.h +2 -0
@@ -392,6 +392,7 @@ enum nft_chain_flags {* @list: used internally * @rcu_head: used internally * @net: net namespace that this chain belongs to +* @table: table that this chain belongs to * @handle: chain handle * @flags: bitmask of enum nft_chain_flags * @use: number of jump references to this chain
@@ -403,6 +404,7 @@ struct nft_chain {struct list_head list;struct rcu_head rcu_head;struct net *net; +struct nft_table *table;u64 handle;u8 flags;u16 use;
net/netfilter/nf_tables_api.c +1 -0
@@ -979,6 +979,7 @@ static int nf_tables_newchain(struct sock *nlsk, struct sk_buff *skb,INIT_LIST_HEAD (&chain->rules); chain->handle =nf_tables_alloc_handle (table); chain->net = net; + chain->table = table;nla_strlcpy (chain->name, name,NFT_CHAIN_MAXNAMELEN ); if (!(table->flags & NFT_TABLE_F_DORMANT) &&
net/netfilter/nf_tables_core.c +57 -0
117 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 17/17 netfilter: nf_tables: add ARP filtering support
In reply to Pablo Neira AyusoThis patch registers the ARP family and he filter chain type for this family.
--- include/net/netns/nftables.h | 1 + net/ipv4/netfilter/Kconfig | 4 ++ net/ipv4/netfilter/Makefile | 1 + net/ipv4/netfilter/nf_tables_arp.c | 102 ++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 net/ipv4/netfilter/nf_tables_arp.c
include/net/netns/nftables.h +1 -0
@@ -10,6 +10,7 @@ struct netns_nftables {struct list_head commit_list;struct nft_af_info *ipv4;struct nft_af_info *ipv6; +struct nft_af_info *arp;struct nft_af_info *bridge;u8 gencursor;u8 genctr;
net/ipv4/netfilter/Kconfig +4 -0
@@ -53,6 +53,10 @@ config NFT_CHAIN_NAT_IPV4 depends on NF_NAT_IPV4 && NFT_NAT tristate "IPv4 nf_tables nat chain support" +config NF_TABLES_ARP + depends on NF_TABLES + tristate "ARP nf_tables support" + config IP_NF_IPTABLES tristate "IP tables support (required for filtering/masq/NAT)" default m if NETFILTER_ADVANCED=n
net/ipv4/netfilter/Makefile +1 -0
@@ -31,6 +31,7 @@ obj-$(CONFIG_NF_TABLES_IPV4) += nf_tables_ipv4.o obj-$(CONFIG_NFT_REJECT_IPV4) += nft_reject_ipv4.o obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV4) += nft_chain_route_ipv4.o obj-$(CONFIG_NFT_CHAIN_NAT_IPV4) += nft_chain_nat_ipv4.o +obj-$(CONFIG_NF_TABLES_ARP) += nf_tables_arp.o # generic IP tables obj-$(CONFIG_IP_NF_IPTABLES) += ip_tables.o
net/ipv4/netfilter/nf_tables_arp.c new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Mon, 14 Oct 2013 18:38:41 +0200
Quoted 4 lines
The following patchset contains the current original
nf_tablestree condensed in 17 patches. I have organized them by chronogical order since the originalnf_tablescode was released in 2009 and by dependencies between the different patches.
...
Quoted 11 lines
There is still work to do to fully replace
x_tables[4] [5] but that can be done incrementally by extending our netlink API. Moreover, looking at netfilter-devel and the amount of contributions tonf_tableswe've been getting, I think it would be good to have it mainstream to avoid accumulating large patchsets skip continuous rebases.I tried to provide a reasonable patchset, we have more than 100 accumulated patches in the original
nf_tablestree, so I collapsed many of the small fixes to the main patch we had since 2009 and provide a small batch for review to netdev, while trying to retain part of the history.
Quoted 4 lines
For those who didn't give a try to
nf_tablesyet, there's a quick howto available from Eric Leblond that describes how to get things working [6].Comments/reviews welcome.
This looks great, pulled, thanks a lot!!
Re: [PATCH 03/17] netfilter: add nftables
In reply to Pablo Neira AyusoQuoted 7 lines · Pablo Neira Ayuso
net/ipv4/netfilter/nf_table_nat_ipv4.c new file +6
-0+static int __init nf_table_nat_init (void ) +{ +int err; + +list_add_tail (&nf_chain_nat_prerouting.chain.list, + &nf_table_nat_ipv4.chains);
net/ipv4/netfilter/nf_table_nat_ipv4.c line 383
Quoted 10 lines
net/ipv4/netfilter/nf_table_nat_ipv4.c new file +10
-0+list_add_tail (&nf_chain_nat_postrouting.chain.list, + &nf_table_nat_ipv4.chains); +list_add_tail (&nf_chain_nat_output.chain.list, + &nf_table_nat_ipv4.chains); +list_add_tail (&nf_chain_nat_input.chain.list, + &nf_table_nat_ipv4.chains); + + err =nft_register_table (&nf_table_nat_ipv4,NFPROTO_IPV4 ); +if (err <0 ) + goto err1;
Why do we still have this redundant table separation?
This ugly 90s era relict was a result of the module split, but given that arbitrary base chain creation is now exposed, it is no longer necessary. (It was not really necessary before either, but that is how things grew in the past.) Don't carry over 90s mistakes.