Netfilter updates for net-next
Subsystems (4)
Pablo Neira Ayuso
maintainercover Netfilter updates for net-next
Hi David,
The following patchset contains Netfilter updates for your net-next tree. Basically, updates to the conntrack core, enhancements for nf_tables, conversion of netfilter hooks from linked list to array to improve memory locality and asorted improvements for the Netfilter codebase. More specifically, they are:
1) Add expection to hashes after timer initialization to prevent access from another CPU that walks on the hashes and calls del_timer(), from Florian Westphal.
2) Don't update nf_tables chain counters from hot path, this is only used by the x_tables compatibility layer.
3) Get rid of nested rcu_read_lock() calls from netfilter hook path. Hooks are always guaranteed to run from rcu read side, so remove nested rcu_read_lock() where possible. Patch from Taehee Yoo.
4) nf_tables new ruleset generation notifications include PID and name of the process that has updated the ruleset, from Phil Sutter.
5) Use skb_header_pointer() from nft_fib, so we can reuse this code from the nf_family netdev family. Patch from Pablo M. Bermudo.
6) Add support for nft_fib in nf_tables netdev family, also from Pablo.
7) Use deferrable workqueue for conntrack garbage collection, to reduce power consumption, from Patch from Subash Abhinov Kasiviswanathan.
8) Add nf_ct_expect_iterate_net() helper and use it. From Florian Westphal.
9) Call nf_ct_unconfirmed_destroy only from cttimeout, from Florian.
10) Drop references on conntrack removal path when skbuffs has escaped via nfqueue, from Florian.
11) Don't queue packets to nfqueue with dying conntrack, from Florian.
12) Constify nf_hook_ops structure, from Florian.
13) Remove neededlessly branch in nf_tables trace code, from Phil Sutter.
14) Add nla_strdup(), from Phil Sutter.
15) Rise nf_tables objects name size up to 255 chars, people want to use DNS names, so increase this according to what RFC 1035 specifies. Patch series from Phil Sutter.
16) Kill nf_conntrack_default_on, it's broken. Default on conntrack hook registration on demand, suggested by Eric Dumazet, patch from Florian.
17) Remove unused variables in compat_copy_entry_from_user both in ip_tables and arp_tables code. Patch from Taehee Yoo.
18) Constify struct nf_conntrack_l4proto, from Julia Lawall.
19) Constify nf_loginfo structure, also from Julia.
20) Use a single rb root in connlimit, from Taehee Yoo.
21) Remove unused netfilter_queue_init() prototype, from Taehee Yoo.
22) Use audit_log() instead of open-coding it, from Geliang Tang.
23) Allow to mangle tcp options via nft_exthdr, from Florian.
24) Allow to fetch TCP MSS from nft_rt, from Florian. This includes a fix for a miscalculation of the minimal length.
25) Simplify branch logic in h323 helper, from Nick Desaulniers.
26) Calculate netlink attribute size for conntrack tuple at compile time, from Florian.
27) Remove protocol name field from nf_conntrack_{l3,l4}proto structure. From Florian.
28) Remove holes in nf_conntrack_l4proto structure, so it becomes smaller. From Florian.
29) Get rid of print_tuple() indirection for /proc conntrack listing. Place all the code in net/netfilter/nf_conntrack_standalone.c. Patch from Florian.
30) Do not built in print_conntrack() if CONFIG_NF_CONNTRACK_PROCFS is off. From Florian.
31) Constify most nf_conntrack_{l3,l4}proto helper functions, from Florian.
32) Fix broken indentation in ebtables extensions, from Colin Ian King.
33) Fix several harmless sparse warning, from Florian.
34) Convert netfilter hook infrastructure to use array for better memory locality, joint work done by Florian and Aaron Conole. Moreover, add some instrumentation to debug this.
35) Batch nf_unregister_net_hooks() calls, to call synchronize_net once per batch, from Florian.
36) Get rid of noisy logging in ICMPv6 conntrack helper, from Florian.
37) Get rid of obsolete NFDEBUG() instrumentation, from Varsha Rao.
38) Remove unused code in the generic protocol tracker, from Davide Caratti.
I think I will have material for a second Netfilter batch in my queue if time allow to make it fit in this merge window.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Thanks a lot!
----------------------------------------------------------------
The following changes since commit 7a68ada6ec7d88c68057d3a4c2a517eb94289976:
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net (2017-07-21 03:38:43 +0100)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git HEAD
for you to fetch changes up to 1aff64715edb8565e99337b842d814d636641b50:
netfilter: rt: account for tcp header size too (2017-08-28 18:14:30 +0200)
----------------------------------------------------------------
Aaron Conole (1):
netfilter: convert hook list to an array
Colin Ian King (1):
netfilter: ebtables: fix indent on if statements
Davide Caratti (1):
netfilter: conntrack: remove unused code in nf_conntrack_proto_generic.c
Florian Westphal (24):
netfilter: expect: add to hash table after expect init
netfilter: expect: add and use nf_ct_expect_iterate helpers
netfilter: add and use nf_ct_unconfirmed_destroy
netfilter: conntrack: destroy functions need to free queued packets
netfilter: nfnetlink_queue: don't queue dying conntracks to userspace
netfilter: nf_hook_ops structs can be const
netfilter: nft_set_rbtree: use seqcount to avoid lock in most cases
netfilter: conntrack: do not enable connection tracking unless needed
netfilter: exthdr: factor out tcp option access
netfilter: exthdr: split netlink dump function
netfilter: exthdr: tcp option set support
netfilter: rt: add support to fetch path mss
netfilter: conntrack: compute l3proto nla size at compile time
netfilter: conntrack: remove protocol name from l3proto struct
netfilter: conntrack: remove protocol name from l4proto struct
netfilter: conntrack: reduce size of l4protocol trackers
netfilter: conntrack: place print_tuple in procfs part
netfilter: conntrack: print_conntrack only needed if CONFIG_NF_CONNTRACK_PROCFS
netfilter: conntrack: make protocol tracker pointers const
netfilter: fix a few (harmless) sparse warnings
netfilter: debug: check for sorted array
netfilter: core: batch nf_unregister_net_hooks synchronize_net calls
netfilter: conntrack: don't log "invalid" icmpv6 connections
netfilter: rt: account for tcp header size too
Geliang Tang (1):
netfilter: use audit_log()
Julia Lawall (2):
netfilter: constify nf_conntrack_l3/4proto parameters
netfilter: constify nf_loginfo structures
Nick Desaulniers (1):
netfilter: nf_nat_h323: fix logical-not-parentheses warning
Pablo M. Bermudo Garay (2):
netfilter: nf_tables: fib: use skb_header_pointer
netfilter: nf_tables: add fib expression to the netdev family
Pablo Neira Ayuso (1):
netfilter: nf_tables: keep chain counters away from hot path
Phil Sutter (7):
netfilter: nf_tables: Attach process info to NFT_MSG_NEWGEN notifications
netfilter: nf_tables: No need to check chain existence when tracing
netlink: Introduce nla_strdup()
netfilter: nf_tables: Allow table names of up to 255 chars
netfilter: nf_tables: Allow chain name of up to 255 chars
netfilter: nf_tables: Allow set names of up to 255 chars
netfilter: nf_tables: Allow object names of up to 255 chars
Subash Abhinov Kasiviswanathan (1):
netfilter: conntrack: Change to deferable work queue
Taehee Yoo (4):
netfilter: Remove duplicated rcu_read_lock.
netfilter: xtables: Remove unused variable in compat_copy_entry_from_user()
netfilter: connlimit: merge root4 and root6.
netfilter: remove prototype of netfilter_queue_init
Varsha Rao (1):
netfilter: Remove NFDEBUG()
Documentation/networking/nf_conntrack-sysctl.txt | 11 - drivers/net/ipvlan/ipvlan_main.c | 2 +- include/linux/netdevice.h | 2 +- include/linux/netfilter.h | 45 +-- include/linux/netfilter_ingress.h | 4 +- include/net/netfilter/nf_conntrack.h | 3 + include/net/netfilter/nf_conntrack_expect.h | 5 + include/net/netfilter/nf_conntrack_l3proto.h | 45 +-- include/net/netfilter/nf_conntrack_l4proto.h | 36 +-- include/net/netfilter/nf_conntrack_timeout.h | 4 +- include/net/netfilter/nf_queue.h | 2 +- include/net/netfilter/nf_tables.h | 10 +- include/net/netfilter/nf_tables_core.h | 2 + include/net/netlink.h | 1 + include/net/netns/netfilter.h | 2 +- include/uapi/linux/netfilter/nf_tables.h | 17 +- lib/nlattr.c | 24 ++ net/bridge/br_netfilter_hooks.c | 21 +- net/bridge/netfilter/ebt_ip.c | 4 +- net/bridge/netfilter/ebt_ip6.c | 2 +- net/bridge/netfilter/ebtable_filter.c | 2 +- net/bridge/netfilter/ebtable_nat.c | 2 +- net/bridge/netfilter/ebtables.c | 13 +- net/decnet/netfilter/dn_rtmsg.c | 2 +- net/ipv4/netfilter/arp_tables.c | 2 - net/ipv4/netfilter/ip_tables.c | 4 +- net/ipv4/netfilter/ipt_CLUSTERIP.c | 2 +- net/ipv4/netfilter/ipt_SYNPROXY.c | 2 +- net/ipv4/netfilter/iptable_nat.c | 2 +- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 40 +-- net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 12 - net/ipv4/netfilter/nf_defrag_ipv4.c | 2 +- net/ipv4/netfilter/nf_log_arp.c | 2 +- net/ipv4/netfilter/nf_log_ipv4.c | 2 +- net/ipv4/netfilter/nf_nat_h323.c | 57 ++-- net/ipv4/netfilter/nft_fib_ipv4.c | 20 +- net/ipv6/ila/ila_xlat.c | 2 +- net/ipv6/netfilter/ip6_tables.c | 2 +- net/ipv6/netfilter/ip6t_SYNPROXY.c | 2 +- net/ipv6/netfilter/ip6table_nat.c | 2 +- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 42 +-- net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 17 -- net/ipv6/netfilter/nf_defrag_ipv6_hooks.c | 2 +- net/ipv6/netfilter/nf_log_ipv6.c | 2 +- net/ipv6/netfilter/nft_fib_ipv6.c | 29 +- net/netfilter/Kconfig | 9 + net/netfilter/Makefile | 1 + net/netfilter/core.c | 351 +++++++++++++++++++---- net/netfilter/ipvs/ip_vs_core.c | 10 +- net/netfilter/ipvs/ip_vs_ctl.c | 3 - net/netfilter/ipvs/ip_vs_ftp.c | 2 - net/netfilter/ipvs/ip_vs_proto_sctp.c | 11 +- net/netfilter/ipvs/ip_vs_proto_tcp.c | 10 +- net/netfilter/ipvs/ip_vs_proto_udp.c | 10 +- net/netfilter/ipvs/ip_vs_xmit.c | 46 +-- net/netfilter/nf_conntrack_broadcast.c | 2 - net/netfilter/nf_conntrack_core.c | 44 +-- net/netfilter/nf_conntrack_expect.c | 66 ++++- net/netfilter/nf_conntrack_helper.c | 34 +-- net/netfilter/nf_conntrack_l3proto_generic.c | 7 - net/netfilter/nf_conntrack_netlink.c | 106 +++---- net/netfilter/nf_conntrack_pptp.c | 2 - net/netfilter/nf_conntrack_proto.c | 90 ++---- net/netfilter/nf_conntrack_proto_dccp.c | 18 +- net/netfilter/nf_conntrack_proto_generic.c | 20 -- net/netfilter/nf_conntrack_proto_gre.c | 15 +- net/netfilter/nf_conntrack_proto_sctp.c | 19 +- net/netfilter/nf_conntrack_proto_tcp.c | 19 +- net/netfilter/nf_conntrack_proto_udp.c | 17 -- net/netfilter/nf_conntrack_sip.c | 6 +- net/netfilter/nf_conntrack_standalone.c | 97 ++++++- net/netfilter/nf_internals.h | 10 +- net/netfilter/nf_queue.c | 68 +++-- net/netfilter/nf_sockopt.c | 2 +- net/netfilter/nf_tables_api.c | 128 ++++++--- net/netfilter/nf_tables_core.c | 28 +- net/netfilter/nf_tables_trace.c | 42 ++- net/netfilter/nfnetlink_cttimeout.c | 22 +- net/netfilter/nfnetlink_log.c | 2 +- net/netfilter/nfnetlink_queue.c | 21 +- net/netfilter/nft_exthdr.c | 213 ++++++++++++-- net/netfilter/nft_fib_netdev.c | 87 ++++++ net/netfilter/nft_payload.c | 2 +- net/netfilter/nft_rt.c | 73 ++++- net/netfilter/nft_set_rbtree.c | 49 +++- net/netfilter/x_tables.c | 14 +- net/netfilter/xt_CT.c | 2 +- net/netfilter/xt_TCPMSS.c | 2 - net/netfilter/xt_TPROXY.c | 4 - net/netfilter/xt_addrtype.c | 3 - net/netfilter/xt_connlimit.c | 26 +- net/netfilter/xt_hashlimit.c | 8 +- net/netfilter/xt_osf.c | 2 - net/openvswitch/conntrack.c | 4 +- security/selinux/hooks.c | 2 +- security/smack/smack_netfilter.c | 2 +- 96 files changed, 1443 insertions(+), 896 deletions(-) create mode 100644 net/netfilter/nft_fib_netdev.c
Pablo Neira Ayuso
maintainerPATCH 1/47 netfilter: expect: add to hash table after expect init
From: Florian Westphal <[email protected]>
assuming we have lockless readers we should make sure they can only see expectations that have already been initialized.
hlist_add_head_rcu acts as memory barrier, move it after timer setup.
Theoretically we could crash due to a del_timer() on other cpu seeing garbage data.
--- net/netfilter/nf_conntrack_expect.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
net/netfilter/nf_conntrack_expect.c +6 -6
@@ -368,12 +368,6 @@ static void nf_ct_expect_insert(struct nf_conntrack_expect *exp)/* two references : one for hash insert, one for the timer */ refcount_add (2 , &exp->use); -hlist_add_head_rcu (&exp->lnode, &master_help->expectations); - master_help->expecting[exp->class]++; - -hlist_add_head_rcu (&exp->hnode, &nf_ct_expect_hash[h]); - net->ct.expect_count++; -setup_timer (&exp->timeout, nf_ct_expectation_timed_out, (unsigned long )exp); helper = rcu_dereference_protected(master_help->helper,
@@ -384,6 +378,12 @@ static void nf_ct_expect_insert(struct nf_conntrack_expect *exp) }add_timer (&exp->timeout); +hlist_add_head_rcu (&exp->lnode, &master_help->expectations); + master_help->expecting[exp->class]++; + +hlist_add_head_rcu (&exp->hnode, &nf_ct_expect_hash[h]); + net->ct.expect_count++; +NF_CT_STAT_INC (net, expect_create); }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 2/47 netfilter: nf_tables: keep chain counters away from hot path
In reply to Pablo Neira AyusoThese chain counters are only used by the iptables-compat tool, that allow users to use the x_tables extensions from the existing nf_tables framework. This patch makes nf_tables by ~5% for the general usecase, ie. native nft users, where no chain counters are used at all.
--- include/net/netfilter/nf_tables_core.h | 2 ++ net/netfilter/nf_tables_api.c | 11 +++-------- net/netfilter/nf_tables_core.c | 26 ++++++++++++++++++-------- 3 files changed, 23 insertions(+), 16 deletions(-)
include/net/netfilter/nf_tables_core.h +2 -0
@@ -49,6 +49,8 @@ struct nft_payload_set { };extern const struct nft_expr_ops nft_payload_fast_ops; + +extern struct static_key_false nft_counters_enabled;extern struct static_key_false nft_trace_enabled;#endif /* _NET_NF_TABLES_CORE_H */
net/netfilter/nf_tables_api.c +3 -8
@@ -1240,6 +1240,8 @@ static void nf_tables_chain_destroy(struct nft_chain *chain)module_put (basechain->type->owner);free_percpu (basechain->stats); +if (basechain->stats) +static_branch_dec (&nft_counters_enabled);if (basechain->ops[0 ].dev !=NULL )dev_put (basechain->ops[0 ].dev);kfree (basechain);
@@ -1504,14 +1506,7 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,return PTR_ERR (stats); } basechain->stats = stats; - }else { - stats = netdev_alloc_pcpu_stats(struct nft_stats); -if (stats ==NULL ) { -nft_chain_release_hook (&hook); -kfree (basechain); -return -ENOMEM ; - } -rcu_assign_pointer (basechain->stats, stats); +static_branch_inc (&nft_counters_enabled); } hookfn = hook.type->hooks[hook.num];
net/netfilter/nf_tables_core.c +18 -8
@@ -114,6 +114,22 @@ static bool nft_payload_fast_eval(const struct nft_expr *expr,return true; } +DEFINE_STATIC_KEY_FALSE (nft_counters_enabled); + +static noinline void nft_update_chain_stats(const struct nft_chain *chain, +const struct nft_pktinfo *pkt) +{ +struct nft_stats *stats; + +local_bh_disable (); + stats =this_cpu_ptr (rcu_dereference (nft_base_chain (chain)->stats)); +u64_stats_update_begin (&stats->syncp); + stats->pkts++; + stats->bytes += pkt->skb->len; +u64_stats_update_end (&stats->syncp); +local_bh_enable (); +} +struct nft_jumpstack {const struct nft_chain *chain;const struct nft_rule *rule;
@@ -130,7 +146,6 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv)struct nft_regs regs;unsigned int stackptr =0 ;struct nft_jumpstack jumpstack[NFT_JUMP_STACK_SIZE ]; -struct nft_stats *stats;int rulenum;unsigned int gencursor =nft_genmask_cur (net);struct nft_traceinfo info;
@@ -220,13 +235,8 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv)nft_trace_packet (&info, basechain,NULL ,-1 ,NFT_TRACETYPE_POLICY ); -rcu_read_lock_bh (); - stats =this_cpu_ptr (rcu_dereference (nft_base_chain (basechain)->stats)); -u64_stats_update_begin (&stats->syncp); - stats->pkts++; - stats->bytes += pkt->skb->len; -u64_stats_update_end (&stats->syncp); -rcu_read_unlock_bh (); +if (static_branch_unlikely (&nft_counters_enabled)) +nft_update_chain_stats (basechain, pkt);return nft_base_chain (basechain)->policy; }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 3/47 netfilter: Remove duplicated rcu_read_lock.
In reply to Pablo Neira AyusoFrom: Taehee Yoo <[email protected]>
This patch removes duplicate rcu_read_lock().
1. IPVS part:
According to Julian Anastasov's mention, contexts of ipvs are described
at: http://marc.info/?l=netfilter-devel&m=149562884514072&w=2, in summary:
- packet RX/TX: does not need locks because packets come from hooks.
- sync msg RX: backup server uses RCU locks while registering new connections.
- ip_vs_ctl.c: configuration get/set, RCU locks needed.
- xt_ipvs.c: It is a netfilter match, running from hook context.
As result, rcu_read_lock and rcu_read_unlock can be removed from:
- ip_vs_core.c: all
- ip_vs_ctl.c:
- only from ip_vs_has_real_service
- ip_vs_ftp.c: all
- ip_vs_proto_sctp.c: all
- ip_vs_proto_tcp.c: all
- ip_vs_proto_udp.c: all
- ip_vs_xmit.c: all (contains only packet processing)
2. Netfilter part:
There are three types of functions that are guaranteed the rcu_read_lock(). First, as result, functions are only called by nf_hook():
- nf_conntrack_broadcast_help(), pptp_expectfn(), set_expected_rtp_rtcp().
- tcpmss_reverse_mtu(), tproxy_laddr4(), tproxy_laddr6().
- match_lookup_rt6(), check_hlist(), hashlimit_mt_common().
- xt_osf_match_packet().
Second, functions that caller already held the rcu_read_lock().
- destroy_conntrack(), ctnetlink_conntrack_event().
- ctnl_timeout_find_get(), nfqnl_nf_hook_drop().
Third, functions that are mixed with type1 and type2.
These functions are called by nf_hook() also these are called by ordinary functions that already held the rcu_read_lock():
- __ctnetlink_glue_build(), ctnetlink_expect_event().
- ctnetlink_proto_size().
Applied files are below:
- nf_conntrack_broadcast.c, nf_conntrack_core.c, nf_conntrack_netlink.c.
- nf_conntrack_pptp.c, nf_conntrack_sip.c, nfnetlink_cttimeout.c.
- nfnetlink_queue.c, xt_TCPMSS.c, xt_TPROXY.c, xt_addrtype.c.
- xt_connlimit.c, xt_hashlimit.c, xt_osf.c
Detailed calltrace can be found at:
http://marc.info/?l=netfilter-devel&m=149667610710350&w=2
--- net/netfilter/ipvs/ip_vs_core.c | 8 ------ net/netfilter/ipvs/ip_vs_ctl.c | 3 --- net/netfilter/ipvs/ip_vs_ftp.c | 2 -- net/netfilter/ipvs/ip_vs_proto_sctp.c | 11 ++------ net/netfilter/ipvs/ip_vs_proto_tcp.c | 10 +------- net/netfilter/ipvs/ip_vs_proto_udp.c | 10 +------- net/netfilter/ipvs/ip_vs_xmit.c | 46 +++------------------------------- net/netfilter/nf_conntrack_broadcast.c | 2 -- net/netfilter/nf_conntrack_core.c | 3 --- net/netfilter/nf_conntrack_netlink.c | 12 --------- net/netfilter/nf_conntrack_pptp.c | 2 -- net/netfilter/nf_conntrack_sip.c | 6 +---- net/netfilter/nfnetlink_cttimeout.c | 2 -- net/netfilter/nfnetlink_queue.c | 2 -- net/netfilter/xt_TCPMSS.c | 2 -- net/netfilter/xt_TPROXY.c | 4 --- net/netfilter/xt_addrtype.c | 3 --- net/netfilter/xt_connlimit.c | 3 --- net/netfilter/xt_hashlimit.c | 8 +++--- net/netfilter/xt_osf.c | 2 -- 20 files changed, 13 insertions(+), 128 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +0 -8
@@ -125,14 +125,12 @@ ip_vs_in_stats(struct ip_vs_conn *cp, struct sk_buff *skb) s->cnt.inbytes += skb->len;u64_stats_update_end (&s->syncp); -rcu_read_lock (); svc =rcu_dereference (dest->svc); s =this_cpu_ptr (svc->stats.cpustats);u64_stats_update_begin (&s->syncp); s->cnt.inpkts++; s->cnt.inbytes += skb->len;u64_stats_update_end (&s->syncp); -rcu_read_unlock (); s =this_cpu_ptr (ipvs->tot_stats.cpustats);u64_stats_update_begin (&s->syncp);
@@ -159,14 +157,12 @@ ip_vs_out_stats(struct ip_vs_conn *cp, struct sk_buff *skb) s->cnt.outbytes += skb->len;u64_stats_update_end (&s->syncp); -rcu_read_lock (); svc =rcu_dereference (dest->svc); s =this_cpu_ptr (svc->stats.cpustats);u64_stats_update_begin (&s->syncp); s->cnt.outpkts++; s->cnt.outbytes += skb->len;u64_stats_update_end (&s->syncp); -rcu_read_unlock (); s =this_cpu_ptr (ipvs->tot_stats.cpustats);u64_stats_update_begin (&s->syncp);
@@ -1222,7 +1218,6 @@ static struct ip_vs_conn *__ip_vs_rs_conn_out(unsigned int hooknum,if (!pptr)return NULL ; -rcu_read_lock (); dest =ip_vs_find_real_service (ipvs, af, iph->protocol, &iph->saddr, pptr[0 ]);if (dest) {
@@ -1237,7 +1232,6 @@ static struct ip_vs_conn *__ip_vs_rs_conn_out(unsigned int hooknum, pptr[0], pptr[1]); } } -rcu_read_unlock ();return cp; }
@@ -1689,11 +1683,9 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,if (dest) {struct ip_vs_dest_dst *dest_dst; -rcu_read_lock (); dest_dst =rcu_dereference (dest->dest_dst);if (dest_dst) mtu =dst_mtu (dest_dst->dst_cache); -rcu_read_unlock (); }if (mtu >68 +sizeof (struct iphdr )) mtu -=sizeof (struct iphdr );
net/netfilter/ipvs/ip_vs_ctl.c +0 -3
@@ -550,18 +550,15 @@ bool ip_vs_has_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol,/* Check for "full" addressed entries */ hash =ip_vs_rs_hashkey (af, daddr, dport); -rcu_read_lock ();hlist_for_each_entry_rcu (dest, &ipvs->rs_table[hash], d_list) {if (dest->port == dport && dest->af == af &&ip_vs_addr_equal (af, &dest->addr, daddr) && (dest->protocol == protocol || dest->vfwmark)) {/* HIT */ -rcu_read_unlock ();return true; } } -rcu_read_unlock ();return false; }
net/netfilter/ipvs/ip_vs_ftp.c +0 -2
@@ -269,13 +269,11 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,* hopefully it will succeed on the retransmitted * packet. */ -rcu_read_lock (); mangled =nf_nat_mangle_tcp_packet (skb, ct, ctinfo, iph->ihl *4 , start - data, end - start, buf, buf_len); -rcu_read_unlock ();if (mangled) {ip_vs_nfct_expect_related (skb, ct, n_cp,IPPROTO_TCP ,0 ,0 );
net/netfilter/ipvs/ip_vs_proto_sctp.c +2 -9
@@ -38,7 +38,6 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,return 0 ; } -rcu_read_lock ();if (likely (!ip_vs_iph_inverse (iph))) svc =ip_vs_service_find (ipvs, af, skb->mark, iph->protocol, &iph->daddr, ports[1 ]);
@@ -53,7 +52,6 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,* It seems that we are very loaded. * We have to drop this packet :( */ -rcu_read_unlock (); *verdict =NF_DROP ;return 0 ; }
@@ -67,11 +65,9 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, *verdict =ip_vs_leave (svc, skb, pd, iph); else *verdict =NF_DROP ; -rcu_read_unlock ();return 0 ; } } -rcu_read_unlock ();/* NF_ACCEPT */ return 1 ; }
@@ -526,12 +522,10 @@ static int sctp_app_conn_bind(struct ip_vs_conn *cp)/* Lookup application incarnations and bind the right one */ hash =sctp_app_hashkey (cp->vport); -rcu_read_lock ();list_for_each_entry_rcu (inc, &ipvs->sctp_apps[hash], p_list) {if (inc->port == cp->vport) {if (unlikely (!ip_vs_app_inc_get (inc)))break ; -rcu_read_unlock (); IP_VS_DBG_BUF(9, "%s: Binding conn %s:%u->" "%s:%u to app %s on port %u\n",
@@ -544,11 +538,10 @@ static int sctp_app_conn_bind(struct ip_vs_conn *cp) cp->app = inc;if (inc->init_conn) result = inc->init_conn (inc, cp); - goto out; +break ; } } -rcu_read_unlock (); -out: +return result; }
net/netfilter/ipvs/ip_vs_proto_tcp.c +1 -9
@@ -63,7 +63,6 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, }/* No !th->ack check to allow scheduling on SYN+ACK for Active FTP */ -rcu_read_lock ();if (likely (!ip_vs_iph_inverse (iph))) svc = ip_vs_service_find(ipvs, af, skb->mark, iph->protocol,
@@ -80,7 +79,6 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,* It seems that we are very loaded. * We have to drop this packet :( */ -rcu_read_unlock (); *verdict =NF_DROP ;return 0 ; }
@@ -95,11 +93,9 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, *verdict =ip_vs_leave (svc, skb, pd, iph); else *verdict =NF_DROP ; -rcu_read_unlock ();return 0 ; } } -rcu_read_unlock ();/* NF_ACCEPT */ return 1 ; }
@@ -661,12 +657,10 @@ tcp_app_conn_bind(struct ip_vs_conn *cp)/* Lookup application incarnations and bind the right one */ hash =tcp_app_hashkey (cp->vport); -rcu_read_lock ();list_for_each_entry_rcu (inc, &ipvs->tcp_apps[hash], p_list) {if (inc->port == cp->vport) {if (unlikely (!ip_vs_app_inc_get (inc)))break ; -rcu_read_unlock (); IP_VS_DBG_BUF(9, "%s(): Binding conn %s:%u->" "%s:%u to app %s on port %u\n",
@@ -680,12 +674,10 @@ tcp_app_conn_bind(struct ip_vs_conn *cp) cp->app = inc;if (inc->init_conn) result = inc->init_conn (inc, cp); - goto out; +break ; } } -rcu_read_unlock (); - out:return result; }
net/netfilter/ipvs/ip_vs_proto_udp.c +1 -9
@@ -53,7 +53,6 @@ udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,return 0 ; } -rcu_read_lock ();if (likely (!ip_vs_iph_inverse (iph))) svc =ip_vs_service_find (ipvs, af, skb->mark, iph->protocol, &iph->daddr, ports[1 ]);
@@ -69,7 +68,6 @@ udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,* It seems that we are very loaded. * We have to drop this packet :( */ -rcu_read_unlock (); *verdict =NF_DROP ;return 0 ; }
@@ -84,11 +82,9 @@ udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, *verdict =ip_vs_leave (svc, skb, pd, iph); else *verdict =NF_DROP ; -rcu_read_unlock ();return 0 ; } } -rcu_read_unlock ();/* NF_ACCEPT */ return 1 ; }
@@ -410,12 +406,10 @@ static int udp_app_conn_bind(struct ip_vs_conn *cp)/* Lookup application incarnations and bind the right one */ hash =udp_app_hashkey (cp->vport); -rcu_read_lock ();list_for_each_entry_rcu (inc, &ipvs->udp_apps[hash], p_list) {if (inc->port == cp->vport) {if (unlikely (!ip_vs_app_inc_get (inc)))break ; -rcu_read_unlock (); IP_VS_DBG_BUF(9, "%s(): Binding conn %s:%u->" "%s:%u to app %s on port %u\n",
@@ -429,12 +423,10 @@ static int udp_app_conn_bind(struct ip_vs_conn *cp) cp->app = inc;if (inc->init_conn) result = inc->init_conn (inc, cp); - goto out; +break ; } } -rcu_read_unlock (); - out:return result; }
net/netfilter/ipvs/ip_vs_xmit.c +4 -42
249 lines not on this page · raw message
net/netfilter/nf_conntrack_broadcast.c +0 -2
@@ -40,7 +40,6 @@ int nf_conntrack_broadcast_help(struct sk_buff *skb,if (CTINFO2DIR (ctinfo) !=IP_CT_DIR_ORIGINAL ) goto out; -rcu_read_lock (); in_dev =__in_dev_get_rcu (rt->dst.dev);if (in_dev !=NULL ) {for_primary_ifa (in_dev) {
@@ -50,7 +49,6 @@ int nf_conntrack_broadcast_help(struct sk_buff *skb, } }endfor_ifa (in_dev); } -rcu_read_unlock ();if (mask ==0 ) goto out;
net/netfilter/nf_conntrack_core.c +0 -3
@@ -407,13 +407,10 @@ destroy_conntrack(struct nf_conntrack *nfct)nf_ct_tmpl_free (ct);return ; } -rcu_read_lock (); l4proto =__nf_ct_l4proto_find (nf_ct_l3num (ct),nf_ct_protonum (ct));if (l4proto->destroy) l4proto->destroy (ct); -rcu_read_unlock (); -local_bh_disable ();/* Expectations will have been removed in clean_from_lists, * except TFTP can create an expectation on the first packet,
net/netfilter/nf_conntrack_netlink.c +0 -12
@@ -539,13 +539,11 @@ static inline size_t ctnetlink_proto_size(const struct nf_conn *ct)struct nf_conntrack_l4proto *l4proto;size_t len =0 ; -rcu_read_lock (); l3proto =__nf_ct_l3proto_find (nf_ct_l3num (ct)); len += l3proto->nla_size; l4proto =__nf_ct_l4proto_find (nf_ct_l3num (ct),nf_ct_protonum (ct)); len += l4proto->nla_size; -rcu_read_unlock ();return len; }
@@ -664,7 +662,6 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item) nfmsg->version =NFNETLINK_V0 ; nfmsg->res_id =0 ; -rcu_read_lock (); zone =nf_ct_zone (ct); nest_parms =nla_nest_start (skb,CTA_TUPLE_ORIG |NLA_F_NESTED );
@@ -736,8 +733,6 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item) && ctnetlink_dump_mark(skb, ct) < 0) goto nla_put_failure;#endif -rcu_read_unlock (); -nlmsg_end (skb, nlh); err =nfnetlink_send (skb, net, item->portid, group, item->report,GFP_ATOMIC );
@@ -747,7 +742,6 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item)return 0 ; nla_put_failure: -rcu_read_unlock ();nlmsg_cancel (skb, nlh); nlmsg_failure:kfree_skb (skb);
@@ -2213,7 +2207,6 @@ static int __ctnetlink_glue_build(struct sk_buff *skb, struct nf_conn *ct)const struct nf_conntrack_zone *zone;struct nlattr *nest_parms; -rcu_read_lock (); zone =nf_ct_zone (ct); nest_parms =nla_nest_start (skb,CTA_TUPLE_ORIG |NLA_F_NESTED );
@@ -2272,11 +2265,9 @@ static int __ctnetlink_glue_build(struct sk_buff *skb, struct nf_conn *ct)#endif if (ctnetlink_dump_labels (skb, ct) <0 ) goto nla_put_failure; -rcu_read_unlock ();return 0 ; nla_put_failure: -rcu_read_unlock ();return -ENOSPC ; }
@@ -2661,17 +2652,14 @@ ctnetlink_expect_event(unsigned int events, struct nf_exp_event *item) nfmsg->version =NFNETLINK_V0 ; nfmsg->res_id =0 ; -rcu_read_lock ();if (ctnetlink_exp_dump_expect (skb, exp) <0 ) goto nla_put_failure; -rcu_read_unlock ();nlmsg_end (skb, nlh);nfnetlink_send (skb, net, item->portid, group, item->report,GFP_ATOMIC );return 0 ; nla_put_failure: -rcu_read_unlock ();nlmsg_cancel (skb, nlh); nlmsg_failure:kfree_skb (skb);
net/netfilter/nf_conntrack_pptp.c +0 -2
@@ -113,7 +113,6 @@ static void pptp_expectfn(struct nf_conn *ct,/* Can you see how rusty this code is, compared with the pre-2.6.11 * one? That's what happened to my shiny newnat of 2002 ;( -HW */ -rcu_read_lock (); nf_nat_pptp_expectfn =rcu_dereference (nf_nat_pptp_hook_expectfn);if (nf_nat_pptp_expectfn && ct->master->status &IPS_NAT_MASK )nf_nat_pptp_expectfn (ct, exp);
@@ -136,7 +135,6 @@ static void pptp_expectfn(struct nf_conn *ct,pr_debug ("not found\n" ); } } -rcu_read_unlock (); } static int destroy_sibling_or_exp(struct net *net, struct nf_conn *ct,
net/netfilter/nf_conntrack_sip.c +1 -5
@@ -884,7 +884,6 @@ static int set_expected_rtp_rtcp(struct sk_buff *skb, unsigned int protoff, tuple.dst.u3 = *daddr; tuple.dst.u.udp.port = port; -rcu_read_lock (); do { exp = __nf_ct_expect_find(net, nf_ct_zone(ct), &tuple);
@@ -918,10 +917,8 @@ static int set_expected_rtp_rtcp(struct sk_buff *skb, unsigned int protoff, goto err1; } -if (skip_expect) { -rcu_read_unlock (); +if (skip_expect)return NF_ACCEPT ; - } rtp_exp =nf_ct_expect_alloc (ct);if (rtp_exp ==NULL )
@@ -952,7 +949,6 @@ static int set_expected_rtp_rtcp(struct sk_buff *skb, unsigned int protoff, err2:nf_ct_expect_put (rtp_exp); err1: -rcu_read_unlock ();return ret; }
net/netfilter/nfnetlink_cttimeout.c +0 -2
@@ -505,7 +505,6 @@ ctnl_timeout_find_get(struct net *net, const char *name) {struct ctnl_timeout *timeout, *matching =NULL ; -rcu_read_lock ();list_for_each_entry_rcu (timeout, &net->nfct_timeout_list, head) {if (strncmp (timeout->name, name,CTNL_TIMEOUT_NAME_MAX ) !=0 )continue ;
@@ -521,7 +520,6 @@ ctnl_timeout_find_get(struct net *net, const char *name)break ; } err: -rcu_read_unlock ();return matching; }
net/netfilter/nfnetlink_queue.c +0 -2
@@ -928,7 +928,6 @@ static unsigned int nfqnl_nf_hook_drop(struct net *net)unsigned int instances =0 ;int i; -rcu_read_lock ();for (i =0 ; i <INSTANCE_BUCKETS ; i++) {struct nfqnl_instance *inst;struct hlist_head *head = &q->instance_table[i];
@@ -938,7 +937,6 @@ static unsigned int nfqnl_nf_hook_drop(struct net *net) instances++; } } -rcu_read_unlock ();return instances; }
net/netfilter/xt_TCPMSS.c +0 -2
@@ -62,11 +62,9 @@ static u_int32_t tcpmss_reverse_mtu(struct net *net,memset (fl6,0 ,sizeof (*fl6)); fl6->daddr =ipv6_hdr (skb)->saddr; } -rcu_read_lock (); ai =nf_get_afinfo (family);if (ai !=NULL ) ai->route (net, (struct dst_entry **)&rt, &fl, false); -rcu_read_unlock ();if (rt !=NULL ) { mtu =dst_mtu (&rt->dst);
net/netfilter/xt_TPROXY.c +0 -4
@@ -70,13 +70,11 @@ tproxy_laddr4(struct sk_buff *skb, __be32 user_laddr, __be32 daddr)return user_laddr; laddr =0 ; -rcu_read_lock (); indev =__in_dev_get_rcu (skb->dev);for_primary_ifa (indev) { laddr = ifa->ifa_local;break ; }endfor_ifa (indev); -rcu_read_unlock ();return laddr ? laddr : daddr; }
@@ -391,7 +389,6 @@ tproxy_laddr6(struct sk_buff *skb, const struct in6_addr *user_laddr,return user_laddr; laddr =NULL ; -rcu_read_lock (); indev =__in6_dev_get (skb->dev);if (indev) {read_lock_bh (&indev->lock);
@@ -404,7 +401,6 @@ tproxy_laddr6(struct sk_buff *skb, const struct in6_addr *user_laddr, }read_unlock_bh (&indev->lock); } -rcu_read_unlock ();return laddr ? laddr : daddr; }
net/netfilter/xt_addrtype.c +0 -3
@@ -47,8 +47,6 @@ static u32 match_lookup_rt6(struct net *net, const struct net_device *dev,if (dev) flow.flowi6_oif = dev->ifindex; -rcu_read_lock (); - afinfo =nf_get_afinfo (NFPROTO_IPV6 );if (afinfo !=NULL ) {const struct nf_ipv6_ops *v6ops;
@@ -63,7 +61,6 @@ static u32 match_lookup_rt6(struct net *net, const struct net_device *dev, }else { route_err =1 ; } -rcu_read_unlock ();if (route_err)return XT_ADDRTYPE_UNREACHABLE ;
net/netfilter/xt_connlimit.c +0 -3
@@ -144,7 +144,6 @@ static unsigned int check_hlist(struct net *net,unsigned int length =0 ; *addit = true; -rcu_read_lock ();/* check the saved connections */ hlist_for_each_entry_safe (conn, n, head, node) {
@@ -179,8 +178,6 @@ static unsigned int check_hlist(struct net *net, length++; } -rcu_read_unlock (); -return length; }
net/netfilter/xt_hashlimit.c +4 -4
@@ -659,12 +659,12 @@ hashlimit_mt_common(const struct sk_buff *skb, struct xt_action_param *par,if (hashlimit_init_dst (hinfo, &dst, skb, par->thoff) <0 ) goto hotdrop; -rcu_read_lock_bh (); +local_bh_disable (); dh =dsthash_find (hinfo, &dst);if (dh ==NULL ) { dh =dsthash_alloc_init (hinfo, &dst, &race);if (dh ==NULL ) { -rcu_read_unlock_bh (); +local_bh_enable (); goto hotdrop; }else if (race) {/* Already got an entry, update expiration timeout */
@@ -689,12 +689,12 @@ hashlimit_mt_common(const struct sk_buff *skb, struct xt_action_param *par,/* below the limit */ dh->rateinfo.credit -= cost;spin_unlock (&dh->lock); -rcu_read_unlock_bh (); +local_bh_enable ();return !(cfg->mode &XT_HASHLIMIT_INVERT ); }spin_unlock (&dh->lock); -rcu_read_unlock_bh (); +local_bh_enable ();/* default match is underlimit - so over the limit, we need to invert */ return cfg->mode &XT_HASHLIMIT_INVERT ;
net/netfilter/xt_osf.c +0 -2
@@ -226,7 +226,6 @@ xt_osf_match_packet(const struct sk_buff *skb, struct xt_action_param *p) sizeof(struct tcphdr), optsize, opts); } -rcu_read_lock ();list_for_each_entry_rcu (kf, &xt_osf_fingers[df], finger_entry) {int foptsize, optnum;
@@ -340,7 +339,6 @@ xt_osf_match_packet(const struct sk_buff *skb, struct xt_action_param *p) info->loglevel == XT_OSF_LOGLEVEL_FIRST)break ; } -rcu_read_unlock ();if (!fcount && (info->flags &XT_OSF_LOG )) nf_log_packet(net, xt_family(p), xt_hooknum(p), skb, xt_in(p),
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 4/47 netfilter: nf_tables: Attach process info to NFT_MSG_NEWGEN notifications
In reply to Pablo Neira AyusoFrom: Phil Sutter <[email protected]>
This is helpful for 'nft monitor' to track which process caused a given change to the ruleset.
--- include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nf_tables_api.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -1221,6 +1221,8 @@ enum nft_objref_attributes {enum nft_gen_attributes {NFTA_GEN_UNSPEC ,NFTA_GEN_ID , +NFTA_GEN_PROC_PID , +NFTA_GEN_PROC_NAME , __NFTA_GEN_MAX };#define NFTA_GEN_MAX (__NFTA_GEN_MAX - 1)
net/netfilter/nf_tables_api.c +4 -1
@@ -4657,6 +4657,7 @@ static int nf_tables_fill_gen_info(struct sk_buff *skb, struct net *net, {struct nlmsghdr *nlh;struct nfgenmsg *nfmsg; +char buf[TASK_COMM_LEN ];int event =nfnl_msg_type (NFNL_SUBSYS_NFTABLES ,NFT_MSG_NEWGEN ); nlh =nlmsg_put (skb, portid, seq, event,sizeof (struct nfgenmsg ),0 );
@@ -4668,7 +4669,9 @@ static int nf_tables_fill_gen_info(struct sk_buff *skb, struct net *net, nfmsg->version =NFNETLINK_V0 ; nfmsg->res_id =htons (net->nft.base_seq &0xffff ); -if (nla_put_be32 (skb,NFTA_GEN_ID ,htonl (net->nft.base_seq))) +if (nla_put_be32 (skb,NFTA_GEN_ID ,htonl (net->nft.base_seq)) || +nla_put_be32 (skb,NFTA_GEN_PROC_PID ,htonl (task_pid_nr (current))) || +nla_put_string (skb,NFTA_GEN_PROC_NAME ,get_task_comm (buf, current))) goto nla_put_failure;nlmsg_end (skb, nlh);
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 5/47 netfilter: nf_tables: fib: use skb_header_pointer
In reply to Pablo Neira AyusoFrom: "Pablo M. Bermudo Garay" <[email protected]>
This is a preparatory patch for adding fib support to the netdev family.
The netdev family receives the packets from ingress hook. At this point we have no guarantee that the ip header is linear. So this patch replaces ip_hdr with skb_header_pointer in order to address that possible situation.
--- net/ipv4/netfilter/nft_fib_ipv4.c | 20 ++++++++++++++++---- net/ipv6/netfilter/nft_fib_ipv6.c | 29 +++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 10 deletions(-)
net/ipv4/netfilter/nft_fib_ipv4.c +16 -4
@@ -32,9 +32,10 @@ void nft_fib4_eval_type(const struct nft_expr *expr, struct nft_regs *regs, const struct nft_pktinfo *pkt) {const struct nft_fib *priv =nft_expr_priv (expr); +int noff =skb_network_offset (pkt->skb);u32 *dst = ®s->data[priv->dreg];const struct net_device *dev =NULL ; -const struct iphdr *iph; +struct iphdr *iph, _iph;__be32 addr;if (priv->flags &NFTA_FIB_F_IIF )
@@ -42,7 +43,12 @@ void nft_fib4_eval_type(const struct nft_expr *expr, struct nft_regs *regs,else if (priv->flags &NFTA_FIB_F_OIF ) dev =nft_out (pkt); - iph =ip_hdr (pkt->skb); + iph =skb_header_pointer (pkt->skb, noff,sizeof (_iph), &_iph); +if (!iph) { + regs->verdict.code =NFT_BREAK ; +return ; + } +if (priv->flags &NFTA_FIB_F_DADDR ) addr = iph->daddr;else
@@ -61,8 +67,9 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs, const struct nft_pktinfo *pkt) {const struct nft_fib *priv =nft_expr_priv (expr); +int noff =skb_network_offset (pkt->skb);u32 *dest = ®s->data[priv->dreg]; -const struct iphdr *iph; +struct iphdr *iph, _iph;struct fib_result res;struct flowi4 fl4 = { .flowi4_scope =RT_SCOPE_UNIVERSE ,
@@ -95,7 +102,12 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,return ; } - iph =ip_hdr (pkt->skb); + iph =skb_header_pointer (pkt->skb, noff,sizeof (_iph), &_iph); +if (!iph) { + regs->verdict.code =NFT_BREAK ; +return ; + } +if (ipv4_is_zeronet (iph->saddr)) {if (ipv4_is_lbcast (iph->daddr) ||ipv4_is_local_multicast (iph->daddr)) {
net/ipv6/netfilter/nft_fib_ipv6.c +23 -6
@@ -25,9 +25,9 @@ static int get_ifindex(const struct net_device *dev)static int nft_fib6_flowi_init (struct flowi6 *fl6,const struct nft_fib *priv,const struct nft_pktinfo *pkt, -const struct net_device *dev) +const struct net_device *dev, +struct ipv6hdr *iph) { -const struct ipv6hdr *iph =ipv6_hdr (pkt->skb);int lookup_flags =0 ;if (priv->flags &NFTA_FIB_F_DADDR ) {
@@ -55,7 +55,8 @@ static int nft_fib6_flowi_init(struct flowi6 *fl6, const struct nft_fib *priv, }static u32 __nft_fib6_eval_type (const struct nft_fib *priv, -const struct nft_pktinfo *pkt) +const struct nft_pktinfo *pkt, +struct ipv6hdr *iph) {const struct net_device *dev =NULL ;const struct nf_ipv6_ops *v6ops;
@@ -77,7 +78,7 @@ static u32 __nft_fib6_eval_type(const struct nft_fib *priv,else if (priv->flags &NFTA_FIB_F_OIF ) dev =nft_out (pkt); -nft_fib6_flowi_init (&fl6, priv, pkt, dev); +nft_fib6_flowi_init (&fl6, priv, pkt, dev, iph); v6ops =nf_get_ipv6_ops ();if (dev && v6ops && v6ops->chk_addr (nft_net (pkt), &fl6.daddr, dev, true))
@@ -131,9 +132,17 @@ void nft_fib6_eval_type(const struct nft_expr *expr, struct nft_regs *regs, const struct nft_pktinfo *pkt) {const struct nft_fib *priv =nft_expr_priv (expr); +int noff =skb_network_offset (pkt->skb);u32 *dest = ®s->data[priv->dreg]; +struct ipv6hdr *iph, _iph; - *dest =__nft_fib6_eval_type (priv, pkt); + iph =skb_header_pointer (pkt->skb, noff,sizeof (_iph), &_iph); +if (!iph) { + regs->verdict.code =NFT_BREAK ; +return ; + } + + *dest =__nft_fib6_eval_type (priv, pkt, iph); }EXPORT_SYMBOL_GPL (nft_fib6_eval_type);
@@ -141,8 +150,10 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs, const struct nft_pktinfo *pkt) {const struct nft_fib *priv =nft_expr_priv (expr); +int noff =skb_network_offset (pkt->skb);const struct net_device *oif =NULL ;u32 *dest = ®s->data[priv->dreg]; +struct ipv6hdr *iph, _iph;struct flowi6 fl6 = { .flowi6_iif =LOOPBACK_IFINDEX , .flowi6_proto = pkt->tprot,
@@ -155,7 +166,13 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs,else if (priv->flags &NFTA_FIB_F_OIF ) oif =nft_out (pkt); - lookup_flags =nft_fib6_flowi_init (&fl6, priv, pkt, oif); + iph =skb_header_pointer (pkt->skb, noff,sizeof (_iph), &_iph); +if (!iph) { + regs->verdict.code =NFT_BREAK ; +return ; + } + + lookup_flags =nft_fib6_flowi_init (&fl6, priv, pkt, oif, iph);if (nft_hook (pkt) ==NF_INET_PRE_ROUTING &&nft_fib_is_loopback (pkt->skb,nft_in (pkt))) {
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 6/47 netfilter: nf_tables: add fib expression to the netdev family
In reply to Pablo Neira AyusoFrom: "Pablo M. Bermudo Garay" <[email protected]>
Add fib expression support for netdev family. Like inet family, netdev delegates the actual decision to the corresponding backend, either ipv4 or ipv6.
This allows to perform very early reverse path filtering, among other things.
You can find more information about fib expression in the f6d0cbcf09c5 ("<netfilter: nf_tables: add fib expression>") commit message.
--- net/netfilter/Kconfig | 9 +++++ net/netfilter/Makefile | 1 + net/netfilter/nft_fib_netdev.c | 87 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 net/netfilter/nft_fib_netdev.c
net/netfilter/Kconfig +9 -0
@@ -636,6 +636,15 @@ config NFT_FWD_NETDEV help This option enables packet forwarding for the "netdev" family. +config NFT_FIB_NETDEV + depends on NFT_FIB_IPV4 + depends on NFT_FIB_IPV6 + tristate "Netfilter nf_tables netdev fib lookups support" + help + This option allows using the FIB expression from the netdev table. + The lookup will be delegated to the IPv4 or IPv6 FIB depending + on the protocol of the packet. + endif # NF_TABLES_NETDEV endif # NF_TABLES
net/netfilter/Makefile +1 -0
@@ -100,6 +100,7 @@ obj-$(CONFIG_NFT_REDIR) += nft_redir.o obj-$(CONFIG_NFT_HASH) += nft_hash.o obj-$(CONFIG_NFT_FIB) += nft_fib.o obj-$(CONFIG_NFT_FIB_INET) += nft_fib_inet.o +obj-$(CONFIG_NFT_FIB_NETDEV) += nft_fib_netdev.o # nf_tables netdev obj-$(CONFIG_NFT_DUP_NETDEV) += nft_dup_netdev.o
net/netfilter/nft_fib_netdev.c new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 7/47 netfilter: conntrack: Change to deferable work queue
In reply to Pablo Neira AyusoFrom: "[email protected]" <[email protected]>
Delayed workqueue causes wakeups to idle CPUs. This was causing a power impact for devices. Use deferable work queue instead so that gc_worker runs when CPU is active only.
--- net/netfilter/nf_conntrack_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_core.c +1 -1
@@ -1081,7 +1081,7 @@ static void gc_worker(struct work_struct *work)static void conntrack_gc_work_init (struct conntrack_gc_work *gc_work) { -INIT_DELAYED_WORK (&gc_work->dwork, gc_worker); +INIT_DEFERRABLE_WORK (&gc_work->dwork, gc_worker); gc_work->next_gc_run =HZ ; gc_work->exiting = false; }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 8/47 netfilter: expect: add and use nf_ct_expect_iterate helpers
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
We have several spots that open-code a expect walk, add a helper that is similar to nf_ct_iterate_destroy/nf_ct_iterate_cleanup.
--- include/net/netfilter/nf_conntrack_expect.h | 5 +++ net/netfilter/nf_conntrack_expect.c | 54 +++++++++++++++++++++++++ net/netfilter/nf_conntrack_helper.c | 34 +++++++--------- net/netfilter/nf_conntrack_netlink.c | 63 ++++++++++------------------- 4 files changed, 95 insertions(+), 61 deletions(-)
include/net/netfilter/nf_conntrack_expect.h +5 -0
@@ -107,6 +107,11 @@ void nf_ct_remove_expectations(struct nf_conn *ct);void nf_ct_unexpect_related (struct nf_conntrack_expect *exp);bool nf_ct_remove_expect (struct nf_conntrack_expect *exp); +void nf_ct_expect_iterate_destroy (bool (*iter)(struct nf_conntrack_expect *e,void *data),void *data); +void nf_ct_expect_iterate_net (struct net *net, +bool (*iter)(struct nf_conntrack_expect *e,void *data), +void *data,u32 portid,int report); +/* Allocate space for an expectation: this is mandatory before calling nf_ct_expect_related. You will have to call put afterwards. */ struct nf_conntrack_expect *nf_ct_expect_alloc (struct nf_conn *me);
net/netfilter/nf_conntrack_expect.c +54 -0
60 lines not on this page · raw message
net/netfilter/nf_conntrack_helper.c +15 -19
@@ -437,12 +437,22 @@ int nf_conntrack_helper_register(struct nf_conntrack_helper *me) }EXPORT_SYMBOL_GPL (nf_conntrack_helper_register); -void nf_conntrack_helper_unregister (struct nf_conntrack_helper *me) +static bool expect_iter_me (struct nf_conntrack_expect *exp,void *data) { -struct nf_conntrack_expect *exp; -const struct hlist_node *next; -unsigned int i; +struct nf_conn_help *help =nfct_help (exp->master); +const struct nf_conntrack_helper *me = data; +const struct nf_conntrack_helper *this; + +if (exp->helper == me) +return true; + this =rcu_dereference_protected (help->helper, +lockdep_is_held (&nf_conntrack_expect_lock)); +return this == me; +} + +void nf_conntrack_helper_unregister (struct nf_conntrack_helper *me) +{mutex_lock (&nf_ct_helper_mutex);hlist_del_rcu (&me->hnode); nf_ct_helper_count--;
@@ -453,21 +463,7 @@ void nf_conntrack_helper_unregister(struct nf_conntrack_helper *me)*/ synchronize_rcu (); -/* Get rid of expectations */ -spin_lock_bh (&nf_conntrack_expect_lock); -for (i =0 ; i < nf_ct_expect_hsize; i++) { -hlist_for_each_entry_safe (exp, next, - &nf_ct_expect_hash[i], hnode) { -struct nf_conn_help *help =nfct_help (exp->master); -if ((rcu_dereference_protected ( - help->helper, -lockdep_is_held (&nf_conntrack_expect_lock) - ) == me || exp->helper == me)) -nf_ct_remove_expect (exp); - } - } -spin_unlock_bh (&nf_conntrack_expect_lock); - +nf_ct_expect_iterate_destroy (expect_iter_me,NULL );nf_ct_iterate_destroy (unhelp, me); }EXPORT_SYMBOL_GPL (nf_conntrack_helper_unregister);
net/netfilter/nf_conntrack_netlink.c +21 -42
86 lines not on this page · raw message
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 9/47 netfilter: add and use nf_ct_unconfirmed_destroy
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
This also removes __nf_ct_unconfirmed_destroy() call from nf_ct_iterate_cleanup_net, so that function can be used only when missing conntracks from unconfirmed list isn't a problem.
--- include/net/netfilter/nf_conntrack.h | 3 +++ net/netfilter/nf_conntrack_core.c | 15 +++++++++++---- net/netfilter/nfnetlink_cttimeout.c | 1 + 3 files changed, 15 insertions(+), 4 deletions(-)
include/net/netfilter/nf_conntrack.h +3 -0
@@ -224,6 +224,9 @@ extern s32 (*nf_ct_nat_offset)(const struct nf_conn *ct,enum ip_conntrack_dir dir, u32 seq); +/* Set all unconfirmed conntrack as dying */ +void nf_ct_unconfirmed_destroy (struct net *); +/* Iterate over all conntracks: if iter returns true, it's deleted. */ void nf_ct_iterate_cleanup_net(struct net *net, int (*iter)(struct nf_conn *i, void *data),
net/netfilter/nf_conntrack_core.c +11 -4
@@ -1686,6 +1686,17 @@ __nf_ct_unconfirmed_destroy(struct net *net) } } +void nf_ct_unconfirmed_destroy (struct net *net) +{ +might_sleep (); + +if (atomic_read (&net->ct.count) >0 ) { +__nf_ct_unconfirmed_destroy (net); +synchronize_net (); + } +} +EXPORT_SYMBOL_GPL (nf_ct_unconfirmed_destroy); +void nf_ct_iterate_cleanup_net (struct net *net,int (*iter)(struct nf_conn *i,void *data),void *data,u32 portid,int report)
@@ -1697,14 +1708,10 @@ void nf_ct_iterate_cleanup_net(struct net *net,if (atomic_read (&net->ct.count) ==0 )return ; -__nf_ct_unconfirmed_destroy (net); - d.iter = iter; d.data = data; d.net = net; -synchronize_net (); -nf_ct_iterate_cleanup (iter_net_only, &d, portid, report); }EXPORT_SYMBOL_GPL (nf_ct_iterate_cleanup_net);
net/netfilter/nfnetlink_cttimeout.c +1 -0
@@ -570,6 +570,7 @@ static void __net_exit cttimeout_net_exit(struct net *net) {struct ctnl_timeout *cur, *tmp; +nf_ct_unconfirmed_destroy (net);ctnl_untimeout (net,NULL );list_for_each_entry_safe (cur, tmp, &net->nfct_timeout_list, head) {
Signature · 1 line
2.1.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Mon, 4 Sep 2017 00:25:42 +0200
Quoted 5 lines
The following patchset contains Netfilter updates for your net-next tree. Basically, updates to the conntrack core, enhancements for
nf_tables, conversion of netfilter hooks from linked list to array to improve memory locality and asorted improvements for the Netfilter codebase. More specifically, they are:
...
Quoted 2 lines
I think I will have material for a second Netfilter batch in my queue if time allow to make it fit in this merge window.
Ok, but please be swift about it.
Quoted 3 lines
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Pulled, thanks.