summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2004-03-02 19:32:44 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2004-03-02 19:32:44 +0000
commit5b258471b908015322203a6e9bbf7a85659e9044 (patch)
tree43b5adfcdedf1e36d1ecc899c10126a6b57ec635 /usr.sbin
parent4f66842855ac46ad2eb084b7ac5e3d7440343c43 (diff)
show rib A.B.C.D and show rib A.B.C.D/N [all] support. Now the most important
show commands are available. OK henning@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/bgpctl/bgpctl.c17
-rw-r--r--usr.sbin/bgpctl/parser.c57
-rw-r--r--usr.sbin/bgpctl/parser.h3
3 files changed, 70 insertions, 7 deletions
diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c
index 444e28b6159..fd21146618a 100644
--- a/usr.sbin/bgpctl/bgpctl.c
+++ b/usr.sbin/bgpctl/bgpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpctl.c,v 1.42 2004/02/26 16:19:58 claudio Exp $ */
+/* $OpenBSD: bgpctl.c,v 1.43 2004/03/02 19:32:43 claudio Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -133,11 +133,20 @@ main(int argc, char *argv[])
imsg_compose(&ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, NULL, 0);
break;
case SHOW_RIB:
- if (res->as.type == AS_NONE)
- imsg_compose(&ibuf, IMSG_CTL_SHOW_RIB, 0, NULL, 0);
- else
+ if (res->as.type != AS_NONE)
imsg_compose(&ibuf, IMSG_CTL_SHOW_RIB_AS, 0,
&res->as, sizeof(res->as));
+ else if (res->addr.af) {
+ struct ctl_show_rib_prefix msg;
+
+ bzero(&msg, sizeof(msg));
+ memcpy(&msg.prefix, &res->addr, sizeof(res->addr));
+ msg.prefixlen = res->prefixlen;
+ msg.flags = res->flags;
+ imsg_compose(&ibuf, IMSG_CTL_SHOW_RIB_PREFIX, 0,
+ &msg, sizeof(msg));
+ } else
+ imsg_compose(&ibuf, IMSG_CTL_SHOW_RIB, 0, NULL, 0);
show_rib_summary_head();
break;
case RELOAD:
diff --git a/usr.sbin/bgpctl/parser.c b/usr.sbin/bgpctl/parser.c
index 4b186c5202f..4539d39e1af 100644
--- a/usr.sbin/bgpctl/parser.c
+++ b/usr.sbin/bgpctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.3 2004/02/26 16:19:58 claudio Exp $ */
+/* $OpenBSD: parser.c,v 1.4 2004/03/02 19:32:43 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -16,6 +16,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <err.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
@@ -31,7 +32,8 @@ enum token_type {
ADDRESS,
FLAG,
ASNUM,
- ASTYPE
+ ASTYPE,
+ PREFIX
};
struct token {
@@ -51,6 +53,7 @@ static const struct token t_fib[];
static const struct token t_neighbor[];
static const struct token t_neighbor_modifiers[];
static const struct token t_show_as[];
+static const struct token t_show_prefix[];
static const struct token t_show_ip[];
static const struct token t_main[] = {
@@ -85,10 +88,12 @@ static const struct token t_show_fib[] = {
static const struct token t_show_rib[] = {
{ NOTOKEN, "", NONE, NULL},
+ { PREFIX, "", NONE, t_show_prefix},
{ ASTYPE, "as", AS_ALL, t_show_as},
{ ASTYPE, "source-as", AS_SOURCE, t_show_as},
{ ASTYPE, "transit-as", AS_TRANSIT, t_show_as},
{ ASTYPE, "empty-as", AS_EMPTY, NULL},
+ { KEYWORD, "summary", SHOW_SUMMARY, NULL},
{ ENDTOKEN, "", NONE, NULL}
};
@@ -127,6 +132,13 @@ static const struct token t_show_as[] = {
{ ENDTOKEN, "", NONE, NULL}
};
+static const struct token t_show_prefix[] = {
+ { NOTOKEN, "", NONE, NULL},
+ { FLAG, "all", F_LONGER, NULL},
+ { FLAG, "longer-prefixes", F_LONGER, NULL},
+ { ENDTOKEN, "", NONE, NULL}
+};
+
static const struct token t_show_ip[] = {
{ KEYWORD, "bgp", SHOW_RIB, t_show_rib},
{ ENDTOKEN, "", NONE, NULL}
@@ -137,6 +149,8 @@ static struct parse_result res;
const struct token *match_token(const char *, const struct token []);
void show_valid_args(const struct token []);
int parse_addr(const char *, struct bgpd_addr *);
+int parse_prefix(const char *, struct bgpd_addr *,
+ u_int8_t *);
int parse_asnum(const char *, u_int16_t *);
struct parse_result *
@@ -223,6 +237,14 @@ match_token(const char *word, const struct token table[])
res.action = t->value;
}
break;
+ case PREFIX:
+ if (parse_prefix(word, &res.addr, &res.prefixlen)) {
+ match++;
+ t = &table[i];
+ if (t->value)
+ res.action = t->value;
+ }
+ break;
case ASTYPE:
if (word != NULL && strncmp(word, table[i].keyword,
strlen(word)) == 0) {
@@ -271,6 +293,9 @@ show_valid_args(const struct token table[])
case ADDRESS:
fprintf(stderr, " <address>\n");
break;
+ case PREFIX:
+ fprintf(stderr, " <address>[/<len>]\n");
+ break;
case ASNUM:
fprintf(stderr, " <asnum>\n");
break;
@@ -301,6 +326,34 @@ parse_addr(const char *word, struct bgpd_addr *addr)
}
int
+parse_prefix(const char *word, struct bgpd_addr *addr, u_int8_t *prefixlen)
+{
+ struct in_addr ina;
+ int bits = 32;
+
+ if (word == NULL)
+ return (0);
+
+ bzero(addr, sizeof(struct bgpd_addr));
+ bzero(&ina, sizeof(ina));
+
+ if (strrchr(word, '/') != NULL) {
+ if ((bits = inet_net_pton(AF_INET, word,
+ &ina, sizeof(ina))) == -1)
+ return (0);
+ addr->af = AF_INET;
+ addr->v4.s_addr = ina.s_addr & htonl(0xffffffff << (32 - bits));
+ *prefixlen = bits;
+ return (1);
+ } else {
+ *prefixlen = 32;
+ return (parse_addr(word, addr));
+ }
+
+ return (0);
+}
+
+int
parse_asnum(const char *word, u_int16_t *asnum)
{
u_long ulval;
diff --git a/usr.sbin/bgpctl/parser.h b/usr.sbin/bgpctl/parser.h
index 116be69cec4..42c8cfefc57 100644
--- a/usr.sbin/bgpctl/parser.h
+++ b/usr.sbin/bgpctl/parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.h,v 1.2 2004/02/26 16:19:58 claudio Exp $ */
+/* $OpenBSD: parser.h,v 1.3 2004/03/02 19:32:43 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -43,6 +43,7 @@ struct parse_result {
enum actions action;
int flags;
struct bgpd_addr addr;
+ u_int8_t prefixlen;
struct as_filter as;
};