Skip to contentSkip to conversation

netfilter updates for net-next (upcoming 3.5), batch 2

PATCH In review [email protected] 3 participants 9 messages May 9, 2012 – May 14, 2012

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

cover netfilter updates for net-next (upcoming 3.5), batch 2

From: Pablo Neira Ayuso <[email protected]>

Hi David,

This is a second batch of netfilter updates for net-next, they contain:

* The new HMARK target from Hans Schillstrom. It took lots of spins to get this into shape. This target provides a hash-based packet / flow pre-classifier for iptables that can be used to distribute packets / flows between uplinks and backend servers. It provides to modes, one that relies on conntrack, and one that is stateless per-packet.

* Byte-based cost calculation for the hashlimit match, to detect when a host consumes more bandwidth than expected. This patch from Florian Westphal.

You can pull these changes from:

git://1984.lsi.us.es/net-next

Thanks!

Florian Westphal (3):
netfilter: limit, hashlimit: avoid duplicated inline
netfilter: hashlimit: move rateinfo initialization to helper
netfilter: hashlimit: byte-based limit mode

Hans Schillstrom (2):
netfilter: ip6_tables: add flags parameter to ipv6_find_hdr()
netfilter: add xt_hmark target for hash-based skb marking

 include/linux/netfilter/xt_HMARK.h        |   45 ++++
 include/linux/netfilter/xt_hashlimit.h    |   10 +-
 include/linux/netfilter_ipv6/ip6_tables.h |    7 +-
 net/ipv6/netfilter/ip6_tables.c           |   36 ++-
 net/ipv6/netfilter/ip6t_ah.c              |    4 +-
 net/ipv6/netfilter/ip6t_frag.c            |    4 +-
 net/ipv6/netfilter/ip6t_hbh.c             |    4 +-
 net/ipv6/netfilter/ip6t_rt.c              |    4 +-
 net/netfilter/Kconfig                     |   15 ++
 net/netfilter/Makefile                    |    1 +
 net/netfilter/xt_HMARK.c                  |  362 +++++++++++++++++++++++++++++
 net/netfilter/xt_TPROXY.c                 |    4 +-
 net/netfilter/xt_hashlimit.c              |  129 ++++++++--
 net/netfilter/xt_limit.c                  |    5 +-
 net/netfilter/xt_socket.c                 |    4 +-
 15 files changed, 588 insertions(+), 46 deletions(-)
 create mode 100644 include/linux/netfilter/xt_HMARK.h
 create mode 100644 net/netfilter/xt_HMARK.c
Signature · 1 line
1.7.9.5
author maintainer
#1 lore raw

PATCH 1/5 netfilter: ip6_tables: add flags parameter to ipv6_find_hdr()

From: Hans Schillstrom <[email protected]>

This patch adds the flags parameter to ipv6_find_hdr. This flags allows us to:

* know if this is a fragment.
* stop at the AH header, so the information contained in that header can be used for some specific packet handling.

This patch also adds the offset parameter for inspection of one inner IPv6 header that is contained in error messages.

---
 include/linux/netfilter_ipv6/ip6_tables.h |    7 +++++-
 net/ipv6/netfilter/ip6_tables.c           |   36 +++++++++++++++++++++++++----
 net/ipv6/netfilter/ip6t_ah.c              |    4 ++--
 net/ipv6/netfilter/ip6t_frag.c            |    4 ++--
 net/ipv6/netfilter/ip6t_hbh.c             |    4 ++--
 net/ipv6/netfilter/ip6t_rt.c              |    4 ++--
 net/netfilter/xt_TPROXY.c                 |    4 ++--
 net/netfilter/xt_socket.c                 |    4 ++--
 8 files changed, 49 insertions(+), 18 deletions(-)
include/linux/netfilter_ipv6/ip6_tables.h +6 -1
index 1bc898b..08c2cbb 100644
@@ -298,9 +298,14 @@ ip6t_ext_hdr(u8 nexthdr)
 	       (nexthdr == IPPROTO_DSTOPTS);
 }
 
+enum {
+	IP6T_FH_F_FRAG	= (1 << 0),
+	IP6T_FH_F_AUTH	= (1 << 1),
+};
+
 /* find specified header and get offset to it */
 extern int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
