Recently, I've been reading the source code of WireGuard. The function name like ipc_get_device() looks to be a little bit misleading. To make the code more readable for new developers, here are some suggestions:
Change the following IPC function names and parameters which used to be confusing:
- ipc_set_device(dev) => ipc_set_device(newconf)
- ipc_get_device(dev, interface) => ipc_fetch_conf(conf, interface)
- kernel_set_device(dev) => kernel_set_device(newconf)
- kernel_get_device(device, interface) => kernel_fetch_conf(conf, interface)
- userspace_set_device(dev) => userspace_set_device(newconf)
- userspace_get_device(out, interface) => userspace_fetch_conf(out, interface)
- free_wgdevice(dev) => free_conf(conf)
Renamed local variable/parameter symbols:
Note:
A lot of braces are added to the if-else code blocks to keep ourselves from making unexpected mistakes in the future.
Changed function prototypes:
int ipc_set_device(struct wgdevice *)
=> int ipc_set_device(const struct wgdevice *newconf)
int kernel_set_device(struct wgdevice *)
=> int kernel_set_device(const struct wgdevice *newconf)
int userspace_set_device(struct wgdevice *)
=> int userspace_set_device(const struct wgdevice *newconf)
free_conf()