diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2009-12-01 14:28:06 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2009-12-01 14:28:06 +0000 |
commit | d34d8813c5fa9b8031432c45c008b3a7a0d97441 (patch) | |
tree | 55c9c7d433f909d1af59bc9e1671cee07a80c7c3 /usr.sbin/bgpd/rde_rib.c | |
parent | d2eb742e2cf480aa441fc39d7cec70b5c3e71ca6 (diff) |
Use an artificial address family id in struct bgpd_addr and almost everywhere
else. Adds conversion functions to map AFI/SAFI and the Unix AF_ values
from and into AID used in bgpd. This is needed to support things like MPLS
VPN and other upcomming changes that need to play a lot with AFI/SAFI pairs.
Mostly mechanical change, henning@ has no particular issues with this.
Must go in so that I can continue working.
Diffstat (limited to 'usr.sbin/bgpd/rde_rib.c')
-rw-r--r-- | usr.sbin/bgpd/rde_rib.c | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c index 591d4e60936..1e0d8ddee11 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.117 2009/10/05 12:03:45 claudio Exp $ */ +/* $OpenBSD: rde_rib.c,v 1.118 2009/12/01 14:28:05 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> @@ -173,15 +173,15 @@ rib_lookup(struct rib *rib, struct bgpd_addr *addr) struct rib_entry *re; int i; - switch (addr->af) { - case AF_INET: + switch (addr->aid) { + case AID_INET: for (i = 32; i >= 0; i--) { re = rib_get(rib, addr, i); if (re != NULL) return (re); } break; - case AF_INET6: + case AID_INET6: for (i = 128; i >= 0; i--) { re = rib_get(rib, addr, i); if (re != NULL) @@ -280,7 +280,8 @@ rib_dump_r(struct rib_context *ctx) re = rib_restart(ctx); for (i = 0; re != NULL; re = RB_NEXT(rib_tree, unused, re)) { - if (ctx->ctx_af != AF_UNSPEC && ctx->ctx_af != re->prefix->af) + if (ctx->ctx_af != AF_UNSPEC && + ctx->ctx_af != aid2af(re->prefix->aid)) continue; if (ctx->ctx_count && i++ >= ctx->ctx_count && (re->flags & F_RIB_ENTRYLOCK) == 0) { @@ -632,11 +633,11 @@ prefix_compare(const struct bgpd_addr *a, const struct bgpd_addr *b, int i; u_int8_t m; - if (a->af != b->af) - return (a->af - b->af); + if (a->aid != b->aid) + return (a->aid - b->aid); - switch (a->af) { - case AF_INET: + switch (a->aid) { + case AID_INET: if (prefixlen > 32) fatalx("prefix_cmp: bad IPv4 prefixlen"); mask = htonl(prefixlen2mask(prefixlen)); @@ -645,7 +646,7 @@ prefix_compare(const struct bgpd_addr *a, const struct bgpd_addr *b, if (aa != ba) return (aa - ba); return (0); - case AF_INET6: + case AID_INET6: if (prefixlen > 128) fatalx("prefix_cmp: bad IPv6 prefixlen"); for (i = 0; i < prefixlen / 8; i++) @@ -806,7 +807,7 @@ prefix_write(u_char *buf, int len, struct bgpd_addr *prefix, u_int8_t plen) { int totlen; - if (prefix->af != AF_INET && prefix->af != AF_INET6) + if (prefix->aid != AID_INET && prefix->aid != AID_INET6) return (-1); totlen = PREFIX_SIZE(plen); @@ -1088,15 +1089,15 @@ nexthop_update(struct kroute_nexthop *msg) memcpy(&nh->true_nexthop, &msg->gateway, sizeof(nh->true_nexthop)); - switch (msg->nexthop.af) { - case AF_INET: + switch (msg->nexthop.aid) { + case AID_INET: nh->nexthop_netlen = msg->kr.kr4.prefixlen; - nh->nexthop_net.af = AF_INET; + nh->nexthop_net.aid = AID_INET; nh->nexthop_net.v4.s_addr = msg->kr.kr4.prefix.s_addr; break; - case AF_INET6: + case AID_INET6: nh->nexthop_netlen = msg->kr.kr6.prefixlen; - nh->nexthop_net.af = AF_INET6; + nh->nexthop_net.aid = AID_INET6; memcpy(&nh->nexthop_net.v6, &msg->kr.kr6.prefix, sizeof(struct in6_addr)); break; @@ -1118,7 +1119,7 @@ nexthop_update(struct kroute_nexthop *msg) void nexthop_modify(struct rde_aspath *asp, struct bgpd_addr *nexthop, - enum action_types type, sa_family_t af) + enum action_types type, u_int8_t aid) { struct nexthop *nh; @@ -1138,7 +1139,7 @@ nexthop_modify(struct rde_aspath *asp, struct bgpd_addr *nexthop, asp->flags |= F_NEXTHOP_SELF; return; } - if (af != nexthop->af) + if (aid != nexthop->aid) return; nh = nexthop_get(nexthop); @@ -1233,17 +1234,17 @@ nexthop_compare(struct nexthop *na, struct nexthop *nb) a = &na->exit_nexthop; b = &nb->exit_nexthop; - if (a->af != b->af) - return (a->af - b->af); + if (a->aid != b->aid) + return (a->aid - b->aid); - switch (a->af) { - case AF_INET: + switch (a->aid) { + case AID_INET: if (ntohl(a->v4.s_addr) > ntohl(b->v4.s_addr)) return (1); if (ntohl(a->v4.s_addr) < ntohl(b->v4.s_addr)) return (-1); return (0); - case AF_INET6: + case AID_INET6: return (memcmp(&a->v6, &b->v6, sizeof(struct in6_addr))); default: fatalx("nexthop_cmp: unknown af"); @@ -1269,13 +1270,13 @@ nexthop_hash(struct bgpd_addr *nexthop) { u_int32_t h = 0; - switch (nexthop->af) { - case AF_INET: + switch (nexthop->aid) { + case AID_INET: h = (AF_INET ^ ntohl(nexthop->v4.s_addr) ^ ntohl(nexthop->v4.s_addr) >> 13) & nexthoptable.nexthop_hashmask; break; - case AF_INET6: + case AID_INET6: h = hash32_buf(nexthop->v6.s6_addr, sizeof(struct in6_addr), HASHINIT) & nexthoptable.nexthop_hashmask; break; |