summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2004-06-22 23:17:02 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2004-06-22 23:17:02 +0000
commita5792356458a7ed9bb6a7d4aa578b74e9d704e84 (patch)
treeed995dba9221ec1a7eb602a73dea47596aa75f2f /usr.sbin
parente571f429990f72a4fbb0354747f839894d4c77c0 (diff)
Cleanup. jajaja henning@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/bgpd/rde.c29
-rw-r--r--usr.sbin/bgpd/rde_attr.c78
-rw-r--r--usr.sbin/bgpd/rde_decide.c14
-rw-r--r--usr.sbin/bgpd/rde_prefix.c11
-rw-r--r--usr.sbin/bgpd/rde_rib.c29
-rw-r--r--usr.sbin/bgpd/rde_update.c40
6 files changed, 83 insertions, 118 deletions
diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c
index 24d229c0403..1529b8dfb31 100644
--- a/usr.sbin/bgpd/rde.c
+++ b/usr.sbin/bgpd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.118 2004/06/22 20:28:58 claudio Exp $ */
+/* $OpenBSD: rde.c,v 1.119 2004/06/22 23:17:01 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -29,7 +29,6 @@
#include <unistd.h>
#include "bgpd.h"
-#include "ensure.h"
#include "mrt.h"
#include "rde.h"
#include "session.h"
@@ -689,7 +688,6 @@ rde_reflector(struct rde_peer *peer, struct attr_flags *attrs)
/* check for originator id if eq router_id drop */
if ((a = attr_optget(attrs, ATTR_ORIGINATOR_ID)) != NULL) {
- ENSURE(a->len == 4);
if (memcmp(&conf->bgpid, a->data, sizeof(conf->bgpid)) == 0)
/* this is comming from myself */
return (0);
@@ -814,7 +812,6 @@ rde_dump_as(struct as_filter *a, pid_t pid)
if (!aspath_match(asp->flags.aspath, a->type, a->as))
continue;
/* match found */
- ENSURE(!path_empty(asp));
rde_dump_rib_as(LIST_FIRST(&asp->prefix_h), pid);
for (p = LIST_NEXT(LIST_FIRST(&asp->prefix_h), path_l);
p != NULL; p = LIST_NEXT(p, path_l))
@@ -876,8 +873,6 @@ rde_send_kroute(struct prefix *new, struct prefix *old)
struct prefix *p;
enum imsg_type type;
- ENSURE(old == NULL || old->aspath->nexthop != NULL);
- ENSURE(new == NULL || new->aspath->nexthop != NULL);
/*
* If old is != NULL we know it was active and should be removed.
* On the other hand new may be UNREACH and then we should not
@@ -966,8 +961,6 @@ rde_generate_updates(struct prefix *new, struct prefix *old)
{
struct rde_peer *peer;
- ENSURE(old == NULL || old->aspath->nexthop != NULL);
- ENSURE(new == NULL || new->aspath->nexthop != NULL);
/*
* If old is != NULL we know it was active and should be removed.
* On the other hand new may be UNREACH and then we should not
@@ -1091,13 +1084,12 @@ peer_get(u_int32_t id)
struct rde_peer *peer;
head = PEER_HASH(id);
- ENSURE(head != NULL);
LIST_FOREACH(peer, head, hash_l) {
if (peer->conf.id == id)
- return peer;
+ return (peer);
}
- return NULL;
+ return (NULL);
}
struct rde_peer *
@@ -1106,7 +1098,8 @@ peer_add(u_int32_t id, struct peer_config *p_conf)
struct rde_peer_head *head;
struct rde_peer *peer;
- ENSURE(peer_get(id) == NULL);
+ if (peer_get(id))
+ return (NULL);
peer = calloc(1, sizeof(struct rde_peer));
if (peer == NULL)
@@ -1119,7 +1112,6 @@ peer_add(u_int32_t id, struct peer_config *p_conf)
up_init(peer);
head = PEER_HASH(id);
- ENSURE(head != NULL);
LIST_INSERT_HEAD(head, peer, hash_l);
LIST_INSERT_HEAD(&peerlist, peer, peer_l);
@@ -1130,10 +1122,6 @@ peer_add(u_int32_t id, struct peer_config *p_conf)
void
peer_remove(struct rde_peer *peer)
{
- ENSURE(peer->state == PEER_DOWN);
- ENSURE(peer_get(peer->conf.id) != NULL);
- ENSURE(LIST_EMPTY(&peer->path_h));
-
LIST_REMOVE(peer, hash_l);
LIST_REMOVE(peer, peer_l);
@@ -1147,11 +1135,12 @@ peer_up(u_int32_t id, struct session_up *sup)
peer = peer_add(id, &sup->conf);
if (peer == NULL) {
- log_warnx("peer_up: unknown peer id %d", id);
+ log_warnx("peer_up: peer id %d already exists", id);
return;
}
- ENSURE(peer->state == PEER_DOWN || peer->state == PEER_NONE);
+ if (peer->state != PEER_DOWN && peer->state != PEER_NONE)
+ fatalx("peer_up: bad state");
peer->remote_bgpid = ntohl(sup->remote_bgpid);
memcpy(&peer->local_addr, &sup->local_addr, sizeof(peer->local_addr));
memcpy(&peer->remote_addr, &sup->remote_addr,
@@ -1326,7 +1315,6 @@ rde_shutdown(void)
* the decision process is turend of if rde_quit = 1 and
* rde_shutdown depends on this.
*/
- ENSURE(rde_quit != 0);
/* First mark all peer as down */
for (i = 0; i <= peertable.peer_hashmask; i++)
@@ -1346,6 +1334,7 @@ rde_shutdown(void)
nasp = LIST_NEXT(asp, peer_l);
path_remove(asp);
}
+ LIST_INIT(&p->path_h);
/* finally remove peer */
peer_remove(p);
}
diff --git a/usr.sbin/bgpd/rde_attr.c b/usr.sbin/bgpd/rde_attr.c
index 8ebd7befa8f..8f864236f34 100644
--- a/usr.sbin/bgpd/rde_attr.c
+++ b/usr.sbin/bgpd/rde_attr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_attr.c,v 1.32 2004/06/20 18:35:12 henning Exp $ */
+/* $OpenBSD: rde_attr.c,v 1.33 2004/06/22 23:17:01 claudio Exp $ */
/*
* Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
@@ -342,15 +342,15 @@ u_int8_t
attr_missing(struct attr_flags *a, int ebgp)
{
if ((a->wflags & F_ATTR_ORIGIN) == 0)
- return ATTR_ORIGIN;
+ return (ATTR_ORIGIN);
if ((a->wflags & F_ATTR_ASPATH) == 0)
- return ATTR_ASPATH;
+ return (ATTR_ASPATH);
if ((a->wflags & F_ATTR_NEXTHOP) == 0)
- return ATTR_NEXTHOP;
+ return (ATTR_NEXTHOP);
if (!ebgp)
if ((a->wflags & F_ATTR_LOCALPREF) == 0)
- return ATTR_LOCALPREF;
- return 0;
+ return (ATTR_LOCALPREF);
+ return (0);
}
int
@@ -560,13 +560,11 @@ aspath_extract(void *seg, int pos)
u_char *ptr = seg;
u_int16_t as = 0;
- ENSURE(0 <= pos && pos < 255);
-
ptr += 2 + 2 * pos;
as = *ptr++;
as <<= 8;
as |= *ptr;
- return as;
+ return (as);
}
int
@@ -578,24 +576,27 @@ aspath_verify(void *data, u_int16_t len)
if (len & 1)
/* odd length aspath are invalid */
- return AS_ERR_BAD;
+ return (AS_ERR_BAD);
for (; len > 0; len -= seg_size, seg += seg_size) {
+ if (len < 2)
+ return (AS_ERR_BAD);
seg_type = seg[0];
seg_len = seg[1];
- if (seg_type != AS_SET && seg_type != AS_SEQUENCE) {
- return AS_ERR_TYPE;
- }
+
+ if (seg_type != AS_SET && seg_type != AS_SEQUENCE)
+ return (AS_ERR_TYPE);
+
seg_size = 2 + 2 * seg_len;
if (seg_size > len)
- return AS_ERR_LEN;
+ return (AS_ERR_LEN);
if (seg_size == 0)
/* empty aspath segment are not allowed */
- return AS_ERR_BAD;
+ return (AS_ERR_BAD);
}
- return 0; /* aspath is valid but probably not loop free */
+ return (0); /* aspath is valid but probably not loop free */
}
struct aspath *
@@ -613,7 +614,7 @@ aspath_create(void *data, u_int16_t len)
aspath->hdr.as_cnt = aspath_count(aspath);
aspath->hdr.prepend = 0;
- return aspath;
+ return (aspath);
}
int
@@ -633,7 +634,8 @@ aspath_write(void *p, u_int16_t len, struct aspath *aspath, u_int16_t myAS,
/* first calculate new size */
if (aspath->hdr.len > 0) {
- ENSURE(aspath->hdr.len > 2);
+ if (aspath->hdr.len < 2)
+ return (-1);
type = aspath->data[0];
size = aspath->data[1];
} else {
@@ -712,13 +714,13 @@ aspath_destroy(struct aspath *aspath)
u_char *
aspath_dump(struct aspath *aspath)
{
- return aspath->data;
+ return (aspath->data);
}
u_int16_t
aspath_length(struct aspath *aspath)
{
- return aspath->hdr.len;
+ return (aspath->hdr.len);
}
u_int16_t
@@ -733,7 +735,6 @@ aspath_count(struct aspath *aspath)
for (len = aspath->hdr.len; len > 0; len -= seg_size, seg += seg_size) {
seg_type = seg[0];
seg_len = seg[1];
- ENSURE(seg_type == AS_SET || seg_type == AS_SEQUENCE);
seg_size = 2 + 2 * seg_len;
if (seg_type == AS_SET)
@@ -741,7 +742,7 @@ aspath_count(struct aspath *aspath)
else
cnt += seg_len;
}
- return cnt;
+ return (cnt);
}
u_int16_t
@@ -754,10 +755,9 @@ aspath_neighbor(struct aspath *aspath)
*/
if (aspath->hdr.len == 0)
- return 0;
+ return (0);
- ENSURE(aspath->hdr.len > 2);
- return aspath_extract(aspath->data, 0);
+ return (aspath_extract(aspath->data, 0));
}
int
@@ -771,16 +771,14 @@ aspath_loopfree(struct aspath *aspath, u_int16_t myAS)
for (len = aspath->hdr.len; len > 0; len -= seg_size, seg += seg_size) {
seg_type = seg[0];
seg_len = seg[1];
- ENSURE(seg_type == AS_SET || seg_type == AS_SEQUENCE);
seg_size = 2 + 2 * seg_len;
- ENSURE(seg_size <= len);
for (i = 0; i < seg_len; i++) {
if (myAS == aspath_extract(seg, i))
- return 0;
+ return (0);
}
}
- return 1;
+ return (1);
}
#define AS_HASH_INITIAL 8271
@@ -798,16 +796,14 @@ aspath_hash(struct aspath *aspath)
for (len = aspath->hdr.len; len > 0; len -= seg_size, seg += seg_size) {
seg_type = seg[0];
seg_len = seg[1];
- ENSURE(seg_type == AS_SET || seg_type == AS_SEQUENCE);
seg_size = 2 + 2 * seg_len;
- ENSURE(seg_size <= len);
for (i = 0; i < seg_len; i++) {
hash += (hash << 5);
hash ^= aspath_extract(seg, i);
}
}
- return hash;
+ return (hash);
}
int
@@ -824,7 +820,7 @@ aspath_compare(struct aspath *a1, struct aspath *a2)
return (1);
if (r < 0)
return (-1);
- return 0;
+ return (0);
}
int
@@ -853,7 +849,6 @@ aspath_snprint(char *buf, size_t size, void *data, u_int16_t len)
for (; len > 0; len -= seg_size, seg += seg_size) {
seg_type = seg[0];
seg_len = seg[1];
- ENSURE(seg_type == AS_SET || seg_type == AS_SEQUENCE);
seg_size = 2 + 2 * seg_len;
if (seg_type == AS_SET) {
@@ -867,7 +862,6 @@ aspath_snprint(char *buf, size_t size, void *data, u_int16_t len)
UPDATE();
}
- ENSURE(seg_size <= len);
for (i = 0; i < seg_len; i++) {
r = snprintf(buf, size, "%hu", aspath_extract(seg, i));
UPDATE();
@@ -885,7 +879,7 @@ aspath_snprint(char *buf, size_t size, void *data, u_int16_t len)
if (size > 0)
*buf = '\0';
- return total_size;
+ return (total_size);
#undef UPDATE
}
@@ -899,7 +893,6 @@ aspath_asprint(char **ret, void *data, u_int16_t len)
if (*ret == NULL)
return (-1);
plen = aspath_snprint(*ret, slen, data, len);
- ENSURE(plen < slen);
return (plen);
}
@@ -917,7 +910,6 @@ aspath_strlen(void *data, u_int16_t len)
for (; len > 0; len -= seg_size, seg += seg_size) {
seg_type = seg[0];
seg_len = seg[1];
- ENSURE(seg_type == AS_SET || seg_type == AS_SEQUENCE);
seg_size = 2 + 2 * seg_len;
if (seg_type == AS_SET)
@@ -928,7 +920,6 @@ aspath_strlen(void *data, u_int16_t len)
else if (total_size != 0)
total_size += 1;
- ENSURE(seg_size <= len);
for (i = 0; i < seg_len; i++) {
as = aspath_extract(seg, i);
if (as >= 10000)
@@ -949,7 +940,7 @@ aspath_strlen(void *data, u_int16_t len)
if (seg_type == AS_SET)
total_size += 2;
}
- return total_size;
+ return (total_size);
}
/* we need to be able to search more than one as */
@@ -973,7 +964,6 @@ aspath_match(struct aspath *a, enum as_spec type, u_int16_t as)
for (len = a->hdr.len; len > 0; len -= seg_size, seg += seg_size) {
seg_type = seg[0];
seg_len = seg[1];
- ENSURE(seg_type == AS_SET || seg_type == AS_SEQUENCE);
seg_size = 2 + 2 * seg_len;
final = (len == seg_size);
@@ -982,7 +972,6 @@ aspath_match(struct aspath *a, enum as_spec type, u_int16_t as)
/* not yet in the final segment */
continue;
- ENSURE(seg_size <= len);
for (i = 0; i < seg_len; i++)
if (as == aspath_extract(seg, i)) {
if (final && i + 1 >= seg_len)
@@ -1004,7 +993,6 @@ community_match(void *data, u_int16_t len, int as, int type)
u_int8_t *p = data;
u_int16_t eas, etype;
- ENSURE((len & 0x3) == 0);
len >>= 2; /* divide by four */
for (; len > 0; len--) {
@@ -1016,9 +1004,9 @@ community_match(void *data, u_int16_t len, int as, int type)
etype |= *p++;
if ((as == COMMUNITY_ANY || (u_int16_t)as == eas) &&
(type == COMMUNITY_ANY || type == etype))
- return 1;
+ return (1);
}
- return 0;
+ return (0);
}
int
diff --git a/usr.sbin/bgpd/rde_decide.c b/usr.sbin/bgpd/rde_decide.c
index 8f4f3c24fb7..770a4aefd4f 100644
--- a/usr.sbin/bgpd/rde_decide.c
+++ b/usr.sbin/bgpd/rde_decide.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_decide.c,v 1.34 2004/04/26 00:46:52 claudio Exp $ */
+/* $OpenBSD: rde_decide.c,v 1.35 2004/06/22 23:17:01 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -23,7 +23,6 @@
#include <string.h>
#include "bgpd.h"
-#include "ensure.h"
#include "rde.h"
int prefix_cmp(struct prefix *, struct prefix *);
@@ -112,7 +111,8 @@ prefix_cmp(struct prefix *p1, struct prefix *p2)
{
struct rde_aspath *asp1, *asp2;
- ENSURE(p1 != NULL);
+ if (p1 == NULL)
+ return (-1);
/* p2 is allowed to be NULL */
if (p2 == NULL)
@@ -121,7 +121,6 @@ prefix_cmp(struct prefix *p1, struct prefix *p2)
asp1 = p1->aspath;
asp2 = p2->aspath;
/* 1. check if prefix is eligible a.k.a reachable */
- ENSURE(asp2->nexthop != NULL && asp1->nexthop != NULL);
if (asp2->nexthop->state != NEXTHOP_REACH)
return (1);
@@ -219,11 +218,8 @@ prefix_evaluate(struct prefix *p, struct pt_entry *pte)
xp = LIST_FIRST(&pte->prefix_h);
if (pte->active != xp) {
/* need to generate an update */
- if (pte->active != NULL) {
- ENSURE(pte->active->aspath != NULL);
- ENSURE(pte->active->aspath->active_cnt > 0);
+ if (pte->active != NULL)
pte->active->aspath->active_cnt--;
- }
/*
* Send update with remove for pte->active and add for xp
@@ -241,8 +237,6 @@ prefix_evaluate(struct prefix *p, struct pt_entry *pte)
else {
pte->active = xp;
pte->active->aspath->active_cnt++;
- ENSURE(pte->active->aspath->active_cnt <=
- pte->active->aspath->prefix_cnt);
}
}
}
diff --git a/usr.sbin/bgpd/rde_prefix.c b/usr.sbin/bgpd/rde_prefix.c
index d58245a7cc0..22622d61a99 100644
--- a/usr.sbin/bgpd/rde_prefix.c
+++ b/usr.sbin/bgpd/rde_prefix.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_prefix.c,v 1.14 2004/06/22 20:28:58 claudio Exp $ */
+/* $OpenBSD: rde_prefix.c,v 1.15 2004/06/22 23:17:01 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -95,7 +95,6 @@ pt_shutdown(void)
int
pt_empty(struct pt_entry *pte)
{
- ENSURE(pte != NULL);
return LIST_EMPTY(&pte->prefix_h);
}
@@ -269,13 +268,6 @@ pt_prefix_cmp(const struct pt_entry *a, const struct pt_entry *b)
const struct pt_entry6 *a6, *b6;
int i;
- if (a == NULL)
- return (1);
- if (b == NULL)
- return (-1);
-
- if (a->af != b->af)
- log_debug("af non equal a %d b %d\n", a->af, b->af);
ENSURE(a->af == b->af);
switch (a->af) {
@@ -305,7 +297,6 @@ pt_prefix_cmp(const struct pt_entry *a, const struct pt_entry *b)
if (a6->prefixlen > b6->prefixlen)
return (1);
return (0);
-
default:
fatalx("pt_prefix_cmp: unknown af");
}
diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c
index c93d0498631..c195644b50f 100644
--- a/usr.sbin/bgpd/rde_rib.c
+++ b/usr.sbin/bgpd/rde_rib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_rib.c,v 1.48 2004/06/22 20:28:58 claudio Exp $ */
+/* $OpenBSD: rde_rib.c,v 1.49 2004/06/22 23:17:01 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -148,7 +148,6 @@ path_get(struct aspath *aspath, struct rde_peer *peer)
RIB_STAT(path_get);
head = PATH_HASH(aspath);
- ENSURE(head != NULL);
LIST_FOREACH(asp, head, path_l) {
if (aspath_compare(asp->flags.aspath, aspath) == 0 &&
@@ -164,7 +163,6 @@ path_add(struct rde_peer *peer, struct attr_flags *attr)
struct rde_aspath *asp;
RIB_STAT(path_add);
- ENSURE(peer != NULL);
asp = path_alloc();
@@ -220,8 +218,6 @@ path_destroy(struct rde_aspath *asp)
int
path_empty(struct rde_aspath *asp)
{
- ENSURE(asp != NULL);
-
return LIST_EMPTY(&asp->prefix_h);
}
@@ -240,13 +236,11 @@ path_link(struct rde_aspath *asp, struct rde_peer *peer)
RIB_STAT(path_link);
head = PATH_HASH(asp->flags.aspath);
- ENSURE(head != NULL);
LIST_INSERT_HEAD(head, asp, path_l);
LIST_INSERT_HEAD(&peer->path_h, asp, peer_l);
asp->peer = peer;
- ENSURE(asp->nexthop == NULL);
nexthop_add(asp);
}
@@ -310,7 +304,6 @@ prefix_get(struct rde_aspath *asp, struct bgpd_addr *prefix, int prefixlen)
struct bgpd_addr addr;
RIB_STAT(prefix_get);
- ENSURE(asp != NULL);
LIST_FOREACH(p, &asp->prefix_h, path_l) {
ENSURE(p->prefix != NULL);
@@ -403,8 +396,6 @@ prefix_move(struct rde_aspath *asp, struct prefix *p)
/* remove old prefix node */
oasp = p->aspath;
LIST_REMOVE(p, path_l);
- ENSURE(oasp->prefix_cnt > 0);
- ENSURE(oasp->peer->prefix_cnt > 0);
oasp->prefix_cnt--;
/* as before peer count needs no update because of move */
@@ -464,8 +455,6 @@ prefix_bypeer(struct pt_entry *pte, struct rde_peer *peer)
{
struct prefix *p;
- ENSURE(pte != NULL);
-
LIST_FOREACH(p, &pte->prefix_h, prefix_l) {
if (p->aspath->peer == peer)
return p;
@@ -479,7 +468,6 @@ prefix_updateall(struct rde_aspath *asp, enum nexthop_state state)
struct prefix *p;
RIB_STAT(prefix_updateall);
- ENSURE(asp != NULL);
if (rde_noevaluate())
/* if the decision process is turned off this is a no-op */
@@ -553,7 +541,6 @@ prefix_link(struct prefix *pref, struct pt_entry *pte, struct rde_aspath *asp)
RIB_STAT(prefix_link);
ENSURE(pref->aspath == NULL &&
pref->prefix == NULL);
- ENSURE(pref != NULL && pte != NULL && asp != NULL);
ENSURE(prefix_bypeer(pte, asp->peer) == NULL);
LIST_INSERT_HEAD(&asp->prefix_h, pref, path_l);
@@ -576,16 +563,12 @@ static void
prefix_unlink(struct prefix *pref)
{
RIB_STAT(prefix_unlink);
- ENSURE(pref != NULL);
- ENSURE(pref->prefix != NULL && pref->aspath != NULL);
/* make route decision */
LIST_REMOVE(pref, prefix_l);
prefix_evaluate(NULL, pref->prefix);
LIST_REMOVE(pref, path_l);
- ENSURE(pref->aspath->prefix_cnt > 0);
- ENSURE(pref->aspath->peer->prefix_cnt > 0);
pref->aspath->prefix_cnt--;
pref->aspath->peer->prefix_cnt--;
@@ -722,7 +705,6 @@ nexthop_add(struct rde_aspath *asp)
struct nexthop *nh;
RIB_STAT(nexthop_add);
- ENSURE(asp != NULL);
if ((nh = asp->nexthop) == NULL)
nh = nexthop_get(asp->flags.nexthop);
@@ -745,7 +727,6 @@ nexthop_remove(struct rde_aspath *asp)
struct nexthop *nh;
RIB_STAT(nexthop_remove);
- ENSURE(asp != NULL);
LIST_REMOVE(asp, nexthop_l);
@@ -790,7 +771,13 @@ nexthop_update(struct kroute_nexthop *msg)
log_warnx("nexthop_update: non-existent nexthop");
return;
}
- ENSURE(nh->exit_nexthop.v4.s_addr == msg->nexthop.v4.s_addr);
+ /* should I trust in the parent ??? */
+ if (nh->exit_nexthop.af != msg->nexthop.af ||
+ (nh->exit_nexthop.af == AF_INET &&
+ nh->exit_nexthop.v4.s_addr != msg->nexthop.v4.s_addr)) {
+ log_warnx("nexthop_update: bad nexthop returned");
+ return;
+ }
if (msg->valid)
nh->state = NEXTHOP_REACH;
diff --git a/usr.sbin/bgpd/rde_update.c b/usr.sbin/bgpd/rde_update.c
index 88adabcc2b9..653dd617244 100644
--- a/usr.sbin/bgpd/rde_update.c
+++ b/usr.sbin/bgpd/rde_update.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_update.c,v 1.20 2004/06/22 20:28:58 claudio Exp $ */
+/* $OpenBSD: rde_update.c,v 1.21 2004/06/22 23:17:01 claudio Exp $ */
/*
* Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
@@ -22,7 +22,6 @@
#include <string.h>
#include "bgpd.h"
-#include "ensure.h"
#include "rde.h"
int up_generate_attr(struct rde_peer *, struct update_attr *,
@@ -106,12 +105,31 @@ up_down(struct rde_peer *peer)
int
up_prefix_cmp(struct update_prefix *a, struct update_prefix *b)
{
- ENSURE(a->prefix.af == AF_INET);
+ int i;
- if (ntohl(a->prefix.v4.s_addr) < ntohl(b->prefix.v4.s_addr))
+ if (a->prefix.af < b->prefix.af)
return (-1);
- if (ntohl(a->prefix.v4.s_addr) > ntohl(b->prefix.v4.s_addr))
+ if (a->prefix.af > b->prefix.af)
return (1);
+
+ switch (a->prefix.af) {
+ case AF_INET:
+ if (ntohl(a->prefix.v4.s_addr) < ntohl(b->prefix.v4.s_addr))
+ return (-1);
+ if (ntohl(a->prefix.v4.s_addr) > ntohl(b->prefix.v4.s_addr))
+ return (1);
+ break;
+ case AF_INET6:
+ i = memcmp(&a->prefix.v6, &b->prefix.v6,
+ sizeof(struct in6_addr));
+ if (i > 0)
+ return (1);
+ if (i < 0)
+ return (-1);
+ break;
+ default:
+ fatalx("pt_prefix_cmp: unknown af");
+ }
if (a->prefixlen < b->prefixlen)
return (-1);
if (a->prefixlen > b->prefixlen)
@@ -139,8 +157,6 @@ up_add(struct rde_peer *peer, struct update_prefix *p, struct update_attr *a)
struct update_attr *na = NULL;
struct update_prefix *np;
- ENSURE(p != NULL);
-
/* 1. search for attr */
if (a != NULL && (na = RB_FIND(uptree_attr, &peer->up_attrs, a)) ==
NULL) {
@@ -215,7 +231,8 @@ up_generate_updates(struct rde_peer *peer,
struct attr_flags attrs;
struct bgpd_addr addr;
- ENSURE(peer->state == PEER_UP);
+ if (peer->state != PEER_UP)
+ return;
/*
* Filtering should be hooked up here.
* With filtering the decision if withdraw, update or nothing
@@ -293,7 +310,6 @@ up_generate_updates(struct rde_peer *peer,
*/
if ((atr = attr_optget(&old->aspath->flags,
ATTR_ORIGINATOR_ID)) != NULL) {
- ENSURE(atr->len == 4);
if (memcmp(atr->data, &peer->remote_bgpid,
sizeof(peer->remote_bgpid)) == 0)
/* would cause loop don't send */
@@ -411,7 +427,6 @@ up_generate_updates(struct rde_peer *peer,
*/
if ((atr = attr_optget(&new->aspath->flags,
ATTR_ORIGINATOR_ID)) != NULL) {
- ENSURE(atr->len == 4);
if (memcmp(atr->data, &peer->remote_bgpid,
sizeof(peer->remote_bgpid)) == 0) {
/* would cause loop don't send */
@@ -600,8 +615,9 @@ up_set_prefix(u_char *buf, int len, struct bgpd_addr *prefix, u_int8_t plen)
{
int totlen;
- ENSURE(prefix->af == AF_INET);
- ENSURE(plen <= 32);
+ if (prefix->af != AF_INET)
+ return (-1);
+
totlen = (plen + 7) / 8 + 1;
if (totlen > len)