Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * netfilter module to limit the number of parallel tcp |
| 3 | * connections per IP address. |
| 4 | * (c) 2000 Gerd Knorr <kraxel@bytesex.org> |
| 5 | * Nov 2002: Martin Bene <martin.bene@icomedias.com>: |
| 6 | * only ignore TIME_WAIT or gone connections |
Jan Engelhardt | ba5dc27 | 2007-11-05 20:35:56 -0800 | [diff] [blame] | 7 | * (C) CC Computer Consultants GmbH, 2007 |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 8 | * |
| 9 | * based on ... |
| 10 | * |
| 11 | * Kernel module to match connection tracking information. |
| 12 | * GPL (C) 1999 Rusty Russell (rusty@rustcorp.com.au). |
| 13 | */ |
Jan Engelhardt | 8bee4ba | 2010-03-17 16:04:40 +0100 | [diff] [blame] | 14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 15 | #include <linux/in.h> |
| 16 | #include <linux/in6.h> |
| 17 | #include <linux/ip.h> |
| 18 | #include <linux/ipv6.h> |
| 19 | #include <linux/jhash.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 21 | #include <linux/list.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/random.h> |
| 24 | #include <linux/skbuff.h> |
| 25 | #include <linux/spinlock.h> |
| 26 | #include <linux/netfilter/nf_conntrack_tcp.h> |
| 27 | #include <linux/netfilter/x_tables.h> |
| 28 | #include <linux/netfilter/xt_connlimit.h> |
| 29 | #include <net/netfilter/nf_conntrack.h> |
| 30 | #include <net/netfilter/nf_conntrack_core.h> |
| 31 | #include <net/netfilter/nf_conntrack_tuple.h> |
Patrick McHardy | 5d0aa2c | 2010-02-15 18:13:33 +0100 | [diff] [blame] | 32 | #include <net/netfilter/nf_conntrack_zones.h> |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 33 | |
| 34 | /* we will save the tuples of all connections we care about */ |
| 35 | struct xt_connlimit_conn { |
Changli Gao | 3e0d514 | 2011-03-15 13:25:42 +0100 | [diff] [blame] | 36 | struct hlist_node node; |
Changli Gao | 8183e3a | 2011-03-15 13:23:28 +0100 | [diff] [blame] | 37 | struct nf_conntrack_tuple tuple; |
| 38 | union nf_inet_addr addr; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | struct xt_connlimit_data { |
Changli Gao | 3e0d514 | 2011-03-15 13:25:42 +0100 | [diff] [blame] | 42 | struct hlist_head iphash[256]; |
| 43 | spinlock_t lock; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
Jan Engelhardt | 294188a | 2010-01-04 16:28:38 +0100 | [diff] [blame] | 46 | static u_int32_t connlimit_rnd __read_mostly; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 47 | |
Al Viro | a34c458 | 2007-07-26 17:33:19 +0100 | [diff] [blame] | 48 | static inline unsigned int connlimit_iphash(__be32 addr) |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 49 | { |
Al Viro | a34c458 | 2007-07-26 17:33:19 +0100 | [diff] [blame] | 50 | return jhash_1word((__force __u32)addr, connlimit_rnd) & 0xFF; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | static inline unsigned int |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 54 | connlimit_iphash6(const union nf_inet_addr *addr, |
| 55 | const union nf_inet_addr *mask) |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 56 | { |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 57 | union nf_inet_addr res; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 58 | unsigned int i; |
| 59 | |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 60 | for (i = 0; i < ARRAY_SIZE(addr->ip6); ++i) |
| 61 | res.ip6[i] = addr->ip6[i] & mask->ip6[i]; |
| 62 | |
Al Viro | a34c458 | 2007-07-26 17:33:19 +0100 | [diff] [blame] | 63 | return jhash2((u32 *)res.ip6, ARRAY_SIZE(res.ip6), connlimit_rnd) & 0xFF; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | static inline bool already_closed(const struct nf_conn *conn) |
| 67 | { |
Patrick McHardy | 5e8fbe2 | 2008-04-14 11:15:52 +0200 | [diff] [blame] | 68 | if (nf_ct_protonum(conn) == IPPROTO_TCP) |
Dong Wei | d2ee3f2 | 2008-06-04 09:57:51 -0700 | [diff] [blame] | 69 | return conn->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT || |
| 70 | conn->proto.tcp.state == TCP_CONNTRACK_CLOSE; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 71 | else |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | static inline unsigned int |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 76 | same_source_net(const union nf_inet_addr *addr, |
| 77 | const union nf_inet_addr *mask, |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 78 | const union nf_inet_addr *u3, u_int8_t family) |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 79 | { |
Jan Engelhardt | ee999d8 | 2008-10-08 11:35:01 +0200 | [diff] [blame] | 80 | if (family == NFPROTO_IPV4) { |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 81 | return (addr->ip & mask->ip) == (u3->ip & mask->ip); |
| 82 | } else { |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 83 | union nf_inet_addr lh, rh; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 84 | unsigned int i; |
| 85 | |
| 86 | for (i = 0; i < ARRAY_SIZE(addr->ip6); ++i) { |
| 87 | lh.ip6[i] = addr->ip6[i] & mask->ip6[i]; |
| 88 | rh.ip6[i] = u3->ip6[i] & mask->ip6[i]; |
| 89 | } |
| 90 | |
| 91 | return memcmp(&lh.ip6, &rh.ip6, sizeof(lh.ip6)) == 0; |
| 92 | } |
| 93 | } |
| 94 | |
Alexey Dobriyan | 83fc810 | 2010-01-18 08:07:50 +0100 | [diff] [blame] | 95 | static int count_them(struct net *net, |
| 96 | struct xt_connlimit_data *data, |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 97 | const struct nf_conntrack_tuple *tuple, |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 98 | const union nf_inet_addr *addr, |
| 99 | const union nf_inet_addr *mask, |
Stefan Berger | 20b7975 | 2011-02-14 16:54:33 +0100 | [diff] [blame] | 100 | u_int8_t family) |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 101 | { |
Jan Engelhardt | 3cf93c9 | 2008-04-14 09:56:05 +0200 | [diff] [blame] | 102 | const struct nf_conntrack_tuple_hash *found; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 103 | struct xt_connlimit_conn *conn; |
Changli Gao | 3e0d514 | 2011-03-15 13:25:42 +0100 | [diff] [blame] | 104 | struct hlist_node *pos, *n; |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 105 | struct nf_conn *found_ct; |
Changli Gao | 3e0d514 | 2011-03-15 13:25:42 +0100 | [diff] [blame] | 106 | struct hlist_head *hash; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 107 | bool addit = true; |
| 108 | int matches = 0; |
| 109 | |
Jan Engelhardt | 539054a | 2009-11-06 18:08:32 -0800 | [diff] [blame] | 110 | if (family == NFPROTO_IPV6) |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 111 | hash = &data->iphash[connlimit_iphash6(addr, mask)]; |
| 112 | else |
| 113 | hash = &data->iphash[connlimit_iphash(addr->ip & mask->ip)]; |
| 114 | |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 115 | rcu_read_lock(); |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 116 | |
| 117 | /* check the saved connections */ |
Changli Gao | 3e0d514 | 2011-03-15 13:25:42 +0100 | [diff] [blame] | 118 | hlist_for_each_entry_safe(conn, pos, n, hash, node) { |
Patrick McHardy | 5d0aa2c | 2010-02-15 18:13:33 +0100 | [diff] [blame] | 119 | found = nf_conntrack_find_get(net, NF_CT_DEFAULT_ZONE, |
| 120 | &conn->tuple); |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 121 | found_ct = NULL; |
| 122 | |
| 123 | if (found != NULL) |
| 124 | found_ct = nf_ct_tuplehash_to_ctrack(found); |
| 125 | |
| 126 | if (found_ct != NULL && |
| 127 | nf_ct_tuple_equal(&conn->tuple, tuple) && |
| 128 | !already_closed(found_ct)) |
| 129 | /* |
| 130 | * Just to be sure we have it only once in the list. |
| 131 | * We should not see tuples twice unless someone hooks |
| 132 | * this into a table without "-p tcp --syn". |
| 133 | */ |
| 134 | addit = false; |
| 135 | |
| 136 | if (found == NULL) { |
| 137 | /* this one is gone */ |
Changli Gao | 3e0d514 | 2011-03-15 13:25:42 +0100 | [diff] [blame] | 138 | hlist_del(&conn->node); |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 139 | kfree(conn); |
| 140 | continue; |
| 141 | } |
| 142 | |
| 143 | if (already_closed(found_ct)) { |
| 144 | /* |
| 145 | * we do not care about connections which are |
| 146 | * closed already -> ditch it |
| 147 | */ |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 148 | nf_ct_put(found_ct); |
Changli Gao | 3e0d514 | 2011-03-15 13:25:42 +0100 | [diff] [blame] | 149 | hlist_del(&conn->node); |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 150 | kfree(conn); |
| 151 | continue; |
| 152 | } |
| 153 | |
Changli Gao | 8183e3a | 2011-03-15 13:23:28 +0100 | [diff] [blame] | 154 | if (same_source_net(addr, mask, &conn->addr, family)) |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 155 | /* same source network -> be counted! */ |
| 156 | ++matches; |
Eric Dumazet | ea781f1 | 2009-03-25 21:05:46 +0100 | [diff] [blame] | 157 | nf_ct_put(found_ct); |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Patrick McHardy | 76507f6 | 2008-01-31 04:38:38 -0800 | [diff] [blame] | 160 | rcu_read_unlock(); |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 161 | |
| 162 | if (addit) { |
| 163 | /* save the new connection in our list */ |
Changli Gao | 0e23ca1 | 2011-03-15 13:24:56 +0100 | [diff] [blame] | 164 | conn = kmalloc(sizeof(*conn), GFP_ATOMIC); |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 165 | if (conn == NULL) |
| 166 | return -ENOMEM; |
| 167 | conn->tuple = *tuple; |
Changli Gao | 8183e3a | 2011-03-15 13:23:28 +0100 | [diff] [blame] | 168 | conn->addr = *addr; |
Changli Gao | 3e0d514 | 2011-03-15 13:25:42 +0100 | [diff] [blame] | 169 | hlist_add_head(&conn->node, hash); |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 170 | ++matches; |
| 171 | } |
| 172 | |
| 173 | return matches; |
| 174 | } |
| 175 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 176 | static bool |
Jan Engelhardt | 62fc805 | 2009-07-07 20:42:08 +0200 | [diff] [blame] | 177 | connlimit_mt(const struct sk_buff *skb, struct xt_action_param *par) |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 178 | { |
Alexey Dobriyan | 83fc810 | 2010-01-18 08:07:50 +0100 | [diff] [blame] | 179 | struct net *net = dev_net(par->in ? par->in : par->out); |
Jan Engelhardt | f7108a2 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 180 | const struct xt_connlimit_info *info = par->matchinfo; |
Jan Engelhardt | 22c2d8b | 2007-12-17 22:44:47 -0800 | [diff] [blame] | 181 | union nf_inet_addr addr; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 182 | struct nf_conntrack_tuple tuple; |
| 183 | const struct nf_conntrack_tuple *tuple_ptr = &tuple; |
| 184 | enum ip_conntrack_info ctinfo; |
| 185 | const struct nf_conn *ct; |
| 186 | int connections; |
| 187 | |
| 188 | ct = nf_ct_get(skb, &ctinfo); |
Changli Gao | 8183e3a | 2011-03-15 13:23:28 +0100 | [diff] [blame] | 189 | if (ct != NULL) |
| 190 | tuple_ptr = &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple; |
| 191 | else if (!nf_ct_get_tuplepr(skb, skb_network_offset(skb), |
| 192 | par->family, &tuple)) |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 193 | goto hotdrop; |
| 194 | |
Jan Engelhardt | 92f3b2b | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 195 | if (par->family == NFPROTO_IPV6) { |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 196 | const struct ipv6hdr *iph = ipv6_hdr(skb); |
Jan Engelhardt | cc4fc02 | 2011-01-18 17:32:40 +0100 | [diff] [blame] | 197 | memcpy(&addr.ip6, (info->flags & XT_CONNLIMIT_DADDR) ? |
| 198 | &iph->daddr : &iph->saddr, sizeof(addr.ip6)); |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 199 | } else { |
| 200 | const struct iphdr *iph = ip_hdr(skb); |
Jan Engelhardt | cc4fc02 | 2011-01-18 17:32:40 +0100 | [diff] [blame] | 201 | addr.ip = (info->flags & XT_CONNLIMIT_DADDR) ? |
| 202 | iph->daddr : iph->saddr; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | spin_lock_bh(&info->data->lock); |
Alexey Dobriyan | 83fc810 | 2010-01-18 08:07:50 +0100 | [diff] [blame] | 206 | connections = count_them(net, info->data, tuple_ptr, &addr, |
Stefan Berger | 20b7975 | 2011-02-14 16:54:33 +0100 | [diff] [blame] | 207 | &info->mask, par->family); |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 208 | spin_unlock_bh(&info->data->lock); |
| 209 | |
Richard Weinberger | 1cc34c3 | 2011-01-18 01:36:57 +0100 | [diff] [blame] | 210 | if (connections < 0) |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 211 | /* kmalloc failed, drop it entirely */ |
Richard Weinberger | 1cc34c3 | 2011-01-18 01:36:57 +0100 | [diff] [blame] | 212 | goto hotdrop; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 213 | |
Jan Engelhardt | cc4fc02 | 2011-01-18 17:32:40 +0100 | [diff] [blame] | 214 | return (connections > info->limit) ^ |
| 215 | !!(info->flags & XT_CONNLIMIT_INVERT); |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 216 | |
| 217 | hotdrop: |
Jan Engelhardt | b4ba261 | 2009-07-07 20:54:30 +0200 | [diff] [blame] | 218 | par->hotdrop = true; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 219 | return false; |
| 220 | } |
| 221 | |
Jan Engelhardt | b0f3845 | 2010-03-19 17:16:42 +0100 | [diff] [blame] | 222 | static int connlimit_mt_check(const struct xt_mtchk_param *par) |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 223 | { |
Jan Engelhardt | 9b4fce7 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 224 | struct xt_connlimit_info *info = par->matchinfo; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 225 | unsigned int i; |
Jan Engelhardt | 4a5a5c7 | 2010-03-19 17:32:59 +0100 | [diff] [blame] | 226 | int ret; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 227 | |
Changli Gao | 4656c4d | 2011-03-15 13:26:32 +0100 | [diff] [blame] | 228 | if (unlikely(!connlimit_rnd)) { |
| 229 | u_int32_t rand; |
| 230 | |
| 231 | do { |
| 232 | get_random_bytes(&rand, sizeof(rand)); |
| 233 | } while (!rand); |
| 234 | cmpxchg(&connlimit_rnd, 0, rand); |
Jan Engelhardt | 294188a | 2010-01-04 16:28:38 +0100 | [diff] [blame] | 235 | } |
Jan Engelhardt | 4a5a5c7 | 2010-03-19 17:32:59 +0100 | [diff] [blame] | 236 | ret = nf_ct_l3proto_try_module_get(par->family); |
| 237 | if (ret < 0) { |
Jan Engelhardt | 8bee4ba | 2010-03-17 16:04:40 +0100 | [diff] [blame] | 238 | pr_info("cannot load conntrack support for " |
| 239 | "address family %u\n", par->family); |
Jan Engelhardt | 4a5a5c7 | 2010-03-19 17:32:59 +0100 | [diff] [blame] | 240 | return ret; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /* init private data */ |
| 244 | info->data = kmalloc(sizeof(struct xt_connlimit_data), GFP_KERNEL); |
| 245 | if (info->data == NULL) { |
Jan Engelhardt | 92f3b2b | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 246 | nf_ct_l3proto_module_put(par->family); |
Jan Engelhardt | 4a5a5c7 | 2010-03-19 17:32:59 +0100 | [diff] [blame] | 247 | return -ENOMEM; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | spin_lock_init(&info->data->lock); |
| 251 | for (i = 0; i < ARRAY_SIZE(info->data->iphash); ++i) |
Changli Gao | 3e0d514 | 2011-03-15 13:25:42 +0100 | [diff] [blame] | 252 | INIT_HLIST_HEAD(&info->data->iphash[i]); |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 253 | |
Jan Engelhardt | bd414ee | 2010-03-23 16:35:56 +0100 | [diff] [blame] | 254 | return 0; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Jan Engelhardt | 6be3d85 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 257 | static void connlimit_mt_destroy(const struct xt_mtdtor_param *par) |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 258 | { |
Jan Engelhardt | 6be3d85 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 259 | const struct xt_connlimit_info *info = par->matchinfo; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 260 | struct xt_connlimit_conn *conn; |
Changli Gao | 3e0d514 | 2011-03-15 13:25:42 +0100 | [diff] [blame] | 261 | struct hlist_node *pos, *n; |
| 262 | struct hlist_head *hash = info->data->iphash; |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 263 | unsigned int i; |
| 264 | |
Jan Engelhardt | 92f3b2b | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 265 | nf_ct_l3proto_module_put(par->family); |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 266 | |
| 267 | for (i = 0; i < ARRAY_SIZE(info->data->iphash); ++i) { |
Changli Gao | 3e0d514 | 2011-03-15 13:25:42 +0100 | [diff] [blame] | 268 | hlist_for_each_entry_safe(conn, pos, n, &hash[i], node) { |
| 269 | hlist_del(&conn->node); |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 270 | kfree(conn); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | kfree(info->data); |
| 275 | } |
| 276 | |
Cong Wang | 68c07cb | 2012-05-19 04:39:01 +0000 | [diff] [blame] | 277 | static struct xt_match connlimit_mt_reg __read_mostly = { |
| 278 | .name = "connlimit", |
| 279 | .revision = 1, |
| 280 | .family = NFPROTO_UNSPEC, |
| 281 | .checkentry = connlimit_mt_check, |
| 282 | .match = connlimit_mt, |
| 283 | .matchsize = sizeof(struct xt_connlimit_info), |
| 284 | .destroy = connlimit_mt_destroy, |
| 285 | .me = THIS_MODULE, |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 286 | }; |
| 287 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 288 | static int __init connlimit_mt_init(void) |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 289 | { |
Cong Wang | 68c07cb | 2012-05-19 04:39:01 +0000 | [diff] [blame] | 290 | return xt_register_match(&connlimit_mt_reg); |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 293 | static void __exit connlimit_mt_exit(void) |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 294 | { |
Cong Wang | 68c07cb | 2012-05-19 04:39:01 +0000 | [diff] [blame] | 295 | xt_unregister_match(&connlimit_mt_reg); |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 298 | module_init(connlimit_mt_init); |
| 299 | module_exit(connlimit_mt_exit); |
Jan Engelhardt | 92f3b2b | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 300 | MODULE_AUTHOR("Jan Engelhardt <jengelh@medozas.de>"); |
Jan Engelhardt | 2ae15b6 | 2008-01-14 23:42:28 -0800 | [diff] [blame] | 301 | MODULE_DESCRIPTION("Xtables: Number of connections matching"); |
Jan Engelhardt | 370786f | 2007-07-14 20:47:26 -0700 | [diff] [blame] | 302 | MODULE_LICENSE("GPL"); |
| 303 | MODULE_ALIAS("ipt_connlimit"); |
| 304 | MODULE_ALIAS("ip6t_connlimit"); |