summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpctl
diff options
context:
space:
mode:
authorPeter Hessler <phessler@cvs.openbsd.org>2013-10-09 08:56:39 +0000
committerPeter Hessler <phessler@cvs.openbsd.org>2013-10-09 08:56:39 +0000
commit9f4f20c00ffc4f80c95fb22a99b0497b4231e133 (patch)
tree0fc627adc179e98a6dbfefb32abda66a14836e4c /usr.sbin/bgpctl
parentc7dbb94dc7cfdd7caa45efd11daed1377b5c8a3b (diff)
Allow us to bulk add / delete routes with the same attributes. Really
useful for distributing IP lists. OK beck@, claudio@, henning@
Diffstat (limited to 'usr.sbin/bgpctl')
-rw-r--r--usr.sbin/bgpctl/bgpctl.823
-rw-r--r--usr.sbin/bgpctl/bgpctl.c70
-rw-r--r--usr.sbin/bgpctl/parser.c13
-rw-r--r--usr.sbin/bgpctl/parser.h6
4 files changed, 105 insertions, 7 deletions
diff --git a/usr.sbin/bgpctl/bgpctl.8 b/usr.sbin/bgpctl/bgpctl.8
index bd6830efca0..4921bc0422a 100644
--- a/usr.sbin/bgpctl/bgpctl.8
+++ b/usr.sbin/bgpctl/bgpctl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: bgpctl.8,v 1.61 2013/03/07 21:28:34 claudio Exp $
+.\" $OpenBSD: bgpctl.8,v 1.62 2013/10/09 08:56:38 phessler 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: March 7 2013 $
+.Dd $Mdocdate: October 9 2013 $
.Dt BGPCTL 8
.Os
.Sh NAME
@@ -126,6 +126,25 @@ It is possible to set various path attributes with additional
Remove the specified prefix from the list of announced networks.
.It Cm network flush
Remove all dynamically added prefixes from the list of announced networks.
+.It Xo
+.Cm network bulk
+.Op Ar arguments
+.Op Cm add
+.Xc
+Bulk add specified prefixes to the list of announced networks.
+Prefixes should be sent via STDIN.
+It is possible to set various path attributes with additional
+.Ar arguments .
+If neither
+.Cm add
+or
+.Cm delete
+is given,
+.Cm add
+is the default.
+.It Cm network bulk delete
+Bulk remove the specified prefixes from the list of announced networks.
+Prefixes should be sent via STDIN.
.It Cm network mrt file Ar file filter
Import networks from an MRT table dump for debugging purposes.
.Ar filter
diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c
index c62f476c059..5beef918c6e 100644
--- a/usr.sbin/bgpctl/bgpctl.c
+++ b/usr.sbin/bgpctl/bgpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpctl.c,v 1.171 2013/08/18 16:32:24 guenther Exp $ */
+/* $OpenBSD: bgpctl.c,v 1.172 2013/10/09 08:56:38 phessler Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -24,6 +24,7 @@
#include <net/if_types.h>
#include <err.h>
+#include <fcntl.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
@@ -91,6 +92,10 @@ void network_mrt_dump(struct mrt_rib *, struct mrt_peer *, void *);
void show_mrt_state(struct mrt_bgp_state *, void *);
void show_mrt_msg(struct mrt_bgp_msg *, void *);
void mrt_to_bgpd_addr(union mrt_addr *, struct bgpd_addr *);
+void network_bulk(struct parse_result *);
+
+/* parser.c */
+int parse_prefix(const char *, struct bgpd_addr *, u_int8_t *);
struct imsgbuf *ibuf;
struct mrt_parser show_mrt = { show_mrt_dump, show_mrt_state, show_mrt_msg };
@@ -314,6 +319,12 @@ main(int argc, char *argv[])
imsg_compose(ibuf, IMSG_CTL_NEIGHBOR_DESTROY, 0, 0, -1,
&neighbor, sizeof(neighbor));
break;
+ case NETWORK_BULK_ADD:
+ case NETWORK_BULK_REMOVE:
+ network_bulk(res);
+ printf("requests sent.\n");
+ done = 1;
+ break;
case NETWORK_ADD:
case NETWORK_REMOVE:
bzero(&net, sizeof(net));
@@ -449,6 +460,8 @@ main(int argc, char *argv[])
case NETWORK_ADD:
case NETWORK_REMOVE:
case NETWORK_FLUSH:
+ case NETWORK_BULK_ADD:
+ case NETWORK_BULK_REMOVE:
case IRRFILTER:
case LOG_VERBOSE:
case LOG_BRIEF:
@@ -1619,6 +1632,61 @@ show_result(struct imsg *imsg)
}
void
+network_bulk(struct parse_result *res)
+{
+ struct network_config net;
+ struct filter_set *s = NULL;
+ struct bgpd_addr h;
+ char *b, *buf, *lbuf;
+ size_t slen;
+ u_int8_t len;
+ FILE *f;
+
+ if ((f = fdopen(STDIN_FILENO, "r")) != NULL) {
+ lbuf = NULL;
+ while ((buf = fgetln(f, &slen))) {
+ if (buf[slen - 1] == '\n')
+ buf[slen - 1] = '\0';
+ else {
+ if ((lbuf = malloc(slen + 1)) == NULL)
+ err(1, NULL);
+ memcpy(lbuf, buf, slen);
+ lbuf[slen] = '\0';
+ buf = lbuf;
+ }
+
+ while ((b = strsep(&buf, " \t")) != NULL) {
+ /* Don't process commented entries */
+ if (strchr(b, '#') != NULL)
+ break;
+ bzero(&net, sizeof(net));
+ parse_prefix(b, &h, &len);
+ memcpy(&net.prefix, &h, sizeof(h));
+ net.prefixlen = len;
+
+ if (res->action == NETWORK_BULK_ADD) {
+ imsg_compose(ibuf, IMSG_NETWORK_ADD,
+ 0, 0, -1, &net, sizeof(net));
+ TAILQ_FOREACH(s, &res->set, entry) {
+ imsg_compose(ibuf,
+ IMSG_FILTER_SET,
+ 0, 0, -1, s, sizeof(*s));
+ }
+ imsg_compose(ibuf, IMSG_NETWORK_DONE,
+ 0, 0, -1, NULL, 0);
+ } else
+ imsg_compose(ibuf, IMSG_NETWORK_REMOVE,
+ 0, 0, -1, &net, sizeof(net));
+ }
+ free(lbuf);
+ }
+ fclose(f);
+ } else {
+ err(1, "Failed to open stdin\n");
+ }
+}
+
+void
show_mrt_dump(struct mrt_rib *mr, struct mrt_peer *mp, void *arg)
{
struct ctl_show_rib ctl;
diff --git a/usr.sbin/bgpctl/parser.c b/usr.sbin/bgpctl/parser.c
index 1f544f0942b..7a1d3d54361 100644
--- a/usr.sbin/bgpctl/parser.c
+++ b/usr.sbin/bgpctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.66 2013/03/07 21:28:34 claudio Exp $ */
+/* $OpenBSD: parser.c,v 1.67 2013/10/09 08:56:38 phessler Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -55,7 +55,8 @@ enum token_type {
FAMILY,
GETOPT,
RTABLE,
- FILENAME
+ FILENAME,
+ BULK
};
enum getopts {
@@ -280,6 +281,7 @@ static const struct token t_network[] = {
{ KEYWORD, "flush", NETWORK_FLUSH, NULL},
{ KEYWORD, "show", NETWORK_SHOW, t_network_show},
{ KEYWORD, "mrt", NETWORK_MRT, t_show_mrt},
+ { KEYWORD, "bulk", NETWORK_BULK_ADD, t_set},
{ ENDTOKEN, "", NONE, NULL}
};
@@ -305,6 +307,8 @@ static const struct token t_set[] = {
{ KEYWORD, "prepend-neighbor", NONE, t_prepnbr},
{ KEYWORD, "prepend-self", NONE, t_prepself},
{ KEYWORD, "weight", NONE, t_weight},
+ { KEYWORD, "add", NETWORK_BULK_ADD, NULL},
+ { KEYWORD, "delete", NETWORK_BULK_REMOVE, NULL},
{ ENDTOKEN, "", NONE, NULL}
};
@@ -608,6 +612,10 @@ match_token(int *argc, char **argv[], const struct token table[])
t = &table[i];
}
break;
+ case BULK:
+ match++;
+ t = &table[i];
+ break;
case ENDTOKEN:
break;
}
@@ -685,6 +693,7 @@ show_valid_args(const struct token table[])
case FILENAME:
fprintf(stderr, " <filename>\n");
break;
+ case BULK:
case ENDTOKEN:
break;
}
diff --git a/usr.sbin/bgpctl/parser.h b/usr.sbin/bgpctl/parser.h
index 80c1e37b9c8..fd298fda7bc 100644
--- a/usr.sbin/bgpctl/parser.h
+++ b/usr.sbin/bgpctl/parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.h,v 1.25 2013/03/07 21:28:34 claudio Exp $ */
+/* $OpenBSD: parser.h,v 1.26 2013/10/09 08:56:38 phessler Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -52,7 +52,9 @@ enum actions {
NETWORK_FLUSH,
NETWORK_SHOW,
NETWORK_MRT,
- IRRFILTER
+ IRRFILTER,
+ NETWORK_BULK_ADD,
+ NETWORK_BULK_REMOVE
};
struct parse_result {