From: Pablo Neira <pablo@eurodev.net>
To: Harald Welte <laforge@netfilter.org>,
netfilter-devel@lists.netfilter.org
Subject: Re: patch for conntrack expectations
Date: Sat, 28 Feb 2004 12:17:52 +0100 [thread overview]
Message-ID: <404078E0.3030902@eurodev.net> (raw)
In-Reply-To: <20040224094014.GV13386@sunbeam.de.gnumonks.org>
[-- Attachment #1: Type: text/plain, Size: 333 bytes --]
Hi Harald and list,
I modified the handling of old expectations in the expect_related
function, some clean ups. Please see line 64 of this patch.
I merged this change to my lastest patch since I think that it's related
stuff. anyway if you want me to keep this different patch, i won't have
any problem to do it.
cheers,
Pablo
[-- Attachment #2: expect.patch --]
[-- Type: text/plain, Size: 5507 bytes --]
--- linux-2.6.3-old/net/ipv4/netfilter/ip_conntrack_core.c 2004-02-22 13:29:30.000000000 +0100
+++ linux-2.6.3/net/ipv4/netfilter/ip_conntrack_core.c 2004-02-28 12:10:50.000000000 +0100
@@ -917,11 +917,53 @@
WRITE_UNLOCK(&ip_conntrack_lock);
}
+int
+ip_conntrack_expect_alloc(struct ip_conntrack_expect **new)
+{
+ *new = (struct ip_conntrack_expect *)
+ kmalloc(sizeof(struct ip_conntrack_expect), GFP_ATOMIC);
+ if (!*new) {
+ DEBUGP("expect_related: OOM allocating expect\n");
+ return -ENOMEM;
+ }
+
+ /* is this important? */
+ memset(*new, 0, sizeof(struct ip_conntrack_expect));
+
+ return 1;
+}
+
+void
+ip_conntrack_expect_insert(struct ip_conntrack_expect *new,
+ struct ip_conntrack *related_to)
+{
+ DEBUGP("new expectation %p of conntrack %p\n", new, related_to);
+ new->expectant = related_to;
+ new->sibling = NULL;
+ atomic_set(&new->use, 1);
+
+ /* add to expected list for this connection */
+ list_add(&new->expected_list, &related_to->sibling_list);
+ /* add to global list of expectations */
+
+ list_prepend(&ip_conntrack_expect_list, &new->list);
+ /* add and start timer if required */
+ if (related_to->helper->timeout) {
+ init_timer(&new->timeout);
+ new->timeout.data = (unsigned long)new;
+ new->timeout.function = expectation_timed_out;
+ new->timeout.expires = jiffies +
+ related_to->helper->timeout * HZ;
+ add_timer(&new->timeout);
+ }
+ related_to->expecting++;
+}
+
/* Add a related connection. */
-int ip_conntrack_expect_related(struct ip_conntrack *related_to,
- struct ip_conntrack_expect *expect)
+int ip_conntrack_expect_related(struct ip_conntrack_expect *expect,
+ struct ip_conntrack *related_to)
{
- struct ip_conntrack_expect *old, *new;
+ struct ip_conntrack_expect *old;
int ret = 0;
WRITE_LOCK(&ip_conntrack_lock);
@@ -943,7 +985,7 @@
if (related_to->helper->timeout) {
if (!del_timer(&old->timeout)) {
/* expectation is dying. Fall through */
- old = NULL;
+ goto out;
} else {
old->timeout.expires = jiffies +
related_to->helper->timeout * HZ;
@@ -951,10 +993,10 @@
}
}
- if (old) {
- WRITE_UNLOCK(&ip_conntrack_lock);
- return -EEXIST;
- }
+ WRITE_UNLOCK(&ip_conntrack_lock);
+ kfree(expect);
+ return -EEXIST;
+
} else if (related_to->helper->max_expected &&
related_to->expecting >= related_to->helper->max_expected) {
struct list_head *cur_item;
@@ -971,6 +1013,7 @@
related_to->helper->name,
NIPQUAD(related_to->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip),
NIPQUAD(related_to->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip));
+ kfree(expect);
return -EPERM;
}
DEBUGP("ip_conntrack: max number of expected "
@@ -1010,37 +1053,12 @@
&expect->mask)) {
WRITE_UNLOCK(&ip_conntrack_lock);
DEBUGP("expect_related: busy!\n");
+
+ kfree(expect);
return -EBUSY;
}
-
- new = (struct ip_conntrack_expect *)
- kmalloc(sizeof(struct ip_conntrack_expect), GFP_ATOMIC);
- if (!new) {
- WRITE_UNLOCK(&ip_conntrack_lock);
- DEBUGP("expect_relaed: OOM allocating expect\n");
- return -ENOMEM;
- }
-
- DEBUGP("new expectation %p of conntrack %p\n", new, related_to);
- memcpy(new, expect, sizeof(*expect));
- new->expectant = related_to;
- new->sibling = NULL;
- atomic_set(&new->use, 1);
-
- /* add to expected list for this connection */
- list_add(&new->expected_list, &related_to->sibling_list);
- /* add to global list of expectations */
- list_prepend(&ip_conntrack_expect_list, &new->list);
- /* add and start timer if required */
- if (related_to->helper->timeout) {
- init_timer(&new->timeout);
- new->timeout.data = (unsigned long)new;
- new->timeout.function = expectation_timed_out;
- new->timeout.expires = jiffies +
- related_to->helper->timeout * HZ;
- add_timer(&new->timeout);
- }
- related_to->expecting++;
+
+out: ip_conntrack_expect_insert(expect, related_to);
WRITE_UNLOCK(&ip_conntrack_lock);
--- linux-2.6.3-old/net/ipv4/netfilter/ip_conntrack_standalone.c 2004-02-18 04:57:46.000000000 +0100
+++ linux-2.6.3/net/ipv4/netfilter/ip_conntrack_standalone.c 2004-02-25 15:16:53.000000000 +0100
@@ -497,6 +497,7 @@
EXPORT_SYMBOL(ip_ct_find_proto);
EXPORT_SYMBOL(__ip_ct_find_proto);
EXPORT_SYMBOL(ip_ct_find_helper);
+EXPORT_SYMBOL(ip_conntrack_expect_alloc);
EXPORT_SYMBOL(ip_conntrack_expect_related);
EXPORT_SYMBOL(ip_conntrack_change_expect);
EXPORT_SYMBOL(ip_conntrack_unexpect_related);
--- linux-2.6.3-old/include/linux/netfilter_ipv4/ip_conntrack_helper.h 2004-02-18 04:57:16.000000000 +0100
+++ linux-2.6.3/include/linux/netfilter_ipv4/ip_conntrack_helper.h 2004-02-25 15:38:27.000000000 +0100
@@ -35,9 +35,13 @@
extern struct ip_conntrack_helper *ip_ct_find_helper(const struct ip_conntrack_tuple *tuple);
+
+/* Allocate space for an expectation: this is mandatory before calling
+ ip_conntrack_expect_related. */
+extern int ip_conntrack_expect_alloc(struct ip_conntrack_expect **new);
/* Add an expected connection: can have more than one per connection */
-extern int ip_conntrack_expect_related(struct ip_conntrack *related_to,
- struct ip_conntrack_expect *exp);
+extern int ip_conntrack_expect_related(struct ip_conntrack_expect *exp,
+ struct ip_conntrack *related_to);
extern int ip_conntrack_change_expect(struct ip_conntrack_expect *expect,
struct ip_conntrack_tuple *newtuple);
extern void ip_conntrack_unexpect_related(struct ip_conntrack_expect *exp);
next prev parent reply other threads:[~2004-02-28 11:17 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <403014C5.8080102@eurodev.net>
2004-02-17 21:32 ` patch for conntrack expectations Harald Welte
2004-02-18 5:15 ` Pablo Neira
2004-02-18 17:25 ` Harald Welte
2004-02-18 17:37 ` Pablo Neira
2004-02-22 13:40 ` Pablo Neira
2004-02-24 9:40 ` Harald Welte
2004-02-24 9:54 ` Patrick McHardy
2004-02-24 10:24 ` Harald Welte
2004-02-24 16:32 ` Patrick McHardy
2004-02-25 16:45 ` Pablo Neira
2004-02-25 17:27 ` Patrick McHardy
2004-02-25 17:59 ` Patrick McHardy
2004-03-03 23:23 ` Patrick McHardy
2004-03-03 23:38 ` Pablo Neira
2004-03-03 23:52 ` Patrick McHardy
2004-03-03 23:50 ` Patrick McHardy
2004-03-04 0:12 ` Pablo Neira
2004-03-04 0:10 ` Pablo Neira
2004-03-06 0:15 ` Pablo Neira
2004-03-06 1:07 ` Patrick McHardy
2004-03-06 1:24 ` Pablo Neira
2004-03-06 1:37 ` Patrick McHardy
2004-02-25 16:29 ` Pablo Neira
2004-02-28 11:17 ` Pablo Neira [this message]
2004-03-09 17:15 ` Pablo Neira
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=404078E0.3030902@eurodev.net \
--to=pablo@eurodev.net \
--cc=laforge@netfilter.org \
--cc=netfilter-devel@lists.netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.