summaryrefslogtreecommitdiff
path: root/usr.sbin/ospf6d
diff options
context:
space:
mode:
authorStefan Sperling <stsp@cvs.openbsd.org>2009-03-12 01:21:50 +0000
committerStefan Sperling <stsp@cvs.openbsd.org>2009-03-12 01:21:50 +0000
commitdf1f1951ead3dc980478947ee0d01a380808b44b (patch)
treea7821d510c20774d42b72f9d43746daef3fcf158 /usr.sbin/ospf6d
parent16b28103432692f21f24ff02f6d001f50a29c7f3 (diff)
lsa_self() did too many things at once, and had too much logic
buried inside of it that its caller relied on. So split it up as follows: lsa_self() Check whether an LSA is self-originated. lsa_flush() Flush an LSA from the LSDB. lsa_reflood() Prepare an LSA for reflooding (actual reflooding currently requires sending an imsg which must be done by the caller). ok claudio@
Diffstat (limited to 'usr.sbin/ospf6d')
-rw-r--r--usr.sbin/ospf6d/rde.c19
-rw-r--r--usr.sbin/ospf6d/rde.h6
-rw-r--r--usr.sbin/ospf6d/rde_lsdb.c56
3 files changed, 42 insertions, 39 deletions
diff --git a/usr.sbin/ospf6d/rde.c b/usr.sbin/ospf6d/rde.c
index dab6850c231..c16e46aa1ae 100644
--- a/usr.sbin/ospf6d/rde.c
+++ b/usr.sbin/ospf6d/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.25 2009/03/07 00:33:13 stsp Exp $ */
+/* $OpenBSD: rde.c,v 1.26 2009/03/12 01:21:49 stsp Exp $ */
/*
* Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org>
@@ -429,10 +429,17 @@ rde_dispatch_imsg(int fd, short event, void *bula)
rde_req_list_del(nbr, &lsa->hdr);
- if (!(self = lsa_self(nbr, lsa, v)))
- if (lsa_add(nbr, lsa))
- /* delayed lsa */
- break;
+ self = lsa_self(lsa);
+ if (self) {
+ if (v == NULL)
+ /* LSA is no longer announced,
+ * remove by premature aging. */
+ lsa_flush(nbr, lsa);
+ else
+ lsa_reflood(v, lsa);
+ } else if (lsa_add(nbr, lsa))
+ /* delayed lsa, don't flood yet */
+ break;
/* flood and perhaps ack LSA */
imsg_compose(ibuf_ospfe, IMSG_LS_FLOOD,
@@ -444,7 +451,7 @@ rde_dispatch_imsg(int fd, short event, void *bula)
imsg_compose(ibuf_ospfe, IMSG_LS_FLOOD,
v->peerid, 0, v->lsa,
ntohs(v->lsa->hdr.len));
- /* lsa not added so free it */
+ /* new LSA was not added so free it */
if (self)
free(lsa);
} else if (r < 0) {
diff --git a/usr.sbin/ospf6d/rde.h b/usr.sbin/ospf6d/rde.h
index 33de3c2186f..cc9aa669a40 100644
--- a/usr.sbin/ospf6d/rde.h
+++ b/usr.sbin/ospf6d/rde.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.h,v 1.10 2009/03/07 00:33:13 stsp Exp $ */
+/* $OpenBSD: rde.h,v 1.11 2009/03/12 01:21:49 stsp Exp $ */
/*
* Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
@@ -137,7 +137,9 @@ int lsa_compare(struct vertex *, struct vertex *);
void vertex_free(struct vertex *);
int lsa_newer(struct lsa_hdr *, struct lsa_hdr *);
int lsa_check(struct rde_nbr *, struct lsa *, u_int16_t);
-int lsa_self(struct rde_nbr *, struct lsa *, struct vertex *);
+int lsa_self(struct lsa *);
+void lsa_flush(struct rde_nbr *, struct lsa *);
+void lsa_reflood(struct vertex *, struct lsa*);
int lsa_add(struct rde_nbr *, struct lsa *);
void lsa_del(struct rde_nbr *, struct lsa_hdr *);
void lsa_age(struct vertex *);
diff --git a/usr.sbin/ospf6d/rde_lsdb.c b/usr.sbin/ospf6d/rde_lsdb.c
index 8682ad2e77b..a44762c80e7 100644
--- a/usr.sbin/ospf6d/rde_lsdb.c
+++ b/usr.sbin/ospf6d/rde_lsdb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_lsdb.c,v 1.22 2009/03/10 17:36:39 stsp Exp $ */
+/* $OpenBSD: rde_lsdb.c,v 1.23 2009/03/12 01:21:49 stsp Exp $ */
/*
* Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org>
@@ -343,44 +343,38 @@ lsa_intra_a_pref_check(struct lsa *lsa, u_int16_t len)
}
int
-lsa_self(struct rde_nbr *nbr, struct lsa *new, struct vertex *v)
+lsa_self(struct lsa *lsa)
{
- struct lsa *dummy;
-
- if (nbr->self)
- return (0);
+ return rde_router_id() == lsa->hdr.adv_rtr;
+}
- if (rde_router_id() != new->hdr.adv_rtr)
- return (0);
+void
+lsa_flush(struct rde_nbr *nbr, struct lsa *lsa)
+{
+ struct lsa *copy;
- if (v == NULL) {
- /*
- * LSA is no longer announced, remove by premature aging.
- * The problem is that new may not be altered so a copy
- * needs to be added to the LSA DB first.
- */
- if ((dummy = malloc(ntohs(new->hdr.len))) == NULL)
- fatal("lsa_self");
- memcpy(dummy, new, ntohs(new->hdr.len));
- dummy->hdr.age = htons(MAX_AGE);
- /*
- * The clue is that by using the remote nbr as originator
- * the dummy LSA will be reflooded via the default timeout
- * handler.
- */
- (void)lsa_add(rde_nbr_self(nbr->area), dummy);
- return (1);
- }
+ /*
+ * The LSA may not be altered because the caller may still
+ * use it, so a copy needs to be added to the LSDB.
+ * The copy will be reflooded via the default timeout handler.
+ */
+ if ((copy = malloc(ntohs(lsa->hdr.len))) == NULL)
+ fatal("lsa_flush");
+ memcpy(copy, lsa, ntohs(lsa->hdr.len));
+ copy->hdr.age = htons(MAX_AGE);
+ (void)lsa_add(rde_nbr_self(nbr->area), copy);
+}
+void
+lsa_reflood(struct vertex *v, struct lsa *new)
+{
/*
- * LSA is still originated, just reflood it. But we need to create
- * a new instance by setting the LSA sequence number equal to the
- * one of new and calling lsa_refresh(). Flooding will be done by the
- * caller.
+ * We only need to create a new instance by setting the LSA
+ * sequence number equal to the one of 'new' and calling
+ * lsa_refresh(). Actual flooding will be done by the caller.
*/
v->lsa->hdr.seq_num = new->hdr.seq_num;
lsa_refresh(v);
- return (1);
}
int