diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2019-09-27 23:21:56 +0200 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2020-05-08 18:52:55 +0200 |
commit | 510414dd18eb6059660a1635fb8fc74727e24915 (patch) | |
tree | 06910c71acf57236c65c366e7eb39f985f6688d6 /proto/wireguard | |
parent | 806a5a8fe4c1af0357efa513b3f070d4585b8118 (diff) |
Wireguard: Add struct tunnel_encap
Diffstat (limited to 'proto/wireguard')
-rw-r--r-- | proto/wireguard/wireguard.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/proto/wireguard/wireguard.c b/proto/wireguard/wireguard.c index 2c2e6796..9896b53a 100644 --- a/proto/wireguard/wireguard.c +++ b/proto/wireguard/wireguard.c @@ -156,7 +156,7 @@ dump(void *ptr, size_t len) } static wg_peer * -add_peer(wg_device *dev, wg_key pubkey) +add_peer(wg_device *dev, const wg_key pubkey) { struct wg_peer *peer = malloc(sizeof(struct wg_peer)); memset(peer, 0, sizeof(struct wg_peer)); @@ -254,21 +254,18 @@ wg_rt_notify(struct proto *P, struct channel *CH, struct network *n, debug("WG: notify new %d %N\n", new->attrs->dest, n->n.addr); - wg_key pubkey; - size_t pubkey_size = sizeof(wg_key); - memset(pubkey, 0, pubkey_size); - u32 tunnel_ep_as4 = 0; - ip_addr tunnel_ep_addr = IPA_NONE; - u16 udp_dest_port = 0; - u32 color = 0; - u16 flags = 0; + struct tunnel_encap encap; + memset(&encap, 0, sizeof(encap)); + encap.ep.ip = IPA_NONE; t = ea_find(new->attrs->eattrs, EA_CODE(PROTOCOL_BGP, BA_TUNNEL_ENCAP)); 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, c->tunnel_type, &pubkey, &pubkey_size, &tunnel_ep_as4, &tunnel_ep_addr, &color, &udp_dest_port, &flags) == 0 && pubkey_size == sizeof(wg_key)) { - log(L_TRACE "WG: Attr %x %x %d %04x", t->flags, t->type, t->u.ptr->length, flags); + if (t && t->u.ptr && decode_tunnel_encap(t, &encap, P->pool) == 0 && encap.type == c->tunnel_type && encap.encap_len == sizeof(wg_key)) { + const wg_key *pubkey = encap.encap; + + log(L_TRACE "WG: Attr %x %x %d %04x", t->flags, t->type, t->u.ptr->length, encap.flags); struct wg_device *dev = p->dev; @@ -288,7 +285,7 @@ wg_rt_notify(struct proto *P, struct channel *CH, struct network *n, log(L_TRACE "WG: Found"); found = true; - set_peer_tunnel_ep(peer, tunnel_ep_addr, udp_dest_port); + set_peer_tunnel_ep(peer, encap.ep.ip, encap.udp_dest_port); add_allowed_ips(ch->c.net_type, n, peer); dirty = true; @@ -297,7 +294,7 @@ wg_rt_notify(struct proto *P, struct channel *CH, struct network *n, if (!found) { wg_peer *peer = add_peer(dev, pubkey); - set_peer_tunnel_ep(peer, tunnel_ep_addr, udp_dest_port); + set_peer_tunnel_ep(peer, encap.ep.ip, encap.udp_dest_port); add_allowed_ips(ch->c.net_type, n, peer); dirty = true; } @@ -351,6 +348,9 @@ wg_rt_notify(struct proto *P, struct channel *CH, struct network *n, log(L_TRACE "WG: No Attr"); } + mb_free(encap.encap); + encap.encap = NULL; + // old_metric = en->valid ? en->metric : -1; // en->valid = RIP_ENTRY_VALID; |