summaryrefslogtreecommitdiffstats
path: root/nhrpd/nhrp_event.c
diff options
context:
space:
mode:
Diffstat (limited to 'nhrpd/nhrp_event.c')
-rw-r--r--nhrpd/nhrp_event.c95
1 files changed, 50 insertions, 45 deletions
diff --git a/nhrpd/nhrp_event.c b/nhrpd/nhrp_event.c
index 4ee58a43e..e7adc971e 100644
--- a/nhrpd/nhrp_event.c
+++ b/nhrpd/nhrp_event.c
@@ -24,7 +24,7 @@ struct event_manager {
struct zbuf ibuf;
struct zbuf_queue obuf;
int fd;
- uint8_t ibuf_data[4*1024];
+ uint8_t ibuf_data[4 * 1024];
};
static int evmgr_reconnect(struct thread *t);
@@ -53,7 +53,7 @@ static void evmgr_recv_message(struct event_manager *evmgr, struct zbuf *zb)
while (zbuf_may_pull_until(zb, "\n", &zl)) {
len = zbuf_used(&zl) - 1;
- if (len >= sizeof(buf)-1)
+ if (len >= sizeof(buf) - 1)
continue;
memcpy(buf, zbuf_pulln(&zl, len), len);
buf[len] = 0;
@@ -64,10 +64,13 @@ static void evmgr_recv_message(struct event_manager *evmgr, struct zbuf *zb)
if (sscanf(buf, "result=%63s", result) != 1)
continue;
}
- debugf(NHRP_DEBUG_EVENT, "evmgr: received: eventid=%d result=%s", eventid, result);
+ debugf(NHRP_DEBUG_EVENT, "evmgr: received: eventid=%d result=%s",
+ eventid, result);
if (eventid && result[0]) {
- struct nhrp_reqid *r = nhrp_reqid_lookup(&nhrp_event_reqid, eventid);
- if (r) r->cb(r, result);
+ struct nhrp_reqid *r =
+ nhrp_reqid_lookup(&nhrp_event_reqid, eventid);
+ if (r)
+ r->cb(r, result);
}
}
@@ -78,7 +81,7 @@ static int evmgr_read(struct thread *t)
struct zbuf msg;
evmgr->t_read = NULL;
- if (zbuf_read(ibuf, evmgr->fd, (size_t) -1) < 0) {
+ if (zbuf_read(ibuf, evmgr->fd, (size_t)-1) < 0) {
evmgr_connection_error(evmgr);
return 0;
}
@@ -114,8 +117,9 @@ static void evmgr_hexdump(struct zbuf *zb, const uint8_t *val, size_t vallen)
size_t i;
char *ptr;
- ptr = zbuf_pushn(zb, 2*vallen);
- if (!ptr) return;
+ ptr = zbuf_pushn(zb, 2 * vallen);
+ if (!ptr)
+ return;
for (i = 0; i < vallen; i++) {
uint8_t b = val[i];
@@ -134,13 +138,15 @@ static void evmgr_put(struct zbuf *zb, const char *fmt, ...)
va_start(va, fmt);
for (pos = fmt; (nxt = strchr(pos, '%')) != NULL; pos = nxt + 2) {
- zbuf_put(zb, pos, nxt-pos);
+ zbuf_put(zb, pos, nxt - pos);
switch (nxt[1]) {
case '%':
zbuf_put8(zb, '%');
break;
case 'u':
- zb->tail += snprintf((char *) zb->tail, zbuf_tailroom(zb), "%u", va_arg(va, uint32_t));
+ zb->tail +=
+ snprintf((char *)zb->tail, zbuf_tailroom(zb),
+ "%u", va_arg(va, uint32_t));
break;
case 's':
str = va_arg(va, const char *);
@@ -148,8 +154,9 @@ static void evmgr_put(struct zbuf *zb, const char *fmt, ...)
break;
case 'U':
su = va_arg(va, const union sockunion *);
- if (sockunion2str(su, (char *) zb->tail, zbuf_tailroom(zb)))
- zb->tail += strlen((char *) zb->tail);
+ if (sockunion2str(su, (char *)zb->tail,
+ zbuf_tailroom(zb)))
+ zb->tail += strlen((char *)zb->tail);
else
zbuf_set_werror(zb);
break;
@@ -183,12 +190,13 @@ static int evmgr_reconnect(struct thread *t)
int fd;
evmgr->t_reconnect = NULL;
- if (evmgr->fd >= 0 || !nhrp_event_socket_path) return 0;
+ if (evmgr->fd >= 0 || !nhrp_event_socket_path)
+ return 0;
fd = sock_open_unix(nhrp_event_socket_path);
if (fd < 0) {
zlog_warn("%s: failure connecting nhrp-event socket: %s",
- __PRETTY_FUNCTION__, strerror(errno));
+ __PRETTY_FUNCTION__, strerror(errno));
zbufq_reset(&evmgr->obuf);
thread_add_timer(master, evmgr_reconnect, evmgr, 10,
&evmgr->t_reconnect);
@@ -218,7 +226,7 @@ void evmgr_init(void)
void evmgr_set_socket(const char *socket)
{
if (nhrp_event_socket_path) {
- free((char *) nhrp_event_socket_path);
+ free((char *)nhrp_event_socket_path);
nhrp_event_socket_path = NULL;
}
if (socket)
@@ -230,7 +238,8 @@ void evmgr_terminate(void)
{
}
-void evmgr_notify(const char *name, struct nhrp_cache *c, void (*cb)(struct nhrp_reqid *, void *))
+void evmgr_notify(const char *name, struct nhrp_cache *c,
+ void (*cb)(struct nhrp_reqid *, void *))
{
struct event_manager *evmgr = &evmgr_connection;
struct nhrp_vc *vc;
@@ -239,51 +248,47 @@ void evmgr_notify(const char *name, struct nhrp_cache *c, void (*cb)(struct nhrp
afi_t afi = family2afi(sockunion_family(&c->remote_addr));
if (!nhrp_event_socket_path) {
- cb(&c->eventid, (void*) "accept");
+ cb(&c->eventid, (void *)"accept");
return;
}
debugf(NHRP_DEBUG_EVENT, "evmgr: sending event %s", name);
vc = c->new.peer ? c->new.peer->vc : NULL;
- zb = zbuf_alloc(1024 + (vc ? (vc->local.certlen + vc->remote.certlen) * 2 : 0));
+ zb = zbuf_alloc(
+ 1024 + (vc ? (vc->local.certlen + vc->remote.certlen) * 2 : 0));
if (cb) {
nhrp_reqid_free(&nhrp_event_reqid, &c->eventid);
- evmgr_put(zb,
- "eventid=%u\n",
- nhrp_reqid_alloc(&nhrp_event_reqid, &c->eventid, cb));
+ evmgr_put(zb, "eventid=%u\n",
+ nhrp_reqid_alloc(&nhrp_event_reqid, &c->eventid, cb));
}
evmgr_put(zb,
- "event=%s\n"
- "type=%s\n"
- "old_type=%s\n"
- "num_nhs=%u\n"
- "interface=%s\n"
- "local_addr=%U\n",
- name,
- nhrp_cache_type_str[c->new.type],
- nhrp_cache_type_str[c->cur.type],
- (unsigned int) nhrp_cache_counts[NHRP_CACHE_NHS],
- c->ifp->name,
- &nifp->afi[afi].addr);
+ "event=%s\n"
+ "type=%s\n"
+ "old_type=%s\n"
+ "num_nhs=%u\n"
+ "interface=%s\n"
+ "local_addr=%U\n",
+ name, nhrp_cache_type_str[c->new.type],
+ nhrp_cache_type_str[c->cur.type],
+ (unsigned int)nhrp_cache_counts[NHRP_CACHE_NHS], c->ifp->name,
+ &nifp->afi[afi].addr);
if (vc) {
evmgr_put(zb,
- "vc_initiated=%s\n"
- "local_nbma=%U\n"
- "local_cert=%H\n"
- "remote_addr=%U\n"
- "remote_nbma=%U\n"
- "remote_cert=%H\n",
- c->new.peer->requested ? "yes" : "no",
- &vc->local.nbma,
- vc->local.cert, vc->local.certlen,
- &c->remote_addr, &vc->remote.nbma,
- vc->remote.cert, vc->remote.certlen);
+ "vc_initiated=%s\n"
+ "local_nbma=%U\n"
+ "local_cert=%H\n"
+ "remote_addr=%U\n"
+ "remote_nbma=%U\n"
+ "remote_cert=%H\n",
+ c->new.peer->requested ? "yes" : "no",
+ &vc->local.nbma, vc->local.cert, vc->local.certlen,
+ &c->remote_addr, &vc->remote.nbma, vc->remote.cert,
+ vc->remote.certlen);
}
evmgr_submit(evmgr, zb);
}
-