Skip to content

Commit 996c8fb

Browse files
committed
nginx
1 parent a5a3799 commit 996c8fb

File tree

5 files changed

+603
-5
lines changed

5 files changed

+603
-5
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# Reading-and-comprehense-linux-Kernel-network-protocol-stack
1+
DDD# Reading-and-comprehense-linux-Kernel-network-protocol-stack
22
linux内核网络协议栈阅读理解
33

44
本代码是linux内核网络协议栈源码(版本为2.6.35),主要是我读研期间在一家公司实习的时候在业余时间分析阅读的,
55
研究生毕业后由于工作需要,对读研期间没有阅读的剩余主要功能重新阅读了一遍。本代码对三层及其以上部分主要功能做
6-
了详细注释,并对重要数据结构的各个成员进行了备注,同事对各个函数的调用关系都有详尽备注。主要参考资料为樊东东
6+
了详细注释,并对重要数据结构的各个成员进行了备注,同时对各个函数的调用关系都有详尽备注。主要参考资料为樊东东
77
老师的<linux内核源码剖析(上下册)>,再此对樊老师表示感谢,这是一本理解网络协议栈很好的书,两本合计1000多页,内
88
容比较多,但都很经典,对阅读内核协议栈源码有很大的帮助。
99

10-
由于工作中经常需要修改协议栈源码,包括封包解包各种隧道报文, NAT功能添加,路径修改等,由于部分内容涉及到
11-
公司保密内容,因此这些工作中新增修改的内核代码已经从本分github中移除,因此可能造成部分函数没有定义,但不会影响
12-
各位同行阅读和理解协议栈源码
10+
由于工作中经常需要修改协议栈源码,包括封包解包各种隧道报文, NAT功能添加,路径修改,添加自己的netfilter代
11+
码等,由于部分内容涉及到公司保密内容,因此这些工作中新增修改的内核代码已经从本分github中移除,因此可能造成部分
12+
函数没有定义,但不会影响各位同行阅读和理解协议栈源码
1313

1414
该代码已经详细分析和注释的协议栈功能有:
1515
.二层 三层 4层 发包收包调用流程,及各层头部封包解包分析注释。

linux-net-kernel/net/netfilter.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
http://bbs.chinaunix.net/thread-3749229-1-2.html [������ϵͳ] linux-2.6.35.6 xtables&iptables&hipac [��������]
2+
3+
http://bbs.chinaunix.net/thread-4082396-1-2.html [������ϵͳ] linux-2.6.35.6 nf_conntrack [��������]
4+
5+
http://bbs.chinaunix.net/thread-1970484-1-1.html Snort ���ּ��ϵͳԴ����� [��������]

linux-net-kernel/net/notify.WK3

15.2 KB
Binary file not shown.

linux-net-kernel/net/notify_test.c

