#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>
}
}
-/* 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;
}
}
};
+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);
/* 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)