summaryrefslogtreecommitdiffhomepage
path: root/src/uapi.h
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2016-07-22 20:30:34 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2016-07-22 20:30:34 +0200
commit2d8170c259fd234c9608df2481f8f5a93f4fe387 (patch)
treee06cd29ebf63102385d6555da1c5f731eddf43f3 /src/uapi.h
parentd23fe2901d9877a60cd219d0d49df01aa07f5940 (diff)
tools: Use seqpacket instead of dgram
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/uapi.h')
-rw-r--r--src/uapi.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/uapi.h b/src/uapi.h
index c701de3..01dba48 100644
--- a/src/uapi.h
+++ b/src/uapi.h
@@ -129,4 +129,20 @@ struct wgdevice {
};
};
+/* These are simply for convenience in iterating. It allows you to write something like:
+ *
+ * for_each_wgpeer(device, peer, i) {
+ * for_each_wgipmask(peer, ipmask, j) {
+ * do_something_with_ipmask(ipmask);
+ * }
+ * }
+ */
+#define for_each_wgpeer(__dev, __peer, __i) for ((__i) = 0, (__peer) = (typeof(__peer))((uint8_t *)(__dev) + sizeof(struct wgdevice)); \
+ (__i) < (__dev)->num_peers; \
+ ++(__i), (__peer) = (typeof(__peer))((uint8_t *)(__peer) + sizeof(struct wgpeer) + (sizeof(struct wgipmask) * (__peer)->num_ipmasks)))
+
+#define for_each_wgipmask(__peer, __ipmask, __i) for ((__i) = 0, (__ipmask) = (typeof(__ipmask))((uint8_t *)(__peer) + sizeof(struct wgpeer)); \
+ (__i) < (__peer)->num_ipmasks; \
+ ++(__i), (__ipmask) = (typeof(__ipmask))((uint8_t *)(__ipmask) + sizeof(struct wgipmask)))
+
#endif