From 4eb97c7a01046c705841d36785d394164f212615 Mon Sep 17 00:00:00 2001 From: Josh Hunt Date: Sun, 8 Jul 2012 11:11:23 -0700 Subject: [PATCH] TARPIT: make tarpit code generic 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 --- extensions/xt_TARPIT.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/extensions/xt_TARPIT.c b/extensions/xt_TARPIT.c index 2499af2..3b497aa 100644 --- a/extensions/xt_TARPIT.c +++ b/extensions/xt_TARPIT.c @@ -142,6 +142,26 @@ static void xttarpit_reset(struct tcphdr *tcph, const struct tcphdr *oth) tcph->ack_seq = oth->seq; } +static bool tarpit_generic(struct tcphdr *tcph, const struct tcphdr *oth, + uint16_t payload, unsigned int mode) +{ + switch(mode) { + case XTTARPIT_TARPIT: + if (!xttarpit_tarpit(tcph, oth)) + return false; + break; + case XTTARPIT_HONEYPOT: + if (!xttarpit_honeypot(tcph, oth, payload)) + return false; + break; + case XTTARPIT_RESET: + xttarpit_reset(tcph, oth); + break; + } + + return true; +} + static void tarpit_tcp(struct sk_buff *oldskb, unsigned int hook, unsigned int mode) { @@ -208,15 +228,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(tcph, oth)) - return; - } else if (mode == XTTARPIT_HONEYPOT) { - if (!xttarpit_honeypot(tcph, oth, payload)) - return; - } else if (mode == XTTARPIT_RESET) { - xttarpit_reset(tcph, oth); - } + if (!tarpit_generic(tcph, oth, payload, mode)) + return; /* Adjust TCP checksum */ tcph->check = 0;