From fca59bea770346cf1c1f9b0e00cb48a61b44a8f3 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 25 Oct 2015 21:00:20 +0100 Subject: import of old now defunct presentation slides svn repo --- 2003/netfilter-programming-ols2003/nf_workshop.c | 57 ++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 2003/netfilter-programming-ols2003/nf_workshop.c (limited to '2003/netfilter-programming-ols2003/nf_workshop.c') diff --git a/2003/netfilter-programming-ols2003/nf_workshop.c b/2003/netfilter-programming-ols2003/nf_workshop.c new file mode 100644 index 0000000..9592264 --- /dev/null +++ b/2003/netfilter-programming-ols2003/nf_workshop.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +#include +#include + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Harald Welte "); +MODULE_DESCRIPTION("OLS2003 workshop module"); + +static unsigned int +workshop_fn(unsigned int hooknum, + struct sk_buff **pskb, + const struct net_device *in, + const struct net_device *out, + int (*okfn)(struct sk_buff *)) +{ + struct iphdr *iph = (*pskb)->nh.iph; + /* do whatever we want to do */ + + printk(KERN_NOTICE "packet from %u.%u.%u.%u received\n", + NIPQUAD(iph->saddr)); + + return NF_ACCEPT; +} + +static struct nf_hook_ops workshop_ops = { + .list = { .prev = NULL, .next = NULL }, + .hook = &workshop_fn, + .pf = PF_INET, + .hooknum = NF_IP_PRE_ROUTING, + .priority = NF_IP_PRI_LAST-1 +}; + +static int __init init(void) +{ + int ret = 0; + + ret = nf_register_hook(&workshop_ops); + if (ret < 0) { + printk(KERN_ERR "something went wrong while registering\n"); + return ret; + } + + printk(KERN_DEBUG "workshop netfilter module successfully loaded\n"); + return ret; +} + +static void __exit fini(void) +{ + nf_unregister_hook(&workshop_ops); +} + +module_init(init); +module_exit(fini); -- cgit v1.2.3