X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=transforward.c;h=5c517f5b7fe43383a19ceebd148cfa451d09e06e;hb=26e4e318717351e7c0e0cfd76c413dc58cc2837d;hp=13e615648dfe12c8c8bf2bad8c119fb2a659481e;hpb=54faa59da020aac2d455e02a3b353a47ebeec142;p=transforward.git diff --git a/transforward.c b/transforward.c index 13e6156..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)); @@ -84,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", @@ -102,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);