summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2009-06-29 12:22:17 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2009-06-29 12:22:17 +0000
commit9dae7d6a8a1b9735b12bc33d5f37c92a7bcde976 (patch)
treea719de9015d8295c04d8813d76e213edf84b7ff1 /usr.sbin
parent2216b7dcf43bb3e23631090a473ffc0cb1a4fb58 (diff)
Unfuck mrt table dumps and plug a memory leak while there.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/bgpd/mrt.c24
-rw-r--r--usr.sbin/bgpd/mrt.h8
-rw-r--r--usr.sbin/bgpd/rde.c26
3 files changed, 28 insertions, 30 deletions
diff --git a/usr.sbin/bgpd/mrt.c b/usr.sbin/bgpd/mrt.c
index bee49a670b7..5fa497a2b26 100644
--- a/usr.sbin/bgpd/mrt.c
+++ b/usr.sbin/bgpd/mrt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mrt.c,v 1.62 2009/06/05 17:36:49 claudio Exp $ */
+/* $OpenBSD: mrt.c,v 1.63 2009/06/29 12:22:16 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -391,7 +391,7 @@ mrt_dump_done(void *ptr)
{
struct mrt *mrtbuf = ptr;
- mrtbuf->type = MRT_STATE_REMOVE;
+ mrtbuf->state = MRT_STATE_REMOVE;
}
int
@@ -585,7 +585,7 @@ mrt_open(struct mrt *mrt, time_t now)
return (1);
}
- if (MRT2MC(mrt)->state == MRT_STATE_OPEN)
+ if (mrt->state == MRT_STATE_OPEN)
type = IMSG_MRT_OPEN;
else
type = IMSG_MRT_REOPEN;
@@ -609,7 +609,7 @@ mrt_timeout(struct mrt_head *mrt)
now = time(NULL);
LIST_FOREACH(m, mrt, entry) {
- if (MRT2MC(m)->state == MRT_STATE_RUNNING &&
+ if (m->state == MRT_STATE_RUNNING &&
MRT2MC(m)->ReopenTimerInterval != 0) {
if (MRT2MC(m)->ReopenTimer <= now) {
mrt_open(m, now);
@@ -632,16 +632,16 @@ mrt_reconfigure(struct mrt_head *mrt)
now = time(NULL);
for (m = LIST_FIRST(mrt); m != NULL; m = xm) {
xm = LIST_NEXT(m, entry);
- if (MRT2MC(m)->state == MRT_STATE_OPEN ||
- MRT2MC(m)->state == MRT_STATE_REOPEN) {
+ if (m->state == MRT_STATE_OPEN ||
+ m->state == MRT_STATE_REOPEN) {
if (mrt_open(m, now) == -1)
continue;
if (MRT2MC(m)->ReopenTimerInterval != 0)
MRT2MC(m)->ReopenTimer =
now + MRT2MC(m)->ReopenTimerInterval;
- MRT2MC(m)->state = MRT_STATE_RUNNING;
+ m->state = MRT_STATE_RUNNING;
}
- if (MRT2MC(m)->state == MRT_STATE_REMOVE) {
+ if (m->state == MRT_STATE_REMOVE) {
LIST_REMOVE(m, entry);
free(m);
continue;
@@ -657,7 +657,7 @@ mrt_handler(struct mrt_head *mrt)
now = time(NULL);
LIST_FOREACH(m, mrt, entry) {
- if (MRT2MC(m)->state == MRT_STATE_RUNNING &&
+ if (m->state == MRT_STATE_RUNNING &&
(MRT2MC(m)->ReopenTimerInterval != 0 ||
m->type == MRT_TABLE_DUMP)) {
if (mrt_open(m, now) == -1)
@@ -696,7 +696,7 @@ mrt_mergeconfig(struct mrt_head *xconf, struct mrt_head *nconf)
if ((xm = calloc(1, sizeof(struct mrt_config))) == NULL)
fatal("mrt_mergeconfig");
memcpy(xm, m, sizeof(struct mrt_config));
- MRT2MC(xm)->state = MRT_STATE_OPEN;
+ xm->state = MRT_STATE_OPEN;
LIST_INSERT_HEAD(xconf, xm, entry);
} else {
/* MERGE */
@@ -706,14 +706,14 @@ mrt_mergeconfig(struct mrt_head *xconf, struct mrt_head *nconf)
fatalx("mrt_mergeconfig: strlcpy");
MRT2MC(xm)->ReopenTimerInterval =
MRT2MC(m)->ReopenTimerInterval;
- MRT2MC(xm)->state = MRT_STATE_REOPEN;
+ xm->state = MRT_STATE_REOPEN;
}
}
LIST_FOREACH(xm, xconf, entry)
if (mrt_get(nconf, xm) == NULL)
/* REMOVE */
- MRT2MC(xm)->state = MRT_STATE_REMOVE;
+ xm->state = MRT_STATE_REMOVE;
/* free config */
while ((m = LIST_FIRST(nconf)) != NULL) {
diff --git a/usr.sbin/bgpd/mrt.h b/usr.sbin/bgpd/mrt.h
index 136d84cd814..4f43cd99640 100644
--- a/usr.sbin/bgpd/mrt.h
+++ b/usr.sbin/bgpd/mrt.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mrt.h,v 1.22 2009/06/05 17:36:49 claudio Exp $ */
+/* $OpenBSD: mrt.h,v 1.23 2009/06/29 12:22:16 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -277,16 +277,16 @@ struct mrt {
u_int32_t peer_id;
u_int32_t group_id;
enum mrt_type type;
+ enum mrt_state state;
u_int16_t seqnum;
};
struct mrt_config {
struct mrt conf;
- time_t ReopenTimer;
- time_t ReopenTimerInterval;
- enum mrt_state state;
char name[MRT_FILE_LEN]; /* base file name */
char file[MRT_FILE_LEN]; /* actual file name */
+ time_t ReopenTimer;
+ time_t ReopenTimerInterval;
};
#define MRT2MC(x) ((struct mrt_config *)(x))
diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c
index 17d0ffbb0bd..05b378e06b1 100644
--- a/usr.sbin/bgpd/rde.c
+++ b/usr.sbin/bgpd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.263 2009/06/22 11:14:14 sthen Exp $ */
+/* $OpenBSD: rde.c,v 1.264 2009/06/29 12:22:16 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -120,8 +120,8 @@ struct rde_dump_ctx {
};
struct rde_mrt_ctx {
+ struct mrt mrt;
struct rib_context ribctx;
- struct mrt *mrt;
};
struct mrt_head rde_mrts = LIST_HEAD_INITIALIZER(rde_mrts);
@@ -332,7 +332,7 @@ rde_main(struct bgpd_config *config, struct peer *peer_l,
pfd[j].revents & POLLOUT)
mrt_write(mrt);
if (mrt->wbuf.queued == 0 &&
- mrt->type == MRT_STATE_REMOVE) {
+ mrt->state == MRT_STATE_REMOVE) {
close(mrt->wbuf.fd);
LIST_REMOVE(mrt, entry);
free(mrt);
@@ -1957,19 +1957,17 @@ rde_dump_mrt_new(struct mrt *mrt, pid_t pid, int fd)
struct rde_mrt_ctx *ctx;
u_int16_t id;
- if ((ctx = calloc(1, sizeof(*ctx))) == NULL ||
- (ctx->mrt = calloc(1, sizeof(struct mrt))) == NULL) {
+ if ((ctx = calloc(1, sizeof(*ctx))) == NULL) {
log_warn("rde_dump_mrt_new");
return;
}
- memcpy(ctx->mrt, mrt, sizeof(struct mrt));
- TAILQ_INIT(&ctx->mrt->wbuf.bufs);
- ctx->mrt->wbuf.fd = fd;
- ctx->mrt->type = MRT_STATE_RUNNING;
- id = rib_find(ctx->mrt->rib);
+ memcpy(&ctx->mrt, mrt, sizeof(struct mrt));
+ TAILQ_INIT(&ctx->mrt.wbuf.bufs);
+ ctx->mrt.wbuf.fd = fd;
+ ctx->mrt.state = MRT_STATE_RUNNING;
+ id = rib_find(ctx->mrt.rib);
if (id == RIB_FAILED) {
- log_warnx("non existing RIB %s for mrt dump", ctx->mrt->rib);
- free(ctx->mrt);
+ log_warnx("non existing RIB %s for mrt dump", ctx->mrt.rib);
free(ctx);
return;
}
@@ -1977,9 +1975,9 @@ rde_dump_mrt_new(struct mrt *mrt, pid_t pid, int fd)
ctx->ribctx.ctx_rib = &ribs[id];
ctx->ribctx.ctx_upcall = mrt_dump_upcall;
ctx->ribctx.ctx_done = mrt_dump_done;
- ctx->ribctx.ctx_arg = ctx->mrt;
+ ctx->ribctx.ctx_arg = &ctx->mrt;
ctx->ribctx.ctx_af = AF_UNSPEC;
- LIST_INSERT_HEAD(&rde_mrts, ctx->mrt, entry);
+ LIST_INSERT_HEAD(&rde_mrts, &ctx->mrt, entry);
rde_mrt_cnt++;
rib_dump_r(&ctx->ribctx);
}