Skip to contentSkip to conversation

WireGuard: Secure Network Tunnel

PATCH Superseded Jason A. Donenfeld 7 participants 47 messages Oct 6, 2018 – Oct 11, 2018 Page 2 of 2

Subsystems (30)

v7 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#38 lore raw

Re: [PATCH net-next v7 28/28] net: WireGuard secure network tunnel

In reply to Jason A. Donenfeld
Quoted 89 lines · Sun, Oct 07, 2018 at 07:26:47PM CEST, [email protected] wrote:

Hi Jiri,

Quoted 72 lines · Jiri Pirko

drivers/net/wireguard/device.c line 306

Quoted 6 lines
drivers/net/wireguard/device.c new file +6 -0
+
+      wg->incoming_handshakes_worker =
+              wg_packet_alloc_percpu_multicore_worker(
+                              wg_packet_handshake_receive_worker, wg);
+      if (!wg->incoming_handshakes_worker)
+              goto error_2;

Please consider renaming the label to "what went wrong". In this case, it would be "err_alloc_worker".

Quoted 8 lines
drivers/net/wireguard/device.c new file +8 -0
+
+      wg->handshake_receive_wq = alloc_workqueue("wg-kex-%s",
+                      WQ_CPU_INTENSIVE | WQ_FREEZABLE, 0, dev->name);
+      if (!wg->handshake_receive_wq)
+              goto error_3;
+
+      wg->handshake_send_wq = alloc_workqueue("wg-kex-%s",
+                      WQ_UNBOUND | WQ_FREEZABLE, 0, dev->name);

drivers/net/wireguard/device.c line 324

Quoted 10 lines
drivers/net/wireguard/device.c new file +10 -0
+      if (!wg->handshake_send_wq)
+              goto error_4;
+
+      wg->packet_crypt_wq = alloc_workqueue("wg-crypt-%s",
+                      WQ_CPU_INTENSIVE | WQ_MEM_RECLAIM, 0, dev->name);
+      if (!wg->packet_crypt_wq)
+              goto error_5;
+
+      if (wg_packet_queue_init(&wg->encrypt_queue, wg_packet_encrypt_worker,
+                               true, MAX_QUEUED_PACKETS) < 0)

You need to have "int err" and always in cases like this to do:
err = wg_packet_queue_init()
if (err)
goto err_*

Quoted 35 lines
drivers/net/wireguard/device.c new file +35 -0
+              goto error_6;
+
+      if (wg_packet_queue_init(&wg->decrypt_queue, wg_packet_decrypt_worker,
+                               true, MAX_QUEUED_PACKETS) < 0)
+              goto error_7;
+
+      ret = wg_ratelimiter_init();
+      if (ret < 0)
+              goto error_8;
+
+      ret = register_netdevice(dev);
+      if (ret < 0)
+              goto error_9;
+
+      list_add(&wg->device_list, &device_list);
+
+      /* We wait until the end to assign priv_destructor, so that
+       * register_netdevice doesn't call it for us if it fails.
+       */
+      dev->priv_destructor = destruct;
+
+      pr_debug("%s: Interface created\n", dev->name);
+      return ret;
+
+error_9:
+      wg_ratelimiter_uninit();
+error_8:
+      wg_packet_queue_free(&wg->decrypt_queue, true);
+error_7:
+      wg_packet_queue_free(&wg->encrypt_queue, true);
+error_6:
+      destroy_workqueue(wg->packet_crypt_wq);
+error_5:
+      destroy_workqueue(wg->handshake_send_wq);
+error_4:
Quoted 8 lines

drivers/net/wireguard/device.c line 367

Quoted 8 lines
drivers/net/wireguard/device.c new file +8 -0
+      destroy_workqueue(wg->handshake_receive_wq);
+error_3:
+      free_percpu(wg->incoming_handshakes_worker);
+error_2:
+      free_percpu(dev->tstats);
+error_1:
+      return ret;
+}

I'll change away from using error_9,8,7,6,5,4,3,2,1 because of your suggestion -- and because it's the norm in the kernel to use real names. But, I would be interested in your opinion on the numerical errors' reasoning for existing in the first place. The idea was that with so many different failure cases that need to cascade in the

Quoted 8 lines

correct order, it's much easier to visually inspect that it's been done right by observing up top 1,2,3,4,5,6,7,8,9 and at the bottom 9,8,7,6,5,4,3,2,1, rather than having to store in my brain's limited stack space what each name pertains to and keep track of the ordering and such. In light of that, do you still think that following the convention of textual error labels is a good match here? Again, I'm changing this for v8, but I am nonetheless curious about what you think.

I think it is perfectly readable when you have:

	err = do_thing_x();
	if (err)
		goto err_do_thing_x;

err_do_thing_x;

Rest of the code (at least in netdev subtree) uses this a lot.

Quoted 2 lines

Jason

#40 lore raw

Re: [PATCH net-next v7 28/28] net: WireGuard secure network tunnel

Quoted 7 lines · Wed, Oct 10, 2018 at 10:27:46PM CEST, [email protected] wrote:

Hey Jiri,

Actually, in the end I went with the suggestion from Andrew and Lukas, which is to follow Dan's guideline:
https://lkml.org/lkml/2016/8/22/374 . It looks like this:

https://git.kernel.org/pub/scm/linux/kernel/git/zx2c4/linux.git/tree/drivers/net/wireguard/device.c?h=jd/wireguard#n280

I prefer:

                 err = do_something();
                 if (err)
                         goto err_do_something;

But your style is also quite common. Up to you, I guess.

Quoted 2 lines

Jason

#41 lore raw

Re: [PATCH net-next v7 28/28] net: WireGuard secure network tunnel

In reply to Jason A. Donenfeld

