110 likes | 334 Views
proc & ppstream. 指導教授 : 李正帆 學生 : 黃健瑋. Content. Save module message to /proc Get ppstream channel ID IP refresh bug. Proc(1). struct proc_dir_entry *create_proc_entry ( const char *name, // 檔案名稱 mode_t mode, // 權限 struct proc_dir_entry *parent // 在 /proc 中的位置 );
E N D
proc & ppstream 指導教授:李正帆 學生:黃健瑋
Content • Save module message to /proc • Get ppstream channel ID • IP refresh bug
Proc(1) struct proc_dir_entry *create_proc_entry ( const char *name, // 檔案名稱 mode_t mode,//權限 struct proc_dir_entry *parent //在/proc中的位置 ); void remove_proc_entry ( const char *name, struct proc_dir_entry *parent );
Proc(2) int init_module(void){ if((proc_mtd = create_proc_entry("wireless", 0, 0))){ proc_mtd->read_proc = procfile_read; …… } // create file named “wireless” // procfile_read->function // when every time read the file, execute the function
Proc(3) void cleanup_module(void){ … if(proc_mtd) remove_proc_entry("wireless", 0); … } // remove the file
Proc(4) static int procfile_read(char *buffer, char **buffer_location, off_t offset, int buffer_length, int zero) { … *buffer_location = procBuffer; … } // we should save the string in procBuffer
Ppstream static void my_check_ci(struct sk_buff *skb) { tcp = (struct tcphdr *)(skb->data + (skb->nh.iph->ihl * 4)); data = (char *)((int)tcp + (int)(tcp->doff * 4)); if (strncmp(data, "GET ", 4) == 0) { do something } }
IP refresh bug • Skb->nh is network layer header • skb->h.raw=skb->nh.raw=skb->data means refresh the transport & network layer data • Still a question: • before the line, where does the raw point to & who use the pointer?
Reference • http://doubao.javaeye.com/blog/278081 • http://www.lslnet.com/linux/f/docs1/i19/big5191723.htm • http://vger.kernel.org/~davem/skb_redundancy.html • http://linux.chinaunix.net/bbs/viewthread.php?action=printable&tid=1131776 • http://zkheartboy.blogspot.com/2007/10/skbuff3.html • 輕輕鬆鬆學會Linux Kernel module及TCP/IP程式設計