All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Mader <thezema@gmail.com>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@lists.netfilter.org
Subject: Re: remove connections notification by conntrack?
Date: Fri, 22 Sep 2006 15:19:46 +0200	[thread overview]
Message-ID: <200609221519.52127.thezema@gmail.com> (raw)
In-Reply-To: <4513DE12.4020305@netfilter.org>

[-- Attachment #1: Type: text/plain, Size: 2729 bytes --]

> Could you post the code?

struct conn_id {
	int id;
	struct list_head elem;
	struct list_head tstamps;
};

struct conn_stamp {
	double stamp;
	struct list_head elem;
};

static LIST_HEAD(list);

void destroyed_connect(struct ip_conntrack *conntrack) {
	printk("destroy id %u\n", conntrack->id);
}

static int match(const struct sk_buff *skb,
                 const struct net_device *in,
                 const struct net_device *out,
		 const struct xt_match *match,
                 const void *matchinfo,
                 int offset,
		 unsigned int protoff,
                 int *hotdrop)
{
.....
	proto = ip_conntrack_proto_find_get(skb->nh.iph->protocol);


	if (ip_ct_get_tuple(skb->nh.iph, skb, skb->nh.iph->ihl*4, &tuple,proto)) {

		h = ip_conntrack_find_get(&tuple, NULL);
		if (h) {
			//printk("dstp: %u\n", ntohs(h->tuple.dst.u.udp.port) );
			ipct = tuplehash_to_ctrack(h);
			if (ipct) {
				int found_id = 0;
				struct conn_stamp *new_stamp;
				connection_id = ipct->id;

				if(!list_empty(&list)) {
					struct conn_id *p;
					
					list_for_each_entry(p, &list, elem) {
						if (connection_id == p->id) {
							found_id = 1;
							new_stamp = (struct conn_stamp*)kmalloc(sizeof(struct conn_stamp), 
GFP_KERNEL);
							if(!new_stamp) {
								printk("new_stamp not allocated!\n");
								return 1;
							}
							
							new_stamp->stamp = sec;
							list_add_tail(&new_stamp->elem, &p->tstamps);
							printk("new tstamp added to already existing id %d\n", p->id);
							break;
						}
					}
				}
				if(!found_id) {
					struct conn_id* new_id = (struct conn_id*)kmalloc(sizeof(struct conn_id), 
GFP_KERNEL);
					if(!new_id) {
						printk("new_id not allocated!\n");
						return 1;
					}
					
					new_id->id = connection_id;
					INIT_LIST_HEAD(&new_id->elem);
					list_add_tail(&new_id->elem, &list);
					
					new_stamp = (struct conn_stamp*)kmalloc(sizeof(struct conn_stamp), 
GFP_KERNEL);
					if(!new_stamp) {
						printk("new_stamp not allocated!\n");
						return 1;
					}
							
					new_stamp->stamp = sec;
					INIT_LIST_HEAD(&new_id->tstamps);
					list_add_tail(&new_stamp->elem, &new_id->tstamps);
					printk("new tstamp added to new created id %d\n", new_id->id);
				}
			}
		}
	}
.....
   return 1;
}

int notify(struct notifier_block *nb, unsigned long ul, void *v) {
	printk("We have been notified!\n");	
	
	return 0;
}

struct notifier_block nb = { notify, &nb, 1 }; 


static int __init init(void)
{
	need_conntrack();
	ip_conntrack_register_notifier(&nb);
	ip_conntrack_destroyed = destroyed_connect;

	return ipt_register_match(&ipaddr_match);
}

[-- Attachment #2: Type: application/pgp-signature, Size: 827 bytes --]

  reply	other threads:[~2006-09-22 13:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-22 11:59 remove connections notification by conntrack? Thomas Mader
2006-09-22 12:58 ` Pablo Neira Ayuso
2006-09-22 13:19   ` Thomas Mader [this message]
2006-09-22 15:00     ` Pablo Neira Ayuso
2006-09-23  9:23       ` Thomas Mader
2006-09-24  3:10         ` Pablo Neira Ayuso
2006-09-24  9:51           ` Thomas Mader
2006-09-24 15:34             ` Pablo Neira Ayuso
2006-10-15 13:01               ` Thomas Mader
2006-10-15 16:11                 ` Pablo Neira Ayuso
2006-10-15 17:03                   ` Thomas Mader
2006-09-25 17:12         ` Alan Ezust

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=200609221519.52127.thezema@gmail.com \
    --to=thezema@gmail.com \
    --cc=netfilter-devel@lists.netfilter.org \
    --cc=pablo@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.