eline saglik erkan abi. ben de detayli bir google taramasindan sonra netfiltere modul ekleyerek ip connection limit yapilabilmesini saglayan bir modul buldum:
------------------ cut here ----------------------
diff -urN netfilter-20001129/userspace/extensions/.iplimit-test netfilter/userspace/extensions/.iplimit-test
--- netfilter-20001129/userspace/extensions/.iplimit-test Thu Jan 1 01:00:00 1970
+++ netfilter/userspace/extensions/.iplimit-test Wed Nov 29 15:48:49 2000
@@ -0,0 +1,2 @@
+#! /bin/sh
+[ -f $KERNEL_DIR/include/linux/netfilter_ipv4/ipt_iplimit.h ] && echo iplimit
diff -urN netfilter-20001129/userspace/extensions/libipt_iplimit.c netfilter/userspace/extensions/libipt_iplimit.c
--- netfilter-20001129/userspace/extensions/libipt_iplimit.c Thu Jan 1 01:00:00 1970
+++ netfilter/userspace/extensions/libipt_iplimit.c Wed Nov 29 14:04:19 2000
@@ -0,0 +1,133 @@
+/* Shared library add-on to iptables to add state tracking support. */
+#include <stdio.h>
+#include <netdb.h>
+#include <string.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <iptables.h>
+#include <linux/netfilter_ipv4/ip_conntrack.h>
+#include <linux/netfilter_ipv4/ipt_iplimit.h>
+
+/* Function which prints out usage message. */
+static void
+help(void)
+{
+ printf(
+"iplimit v%s options:\n"
+"[!] --iplimit-above n match if the number of existing tcp connections is (not) above n\n"
+" --iplimit-mask n group hosts using mask\n"
+"\n", NETFILTER_VERSION);
+}
+
+static struct option opts[] = {
+ { "iplimit-above", 1, 0, '1' },
+ { "iplimit-mask", 1, 0, '2' },
+ {0}
+};
+
+/* Initialize the match. */
+static void
+init(struct ipt_entry_match *m, unsigned int *nfcache)
+{
+ /* Can't cache this */
+ *nfcache |= NFC_UNKNOWN;
+}
+
+/* Function which parses command options; returns true if it
+ ate an option */
+static int
+parse(int c, char **argv, int invert, unsigned int *flags,
+ const struct ipt_entry *entry,
+ unsigned int *nfcache,
+ struct ipt_entry_match **match)
+{
+ struct ipt_iplimit_info *info = (struct ipt_iplimit_info*)(*match)->data;
+
+ if (0 == (*flags & 2)) {
+ /* set default mask unless we've already seen a mask option */
+ info->mask = htonl(0xFFFFFFFF);
+ }
+
+ switch (c) {
+ case '1':
+ if (check_inverse(optarg, &invert))
+ optind++;
+ info->limit = atoi(argv[optind-1]);
+ info->inverse = invert;
+ *flags |= 1;
+ break;
+
+ case '2':
+ info->mask = htonl(0xFFFFFFFF << (32 - atoi(argv[optind-1])));
+ *flags |= 2;
+ break;
+
+ default:
+ return 0;
+ }
+
+ return 1;
+}
+
+/* Final check */
+static void final_check(unsigned int flags)
+{
+ if (!flags & 1)
+ exit_error(PARAMETER_PROBLEM, "You must specify `--iplimit-above'");
+}
+
+static int
+count_bits(u_int32_t mask)
+{
+ int i, bits;
+
+ for (bits = 0, i = 31; i >= 0; i--) {
+ if (mask & htonl((u_int32_t)1 << i)) {
+ bits++;
+ continue;
+ }
+ break;
+ }
+ return bits;
+}
+
+/* Prints out the matchinfo. */
+static void
+print(const struct ipt_ip *ip,
+ const struct ipt_entry_match *match,
+ int numeric)
+{
+ struct ipt_iplimit_info *info = (struct ipt_iplimit_info*)match->data;
+
+ printf("#conn/%d %s %d", count_bits(info->mask),
+ info->inverse ? "<" : ">", info->limit);
+}
+
+/* Saves the matchinfo in parsable form to stdout. */
+static void save(const struct ipt_ip *ip, const struct ipt_entry_match *match)
+{
+ struct ipt_iplimit_info *info = (struct ipt_iplimit_info*)match->data;
+
+ printf("%s--iplimit-above %d",info->inverse ? "! " : "",info->limit);
+ printf(" --iplimit-mask %d",count_bits(info->mask));
+}
+
+struct iptables_match iplimit
+= { NULL,
+ "iplimit",
+ NETFILTER_VERSION,
+ IPT_ALIGN(sizeof(struct ipt_iplimit_info)),
+ IPT_ALIGN(sizeof(struct ipt_iplimit_info)),
+ &help,
+ &init,
+ &parse,
+ &final_check,
+ &print,
+ &save,
+ opts
+};
+
+void _init(void)
+{
+ register_match(&iplimit);
+}
diff -urN netfilter-20001129/userspace/patch-o-matic/iplimit.patch netfilter/userspace/patch-o-matic/iplimit.patch
--- netfilter-20001129/userspace/patch-o-matic/iplimit.patch Thu Jan 1 01:00:00 1970
+++ netfilter/userspace/patch-o-matic/iplimit.patch Wed Nov 29 15:57:23 2000
@@ -0,0 +1,256 @@
+diff -urN -x *~ -x [Cc]onfig.* -x Makefile vanilla-2.4.0-test8/include/linux/netfilter_ipv4/ipt_iplimit.h linux-2.4.0-test8/include/linux/netfilter_ipv4/ipt_iplimit.h
+--- vanilla-2.4.0-test8/include/linux/netfilter_ipv4/ipt_iplimit.h Thu Jan 1 01:00:00 1970
++++ linux-2.4.0-test8/include/linux/netfilter_ipv4/ipt_iplimit.h Wed Nov 29 09:57:33 2000
+@@ -0,0 +1,12 @@
++#ifndef _IPT_IPLIMIT_H
++#define _IPT_IPLIMIT_H
++
++struct ipt_iplimit_data;
++
++struct ipt_iplimit_info {
++ int limit;
++ int inverse;
++ u_int32_t mask;
++ struct ipt_iplimit_data *data;
++};
++#endif /* _IPT_IPLIMIT_H */
+diff -urN -x *~ -x [Cc]onfig.* -x Makefile vanilla-2.4.0-test8/net/ipv4/netfilter/ip_conntrack_standalone.c linux-2.4.0-test8/net/ipv4/netfilter/ip_conntrack_standalone.c
+--- vanilla-2.4.0-test8/net/ipv4/netfilter/ip_conntrack_standalone.c Thu Aug 10 21:35:15 2000
++++ linux-2.4.0-test8/net/ipv4/netfilter/ip_conntrack_standalone.c Mon Nov 27 15:41:33 2000
+@@ -343,5 +343,6 @@
+ EXPORT_SYMBOL(ip_ct_selective_cleanup);
+ EXPORT_SYMBOL(ip_ct_refresh);
+ EXPORT_SYMBOL(ip_conntrack_expect_related);
++EXPORT_SYMBOL(ip_conntrack_find_get);
+ EXPORT_SYMBOL(ip_conntrack_tuple_taken);
+ EXPORT_SYMBOL(ip_ct_gather_frags);
+diff -urN -x *~ -x [Cc]onfig.* -x Makefile vanilla-2.4.0-test8/net/ipv4/netfilter/ipt_iplimit.c linux-2.4.0-test8/net/ipv4/netfilter/ipt_iplimit.c
+--- vanilla-2.4.0-test8/net/ipv4/netfilter/ipt_iplimit.c Thu Jan 1 01:00:00 1970
++++ linux-2.4.0-test8/net/ipv4/netfilter/ipt_iplimit.c Wed Nov 29 15:37:40 2000
+@@ -0,0 +1,226 @@
++/*
++ * netfilter module to limit the number of parallel tcp
++ * connections per IP address.
++ * (c) 2000 Gerd Knorr <kraxel@bytesex.org>
++ *
++ * based on ...
++ *
++ * Kernel module to match connection tracking information.
++ * GPL (C) 1999 Rusty Russell (rusty@rustcorp.com.au).
++ */
++#include <linux/module.h>
++#include <linux/skbuff.h>
++#include <linux/list.h>
++#include <linux/netfilter_ipv4/ip_conntrack.h>
++#include <linux/netfilter_ipv4/ip_conntrack_core.h>
++#include <linux/netfilter_ipv4/ip_conntrack_tcp.h>
++#include <linux/netfilter_ipv4/ip_tables.h>
++#include <linux/netfilter_ipv4/ipt_iplimit.h>
++
++#define DEBUG 0
++
++/* we'll save the tuples of all connections we care about */
++struct ipt_iplimit_conn
++{
++ struct list_head list;
++ struct ip_conntrack_tuple tuple;
++};
++
++struct ipt_iplimit_data {
++ spinlock_t lock;
++ struct list_head iphash[256];
++};
++
++static int ipt_iphash(u_int32_t addr)
++{
++ int hash;
++
++ hash = addr & 0xff;
++ hash ^= (addr >> 8) & 0xff;
++ hash ^= (addr >> 16) & 0xff;
++ hash ^= (addr >> 24) & 0xff;
++ return hash;
++}
++
++static int count_them(struct ipt_iplimit_data *data,
++ u_int32_t addr, u_int32_t mask,
++ struct ip_conntrack *ct)
++{
++#if DEBUG
++ const static char *tcp[] = { "none", "established", "syn_sent", "syn_recv",
++ "fin_wait", "time_wait", "close", "close_wait",
++ "last_ack", "listen" };
++#endif
++ int addit = 1, matches = 0;
++ struct ip_conntrack_tuple tuple;
++ struct ip_conntrack_tuple_hash *found;
++ struct ipt_iplimit_conn *conn;
++ struct list_head *hash,*lh;
++
++ spin_lock(&data->lock);
++ tuple = ct->tuplehash[0].tuple;
++ hash = &data->iphash[ipt_iphash(addr & mask)];
++
++ /* check the saved connections */
++ for (lh = hash->next; lh != hash; lh = lh->next) {
++ conn = list_entry(lh,struct ipt_iplimit_conn,list);
++ if (0 == memcmp(&conn->tuple,&tuple,sizeof(tuple))) {
++ /* Just to be sure we have it only once in the list.
++ We should'nt see tuples twice unless someone hooks this
++ into a table without "-p tcp --syn" */
++ addit = 0;
++ }
++ found = ip_conntrack_find_get(&conn->tuple,ct);
++#if DEBUG
++ printk("ipt_iplimit [%d]: src=%u.%u.%u.%u:%d dst=%u.%u.%u.%u:%d %s\n",
++ ipt_iphash(addr & mask),
++ NIPQUAD(conn->tuple.src.ip), ntohs(conn->tuple.src.u.tcp.port),
++ NIPQUAD(conn->tuple.dst.ip), ntohs(conn->tuple.dst.u.tcp.port),
++ (NULL != found) ? tcp[found->ctrack->proto.tcp.state] : "gone");
++#endif
++ if (NULL == found) {
++ /* this one is gone */
++ lh = lh->prev;
++ list_del(lh->next);
++ kfree(conn);
++ continue;
++ }
++ if (found->ctrack->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT) {
++ /* we don't care about connections which are
++ closed already -> ditch it */
++ lh = lh->prev;
++ list_del(lh->next);
++ kfree(conn);
++ nf_conntrack_put(&found->ctrack->infos[0]);
++ continue;
++ }
++ if ((addr & mask) == (conn->tuple.src.ip & mask)) {
++ /* same source IP address -> be counted! */
++