diff options
-rw-r--r-- | proto/wireguard/config.Y | 8 | ||||
-rw-r--r-- | proto/wireguard/wireguard.c | 8 | ||||
-rw-r--r-- | proto/wireguard/wireguard.h | 1 |
3 files changed, 11 insertions, 6 deletions
diff --git a/proto/wireguard/config.Y b/proto/wireguard/config.Y index dceebb67..6d3b1ef6 100644 --- a/proto/wireguard/config.Y +++ b/proto/wireguard/config.Y @@ -12,13 +12,15 @@ CF_HDR CF_DEFINES +#define WG_DEFAULT_TUNNEL_TYPE 51820 + #define WG_CFG ((struct wg_config *) this_proto) static struct peer_config *this_peer = NULL; CF_DECLS -CF_KEYWORDS(WIREGUARD, PRIVATE_KEY, LISTEN_PORT, PUBLIC_KEY, ENDPOINT, ALLOWED_IP) +CF_KEYWORDS(WIREGUARD, TUNNEL_TYPE, PRIVATE_KEY, LISTEN_PORT, PUBLIC_KEY, ENDPOINT, ALLOWED_IP) CF_GRAMMAR @@ -27,6 +29,7 @@ proto: wireguard_proto '}' ; wireguard_proto_start: proto_start WIREGUARD { this_proto = proto_config_new(&proto_wireguard, $1); init_list(&WG_CFG->peers); + WG_CFG->tunnel_type = WG_DEFAULT_TUNNEL_TYPE; } ; @@ -34,6 +37,7 @@ wireguard_proto: wireguard_proto_start proto_name '{' | wireguard_proto wg_proto_channel ';' | wireguard_proto proto_item ';' + | wireguard_proto TUNNEL_TYPE tunnel_type ';' | wireguard_proto INTERFACE TEXT ';' { WG_CFG->ifname = $3; } | wireguard_proto PRIVATE_KEY private_key ';' | wireguard_proto LISTEN_PORT listen_port ';' @@ -66,6 +70,8 @@ wg_peer_opt_list: | '{' wg_peer_opts '}' ; +tunnel_type: expr { WG_CFG->tunnel_type = $1; } + private_key: text { WG_CFG->private_key = $1; } listen_port: expr { WG_CFG->listen_port = $1; } diff --git a/proto/wireguard/wireguard.c b/proto/wireguard/wireguard.c index f0ac45e6..f73460d5 100644 --- a/proto/wireguard/wireguard.c +++ b/proto/wireguard/wireguard.c @@ -402,8 +402,6 @@ dump(void *ptr, size_t len) #define FLAG_BGP_TUNNEL_ENCAP_A_SUB_TLV_REMOTE_EP (1<<BGP_TUNNEL_ENCAP_A_SUB_TLV_REMOTE_EP) #define FLAG_BGP_TUNNEL_ENCAP_A_SUB_TLV_UDP_DEST_PORT (1<<BGP_TUNNEL_ENCAP_A_SUB_TLV_UDP_DEST_PORT) -#define BGP_TUNNEL_ENCAP_A_TUNNEL_TYPE_WIREGUARD 65535 - static int decode_wireguard(const void *p, size_t sub_tlv_len, wg_key *pubkey, u16 *flags) { @@ -542,7 +540,7 @@ int decode_sub_tlv(u8 *p, size_t len, wg_key *pubkey, } static -int decode_tunnel_encap(const eattr *e, wg_key *pubkey, u32 *as4, ip_addr *remote_ep, u32 *color, u16 *udp_port, u16 *flags) +int decode_tunnel_encap(const eattr *e, u16 wg_tunnel_type, wg_key *pubkey, u32 *as4, ip_addr *remote_ep, u32 *color, u16 *udp_port, u16 *flags) { u8 *p = e->u.ptr->data; int len = e->u.ptr->length; @@ -556,7 +554,7 @@ int decode_tunnel_encap(const eattr *e, wg_key *pubkey, u32 *as4, ip_addr *remot log(L_DEBUG "WG: tunnel type %d", tunnel_type); - if (tunnel_type != BGP_TUNNEL_ENCAP_A_TUNNEL_TYPE_WIREGUARD) { + if (tunnel_type != wg_tunnel_type) { log(L_TRACE "WG: tunnel type error %d", tunnel_type); return -1; } @@ -695,7 +693,7 @@ wg_rt_notify(struct proto *P, struct channel *CH, struct network *n, if (!t && he && he->src) { t = ea_find(he->src->eattrs, EA_CODE(PROTOCOL_BGP, BA_TUNNEL_ENCAP)); } - if (t && t->u.ptr && decode_tunnel_encap(t, &pubkey, &remote_ep_as4, &remote_ep_addr, &color, &udp_dest_port, &flags) == 0) { + if (t && t->u.ptr && decode_tunnel_encap(t, c->tunnel_type, &pubkey, &remote_ep_as4, &remote_ep_addr, &color, &udp_dest_port, &flags) == 0) { log(L_TRACE "WG: Attr %x %x %d %04x", t->flags, t->type, t->u.ptr->length, flags); struct wg_device *dev = p->dev; diff --git a/proto/wireguard/wireguard.h b/proto/wireguard/wireguard.h index 69345953..c2f780ca 100644 --- a/proto/wireguard/wireguard.h +++ b/proto/wireguard/wireguard.h @@ -18,6 +18,7 @@ struct wg_config { const char *ifname; const char *socket_path; const char *private_key; + u16 tunnel_type; u16 listen_port; list peers; }; |