diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2019-09-27 10:33:08 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2019-09-27 10:33:08 +0000 |
commit | d46bf29f6788165ecc0fc187b795f58c3cd9610f (patch) | |
tree | b157e74c2d49b57b8ca7ba4c8988c5efd113c8fd /usr.sbin | |
parent | 020bd7faa45272d05dc5cb6136932dfda43426ee (diff) |
Implement F_SHORTER in the prefix lookup code for bgpctl. F_SHORTER will
match all prefixes that have a shorter prefixlen than the one in the request.
It will print all routes which cover the specified prefix.
OK job@ sthen@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/bgpd/bgpd.h | 5 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde.c | 43 |
2 files changed, 34 insertions, 14 deletions
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index d9207e4446f..52f269f49bd 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.392 2019/08/07 10:26:41 claudio Exp $ */ +/* $OpenBSD: bgpd.h,v 1.393 2019/09/27 10:33:06 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -80,7 +80,8 @@ #define F_REJECT 0x0080 #define F_BLACKHOLE 0x0100 #define F_LONGER 0x0200 -#define F_MPLS 0x0400 +#define F_SHORTER 0x0400 +#define F_MPLS 0x0800 #define F_CTL_DETAIL 0x1000 /* only set on requests */ #define F_CTL_ADJ_IN 0x2000 /* only set on requests */ #define F_CTL_ADJ_OUT 0x4000 /* only set on requests */ diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index 5725d86881e..f391d916aa5 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.487 2019/08/14 11:57:21 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.488 2019/09/27 10:33:07 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -2353,11 +2353,21 @@ rde_dump_prefix_upcall(struct rib_entry *re, void *ptr) pt_getaddr(pt, &addr); if (addr.aid != ctx->req.prefix.aid) return; - if (ctx->req.prefixlen > pt->prefixlen) - return; - if (!prefix_compare(&ctx->req.prefix, &addr, ctx->req.prefixlen)) - LIST_FOREACH(p, &re->prefix_h, entry.list.rib) - rde_dump_filter(p, &ctx->req); + if (ctx->req.flags & F_LONGER) { + if (ctx->req.prefixlen > pt->prefixlen) + return; + if (!prefix_compare(&ctx->req.prefix, &addr, + ctx->req.prefixlen)) + LIST_FOREACH(p, &re->prefix_h, entry.list.rib) + rde_dump_filter(p, &ctx->req); + } else { + if (ctx->req.prefixlen < pt->prefixlen) + return; + if (!prefix_compare(&addr, &ctx->req.prefix, + pt->prefixlen)) + LIST_FOREACH(p, &re->prefix_h, entry.list.rib) + rde_dump_filter(p, &ctx->req); + } } static void @@ -2382,10 +2392,19 @@ rde_dump_adjout_prefix_upcall(struct prefix *p, void *ptr) pt_getaddr(p->pt, &addr); if (addr.aid != ctx->req.prefix.aid) return; - if (ctx->req.prefixlen > p->pt->prefixlen) - return; - if (!prefix_compare(&ctx->req.prefix, &addr, ctx->req.prefixlen)) - rde_dump_filter(p, &ctx->req); + if (ctx->req.flags & F_LONGER) { + if (ctx->req.prefixlen > p->pt->prefixlen) + return; + if (!prefix_compare(&ctx->req.prefix, &addr, + ctx->req.prefixlen)) + rde_dump_filter(p, &ctx->req); + } else { + if (ctx->req.prefixlen < p->pt->prefixlen) + return; + if (!prefix_compare(&addr, &ctx->req.prefix, + p->pt->prefixlen)) + rde_dump_filter(p, &ctx->req); + } } static int @@ -2489,7 +2508,7 @@ rde_dump_ctx_new(struct ctl_show_rib_request *req, pid_t pid, goto nomem; break; case IMSG_CTL_SHOW_RIB_PREFIX: - if (req->flags & F_LONGER) { + if (req->flags & (F_LONGER|F_SHORTER)) { if (prefix_dump_new(peer, ctx->req.aid, CTL_MSG_HIGH_MARK, ctx, rde_dump_adjout_prefix_upcall, @@ -2553,7 +2572,7 @@ rde_dump_ctx_new(struct ctl_show_rib_request *req, pid_t pid, goto nomem; break; case IMSG_CTL_SHOW_RIB_PREFIX: - if (req->flags & F_LONGER) { + if (req->flags & (F_LONGER|F_SHORTER)) { if (rib_dump_new(rid, ctx->req.aid, CTL_MSG_HIGH_MARK, ctx, rde_dump_prefix_upcall, rde_dump_done, rde_dump_throttled) == -1) |