-/* $OpenBSD: session.c,v 1.366 2018/09/04 12:00:29 claudio Exp $ */
+/* $OpenBSD: session.c,v 1.367 2018/09/19 13:09:30 claudio Exp $ */
/*
* Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org>
void session_dispatch_imsg(struct imsgbuf *, int, u_int *);
void session_up(struct peer *);
void session_down(struct peer *);
+int imsg_rde(int, u_int32_t, void *, u_int16_t);
void session_demote(struct peer *, int);
int session_link_state_is_up(int, int, int);
ibuf_close(&p->wbuf, msg->buf);
if (!p->throttled && p->wbuf.queued > SESS_MSG_HIGH_MARK) {
- if (imsg_compose(ibuf_rde, IMSG_XOFF, p->conf.id, 0, -1,
- NULL, 0) == -1)
+ if (imsg_rde(IMSG_XOFF, p->conf.id, NULL, 0) == -1)
log_peer_warn(&p->conf, "imsg_compose XOFF");
p->throttled = 1;
}
for (i = 0; i < AID_MAX; i++) {
if (p->capa.neg.grestart.flags[i] & CAPA_GR_PRESENT) {
- if (imsg_compose(ibuf_rde, IMSG_SESSION_STALE,
- p->conf.id, 0, -1, &i, sizeof(i)) == -1)
+ if (imsg_rde(IMSG_SESSION_STALE, p->conf.id,
+ &i, sizeof(i)) == -1)
return (-1);
log_peer_warnx(&p->conf,
"graceful restart of %s, keeping routes",
aid2str(i));
p->capa.neg.grestart.flags[i] |= CAPA_GR_RESTARTING;
} else if (p->capa.neg.mp[i]) {
- if (imsg_compose(ibuf_rde, IMSG_SESSION_FLUSH,
- p->conf.id, 0, -1, &i, sizeof(i)) == -1)
+ if (imsg_rde(IMSG_SESSION_FLUSH, p->conf.id,
+ &i, sizeof(i)) == -1)
return (-1);
log_peer_warnx(&p->conf,
"graceful restart of %s, flushing routes",
if (p->capa.neg.grestart.flags[i] & CAPA_GR_RESTARTING) {
log_peer_warnx(&p->conf, "graceful restart of %s, "
"time-out, flushing", aid2str(i));
- if (imsg_compose(ibuf_rde, IMSG_SESSION_FLUSH,
- p->conf.id, 0, -1, &i, sizeof(i)) == -1)
+ if (imsg_rde(IMSG_SESSION_FLUSH, p->conf.id,
+ &i, sizeof(i)) == -1)
return (-1);
}
p->capa.neg.grestart.flags[i] &= ~CAPA_GR_RESTARTING;
return (1);
}
if (p->throttled && p->wbuf.queued < SESS_MSG_LOW_MARK) {
- if (imsg_compose(ibuf_rde, IMSG_XON, p->conf.id, 0, -1,
- NULL, 0) == -1)
+ if (imsg_rde(IMSG_XON, p->conf.id, NULL, 0) == -1)
log_peer_warn(&p->conf, "imsg_compose XON");
p->throttled = 0;
}
p += MSGSIZE_HEADER; /* header is already checked */
datalen -= MSGSIZE_HEADER;
- if (imsg_compose(ibuf_rde, IMSG_UPDATE, peer->conf.id, 0, -1, p,
- datalen) == -1)
+ if (imsg_rde(IMSG_UPDATE, peer->conf.id, p, datalen) == -1)
return (-1);
return (0);
return (0);
}
- if (imsg_compose(ibuf_rde, IMSG_REFRESH, peer->conf.id, 0, -1, &aid,
- sizeof(aid)) == -1)
+ if (imsg_rde(IMSG_REFRESH, peer->conf.id, &aid, sizeof(aid)) == -1)
return (-1);
return (0);
if (negflags & CAPA_GR_RESTARTING) {
if (!(p->capa.peer.grestart.flags[i] &
CAPA_GR_FORWARD)) {
- if (imsg_compose(ibuf_rde, IMSG_SESSION_FLUSH,
- p->conf.id, 0, -1, &i, sizeof(i)) == -1)
+ if (imsg_rde(IMSG_SESSION_FLUSH, p->conf.id,
+ &i, sizeof(i)) == -1)
return (-1);
log_peer_warnx(&p->conf, "graceful restart of "
"%s, not restarted, flushing", aid2str(i));
/* sync the RDE in case we keep the peer */
if (reconf == RECONF_KEEP) {
- if (imsg_compose(ibuf_rde, IMSG_SESSION_ADD,
- p->conf.id, 0, -1, &p->conf,
- sizeof(struct peer_config)) == -1)
+ if (imsg_rde(IMSG_SESSION_ADD, p->conf.id,
+ &p->conf, sizeof(struct peer_config)) == -1)
fatalx("imsg_compose error");
if (p->conf.template) {
/* apply the conf to all clones */
session_template_clone(np,
NULL, np->conf.id,
np->conf.remote_as);
- if (imsg_compose(ibuf_rde,
- IMSG_SESSION_ADD,
- np->conf.id, 0, -1,
- &np->conf,
+ if (imsg_rde(IMSG_SESSION_ADD,
+ np->conf.id, &np->conf,
sizeof(struct peer_config))
== -1)
fatalx("imsg_compose error");
timer_stop(p, Timer_RestartTimeout);
/* signal back to RDE to cleanup stale routes */
- if (imsg_compose(ibuf_rde,
- IMSG_SESSION_RESTARTED, imsg.hdr.peerid, 0,
- -1, &aid, sizeof(aid)) == -1)
+ if (imsg_rde(IMSG_SESSION_RESTARTED,
+ imsg.hdr.peerid, &aid, sizeof(aid)) == -1)
fatal("imsg_compose: "
"IMSG_SESSION_RESTARTED");
}
{
bzero(&peer->capa.neg, sizeof(peer->capa.neg));
peer->stats.last_updown = time(NULL);
- if (imsg_compose(ibuf_rde, IMSG_SESSION_DOWN, peer->conf.id, 0, -1,
- NULL, 0) == -1)
+ /*
+ * session_down is called in the exit code path so check
+ * if the RDE is still around, if not there is no need to
+ * send the message.
+ */
+ if (ibuf_rde == NULL)
+ return;
+ if (imsg_rde(IMSG_SESSION_DOWN, peer->conf.id, NULL, 0) == -1)
fatalx("imsg_compose error");
}
{
struct session_up sup;
- if (imsg_compose(ibuf_rde, IMSG_SESSION_ADD, p->conf.id, 0, -1,
+ if (imsg_rde(IMSG_SESSION_ADD, p->conf.id,
&p->conf, sizeof(p->conf)) == -1)
fatalx("imsg_compose error");
sup.short_as = p->short_as;
memcpy(&sup.capa, &p->capa.neg, sizeof(sup.capa));
p->stats.last_updown = time(NULL);
- if (imsg_compose(ibuf_rde, IMSG_SESSION_UP, p->conf.id, 0, -1,
- &sup, sizeof(sup)) == -1)
+ if (imsg_rde(IMSG_SESSION_UP, p->conf.id, &sup, sizeof(sup)) == -1)
fatalx("imsg_compose error");
}
int
imsg_ctl_rde(int type, pid_t pid, void *data, u_int16_t datalen)
{
+ if (ibuf_rde_ctl == NULL) {
+ log_warnx("Can't send message %u to RDE, ctl pipe closed",
+ type);
+ return (0);
+ }
/*
* Use control socket to talk to RDE to bypass the queue of the
* regular imsg socket.
return (imsg_compose(ibuf_rde_ctl, type, 0, pid, -1, data, datalen));
}
+int
+imsg_rde(int type, uint32_t peerid, void *data, u_int16_t datalen)
+{
+ if (ibuf_rde == NULL) {
+ log_warnx("Can't send message %u to RDE, pipe closed", type);
+ return (0);
+ }
+
+ return (imsg_compose(ibuf_rde, type, peerid, 0, -1, data, datalen));
+}
+
void
session_demote(struct peer *p, int level)
{