Kernel Module Logic

  • Specify the module initialization entry function wg_device_init
  • Register the virtual network device rtnl_link_register(&link_ops)
  • Initialize the net_device struct via wg_setup
  • Specify the initialization operation for the ip link add command (where the main functional logic resides) wg_newlink
  • Specify the operation when the virtual network device is brought up wg_open
  • Specify the operation when the virtual network device is stopped wg_stop
  • Specify the operation when the virtual network device starts transmitting the first packet wg_xmit
  • The WireGuard initialization steps are:
    • Add a virtual network device via ip link add dev wg0 type wireguard
    • Configure the virtual network device address via ip addr add 10.0.0.4/24 dev wg0
    • Apply WireGuard configuration via wg set wg0
    • Bring up the virtual network device via ip link set wg0 up
  • Therefore, we should first look at the logic of wg_newlink, then the logic of wg_open