summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2004-02-08 23:44:58 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2004-02-08 23:44:58 +0000
commit8a86b13a9680c84a15047409e47c7e9880b2c432 (patch)
tree43f2937da846746315d280a43be59581b9a22cfe
parent627c358ce1287125f08bcea706dec75aa35e0905 (diff)
factor out functions to print the configuration (rules only for now)
will become more and needed by bgpctl too
-rw-r--r--usr.sbin/bgpd/Makefile4
-rw-r--r--usr.sbin/bgpd/parse.y119
-rw-r--r--usr.sbin/bgpd/printconf.c137
-rw-r--r--usr.sbin/bgpd/session.h5
4 files changed, 145 insertions, 120 deletions
diff --git a/usr.sbin/bgpd/Makefile b/usr.sbin/bgpd/Makefile
index 93adc024a63..063080ab23c 100644
--- a/usr.sbin/bgpd/Makefile
+++ b/usr.sbin/bgpd/Makefile
@@ -1,11 +1,11 @@
-# $OpenBSD: Makefile,v 1.15 2004/02/04 09:18:03 claudio Exp $
+# $OpenBSD: Makefile,v 1.16 2004/02/08 23:44:57 henning Exp $
.PATH: ${.CURDIR}/..
PROG= bgpd
SRCS= bgpd.c buffer.c session.c log.c parse.y config.c imsg.c \
rde.c rde_rib.c rde_decide.c rde_prefix.c mrt.c kroute.c \
- control.c pfkey.c rde_update.c rde_attr.c
+ control.c pfkey.c rde_update.c rde_attr.c printconf.c
CFLAGS+= -Wall -I${.CURDIR}
CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes
CLFAGS+= -Wmissing-declarations -Wredundant-decls
diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y
index b2a0be0a34b..0b137d3b785 100644
--- a/usr.sbin/bgpd/parse.y
+++ b/usr.sbin/bgpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.52 2004/02/06 20:37:53 henning Exp $ */
+/* $OpenBSD: parse.y,v 1.53 2004/02/08 23:44:57 henning Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -67,8 +67,6 @@ int add_mrtconfig(enum mrt_type, char *, time_t);
int get_id(struct peer *);
int expand_rule(struct filter_rule *, struct filter_peers *,
struct filter_match *, struct filter_set *);
-void print_op(enum comp_ops);
-void print_rule(struct filter_rule *);
TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead);
struct sym {
@@ -920,7 +918,7 @@ parse_config(char *filename, struct bgpd_config *xconf,
if (xconf->opts & BGPD_OPT_VERBOSE)
TAILQ_FOREACH(r, filter_l, entries)
- print_rule(r);
+ print_rule(peer_l, r);
errors += merge_config(xconf, conf, peer_l);
errors += mrt_mergeconfig(xmconf, mrtconf);
@@ -1150,116 +1148,3 @@ expand_rule(struct filter_rule *rule, struct filter_peers *peer,
return (0);
}
-
-void
-print_op(enum comp_ops op)
-{
- switch (op) {
- case OP_EQ:
- printf("=");
- break;
- case OP_NE:
- printf("!=");
- break;
- case OP_LE:
- printf("<=");
- break;
- case OP_LT:
- printf("<");
- break;
- case OP_GE:
- printf(">=");
- break;
- case OP_GT:
- printf(">");
- break;
- default:
- printf("?");
- break;
- }
-}
-
-void
-print_rule(struct filter_rule *r)
-{
- struct peer *p;
-
- if (r->action == ACTION_ALLOW)
- printf("allow ");
- else if (r->action == ACTION_DENY)
- printf("deny ");
- else
- printf("match ");
-
- if (r->quick)
- printf("quick ");
-
- if (r->dir == DIR_IN)
- printf("from ");
- else if (r->dir == DIR_OUT)
- printf("to ");
- else
- printf("eeeeeeeps. ");
-
- if (r->peer.peerid) {
- for (p = peer_l; p != NULL && p->conf.id != r->peer.peerid;
- p = p->next)
- ; /* nothing */
- if (p == NULL)
- printf("?");
- else
- printf("%s ", log_addr(&p->conf.remote_addr));
- } else if (r->peer.groupid) {
- for (p = peer_l; p != NULL &&
- p->conf.groupid != r->peer.groupid; p = p->next)
- ; /* nothing */
- if (p == NULL)
- printf("group ? ");
- else
- printf("group %s ", p->conf.group);
- } else
- printf("any ");
-
- if (r->match.prefix.addr.af)
- printf("prefix %s/%u ", log_addr(&r->match.prefix.addr),
- r->match.prefix.len);
-
- if (r->match.prefixlen.op) {
- if (r->match.prefixlen.op == OP_RANGE)
- printf("prefixlen %u - %u ", r->match.prefixlen.len_min,
- r->match.prefixlen.len_max);
- else {
- printf("prefixlen ");
- print_op(r->match.prefixlen.op);
- printf(" %u ", r->match.prefixlen.len_min);
- }
- }
-
- if (r->match.as.type) {
- if (r->match.as.type == AS_ALL)
- printf("AS %u ", r->match.as.as);
- else if (r->match.as.type == AS_SOURCE)
- printf("source-AS %u ", r->match.as.as);
- else if (r->match.as.type == AS_TRANSIT)
- printf("transit-AS %u ", r->match.as.as);
- else
- printf("unfluffy-AS %u ", r->match.as.as);
- }
-
- if (r->set.flags) {
- printf("set { ");
- if (r->set.flags & SET_LOCALPREF)
- printf("localpref %u ", r->set.localpref);
- if (r->set.flags & SET_MED)
- printf("med %u ", r->set.med);
- if (r->set.flags & SET_NEXTHOP)
- printf("nexthop %s ", inet_ntoa(r->set.nexthop));
- if (r->set.flags & SET_PREPEND)
- printf("prepend-self %u ", r->set.prepend);
-
-
- printf("}");
- }
-
- printf("\n");
-}
diff --git a/usr.sbin/bgpd/printconf.c b/usr.sbin/bgpd/printconf.c
new file mode 100644
index 00000000000..d3f8afdcf23
--- /dev/null
+++ b/usr.sbin/bgpd/printconf.c
@@ -0,0 +1,137 @@
+/* $OpenBSD: printconf.c,v 1.1 2004/02/08 23:44:57 henning Exp $ */
+
+/*
+ * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA, PROFITS OR MIND, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdio.h>
+
+#include "bgpd.h"
+#include "session.h"
+
+void print_op(enum comp_ops);
+
+void
+print_op(enum comp_ops op)
+{
+ switch (op) {
+ case OP_EQ:
+ printf("=");
+ break;
+ case OP_NE:
+ printf("!=");
+ break;
+ case OP_LE:
+ printf("<=");
+ break;
+ case OP_LT:
+ printf("<");
+ break;
+ case OP_GE:
+ printf(">=");
+ break;
+ case OP_GT:
+ printf(">");
+ break;
+ default:
+ printf("?");
+ break;
+ }
+}
+
+void
+print_rule(struct peer *peer_l, struct filter_rule *r)
+{
+ struct peer *p;
+
+ if (r->action == ACTION_ALLOW)
+ printf("allow ");
+ else if (r->action == ACTION_DENY)
+ printf("deny ");
+ else
+ printf("match ");
+
+ if (r->quick)
+ printf("quick ");
+
+ if (r->dir == DIR_IN)
+ printf("from ");
+ else if (r->dir == DIR_OUT)
+ printf("to ");
+ else
+ printf("eeeeeeeps. ");
+
+ if (r->peer.peerid) {
+ for (p = peer_l; p != NULL && p->conf.id != r->peer.peerid;
+ p = p->next)
+ ; /* nothing */
+ if (p == NULL)
+ printf("?");
+ else
+ printf("%s ", log_addr(&p->conf.remote_addr));
+ } else if (r->peer.groupid) {
+ for (p = peer_l; p != NULL &&
+ p->conf.groupid != r->peer.groupid; p = p->next)
+ ; /* nothing */
+ if (p == NULL)
+ printf("group ? ");
+ else
+ printf("group %s ", p->conf.group);
+ } else
+ printf("any ");
+
+ if (r->match.prefix.addr.af)
+ printf("prefix %s/%u ", log_addr(&r->match.prefix.addr),
+ r->match.prefix.len);
+
+ if (r->match.prefixlen.op) {
+ if (r->match.prefixlen.op == OP_RANGE)
+ printf("prefixlen %u - %u ", r->match.prefixlen.len_min,
+ r->match.prefixlen.len_max);
+ else {
+ printf("prefixlen ");
+ print_op(r->match.prefixlen.op);
+ printf(" %u ", r->match.prefixlen.len_min);
+ }
+ }
+
+ if (r->match.as.type) {
+ if (r->match.as.type == AS_ALL)
+ printf("AS %u ", r->match.as.as);
+ else if (r->match.as.type == AS_SOURCE)
+ printf("source-AS %u ", r->match.as.as);
+ else if (r->match.as.type == AS_TRANSIT)
+ printf("transit-AS %u ", r->match.as.as);
+ else
+ printf("unfluffy-AS %u ", r->match.as.as);
+ }
+
+ if (r->set.flags) {
+ printf("set { ");
+ if (r->set.flags & SET_LOCALPREF)
+ printf("localpref %u ", r->set.localpref);
+ if (r->set.flags & SET_MED)
+ printf("med %u ", r->set.med);
+ if (r->set.flags & SET_NEXTHOP)
+ printf("nexthop %s ", inet_ntoa(r->set.nexthop));
+ if (r->set.flags & SET_PREPEND)
+ printf("prepend-self %u ", r->set.prepend);
+
+
+ printf("}");
+ }
+
+ printf("\n");
+}
diff --git a/usr.sbin/bgpd/session.h b/usr.sbin/bgpd/session.h
index ffe02dd80f0..8e2162f0269 100644
--- a/usr.sbin/bgpd/session.h
+++ b/usr.sbin/bgpd/session.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.h,v 1.26 2004/02/07 11:42:30 henning Exp $ */
+/* $OpenBSD: session.h,v 1.27 2004/02/08 23:44:57 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -197,3 +197,6 @@ void control_close(int);
int pfkey_auth_establish(struct peer *p);
int pfkey_auth_remove(struct peer *p);
int pfkey_init(void);
+
+/* printconf.c */
+void print_rule(struct peer *, struct filter_rule *);