95 lines
1.9 KiB
C
Executable File
95 lines
1.9 KiB
C
Executable File
/* huangxiaolu@2014-03-19 */
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/init.h>
|
|
#include <linux/list.h>
|
|
#include <linux/device.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/string.h>
|
|
//#include <linux/sysdev.h>
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/version.h>
|
|
#include <linux/skbuff.h>
|
|
|
|
/*
|
|
* skb debug proc entry
|
|
*/
|
|
struct proc_dir_entry *tplink_proc;
|
|
EXPORT_SYMBOL(tplink_proc);
|
|
|
|
unsigned int skb_debug_enable = 0;
|
|
EXPORT_SYMBOL(skb_debug_enable);
|
|
|
|
int skb_debug_proc_read(char *page, char **start, off_t off,
|
|
int count, int *eof, void *data)
|
|
{
|
|
return sprintf(page, "skb_debug_enable = %d\n", skb_debug_enable);
|
|
}
|
|
|
|
int skb_debug_proc_write(struct file *file, const char *buffer,
|
|
unsigned long count, void *data)
|
|
{
|
|
char val_string[32] = {0};
|
|
int value = -1;
|
|
|
|
if (count > sizeof(val_string) - 1)
|
|
return -EINVAL;
|
|
|
|
if (copy_from_user(val_string, buffer, count))
|
|
return -EFAULT;
|
|
|
|
sscanf(val_string, "%d", &value);
|
|
|
|
if (value)
|
|
{
|
|
skb_debug_enable = 1;
|
|
}
|
|
else
|
|
{
|
|
skb_debug_enable = 0;
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
void skb_debug_dump(struct sk_buff *skb)
|
|
{
|
|
char tmp[80];
|
|
char *p = skb->data;
|
|
char *t = tmp;
|
|
int i, n = 0;
|
|
|
|
printk("skb=0x%08x data=0x%08x len=%d\n", (unsigned int) skb, (unsigned int) skb->data, skb->len);
|
|
for (i = 0; i < skb->len; i++) {
|
|
t += sprintf(t, "%02x ", *p++ & 0xff);
|
|
if ((i & 0x0f) == 0x0f) {
|
|
printk("%04x: %s\n", n, tmp);
|
|
n += 16;
|
|
t = tmp;
|
|
}
|
|
}
|
|
if (i & 0x0f)
|
|
printk("%04x: %s\n", n, tmp);
|
|
}
|
|
EXPORT_SYMBOL(skb_debug_dump);
|
|
|
|
int __init tp_proc_init(void)
|
|
{
|
|
tplink_proc = proc_mkdir("tplink", NULL);
|
|
|
|
/* skb dump */
|
|
struct proc_dir_entry *skb_debug_proc;
|
|
skb_debug_proc = create_proc_entry("skb_debug_enable", 0666, tplink_proc);
|
|
skb_debug_proc->read_proc = skb_debug_proc_read;
|
|
skb_debug_proc->write_proc = skb_debug_proc_write;
|
|
skb_debug_proc->nlink = 1;
|
|
|
|
/* other proc */
|
|
|
|
return 0;
|
|
}
|
|
module_init(tp_proc_init);
|
|
|
|
/* end */
|