netfilter updates for net-next (upcoming 3.5)
Subsystems (9)
[email protected]
maintainerv3 cover netfilter updates for net-next (upcoming 3.5)
From: Pablo Neira Ayuso <[email protected]>
Hi David,
Third version, now based on your fresh current net-next tree.
The following patchset contains the Netfilter updates for net-next. Most notably:
* The new /proc/sys/net/netfilter/nf_conntrack_helper entry that allows to disable the automatic conntrack helper assignment from Eric Leblond. This patch also spots a warning to inform the user that this behaviour will be removed at some point. The automatic conntrack helper assignment may allows attackers to open hole in the firewall to access the protected network segments (with incorrect configurations). More information on this issue at:
https://home.regit.org/netfilter-en/secure-use-of-helpers/
In the near future, all conntrack helpers will be explicitly attached via the CT target, as we longing discussed during the last netfilter workshop.
* One new sysctl to translate the input device to vlan device name from Florian Westphal. He required this to get the REDIRECT target working with another sysctl vlan-on-top-of-bridge.
* Major improvements in the ip_vs_sync code from Julian Anastasov. They aim to improve scalability and to address possible message loss due to socket overrun under high rate of synchronization messages.
* Several minor memory allocation flags fixes from IPVS people contributors.
* Eric Leblond's patch spotted one problem that becomes noticeable if a) automatic helper assignment is disabled, and b) if NAT is in use, and c) the CT target is used to attach a non-standard conntrack helper port. This fix comes from myself.
* One small update to allow updating the expectation timeout from Kelvie Wong.
* Finally, remove ip[6]_queue support since they have been marked as obsolete since long time ago. Now, we have nfnetlink_queue which is way more flexible from myself.
You can pull these changes from:
git://1984.lsi.us.es/net-next master
If time allows, I'd like to send a second batch. There a several patches that are very close to get into shape still on netfilter-devel.
Thanks!
Eric Dumazet (1):
netfilter: nf_conntrack: use this_cpu_inc()
Eric Leblond (1):
netfilter: nf_ct_helper: allow to disable automatic helper assignment
Florian Westphal (1):
netfilter: bridge: optionally set indev to vlan
H Hartley Sweeten (2):
ipvs: ip_vs_ftp: local functions should not be exposed globally
ipvs: ip_vs_proto: local functions should not be exposed globally
Hans Schillstrom (1):
net: export sysctl_[r|w]mem_max symbols needed by ip_vs_sync
Julian Anastasov (14):
ipvs: timeout tables do not need GFP_ATOMIC allocation
ipvs: LBLC scheduler does not need GFP_ATOMIC allocation on init
ipvs: DH scheduler does not need GFP_ATOMIC allocation
ipvs: WRR scheduler does not need GFP_ATOMIC allocation
ipvs: LBLCR scheduler does not need GFP_ATOMIC allocation on init
ipvs: SH scheduler does not need GFP_ATOMIC allocation
ipvs: ignore IP_VS_CONN_F_NOOUTPUT in backup server
ipvs: remove check for IP_VS_CONN_F_SYNC from ip_vs_bind_dest
ipvs: fix ip_vs_try_bind_dest to rebind app and transmitter
ipvs: always update some of the flags bits in backup
ipvs: wakeup master thread
ipvs: reduce sync rate with time thresholds
ipvs: add support for sync threads
ipvs: optimize the use of flags in ip_vs_bind_dest
Kelvie Wong (1):
netfilter: nf_ct_expect: partially implement ctnetlink_change_expect
Pablo Neira Ayuso (2):
netfilter: nf_conntrack: fix explicit helper attachment and NAT
netfilter: remove ip_queue support
Sasha Levin (1):
ipvs: use GFP_KERNEL allocation where possible
Tony Zelenoff (1):
netfilter: nf_ct_ecache: refactor notifier registration
Documentation/ABI/removed/ip_queue | 9 + Documentation/networking/ip-sysctl.txt | 13 +- include/linux/ip_vs.h | 5 + include/linux/netfilter/nf_conntrack_common.h | 4 + include/linux/netfilter_ipv4/Kbuild | 1 - include/linux/netfilter_ipv4/ip_queue.h | 72 --- include/linux/netlink.h | 2 +- include/net/ip_vs.h | 87 +++- include/net/netfilter/nf_conntrack.h | 10 +- include/net/netfilter/nf_conntrack_helper.h | 4 +- include/net/netns/conntrack.h | 3 + net/bridge/br_netfilter.c | 26 +- net/core/sock.c | 2 + net/ipv4/netfilter/Makefile | 3 - net/ipv4/netfilter/ip_queue.c | 639 ------------------------ net/ipv6/netfilter/Kconfig | 22 - net/ipv6/netfilter/Makefile | 1 - net/ipv6/netfilter/ip6_queue.c | 641 ------------------------ net/netfilter/ipvs/ip_vs_conn.c | 69 ++- net/netfilter/ipvs/ip_vs_core.c | 30 +- net/netfilter/ipvs/ip_vs_ctl.c | 70 ++- net/netfilter/ipvs/ip_vs_dh.c | 2 +- net/netfilter/ipvs/ip_vs_ftp.c | 2 +- net/netfilter/ipvs/ip_vs_lblc.c | 2 +- net/netfilter/ipvs/ip_vs_lblcr.c | 2 +- net/netfilter/ipvs/ip_vs_proto.c | 6 +- net/netfilter/ipvs/ip_vs_sh.c | 2 +- net/netfilter/ipvs/ip_vs_sync.c | 662 +++++++++++++++++-------- net/netfilter/ipvs/ip_vs_wrr.c | 2 +- net/netfilter/nf_conntrack_core.c | 15 +- net/netfilter/nf_conntrack_ecache.c | 10 +- net/netfilter/nf_conntrack_helper.c | 120 ++++- net/netfilter/nf_conntrack_netlink.c | 10 +- security/selinux/nlmsgtab.c | 13 - 34 files changed, 853 insertions(+), 1708 deletions(-) create mode 100644 Documentation/ABI/removed/ip_queue delete mode 100644 include/linux/netfilter_ipv4/ip_queue.h delete mode 100644 net/ipv4/netfilter/ip_queue.c delete mode 100644 net/ipv6/netfilter/ip6_queue.c
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 1/25 netfilter: nf_ct_ecache: refactor notifier registration
From: Tony Zelenoff <[email protected]>
* ret variable initialization removed as useless
* similar code strings concatenated and functions code flow became more plain
--- net/netfilter/nf_conntrack_ecache.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
net/netfilter/nf_conntrack_ecache.c +4 -6
@@ -84,7 +84,7 @@ EXPORT_SYMBOL_GPL(nf_ct_deliver_cached_events);int nf_conntrack_register_notifier (struct net *net,struct nf_ct_event_notifier *new) { -int ret =0 ; +int ret;struct nf_ct_event_notifier *notify;mutex_lock (&nf_ct_ecache_mutex);
@@ -95,8 +95,7 @@ int nf_conntrack_register_notifier(struct net *net, goto out_unlock; }rcu_assign_pointer (net->ct.nf_conntrack_event_cb, new); -mutex_unlock (&nf_ct_ecache_mutex); -return ret; + ret =0 ; out_unlock:mutex_unlock (&nf_ct_ecache_mutex);
@@ -121,7 +120,7 @@ EXPORT_SYMBOL_GPL(nf_conntrack_unregister_notifier);int nf_ct_expect_register_notifier (struct net *net,struct nf_exp_event_notifier *new) { -int ret =0 ; +int ret;struct nf_exp_event_notifier *notify;mutex_lock (&nf_ct_ecache_mutex);
@@ -132,8 +131,7 @@ int nf_ct_expect_register_notifier(struct net *net, goto out_unlock; }rcu_assign_pointer (net->ct.nf_expect_event_cb, new); -mutex_unlock (&nf_ct_ecache_mutex); -return ret; + ret =0 ; out_unlock:mutex_unlock (&nf_ct_ecache_mutex);
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 2/25 netfilter: nf_ct_helper: allow to disable automatic helper assignment
In reply to [email protected]From: Eric Leblond <[email protected]>
This patch allows you to disable automatic conntrack helper lookup based on TCP/UDP ports, eg.
echo 0 > /proc/sys/net/netfilter/nf_conntrack_helper
[ Note: flows that already got a helper will keep using it even
if automatic helper assignment has been disabled ]
Once this behaviour has been disabled, you have to explicitly use the iptables CT target to attach helper to flows.
There are good reasons to stop supporting automatic helper assignment, for further information, please read:
http://www.netfilter.org/news.html#2012-04-03
This patch also adds one message to inform that automatic helper assignment is deprecated and it will be removed soon (this is spotted only once, with the first flow that gets a helper attached to make it as less annoying as possible).
--- include/net/netfilter/nf_conntrack_helper.h | 4 +- include/net/netns/conntrack.h | 3 + net/netfilter/nf_conntrack_core.c | 15 ++-- net/netfilter/nf_conntrack_helper.c | 109 ++++++++++++++++++++++++--- 4 files changed, 110 insertions(+), 21 deletions(-)
include/net/netfilter/nf_conntrack_helper.h +2 -2
@@ -60,8 +60,8 @@ static inline struct nf_conn_help *nfct_help(const struct nf_conn *ct)return nf_ct_ext_find (ct,NF_CT_EXT_HELPER ); } -extern int nf_conntrack_helper_init (void ); -extern void nf_conntrack_helper_fini (void ); +extern int nf_conntrack_helper_init (struct net *net); +extern void nf_conntrack_helper_fini (struct net *net); extern int nf_conntrack_broadcast_help(struct sk_buff *skb, unsigned int protoff,
include/net/netns/conntrack.h +3 -0
@@ -26,11 +26,14 @@ struct netns_ct {int sysctl_tstamp;int sysctl_checksum;unsigned int sysctl_log_invalid;/* Log invalid packets */ +int sysctl_auto_assign_helper; +bool auto_assign_helper_warned;#ifdef CONFIG_SYSCTL struct ctl_table_header *sysctl_header;struct ctl_table_header *acct_sysctl_header;struct ctl_table_header *tstamp_sysctl_header;struct ctl_table_header *event_sysctl_header; +struct ctl_table_header *helper_sysctl_header;#endif char *slabname; };
net/netfilter/nf_conntrack_core.c +7 -8
@@ -1336,7 +1336,6 @@ static void nf_conntrack_cleanup_init_net(void)while (untrack_refs () >0 )schedule (); -nf_conntrack_helper_fini ();nf_conntrack_proto_fini ();#ifdef CONFIG_NF_CONNTRACK_ZONES nf_ct_extend_unregister (&nf_ct_zone_extend);
@@ -1354,6 +1353,7 @@ static void nf_conntrack_cleanup_net(struct net *net) }nf_ct_free_hashtable (net->ct.hash, net->ct.htable_size); +nf_conntrack_helper_fini (net);nf_conntrack_timeout_fini (net);nf_conntrack_ecache_fini (net);nf_conntrack_tstamp_fini (net);
@@ -1504,10 +1504,6 @@ static int nf_conntrack_init_init_net(void)if (ret <0 ) goto err_proto; - ret =nf_conntrack_helper_init (); -if (ret <0 ) - goto err_helper; -#ifdef CONFIG_NF_CONNTRACK_ZONES ret =nf_ct_extend_register (&nf_ct_zone_extend);if (ret <0 )
@@ -1525,10 +1521,8 @@ static int nf_conntrack_init_init_net(void)#ifdef CONFIG_NF_CONNTRACK_ZONES err_extend: -nf_conntrack_helper_fini (); -#endif -err_helper:nf_conntrack_proto_fini (); +#endif err_proto:return ret; }
@@ -1589,9 +1583,14 @@ static int nf_conntrack_init_net(struct net *net) ret =nf_conntrack_timeout_init (net);if (ret <0 ) goto err_timeout; + ret =nf_conntrack_helper_init (net); +if (ret <0 ) + goto err_helper;return 0 ; +err_helper: +nf_conntrack_timeout_fini (net); err_timeout:nf_conntrack_ecache_fini (net); err_ecache:
net/netfilter/nf_conntrack_helper.c +98 -11
146 lines not on this page · raw message
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 3/25 netfilter: nf_conntrack: use this_cpu_inc()
In reply to [email protected]From: Eric Dumazet <[email protected]>
this_cpu_inc() is IRQ safe and faster than local_bh_disable()/__this_cpu_inc()/local_bh_enable(), at least on x86.
--- include/net/netfilter/nf_conntrack.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
include/net/netfilter/nf_conntrack.h +2 -8
@@ -321,14 +321,8 @@ extern unsigned int nf_conntrack_max;extern unsigned int nf_conntrack_hash_rnd;void init_nf_conntrack_hash_rnd (void ); -#define NF_CT_STAT_INC (net, count) \ - __this_cpu_inc((net)->ct.stat->count) -#define NF_CT_STAT_INC_ATOMIC (net, count) \ -do { \ - local_bh_disable(); \ - __this_cpu_inc((net)->ct.stat->count); \ - local_bh_enable(); \ -} while (0) +#define NF_CT_STAT_INC (net, count) __this_cpu_inc((net)->ct.stat->count) +#define NF_CT_STAT_INC_ATOMIC (net, count) this_cpu_inc((net)->ct.stat->count)#define MODULE_ALIAS_NFCT_HELPER (helper) \ MODULE_ALIAS("nfct-helper-" helper)
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 4/25 netfilter: bridge: optionally set indev to vlan
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
if net.bridge.bridge-nf-filter-vlan-tagged sysctl is enabled, bridge netfilter removes the vlan header temporarily and then feeds the packet to ip(6)tables.
When the new "bridge-nf-pass-vlan-input-device" sysctl is on (default off), then bridge netfilter will also set the in-interface to the vlan interface; if such an interface exists.
This is needed to make iptables REDIRECT target work with "vlan-on-top-of-bridge" setups and to allow use of "iptables -i" to match the vlan device name.
Also update Documentation with current brnf default settings.
--- Documentation/networking/ip-sysctl.txt | 13 +++++++++++-- net/bridge/br_netfilter.c | 26 ++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-)
Documentation/networking/ip-sysctl.txt +11 -2
@@ -1301,13 +1301,22 @@ bridge-nf-call-ip6tables - BOOLEAN bridge-nf-filter-vlan-tagged - BOOLEAN 1 : pass bridged vlan-tagged ARP/IP/IPv6 traffic to {arp,ip,ip6}tables. 0 : disable this. - Default: 1 + Default: 0 bridge-nf-filter-pppoe-tagged - BOOLEAN 1 : pass bridged pppoe-tagged IP/IPv6 traffic to {ip,ip6}tables. 0 : disable this. - Default: 1 + Default: 0 +bridge-nf-pass-vlan-input-dev - BOOLEAN + 1: if bridge-nf-filter-vlan-tagged is enabled, try to find a vlan + interface on the bridge and set the netfilter input device to the vlan. + This allows use of e.g. "iptables -i br0.1" and makes the REDIRECT + target work with vlan-on-top-of-bridge interfaces. When no matching + vlan interface is found, or this switch is off, the input device is + set to the bridge interface. + 0: disable bridge netfilter vlan interface lookup. + Default: 0 proc/sys/net/sctp/* Variables:
net/bridge/br_netfilter.c +24 -2
@@ -54,12 +54,14 @@ static int brnf_call_ip6tables __read_mostly = 1;static int brnf_call_arptables__read_mostly =1 ;static int brnf_filter_vlan_tagged__read_mostly =0 ;static int brnf_filter_pppoe_tagged__read_mostly =0 ; +static int brnf_pass_vlan_indev__read_mostly =0 ;#else #define brnf_call_iptables 1#define brnf_call_ip6tables 1#define brnf_call_arptables 1#define brnf_filter_vlan_tagged 0#define brnf_filter_pppoe_tagged 0 +#define brnf_pass_vlan_indev 0#endif #define IS_IP (skb) \
@@ -503,6 +505,19 @@ bridged_dnat:return 0 ; } +static struct net_device *brnf_get_logical_dev (struct sk_buff *skb,const struct net_device *dev) +{ +struct net_device *vlan, *br; + + br =bridge_parent (dev); +if (brnf_pass_vlan_indev ==0 || !vlan_tx_tag_present (skb)) +return br; + + vlan =__vlan_find_dev_deep (br,vlan_tx_tag_get (skb) &VLAN_VID_MASK ); + +return vlan ? vlan : br; +} +/* Some common code for IPv4/IPv6 */ static struct net_device *setup_pre_routing (struct sk_buff *skb) {
@@ -515,7 +530,7 @@ static struct net_device *setup_pre_routing(struct sk_buff *skb) nf_bridge->mask |=BRNF_NF_BRIDGE_PREROUTING ; nf_bridge->physindev = skb->dev; - skb->dev =bridge_parent (skb->dev); + skb->dev =brnf_get_logical_dev (skb, skb->dev);if (skb->protocol ==htons (ETH_P_8021Q )) nf_bridge->mask |=BRNF_8021Q ;else if (skb->protocol ==htons (ETH_P_PPP_SES ))
@@ -774,7 +789,7 @@ static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff *skb,else skb->protocol =htons (ETH_P_IPV6 ); -NF_HOOK (pf,NF_INET_FORWARD , skb,bridge_parent (in), parent, +NF_HOOK (pf,NF_INET_FORWARD , skb,brnf_get_logical_dev (skb, in), parent, br_nf_forward_finish);return NF_STOLEN ;
@@ -1002,6 +1017,13 @@ static ctl_table brnf_table[] = { .mode = 0644, .proc_handler = brnf_sysctl_call_tables, }, + { + .procname = "bridge-nf-pass-vlan-input-dev", + .data = &brnf_pass_vlan_indev, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = brnf_sysctl_call_tables, + }, { } };#endif
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 5/25 ipvs: timeout tables do not need GFP_ATOMIC allocation
In reply to [email protected]From: Julian Anastasov <[email protected]>
They are called only on initialization.
--- net/netfilter/ipvs/ip_vs_proto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_proto.c +1 -1
@@ -199,7 +199,7 @@ void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags)int *ip_vs_create_timeout_table (int *table,int size) { -return kmemdup (table, size,GFP_ATOMIC ); +return kmemdup (table, size,GFP_KERNEL ); }
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 6/25 ipvs: LBLC scheduler does not need GFP_ATOMIC allocation on init
In reply to [email protected]From: Julian Anastasov <[email protected]>
Schedulers are initialized and bound to services only
on commands.
--- net/netfilter/ipvs/ip_vs_lblc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_lblc.c +1 -1
@@ -342,7 +342,7 @@ static int ip_vs_lblc_init_svc(struct ip_vs_service *svc)/* * Allocate the ip_vs_lblc_table for this service */ - tbl =kmalloc (sizeof (*tbl),GFP_ATOMIC ); + tbl =kmalloc (sizeof (*tbl),GFP_KERNEL );if (tbl ==NULL )return -ENOMEM ;
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 7/25 ipvs: DH scheduler does not need GFP_ATOMIC allocation
In reply to [email protected]From: Julian Anastasov <[email protected]>
Schedulers are initialized and bound to services only
on commands.
--- net/netfilter/ipvs/ip_vs_dh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_dh.c +1 -1
@@ -149,7 +149,7 @@ static int ip_vs_dh_init_svc(struct ip_vs_service *svc)/* allocate the DH table for this service */ tbl =kmalloc (sizeof (struct ip_vs_dh_bucket )*IP_VS_DH_TAB_SIZE , -GFP_ATOMIC ); +GFP_KERNEL );if (tbl ==NULL )return -ENOMEM ;
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 8/25 ipvs: WRR scheduler does not need GFP_ATOMIC allocation
In reply to [email protected]From: Julian Anastasov <[email protected]>
Schedulers are initialized and bound to services only
on commands.
--- net/netfilter/ipvs/ip_vs_wrr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_wrr.c +1 -1
@@ -84,7 +84,7 @@ static int ip_vs_wrr_init_svc(struct ip_vs_service *svc)/* * Allocate the mark variable for WRR scheduling */ - mark =kmalloc (sizeof (struct ip_vs_wrr_mark ),GFP_ATOMIC ); + mark =kmalloc (sizeof (struct ip_vs_wrr_mark ),GFP_KERNEL );if (mark ==NULL )return -ENOMEM ;
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 9/25 ipvs: LBLCR scheduler does not need GFP_ATOMIC allocation on init
In reply to [email protected]From: Julian Anastasov <[email protected]>
Schedulers are initialized and bound to services only
on commands.
--- net/netfilter/ipvs/ip_vs_lblcr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_lblcr.c +1 -1
@@ -511,7 +511,7 @@ static int ip_vs_lblcr_init_svc(struct ip_vs_service *svc)/* * Allocate the ip_vs_lblcr_table for this service */ - tbl =kmalloc (sizeof (*tbl),GFP_ATOMIC ); + tbl =kmalloc (sizeof (*tbl),GFP_KERNEL );if (tbl ==NULL )return -ENOMEM ;
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 10/25 ipvs: SH scheduler does not need GFP_ATOMIC allocation
In reply to [email protected]From: Julian Anastasov <[email protected]>
Schedulers are initialized and bound to services only
on commands.
--- net/netfilter/ipvs/ip_vs_sh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_sh.c +1 -1
@@ -162,7 +162,7 @@ static int ip_vs_sh_init_svc(struct ip_vs_service *svc)/* allocate the SH table for this service */ tbl =kmalloc (sizeof (struct ip_vs_sh_bucket )*IP_VS_SH_TAB_SIZE , -GFP_ATOMIC ); +GFP_KERNEL );if (tbl ==NULL )return -ENOMEM ;
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 11/25 ipvs: use GFP_KERNEL allocation where possible
In reply to [email protected]From: Sasha Levin <[email protected]>
Use GFP_KERNEL instead of GFP_ATOMIC when registering an ipvs protocol.
This is safe since it will always run from a process context.
--- net/netfilter/ipvs/ip_vs_proto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_proto.c +1 -1
@@ -68,7 +68,7 @@ register_ip_vs_proto_netns(struct net *net, struct ip_vs_protocol *pp)struct netns_ipvs *ipvs =net_ipvs (net);unsigned int hash =IP_VS_PROTO_HASH (pp->protocol);struct ip_vs_proto_data *pd = -kzalloc (sizeof (struct ip_vs_proto_data ),GFP_ATOMIC ); +kzalloc (sizeof (struct ip_vs_proto_data ),GFP_KERNEL );if (!pd)return -ENOMEM ;
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 12/25 ipvs: ignore IP_VS_CONN_F_NOOUTPUT in backup server
In reply to [email protected]From: Julian Anastasov <[email protected]>
As IP_VS_CONN_F_NOOUTPUT is derived from the
forwarding method we should get it from conn_flags just like we do it for IP_VS_CONN_F_FWD_MASK bits when binding to real server.
--- net/netfilter/ipvs/ip_vs_conn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_conn.c +1 -1
@@ -567,7 +567,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)if (!(cp->flags &IP_VS_CONN_F_TEMPLATE )) conn_flags &= ~IP_VS_CONN_F_INACTIVE ;/* connections inherit forwarding method from dest */ - cp->flags &= ~IP_VS_CONN_F_FWD_MASK ; + cp->flags &= ~(IP_VS_CONN_F_FWD_MASK |IP_VS_CONN_F_NOOUTPUT ); } cp->flags |= conn_flags; cp->dest = dest;
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 13/25 ipvs: remove check for IP_VS_CONN_F_SYNC from ip_vs_bind_dest
In reply to [email protected]From: Julian Anastasov <[email protected]>
As the IP_VS_CONN_F_INACTIVE bit is properly set
in cp->flags for all kind of connections we do not need to add special checks for synced connections when updating the activeconns/inactconns counters for first time. Now logic will look just like in ip_vs_unbind_dest.
--- net/netfilter/ipvs/ip_vs_conn.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/netfilter/ipvs/ip_vs_conn.c +5 -5
@@ -585,11 +585,11 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)/* Update the connection counters */ if (!(cp->flags &IP_VS_CONN_F_TEMPLATE )) { -/* It is a normal connection, so increase the inactive -connection counter because it is in TCP SYNRECV -state (inactive) or other protocol inacive state */ -if ((cp->flags &IP_VS_CONN_F_SYNC ) && - (!(cp->flags &IP_VS_CONN_F_INACTIVE ))) +/* It is a normal connection, so modify the counters +* according to the flags, later the protocol can +* update them on state change +*/ +if (!(cp->flags &IP_VS_CONN_F_INACTIVE ))atomic_inc (&dest->activeconns);else atomic_inc (&dest->inactconns);
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 14/25 ipvs: fix ip_vs_try_bind_dest to rebind app and transmitter
In reply to [email protected]From: Julian Anastasov <[email protected]>
Initially, when the synced connection is created we
use the forwarding method provided by master but once we bind to destination it can be changed. As result, we must update the application and the transmitter.
As ip_vs_try_bind_dest is called always for connections
that require dest binding, there is no need to validate the cp and dest pointers.
--- net/netfilter/ipvs/ip_vs_conn.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-)
net/netfilter/ipvs/ip_vs_conn.c +26 -7
@@ -613,14 +613,33 @@ struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp) {struct ip_vs_dest *dest; -if ((cp) && (!cp->dest)) { - dest =ip_vs_find_dest (ip_vs_conn_net (cp), cp->af, &cp->daddr, - cp->dport, &cp->vaddr, cp->vport, - cp->protocol, cp->fwmark, cp->flags); + dest =ip_vs_find_dest (ip_vs_conn_net (cp), cp->af, &cp->daddr, + cp->dport, &cp->vaddr, cp->vport, + cp->protocol, cp->fwmark, cp->flags); +if (dest) { +struct ip_vs_proto_data *pd; + +/* Applications work depending on the forwarding method +* but better to reassign them always when binding dest */ +if (cp->app) +ip_vs_unbind_app (cp); +ip_vs_bind_dest (cp, dest); -return dest; - }else -return NULL ; + +/* Update its packet transmitter */ + cp->packet_xmit =NULL ; +#ifdef CONFIG_IP_VS_IPV6 +if (cp->af ==AF_INET6 ) +ip_vs_bind_xmit_v6 (cp); + else +#endif +ip_vs_bind_xmit (cp); + + pd =ip_vs_proto_data_get (ip_vs_conn_net (cp), cp->protocol); +if (pd &&atomic_read (&pd->appcnt)) +ip_vs_bind_app (cp, pd->pp); + } +return dest; }
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 15/25 ipvs: always update some of the flags bits in backup
In reply to [email protected]From: Julian Anastasov <[email protected]>
As the goal is to mirror the inactconns/activeconns
counters in the backup server, make sure the cp->flags are updated even if cp is still not bound to dest. If cp->flags are not updated ip_vs_bind_dest will rely only on the initial flags when updating the counters. To avoid mistakes and complicated checks for protocol state rely only on the IP_VS_CONN_F_INACTIVE bit when updating the counters.
--- include/linux/ip_vs.h | 5 +++ net/netfilter/ipvs/ip_vs_sync.c | 65 ++++++++++++++------------------------- 2 files changed, 28 insertions(+), 42 deletions(-)
include/linux/ip_vs.h +5 -0
@@ -89,6 +89,7 @@#define IP_VS_CONN_F_TEMPLATE 0x1000/* template, not connection */ #define IP_VS_CONN_F_ONE_PACKET 0x2000/* forward only one packet */ +/* Initial bits allowed in backup server */ #define IP_VS_CONN_F_BACKUP_MASK (IP_VS_CONN_F_FWD_MASK | \ IP_VS_CONN_F_NOOUTPUT | \ IP_VS_CONN_F_INACTIVE | \
@@ -97,6 +98,10 @@ IP_VS_CONN_F_TEMPLATE \ ) +/* Bits allowed to update in backup server */ +#define IP_VS_CONN_F_BACKUP_UPD_MASK (IP_VS_CONN_F_INACTIVE | \ + IP_VS_CONN_F_SEQ_MASK) +/* Flags that are not sent to backup server start from bit 16 */ #define IP_VS_CONN_F_NFCT (1 << 16)/* use netfilter conntrack */
net/netfilter/ipvs/ip_vs_sync.c +23 -42
84 lines not on this page · raw message
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 16/25 ipvs: wakeup master thread
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
High rate of sync messages in master can lead to
overflowing the socket buffer and dropping the messages. Fixed sleep of 1 second without wakeup events is not suitable for loaded masters,
Use delayed_work to schedule sending for queued messages
and limit the delay to IPVS_SYNC_SEND_DELAY (20ms). This will reduce the rate of wakeups but to avoid sending long bursts we wakeup the master thread after IPVS_SYNC_WAKEUP_RATE (8) messages.
Add hard limit for the queued messages before sending
by using "sync_qlen_max" sysctl var. It defaults to 1/32 of the memory pages but actually represents number of messages. It will protect us from allocating large parts of memory when the sending rate is lower than the queuing rate.
As suggested by Pablo, add new sysctl var
"sync_sock_size" to configure the SNDBUF (master) or RCVBUF (slave) socket limit. Default value is 0 (preserve system defaults).
Change the master thread to detect and block on
SNDBUF overflow, so that we do not drop messages when the socket limit is low but the sync_qlen_max limit is not reached. On ENOBUFS or other errors just drop the messages.
Change master thread to enter TASK_INTERRUPTIBLE
state early, so that we do not miss wakeups due to messages or kthread_should_stop event.
Thanks to Pablo Neira Ayuso for his valuable feedback!
--- include/net/ip_vs.h | 29 ++++++++ net/netfilter/ipvs/ip_vs_ctl.c | 16 +++++ net/netfilter/ipvs/ip_vs_sync.c | 149 ++++++++++++++++++++++++++++++--------- 3 files changed, 162 insertions(+), 32 deletions(-)
include/net/ip_vs.h +29 -0
@@ -869,6 +869,8 @@ struct netns_ipvs {#endif int sysctl_snat_reroute;int sysctl_sync_ver; +int sysctl_sync_qlen_max; +int sysctl_sync_sock_size;int sysctl_cache_bypass;int sysctl_expire_nodest_conn;int sysctl_expire_quiescent_template;
@@ -889,6 +891,9 @@ struct netns_ipvs {struct timer_list est_timer;/* Estimation timer */ /* ip_vs_sync */ struct list_head sync_queue; +int sync_queue_len; +unsigned int sync_queue_delay; +struct delayed_work master_wakeup_work;spinlock_t sync_lock;struct ip_vs_sync_buff *sync_buff;spinlock_t sync_buff_lock;
@@ -911,6 +916,10 @@ struct netns_ipvs {#define DEFAULT_SYNC_THRESHOLD 3#define DEFAULT_SYNC_PERIOD 50#define DEFAULT_SYNC_VER 1 +#define IPVS_SYNC_WAKEUP_RATE 8 +#define IPVS_SYNC_QLEN_MAX (IPVS_SYNC_WAKEUP_RATE * 4) +#define IPVS_SYNC_SEND_DELAY (HZ / 50) +#define IPVS_SYNC_CHECK_PERIOD HZ#ifdef CONFIG_SYSCTL
@@ -929,6 +938,16 @@ static inline int sysctl_sync_ver(struct netns_ipvs *ipvs) return ipvs->sysctl_sync_ver; } +static inline int sysctl_sync_qlen_max (struct netns_ipvs *ipvs) +{ +return ipvs->sysctl_sync_qlen_max; +} + +static inline int sysctl_sync_sock_size (struct netns_ipvs *ipvs) +{ +return ipvs->sysctl_sync_sock_size; +} +#else static inline int sysctl_sync_threshold (struct netns_ipvs *ipvs)
@@ -946,6 +965,16 @@ static inline int sysctl_sync_ver(struct netns_ipvs *ipvs) return DEFAULT_SYNC_VER; } +static inline int sysctl_sync_qlen_max (struct netns_ipvs *ipvs) +{ +return IPVS_SYNC_QLEN_MAX ; +} + +static inline int sysctl_sync_sock_size (struct netns_ipvs *ipvs) +{ +return 0 ; +} +#endif /*
net/netfilter/ipvs/ip_vs_ctl.c +16 -0
@@ -1718,6 +1718,18 @@ static struct ctl_table vs_vars[] = { .proc_handler = &proc_do_sync_mode, }, { + .procname = "sync_qlen_max", + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, + { + .procname = "sync_sock_size", + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, + { .procname = "cache_bypass", .maxlen = sizeof(int), .mode = 0644,
@@ -3655,6 +3667,10 @@ int __net_init ip_vs_control_net_init_sysctl(struct net *net) tbl[idx++].data = &ipvs->sysctl_snat_reroute; ipvs->sysctl_sync_ver =1 ; tbl[idx++].data = &ipvs->sysctl_sync_ver; + ipvs->sysctl_sync_qlen_max =nr_free_buffer_pages () /32 ; + tbl[idx++].data = &ipvs->sysctl_sync_qlen_max; + ipvs->sysctl_sync_sock_size =0 ; + tbl[idx++].data = &ipvs->sysctl_sync_sock_size; tbl[idx++].data = &ipvs->sysctl_cache_bypass; tbl[idx++].data = &ipvs->sysctl_expire_nodest_conn; tbl[idx++].data = &ipvs->sysctl_expire_quiescent_template;
net/netfilter/ipvs/ip_vs_sync.c +117 -32
253 lines not on this page · raw message
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 17/25 ipvs: reduce sync rate with time thresholds
In reply to [email protected]From: Julian Anastasov <[email protected]>
Add two new sysctl vars to control the sync rate with the
main idea to reduce the rate for connection templates because currently it depends on the packet rate for controlled connections. This mechanism should be useful also for normal connections with high traffic.
sync_refresh_period: in seconds, difference in reported connection
timer that triggers new sync message. It can be used to avoid sync messages for the specified period (or half of the connection timeout if it is lower) if connection state is not changed from last sync.
sync_retries: integer, 0..3, defines sync retries with period of
sync_refresh_period/8. Useful to protect against loss of sync messages.
Allow sysctl_sync_threshold to be used with
sysctl_sync_period=0, so that only single sync message is sent if sync_refresh_period is also 0.
Add new field "sync_endtime" in connection structure to
hold the reported time when connection expires. The 2 lowest bits will represent the retry count.
As the sysctl_sync_period now can be 0 use ACCESS_ONCE to
avoid division by zero.
Special thanks to Aleksey Chudov for being patient with me,
for his extensive reports and helping in all tests.
--- include/net/ip_vs.h | 30 +++++++++- net/netfilter/ipvs/ip_vs_conn.c | 7 ++- net/netfilter/ipvs/ip_vs_core.c | 30 +--------- net/netfilter/ipvs/ip_vs_ctl.c | 25 +++++++- net/netfilter/ipvs/ip_vs_sync.c | 121 +++++++++++++++++++++++++++++++++------ 5 files changed, 165 insertions(+), 48 deletions(-)
include/net/ip_vs.h +28 -2
@@ -504,6 +504,7 @@ struct ip_vs_conn {* state transition triggerd * synchronization */ +unsigned long sync_endtime;/* jiffies + sent_retries */ /* Control members */ struct ip_vs_conn *control;/* Master control connection */
@@ -875,6 +876,8 @@ struct netns_ipvs {int sysctl_expire_nodest_conn;int sysctl_expire_quiescent_template;int sysctl_sync_threshold[2 ]; +unsigned int sysctl_sync_refresh_period; +int sysctl_sync_retries;int sysctl_nat_icmp_send;/* ip_vs_lblc */
@@ -916,10 +919,13 @@ struct netns_ipvs {#define DEFAULT_SYNC_THRESHOLD 3#define DEFAULT_SYNC_PERIOD 50#define DEFAULT_SYNC_VER 1 +#define DEFAULT_SYNC_REFRESH_PERIOD (0U * HZ) +#define DEFAULT_SYNC_RETRIES 0#define IPVS_SYNC_WAKEUP_RATE 8#define IPVS_SYNC_QLEN_MAX (IPVS_SYNC_WAKEUP_RATE * 4)#define IPVS_SYNC_SEND_DELAY (HZ / 50)#define IPVS_SYNC_CHECK_PERIOD HZ +#define IPVS_SYNC_FLUSH_TIME (HZ * 2)#ifdef CONFIG_SYSCTL
@@ -930,7 +936,17 @@ static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)static inline int sysctl_sync_period (struct netns_ipvs *ipvs) { -return ipvs->sysctl_sync_threshold[1 ]; +return ACCESS_ONCE (ipvs->sysctl_sync_threshold[1 ]); +} + +static inline unsigned int sysctl_sync_refresh_period (struct netns_ipvs *ipvs) +{ +return ACCESS_ONCE (ipvs->sysctl_sync_refresh_period); +} + +static inline int sysctl_sync_retries (struct netns_ipvs *ipvs) +{ +return ipvs->sysctl_sync_retries; }static inline int sysctl_sync_ver (struct netns_ipvs *ipvs)
@@ -960,6 +976,16 @@ static inline int sysctl_sync_period(struct netns_ipvs *ipvs)return DEFAULT_SYNC_PERIOD ; } +static inline unsigned int sysctl_sync_refresh_period (struct netns_ipvs *ipvs) +{ +return DEFAULT_SYNC_REFRESH_PERIOD ; +} + +static inline int sysctl_sync_retries (struct netns_ipvs *ipvs) +{ +return DEFAULT_SYNC_RETRIES &3 ; +} +static inline int sysctl_sync_ver (struct netns_ipvs *ipvs) {return DEFAULT_SYNC_VER ;
@@ -1248,7 +1274,7 @@ extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp);extern int start_sync_thread (struct net *net,int state,char *mcast_ifn,__u8 syncid);extern int stop_sync_thread (struct net *net,int state); -extern void ip_vs_sync_conn (struct net *net,struct ip_vs_conn *cp); +extern void ip_vs_sync_conn (struct net *net,struct ip_vs_conn *cp,int pkts);/*
net/netfilter/ipvs/ip_vs_conn.c +6 -1
@@ -762,7 +762,8 @@ int ip_vs_check_template(struct ip_vs_conn *ct)static void ip_vs_conn_expire (unsigned long data) {struct ip_vs_conn *cp = (struct ip_vs_conn *)data; -struct netns_ipvs *ipvs =net_ipvs (ip_vs_conn_net (cp)); +struct net *net =ip_vs_conn_net (cp); +struct netns_ipvs *ipvs =net_ipvs (net); cp->timeout =60 *HZ ;
@@ -827,6 +828,9 @@ static void ip_vs_conn_expire(unsigned long data)atomic_read (&cp->refcnt)-1 , atomic_read(&cp->n_control)); +if (ipvs->sync_state &IP_VS_STATE_MASTER ) +ip_vs_sync_conn (net, cp,sysctl_sync_threshold (ipvs)); +ip_vs_conn_put (cp); }
@@ -900,6 +904,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,/* Set its state and timeout */ cp->state =0 ; cp->timeout =3 *HZ ; + cp->sync_endtime = jiffies & ~3UL ;/* Bind its packet transmitter */ #ifdef CONFIG_IP_VS_IPV6
net/netfilter/ipvs/ip_vs_core.c +2 -28
@@ -1613,34 +1613,8 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)else pkts =atomic_add_return (1 , &cp->in_pkts); -if ((ipvs->sync_state &IP_VS_STATE_MASTER ) && - cp->protocol ==IPPROTO_SCTP ) { -if ((cp->state ==IP_VS_SCTP_S_ESTABLISHED && - (pkts %sysctl_sync_period (ipvs) - ==sysctl_sync_threshold (ipvs))) || - (cp->old_state != cp->state && - ((cp->state ==IP_VS_SCTP_S_CLOSED ) || - (cp->state ==IP_VS_SCTP_S_SHUT_ACK_CLI ) || - (cp->state ==IP_VS_SCTP_S_SHUT_ACK_SER )))) { -ip_vs_sync_conn (net, cp); - goto out; - } - } - -/* Keep this block last: TCP and others with pp->num_states <= 1 */ -else if ((ipvs->sync_state &IP_VS_STATE_MASTER ) && - (((cp->protocol !=IPPROTO_TCP || - cp->state ==IP_VS_TCP_S_ESTABLISHED ) && - (pkts %sysctl_sync_period (ipvs) - ==sysctl_sync_threshold (ipvs))) || - ((cp->protocol ==IPPROTO_TCP ) && (cp->old_state != cp->state) && - ((cp->state ==IP_VS_TCP_S_FIN_WAIT ) || - (cp->state ==IP_VS_TCP_S_CLOSE ) || - (cp->state ==IP_VS_TCP_S_CLOSE_WAIT ) || - (cp->state ==IP_VS_TCP_S_TIME_WAIT ))))) -ip_vs_sync_conn (net, cp); -out: - cp->old_state = cp->state; +if (ipvs->sync_state &IP_VS_STATE_MASTER ) +ip_vs_sync_conn (net, cp, pkts);ip_vs_conn_put (cp);return ret;
net/netfilter/ipvs/ip_vs_ctl.c +24 -1
@@ -1599,6 +1599,10 @@ static int ip_vs_zero_all(struct net *net) }#ifdef CONFIG_SYSCTL + +static int zero; +static int three =3 ; +static int proc_do_defense_mode (ctl_table *table,int write,void __user *buffer,size_t *lenp,loff_t *ppos)
@@ -1632,7 +1636,8 @@ proc_do_sync_threshold(ctl_table *table, int write,memcpy (val, valp,sizeof (val)); rc =proc_dointvec (table, write, buffer, lenp, ppos); -if (write && (valp[0 ] <0 || valp[1 ] <0 || valp[0 ] >= valp[1 ])) { +if (write && (valp[0 ] <0 || valp[1 ] <0 || + (valp[0 ] >= valp[1 ] && valp[1 ]))) {/* Restore the correct value */ memcpy (valp, val,sizeof (val)); }
@@ -1755,6 +1760,20 @@ static struct ctl_table vs_vars[] = { .proc_handler = proc_do_sync_threshold, }, { + .procname = "sync_refresh_period", + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_jiffies, + }, + { + .procname = "sync_retries", + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &three, + }, + { .procname = "nat_icmp_send", .maxlen = sizeof(int), .mode = 0644,
@@ -3678,6 +3697,10 @@ int __net_init ip_vs_control_net_init_sysctl(struct net *net) ipvs->sysctl_sync_threshold[1 ] =DEFAULT_SYNC_PERIOD ; tbl[idx].data = &ipvs->sysctl_sync_threshold; tbl[idx++].maxlen =sizeof (ipvs->sysctl_sync_threshold); + ipvs->sysctl_sync_refresh_period =DEFAULT_SYNC_REFRESH_PERIOD ; + tbl[idx++].data = &ipvs->sysctl_sync_refresh_period; + ipvs->sysctl_sync_retries =clamp_t (int,DEFAULT_SYNC_RETRIES ,0 ,3 ); + tbl[idx++].data = &ipvs->sysctl_sync_retries; tbl[idx++].data = &ipvs->sysctl_nat_icmp_send;
net/netfilter/ipvs/ip_vs_sync.c +105 -16
173 lines not on this page · raw message
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 18/25 ipvs: add support for sync threads
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
Allow master and backup servers to use many threads
for sync traffic. Add sysctl var "sync_ports" to define the number of threads. Every thread will use single UDP port, thread 0 will use the default port 8848 while last thread will use port 8848+sync_ports-1.
The sync traffic for connections is scheduled to many
master threads based on the cp address but one connection is always assigned to same thread to avoid reordering of the sync messages.
Remove ip_vs_sync_switch_mode because this check
for sync mode change is still risky. Instead, check for mode change under sync_buff_lock.
Make sure the backup socks do not block on reading.
Special thanks to Aleksey Chudov for helping in all tests.
--- include/net/ip_vs.h | 34 +++- net/netfilter/ipvs/ip_vs_conn.c | 7 + net/netfilter/ipvs/ip_vs_ctl.c | 29 ++- net/netfilter/ipvs/ip_vs_sync.c | 401 ++++++++++++++++++++++++--------------- 4 files changed, 305 insertions(+), 166 deletions(-)
include/net/ip_vs.h +25 -9
@@ -784,6 +784,16 @@ struct ip_vs_app {void (*timeout_change)(struct ip_vs_app *app,int flags); }; +struct ipvs_master_sync_state { +struct list_head sync_queue; +struct ip_vs_sync_buff *sync_buff; +int sync_queue_len; +unsigned int sync_queue_delay; +struct task_struct *master_thread; +struct delayed_work master_wakeup_work; +struct netns_ipvs *ipvs; +}; +/* IPVS in network namespace */ struct netns_ipvs {int gen;/* Generation */
@@ -870,6 +880,7 @@ struct netns_ipvs {#endif int sysctl_snat_reroute;int sysctl_sync_ver; +int sysctl_sync_ports;int sysctl_sync_qlen_max;int sysctl_sync_sock_size;int sysctl_cache_bypass;
@@ -893,16 +904,11 @@ struct netns_ipvs {spinlock_t est_lock;struct timer_list est_timer;/* Estimation timer */ /* ip_vs_sync */ -struct list_head sync_queue; -int sync_queue_len; -unsigned int sync_queue_delay; -struct delayed_work master_wakeup_work;spinlock_t sync_lock; -struct ip_vs_sync_buff *sync_buff; +struct ipvs_master_sync_state *ms;spinlock_t sync_buff_lock; -struct sockaddr_in sync_mcast_addr; -struct task_struct *master_thread; -struct task_struct *backup_thread; +struct task_struct **backup_threads; +int threads_mask;int send_mesg_maxlen;int recv_mesg_maxlen;volatile int sync_state;
@@ -926,6 +932,7 @@ struct netns_ipvs {#define IPVS_SYNC_SEND_DELAY (HZ / 50)#define IPVS_SYNC_CHECK_PERIOD HZ#define IPVS_SYNC_FLUSH_TIME (HZ * 2) +#define IPVS_SYNC_PORTS_MAX (1 << 6)#ifdef CONFIG_SYSCTL
@@ -954,6 +961,11 @@ static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)return ipvs->sysctl_sync_ver; } +static inline int sysctl_sync_ports (struct netns_ipvs *ipvs) +{ +return ACCESS_ONCE (ipvs->sysctl_sync_ports); +} +static inline int sysctl_sync_qlen_max (struct netns_ipvs *ipvs) {return ipvs->sysctl_sync_qlen_max;
@@ -991,6 +1003,11 @@ static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)return DEFAULT_SYNC_VER ; } +static inline int sysctl_sync_ports (struct netns_ipvs *ipvs) +{ +return 1 ; +} +static inline int sysctl_sync_qlen_max (struct netns_ipvs *ipvs) {return IPVS_SYNC_QLEN_MAX ;
@@ -1240,7 +1257,6 @@ extern void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg);extern struct ip_vs_stats ip_vs_stats;extern int sysctl_ip_vs_sync_ver; -extern void ip_vs_sync_switch_mode (struct net *net,int mode);extern struct ip_vs_service *ip_vs_service_get (struct net *net,int af,__u32 fwmark,__u16 protocol,const union nf_inet_addr *vaddr,__be16 vport);
net/netfilter/ipvs/ip_vs_conn.c +7 -0
@@ -619,12 +619,19 @@ struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp)if (dest) {struct ip_vs_proto_data *pd; +spin_lock (&cp->lock); +if (cp->dest) { +spin_unlock (&cp->lock); +return dest; + } +/* Applications work depending on the forwarding method * but better to reassign them always when binding dest */ if (cp->app)ip_vs_unbind_app (cp);ip_vs_bind_dest (cp, dest); +spin_unlock (&cp->lock);/* Update its packet transmitter */ cp->packet_xmit =NULL ;
net/netfilter/ipvs/ip_vs_ctl.c +26 -3
@@ -1657,9 +1657,24 @@ proc_do_sync_mode(ctl_table *table, int write,if ((*valp <0 ) || (*valp >1 )) {/* Restore the correct value */ *valp = val; - }else { -struct net *net = current->nsproxy->net_ns; -ip_vs_sync_switch_mode (net, val); + } + } +return rc; +} + +static int +proc_do_sync_ports (ctl_table *table,int write, +void __user *buffer,size_t *lenp,loff_t *ppos) +{ +int *valp = table->data; +int val = *valp; +int rc; + + rc =proc_dointvec (table, write, buffer, lenp, ppos); +if (write && (*valp != val)) { +if (*valp <1 || !is_power_of_2 (*valp)) { +/* Restore the correct value */ + *valp = val; } }return rc;
@@ -1723,6 +1738,12 @@ static struct ctl_table vs_vars[] = { .proc_handler = &proc_do_sync_mode, }, { + .procname = "sync_ports", + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = &proc_do_sync_ports, + }, + { .procname = "sync_qlen_max", .maxlen = sizeof(int), .mode = 0644,
@@ -3686,6 +3707,8 @@ int __net_init ip_vs_control_net_init_sysctl(struct net *net) tbl[idx++].data = &ipvs->sysctl_snat_reroute; ipvs->sysctl_sync_ver =1 ; tbl[idx++].data = &ipvs->sysctl_sync_ver; + ipvs->sysctl_sync_ports =1 ; + tbl[idx++].data = &ipvs->sysctl_sync_ports; ipvs->sysctl_sync_qlen_max =nr_free_buffer_pages () /32 ; tbl[idx++].data = &ipvs->sysctl_sync_qlen_max; ipvs->sysctl_sync_sock_size =0 ;
net/netfilter/ipvs/ip_vs_sync.c +247 -154
691 lines not on this page · raw message
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 19/25 ipvs: optimize the use of flags in ip_vs_bind_dest
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
cp->flags is marked volatile but ip_vs_bind_dest
can safely modify the flags, so save some CPU cycles by using temp variable.
--- net/netfilter/ipvs/ip_vs_conn.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
net/netfilter/ipvs/ip_vs_conn.c +9 -6
@@ -548,6 +548,7 @@ static inline void ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest) { unsigned int conn_flags; +__u32 flags;/* if dest is NULL, then return directly */ if (!dest)
@@ -559,17 +560,19 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest) conn_flags =atomic_read (&dest->conn_flags);if (cp->protocol !=IPPROTO_UDP ) conn_flags &= ~IP_VS_CONN_F_ONE_PACKET ; + flags = cp->flags;/* Bind with the destination and its corresponding transmitter */ -if (cp->flags &IP_VS_CONN_F_SYNC ) { +if (flags &IP_VS_CONN_F_SYNC ) {/* if the connection is not template and is created * by sync, preserve the activity flag. */ -if (!(cp->flags &IP_VS_CONN_F_TEMPLATE )) +if (!(flags &IP_VS_CONN_F_TEMPLATE )) conn_flags &= ~IP_VS_CONN_F_INACTIVE ;/* connections inherit forwarding method from dest */ - cp->flags &= ~(IP_VS_CONN_F_FWD_MASK |IP_VS_CONN_F_NOOUTPUT ); + flags &= ~(IP_VS_CONN_F_FWD_MASK |IP_VS_CONN_F_NOOUTPUT ); } - cp->flags |= conn_flags; + flags |= conn_flags; + cp->flags = flags; cp->dest = dest; IP_VS_DBG_BUF(7, "Bind-dest %s c:%s:%d v:%s:%d "
@@ -584,12 +587,12 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest) atomic_read(&dest->refcnt));/* Update the connection counters */ -if (!(cp->flags &IP_VS_CONN_F_TEMPLATE )) { +if (!(flags &IP_VS_CONN_F_TEMPLATE )) {/* It is a normal connection, so modify the counters * according to the flags, later the protocol can * update them on state change */ -if (!(cp->flags &IP_VS_CONN_F_INACTIVE )) +if (!(flags &IP_VS_CONN_F_INACTIVE ))atomic_inc (&dest->activeconns);else atomic_inc (&dest->inactconns);
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 20/25 ipvs: ip_vs_ftp: local functions should not be exposed globally
In reply to [email protected]From: H Hartley Sweeten <[email protected]>
Functions not referenced outside of a source file should be marked static to prevent it from being exposed globally.
This quiets the sparse warnings:
warning: symbol 'ip_vs_ftp_init' was not declared. Should it be static?
--- net/netfilter/ipvs/ip_vs_ftp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_ftp.c +1 -1
@@ -485,7 +485,7 @@ static struct pernet_operations ip_vs_ftp_ops = { .exit = __ip_vs_ftp_exit, }; -int __init ip_vs_ftp_init (void ) +static int __init ip_vs_ftp_init (void ) {int rv;
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 21/25 ipvs: ip_vs_proto: local functions should not be exposed globally
In reply to [email protected]From: H Hartley Sweeten <[email protected]>
Functions not referenced outside of a source file should be marked static to prevent it from being exposed globally.
This quiets the sparse warnings:
warning: symbol '__ipvs_proto_data_get' was not declared. Should it be static?
--- net/netfilter/ipvs/ip_vs_proto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_proto.c +1 -1
@@ -156,7 +156,7 @@ EXPORT_SYMBOL(ip_vs_proto_get);/* * get ip_vs_protocol object data by netns and proto */ -struct ip_vs_proto_data * +static struct ip_vs_proto_data *__ipvs_proto_data_get (struct netns_ipvs *ipvs,unsigned short proto) {struct ip_vs_proto_data *pd;
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 22/25 net: export sysctl_[r|w]mem_max symbols needed by ip_vs_sync
In reply to [email protected]From: Hans Schillstrom <[email protected]>
To build ip_vs as a module sysctl_rmem_max and sysctl_wmem_max needs to be exported.
The dependency was added by "ipvs: wakeup master thread" patch.
--- net/core/sock.c | 2 ++ 1 file changed, 2 insertions(+)
net/core/sock.c +2 -0
@@ -259,7 +259,9 @@ static struct lock_class_key af_callback_keys[AF_MAX];/* Run time adjustable parameters. */ __u32 sysctl_wmem_max__read_mostly =SK_WMEM_MAX ; +EXPORT_SYMBOL (sysctl_wmem_max);__u32 sysctl_rmem_max__read_mostly =SK_RMEM_MAX ; +EXPORT_SYMBOL (sysctl_rmem_max);__u32 sysctl_wmem_default__read_mostly =SK_WMEM_MAX ;__u32 sysctl_rmem_default__read_mostly =SK_RMEM_MAX ;
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 23/25 netfilter: nf_ct_expect: partially implement ctnetlink_change_expect
In reply to [email protected]From: Kelvie Wong <[email protected]>
This refreshes the "timeout" attribute in existing expectations if one is given.
The use case for this would be for userspace helpers to extend the lifetime of the expectation when requested, as this is not possible right now without deleting/recreating the expectation.
I use this specifically for forwarding DCERPC traffic through:
DCERPC has a port mapper daemon that chooses a (seemingly) random port for future traffic to go to. We expect this traffic (with a reasonable timeout), but sometimes the port mapper will tell the client to continue using the same port. This allows us to extend the expectation accordingly.
--- net/netfilter/nf_conntrack_netlink.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
net/netfilter/nf_conntrack_netlink.c +9 -1
@@ -2080,7 +2080,15 @@ static int ctnetlink_change_expect(struct nf_conntrack_expect *x, const struct nlattr * const cda[]) { - return -EOPNOTSUPP; + if (cda[CTA_EXPECT_TIMEOUT]) { + if (!del_timer(&x->timeout)) + return -ETIME; + + x->timeout.expires = jiffies + +ntohl (nla_get_be32 (cda[CTA_EXPECT_TIMEOUT ])) *HZ ; +add_timer (&x->timeout); + } +return 0 ; }static const struct nla_policy exp_nat_nla_policy[CTA_EXPECT_NAT_MAX +1 ] = {
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 24/25 netfilter: nf_conntrack: fix explicit helper attachment and NAT
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
Explicit helper attachment via the CT target is broken with NAT if non-standard ports are used. This problem was hidden behind the automatic helper assignment routine. Thus, it becomes more noticeable now that we can disable the automatic helper assignment with Eric Leblond's:
9e8ac5a netfilter: nf_ct_helper: allow to disable automatic helper assignment
Basically, nf_conntrack_alter_reply asks for looking up the helper up if NAT is enabled. Unfortunately, we don't have the conntrack template at that point anymore.
Since we don't want to rely on the automatic helper assignment, we can skip the second look-up and stick to the helper that was attached by iptables. With the CT target, the user is in full control of helper attachment, thus, the policy is to trust what the user explicitly configures via iptables (no automatic magic anymore).
Interestingly, this bug was hidden by the automatic helper look-up code. But it can be easily trigger if you attach the helper in a non-standard port, eg.
iptables -I PREROUTING -t raw -p tcp --dport 8888 \ -j CT --helper ftp
And you disabled the automatic helper assignment.
I added the IPS_HELPER_BIT that allows us to differenciate between a helper that has been explicitly attached and those that have been automatically assigned. I didn't come up with a better solution (having backward compatibility in mind).
--- include/linux/netfilter/nf_conntrack_common.h | 4 ++++ net/netfilter/nf_conntrack_helper.c | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-)
include/linux/netfilter/nf_conntrack_common.h +4 -0
@@ -83,6 +83,10 @@ enum ip_conntrack_status {/* Conntrack is a fake untracked entry */ IPS_UNTRACKED_BIT =12 ,IPS_UNTRACKED = (1 <<IPS_UNTRACKED_BIT ), + +/* Conntrack got a helper explicitly attached via CT target. */ +IPS_HELPER_BIT =13 , + IPS_HELPER = (1 << IPS_HELPER_BIT), };/* Connection tracking event types */
net/netfilter/nf_conntrack_helper.c +12 -1
@@ -182,10 +182,21 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,struct net *net =nf_ct_net (ct);int ret =0 ; +/* We already got a helper explicitly attached. The function +* nf_conntrack_alter_reply - in case NAT is in use - asks for looking +* the helper up again. Since now the user is in full control of +* making consistent helper configurations, skip this automatic +* re-lookup, otherwise we'll lose the helper. +*/ +if (test_bit (IPS_HELPER_BIT , &ct->status)) +return 0 ; +if (tmpl !=NULL ) { help =nfct_help (tmpl); -if (help !=NULL ) +if (help !=NULL ) { helper = help->helper; +set_bit (IPS_HELPER_BIT , &ct->status); + } } help =nfct_help (ct);
Signature · 1 line
1.7.9.5
[email protected]
maintainerPATCH v3 25/25 netfilter: remove ip_queue support
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
This patch removes ip_queue support which was marked as obsolete years ago. The nfnetlink_queue modules provides more advanced user-space packet queueing mechanism.
This patch also removes capability code included in SELinux that refers to ip_queue. Otherwise, we break compilation.
Several warning has been sent regarding this to the mailing list in the past month without anyone rising the hand to stop this with some strong argument.
--- Documentation/ABI/removed/ip_queue | 9 + include/linux/netfilter_ipv4/Kbuild | 1 - include/linux/netfilter_ipv4/ip_queue.h | 72 ---- include/linux/netlink.h | 2 +- net/ipv4/netfilter/Makefile | 3 - net/ipv4/netfilter/ip_queue.c | 639 ------------------------------ net/ipv6/netfilter/Kconfig | 22 -- net/ipv6/netfilter/Makefile | 1 - net/ipv6/netfilter/ip6_queue.c | 641 ------------------------------- security/selinux/nlmsgtab.c | 13 - 10 files changed, 10 insertions(+), 1393 deletions(-) create mode 100644 Documentation/ABI/removed/ip_queue delete mode 100644 include/linux/netfilter_ipv4/ip_queue.h delete mode 100644 net/ipv4/netfilter/ip_queue.c delete mode 100644 net/ipv6/netfilter/ip6_queue.c
Documentation/ABI/removed/ip_queue new file +9 -0
@@ -0,0 +1,9 @@ +What: ip_queue +Date: finally removed in kernel v3.5.0 +Contact: Pablo Neira Ayuso <[email protected]> +Description: + ip_queue has been replaced by nfnetlink_queue which provides + more advanced queueing mechanism to user-space. The ip_queue + module was already announced to become obsolete years ago. + +Users:
include/linux/netfilter_ipv4/Kbuild +0 -1
@@ -1,4 +1,3 @@ -header-y += ip_queue.h header-y += ip_tables.h header-y += ipt_CLUSTERIP.h header-y += ipt_ECN.h
include/linux/netfilter_ipv4/ip_queue.h deleted +0 -72
72 lines not on this page · raw message
include/linux/netlink.h +1 -1
@@ -7,7 +7,7 @@#define NETLINK_ROUTE 0/* Routing/device hook */ #define NETLINK_UNUSED 1/* Unused number */ #define NETLINK_USERSOCK 2/* Reserved for user mode socket protocols */ -#define NETLINK_FIREWALL 3/* Firewalling hook */ +#define NETLINK_FIREWALL 3/* Unused number, formerly ip_queue */ #define NETLINK_SOCK_DIAG 4/* socket monitoring */ #define NETLINK_NFLOG 5/* netfilter/iptables ULOG */ #define NETLINK_XFRM 6/* ipsec */
net/ipv4/netfilter/Makefile +0 -3
@@ -66,6 +66,3 @@ obj-$(CONFIG_IP_NF_ARP_MANGLE) += arpt_mangle.o # just filtering instance of ARP tables for now obj-$(CONFIG_IP_NF_ARPFILTER) += arptable_filter.o - -obj-$(CONFIG_IP_NF_QUEUE) += ip_queue.o -
net/ipv4/netfilter/ip_queue.c deleted +0 -639
639 lines not on this page · raw message
net/ipv6/netfilter/Kconfig +0 -22
@@ -25,28 +25,6 @@ config NF_CONNTRACK_IPV6 To compile it as a module, choose M here. If unsure, say N. -config IP6_NF_QUEUE - tristate "IP6 Userspace queueing via NETLINK (OBSOLETE)" - depends on INET && IPV6 && NETFILTER - depends on NETFILTER_ADVANCED - ---help--- - - This option adds a queue handler to the kernel for IPv6 - packets which enables users to receive the filtered packets - with QUEUE target using libipq. - - This option enables the old IPv6-only "ip6_queue" implementation - which has been obsoleted by the new "nfnetlink_queue" code (see - CONFIG_NETFILTER_NETLINK_QUEUE). - - (C) Fernando Anton 2001 - IPv64 Project - Work based in IPv64 draft by Arturo Azcorra. - Universidad Carlos III de Madrid - Universidad Politecnica de Alcala de Henares - email: <[email protected]>. - - To compile it as a module, choose M here. If unsure, say N. - config IP6_NF_IPTABLES tristate "IP6 tables support (required for filtering)" depends on INET && IPV6
net/ipv6/netfilter/Makefile +0 -1
@@ -6,7 +6,6 @@ obj-$(CONFIG_IP6_NF_IPTABLES) += ip6_tables.o obj-$(CONFIG_IP6_NF_FILTER) += ip6table_filter.o obj-$(CONFIG_IP6_NF_MANGLE) += ip6table_mangle.o -obj-$(CONFIG_IP6_NF_QUEUE) += ip6_queue.o obj-$(CONFIG_IP6_NF_RAW) += ip6table_raw.o obj-$(CONFIG_IP6_NF_SECURITY) += ip6table_security.o
net/ipv6/netfilter/ip6_queue.c deleted +0 -641
641 lines not on this page · raw message
security/selinux/nlmsgtab.c +0 -13
@@ -14,7 +14,6 @@#include <linux/netlink.h> #include <linux/rtnetlink.h> #include <linux/if.h> -#include <linux/netfilter_ipv4/ip_queue.h> #include <linux/inet_diag.h> #include <linux/xfrm.h> #include <linux/audit.h>
@@ -70,12 +69,6 @@ static struct nlmsg_perm nlmsg_route_perms[] = { RTM_SETDCB, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, }; -static struct nlmsg_perm nlmsg_firewall_perms[] = -{ - {IPQM_MODE ,NETLINK_FIREWALL_SOCKET__NLMSG_WRITE }, - {IPQM_VERDICT ,NETLINK_FIREWALL_SOCKET__NLMSG_WRITE }, -}; -static struct nlmsg_perm nlmsg_tcpdiag_perms[] = { { TCPDIAG_GETSOCK, NETLINK_TCPDIAG_SOCKET__NLMSG_READ },
@@ -145,12 +138,6 @@ int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm) sizeof(nlmsg_route_perms));break ; -case SECCLASS_NETLINK_FIREWALL_SOCKET : -case SECCLASS_NETLINK_IP6FW_SOCKET : - err =nlmsg_perm (nlmsg_type, perm, nlmsg_firewall_perms, -sizeof (nlmsg_firewall_perms)); -break ; -case SECCLASS_NETLINK_TCPDIAG_SOCKET : err =nlmsg_perm (nlmsg_type, perm, nlmsg_tcpdiag_perms,sizeof (nlmsg_tcpdiag_perms));
Signature · 1 line
1.7.9.5
David Miller
maintainerFrom: [email protected]
Date: Tue, 8 May 2012 20:37:58 +0200
Quoted 1 line
git://1984.lsi.us.es/net-nextmaster
Pulled, thanks.