1 Star 2 Fork 2

e665107/Linux-Device-Drivers-Development

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Fake ethernet driver

After running make command, there will be two modules:

  • fake-eth.ko
  • eth-ins.ko

The fist module is ou fake ethernet driver, the second one is used to create a plateform device that matches our first module. This way, one can avoid updating the devicetree.

 # insmod ./fake-eth.ko
 # insmod ./eth-ins.ko

After loading both modules, one can print debug message, and see something like below:

#dmesg
[146626.222072] fake-eth added
[146689.422000] fake-fake removed
[146698.060074] fake eth device initialized
[146698.060285] fake-eth added
[146698.087297] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready

Before loading the module, there were no eth0

$ ifconfig -a

enp3s0f1  Link encap:Ethernet  HWaddr 34:97:f6:ba:5e:d7  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:49727 errors:0 dropped:0 overruns:0 frame:0
          TX packets:49727 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:8431650 (8.4 MB)  TX bytes:8431650 (8.4 MB)

[...]

After loading modules,

$ ifconfig -a

enp3s0f1  Link encap:Ethernet  HWaddr 34:97:f6:ba:5e:d7  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

eth0      Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:49727 errors:0 dropped:0 overruns:0 frame:0
          TX packets:49727 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:8431650 (8.4 MB)  TX bytes:8431650 (8.4 MB)

[...]

One can also configure the interface like ifconfig eth0 192.168.1.45, and then

$ ifconfig eth0

eth0      Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
          inet addr:192.168.1.45  Bcast:192.168.1.255  Mask:255.255.255.0
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/e665107/Linux-Device-Drivers-Development.git
git@gitee.com:e665107/Linux-Device-Drivers-Development.git
e665107
Linux-Device-Drivers-Development
Linux-Device-Drivers-Development
master

搜索帮助