]> git.ipfire.org Git - people/ms/linux.git/commitdiff
layer7: Adapt proc interface to kernel 3.10.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 30 Mar 2014 15:39:52 +0000 (17:39 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 30 Mar 2014 15:39:52 +0000 (17:39 +0200)
net/netfilter/xt_layer7.c

index da61d485f0863fe953855500e3adf2a4b2bf7bf9..72e903f286f4601cacbbe57e9d5109b4a7e24abc 100644 (file)
@@ -21,6 +21,7 @@
 #include <net/ip.h>
 #include <net/tcp.h>
 #include <linux/module.h>
+#include <linux/seq_file.h>
 #include <linux/skbuff.h>
 #include <linux/netfilter.h>
 #include <net/netfilter/nf_conntrack.h>
@@ -356,54 +357,34 @@ static int my_atoi(const char *s)
        }
 }
 
-/* write out num_packets to userland. */
-static int layer7_read_proc(char* page, char ** start, off_t off, int count,
-                            int* eof, void * data)
-{
-       if(num_packets > 99 && net_ratelimit())
-               printk(KERN_ERR "layer7: NOT REACHED. num_packets too big\n");
-
-       page[0] = num_packets/10 + '0';
-       page[1] = num_packets%10 + '0';
-       page[2] = '\n';
-       page[3] = '\0';
+static int layer7_numpackets_proc_show(struct seq_file *s, void *p) {
+       seq_printf(s, "%d\n", num_packets);
 
-       *eof=1;
+       return 0;
+}
 
-       return 3;
+static int layer7_numpackets_proc_open(struct inode *inode, struct file *file) {
+       return single_open(file, layer7_numpackets_proc_show, NULL);
 }
 
 /* Read in num_packets from userland */
-static int layer7_write_proc(struct file* file, const char* buffer,
-                             unsigned long count, void *data)
-{
-       char * foo = kmalloc(count, GFP_ATOMIC);
-
-       if(!foo){
-               if (net_ratelimit())
-                       printk(KERN_ERR "layer7: out of memory, bailing. "
-                                       "num_packets unchanged.\n");
-               return count;
-       }
+static ssize_t layer7_numpackets_write_proc(struct file* file, const char __user *buffer,
+               size_t count, loff_t *data) {
+       char value[1024];
+       int new_num_packets;
 
-       if(copy_from_user(foo, buffer, count)) {
+       if (copy_from_user(&value, buffer, sizeof(value)))
                return -EFAULT;
-       }
 
+       new_num_packets = my_atoi(value);
 
-       num_packets = my_atoi(foo);
-       kfree (foo);
-
-       /* This has an arbitrary limit to make the math easier. I'm lazy.
-       But anyway, 99 is a LOT! If you want more, you're doing it wrong! */
-       if(num_packets > 99) {
-               printk(KERN_WARNING "layer7: num_packets can't be > 99.\n");
-               num_packets = 99;
-       } else if(num_packets < 1) {
-               printk(KERN_WARNING "layer7: num_packets can't be < 1.\n");
-               num_packets = 1;
+       if ((new_num_packets < 1) || (new_num_packets > 99)) {
+               printk(KERN_WARNING "layer7: numpackets must be between 1 and 99\n");
+               return -EFAULT;
        }
 
+       num_packets = new_num_packets;
+
        return count;
 }
 
@@ -601,6 +582,15 @@ static struct xt_match xt_layer7_match[] __read_mostly = {
 }
 };
 
+static const struct file_operations layer7_numpackets_proc_fops = {
+       .owner   = THIS_MODULE,
+       .open    = layer7_numpackets_proc_open,
+       .read    = seq_read,
+       .llseek  = seq_lseek,
+       .release = single_release,
+       .write   = layer7_numpackets_write_proc,
+};
+
 static void layer7_cleanup_proc(void)
 {
        remove_proc_entry("layer7_numpackets", init_net.proc_net);
@@ -609,10 +599,8 @@ static void layer7_cleanup_proc(void)
 /* register the proc file */
 static void layer7_init_proc(void)
 {
-       struct proc_dir_entry* entry;
-       entry = create_proc_entry("layer7_numpackets", 0644, init_net.proc_net);
-       entry->read_proc = layer7_read_proc;
-       entry->write_proc = layer7_write_proc;
+       proc_create_data("layer7_numpackets", 0644,
+               init_net.proc_net, &layer7_numpackets_proc_fops, NULL);
 }
 
 static int __init xt_layer7_init(void)