对LDD中snull程序,编译的时候会有许多问题,鉴于网上还没有合适的解决办法,做此总结,整理知识。本文在debian6.0上运行通过,内核版本为2.6.32。
学习LDD中网络驱动程序部分,理解snull程序的原理很有必要。snull不依赖于硬件,数据包的收发都属于内存操作,但对整个网络驱动程序原理已经做了很好的阐述。程序并不复杂,相比e100.c;8139too.c;pci-skeleton.c,容易理解的多。作者写这本书的时候尚是2.6.11的年代,与现在内核版本相比,有些接口发生了变化,这是snull编译失败的直接原因。本文将描述snull的修改方法,并指出发生变化的接口。本文在debian6.0上运行通过,内核版本为2.6.32。
本文提供了修改完成后的makefile和snull.c,并生成了patch文件。
本文内容
1)常见问题
2)正确的snull编译方法
3)文件下载
一 常见问题
这是我自己遇到的,和网上看到的部分问题,现一一阐述原因,并在第二段(见下文)中阐述解决方法。 如果在这些问题之外,还有问题,清大家留言,方便讨论。至于详细的接口变化,我会另写文章,一一说明。
1)错误描述:
make -C /lib/modules/2.6.32-5-686/build M=/home/xiebiwei/dev/code/Ldd/snull modules
make: *** /lib/modules/2.6.32-5-686/build: No such file or directory. Stop.
make: *** [default] Error 2
问题原因:没有安装内核源代码树,或者是安装了内核源代码树后,没有修改makefile中的kerneldir。
2)错误描述:
make -C /lib/modules/2.6.32/build M=/home/xiebiwei/dev/code/Ldd/snull modules
make[1]: Entering directory `/usr/src/linux-source-2.6.32'
scripts/Makefile.build:49: *** CFLAGS was changed in "/home/xiebiwei/dev/code/Ldd/snull/Makefile". Fix it to use EXTRA_CFLAGS. Stop.
make[1]: *** [_module_/home/xiebiwei/dev/code/Ldd/snull] Error 2
make[1]: Leaving directory `/usr/src/linux-source-2.6.32'
make: *** [default] Error 2
问题原因:内核版本不同,最近版本已经把CFLAGS变为EXTRA_CFLAGS
3)错误描述:
make -C /lib/modules/2.6.32/build M=/home/xiebiwei/dev/code/Ldd/snull modules
make[1]: Entering directory `/usr/src/linux-source-2.6.32'
CC [M] /home/xiebiwei/dev/code/Ldd/snull/snull.o
/home/xiebiwei/dev/code/Ldd/snull/snull.c:18:26: error: linux/config.h: No such file or directory
/home/xiebiwei/dev/code/Ldd/snull/snull.c: In function ‘snull_poll’:
/home/xiebiwei/dev/code/Ldd/snull/snull.c:289: error: ‘struct net_device’ has no member named ‘quota’
/home/xiebiwei/dev/code/Ldd/snull/snull.c:289: warning: type defaults to ‘int’ in declaration of ‘_min1’
/home/xiebiwei/dev/code/Ldd/snull/snull.c:289: error: ‘struct net_device’ has no member named ‘quota’
/home/xiebiwei/dev/code/Ldd/snull/snull.c:319: error: ‘struct net_device’ has no member named ‘quota’
/home/xiebiwei/dev/code/Ldd/snull/snull.c:321: error: implicit declaration of function ‘netif_rx_complete’
/home/xiebiwei/dev/code/Ldd/snull/snull.c: In function ‘snull_napi_interrupt’:
/home/xiebiwei/dev/code/Ldd/snull/snull.c:406: error: implicit declaration of function ‘netif_rx_schedule’
/home/xiebiwei/dev/code/Ldd/snull/snull.c: In function ‘snull_init’:
/home/xiebiwei/dev/code/Ldd/snull/snull.c:647: error: ‘struct net_device’ has no member named ‘open’
/home/xiebiwei/dev/code/Ldd/snull/snu