diff options
author | deraadt <deraadt@openbsd.org> | 2020-05-10 13:38:46 +0000 |
---|---|---|
committer | deraadt <deraadt@openbsd.org> | 2020-05-10 13:38:46 +0000 |
commit | a78f83ce721c25bb7a3c00a20e2c8bec5a6f6e48 (patch) | |
tree | 6c0d79bf26707e5efa4042897f1b0f191b33bd3b /usr.sbin/bgpd | |
parent | Allow to have multiple domain ... {} sextions with the same domain (diff) | |
download | wireguard-openbsd-a78f83ce721c25bb7a3c00a20e2c8bec5a6f6e48.tar.xz wireguard-openbsd-a78f83ce721c25bb7a3c00a20e2c8bec5a6f6e48.zip |
In bgpctl argument parser, re-arrange 'reason' parsing ('nei action [reason]')
to be more generic, then change 'reload' to take take a '[reason]' also,
which will be logged by bgpd.
ok kn claudio
Diffstat (limited to 'usr.sbin/bgpd')
-rw-r--r-- | usr.sbin/bgpd/bgpd.c | 6 | ||||
-rw-r--r-- | usr.sbin/bgpd/bgpd.h | 10 | ||||
-rw-r--r-- | usr.sbin/bgpd/control.c | 16 | ||||
-rw-r--r-- | usr.sbin/bgpd/parse.y | 8 | ||||
-rw-r--r-- | usr.sbin/bgpd/session.c | 40 | ||||
-rw-r--r-- | usr.sbin/bgpd/session.h | 4 | ||||
-rw-r--r-- | usr.sbin/bgpd/util.c | 6 |
7 files changed, 47 insertions, 43 deletions
diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c index e8836230326..ef2142f4fa0 100644 --- a/usr.sbin/bgpd/bgpd.c +++ b/usr.sbin/bgpd/bgpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.c,v 1.227 2019/10/02 08:58:34 claudio Exp $ */ +/* $OpenBSD: bgpd.c,v 1.228 2020/05/10 13:38:46 deraadt Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -829,6 +829,10 @@ dispatch_imsg(struct imsgbuf *ibuf, int idx, struct bgpd_config *conf) else { reconfig = 1; reconfpid = imsg.hdr.pid; + if (imsg.hdr.len == IMSG_HEADER_SIZE + REASON_LEN && + ((char *)imsg.data)[0]) + log_info("reload due to: %.*s", + REASON_LEN, log_reason(imsg.data)); } break; case IMSG_CTL_FIB_COUPLE: diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index 3876b9e125c..7d081693cef 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.402 2020/04/23 16:13:11 claudio Exp $ */ +/* $OpenBSD: bgpd.h,v 1.403 2020/05/10 13:38:46 deraadt Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -38,7 +38,7 @@ #define CONFFILE "/etc/bgpd.conf" #define BGPD_USER "_bgpd" #define PEER_DESCR_LEN 32 -#define SHUT_COMM_LEN 256 /* includes NUL terminator */ +#define REASON_LEN 256 /* includes NUL terminator */ #define PFTABLE_LEN 32 #define TCP_MD5_KEY_LEN 80 #define IPSEC_ENC_KEY_LEN 32 @@ -371,7 +371,7 @@ struct peer_config { struct capabilities capabilities; char group[PEER_DESCR_LEN]; char descr[PEER_DESCR_LEN]; - char shutcomm[SHUT_COMM_LEN]; + char reason[REASON_LEN]; char rib[PEER_DESCR_LEN]; char if_depend[IFNAMSIZ]; char demote_group[IFNAMSIZ]; @@ -699,7 +699,7 @@ struct ctl_show_nexthop { struct ctl_neighbor { struct bgpd_addr addr; char descr[PEER_DESCR_LEN]; - char shutcomm[SHUT_COMM_LEN]; + char reason[REASON_LEN]; int show_timers; int is_group; }; @@ -1305,7 +1305,7 @@ const char *log_sockaddr(struct sockaddr *, socklen_t); const char *log_as(u_int32_t); const char *log_rd(u_int64_t); const char *log_ext_subtype(short, u_int8_t); -const char *log_shutcomm(const char *); +const char *log_reason(const char *); int aspath_snprint(char *, size_t, void *, u_int16_t); int aspath_asprint(char **, void *, u_int16_t); size_t aspath_strlen(void *, u_int16_t); diff --git a/usr.sbin/bgpd/control.c b/usr.sbin/bgpd/control.c index 433bbee096c..2b9ebdc8a9a 100644 --- a/usr.sbin/bgpd/control.c +++ b/usr.sbin/bgpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.99 2019/08/12 15:02:05 claudio Exp $ */ +/* $OpenBSD: control.c,v 1.100 2020/05/10 13:38:46 deraadt Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -375,7 +375,7 @@ control_dispatch_msg(struct pollfd *pfd, u_int *ctl_cnt, case IMSG_CTL_NEIGHBOR_UP: bgp_fsm(p, EVNT_START); p->conf.down = 0; - p->conf.shutcomm[0] = '\0'; + p->conf.reason[0] = '\0'; p->IdleHoldTime = INTERVAL_IDLE_HOLD_INITIAL; p->errcnt = 0; @@ -383,16 +383,16 @@ control_dispatch_msg(struct pollfd *pfd, u_int *ctl_cnt, break; case IMSG_CTL_NEIGHBOR_DOWN: p->conf.down = 1; - strlcpy(p->conf.shutcomm, - neighbor->shutcomm, - sizeof(neighbor->shutcomm)); + strlcpy(p->conf.reason, + neighbor->reason, + sizeof(neighbor->reason)); session_stop(p, ERR_CEASE_ADMIN_DOWN); control_result(c, CTL_RES_OK); break; case IMSG_CTL_NEIGHBOR_CLEAR: - strlcpy(p->conf.shutcomm, - neighbor->shutcomm, - sizeof(neighbor->shutcomm)); + strlcpy(p->conf.reason, + neighbor->reason, + sizeof(neighbor->reason)); p->IdleHoldTime = INTERVAL_IDLE_HOLD_INITIAL; p->errcnt = 0; diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y index a2d98aff687..66f6eaad148 100644 --- a/usr.sbin/bgpd/parse.y +++ b/usr.sbin/bgpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.407 2020/05/08 07:44:17 claudio Exp $ */ +/* $OpenBSD: parse.y,v 1.408 2020/05/10 13:38:46 deraadt Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -1297,9 +1297,9 @@ peeropts : REMOTEAS as4number { } | DOWN STRING { curpeer->conf.down = 1; - if (strlcpy(curpeer->conf.shutcomm, $2, - sizeof(curpeer->conf.shutcomm)) >= - sizeof(curpeer->conf.shutcomm)) { + if (strlcpy(curpeer->conf.reason, $2, + sizeof(curpeer->conf.reason)) >= + sizeof(curpeer->conf.reason)) { yyerror("shutdown reason too long"); free($2); YYERROR; diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c index c92a5132c1f..4930c38e999 100644 --- a/usr.sbin/bgpd/session.c +++ b/usr.sbin/bgpd/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.400 2020/04/23 16:13:11 claudio Exp $ */ +/* $OpenBSD: session.c,v 1.401 2020/05/10 13:38:46 deraadt Exp $ */ /* * Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org> @@ -516,9 +516,9 @@ session_main(int debug, int verbose) RB_FOREACH_SAFE(p, peer_head, &conf->peers, next) { RB_REMOVE(peer_head, &conf->peers, p); - strlcpy(p->conf.shutcomm, + strlcpy(p->conf.reason, "bgpd shutting down", - sizeof(p->conf.shutcomm)); + sizeof(p->conf.reason)); session_stop(p, ERR_CEASE_ADMIN_DOWN); timer_remove_all(p); free(p); @@ -2242,7 +2242,7 @@ parse_notification(struct peer *peer) u_int8_t subcode; u_int8_t capa_code; u_int8_t capa_len; - size_t shutcomm_len; + size_t reason_len; u_int8_t i; /* just log */ @@ -2343,25 +2343,25 @@ parse_notification(struct peer *peer) (subcode == ERR_CEASE_ADMIN_DOWN || subcode == ERR_CEASE_ADMIN_RESET)) { if (datalen > 1) { - shutcomm_len = *p++; + reason_len = *p++; datalen--; - if (datalen < shutcomm_len) { + if (datalen < reason_len) { log_peer_warnx(&peer->conf, "received truncated shutdown reason"); return (0); } - if (shutcomm_len > SHUT_COMM_LEN - 1) { + if (reason_len > REASON_LEN - 1) { log_peer_warnx(&peer->conf, "received overly long shutdown reason"); return (0); } - memcpy(peer->stats.last_shutcomm, p, shutcomm_len); - peer->stats.last_shutcomm[shutcomm_len] = '\0'; + memcpy(peer->stats.last_reason, p, reason_len); + peer->stats.last_reason[reason_len] = '\0'; log_peer_warnx(&peer->conf, "received shutdown reason: \"%s\"", - log_shutcomm(peer->stats.last_shutcomm)); - p += shutcomm_len; - datalen -= shutcomm_len; + log_reason(peer->stats.last_reason)); + p += reason_len; + datalen -= reason_len; } } @@ -3222,25 +3222,25 @@ session_demote(struct peer *p, int level) void session_stop(struct peer *peer, u_int8_t subcode) { - char data[SHUT_COMM_LEN]; + char data[REASON_LEN]; size_t datalen; - size_t shutcomm_len; + size_t reason_len; char *communication; datalen = 0; - communication = peer->conf.shutcomm; + communication = peer->conf.reason; if ((subcode == ERR_CEASE_ADMIN_DOWN || subcode == ERR_CEASE_ADMIN_RESET) && communication && *communication) { - shutcomm_len = strlen(communication); - if (shutcomm_len > SHUT_COMM_LEN - 1) { + reason_len = strlen(communication); + if (reason_len > REASON_LEN - 1) { log_peer_warnx(&peer->conf, "trying to send overly long shutdown reason"); } else { - data[0] = shutcomm_len; - datalen = shutcomm_len + sizeof(data[0]); - memcpy(data + 1, communication, shutcomm_len); + data[0] = reason_len; + datalen = reason_len + sizeof(data[0]); + memcpy(data + 1, communication, reason_len); } } switch (peer->state) { diff --git a/usr.sbin/bgpd/session.h b/usr.sbin/bgpd/session.h index 522e1c5f863..67c0e34a65f 100644 --- a/usr.sbin/bgpd/session.h +++ b/usr.sbin/bgpd/session.h @@ -1,4 +1,4 @@ -/* $OpenBSD: session.h,v 1.145 2020/02/12 10:33:56 claudio Exp $ */ +/* $OpenBSD: session.h,v 1.146 2020/05/10 13:38:46 deraadt Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -174,7 +174,7 @@ struct peer_stats { u_int8_t last_sent_suberr; u_int8_t last_rcvd_errcode; u_int8_t last_rcvd_suberr; - char last_shutcomm[SHUT_COMM_LEN]; + char last_reason[REASON_LEN]; }; enum Timer { diff --git a/usr.sbin/bgpd/util.c b/usr.sbin/bgpd/util.c index 39480fe82ee..90315c8a92a 100644 --- a/usr.sbin/bgpd/util.c +++ b/usr.sbin/bgpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.53 2020/04/23 16:13:11 claudio Exp $ */ +/* $OpenBSD: util.c,v 1.54 2020/05/10 13:38:46 deraadt Exp $ */ /* * Copyright (c) 2006 Claudio Jeker <claudio@openbsd.org> @@ -163,8 +163,8 @@ log_ext_subtype(short type, u_int8_t subtype) } const char * -log_shutcomm(const char *communication) { - static char buf[(SHUT_COMM_LEN - 1) * 4 + 1]; +log_reason(const char *communication) { + static char buf[(REASON_LEN - 1) * 4 + 1]; strnvis(buf, communication, sizeof(buf), VIS_NL | VIS_OCTAL); |