[Linux Kernel 源码分析] 通过vconfig配置vlan的系统调用/驱动流程分析

发布时间 2023-03-22 19:08:13作者: 蓝天上的云℡

By YuCloud (蓝天上的云℡ - 博客园 https://www.cnblogs.com/yucloud/)
转载请注明出处


vconfig源码分析

vlan/vconfig.c at master · Distrotech/vlan (github.com)
https://github.com/Distrotech/vlan/blob/master/vconfig.c#L185-L199

vconfig简单使用

#为网卡eth0添加vlan10
vconfig add eth0 10
#为网卡eth0删除vlan10
vconfig rem eth0.10

源码分析

以下是本人对整个流程的源码分析

配置vlan的驱动流程

  1. vconfig 通过 ioctl 系统调用接口陷入内核态执行驱动里的net/socket.c:sock_ioctl,里面调用了钩子函数
  2. 钩子是在net/8021q/vlan.c:vlan_proto_init里面配置好的
  3. 钩子处理函数本体位于 net/8021q/vlan.c:vlan_ioctl_handler,里面就是配置vlan的地方了。

源码分析片段

image

OneNote写的,懒得转了,右击打开图片即可

总结

  • 成功:分析了kernel里配置vlan的流程
  • 不足:对于网络包收发过程中内核如何对 vlan 包的处理还没分析。