Patchwork [v2,4/6] netfilter: tarpit: Make tarpit code generic

login
register
mail settings
Submitter Josh Hunt
Date July 8, 2012, 6:11 p.m.
Message ID <1341771085-5771-5-git-send-email-johunt@akamai.com>
Download mbox | patch
Permalink /patch/169657/
State Superseded
Headers show

Comments

Josh Hunt - July 8, 2012, 6:11 p.m.
Creates a generic function to perform the tcp header manipulation in. Done
in preparation for IPv6 support. This allows us to share code between v4 and
v6 processing.

Signed-off-by: Josh Hunt <johunt@akamai.com>
---
 extensions/xt_TARPIT.c |   33 +++++++++++++++++++++++----------
 1 files changed, 23 insertions(+), 10 deletions(-)

Patch

diff --git a/extensions/xt_TARPIT.c b/extensions/xt_TARPIT.c
index 5d8af70..528c012 100644
--- a/extensions/xt_TARPIT.c
+++ b/extensions/xt_TARPIT.c
@@ -146,6 +146,27 @@  static bool xttarpit_reset(struct tcphdr *oth, struct tcphdr *tcph)
 	return true;
 }
 
+static bool tarpit_generic(struct tcphdr *oth, struct tcphdr *tcph, uint16_t payload,
+	unsigned int mode)
+{
+	switch(mode) {
+	case XTTARPIT_TARPIT:
+		if (!xttarpit_tarpit(oth, tcph))
+			return false;
+		break;
+	case XTTARPIT_HONEYPOT:
+		if (!xttarpit_honeypot(oth, tcph, payload))
+			return false;
+		break;
+	case XTTARPIT_RESET:
+		if (!xttarpit_reset(oth, tcph))
+			return false;
+		break;
+	}
+
+	return true;
+}
+
 static void tarpit_tcp(struct sk_buff *oldskb, unsigned int hook,
     unsigned int mode)
 {
@@ -211,16 +232,8 @@  static void tarpit_tcp(struct sk_buff *oldskb, unsigned int hook,
 	/* Reset flags */
 	((u_int8_t *)tcph)[13] = 0;
 
-	if (mode == XTTARPIT_TARPIT) {
-		if (!xttarpit_tarpit(oth, tcph))
-			return;
-	} else if (mode == XTTARPIT_HONEYPOT) {
-		if (!xttarpit_honeypot(oth, tcph, payload))
-			return;
-	} else if (mode == XTTARPIT_RESET) {
-		if (!xttarpit_reset(oth, tcph))
-			return;
-	}
+	if (!tarpit_generic(oth, tcph, payload, mode))
+		return;
 
 	/* Adjust TCP checksum */
 	tcph->check = 0;