drivers/net/wireguard/netlink.c line 84

Quoted 6 lines · Jason A. Donenfeld
drivers/net/wireguard/netlink.c new file +6 -0
+static int get_allowedips(void *ctx, const u8 *ip, u8 cidr, int family)
+{
+	struct allowedips_ctx *actx = ctx;
+	struct nlattr *allowedip_nest;
+
+	allowedip_nest = nla_nest_start(actx->skb, actx->i++);

Second parameter of nl_nest_start is an attribute type; (ab)using it as array index leads to special handling of such structures in parsers. It's better to have some type like WGDEVICE_A_PEER_ITEM and provide an additional attribute inside it for index (WGPEER_A_INDEX?). See, for example, commit v4.12-rc1~119^2~131 ("nbd: add a status netlink command").

drivers/net/wireguard/netlink.c line 103

Quoted 4 lines
drivers/net/wireguard/netlink.c new file +4 -0
+static int get_peer(struct wireguard_peer *peer, unsigned int index,
+		    struct allowedips_cursor *rt_cursor, struct sk_buff *skb)
+{
+	struct nlattr *allowedips_nest, *peer_nest = nla_nest_start(skb, index);

Same here.

author maintainer
#42 lore raw

Re: [PATCH net-next v7 28/28] net: WireGuard secure network tunnel

Hey Eugene,

Quoted 16 lines · Eugene Syromiatnikov

drivers/net/wireguard/netlink.c line 84

Quoted 6 lines · Jason A. Donenfeld
drivers/net/wireguard/netlink.c new file +6 -0
+static int get_allowedips(void *ctx, const u8 *ip, u8 cidr, int family)
+{
+     struct allowedips_ctx *actx = ctx;
+     struct nlattr *allowedip_nest;
+
+     allowedip_nest = nla_nest_start(actx->skb, actx->i++);

Second parameter of nl_nest_start is an attribute type; (ab)using it as array index leads to special handling of such structures in parsers. It's better to have some type like WGDEVICE_A_PEER_ITEM and provide an additional attribute inside it for index (WGPEER_A_INDEX?). See, for example, commit v4.12-rc1~119^2~131 ("nbd: add a status netlink command").

Quoted 6 lines

drivers/net/wireguard/netlink.c line 103

Quoted 4 lines
drivers/net/wireguard/netlink.c new file +4 -0
+static int get_peer(struct wireguard_peer *peer, unsigned int index,
+                 struct allowedips_cursor *rt_cursor, struct sk_buff *skb)
+{
+     struct nlattr *allowedips_nest, *peer_nest = nla_nest_start(skb, index);

Same here.

Good point. Actually the index aspect is totally arbitrary and not useful at all, and so that part can just be entirely excised.

Jason

#43 lore raw

Re: [PATCH net-next v7 28/28] net: WireGuard secure network tunnel

In reply to Jason A. Donenfeld

Hi Jason

The BUG() statements all seemed to be removed. Thanks.

We still have 1 errors, 193 warnings, 7529 lines checked from checkpatch. There are still some Macros flow control statements in them, despite me pointed them out multiple times.

Im not reviewing this version any further. Until you get the very basics right, i doubt this patch is going to make much progress towards inclusion.

Andrew

author maintainer
#44 lore raw

Re: [PATCH net-next v7 28/28] net: WireGuard secure network tunnel

Hey Andrew,

Quoted 9 lines · Andrew Lunn

The BUG() statements all seemed to be removed. Thanks.

We still have 1 errors, 193 warnings, 7529 lines checked from checkpatch. There are still some Macros flow control statements in them, despite me pointed them out multiple times.

Im not reviewing this version any further. Until you get the very basics right, i doubt this patch is going to make much progress towards inclusion.

Dave mentioned he wanted the Zinc stuff to be all set before looking at this, so I've been focusing my efforts mostly on that. But I haven't forgotten about your reviews, and seeing as you're actually interested in looking at this now, I'll be sure to address everything you've mentioned for v8. When I'm reasonably sure that's all done, I'll let you know, so that you're not disappointed again.

Jason

#45 lore raw

Re: [PATCH net-next v7 28/28] net: WireGuard secure network tunnel

Quoted 13 lines · Jason A. Donenfeld

Hey Andrew,

Quoted 9 lines · Andrew Lunn

The BUG() statements all seemed to be removed. Thanks.

We still have 1 errors, 193 warnings, 7529 lines checked from checkpatch. There are still some Macros flow control statements in them, despite me pointed them out multiple times.

Im not reviewing this version any further. Until you get the very basics right, i doubt this patch is going to make much progress towards inclusion.

Quoted 6 lines

Dave mentioned he wanted the Zinc stuff to be all set before looking at this, so I've been focusing my efforts mostly on that. But I haven't forgotten about your reviews, and seeing as you're actually interested in looking at this now, I'll be sure to address everything you've mentioned for v8. When I'm reasonably sure that's all done, I'll let you know, so that you're not disappointed again.

Hi Jason

This is the sort of thing you should state in the patchset version history. It is O.K. to say i will address this later, but you need to communicate that. Otherwise reviewers just get frustrated that comments are getting repeatedly ignored and why should they bother reviewing it. And without reviewers willing to review your code, it will never get into mainline.

author maintainer
#46 lore raw

Re: [PATCH net-next v7 28/28] net: WireGuard secure network tunnel

Hi Andrew,

Quoted 8 lines · Andrew Lunn

Hi Jason

This is the sort of thing you should state in the patchset version history. It is O.K. to say i will address this later, but you need to communicate that. Otherwise reviewers just get frustrated that comments are getting repeatedly ignored and why should they bother reviewing it. And without reviewers willing to review your code, it will never get into mainline.

Understood. Sorry about that.

Jason