// Based on proto/rip/rip.c #include #include #include #include #include #include #include "lib/lists.h" #include "lib/socket.h" #include "nest/protocol.h" #include "nest/iface.h" #include "sysdep/linux/wireguard.h" #include "sysdep/unix/unix.h" #include "wireguard.h" #include "proto/bgp/bgp.h" #define SOCKET_PATH PATH_RUNSTATEDIR "/wireguard/" static char *get_socket_path(struct wg_proto *p, char *buf, uint size) { struct wg_config *c = (struct wg_config *) p->p.cf; bsnprintf(buf, size, SOCKET_PATH "%s.sock", c->ifname); return buf; } static bool has_userspace(struct wg_proto *p) { struct wg_config *c = (struct wg_config *) p->p.cf; struct stat sb; char tmp[sizeof(struct sockaddr_un)]; if (stat(get_socket_path(p, tmp, sizeof(tmp)), &sb) == 0) return (sb.st_mode & S_IFMT) == S_IFSOCK; else { log(L_TRACE "WG: no socket %s", tmp); return false; } } /* NULL=receiving turned off, returns 1 to clear rx buffer */ static int user_rx_hook(struct birdsock *sk, uint size) { log(L_TRACE "WG: RX %d", size); return 1; } static void user_tx_hook(struct birdsock *bs) { log(L_TRACE "WG: TX"); } /* errno or zero if EOF */ static void user_err_hook(struct birdsock *bs, int err) { /* if (err == 0) */ /* return; */ log(L_TRACE "WG: ERR %d %s", err, bs->err); if (bs->fd >= 0) close(bs->fd); bs->fd = -1; } static void wg_puts(const char *str, byte **buf, uint *size) { int len = strlen(str); if (0 < len && len < (int)*size) { strcpy(*buf, str); *size -= len; *buf += len; } else *size = 0; } static void wg_put_str(const char *key, const char *value, byte **buf, uint *size) { char tmp[128]; int len = snprintf(tmp, sizeof(tmp), "%s=%s\n", key, value); if (0 < len && len < (int)*size) { strcpy(*buf, tmp); *size -= len; *buf += len; } else *size = 0; } static void wg_put_u16(const char *key, u16 value, byte **buf, uint *size) { char tmp[64]; int len = snprintf(tmp, sizeof(tmp), "%u", value); if (len > 0) wg_put_str(key, tmp, buf, size); else *size = 0; } static void wg_put_bool(const char *key, bool value, byte **buf, uint *size) { char tmp[64]; if (value) wg_put_str(key, "true", buf, size); } static void wg_put_key(const char *key, wg_key value, byte **buf, uint *size) { char tmp[128]; for (uint i=0; i < sizeof(wg_key); i++) bsnprintf(tmp+2*i, sizeof(tmp)-2*i, "%02x", value[i]); wg_put_str(key, tmp, buf, size); } static void wg_put_endpoint(const char *key, const wg_endpoint *endpoint, byte **buf, uint *size) { char tmp[INET6_ADDRSTRLEN + 16]; ip_addr ip; struct iface *ifa = NULL; uint port = 0; if (sockaddr_read((sockaddr*)&endpoint->addr, endpoint->addr.sa_family, &ip, &ifa, &port) == 0) { char *pos = NULL; if (ipa_is_ip4(ip)) pos = ip4_ntop(ipa_to_ip4(ip), tmp); else { tmp[0] = '['; pos = ip6_ntop(ipa_to_ip6(ip), tmp + 1); if (ifa) pos += bsprintf(pos, "%%%u", ifa->index); *pos++ = ']'; } bsprintf(pos, ":%u", port); wg_put_str("endpoint", tmp, buf, size); } } static void wg_put_allowedip(wg_allowedip *allowedip, byte **buf, uint *size) { char tmp[INET6_ADDRSTRLEN + 10]; ip_addr ip = IP6_NONE; switch (allowedip->family) { case AF_INET: ip = ipa_from_in4(allowedip->ip4); break; case AF_INET6: ip = ipa_from_in6(allowedip->ip6); break; default: return; } int res = bsnprintf(tmp, sizeof(tmp), "%I/%u", ip, allowedip->cidr); if (res < 0) { *size = 0; return; } wg_put_str("allowed_ip", tmp, buf, size); } 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); wg_put_bool("replace_peers", dev->flags & WGDEVICE_REPLACE_PEERS, buf, size); wg_peer *peer = NULL; wg_for_each_peer(dev, peer) { wg_put_key("public_key", peer->public_key, buf, size); wg_put_endpoint("endpoint", &peer->endpoint, buf, size); wg_put_bool("replace_allowed_ips", peer->flags & WGPEER_REPLACE_ALLOWEDIPS, buf, size); wg_allowedip *allowedip = NULL; wg_for_each_allowedip(peer, allowedip) { wg_put_allowedip(allowedip, buf, size); } } wg_puts("\n", buf, size); if (*size > 0) return 0; else return -1; } static int user_set_device(struct wg_proto *p) { struct wg_config *c = (struct wg_config *) p->p.cf; char path[sizeof(struct sockaddr_un)]; bsnprintf(path, sizeof(path), SOCKET_PATH "%s.sock", c->ifname); struct birdsock *sock = sk_new(p->p.pool); sock->rx_hook = user_rx_hook; sock->tx_hook = user_tx_hook; sock->err_hook = user_err_hook; int res = sk_connect_unix(sock, path); log(L_TRACE "WG: socket %d %d %s", res, sock->fd, path); if (res < 0) return -1; uint tbsize = 8192; sk_set_tbsize(sock, tbsize); sk_set_rbsize(sock, 16); byte *pos = sock->tbuf; uint size = tbsize; int len = user_put_device(p->dev, &pos, &size); log(L_TRACE "WG: put %d %s", size, sock->tbuf); if (len < 0) { /* FIXME close */ return -1; } res = sk_send(sock, tbsize - size); /* Send data, <0=err, >0=ok, 0=sleep */ log(L_TRACE "WG: send %d", res); /* abort(); */ return -1; } static int get_device(struct wg_proto *p, wg_device **pdev, const char *device_name) { struct wg_config *c = (struct wg_config *) p->p.cf; /* if (has_user_space(p)) */ /* return user_get_device(p, dev, device_name); */ /* else */ /* return wg_get_device(dev, device_name); */ if (p->dev) { wg_free_device(p->dev); p->dev = NULL; } wg_device *dev = calloc(1, sizeof(wg_device)); strncpy(dev->name, device_name, sizeof(dev->name)); dev->flags = WGDEVICE_REPLACE_PEERS; if (c->private_key) { dev->flags |= WGDEVICE_HAS_PRIVATE_KEY | WGDEVICE_HAS_PUBLIC_KEY; wg_key_from_base64(dev->private_key, c->private_key); wg_generate_public_key(dev->public_key, dev->private_key); } if (c->listen_port) dev->flags |= WGDEVICE_HAS_LISTEN_PORT; dev->listen_port = c->listen_port; debug("listen port %d\n", c->listen_port); struct peer_config *pc = NULL; WALK_LIST(pc,c->peers) { wg_peer *peer = calloc(1, sizeof(wg_peer)); if (!dev->first_peer) dev->first_peer = peer; if (dev->last_peer) dev->last_peer->next_peer = peer; dev->last_peer = peer; peer->flags = WGPEER_REPLACE_ALLOWEDIPS; if (pc->public_key) { peer->flags = WGPEER_HAS_PUBLIC_KEY; wg_key_from_base64(peer->public_key, pc->public_key); } peer->next_peer = NULL; sockaddr_fill((sockaddr*)&peer->endpoint.addr, ipa_is_ip4(pc->endpoint) ? AF_INET : AF_INET6, pc->endpoint, NULL, pc->remote_port); wg_allowedip *allowedip = calloc(1, sizeof(wg_allowedip)); peer->first_allowedip = allowedip; peer->last_allowedip = allowedip; switch (pc->allowedip.type) { case NET_IP4: allowedip->family = AF_INET; allowedip->ip4 = ipa_to_in4(net_prefix(&pc->allowedip)); allowedip->cidr = net_pxlen(&pc->allowedip); break; case NET_IP6: allowedip->family = AF_INET6; allowedip->ip6 = ipa_to_in6(net_prefix(&pc->allowedip)); allowedip->cidr = net_pxlen(&pc->allowedip); break; default: break; } allowedip->next_allowedip = NULL; } *pdev = dev; return 0; } static int set_device(struct wg_proto *p) { if (has_userspace(p)) return user_set_device(p); else { log(L_TRACE "WG: wg_set_device"); return wg_set_device(p->dev); } } static void wg_init_entry(void *e_) { struct wg_entry *e UNUSED = e_; // debug("wg_init_entry\n"); } static void wg_postconfig(struct proto_config *C UNUSED) { debug("postconfig\n"); } static void wg_if_notify(struct proto *P, unsigned flags, struct iface *i) { struct wg_proto *p = (struct wg_proto *) P; struct wg_config *c = (struct wg_config *) P->cf; debug("WG: if_notify %p %s %d %s\n", i, i->name, flags, c->ifname); if (c->ifname && !strcmp(i->name, c->ifname)) { debug("WG: found ifname\n"); p->iface = i; } if (flags & IF_CHANGE_UP) { debug("WG: IF_CHANGE_UP %s\n", i->name); int res = set_device(p); log(L_TRACE "WG: wg_set_device %d", res); } } static void dump(void *ptr, size_t len) { unsigned char *data = ptr; for (size_t i=0; i= 0 && type <= 127) { sub_tlv_len = get_u8(p); p++; } else if (type >= 128 && type <= 255) { sub_tlv_len = get_u16(p); p += 2; } else { log(L_TRACE "WG: sub_tlv type error %d", type); return -1; } log(L_TRACE "WG: sub tlv len %d", sub_tlv_len); if (p + sub_tlv_len > last) { log(L_TRACE "WG: sub_tlv value len error %d", sub_tlv_len); return -1; } int res = 0; switch (type) { case BGP_TUNNEL_ENCAP_A_SUB_TLV_ENCAP: res = decode_wireguard(p, sub_tlv_len, pubkey, flags); break; case BGP_TUNNEL_ENCAP_A_SUB_TLV_TUNNEL_EP: res = decode_tunnel_ep(p, sub_tlv_len, tunnel_ep_as, tunnel_ep_addr, flags); break; case BGP_TUNNEL_ENCAP_A_SUB_TLV_COLOR: res = decode_color(p, sub_tlv_len, color, flags); break; case BGP_TUNNEL_ENCAP_A_SUB_TLV_UDP_DEST_PORT: res = decode_udp_dest_port(p, sub_tlv_len, udp_dest_port, flags); break; default: /* Skip unsupported sub-TLV. */ res = 0; break; } if (res < 0) return res; return p - first + sub_tlv_len; } static int decode_tunnel_encap(const eattr *e, u16 wg_tunnel_type, wg_key *pubkey, u32 *as4, ip_addr *tunnel_ep, u32 *color, u16 *udp_port, u16 *flags) { u8 *p = e->u.ptr->data; int len = e->u.ptr->length; if (len < 4) { log(L_TRACE "WG: tunnel_encap len error %d", len); return -1; } u16 tunnel_type = get_u16(p); log(L_DEBUG "WG: tunnel type %d", tunnel_type); if (tunnel_type != wg_tunnel_type) { log(L_TRACE "WG: tunnel type error %d", tunnel_type); return -1; } u16 value_length = get_u16(p + 2); log(L_TRACE "WG: tunnel encap value len %d", value_length); if (len < value_length + 4) { log(L_TRACE "WG: tunnel encap len error %d", value_length); return -1; } for (u8 *cur = p + 4; cur < p + 4 + value_length;) { int res = decode_sub_tlv(cur, value_length, pubkey, as4, tunnel_ep, color, udp_port, flags); if (res < 0) { log(L_TRACE "WG: decode error %d", res); return res; } cur += res; } return 0; } static wg_peer * add_peer(wg_device *dev, wg_key pubkey) { struct wg_peer *peer = malloc(sizeof(struct wg_peer)); memset(peer, 0, sizeof(struct wg_peer)); peer->flags = WGPEER_HAS_PUBLIC_KEY; memcpy(peer->public_key, pubkey, sizeof(wg_key)); if (dev->first_peer && dev->last_peer) dev->last_peer->next_peer = peer; else dev->first_peer = peer; dev->last_peer = peer; return peer; } static int set_peer_tunnel_ep(wg_peer *peer, ip_addr tunnel_ep_addr, u16 udp_dest_port) { if (udp_dest_port != 0 && ipa_nonzero(tunnel_ep_addr) ) { if (ipa_is_ip4(tunnel_ep_addr)) { log(L_TRACE "WG: found ip4 ep"); peer->endpoint.addr4.sin_family = AF_INET; put_ip4(&peer->endpoint.addr4.sin_addr.s_addr, ipa_to_ip4(tunnel_ep_addr)); put_u16(&peer->endpoint.addr4.sin_port, udp_dest_port); } else { log(L_TRACE "WG: found ip6 ep"); peer->endpoint.addr6.sin6_family = AF_INET6; put_ip6(&peer->endpoint.addr6.sin6_addr, ipa_to_ip6(tunnel_ep_addr)); put_u16(&peer->endpoint.addr6.sin6_port, udp_dest_port); } } return 0; } static int add_allowed_ips(u8 net_type, struct network *n, wg_peer *peer) { // Add allowed ip struct wg_allowedip *allowedip = malloc(sizeof(struct wg_allowedip)); memset(allowedip, 0, sizeof(struct wg_allowedip)); if (net_type == NET_IP4) { allowedip->family = AF_INET; allowedip->ip4.s_addr = ip4_to_u32(ip4_hton(net4_prefix(n->n.addr))); } else if (net_type == NET_IP6) { allowedip->family = AF_INET6; ip6_addr addr = ip6_hton(net6_prefix(n->n.addr)); memcpy(allowedip->ip6.s6_addr, &addr, 16); } allowedip->cidr = net_pxlen(n->n.addr); if (peer->first_allowedip && peer->last_allowedip) peer->last_allowedip->next_allowedip = allowedip; else peer->first_allowedip = allowedip; peer->last_allowedip = allowedip; return 0; } static void wg_rt_notify(struct proto *P, struct channel *CH, struct network *n, struct rte *new, struct rte *old UNUSED) { struct wg_proto *p = (struct wg_proto *) P; struct wg_config *c = (struct wg_config *) P->cf; struct wg_channel *ch = (struct wg_channel *) CH; struct wg_entry *en; struct iface *iface = NULL; const char *ifname = NULL; // debug("WG: notify\n"); if (new) { struct nexthop *nh = &new->attrs->nh; iface = nh->iface; ifname = iface ? iface->name : NULL; if (iface && iface == p->iface) { struct eattr *t; debug("WG: found %p iface %I %p\n", new->attrs, nh->gw, nh->next); struct hostentry *he = new->attrs->hostentry; debug("WG: he %p src %p\n", he, he?he->src:NULL); if (he && he->src) { struct eattr *t = ea_find(he->src->eattrs, EA_CODE(PROTOCOL_BGP, BA_TUNNEL_ENCAP)); debug("WG: he %p %I %I %p %p %I\n", t, he->addr, he->link, he->next, he->src->hostentry, he->src->nh.gw); } en = fib_get(&ch->rtable, n->n.addr); debug("WG: notify new %d %N\n", new->attrs->dest, n->n.addr); wg_key pubkey; memset(pubkey, 0, sizeof(wg_key)); u32 tunnel_ep_as4 = 0; ip_addr tunnel_ep_addr = IPA_NONE; u16 udp_dest_port = 0; u32 color = 0; u16 flags = 0; 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, &tunnel_ep_as4, &tunnel_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; if (dev != NULL) { bool dirty = false; bool found = false; struct wg_peer *peer = NULL; wg_for_each_peer(dev, peer) { // Look for public key size_t len = 32; // FIXME // MIN(32, t->u.ptr->length) if (memcmp(peer->public_key, pubkey, len) != 0) { log(L_TRACE "WG: Not found"); continue; } log(L_TRACE "WG: Found"); found = true; set_peer_tunnel_ep(peer, tunnel_ep_addr, udp_dest_port); add_allowed_ips(ch->c.net_type, n, peer); dirty = true; break; } if (!found) { wg_peer *peer = add_peer(dev, pubkey); set_peer_tunnel_ep(peer, tunnel_ep_addr, udp_dest_port); add_allowed_ips(ch->c.net_type, n, peer); dirty = true; } if (dirty) { int res = set_device(p); log(L_TRACE "WG: wg_set_device %d", res); } } /* struct sub_tlv_remove_endpoint { u32 asn; u8 address_family; union { ip4_addr ip4; ip6_addr ip6; }; }; struct sub_tlv_udp_dest_port { u16 port; }; struct sub_tlv_wireguard { u8 pubkey[32]; }; struct sub_tlv { u8 type; union { struct { u8 length; struct sub_tlv_value value[]; } s8; struct { u16 length; struct sub_tlv_value value[]; } s16; } u; }; struct bgp_tunnel_encap_attr { u16 type; u16 length; struct sub_tlv stlv[]; }; */ } else { log(L_TRACE "WG: No Attr"); } // old_metric = en->valid ? en->metric : -1; // en->valid = RIP_ENTRY_VALID; // en->metric = rt_metric; // en->tag = rt_tag; // en->from = (new->attrs->src->proto == P) ? new->u.rip.from : NULL; // en->iface = new->attrs->iface; // en->next_hop = new->attrs->gw; } } else { debug("WG: notify withdraw %N\n", n->n.addr); /* Withdraw */ en = fib_find(&ch->rtable, n->n.addr); if (!en) { // || en->valid != RIP_ENTRY_VALID) debug("WG: fib not found\n"); return; } struct wg_device *dev = p->dev; if (dev != NULL) { bool found = false; struct wg_peer *peer = NULL; wg_for_each_peer(dev, peer) { // Remove from all peers found = true; if (found) { // Add allowed ip struct wg_allowedip *allowedip = malloc(sizeof(struct wg_allowedip)); memset(allowedip, 0, sizeof(struct wg_allowedip)); if (ch->c.net_type == NET_IP4) { allowedip->family = AF_INET; allowedip->ip4.s_addr = ip4_to_u32(ip4_hton(net4_prefix(n->n.addr))); } else if (ch->c.net_type == NET_IP6) { allowedip->family = AF_INET6; ip6_addr addr = ip6_hton(net6_prefix(n->n.addr)); memcpy(allowedip->ip6.s6_addr, &addr, 16); } allowedip->cidr = net_pxlen(n->n.addr); struct wg_allowedip *ip = NULL; struct wg_allowedip *previp = NULL; wg_for_each_allowedip(peer, ip) { if (allowedip->family != ip->family) { debug("WG: family no match\n"); previp = ip; continue; } if (allowedip->cidr != ip->cidr) { debug("WG: cidr no match\n"); previp = ip; continue; } if (memcmp(&allowedip->ip6, &ip->ip6, sizeof(struct in6_addr))) { debug("WG: ip no match\n"); dump(&allowedip->ip6, sizeof(struct in6_addr)); dump(&ip->ip6, sizeof(struct in6_addr)); previp = ip; continue; } debug("WG: found ip\n"); if (!previp) { debug("WG: remove first\n"); peer->first_allowedip = ip->next_allowedip; if (peer->last_allowedip == ip) { peer->last_allowedip = NULL; peer->first_allowedip = NULL; } } else { debug("WG: remove middle\n"); // Remove if (peer->last_allowedip == ip) peer->last_allowedip = previp; previp->next_allowedip = ip->next_allowedip; } free(ip); break; } peer->flags |= WGPEER_REPLACE_ALLOWEDIPS; int res = set_device(p); log(L_TRACE "WG: wg_set_device %d", res); } } /* old_metric = en->metric; en->valid = RIP_ENTRY_STALE; en->metric = p->infinity; en->tag = 0; en->from = NULL; en->iface = NULL; en->next_hop = IPA_NONE; */ } } // TRACE(D_EVENTS, "wg notify %s %s", src_table->name, ifname?ifname:"(null)"); } static void wg_reload_routes(struct channel *C) { struct wg_proto *p UNUSED = (struct wg_proto *) C->proto; debug("reload routes\n"); // TODO // WALK_LIST(c, p->channels) // channel_request_feeding(c); } static struct proto * wg_init(struct proto_config *C) { struct wg_config *c UNUSED = (struct wg_config *) C; struct proto *P = proto_new(C); struct wg_proto *p UNUSED = (struct wg_proto *) P; debug("init\n"); P->if_notify = wg_if_notify; P->rt_notify = wg_rt_notify; P->reload_routes = wg_reload_routes; // P->accept_ra_types = RA_ANY; /* Add all channels */ struct wg_channel_config *cc; WALK_LIST(cc, C->channels) proto_add_channel(P, &cc->c); return P; } static int wg_start(struct proto *P) { struct wg_config *cf UNUSED = (struct wg_config *) P->cf; struct wg_proto *p = (struct wg_proto *) P; log(L_TRACE "WG: start"); if (get_device(p, &p->dev, cf->ifname) >= 0) { int res = set_device(p); log(L_TRACE "WG: wg_set_device %d", res); } struct wg_channel *ch; WALK_LIST(ch,p->p.channels) { fib_init(&ch->rtable, P->pool, ch->c.net_type, sizeof(struct wg_entry), OFFSETOF(struct wg_entry, n), 0, wg_init_entry); } return PS_UP; } static int wg_shutdown(struct proto *P) { struct wg_config *cf = (struct wg_config*)P->cf; struct wg_proto *p = (struct wg_proto*)P; wg_device *dev = NULL; log(L_TRACE "WG: wg_shutdown"); if (get_device(p, &p->dev, cf->ifname) >= 0) { int res = set_device(p); log(L_TRACE "WG: flush wg_set_device %d", res); } return PS_DOWN; } static void wg_dump(struct proto *P) { struct wg_proto *p = (struct wg_proto *) P; int i; i = 0; struct wg_channel *ch; WALK_LIST(ch,p->p.channels) { FIB_WALK(&ch->rtable, struct wg_entry, en) { // struct wg_entry *en = (struct wg_entry *) e; debug("WG: entry #%d:\n", i++); } FIB_WALK_END; } } static void wg_copy_config(struct proto_config *DEST, struct proto_config *SRC) { struct wg_config *dest = (struct wg_config *)DEST; struct wg_config *src = (struct wg_config *)SRC; dest->ifname = src->ifname; dest->socket_path = src->socket_path; dest->private_key = src->private_key; dest->listen_port = src->listen_port; struct peer_config *spc = NULL; WALK_LIST(spc,src->peers) { struct peer_config *dpc = cfg_allocz(sizeof(struct peer_config)); dpc->public_key = spc->public_key; dpc->listen_port = spc->listen_port; dpc->endpoint = spc->endpoint; dpc->remote_port = spc->remote_port; dpc->allowedip = spc->allowedip; add_tail(&dest->peers, (node*)spc); } } struct peer_config *peer_new(struct wg_config *c) { struct peer_config *pc = cfg_allocz(sizeof(struct peer_config)); debug("peer_new %p\n", pc); add_tail(&c->peers, (node*)pc); return pc; } static void wg_channel_init(struct channel *CH, struct channel_config *CHC) { struct wg_channel *ch = (struct wg_channel*)CH; struct proto *P = CH->proto; /* Create new instance */ log(L_TRACE "WG: wg_channel_init"); } static int wg_channel_reconfigure(struct channel *CH, struct channel_config *CHC) { /* Try to reconfigure instance, returns success */ log(L_TRACE "WG: wg_channel_reconfigure"); return 1; } static int wg_channel_start(struct channel *CH) { struct wg_channel *ch = (struct wg_channel*)CH; struct proto *P = CH->proto; /* Start the instance */ log(L_TRACE "WG: wg_channel_start"); #if 0 fib_init(&ch->rtable, P->pool, ch->c.net_type, sizeof(struct wg_entry), OFFSETOF(struct wg_entry, n), 0, wg_init_entry); #endif return 1; } static void wg_channel_shutdown(struct channel *CH) { struct wg_channel *ch = (struct wg_channel*)CH; /* Stop the instance */ log(L_TRACE "WG: wg_channel_shutdown"); } static void wg_channel_cleanup(struct channel *CH) { struct wg_channel *ch = (struct wg_channel*)CH; /* Channel finished flush */ log(L_TRACE "WG: wg_channel_cleanup"); } struct channel_class channel_wg = { .channel_size = sizeof(struct wg_channel), .config_size = sizeof(struct wg_channel_config), .init = wg_channel_init, .start = wg_channel_start, .shutdown = wg_channel_shutdown, .cleanup = wg_channel_cleanup, .reconfigure = wg_channel_reconfigure, }; struct protocol proto_wireguard = { .name = "Wireguard", .template = "wg%d", .class = PROTOCOL_WG, .channel_mask = NB_IP, .proto_size = sizeof(struct wg_proto), .config_size = sizeof(struct wg_config), .postconfig = wg_postconfig, .init = wg_init, .start = wg_start, .shutdown = wg_shutdown, .dump = wg_dump, .copy_config = wg_copy_config, /* .multitable = 1, .preference = DEF_PREF_PIPE, .cleanup = wg_cleanup, .reconfigure = wg_reconfigure, .copy_config = wg_copy_config, .get_status = wg_get_status, .show_proto_info = wg_show_proto_info*/ };