Fw: WireGuard/src/tools/ipc.c improvement

阿群 517067180 at qq.com
Thu Feb 28 07:38:21 CET 2019


Hi dear developers of WireGuard!



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:
  
Rename ipc_get_device(&dev) to ipc_fetch_conf(&conf) because it only fetches the runtime configuations from kernel.
 
Change funtion prototype ipc_set_device(struct wgdevice *dev) to ipc_set_device(const struct wgdevice *newconf).
  
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:
  
In showconf_main(), show_main():
 device => conf
 
In ipc_fetch_conf(), kernel_fetch_conf(), userspace_fetch_conf():
 dev => conf
 
In ipc_set_device(), kernel_set_device(), userspace_set_device():
 dev => newconf
  
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)


Added function:

free_conf()




Patch code is both in the email attachment and on github.com ( https://github.com/WireGuard/WireGuard/pull/5/files )


Please tell me anything you thought, I would be glad to help.


Happy hacking!



------------------
-- Liu Qun from Tsingtao, China
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/wireguard/attachments/20190228/e839417f/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-tools-Rename-IPC-functions-to-reduce-misleading.patch
Type: application/octet-stream
Size: 22874 bytes
Desc: not available
URL: <http://lists.zx2c4.com/pipermail/wireguard/attachments/20190228/e839417f/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-tools-introduce-free_conf-as-an-alias-of-free_wgdevi.patch
Type: application/octet-stream
Size: 3534 bytes
Desc: not available
URL: <http://lists.zx2c4.com/pipermail/wireguard/attachments/20190228/e839417f/attachment-0003.obj>


More information about the WireGuard mailing list