summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2020-05-13 17:34:23 +0200
committerMikael Magnusson <mikma@users.sourceforge.net>2023-11-23 02:25:36 +0100
commited671b33199dfcd0290c768e43c8e10f507485fd (patch)
tree23cd70f92ff218ea110f411ce982cf9d8334e458
parent4094bd5e7a3b7d993ba4ea5baf4a98f11789ec57 (diff)
Wg-user: Work-around listen_port mutex dead lock
Problem with listen_port dead lock in wireguard-go.
-rw-r--r--filter/f-inst.c76
-rw-r--r--sysdep/unix/wg_user.c9
2 files changed, 83 insertions, 2 deletions
diff --git a/filter/f-inst.c b/filter/f-inst.c
index 9cc46aa0..6999d433 100644
--- a/filter/f-inst.c
+++ b/filter/f-inst.c
@@ -826,6 +826,13 @@
eattr *e = ea_find(eal, da.ea_code);
if (!e) {
+ /* A special case for tunnel encap */
+ if (da.type == EAF_TYPE_TUNNEL_ENCAP) {
+ RESULT_(T_TLVLIST, tl, NULL);
+ runtime("Can't get null tunnel encap");
+ break;
+ }
+
RESULT_VAL(val_empty(da.f_type));
break;
}
@@ -861,6 +868,14 @@
case EAF_TYPE_LC_SET:
RESULT_(T_LCLIST, ad, e->u.ptr);
break;
+ case EAF_TYPE_TUNNEL_ENCAP:
+ {
+ struct te_tlvlist *decoded_tl = tlvlist_decode_tunnel_encap(fpool, e->u.ptr);
+ if (!decoded_tl)
+ runtime( "Tunnel encapsulation decoder error" );
+ RESULT_(T_TLVLIST, tl, decoded_tl);
+ break;
+ }
default:
bug("Unknown dynamic attribute type");
}
@@ -927,6 +942,16 @@
}
break;
+ case EAF_TYPE_TUNNEL_ENCAP:
+ {
+ if (v1.type != T_TLVLIST)
+ runtime( "Setting tunnel encap attribute to non-tlvlist value %d", v1.type );
+ l->attrs[0].u.ptr = tlvlist_encode_tunnel_encap(fpool, v1.val.tl);
+ if (!l->attrs[0].u.ptr)
+ runtime( "Tunnel encapsulation encoder error" );
+ break;
+ }
+
default:
bug("Unknown dynamic attribute type");
}
@@ -1309,6 +1334,23 @@
RESULT(T_LCLIST, ad, [[ lc_set_union(fpool, v1.val.ad, v2.val.ad) ]]);
}
+ INST(FI_TLVLIST_ADD_SET, 2, 1) {
+ ARG(1, T_TLVLIST);
+ ARG(2, T_SET);
+ METHOD_CONSTRUCTOR("add");
+ if (subtlv_set_type(v2.val.t))
+ RESULT_(T_TLVLIST, tl, [[ tlv_set_add(fpool, v1.val.tl, tlv_alloc(fpool, v2.val.t)) ]]);
+ else
+ runtime("Can't add non-tlv");
+ }
+
+ INST(FI_TLVLIST_ADD_SET, 2, 1) {
+ ARG(1, T_TLVLIST);
+ ARG(2, T_TLVLIST);
+ METHOD_CONSTRUCTOR("add");
+ RESULT_(T_TLVLIST, tl, [[ tlv_set_union(fpool, v1.val.tl, v2.val.tl) ]]);
+ }
+
INST(FI_PATH_DELETE_INT, 2, 1) {
ARG(1, T_PATH);
ARG(2, T_INT);
@@ -1424,6 +1466,19 @@
RESULT(T_LCLIST, ad, [[ lclist_filter(fpool, v1.val.ad, &v2, 0) ]]);
}
+#if 0
+ INST(FI_TLVLIST_DELETE_SET, 2, 1) {
+ ARG(1, T_TLVLIST);
+ ARG(2, T_SET);
+ METHOD_CONSTRUCTOR("delete");
+
+ if (!subtlv_set_type(v2.val.t))
+ runtime("Mismatched set type");
+
+ RESULT_(T_TLVLIST, tl, [[ tlvlist_filter(fpool, v1.val.tl, &v2, 0) ]]);
+ }
+#endif
+
INST(FI_PATH_FILTER_SET, 2, 1) {
ARG(1, T_PATH);
ARG(2, T_SET);
@@ -1489,6 +1544,27 @@
RESULT(T_LCLIST, ad, [[ lclist_filter(fpool, v1.val.ad, &v2, 1) ]]);
}
+#if 0
+ INST(FI_TLVLIST_FILTER_TLVLIST, 2, 1) {
+ ARG(1, T_TLVLIST);
+ ARG(2, T_SET);
+ METHOD_CONSTRUCTOR("filter");
+
+ RESULT_(T_TLVLIST, tl, [[ tlvlist_filter(fpool, v1.val.tl, &v2, 1) ]]);
+ }
+
+ INST(FI_TLVLIST_FILTER_SET, 2, 1) {
+ ARG(1, T_TLVLIST);
+ ARG(2, T_TLVLIST);
+ METHOD_CONSTRUCTOR("filter");
+
+ if (!subtlv_set_type(v2.val.t))
+ runtime("Mismatched set type");
+
+ RESULT_(T_TLVLIST, tl, [[ tlvlist_filter(fpool, v1.val.tl, &v2, 1) ]]);
+ }
+#endif
+
INST(FI_ROA_CHECK_IMPLICIT, 0, 1) { /* ROA Check */
NEVER_CONSTANT;
RTC(1);
diff --git a/sysdep/unix/wg_user.c b/sysdep/unix/wg_user.c
index 9192f952..df2dafa6 100644
--- a/sysdep/unix/wg_user.c
+++ b/sysdep/unix/wg_user.c
@@ -212,8 +212,13 @@ static int
user_put_device(wg_device *dev, byte **buf, uint *size)
{
wg_put_u16("set", 1, buf, size);
- wg_put_key("private_key", dev->private_key, buf, size);
- wg_put_u16("listen_port", dev->listen_port, buf, size);
+ if (dev->flags & WGDEVICE_HAS_PRIVATE_KEY)
+ wg_put_key("private_key", dev->private_key, buf, size);
+#if 0
+ /* Setting listen_port causes dead-lock in wireguard-go. */
+ if (dev->flags & WGDEVICE_HAS_LISTEN_PORT)
+ wg_put_u16("listen_port", dev->listen_port, buf, size);
+#endif
wg_put_bool("replace_peers", dev->flags & WGDEVICE_REPLACE_PEERS, buf, size);
wg_peer *peer = NULL;