-			 int target, unsigned short *fragoff);
+			 int target, unsigned short *fragoff, int *fragflg);
 
 #ifdef CONFIG_COMPAT
 #include <net/compat.h>
net/ipv6/netfilter/ip6_tables.c +31 -5
index d4e350f..308bdd6 100644
@@ -133,7 +133,7 @@ ip6_packet_match(const struct sk_buff *skb,
 		int protohdr;
 		unsigned short _frag_off;
 
-		protohdr = ipv6_find_hdr(skb, protoff, -1, &_frag_off);
+		protohdr = ipv6_find_hdr(skb, protoff, -1, &_frag_off, NULL);
 		if (protohdr < 0) {
 			if (_frag_off == 0)
 				*hotdrop = true;
@@ -362,6 +362,7 @@ ip6t_do_table(struct sk_buff *skb,
 		const struct xt_entry_match *ematch;
 
 		IP_NF_ASSERT(e);
+		acpar.thoff = 0;
 		if (!ip6_packet_match(skb, indev, outdev, &e->ipv6,
 		    &acpar.thoff, &acpar.fragoff, &acpar.hotdrop)) {
  no_match:
@@ -2278,6 +2279,10 @@ static void __exit ip6_tables_fini(void)
  * if target < 0. "last header" is transport protocol header, ESP, or
  * "No next header".
  *
+ * Note that *offset is used as input/output parameter. an if it is not zero,
+ * then it must be a valid offset to an inner IPv6 header. This can be used
+ * to explore inner IPv6 header, eg. ICMPv6 error messages.
+ *
  * If target header is found, its offset is set in *offset and return protocol
  * number. Otherwise, return -1.
  *
@@ -2289,17 +2294,33 @@ static void __exit ip6_tables_fini(void)
  * *offset is meaningless and fragment offset is stored in *fragoff if fragoff
  * isn't NULL.
  *
+ * if flags is not NULL and it's a fragment, then the frag flag IP6T_FH_F_FRAG
+ * will be set. If it's an AH header, the IP6T_FH_F_AUTH flag is set and
+ * target < 0, then this function will stop at the AH header.
  */
 int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
-		  int target, unsigned short *fragoff)
+		  int target, unsigned short *fragoff, int *flags)
 {
 	unsigned int start = skb_network_offset(skb) + sizeof(struct ipv6hdr);
 	u8 nexthdr = ipv6_hdr(skb)->nexthdr;
-	unsigned int len = skb->len - start;
+	unsigned int len;
 
 	if (fragoff)
 		*fragoff = 0;
 
+	if (*offset) {
+		struct ipv6hdr _ip6, *ip6;
+
+		ip6 = skb_header_pointer(skb, *offset, sizeof(_ip6), &_ip6);
+		if (!ip6 || (ip6->version != 6)) {
+			printk(KERN_ERR "IPv6 header not found\n");
+			return -EBADMSG;
+		}
+		start = *offset + sizeof(struct ipv6hdr);
+		nexthdr = ip6->nexthdr;
+	}
+	len = skb->len - start;
+
 	while (nexthdr != target) {
 		struct ipv6_opt_hdr _hdr, *hp;
 		unsigned int hdrlen;
@@ -2316,6 +2337,9 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
 		if (nexthdr == NEXTHDR_FRAGMENT) {
 			unsigned short _frag_off;
 			__be16 *fp;
+
+			if (flags)	/* Indicate that this is a fragment */
+				*flags |= IP6T_FH_F_FRAG;
 			fp = skb_header_pointer(skb,
 						start+offsetof(struct frag_hdr,
 							       frag_off),
@@ -2336,9 +2360,11 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
 				return -ENOENT;
 			}
 			hdrlen = 8;
-		} else if (nexthdr == NEXTHDR_AUTH)
+		} else if (nexthdr == NEXTHDR_AUTH) {
+			if (flags && (*flags & IP6T_FH_F_AUTH) && (target < 0))
+				break;
 			hdrlen = (hp->hdrlen + 2) << 2;
-		else
+		} else
 			hdrlen = ipv6_optlen(hp);
 
 		nexthdr = hp->nexthdr;
net/ipv6/netfilter/ip6t_ah.c +2 -2
index 89cccc5..04099ab 100644
@@ -41,11 +41,11 @@ static bool ah_mt6(const struct sk_buff *skb, struct xt_action_param *par)
 	struct ip_auth_hdr _ah;
 	const struct ip_auth_hdr *ah;
 	const struct ip6t_ah *ahinfo = par->matchinfo;
-	unsigned int ptr;
+	unsigned int ptr = 0;
 	unsigned int hdrlen = 0;
 	int err;
 
-	err = ipv6_find_hdr(skb, &ptr, NEXTHDR_AUTH, NULL);
+	err = ipv6_find_hdr(skb, &ptr, NEXTHDR_AUTH, NULL, NULL);
 	if (err < 0) {
 		if (err != -ENOENT)
 			par->hotdrop = true;
net/ipv6/netfilter/ip6t_frag.c +2 -2
index eda898f..3b5735e 100644
@@ -40,10 +40,10 @@ frag_mt6(const struct sk_buff *skb, struct xt_action_param *par)
 	struct frag_hdr _frag;
 	const struct frag_hdr *fh;
 	const struct ip6t_frag *fraginfo = par->matchinfo;
-	unsigned int ptr;
+	unsigned int ptr = 0;
 	int err;
 
-	err = ipv6_find_hdr(skb, &ptr, NEXTHDR_FRAGMENT, NULL);
+	err = ipv6_find_hdr(skb, &ptr, NEXTHDR_FRAGMENT, NULL, NULL);
 	if (err < 0) {
 		if (err != -ENOENT)
 			par->hotdrop = true;
net/ipv6/netfilter/ip6t_hbh.c +2 -2
index 59df051..01df142 100644
@@ -50,7 +50,7 @@ hbh_mt6(const struct sk_buff *skb, struct xt_action_param *par)
 	const struct ipv6_opt_hdr *oh;
 	const struct ip6t_opts *optinfo = par->matchinfo;
 	unsigned int temp;
-	unsigned int ptr;
+	unsigned int ptr = 0;
 	unsigned int hdrlen = 0;
 	bool ret = false;
 	u8 _opttype;
@@ -62,7 +62,7 @@ hbh_mt6(const struct sk_buff *skb, struct xt_action_param *par)
 
 	err = ipv6_find_hdr(skb, &ptr,
 			    (par->match == &hbh_mt6_reg[0]) ?
-			    NEXTHDR_HOP : NEXTHDR_DEST, NULL);
+			    NEXTHDR_HOP : NEXTHDR_DEST, NULL, NULL);
 	if (err < 0) {
 		if (err != -ENOENT)
 			par->hotdrop = true;
net/ipv6/netfilter/ip6t_rt.c +2 -2
index d8488c5..2c99b94 100644
@@ -42,14 +42,14 @@ static bool rt_mt6(const struct sk_buff *skb, struct xt_action_param *par)
 	const struct ipv6_rt_hdr *rh;
 	const struct ip6t_rt *rtinfo = par->matchinfo;
 	unsigned int temp;
-	unsigned int ptr;
+	unsigned int ptr = 0;
 	unsigned int hdrlen = 0;
 	bool ret = false;
 	struct in6_addr _addr;
 	const struct in6_addr *ap;
 	int err;
 
-	err = ipv6_find_hdr(skb, &ptr, NEXTHDR_ROUTING, NULL);
+	err = ipv6_find_hdr(skb, &ptr, NEXTHDR_ROUTING, NULL, NULL);
 	if (err < 0) {
 		if (err != -ENOENT)
 			par->hotdrop = true;
net/netfilter/xt_TPROXY.c +2 -2
index 35a959a..146033a 100644
@@ -282,10 +282,10 @@ tproxy_tg6_v1(struct sk_buff *skb, const struct xt_action_param *par)
 	struct sock *sk;
 	const struct in6_addr *laddr;
 	__be16 lport;
-	int thoff;
+	int thoff = 0;
 	int tproto;
 
-	tproto = ipv6_find_hdr(skb, &thoff, -1, NULL);
+	tproto = ipv6_find_hdr(skb, &thoff, -1, NULL, NULL);
 	if (tproto < 0) {
 		pr_debug("unable to find transport header in IPv6 packet, dropping\n");
 		return NF_DROP;
net/netfilter/xt_socket.c +2 -2
index 72bb07f..9ea482d 100644
@@ -263,10 +263,10 @@ socket_mt6_v1(const struct sk_buff *skb, struct xt_action_param *par)
 	struct sock *sk;
 	struct in6_addr *daddr, *saddr;
 	__be16 dport, sport;
-	int thoff, tproto;
+	int thoff = 0, tproto;
 	const struct xt_socket_mtinfo1 *info = (struct xt_socket_mtinfo1 *) par->matchinfo;
 
-	tproto = ipv6_find_hdr(skb, &thoff, -1, NULL);
+	tproto = ipv6_find_hdr(skb, &thoff, -1, NULL, NULL);
 	if (tproto < 0) {
 		pr_debug("unable to find transport header in IPv6 packet, dropping\n");
 		return NF_DROP;
Signature · 1 line
1.7.9.5
author maintainer
#2 lore raw

PATCH 2/5 netfilter: add xt_hmark target for hash-based skb marking

In reply to [email protected]

From: Hans Schillstrom <[email protected]>

The target allows you to create rules in the "raw" and "mangle" tables which set the skbuff mark by means of hash calculation within a given range. The nfmark can influence the routing method (see "Use netfilter MARK value as routing key") and can also be used by other subsystems to change their behaviour.

[ Part of this patch has been refactorized and modified by Pablo Neira Ayuso ]

---
 include/linux/netfilter/xt_HMARK.h |   45 +++++
 net/netfilter/Kconfig              |   15 ++
 net/netfilter/Makefile             |    1 +
 net/netfilter/xt_HMARK.c           |  362 ++++++++++++++++++++++++++++++++++++
 4 files changed, 423 insertions(+)
 create mode 100644 include/linux/netfilter/xt_HMARK.h
 create mode 100644 net/netfilter/xt_HMARK.c
include/linux/netfilter/xt_HMARK.h new file +45 -0
new file mode 100644
index 0000000..abb1650
@@ -0,0 +1,45 @@
+#ifndef XT_HMARK_H_
+#define XT_HMARK_H_
+
+#include <linux/types.h>
+
+enum {
+	XT_HMARK_SADDR_MASK,
+	XT_HMARK_DADDR_MASK,
+	XT_HMARK_SPI,
+	XT_HMARK_SPI_MASK,
+	XT_HMARK_SPORT,
+	XT_HMARK_DPORT,
+	XT_HMARK_SPORT_MASK,
+	XT_HMARK_DPORT_MASK,
+	XT_HMARK_PROTO_MASK,
+	XT_HMARK_RND,
+	XT_HMARK_MODULUS,
+	XT_HMARK_OFFSET,
+	XT_HMARK_CT,
+	XT_HMARK_METHOD_L3,
+	XT_HMARK_METHOD_L3_4,
+};
+#define XT_HMARK_FLAG(flag)	(1 << flag)
+
+union hmark_ports {
+	struct {
+		__u16	src;
+		__u16	dst;
+	} p16;
+	__u32	v32;
+};
+
+struct xt_hmark_info {
+	union nf_inet_addr	src_mask;
+	union nf_inet_addr	dst_mask;
+	union hmark_ports	port_mask;
+	union hmark_ports	port_set;
+	__u32			flags;
+	__u16			proto_mask;
+	__u32			hashrnd;
+	__u32			hmodulus;
+	__u32			hoffset;	/* Mark offset to start from */
+};
+
+#endif /* XT_HMARK_H_ */
net/netfilter/Kconfig +15 -0
index 0c6f67e..209c1ed 100644
@@ -509,6 +509,21 @@ config NETFILTER_XT_TARGET_HL
 	since you can easily create immortal packets that loop
 	forever on the network.
 
+config NETFILTER_XT_TARGET_HMARK
+	tristate '"HMARK" target support'
+	depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
+	depends on NETFILTER_ADVANCED
+	---help---
+	This option adds the "HMARK" target.
+
+	The target allows you to create rules in the "raw" and "mangle" tables
+	which set the skbuff mark by means of hash calculation within a given
+	range. The nfmark can influence the routing method (see "Use netfilter
+	MARK value as routing key") and can also be used by other subsystems to
+	change their behaviour.
+
+	To compile it as a module, choose M here. If unsure, say N.
+
 config NETFILTER_XT_TARGET_IDLETIMER
 	tristate  "IDLETIMER target support"
 	depends on NETFILTER_ADVANCED
net/netfilter/Makefile +1 -0
index ca36765..4e7960c 100644
@@ -59,6 +59,7 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_CONNSECMARK) += xt_CONNSECMARK.o
 obj-$(CONFIG_NETFILTER_XT_TARGET_CT) += xt_CT.o
 obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o
 obj-$(CONFIG_NETFILTER_XT_TARGET_HL) += xt_HL.o
+obj-$(CONFIG_NETFILTER_XT_TARGET_HMARK) += xt_HMARK.o
 obj-$(CONFIG_NETFILTER_XT_TARGET_LED) += xt_LED.o
 obj-$(CONFIG_NETFILTER_XT_TARGET_LOG) += xt_LOG.o
 obj-$(CONFIG_NETFILTER_XT_TARGET_NFLOG) += xt_NFLOG.o
net/netfilter/xt_HMARK.c new file +362 -0

362 lines not on this page · raw message

Signature · 1 line
1.7.9.5
author maintainer
#3 lore raw

PATCH 3/5 netfilter: limit, hashlimit: avoid duplicated inline

In reply to [email protected]

From: Florian Westphal <[email protected]>

credit_cap can be set to credit, which avoids inlining user2credits twice. Also, remove inline keyword and let compiler decide.

old:

    684     192       0     876     36c net/netfilter/xt_limit.o
   4927     344      32    5303    14b7 net/netfilter/xt_hashlimit.o
now:
    668     192       0     860     35c net/netfilter/xt_limit.o

4793 344 32 5169 1431 net/netfilter/xt_hashlimit.o

---
 net/netfilter/xt_hashlimit.c |    8 +++-----
 net/netfilter/xt_limit.c     |    5 ++---
 2 files changed, 5 insertions(+), 8 deletions(-)
net/netfilter/xt_hashlimit.c +3 -5
index d95f9c9..2195eb0 100644
@@ -389,8 +389,7 @@ static void htable_put(struct xt_hashlimit_htable *hinfo)
 #define CREDITS_PER_JIFFY POW2_BELOW32(MAX_CPJ)
 
 /* Precision saver. */
-static inline u_int32_t
-user2credits(u_int32_t user)
+static u32 user2credits(u32 user)
 {
 	/* If multiplying would overflow... */
 	if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
@@ -400,7 +399,7 @@ user2credits(u_int32_t user)
 	return (user * HZ * CREDITS_PER_JIFFY) / XT_HASHLIMIT_SCALE;
 }
 
-static inline void rateinfo_recalc(struct dsthash_ent *dh, unsigned long now)
+static void rateinfo_recalc(struct dsthash_ent *dh, unsigned long now)
 {
 	dh->rateinfo.credit += (now - dh->rateinfo.prev) * CREDITS_PER_JIFFY;
 	if (dh->rateinfo.credit > dh->rateinfo.credit_cap)
@@ -535,8 +534,7 @@ hashlimit_mt(const struct sk_buff *skb, struct xt_action_param *par)
 		dh->rateinfo.prev = jiffies;
 		dh->rateinfo.credit = user2credits(hinfo->cfg.avg *
 		                      hinfo->cfg.burst);
-		dh->rateinfo.credit_cap = user2credits(hinfo->cfg.avg *
-		                          hinfo->cfg.burst);
+		dh->rateinfo.credit_cap = dh->rateinfo.credit;
 		dh->rateinfo.cost = user2credits(hinfo->cfg.avg);
 	} else {
 		/* update expiration timeout */
net/netfilter/xt_limit.c +2 -3
index 32b7a57..5c22ce8 100644
@@ -88,8 +88,7 @@ limit_mt(const struct sk_buff *skb, struct xt_action_param *par)
 }
 
 /* Precision saver. */
-static u_int32_t
-user2credits(u_int32_t user)
+static u32 user2credits(u32 user)
 {
 	/* If multiplying would overflow... */
 	if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
@@ -123,7 +122,7 @@ static int limit_mt_check(const struct xt_mtchk_param *par)
 		   128. */
 		priv->prev = jiffies;
 		priv->credit = user2credits(r->avg * r->burst); /* Credits full. */
-		r->credit_cap = user2credits(r->avg * r->burst); /* Credits full. */
+		r->credit_cap = priv->credit; /* Credits full. */
 		r->cost = user2credits(r->avg);
 	}
 	return 0;
Signature · 1 line
1.7.9.5
author maintainer
#4 lore raw

PATCH 4/5 netfilter: hashlimit: move rateinfo initialization to helper

In reply to [email protected]

From: Florian Westphal <[email protected]>

followup patch would bloat main match function too much.

---
 net/netfilter/xt_hashlimit.c |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
net/netfilter/xt_hashlimit.c +10 -5
index 2195eb0..b6bbd06 100644
@@ -407,6 +407,15 @@ static void rateinfo_recalc(struct dsthash_ent *dh, unsigned long now)
 	dh->rateinfo.prev = now;
 }
 
+static void rateinfo_init(struct dsthash_ent *dh,
+			  struct xt_hashlimit_htable *hinfo)
+{
+	dh->rateinfo.prev = jiffies;
+	dh->rateinfo.credit = user2credits(hinfo->cfg.avg * hinfo->cfg.burst);
+	dh->rateinfo.cost = user2credits(hinfo->cfg.avg);
+	dh->rateinfo.credit_cap = dh->rateinfo.credit;
+}
+
 static inline __be32 maskl(__be32 a, unsigned int l)
 {
 	return l ? htonl(ntohl(a) & ~0 << (32 - l)) : 0;
@@ -531,11 +540,7 @@ hashlimit_mt(const struct sk_buff *skb, struct xt_action_param *par)
 			goto hotdrop;
 		}
 		dh->expires = jiffies + msecs_to_jiffies(hinfo->cfg.expire);
-		dh->rateinfo.prev = jiffies;
-		dh->rateinfo.credit = user2credits(hinfo->cfg.avg *
-		                      hinfo->cfg.burst);
-		dh->rateinfo.credit_cap = dh->rateinfo.credit;
-		dh->rateinfo.cost = user2credits(hinfo->cfg.avg);
+		rateinfo_init(dh, hinfo);
 	} else {
 		/* update expiration timeout */
 		dh->expires = now + msecs_to_jiffies(hinfo->cfg.expire);
Signature · 1 line
1.7.9.5
author maintainer
#5 lore raw

PATCH 5/5 netfilter: hashlimit: byte-based limit mode

In reply to [email protected]

From: Florian Westphal <[email protected]>

can be used e.g. for ingress traffic policing or
to detect when a host/port consumes more bandwidth than expected.

This is done by optionally making cost to mean
"cost per 16-byte-chunk-of-data" instead of "cost per packet".

---
 include/linux/netfilter/xt_hashlimit.h |   10 ++-
 net/netfilter/xt_hashlimit.c           |  116 ++++++++++++++++++++++++++------
 2 files changed, 106 insertions(+), 20 deletions(-)
include/linux/netfilter/xt_hashlimit.h +9 -1
index b1925b5..05fe799 100644
@@ -6,7 +6,11 @@
 /* timings are in milliseconds. */
 #define XT_HASHLIMIT_SCALE 10000
 /* 1/10,000 sec period => max of 10,000/sec.  Min rate is then 429490
-   seconds, or one every 59 hours. */
+ * seconds, or one packet every 59 hours.
+ */
+
+/* packet length accounting is done in 16-byte steps */
+#define XT_HASHLIMIT_BYTE_SHIFT 4
 
 /* details of this structure hidden by the implementation */
 struct xt_hashlimit_htable;
@@ -17,6 +21,10 @@ enum {
 	XT_HASHLIMIT_HASH_SIP = 1 << 2,
 	XT_HASHLIMIT_HASH_SPT = 1 << 3,
 	XT_HASHLIMIT_INVERT   = 1 << 4,
+	XT_HASHLIMIT_BYTES    = 1 << 5,
+#ifdef __KERNEL__
+	XT_HASHLIMIT_MAX      = 1 << 6,
+#endif
 };
 
 struct hashlimit_cfg {
net/netfilter/xt_hashlimit.c +97 -19

178 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#6 lore raw
In reply to [email protected]
Quoted 11 lines · Le mercredi 09 mai 2012 à 13:33 +0200, [email protected] a écrit :

From: Pablo Neira Ayuso <[email protected]>

Hi David,

This is a second batch of netfilter updates for net-next, they contain:

* The new HMARK target from Hans Schillstrom. It took lots of spins to get this into shape. This target provides a hash-based packet / flow pre-classifier for iptables that can be used to distribute packets / flows between uplinks and backend servers. It provides to modes, one that relies on conntrack, and one that is stateless per-packet.

It seems this might be a good base for Deng-Cheng Zhu concerns.

(subject on netdev : RPS: Sparse connection optimizations )

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#7 lore raw
In reply to [email protected]

From: [email protected]
Date: Wed, 9 May 2012 13:33:03 +0200

Quoted 8 lines

This is a second batch of netfilter updates for net-next, they contain:

* The new HMARK target from Hans Schillstrom. It took lots of spins to get this into shape. This target provides a hash-based packet / flow pre-classifier for iptables that can be used to distribute packets / flows between uplinks and backend servers. It provides to modes, one that relies on conntrack, and one that is stateless per-packet.

Quoted 7 lines

* Byte-based cost calculation for the hashlimit match, to detect when a host consumes more bandwidth than expected. This patch from Florian Westphal.

You can pull these changes from:

git://1984.lsi.us.es/net-next

Pulled.

Two suggested improvements:

1) The HMARK hash is quite expensive, because it uses a modulus.

Consider adjusting it to use the usual trick:

	((u64)(HASH_VAL * HASH_SIZE)) >> 32

so that this can be a multiply instead of a modulus.

2) XT_HASHLIMIT_MAX is cumbersome.

The canonical way to validate if the set bits are in a
valid range is to have a "_ALL" macro, and test:

	if (val & ~XT_HASHLIMIT_ALL)
		goto err;

or similar.

Thanks.

author maintainer
#8 lore raw
Quoted 23 lines · David Miller

From: [email protected]
Date: Wed, 9 May 2012 13:33:03 +0200

Quoted 8 lines

This is a second batch of netfilter updates for net-next, they contain:

* The new HMARK target from Hans Schillstrom. It took lots of spins to get this into shape. This target provides a hash-based packet / flow pre-classifier for iptables that can be used to distribute packets / flows between uplinks and backend servers. It provides to modes, one that relies on conntrack, and one that is stateless per-packet.

Quoted 7 lines

* Byte-based cost calculation for the hashlimit match, to detect when a host consumes more bandwidth than expected. This patch from Florian Westphal.

You can pull these changes from:

git://1984.lsi.us.es/net-next

Pulled.

Two suggested improvements:

Quoted 7 lines

1) The HMARK hash is quite expensive, because it uses a modulus.

Consider adjusting it to use the usual trick:

	((u64)(HASH_VAL * HASH_SIZE)) >> 32

so that this can be a multiply instead of a modulus.

I'll enqueue the patch attached for this. Thanks for spotting this.

Quoted 1 line

From 3b81af711d639cdcf820836bad6b4ac0f5a761fa Mon Sep 17 00:00:00 2001

From: Pablo Neira Ayuso <[email protected]>
Date: Mon, 14 May 2012 02:01:46 +0200
Subject: [PATCH] netfilter: xt_HMARK: modulus is expensive for hash
calculation

Use:

((u64)(HASH_VAL * HASH_SIZE)) >> 32

as suggested by David S. Miller.

---
 net/netfilter/xt_HMARK.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_HMARK.c +1 -1
index 5817d03..0a96a43 100644
@@ -109,7 +109,7 @@ hmark_hash(struct hmark_tuple *t, const struct xt_hmark_info *info)
 	hash = jhash_3words(t->src, t->dst, t->uports.v32, info->hashrnd);
 	hash = hash ^ (t->proto & info->proto_mask);
 
-	return (hash % info->hmodulus) + info->hoffset;
+	return (((u64)hash * info->hmodulus) >> 32) + info->hoffset;
 }
 
 static void
Signature · 1 line
1.7.10