+212
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
/* test_chain_0.c :0. 申明一个通知链;1. 向内核注册通知链;2. 定义事件; 3. 导出符号,因而必需最后退出*/
2+
3+
#include <linux/notifier.h>
4+
#include <linux/module.h>
5+
#include <linux/init.h>
6+
#include <linux/kernel.h> /* printk() */
7+
#include <linux/fs.h> /* everything() */
8+
9+
#define TESTCHAIN_INIT 0x52U
10+
static RAW_NOTIFIER_HEAD(test_chain);
11+
12+
/* define our own notifier_call_chain */
13+
static int call_test_notifiers(unsigned long val, void *v)
14+
{
15+
return raw_notifier_call_chain(&test_chain, val, v);
16+
}
17+
EXPORT_SYMBOL(call_test_notifiers);
18+
19+
/* define our own notifier_chain_register func */
20+
static int register_test_notifier(struct notifier_block *nb)
21+
{
22+
int err;
23+
err = raw_notifier_chain_register(&test_chain, nb);
24+
25+
if(err)
26+
goto out;
27+
28+
out:
29+
return err;
30+
}
31+
32+
EXPORT_SYMBOL(register_test_notifier);
33+
34+
static int __init test_chain_0_init(void)
35+
{
36+
printk(KERN_DEBUG "I'm in test_chain_0\n");
37+
38+
return 0;
39+
}
40+
41+
static void __exit test_chain_0_exit(void)
42+
{
43+
printk(KERN_DEBUG "Goodbye to test_chain_0\n");
44+
// call_test_notifiers(TESTCHAIN_EXIT, (int *)NULL);
45+
}
46+
47+
MODULE_LICENSE("GPL v2");
48+
MODULE_AUTHOR("fishOnFly");
49+
50+
module_init(test_chain_0_init);
51+
module_exit(test_chain_0_exit);
52+
53+
54+
55+
56+
57+
58+
59+
/* test_chain_1.c :1. 定义回调函数;2. 定义notifier_block;3. 向chain_0注册notifier_block;*/
60+
#include <linux/notifier.h>
61+
#include <linux/module.h>
62+
#include <linux/init.h>
63+
64+
#include <linux/kernel.h> /* printk() */
65+
#include <linux/fs.h> /* everything() */
66+
67+
extern int register_test_notifier(struct notifier_block *nb);
68+
#define TESTCHAIN_INIT 0x52U
69+
70+
/* realize the notifier_call func */
71+
int test_init_event(struct notifier_block *nb, unsigned long event,
72+
void *v)
73+
{
74+
switch(event){
75+
case TESTCHAIN_INIT:
76+
printk(KERN_DEBUG "I got the chain event: test_chain_2 is on the way of init\n");
77+
break;
78+
79+
default:
80+
break;
81+
}
82+
83+
return NOTIFY_DONE;
84+
}
85+
/* define a notifier_block */
86+
static struct notifier_block test_init_notifier = {
87+
.notifier_call = test_init_event,
88+
};
89+
static int __init test_chain_1_init(void)
90+
{
91+
printk(KERN_DEBUG "I'm in test_chain_1\n");
92+
register_test_notifier(&test_init_notifier);//<span style="white-space:pre"> </span>// 由chain_0提供的设施
93+
return 0;
94+
}
95+
96+
static void __exit test_chain_1_exit(void)
97+
{
98+
printk(KERN_DEBUG "Goodbye to test_clain_l\n");
99+
}
100+
101+
MODULE_LICENSE("GPL");
102+
MODULE_AUTHOR("fishOnFly");
103+
104+
module_init(test_chain_1_init);
105+
module_exit(test_chain_1_exit);
106+
107+
108+
109+
110+
111+
112+
113+
114+
115+
116+
117+
118+
119+
120+
121+
/* test_chain_2.c:发出通知链事件*/
122+
123+
#include <linux/notifier.h>
124+
#include <linux/module.h>
125+
#include <linux/init.h>
126+
#include <linux/kernel.h> /* printk() */
127+
#include <linux/fs.h> /* everything() */
128+
129+
extern int call_test_notifiers(unsigned long val, void *v);
130+
#define TESTCHAIN_INIT 0x52U
131+
132+
static int __init test_chain_2_init(void)
133+
{
134+
printk(KERN_DEBUG "I'm in test_chain_2\n");
135+
call_test_notifiers(TESTCHAIN_INIT, "no_use");
136+
137+
return 0;
138+
}
139+
140+
static void __exit test_chain_2_exit(void)
141+
{
142+
printk(KERN_DEBUG "Goodbye to test_chain_2\n");
143+
}
144+
145+
MODULE_LICENSE("GPL v2");
146+
MODULE_AUTHOR("fishOnFly");
147+
148+
module_init(test_chain_2_init);
149+
module_exit(test_chain_2_exit);
150+
151+
/*
152+
[wang2@iwooing: notifier_chian]$ sudo insmod./test_chain_0.ko
153+
[wang2@iwooing: notifier_chian]$ sudo insmod./test_chain_1.ko
154+
[wang2@iwooing: notifier_chian]$ sudo insmod./test_chain_2.ko
155+
156+
157+
[wang2@iwooing: notifier_chian]$ dmesg
158+
159+
[ 5950.112649] I'm in test_chain_0
160+
[ 5956.766610] I'm in test_chain_1
161+
[ 5962.570003] I'm in test_chain_2
162+
[ 5962.570008] I got the chain event: test_chain_2 is on the way of init
163+
164+
[ 6464.042975] Goodbye to test_chain_2
165+
[ 6466.368030] Goodbye to test_clain_l
166+
[ 6468.371479] Goodbye to test_chain_0
167+
168+
169+
170+
171+
# Makefile
172+
173+
# Comment/uncomment the following line to disable/enable debugging
174+
# DEBUG = y
175+
176+
177+
# Add your debugging flag (or not) to CFLAGS
178+
ifeq ($(DEBUG),y)
179+
DEBFLAGS = -O -g -DSCULL_DEBUG # "-O" is needed to expand inlines
180+
else
181+
DEBFLAGS = -O2
182+
endif
183+
184+
185+
ifneq ($(KERNELRELEASE),)
186+
# call from kernel build system
187+
188+
obj-m := test_chain_0.o test_chain_1.o test_chain_2.o
189+
190+
else
191+
192+
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
193+
PWD := $(shell pwd)
194+
195+
modules:
196+
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
197+
198+
endif
199+
200+
201+
202+
clean:
203+
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
204+
205+
depend .depend dep:
206+
$(CC) $(CFLAGS) -M *.c > .depend
207+
208+
209+
ifeq (.depend,$(wildcard .depend))
210+
include .depend
211+
endif
212+
*/

0 commit comments

Comments
 (0)