summaryrefslogtreecommitdiff
path: root/proto/wireguard
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2020-01-02 10:32:42 +0100
committerMikael Magnusson <mikma@users.sourceforge.net>2020-05-08 18:52:55 +0200
commit96167d9372ff7fc94a4f235a720f935ef6c00ee1 (patch)
tree858f4e7c530a24dc31a81df22ef3a9da91d480e3 /proto/wireguard
parent0d756ffc1b9e452267383e9486ab42a74cc2dc06 (diff)
Wireguard: Replace log with WG_TRACE
Diffstat (limited to 'proto/wireguard')
-rw-r--r--proto/wireguard/wireguard.c71
-rw-r--r--proto/wireguard/wireguard.h8
2 files changed, 50 insertions, 29 deletions
diff --git a/proto/wireguard/wireguard.c b/proto/wireguard/wireguard.c
index 6db9c9ea..feea9682 100644
--- a/proto/wireguard/wireguard.c
+++ b/proto/wireguard/wireguard.c
@@ -108,7 +108,7 @@ set_device(struct wg_proto *p)
return wg_user_set_device(p->p.pool, c->ifname, p->dev);
else
{
- log(L_TRACE "WG: wg_set_device");
+ WG_TRACE(D_EVENTS, "WG: wg_set_device");
return wg_set_device(p->dev);
}
}
@@ -145,7 +145,7 @@ wg_if_notify(struct proto *P, unsigned flags, struct iface *i)
DBG("WG: IF_CHANGE_UP %s\n", i->name);
int res = set_device(p);
- log(L_TRACE "WG: wg_set_device %d", res);
+ WG_TRACE(D_EVENTS, "WG: wg_set_device %d", res);
}
}
@@ -193,12 +193,13 @@ add_peer(wg_device *dev, const wg_key pubkey)
}
static void
-remove_marked_peer(wg_device *dev)
+remove_marked_peer(struct wg_proto *p)
{
+ wg_device *dev = p->dev;
struct wg_peer *peer = NULL;
struct wg_peer *prevpeer = NULL;
- log(L_TRACE "WG: remove_marked_peer");
+ WG_TRACE(D_EVENTS, "WG: remove_marked_peer");
wg_for_each_peer(dev, peer) {
if (peer->flags & WGPEER_REMOVE_ME) {
if (!prevpeer) {
@@ -227,16 +228,16 @@ remove_marked_peer(wg_device *dev)
}
static int
-set_peer_tunnel_ep(wg_peer *peer, ip_addr tunnel_ep_addr, u16 udp_dest_port)
+set_peer_tunnel_ep(struct wg_proto *p, 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");
+ WG_TRACE(D_EVENTS, "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");
+ WG_TRACE(D_EVENTS, "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);
@@ -314,8 +315,10 @@ remove_allowed_ip(wg_peer *peer, struct wg_allowedip *allowedip)
if (memcmp(&allowedip->ip6, &ip->ip6, sizeof(struct in6_addr))) {
DBG("WG: ip no match\n");
+#if defined(LOCAL_DEBUG) || defined(GLOBAL_DEBUG)
dump(&allowedip->ip6, sizeof(struct in6_addr));
dump(&ip->ip6, sizeof(struct in6_addr));
+#endif
previp = ip;
continue;
}
@@ -385,7 +388,7 @@ wg_rt_notify(struct proto *P, struct channel *CH, struct network *n,
t = ea_find(new->attrs->eattrs, EA_CODE(PROTOCOL_BGP, BA_TUNNEL_ENCAP));
if (t) {
- log(L_TRACE "WG: Set is tunnel");
+ WG_TRACE(D_EVENTS, "WG: Set is tunnel");
is_tunnel_ep = true;
}
if (!t && he && he->src) {
@@ -406,7 +409,7 @@ wg_rt_notify(struct proto *P, struct channel *CH, struct network *n,
memcpy(en->public_key, pubkey, sizeof(wg_key));
}
- log(L_TRACE "WG: Attr %x %x %d %04x", t->flags, t->type, t->u.ptr->length, encap.flags);
+ WG_TRACE(D_EVENTS, "WG: Attr %x %x %d %04x", t->flags, t->type, t->u.ptr->length, encap.flags);
struct wg_device *dev = p->dev;
@@ -419,11 +422,11 @@ wg_rt_notify(struct proto *P, struct channel *CH, struct network *n,
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");
+ WG_TRACE(D_EVENTS, "WG: Not found");
continue;
}
- log(L_TRACE "WG: Found");
+ WG_TRACE(D_EVENTS, "WG: Found");
found = true;
dirty = true;
break;
@@ -435,14 +438,14 @@ wg_rt_notify(struct proto *P, struct channel *CH, struct network *n,
dump_peer(peer);
if (is_tunnel_ep)
- set_peer_tunnel_ep(peer, encap.ep.ip, encap.udp_dest_port);
+ set_peer_tunnel_ep(p, peer, encap.ep.ip, encap.udp_dest_port);
if (add_ip)
add_allowed_ip(ch->c.net_type, n, peer);
dirty = true;
if (dirty) {
int res = set_device(p);
- log(L_TRACE "WG: wg_set_device %d", res);
+ WG_TRACE(D_EVENTS, "WG: wg_set_device %d", res);
}
}
@@ -486,7 +489,7 @@ wg_rt_notify(struct proto *P, struct channel *CH, struct network *n,
};
*/
} else {
- log(L_TRACE "WG: No Attr");
+ WG_TRACE(D_EVENTS, "WG: No Attr");
}
mb_free(encap.encap);
@@ -522,7 +525,7 @@ wg_rt_notify(struct proto *P, struct channel *CH, struct network *n,
struct wg_peer *peer = NULL;
wg_for_each_peer(dev, peer) {
if (en->is_tunnel_ep && !marked_peer) {
- log(L_TRACE "WG: Is tunnel");
+ WG_TRACE(D_EVENTS, "WG: Is tunnel");
if (memcmp(peer->public_key, en->public_key, sizeof(wg_key)) == 0) {
struct peer_config *pc = NULL;
bool remove_me = true;
@@ -540,7 +543,7 @@ wg_rt_notify(struct proto *P, struct channel *CH, struct network *n,
}
if (remove_me) {
- log(L_TRACE "WG: Remove peer");
+ WG_TRACE(D_EVENTS, "WG: Remove peer");
peer->flags |= WGPEER_REMOVE_ME;
marked_peer = true;
continue;
@@ -556,7 +559,7 @@ wg_rt_notify(struct proto *P, struct channel *CH, struct network *n,
dump_peer(peer);
if (remove_allowed_ip(peer, allowedip)) {
ip_addr ip = allowedip_to_ipa(allowedip);
- log(L_TRACE "WG: removed %I/%d", ip, allowedip->cidr);
+ WG_TRACE(D_EVENTS, "WG: removed %I/%d", ip, allowedip->cidr);
peer->flags |= WGPEER_REPLACE_ALLOWEDIPS;
dump_peer(peer);
@@ -565,10 +568,10 @@ wg_rt_notify(struct proto *P, struct channel *CH, struct network *n,
}
if (marked_peer) {
- remove_marked_peer(p->dev);
+ remove_marked_peer(p);
}
int res = set_device(p);
- log(L_TRACE "WG: wg_set_device %d", res);
+ WG_TRACE(D_EVENTS, "WG: wg_set_device %d", res);
fib_delete(&ch->rtable, en);
en = NULL;
@@ -630,12 +633,12 @@ 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");
+ WG_TRACE(D_EVENTS, "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);
+ WG_TRACE(D_EVENTS, "WG: wg_set_device %d", res);
}
struct wg_channel *ch;
@@ -653,11 +656,11 @@ wg_shutdown(struct proto *P)
struct wg_proto *p = (struct wg_proto*)P;
wg_device *dev = NULL;
- log(L_TRACE "WG: wg_shutdown");
+ WG_TRACE(D_EVENTS, "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);
+ WG_TRACE(D_EVENTS, "WG: flush wg_set_device %d", res);
}
return PS_DOWN;
@@ -684,7 +687,7 @@ wg_dump(struct proto *P)
struct wg_peer *peer = NULL;
- log(L_TRACE "WG: dump peers");
+ WG_TRACE(D_EVENTS, "WG: dump peers");
wg_for_each_peer(p->dev, peer) {
dump_peer(peer);
}
@@ -728,17 +731,22 @@ wg_channel_init(struct channel *CH, struct channel_config *CHC)
{
struct wg_channel *ch = (struct wg_channel*)CH;
struct proto *P = CH->proto;
+ struct wg_proto *p = (struct wg_proto *) P;
/* Create new instance */
- log(L_TRACE "WG: wg_channel_init");
+ WG_TRACE(D_EVENTS, "WG: wg_channel_init");
}
static int
wg_channel_reconfigure(struct channel *CH, struct channel_config *CHC,
int *import_changed, int *export_changed)
{
+ struct wg_channel *ch = (struct wg_channel*)CH;
+ struct proto *P = CH->proto;
+ struct wg_proto *p = (struct wg_proto *) P;
+
/* Try to reconfigure instance, returns success */
- log(L_TRACE "WG: wg_channel_reconfigure");
+ WG_TRACE(D_EVENTS, "WG: wg_channel_reconfigure");
return 1;
}
@@ -747,9 +755,10 @@ wg_channel_start(struct channel *CH)
{
struct wg_channel *ch = (struct wg_channel*)CH;
struct proto *P = CH->proto;
+ struct wg_proto *p = (struct wg_proto *) P;
/* Start the instance */
- log(L_TRACE "WG: wg_channel_start");
+ WG_TRACE(D_EVENTS, "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);
@@ -761,18 +770,22 @@ static void
wg_channel_shutdown(struct channel *CH)
{
struct wg_channel *ch = (struct wg_channel*)CH;
+ struct proto *P = CH->proto;
+ struct wg_proto *p = (struct wg_proto *) P;
/* Stop the instance */
- log(L_TRACE "WG: wg_channel_shutdown");
+ WG_TRACE(D_EVENTS, "WG: wg_channel_shutdown");
}
static void
wg_channel_cleanup(struct channel *CH)
{
struct wg_channel *ch = (struct wg_channel*)CH;
+ struct proto *P = CH->proto;
+ struct wg_proto *p = (struct wg_proto *) P;
/* Channel finished flush */
- log(L_TRACE "WG: wg_channel_cleanup");
+ WG_TRACE(D_EVENTS, "WG: wg_channel_cleanup");
}
diff --git a/proto/wireguard/wireguard.h b/proto/wireguard/wireguard.h
index e1cce73f..30073869 100644
--- a/proto/wireguard/wireguard.h
+++ b/proto/wireguard/wireguard.h
@@ -4,6 +4,14 @@
#include "nest/protocol.h"
#include "sysdep/linux/wireguard.h"
+#ifdef LOCAL_DEBUG
+#define WG_FORCE_DEBUG 1
+#else
+#define WG_FORCE_DEBUG 0
+#endif
+#define WG_TRACE(flags, msg, args...) do { if ((p->p.debug & flags) || WG_FORCE_DEBUG) \
+ log(L_TRACE "%s: " msg, p->p.name , ## args ); } while(0)
+
struct peer_config {
node n;
const char *public_key;