summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/bgpctl/bgpctl.89
-rw-r--r--usr.sbin/bgpctl/bgpctl.c57
-rw-r--r--usr.sbin/bgpctl/parser.c4
-rw-r--r--usr.sbin/bgpd/bgpd.h3
4 files changed, 43 insertions, 30 deletions
diff --git a/usr.sbin/bgpctl/bgpctl.8 b/usr.sbin/bgpctl/bgpctl.8
index 061afca0302..38fd56c895e 100644
--- a/usr.sbin/bgpctl/bgpctl.8
+++ b/usr.sbin/bgpctl/bgpctl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: bgpctl.8,v 1.78 2017/09/21 14:47:51 jmc Exp $
+.\" $OpenBSD: bgpctl.8,v 1.79 2017/10/15 20:44:21 deraadt Exp $
.\"
.\" Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: September 21 2017 $
+.Dd $Mdocdate: October 15 2017 $
.Dt BGPCTL 8
.Os
.Sh NAME
@@ -365,6 +365,11 @@ Alias for
.Ic selected .
.It Cm selected
Show only selected routes.
+.It Cm ssv
+Show each RIB entry as a single line, with fields separated by semicolons.
+Only works if
+.Cm detail
+is specified.
.It Cm detail
Show more detailed output for matching routes.
.It Ar family
diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c
index 43102769439..994d25e59af 100644
--- a/usr.sbin/bgpctl/bgpctl.c
+++ b/usr.sbin/bgpctl/bgpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpctl.c,v 1.199 2017/08/10 14:22:59 benno Exp $ */
+/* $OpenBSD: bgpctl.c,v 1.200 2017/10/15 20:44:21 deraadt Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -48,6 +48,8 @@ enum neighbor_views {
NV_TIMERS
};
+#define EOL0(flag) ((flag & F_CTL_SSV) ? ';' : '\n')
+
int main(int, char *[]);
char *fmt_peer(const char *, const struct bgpd_addr *, int, int);
void show_summary_head(void);
@@ -79,10 +81,10 @@ void print_prefix(struct bgpd_addr *, u_int8_t, u_int8_t);
const char * print_origin(u_int8_t, int);
void print_flags(u_int8_t, int);
int show_rib_summary_msg(struct imsg *);
-int show_rib_detail_msg(struct imsg *, int);
+int show_rib_detail_msg(struct imsg *, int, int);
void show_rib_brief(struct ctl_show_rib *, u_char *);
-void show_rib_detail(struct ctl_show_rib *, u_char *, int);
-void show_attr(void *, u_int16_t);
+void show_rib_detail(struct ctl_show_rib *, u_char *, int, int);
+void show_attr(void *, u_int16_t, int);
void show_community(u_char *, u_int16_t);
void show_large_community(u_char *, u_int16_t);
void show_ext_community(u_char *, u_int16_t);
@@ -472,7 +474,7 @@ main(int argc, char *argv[])
case SHOW_RIB:
if (res->flags & F_CTL_DETAIL)
done = show_rib_detail_msg(&imsg,
- nodescr);
+ nodescr, res->flags);
else
done = show_rib_summary_msg(&imsg);
break;
@@ -1337,7 +1339,7 @@ show_rib_summary_msg(struct imsg *imsg)
}
int
-show_rib_detail_msg(struct imsg *imsg, int nodescr)
+show_rib_detail_msg(struct imsg *imsg, int nodescr, int flag0)
{
struct ctl_show_rib rib;
u_char *asdata;
@@ -1348,16 +1350,16 @@ show_rib_detail_msg(struct imsg *imsg, int nodescr)
memcpy(&rib, imsg->data, sizeof(rib));
asdata = imsg->data;
asdata += sizeof(struct ctl_show_rib);
- show_rib_detail(&rib, asdata, nodescr);
+ show_rib_detail(&rib, asdata, nodescr, flag0);
break;
case IMSG_CTL_SHOW_RIB_ATTR:
ilen = imsg->hdr.len - IMSG_HEADER_SIZE;
if (ilen < 3)
errx(1, "bad IMSG_CTL_SHOW_RIB_ATTR received");
- show_attr(imsg->data, ilen);
+ show_attr(imsg->data, ilen, flag0);
break;
case IMSG_CTL_END:
- printf("\n");
+ printf("%c", EOL0(flag0));
return (1);
default:
break;
@@ -1385,19 +1387,20 @@ show_rib_brief(struct ctl_show_rib *r, u_char *asdata)
}
void
-show_rib_detail(struct ctl_show_rib *r, u_char *asdata, int nodescr)
+show_rib_detail(struct ctl_show_rib *r, u_char *asdata, int nodescr, int flag0)
{
struct in_addr id;
char *aspath, *s;
time_t now;
- printf("\nBGP routing table entry for %s/%u\n",
- log_addr(&r->prefix), r->prefixlen);
+ printf("\nBGP routing table entry for %s/%u%c",
+ log_addr(&r->prefix), r->prefixlen,
+ EOL0(flag0));
if (aspath_asprint(&aspath, asdata, r->aspath_len) == -1)
err(1, NULL);
if (strlen(aspath) > 0)
- printf(" %s\n", aspath);
+ printf(" %s%c", aspath, EOL0(flag0));
free(aspath);
s = fmt_peer(r->descr, &r->remote_addr, -1, nodescr);
@@ -1405,7 +1408,7 @@ show_rib_detail(struct ctl_show_rib *r, u_char *asdata, int nodescr)
printf("(via %s) from %s (", log_addr(&r->true_nexthop), s);
free(s);
id.s_addr = htonl(r->remote_id);
- printf("%s)\n", inet_ntoa(id));
+ printf("%s)%c", inet_ntoa(id), EOL0(flag0));
printf(" Origin %s, metric %u, localpref %u, weight %u, ",
print_origin(r->origin, 0), r->med, r->local_pref, r->weight);
@@ -1417,11 +1420,12 @@ show_rib_detail(struct ctl_show_rib *r, u_char *asdata, int nodescr)
else
now = 0;
- printf("\n Last update: %s ago\n", fmt_timeframe_core(now));
+ printf("%c Last update: %s ago%c", EOL0(flag0),
+ fmt_timeframe_core(now), EOL0(flag0));
}
void
-show_attr(void *b, u_int16_t len)
+show_attr(void *b, u_int16_t len, int flag0)
{
char *data = b;
struct in_addr id;
@@ -1458,22 +1462,22 @@ show_attr(void *b, u_int16_t len)
case ATTR_COMMUNITIES:
printf(" Communities: ");
show_community(data, alen);
- printf("\n");
+ printf("%c", EOL0(flag0));
break;
case ATTR_LARGE_COMMUNITIES:
printf(" Large Communities: ");
show_large_community(data, alen);
- printf("\n");
+ printf("%c", EOL0(flag0));
break;
case ATTR_AGGREGATOR:
memcpy(&as, data, sizeof(as));
memcpy(&id, data + sizeof(as), sizeof(id));
- printf(" Aggregator: %s [%s]\n",
- log_as(ntohl(as)), inet_ntoa(id));
+ printf(" Aggregator: %s [%s]%c",
+ log_as(ntohl(as)), inet_ntoa(id), EOL0(flag0));
break;
case ATTR_ORIGINATOR_ID:
memcpy(&id, data, sizeof(id));
- printf(" Originator Id: %s\n", inet_ntoa(id));
+ printf(" Originator Id: %s%c", inet_ntoa(id), EOL0(flag0));
break;
case ATTR_CLUSTER_LIST:
printf(" Cluster ID List:");
@@ -1482,12 +1486,12 @@ show_attr(void *b, u_int16_t len)
memcpy(&id, data + ioff, sizeof(id));
printf(" %s", inet_ntoa(id));
}
- printf("\n");
+ printf("%c", EOL0(flag0));
break;
case ATTR_EXT_COMMUNITIES:
printf(" Ext. communities: ");
show_ext_community(data, alen);
- printf("\n");
+ printf("%c", EOL0(flag0));
break;
case ATTR_ATOMIC_AGGREGATE:
/* ignore */
@@ -1511,7 +1515,7 @@ show_attr(void *b, u_int16_t len)
for (i=0; i < alen; i++)
printf(" %02x", *(data+i) & 0xFF);
}
- printf("\n");
+ printf("%c", EOL0(flag0));
break;
}
}
@@ -1898,10 +1902,11 @@ show_mrt_dump(struct mrt_rib *mr, struct mrt_peer *mp, void *arg)
continue;
if (req->flags & F_CTL_DETAIL) {
- show_rib_detail(&ctl, mre->aspath, 1);
+ show_rib_detail(&ctl, mre->aspath, 1, 0);
for (j = 0; j < mre->nattrs; j++)
show_attr(mre->attrs[j].attr,
- mre->attrs[j].attr_len);
+ mre->attrs[j].attr_len,
+ req->flags);
} else
show_rib_brief(&ctl, mre->aspath);
}
diff --git a/usr.sbin/bgpctl/parser.c b/usr.sbin/bgpctl/parser.c
index 502a71e6aa5..a8bf259b0ac 100644
--- a/usr.sbin/bgpctl/parser.c
+++ b/usr.sbin/bgpctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.80 2017/08/10 14:12:34 benno Exp $ */
+/* $OpenBSD: parser.c,v 1.81 2017/10/15 20:44:21 deraadt Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -177,6 +177,7 @@ static const struct token t_show_rib[] = {
{ FLAG, "best", F_CTL_ACTIVE, t_show_rib},
{ FLAG, "selected", F_CTL_ACTIVE, t_show_rib},
{ FLAG, "detail", F_CTL_DETAIL, t_show_rib},
+ { FLAG, "ssv" , F_CTL_SSV, t_show_rib},
{ FLAG, "in", F_CTL_ADJ_IN, t_show_rib},
{ FLAG, "out", F_CTL_ADJ_OUT, t_show_rib},
{ KEYWORD, "neighbor", NONE, t_show_rib_neigh},
@@ -197,6 +198,7 @@ static const struct token t_show_mrt[] = {
{ ASTYPE, "peer-as", AS_PEER, t_show_mrt_as},
{ ASTYPE, "empty-as", AS_EMPTY, t_show_mrt},
{ FLAG, "detail", F_CTL_DETAIL, t_show_mrt},
+ { FLAG, "ssv" , F_CTL_SSV, t_show_mrt},
{ KEYWORD, "neighbor", NONE, t_show_mrt_neigh},
{ KEYWORD, "file", NONE, t_show_mrt_file},
{ FAMILY, "", NONE, t_show_mrt},
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h
index 4e8ccc104f7..baa630dd13c 100644
--- a/usr.sbin/bgpd/bgpd.h
+++ b/usr.sbin/bgpd/bgpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.h,v 1.314 2017/08/12 16:47:50 phessler Exp $ */
+/* $OpenBSD: bgpd.h,v 1.315 2017/10/15 20:44:21 deraadt Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -85,6 +85,7 @@
#define F_CTL_ADJ_OUT 0x4000
#define F_CTL_ACTIVE 0x8000
#define F_RTLABEL 0x10000
+#define F_CTL_SSV 0x20000 /* only used by bgpctl */
/*
* Limit the number of messages queued in the session engine.