├── README.md
├── ex1-hello
├── Makefile
├── README.md
└── hello.c
├── ex10-print_vmem
├── Makefile
└── vma.c
├── ex11-alloc_mm
├── Makefile
└── alloc_mm.c
├── ex12-slab
├── Makefile
└── slab.c
├── ex13-syscall
├── .syscall.ko.cmd
├── .syscall.mod.cmd
├── .syscall.mod.o.cmd
├── .syscall.o.cmd
├── Makefile
├── Module.symvers
├── a.out
├── modules.order
├── syscall.c
├── syscall.ko
├── syscall.mod
├── syscall.mod.c
├── syscall.mod.o
├── syscall.o
└── test.c
├── ex14-drop-packet
├── __MACOSX
│ └── drop-packet
│ │ ├── ._.DS_Store
│ │ ├── ._drop-packet.docx
│ │ └── src
│ │ ├── ._.DS_Store
│ │ ├── step1
│ │ ├── ._.DS_Store
│ │ ├── ._Makefile
│ │ ├── ._drop_packet.h
│ │ └── ._main.c
│ │ └── step2
│ │ └── ._main.c
└── drop-packet
│ ├── .DS_Store
│ ├── drop-packet.docx
│ └── src
│ ├── .DS_Store
│ ├── step1
│ ├── .DS_Store
│ ├── .cache.mk
│ ├── .drop-packet.ko.cmd
│ ├── .drop-packet.mod.o.cmd
│ ├── .drop-packet.o.cmd
│ ├── .main.o.cmd
│ ├── .tmp_versions
│ │ └── drop-packet.mod
│ ├── Makefile
│ ├── Module.symvers
│ ├── drop-packet.ko
│ ├── drop-packet.mod.c
│ ├── drop-packet.mod.o
│ ├── drop-packet.o
│ ├── drop_packet.h
│ ├── main.c
│ ├── main.o
│ └── modules.order
│ ├── step2
│ ├── .cache.mk
│ ├── .drop-packet.ko.cmd
│ ├── .drop-packet.mod.o.cmd
│ ├── .drop-packet.o.cmd
│ ├── .main.o.cmd
│ ├── .tmp_versions
│ │ └── drop-packet.mod
│ ├── Makefile
│ ├── Module.symvers
│ ├── drop-packet.ko
│ ├── drop-packet.mod.c
│ ├── drop-packet.mod.o
│ ├── drop-packet.o
│ ├── drop_packet.h
│ ├── main.c
│ ├── main.o
│ └── modules.order
│ ├── step3
│ ├── .cache.mk
│ ├── .drop-packet.ko.cmd
│ ├── .drop-packet.mod.o.cmd
│ ├── .drop-packet.o.cmd
│ ├── .main.o.cmd
│ ├── .misc.o.cmd
│ ├── .tmp_versions
│ │ └── drop-packet.mod
│ ├── Makefile
│ ├── Module.symvers
│ ├── drop-packet.ko
│ ├── drop-packet.mod.c
│ ├── drop-packet.mod.o
│ ├── drop-packet.o
│ ├── drop_packet.h
│ ├── main.c
│ ├── main.o
│ ├── misc.c
│ ├── misc.o
│ └── modules.order
│ ├── step4
│ ├── .cache.mk
│ ├── .drop-packet.ko.cmd
│ ├── .drop-packet.mod.o.cmd
│ ├── .drop-packet.o.cmd
│ ├── .main.o.cmd
│ ├── .misc.o.cmd
│ ├── .tmp_versions
│ │ └── drop-packet.mod
│ ├── Makefile
│ ├── Module.symvers
│ ├── drop-packet.ko
│ ├── drop-packet.mod.c
│ ├── drop-packet.mod.o
│ ├── drop-packet.o
│ ├── drop_packet.h
│ ├── main.c
│ ├── main.o
│ ├── misc.c
│ ├── misc.o
│ └── modules.order
│ ├── step5
│ ├── .cache.mk
│ ├── .drop-packet.ko.cmd
│ ├── .drop-packet.mod.o.cmd
│ ├── .drop-packet.o.cmd
│ ├── .main.o.cmd
│ ├── .misc.o.cmd
│ ├── .tmp_versions
│ │ └── drop-packet.mod
│ ├── Makefile
│ ├── Module.symvers
│ ├── drop-packet.ko
│ ├── drop-packet.mod.c
│ ├── drop-packet.mod.o
│ ├── drop-packet.o
│ ├── drop_packet.h
│ ├── index.html
│ ├── main.c
│ ├── main.o
│ ├── misc.c
│ ├── misc.o
│ └── modules.order
│ └── step6
│ ├── .cache.mk
│ ├── .drop-packet.ko.cmd
│ ├── .drop-packet.mod.o.cmd
│ ├── .drop-packet.o.cmd
│ ├── .main.o.cmd
│ ├── .misc.o.cmd
│ ├── .tmp_versions
│ └── drop-packet.mod
│ ├── Makefile
│ ├── Module.symvers
│ ├── drop-packet.ko
│ ├── drop-packet.mod.c
│ ├── drop-packet.mod.o
│ ├── drop-packet.o
│ ├── drop_packet.h
│ ├── index.html
│ ├── main.c
│ ├── main.o
│ ├── misc.c
│ ├── misc.o
│ └── modules.order
├── ex2-exnum
├── Makefile
├── exnum.c
├── maxnum.c
├── test
│ ├── diff.out
│ ├── same.out
│ ├── testmax.c
│ ├── testmax.out
│ ├── text_diff.c
│ ├── text_same.c
│ ├── type.out
│ └── type2.out
└── 运行结果.png
├── ex3-lklist
├── .Makefile.swo
├── .Makefile.swp
├── Makefile
├── lklist.c
├── 删除10个节点.png
├── 插入100个节点.png
└── 还有90个.png
├── ex4-kernel_param
├── Makefile
├── kernel_param.c
├── 查看结果.png
└── 输入参数.png
├── ex5-Makefile2file
├── Makefile
├── hello1.c
├── hello2.c
└── 运行结果.png
├── ex6-rbtree
├── Makefile
├── rbtree.c
└── 运行结果.png
├── ex7-ForkAndClone
├── fork_test
└── fork_test.c
├── ex8-KernelThread
├── .kthread.o.d
├── Makefile
└── kthread.c
├── ex9-TraversePcb
├── Makefile
└── traverse_pcb.c
└── 代码目录索引.md
/README.md:
--------------------------------------------------------------------------------
1 |
2 | #
索引目录
3 |
4 | 本文总结了Linux初学者系列文章,从安装Linux操作系统开始,搭建Linux环境,编写代码,使用工具,手把手带大家走进Linux内核的世界。文章也是作者初学内核时所写,难免有不周全之处,若有问题之处,大家可以联系作者。
5 |
6 | #### 作者寄语:热爱开源,践行开放、自由、分享,希望和大家一起进步,谢谢大家。
7 | Linux内核之旅网站:[http://kerneltravel.net/](http://kerneltravel.net/)
8 |
9 | 目录更新地址:[https://blog.csdn.net/qq_34258344/article/details/102015623](https://blog.csdn.net/qq_34258344/article/details/102015623)
10 |
11 | GitHub地址:[https://github.com/ljrcore](https://github.com/ljrcore)
12 |
13 |
14 | ## Linux初学者入门系列
15 |
16 | ||
17 | |--|
18 | |[手把手教你搭建Linux开发环境(VMware+Ubuntu)(一)——安装VMware虚拟机和Ubuntu](https://blog.csdn.net/qq_34258344/article/details/101175849)|
19 | |[手把手教你搭建Linux开发环境(VMware+Ubuntu)(二)——安装VMwareTools并设置共享文件夹](https://blog.csdn.net/qq_34258344/article/details/101942788) |
20 | | [手把手教你搭建Linux开发环境(VMware+Ubuntu)(三)——Ubuntu下vim编辑器的安装、配置和使用](https://blog.csdn.net/qq_34258344/article/details/97525312) |
21 | | [手把手教你搭建Linux开发环境(VMware+Ubuntu)(四)——gcc编译器的安装和使用](https://blog.csdn.net/qq_34258344/article/details/101975444) |
22 | | [Linux初学者接住了---Linux常用命令](https://blog.csdn.net/qq_34258344/article/details/96960662) |
23 | | [Xshell远程登录Ubuntu](https://blog.csdn.net/qq_34258344/article/details/97394189) |
24 | | [网站迁移的一般步骤、常见问题及解决措施](https://blog.csdn.net/qq_34258344/article/details/99619696) |
25 |
26 | ## Linux内核系列
27 |
28 | ||
29 | |--|
30 | |[陈老师Linux内核概述导学](https://blog.csdn.net/qq_34258344/article/details/102399144)|
31 | |[陈老师Linux内核内存寻址导学](https://blog.csdn.net/qq_34258344/article/details/102399578)|
32 | |[陈老师Linux内核进程管理导学](https://blog.csdn.net/qq_34258344/article/details/102399917)|
33 | | [Linxu内核模块开发入门](https://blog.csdn.net/qq_34258344/article/details/95028200) |
34 | |[如何使用Linux内核中没有被导出的变量或函数](https://blog.csdn.net/qq_34258344/article/details/103547971)|
35 | | [Linux内核中max()宏的奥妙何在?(一)](https://blog.csdn.net/qq_34258344/article/details/101039771) |
36 | | [Linux内核中max()宏的奥妙何在?(二)——大神Linus对这个宏怎么看?](https://blog.csdn.net/qq_34258344/article/details/101161512) |
37 | | [Linux内核之浅谈内存寻址](https://blog.csdn.net/qq_34258344/article/details/95519020)|
38 | | [Linux内核之话说进程](https://blog.csdn.net/qq_34258344/article/details/98347167) |
39 | | [Linux内核之内核同步(一)——内核同步基础](https://blog.csdn.net/qq_34258344/article/details/103324755)|
40 | |[Linux内核之内核同步(二)——原子操作](https://blog.csdn.net/qq_34258344/article/details/100592236)|
41 | |[Linux内核之内核同步(三)——自旋锁](https://blog.csdn.net/qq_34258344/article/details/103326114)|
42 | |[Linux 系统调用(一)](https://editor.csdn.net/md/?articleId=104537181)|
43 | |[Linux 系统调用(二)——使用内核模块添加系统调用(无需编译内核)](https://editor.csdn.net/md/?articleId=103228607)|
44 | |[Linux内核网络(一)——初探内核网络](https://editor.csdn.net/md/?articleId=105848293)|
45 |
46 |
47 | ## Linux性能优化
48 |
49 | ||
50 | |--|
51 | |[Linux系统cpu负载浅析](https://blog.csdn.net/qq_34258344/article/details/102584504)|
52 | |[内核同步对性能的影响及perf的安装和简单的使用](https://blog.csdn.net/qq_34258344/article/details/104309361)|
53 | |[eBPF & bcc 教程(一)](https://blog.csdn.net/qq_34258344/article/details/104400738)|
54 | |[eBPF & bcc教程(二)](https://blog.csdn.net/qq_34258344/article/details/104531060)|
55 |
56 |
57 | ## Docker
58 | ||
59 | | -- |
60 | | [Docker初体验](https://blog.csdn.net/qq_34258344/article/details/95972999) |
61 | | [Ubuntu中安装最新Docker社区版](https://blog.csdn.net/qq_34258344/article/details/102671094) |
62 | | [Ubuntu中安装docker-compose](https://blog.csdn.net/qq_34258344/article/details/102715511) |
63 |
64 |
65 | ## Git
66 | ||
67 | |--|
68 | | [Linux下如何快速使用GitHub](https://blog.csdn.net/qq_34258344/article/details/100625434)|
69 | |[使用GitHub免费搭建属于自己的网站](https://editor.csdn.net/md/?articleId=104665562)|
70 |
71 |
72 | ## 其它
73 | ||
74 | | -- |
75 | |[Ubuntu下安装中文输入法(本博客安装的搜狗输入法)](https://blog.csdn.net/qq_34258344/article/details/102997942)|
76 | |[解决Ubuntu中sublime无法输入中文的问题](https://editor.csdn.net/md/?articleId=104849673)|
77 | |[并行计算、分布式计算、集群计算和云计算,大科普!](https://editor.csdn.net/md/?articleId=104798142)|
78 | |[使用微软官方工具下载最新系统(win10为例)](https://editor.csdn.net/md/?articleId=104701570)|
79 |
--------------------------------------------------------------------------------
/ex1-hello/Makefile:
--------------------------------------------------------------------------------
1 | obj-m:= hello.o
2 | CURRENT_PATH:=$(shell pwd)
3 | LINUX_KERNEL:=$(shell uname -r)
4 | LINUX_KERNEL_PATH:=/usr/src/linux-headers-$(LINUX_KERNEL)
5 |
6 | all:
7 | make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
8 | clean:
9 | make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean
10 |
11 |
--------------------------------------------------------------------------------
/ex1-hello/README.md:
--------------------------------------------------------------------------------
1 | # 经典的hello world入门代码
2 |
--------------------------------------------------------------------------------
/ex1-hello/hello.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | static int __init lk_hello(void)
6 | {
7 | printk("hello world!\n");
8 | return 0;
9 | }
10 | static void __exit lk_exit(void)
11 | {
12 | printk("good bye!\n");
13 |
14 | }
15 | module_init(lk_hello);
16 | module_exit(lk_exit);
17 | MODULE_LICENSE("GPL");
18 |
19 |
--------------------------------------------------------------------------------
/ex10-print_vmem/Makefile:
--------------------------------------------------------------------------------
1 | obj-m:=vma.o
2 |
3 | CURRENT_PATH:=$(shell pwd)
4 | LINUX_KERNEL:=$(shell uname -r)
5 | LINUX_KERNEL_PATH:=/usr/src/linux-headers-$(LINUX_KERNEL)
6 |
7 | all:
8 | make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
9 |
10 | clean:
11 | make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean
12 |
--------------------------------------------------------------------------------
/ex10-print_vmem/vma.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | static int pid;
7 | module_param(pid, int, 0644);
8 |
9 | static void printit(struct task_struct *tsk)
10 | {
11 | struct mm_struct *mm;
12 | struct vm_area_struct *vma;
13 | int j = 0;
14 | unsigned long start, end, length;
15 |
16 | mm = tsk->mm;
17 | pr_info("mm_struct addr = 0x%p\n", mm);
18 | vma = mm->mmap;
19 |
20 | /* protect from simultaneous modification */
21 | down_read(&mm->mmap_sem);
22 | pr_info("vmas: vma start end length\n");
23 |
24 | while (vma) {
25 | j++;
26 | start = vma->vm_start;
27 | end = vma->vm_end;
28 | length = end - start;
29 | pr_info("%6d: %16p %12lx %12lx %8ld\n",
30 | j, vma, start, end, length);
31 | vma = vma->vm_next;
32 | }
33 | up_read(&mm->mmap_sem);
34 | }
35 |
36 | static int __init my_init(void)
37 | {
38 | struct task_struct *tsk;
39 | /* if don't pass the pid over insmod, then use the current process */
40 | if (pid == 0) {
41 | tsk = current;
42 | pid = current->pid;
43 | pr_info("using current process\n");
44 | } else {
45 | tsk = pid_task(find_vpid(pid), PIDTYPE_PID);
46 | }
47 | if (!tsk)
48 | return -1;
49 | pr_info(" Examining vma's for pid=%d, command=%s\n", pid, tsk->comm);
50 | printit(tsk);
51 | return 0;
52 | }
53 |
54 | static void __exit my_exit(void)
55 | {
56 | pr_info("Module exit\n");
57 | }
58 |
59 | module_init(my_init);
60 | module_exit(my_exit);
61 |
62 | MODULE_LICENSE("GPL v2");
63 |
--------------------------------------------------------------------------------
/ex11-alloc_mm/Makefile:
--------------------------------------------------------------------------------
1 | obj-m:=alloc_mm.o
2 |
3 | CURRENT_PATH:=$(shell pwd)
4 | LINUX_KERNEL:=$(shell uname -r)
5 | LINUX_KERNEL_PATH:=/usr/src/linux-headers-$(LINUX_KERNEL)
6 |
7 | all:
8 | make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
9 |
10 | clean:
11 | make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean
12 |
--------------------------------------------------------------------------------
/ex11-alloc_mm/alloc_mm.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | static int mem = 64;
7 |
8 | #define MB (1024*1024)
9 |
10 | static int __init my_init(void)
11 | {
12 | char *kbuf;
13 | unsigned long order;
14 | unsigned long size;
15 | char *vm_buff;
16 |
17 | /* try __get_free_pages__ */
18 | for (size = PAGE_SIZE, order = 0; order < MAX_ORDER;
19 | order++, size *= 2) {
20 | pr_info(" order=%2lu, pages=%5lu, size=%8lu ", order,
21 | size / PAGE_SIZE, size);
22 | kbuf = (char *)__get_free_pages(GFP_ATOMIC, order);
23 | if (!kbuf) {
24 | pr_err("... __get_free_pages failed\n");
25 | break;
26 | }
27 | pr_info("... __get_free_pages OK\n");
28 | free_pages((unsigned long)kbuf, order);
29 | }
30 |
31 | /* try kmalloc */
32 | for (size = PAGE_SIZE, order = 0; order < MAX_ORDER;
33 | order++, size *= 2) {
34 | pr_info(" order=%2lu, pages=%5lu, size=%8lu ", order,
35 | size / PAGE_SIZE, size);
36 | kbuf = kmalloc((size_t) size, GFP_ATOMIC);
37 | if (!kbuf) {
38 | pr_err("... kmalloc failed\n");
39 | break;
40 | }
41 | pr_info("... kmalloc OK\n");
42 | kfree(kbuf);
43 | }
44 |
45 | /* try vmalloc */
46 | for (size = 4 * MB; size <= mem * MB; size += 4 * MB) {
47 | pr_info(" pages=%6lu, size=%8lu ", size / PAGE_SIZE, size / MB);
48 | vm_buff = vmalloc(size);
49 | if (!vm_buff) {
50 | pr_err("... vmalloc failed\n");
51 | break;
52 | }
53 | pr_info("... vmalloc OK\n");
54 | vfree(vm_buff);
55 | }
56 |
57 | return 0;
58 | }
59 |
60 | static void __exit my_exit(void)
61 | {
62 | pr_info("Module exit\n");
63 | }
64 |
65 | module_init(my_init);
66 | module_exit(my_exit);
67 |
68 | MODULE_LICENSE("GPL v2");
69 |
--------------------------------------------------------------------------------
/ex12-slab/Makefile:
--------------------------------------------------------------------------------
1 | obj-m:=slab.o
2 |
3 | CURRENT_PATH:=$(shell pwd)
4 | LINUX_KERNEL:=$(shell uname -r)
5 | LINUX_KERNEL_PATH:=/usr/src/linux-headers-$(LINUX_KERNEL)
6 |
7 | all:
8 | make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
9 |
10 | clean:
11 | make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean
12 |
--------------------------------------------------------------------------------
/ex12-slab/slab.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | static char *kbuf;
7 | static int size = 21*PAGE_SIZE;
8 | static struct kmem_cache *my_cache;
9 | module_param(size, int, 0644);
10 |
11 | static int __init my_init(void)
12 | {
13 | /* create a memory cache */
14 | if (size > KMALLOC_MAX_SIZE) {
15 | pr_err
16 | (" size=%d is too large; you can't have more than %lu!\n",
17 | size, KMALLOC_MAX_SIZE);
18 | return -1;
19 | }
20 |
21 | my_cache = kmem_cache_create("mycache", size, 0,
22 | SLAB_HWCACHE_ALIGN, NULL);
23 | if (!my_cache) {
24 | pr_err("kmem_cache_create failed\n");
25 | return -ENOMEM;
26 | }
27 | pr_info("create mycache correctly\n");
28 |
29 | /* allocate a memory cache object */
30 | kbuf = kmem_cache_alloc(my_cache, GFP_ATOMIC);
31 | if (!kbuf) {
32 | pr_err(" failed to create a cache object\n");
33 | (void)kmem_cache_destroy(my_cache);
34 | return -1;
35 | }
36 | pr_info(" successfully created a object, kbuf_addr=0x%p\n", kbuf);
37 |
38 | return 0;
39 | }
40 |
41 | static void __exit my_exit(void)
42 | {
43 | /* destroy a memory cache object */
44 | kmem_cache_free(my_cache, kbuf);
45 | pr_info("destroyed a cache object\n");
46 |
47 | /* destroy the memory cache */
48 | kmem_cache_destroy(my_cache);
49 | pr_info("destroyed mycache\n");
50 | }
51 |
52 | module_init(my_init);
53 | module_exit(my_exit);
54 |
55 | MODULE_LICENSE("GPL v2");
56 | MODULE_AUTHOR("Ben ShuShu");
57 |
--------------------------------------------------------------------------------
/ex13-syscall/.syscall.ko.cmd:
--------------------------------------------------------------------------------
1 | cmd_/home/ljr/Learning_linux_kernel/ex13-syscall/syscall.ko := ld -r -m elf_x86_64 -z max-page-size=0x200000 -T ./scripts/module-common.lds --build-id -o /home/ljr/Learning_linux_kernel/ex13-syscall/syscall.ko /home/ljr/Learning_linux_kernel/ex13-syscall/syscall.o /home/ljr/Learning_linux_kernel/ex13-syscall/syscall.mod.o ; true
2 |
--------------------------------------------------------------------------------
/ex13-syscall/.syscall.mod.cmd:
--------------------------------------------------------------------------------
1 | cmd_/home/ljr/Learning_linux_kernel/ex13-syscall/syscall.mod := { echo /home/ljr/Learning_linux_kernel/ex13-syscall/syscall.o; echo; } > /home/ljr/Learning_linux_kernel/ex13-syscall/syscall.mod
2 |
--------------------------------------------------------------------------------
/ex13-syscall/Makefile:
--------------------------------------------------------------------------------
1 | obj-m:=syscall.o
2 | PWD:= $(shell pwd)
3 | KERNELDIR:= /lib/modules/$(shell uname -r)/build
4 | EXTRA_CFLAGS= -O0
5 |
6 | all:
7 | make -C $(KERNELDIR) M=$(PWD) modules
8 | clean:
9 | make -C $(KERNELDIR) M=$(PWD) clean
10 |
--------------------------------------------------------------------------------
/ex13-syscall/Module.symvers:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex13-syscall/Module.symvers
--------------------------------------------------------------------------------
/ex13-syscall/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex13-syscall/a.out
--------------------------------------------------------------------------------
/ex13-syscall/modules.order:
--------------------------------------------------------------------------------
1 | /home/ljr/Learning_linux_kernel/ex13-syscall/syscall.ko
2 |
--------------------------------------------------------------------------------
/ex13-syscall/syscall.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #define __NR_syscall 335 /* 系统调用号335 */
11 |
12 | unsigned long * sys_call_table;
13 |
14 | unsigned int clear_and_return_cr0(void);
15 | void setback_cr0(unsigned int val);
16 | static int sys_mycall(void);
17 |
18 |
19 | int orig_cr0; /* 用来存储cr0寄存器原来的值 */
20 | unsigned long *sys_call_table = 0;
21 | static int (*anything_saved)(void); /*定义一个函数指针,用来保存一个系统调用*/
22 | /*
23 | * 设置cr0寄存器的第17位为0
24 | */
25 | unsigned int clear_and_return_cr0(void)
26 | {
27 | unsigned int cr0 = 0;
28 | unsigned int ret;
29 | /* 前者用在32位系统。后者用在64位系统,本系统64位 */
30 | //asm volatile ("movl %%cr0, %%eax" : "=a"(cr0));
31 | asm volatile ("movq %%cr0, %%rax" : "=a"(cr0)); /* 将cr0寄存器的值移动到rax寄存器中,同时输出到cr0变量中 */
32 | ret = cr0;
33 | cr0 &= 0xfffeffff; /* 将cr0变量值中的第17位清0,将修改后的值写入cr0寄存器 */
34 | //asm volatile ("movl %%eax, %%cr0" :: "a"(cr0));
35 | asm volatile ("movq %%rax, %%cr0" :: "a"(cr0)); /* 读取cr0的值到rax寄存器,再将rax寄存器的值放入cr0中 */
36 | return ret;
37 | }
38 |
39 | /* 读取val的值到rax寄存器,再将rax寄存器的值放入cr0中 */
40 | void setback_cr0(unsigned int val)
41 | {
42 |
43 | //asm volatile ("movl %%eax, %%cr0" :: "a"(val));
44 | asm volatile ("movq %%rax, %%cr0" :: "a"(val));
45 | }
46 |
47 | /* 添加自己的系统调用函数 */
48 | static int sys_mycall(void)
49 | {
50 | int ret = 12345;
51 | printk("My syscall is successful!\n");
52 | return ret;
53 | }
54 |
55 | /*模块的初始化函数,模块的入口函数,加载模块*/
56 | static int __init init_addsyscall(void)
57 | {
58 | printk("My syscall is starting。。。\n");
59 | sys_call_table = (unsigned long *)kallsyms_lookup_name("sys_call_table"); /* 获取系统调用服务首地址 */
60 | printk("sys_call_table: 0x%p\n", sys_call_table);
61 | anything_saved = (int(*)(void))(sys_call_table[__NR_syscall]); /* 保存原始系统调用 */
62 | orig_cr0 = clear_and_return_cr0(); /* 设置cr0可更改 */
63 | sys_call_table[__NR_syscall] = (unsigned long)&sys_mycall; /* 更改原始的系统调用服务地址 */
64 | setback_cr0(orig_cr0); /* 设置为原始的只读cr0 */
65 | return 0;
66 | }
67 |
68 | /*出口函数,卸载模块*/
69 | static void __exit exit_addsyscall(void)
70 | {
71 | orig_cr0 = clear_and_return_cr0(); /* 设置cr0中对sys_call_table的更改权限 */
72 | sys_call_table[__NR_syscall] = (unsigned long)anything_saved; /* 设置cr0可更改 */
73 | setback_cr0(orig_cr0); /* 恢复原有的中断向量表中的函数指针的值 */
74 | printk("My syscall exit....\n"); /* 恢复原有的cr0的值 */
75 | }
76 |
77 | module_init(init_addsyscall);
78 | module_exit(exit_addsyscall);
79 | MODULE_LICENSE("GPL");
80 |
--------------------------------------------------------------------------------
/ex13-syscall/syscall.ko:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex13-syscall/syscall.ko
--------------------------------------------------------------------------------
/ex13-syscall/syscall.mod:
--------------------------------------------------------------------------------
1 | /home/ljr/Learning_linux_kernel/ex13-syscall/syscall.o
2 |
3 |
--------------------------------------------------------------------------------
/ex13-syscall/syscall.mod.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | BUILD_SALT;
7 |
8 | MODULE_INFO(vermagic, VERMAGIC_STRING);
9 | MODULE_INFO(name, KBUILD_MODNAME);
10 |
11 | __visible struct module __this_module
12 | __attribute__((section(".gnu.linkonce.this_module"))) = {
13 | .name = KBUILD_MODNAME,
14 | .init = init_module,
15 | #ifdef CONFIG_MODULE_UNLOAD
16 | .exit = cleanup_module,
17 | #endif
18 | .arch = MODULE_ARCH_INIT,
19 | };
20 |
21 | #ifdef CONFIG_RETPOLINE
22 | MODULE_INFO(retpoline, "Y");
23 | #endif
24 |
25 | static const char __module_depends[]
26 | __used
27 | __attribute__((section(".modinfo"))) =
28 | "depends=";
29 |
30 |
31 | MODULE_INFO(srcversion, "174A74DD920B69890CA58EB");
32 |
--------------------------------------------------------------------------------
/ex13-syscall/syscall.mod.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex13-syscall/syscall.mod.o
--------------------------------------------------------------------------------
/ex13-syscall/syscall.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex13-syscall/syscall.o
--------------------------------------------------------------------------------
/ex13-syscall/test.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | //#include
4 | //#include
5 | //#include
6 |
7 | int main(void)
8 | {
9 | printf("%d\n",syscall(335));
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/ex14-drop-packet/__MACOSX/drop-packet/._.DS_Store:
--------------------------------------------------------------------------------
1 | Mac OS X 2 F x @ ATTR x x
--------------------------------------------------------------------------------
/ex14-drop-packet/__MACOSX/drop-packet/._drop-packet.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/__MACOSX/drop-packet/._drop-packet.docx
--------------------------------------------------------------------------------
/ex14-drop-packet/__MACOSX/drop-packet/src/._.DS_Store:
--------------------------------------------------------------------------------
1 | Mac OS X 2 F x @ ATTR x x
--------------------------------------------------------------------------------
/ex14-drop-packet/__MACOSX/drop-packet/src/step1/._.DS_Store:
--------------------------------------------------------------------------------
1 | Mac OS X 2 F x @ ATTR x x
--------------------------------------------------------------------------------
/ex14-drop-packet/__MACOSX/drop-packet/src/step1/._Makefile:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/__MACOSX/drop-packet/src/step1/._Makefile
--------------------------------------------------------------------------------
/ex14-drop-packet/__MACOSX/drop-packet/src/step1/._drop_packet.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/__MACOSX/drop-packet/src/step1/._drop_packet.h
--------------------------------------------------------------------------------
/ex14-drop-packet/__MACOSX/drop-packet/src/step1/._main.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/__MACOSX/drop-packet/src/step1/._main.c
--------------------------------------------------------------------------------
/ex14-drop-packet/__MACOSX/drop-packet/src/step2/._main.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/__MACOSX/drop-packet/src/step2/._main.c
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/.DS_Store
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/drop-packet.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/drop-packet.docx
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/.DS_Store
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step1/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step1/.DS_Store
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step1/.drop-packet.ko.cmd:
--------------------------------------------------------------------------------
1 | cmd_/home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop-packet.ko := ld -r -m elf_x86_64 -z max-page-size=0x200000 -T ./scripts/module-common.lds --build-id -o /home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop-packet.ko /home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop-packet.o /home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop-packet.mod.o ; true
2 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step1/.drop-packet.mod.o.cmd:
--------------------------------------------------------------------------------
1 | cmd_/home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop-packet.mod.o := gcc -Wp,-MD,/home/xiebaoyou/study/陈老师/drop-packet/src/step1/.drop-packet.mod.o.d -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/5/include -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -Iubuntu/include -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-PIE -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -DCONFIG_X86_X32_ABI -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_AVX512=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -DRETPOLINE -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -DCC_HAVE_ASM_GOTO -Wframe-larger-than=1024 -fstack-protector-strong -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -pg -mfentry -DCC_USING_FENTRY -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fno-merge-all-constants -fmerge-constants -fno-stack-check -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -I/home/xiebaoyou/study/陈老师/drop-packet/src/step1/ -DKBUILD_BASENAME='"drop_packet.mod"' -DKBUILD_MODNAME='"drop_packet"' -DMODULE -DUBUNTU_1604 -c -o /home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop-packet.mod.o /home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop-packet.mod.c
2 |
3 | source_/home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop-packet.mod.o := /home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop-packet.mod.c
4 |
5 | deps_/home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop-packet.mod.o := \
6 | $(wildcard include/config/module/unload.h) \
7 | include/linux/compiler_types.h \
8 | $(wildcard include/config/enable/must/check.h) \
9 | $(wildcard include/config/enable/warn/deprecated.h) \
10 | include/linux/compiler-gcc.h \
11 | $(wildcard include/config/arch/supports/optimized/inlining.h) \
12 | $(wildcard include/config/optimize/inlining.h) \
13 | $(wildcard include/config/gcov/kernel.h) \
14 | $(wildcard include/config/arch/use/builtin/bswap.h) \
15 | include/linux/module.h \
16 | $(wildcard include/config/modules.h) \
17 | $(wildcard include/config/sysfs.h) \
18 | $(wildcard include/config/modules/tree/lookup.h) \
19 | $(wildcard include/config/livepatch.h) \
20 | $(wildcard include/config/unused/symbols.h) \
21 | $(wildcard include/config/module/sig.h) \
22 | $(wildcard include/config/generic/bug.h) \
23 | $(wildcard include/config/kallsyms.h) \
24 | $(wildcard include/config/smp.h) \
25 | $(wildcard include/config/tracepoints.h) \
26 | $(wildcard include/config/tracing.h) \
27 | $(wildcard include/config/event/tracing.h) \
28 | $(wildcard include/config/ftrace/mcount/record.h) \
29 | $(wildcard include/config/constructors.h) \
30 | $(wildcard include/config/strict/module/rwx.h) \
31 | include/linux/list.h \
32 | $(wildcard include/config/debug/list.h) \
33 | include/linux/types.h \
34 | $(wildcard include/config/have/uid16.h) \
35 | $(wildcard include/config/uid16.h) \
36 | $(wildcard include/config/lbdaf.h) \
37 | $(wildcard include/config/arch/dma/addr/t/64bit.h) \
38 | $(wildcard include/config/phys/addr/t/64bit.h) \
39 | $(wildcard include/config/64bit.h) \
40 | include/uapi/linux/types.h \
41 | arch/x86/include/uapi/asm/types.h \
42 | include/uapi/asm-generic/types.h \
43 | include/asm-generic/int-ll64.h \
44 | include/uapi/asm-generic/int-ll64.h \
45 | arch/x86/include/uapi/asm/bitsperlong.h \
46 | include/asm-generic/bitsperlong.h \
47 | include/uapi/asm-generic/bitsperlong.h \
48 | include/uapi/linux/posix_types.h \
49 | include/linux/stddef.h \
50 | include/uapi/linux/stddef.h \
51 | arch/x86/include/asm/posix_types.h \
52 | $(wildcard include/config/x86/32.h) \
53 | arch/x86/include/uapi/asm/posix_types_64.h \
54 | include/uapi/asm-generic/posix_types.h \
55 | include/linux/poison.h \
56 | $(wildcard include/config/illegal/pointer/value.h) \
57 | $(wildcard include/config/page/poisoning/zero.h) \
58 | include/uapi/linux/const.h \
59 | include/linux/kernel.h \
60 | $(wildcard include/config/preempt/voluntary.h) \
61 | $(wildcard include/config/debug/atomic/sleep.h) \
62 | $(wildcard include/config/mmu.h) \
63 | $(wildcard include/config/prove/locking.h) \
64 | $(wildcard include/config/arch/has/refcount.h) \
65 | $(wildcard include/config/lock/down/kernel.h) \
66 | $(wildcard include/config/panic/timeout.h) \
67 | /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \
68 | include/linux/linkage.h \
69 | include/linux/stringify.h \
70 | include/linux/export.h \
71 | $(wildcard include/config/have/underscore/symbol/prefix.h) \
72 | $(wildcard include/config/modversions.h) \
73 | $(wildcard include/config/module/rel/crcs.h) \
74 | $(wildcard include/config/trim/unused/ksyms.h) \
75 | arch/x86/include/asm/linkage.h \
76 | $(wildcard include/config/x86/64.h) \
77 | $(wildcard include/config/x86/alignment/16.h) \
78 | include/linux/compiler.h \
79 | $(wildcard include/config/trace/branch/profiling.h) \
80 | $(wildcard include/config/profile/all/branches.h) \
81 | $(wildcard include/config/stack/validation.h) \
82 | $(wildcard include/config/kasan.h) \
83 | arch/x86/include/asm/barrier.h \
84 | $(wildcard include/config/x86/ppro/fence.h) \
85 | arch/x86/include/asm/alternative.h \
86 | arch/x86/include/asm/asm.h \
87 | arch/x86/include/asm/nops.h \
88 | $(wildcard include/config/mk7.h) \
89 | $(wildcard include/config/x86/p6/nop.h) \
90 | include/asm-generic/barrier.h \
91 | include/linux/bitops.h \
92 | arch/x86/include/asm/bitops.h \
93 | $(wildcard include/config/x86/cmov.h) \
94 | arch/x86/include/asm/rmwcc.h \
95 | include/asm-generic/bitops/find.h \
96 | $(wildcard include/config/generic/find/first/bit.h) \
97 | include/asm-generic/bitops/sched.h \
98 | arch/x86/include/asm/arch_hweight.h \
99 | arch/x86/include/asm/cpufeatures.h \
100 | arch/x86/include/asm/required-features.h \
101 | $(wildcard include/config/x86/minimum/cpu/family.h) \
102 | $(wildcard include/config/math/emulation.h) \
103 | $(wildcard include/config/x86/pae.h) \
104 | $(wildcard include/config/x86/cmpxchg64.h) \
105 | $(wildcard include/config/x86/use/3dnow.h) \
106 | $(wildcard include/config/matom.h) \
107 | $(wildcard include/config/x86/5level.h) \
108 | $(wildcard include/config/paravirt.h) \
109 | arch/x86/include/asm/disabled-features.h \
110 | $(wildcard include/config/x86/intel/mpx.h) \
111 | $(wildcard include/config/x86/intel/umip.h) \
112 | $(wildcard include/config/x86/intel/memory/protection/keys.h) \
113 | $(wildcard include/config/page/table/isolation.h) \
114 | include/asm-generic/bitops/const_hweight.h \
115 | include/asm-generic/bitops/le.h \
116 | arch/x86/include/uapi/asm/byteorder.h \
117 | include/linux/byteorder/little_endian.h \
118 | $(wildcard include/config/cpu/big/endian.h) \
119 | include/uapi/linux/byteorder/little_endian.h \
120 | include/linux/swab.h \
121 | include/uapi/linux/swab.h \
122 | arch/x86/include/uapi/asm/swab.h \
123 | include/linux/byteorder/generic.h \
124 | include/asm-generic/bitops/ext2-atomic-setbit.h \
125 | include/linux/log2.h \
126 | $(wildcard include/config/arch/has/ilog2/u32.h) \
127 | $(wildcard include/config/arch/has/ilog2/u64.h) \
128 | include/linux/typecheck.h \
129 | include/linux/printk.h \
130 | $(wildcard include/config/message/loglevel/default.h) \
131 | $(wildcard include/config/console/loglevel/default.h) \
132 | $(wildcard include/config/early/printk.h) \
133 | $(wildcard include/config/printk/nmi.h) \
134 | $(wildcard include/config/printk.h) \
135 | $(wildcard include/config/kmsg/ids.h) \
136 | $(wildcard include/config/dynamic/debug.h) \
137 | include/linux/init.h \
138 | $(wildcard include/config/strict/kernel/rwx.h) \
139 | include/linux/kern_levels.h \
140 | include/linux/cache.h \
141 | $(wildcard include/config/arch/has/cache/line/size.h) \
142 | include/uapi/linux/kernel.h \
143 | include/uapi/linux/sysinfo.h \
144 | arch/x86/include/asm/cache.h \
145 | $(wildcard include/config/x86/l1/cache/shift.h) \
146 | $(wildcard include/config/x86/internode/cache/shift.h) \
147 | $(wildcard include/config/x86/vsmp.h) \
148 | include/linux/dynamic_debug.h \
149 | $(wildcard include/config/jump/label.h) \
150 | include/linux/jump_label.h \
151 | arch/x86/include/asm/jump_label.h \
152 | include/linux/build_bug.h \
153 | include/linux/stat.h \
154 | arch/x86/include/uapi/asm/stat.h \
155 | include/uapi/linux/stat.h \
156 | include/linux/time.h \
157 | $(wildcard include/config/arch/uses/gettimeoffset.h) \
158 | include/linux/seqlock.h \
159 | $(wildcard include/config/debug/lock/alloc.h) \
160 | include/linux/spinlock.h \
161 | $(wildcard include/config/debug/spinlock.h) \
162 | $(wildcard include/config/preempt.h) \
163 | include/linux/preempt.h \
164 | $(wildcard include/config/preempt/count.h) \
165 | $(wildcard include/config/debug/preempt.h) \
166 | $(wildcard include/config/preempt/tracer.h) \
167 | $(wildcard include/config/preempt/notifiers.h) \
168 | arch/x86/include/asm/preempt.h \
169 | arch/x86/include/asm/percpu.h \
170 | $(wildcard include/config/x86/64/smp.h) \
171 | include/asm-generic/percpu.h \
172 | $(wildcard include/config/have/setup/per/cpu/area.h) \
173 | include/linux/threads.h \
174 | $(wildcard include/config/nr/cpus.h) \
175 | $(wildcard include/config/base/small.h) \
176 | include/linux/percpu-defs.h \
177 | $(wildcard include/config/debug/force/weak/per/cpu.h) \
178 | $(wildcard include/config/virtualization.h) \
179 | $(wildcard include/config/amd/mem/encrypt.h) \
180 | include/linux/thread_info.h \
181 | $(wildcard include/config/thread/info/in/task.h) \
182 | $(wildcard include/config/debug/stack/usage.h) \
183 | $(wildcard include/config/debug/kmemleak.h) \
184 | $(wildcard include/config/have/arch/within/stack/frames.h) \
185 | $(wildcard include/config/hardened/usercopy.h) \
186 | include/linux/bug.h \
187 | $(wildcard include/config/bug/on/data/corruption.h) \
188 | arch/x86/include/asm/bug.h \
189 | $(wildcard include/config/debug/bugverbose.h) \
190 | include/asm-generic/bug.h \
191 | $(wildcard include/config/bug.h) \
192 | $(wildcard include/config/generic/bug/relative/pointers.h) \
193 | include/linux/restart_block.h \
194 | $(wildcard include/config/compat.h) \
195 | arch/x86/include/asm/current.h \
196 | arch/x86/include/asm/thread_info.h \
197 | $(wildcard include/config/vm86.h) \
198 | $(wildcard include/config/frame/pointer.h) \
199 | $(wildcard include/config/ia32/emulation.h) \
200 | arch/x86/include/asm/page.h \
201 | arch/x86/include/asm/page_types.h \
202 | $(wildcard include/config/physical/start.h) \
203 | $(wildcard include/config/physical/align.h) \
204 | include/linux/mem_encrypt.h \
205 | $(wildcard include/config/arch/has/mem/encrypt.h) \
206 | arch/x86/include/asm/mem_encrypt.h \
207 | arch/x86/include/uapi/asm/bootparam.h \
208 | include/linux/screen_info.h \
209 | include/uapi/linux/screen_info.h \
210 | include/linux/apm_bios.h \
211 | include/uapi/linux/apm_bios.h \
212 | include/uapi/linux/ioctl.h \
213 | arch/x86/include/uapi/asm/ioctl.h \
214 | include/asm-generic/ioctl.h \
215 | include/uapi/asm-generic/ioctl.h \
216 | include/linux/edd.h \
217 | include/uapi/linux/edd.h \
218 | arch/x86/include/asm/ist.h \
219 | arch/x86/include/uapi/asm/ist.h \
220 | include/video/edid.h \
221 | $(wildcard include/config/x86.h) \
222 | include/uapi/video/edid.h \
223 | arch/x86/include/asm/page_64_types.h \
224 | $(wildcard include/config/randomize/memory.h) \
225 | $(wildcard include/config/randomize/base.h) \
226 | arch/x86/include/asm/kaslr.h \
227 | arch/x86/include/asm/page_64.h \
228 | $(wildcard include/config/debug/virtual.h) \
229 | $(wildcard include/config/flatmem.h) \
230 | $(wildcard include/config/x86/vsyscall/emulation.h) \
231 | include/linux/range.h \
232 | include/asm-generic/memory_model.h \
233 | $(wildcard include/config/discontigmem.h) \
234 | $(wildcard include/config/sparsemem/vmemmap.h) \
235 | $(wildcard include/config/sparsemem.h) \
236 | include/linux/pfn.h \
237 | include/asm-generic/getorder.h \
238 | arch/x86/include/asm/cpufeature.h \
239 | $(wildcard include/config/x86/feature/names.h) \
240 | $(wildcard include/config/x86/fast/feature/tests.h) \
241 | arch/x86/include/asm/processor.h \
242 | $(wildcard include/config/cc/stackprotector.h) \
243 | $(wildcard include/config/x86/debugctlmsr.h) \
244 | $(wildcard include/config/cpu/sup/amd.h) \
245 | $(wildcard include/config/xen.h) \
246 | arch/x86/include/asm/processor-flags.h \
247 | arch/x86/include/uapi/asm/processor-flags.h \
248 | arch/x86/include/asm/math_emu.h \
249 | arch/x86/include/asm/ptrace.h \
250 | arch/x86/include/asm/segment.h \
251 | $(wildcard include/config/xen/pv.h) \
252 | $(wildcard include/config/x86/32/lazy/gs.h) \
253 | arch/x86/include/uapi/asm/ptrace.h \
254 | arch/x86/include/uapi/asm/ptrace-abi.h \
255 | arch/x86/include/asm/paravirt_types.h \
256 | $(wildcard include/config/pgtable/levels.h) \
257 | $(wildcard include/config/paravirt/debug.h) \
258 | arch/x86/include/asm/desc_defs.h \
259 | arch/x86/include/asm/kmap_types.h \
260 | $(wildcard include/config/debug/highmem.h) \
261 | include/asm-generic/kmap_types.h \
262 | arch/x86/include/asm/pgtable_types.h \
263 | $(wildcard include/config/mem/soft/dirty.h) \
264 | $(wildcard include/config/proc/fs.h) \
265 | arch/x86/include/asm/pgtable_64_types.h \
266 | arch/x86/include/asm/sparsemem.h \
267 | include/asm-generic/pgtable-nop4d.h \
268 | arch/x86/include/asm/nospec-branch.h \
269 | $(wildcard include/config/retpoline.h) \
270 | arch/x86/include/asm/alternative-asm.h \
271 | arch/x86/include/asm/msr-index.h \
272 | $(wildcard include/config/control.h) \
273 | $(wildcard include/config/tdp/nominal.h) \
274 | $(wildcard include/config/tdp/level/1.h) \
275 | $(wildcard include/config/tdp/level/2.h) \
276 | $(wildcard include/config/tdp/control.h) \
277 | arch/x86/include/asm/spinlock_types.h \
278 | $(wildcard include/config/paravirt/spinlocks.h) \
279 | include/asm-generic/qspinlock_types.h \
280 | include/asm-generic/qrwlock_types.h \
281 | include/asm-generic/ptrace.h \
282 | arch/x86/include/uapi/asm/sigcontext.h \
283 | arch/x86/include/asm/msr.h \
284 | arch/x86/include/asm/msr-index.h \
285 | arch/x86/include/uapi/asm/errno.h \
286 | include/uapi/asm-generic/errno.h \
287 | include/uapi/asm-generic/errno-base.h \
288 | arch/x86/include/asm/cpumask.h \
289 | include/linux/cpumask.h \
290 | $(wildcard include/config/cpumask/offstack.h) \
291 | $(wildcard include/config/hotplug/cpu.h) \
292 | $(wildcard include/config/debug/per/cpu/maps.h) \
293 | include/linux/bitmap.h \
294 | include/linux/string.h \
295 | $(wildcard include/config/binary/printf.h) \
296 | $(wildcard include/config/fortify/source.h) \
297 | include/uapi/linux/string.h \
298 | arch/x86/include/asm/string.h \
299 | arch/x86/include/asm/string_64.h \
300 | $(wildcard include/config/x86/mce.h) \
301 | $(wildcard include/config/arch/has/uaccess/flushcache.h) \
302 | arch/x86/include/uapi/asm/msr.h \
303 | arch/x86/include/asm/atomic.h \
304 | arch/x86/include/asm/cmpxchg.h \
305 | arch/x86/include/asm/cmpxchg_64.h \
306 | arch/x86/include/asm/atomic64_64.h \
307 | include/linux/tracepoint-defs.h \
308 | include/linux/atomic.h \
309 | $(wildcard include/config/generic/atomic64.h) \
310 | include/asm-generic/atomic-long.h \
311 | include/linux/static_key.h \
312 | arch/x86/include/asm/paravirt.h \
313 | $(wildcard include/config/debug/entry.h) \
314 | arch/x86/include/asm/frame.h \
315 | arch/x86/include/asm/special_insns.h \
316 | arch/x86/include/asm/fpu/types.h \
317 | arch/x86/include/asm/unwind_hints.h \
318 | arch/x86/include/asm/orc_types.h \
319 | include/linux/personality.h \
320 | include/uapi/linux/personality.h \
321 | include/linux/math64.h \
322 | $(wildcard include/config/arch/supports/int128.h) \
323 | arch/x86/include/asm/div64.h \
324 | include/asm-generic/div64.h \
325 | include/linux/err.h \
326 | include/linux/irqflags.h \
327 | $(wildcard include/config/trace/irqflags.h) \
328 | $(wildcard include/config/irqsoff/tracer.h) \
329 | $(wildcard include/config/trace/irqflags/support.h) \
330 | arch/x86/include/asm/irqflags.h \
331 | include/linux/bottom_half.h \
332 | include/linux/spinlock_types.h \
333 | include/linux/lockdep.h \
334 | $(wildcard include/config/lockdep.h) \
335 | $(wildcard include/config/lock/stat.h) \
336 | include/linux/rwlock_types.h \
337 | arch/x86/include/asm/spinlock.h \
338 | arch/x86/include/asm/qspinlock.h \
339 | include/asm-generic/qspinlock.h \
340 | arch/x86/include/asm/qrwlock.h \
341 | include/asm-generic/qrwlock.h \
342 | include/linux/rwlock.h \
343 | include/linux/spinlock_api_smp.h \
344 | $(wildcard include/config/inline/spin/lock.h) \
345 | $(wildcard include/config/inline/spin/lock/bh.h) \
346 | $(wildcard include/config/inline/spin/lock/irq.h) \
347 | $(wildcard include/config/inline/spin/lock/irqsave.h) \
348 | $(wildcard include/config/inline/spin/trylock.h) \
349 | $(wildcard include/config/inline/spin/trylock/bh.h) \
350 | $(wildcard include/config/uninline/spin/unlock.h) \
351 | $(wildcard include/config/inline/spin/unlock/bh.h) \
352 | $(wildcard include/config/inline/spin/unlock/irq.h) \
353 | $(wildcard include/config/inline/spin/unlock/irqrestore.h) \
354 | $(wildcard include/config/generic/lockbreak.h) \
355 | include/linux/rwlock_api_smp.h \
356 | $(wildcard include/config/inline/read/lock.h) \
357 | $(wildcard include/config/inline/write/lock.h) \
358 | $(wildcard include/config/inline/read/lock/bh.h) \
359 | $(wildcard include/config/inline/write/lock/bh.h) \
360 | $(wildcard include/config/inline/read/lock/irq.h) \
361 | $(wildcard include/config/inline/write/lock/irq.h) \
362 | $(wildcard include/config/inline/read/lock/irqsave.h) \
363 | $(wildcard include/config/inline/write/lock/irqsave.h) \
364 | $(wildcard include/config/inline/read/trylock.h) \
365 | $(wildcard include/config/inline/write/trylock.h) \
366 | $(wildcard include/config/inline/read/unlock.h) \
367 | $(wildcard include/config/inline/write/unlock.h) \
368 | $(wildcard include/config/inline/read/unlock/bh.h) \
369 | $(wildcard include/config/inline/write/unlock/bh.h) \
370 | $(wildcard include/config/inline/read/unlock/irq.h) \
371 | $(wildcard include/config/inline/write/unlock/irq.h) \
372 | $(wildcard include/config/inline/read/unlock/irqrestore.h) \
373 | $(wildcard include/config/inline/write/unlock/irqrestore.h) \
374 | include/linux/time64.h \
375 | include/uapi/linux/time.h \
376 | include/linux/time32.h \
377 | include/linux/uidgid.h \
378 | $(wildcard include/config/multiuser.h) \
379 | $(wildcard include/config/user/ns.h) \
380 | include/linux/highuid.h \
381 | include/linux/kmod.h \
382 | include/linux/umh.h \
383 | include/linux/gfp.h \
384 | $(wildcard include/config/highmem.h) \
385 | $(wildcard include/config/zone/dma.h) \
386 | $(wildcard include/config/zone/dma32.h) \
387 | $(wildcard include/config/zone/device.h) \
388 | $(wildcard include/config/numa.h) \
389 | $(wildcard include/config/pm/sleep.h) \
390 | $(wildcard include/config/memory/isolation.h) \
391 | $(wildcard include/config/compaction.h) \
392 | $(wildcard include/config/cma.h) \
393 | include/linux/mmdebug.h \
394 | $(wildcard include/config/debug/vm.h) \
395 | $(wildcard include/config/debug/vm/pgflags.h) \
396 | include/linux/mmzone.h \
397 | $(wildcard include/config/force/max/zoneorder.h) \
398 | $(wildcard include/config/zsmalloc.h) \
399 | $(wildcard include/config/memcg.h) \
400 | $(wildcard include/config/memory/hotplug.h) \
401 | $(wildcard include/config/flat/node/mem/map.h) \
402 | $(wildcard include/config/page/extension.h) \
403 | $(wildcard include/config/no/bootmem.h) \
404 | $(wildcard include/config/numa/balancing.h) \
405 | $(wildcard include/config/deferred/struct/page/init.h) \
406 | $(wildcard include/config/transparent/hugepage.h) \
407 | $(wildcard include/config/have/memory/present.h) \
408 | $(wildcard include/config/have/memoryless/nodes.h) \
409 | $(wildcard include/config/need/node/memmap/size.h) \
410 | $(wildcard include/config/have/memblock/node/map.h) \
411 | $(wildcard include/config/need/multiple/nodes.h) \
412 | $(wildcard include/config/have/arch/early/pfn/to/nid.h) \
413 | $(wildcard include/config/sparsemem/extreme.h) \
414 | $(wildcard include/config/memory/hotremove.h) \
415 | $(wildcard include/config/have/arch/pfn/valid.h) \
416 | $(wildcard include/config/holes/in/zone.h) \
417 | $(wildcard include/config/arch/has/holes/memorymodel.h) \
418 | include/linux/wait.h \
419 | include/uapi/linux/wait.h \
420 | include/linux/numa.h \
421 | $(wildcard include/config/nodes/shift.h) \
422 | include/linux/nodemask.h \
423 | include/linux/pageblock-flags.h \
424 | $(wildcard include/config/hugetlb/page.h) \
425 | $(wildcard include/config/hugetlb/page/size/variable.h) \
426 | include/linux/page-flags-layout.h \
427 | include/generated/bounds.h \
428 | include/linux/memory_hotplug.h \
429 | $(wildcard include/config/arch/has/add/pages.h) \
430 | $(wildcard include/config/have/arch/nodedata/extension.h) \
431 | $(wildcard include/config/have/bootmem/info/node.h) \
432 | include/linux/notifier.h \
433 | include/linux/errno.h \
434 | include/uapi/linux/errno.h \
435 | include/linux/mutex.h \
436 | $(wildcard include/config/mutex/spin/on/owner.h) \
437 | $(wildcard include/config/debug/mutexes.h) \
438 | include/linux/osq_lock.h \
439 | include/linux/debug_locks.h \
440 | $(wildcard include/config/debug/locking/api/selftests.h) \
441 | include/linux/rwsem.h \
442 | $(wildcard include/config/rwsem/spin/on/owner.h) \
443 | $(wildcard include/config/rwsem/generic/spinlock.h) \
444 | arch/x86/include/asm/rwsem.h \
445 | include/linux/srcu.h \
446 | $(wildcard include/config/tiny/srcu.h) \
447 | $(wildcard include/config/tree/srcu.h) \
448 | $(wildcard include/config/srcu.h) \
449 | include/linux/rcupdate.h \
450 | $(wildcard include/config/preempt/rcu.h) \
451 | $(wildcard include/config/rcu/stall/common.h) \
452 | $(wildcard include/config/no/hz/full.h) \
453 | $(wildcard include/config/rcu/nocb/cpu.h) \
454 | $(wildcard include/config/tasks/rcu.h) \
455 | $(wildcard include/config/tree/rcu.h) \
456 | $(wildcard include/config/tiny/rcu.h) \
457 | $(wildcard include/config/debug/objects/rcu/head.h) \
458 | $(wildcard include/config/prove/rcu.h) \
459 | $(wildcard include/config/rcu/boost.h) \
460 | $(wildcard include/config/arch/weak/release/acquire.h) \
461 | include/linux/rcutree.h \
462 | include/linux/workqueue.h \
463 | $(wildcard include/config/debug/objects/work.h) \
464 | $(wildcard include/config/freezer.h) \
465 | $(wildcard include/config/wq/watchdog.h) \
466 | include/linux/timer.h \
467 | $(wildcard include/config/debug/objects/timers.h) \
468 | $(wildcard include/config/no/hz/common.h) \
469 | include/linux/ktime.h \
470 | include/linux/jiffies.h \
471 | include/linux/timex.h \
472 | include/uapi/linux/timex.h \
473 | include/uapi/linux/param.h \
474 | arch/x86/include/uapi/asm/param.h \
475 | include/asm-generic/param.h \
476 | $(wildcard include/config/hz.h) \
477 | include/uapi/asm-generic/param.h \
478 | arch/x86/include/asm/timex.h \
479 | arch/x86/include/asm/tsc.h \
480 | $(wildcard include/config/x86/tsc.h) \
481 | include/generated/timeconst.h \
482 | include/linux/timekeeping.h \
483 | include/linux/timekeeping32.h \
484 | include/linux/debugobjects.h \
485 | $(wildcard include/config/debug/objects.h) \
486 | $(wildcard include/config/debug/objects/free.h) \
487 | include/linux/rcu_segcblist.h \
488 | include/linux/srcutree.h \
489 | include/linux/rcu_node_tree.h \
490 | $(wildcard include/config/rcu/fanout.h) \
491 | $(wildcard include/config/rcu/fanout/leaf.h) \
492 | include/linux/completion.h \
493 | arch/x86/include/asm/mmzone.h \
494 | arch/x86/include/asm/mmzone_64.h \
495 | arch/x86/include/asm/smp.h \
496 | $(wildcard include/config/x86/local/apic.h) \
497 | $(wildcard include/config/x86/io/apic.h) \
498 | $(wildcard include/config/debug/nmi/selftest.h) \
499 | arch/x86/include/asm/mpspec.h \
500 | $(wildcard include/config/eisa.h) \
501 | $(wildcard include/config/x86/mpparse.h) \
502 | arch/x86/include/asm/mpspec_def.h \
503 | arch/x86/include/asm/x86_init.h \
504 | arch/x86/include/asm/apicdef.h \
505 | arch/x86/include/asm/apic.h \
506 | $(wildcard include/config/x86/x2apic.h) \
507 | arch/x86/include/asm/fixmap.h \
508 | $(wildcard include/config/provide/ohci1394/dma/init.h) \
509 | $(wildcard include/config/pci/mmconfig.h) \
510 | $(wildcard include/config/x86/intel/mid.h) \
511 | $(wildcard include/config/acpi/apei/ghes.h) \
512 | $(wildcard include/config/intel/txt.h) \
513 | arch/x86/include/asm/acpi.h \
514 | $(wildcard include/config/acpi/apei.h) \
515 | $(wildcard include/config/acpi.h) \
516 | $(wildcard include/config/acpi/numa.h) \
517 | include/acpi/pdc_intel.h \
518 | arch/x86/include/asm/numa.h \
519 | $(wildcard include/config/numa/emu.h) \
520 | arch/x86/include/asm/topology.h \
521 | $(wildcard include/config/sched/mc/prio.h) \
522 | include/asm-generic/topology.h \
523 | arch/x86/include/asm/mmu.h \
524 | $(wildcard include/config/modify/ldt/syscall.h) \
525 | arch/x86/include/asm/realmode.h \
526 | $(wildcard include/config/acpi/sleep.h) \
527 | arch/x86/include/asm/io.h \
528 | $(wildcard include/config/mtrr.h) \
529 | $(wildcard include/config/x86/pat.h) \
530 | arch/x86/include/generated/asm/early_ioremap.h \
531 | include/asm-generic/early_ioremap.h \
532 | $(wildcard include/config/generic/early/ioremap.h) \
533 | include/asm-generic/iomap.h \
534 | $(wildcard include/config/has/ioport/map.h) \
535 | $(wildcard include/config/pci.h) \
536 | $(wildcard include/config/generic/iomap.h) \
537 | include/asm-generic/pci_iomap.h \
538 | $(wildcard include/config/no/generic/pci/ioport/map.h) \
539 | $(wildcard include/config/generic/pci/iomap.h) \
540 | include/xen/xen.h \
541 | $(wildcard include/config/xen/pvh.h) \
542 | $(wildcard include/config/xen/dom0.h) \
543 | include/xen/interface/xen.h \
544 | arch/x86/include/asm/xen/interface.h \
545 | arch/x86/include/asm/xen/interface_64.h \
546 | arch/x86/include/asm/pvclock-abi.h \
547 | arch/x86/include/asm/xen/hypervisor.h \
548 | include/asm-generic/io.h \
549 | $(wildcard include/config/virt/to/bus.h) \
550 | include/linux/logic_pio.h \
551 | $(wildcard include/config/indirect/pio.h) \
552 | include/linux/fwnode.h \
553 | include/linux/vmalloc.h \
554 | include/linux/llist.h \
555 | $(wildcard include/config/arch/have/nmi/safe/cmpxchg.h) \
556 | include/linux/rbtree.h \
557 | arch/x86/include/uapi/asm/vsyscall.h \
558 | include/asm-generic/fixmap.h \
559 | arch/x86/include/asm/hardirq.h \
560 | $(wildcard include/config/kvm/intel.h) \
561 | $(wildcard include/config/have/kvm.h) \
562 | $(wildcard include/config/x86/thermal/vector.h) \
563 | $(wildcard include/config/x86/mce/threshold.h) \
564 | $(wildcard include/config/x86/mce/amd.h) \
565 | $(wildcard include/config/hyperv.h) \
566 | arch/x86/include/asm/io_apic.h \
567 | arch/x86/include/asm/irq_vectors.h \
568 | $(wildcard include/config/pci/msi.h) \
569 | include/linux/topology.h \
570 | $(wildcard include/config/use/percpu/numa/node/id.h) \
571 | $(wildcard include/config/sched/smt.h) \
572 | include/linux/smp.h \
573 | $(wildcard include/config/up/late/init.h) \
574 | include/linux/percpu.h \
575 | $(wildcard include/config/need/per/cpu/embed/first/chunk.h) \
576 | $(wildcard include/config/need/per/cpu/page/first/chunk.h) \
577 | include/linux/sysctl.h \
578 | $(wildcard include/config/sysctl.h) \
579 | include/uapi/linux/sysctl.h \
580 | include/linux/elf.h \
581 | arch/x86/include/asm/elf.h \
582 | $(wildcard include/config/x86/x32/abi.h) \
583 | arch/x86/include/asm/user.h \
584 | arch/x86/include/asm/user_64.h \
585 | arch/x86/include/uapi/asm/auxvec.h \
586 | arch/x86/include/asm/vdso.h \
587 | $(wildcard include/config/x86/x32.h) \
588 | include/linux/mm_types.h \
589 | $(wildcard include/config/have/cmpxchg/double.h) \
590 | $(wildcard include/config/have/aligned/struct/page.h) \
591 | $(wildcard include/config/userfaultfd.h) \
592 | $(wildcard include/config/have/arch/compat/mmap/bases.h) \
593 | $(wildcard include/config/membarrier.h) \
594 | $(wildcard include/config/aio.h) \
595 | $(wildcard include/config/mmu/notifier.h) \
596 | $(wildcard include/config/arch/want/batched/unmap/tlb/flush.h) \
597 | $(wildcard include/config/hmm.h) \
598 | include/linux/mm_types_task.h \
599 | $(wildcard include/config/split/ptlock/cpus.h) \
600 | $(wildcard include/config/arch/enable/split/pmd/ptlock.h) \
601 | arch/x86/include/asm/tlbbatch.h \
602 | include/linux/auxvec.h \
603 | include/uapi/linux/auxvec.h \
604 | include/linux/uprobes.h \
605 | $(wildcard include/config/uprobes.h) \
606 | arch/x86/include/asm/uprobes.h \
607 | include/uapi/linux/elf.h \
608 | include/uapi/linux/elf-em.h \
609 | include/linux/kobject.h \
610 | $(wildcard include/config/uevent/helper.h) \
611 | $(wildcard include/config/debug/kobject/release.h) \
612 | include/linux/sysfs.h \
613 | include/linux/kernfs.h \
614 | $(wildcard include/config/kernfs.h) \
615 | include/linux/idr.h \
616 | include/linux/radix-tree.h \
617 | $(wildcard include/config/radix/tree/multiorder.h) \
618 | include/linux/kobject_ns.h \
619 | include/linux/kref.h \
620 | include/linux/refcount.h \
621 | $(wildcard include/config/refcount/full.h) \
622 | arch/x86/include/asm/refcount.h \
623 | include/linux/moduleparam.h \
624 | $(wildcard include/config/alpha.h) \
625 | $(wildcard include/config/ia64.h) \
626 | $(wildcard include/config/ppc64.h) \
627 | include/linux/rbtree_latch.h \
628 | arch/x86/include/asm/module.h \
629 | $(wildcard include/config/unwinder/orc.h) \
630 | $(wildcard include/config/m486.h) \
631 | $(wildcard include/config/m586.h) \
632 | $(wildcard include/config/m586tsc.h) \
633 | $(wildcard include/config/m586mmx.h) \
634 | $(wildcard include/config/mcore2.h) \
635 | $(wildcard include/config/m686.h) \
636 | $(wildcard include/config/mpentiumii.h) \
637 | $(wildcard include/config/mpentiumiii.h) \
638 | $(wildcard include/config/mpentiumm.h) \
639 | $(wildcard include/config/mpentium4.h) \
640 | $(wildcard include/config/mk6.h) \
641 | $(wildcard include/config/mk8.h) \
642 | $(wildcard include/config/melan.h) \
643 | $(wildcard include/config/mcrusoe.h) \
644 | $(wildcard include/config/mefficeon.h) \
645 | $(wildcard include/config/mwinchipc6.h) \
646 | $(wildcard include/config/mwinchip3d.h) \
647 | $(wildcard include/config/mcyrixiii.h) \
648 | $(wildcard include/config/mviac3/2.h) \
649 | $(wildcard include/config/mviac7.h) \
650 | $(wildcard include/config/mgeodegx1.h) \
651 | $(wildcard include/config/mgeode/lx.h) \
652 | include/asm-generic/module.h \
653 | $(wildcard include/config/have/mod/arch/specific.h) \
654 | $(wildcard include/config/modules/use/elf/rel.h) \
655 | $(wildcard include/config/modules/use/elf/rela.h) \
656 | arch/x86/include/asm/orc_types.h \
657 | include/linux/vermagic.h \
658 | include/generated/utsrelease.h \
659 |
660 | /home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop-packet.mod.o: $(deps_/home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop-packet.mod.o)
661 |
662 | $(deps_/home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop-packet.mod.o):
663 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step1/.drop-packet.o.cmd:
--------------------------------------------------------------------------------
1 | cmd_/home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop-packet.o := ld -m elf_x86_64 -z max-page-size=0x200000 -r -o /home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop-packet.o /home/xiebaoyou/study/陈老师/drop-packet/src/step1/main.o
2 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step1/.main.o.cmd:
--------------------------------------------------------------------------------
1 | cmd_/home/xiebaoyou/study/陈老师/drop-packet/src/step1/main.o := gcc -Wp,-MD,/home/xiebaoyou/study/陈老师/drop-packet/src/step1/.main.o.d -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/5/include -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -Iubuntu/include -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-PIE -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -DCONFIG_X86_X32_ABI -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_AVX512=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -DRETPOLINE -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -DCC_HAVE_ASM_GOTO -Wframe-larger-than=1024 -fstack-protector-strong -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -pg -mfentry -DCC_USING_FENTRY -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fno-merge-all-constants -fmerge-constants -fno-stack-check -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -I/home/xiebaoyou/study/陈老师/drop-packet/src/step1/ -DMODULE -DUBUNTU_1604 -DKBUILD_BASENAME='"main"' -DKBUILD_MODNAME='"drop_packet"' -c -o /home/xiebaoyou/study/陈老师/drop-packet/src/step1/main.o /home/xiebaoyou/study/陈老师/drop-packet/src/step1/main.c
2 |
3 | source_/home/xiebaoyou/study/陈老师/drop-packet/src/step1/main.o := /home/xiebaoyou/study/陈老师/drop-packet/src/step1/main.c
4 |
5 | deps_/home/xiebaoyou/study/陈老师/drop-packet/src/step1/main.o := \
6 | include/linux/compiler_types.h \
7 | $(wildcard include/config/enable/must/check.h) \
8 | $(wildcard include/config/enable/warn/deprecated.h) \
9 | include/linux/compiler-gcc.h \
10 | $(wildcard include/config/arch/supports/optimized/inlining.h) \
11 | $(wildcard include/config/optimize/inlining.h) \
12 | $(wildcard include/config/gcov/kernel.h) \
13 | $(wildcard include/config/arch/use/builtin/bswap.h) \
14 | include/generated/uapi/linux/version.h \
15 | include/linux/module.h \
16 | $(wildcard include/config/modules.h) \
17 | $(wildcard include/config/sysfs.h) \
18 | $(wildcard include/config/modules/tree/lookup.h) \
19 | $(wildcard include/config/livepatch.h) \
20 | $(wildcard include/config/unused/symbols.h) \
21 | $(wildcard include/config/module/sig.h) \
22 | $(wildcard include/config/generic/bug.h) \
23 | $(wildcard include/config/kallsyms.h) \
24 | $(wildcard include/config/smp.h) \
25 | $(wildcard include/config/tracepoints.h) \
26 | $(wildcard include/config/tracing.h) \
27 | $(wildcard include/config/event/tracing.h) \
28 | $(wildcard include/config/ftrace/mcount/record.h) \
29 | $(wildcard include/config/module/unload.h) \
30 | $(wildcard include/config/constructors.h) \
31 | $(wildcard include/config/strict/module/rwx.h) \
32 | include/linux/list.h \
33 | $(wildcard include/config/debug/list.h) \
34 | include/linux/types.h \
35 | $(wildcard include/config/have/uid16.h) \
36 | $(wildcard include/config/uid16.h) \
37 | $(wildcard include/config/lbdaf.h) \
38 | $(wildcard include/config/arch/dma/addr/t/64bit.h) \
39 | $(wildcard include/config/phys/addr/t/64bit.h) \
40 | $(wildcard include/config/64bit.h) \
41 | include/uapi/linux/types.h \
42 | arch/x86/include/uapi/asm/types.h \
43 | include/uapi/asm-generic/types.h \
44 | include/asm-generic/int-ll64.h \
45 | include/uapi/asm-generic/int-ll64.h \
46 | arch/x86/include/uapi/asm/bitsperlong.h \
47 | include/asm-generic/bitsperlong.h \
48 | include/uapi/asm-generic/bitsperlong.h \
49 | include/uapi/linux/posix_types.h \
50 | include/linux/stddef.h \
51 | include/uapi/linux/stddef.h \
52 | arch/x86/include/asm/posix_types.h \
53 | $(wildcard include/config/x86/32.h) \
54 | arch/x86/include/uapi/asm/posix_types_64.h \
55 | include/uapi/asm-generic/posix_types.h \
56 | include/linux/poison.h \
57 | $(wildcard include/config/illegal/pointer/value.h) \
58 | $(wildcard include/config/page/poisoning/zero.h) \
59 | include/uapi/linux/const.h \
60 | include/linux/kernel.h \
61 | $(wildcard include/config/preempt/voluntary.h) \
62 | $(wildcard include/config/debug/atomic/sleep.h) \
63 | $(wildcard include/config/mmu.h) \
64 | $(wildcard include/config/prove/locking.h) \
65 | $(wildcard include/config/arch/has/refcount.h) \
66 | $(wildcard include/config/lock/down/kernel.h) \
67 | $(wildcard include/config/panic/timeout.h) \
68 | /usr/lib/gcc/x86_64-linux-gnu/5/include/stdarg.h \
69 | include/linux/linkage.h \
70 | include/linux/stringify.h \
71 | include/linux/export.h \
72 | $(wildcard include/config/have/underscore/symbol/prefix.h) \
73 | $(wildcard include/config/modversions.h) \
74 | $(wildcard include/config/module/rel/crcs.h) \
75 | $(wildcard include/config/trim/unused/ksyms.h) \
76 | arch/x86/include/asm/linkage.h \
77 | $(wildcard include/config/x86/64.h) \
78 | $(wildcard include/config/x86/alignment/16.h) \
79 | include/linux/compiler.h \
80 | $(wildcard include/config/trace/branch/profiling.h) \
81 | $(wildcard include/config/profile/all/branches.h) \
82 | $(wildcard include/config/stack/validation.h) \
83 | $(wildcard include/config/kasan.h) \
84 | arch/x86/include/asm/barrier.h \
85 | $(wildcard include/config/x86/ppro/fence.h) \
86 | arch/x86/include/asm/alternative.h \
87 | arch/x86/include/asm/asm.h \
88 | arch/x86/include/asm/nops.h \
89 | $(wildcard include/config/mk7.h) \
90 | $(wildcard include/config/x86/p6/nop.h) \
91 | include/asm-generic/barrier.h \
92 | include/linux/bitops.h \
93 | arch/x86/include/asm/bitops.h \
94 | $(wildcard include/config/x86/cmov.h) \
95 | arch/x86/include/asm/rmwcc.h \
96 | include/asm-generic/bitops/find.h \
97 | $(wildcard include/config/generic/find/first/bit.h) \
98 | include/asm-generic/bitops/sched.h \
99 | arch/x86/include/asm/arch_hweight.h \
100 | arch/x86/include/asm/cpufeatures.h \
101 | arch/x86/include/asm/required-features.h \
102 | $(wildcard include/config/x86/minimum/cpu/family.h) \
103 | $(wildcard include/config/math/emulation.h) \
104 | $(wildcard include/config/x86/pae.h) \
105 | $(wildcard include/config/x86/cmpxchg64.h) \
106 | $(wildcard include/config/x86/use/3dnow.h) \
107 | $(wildcard include/config/matom.h) \
108 | $(wildcard include/config/x86/5level.h) \
109 | $(wildcard include/config/paravirt.h) \
110 | arch/x86/include/asm/disabled-features.h \
111 | $(wildcard include/config/x86/intel/mpx.h) \
112 | $(wildcard include/config/x86/intel/umip.h) \
113 | $(wildcard include/config/x86/intel/memory/protection/keys.h) \
114 | $(wildcard include/config/page/table/isolation.h) \
115 | include/asm-generic/bitops/const_hweight.h \
116 | include/asm-generic/bitops/le.h \
117 | arch/x86/include/uapi/asm/byteorder.h \
118 | include/linux/byteorder/little_endian.h \
119 | $(wildcard include/config/cpu/big/endian.h) \
120 | include/uapi/linux/byteorder/little_endian.h \
121 | include/linux/swab.h \
122 | include/uapi/linux/swab.h \
123 | arch/x86/include/uapi/asm/swab.h \
124 | include/linux/byteorder/generic.h \
125 | include/asm-generic/bitops/ext2-atomic-setbit.h \
126 | include/linux/log2.h \
127 | $(wildcard include/config/arch/has/ilog2/u32.h) \
128 | $(wildcard include/config/arch/has/ilog2/u64.h) \
129 | include/linux/typecheck.h \
130 | include/linux/printk.h \
131 | $(wildcard include/config/message/loglevel/default.h) \
132 | $(wildcard include/config/console/loglevel/default.h) \
133 | $(wildcard include/config/early/printk.h) \
134 | $(wildcard include/config/printk/nmi.h) \
135 | $(wildcard include/config/printk.h) \
136 | $(wildcard include/config/kmsg/ids.h) \
137 | $(wildcard include/config/dynamic/debug.h) \
138 | include/linux/init.h \
139 | $(wildcard include/config/strict/kernel/rwx.h) \
140 | include/linux/kern_levels.h \
141 | include/linux/cache.h \
142 | $(wildcard include/config/arch/has/cache/line/size.h) \
143 | include/uapi/linux/kernel.h \
144 | include/uapi/linux/sysinfo.h \
145 | arch/x86/include/asm/cache.h \
146 | $(wildcard include/config/x86/l1/cache/shift.h) \
147 | $(wildcard include/config/x86/internode/cache/shift.h) \
148 | $(wildcard include/config/x86/vsmp.h) \
149 | include/linux/dynamic_debug.h \
150 | $(wildcard include/config/jump/label.h) \
151 | include/linux/jump_label.h \
152 | arch/x86/include/asm/jump_label.h \
153 | include/linux/build_bug.h \
154 | include/linux/stat.h \
155 | arch/x86/include/uapi/asm/stat.h \
156 | include/uapi/linux/stat.h \
157 | include/linux/time.h \
158 | $(wildcard include/config/arch/uses/gettimeoffset.h) \
159 | include/linux/seqlock.h \
160 | $(wildcard include/config/debug/lock/alloc.h) \
161 | include/linux/spinlock.h \
162 | $(wildcard include/config/debug/spinlock.h) \
163 | $(wildcard include/config/preempt.h) \
164 | include/linux/preempt.h \
165 | $(wildcard include/config/preempt/count.h) \
166 | $(wildcard include/config/debug/preempt.h) \
167 | $(wildcard include/config/preempt/tracer.h) \
168 | $(wildcard include/config/preempt/notifiers.h) \
169 | arch/x86/include/asm/preempt.h \
170 | arch/x86/include/asm/percpu.h \
171 | $(wildcard include/config/x86/64/smp.h) \
172 | include/asm-generic/percpu.h \
173 | $(wildcard include/config/have/setup/per/cpu/area.h) \
174 | include/linux/threads.h \
175 | $(wildcard include/config/nr/cpus.h) \
176 | $(wildcard include/config/base/small.h) \
177 | include/linux/percpu-defs.h \
178 | $(wildcard include/config/debug/force/weak/per/cpu.h) \
179 | $(wildcard include/config/virtualization.h) \
180 | $(wildcard include/config/amd/mem/encrypt.h) \
181 | include/linux/thread_info.h \
182 | $(wildcard include/config/thread/info/in/task.h) \
183 | $(wildcard include/config/debug/stack/usage.h) \
184 | $(wildcard include/config/debug/kmemleak.h) \
185 | $(wildcard include/config/have/arch/within/stack/frames.h) \
186 | $(wildcard include/config/hardened/usercopy.h) \
187 | include/linux/bug.h \
188 | $(wildcard include/config/bug/on/data/corruption.h) \
189 | arch/x86/include/asm/bug.h \
190 | $(wildcard include/config/debug/bugverbose.h) \
191 | include/asm-generic/bug.h \
192 | $(wildcard include/config/bug.h) \
193 | $(wildcard include/config/generic/bug/relative/pointers.h) \
194 | include/linux/restart_block.h \
195 | $(wildcard include/config/compat.h) \
196 | arch/x86/include/asm/current.h \
197 | arch/x86/include/asm/thread_info.h \
198 | $(wildcard include/config/vm86.h) \
199 | $(wildcard include/config/frame/pointer.h) \
200 | $(wildcard include/config/ia32/emulation.h) \
201 | arch/x86/include/asm/page.h \
202 | arch/x86/include/asm/page_types.h \
203 | $(wildcard include/config/physical/start.h) \
204 | $(wildcard include/config/physical/align.h) \
205 | include/linux/mem_encrypt.h \
206 | $(wildcard include/config/arch/has/mem/encrypt.h) \
207 | arch/x86/include/asm/mem_encrypt.h \
208 | arch/x86/include/uapi/asm/bootparam.h \
209 | include/linux/screen_info.h \
210 | include/uapi/linux/screen_info.h \
211 | include/linux/apm_bios.h \
212 | include/uapi/linux/apm_bios.h \
213 | include/uapi/linux/ioctl.h \
214 | arch/x86/include/uapi/asm/ioctl.h \
215 | include/asm-generic/ioctl.h \
216 | include/uapi/asm-generic/ioctl.h \
217 | include/linux/edd.h \
218 | include/uapi/linux/edd.h \
219 | arch/x86/include/asm/ist.h \
220 | arch/x86/include/uapi/asm/ist.h \
221 | include/video/edid.h \
222 | $(wildcard include/config/x86.h) \
223 | include/uapi/video/edid.h \
224 | arch/x86/include/asm/page_64_types.h \
225 | $(wildcard include/config/randomize/memory.h) \
226 | $(wildcard include/config/randomize/base.h) \
227 | arch/x86/include/asm/kaslr.h \
228 | arch/x86/include/asm/page_64.h \
229 | $(wildcard include/config/debug/virtual.h) \
230 | $(wildcard include/config/flatmem.h) \
231 | $(wildcard include/config/x86/vsyscall/emulation.h) \
232 | include/linux/range.h \
233 | include/asm-generic/memory_model.h \
234 | $(wildcard include/config/discontigmem.h) \
235 | $(wildcard include/config/sparsemem/vmemmap.h) \
236 | $(wildcard include/config/sparsemem.h) \
237 | include/linux/pfn.h \
238 | include/asm-generic/getorder.h \
239 | arch/x86/include/asm/cpufeature.h \
240 | $(wildcard include/config/x86/feature/names.h) \
241 | $(wildcard include/config/x86/fast/feature/tests.h) \
242 | arch/x86/include/asm/processor.h \
243 | $(wildcard include/config/cc/stackprotector.h) \
244 | $(wildcard include/config/x86/debugctlmsr.h) \
245 | $(wildcard include/config/cpu/sup/amd.h) \
246 | $(wildcard include/config/xen.h) \
247 | arch/x86/include/asm/processor-flags.h \
248 | arch/x86/include/uapi/asm/processor-flags.h \
249 | arch/x86/include/asm/math_emu.h \
250 | arch/x86/include/asm/ptrace.h \
251 | arch/x86/include/asm/segment.h \
252 | $(wildcard include/config/xen/pv.h) \
253 | $(wildcard include/config/x86/32/lazy/gs.h) \
254 | arch/x86/include/uapi/asm/ptrace.h \
255 | arch/x86/include/uapi/asm/ptrace-abi.h \
256 | arch/x86/include/asm/paravirt_types.h \
257 | $(wildcard include/config/pgtable/levels.h) \
258 | $(wildcard include/config/paravirt/debug.h) \
259 | arch/x86/include/asm/desc_defs.h \
260 | arch/x86/include/asm/kmap_types.h \
261 | $(wildcard include/config/debug/highmem.h) \
262 | include/asm-generic/kmap_types.h \
263 | arch/x86/include/asm/pgtable_types.h \
264 | $(wildcard include/config/mem/soft/dirty.h) \
265 | $(wildcard include/config/proc/fs.h) \
266 | arch/x86/include/asm/pgtable_64_types.h \
267 | arch/x86/include/asm/sparsemem.h \
268 | include/asm-generic/pgtable-nop4d.h \
269 | arch/x86/include/asm/nospec-branch.h \
270 | $(wildcard include/config/retpoline.h) \
271 | arch/x86/include/asm/alternative-asm.h \
272 | arch/x86/include/asm/msr-index.h \
273 | $(wildcard include/config/control.h) \
274 | $(wildcard include/config/tdp/nominal.h) \
275 | $(wildcard include/config/tdp/level/1.h) \
276 | $(wildcard include/config/tdp/level/2.h) \
277 | $(wildcard include/config/tdp/control.h) \
278 | arch/x86/include/asm/spinlock_types.h \
279 | $(wildcard include/config/paravirt/spinlocks.h) \
280 | include/asm-generic/qspinlock_types.h \
281 | include/asm-generic/qrwlock_types.h \
282 | include/asm-generic/ptrace.h \
283 | arch/x86/include/uapi/asm/sigcontext.h \
284 | arch/x86/include/asm/msr.h \
285 | arch/x86/include/asm/msr-index.h \
286 | arch/x86/include/uapi/asm/errno.h \
287 | include/uapi/asm-generic/errno.h \
288 | include/uapi/asm-generic/errno-base.h \
289 | arch/x86/include/asm/cpumask.h \
290 | include/linux/cpumask.h \
291 | $(wildcard include/config/cpumask/offstack.h) \
292 | $(wildcard include/config/hotplug/cpu.h) \
293 | $(wildcard include/config/debug/per/cpu/maps.h) \
294 | include/linux/bitmap.h \
295 | include/linux/string.h \
296 | $(wildcard include/config/binary/printf.h) \
297 | $(wildcard include/config/fortify/source.h) \
298 | include/uapi/linux/string.h \
299 | arch/x86/include/asm/string.h \
300 | arch/x86/include/asm/string_64.h \
301 | $(wildcard include/config/x86/mce.h) \
302 | $(wildcard include/config/arch/has/uaccess/flushcache.h) \
303 | arch/x86/include/uapi/asm/msr.h \
304 | arch/x86/include/asm/atomic.h \
305 | arch/x86/include/asm/cmpxchg.h \
306 | arch/x86/include/asm/cmpxchg_64.h \
307 | arch/x86/include/asm/atomic64_64.h \
308 | include/linux/tracepoint-defs.h \
309 | include/linux/atomic.h \
310 | $(wildcard include/config/generic/atomic64.h) \
311 | include/asm-generic/atomic-long.h \
312 | include/linux/static_key.h \
313 | arch/x86/include/asm/paravirt.h \
314 | $(wildcard include/config/debug/entry.h) \
315 | arch/x86/include/asm/frame.h \
316 | arch/x86/include/asm/special_insns.h \
317 | arch/x86/include/asm/fpu/types.h \
318 | arch/x86/include/asm/unwind_hints.h \
319 | arch/x86/include/asm/orc_types.h \
320 | include/linux/personality.h \
321 | include/uapi/linux/personality.h \
322 | include/linux/math64.h \
323 | $(wildcard include/config/arch/supports/int128.h) \
324 | arch/x86/include/asm/div64.h \
325 | include/asm-generic/div64.h \
326 | include/linux/err.h \
327 | include/linux/irqflags.h \
328 | $(wildcard include/config/trace/irqflags.h) \
329 | $(wildcard include/config/irqsoff/tracer.h) \
330 | $(wildcard include/config/trace/irqflags/support.h) \
331 | arch/x86/include/asm/irqflags.h \
332 | include/linux/bottom_half.h \
333 | include/linux/spinlock_types.h \
334 | include/linux/lockdep.h \
335 | $(wildcard include/config/lockdep.h) \
336 | $(wildcard include/config/lock/stat.h) \
337 | include/linux/rwlock_types.h \
338 | arch/x86/include/asm/spinlock.h \
339 | arch/x86/include/asm/qspinlock.h \
340 | include/asm-generic/qspinlock.h \
341 | arch/x86/include/asm/qrwlock.h \
342 | include/asm-generic/qrwlock.h \
343 | include/linux/rwlock.h \
344 | include/linux/spinlock_api_smp.h \
345 | $(wildcard include/config/inline/spin/lock.h) \
346 | $(wildcard include/config/inline/spin/lock/bh.h) \
347 | $(wildcard include/config/inline/spin/lock/irq.h) \
348 | $(wildcard include/config/inline/spin/lock/irqsave.h) \
349 | $(wildcard include/config/inline/spin/trylock.h) \
350 | $(wildcard include/config/inline/spin/trylock/bh.h) \
351 | $(wildcard include/config/uninline/spin/unlock.h) \
352 | $(wildcard include/config/inline/spin/unlock/bh.h) \
353 | $(wildcard include/config/inline/spin/unlock/irq.h) \
354 | $(wildcard include/config/inline/spin/unlock/irqrestore.h) \
355 | $(wildcard include/config/generic/lockbreak.h) \
356 | include/linux/rwlock_api_smp.h \
357 | $(wildcard include/config/inline/read/lock.h) \
358 | $(wildcard include/config/inline/write/lock.h) \
359 | $(wildcard include/config/inline/read/lock/bh.h) \
360 | $(wildcard include/config/inline/write/lock/bh.h) \
361 | $(wildcard include/config/inline/read/lock/irq.h) \
362 | $(wildcard include/config/inline/write/lock/irq.h) \
363 | $(wildcard include/config/inline/read/lock/irqsave.h) \
364 | $(wildcard include/config/inline/write/lock/irqsave.h) \
365 | $(wildcard include/config/inline/read/trylock.h) \
366 | $(wildcard include/config/inline/write/trylock.h) \
367 | $(wildcard include/config/inline/read/unlock.h) \
368 | $(wildcard include/config/inline/write/unlock.h) \
369 | $(wildcard include/config/inline/read/unlock/bh.h) \
370 | $(wildcard include/config/inline/write/unlock/bh.h) \
371 | $(wildcard include/config/inline/read/unlock/irq.h) \
372 | $(wildcard include/config/inline/write/unlock/irq.h) \
373 | $(wildcard include/config/inline/read/unlock/irqrestore.h) \
374 | $(wildcard include/config/inline/write/unlock/irqrestore.h) \
375 | include/linux/time64.h \
376 | include/uapi/linux/time.h \
377 | include/linux/time32.h \
378 | include/linux/uidgid.h \
379 | $(wildcard include/config/multiuser.h) \
380 | $(wildcard include/config/user/ns.h) \
381 | include/linux/highuid.h \
382 | include/linux/kmod.h \
383 | include/linux/umh.h \
384 | include/linux/gfp.h \
385 | $(wildcard include/config/highmem.h) \
386 | $(wildcard include/config/zone/dma.h) \
387 | $(wildcard include/config/zone/dma32.h) \
388 | $(wildcard include/config/zone/device.h) \
389 | $(wildcard include/config/numa.h) \
390 | $(wildcard include/config/pm/sleep.h) \
391 | $(wildcard include/config/memory/isolation.h) \
392 | $(wildcard include/config/compaction.h) \
393 | $(wildcard include/config/cma.h) \
394 | include/linux/mmdebug.h \
395 | $(wildcard include/config/debug/vm.h) \
396 | $(wildcard include/config/debug/vm/pgflags.h) \
397 | include/linux/mmzone.h \
398 | $(wildcard include/config/force/max/zoneorder.h) \
399 | $(wildcard include/config/zsmalloc.h) \
400 | $(wildcard include/config/memcg.h) \
401 | $(wildcard include/config/memory/hotplug.h) \
402 | $(wildcard include/config/flat/node/mem/map.h) \
403 | $(wildcard include/config/page/extension.h) \
404 | $(wildcard include/config/no/bootmem.h) \
405 | $(wildcard include/config/numa/balancing.h) \
406 | $(wildcard include/config/deferred/struct/page/init.h) \
407 | $(wildcard include/config/transparent/hugepage.h) \
408 | $(wildcard include/config/have/memory/present.h) \
409 | $(wildcard include/config/have/memoryless/nodes.h) \
410 | $(wildcard include/config/need/node/memmap/size.h) \
411 | $(wildcard include/config/have/memblock/node/map.h) \
412 | $(wildcard include/config/need/multiple/nodes.h) \
413 | $(wildcard include/config/have/arch/early/pfn/to/nid.h) \
414 | $(wildcard include/config/sparsemem/extreme.h) \
415 | $(wildcard include/config/memory/hotremove.h) \
416 | $(wildcard include/config/have/arch/pfn/valid.h) \
417 | $(wildcard include/config/holes/in/zone.h) \
418 | $(wildcard include/config/arch/has/holes/memorymodel.h) \
419 | include/linux/wait.h \
420 | include/uapi/linux/wait.h \
421 | include/linux/numa.h \
422 | $(wildcard include/config/nodes/shift.h) \
423 | include/linux/nodemask.h \
424 | include/linux/pageblock-flags.h \
425 | $(wildcard include/config/hugetlb/page.h) \
426 | $(wildcard include/config/hugetlb/page/size/variable.h) \
427 | include/linux/page-flags-layout.h \
428 | include/generated/bounds.h \
429 | include/linux/memory_hotplug.h \
430 | $(wildcard include/config/arch/has/add/pages.h) \
431 | $(wildcard include/config/have/arch/nodedata/extension.h) \
432 | $(wildcard include/config/have/bootmem/info/node.h) \
433 | include/linux/notifier.h \
434 | include/linux/errno.h \
435 | include/uapi/linux/errno.h \
436 | include/linux/mutex.h \
437 | $(wildcard include/config/mutex/spin/on/owner.h) \
438 | $(wildcard include/config/debug/mutexes.h) \
439 | include/linux/osq_lock.h \
440 | include/linux/debug_locks.h \
441 | $(wildcard include/config/debug/locking/api/selftests.h) \
442 | include/linux/rwsem.h \
443 | $(wildcard include/config/rwsem/spin/on/owner.h) \
444 | $(wildcard include/config/rwsem/generic/spinlock.h) \
445 | arch/x86/include/asm/rwsem.h \
446 | include/linux/srcu.h \
447 | $(wildcard include/config/tiny/srcu.h) \
448 | $(wildcard include/config/tree/srcu.h) \
449 | $(wildcard include/config/srcu.h) \
450 | include/linux/rcupdate.h \
451 | $(wildcard include/config/preempt/rcu.h) \
452 | $(wildcard include/config/rcu/stall/common.h) \
453 | $(wildcard include/config/no/hz/full.h) \
454 | $(wildcard include/config/rcu/nocb/cpu.h) \
455 | $(wildcard include/config/tasks/rcu.h) \
456 | $(wildcard include/config/tree/rcu.h) \
457 | $(wildcard include/config/tiny/rcu.h) \
458 | $(wildcard include/config/debug/objects/rcu/head.h) \
459 | $(wildcard include/config/prove/rcu.h) \
460 | $(wildcard include/config/rcu/boost.h) \
461 | $(wildcard include/config/arch/weak/release/acquire.h) \
462 | include/linux/rcutree.h \
463 | include/linux/workqueue.h \
464 | $(wildcard include/config/debug/objects/work.h) \
465 | $(wildcard include/config/freezer.h) \
466 | $(wildcard include/config/wq/watchdog.h) \
467 | include/linux/timer.h \
468 | $(wildcard include/config/debug/objects/timers.h) \
469 | $(wildcard include/config/no/hz/common.h) \
470 | include/linux/ktime.h \
471 | include/linux/jiffies.h \
472 | include/linux/timex.h \
473 | include/uapi/linux/timex.h \
474 | include/uapi/linux/param.h \
475 | arch/x86/include/uapi/asm/param.h \
476 | include/asm-generic/param.h \
477 | $(wildcard include/config/hz.h) \
478 | include/uapi/asm-generic/param.h \
479 | arch/x86/include/asm/timex.h \
480 | arch/x86/include/asm/tsc.h \
481 | $(wildcard include/config/x86/tsc.h) \
482 | include/generated/timeconst.h \
483 | include/linux/timekeeping.h \
484 | include/linux/timekeeping32.h \
485 | include/linux/debugobjects.h \
486 | $(wildcard include/config/debug/objects.h) \
487 | $(wildcard include/config/debug/objects/free.h) \
488 | include/linux/rcu_segcblist.h \
489 | include/linux/srcutree.h \
490 | include/linux/rcu_node_tree.h \
491 | $(wildcard include/config/rcu/fanout.h) \
492 | $(wildcard include/config/rcu/fanout/leaf.h) \
493 | include/linux/completion.h \
494 | arch/x86/include/asm/mmzone.h \
495 | arch/x86/include/asm/mmzone_64.h \
496 | arch/x86/include/asm/smp.h \
497 | $(wildcard include/config/x86/local/apic.h) \
498 | $(wildcard include/config/x86/io/apic.h) \
499 | $(wildcard include/config/debug/nmi/selftest.h) \
500 | arch/x86/include/asm/mpspec.h \
501 | $(wildcard include/config/eisa.h) \
502 | $(wildcard include/config/x86/mpparse.h) \
503 | arch/x86/include/asm/mpspec_def.h \
504 | arch/x86/include/asm/x86_init.h \
505 | arch/x86/include/asm/apicdef.h \
506 | arch/x86/include/asm/apic.h \
507 | $(wildcard include/config/x86/x2apic.h) \
508 | arch/x86/include/asm/fixmap.h \
509 | $(wildcard include/config/provide/ohci1394/dma/init.h) \
510 | $(wildcard include/config/pci/mmconfig.h) \
511 | $(wildcard include/config/x86/intel/mid.h) \
512 | $(wildcard include/config/acpi/apei/ghes.h) \
513 | $(wildcard include/config/intel/txt.h) \
514 | arch/x86/include/asm/acpi.h \
515 | $(wildcard include/config/acpi/apei.h) \
516 | $(wildcard include/config/acpi.h) \
517 | $(wildcard include/config/acpi/numa.h) \
518 | include/acpi/pdc_intel.h \
519 | arch/x86/include/asm/numa.h \
520 | $(wildcard include/config/numa/emu.h) \
521 | arch/x86/include/asm/topology.h \
522 | $(wildcard include/config/sched/mc/prio.h) \
523 | include/asm-generic/topology.h \
524 | arch/x86/include/asm/mmu.h \
525 | $(wildcard include/config/modify/ldt/syscall.h) \
526 | arch/x86/include/asm/realmode.h \
527 | $(wildcard include/config/acpi/sleep.h) \
528 | arch/x86/include/asm/io.h \
529 | $(wildcard include/config/mtrr.h) \
530 | $(wildcard include/config/x86/pat.h) \
531 | arch/x86/include/generated/asm/early_ioremap.h \
532 | include/asm-generic/early_ioremap.h \
533 | $(wildcard include/config/generic/early/ioremap.h) \
534 | include/asm-generic/iomap.h \
535 | $(wildcard include/config/has/ioport/map.h) \
536 | $(wildcard include/config/pci.h) \
537 | $(wildcard include/config/generic/iomap.h) \
538 | include/asm-generic/pci_iomap.h \
539 | $(wildcard include/config/no/generic/pci/ioport/map.h) \
540 | $(wildcard include/config/generic/pci/iomap.h) \
541 | include/xen/xen.h \
542 | $(wildcard include/config/xen/pvh.h) \
543 | $(wildcard include/config/xen/dom0.h) \
544 | include/xen/interface/xen.h \
545 | arch/x86/include/asm/xen/interface.h \
546 | arch/x86/include/asm/xen/interface_64.h \
547 | arch/x86/include/asm/pvclock-abi.h \
548 | arch/x86/include/asm/xen/hypervisor.h \
549 | include/asm-generic/io.h \
550 | $(wildcard include/config/virt/to/bus.h) \
551 | include/linux/logic_pio.h \
552 | $(wildcard include/config/indirect/pio.h) \
553 | include/linux/fwnode.h \
554 | include/linux/vmalloc.h \
555 | include/linux/llist.h \
556 | $(wildcard include/config/arch/have/nmi/safe/cmpxchg.h) \
557 | include/linux/rbtree.h \
558 | arch/x86/include/uapi/asm/vsyscall.h \
559 | include/asm-generic/fixmap.h \
560 | arch/x86/include/asm/hardirq.h \
561 | $(wildcard include/config/kvm/intel.h) \
562 | $(wildcard include/config/have/kvm.h) \
563 | $(wildcard include/config/x86/thermal/vector.h) \
564 | $(wildcard include/config/x86/mce/threshold.h) \
565 | $(wildcard include/config/x86/mce/amd.h) \
566 | $(wildcard include/config/hyperv.h) \
567 | arch/x86/include/asm/io_apic.h \
568 | arch/x86/include/asm/irq_vectors.h \
569 | $(wildcard include/config/pci/msi.h) \
570 | include/linux/topology.h \
571 | $(wildcard include/config/use/percpu/numa/node/id.h) \
572 | $(wildcard include/config/sched/smt.h) \
573 | include/linux/smp.h \
574 | $(wildcard include/config/up/late/init.h) \
575 | include/linux/percpu.h \
576 | $(wildcard include/config/need/per/cpu/embed/first/chunk.h) \
577 | $(wildcard include/config/need/per/cpu/page/first/chunk.h) \
578 | include/linux/sysctl.h \
579 | $(wildcard include/config/sysctl.h) \
580 | include/uapi/linux/sysctl.h \
581 | include/linux/elf.h \
582 | arch/x86/include/asm/elf.h \
583 | $(wildcard include/config/x86/x32/abi.h) \
584 | arch/x86/include/asm/user.h \
585 | arch/x86/include/asm/user_64.h \
586 | arch/x86/include/uapi/asm/auxvec.h \
587 | arch/x86/include/asm/vdso.h \
588 | $(wildcard include/config/x86/x32.h) \
589 | include/linux/mm_types.h \
590 | $(wildcard include/config/have/cmpxchg/double.h) \
591 | $(wildcard include/config/have/aligned/struct/page.h) \
592 | $(wildcard include/config/userfaultfd.h) \
593 | $(wildcard include/config/have/arch/compat/mmap/bases.h) \
594 | $(wildcard include/config/membarrier.h) \
595 | $(wildcard include/config/aio.h) \
596 | $(wildcard include/config/mmu/notifier.h) \
597 | $(wildcard include/config/arch/want/batched/unmap/tlb/flush.h) \
598 | $(wildcard include/config/hmm.h) \
599 | include/linux/mm_types_task.h \
600 | $(wildcard include/config/split/ptlock/cpus.h) \
601 | $(wildcard include/config/arch/enable/split/pmd/ptlock.h) \
602 | arch/x86/include/asm/tlbbatch.h \
603 | include/linux/auxvec.h \
604 | include/uapi/linux/auxvec.h \
605 | include/linux/uprobes.h \
606 | $(wildcard include/config/uprobes.h) \
607 | arch/x86/include/asm/uprobes.h \
608 | include/uapi/linux/elf.h \
609 | include/uapi/linux/elf-em.h \
610 | include/linux/kobject.h \
611 | $(wildcard include/config/uevent/helper.h) \
612 | $(wildcard include/config/debug/kobject/release.h) \
613 | include/linux/sysfs.h \
614 | include/linux/kernfs.h \
615 | $(wildcard include/config/kernfs.h) \
616 | include/linux/idr.h \
617 | include/linux/radix-tree.h \
618 | $(wildcard include/config/radix/tree/multiorder.h) \
619 | include/linux/kobject_ns.h \
620 | include/linux/kref.h \
621 | include/linux/refcount.h \
622 | $(wildcard include/config/refcount/full.h) \
623 | arch/x86/include/asm/refcount.h \
624 | include/linux/moduleparam.h \
625 | $(wildcard include/config/alpha.h) \
626 | $(wildcard include/config/ia64.h) \
627 | $(wildcard include/config/ppc64.h) \
628 | include/linux/rbtree_latch.h \
629 | arch/x86/include/asm/module.h \
630 | $(wildcard include/config/unwinder/orc.h) \
631 | $(wildcard include/config/m486.h) \
632 | $(wildcard include/config/m586.h) \
633 | $(wildcard include/config/m586tsc.h) \
634 | $(wildcard include/config/m586mmx.h) \
635 | $(wildcard include/config/mcore2.h) \
636 | $(wildcard include/config/m686.h) \
637 | $(wildcard include/config/mpentiumii.h) \
638 | $(wildcard include/config/mpentiumiii.h) \
639 | $(wildcard include/config/mpentiumm.h) \
640 | $(wildcard include/config/mpentium4.h) \
641 | $(wildcard include/config/mk6.h) \
642 | $(wildcard include/config/mk8.h) \
643 | $(wildcard include/config/melan.h) \
644 | $(wildcard include/config/mcrusoe.h) \
645 | $(wildcard include/config/mefficeon.h) \
646 | $(wildcard include/config/mwinchipc6.h) \
647 | $(wildcard include/config/mwinchip3d.h) \
648 | $(wildcard include/config/mcyrixiii.h) \
649 | $(wildcard include/config/mviac3/2.h) \
650 | $(wildcard include/config/mviac7.h) \
651 | $(wildcard include/config/mgeodegx1.h) \
652 | $(wildcard include/config/mgeode/lx.h) \
653 | include/asm-generic/module.h \
654 | $(wildcard include/config/have/mod/arch/specific.h) \
655 | $(wildcard include/config/modules/use/elf/rel.h) \
656 | $(wildcard include/config/modules/use/elf/rela.h) \
657 | arch/x86/include/asm/orc_types.h \
658 | /home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop_packet.h \
659 |
660 | /home/xiebaoyou/study/陈老师/drop-packet/src/step1/main.o: $(deps_/home/xiebaoyou/study/陈老师/drop-packet/src/step1/main.o)
661 |
662 | $(deps_/home/xiebaoyou/study/陈老师/drop-packet/src/step1/main.o):
663 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step1/.tmp_versions/drop-packet.mod:
--------------------------------------------------------------------------------
1 | /home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop-packet.ko
2 | /home/xiebaoyou/study/陈老师/drop-packet/src/step1/main.o
3 |
4 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step1/Makefile:
--------------------------------------------------------------------------------
1 | OS_VER := UNKNOWN
2 | UNAME := $(shell uname -r)
3 | ifneq ($(findstring 4.15.0-39-generic,$(UNAME)),)
4 | OS_VER := UBUNTU_1604
5 | endif
6 |
7 | ifneq ($(KERNELRELEASE),)
8 | obj-m += $(MODNAME).o
9 | $(MODNAME)-y := main.o
10 | ccflags-y := -I$(PWD)/
11 | else
12 | export PWD=`pwd`
13 |
14 | ifeq ($(KERNEL_BUILD_PATH),)
15 | KERNEL_BUILD_PATH := /lib/modules/`uname -r`/build
16 | endif
17 | ifeq ($(MODNAME),)
18 | export MODNAME=drop-packet
19 | endif
20 |
21 | all:
22 | make CFLAGS_MODULE=-D$(OS_VER) -C /lib/modules/`uname -r`/build M=`pwd` modules
23 | clean:
24 | make -C $(KERNEL_BUILD_PATH) M=$(PWD) clean
25 | endif
26 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step1/Module.symvers:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step1/Module.symvers
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step1/drop-packet.ko:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step1/drop-packet.ko
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step1/drop-packet.mod.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | MODULE_INFO(vermagic, VERMAGIC_STRING);
6 | MODULE_INFO(name, KBUILD_MODNAME);
7 |
8 | __visible struct module __this_module
9 | __attribute__((section(".gnu.linkonce.this_module"))) = {
10 | .name = KBUILD_MODNAME,
11 | .init = init_module,
12 | #ifdef CONFIG_MODULE_UNLOAD
13 | .exit = cleanup_module,
14 | #endif
15 | .arch = MODULE_ARCH_INIT,
16 | };
17 |
18 | #ifdef RETPOLINE
19 | MODULE_INFO(retpoline, "Y");
20 | #endif
21 |
22 | static const char __module_depends[]
23 | __used
24 | __attribute__((section(".modinfo"))) =
25 | "depends=";
26 |
27 |
28 | MODULE_INFO(srcversion, "3B2D768608D090800D8AF38");
29 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step1/drop-packet.mod.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step1/drop-packet.mod.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step1/drop-packet.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step1/drop-packet.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step1/drop_packet.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Baoyou Xie's drop-packet module
3 | *
4 | * Copyright (C) 2018 Baoyou Xie.
5 | *
6 | * Author: Baoyou Xie
7 | *
8 | * License terms: GNU General Public License (GPL) version 2
9 | */
10 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step1/main.c:
--------------------------------------------------------------------------------
1 | /**
2 | * Baoyou Xie's drop-packet module
3 | *
4 | * Copyright (C) 2018 Baoyou Xie.
5 | *
6 | * Author: Baoyou Xie
7 | *
8 | * License terms: GNU General Public License (GPL) version 2
9 | */
10 |
11 | #include
12 | #include
13 |
14 | #include "drop_packet.h"
15 |
16 | static int drop_packet_init(void)
17 | {
18 | printk("drop-packet loaded.\n");
19 |
20 | return 0;
21 | }
22 |
23 | static void drop_packet_exit(void)
24 | {
25 | printk("drop-packet unloaded.\n");
26 | }
27 |
28 | module_init(drop_packet_init)
29 | module_exit(drop_packet_exit)
30 |
31 | MODULE_DESCRIPTION("Baoyou Xie's drop-packet module");
32 | MODULE_AUTHOR("Baoyou Xie ");
33 | MODULE_LICENSE("GPL v2");
34 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step1/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step1/main.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step1/modules.order:
--------------------------------------------------------------------------------
1 | kernel//home/xiebaoyou/study/陈老师/drop-packet/src/step1/drop-packet.ko
2 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step2/.drop-packet.ko.cmd:
--------------------------------------------------------------------------------
1 | cmd_/home/xiebaoyou/study/陈老师/drop-packet/src/step2/drop-packet.ko := ld -r -m elf_x86_64 -z max-page-size=0x200000 -T ./scripts/module-common.lds --build-id -o /home/xiebaoyou/study/陈老师/drop-packet/src/step2/drop-packet.ko /home/xiebaoyou/study/陈老师/drop-packet/src/step2/drop-packet.o /home/xiebaoyou/study/陈老师/drop-packet/src/step2/drop-packet.mod.o ; true
2 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step2/.drop-packet.o.cmd:
--------------------------------------------------------------------------------
1 | cmd_/home/xiebaoyou/study/陈老师/drop-packet/src/step2/drop-packet.o := ld -m elf_x86_64 -z max-page-size=0x200000 -r -o /home/xiebaoyou/study/陈老师/drop-packet/src/step2/drop-packet.o /home/xiebaoyou/study/陈老师/drop-packet/src/step2/main.o
2 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step2/.tmp_versions/drop-packet.mod:
--------------------------------------------------------------------------------
1 | /home/xiebaoyou/study/陈老师/drop-packet/src/step2/drop-packet.ko
2 | /home/xiebaoyou/study/陈老师/drop-packet/src/step2/main.o
3 |
4 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step2/Makefile:
--------------------------------------------------------------------------------
1 | OS_VER := UNKNOWN
2 | UNAME := $(shell uname -r)
3 | ifneq ($(findstring 4.15.0-39-generic,$(UNAME)),)
4 | OS_VER := UBUNTU_1604
5 | endif
6 |
7 | ifneq ($(KERNELRELEASE),)
8 | obj-m += $(MODNAME).o
9 | $(MODNAME)-y := main.o
10 | ccflags-y := -I$(PWD)/
11 | else
12 | export PWD=`pwd`
13 |
14 | ifeq ($(KERNEL_BUILD_PATH),)
15 | KERNEL_BUILD_PATH := /lib/modules/`uname -r`/build
16 | endif
17 | ifeq ($(MODNAME),)
18 | export MODNAME=drop-packet
19 | endif
20 |
21 | all:
22 | make CFLAGS_MODULE=-D$(OS_VER) -C /lib/modules/`uname -r`/build M=`pwd` modules
23 | clean:
24 | make -C $(KERNEL_BUILD_PATH) M=$(PWD) clean
25 | endif
26 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step2/Module.symvers:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step2/Module.symvers
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step2/drop-packet.ko:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step2/drop-packet.ko
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step2/drop-packet.mod.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | MODULE_INFO(vermagic, VERMAGIC_STRING);
6 | MODULE_INFO(name, KBUILD_MODNAME);
7 |
8 | __visible struct module __this_module
9 | __attribute__((section(".gnu.linkonce.this_module"))) = {
10 | .name = KBUILD_MODNAME,
11 | .init = init_module,
12 | #ifdef CONFIG_MODULE_UNLOAD
13 | .exit = cleanup_module,
14 | #endif
15 | .arch = MODULE_ARCH_INIT,
16 | };
17 |
18 | #ifdef RETPOLINE
19 | MODULE_INFO(retpoline, "Y");
20 | #endif
21 |
22 | static const char __module_depends[]
23 | __used
24 | __attribute__((section(".modinfo"))) =
25 | "depends=";
26 |
27 |
28 | MODULE_INFO(srcversion, "B5656D092B46683305B23FE");
29 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step2/drop-packet.mod.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step2/drop-packet.mod.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step2/drop-packet.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step2/drop-packet.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step2/drop_packet.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Baoyou Xie's drop-packet module
3 | *
4 | * Copyright (C) 2018 Baoyou Xie.
5 | *
6 | * Author: Baoyou Xie
7 | *
8 | * License terms: GNU General Public License (GPL) version 2
9 | */
10 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step2/main.c:
--------------------------------------------------------------------------------
1 | /**
2 | * Baoyou Xie's drop-packet module
3 | *
4 | * Copyright (C) 2018 Baoyou Xie.
5 | *
6 | * Author: Baoyou Xie
7 | *
8 | * License terms: GNU General Public License (GPL) version 2
9 | */
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | #include "drop_packet.h"
18 |
19 | static unsigned long drop_packet_activated;
20 |
21 | static int activate_drop_packet(void)
22 | {
23 | return 1;
24 | }
25 |
26 | static void deactivate_drop_packet(void)
27 | {
28 | }
29 |
30 | static int drop_packet_show(struct seq_file *m, void *v)
31 | {
32 | seq_printf(m, "settings:\n");
33 | seq_printf(m, " activated: %s\n", drop_packet_activated ? "y" : "N");
34 |
35 | return 0;
36 | }
37 |
38 | static int drop_packet_open(struct inode *inode, struct file *filp)
39 | {
40 | return single_open(filp, drop_packet_show, NULL);
41 | }
42 |
43 | static ssize_t drop_packet_write(struct file *file,
44 | const char __user *buf, size_t count, loff_t *offs)
45 | {
46 | int ret;
47 | char cmd[255];
48 | char chr[255];
49 |
50 | if (count < 1 || *offs)
51 | return -EINVAL;
52 |
53 | if (copy_from_user(chr, buf, 255))
54 | return -EFAULT;
55 |
56 | ret = sscanf(chr, "%255s", cmd);
57 | if (ret <= 0)
58 | return -EINVAL;
59 |
60 | if (strcmp(cmd, "activate") == 0) {
61 | if (!drop_packet_activated)
62 | drop_packet_activated = activate_drop_packet();
63 | } else if (strcmp(cmd, "deactivate") == 0) {
64 | if (drop_packet_activated)
65 | deactivate_drop_packet();
66 | drop_packet_activated = 0;
67 | }
68 |
69 | return count;
70 | }
71 |
72 | const struct file_operations drop_packet_fops = {
73 | .open = drop_packet_open,
74 | .read = seq_read,
75 | .llseek = seq_lseek,
76 | .write = drop_packet_write,
77 | .release = single_release,
78 | };
79 |
80 | static int drop_packet_init(void)
81 | {
82 | int ret;
83 | struct proc_dir_entry *pe;
84 |
85 | proc_mkdir("mooc", NULL);
86 | proc_mkdir("mooc/net", NULL);
87 |
88 | ret = -ENOMEM;
89 | pe = proc_create("mooc/net/drop-packet",
90 | S_IFREG | 0644,
91 | NULL,
92 | &drop_packet_fops);
93 | if (!pe)
94 | goto err_proc;
95 |
96 | printk("drop-packet loaded.\n");
97 |
98 | return 0;
99 |
100 | err_proc:
101 | return ret;
102 | }
103 |
104 | static void drop_packet_exit(void)
105 | {
106 | remove_proc_entry("mooc/net/drop-packet", NULL);
107 | remove_proc_entry("mooc/net", NULL);
108 | remove_proc_entry("mooc", NULL);
109 |
110 | printk("drop-packet unloaded.\n");
111 | }
112 |
113 | module_init(drop_packet_init)
114 | module_exit(drop_packet_exit)
115 |
116 | MODULE_DESCRIPTION("Baoyou Xie's drop-packet module");
117 | MODULE_AUTHOR("Baoyou Xie ");
118 | MODULE_LICENSE("GPL v2");
119 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step2/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step2/main.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step2/modules.order:
--------------------------------------------------------------------------------
1 | kernel//home/xiebaoyou/study/陈老师/drop-packet/src/step2/drop-packet.ko
2 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step3/.drop-packet.ko.cmd:
--------------------------------------------------------------------------------
1 | cmd_/home/xiebaoyou/study/陈老师/drop-packet/src/step3/drop-packet.ko := ld -r -m elf_x86_64 -z max-page-size=0x200000 -T ./scripts/module-common.lds --build-id -o /home/xiebaoyou/study/陈老师/drop-packet/src/step3/drop-packet.ko /home/xiebaoyou/study/陈老师/drop-packet/src/step3/drop-packet.o /home/xiebaoyou/study/陈老师/drop-packet/src/step3/drop-packet.mod.o ; true
2 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step3/.drop-packet.o.cmd:
--------------------------------------------------------------------------------
1 | cmd_/home/xiebaoyou/study/陈老师/drop-packet/src/step3/drop-packet.o := ld -m elf_x86_64 -z max-page-size=0x200000 -r -o /home/xiebaoyou/study/陈老师/drop-packet/src/step3/drop-packet.o /home/xiebaoyou/study/陈老师/drop-packet/src/step3/main.o /home/xiebaoyou/study/陈老师/drop-packet/src/step3/misc.o
2 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step3/.tmp_versions/drop-packet.mod:
--------------------------------------------------------------------------------
1 | /home/xiebaoyou/study/陈老师/drop-packet/src/step3/drop-packet.ko
2 | /home/xiebaoyou/study/陈老师/drop-packet/src/step3/main.o /home/xiebaoyou/study/陈老师/drop-packet/src/step3/misc.o
3 |
4 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step3/Makefile:
--------------------------------------------------------------------------------
1 | OS_VER := UNKNOWN
2 | UNAME := $(shell uname -r)
3 | ifneq ($(findstring 4.15.0-39-generic,$(UNAME)),)
4 | OS_VER := UBUNTU_1604
5 | endif
6 |
7 | ifneq ($(KERNELRELEASE),)
8 | obj-m += $(MODNAME).o
9 | $(MODNAME)-y := main.o misc.o
10 | ccflags-y := -I$(PWD)/
11 | else
12 | export PWD=`pwd`
13 |
14 | ifeq ($(KERNEL_BUILD_PATH),)
15 | KERNEL_BUILD_PATH := /lib/modules/`uname -r`/build
16 | endif
17 | ifeq ($(MODNAME),)
18 | export MODNAME=drop-packet
19 | endif
20 |
21 | all:
22 | make CFLAGS_MODULE=-D$(OS_VER) -C /lib/modules/`uname -r`/build M=`pwd` modules
23 | clean:
24 | make -C $(KERNEL_BUILD_PATH) M=$(PWD) clean
25 | endif
26 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step3/Module.symvers:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step3/Module.symvers
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step3/drop-packet.ko:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step3/drop-packet.ko
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step3/drop-packet.mod.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | MODULE_INFO(vermagic, VERMAGIC_STRING);
6 | MODULE_INFO(name, KBUILD_MODNAME);
7 |
8 | __visible struct module __this_module
9 | __attribute__((section(".gnu.linkonce.this_module"))) = {
10 | .name = KBUILD_MODNAME,
11 | .init = init_module,
12 | #ifdef CONFIG_MODULE_UNLOAD
13 | .exit = cleanup_module,
14 | #endif
15 | .arch = MODULE_ARCH_INIT,
16 | };
17 |
18 | #ifdef RETPOLINE
19 | MODULE_INFO(retpoline, "Y");
20 | #endif
21 |
22 | static const char __module_depends[]
23 | __used
24 | __attribute__((section(".modinfo"))) =
25 | "depends=";
26 |
27 |
28 | MODULE_INFO(srcversion, "0535A6390B9A0E93BB3D81A");
29 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step3/drop-packet.mod.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step3/drop-packet.mod.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step3/drop-packet.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step3/drop-packet.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step3/drop_packet.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Baoyou Xie's drop-packet module
3 | *
4 | * Copyright (C) 2018 Baoyou Xie.
5 | *
6 | * Author: Baoyou Xie
7 | *
8 | * License terms: GNU General Public License (GPL) version 2
9 | */
10 | #include
11 |
12 | int hook_kprobe(struct kprobe *kp, const char *name,
13 | kprobe_pre_handler_t pre, kprobe_post_handler_t post);
14 | void unhook_kprobe(struct kprobe *kp);
15 | int hook_tracepoint(const char *name, void *probe, void *data);
16 | int unhook_tracepoint(const char *name, void *probe, void *data);
17 |
18 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step3/main.c:
--------------------------------------------------------------------------------
1 | /**
2 | * Baoyou Xie's drop-packet module
3 | *
4 | * Copyright (C) 2018 Baoyou Xie.
5 | *
6 | * Author: Baoyou Xie
7 | *
8 | * License terms: GNU General Public License (GPL) version 2
9 | */
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 |
18 | #include "drop_packet.h"
19 |
20 | static unsigned long drop_packet_activated;
21 |
22 | static struct kprobe kprobe_eth_type_trans;
23 | static struct kprobe kprobe_napi_gro_receive;
24 | static struct kprobe kprobe___netif_receive_skb_core;
25 | static struct kprobe kprobe_tcp_v4_rcv;
26 | static struct kprobe kprobe_dev_queue_xmit;
27 |
28 | static void trace_net_dev_xmit_hit(void *ignore, struct sk_buff *skb,
29 | int rc, struct net_device *dev, unsigned int skb_len)
30 | {
31 | printk("xby-debug in trace_net_dev_xmit_hit\n");
32 | }
33 |
34 | static int kprobe_dev_queue_xmit_pre(struct kprobe *p, struct pt_regs *regs)
35 | {
36 | printk("xby-debug in kprobe_dev_queue_xmit_pre\n");
37 |
38 | return 0;
39 | }
40 |
41 | static int kprobe_eth_type_trans_pre(struct kprobe *p, struct pt_regs *regs)
42 | {
43 | return 0;
44 | }
45 |
46 | static int kprobe_napi_gro_receive_pre(struct kprobe *p, struct pt_regs *regs)
47 | {
48 | return 0;
49 | }
50 |
51 | static int kprobe___netif_receive_skb_core_pre(struct kprobe *p, struct pt_regs *regs)
52 | {
53 | return 0;
54 | }
55 |
56 | static int kprobe_tcp_v4_rcv_pre(struct kprobe *p, struct pt_regs *regs)
57 | {
58 | return 0;
59 | }
60 |
61 | static int activate_drop_packet(void)
62 | {
63 | hook_tracepoint("net_dev_xmit", trace_net_dev_xmit_hit, NULL);
64 | hook_kprobe(&kprobe_dev_queue_xmit, "dev_queue_xmit",
65 | kprobe_dev_queue_xmit_pre, NULL);
66 | hook_kprobe(&kprobe_eth_type_trans, "eth_type_trans",
67 | kprobe_eth_type_trans_pre, NULL);
68 | hook_kprobe(&kprobe_napi_gro_receive, "napi_gro_receive",
69 | kprobe_napi_gro_receive_pre, NULL);
70 | hook_kprobe(&kprobe___netif_receive_skb_core, "__netif_receive_skb_core",
71 | kprobe___netif_receive_skb_core_pre, NULL);
72 | hook_kprobe(&kprobe_tcp_v4_rcv, "tcp_v4_rcv",
73 | kprobe_tcp_v4_rcv_pre, NULL);
74 |
75 | return 1;
76 | }
77 |
78 | static void deactivate_drop_packet(void)
79 | {
80 | unhook_tracepoint("net_dev_xmit", trace_net_dev_xmit_hit, NULL);
81 | unhook_kprobe(&kprobe_dev_queue_xmit);
82 | unhook_kprobe(&kprobe_eth_type_trans);
83 | unhook_kprobe(&kprobe_napi_gro_receive);
84 | unhook_kprobe(&kprobe___netif_receive_skb_core);
85 | unhook_kprobe(&kprobe_tcp_v4_rcv);
86 | }
87 |
88 | static int drop_packet_show(struct seq_file *m, void *v)
89 | {
90 | seq_printf(m, "settings:\n");
91 | seq_printf(m, " activated: %s\n", drop_packet_activated ? "y" : "N");
92 |
93 | return 0;
94 | }
95 |
96 | static int drop_packet_open(struct inode *inode, struct file *filp)
97 | {
98 | return single_open(filp, drop_packet_show, NULL);
99 | }
100 |
101 | static ssize_t drop_packet_write(struct file *file,
102 | const char __user *buf, size_t count, loff_t *offs)
103 | {
104 | int ret;
105 | char cmd[255];
106 | char chr[255];
107 |
108 | if (count < 1 || *offs)
109 | return -EINVAL;
110 |
111 | if (copy_from_user(chr, buf, 255))
112 | return -EFAULT;
113 |
114 | ret = sscanf(chr, "%255s", cmd);
115 | if (ret <= 0)
116 | return -EINVAL;
117 |
118 | if (strcmp(cmd, "activate") == 0) {
119 | if (!drop_packet_activated)
120 | drop_packet_activated = activate_drop_packet();
121 | } else if (strcmp(cmd, "deactivate") == 0) {
122 | if (drop_packet_activated)
123 | deactivate_drop_packet();
124 | drop_packet_activated = 0;
125 | }
126 |
127 | return count;
128 | }
129 |
130 | const struct file_operations drop_packet_fops = {
131 | .open = drop_packet_open,
132 | .read = seq_read,
133 | .llseek = seq_lseek,
134 | .write = drop_packet_write,
135 | .release = single_release,
136 | };
137 |
138 | static int drop_packet_init(void)
139 | {
140 | int ret;
141 | struct proc_dir_entry *pe;
142 |
143 | proc_mkdir("mooc", NULL);
144 | proc_mkdir("mooc/net", NULL);
145 |
146 | ret = -ENOMEM;
147 | pe = proc_create("mooc/net/drop-packet",
148 | S_IFREG | 0644,
149 | NULL,
150 | &drop_packet_fops);
151 | if (!pe)
152 | goto err_proc;
153 |
154 | printk("drop-packet loaded.\n");
155 |
156 | return 0;
157 |
158 | err_proc:
159 | return ret;
160 | }
161 |
162 | static void drop_packet_exit(void)
163 | {
164 | remove_proc_entry("mooc/net/drop-packet", NULL);
165 | remove_proc_entry("mooc/net", NULL);
166 | remove_proc_entry("mooc", NULL);
167 |
168 | if (drop_packet_activated)
169 | deactivate_drop_packet();
170 | drop_packet_activated = 0;
171 |
172 | printk("drop-packet unloaded.\n");
173 | }
174 |
175 | module_init(drop_packet_init)
176 | module_exit(drop_packet_exit)
177 |
178 | MODULE_DESCRIPTION("Baoyou Xie's drop-packet module");
179 | MODULE_AUTHOR("Baoyou Xie ");
180 | MODULE_LICENSE("GPL v2");
181 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step3/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step3/main.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step3/misc.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "drop_packet.h"
6 |
7 | int hook_kprobe(struct kprobe *kp, const char *name,
8 | kprobe_pre_handler_t pre, kprobe_post_handler_t post)
9 | {
10 | kprobe_opcode_t *addr;
11 |
12 | if (!name || strlen(name) >= 255)
13 | return -EINVAL;
14 | addr = (kprobe_opcode_t *)kallsyms_lookup_name(name);
15 | if (!addr)
16 | return -EINVAL;
17 |
18 | memset(kp, 0, sizeof(struct kprobe));
19 | kp->symbol_name = name;
20 | kp->pre_handler = pre;
21 | kp->post_handler = post;
22 |
23 | register_kprobe(kp);
24 |
25 | return 0;
26 | }
27 |
28 | void unhook_kprobe(struct kprobe *kp)
29 | {
30 | unregister_kprobe(kp);
31 | memset(kp, 0, sizeof(struct kprobe));
32 | }
33 |
34 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
35 | int hook_tracepoint(const char *name, void *probe, void *data)
36 | {
37 | return tracepoint_probe_register(name, probe);
38 | }
39 |
40 | int unhook_tracepoint(const char *name, void *probe, void *data)
41 | {
42 | return tracepoint_probe_unregister(name, probe);
43 | }
44 | #elif LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0)
45 | int hook_tracepoint(const char *name, void *probe, void *data)
46 | {
47 | return tracepoint_probe_register(name, probe, data);
48 | }
49 |
50 | int unhook_tracepoint(const char *name, void *probe, void *data)
51 | {
52 | return tracepoint_probe_unregister(name, probe, data);
53 | }
54 | #else
55 | static struct tracepoint *tp_ret;
56 | static void probe_tracepoint(struct tracepoint *tp, void *priv)
57 | {
58 | char *n = priv;
59 |
60 | if (strcmp(tp->name, n) == 0)
61 | tp_ret = tp;
62 | }
63 |
64 | static struct tracepoint *find_tracepoint(const char *name)
65 | {
66 | tp_ret = NULL;
67 | for_each_kernel_tracepoint(probe_tracepoint, (void *)name);
68 |
69 | return tp_ret;
70 | }
71 |
72 | int hook_tracepoint(const char *name, void *probe, void *data)
73 | {
74 | struct tracepoint *tp;
75 |
76 | tp = find_tracepoint(name);
77 | if (!tp)
78 | return 0;
79 |
80 | return tracepoint_probe_register(tp, probe, data);
81 | }
82 |
83 | int unhook_tracepoint(const char *name, void *probe, void *data)
84 | {
85 | struct tracepoint *tp;
86 |
87 | tp = find_tracepoint(name);
88 | if (!tp)
89 | return 0;
90 |
91 | return tracepoint_probe_unregister(tp, probe, data);
92 | }
93 | #endif
94 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step3/misc.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step3/misc.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step3/modules.order:
--------------------------------------------------------------------------------
1 | kernel//home/xiebaoyou/study/陈老师/drop-packet/src/step3/drop-packet.ko
2 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step4/.drop-packet.ko.cmd:
--------------------------------------------------------------------------------
1 | cmd_/home/xiebaoyou/study/陈老师/drop-packet/src/step4/drop-packet.ko := ld -r -m elf_x86_64 -z max-page-size=0x200000 -T ./scripts/module-common.lds --build-id -o /home/xiebaoyou/study/陈老师/drop-packet/src/step4/drop-packet.ko /home/xiebaoyou/study/陈老师/drop-packet/src/step4/drop-packet.o /home/xiebaoyou/study/陈老师/drop-packet/src/step4/drop-packet.mod.o ; true
2 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step4/.drop-packet.o.cmd:
--------------------------------------------------------------------------------
1 | cmd_/home/xiebaoyou/study/陈老师/drop-packet/src/step4/drop-packet.o := ld -m elf_x86_64 -z max-page-size=0x200000 -r -o /home/xiebaoyou/study/陈老师/drop-packet/src/step4/drop-packet.o /home/xiebaoyou/study/陈老师/drop-packet/src/step4/main.o /home/xiebaoyou/study/陈老师/drop-packet/src/step4/misc.o
2 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step4/.tmp_versions/drop-packet.mod:
--------------------------------------------------------------------------------
1 | /home/xiebaoyou/study/陈老师/drop-packet/src/step4/drop-packet.ko
2 | /home/xiebaoyou/study/陈老师/drop-packet/src/step4/main.o /home/xiebaoyou/study/陈老师/drop-packet/src/step4/misc.o
3 |
4 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step4/Makefile:
--------------------------------------------------------------------------------
1 | OS_VER := UNKNOWN
2 | UNAME := $(shell uname -r)
3 | ifneq ($(findstring 4.15.0-39-generic,$(UNAME)),)
4 | OS_VER := UBUNTU_1604
5 | endif
6 |
7 | ifneq ($(KERNELRELEASE),)
8 | obj-m += $(MODNAME).o
9 | $(MODNAME)-y := main.o misc.o
10 | ccflags-y := -I$(PWD)/
11 | else
12 | export PWD=`pwd`
13 |
14 | ifeq ($(KERNEL_BUILD_PATH),)
15 | KERNEL_BUILD_PATH := /lib/modules/`uname -r`/build
16 | endif
17 | ifeq ($(MODNAME),)
18 | export MODNAME=drop-packet
19 | endif
20 |
21 | all:
22 | make CFLAGS_MODULE=-D$(OS_VER) -C /lib/modules/`uname -r`/build M=`pwd` modules
23 | clean:
24 | make -C $(KERNEL_BUILD_PATH) M=$(PWD) clean
25 | endif
26 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step4/Module.symvers:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step4/Module.symvers
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step4/drop-packet.ko:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step4/drop-packet.ko
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step4/drop-packet.mod.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | MODULE_INFO(vermagic, VERMAGIC_STRING);
6 | MODULE_INFO(name, KBUILD_MODNAME);
7 |
8 | __visible struct module __this_module
9 | __attribute__((section(".gnu.linkonce.this_module"))) = {
10 | .name = KBUILD_MODNAME,
11 | .init = init_module,
12 | #ifdef CONFIG_MODULE_UNLOAD
13 | .exit = cleanup_module,
14 | #endif
15 | .arch = MODULE_ARCH_INIT,
16 | };
17 |
18 | #ifdef RETPOLINE
19 | MODULE_INFO(retpoline, "Y");
20 | #endif
21 |
22 | static const char __module_depends[]
23 | __used
24 | __attribute__((section(".modinfo"))) =
25 | "depends=";
26 |
27 |
28 | MODULE_INFO(srcversion, "184E169951C3296D9DE84C4");
29 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step4/drop-packet.mod.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step4/drop-packet.mod.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step4/drop-packet.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step4/drop-packet.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step4/drop_packet.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Baoyou Xie's drop-packet module
3 | *
4 | * Copyright (C) 2018 Baoyou Xie.
5 | *
6 | * Author: Baoyou Xie
7 | *
8 | * License terms: GNU General Public License (GPL) version 2
9 | */
10 | #include
11 |
12 | int hook_kprobe(struct kprobe *kp, const char *name,
13 | kprobe_pre_handler_t pre, kprobe_post_handler_t post);
14 | void unhook_kprobe(struct kprobe *kp);
15 | int hook_tracepoint(const char *name, void *probe, void *data);
16 | int unhook_tracepoint(const char *name, void *probe, void *data);
17 |
18 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step4/main.c:
--------------------------------------------------------------------------------
1 | /**
2 | * Baoyou Xie's drop-packet module
3 | *
4 | * Copyright (C) 2018 Baoyou Xie.
5 | *
6 | * Author: Baoyou Xie
7 | *
8 | * License terms: GNU General Public License (GPL) version 2
9 | */
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 |
21 | #include "drop_packet.h"
22 |
23 | static unsigned long drop_packet_activated;
24 |
25 | static struct kprobe kprobe_eth_type_trans;
26 | static struct kprobe kprobe_napi_gro_receive;
27 | static struct kprobe kprobe___netif_receive_skb_core;
28 | static struct kprobe kprobe_tcp_v4_rcv;
29 |
30 | enum packet_footprint
31 | {
32 | ETH_RECV,
33 | GRO_RECV,
34 | RECV_SKB,
35 | TCP_V4_RCV,
36 | SEND_SKB,
37 | TRACK_COUNT,
38 | };
39 |
40 | static void trace_packet(const struct sk_buff *skb,
41 | const struct iphdr *iphdr, enum packet_footprint fp)
42 | {
43 | unsigned int source = iphdr->saddr;
44 | unsigned int dest = iphdr->daddr;
45 | unsigned char *saddr = (void *)&source;
46 | unsigned char *daddr = (void *)&dest;
47 |
48 | printk("Source IP:%u.%u.%u.%u, Dest IP:%u.%u.%u.%u, fp: %d\n",
49 | saddr[0], saddr[1], saddr[2], saddr[3],
50 | daddr[0], daddr[1], daddr[2], daddr[3], fp);
51 | }
52 |
53 | static void trace_net_dev_xmit_hit(void *ignore, struct sk_buff *skb,
54 | int rc, struct net_device *dev, unsigned int skb_len)
55 | {
56 | struct iphdr *iphdr;
57 |
58 | if (!drop_packet_activated)
59 | return;
60 |
61 | if (rc != NETDEV_TX_OK)
62 | return;
63 |
64 | iphdr = ip_hdr(skb);
65 | trace_packet(skb, iphdr, SEND_SKB);
66 | }
67 |
68 | static int kprobe_eth_type_trans_pre(struct kprobe *p, struct pt_regs *regs)
69 | {
70 | struct sk_buff *skb = (void *)regs->di;
71 | struct iphdr *iphdr;
72 |
73 | if (!drop_packet_activated)
74 | return 0;
75 |
76 | iphdr = (struct iphdr *)(skb->data + ETH_HLEN);
77 | trace_packet(skb, iphdr, ETH_RECV);
78 |
79 | return 0;
80 | }
81 |
82 | static int kprobe_napi_gro_receive_pre(struct kprobe *p, struct pt_regs *regs)
83 | {
84 | struct sk_buff *skb = (void *)regs->si;
85 | struct iphdr *iphdr;
86 |
87 | if (!drop_packet_activated)
88 | return 0;
89 |
90 | if (skb->protocol != cpu_to_be16(ETH_P_IP))
91 | return 0;
92 |
93 | iphdr = (struct iphdr *)skb->data;
94 | trace_packet(skb, iphdr, GRO_RECV);
95 |
96 | return 0;
97 | }
98 |
99 | static int kprobe___netif_receive_skb_core_pre(struct kprobe *p, struct pt_regs *regs)
100 | {
101 | struct sk_buff *skb = (void *)regs->di;
102 | struct iphdr *iphdr;
103 |
104 | if (!drop_packet_activated)
105 | return 0;
106 |
107 | if (skb->protocol != cpu_to_be16(ETH_P_IP))
108 | return 0;
109 |
110 | iphdr = (struct iphdr *)skb->data;
111 | trace_packet(skb, iphdr, RECV_SKB);
112 |
113 | return 0;
114 | }
115 |
116 | static int kprobe_tcp_v4_rcv_pre(struct kprobe *p, struct pt_regs *regs)
117 | {
118 | struct sk_buff *skb = (void *)regs->di;
119 | struct iphdr *iphdr;
120 |
121 | if (!drop_packet_activated)
122 | return 0;
123 |
124 | if (skb->protocol != cpu_to_be16(ETH_P_IP))
125 | return 0;
126 |
127 | iphdr = ip_hdr(skb);
128 | trace_packet(skb, iphdr, TCP_V4_RCV);
129 |
130 | return 0;
131 | }
132 |
133 | static int activate_drop_packet(void)
134 | {
135 | hook_tracepoint("net_dev_xmit", trace_net_dev_xmit_hit, NULL);
136 | hook_kprobe(&kprobe_eth_type_trans, "eth_type_trans",
137 | kprobe_eth_type_trans_pre, NULL);
138 | hook_kprobe(&kprobe_napi_gro_receive, "napi_gro_receive",
139 | kprobe_napi_gro_receive_pre, NULL);
140 | hook_kprobe(&kprobe___netif_receive_skb_core, "__netif_receive_skb_core",
141 | kprobe___netif_receive_skb_core_pre, NULL);
142 | hook_kprobe(&kprobe_tcp_v4_rcv, "tcp_v4_rcv",
143 | kprobe_tcp_v4_rcv_pre, NULL);
144 |
145 | return 1;
146 | }
147 |
148 | static void deactivate_drop_packet(void)
149 | {
150 | unhook_tracepoint("net_dev_xmit", trace_net_dev_xmit_hit, NULL);
151 | unhook_kprobe(&kprobe_eth_type_trans);
152 | unhook_kprobe(&kprobe_napi_gro_receive);
153 | unhook_kprobe(&kprobe___netif_receive_skb_core);
154 | unhook_kprobe(&kprobe_tcp_v4_rcv);
155 | }
156 |
157 | static int drop_packet_show(struct seq_file *m, void *v)
158 | {
159 | seq_printf(m, "settings:\n");
160 | seq_printf(m, " activated: %s\n", drop_packet_activated ? "y" : "N");
161 |
162 | return 0;
163 | }
164 |
165 | static int drop_packet_open(struct inode *inode, struct file *filp)
166 | {
167 | return single_open(filp, drop_packet_show, NULL);
168 | }
169 |
170 | static ssize_t drop_packet_write(struct file *file,
171 | const char __user *buf, size_t count, loff_t *offs)
172 | {
173 | int ret;
174 | char cmd[255];
175 | char chr[255];
176 |
177 | if (count < 1 || *offs)
178 | return -EINVAL;
179 |
180 | if (copy_from_user(chr, buf, 255))
181 | return -EFAULT;
182 |
183 | ret = sscanf(chr, "%255s", cmd);
184 | if (ret <= 0)
185 | return -EINVAL;
186 |
187 | if (strcmp(cmd, "activate") == 0) {
188 | if (!drop_packet_activated)
189 | drop_packet_activated = activate_drop_packet();
190 | } else if (strcmp(cmd, "deactivate") == 0) {
191 | if (drop_packet_activated)
192 | deactivate_drop_packet();
193 | drop_packet_activated = 0;
194 | }
195 |
196 | return count;
197 | }
198 |
199 | const struct file_operations drop_packet_fops = {
200 | .open = drop_packet_open,
201 | .read = seq_read,
202 | .llseek = seq_lseek,
203 | .write = drop_packet_write,
204 | .release = single_release,
205 | };
206 |
207 | static int drop_packet_init(void)
208 | {
209 | int ret;
210 | struct proc_dir_entry *pe;
211 |
212 | proc_mkdir("mooc", NULL);
213 | proc_mkdir("mooc/net", NULL);
214 |
215 | ret = -ENOMEM;
216 | pe = proc_create("mooc/net/drop-packet",
217 | S_IFREG | 0644,
218 | NULL,
219 | &drop_packet_fops);
220 | if (!pe)
221 | goto err_proc;
222 |
223 | printk("drop-packet loaded.\n");
224 |
225 | return 0;
226 |
227 | err_proc:
228 | return ret;
229 | }
230 |
231 | static void drop_packet_exit(void)
232 | {
233 | remove_proc_entry("mooc/net/drop-packet", NULL);
234 | remove_proc_entry("mooc/net", NULL);
235 | remove_proc_entry("mooc", NULL);
236 |
237 | if (drop_packet_activated)
238 | deactivate_drop_packet();
239 | drop_packet_activated = 0;
240 |
241 | printk("drop-packet unloaded.\n");
242 | }
243 |
244 | module_init(drop_packet_init)
245 | module_exit(drop_packet_exit)
246 |
247 | MODULE_DESCRIPTION("Baoyou Xie's drop-packet module");
248 | MODULE_AUTHOR("Baoyou Xie ");
249 | MODULE_LICENSE("GPL v2");
250 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step4/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step4/main.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step4/misc.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "drop_packet.h"
6 |
7 | int hook_kprobe(struct kprobe *kp, const char *name,
8 | kprobe_pre_handler_t pre, kprobe_post_handler_t post)
9 | {
10 | kprobe_opcode_t *addr;
11 |
12 | if (!name || strlen(name) >= 255)
13 | return -EINVAL;
14 | addr = (kprobe_opcode_t *)kallsyms_lookup_name(name);
15 | if (!addr)
16 | return -EINVAL;
17 |
18 | memset(kp, 0, sizeof(struct kprobe));
19 | kp->symbol_name = name;
20 | kp->pre_handler = pre;
21 | kp->post_handler = post;
22 |
23 | register_kprobe(kp);
24 |
25 | return 0;
26 | }
27 |
28 | void unhook_kprobe(struct kprobe *kp)
29 | {
30 | unregister_kprobe(kp);
31 | memset(kp, 0, sizeof(struct kprobe));
32 | }
33 |
34 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
35 | int hook_tracepoint(const char *name, void *probe, void *data)
36 | {
37 | return tracepoint_probe_register(name, probe);
38 | }
39 |
40 | int unhook_tracepoint(const char *name, void *probe, void *data)
41 | {
42 | return tracepoint_probe_unregister(name, probe);
43 | }
44 | #elif LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0)
45 | int hook_tracepoint(const char *name, void *probe, void *data)
46 | {
47 | return tracepoint_probe_register(name, probe, data);
48 | }
49 |
50 | int unhook_tracepoint(const char *name, void *probe, void *data)
51 | {
52 | return tracepoint_probe_unregister(name, probe, data);
53 | }
54 | #else
55 | static struct tracepoint *tp_ret;
56 | static void probe_tracepoint(struct tracepoint *tp, void *priv)
57 | {
58 | char *n = priv;
59 |
60 | if (strcmp(tp->name, n) == 0)
61 | tp_ret = tp;
62 | }
63 |
64 | static struct tracepoint *find_tracepoint(const char *name)
65 | {
66 | tp_ret = NULL;
67 | for_each_kernel_tracepoint(probe_tracepoint, (void *)name);
68 |
69 | return tp_ret;
70 | }
71 |
72 | int hook_tracepoint(const char *name, void *probe, void *data)
73 | {
74 | struct tracepoint *tp;
75 |
76 | tp = find_tracepoint(name);
77 | if (!tp)
78 | return 0;
79 |
80 | return tracepoint_probe_register(tp, probe, data);
81 | }
82 |
83 | int unhook_tracepoint(const char *name, void *probe, void *data)
84 | {
85 | struct tracepoint *tp;
86 |
87 | tp = find_tracepoint(name);
88 | if (!tp)
89 | return 0;
90 |
91 | return tracepoint_probe_unregister(tp, probe, data);
92 | }
93 | #endif
94 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step4/misc.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step4/misc.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step4/modules.order:
--------------------------------------------------------------------------------
1 | kernel//home/xiebaoyou/study/陈老师/drop-packet/src/step4/drop-packet.ko
2 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step5/.drop-packet.ko.cmd:
--------------------------------------------------------------------------------
1 | cmd_/home/xiebaoyou/study/陈老师/drop-packet/src/step5/drop-packet.ko := ld -r -m elf_x86_64 -z max-page-size=0x200000 -T ./scripts/module-common.lds --build-id -o /home/xiebaoyou/study/陈老师/drop-packet/src/step5/drop-packet.ko /home/xiebaoyou/study/陈老师/drop-packet/src/step5/drop-packet.o /home/xiebaoyou/study/陈老师/drop-packet/src/step5/drop-packet.mod.o ; true
2 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step5/.drop-packet.o.cmd:
--------------------------------------------------------------------------------
1 | cmd_/home/xiebaoyou/study/陈老师/drop-packet/src/step5/drop-packet.o := ld -m elf_x86_64 -z max-page-size=0x200000 -r -o /home/xiebaoyou/study/陈老师/drop-packet/src/step5/drop-packet.o /home/xiebaoyou/study/陈老师/drop-packet/src/step5/main.o /home/xiebaoyou/study/陈老师/drop-packet/src/step5/misc.o
2 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step5/.tmp_versions/drop-packet.mod:
--------------------------------------------------------------------------------
1 | /home/xiebaoyou/study/陈老师/drop-packet/src/step5/drop-packet.ko
2 | /home/xiebaoyou/study/陈老师/drop-packet/src/step5/main.o /home/xiebaoyou/study/陈老师/drop-packet/src/step5/misc.o
3 |
4 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step5/Makefile:
--------------------------------------------------------------------------------
1 | OS_VER := UNKNOWN
2 | UNAME := $(shell uname -r)
3 | ifneq ($(findstring 4.15.0-39-generic,$(UNAME)),)
4 | OS_VER := UBUNTU_1604
5 | endif
6 |
7 | ifneq ($(KERNELRELEASE),)
8 | obj-m += $(MODNAME).o
9 | $(MODNAME)-y := main.o misc.o
10 | ccflags-y := -I$(PWD)/
11 | else
12 | export PWD=`pwd`
13 |
14 | ifeq ($(KERNEL_BUILD_PATH),)
15 | KERNEL_BUILD_PATH := /lib/modules/`uname -r`/build
16 | endif
17 | ifeq ($(MODNAME),)
18 | export MODNAME=drop-packet
19 | endif
20 |
21 | all:
22 | make CFLAGS_MODULE=-D$(OS_VER) -C /lib/modules/`uname -r`/build M=`pwd` modules
23 | clean:
24 | make -C $(KERNEL_BUILD_PATH) M=$(PWD) clean
25 | endif
26 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step5/Module.symvers:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step5/Module.symvers
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step5/drop-packet.ko:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step5/drop-packet.ko
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step5/drop-packet.mod.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | MODULE_INFO(vermagic, VERMAGIC_STRING);
6 | MODULE_INFO(name, KBUILD_MODNAME);
7 |
8 | __visible struct module __this_module
9 | __attribute__((section(".gnu.linkonce.this_module"))) = {
10 | .name = KBUILD_MODNAME,
11 | .init = init_module,
12 | #ifdef CONFIG_MODULE_UNLOAD
13 | .exit = cleanup_module,
14 | #endif
15 | .arch = MODULE_ARCH_INIT,
16 | };
17 |
18 | #ifdef RETPOLINE
19 | MODULE_INFO(retpoline, "Y");
20 | #endif
21 |
22 | static const char __module_depends[]
23 | __used
24 | __attribute__((section(".modinfo"))) =
25 | "depends=";
26 |
27 |
28 | MODULE_INFO(srcversion, "7781F3F64D532FB0403CF41");
29 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step5/drop-packet.mod.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step5/drop-packet.mod.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step5/drop-packet.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step5/drop-packet.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step5/drop_packet.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Baoyou Xie's drop-packet module
3 | *
4 | * Copyright (C) 2018 Baoyou Xie.
5 | *
6 | * Author: Baoyou Xie
7 | *
8 | * License terms: GNU General Public License (GPL) version 2
9 | */
10 | #include
11 |
12 | int hook_kprobe(struct kprobe *kp, const char *name,
13 | kprobe_pre_handler_t pre, kprobe_post_handler_t post);
14 | void unhook_kprobe(struct kprobe *kp);
15 | int hook_tracepoint(const char *name, void *probe, void *data);
16 | int unhook_tracepoint(const char *name, void *probe, void *data);
17 |
18 | unsigned int ipstr2int(const char *ipstr);
19 | char *int2ipstr(const unsigned int ip, char *ipstr, const unsigned int ip_str_len);
20 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step5/index.html:
--------------------------------------------------------------------------------
1 |
2 | 百度一下,你就知道
3 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step5/main.c:
--------------------------------------------------------------------------------
1 | /**
2 | * Baoyou Xie's drop-packet module
3 | *
4 | * Copyright (C) 2018 Baoyou Xie.
5 | *
6 | * Author: Baoyou Xie
7 | *
8 | * License terms: GNU General Public License (GPL) version 2
9 | */
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 |
22 | #include "drop_packet.h"
23 |
24 | static unsigned long drop_packet_activated;
25 |
26 | static unsigned int drop_patcket_saddr = 0;
27 | static unsigned int drop_patcket_sport = 0;
28 | static unsigned int drop_patcket_daddr = 0;
29 | static unsigned int drop_patcket_dport = 0;
30 |
31 | static struct rb_root drop_packet_tree = RB_ROOT;
32 | static LIST_HEAD(drop_packet_list);
33 | static DEFINE_SPINLOCK(drop_packet_lock);
34 |
35 | static struct kprobe kprobe_eth_type_trans;
36 | static struct kprobe kprobe_napi_gro_receive;
37 | static struct kprobe kprobe___netif_receive_skb_core;
38 | static struct kprobe kprobe_tcp_v4_rcv;
39 |
40 | enum packet_footprint
41 | {
42 | ETH_RECV,
43 | GRO_RECV,
44 | RECV_SKB,
45 | TCP_V4_RCV,
46 | SEND_SKB,
47 | TRACK_COUNT,
48 | };
49 |
50 | static char *packet_footprint_str[TRACK_COUNT] = {
51 | "ETH_RECV",
52 | "GRO_RECV",
53 | "RECV_SKB",
54 | "TCP_V4_RCV",
55 | "SEND_SKB",
56 | };
57 |
58 | struct conn_desc
59 | {
60 | int protocol;
61 | int saddr;
62 | int sport;
63 | int daddr;
64 | int dport;
65 |
66 | atomic64_t packages[TRACK_COUNT];
67 |
68 | struct rb_node rb_node;
69 | struct list_head list;
70 | };
71 |
72 | __maybe_unused int compare_conn(__u8 protocol,
73 | unsigned int saddr,
74 | unsigned int sport,
75 | unsigned int daddr,
76 | unsigned int dport,
77 | struct conn_desc *conn)
78 | {
79 | if (protocol < conn->protocol)
80 | return -1;
81 | if (protocol > conn->protocol)
82 | return 1;
83 | if (saddr < conn->saddr)
84 | return -1;
85 | if (saddr > conn->saddr)
86 | return 1;
87 | if (sport < conn->sport)
88 | return -1;
89 | if (sport > conn->sport)
90 | return 1;
91 | if (daddr < conn->daddr)
92 | return -1;
93 | if (daddr > conn->daddr)
94 | return 1;
95 | if (dport < conn->dport)
96 | return -1;
97 | if (dport > conn->dport)
98 | return 1;
99 |
100 | return 0;
101 | }
102 |
103 | __maybe_unused static struct conn_desc *__find_alloc_desc(struct rb_root *root,
104 | __u8 protocol,
105 | unsigned int saddr,
106 | unsigned int sport,
107 | unsigned int daddr,
108 | unsigned int dport)
109 | {
110 | struct rb_node **node, *parent;
111 | struct conn_desc *conn_desc = NULL;
112 |
113 | node = &root->rb_node;
114 | parent = NULL;
115 | while (*node != NULL) {
116 | struct conn_desc *this;
117 | int ret = 0;
118 |
119 | parent = *node;
120 | this = container_of(parent, struct conn_desc, rb_node);
121 | ret = compare_conn(protocol, saddr, sport, daddr, dport, this);
122 |
123 | if (ret < 0)
124 | node = &parent->rb_left;
125 | else if (ret > 0)
126 | node = &parent->rb_right;
127 | else
128 | return this;
129 | }
130 |
131 | conn_desc = kmalloc(sizeof(struct conn_desc), GFP_ATOMIC | __GFP_ZERO);
132 | if (conn_desc) {
133 | conn_desc->protocol = protocol;
134 | conn_desc->saddr = saddr;
135 | conn_desc->sport = sport;
136 | conn_desc->daddr = daddr;
137 | conn_desc->dport = dport;
138 |
139 | INIT_LIST_HEAD(&conn_desc->list);
140 | list_add_tail(&conn_desc->list, &drop_packet_list);
141 | rb_link_node(&conn_desc->rb_node, parent, node);
142 | rb_insert_color(&conn_desc->rb_node, root);
143 | }
144 |
145 | return conn_desc;
146 | }
147 |
148 | __maybe_unused static struct conn_desc *find_alloc_desc(__u8 protocol,
149 | unsigned int saddr,
150 | unsigned int sport,
151 | unsigned int daddr,
152 | unsigned int dport)
153 | {
154 | unsigned long flags;
155 | struct conn_desc *ret;
156 |
157 | spin_lock_irqsave(&drop_packet_lock, flags);
158 | ret = __find_alloc_desc(&drop_packet_tree, protocol,
159 | saddr, sport, daddr, dport);
160 | spin_unlock_irqrestore(&drop_packet_lock, flags);
161 |
162 | return ret;
163 | }
164 |
165 | static void trace_packet(const struct sk_buff *skb,
166 | const struct iphdr *iphdr, enum packet_footprint fp)
167 | {
168 | int source = 0;
169 | int dest = 0;
170 | struct conn_desc *conn_desc;
171 |
172 | if (fp >= TRACK_COUNT)
173 | return;
174 |
175 | if (iphdr->protocol == IPPROTO_UDP)
176 | {
177 | struct udphdr *uh;
178 |
179 | uh = (void *)iphdr + iphdr->ihl * 4;
180 | source = be16_to_cpu(uh->source);
181 | dest = be16_to_cpu(uh->dest);
182 | }
183 | else if (iphdr->protocol == IPPROTO_TCP)
184 | {
185 | struct tcphdr *th;
186 |
187 | th = (void *)iphdr + iphdr->ihl * 4;
188 | source = be16_to_cpu(th->source);
189 | dest = be16_to_cpu(th->dest);
190 | } else
191 | return;
192 |
193 | conn_desc = find_alloc_desc(iphdr->protocol,
194 | iphdr->saddr, source, iphdr->daddr, dest);
195 | if (!conn_desc)
196 | return;
197 |
198 | atomic64_inc(&conn_desc->packages[fp]);
199 | }
200 |
201 | static void trace_net_dev_xmit_hit(void *ignore, struct sk_buff *skb,
202 | int rc, struct net_device *dev, unsigned int skb_len)
203 | {
204 | struct iphdr *iphdr;
205 |
206 | if (!drop_packet_activated)
207 | return;
208 |
209 | if (rc != NETDEV_TX_OK)
210 | return;
211 |
212 | iphdr = ip_hdr(skb);
213 | trace_packet(skb, iphdr, SEND_SKB);
214 | }
215 |
216 | static int kprobe_eth_type_trans_pre(struct kprobe *p, struct pt_regs *regs)
217 | {
218 | struct sk_buff *skb = (void *)regs->di;
219 | struct iphdr *iphdr;
220 |
221 | if (!drop_packet_activated)
222 | return 0;
223 |
224 | iphdr = (struct iphdr *)(skb->data + ETH_HLEN);
225 | trace_packet(skb, iphdr, ETH_RECV);
226 |
227 | return 0;
228 | }
229 |
230 | static int kprobe_napi_gro_receive_pre(struct kprobe *p, struct pt_regs *regs)
231 | {
232 | struct sk_buff *skb = (void *)regs->si;
233 | struct iphdr *iphdr;
234 |
235 | if (!drop_packet_activated)
236 | return 0;
237 |
238 | if (skb->protocol != cpu_to_be16(ETH_P_IP))
239 | return 0;
240 |
241 | iphdr = (struct iphdr *)skb->data;
242 | trace_packet(skb, iphdr, GRO_RECV);
243 |
244 | return 0;
245 | }
246 |
247 | static int kprobe___netif_receive_skb_core_pre(struct kprobe *p, struct pt_regs *regs)
248 | {
249 | struct sk_buff *skb = (void *)regs->di;
250 | struct iphdr *iphdr;
251 |
252 | if (!drop_packet_activated)
253 | return 0;
254 |
255 | if (skb->protocol != cpu_to_be16(ETH_P_IP))
256 | return 0;
257 |
258 | iphdr = (struct iphdr *)skb->data;
259 | trace_packet(skb, iphdr, RECV_SKB);
260 |
261 | return 0;
262 | }
263 |
264 | static int kprobe_tcp_v4_rcv_pre(struct kprobe *p, struct pt_regs *regs)
265 | {
266 | struct sk_buff *skb = (void *)regs->di;
267 | struct iphdr *iphdr;
268 |
269 | if (!drop_packet_activated)
270 | return 0;
271 |
272 | if (skb->protocol != cpu_to_be16(ETH_P_IP))
273 | return 0;
274 |
275 | iphdr = ip_hdr(skb);
276 | trace_packet(skb, iphdr, TCP_V4_RCV);
277 |
278 | return 0;
279 | }
280 |
281 | static int activate_drop_packet(void)
282 | {
283 | hook_tracepoint("net_dev_xmit", trace_net_dev_xmit_hit, NULL);
284 | hook_kprobe(&kprobe_eth_type_trans, "eth_type_trans",
285 | kprobe_eth_type_trans_pre, NULL);
286 | hook_kprobe(&kprobe_napi_gro_receive, "napi_gro_receive",
287 | kprobe_napi_gro_receive_pre, NULL);
288 | hook_kprobe(&kprobe___netif_receive_skb_core, "__netif_receive_skb_core",
289 | kprobe___netif_receive_skb_core_pre, NULL);
290 | hook_kprobe(&kprobe_tcp_v4_rcv, "tcp_v4_rcv",
291 | kprobe_tcp_v4_rcv_pre, NULL);
292 |
293 | return 1;
294 | }
295 |
296 | static void deactivate_drop_packet(void)
297 | {
298 | unhook_tracepoint("net_dev_xmit", trace_net_dev_xmit_hit, NULL);
299 | unhook_kprobe(&kprobe_eth_type_trans);
300 | unhook_kprobe(&kprobe_napi_gro_receive);
301 | unhook_kprobe(&kprobe___netif_receive_skb_core);
302 | unhook_kprobe(&kprobe_tcp_v4_rcv);
303 | }
304 |
305 | static int drop_packet_show(struct seq_file *m, void *v)
306 | {
307 | struct conn_desc *this;
308 | unsigned long flags;
309 | struct list_head header;
310 | int i;
311 |
312 | seq_printf(m, "settings:\n");
313 | seq_printf(m, " activated: %s\n", drop_packet_activated ? "y" : "N");
314 |
315 | INIT_LIST_HEAD(&header);
316 | spin_lock_irqsave(&drop_packet_lock, flags);
317 | drop_packet_tree = RB_ROOT;
318 | list_splice_init(&drop_packet_list, &header);
319 | spin_unlock_irqrestore(&drop_packet_lock, flags);
320 |
321 | synchronize_sched();
322 |
323 | list_for_each_entry(this, &header, list)
324 | {
325 | unsigned char *saddr = (void *)&this->saddr;
326 | unsigned char *daddr = (void *)&this->daddr;
327 |
328 | seq_printf(m,
329 | "protocol:%s, Source IP: %u.%u.%u.%u, Source Port: %d, "
330 | "Dest IP: %u.%u.%u.%u, Dest Port: %d\n",
331 | this->protocol == IPPROTO_UDP ? "UDP" : "TCP",
332 | saddr[0], saddr[1], saddr[2], saddr[3], this->sport,
333 | daddr[0], daddr[1], daddr[2], daddr[3], this->dport);
334 | for (i = 0; i < TRACK_COUNT; i++) {
335 | seq_printf(m,
336 | " %s: %lu\n",
337 | packet_footprint_str[i],
338 | atomic64_read(&this->packages[i]));
339 | }
340 | }
341 |
342 | while (!list_empty(&header))
343 | {
344 | struct conn_desc *this = list_first_entry(&header,
345 | struct conn_desc, list);
346 |
347 | list_del_init(&this->list);
348 | kfree(this);
349 | }
350 |
351 | return 0;
352 | }
353 |
354 | static int drop_packet_open(struct inode *inode, struct file *filp)
355 | {
356 | return single_open(filp, drop_packet_show, NULL);
357 | }
358 |
359 | static ssize_t drop_packet_write(struct file *file,
360 | const char __user *buf, size_t count, loff_t *offs)
361 | {
362 | int ret;
363 | char cmd[255];
364 | char chr[255];
365 |
366 | if (count < 1 || *offs)
367 | return -EINVAL;
368 |
369 | if (copy_from_user(chr, buf, 255))
370 | return -EFAULT;
371 |
372 | ret = sscanf(chr, "%255s", cmd);
373 | if (ret <= 0)
374 | return -EINVAL;
375 |
376 | if (strcmp(cmd, "activate") == 0) {
377 | if (!drop_packet_activated)
378 | drop_packet_activated = activate_drop_packet();
379 | } else if (strcmp(cmd, "deactivate") == 0) {
380 | if (drop_packet_activated)
381 | deactivate_drop_packet();
382 | drop_packet_activated = 0;
383 | } else if (strcmp(cmd, "source-addr") == 0) {
384 | char addr[255];
385 |
386 | ret = sscanf(chr, "%255s %255s", cmd, addr);
387 | if (ret == 2) {
388 | drop_patcket_saddr = ipstr2int(addr);
389 | } else if (ret == 1) {
390 | drop_patcket_saddr = 0;
391 | }
392 | } else if (strcmp(cmd, "source-port") == 0) {
393 | unsigned int port;
394 |
395 | ret = sscanf(chr, "%255s %255d", cmd, &port);
396 | if (ret == 2) {
397 | drop_patcket_sport = port;
398 | } else if (ret == 1) {
399 | drop_patcket_sport = 0;
400 | }
401 | } else if (strcmp(cmd, "dest-addr") == 0) {
402 | char addr[255];
403 |
404 | ret = sscanf(chr, "%255s %255s", cmd, addr);
405 | if (ret == 2) {
406 | drop_patcket_daddr = ipstr2int(addr);
407 | } else if (ret == 1) {
408 | drop_patcket_daddr = 0;
409 | }
410 | } else if (strcmp(cmd, "dest-port") == 0) {
411 | unsigned int port;
412 |
413 | ret = sscanf(chr, "%255s %255d", cmd, &port);
414 | if (ret == 2) {
415 | drop_patcket_dport = port;
416 | } else if (ret == 1) {
417 | drop_patcket_dport = 0;
418 | }
419 | }
420 |
421 | return count;
422 | }
423 |
424 | const struct file_operations drop_packet_fops = {
425 | .open = drop_packet_open,
426 | .read = seq_read,
427 | .llseek = seq_lseek,
428 | .write = drop_packet_write,
429 | .release = single_release,
430 | };
431 |
432 | static int drop_packet_init(void)
433 | {
434 | int ret;
435 | struct proc_dir_entry *pe;
436 |
437 | proc_mkdir("mooc", NULL);
438 | proc_mkdir("mooc/net", NULL);
439 |
440 | ret = -ENOMEM;
441 | pe = proc_create("mooc/net/drop-packet",
442 | S_IFREG | 0644,
443 | NULL,
444 | &drop_packet_fops);
445 | if (!pe)
446 | goto err_proc;
447 |
448 | printk("drop-packet loaded.\n");
449 |
450 | return 0;
451 |
452 | err_proc:
453 | return ret;
454 | }
455 |
456 | static void drop_packet_exit(void)
457 | {
458 | remove_proc_entry("mooc/net/drop-packet", NULL);
459 | remove_proc_entry("mooc/net", NULL);
460 | remove_proc_entry("mooc", NULL);
461 |
462 | if (drop_packet_activated)
463 | deactivate_drop_packet();
464 | drop_packet_activated = 0;
465 |
466 | printk("drop-packet unloaded.\n");
467 | }
468 |
469 | module_init(drop_packet_init)
470 | module_exit(drop_packet_exit)
471 |
472 | MODULE_DESCRIPTION("Baoyou Xie's drop-packet module");
473 | MODULE_AUTHOR("Baoyou Xie ");
474 | MODULE_LICENSE("GPL v2");
475 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step5/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step5/main.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step5/misc.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "drop_packet.h"
6 |
7 | int hook_kprobe(struct kprobe *kp, const char *name,
8 | kprobe_pre_handler_t pre, kprobe_post_handler_t post)
9 | {
10 | kprobe_opcode_t *addr;
11 |
12 | if (!name || strlen(name) >= 255)
13 | return -EINVAL;
14 | addr = (kprobe_opcode_t *)kallsyms_lookup_name(name);
15 | if (!addr)
16 | return -EINVAL;
17 |
18 | memset(kp, 0, sizeof(struct kprobe));
19 | kp->symbol_name = name;
20 | kp->pre_handler = pre;
21 | kp->post_handler = post;
22 |
23 | register_kprobe(kp);
24 |
25 | return 0;
26 | }
27 |
28 | void unhook_kprobe(struct kprobe *kp)
29 | {
30 | unregister_kprobe(kp);
31 | memset(kp, 0, sizeof(struct kprobe));
32 | }
33 |
34 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
35 | int hook_tracepoint(const char *name, void *probe, void *data)
36 | {
37 | return tracepoint_probe_register(name, probe);
38 | }
39 |
40 | int unhook_tracepoint(const char *name, void *probe, void *data)
41 | {
42 | return tracepoint_probe_unregister(name, probe);
43 | }
44 | #elif LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0)
45 | int hook_tracepoint(const char *name, void *probe, void *data)
46 | {
47 | return tracepoint_probe_register(name, probe, data);
48 | }
49 |
50 | int unhook_tracepoint(const char *name, void *probe, void *data)
51 | {
52 | return tracepoint_probe_unregister(name, probe, data);
53 | }
54 | #else
55 | static struct tracepoint *tp_ret;
56 | static void probe_tracepoint(struct tracepoint *tp, void *priv)
57 | {
58 | char *n = priv;
59 |
60 | if (strcmp(tp->name, n) == 0)
61 | tp_ret = tp;
62 | }
63 |
64 | static struct tracepoint *find_tracepoint(const char *name)
65 | {
66 | tp_ret = NULL;
67 | for_each_kernel_tracepoint(probe_tracepoint, (void *)name);
68 |
69 | return tp_ret;
70 | }
71 |
72 | int hook_tracepoint(const char *name, void *probe, void *data)
73 | {
74 | struct tracepoint *tp;
75 |
76 | tp = find_tracepoint(name);
77 | if (!tp)
78 | return 0;
79 |
80 | return tracepoint_probe_register(tp, probe, data);
81 | }
82 |
83 | int unhook_tracepoint(const char *name, void *probe, void *data)
84 | {
85 | struct tracepoint *tp;
86 |
87 | tp = find_tracepoint(name);
88 | if (!tp)
89 | return 0;
90 |
91 | return tracepoint_probe_unregister(tp, probe, data);
92 | }
93 | #endif
94 |
95 | #define IP_STR_LEN 18
96 | #define MAC_STR_LEN 18
97 | #define MAC_BIT_LEN 6
98 | #define LITTLE_ENDIAN 0
99 | #define BIG_ENDIAN 1
100 |
101 | int big_little_endian(void)
102 | {
103 | int data = 0x1;
104 |
105 | if (*((char *)&data) == 0x1)
106 | return LITTLE_ENDIAN;
107 |
108 | return BIG_ENDIAN;
109 | }
110 |
111 | unsigned int ipstr2int(const char *ipstr)
112 | {
113 | unsigned int a, b, c, d;
114 | unsigned int ip = 0;
115 | int count;
116 |
117 | count = sscanf(ipstr, "%u.%u.%u.%u", &a, &b, &c, &d);
118 | if (count == 4) {
119 | a = (a << 24);
120 | b = (b << 16);
121 | c = (c << 8);
122 | d = (d << 0);
123 | ip = a | b | c | d;
124 |
125 | return ip;
126 | } else {
127 | return 0;
128 | }
129 | }
130 |
131 | char *int2ipstr(const unsigned int ip, char *ipstr, const unsigned int ip_str_len)
132 | {
133 | int len;
134 |
135 | if (big_little_endian() == LITTLE_ENDIAN)
136 | len = snprintf(ipstr, ip_str_len, "%u.%u.%u.%u",
137 | (unsigned char) * ((char *)(&ip) + 3),
138 | (unsigned char) * ((char *)(&ip) + 2),
139 | (unsigned char) * ((char *)(&ip) + 1),
140 | (unsigned char) * ((char *)(&ip) + 0));
141 | else
142 | len = snprintf(ipstr, ip_str_len, "%u.%u.%u.%u",
143 | (unsigned char) * ((char *)(&ip) + 0),
144 | (unsigned char) * ((char *)(&ip) + 1),
145 | (unsigned char) * ((char *)(&ip) + 2),
146 | (unsigned char) * ((char *)(&ip) + 3));
147 |
148 | if (len < ip_str_len)
149 | return ipstr;
150 | else
151 | return NULL;
152 | }
153 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step5/misc.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step5/misc.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step5/modules.order:
--------------------------------------------------------------------------------
1 | kernel//home/xiebaoyou/study/陈老师/drop-packet/src/step5/drop-packet.ko
2 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step6/.drop-packet.ko.cmd:
--------------------------------------------------------------------------------
1 | cmd_/home/xiebaoyou/study/陈老师/drop-packet/src/step6/drop-packet.ko := ld -r -m elf_x86_64 -z max-page-size=0x200000 -T ./scripts/module-common.lds --build-id -o /home/xiebaoyou/study/陈老师/drop-packet/src/step6/drop-packet.ko /home/xiebaoyou/study/陈老师/drop-packet/src/step6/drop-packet.o /home/xiebaoyou/study/陈老师/drop-packet/src/step6/drop-packet.mod.o ; true
2 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step6/.drop-packet.o.cmd:
--------------------------------------------------------------------------------
1 | cmd_/home/xiebaoyou/study/陈老师/drop-packet/src/step6/drop-packet.o := ld -m elf_x86_64 -z max-page-size=0x200000 -r -o /home/xiebaoyou/study/陈老师/drop-packet/src/step6/drop-packet.o /home/xiebaoyou/study/陈老师/drop-packet/src/step6/main.o /home/xiebaoyou/study/陈老师/drop-packet/src/step6/misc.o
2 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step6/.tmp_versions/drop-packet.mod:
--------------------------------------------------------------------------------
1 | /home/xiebaoyou/study/陈老师/drop-packet/src/step6/drop-packet.ko
2 | /home/xiebaoyou/study/陈老师/drop-packet/src/step6/main.o /home/xiebaoyou/study/陈老师/drop-packet/src/step6/misc.o
3 |
4 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step6/Makefile:
--------------------------------------------------------------------------------
1 | OS_VER := UNKNOWN
2 | UNAME := $(shell uname -r)
3 | ifneq ($(findstring 4.15.0-39-generic,$(UNAME)),)
4 | OS_VER := UBUNTU_1604
5 | endif
6 |
7 | ifneq ($(KERNELRELEASE),)
8 | obj-m += $(MODNAME).o
9 | $(MODNAME)-y := main.o misc.o
10 | ccflags-y := -I$(PWD)/
11 | else
12 | export PWD=`pwd`
13 |
14 | ifeq ($(KERNEL_BUILD_PATH),)
15 | KERNEL_BUILD_PATH := /lib/modules/`uname -r`/build
16 | endif
17 | ifeq ($(MODNAME),)
18 | export MODNAME=drop-packet
19 | endif
20 |
21 | all:
22 | make CFLAGS_MODULE=-D$(OS_VER) -C /lib/modules/`uname -r`/build M=`pwd` modules
23 | clean:
24 | make -C $(KERNEL_BUILD_PATH) M=$(PWD) clean
25 | endif
26 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step6/Module.symvers:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step6/Module.symvers
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step6/drop-packet.ko:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step6/drop-packet.ko
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step6/drop-packet.mod.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | MODULE_INFO(vermagic, VERMAGIC_STRING);
6 | MODULE_INFO(name, KBUILD_MODNAME);
7 |
8 | __visible struct module __this_module
9 | __attribute__((section(".gnu.linkonce.this_module"))) = {
10 | .name = KBUILD_MODNAME,
11 | .init = init_module,
12 | #ifdef CONFIG_MODULE_UNLOAD
13 | .exit = cleanup_module,
14 | #endif
15 | .arch = MODULE_ARCH_INIT,
16 | };
17 |
18 | #ifdef RETPOLINE
19 | MODULE_INFO(retpoline, "Y");
20 | #endif
21 |
22 | static const char __module_depends[]
23 | __used
24 | __attribute__((section(".modinfo"))) =
25 | "depends=";
26 |
27 |
28 | MODULE_INFO(srcversion, "05E5DEECA29C9E2F073ED10");
29 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step6/drop-packet.mod.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step6/drop-packet.mod.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step6/drop-packet.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step6/drop-packet.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step6/drop_packet.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Baoyou Xie's drop-packet module
3 | *
4 | * Copyright (C) 2018 Baoyou Xie.
5 | *
6 | * Author: Baoyou Xie
7 | *
8 | * License terms: GNU General Public License (GPL) version 2
9 | */
10 | #include
11 |
12 | int hook_kprobe(struct kprobe *kp, const char *name,
13 | kprobe_pre_handler_t pre, kprobe_post_handler_t post);
14 | void unhook_kprobe(struct kprobe *kp);
15 | int hook_tracepoint(const char *name, void *probe, void *data);
16 | int unhook_tracepoint(const char *name, void *probe, void *data);
17 |
18 | unsigned int ipstr2int(const char *ipstr);
19 | char *int2ipstr(const unsigned int ip, char *ipstr, const unsigned int ip_str_len);
20 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step6/index.html:
--------------------------------------------------------------------------------
1 |
2 | 百度一下,你就知道
3 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step6/main.c:
--------------------------------------------------------------------------------
1 | /**
2 | * Baoyou Xie's drop-packet module
3 | *
4 | * Copyright (C) 2018 Baoyou Xie.
5 | *
6 | * Author: Baoyou Xie
7 | *
8 | * License terms: GNU General Public License (GPL) version 2
9 | */
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 |
22 | #include "drop_packet.h"
23 |
24 | static unsigned long drop_packet_activated;
25 |
26 | static unsigned int drop_patcket_saddr = 0;
27 | static unsigned int drop_patcket_sport = 0;
28 | static unsigned int drop_patcket_daddr = 0;
29 | static unsigned int drop_patcket_dport = 0;
30 |
31 | static struct rb_root drop_packet_tree = RB_ROOT;
32 | static LIST_HEAD(drop_packet_list);
33 | static DEFINE_SPINLOCK(drop_packet_lock);
34 |
35 | static struct kprobe kprobe_eth_type_trans;
36 | static struct kprobe kprobe_napi_gro_receive;
37 | static struct kprobe kprobe___netif_receive_skb_core;
38 | static struct kprobe kprobe_tcp_v4_rcv;
39 |
40 | enum packet_footprint
41 | {
42 | ETH_RECV,
43 | GRO_RECV,
44 | RECV_SKB,
45 | TCP_V4_RCV,
46 | SEND_SKB,
47 | TRACK_COUNT,
48 | };
49 |
50 | static char *packet_footprint_str[TRACK_COUNT] = {
51 | "ETH_RECV",
52 | "GRO_RECV",
53 | "RECV_SKB",
54 | "TCP_V4_RCV",
55 | "SEND_SKB",
56 | };
57 |
58 | struct conn_desc
59 | {
60 | int protocol;
61 | int saddr;
62 | int sport;
63 | int daddr;
64 | int dport;
65 |
66 | atomic64_t packages[TRACK_COUNT];
67 |
68 | struct rb_node rb_node;
69 | struct list_head list;
70 | };
71 |
72 | __maybe_unused static void clean_data(void)
73 | {
74 | unsigned long flags;
75 | struct list_head header;
76 |
77 | INIT_LIST_HEAD(&header);
78 | spin_lock_irqsave(&drop_packet_lock, flags);
79 | drop_packet_tree = RB_ROOT;
80 | list_splice_init(&drop_packet_list, &header);
81 | spin_unlock_irqrestore(&drop_packet_lock, flags);
82 |
83 | synchronize_sched();
84 |
85 | while (!list_empty(&header))
86 | {
87 | struct conn_desc *this = list_first_entry(&header, struct conn_desc, list);
88 |
89 | list_del_init(&this->list);
90 | kfree(this);
91 | }
92 | }
93 |
94 | __maybe_unused int compare_conn(__u8 protocol,
95 | unsigned int saddr,
96 | unsigned int sport,
97 | unsigned int daddr,
98 | unsigned int dport,
99 | struct conn_desc *conn)
100 | {
101 | if (protocol < conn->protocol)
102 | return -1;
103 | if (protocol > conn->protocol)
104 | return 1;
105 | if (saddr < conn->saddr)
106 | return -1;
107 | if (saddr > conn->saddr)
108 | return 1;
109 | if (sport < conn->sport)
110 | return -1;
111 | if (sport > conn->sport)
112 | return 1;
113 | if (daddr < conn->daddr)
114 | return -1;
115 | if (daddr > conn->daddr)
116 | return 1;
117 | if (dport < conn->dport)
118 | return -1;
119 | if (dport > conn->dport)
120 | return 1;
121 |
122 | return 0;
123 | }
124 |
125 | __maybe_unused static struct conn_desc *__find_alloc_desc(struct rb_root *root,
126 | __u8 protocol,
127 | unsigned int saddr,
128 | unsigned int sport,
129 | unsigned int daddr,
130 | unsigned int dport)
131 | {
132 | struct rb_node **node, *parent;
133 | struct conn_desc *conn_desc = NULL;
134 |
135 | node = &root->rb_node;
136 | parent = NULL;
137 | while (*node != NULL) {
138 | struct conn_desc *this;
139 | int ret = 0;
140 |
141 | parent = *node;
142 | this = container_of(parent, struct conn_desc, rb_node);
143 | ret = compare_conn(protocol, saddr, sport, daddr, dport, this);
144 |
145 | if (ret < 0)
146 | node = &parent->rb_left;
147 | else if (ret > 0)
148 | node = &parent->rb_right;
149 | else
150 | return this;
151 | }
152 |
153 | conn_desc = kmalloc(sizeof(struct conn_desc), GFP_ATOMIC | __GFP_ZERO);
154 | if (conn_desc) {
155 | conn_desc->protocol = protocol;
156 | conn_desc->saddr = saddr;
157 | conn_desc->sport = sport;
158 | conn_desc->daddr = daddr;
159 | conn_desc->dport = dport;
160 |
161 | INIT_LIST_HEAD(&conn_desc->list);
162 | list_add_tail(&conn_desc->list, &drop_packet_list);
163 | rb_link_node(&conn_desc->rb_node, parent, node);
164 | rb_insert_color(&conn_desc->rb_node, root);
165 | }
166 |
167 | return conn_desc;
168 | }
169 |
170 | __maybe_unused static struct conn_desc *find_alloc_desc(__u8 protocol,
171 | unsigned int saddr,
172 | unsigned int sport,
173 | unsigned int daddr,
174 | unsigned int dport)
175 | {
176 | unsigned long flags;
177 | struct conn_desc *ret;
178 |
179 | spin_lock_irqsave(&drop_packet_lock, flags);
180 | ret = __find_alloc_desc(&drop_packet_tree, protocol,
181 | saddr, sport, daddr, dport);
182 | spin_unlock_irqrestore(&drop_packet_lock, flags);
183 |
184 | return ret;
185 | }
186 |
187 | static void trace_packet(const struct sk_buff *skb,
188 | const struct iphdr *iphdr, enum packet_footprint fp)
189 | {
190 | int source = 0;
191 | int dest = 0;
192 | struct conn_desc *conn_desc;
193 |
194 | if (fp >= TRACK_COUNT)
195 | return;
196 |
197 | if (iphdr->protocol == IPPROTO_UDP)
198 | {
199 | struct udphdr *uh;
200 |
201 | uh = (void *)iphdr + iphdr->ihl * 4;
202 | source = be16_to_cpu(uh->source);
203 | dest = be16_to_cpu(uh->dest);
204 | }
205 | else if (iphdr->protocol == IPPROTO_TCP)
206 | {
207 | struct tcphdr *th;
208 |
209 | th = (void *)iphdr + iphdr->ihl * 4;
210 | source = be16_to_cpu(th->source);
211 | dest = be16_to_cpu(th->dest);
212 | } else
213 | return;
214 |
215 | conn_desc = find_alloc_desc(iphdr->protocol,
216 | iphdr->saddr, source, iphdr->daddr, dest);
217 | if (!conn_desc)
218 | return;
219 |
220 | atomic64_inc(&conn_desc->packages[fp]);
221 | }
222 |
223 | static void trace_net_dev_xmit_hit(void *ignore, struct sk_buff *skb,
224 | int rc, struct net_device *dev, unsigned int skb_len)
225 | {
226 | struct iphdr *iphdr;
227 |
228 | if (!drop_packet_activated)
229 | return;
230 |
231 | if (rc != NETDEV_TX_OK)
232 | return;
233 |
234 | iphdr = ip_hdr(skb);
235 | trace_packet(skb, iphdr, SEND_SKB);
236 | }
237 |
238 | static int kprobe_eth_type_trans_pre(struct kprobe *p, struct pt_regs *regs)
239 | {
240 | struct sk_buff *skb = (void *)regs->di;
241 | struct iphdr *iphdr;
242 |
243 | if (!drop_packet_activated)
244 | return 0;
245 |
246 | iphdr = (struct iphdr *)(skb->data + ETH_HLEN);
247 | trace_packet(skb, iphdr, ETH_RECV);
248 |
249 | return 0;
250 | }
251 |
252 | static int kprobe_napi_gro_receive_pre(struct kprobe *p, struct pt_regs *regs)
253 | {
254 | struct sk_buff *skb = (void *)regs->si;
255 | struct iphdr *iphdr;
256 |
257 | if (!drop_packet_activated)
258 | return 0;
259 |
260 | if (skb->protocol != cpu_to_be16(ETH_P_IP))
261 | return 0;
262 |
263 | iphdr = (struct iphdr *)skb->data;
264 | trace_packet(skb, iphdr, GRO_RECV);
265 |
266 | return 0;
267 | }
268 |
269 | static int kprobe___netif_receive_skb_core_pre(struct kprobe *p, struct pt_regs *regs)
270 | {
271 | struct sk_buff *skb = (void *)regs->di;
272 | struct iphdr *iphdr;
273 |
274 | if (!drop_packet_activated)
275 | return 0;
276 |
277 | if (skb->protocol != cpu_to_be16(ETH_P_IP))
278 | return 0;
279 |
280 | iphdr = (struct iphdr *)skb->data;
281 | trace_packet(skb, iphdr, RECV_SKB);
282 |
283 | return 0;
284 | }
285 |
286 | static int kprobe_tcp_v4_rcv_pre(struct kprobe *p, struct pt_regs *regs)
287 | {
288 | struct sk_buff *skb = (void *)regs->di;
289 | struct iphdr *iphdr;
290 |
291 | if (!drop_packet_activated)
292 | return 0;
293 |
294 | if (skb->protocol != cpu_to_be16(ETH_P_IP))
295 | return 0;
296 |
297 | iphdr = ip_hdr(skb);
298 | trace_packet(skb, iphdr, TCP_V4_RCV);
299 |
300 | return 0;
301 | }
302 |
303 | static int activate_drop_packet(void)
304 | {
305 | clean_data();
306 |
307 | hook_tracepoint("net_dev_xmit", trace_net_dev_xmit_hit, NULL);
308 | hook_kprobe(&kprobe_eth_type_trans, "eth_type_trans",
309 | kprobe_eth_type_trans_pre, NULL);
310 | hook_kprobe(&kprobe_napi_gro_receive, "napi_gro_receive",
311 | kprobe_napi_gro_receive_pre, NULL);
312 | hook_kprobe(&kprobe___netif_receive_skb_core, "__netif_receive_skb_core",
313 | kprobe___netif_receive_skb_core_pre, NULL);
314 | hook_kprobe(&kprobe_tcp_v4_rcv, "tcp_v4_rcv",
315 | kprobe_tcp_v4_rcv_pre, NULL);
316 |
317 | return 1;
318 | }
319 |
320 | static void deactivate_drop_packet(void)
321 | {
322 | unhook_tracepoint("net_dev_xmit", trace_net_dev_xmit_hit, NULL);
323 | unhook_kprobe(&kprobe_eth_type_trans);
324 | unhook_kprobe(&kprobe_napi_gro_receive);
325 | unhook_kprobe(&kprobe___netif_receive_skb_core);
326 | unhook_kprobe(&kprobe_tcp_v4_rcv);
327 |
328 | clean_data();
329 | }
330 |
331 | static int drop_packet_show(struct seq_file *m, void *v)
332 | {
333 | struct conn_desc *this;
334 | unsigned long flags;
335 | struct list_head header;
336 | int i;
337 |
338 | seq_printf(m, "settings:\n");
339 | seq_printf(m, " activated: %s\n", drop_packet_activated ? "y" : "N");
340 |
341 | INIT_LIST_HEAD(&header);
342 | spin_lock_irqsave(&drop_packet_lock, flags);
343 | drop_packet_tree = RB_ROOT;
344 | list_splice_init(&drop_packet_list, &header);
345 | spin_unlock_irqrestore(&drop_packet_lock, flags);
346 |
347 | synchronize_sched();
348 |
349 | list_for_each_entry(this, &header, list)
350 | {
351 | unsigned char *saddr = (void *)&this->saddr;
352 | unsigned char *daddr = (void *)&this->daddr;
353 |
354 | seq_printf(m,
355 | "protocol:%s, Source IP: %u.%u.%u.%u, Source Port: %d, "
356 | "Dest IP: %u.%u.%u.%u, Dest Port: %d\n",
357 | this->protocol == IPPROTO_UDP ? "UDP" : "TCP",
358 | saddr[0], saddr[1], saddr[2], saddr[3], this->sport,
359 | daddr[0], daddr[1], daddr[2], daddr[3], this->dport);
360 | for (i = 0; i < TRACK_COUNT; i++) {
361 | seq_printf(m,
362 | " %s: %lu\n",
363 | packet_footprint_str[i],
364 | atomic64_read(&this->packages[i]));
365 | }
366 | }
367 |
368 | while (!list_empty(&header))
369 | {
370 | struct conn_desc *this = list_first_entry(&header,
371 | struct conn_desc, list);
372 |
373 | list_del_init(&this->list);
374 | kfree(this);
375 | }
376 |
377 | return 0;
378 | }
379 |
380 | static int drop_packet_open(struct inode *inode, struct file *filp)
381 | {
382 | return single_open(filp, drop_packet_show, NULL);
383 | }
384 |
385 | static ssize_t drop_packet_write(struct file *file,
386 | const char __user *buf, size_t count, loff_t *offs)
387 | {
388 | int ret;
389 | char cmd[255];
390 | char chr[255];
391 |
392 | if (count < 1 || *offs)
393 | return -EINVAL;
394 |
395 | if (copy_from_user(chr, buf, 255))
396 | return -EFAULT;
397 |
398 | ret = sscanf(chr, "%255s", cmd);
399 | if (ret <= 0)
400 | return -EINVAL;
401 |
402 | if (strcmp(cmd, "activate") == 0) {
403 | if (!drop_packet_activated)
404 | drop_packet_activated = activate_drop_packet();
405 | } else if (strcmp(cmd, "deactivate") == 0) {
406 | if (drop_packet_activated)
407 | deactivate_drop_packet();
408 | drop_packet_activated = 0;
409 | } else if (strcmp(cmd, "source-addr") == 0) {
410 | char addr[255];
411 |
412 | ret = sscanf(chr, "%255s %255s", cmd, addr);
413 | if (ret == 2) {
414 | drop_patcket_saddr = ipstr2int(addr);
415 | } else if (ret == 1) {
416 | drop_patcket_saddr = 0;
417 | }
418 | } else if (strcmp(cmd, "source-port") == 0) {
419 | unsigned int port;
420 |
421 | ret = sscanf(chr, "%255s %255d", cmd, &port);
422 | if (ret == 2) {
423 | drop_patcket_sport = port;
424 | } else if (ret == 1) {
425 | drop_patcket_sport = 0;
426 | }
427 | } else if (strcmp(cmd, "dest-addr") == 0) {
428 | char addr[255];
429 |
430 | ret = sscanf(chr, "%255s %255s", cmd, addr);
431 | if (ret == 2) {
432 | drop_patcket_daddr = ipstr2int(addr);
433 | } else if (ret == 1) {
434 | drop_patcket_daddr = 0;
435 | }
436 | } else if (strcmp(cmd, "dest-port") == 0) {
437 | unsigned int port;
438 |
439 | ret = sscanf(chr, "%255s %255d", cmd, &port);
440 | if (ret == 2) {
441 | drop_patcket_dport = port;
442 | } else if (ret == 1) {
443 | drop_patcket_dport = 0;
444 | }
445 | }
446 |
447 | return count;
448 | }
449 |
450 | const struct file_operations drop_packet_fops = {
451 | .open = drop_packet_open,
452 | .read = seq_read,
453 | .llseek = seq_lseek,
454 | .write = drop_packet_write,
455 | .release = single_release,
456 | };
457 |
458 | static int drop_packet_init(void)
459 | {
460 | int ret;
461 | struct proc_dir_entry *pe;
462 |
463 | proc_mkdir("mooc", NULL);
464 | proc_mkdir("mooc/net", NULL);
465 |
466 | ret = -ENOMEM;
467 | pe = proc_create("mooc/net/drop-packet",
468 | S_IFREG | 0644,
469 | NULL,
470 | &drop_packet_fops);
471 | if (!pe)
472 | goto err_proc;
473 |
474 | printk("drop-packet loaded.\n");
475 |
476 | return 0;
477 |
478 | err_proc:
479 | return ret;
480 | }
481 |
482 | static void drop_packet_exit(void)
483 | {
484 | remove_proc_entry("mooc/net/drop-packet", NULL);
485 | remove_proc_entry("mooc/net", NULL);
486 | remove_proc_entry("mooc", NULL);
487 |
488 | if (drop_packet_activated)
489 | deactivate_drop_packet();
490 | drop_packet_activated = 0;
491 |
492 | printk("drop-packet unloaded.\n");
493 | }
494 |
495 | module_init(drop_packet_init)
496 | module_exit(drop_packet_exit)
497 |
498 | MODULE_DESCRIPTION("Baoyou Xie's drop-packet module");
499 | MODULE_AUTHOR("Baoyou Xie ");
500 | MODULE_LICENSE("GPL v2");
501 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step6/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step6/main.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step6/misc.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "drop_packet.h"
6 |
7 | int hook_kprobe(struct kprobe *kp, const char *name,
8 | kprobe_pre_handler_t pre, kprobe_post_handler_t post)
9 | {
10 | kprobe_opcode_t *addr;
11 |
12 | if (!name || strlen(name) >= 255)
13 | return -EINVAL;
14 | addr = (kprobe_opcode_t *)kallsyms_lookup_name(name);
15 | if (!addr)
16 | return -EINVAL;
17 |
18 | memset(kp, 0, sizeof(struct kprobe));
19 | kp->symbol_name = name;
20 | kp->pre_handler = pre;
21 | kp->post_handler = post;
22 |
23 | register_kprobe(kp);
24 |
25 | return 0;
26 | }
27 |
28 | void unhook_kprobe(struct kprobe *kp)
29 | {
30 | unregister_kprobe(kp);
31 | memset(kp, 0, sizeof(struct kprobe));
32 | }
33 |
34 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
35 | int hook_tracepoint(const char *name, void *probe, void *data)
36 | {
37 | return tracepoint_probe_register(name, probe);
38 | }
39 |
40 | int unhook_tracepoint(const char *name, void *probe, void *data)
41 | {
42 | return tracepoint_probe_unregister(name, probe);
43 | }
44 | #elif LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0)
45 | int hook_tracepoint(const char *name, void *probe, void *data)
46 | {
47 | return tracepoint_probe_register(name, probe, data);
48 | }
49 |
50 | int unhook_tracepoint(const char *name, void *probe, void *data)
51 | {
52 | return tracepoint_probe_unregister(name, probe, data);
53 | }
54 | #else
55 | static struct tracepoint *tp_ret;
56 | static void probe_tracepoint(struct tracepoint *tp, void *priv)
57 | {
58 | char *n = priv;
59 |
60 | if (strcmp(tp->name, n) == 0)
61 | tp_ret = tp;
62 | }
63 |
64 | static struct tracepoint *find_tracepoint(const char *name)
65 | {
66 | tp_ret = NULL;
67 | for_each_kernel_tracepoint(probe_tracepoint, (void *)name);
68 |
69 | return tp_ret;
70 | }
71 |
72 | int hook_tracepoint(const char *name, void *probe, void *data)
73 | {
74 | struct tracepoint *tp;
75 |
76 | tp = find_tracepoint(name);
77 | if (!tp)
78 | return 0;
79 |
80 | return tracepoint_probe_register(tp, probe, data);
81 | }
82 |
83 | int unhook_tracepoint(const char *name, void *probe, void *data)
84 | {
85 | struct tracepoint *tp;
86 |
87 | tp = find_tracepoint(name);
88 | if (!tp)
89 | return 0;
90 |
91 | return tracepoint_probe_unregister(tp, probe, data);
92 | }
93 | #endif
94 |
95 | #define IP_STR_LEN 18
96 | #define MAC_STR_LEN 18
97 | #define MAC_BIT_LEN 6
98 | #define LITTLE_ENDIAN 0
99 | #define BIG_ENDIAN 1
100 |
101 | int big_little_endian(void)
102 | {
103 | int data = 0x1;
104 |
105 | if (*((char *)&data) == 0x1)
106 | return LITTLE_ENDIAN;
107 |
108 | return BIG_ENDIAN;
109 | }
110 |
111 | unsigned int ipstr2int(const char *ipstr)
112 | {
113 | unsigned int a, b, c, d;
114 | unsigned int ip = 0;
115 | int count;
116 |
117 | count = sscanf(ipstr, "%u.%u.%u.%u", &a, &b, &c, &d);
118 | if (count == 4) {
119 | a = (a << 24);
120 | b = (b << 16);
121 | c = (c << 8);
122 | d = (d << 0);
123 | ip = a | b | c | d;
124 |
125 | return ip;
126 | } else {
127 | return 0;
128 | }
129 | }
130 |
131 | char *int2ipstr(const unsigned int ip, char *ipstr, const unsigned int ip_str_len)
132 | {
133 | int len;
134 |
135 | if (big_little_endian() == LITTLE_ENDIAN)
136 | len = snprintf(ipstr, ip_str_len, "%u.%u.%u.%u",
137 | (unsigned char) * ((char *)(&ip) + 3),
138 | (unsigned char) * ((char *)(&ip) + 2),
139 | (unsigned char) * ((char *)(&ip) + 1),
140 | (unsigned char) * ((char *)(&ip) + 0));
141 | else
142 | len = snprintf(ipstr, ip_str_len, "%u.%u.%u.%u",
143 | (unsigned char) * ((char *)(&ip) + 0),
144 | (unsigned char) * ((char *)(&ip) + 1),
145 | (unsigned char) * ((char *)(&ip) + 2),
146 | (unsigned char) * ((char *)(&ip) + 3));
147 |
148 | if (len < ip_str_len)
149 | return ipstr;
150 | else
151 | return NULL;
152 | }
153 |
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step6/misc.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex14-drop-packet/drop-packet/src/step6/misc.o
--------------------------------------------------------------------------------
/ex14-drop-packet/drop-packet/src/step6/modules.order:
--------------------------------------------------------------------------------
1 | kernel//home/xiebaoyou/study/陈老师/drop-packet/src/step6/drop-packet.ko
2 |
--------------------------------------------------------------------------------
/ex2-exnum/Makefile:
--------------------------------------------------------------------------------
1 | #产生目标文件
2 | obj-m:=exnum.o
3 | #定义当前路径
4 | CURRENT_PATH:=$(shell pwd)
5 | #定义内核版本号
6 | LINUX_KERNEL:=$(shell uname -r)
7 | #定义内核源码绝对路径
8 | LINUX_KERNEL_PATH:=/usr/src/linux-headers-$(LINUX_KERNEL)
9 | #编译模块
10 | all:
11 | make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
12 | #清理模块
13 | clean:
14 | make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean
15 |
16 |
17 |
--------------------------------------------------------------------------------
/ex2-exnum/exnum.c:
--------------------------------------------------------------------------------
1 | /**********************************************************
2 | * Author : 梁金荣
3 | * Email : Liangjinrong111@163.com
4 | * Last modified : 2019-09-14 13:00
5 | * Filename : exnum.c
6 | * Description : 模块初始化函数中求最大数(使用内核中的代码)
7 | * *******************************************************/
8 |
9 | //必要的头文件
10 | #include
11 | #include
12 | #include
13 | //模块的初始化函数,模块的入口函数,加载模块,需超级用户权限
14 | static int __init lk_exnum(void)
15 | {
16 | int x = 1, y = 2;
17 |
18 | printk("The module is starting here!\n");
19 | printk("x = %d, y = %d\n", x, y);
20 | printk("max=%d\n", max(x++, y++));
21 | printk("x = %d, y = %d\n", x, y);
22 | printk("min=%d\n", min(x++, y++));
23 |
24 | return 0;
25 | }
26 | //出口函数,卸载模块,需超级用户权限
27 | static void __exit lk_exit(void)
28 | {
29 | printk("The maxnum moudle has exited!\n");
30 | }
31 |
32 | module_init(lk_exnum); //内核入口点,调用初始化函数,包含在module.h中
33 | module_exit(lk_exit); //出口点
34 | MODULE_LICENSE("GPL"); //许可证
35 | MODULE_AUTHOR("ljr"); //作者(非必须)
36 | MODULE_DESCRIPTION("max and min number"); //模块描述(非必须)
37 |
38 |
--------------------------------------------------------------------------------
/ex2-exnum/maxnum.c:
--------------------------------------------------------------------------------
1 | /**********************************************************
2 | * Author : 梁金荣
3 | * Email : Liangjinrong111@163.com
4 | * Last modified : 2019-09-14 13:00
5 | * Filename : exnum.c
6 | * Description : 模块初始化函数中求最大数(使用内核中的代码)
7 | * *******************************************************/
8 |
9 | //必要的头文件
10 | #include
11 | #include
12 | #include
13 | //模块的初始化函数,模块的入口函数,加载模块,需超级用户权限
14 | static int __init lk_exnum(void)
15 | {
16 | int x = 5, y = 8;
17 | printk("The module is starting here!\n");
18 | printk("x = %d, y = %d\n", x, y);
19 | printk("max=%d\n", max(x++, y++));
20 | printk("x = %d, y = %d\n", x, y);
21 | printk("min=%d\n", min(x++, y++));
22 | return 0;
23 | }
24 | //出口函数,卸载模块,需超级用户权限
25 | static void __exit lk_exit(void)
26 | {
27 | printk("The maxnum moudle has exited!\n");
28 | }
29 |
30 | module_init(lk_exnum); //内核入口点,调用初始化函数,包含在module.h中
31 | module_exit(lk_exit); //出口点
32 | MODULE_LICENSE("GPL"); //许可证
33 | MODULE_AUTHOR("ljr"); //作者(非必须)
34 | MODULE_DESCRIPTION("max and min number"); //模块描述(非必须)
35 |
36 |
--------------------------------------------------------------------------------
/ex2-exnum/test/diff.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex2-exnum/test/diff.out
--------------------------------------------------------------------------------
/ex2-exnum/test/same.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex2-exnum/test/same.out
--------------------------------------------------------------------------------
/ex2-exnum/test/testmax.c:
--------------------------------------------------------------------------------
1 | #include
2 | #define max(a,b) ((a)>(b)?(a):(b))
3 | int main()
4 | {
5 |
6 | int x = 1, y = 2;
7 | printf("max=%d\n", max(x++, y++));
8 | printf("x = %d, y = %d\n", x, y);
9 | }
10 |
--------------------------------------------------------------------------------
/ex2-exnum/test/testmax.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex2-exnum/test/testmax.out
--------------------------------------------------------------------------------
/ex2-exnum/test/text_diff.c:
--------------------------------------------------------------------------------
1 | #include
2 | int main()
3 | {
4 | int x=1;
5 | double y=1;
6 |
7 | if((!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))==1)
8 | printf("表达式结果是1\n");
9 | else
10 | printf("表达式结果不是1\n");
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/ex2-exnum/test/text_same.c:
--------------------------------------------------------------------------------
1 | #include
2 | int main()
3 | {
4 | int x=1;
5 | int y=1;
6 |
7 | if((!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))==1)
8 | printf("表达式结果是1\n");
9 | else
10 | printf("表达式结果不是1\n");
11 | }
12 |
--------------------------------------------------------------------------------
/ex2-exnum/test/type.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex2-exnum/test/type.out
--------------------------------------------------------------------------------
/ex2-exnum/test/type2.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex2-exnum/test/type2.out
--------------------------------------------------------------------------------
/ex2-exnum/运行结果.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex2-exnum/运行结果.png
--------------------------------------------------------------------------------
/ex3-lklist/.Makefile.swo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex3-lklist/.Makefile.swo
--------------------------------------------------------------------------------
/ex3-lklist/.Makefile.swp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex3-lklist/.Makefile.swp
--------------------------------------------------------------------------------
/ex3-lklist/Makefile:
--------------------------------------------------------------------------------
1 | #产生目标文件
2 | obj-m:=lklist.o
3 | #定义当前路径
4 | CURRENT_PATH:=$(shell pwd)
5 | #定义内核版本号
6 | LINUX_KERNEL:=$(shell uname -r)
7 | #定义内核源码绝对路径
8 | LINUX_KERNEL_PATH:=/usr/src/linux-headers-$(LINUX_KERNEL)
9 | #编译模块
10 | all:
11 | make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
12 | #清理模块
13 | clean:
14 | make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean
15 |
16 |
--------------------------------------------------------------------------------
/ex3-lklist/lklist.c:
--------------------------------------------------------------------------------
1 | /**********************************************************
2 | * Author : ljr
3 | * Email : Liangjinrong111@163.com
4 | * Last modified : 2019-09-15 12:41
5 | * Filename : lk_list
6 | * Description : The operation of Linux Kernel List
7 | * *******************************************************/
8 |
9 | #include //包含了常用的内核函数
10 | #include //模块必备
11 | #include //包含了宏__init和__exit,它们允许释放内核占用的内存
12 | #include //包含双链表操作函数
13 | #include //包含了kmalloc等内存分配函数
14 |
15 | #define N 100 //链表节点数
16 | struct lklist{
17 | int data; //数据
18 | struct list_head list; //指向双链表前后节点的指针
19 | };
20 | struct lklist lk; //头节点
21 |
22 | /**
23 | *创建内核链表
24 | *指针和变量
25 | */
26 | void creat_lklist(void)
27 | {
28 | struct lklist *node; //定义每次申请链表节点时所用的指针
29 | int i;
30 |
31 | INIT_LIST_HEAD(&lk.list); //初始化头节点
32 | printk("\nCreating linux kernel list!\n");
33 | //建立N个节点,依次加到链表中
34 | for(i = 0; i < N; i++)
35 | {
36 | //GFP_KERNEL是linux内存分配器的标志,标识着内存分配器将要采取的行为
37 | node = (struct lklist *)kmalloc(sizeof(struct lklist), GFP_KERNEL);
38 | node -> data = i+1;
39 | list_add_tail(&node -> list, &lk.list);
40 | printk("Node %d has added to the lklist...\n ",i+1);
41 | }
42 | }
43 |
44 | /**
45 | * 遍历内核链表
46 | *
47 | */
48 | void traversal_lklist(void)
49 | {
50 | struct lklist *p;
51 | struct list_head *pos;
52 | int i = 1;
53 | printk("\nTraveral linux kernel list!\n");
54 | list_for_each(pos, &lk.list)
55 | {
56 | //通过结构体成员的指针来返回结构体的指针
57 | p = list_entry(pos, struct lklist, list);
58 | printk("Node %d's data: %d\n", i, p -> data);
59 | i++;
60 | }
61 | printk("\n\n");
62 | }
63 |
64 | /**
65 | * 删除内核链表
66 | * 删除10个节点
67 | */
68 | void del_lklist(void)
69 | {
70 | struct list_head *n, *pos;
71 | struct lklist *p;
72 | int i=10;
73 | printk("\nDelete linux kernel list!\n");
74 |
75 | /*
76 | * 提供一个与pos同类型的指针n
77 | * 在for循环中暂存pos下一个节点的地址
78 | * 避免因pos节点被释放而造成的断链
79 | */
80 | list_for_each_safe(pos, n, &lk.list)
81 | {
82 | p = list_entry(pos, struct lklist, list);
83 | list_del(pos);
84 | kfree(p);
85 | printk("\nThe node has removed from the lklist...\n");
86 | i--;
87 | if(i==0) break;
88 | }
89 | }
90 |
91 | /**
92 | * 内核入口函数
93 | *
94 | */
95 | static int __init lklist(void)
96 | {
97 | printk("\nLinux kernel list is starting...\n\n");
98 | creat_lklist(); //调用创建内核链表函数
99 | traversal_lklist(); //调用遍历内核链表函数
100 | del_lklist(); //调用删除内核链表函数
101 | traversal_lklist(); //调用遍历内核链表函数
102 | return 0;
103 | }
104 |
105 | /**
106 | * 内核出口函数
107 | *
108 | */
109 | static void __exit lklist_exit(void)
110 | {
111 | printk("\nlklist is exiting...\n");
112 | }
113 |
114 | module_init(lklist); //入口点
115 | module_exit(lklist_exit); //出口点
116 | MODULE_LICENSE("GPL"); //许可证
117 | MODULE_AUTHOR("梁金荣"); //作者信息(非必要项)
118 | MODULE_DESCRIPTION("The operation of Linux Kernel List"); //模块描述(非必要项)
119 |
--------------------------------------------------------------------------------
/ex3-lklist/删除10个节点.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex3-lklist/删除10个节点.png
--------------------------------------------------------------------------------
/ex3-lklist/插入100个节点.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex3-lklist/插入100个节点.png
--------------------------------------------------------------------------------
/ex3-lklist/还有90个.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex3-lklist/还有90个.png
--------------------------------------------------------------------------------
/ex4-kernel_param/Makefile:
--------------------------------------------------------------------------------
1 | obj-m:=kernel_param.o
2 | CU_PATH:=$(shell pwd)
3 | LK:=$(shell uname -r)
4 | LK_PATH:=/usr/src/linux-headers-$(LK)
5 | all:
6 | make -C $(LK_PATH) M=$(CU_PATH) modules
7 | clean:
8 | make -C $(LK_PATH) M=$(CU_PATH) clean
9 |
--------------------------------------------------------------------------------
/ex4-kernel_param/kernel_param.c:
--------------------------------------------------------------------------------
1 | /**********************************************************
2 | * Author : 梁金荣
3 | * Email : Liangjinrong111@163.com
4 | * Last modified : 2019-09-14 13:00
5 | * Filename : exnum.c
6 | * Description : 模块初始化函数中求最大数(使用内核中的代码)
7 | * *******************************************************/
8 |
9 | /**
10 | *必要的头文件
11 | */
12 | #include
13 | #include
14 | #include
15 |
16 | static int a,b ;
17 | module_param(a, int, 0644);
18 | MODULE_PARM_DESC(a, "data of a");
19 | module_param(b, int, 0644);
20 | MODULE_PARM_DESC(b, "data of b");
21 | /**
22 | *模块的初始化函数,模块的入口函数,加载模块,需超级用户权限
23 | */
24 | static int __init lk_exnum(void)
25 | {
26 | printk("Linux kernel param max number module is starting here!\n");
27 | printk("a = %d, b = %d\n", a, b);
28 | printk("max=%d\n", max(a,b));
29 | return 0;
30 | }
31 |
32 | /**
33 | *出口函数,卸载模块,需超级用户权限
34 | */
35 | static void __exit lk_exit(void)
36 | {
37 | printk("Linux kernel param max number moudle has exited!\n");
38 | }
39 |
40 | module_init(lk_exnum); //内核入口点,调用初始化函数,包含在module.h中
41 | module_exit(lk_exit); //出口点
42 | MODULE_LICENSE("GPL"); //许可证
43 | MODULE_AUTHOR("ljr"); //作者(非必须)
44 | MODULE_DESCRIPTION("Linux kernel param max number"); //模块描述(非必须)
45 |
46 |
--------------------------------------------------------------------------------
/ex4-kernel_param/查看结果.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex4-kernel_param/查看结果.png
--------------------------------------------------------------------------------
/ex4-kernel_param/输入参数.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex4-kernel_param/输入参数.png
--------------------------------------------------------------------------------
/ex5-Makefile2file/Makefile:
--------------------------------------------------------------------------------
1 |
2 | hello-objs+=hello1.o hello2.o
3 |
4 | obj-m:=hello.o
5 | CU_PATH:=$(shell pwd)
6 | LK:=$(shell uname -r)
7 | LK_PATH:=/usr/src/linux-headers-$(LK)
8 | all:
9 | make -C $(LK_PATH) M=$(CU_PATH) modules
10 | clean:
11 | make -C $(LK_PATH) M=$(CU_PATH) clean
12 |
--------------------------------------------------------------------------------
/ex5-Makefile2file/hello1.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | int __init lk_hello1(void)
6 | {
7 | printk("hello,i am the first module!\n");
8 | return 0;
9 | }
10 | void __exit lk_exit1(void)
11 | {
12 | printk("good bye,the first module !\n");
13 |
14 | }
15 | //module_init(lk_hello1);
16 | //module_exit(lk_exit1);
17 | MODULE_LICENSE("GPL");
18 |
19 |
--------------------------------------------------------------------------------
/ex5-Makefile2file/hello2.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | extern int lk_hello1(void);
5 | extern void lk_exit1(void);
6 | static int __init lk_hello2(void)
7 | {
8 | lk_hello1();
9 | printk("hello,i an the second module!\n");
10 | return 0;
11 | }
12 | static void __exit lk_exit2(void)
13 | {
14 | lk_exit1();
15 | printk("good bye,the second module!\n");
16 |
17 | }
18 | module_init(lk_hello2);
19 | module_exit(lk_exit2);
20 | MODULE_LICENSE("GPL");
21 |
22 |
--------------------------------------------------------------------------------
/ex5-Makefile2file/运行结果.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex5-Makefile2file/运行结果.png
--------------------------------------------------------------------------------
/ex6-rbtree/Makefile:
--------------------------------------------------------------------------------
1 | obj-m:=rbtree.o
2 | CU_PATH:=$(shell pwd)
3 | LK:=$(shell uname -r)
4 | LK_PATH:=/usr/src/linux-headers-$(LK)
5 | all:
6 | make -C $(LK_PATH) M=$(CU_PATH) modules
7 | clean:
8 | make -C $(LK_PATH) M=$(CU_PATH) clean
9 |
--------------------------------------------------------------------------------
/ex6-rbtree/rbtree.c:
--------------------------------------------------------------------------------
1 | /**********************************************************
2 | * Author : 梁金荣
3 | * Email : Liangjinrong111@163.com
4 | * Last modified : 2019-09-21 23:21
5 | * Filename : rbtree.c
6 | * Description : Using rbtree
7 | * *******************************************************/
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | MODULE_AUTHOR("ljr");
18 | MODULE_DESCRIPTION("Using rbtree");
19 | MODULE_LICENSE("GPL");
20 |
21 | struct mytype {
22 | struct rb_node node;
23 | int key;
24 | };
25 |
26 | struct rb_root mytree = RB_ROOT;
27 |
28 | struct mytype *my_search(struct rb_root *root, int new)
29 | {
30 | struct rb_node *node = root->rb_node;
31 |
32 | while (node) {
33 | struct mytype *data = container_of(node, struct mytype, node);
34 |
35 | if (data->key > new)
36 | node = node->rb_left;
37 | else if (data->key < new)
38 | node = node->rb_right;
39 | else
40 | return data;
41 | }
42 | return NULL;
43 | }
44 |
45 | int my_insert(struct rb_root *root, struct mytype *data)
46 | {
47 | struct rb_node **new = &(root->rb_node), *parent=NULL;
48 |
49 | /* Figure out where to put new node */
50 | while (*new) {
51 | struct mytype *this = container_of(*new, struct mytype, node);
52 |
53 | parent = *new;
54 | if (this->key > data->key)
55 | new = &((*new)->rb_left);
56 | else if (this->key < data->key) {
57 | new = &((*new)->rb_right);
58 | } else
59 | return -1;
60 | }
61 |
62 | /* Add new node and rebalance tree. */
63 | rb_link_node(&data->node, parent, new);
64 | rb_insert_color(&data->node, root);
65 |
66 | return 0;
67 | }
68 |
69 |
70 | static int __init my_init(void)
71 | {
72 | int i;
73 | struct mytype *data;
74 | struct rb_node *node;
75 | printk("The rbtree kernel is starting!\n");
76 | for (i =0; i < 10; i++) {
77 | data = kmalloc(sizeof(struct mytype), GFP_KERNEL);
78 | data->key = i+1;
79 | my_insert(&mytree, data);
80 | }
81 |
82 | /*list all tree*/
83 | for (node = rb_first(&mytree); node; node = rb_next(node))
84 | printk("data=%d\n", rb_entry(node, struct mytype, node)->key);
85 |
86 | return 0;
87 | }
88 |
89 | static void __exit my_exit(void)
90 | {
91 | struct mytype *data;
92 | struct rb_node *node;
93 | printk("The rbtree kernel is exiting!\n");
94 | for (node = rb_first(&mytree); node; node = rb_next(node)) {
95 | data = rb_entry(node, struct mytype, node);
96 | if (data) {
97 | rb_erase(&data->node, &mytree);
98 | kfree(data);
99 | }
100 | }
101 | }
102 | module_init(my_init);
103 | module_exit(my_exit);
104 |
105 |
--------------------------------------------------------------------------------
/ex6-rbtree/运行结果.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex6-rbtree/运行结果.png
--------------------------------------------------------------------------------
/ex7-ForkAndClone/fork_test:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ljrcore/LearningLinuxKernel/0bb373f091335d7669fc30e96cd3f5712556bb77/ex7-ForkAndClone/fork_test
--------------------------------------------------------------------------------
/ex7-ForkAndClone/fork_test.c:
--------------------------------------------------------------------------------
1 | #define _GNU_SOURCE
2 | #include //clone()相关
3 | #include
4 | #include
5 | #include
6 | #include //fork()相关
7 | #include
8 | #include
9 | #include
10 |
11 | int param = 0;
12 |
13 | int thread_fn(void *data)
14 | {
15 | int j;
16 | printf("starting child thread_fn, pid=%d\n", getpid());
17 | for (j = 0; j < 10; j++) {
18 | param = j + 1000;
19 | sleep(1);
20 | printf("child thread running: j=%d, param=%d secs\n", j,param);
21 | }
22 | printf("child thread_fn exit\n");
23 | return 0;
24 | }
25 |
26 | int main(int argc, char **argv)
27 | {
28 | int j, tid, pagesize, stacksize;
29 | void *stack;
30 |
31 | printf("starting parent process, pid=%d\n", getpid());
32 |
33 | pagesize = getpagesize();
34 | stacksize = 4 * pagesize;
35 |
36 | posix_memalign(&stack, pagesize, stacksize);
37 |
38 | printf("Setting a clone child thread with stacksize = %d....", stacksize);
39 | tid = clone(thread_fn, (char *)stack + stacksize, CLONE_VM | SIGCHLD, 0);
40 | printf(" with tid=%d\n", tid);
41 | if (tid < 0)
42 | exit(EXIT_FAILURE);
43 |
44 | for (j = 0; j < 6; j++) {
45 | param = j;
46 | sleep(1);
47 | printf("parent running: j=%d, param=%d secs\n", j,param);
48 | }
49 | printf("parent killitself\n");
50 | exit(EXIT_SUCCESS);
51 | }
52 |
53 |
54 |
--------------------------------------------------------------------------------
/ex8-KernelThread/.kthread.o.d:
--------------------------------------------------------------------------------
1 | kthread.o: \
2 | /home/ljr/GitHub/LearningLinuxKernel/ex8_KernelThread/kthread.c \
3 | include/linux/kconfig.h include/generated/autoconf.h \
4 | include/linux/compiler_types.h include/linux/compiler-gcc.h \
5 | include/linux/module.h include/linux/list.h include/linux/types.h \
6 | include/uapi/linux/types.h arch/x86/include/uapi/asm/types.h \
7 | include/uapi/asm-generic/types.h include/asm-generic/int-ll64.h \
8 | include/uapi/asm-generic/int-ll64.h \
9 | arch/x86/include/uapi/asm/bitsperlong.h \
10 | include/asm-generic/bitsperlong.h include/uapi/asm-generic/bitsperlong.h \
11 | include/uapi/linux/posix_types.h include/linux/stddef.h \
12 | include/uapi/linux/stddef.h include/linux/compiler_types.h \
13 | arch/x86/include/asm/posix_types.h \
14 | arch/x86/include/uapi/asm/posix_types_64.h \
15 | include/uapi/asm-generic/posix_types.h include/linux/poison.h \
16 | include/linux/const.h include/uapi/linux/const.h include/linux/kernel.h \
17 | /usr/lib/gcc/x86_64-linux-gnu/7/include/stdarg.h include/linux/linkage.h \
18 | include/linux/stringify.h include/linux/export.h \
19 | arch/x86/include/asm/linkage.h include/linux/compiler.h \
20 | arch/x86/include/asm/barrier.h arch/x86/include/asm/alternative.h \
21 | arch/x86/include/asm/asm.h arch/x86/include/asm/nops.h \
22 | include/asm-generic/barrier.h include/linux/kasan-checks.h \
23 | include/linux/bitops.h arch/x86/include/asm/bitops.h \
24 | arch/x86/include/asm/rmwcc.h include/asm-generic/bitops/find.h \
25 | include/asm-generic/bitops/sched.h arch/x86/include/asm/arch_hweight.h \
26 | arch/x86/include/asm/cpufeatures.h \
27 | arch/x86/include/asm/required-features.h \
28 | arch/x86/include/asm/disabled-features.h \
29 | include/asm-generic/bitops/const_hweight.h \
30 | include/asm-generic/bitops/le.h arch/x86/include/uapi/asm/byteorder.h \
31 | include/linux/byteorder/little_endian.h \
32 | include/uapi/linux/byteorder/little_endian.h include/linux/swab.h \
33 | include/uapi/linux/swab.h arch/x86/include/uapi/asm/swab.h \
34 | include/linux/byteorder/generic.h \
35 | include/asm-generic/bitops/ext2-atomic-setbit.h include/linux/log2.h \
36 | include/linux/typecheck.h include/linux/printk.h include/linux/init.h \
37 | include/linux/kern_levels.h include/linux/cache.h \
38 | include/uapi/linux/kernel.h include/uapi/linux/sysinfo.h \
39 | arch/x86/include/asm/cache.h include/linux/dynamic_debug.h \
40 | include/linux/jump_label.h arch/x86/include/asm/jump_label.h \
41 | include/linux/build_bug.h include/linux/stat.h \
42 | arch/x86/include/uapi/asm/stat.h include/uapi/linux/stat.h \
43 | include/linux/time.h include/linux/seqlock.h include/linux/spinlock.h \
44 | include/linux/preempt.h arch/x86/include/asm/preempt.h \
45 | arch/x86/include/asm/percpu.h include/asm-generic/percpu.h \
46 | include/linux/threads.h include/linux/percpu-defs.h \
47 | include/linux/thread_info.h include/linux/bug.h \
48 | arch/x86/include/asm/bug.h include/asm-generic/bug.h \
49 | include/linux/restart_block.h include/linux/time64.h \
50 | include/linux/math64.h arch/x86/include/asm/div64.h \
51 | include/asm-generic/div64.h include/uapi/linux/time.h \
52 | arch/x86/include/asm/current.h arch/x86/include/asm/thread_info.h \
53 | arch/x86/include/asm/page.h arch/x86/include/asm/page_types.h \
54 | include/linux/mem_encrypt.h arch/x86/include/asm/mem_encrypt.h \
55 | arch/x86/include/uapi/asm/bootparam.h include/linux/screen_info.h \
56 | include/uapi/linux/screen_info.h include/linux/apm_bios.h \
57 | include/uapi/linux/apm_bios.h include/uapi/linux/ioctl.h \
58 | arch/x86/include/uapi/asm/ioctl.h include/asm-generic/ioctl.h \
59 | include/uapi/asm-generic/ioctl.h include/linux/edd.h \
60 | include/uapi/linux/edd.h arch/x86/include/asm/ist.h \
61 | arch/x86/include/uapi/asm/ist.h include/video/edid.h \
62 | include/uapi/video/edid.h arch/x86/include/asm/page_64_types.h \
63 | arch/x86/include/asm/kaslr.h arch/x86/include/asm/page_64.h \
64 | include/linux/range.h include/asm-generic/memory_model.h \
65 | include/linux/pfn.h include/asm-generic/getorder.h \
66 | arch/x86/include/asm/cpufeature.h arch/x86/include/asm/processor.h \
67 | arch/x86/include/asm/processor-flags.h \
68 | arch/x86/include/uapi/asm/processor-flags.h \
69 | arch/x86/include/asm/math_emu.h arch/x86/include/asm/ptrace.h \
70 | arch/x86/include/asm/segment.h arch/x86/include/uapi/asm/ptrace.h \
71 | arch/x86/include/uapi/asm/ptrace-abi.h \
72 | arch/x86/include/asm/paravirt_types.h arch/x86/include/asm/desc_defs.h \
73 | arch/x86/include/asm/kmap_types.h include/asm-generic/kmap_types.h \
74 | arch/x86/include/asm/pgtable_types.h \
75 | arch/x86/include/asm/pgtable_64_types.h arch/x86/include/asm/sparsemem.h \
76 | include/asm-generic/pgtable-nop4d.h arch/x86/include/asm/nospec-branch.h \
77 | arch/x86/include/asm/alternative-asm.h arch/x86/include/asm/msr-index.h \
78 | arch/x86/include/asm/spinlock_types.h \
79 | include/asm-generic/qspinlock_types.h \
80 | include/asm-generic/qrwlock_types.h include/asm-generic/ptrace.h \
81 | arch/x86/include/uapi/asm/sigcontext.h arch/x86/include/asm/msr.h \
82 | arch/x86/include/asm/msr-index.h arch/x86/include/uapi/asm/errno.h \
83 | include/uapi/asm-generic/errno.h include/uapi/asm-generic/errno-base.h \
84 | arch/x86/include/asm/cpumask.h include/linux/cpumask.h \
85 | include/linux/bitmap.h include/linux/string.h \
86 | include/uapi/linux/string.h arch/x86/include/asm/string.h \
87 | arch/x86/include/asm/string_64.h arch/x86/include/uapi/asm/msr.h \
88 | arch/x86/include/asm/atomic.h arch/x86/include/asm/cmpxchg.h \
89 | arch/x86/include/asm/cmpxchg_64.h arch/x86/include/asm/atomic64_64.h \
90 | include/asm-generic/atomic-instrumented.h \
91 | include/linux/tracepoint-defs.h include/linux/atomic.h \
92 | include/asm-generic/atomic-long.h include/linux/static_key.h \
93 | arch/x86/include/asm/paravirt.h arch/x86/include/asm/frame.h \
94 | arch/x86/include/asm/special_insns.h arch/x86/include/asm/fpu/types.h \
95 | arch/x86/include/asm/unwind_hints.h arch/x86/include/asm/orc_types.h \
96 | include/linux/personality.h include/uapi/linux/personality.h \
97 | include/linux/err.h include/linux/irqflags.h \
98 | arch/x86/include/asm/irqflags.h include/linux/bottom_half.h \
99 | include/linux/spinlock_types.h include/linux/lockdep.h \
100 | include/linux/rwlock_types.h arch/x86/include/asm/spinlock.h \
101 | arch/x86/include/asm/qspinlock.h include/asm-generic/qspinlock.h \
102 | arch/x86/include/asm/qrwlock.h include/asm-generic/qrwlock.h \
103 | include/linux/rwlock.h include/linux/spinlock_api_smp.h \
104 | include/linux/rwlock_api_smp.h include/linux/time32.h \
105 | include/linux/uidgid.h include/linux/highuid.h include/linux/kmod.h \
106 | include/linux/umh.h include/linux/gfp.h include/linux/mmdebug.h \
107 | include/linux/mmzone.h include/linux/wait.h include/uapi/linux/wait.h \
108 | include/linux/numa.h include/linux/nodemask.h \
109 | include/linux/pageblock-flags.h include/linux/page-flags-layout.h \
110 | include/generated/bounds.h include/linux/memory_hotplug.h \
111 | include/linux/notifier.h include/linux/errno.h \
112 | include/uapi/linux/errno.h include/linux/mutex.h \
113 | include/linux/osq_lock.h include/linux/debug_locks.h \
114 | include/linux/rwsem.h arch/x86/include/asm/rwsem.h include/linux/srcu.h \
115 | include/linux/rcupdate.h include/linux/rcutree.h \
116 | include/linux/workqueue.h include/linux/timer.h include/linux/ktime.h \
117 | include/linux/jiffies.h include/linux/timex.h include/uapi/linux/timex.h \
118 | include/uapi/linux/param.h arch/x86/include/uapi/asm/param.h \
119 | include/asm-generic/param.h include/uapi/asm-generic/param.h \
120 | arch/x86/include/asm/timex.h arch/x86/include/asm/tsc.h \
121 | include/generated/timeconst.h include/linux/timekeeping.h \
122 | include/linux/timekeeping32.h include/linux/debugobjects.h \
123 | include/linux/rcu_segcblist.h include/linux/srcutree.h \
124 | include/linux/rcu_node_tree.h include/linux/completion.h \
125 | arch/x86/include/asm/mmzone.h arch/x86/include/asm/mmzone_64.h \
126 | arch/x86/include/asm/smp.h arch/x86/include/asm/mpspec.h \
127 | arch/x86/include/asm/mpspec_def.h arch/x86/include/asm/x86_init.h \
128 | arch/x86/include/asm/apicdef.h arch/x86/include/asm/apic.h \
129 | arch/x86/include/asm/fixmap.h arch/x86/include/asm/acpi.h \
130 | include/acpi/pdc_intel.h arch/x86/include/asm/numa.h \
131 | arch/x86/include/asm/topology.h include/asm-generic/topology.h \
132 | arch/x86/include/asm/mmu.h arch/x86/include/asm/realmode.h \
133 | arch/x86/include/asm/io.h arch/x86/include/generated/asm/early_ioremap.h \
134 | include/asm-generic/early_ioremap.h include/asm-generic/iomap.h \
135 | include/asm-generic/pci_iomap.h include/xen/xen.h \
136 | include/xen/interface/xen.h arch/x86/include/asm/xen/interface.h \
137 | arch/x86/include/asm/xen/interface_64.h \
138 | arch/x86/include/asm/pvclock-abi.h arch/x86/include/asm/xen/hypervisor.h \
139 | include/asm-generic/io.h include/linux/logic_pio.h \
140 | include/linux/fwnode.h include/linux/vmalloc.h include/linux/llist.h \
141 | include/linux/rbtree.h include/linux/overflow.h \
142 | arch/x86/include/uapi/asm/vsyscall.h include/asm-generic/fixmap.h \
143 | arch/x86/include/asm/hardirq.h arch/x86/include/asm/io_apic.h \
144 | arch/x86/include/asm/irq_vectors.h include/linux/topology.h \
145 | include/linux/smp.h include/linux/percpu.h include/linux/sysctl.h \
146 | include/uapi/linux/sysctl.h include/linux/elf.h \
147 | arch/x86/include/asm/elf.h arch/x86/include/asm/user.h \
148 | arch/x86/include/asm/user_64.h arch/x86/include/uapi/asm/auxvec.h \
149 | arch/x86/include/asm/vdso.h include/linux/mm_types.h \
150 | include/linux/mm_types_task.h arch/x86/include/asm/tlbbatch.h \
151 | include/linux/auxvec.h include/uapi/linux/auxvec.h \
152 | include/linux/uprobes.h arch/x86/include/asm/uprobes.h \
153 | include/uapi/linux/elf.h include/uapi/linux/elf-em.h \
154 | include/linux/kobject.h include/linux/sysfs.h include/linux/kernfs.h \
155 | include/linux/idr.h include/linux/radix-tree.h \
156 | include/linux/kobject_ns.h include/linux/kref.h include/linux/refcount.h \
157 | arch/x86/include/asm/refcount.h include/linux/moduleparam.h \
158 | include/linux/rbtree_latch.h include/linux/error-injection.h \
159 | arch/x86/include/asm/error-injection.h \
160 | include/asm-generic/error-injection.h arch/x86/include/asm/module.h \
161 | include/asm-generic/module.h arch/x86/include/asm/orc_types.h \
162 | include/linux/kthread.h include/linux/sched.h include/uapi/linux/sched.h \
163 | include/linux/pid.h include/linux/rculist.h include/linux/sem.h \
164 | include/uapi/linux/sem.h include/linux/ipc.h include/linux/rhashtable.h \
165 | include/linux/jhash.h include/linux/unaligned/packed_struct.h \
166 | include/linux/list_nulls.h include/uapi/linux/ipc.h \
167 | arch/x86/include/uapi/asm/ipcbuf.h include/uapi/asm-generic/ipcbuf.h \
168 | arch/x86/include/uapi/asm/sembuf.h include/linux/shm.h \
169 | include/uapi/linux/shm.h include/uapi/asm-generic/hugetlb_encode.h \
170 | arch/x86/include/uapi/asm/shmbuf.h include/uapi/asm-generic/shmbuf.h \
171 | arch/x86/include/asm/shmparam.h include/linux/kcov.h \
172 | include/uapi/linux/kcov.h include/linux/plist.h include/linux/hrtimer.h \
173 | include/linux/timerqueue.h include/linux/seccomp.h \
174 | include/uapi/linux/seccomp.h arch/x86/include/asm/seccomp.h \
175 | arch/x86/include/asm/unistd.h arch/x86/include/uapi/asm/unistd.h \
176 | arch/x86/include/generated/uapi/asm/unistd_64.h \
177 | arch/x86/include/generated/asm/unistd_64_x32.h \
178 | arch/x86/include/asm/ia32_unistd.h \
179 | arch/x86/include/generated/asm/unistd_32_ia32.h \
180 | include/asm-generic/seccomp.h include/uapi/linux/unistd.h \
181 | include/linux/resource.h include/uapi/linux/resource.h \
182 | arch/x86/include/uapi/asm/resource.h include/asm-generic/resource.h \
183 | include/uapi/asm-generic/resource.h include/linux/latencytop.h \
184 | include/linux/sched/prio.h include/linux/signal_types.h \
185 | include/uapi/linux/signal.h arch/x86/include/asm/signal.h \
186 | arch/x86/include/uapi/asm/signal.h \
187 | include/uapi/asm-generic/signal-defs.h \
188 | arch/x86/include/uapi/asm/siginfo.h include/uapi/asm-generic/siginfo.h \
189 | include/linux/task_io_accounting.h include/uapi/linux/rseq.h \
190 | include/linux/cgroup.h include/uapi/linux/cgroupstats.h \
191 | include/uapi/linux/taskstats.h include/linux/fs.h \
192 | include/linux/wait_bit.h include/linux/kdev_t.h \
193 | include/uapi/linux/kdev_t.h include/linux/dcache.h \
194 | include/linux/rculist_bl.h include/linux/list_bl.h \
195 | include/linux/bit_spinlock.h include/linux/lockref.h \
196 | include/linux/stringhash.h include/linux/hash.h include/linux/path.h \
197 | include/linux/list_lru.h include/linux/shrinker.h include/linux/xarray.h \
198 | include/linux/capability.h include/uapi/linux/capability.h \
199 | include/linux/semaphore.h include/linux/fcntl.h \
200 | include/uapi/linux/fcntl.h arch/x86/include/uapi/asm/fcntl.h \
201 | include/uapi/asm-generic/fcntl.h include/uapi/linux/fiemap.h \
202 | include/linux/migrate_mode.h include/linux/percpu-rwsem.h \
203 | include/linux/rcuwait.h include/linux/rcu_sync.h \
204 | include/linux/delayed_call.h include/linux/uuid.h \
205 | include/uapi/linux/uuid.h include/linux/errseq.h include/linux/ioprio.h \
206 | include/linux/sched/rt.h include/linux/iocontext.h \
207 | include/uapi/linux/fs.h include/uapi/linux/limits.h \
208 | include/linux/quota.h include/linux/percpu_counter.h \
209 | include/uapi/linux/dqblk_xfs.h include/linux/dqblk_v1.h \
210 | include/linux/dqblk_v2.h include/linux/dqblk_qtree.h \
211 | include/linux/projid.h include/uapi/linux/quota.h \
212 | include/linux/nfs_fs_i.h include/linux/seq_file.h include/linux/cred.h \
213 | include/linux/key.h include/linux/assoc_array.h include/linux/selinux.h \
214 | include/linux/sched/user.h include/linux/ratelimit.h \
215 | include/linux/ns_common.h include/linux/nsproxy.h \
216 | include/linux/user_namespace.h include/linux/kernel_stat.h \
217 | include/linux/interrupt.h include/linux/irqreturn.h \
218 | include/linux/irqnr.h include/uapi/linux/irqnr.h include/linux/hardirq.h \
219 | include/linux/ftrace_irq.h include/linux/vtime.h \
220 | include/linux/context_tracking_state.h arch/x86/include/asm/irq.h \
221 | arch/x86/include/asm/sections.h include/asm-generic/sections.h \
222 | arch/x86/include/asm/extable.h include/linux/cgroup-defs.h \
223 | include/linux/percpu-refcount.h include/linux/u64_stats_sync.h \
224 | include/linux/bpf-cgroup.h include/uapi/linux/bpf.h \
225 | include/uapi/linux/bpf_common.h include/linux/cgroup_subsys.h \
226 | include/linux/delay.h arch/x86/include/asm/delay.h \
227 | include/asm-generic/delay.h
228 |
--------------------------------------------------------------------------------
/ex8-KernelThread/Makefile:
--------------------------------------------------------------------------------
1 | obj-m:=kthread.o
2 | CURRENT_PATH:=$(shell pwd)
3 | LINUX_KERNEL:=$(shell uname -r)
4 | LINUX_KERNEL_PATH:=/usr/src/linux-headers-$(LINUX_KERNEL)
5 | all:
6 | make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
7 | clean:
8 | make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean
9 |
--------------------------------------------------------------------------------
/ex8-KernelThread/kthread.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | static struct task_struct *tsk[NR_CPUS];
8 |
9 | static void show_reg(void)
10 | {
11 | unsigned int cpsr, sp;
12 |
13 | asm("mrs %0, cpsr" : "=r" (cpsr) : : "cc");
14 | asm("mov %0, sp" : "=r" (sp) : : "cc");
15 |
16 | printk("cpsr:0x%x, sp:0x%x\n", cpsr, sp);
17 | }
18 |
19 | static void show_prio(void)
20 | {
21 | struct task_struct *task = current;
22 |
23 | printk("%s pid:%d, nice:%d prio:%d static_prio:%d normal_prio:%d\n",
24 | task->comm, task->pid,
25 | PRIO_TO_NICE(task->static_prio),
26 | task->prio, task->static_prio,
27 | task->normal_prio);
28 | }
29 |
30 | static void print_cpu(char *s)
31 | {
32 | preempt_disable();
33 | pr_info("%s cpu=%d.\n", s, smp_processor_id());
34 | preempt_enable();
35 | }
36 |
37 | static int thread_fun(void *t)
38 | {
39 | do {
40 | print_cpu("SLEEP in Thread Function ");
41 | msleep_interruptible(2000);
42 | print_cpu("msleep over in Thread Function");
43 | print_cpu("running");
44 | show_reg();
45 | show_prio();
46 | } while (!kthread_should_stop());
47 | return 0;
48 | }
49 |
50 | static int __init my_init(void)
51 | {
52 | int i;
53 | print_cpu("Loading module");
54 | for_each_online_cpu(i) {
55 | tsk[i] = kthread_create(thread_fun, NULL, "kdemo/%d", i);
56 | if (!tsk[i]) {
57 | pr_info("Failed to generate a kernel thread\n");
58 | return -1;
59 | }
60 | kthread_bind(tsk[i], i);
61 | pr_info("About to wake up and run the thread for cpu=%d\n", i);
62 | wake_up_process(tsk[i]);
63 | pr_info("Staring thread for cpu %d", i);
64 | print_cpu("on");
65 | }
66 | return 0;
67 | }
68 |
69 | static void __exit my_exit(void)
70 | {
71 | int i;
72 | for_each_online_cpu(i) {
73 | pr_info(" Kill Thread %d", i);
74 | kthread_stop(tsk[i]);
75 | print_cpu("Kill was done on ");
76 | }
77 | }
78 |
79 | module_init(my_init);
80 | module_exit(my_exit);
81 |
82 | MODULE_AUTHOR("Ben ShuShu");
83 | MODULE_LICENSE("GPL v2");
84 |
85 |
--------------------------------------------------------------------------------
/ex9-TraversePcb/Makefile:
--------------------------------------------------------------------------------
1 | obj-m:=traverse_pcb.o
2 |
3 | CURRENT_PATH:=$(shell pwd)
4 | LINUX_KERNEL:=$(shell uname -r)
5 | LINUX_KERNEL_PATH:=/usr/src/linux-headers-$(LINUX_KERNEL)
6 |
7 | all:
8 | make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
9 |
10 | clean:
11 | make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean
12 |
--------------------------------------------------------------------------------
/ex9-TraversePcb/traverse_pcb.c:
--------------------------------------------------------------------------------
1 | # include
2 | # include
3 | # include
4 | # include
5 | # include
6 | # include
7 | # include
8 | # include
9 |
10 | //内核模块初始化函数
11 | static int __init traverse_pcb(void)
12 | {
13 | struct task_struct *task, *p;//定义指向task_struct类型的指针
14 | struct list_head *pos;//定义双向链表指针
15 | int count=0;//定义统计系统进程个数的变量
16 | printk("Printf process'message begin:\n");//提示模块开始运行
17 | task = &init_task;//指向0号进程的PCB
18 |
19 | list_for_each(pos,&task->tasks)//使用list_for_each宏来遍历进程链表
20 | {
21 | p = list_entry(pos,struct task_struct,tasks);//指向当前进程的task_struct结构
22 | count++;//统计系统进程个数
23 | printk("\n\n");//方便查看后续打印信息
24 | /*
25 | 打印task_struct中的字段,其中pid:进程的pid号;state:进程的状态;
26 | prio:动态优先级;static_prio:静态优先级; parent'pid:父进程的pid号;
27 | count:文件系统信息,文件被使用的次数; umask:进程权限位的默认设置;
28 | 使用atomic_read原子操作是为了(p->files)->count字段计数不被打断
29 | */
30 | printk("pid:%d; state:%lx; prio:%d; static_prio:%d; parent'pid:%d; count:%d; umask:%d;", \
31 | p->pid,p->state,p->prio,p->static_prio,(p->parent)->pid, \
32 | atomic_read((&(p->files)->count)),(p->fs)->umask);
33 | //打印进程地址空间的信息
34 | if((p->mm)!=NULL)
35 | printk("total_vm:%ld;",(p->mm)->total_vm);//total_vm:线性区总的页数
36 | }
37 | printk("进程的个数:%d\n",count);//打印进程个数
38 | return 0;
39 | }
40 |
41 | //内核模块退出函数
42 | static void __exit end_pcb(void)
43 | {
44 | printk("traverse pcb is end.");
45 | }
46 | module_init(traverse_pcb);//入口
47 | module_exit(end_pcb);//出口
48 | MODULE_LICENSE("GPL");//许可证
--------------------------------------------------------------------------------
/代码目录索引.md:
--------------------------------------------------------------------------------
1 | # 本仓库代码为Linux内核初学者练习代码,包含源代码、编译链接后的文件和运行结果,目录说明如下
2 |
3 | ## ex1_hello
4 |
5 | 经典的helloworld入门代码
6 |
7 | ## ex2_exnum
8 |
9 | 使用内核中的函数求最大值和最小值
10 |
11 | ## ex3_lklist
12 |
13 | 内核链表的创建、遍历,删除,并将数据打印出来
14 |
15 | ## ex4_kernel_param
16 |
17 | 内核传参
18 |
19 | ## ex5_Makefile2file
20 |
21 | Makefile编译两个以上文件
22 |
23 | ## ex6_rbtree
24 |
25 | 红黑树的应用
26 |
27 | ## ex7_ForkAndClone
28 |
29 | fork()的应用
30 |
31 | ## ex8_KernelThread
32 |
33 | 内核线程的应用
34 |
35 | ## ex9_TraversePcb
36 |
37 | 打印进程PCB中的字段
38 |
--------------------------------------------------------------------------------