X-Git-Url: http://git.onelab.eu/?p=transforward.git;a=blobdiff_plain;f=transforward.c;h=5c517f5b7fe43383a19ceebd148cfa451d09e06e;hp=0e42f52d6ad97a8a4a630586af1dd2d8aad12fdd;hb=HEAD;hpb=efdca6dbb43acd22b5f3e685e39294fc5895c1aa diff --git a/transforward.c b/transforward.c index 0e42f52..5c517f5 100644 --- a/transforward.c +++ b/transforward.c @@ -8,11 +8,12 @@ #include #include #include +#include #include #include #include #include -#include +/*#include */ #include #include #include @@ -40,8 +41,9 @@ MODULE_DESCRIPTION("Transparent port forwarding for LXC."); MODULE_LICENSE("GPL"); MODULE_VERSION(VERSION_STR); +struct proc_dir_entry *proc_entry; + static int address_in_root(unsigned int haddr) { - //printk(KERN_CRIT "In address_in_root: %u",haddr); struct net_device *dev; struct net *net = &init_net; @@ -56,6 +58,7 @@ static int address_in_root(unsigned int haddr) { static int inet_bind_entry(struct socket *sock, struct sockaddr *uaddr, int addr_len) { struct sockaddr_in *addr = (struct sockaddr_in *)uaddr; unsigned int snum = addr->sin_addr.s_addr; + //printk(KERN_CRIT "Checking address %d",snum); if (address_in_root(snum)) { put_net(sock_net(sock->sk)); sock_net_set(sock->sk, get_net(&init_net)); @@ -65,6 +68,13 @@ static int inet_bind_entry(struct socket *sock, struct sockaddr *uaddr, int addr return 0; } +static struct file *do_last_probe(struct nameidata *nd, struct path *path, + const struct open_flags *op, const char *pathname) { + + + jprobe_return(); + +} static struct jprobe net_probe = { .entry = (kprobe_opcode_t *) inet_bind_entry @@ -77,9 +87,9 @@ static void __exit transforward_exit(void) printk("Transforward: Stopped transforward.\n"); } +int once_only=0; - -static int __init transforward_init(void) +static int init_probes(void) { int ret = 0; printk("Transforward: starting transforward version %s.\n", @@ -95,11 +105,38 @@ static int __init transforward_init(void) printk("register_jprobe failed, returned %u\n", ret); return -1; } - //printk("Planted jprobe at %p, handler addr %p\n", - //net_probe.kp.addr, net_probe.entry); return ret; } +/* as per http://www.tldp.org/LDP/lkmpg/2.4/html/c577.htm + the declaration of write in the file_operations struct reads: + ssize_t (*write) (struct file *, const char *, size_t, loff_t *); +*/ +ssize_t procfile_write(struct file *file, const char *buffer, size_t count, loff_t *data) { + if (!once_only) { + once_only=1; + if (init_probes()==-1) + printk(KERN_CRIT "Could not install procprotect probes. Reload module to retry."); + else + printk(KERN_CRIT "Activated transforward module"); + } + return count; +} +static const struct file_operations transforward_fops = { + .owner = THIS_MODULE, + .write = procfile_write +}; + +static int __init transforward_init(void) +{ + int ret = 0; + printk("Transforward: starting transforward version %s.\n", + VERSION_STR); + + proc_entry = proc_create("transforward", 0644, NULL, &transforward_fops); + return ret; +} + module_init(transforward_init); module_exit(transforward_exit);