Update to 4.6.20100215.

Feature safe:	yes
This commit is contained in:
Hiroki Sato 2010-02-16 19:27:03 +00:00
parent 888120ca23
commit 7ab9a19af6
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=249966
51 changed files with 6804 additions and 8082 deletions

View file

@ -6,11 +6,11 @@
# #
PORTNAME= openbgpd PORTNAME= openbgpd
PORTVERSION= 4.5.20091022 PORTVERSION= 4.6.20100215
CATEGORIES= net CATEGORIES= net
MASTER_SITES= ${MASTER_SITE_OPENBSD} MASTER_SITES= ${MASTER_SITE_OPENBSD}
MASTER_SITE_SUBDIR= OpenBGPD MASTER_SITE_SUBDIR= OpenBGPD
DISTNAME= ${PORTNAME}-4.4.1 DISTNAME= ${PORTNAME}-4.6
EXTRACT_SUFX= .tgz EXTRACT_SUFX= .tgz
DIST_SUBDIR= ${PORTNAME} DIST_SUBDIR= ${PORTNAME}

View file

@ -1,12 +1,3 @@
MD5 (openbgpd/openbgpd-4.4.1.tgz) = 5ac036b2ca2905a7efe2e0364aef00e7 MD5 (openbgpd/openbgpd-4.6.tgz) = 846feb4de328e7d47526a83087000863
SHA256 (openbgpd/openbgpd-4.4.1.tgz) = 284406daa359bf1e9386e5055a1803453d04fd9c9ef5479ac324c8d1eebc33a4 SHA256 (openbgpd/openbgpd-4.6.tgz) = d9a0a3542e5ec744889ca12871f01aa1d86f12844e093010f37d0601796e15cf
SIZE (openbgpd/openbgpd-4.4.1.tgz) = 163070 SIZE (openbgpd/openbgpd-4.6.tgz) = 168197
MD5 (openbgpd/if_media.h) = 4ff9297f5c133425dafe3ca565c0f811
SHA256 (openbgpd/if_media.h) = 58225d0ed363c2beb23426f0f8254089d4541c3334776f3750ba434d4491a1d1
SIZE (openbgpd/if_media.h) = 23762
MD5 (openbgpd/hash.h) = 0c397692b9b152f1bca968b6248bc09c
SHA256 (openbgpd/hash.h) = 0c5561c6765325f49d82d5c5fd9471dbfadf21f44e554758eb112a23f7c317b1
SIZE (openbgpd/hash.h) = 3488
MD5 (openbgpd/strtonum.c) = da3ba14723ae645c13b8ea96d3f78f20
SHA256 (openbgpd/strtonum.c) = eabeece529ed7678b5d79774813818ed1d46b7c7a934c98e474c8f62c56abaec
SIZE (openbgpd/strtonum.c) = 1769

View file

@ -1,6 +0,0 @@
--- /dev/null 2009-06-24 01:22:00.000000000 +0900
+++ bgpctl/compat-openbsd.h 2009-06-24 01:24:55.000000000 +0900
@@ -0,0 +1,3 @@
+#include <sys/endian.h>
+
+#define betoh64(x) (be64toh(x))

View file

@ -1,14 +1,14 @@
Index: bgpctl/bgpctl.8 Index: bgpctl/bgpctl.8
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpctl/bgpctl.8,v RCS file: /home/cvs/private/hrs/openbgpd/bgpctl/bgpctl.8,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.6
retrieving revision 1.3 retrieving revision 1.4
diff -u -p -r1.1.1.1 -r1.3 diff -u -p -r1.1.1.6 -r1.4
--- bgpctl/bgpctl.8 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpctl/bgpctl.8 14 Feb 2010 20:20:13 -0000 1.1.1.6
+++ bgpctl/bgpctl.8 9 Jul 2009 17:22:12 -0000 1.3 +++ bgpctl/bgpctl.8 4 Feb 2010 16:22:26 -0000 1.4
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-.\" $OpenBSD: bgpctl.8,v 1.47 2008/06/07 18:14:41 henning Exp $ -.\" $OpenBSD: bgpctl.8,v 1.49 2009/06/06 06:11:17 claudio Exp $
+.\" $OpenBSD: bgpctl.8,v 1.49 2009/06/06 06:11:17 claudio Exp $ +.\" $OpenBSD: bgpctl.8,v 1.52 2009/11/03 08:09:15 jmc Exp $
.\" .\"
.\" Copyright (c) 2003 Henning Brauer <henning@openbsd.org> .\" Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
.\" .\"
@ -16,30 +16,28 @@ diff -u -p -r1.1.1.1 -r1.3
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
-.Dd $Mdocdate: June 7 2008 $ -.Dd $Mdocdate: June 6 2009 $
+.Dd $Mdocdate: December 6 2008 $ +.Dd $Mdocdate: November 2 2009 $
.Dt BGPCTL 8 .Dt BGPCTL 8
.Os .Os
.Sh NAME .Sh NAME
@@ -25,7 +25,7 @@ @@ -79,7 +79,15 @@ The options are as follows:
.Op Fl n Use
.Op Fl s Ar socket .Ar directory
.Ar command to write the filter files to.
-.Op Ar arguments ... +.It Fl 4
+.Op Ar argument ... +Fetch only IPv4 prefixes from the registry.
.Sh DESCRIPTION +.It Fl 6
The +Fetch only IPv6 prefixes from the registry.
.Nm .El
@@ -202,6 +202,8 @@ Show all entries with community +.It Cm log brief
.Ar community . +Disable verbose debug logging.
.It Cm neighbor Ar peer +.It Cm log verbose
Show only entries from the specified peer. +Enable verbose debug logging.
+.It Cm table Ar rib .It Cm neighbor Ar peer Cm up
+Show only entries from the specified RIB table. Take the BGP session to the specified neighbor up.
.It Cm summary .Ar peer
This is the same as the @@ -246,7 +254,7 @@ in a terse format.
.Ic show summary
@@ -244,7 +246,7 @@ in a terse format.
.El .El
.Sh FILES .Sh FILES
.Bl -tag -width "/var/run/bgpd.sockXXX" -compact .Bl -tag -width "/var/run/bgpd.sockXXX" -compact

View file

@ -1,14 +1,14 @@
Index: bgpctl/bgpctl.c Index: bgpctl/bgpctl.c
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpctl/bgpctl.c,v RCS file: /home/cvs/private/hrs/openbgpd/bgpctl/bgpctl.c,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.7
retrieving revision 1.4 retrieving revision 1.6
diff -u -p -r1.1.1.1 -r1.4 diff -u -p -r1.1.1.7 -r1.6
--- bgpctl/bgpctl.c 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpctl/bgpctl.c 14 Feb 2010 20:20:14 -0000 1.1.1.7
+++ bgpctl/bgpctl.c 10 Aug 2009 21:20:02 -0000 1.4 +++ bgpctl/bgpctl.c 14 Feb 2010 19:55:02 -0000 1.6
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: bgpctl.c,v 1.134 2008/06/07 20:23:15 henning Exp $ */ -/* $OpenBSD: bgpctl.c,v 1.142 2009/06/06 06:33:15 eric Exp $ */
+/* $OpenBSD: bgpctl.c,v 1.145 2009/07/23 14:55:25 claudio Exp $ */ +/* $OpenBSD: bgpctl.c,v 1.155 2010/01/10 00:16:23 claudio Exp $ */
/* /*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@ -55,6 +55,15 @@ diff -u -p -r1.1.1.1 -r1.4
enum neighbor_views { enum neighbor_views {
NV_DEFAULT, NV_DEFAULT,
NV_TIMERS NV_TIMERS
@@ -50,7 +66,7 @@ int show_summary_msg(struct imsg *, in
int show_summary_terse_msg(struct imsg *, int);
int show_neighbor_terse(struct imsg *);
int show_neighbor_msg(struct imsg *, enum neighbor_views);
-void print_neighbor_capa_mp_safi(u_int8_t);
+void print_neighbor_capa_mp(struct peer *);
void print_neighbor_msgstats(struct peer *);
void print_timer(const char *, time_t);
static char *fmt_timeframe(time_t t);
@@ -65,7 +81,7 @@ void show_interface_head(void); @@ -65,7 +81,7 @@ void show_interface_head(void);
int ift2ifm(int); int ift2ifm(int);
const char * get_media_descr(int); const char * get_media_descr(int);
@ -64,58 +73,217 @@ diff -u -p -r1.1.1.1 -r1.4
int show_interface_msg(struct imsg *); int show_interface_msg(struct imsg *);
void show_rib_summary_head(void); void show_rib_summary_head(void);
void print_prefix(struct bgpd_addr *, u_int8_t, u_int8_t); void print_prefix(struct bgpd_addr *, u_int8_t, u_int8_t);
@@ -89,8 +105,8 @@ usage(void) @@ -74,7 +90,6 @@ void print_flags(u_int8_t, int);
int show_rib_summary_msg(struct imsg *);
int show_rib_detail_msg(struct imsg *, int);
void show_community(u_char *, u_int16_t);
-const char *get_ext_subtype(u_int8_t);
void show_ext_community(u_char *, u_int16_t);
char *fmt_mem(int64_t);
int show_rib_memory_msg(struct imsg *);
@@ -98,7 +113,7 @@ int
main(int argc, char *argv[])
{ {
extern char *__progname; struct sockaddr_un sun;
- int fd, n, done, ch, nodescr = 0;
+ int fd, n, done, ch, nodescr = 0, verbose = 0;
struct imsg imsg;
struct network_config net;
struct parse_result *res;
@@ -164,15 +179,17 @@ main(int argc, char *argv[])
imsg_compose(ibuf, IMSG_CTL_SHOW_TERSE, 0, 0, -1, NULL, 0);
break;
case SHOW_FIB:
- if (!res->addr.af) {
+ if (!res->addr.aid) {
struct buf *msg;
+ sa_family_t af;
- fprintf(stderr, "usage: %s [-n] [-s socket] " + af = aid2af(res->aid);
- "command [arguments ...]\n", __progname); if ((msg = imsg_create(ibuf, IMSG_CTL_KROUTE, 0, 0,
+ fprintf(stderr, "usage: %s [-n] [-s socket] command [argument ...]\n", - sizeof(res->flags) + sizeof(res->af))) == NULL)
+ __progname); + sizeof(res->flags) + sizeof(af))) == NULL)
exit(1); errx(1, "imsg_create failure");
} if (imsg_add(msg, &res->flags, sizeof(res->flags)) ==
@@ -174,8 +190,7 @@ main(int argc, char *argv[])
-1 || -1 ||
imsg_add(msg, &res->af, sizeof(res->af)) == -1) - imsg_add(msg, &res->af, sizeof(res->af)) == -1)
+ imsg_add(msg, &af, sizeof(af)) == -1)
errx(1, "imsg_add failure"); errx(1, "imsg_add failure");
- if (imsg_close(ibuf, msg) < 0) imsg_close(ibuf, msg);
- errx(1, "imsg_close error");
+ imsg_close(ibuf, msg);
} else } else
imsg_compose(ibuf, IMSG_CTL_KROUTE_ADDR, 0, 0, -1, @@ -192,7 +209,7 @@ main(int argc, char *argv[])
&res->addr, sizeof(res->addr)); case SHOW_NEIGHBOR_TIMERS:
@@ -220,6 +235,7 @@ main(int argc, char *argv[]) case SHOW_NEIGHBOR_TERSE:
neighbor.show_timers = (res->action == SHOW_NEIGHBOR_TIMERS);
- if (res->peeraddr.af || res->peerdesc[0])
+ if (res->peeraddr.aid || res->peerdesc[0])
imsg_compose(ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1,
&neighbor, sizeof(neighbor));
else
@@ -206,7 +223,7 @@ main(int argc, char *argv[])
memcpy(&ribreq.as, &res->as, sizeof(res->as));
type = IMSG_CTL_SHOW_RIB_AS;
} }
- if (res->addr.af) {
+ if (res->addr.aid) {
memcpy(&ribreq.prefix, &res->addr, sizeof(res->addr));
ribreq.prefixlen = res->prefixlen;
type = IMSG_CTL_SHOW_RIB_PREFIX;
@@ -220,7 +237,7 @@ main(int argc, char *argv[])
memcpy(&ribreq.neighbor, &neighbor, memcpy(&ribreq.neighbor, &neighbor,
sizeof(ribreq.neighbor)); sizeof(ribreq.neighbor));
+ strlcpy(ribreq.rib, res->rib, sizeof(ribreq.rib)); strlcpy(ribreq.rib, res->rib, sizeof(ribreq.rib));
ribreq.af = res->af; - ribreq.af = res->af;
+ ribreq.aid = res->aid;
ribreq.flags = res->flags; ribreq.flags = res->flags;
imsg_compose(ibuf, type, 0, 0, -1, &ribreq, sizeof(ribreq)); imsg_compose(ibuf, type, 0, 0, -1, &ribreq, sizeof(ribreq));
@@ -289,8 +305,11 @@ main(int argc, char *argv[]) if (!(res->flags & F_CTL_DETAIL))
done = 1; @@ -290,12 +307,21 @@ main(int argc, char *argv[])
break; break;
case NETWORK_SHOW: case NETWORK_SHOW:
+ bzero(&ribreq, sizeof(ribreq)); bzero(&ribreq, sizeof(ribreq));
+ ribreq.af = res->af; - ribreq.af = res->af;
+ strlcpy(ribreq.rib, res->rib, sizeof(ribreq.rib)); + ribreq.aid = res->aid;
strlcpy(ribreq.rib, res->rib, sizeof(ribreq.rib));
imsg_compose(ibuf, IMSG_CTL_SHOW_NETWORK, 0, 0, -1, imsg_compose(ibuf, IMSG_CTL_SHOW_NETWORK, 0, 0, -1,
- &res->af, sizeof(res->af)); &ribreq, sizeof(ribreq));
+ &ribreq, sizeof(ribreq));
show_network_head(); show_network_head();
break; break;
} + case LOG_VERBOSE:
@@ -410,7 +429,7 @@ fmt_peer(const char *descr, const struct + verbose = 1;
void + /* FALLTHROUGH */
show_summary_head(void) + case LOG_BRIEF:
{ + imsg_compose(ibuf, IMSG_CTL_LOG_VERBOSE, 0, 0, -1,
- printf("%-20s %-8s %-10s %-10s %-5s %-8s %s\n", "Neighbor", "AS", + &verbose, sizeof(verbose));
+ printf("%-20s %8s %10s %10s %5s %-8s %s\n", "Neighbor", "AS", + printf("logging request sent.\n");
"MsgRcvd", "MsgSent", "OutQ", "Up/Down", "State/PrfRcvd"); + done = 1;
+ break;
} }
@@ -677,7 +696,7 @@ print_neighbor_msgstats(struct peer *p) while (ibuf->w.queued)
@@ -304,13 +330,13 @@ main(int argc, char *argv[])
while (!done) {
if ((n = imsg_read(ibuf)) == -1)
- errx(1, "imsg_read error");
+ err(1, "imsg_read error");
if (n == 0)
errx(1, "pipe closed");
while (!done) {
if ((n = imsg_get(ibuf, &imsg)) == -1)
- errx(1, "imsg_get error");
+ err(1, "imsg_get error");
if (n == 0)
break;
@@ -373,6 +399,8 @@ main(int argc, char *argv[])
case NETWORK_REMOVE:
case NETWORK_FLUSH:
case IRRFILTER:
+ case LOG_VERBOSE:
+ case LOG_BRIEF:
break;
}
imsg_free(&imsg);
@@ -398,8 +426,8 @@ fmt_peer(const char *descr, const struct
}
ip = log_addr(remote_addr);
- if (masklen != -1 && ((remote_addr->af == AF_INET && masklen != 32) ||
- (remote_addr->af == AF_INET6 && masklen != 128))) {
+ if (masklen != -1 && ((remote_addr->aid == AID_INET && masklen != 32) ||
+ (remote_addr->aid == AID_INET6 && masklen != 128))) {
if (asprintf(&p, "%s/%u", ip, masklen) == -1)
err(1, NULL);
} else {
@@ -521,13 +549,15 @@ show_neighbor_msg(struct imsg *imsg, enu
struct ctl_timer *t;
struct in_addr ina;
char buf[NI_MAXHOST], pbuf[NI_MAXSERV], *s;
+ int hascapamp = 0;
+ u_int8_t i;
switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_NEIGHBOR:
p = imsg->data;
- if ((p->conf.remote_addr.af == AF_INET &&
+ if ((p->conf.remote_addr.aid == AID_INET &&
p->conf.remote_masklen != 32) ||
- (p->conf.remote_addr.af == AF_INET6 &&
+ (p->conf.remote_addr.aid == AID_INET6 &&
p->conf.remote_masklen != 128)) {
if (asprintf(&s, "%s/%u",
log_addr(&p->conf.remote_addr),
@@ -549,6 +579,10 @@ show_neighbor_msg(struct imsg *imsg, enu
printf(", Template");
if (p->conf.cloned)
printf(", Cloned");
+ if (p->conf.passive)
+ printf(", Passive");
+ if (p->conf.ebgp && p->conf.distance > 1)
+ printf(", Multihop (%u)", (int)p->conf.distance);
printf("\n");
if (p->conf.descr[0])
printf(" Description: %s\n", p->conf.descr);
@@ -563,17 +597,16 @@ show_neighbor_msg(struct imsg *imsg, enu
printf(" Last read %s, holdtime %us, keepalive interval %us\n",
fmt_timeframe(p->stats.last_read),
p->holdtime, p->holdtime/3);
- if (p->capa.peer.mp_v4 || p->capa.peer.mp_v6 ||
- p->capa.peer.refresh || p->capa.peer.restart ||
- p->capa.peer.as4byte) {
+ for (i = 0; i < AID_MAX; i++)
+ if (p->capa.peer.mp[i])
+ hascapamp = 1;
+ if (hascapamp || p->capa.peer.refresh ||
+ p->capa.peer.restart || p->capa.peer.as4byte) {
printf(" Neighbor capabilities:\n");
- if (p->capa.peer.mp_v4) {
- printf(" Multiprotocol extensions: IPv4");
- print_neighbor_capa_mp_safi(p->capa.peer.mp_v4);
- }
- if (p->capa.peer.mp_v6) {
- printf(" Multiprotocol extensions: IPv6");
- print_neighbor_capa_mp_safi(p->capa.peer.mp_v6);
+ if (hascapamp) {
+ printf(" Multiprotocol extensions: ");
+ print_neighbor_capa_mp(p);
+ printf("\n");
}
if (p->capa.peer.refresh)
printf(" Route Refresh\n");
@@ -633,20 +666,16 @@ show_neighbor_msg(struct imsg *imsg, enu
}
void
-print_neighbor_capa_mp_safi(u_int8_t safi)
+print_neighbor_capa_mp(struct peer *p)
{
- switch (safi) {
- case SAFI_UNICAST:
- printf(" Unicast");
- break;
- case SAFI_MULTICAST:
- printf(" Multicast");
- break;
- default:
- printf(" unknown (%u)", safi);
- break;
- }
- printf("\n");
+ int comma;
+ u_int8_t i;
+
+ for (i = 0, comma = 0; i < AID_MAX; i++)
+ if (p->capa.peer.mp[i]) {
+ printf("%s%s", comma ? ", " : "", aid2str(i));
+ comma = 1;
+ }
}
void
@@ -680,7 +709,7 @@ print_neighbor_msgstats(struct peer *p)
} }
void void
@ -124,34 +292,7 @@ diff -u -p -r1.1.1.1 -r1.4
{ {
printf(" %-20s ", name); printf(" %-20s ", name);
@@ -738,7 +757,7 @@ show_fib_head(void) @@ -848,35 +877,70 @@ show_fib_msg(struct imsg *imsg)
printf("flags: * = valid, B = BGP, C = Connected, S = Static\n");
printf(" N = BGP Nexthop reachable via this route\n");
printf(" r = reject route, b = blackhole route\n\n");
- printf("flags destination gateway\n");
+ printf("flags prio destination gateway\n");
}
void
@@ -801,7 +820,7 @@ show_fib_msg(struct imsg *imsg)
if (asprintf(&p, "%s/%u", inet_ntoa(k->prefix), k->prefixlen) ==
-1)
err(1, NULL);
- printf("%-20s ", p);
+ printf("%4i %-20s ", k->priority, p);
free(p);
if (k->nexthop.s_addr)
@@ -822,7 +841,7 @@ show_fib_msg(struct imsg *imsg)
if (asprintf(&p, "%s/%u", log_in6addr(&k6->prefix),
k6->prefixlen) == -1)
err(1, NULL);
- printf("%-20s ", p);
+ printf("%4i %-20s ", k6->priority, p);
free(p);
if (!IN6_IS_ADDR_UNSPECIFIED(&k6->nexthop))
@@ -845,35 +864,77 @@ show_fib_msg(struct imsg *imsg)
void void
show_nexthop_head(void) show_nexthop_head(void)
{ {
@ -165,10 +306,10 @@ diff -u -p -r1.1.1.1 -r1.4
show_nexthop_msg(struct imsg *imsg) show_nexthop_msg(struct imsg *imsg)
{ {
struct ctl_show_nexthop *p; struct ctl_show_nexthop *p;
- int ifms_type;
+ struct kroute *k; + struct kroute *k;
+ struct kroute6 *k6; + struct kroute6 *k6;
+ char *s; + char *s;
int ifms_type;
switch (imsg->hdr.type) { switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_NEXTHOP: case IMSG_CTL_SHOW_NEXTHOP:
@ -180,8 +321,8 @@ diff -u -p -r1.1.1.1 -r1.4
+ printf("\n"); + printf("\n");
+ return (0); + return (0);
+ } + }
+ switch (p->addr.af) { + switch (p->addr.aid) {
+ case AF_INET: + case AID_INET:
+ k = &p->kr.kr4; + k = &p->kr.kr4;
+ if (asprintf(&s, "%s/%u", inet_ntoa(k->prefix), + if (asprintf(&s, "%s/%u", inet_ntoa(k->prefix),
+ k->prefixlen) == -1) + k->prefixlen) == -1)
@ -192,7 +333,7 @@ diff -u -p -r1.1.1.1 -r1.4
+ k->flags & F_CONNECTED ? "connected" : + k->flags & F_CONNECTED ? "connected" :
+ inet_ntoa(k->nexthop)); + inet_ntoa(k->nexthop));
+ break; + break;
+ case AF_INET6: + case AID_INET6:
+ k6 = &p->kr.kr6; + k6 = &p->kr.kr6;
+ if (asprintf(&s, "%s/%u", log_in6addr(&k6->prefix), + if (asprintf(&s, "%s/%u", log_in6addr(&k6->prefix),
+ k6->prefixlen) == -1) + k6->prefixlen) == -1)
@ -204,7 +345,7 @@ diff -u -p -r1.1.1.1 -r1.4
+ log_in6addr(&k6->nexthop)); + log_in6addr(&k6->nexthop));
+ break; + break;
+ default: + default:
+ printf("unknown address familiy %d\n", p->addr.af); + printf("unknown address family\n");
+ return (0); + return (0);
+ } + }
if (p->kif.ifname[0]) { if (p->kif.ifname[0]) {
@ -217,24 +358,19 @@ diff -u -p -r1.1.1.1 -r1.4
- get_media_descr(ifms_type), - get_media_descr(ifms_type),
- get_linkstate(ifms_type, - get_linkstate(ifms_type,
- p->kif.link_state)); - p->kif.link_state));
+ char *s1; - if (p->kif.baudrate) {
+ ifms_type = ift2ifm(p->kif.media_type);
+ if (LINK_STATE_IS_UP(p->kif.link_state)) {
if (p->kif.baudrate) {
- printf(", "); - printf(", ");
- print_baudrate(p->kif.baudrate); - print_baudrate(p->kif.baudrate);
- } - }
- } - }
+ char *s1;
+ if (p->kif.baudrate) {
+ if (asprintf(&s1, ", %s", + if (asprintf(&s1, ", %s",
+ get_baudrate(p->kif.baudrate, + get_baudrate(p->kif.baudrate,
+ "bps")) == -1) + "bps")) == -1)
+ err(1, NULL); + err(1, NULL);
+ } else if (asprintf(&s1, ", %s", get_linkstate( + } else if (asprintf(&s1, ", %s", get_linkstate(
+ ifms_type, p->kif.link_state)) == -1) + p->kif.media_type, p->kif.link_state)) == -1)
+ err(1, NULL);
+ } else if (ifms_type)
+ if (asprintf(&s1, ", %s", get_linkstate(
+ ifms_type, p->kif.link_state)) == -1)
+ err(1, NULL); + err(1, NULL);
+ if (asprintf(&s, "%s (%s%s)", p->kif.ifname, + if (asprintf(&s, "%s (%s%s)", p->kif.ifname,
+ p->kif.flags & IFF_UP ? "UP" : "DOWN", s1) == -1) + p->kif.flags & IFF_UP ? "UP" : "DOWN", s1) == -1)
@ -245,8 +381,47 @@ diff -u -p -r1.1.1.1 -r1.4
} }
printf("\n"); printf("\n");
break; break;
@@ -952,17 +1013,25 @@ get_linkstate(int media_type, int link_s @@ -898,9 +962,8 @@ show_interface_head(void)
return ("unknown link state"); "Link state");
}
-const int ifm_status_valid_list[] = IFM_STATUS_VALID_LIST;
-const struct ifmedia_status_description
- ifm_status_descriptions[] = IFM_STATUS_DESCRIPTIONS;
+const struct if_status_description
+ if_status_descriptions[] = LINK_STATE_DESCRIPTIONS;
const struct ifmedia_description
ifm_type_descriptions[] = IFM_TYPE_DESCRIPTIONS;
@@ -936,36 +999,36 @@ get_media_descr(int media_type)
const char *
get_linkstate(int media_type, int link_state)
{
- const struct ifmedia_status_description *p;
- int i;
+ const struct if_status_description *p;
+ static char buf[8];
- if (link_state == LINK_STATE_UNKNOWN)
- return ("unknown");
-
- for (i = 0; ifm_status_valid_list[i] != 0; i++)
- for (p = ifm_status_descriptions; p->ifms_valid != 0; p++) {
- if (p->ifms_type != media_type ||
- p->ifms_valid != ifm_status_valid_list[i])
- continue;
- if (LINK_STATE_IS_UP(link_state))
- return (p->ifms_string[1]);
- return (p->ifms_string[0]);
- }
-
- return ("unknown link state");
+ for (p = if_status_descriptions; p->ifs_string != NULL; p++) {
+ if (LINK_STATE_DESC_MATCH(p, media_type, link_state))
+ return (p->ifs_string);
+ }
+ snprintf(buf, sizeof(buf), "[#%d]", link_state);
+ return (buf);
} }
-void -void
@ -277,42 +452,162 @@ diff -u -p -r1.1.1.1 -r1.4
} }
int int
@@ -987,8 +1056,7 @@ show_interface_msg(struct imsg *imsg) @@ -982,17 +1045,12 @@ show_interface_msg(struct imsg *imsg)
printf("link state %u", k->link_state); printf("%-15s", k->flags & IFF_UP ? "UP" : "");
if (k->link_state != LINK_STATE_DOWN && k->baudrate > 0) { if ((ifms_type = ift2ifm(k->media_type)) != 0)
- printf("%s, %s", get_media_descr(ifms_type),
- get_linkstate(ifms_type, k->link_state));
- else if (k->link_state == LINK_STATE_UNKNOWN)
- printf("unknown");
- else
- printf("link state %u", k->link_state);
+ printf("%s, ", get_media_descr(ifms_type));
- if (k->link_state != LINK_STATE_DOWN && k->baudrate > 0) {
- printf(", "); - printf(", ");
- print_baudrate(k->baudrate); - print_baudrate(k->baudrate);
- }
+ printf("%s", get_linkstate(k->media_type, k->link_state));
+
+ if (k->link_state != LINK_STATE_DOWN && k->baudrate > 0)
+ printf(", %s", get_baudrate(k->baudrate, "Bit/s")); + printf(", %s", get_baudrate(k->baudrate, "Bit/s"));
}
printf("\n"); printf("\n");
break; break;
@@ -1186,8 +1254,8 @@ show_rib_detail_msg(struct imsg *imsg, i case IMSG_CTL_END:
case ATTR_AGGREGATOR: @@ -1011,7 +1069,7 @@ show_rib_summary_head(void)
printf(
"flags: * = Valid, > = Selected, I = via IBGP, A = Announced\n");
printf("origin: i = IGP, e = EGP, ? = Incomplete\n\n");
- printf("%-5s %-20s%-15s %5s %5s %s\n", "flags", "destination",
+ printf("%-5s %-20s %-15s %5s %5s %s\n", "flags", "destination",
"gateway", "lpref", "med", "aspath origin");
}
@@ -1085,7 +1143,7 @@ show_rib_summary_msg(struct imsg *imsg)
memcpy(&rib, imsg->data, sizeof(rib));
print_prefix(&rib.prefix, rib.prefixlen, rib.flags);
- printf("%-15s ", log_addr(&rib.exit_nexthop));
+ printf(" %-15s ", log_addr(&rib.exit_nexthop));
printf(" %5u %5u ", rib.local_pref, rib.med);
@@ -1190,7 +1248,7 @@ show_rib_detail_msg(struct imsg *imsg, i
memcpy(&as, data, sizeof(as)); memcpy(&as, data, sizeof(as));
memcpy(&id, data + sizeof(as), sizeof(id)); memcpy(&id, data + sizeof(as), sizeof(id));
- printf(" Aggregator: %s [%s]\n", log_as(as), printf(" Aggregator: %s [%s]\n",
- inet_ntoa(id)); - log_as(htonl(as)), inet_ntoa(id));
+ printf(" Aggregator: %s [%s]\n", + log_as(ntohl(as)), inet_ntoa(id));
+ log_as(htonl(as)), inet_ntoa(id));
break; break;
case ATTR_ORIGINATOR_ID: case ATTR_ORIGINATOR_ID:
memcpy(&id, data, sizeof(id)); memcpy(&id, data, sizeof(id));
@@ -1249,6 +1317,9 @@ show_rib_memory_msg(struct imsg *imsg) @@ -1236,22 +1294,27 @@ fmt_mem(int64_t num)
printf("%10lld IPv6 network entries using " return (buf);
"%s of memory\n", (long long)stats.pt6_cnt, }
fmt_mem(stats.pt6_cnt * sizeof(struct pt_entry6)));
+ printf("%10lld rib entries using %s of memory\n", +size_t pt_sizes[AID_MAX] = AID_PTSIZE;
+ (long long)stats.rib_cnt, fmt_mem(stats.rib_cnt * +
+ sizeof(struct rib_entry))); int
printf("%10lld prefix entries using %s of memory\n", show_rib_memory_msg(struct imsg *imsg)
(long long)stats.prefix_cnt, fmt_mem(stats.prefix_cnt * {
sizeof(struct prefix))); struct rde_memstats stats;
@@ -1270,6 +1341,7 @@ show_rib_memory_msg(struct imsg *imsg) + size_t pts = 0;
stats.pt4_cnt * sizeof(struct pt_entry4) + + int i;
stats.pt6_cnt * sizeof(struct pt_entry6) +
switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_RIB_MEM:
memcpy(&stats, imsg->data, sizeof(stats));
printf("RDE memory statistics\n");
- printf("%10lld IPv4 network entries using %s of memory\n",
- (long long)stats.pt4_cnt, fmt_mem(stats.pt4_cnt *
- sizeof(struct pt_entry4)));
- if (stats.pt6_cnt != 0)
- printf("%10lld IPv6 network entries using "
- "%s of memory\n", (long long)stats.pt6_cnt,
- fmt_mem(stats.pt6_cnt * sizeof(struct pt_entry6)));
+ for (i = 0; i < AID_MAX; i++) {
+ if (stats.pt_cnt[i] == 0)
+ continue;
+ pts += stats.pt_cnt[i] * pt_sizes[i];
+ printf("%10lld %s network entries using %s of memory\n",
+ (long long)stats.pt_cnt[i], aid_vals[i].name,
+ fmt_mem(stats.pt_cnt[i] * pt_sizes[i]));
+ }
printf("%10lld rib entries using %s of memory\n",
(long long)stats.rib_cnt, fmt_mem(stats.rib_cnt *
sizeof(struct rib_entry)));
@@ -1272,9 +1335,7 @@ show_rib_memory_msg(struct imsg *imsg)
(long long)stats.attr_refs);
printf("%10lld BGP attributes using %s of memory\n",
(long long)stats.attr_dcnt, fmt_mem(stats.attr_data));
- printf("RIB using %s of memory\n", fmt_mem(
- stats.pt4_cnt * sizeof(struct pt_entry4) +
- stats.pt6_cnt * sizeof(struct pt_entry6) +
+ printf("RIB using %s of memory\n", fmt_mem(pts +
stats.prefix_cnt * sizeof(struct prefix) + stats.prefix_cnt * sizeof(struct prefix) +
+ stats.rib_cnt * sizeof(struct rib_entry) + stats.rib_cnt * sizeof(struct rib_entry) +
stats.path_cnt * sizeof(struct rde_aspath) + stats.path_cnt * sizeof(struct rde_aspath) +
stats.aspath_size + stats.attr_cnt * sizeof(struct attr) + @@ -1328,30 +1389,6 @@ show_community(u_char *data, u_int16_t l
stats.attr_data)); }
}
-const char *
-get_ext_subtype(u_int8_t type)
-{
- static char etype[6];
-
- switch (type) {
- case EXT_COMMUNITY_ROUTE_TGT:
- return "rt"; /* route target */
- case EXT_CUMMUNITY_ROUTE_ORIG:
- return "soo"; /* source of origin */
- case EXT_COMMUNITY_OSPF_DOM_ID:
- return "odi"; /* ospf domain id */
- case EXT_COMMUNITY_OSPF_RTR_TYPE:
- return "ort"; /* ospf route type */
- case EXT_COMMUNITY_OSPF_RTR_ID:
- return "ori"; /* ospf router id */
- case EXT_COMMUNITY_BGP_COLLECT:
- return "bdc"; /* bgp data collection */
- default:
- snprintf(etype, sizeof(etype), "[%i]", (int)type);
- return etype;
- }
-}
-
void
show_ext_community(u_char *data, u_int16_t len)
{
@@ -1372,24 +1409,25 @@ show_ext_community(u_char *data, u_int16
case EXT_COMMUNITY_TWO_AS:
memcpy(&as2, data + i + 2, sizeof(as2));
memcpy(&u32, data + i + 4, sizeof(u32));
- printf("%s %hu:%u", get_ext_subtype(subtype), as2, u32);
+ printf("%s %s:%u", log_ext_subtype(subtype),
+ log_as(ntohs(as2)), ntohl(u32));
break;
case EXT_COMMUNITY_IPV4:
memcpy(&ip, data + i + 2, sizeof(ip));
memcpy(&u16, data + i + 6, sizeof(u16));
- printf("%s %s:%hu", get_ext_subtype(subtype),
- inet_ntoa(ip), u16);
+ printf("%s %s:%hu", log_ext_subtype(subtype),
+ inet_ntoa(ip), ntohs(u16));
break;
case EXT_COMMUNITY_FOUR_AS:
memcpy(&as4, data + i + 2, sizeof(as4));
memcpy(&u16, data + i + 6, sizeof(u16));
- printf("%s %s:%hu", get_ext_subtype(subtype),
- log_as(as4), u16);
+ printf("%s %s:%hu", log_ext_subtype(subtype),
+ log_as(ntohl(as4)), ntohs(u16));
break;
case EXT_COMMUNITY_OPAQUE:
memcpy(&ext, data + i, sizeof(ext));
ext = betoh64(ext) & 0xffffffffffffLL;
- printf("%s 0x%llx", get_ext_subtype(subtype), ext);
+ printf("%s 0x%llx", log_ext_subtype(subtype), ext);
break;
default:
memcpy(&ext, data + i, sizeof(ext));

View file

@ -1,271 +0,0 @@
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ bgpctl/fmt_scaled.c 2008-03-18 13:27:29.000000000 +0100
@@ -0,0 +1,268 @@
+/* $OpenBSD: fmt_scaled.c,v 1.9 2007/03/20 03:42:52 tedu Exp $ */
+
+/*
+ * Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * fmt_scaled: Format numbers scaled for human comprehension
+ * scan_scaled: Scan numbers in this format.
+ *
+ * "Human-readable" output uses 4 digits max, and puts a unit suffix at
+ * the end. Makes output compact and easy-to-read esp. on huge disks.
+ * Formatting code was originally in OpenBSD "df", converted to library routine.
+ * Scanning code written for OpenBSD libutil.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <ctype.h>
+#include <limits.h>
+
+#include "util.h"
+
+typedef enum {
+ NONE = 0, KILO = 1, MEGA = 2, GIGA = 3, TERA = 4, PETA = 5, EXA = 6
+} unit_type;
+
+/* These three arrays MUST be in sync! XXX make a struct */
+static unit_type units[] = { NONE, KILO, MEGA, GIGA, TERA, PETA, EXA };
+static char scale_chars[] = "BKMGTPE";
+static long long scale_factors[] = {
+ 1LL,
+ 1024LL,
+ 1024LL*1024,
+ 1024LL*1024*1024,
+ 1024LL*1024*1024*1024,
+ 1024LL*1024*1024*1024*1024,
+ 1024LL*1024*1024*1024*1024*1024,
+};
+#define SCALE_LENGTH (sizeof(units)/sizeof(units[0]))
+
+#define MAX_DIGITS (SCALE_LENGTH * 3) /* XXX strlen(sprintf("%lld", -1)? */
+
+/** Convert the given input string "scaled" into numeric in "result".
+ * Return 0 on success, -1 and errno set on error.
+ */
+int
+scan_scaled(char *scaled, long long *result)
+{
+ char *p = scaled;
+ int sign = 0;
+ unsigned int i, ndigits = 0, fract_digits = 0;
+ long long scale_fact = 1, whole = 0, fpart = 0;
+
+ /* Skip leading whitespace */
+ while (isascii(*p) && isspace(*p))
+ ++p;
+
+ /* Then at most one leading + or - */
+ while (*p == '-' || *p == '+') {
+ if (*p == '-') {
+ if (sign) {
+ errno = EINVAL;
+ return -1;
+ }
+ sign = -1;
+ ++p;
+ } else if (*p == '+') {
+ if (sign) {
+ errno = EINVAL;
+ return -1;
+ }
+ sign = +1;
+ ++p;
+ }
+ }
+
+ /* Main loop: Scan digits, find decimal point, if present.
+ * We don't allow exponentials, so no scientific notation
+ * (but note that E for Exa might look like e to some!).
+ * Advance 'p' to end, to get scale factor.
+ */
+ for (; isascii(*p) && (isdigit(*p) || *p=='.'); ++p) {
+ if (*p == '.') {
+ if (fract_digits > 0) { /* oops, more than one '.' */
+ errno = EINVAL;
+ return -1;
+ }
+ fract_digits = 1;
+ continue;
+ }
+
+ i = (*p) - '0'; /* whew! finally a digit we can use */
+ if (fract_digits > 0) {
+ if (fract_digits >= MAX_DIGITS-1)
+ /* ignore extra fractional digits */
+ continue;
+ fract_digits++; /* for later scaling */
+ fpart *= 10;
+ fpart += i;
+ } else { /* normal digit */
+ if (++ndigits >= MAX_DIGITS) {
+ errno = ERANGE;
+ return -1;
+ }
+ whole *= 10;
+ whole += i;
+ }
+ }
+
+ if (sign) {
+ whole *= sign;
+ fpart *= sign;
+ }
+
+ /* If no scale factor given, we're done. fraction is discarded. */
+ if (!*p) {
+ *result = whole;
+ return 0;
+ }
+
+ /* Validate scale factor, and scale whole and fraction by it. */
+ for (i = 0; i < SCALE_LENGTH; i++) {
+
+ /** Are we there yet? */
+ if (*p == scale_chars[i] ||
+ *p == tolower(scale_chars[i])) {
+
+ /* If it ends with alphanumerics after the scale char, bad. */
+ if (isalnum(*(p+1))) {
+ errno = EINVAL;
+ return -1;
+ }
+ scale_fact = scale_factors[i];
+
+ /* scale whole part */
+ whole *= scale_fact;
+
+ /* truncate fpart so it does't overflow.
+ * then scale fractional part.
+ */
+ while (fpart >= LLONG_MAX / scale_fact) {
+ fpart /= 10;
+ fract_digits--;
+ }
+ fpart *= scale_fact;
+ if (fract_digits > 0) {
+ for (i = 0; i < fract_digits -1; i++)
+ fpart /= 10;
+ }
+ whole += fpart;
+ *result = whole;
+ return 0;
+ }
+ }
+ errno = ERANGE;
+ return -1;
+}
+
+/* Format the given "number" into human-readable form in "result".
+ * Result must point to an allocated buffer of length FMT_SCALED_STRSIZE.
+ * Return 0 on success, -1 and errno set if error.
+ */
+int
+fmt_scaled(long long number, char *result)
+{
+ long long abval, fract = 0;
+ unsigned int i;
+ unit_type unit = NONE;
+
+ abval = (number < 0LL) ? -number : number; /* no long long_abs yet */
+
+ /* Not every negative long long has a positive representation.
+ * Also check for numbers that are just too darned big to format
+ */
+ if (abval < 0 || abval / 1024 >= scale_factors[SCALE_LENGTH-1]) {
+ errno = ERANGE;
+ return -1;
+ }
+
+ /* scale whole part; get unscaled fraction */
+ for (i = 0; i < SCALE_LENGTH; i++) {
+ if (abval/1024 < scale_factors[i]) {
+ unit = units[i];
+ fract = (i == 0) ? 0 : abval % scale_factors[i];
+ number /= scale_factors[i];
+ if (i > 0)
+ fract /= scale_factors[i - 1];
+ break;
+ }
+ }
+
+ fract = (10 * fract + 512) / 1024;
+ /* if the result would be >= 10, round main number */
+ if (fract == 10) {
+ if (number >= 0)
+ number++;
+ else
+ number--;
+ fract = 0;
+ }
+
+ if (number == 0)
+ strlcpy(result, "0B", FMT_SCALED_STRSIZE);
+ else if (unit == NONE || number >= 100 || number <= -100) {
+ if (fract >= 5) {
+ if (number >= 0)
+ number++;
+ else
+ number--;
+ }
+ (void)snprintf(result, FMT_SCALED_STRSIZE, "%lld%c",
+ number, scale_chars[unit]);
+ } else
+ (void)snprintf(result, FMT_SCALED_STRSIZE, "%lld.%1lld%c",
+ number, fract, scale_chars[unit]);
+
+ return 0;
+}
+
+#ifdef MAIN
+/*
+ * This is the original version of the program in the man page.
+ * Copy-and-paste whatever you need from it.
+ */
+int
+main(int argc, char **argv)
+{
+ char *cinput = "1.5K", buf[FMT_SCALED_STRSIZE];
+ long long ninput = 10483892, result;
+
+ if (scan_scaled(cinput, &result) == 0)
+ printf("\"%s\" -> %lld\n", cinput, result);
+ else
+ perror(cinput);
+
+ if (fmt_scaled(ninput, buf) == 0)
+ printf("%lld -> \"%s\"\n", ninput, buf);
+ else
+ fprintf(stderr, "%lld invalid (%s)\n", ninput, strerror(errno));
+
+ return 0;
+}
+#endif

View file

@ -1,23 +0,0 @@
Index: bgpctl/irr_asset.c
===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpctl/irr_asset.c,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.1 -r1.1.1.2
--- bgpctl/irr_asset.c 30 Jun 2009 05:46:15 -0000 1.1.1.1
+++ bgpctl/irr_asset.c 9 Jul 2009 16:49:55 -0000 1.1.1.2
@@ -1,4 +1,4 @@
-/* $OpenBSD: irr_asset.c,v 1.7 2007/03/31 12:46:55 henning Exp $ */
+/* $OpenBSD: irr_asset.c,v 1.8 2009/04/14 21:10:54 jj Exp $ */
/*
* Copyright (c) 2007 Henning Brauer <henning@openbsd.org>
@@ -105,7 +105,7 @@ asset_get(char *name)
break;
case T_AUTNUM:
/*
- * make a dummy as-set with the the AS both as name
+ * make a dummy as-set with the AS both as name
* and its only member
*/
asset_add_as(ass, name);

View file

@ -1,16 +1,41 @@
Index: bgpctl/irr_parser.c Index: bgpctl/irr_parser.c
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpctl/irr_parser.c,v RCS file: /home/cvs/private/hrs/openbgpd/bgpctl/irr_parser.c,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.5
retrieving revision 1.2 retrieving revision 1.4
diff -u -p -r1.1.1.1 -r1.2 diff -u -p -r1.1.1.5 -r1.4
--- bgpctl/irr_parser.c 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpctl/irr_parser.c 14 Feb 2010 20:20:14 -0000 1.1.1.5
+++ bgpctl/irr_parser.c 30 Jun 2009 06:40:06 -0000 1.2 +++ bgpctl/irr_parser.c 4 Feb 2010 16:22:26 -0000 1.4
@@ -18,6 +18,7 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: irr_parser.c,v 1.8 2007/03/05 22:34:08 henning Exp $ */
+/* $OpenBSD: irr_parser.c,v 1.9 2009/09/08 15:40:25 claudio Exp $ */
#include <sys/types.h> /*
#include <sys/param.h> * Copyright (c) 2007 Henning Brauer <henning@openbsd.org>
+ @@ -81,6 +81,7 @@ parse_response(FILE *f, enum qtype qtype
#include <ctype.h> return (-1);
#include <err.h> break;
#include <stdio.h> case QTYPE_ROUTE:
+ case QTYPE_ROUTE6:
if ((n = parse_route(key, val)) == -1)
return (-1);
break;
@@ -281,7 +282,7 @@ parse_policy(char *key, char *val)
!isdigit(tok[2]))
errx(1, "peering spec \"%s\": format "
"error, AS expected", tok);
- pi->peer_as = strtonum(tok + 2, 1, USHRT_MAX,
+ pi->peer_as = strtonum(tok + 2, 1, UINT_MAX,
&errstr);
if (errstr)
errx(1, "peering spec \"%s\": format "
@@ -407,7 +408,8 @@ parse_asset(char *key, char *val)
int
parse_route(char *key, char *val)
{
- if (strcmp(key, "route")) /* ignore everything else */
+ if (strcmp(key, "route") && strcmp(key, "route6"))
+ /* ignore everything else */
return (0);
/* route is single-value, but seen trailing , in the wild */

View file

@ -0,0 +1,156 @@
Index: bgpctl/irr_prefix.c
===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpctl/irr_prefix.c,v
retrieving revision 1.1.1.5
retrieving revision 1.1.1.6
diff -u -p -r1.1.1.5 -r1.1.1.6
--- bgpctl/irr_prefix.c 14 Feb 2010 20:20:14 -0000 1.1.1.5
+++ bgpctl/irr_prefix.c 14 Feb 2010 20:27:21 -0000 1.1.1.6
@@ -1,4 +1,4 @@
-/* $OpenBSD: irr_prefix.c,v 1.15 2007/05/27 18:54:25 henning Exp $ */
+/* $OpenBSD: irr_prefix.c,v 1.17 2009/09/08 16:11:36 sthen Exp $ */
/*
* Copyright (c) 2007 Henning Brauer <henning@openbsd.org>
@@ -29,6 +29,7 @@
#include <arpa/inet.h>
#include "irrfilter.h"
+#include "bgpd.h"
void prefixset_aggregate(struct prefix_set *);
int prefix_aggregate(struct irr_prefix *, const struct irr_prefix *);
@@ -63,7 +64,11 @@ prefixset_get(char *as)
fflush(stdout);
}
curpfxs = pfxs;
- if (whois(as, QTYPE_ROUTE) == -1)
+ if ((irrflags & F_IPV4) && whois(as, QTYPE_ROUTE) == -1)
+ errx(1, "whois error, prefixset_get %s", as);
+ if ((irrflags & F_IPV6) && whois(as, QTYPE_ROUTE6) == -1)
+ errx(1, "whois error, prefixset_get %s", as);
+ if (whois(as, QTYPE_ROUTE6) == -1)
errx(1, "whois error, prefixset_get %s", as);
curpfxs = NULL;
if (irrverbose >= 3)
@@ -80,9 +85,11 @@ prefixset_addmember(char *s)
void *p;
u_int i;
struct irr_prefix *pfx;
- int len;
+ int len, ret;
+ char *slash;
+ const char *errstr;
- if (strchr(s, '/') == NULL) {
+ if ((slash = strchr(s, '/')) == NULL) {
fprintf(stderr, "%s: prefix %s does not have the len "
"specified, ignoring\n", curpfxs->as, s);
return (0);
@@ -92,17 +99,26 @@ prefixset_addmember(char *s)
err(1, "prefixset_addmember calloc");
if ((len = inet_net_pton(AF_INET, s, &pfx->addr.in,
- sizeof(pfx->addr.in))) == -1) {
- if (errno == ENOENT) {
- fprintf(stderr, "%s: prefix \"%s\": parse error\n",
+ sizeof(pfx->addr.in))) != -1) {
+ pfx->af = AF_INET;
+ } else {
+ len = strtonum(slash + 1, 0, 128, &errstr);
+ if (errstr)
+ errx(1, "prefixset_addmember %s prefix %s: prefixlen "
+ "is %s", curpfxs->as, s, errstr);
+ *slash = '\0';
+
+ if ((ret = inet_pton(AF_INET6, s, &pfx->addr.in6)) == -1)
+ err(1, "prefixset_addmember %s prefix \"%s\"",
curpfxs->as, s);
+ else if (ret == 0) {
+ fprintf(stderr, "prefixset_addmember %s prefix \"%s\": "
+ "No matching address family found", curpfxs->as, s);
+ free(pfx);
return (0);
- } else
- err(1, "prefixset_addmember %s inet_net_pton \"%s\"",
- curpfxs->as, s);
+ }
+ pfx->af = AF_INET6;
}
-
- pfx->af = AF_INET;
pfx->len = pfx->maxlen = len;
/* yes, there are dupes... e. g. from multiple sources */
@@ -175,24 +191,47 @@ prefixset_aggregate(struct prefix_set *p
int
prefix_aggregate(struct irr_prefix *a, const struct irr_prefix *b)
{
- in_addr_t mask;
+ in_addr_t mask;
+ struct in6_addr ma;
+ struct in6_addr mb;
if (a->len == 0)
return (1);
- mask = htonl(0xffffffff << (32 - a->len));
+ if (a->af != b->af)
+ /* We cannot aggregate addresses of different families. */
+ return (0);
- if ((a->addr.in.s_addr & mask) == (b->addr.in.s_addr & mask))
- return (1);
+ if (a->af == AF_INET) {
+ mask = htonl(prefixlen2mask(a->len));
+ if ((a->addr.in.s_addr & mask) == (b->addr.in.s_addr & mask))
+ return (1);
+ } else if (a->af == AF_INET6) {
+ inet6applymask(&ma, &a->addr.in6, a->len);
+ inet6applymask(&mb, &b->addr.in6, a->len);
+ if (IN6_ARE_ADDR_EQUAL(&ma, &mb))
+ return (1);
+ }
/* see wether we can fold them in one */
if (a->len == b->len && a->len > 1) {
- mask = htonl(0xffffffff << (32 - (a->len - 1)));
- if ((a->addr.in.s_addr & mask) ==
- (b->addr.in.s_addr & mask)) {
- a->len--;
- a->addr.in.s_addr &= mask;
- return (1);
+ if (a->af == AF_INET) {
+ mask = htonl(prefixlen2mask(a->len - 1));
+ if ((a->addr.in.s_addr & mask) ==
+ (b->addr.in.s_addr & mask)) {
+ a->len--;
+ a->addr.in.s_addr &= mask;
+ return (1);
+ }
+ } else if (a->af == AF_INET6) {
+ inet6applymask(&ma, &a->addr.in6, a->len - 1);
+ inet6applymask(&mb, &b->addr.in6, a->len - 1);
+
+ if (IN6_ARE_ADDR_EQUAL(&ma, &mb)) {
+ a->len--;
+ memcpy(&a->addr.in6, &ma, sizeof(ma));
+ return (1);
+ }
}
}
@@ -219,6 +258,13 @@ irr_prefix_cmp(const void *a, const void
if (ntohl(pa->addr.in.s_addr) >
ntohl(pb->addr.in.s_addr))
return (1);
+ } else if (pa->af == AF_INET6) {
+ for (r = 0; r < 16; r++) {
+ if (pa->addr.in6.s6_addr[r] < pb->addr.in6.s6_addr[r])
+ return (-1);
+ if (pa->addr.in6.s6_addr[r] > pb->addr.in6.s6_addr[r])
+ return (1);
+ }
} else
errx(1, "irr_prefix_cmp unknown af %u", pa->af);

View file

@ -1,12 +1,18 @@
Index: bgpctl/irrfilter.h Index: bgpctl/irrfilter.h
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpctl/irrfilter.h,v RCS file: /home/cvs/private/hrs/openbgpd/bgpctl/irrfilter.h,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.5
retrieving revision 1.2 retrieving revision 1.3
diff -u -p -r1.1.1.1 -r1.2 diff -u -p -r1.1.1.5 -r1.3
--- bgpctl/irrfilter.h 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpctl/irrfilter.h 14 Feb 2010 20:20:14 -0000 1.1.1.5
+++ bgpctl/irrfilter.h 30 Jun 2009 06:40:06 -0000 1.2 +++ bgpctl/irrfilter.h 4 Feb 2010 16:22:26 -0000 1.3
@@ -16,6 +16,10 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: irrfilter.h,v 1.7 2007/03/06 16:45:34 henning Exp $ */
+/* $OpenBSD: irrfilter.h,v 1.9 2009/09/08 16:11:36 sthen Exp $ */
/*
* Copyright (c) 2007 Henning Brauer <henning@openbsd.org>
@@ -16,11 +16,17 @@
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
@ -17,3 +23,37 @@ diff -u -p -r1.1.1.1 -r1.2
#include <sys/queue.h> #include <sys/queue.h>
#include <sys/tree.h> #include <sys/tree.h>
#include <netinet/in.h> #include <netinet/in.h>
#define F_IMPORTONLY 0x01 /* skip export: items */
+#define F_IPV4 0x02 /* use IPv4 items */
+#define F_IPV6 0x04 /* use IPv6 items */
int irrflags;
int irrverbose;
@@ -37,7 +43,7 @@ struct policy_item {
char *action;
char *filter;
enum pdir dir;
- u_int16_t peer_as;
+ u_int32_t peer_as;
};
TAILQ_HEAD(policy_head, policy_item);
@@ -55,7 +61,8 @@ enum qtype {
QTYPE_NONE,
QTYPE_OWNAS,
QTYPE_ASSET,
- QTYPE_ROUTE
+ QTYPE_ROUTE,
+ QTYPE_ROUTE6
};
struct as_set {
@@ -72,6 +79,7 @@ struct as_set {
struct irr_prefix {
union {
struct in_addr in;
+ struct in6_addr in6;
} addr;
sa_family_t af;
u_int8_t len;

View file

@ -1,14 +1,14 @@
Index: bgpctl/parser.c Index: bgpctl/parser.c
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpctl/parser.c,v RCS file: /home/cvs/private/hrs/openbgpd/bgpctl/parser.c,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.6
retrieving revision 1.3 retrieving revision 1.4
diff -u -p -r1.1.1.1 -r1.3 diff -u -p -r1.1.1.6 -r1.4
--- bgpctl/parser.c 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpctl/parser.c 14 Feb 2010 20:20:14 -0000 1.1.1.6
+++ bgpctl/parser.c 9 Jul 2009 17:22:12 -0000 1.3 +++ bgpctl/parser.c 4 Feb 2010 16:22:26 -0000 1.4
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.50 2008/06/15 09:58:43 claudio Exp $ */ -/* $OpenBSD: parser.c,v 1.54 2009/06/12 16:44:02 claudio Exp $ */
+/* $OpenBSD: parser.c,v 1.54 2009/06/12 16:44:02 claudio Exp $ */ +/* $OpenBSD: parser.c,v 1.60 2010/01/13 06:04:00 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -23,126 +23,144 @@ diff -u -p -r1.1.1.1 -r1.3
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
@@ -42,6 +46,7 @@ enum token_type { @@ -97,6 +101,7 @@ static const struct token t_prepself[];
ASTYPE, static const struct token t_weight[];
PREFIX, static const struct token t_irrfilter[];
PEERDESC, static const struct token t_irrfilter_opts[];
+ RIBNAME, +static const struct token t_log[];
COMMUNITY,
LOCALPREF, static const struct token t_main[] = {
MED, { KEYWORD, "reload", RELOAD, NULL},
@@ -72,6 +77,7 @@ static const struct token t_show_summary @@ -105,6 +110,7 @@ static const struct token t_main[] = {
static const struct token t_show_fib[]; { KEYWORD, "neighbor", NEIGHBOR, t_neighbor},
static const struct token t_show_rib[]; { KEYWORD, "network", NONE, t_network},
static const struct token t_show_rib_neigh[]; { KEYWORD, "irrfilter", IRRFILTER, t_irrfilter},
+static const struct token t_show_rib_rib[]; + { KEYWORD, "log", NONE, t_log},
static const struct token t_show_neighbor[];
static const struct token t_show_neighbor_modifiers[];
static const struct token t_fib[];
@@ -148,6 +154,7 @@ static const struct token t_show_rib[] =
{ FLAG, "in", F_CTL_ADJ_IN, t_show_rib},
{ FLAG, "out", F_CTL_ADJ_OUT, t_show_rib},
{ KEYWORD, "neighbor", NONE, t_show_rib_neigh},
+ { KEYWORD, "table", NONE, t_show_rib_rib},
{ KEYWORD, "summary", SHOW_SUMMARY, t_show_summary},
{ KEYWORD, "memory", SHOW_RIB_MEM, NULL},
{ FAMILY, "", NONE, t_show_rib},
@@ -161,6 +168,11 @@ static const struct token t_show_rib_nei
{ ENDTOKEN, "", NONE, NULL} { ENDTOKEN, "", NONE, NULL}
}; };
+static const struct token t_show_rib_rib[] = { @@ -311,6 +317,12 @@ static const struct token t_irrfilter_op
+ { RIBNAME, "", NONE, t_show_rib}, { ENDTOKEN, "", NONE, NULL}
};
+static const struct token t_log[] = {
+ { KEYWORD, "verbose", LOG_VERBOSE, NULL},
+ { KEYWORD, "brief", LOG_BRIEF, NULL},
+ { ENDTOKEN, "", NONE, NULL} + { ENDTOKEN, "", NONE, NULL}
+}; +};
+ +
static const struct token t_show_neighbor[] = { static struct parse_result res;
{ NOTOKEN, "", NONE, NULL},
{ PEERADDRESS, "", NONE, t_show_neighbor_modifiers}, const struct token *match_token(int *argc, char **argv[],
@@ -456,6 +468,15 @@ match_token(int *argc, char **argv[], co @@ -336,6 +348,7 @@ parse(int argc, char *argv[])
t = &table[i]; bzero(&res, sizeof(res));
} res.community.as = COMMUNITY_UNSET;
res.community.type = COMMUNITY_UNSET;
+ res.flags = (F_IPV4 | F_IPV6);
TAILQ_INIT(&res.set);
if ((res.irr_outdir = getcwd(NULL, 0)) == NULL) {
fprintf(stderr, "getcwd failed: %s", strerror(errno));
@@ -404,15 +417,22 @@ match_token(int *argc, char **argv[], co
case FAMILY:
if (word == NULL)
break; break;
+ case RIBNAME: - if (!strcmp(word, "inet") || !strcmp(word, "IPv4")) {
+ if (!match && word != NULL && strlen(word) > 0) { + if (!strcmp(word, "inet") ||
+ if (strlcpy(res.rib, word, sizeof(res.rib)) >= + !strcasecmp(word, "IPv4")) {
+ sizeof(res.rib))
+ errx(1, "rib name too long");
+ match++; + match++;
+ t = &table[i]; + t = &table[i];
+ res.aid = AID_INET;
+ } + }
+ break; + if (!strcmp(word, "inet6") ||
case COMMUNITY: + !strcasecmp(word, "IPv6")) {
if (word != NULL && strlen(word) > 0 && match++;
parse_community(word, &res)) { t = &table[i];
@@ -547,6 +568,9 @@ show_valid_args(const struct token table - res.af = AF_INET;
case PEERDESC: + res.aid = AID_INET6;
fprintf(stderr, " <neighbor description>\n"); }
- if (!strcmp(word, "inet6") || !strcmp(word, "IPv6")) {
+ if (!strcasecmp(word, "VPNv4")) {
match++;
t = &table[i];
- res.af = AF_INET6;
+ res.aid = AID_VPN_IPv4;
}
break; break;
+ case RIBNAME: case ADDRESS:
+ fprintf(stderr, " <rib name>\n"); @@ -584,7 +604,7 @@ show_valid_args(const struct token table
+ break; fprintf(stderr, " <pftable>\n");
case COMMUNITY:
fprintf(stderr, " <community>\n");
break; break;
@@ -686,7 +710,7 @@ parse_asnum(const char *word, u_int32_t case FAMILY:
- fprintf(stderr, " [ inet | inet6 | IPv4 | IPv6 ]\n");
+ fprintf(stderr, " [ inet | inet6 | IPv4 | IPv6 | VPNv4 ]\n");
break;
case GETOPT:
fprintf(stderr, " <options>\n");
@@ -608,7 +628,7 @@ parse_addr(const char *word, struct bgpd
bzero(&ina, sizeof(ina));
if (inet_net_pton(AF_INET, word, &ina, sizeof(ina)) != -1) {
- addr->af = AF_INET;
+ addr->aid = AID_INET;
addr->v4 = ina;
return (1);
}
@@ -618,13 +638,7 @@ parse_addr(const char *word, struct bgpd
hints.ai_socktype = SOCK_DGRAM; /*dummy*/
hints.ai_flags = AI_NUMERICHOST;
if (getaddrinfo(word, "0", &hints, &r) == 0) {
- addr->af = AF_INET6;
- memcpy(&addr->v6,
- &((struct sockaddr_in6 *)r->ai_addr)->sin6_addr,
- sizeof(addr->v6));
- addr->scope_id =
- ((struct sockaddr_in6 *)r->ai_addr)->sin6_scope_id;
-
+ sa2addr(r->ai_addr, addr);
freeaddrinfo(r);
return (1);
}
@@ -663,15 +677,15 @@ parse_prefix(const char *word, struct bg
if (parse_addr(word, addr) == 0)
return (0);
- switch (addr->af) {
- case AF_INET:
+ switch (addr->aid) {
+ case AID_INET:
if (mask == -1)
mask = 32;
if (mask > 32)
errx(1, "invalid netmask: too large");
addr->v4.s_addr = addr->v4.s_addr & htonl(prefixlen2mask(mask));
break;
- case AF_INET6:
+ case AID_INET6:
if (mask == -1)
mask = 128;
inet6applymask(&addr->v6, &addr->v6, mask);
@@ -706,7 +720,7 @@ parse_asnum(const char *word, u_int32_t
if (errstr) if (errstr)
errx(1, "AS number is %s: %s", errstr, word); errx(1, "AS number is %s: %s", errstr, word);
} else { } else {
- uval = strtonum(word, 0, USHRT_MAX - 1, &errstr); - uval = strtonum(word, 0, ASNUM_MAX - 1, &errstr);
+ uval = strtonum(word, 0, ASNUM_MAX - 1, &errstr); + uval = strtonum(word, 0, UINT_MAX, &errstr);
if (errstr) if (errstr)
errx(1, "AS number is %s: %s", errstr, word); errx(1, "AS number is %s: %s", errstr, word);
} }
@@ -801,7 +825,7 @@ parse_community(const char *word, struct @@ -882,8 +896,14 @@ bgpctl_getopt(int *argc, char **argv[],
type = getcommunity(p); int ch;
done: optind = optreset = 1;
- if (as == 0 || as == USHRT_MAX) { - while ((ch = getopt((*argc) + 1, (*argv) - 1, "o:")) != -1) {
+ if (as == 0) { + while ((ch = getopt((*argc) + 1, (*argv) - 1, "46o:")) != -1) {
fprintf(stderr, "Invalid community\n"); switch (ch) {
return (0); + case '4':
} + res.flags = (res.flags | F_IPV4) & ~F_IPV6;
@@ -814,7 +838,7 @@ done: + break;
+ case '6':
+ res.flags = (res.flags | F_IPV6) & ~F_IPV4;
+ break;
case 'o':
res.irr_outdir = optarg;
break; break;
default:
/* unknown */
- fprintf(stderr, "Invalid well-known community\n");
+ fprintf(stderr, "Unknown well-known community\n");
return (0);
}
@@ -856,33 +880,6 @@ parse_nexthop(const char *word, struct p
return (1);
}
-/* XXX local copies from kroute.c, should go to a shared file */
-in_addr_t
-prefixlen2mask(u_int8_t prefixlen)
-{
- if (prefixlen == 0)
- return (0);
-
- return (0xffffffff << (32 - prefixlen));
-}
-
-void
-inet6applymask(struct in6_addr *dest, const struct in6_addr *src, int prefixlen)
-{
- struct in6_addr mask;
- int i;
-
- bzero(&mask, sizeof(mask));
- for (i = 0; i < prefixlen / 8; i++)
- mask.s6_addr[i] = 0xff;
- i = prefixlen % 8;
- if (i)
- mask.s6_addr[prefixlen / 8] = 0xff00 >> i;
-
- for (i = 0; i < 16; i++)
- dest->s6_addr[i] = src->s6_addr[i] & mask.s6_addr[i];
-}
-
int
bgpctl_getopt(int *argc, char **argv[], int type)
{

View file

@ -1,22 +1,32 @@
Index: bgpctl/parser.h Index: bgpctl/parser.h
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpctl/parser.h,v RCS file: /home/cvs/private/hrs/openbgpd/bgpctl/parser.h,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.6
retrieving revision 1.1.1.2 retrieving revision 1.1.1.7
diff -u -p -r1.1.1.1 -r1.1.1.2 diff -u -p -r1.1.1.6 -r1.1.1.7
--- bgpctl/parser.h 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpctl/parser.h 14 Feb 2010 20:20:14 -0000 1.1.1.6
+++ bgpctl/parser.h 9 Jul 2009 16:49:55 -0000 1.1.1.2 +++ bgpctl/parser.h 14 Feb 2010 20:27:21 -0000 1.1.1.7
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: parser.h,v 1.18 2008/06/07 18:14:41 henning Exp $ */ -/* $OpenBSD: parser.h,v 1.19 2009/06/06 06:05:41 claudio Exp $ */
+/* $OpenBSD: parser.h,v 1.19 2009/06/06 06:05:41 claudio Exp $ */ +/* $OpenBSD: parser.h,v 1.21 2010/01/10 00:16:23 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -56,6 +56,7 @@ struct parse_result { @@ -37,6 +37,8 @@ enum actions {
struct filter_set_head set; FIB,
struct filter_community community; FIB_COUPLE,
char peerdesc[PEER_DESCR_LEN]; FIB_DECOUPLE,
+ char rib[PEER_DESCR_LEN]; + LOG_VERBOSE,
char *irr_outdir; + LOG_BRIEF,
NEIGHBOR,
NEIGHBOR_UP,
NEIGHBOR_DOWN,
@@ -61,7 +63,7 @@ struct parse_result {
int flags; int flags;
enum actions action; enum actions action;
u_int8_t prefixlen;
- sa_family_t af;
+ u_int8_t aid;
};
__dead void usage(void);

View file

@ -1,122 +0,0 @@
--- /dev/null 1970-01-01 01:00:00.000000000 +0100
+++ bgpctl/util.h 2008-03-18 13:27:29.000000000 +0100
@@ -0,0 +1,119 @@
+/* $OpenBSD: util.h,v 1.27 2006/06/14 02:14:25 krw Exp $ */
+/* $NetBSD: util.h,v 1.2 1996/05/16 07:00:22 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 1995
+ * The Regents of the University of California. All rights reserved.
+ * Portions Copyright (c) 1996, Jason Downs. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _UTIL_H_
+#define _UTIL_H_
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+/*
+ * fparseln() specific operation flags.
+ */
+#define FPARSELN_UNESCESC 0x01
+#define FPARSELN_UNESCCONT 0x02
+#define FPARSELN_UNESCCOMM 0x04
+#define FPARSELN_UNESCREST 0x08
+#define FPARSELN_UNESCALL 0x0f
+
+/*
+ * opendev() specific operation flags.
+ */
+#define OPENDEV_PART 0x01 /* Try to open the raw partition. */
+#define OPENDEV_BLCK 0x04 /* Open block, not character device. */
+
+/*
+ * uucplock(3) specific flags.
+ */
+#define UU_LOCK_INUSE (1)
+#define UU_LOCK_OK (0)
+#define UU_LOCK_OPEN_ERR (-1)
+#define UU_LOCK_READ_ERR (-2)
+#define UU_LOCK_CREAT_ERR (-3)
+#define UU_LOCK_WRITE_ERR (-4)
+#define UU_LOCK_LINK_ERR (-5)
+#define UU_LOCK_TRY_ERR (-6)
+#define UU_LOCK_OWNER_ERR (-7)
+
+/*
+ * fmt_scaled(3) specific flags.
+ */
+#define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
+
+/*
+ * stub struct definitions.
+ */
+struct __sFILE;
+struct login_cap;
+struct passwd;
+struct termios;
+struct utmp;
+struct winsize;
+
+__BEGIN_DECLS
+char *fparseln(struct __sFILE *, size_t *, size_t *, const char[3], int);
+void login(struct utmp *);
+int login_tty(int);
+int logout(const char *);
+void logwtmp(const char *, const char *, const char *);
+int opendev(char *, int, int, char **);
+int pidfile(const char *);
+void pw_setdir(const char *);
+char *pw_file(const char *);
+int pw_lock(int retries);
+int pw_mkdb(char *, int);
+int pw_abort(void);
+void pw_init(void);
+void pw_edit(int, const char *);
+void pw_prompt(void);
+void pw_copy(int, int, const struct passwd *, const struct passwd *);
+int pw_scan(char *, struct passwd *, int *);
+void pw_error(const char *, int, int);
+int openpty(int *, int *, char *, struct termios *, struct winsize *);
+int opendisk(const char *path, int flags, char *buf, size_t buflen,
+ int iscooked);
+pid_t forkpty(int *, char *, struct termios *, struct winsize *);
+int getmaxpartitions(void);
+int getrawpartition(void);
+void login_fbtab(const char *, uid_t, gid_t);
+int login_check_expire(struct __sFILE *, struct passwd *, char *, int);
+char *readlabelfs(char *, int);
+const char *uu_lockerr(int _uu_lockresult);
+int uu_lock(const char *_ttyname);
+int uu_lock_txfr(const char *_ttyname, pid_t _pid);
+int uu_unlock(const char *_ttyname);
+int fmt_scaled(long long number, char *result);
+int scan_scaled(char *scaled, long long *result);
+__END_DECLS
+
+#endif /* !_UTIL_H_ */

View file

@ -0,0 +1,24 @@
Index: bgpctl/whois.c
===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpctl/whois.c,v
retrieving revision 1.1.1.5
retrieving revision 1.1.1.6
diff -u -p -r1.1.1.5 -r1.1.1.6
--- bgpctl/whois.c 14 Feb 2010 20:20:14 -0000 1.1.1.5
+++ bgpctl/whois.c 14 Feb 2010 20:27:21 -0000 1.1.1.6
@@ -1,4 +1,4 @@
-/* $OpenBSD: whois.c,v 1.3 2007/03/05 16:43:24 henning Exp $ */
+/* $OpenBSD: whois.c,v 1.4 2009/09/08 15:40:25 claudio Exp $ */
/*
* Copyright (c) 2007 Henning Brauer <henning@openbsd.org>
@@ -68,7 +68,8 @@ char *qtype_opts[] = {
"",
"-T aut-num",
"-K -T as-set",
- "-K -T route -i origin"
+ "-K -T route -i origin",
+ "-K -T route6 -i origin"
};
char *server = "whois.radb.net";

View file

@ -1,20 +1,18 @@
Index: bgpd/Makefile Index: bgpd/Makefile
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/Makefile,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/Makefile,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.2
retrieving revision 1.6 retrieving revision 1.6
diff -u -p -r1.1.1.1 -r1.6 diff -u -p -r1.1.1.2 -r1.6
--- bgpd/Makefile 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/Makefile 9 Jul 2009 16:49:54 -0000 1.1.1.2
+++ bgpd/Makefile 9 Jul 2009 17:22:14 -0000 1.6 +++ bgpd/Makefile 9 Jul 2009 17:22:14 -0000 1.6
@@ -1,17 +1,23 @@ @@ -1,15 +1,23 @@
-# $OpenBSD: Makefile,v 1.27 2007/12/20 17:08:47 henning Exp $ # $OpenBSD: Makefile,v 1.28 2009/06/25 14:14:54 deraadt Exp $
+# $OpenBSD: Makefile,v 1.28 2009/06/25 14:14:54 deraadt Exp $
-.PATH: ${.CURDIR}/..
+.PATH: ${.CURDIR}/.. ${.CURDIR}/../openbsd-compat +.PATH: ${.CURDIR}/.. ${.CURDIR}/../openbsd-compat
+ +
+CONFFILE?= ${PREFIX}/etc/bgpd.conf +CONFFILE?= ${PREFIX}/etc/bgpd.conf
+
PROG= bgpd PROG= bgpd
SRCS= bgpd.c buffer.c session.c log.c parse.y config.c imsg.c \ 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 \ rde.c rde_rib.c rde_decide.c rde_prefix.c mrt.c kroute.c \

View file

@ -1,14 +1,14 @@
Index: bgpd/bgpd.8 Index: bgpd/bgpd.8
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/bgpd.8,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/bgpd.8,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.8
retrieving revision 1.6 retrieving revision 1.7
diff -u -p -r1.1.1.1 -r1.6 diff -u -p -r1.1.1.8 -r1.7
--- bgpd/bgpd.8 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/bgpd.8 14 Feb 2010 20:19:57 -0000 1.1.1.8
+++ bgpd/bgpd.8 22 Oct 2009 15:10:02 -0000 1.6 +++ bgpd/bgpd.8 4 Feb 2010 16:22:23 -0000 1.7
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-.\" $OpenBSD: bgpd.8,v 1.27 2007/05/31 19:20:22 jmc Exp $ -.\" $OpenBSD: bgpd.8,v 1.28 2009/01/13 23:01:36 sthen Exp $
+.\" $OpenBSD: bgpd.8,v 1.29 2009/08/06 08:53:11 claudio Exp $ +.\" $OpenBSD: bgpd.8,v 1.33 2009/12/16 15:40:55 claudio Exp $
.\" .\"
.\" Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> .\" Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
.\" .\"
@ -16,8 +16,8 @@ diff -u -p -r1.1.1.1 -r1.6
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
-.Dd $Mdocdate: May 31 2007 $ -.Dd $Mdocdate: January 13 2009 $
+.Dd $Mdocdate: September 2 2009 $ +.Dd $Mdocdate: October 26 2009 $
.Dt BGPD 8 .Dt BGPD 8
.Os .Os
.Sh NAME .Sh NAME
@ -51,7 +51,19 @@ diff -u -p -r1.1.1.1 -r1.6
default default
.Nm .Nm
configuration file configuration file
@@ -175,11 +175,6 @@ control socket @@ -165,6 +165,11 @@ control socket
.%D August 1998
.Re
.Rs
+.%R RFC 2545
+.%T "Use of BGP-4 Multiprotocol Extensions for IPv6 Inter-Domain Routing"
+.%D March 1999
+.Re
+.Rs
.%R RFC 2796
.%T "BGP Route Reflection - An Alternative to Full Mesh IBGP"
.%D April 2000
@@ -175,11 +180,6 @@ control socket
.%D September 2000 .%D September 2000
.Re .Re
.Rs .Rs
@ -63,10 +75,15 @@ diff -u -p -r1.1.1.1 -r1.6
.%R RFC 3682 .%R RFC 3682
.%T "The Generalized TTL Security Mechanism (GTSM)" .%T "The Generalized TTL Security Mechanism (GTSM)"
.%D February 2004 .%D February 2004
@@ -190,14 +185,29 @@ control socket @@ -190,6 +190,16 @@ control socket
.%D April 2004 .%D April 2004
.Re .Re
.Rs .Rs
+.%R RFC 4360
+.%T "BGP Extended Communities Attribute"
+.%D February 2006
+.Re
+.Rs
+.%R RFC 4486 +.%R RFC 4486
+.%T "BGP Cease Notification Message Subcodes" +.%T "BGP Cease Notification Message Subcodes"
+.%D April 2006 +.%D April 2006
@ -75,14 +92,10 @@ diff -u -p -r1.1.1.1 -r1.6
.%R RFC 4760 .%R RFC 4760
.%T "Multiprotocol Extensions for BGP-4" .%T "Multiprotocol Extensions for BGP-4"
.%D January 2007 .%D January 2007
.Re @@ -199,6 +209,16 @@ control socket
.Rs
-.%R draft-ietf-idr-as4bytes-13
+.%R RFC 4893
.%T "BGP Support for Four-octet AS Number Space" .%T "BGP Support for Four-octet AS Number Space"
-.%D February 2007 .%D May 2007
+.%D May 2007 .Re
+.Re
+.Rs +.Rs
+.%R RFC 5492 +.%R RFC 5492
+.%T "Capabilities Advertisement with BGP-4" +.%T "Capabilities Advertisement with BGP-4"
@ -92,6 +105,7 @@ diff -u -p -r1.1.1.1 -r1.6
+.%R draft-ietf-idr-optional-transitive-00 +.%R draft-ietf-idr-optional-transitive-00
+.%T "Error Handling for Optional Transitive BGP Attributes" +.%T "Error Handling for Optional Transitive BGP Attributes"
+.%D April 2009 +.%D April 2009
.Re +.Re
.Sh HISTORY .Sh HISTORY
The The
.Nm

View file

@ -1,72 +1,145 @@
Index: bgpd/bgpd.c Index: bgpd/bgpd.c
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/bgpd.c,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/bgpd.c,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.7
retrieving revision 1.1.1.3 retrieving revision 1.1.1.8
diff -u -p -r1.1.1.1 -r1.1.1.3 diff -u -p -r1.1.1.7 -r1.1.1.8
--- bgpd/bgpd.c 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/bgpd.c 14 Feb 2010 20:19:57 -0000 1.1.1.7
+++ bgpd/bgpd.c 10 Aug 2009 21:09:57 -0000 1.1.1.3 +++ bgpd/bgpd.c 14 Feb 2010 20:27:06 -0000 1.1.1.8
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.c,v 1.145 2008/05/12 19:15:02 pyr Exp $ */ -/* $OpenBSD: bgpd.c,v 1.148 2009/06/07 00:30:23 claudio Exp $ */
+/* $OpenBSD: bgpd.c,v 1.149 2009/07/20 15:00:13 claudio Exp $ */ +/* $OpenBSD: bgpd.c,v 1.154 2010/02/11 14:40:06 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -58,6 +58,7 @@ volatile sig_atomic_t reconfig = 0; @@ -101,15 +101,11 @@ int
pid_t reconfpid = 0; main(int argc, char *argv[])
struct imsgbuf *ibuf_se; {
struct imsgbuf *ibuf_rde; struct bgpd_config conf;
+struct rib_names ribnames = SIMPLEQ_HEAD_INITIALIZER(ribnames); - struct peer *peer_l, *p;
struct mrt_head mrt_l;
void - struct network_head net_l;
sighdlr(int sig) + struct peer *peer_l, *p;
@@ -108,6 +109,7 @@ main(int argc, char *argv[]) struct filter_head *rules_l;
struct filter_rule *r; - struct network *net;
- struct filter_rule *r;
struct mrt *m; struct mrt *m;
struct listen_addr *la; struct listen_addr *la;
+ struct rde_rib *rr; - struct rde_rib *rr;
struct pollfd pfd[POLL_MAX]; struct pollfd pfd[POLL_MAX];
pid_t io_pid = 0, rde_pid = 0, pid; pid_t io_pid = 0, rde_pid = 0, pid;
char *conffile; char *conffile;
@@ -181,7 +183,8 @@ main(int argc, char *argv[]) @@ -129,9 +125,8 @@ main(int argc, char *argv[])
err(1, NULL);
if (conf.opts & BGPD_OPT_NOACTION) { bzero(&conf, sizeof(conf));
- LIST_INIT(&mrt_l);
- TAILQ_INIT(&net_l);
TAILQ_INIT(rules_l);
+ LIST_INIT(&mrt_l);
peer_l = NULL;
conf.csock = SOCKET_NAME;
@@ -158,6 +153,7 @@ main(int argc, char *argv[])
if (conf.opts & BGPD_OPT_VERBOSE) if (conf.opts & BGPD_OPT_VERBOSE)
- print_config(&conf, &net_l, peer_l, rules_l, &mrt_l); conf.opts |= BGPD_OPT_VERBOSE2;
+ print_config(&conf, &ribnames, &net_l, peer_l, rules_l, conf.opts |= BGPD_OPT_VERBOSE;
+ &mrt_l); + log_verbose(1);
else break;
fprintf(stderr, "configuration OK\n"); case 'r':
exit(0); conf.rcsock = optarg;
@@ -225,9 +228,9 @@ main(int argc, char *argv[]) @@ -176,12 +172,15 @@ main(int argc, char *argv[])
prepare_listeners(&conf); if (argc > 0)
usage();
- if (parse_config(conffile, &conf, &mrt_l, &peer_l, &net_l, rules_l)) {
- free(rules_l);
- exit(1);
- }
-
if (conf.opts & BGPD_OPT_NOACTION) {
+ struct network_head net_l;
+ TAILQ_INIT(&net_l);
+ if (parse_config(conffile, &conf, &mrt_l, &peer_l, &net_l,
+ rules_l)) {
+ free(rules_l);
+ exit(1);
+ }
+
if (conf.opts & BGPD_OPT_VERBOSE)
print_config(&conf, &ribnames, &net_l, peer_l, rules_l,
&mrt_l);
@@ -225,13 +224,10 @@ main(int argc, char *argv[])
session_socket_blockmode(pipe_s2r_c[0], BM_NONBLOCK);
session_socket_blockmode(pipe_s2r_c[1], BM_NONBLOCK);
- prepare_listeners(&conf);
-
/* fork children */ /* fork children */
- rde_pid = rde_main(&conf, peer_l, &net_l, rules_l, &mrt_l, - rde_pid = rde_main(&conf, peer_l, &net_l, rules_l, &mrt_l, &ribnames,
+ rde_pid = rde_main(&conf, peer_l, &net_l, rules_l, &mrt_l, &ribnames, - pipe_m2r, pipe_s2r, pipe_m2s, pipe_s2r_c, debug);
pipe_m2r, pipe_s2r, pipe_m2s, pipe_s2r_c, debug); - io_pid = session_main(&conf, peer_l, &net_l, rules_l, &mrt_l, &ribnames,
- io_pid = session_main(&conf, peer_l, &net_l, rules_l, &mrt_l, - pipe_m2s, pipe_s2r, pipe_m2r, pipe_s2r_c);
+ io_pid = session_main(&conf, peer_l, &net_l, rules_l, &mrt_l, &ribnames, + rde_pid = rde_main(pipe_m2r, pipe_s2r, pipe_m2s, pipe_s2r_c, debug);
pipe_m2s, pipe_s2r, pipe_m2r, pipe_s2r_c); + io_pid = session_main(pipe_m2s, pipe_s2r, pipe_m2r, pipe_s2r_c,
+ conf.csock, conf.rcsock);
setproctitle("parent"); setproctitle("parent");
@@ -271,6 +274,10 @@ main(int argc, char *argv[])
close(la->fd); @@ -254,33 +250,13 @@ main(int argc, char *argv[])
la->fd = -1; imsg_init(ibuf_se, pipe_m2s[0]);
imsg_init(ibuf_rde, pipe_m2r[0]);
mrt_init(ibuf_rde, ibuf_se);
+ quit = reconfigure(conffile, &conf, &mrt_l, &peer_l, rules_l);
if ((rfd = kr_init(!(conf.flags & BGPD_FLAG_NO_FIB_UPDATE),
conf.rtableid)) == -1)
quit = 1;
if (pftable_clear_all() != 0)
quit = 1;
- while ((net = TAILQ_FIRST(&net_l)) != NULL) {
- TAILQ_REMOVE(&net_l, net, entry);
- filterset_free(&net->net.attrset);
- free(net);
- }
-
- while ((r = TAILQ_FIRST(rules_l)) != NULL) {
- TAILQ_REMOVE(rules_l, r, entry);
- free(r);
- }
- TAILQ_FOREACH(la, conf.listen_addrs, entry) {
- close(la->fd);
- la->fd = -1;
- }
- while ((rr = SIMPLEQ_FIRST(&ribnames))) {
- SIMPLEQ_REMOVE_HEAD(&ribnames, entry);
- free(rr);
- }
-
- mrt_reconfigure(&mrt_l);
-
while (quit == 0) {
bzero(pfd, sizeof(pfd));
pfd[PFD_PIPE_SESSION].fd = ibuf_se->fd;
@@ -389,11 +365,12 @@ main(int argc, char *argv[])
LIST_REMOVE(m, entry);
free(m);
} }
+ while ((rr = SIMPLEQ_FIRST(&ribnames))) { - while ((la = TAILQ_FIRST(conf.listen_addrs)) != NULL) {
+ SIMPLEQ_REMOVE_HEAD(&ribnames, entry); - TAILQ_REMOVE(conf.listen_addrs, la, entry);
+ free(rr); - close(la->fd);
- free(la);
- }
+ if (conf.listen_addrs)
+ while ((la = TAILQ_FIRST(conf.listen_addrs)) != NULL) {
+ TAILQ_REMOVE(conf.listen_addrs, la, entry);
+ close(la->fd);
+ free(la);
+ } + }
mrt_reconfigure(&mrt_l); free(rules_l);
control_cleanup(conf.csock);
@@ -452,10 +459,15 @@ reconfigure(char *conffile, struct bgpd_ @@ -464,6 +441,10 @@ reconfigure(char *conffile, struct bgpd_
struct peer *p;
struct filter_rule *r;
struct listen_addr *la;
+ struct rde_rib *rr;
if (parse_config(conffile, conf, mrt_l, peer_l, &net_l, rules_l)) { if (parse_config(conffile, conf, mrt_l, peer_l, &net_l, rules_l)) {
log_warnx("config file %s has errors, not reloading", log_warnx("config file %s has errors, not reloading",
conffile); conffile);
@ -77,19 +150,59 @@ diff -u -p -r1.1.1.1 -r1.1.1.3
return (1); return (1);
} }
@@ -488,6 +500,15 @@ reconfigure(char *conffile, struct bgpd_ @@ -550,8 +531,8 @@ int
la->fd = -1; dispatch_imsg(struct imsgbuf *ibuf, int idx)
} {
struct imsg imsg;
- int n;
- int rv;
+ ssize_t n;
+ int rv, verbose;
+ /* RIBs for the RDE */ if ((n = imsg_read(ibuf)) == -1)
+ while ((rr = SIMPLEQ_FIRST(&ribnames))) { return (-1);
+ SIMPLEQ_REMOVE_HEAD(&ribnames, entry); @@ -692,6 +673,11 @@ dispatch_imsg(struct imsgbuf *ibuf, int
+ if (imsg_compose(ibuf_rde, IMSG_RECONF_RIB, 0, 0, -1, carp_demote_set(msg->demote_group, msg->level);
+ rr, sizeof(struct rde_rib)) == -1) }
+ return (-1); break;
+ free(rr); + case IMSG_CTL_LOG_VERBOSE:
+ } + /* already checked by SE */
+ + memcpy(&verbose, imsg.data, sizeof(verbose));
/* networks for the RDE */ + log_verbose(verbose);
while ((n = TAILQ_FIRST(&net_l)) != NULL) { + break;
if (imsg_compose(ibuf_rde, IMSG_NETWORK_ADD, 0, 0, -1, default:
break;
}
@@ -707,7 +693,7 @@ send_nexthop_update(struct kroute_nextho
{
char *gw = NULL;
- if (msg->gateway.af)
+ if (msg->gateway.aid)
if (asprintf(&gw, ": via %s",
log_addr(&msg->gateway)) == -1) {
log_warn("send_nexthop_update");
@@ -717,7 +703,7 @@ send_nexthop_update(struct kroute_nextho
log_info("nexthop %s now %s%s%s", log_addr(&msg->nexthop),
msg->valid ? "valid" : "invalid",
msg->connected ? ": directly connected" : "",
- msg->gateway.af ? gw : "");
+ msg->gateway.aid ? gw : "");
free(gw);
@@ -758,12 +744,12 @@ bgpd_redistribute(int type, struct krout
fatalx("bgpd_redistribute: unable to redistribute v4 and v6"
"together");
if (kr != NULL) {
- net.prefix.af = AF_INET;
+ net.prefix.aid = AID_INET;
net.prefix.v4.s_addr = kr->prefix.s_addr;
net.prefixlen = kr->prefixlen;
}
if (kr6 != NULL) {
- net.prefix.af = AF_INET6;
+ net.prefix.aid = AID_INET6;
memcpy(&net.prefix.v6, &kr6->prefix, sizeof(struct in6_addr));
net.prefixlen = kr6->prefixlen;
}

View file

@ -1,14 +1,14 @@
Index: bgpd/bgpd.conf.5 Index: bgpd/bgpd.conf.5
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/bgpd.conf.5,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/bgpd.conf.5,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.7
retrieving revision 1.5 retrieving revision 1.6
diff -u -p -r1.1.1.1 -r1.5 diff -u -p -r1.1.1.7 -r1.6
--- bgpd/bgpd.conf.5 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/bgpd.conf.5 14 Feb 2010 20:19:57 -0000 1.1.1.7
+++ bgpd/bgpd.conf.5 22 Oct 2009 15:10:02 -0000 1.5 +++ bgpd/bgpd.conf.5 4 Feb 2010 16:22:23 -0000 1.6
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-.\" $OpenBSD: bgpd.conf.5,v 1.88 2008/03/22 08:38:38 claudio Exp $ -.\" $OpenBSD: bgpd.conf.5,v 1.94 2009/06/07 00:31:22 claudio Exp $
+.\" $OpenBSD: bgpd.conf.5,v 1.94 2009/06/07 00:31:22 claudio Exp $ +.\" $OpenBSD: bgpd.conf.5,v 1.103 2009/12/16 15:40:55 claudio Exp $
.\" .\"
.\" Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org> .\" Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
.\" Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> .\" Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -16,73 +16,39 @@ diff -u -p -r1.1.1.1 -r1.5
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
-.Dd $Mdocdate: March 22 2008 $ -.Dd $Mdocdate: June 7 2009 $
+.Dd $Mdocdate: October 6 2009 $ +.Dd $Mdocdate: November 26 2009 $
.Dt BGPD.CONF 5 .Dt BGPD.CONF 5
.Os .Os
.Sh NAME .Sh NAME
@@ -123,14 +123,26 @@ sets the local AS to 65001. @@ -93,7 +93,7 @@ Set the local
The AS numbers 64512 \(en 65534 are designated for private use. .Em autonomous system
The AS number 23456 is a specially designated Autonomous System Number and number to
should not be used. .Ar as-number .
-4-byte AS numbers are specified as two numbers separated by a dot. -If the first AS number is a 4-byte AS it is possible to specifiy a secondary
-For example: +If the first AS number is a 4-byte AS it is possible to specify a secondary
+4-byte AS numbers are specified as two numbers separated by a dot 2-byte AS number which is used for neighbors which do not support 4-byte AS
+(ASDOT format), numbers.
+for example: The default for the secondary AS is 23456.
.Bd -literal -offset indent @@ -313,7 +313,7 @@ is only compared between peers belonging
AS 3.10 .Ic rib Ar name
.Ed .Op Ic no Ic evaluate
.Pp
+or as a large number (ASPLAIN format), for example:
+.Bd -literal -offset indent
+AS 196618
+.Ed
+.Pp
+.It Ic connect-retry Ar seconds
+Set the number of seconds before retrying to open a connection.
+This timer should be sufficiently large in EBGP configurations.
+The default is 120 seconds.
+.Pp
.It Xo
.Ic dump
+.Op Ic rib Ar name
.Pq Ic table Ns \&| Ns Ic table-mp
.Ar file Op Ar timeout
.Xc .Xc
@@ -145,7 +157,8 @@ Dump the RIB, a.k.a. the -Creat an additional RIB named
and all BGP messages in Multi-threaded Routing Toolkit (MRT) format. +Create an additional RIB named
Dumping the RIB is normally an expensive operation, .Ar name .
but it should not influence the session handling. It is possible to disable the decision process per RIB with the
-Excessive dumping may result in delayed update processing. .Ic no Ic evaluate
+It is possible to dump alternate RIB with the use of @@ -321,7 +321,7 @@ flag.
+.Ar name . .Ic Adj-RIB-In
.Pp and
For example, the following will dump the entire table to the .Ic Loc-RIB
.Xr strftime 3 Ns -expanded -are created automaticaly and used as default.
@@ -297,6 +310,21 @@ is only compared between peers belonging +are created automatically and used as default.
.Pp .Pp
.It Xo .It Xo
.Ic rde .Ic rde
+.Ic rib Ar name @@ -483,6 +483,17 @@ Only routes for that address family and
+.Op Ic no Ic evaluate
+.Xc
+Create an additional RIB named
+.Ar name .
+It is possible to disable the decision process per RIB with the
+.Ic no Ic evaluate
+flag.
+.Ic Adj-RIB-In
+and
+.Ic Loc-RIB
+are created automaticaly and used as default.
+.Pp
+.It Xo
+.Ic rde
.Ic route-age
.Pq Ic ignore Ns \&| Ns Ic evaluate
.Xc
@@ -455,6 +483,17 @@ Only routes for that address family and
announced and processed. announced and processed.
.Pp .Pp
.It Xo .It Xo
@ -100,7 +66,7 @@ diff -u -p -r1.1.1.1 -r1.5
.Ic announce capabilities .Ic announce capabilities
.Pq Ic yes Ns \&| Ns Ic no .Pq Ic yes Ns \&| Ns Ic no
.Xc .Xc
@@ -465,6 +504,29 @@ This can be helpful to connect to old or @@ -493,6 +504,29 @@ This can be helpful to connect to old or
The default is The default is
.Ic yes . .Ic yes .
.Pp .Pp
@ -130,7 +96,16 @@ diff -u -p -r1.1.1.1 -r1.5
.It Ic demote Ar group .It Ic demote Ar group
Increase the Increase the
.Xr carp 4 .Xr carp 4
@@ -561,6 +623,12 @@ Inherited from the global configuration @@ -504,7 +538,7 @@ The demotion counter will be increased a
.Xr bgpd 8
starts and decreased
60 seconds after the session went to state
-.Em ESTABLISHED.
+.Em ESTABLISHED .
For neighbors added at runtime, the demotion counter is only increased after
the session has been
.Em ESTABLISHED
@@ -589,6 +623,12 @@ Inherited from the global configuration
Set the minimal acceptable holdtime. Set the minimal acceptable holdtime.
Inherited from the global configuration if not given. Inherited from the global configuration if not given.
.Pp .Pp
@ -143,11 +118,11 @@ diff -u -p -r1.1.1.1 -r1.5
.It Xo .It Xo
.Ic ipsec .Ic ipsec
.Pq Ic ah Ns \&| Ns Ic esp .Pq Ic ah Ns \&| Ns Ic esp
@@ -611,11 +679,11 @@ is responsible for managing the session @@ -639,11 +679,11 @@ is responsible for managing the session
With With
.Xr isakmpd 8 , .Xr isakmpd 8 ,
it is sufficient to copy the peer's public key, found in it is sufficient to copy the peer's public key, found in
-.Pa /etc/isakmpd/private/local.pub , -.Pa /etc/isakmpd/local.pub ,
+.Pa %%PREFIX%%/etc/isakmpd/private/local.pub , +.Pa %%PREFIX%%/etc/isakmpd/private/local.pub ,
to the local machine. to the local machine.
It must be stored in a file It must be stored in a file
@ -157,44 +132,99 @@ diff -u -p -r1.1.1.1 -r1.5
The local public key must be copied to the peer in the same way. The local public key must be copied to the peer in the same way.
As As
.Xr bgpd 8 .Xr bgpd 8
@@ -670,6 +738,9 @@ Do not attempt to actively open a TCP co @@ -698,7 +738,7 @@ Do not attempt to actively open a TCP co
.It Ic remote-as Ar as-number .It Ic remote-as Ar as-number
Set the AS number of the remote system. Set the AS number of the remote system.
.Pp .Pp
-.It rib .Ar name
+.It Ic rib Ar name +.It Ic rib Ar name
+Bind the neighbor to the specified RIB. Bind the neighbor to the specified RIB.
+.Pp .Pp
.It Ic route-reflector Op Ar address .It Ic route-reflector Op Ar address
Act as an RFC 2796 @@ -1028,6 +1068,12 @@ matches a rule which has the
.Em route-reflector option set, this rule is considered the last matching rule, and evaluation
@@ -728,6 +799,18 @@ tcp md5sig key deadbeef of subsequent rules is skipped.
.Ed .Pp
+.It Ic rib Ar name
+Apply rule only to the specified RIB.
+This only applies for received updates, so not for rules using the
+.Ar to peer
+parameter.
+.Pp
.It Ic set Ar attribute ...
All matching rules can set the
.Em AS path attributes
@@ -1079,6 +1125,48 @@ Alternately, well-known communities may
or
.Ic NO_PEER .
.Pp
+.It Xo
+.Ic ext-community Op Ar delete
+.Ar subtype Ar as-number Ns Li : Ns Ar local
+.Xc
+.It Xo
+.Ic ext-community Op Ar delete
+.Ar subtype Ar IP Ns Li : Ns Ar local
+.Xc
+.It Xo
+.Ic ext-community Op Ar delete
+.Ar subtype Ar numvalue
+.Xc
+Set or delete the
+.Em Extended Community
+AS path attribute.
+Extended Communities are specified by a
+.Ar subtype
+and normally two values, a globally unique part (e.g. the AS number) and a
+local part.
+The type is selected depending on the encoding of the global part.
+Two-octet AS Specific Extended Communities and Four-octet AS Specific Extended
+Communities are encoded as
+.Ar as-number Ns Li : Ns Ar local .
+Four-octet encoding is used if the
+.Ar as-number
+is bigger then 65535 or if the AS_DOT encoding is used.
+IPv4 Address Specific Extended Communities are encoded as
+.Ar IP Ns Li : Ns Ar local .
+Opaque Extended Communities are encoded with a single numeric value.
+Currently the following subtypes are supported:
+.Bd -literal -offset indent
+rt Route Target
+soo Source of Origin
+odi OSPF Domain Identifier
+ort OSPF Route Type
+ori OSPF Router ID
+bdc BGP Data Collection
+.Ed
+.Pp
+Not all type and subtype value pairs are allowed by IANA and the parser
+will ensure that no invalid combination is created.
+.Pp
.It Ic localpref Ar number
Set the
.Em LOCAL_PREF
@@ -1108,6 +1196,20 @@ otherwise it will be set to
.Ar number .
.Pp .Pp
.It Xo .It Xo
+.Ic transparent-as +.Ic origin
+.Pq Ic yes Ns \&| Ns Ic no +.Sm off
+.Po Ic igp \*(Ba
+.Ic egp \*(Ba
+.Ic incomplete Pc
+.Sm on
+.Xc +.Xc
+If set to +Set the
+.Ic yes , +.Em ORIGIN
+.Em AS paths +AS path attribute to mark the source of this
+to EBGP neighbors are not prepended with their own AS. +route as being injected from an igp protocol, an egp protocol
+The default is inherited from the global +or being an aggregated route.
+.Ic transparent-as
+setting.
+.Pp +.Pp
+.It Xo +.It Xo
.Ic ttl-security .Ic nexthop
.Pq Ic yes Ns \&| Ns Ic no .Sm off
.Xc .Po Ar address \*(Ba
@@ -1048,6 +1131,7 @@ will be adjusted by adding or subtractin @@ -1181,8 +1283,8 @@ For prefixes with equally long paths, th
.Ar number ;
otherwise it will be set to
.Ar number .
+The default is 100.
.Pp
.It Ic med Ar number
.It Ic metric Ar number
@@ -1137,8 +1221,8 @@ For prefixes with equally long paths, th
is selected. is selected.
.El .El
.Sh FILES .Sh FILES

View file

@ -1,26 +1,27 @@
Index: bgpd/bgpd.h Index: bgpd/bgpd.h
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/bgpd.h,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/bgpd.h,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.8
retrieving revision 1.8 retrieving revision 1.10
diff -u -p -r1.1.1.1 -r1.8 diff -u -p -r1.1.1.8 -r1.10
--- bgpd/bgpd.h 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/bgpd.h 14 Feb 2010 20:19:57 -0000 1.1.1.8
+++ bgpd/bgpd.h 22 Oct 2009 15:53:39 -0000 1.8 +++ bgpd/bgpd.h 14 Feb 2010 19:53:36 -0000 1.10
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.h,v 1.222 2008/01/23 08:11:32 claudio Exp $ */ -/* $OpenBSD: bgpd.h,v 1.241 2009/06/12 16:42:53 claudio Exp $ */
+/* $OpenBSD: bgpd.h,v 1.243 2009/07/23 14:53:18 claudio Exp $ */ +/* $OpenBSD: bgpd.h,v 1.252 2010/01/13 06:02:37 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -30,9 +30,16 @@ @@ -30,11 +30,16 @@
#include <poll.h> #include <poll.h>
#include <stdarg.h> #include <stdarg.h>
-#include <imsg.h>
+#if defined(__FreeBSD__) /* compat */ +#if defined(__FreeBSD__) /* compat */
+#include "openbsd-compat.h" +#include "openbsd-compat.h"
+#endif /* defined(__FreeBSD__) */ +#endif /* defined(__FreeBSD__) */
+#include "imsg.h" +#include "imsg.h"
+
#define BGP_VERSION 4 #define BGP_VERSION 4
#define BGP_PORT 179 #define BGP_PORT 179
+#ifndef CONFFILE +#ifndef CONFFILE
@ -29,223 +30,137 @@ diff -u -p -r1.1.1.1 -r1.8
#define BGPD_USER "_bgpd" #define BGPD_USER "_bgpd"
#define PEER_DESCR_LEN 32 #define PEER_DESCR_LEN 32
#define PFTABLE_LEN 16 #define PFTABLE_LEN 16
@@ -40,6 +47,8 @@ @@ -42,8 +47,6 @@
#define IPSEC_ENC_KEY_LEN 32 #define IPSEC_ENC_KEY_LEN 32
#define IPSEC_AUTH_KEY_LEN 20 #define IPSEC_AUTH_KEY_LEN 20
+#define ASNUM_MAX 0xffffffff -#define ASNUM_MAX 0xffffffff
+ -
#define MAX_PKTSIZE 4096 #define MAX_PKTSIZE 4096
#define MIN_HOLDTIME 3 #define MIN_HOLDTIME 3
#define READ_BUF_SIZE 65535 #define READ_BUF_SIZE 65535
@@ -85,8 +94,8 @@ @@ -109,18 +112,74 @@ enum reconf_action {
/*
* Limit the number of control messages generated by the RDE and queued in
- * session enigine. The RDE limit defines how many imsg are generated in
- * on poll round. The if the SE limit is hit the RDE control socket will no
+ * session engine. The RDE limit defines how many imsg are generated in
+ * one poll round. Then if the SE limit is hit the RDE control socket will no
* longer be polled.
*/
#define RDE_RUNNER_ROUNDS 100
@@ -105,21 +114,6 @@ enum reconf_action {
RECONF_DELETE RECONF_DELETE
}; };
-struct buf { +/* Address Family Numbers as per RFC 1700 */
- TAILQ_ENTRY(buf) entry; +#define AFI_UNSPEC 0
- u_char *buf; +#define AFI_IPv4 1
- size_t size; +#define AFI_IPv6 2
- size_t wpos; +
- size_t rpos; +/* Subsequent Address Family Identifier as per RFC 4760 */
- int fd; +#define SAFI_NONE 0
-}; +#define SAFI_UNICAST 1
- +#define SAFI_MULTICAST 2
-struct msgbuf { +#define SAFI_MPLS 4
- TAILQ_HEAD(, buf) bufs; +#define SAFI_MPLSVPN 128
- u_int32_t queued; +
- int fd; +struct aid {
-}; + u_int16_t afi;
- + sa_family_t af;
+ u_int8_t safi;
+ char *name;
+};
+
+extern const struct aid aid_vals[];
+
+#define AID_UNSPEC 0
+#define AID_INET 1
+#define AID_INET6 2
+#define AID_VPN_IPv4 3
+#define AID_MAX 4
+
+#define AID_VALS { \
+ /* afi, af, safii, name */ \
+ { AFI_UNSPEC, AF_UNSPEC, SAFI_NONE, "unspec"}, \
+ { AFI_IPv4, AF_INET, SAFI_UNICAST, "IPv4 unicast" }, \
+ { AFI_IPv6, AF_INET6, SAFI_UNICAST, "IPv6 unicast" }, \
+ { AFI_IPv4, AF_INET, SAFI_MPLSVPN, "IPv4 vpn" } \
+}
+
+#define AID_PTSIZE { \
+ 0, \
+ sizeof(struct pt_entry4), \
+ sizeof(struct pt_entry6), \
+ sizeof(struct pt_entry_vpn4) \
+}
+
+struct vpn4_addr {
+ u_int64_t rd;
+ struct in_addr addr;
+ u_int8_t labelstack[21]; /* max that makes sense */
+ u_int8_t labellen;
+ u_int8_t pad1;
+ u_int8_t pad2;
+};
+
+#define BGP_MPLS_BOS 0x01
+
struct bgpd_addr { struct bgpd_addr {
sa_family_t af; - sa_family_t af;
union { union {
@@ -169,12 +163,7 @@ struct bgpd_config { struct in_addr v4;
u_int16_t short_as; struct in6_addr v6;
u_int16_t holdtime; - u_int8_t addr8[16];
u_int16_t min_holdtime; - u_int16_t addr16[8];
-}; - u_int32_t addr32[4];
- + struct vpn4_addr vpn4;
-struct buf_read { + /* maximum size for a prefix is 256 bits */
- u_char buf[READ_BUF_SIZE]; + u_int8_t addr8[32];
- u_char *rptr; + u_int16_t addr16[16];
- size_t wpos; + u_int32_t addr32[8];
+ u_int16_t connectretry; } ba; /* 128-bit address */
u_int32_t scope_id; /* iface scope id for v6 */
+ u_int8_t aid;
#define v4 ba.v4
#define v6 ba.v6
+#define vpn4 ba.vpn4
#define addr8 ba.addr8
#define addr16 ba.addr16
#define addr32 ba.addr32
@@ -205,11 +264,10 @@ struct peer_auth {
}; };
enum announce_type { struct capabilities {
@@ -235,11 +224,13 @@ struct peer_config { - u_int8_t mp_v4; /* multiprotocol extensions, RFC 4760 */
struct capabilities capabilities; - u_int8_t mp_v6;
char group[PEER_DESCR_LEN]; - u_int8_t refresh; /* route refresh, RFC 2918 */
char descr[PEER_DESCR_LEN]; - u_int8_t restart; /* graceful restart, RFC 4724 */
+ char rib[PEER_DESCR_LEN]; - u_int8_t as4byte; /* draft-ietf-idr-as4bytes-13 */
char if_depend[IFNAMSIZ]; + int8_t mp[AID_MAX]; /* multiprotocol extensions, RFC 4760 */
char demote_group[IFNAMSIZ]; + int8_t refresh; /* route refresh, RFC 2918 */
u_int32_t id; + int8_t restart; /* graceful restart, RFC 4724 */
u_int32_t groupid; + int8_t as4byte; /* draft-ietf-idr-as4bytes-13 */
u_int32_t remote_as; };
+ u_int32_t local_as;
u_int32_t max_prefix; struct peer_config {
enum announce_type announce_type; @@ -248,6 +306,7 @@ struct peer_config {
enum enforce_as enforce_as;
@@ -247,6 +238,7 @@ struct peer_config {
u_int16_t max_prefix_restart;
u_int16_t holdtime;
u_int16_t min_holdtime;
+ u_int16_t local_short_as;
u_int8_t template;
u_int8_t remote_masklen;
u_int8_t cloned;
@@ -259,8 +251,13 @@ struct peer_config {
u_int8_t softreconfig_in;
u_int8_t softreconfig_out;
u_int8_t ttlsec; /* TTL security hack */ u_int8_t ttlsec; /* TTL security hack */
+ u_int8_t flags; u_int8_t flags;
+ u_int8_t pad[3]; u_int8_t pad[3];
+ char lliface[IFNAMSIZ]; + char lliface[IFNAMSIZ];
}; };
+#define PEERFLAG_TRANS_AS 0x01 #define PEERFLAG_TRANS_AS 0x01
+ @@ -292,6 +351,7 @@ enum imsg_type {
struct network_config {
struct bgpd_addr prefix;
struct filter_set_head attrset;
@@ -274,54 +271,8 @@ struct network {
TAILQ_ENTRY(network) entry;
};
-/* ipc messages */
-
-#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
-#define MAX_IMSGSIZE 8192
-
-struct imsg_fd {
- TAILQ_ENTRY(imsg_fd) entry;
- int fd;
-};
-
-struct imsgbuf {
- TAILQ_HEAD(fds, imsg_fd) fds;
- struct buf_read r;
- struct msgbuf w;
- int fd;
- pid_t pid;
-};
-
enum imsg_type {
IMSG_NONE,
- IMSG_RECONF_CONF,
- IMSG_RECONF_PEER,
- IMSG_RECONF_FILTER,
- IMSG_RECONF_LISTENER,
- IMSG_RECONF_DONE,
- IMSG_UPDATE,
- IMSG_UPDATE_ERR,
- IMSG_SESSION_ADD,
- IMSG_SESSION_UP,
- IMSG_SESSION_DOWN,
- IMSG_MRT_OPEN,
- IMSG_MRT_REOPEN,
- IMSG_MRT_CLOSE,
- IMSG_KROUTE_CHANGE,
- IMSG_KROUTE_DELETE,
- IMSG_KROUTE6_CHANGE,
- IMSG_KROUTE6_DELETE,
- IMSG_NEXTHOP_ADD,
- IMSG_NEXTHOP_REMOVE,
- IMSG_NEXTHOP_UPDATE,
- IMSG_PFTABLE_ADD,
- IMSG_PFTABLE_REMOVE,
- IMSG_PFTABLE_COMMIT,
- IMSG_NETWORK_ADD,
- IMSG_NETWORK_REMOVE,
- IMSG_NETWORK_FLUSH,
- IMSG_NETWORK_DONE,
- IMSG_FILTER_SET,
IMSG_CTL_END,
IMSG_CTL_RELOAD,
IMSG_CTL_FIB_COUPLE,
@@ -347,23 +298,40 @@ enum imsg_type {
IMSG_CTL_SHOW_RIB_MEM, IMSG_CTL_SHOW_RIB_MEM,
IMSG_CTL_SHOW_TERSE, IMSG_CTL_SHOW_TERSE,
IMSG_CTL_SHOW_TIMER, IMSG_CTL_SHOW_TIMER,
+ IMSG_NETWORK_ADD, + IMSG_CTL_LOG_VERBOSE,
+ IMSG_NETWORK_REMOVE, IMSG_NETWORK_ADD,
+ IMSG_NETWORK_FLUSH, IMSG_NETWORK_REMOVE,
+ IMSG_NETWORK_DONE, IMSG_NETWORK_FLUSH,
+ IMSG_FILTER_SET, @@ -423,8 +483,7 @@ struct kif {
+ IMSG_RECONF_CONF, struct session_up {
+ IMSG_RECONF_RIB, struct bgpd_addr local_addr;
+ IMSG_RECONF_PEER, struct bgpd_addr remote_addr;
+ IMSG_RECONF_FILTER, - struct capabilities capa_announced;
+ IMSG_RECONF_LISTENER, - struct capabilities capa_received;
+ IMSG_RECONF_DONE, + struct capabilities capa;
+ IMSG_UPDATE, u_int32_t remote_bgpid;
+ IMSG_UPDATE_ERR, u_int16_t short_as;
+ IMSG_SESSION_ADD,
+ IMSG_SESSION_UP,
+ IMSG_SESSION_DOWN,
+ IMSG_MRT_OPEN,
+ IMSG_MRT_REOPEN,
+ IMSG_MRT_CLOSE,
+ IMSG_KROUTE_CHANGE,
+ IMSG_KROUTE_DELETE,
+ IMSG_KROUTE6_CHANGE,
+ IMSG_KROUTE6_DELETE,
+ IMSG_NEXTHOP_ADD,
+ IMSG_NEXTHOP_REMOVE,
+ IMSG_NEXTHOP_UPDATE,
+ IMSG_PFTABLE_ADD,
+ IMSG_PFTABLE_REMOVE,
+ IMSG_PFTABLE_COMMIT,
IMSG_REFRESH,
IMSG_IFINFO,
IMSG_DEMOTE
}; };
@@ -437,8 +496,13 @@ struct pftable_msg {
-struct imsg_hdr {
- u_int32_t peerid;
- pid_t pid;
- enum imsg_type type;
- u_int16_t len;
-};
-
-struct imsg {
- struct imsg_hdr hdr;
- void *data;
-};
-
struct demote_msg {
char demote_group[IFNAMSIZ];
int level;
@@ -424,6 +392,7 @@ struct kroute {
u_int16_t labelid;
u_short ifindex;
u_int8_t prefixlen;
+ u_int8_t priority;
};
struct kroute6 {
@@ -433,6 +402,7 @@ struct kroute6 {
u_int16_t labelid;
u_short ifindex;
u_int8_t prefixlen;
+ u_int8_t priority;
};
struct kroute_nexthop {
@@ -473,8 +443,13 @@ struct pftable_msg {
struct ctl_show_nexthop { struct ctl_show_nexthop {
struct bgpd_addr addr; struct bgpd_addr addr;
@ -260,73 +175,159 @@ diff -u -p -r1.1.1.1 -r1.8
}; };
struct ctl_neighbor { struct ctl_neighbor {
@@ -510,7 +485,7 @@ struct ctl_show_rib { @@ -508,6 +572,27 @@ struct filter_community {
u_int32_t med; int type;
u_int32_t prefix_cnt;
u_int32_t active_cnt;
- u_int32_t adjrib_cnt;
+ u_int32_t rib_cnt;
u_int16_t aspath_len;
u_int16_t flags;
u_int8_t prefixlen;
@@ -545,6 +520,7 @@ struct filter_community {
}; };
+struct filter_extcommunity {
+ u_int8_t type;
+ u_int8_t subtype; /* if extended type */
+ union {
+ struct ext_as {
+ u_int16_t as;
+ u_int32_t val;
+ } ext_as;
+ struct ext_as4 {
+ u_int32_t as4;
+ u_int16_t val;
+ } ext_as4;
+ struct ext_ip {
+ struct in_addr addr;
+ u_int16_t val;
+ } ext_ip;
+ u_int64_t ext_opaq; /* only 48 bits */
+ } data;
+};
+
+
struct ctl_show_rib_request { struct ctl_show_rib_request {
+ char rib[PEER_DESCR_LEN]; char rib[PEER_DESCR_LEN];
struct ctl_neighbor neighbor; struct ctl_neighbor neighbor;
struct bgpd_addr prefix; @@ -518,8 +603,8 @@ struct ctl_show_rib_request {
struct filter_as as; pid_t pid;
@@ -590,6 +566,7 @@ enum comp_ops { u_int16_t flags;
struct filter_peers { enum imsg_type type;
u_int32_t peerid; - sa_family_t af;
u_int32_t groupid; u_int8_t prefixlen;
+ u_int16_t ribid; + u_int8_t aid;
}; };
/* special community type */ enum filter_actions {
@@ -644,6 +621,7 @@ TAILQ_HEAD(filter_head, filter_rule); @@ -585,6 +670,27 @@ struct filter_peers {
#define EXT_COMMUNITY_OSPF_RTR_TYPE 6 /* RFC 4577 */
#define EXT_COMMUNITY_OSPF_RTR_ID 7 /* RFC 4577 */
#define EXT_COMMUNITY_BGP_COLLECT 8 /* RFC 4384 */
+/* other handy defines */
+#define EXT_COMMUNITY_OPAQUE_MAX 0xffffffffffffULL
+
+struct ext_comm_pairs {
+ u_int8_t type;
+ u_int8_t subtype;
+ u_int8_t transitive; /* transitive bit needs to be set */
+};
+
+#define IANA_EXT_COMMUNITIES { \
+ { EXT_COMMUNITY_TWO_AS, EXT_COMMUNITY_ROUTE_TGT, 0 }, \
+ { EXT_COMMUNITY_TWO_AS, EXT_CUMMUNITY_ROUTE_ORIG, 0 }, \
+ { EXT_COMMUNITY_TWO_AS, EXT_COMMUNITY_OSPF_DOM_ID, 0 }, \
+ { EXT_COMMUNITY_TWO_AS, EXT_COMMUNITY_BGP_COLLECT, 0 }, \
+ { EXT_COMMUNITY_FOUR_AS, EXT_COMMUNITY_ROUTE_TGT, 0 }, \
+ { EXT_COMMUNITY_FOUR_AS, EXT_CUMMUNITY_ROUTE_ORIG, 0 }, \
+ { EXT_COMMUNITY_IPV4, EXT_COMMUNITY_ROUTE_TGT, 0 }, \
+ { EXT_COMMUNITY_IPV4, EXT_CUMMUNITY_ROUTE_ORIG, 0 }, \
+ { EXT_COMMUNITY_IPV4, EXT_COMMUNITY_OSPF_RTR_ID, 0 }, \
+ { EXT_COMMUNITY_OPAQUE, EXT_COMMUNITY_OSPF_RTR_TYPE, 0 } \
+}
struct filter_rule {
TAILQ_ENTRY(filter_rule) entry; struct filter_prefix {
+ char rib[PEER_DESCR_LEN]; @@ -594,7 +700,7 @@ struct filter_prefix {
struct filter_peers peer;
struct filter_match match; struct filter_prefixlen {
struct filter_set_head set; enum comp_ops op;
@@ -697,6 +675,7 @@ struct rrefresh { - sa_family_t af;
struct rde_memstats { + u_int8_t aid;
int64_t path_cnt; u_int8_t len_min;
int64_t prefix_cnt; u_int8_t len_max;
+ int64_t rib_cnt; };
int64_t pt4_cnt; @@ -635,10 +741,13 @@ enum action_types {
int64_t pt6_cnt; ACTION_SET_NEXTHOP_SELF,
int64_t nexthop_cnt; ACTION_SET_COMMUNITY,
@@ -709,6 +688,15 @@ struct rde_memstats { ACTION_DEL_COMMUNITY,
int64_t attr_dcnt; + ACTION_SET_EXT_COMMUNITY,
+ ACTION_DEL_EXT_COMMUNITY,
ACTION_PFTABLE,
ACTION_PFTABLE_ID,
ACTION_RTLABEL,
- ACTION_RTLABEL_ID
+ ACTION_RTLABEL_ID,
+ ACTION_SET_ORIGIN
}; };
struct filter_set {
@@ -650,23 +759,31 @@ struct filter_set {
int32_t relative;
struct bgpd_addr nexthop;
struct filter_community community;
+ struct filter_extcommunity ext_community;
char pftable[PFTABLE_LEN];
char rtlabel[RTLABEL_LEN];
+ u_int8_t origin;
} action;
enum action_types type;
};
-struct rrefresh {
- u_int16_t afi;
- u_int8_t safi;
+struct rde_rib { +struct rde_rib {
+ SIMPLEQ_ENTRY(rde_rib) entry; + SIMPLEQ_ENTRY(rde_rib) entry;
+ char name[PEER_DESCR_LEN]; + char name[PEER_DESCR_LEN];
+ u_int16_t id; + u_int16_t id;
+ u_int16_t flags; + u_int16_t flags;
+}; };
+SIMPLEQ_HEAD(rib_names, rde_rib); +SIMPLEQ_HEAD(rib_names, rde_rib);
+extern struct rib_names ribnames; +extern struct rib_names ribnames;
+ +
/* Address Family Numbers as per RFC 1700 */ +/* 4-byte magic AS number */
#define AFI_IPv4 1 +#define AS_TRANS 23456
#define AFI_IPv6 2
@@ -718,11 +706,24 @@ struct rde_memstats {
#define SAFI_NONE 0x00
#define SAFI_UNICAST 0x01
#define SAFI_MULTICAST 0x02
+#define SAFI_MPLS 0x04
#define SAFI_ALL 0xff
/* 4-byte magic AS number */ struct rde_memstats {
#define AS_TRANS 23456 int64_t path_cnt;
int64_t prefix_cnt;
int64_t rib_cnt;
- int64_t pt4_cnt;
- int64_t pt6_cnt;
+ int64_t pt_cnt[AID_MAX];
int64_t nexthop_cnt;
int64_t aspath_cnt;
int64_t aspath_size;
@@ -677,28 +794,17 @@ struct rde_memstats {
int64_t attr_dcnt;
};
-struct rde_rib {
- SIMPLEQ_ENTRY(rde_rib) entry;
- char name[PEER_DESCR_LEN];
- u_int16_t id;
- u_int16_t flags;
-};
-SIMPLEQ_HEAD(rib_names, rde_rib);
-extern struct rib_names ribnames;
-
-/* Address Family Numbers as per RFC 1700 */
-#define AFI_IPv4 1
-#define AFI_IPv6 2
-#define AFI_ALL 0xffff
-
-/* Subsequent Address Family Identifier as per RFC 4760 */
-#define SAFI_NONE 0x00
-#define SAFI_UNICAST 0x01
-#define SAFI_MULTICAST 0x02
-#define SAFI_ALL 0xff
-
-/* 4-byte magic AS number */
-#define AS_TRANS 23456
+/* macros for IPv6 link-local address */ +/* macros for IPv6 link-local address */
+#if defined(__KAME__) && defined(IPV6_LINKLOCAL_PEER) +#if defined(__KAME__) && defined(IPV6_LINKLOCAL_PEER)
+#define IN6_LINKLOCAL_IFINDEX(addr) \ +#define IN6_LINKLOCAL_IFINDEX(addr) \
@ -338,77 +339,34 @@ diff -u -p -r1.1.1.1 -r1.8
+ (addr).s6_addr[3] = (index) & 0xff; \ + (addr).s6_addr[3] = (index) & 0xff; \
+ } while (0) + } while (0)
+#endif +#endif
+
/* prototypes */ /* prototypes */
/* bgpd.c */ /* bgpd.c */
void send_nexthop_update(struct kroute_nexthop *); @@ -709,6 +815,7 @@ int bgpd_filternexthop(struct kroute *
@@ -730,18 +731,6 @@ void send_imsg_session(int, pid_t, voi
int bgpd_redistribute(int, struct kroute *, struct kroute6 *);
int bgpd_filternexthop(struct kroute *, struct kroute6 *);
-/* buffer.c */
-struct buf *buf_open(size_t);
-struct buf *buf_grow(struct buf *, size_t);
-int buf_add(struct buf *, const void *, size_t);
-void *buf_reserve(struct buf *, size_t);
-int buf_close(struct msgbuf *, struct buf *);
-int buf_write(int, struct buf *);
-void buf_free(struct buf *);
-void msgbuf_init(struct msgbuf *);
-void msgbuf_clear(struct msgbuf *);
-int msgbuf_write(struct msgbuf *);
-
/* log.c */ /* log.c */
void log_init(int); void log_init(int);
+void log_verbose(int);
void vlog(int, const char *, va_list); void vlog(int, const char *, va_list);
@@ -760,19 +749,6 @@ int cmdline_symset(char *); void log_peer_warn(const struct peer_config *, const char *, ...);
/* config.c */ void log_peer_warnx(const struct peer_config *, const char *, ...);
int host(const char *, struct bgpd_addr *, u_int8_t *); @@ -779,11 +886,19 @@ const char *log_addr(const struct bgpd_a
const char *log_in6addr(const struct in6_addr *);
-/* imsg.c */ const char *log_sockaddr(struct sockaddr *);
-void imsg_init(struct imsgbuf *, int); const char *log_as(u_int32_t);
-int imsg_read(struct imsgbuf *); +const char *log_ext_subtype(u_int8_t);
-int imsg_get(struct imsgbuf *, struct imsg *);
-int imsg_compose(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t, int,
- const void *, u_int16_t);
-struct buf *imsg_create(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
- u_int16_t);
-int imsg_add(struct buf *, const void *, u_int16_t);
-int imsg_close(struct imsgbuf *, struct buf *);
-void imsg_free(struct imsg *);
-int imsg_get_fd(struct imsgbuf *);
-
/* kroute.c */
int kr_init(int, u_int);
int kr_change(struct kroute_label *);
@@ -788,10 +764,7 @@ void kr_nexthop_delete(struct bgpd_add
void kr_show_route(struct imsg *);
void kr_ifinfo(char *);
int kr_reload(void);
-in_addr_t prefixlen2mask(u_int8_t);
struct in6_addr *prefixlen2mask6(u_int8_t prefixlen);
-void inet6applymask(struct in6_addr *, const struct in6_addr *,
- int);
/* control.c */
void control_cleanup(const char *);
@@ -806,6 +779,10 @@ int pftable_addr_remove(struct pftable_m
int pftable_commit(void);
/* name2id.c */
+u_int16_t rib_name2id(const char *);
+const char *rib_id2name(u_int16_t);
+void rib_unref(u_int16_t);
+void rib_ref(u_int16_t);
u_int16_t rtlabel_name2id(const char *);
const char *rtlabel_id2name(u_int16_t);
void rtlabel_unref(u_int16_t);
@@ -829,5 +806,8 @@ const char *log_as(u_int32_t);
int aspath_snprint(char *, size_t, void *, u_int16_t); int aspath_snprint(char *, size_t, void *, u_int16_t);
int aspath_asprint(char **, void *, u_int16_t); int aspath_asprint(char **, void *, u_int16_t);
size_t aspath_strlen(void *, u_int16_t); size_t aspath_strlen(void *, u_int16_t);
+in_addr_t prefixlen2mask(u_int8_t); in_addr_t prefixlen2mask(u_int8_t);
+void inet6applymask(struct in6_addr *, const struct in6_addr *, void inet6applymask(struct in6_addr *, const struct in6_addr *,
+ int); int);
+const char *aid2str(u_int8_t);
+int aid2afi(u_int8_t, u_int16_t *, u_int8_t *);
+int afi2aid(u_int16_t, u_int8_t, u_int8_t *);
+sa_family_t aid2af(u_int8_t);
+int af2aid(sa_family_t, u_int8_t, u_int8_t *);
+struct sockaddr *addr2sa(struct bgpd_addr *, u_int16_t);
+void sa2addr(struct sockaddr *, struct bgpd_addr *);
#endif /* __BGPD_H__ */ #endif /* __BGPD_H__ */

View file

@ -1,191 +1,55 @@
Index: bgpd/buffer.c Index: bgpd/buffer.c
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/buffer.c,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/buffer.c,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.7
retrieving revision 1.1.1.4 retrieving revision 1.1.1.8
diff -u -p -r1.1.1.1 -r1.1.1.4 diff -u -p -r1.1.1.7 -r1.1.1.8
--- bgpd/buffer.c 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/buffer.c 14 Feb 2010 20:19:57 -0000 1.1.1.7
+++ bgpd/buffer.c 22 Oct 2009 14:24:02 -0000 1.1.1.4 +++ bgpd/buffer.c 14 Feb 2010 20:27:06 -0000 1.1.1.8
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: buffer.c,v 1.39 2008/03/24 16:11:02 deraadt Exp $ */ -/* $OpenBSD: buffer.c,v 1.43 2009/06/06 06:33:15 eric Exp $ */
+/* $OpenBSD: buffer.c,v 1.44 2009/07/23 18:58:42 eric Exp $ */ +/* $OpenBSD: buffer.c,v 1.44 2009/07/23 18:58:42 eric Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -16,18 +16,19 @@ @@ -144,7 +144,7 @@ int
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. buf_write(struct msgbuf *msgbuf)
*/
-#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/socket.h>
#include <sys/uio.h>
#include <errno.h>
-#include <limits.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "bgpd.h"
+#include "imsg.h"
+int buf_realloc(struct buf *, size_t);
void buf_enqueue(struct msgbuf *, struct buf *);
void buf_dequeue(struct msgbuf *, struct buf *);
@@ -42,35 +43,55 @@ buf_open(size_t len)
free(buf);
return (NULL);
}
- buf->size = len;
+ buf->size = buf->max = len;
buf->fd = -1;
return (buf);
}
struct buf *
-buf_grow(struct buf *buf, size_t len)
+buf_dynamic(size_t len, size_t max)
{ {
- void *p; struct iovec iov[IOV_MAX];
- struct buf *buf, *next;
+ struct buf *buf; + struct buf *buf;
unsigned int i = 0;
- if ((p = realloc(buf->buf, buf->size + len)) == NULL) {
- free(buf->buf);
- buf->buf = NULL;
- buf->size = 0;
+ if (max < len)
return (NULL);
- }
- buf->buf = p;
- buf->size += len;
+ if ((buf = buf_open(len)) == NULL)
+ return (NULL);
+
+ if (max > 0)
+ buf->max = max;
return (buf);
}
int
+buf_realloc(struct buf *buf, size_t len)
+{
+ u_char *b;
+
+ /* on static buffers max is eq size and so the following fails */
+ if (buf->wpos + len > buf->max) {
+ errno = ENOMEM;
+ return (-1);
+ }
+
+ b = realloc(buf->buf, buf->wpos + len);
+ if (b == NULL)
+ return (-1);
+ buf->buf = b;
+ buf->size = buf->wpos + len;
+
+ return (0);
+}
+
+int
buf_add(struct buf *buf, const void *data, size_t len)
{
if (buf->wpos + len > buf->size)
- return (-1);
+ if (buf_realloc(buf, len) == -1)
+ return (-1);
memcpy(buf->buf + buf->wpos, data, len);
buf->wpos += len;
@@ -83,27 +104,60 @@ buf_reserve(struct buf *buf, size_t len)
void *b;
if (buf->wpos + len > buf->size)
- return (NULL);
+ if (buf_realloc(buf, len) == -1)
+ return (NULL);
b = buf->buf + buf->wpos;
buf->wpos += len;
return (b);
}
-int
+void *
+buf_seek(struct buf *buf, size_t pos, size_t len)
+{
+ /* only allowed to seek in already written parts */
+ if (pos + len > buf->wpos)
+ return (NULL);
+
+ return (buf->buf + pos);
+}
+
+size_t
+buf_size(struct buf *buf)
+{
+ return (buf->wpos);
+}
+
+size_t
+buf_left(struct buf *buf)
+{
+ return (buf->max - buf->wpos);
+}
+
+void
buf_close(struct msgbuf *msgbuf, struct buf *buf)
{
buf_enqueue(msgbuf, buf);
- return (1);
}
int
-buf_write(int sock, struct buf *buf)
+buf_write(struct msgbuf *msgbuf)
{
+ struct iovec iov[IOV_MAX];
+ struct buf *buf;
+ unsigned int i = 0;
ssize_t n; ssize_t n;
- if ((n = write(sock, buf->buf + buf->rpos, @@ -153,7 +153,7 @@ buf_write(struct msgbuf *msgbuf)
- buf->size - buf->rpos)) == -1) { if (i >= IOV_MAX)
+ bzero(&iov, sizeof(iov)); break;
+ TAILQ_FOREACH(buf, &msgbuf->bufs, entry) { iov[i].iov_base = buf->buf + buf->rpos;
+ if (i >= IOV_MAX) - iov[i].iov_len = buf->size - buf->rpos;
+ break;
+ iov[i].iov_base = buf->buf + buf->rpos;
+ iov[i].iov_len = buf->wpos - buf->rpos; + iov[i].iov_len = buf->wpos - buf->rpos;
+ i++; i++;
+ } }
+
+ if ((n = writev(msgbuf->fd, iov, i)) == -1) { @@ -170,17 +170,7 @@ buf_write(struct msgbuf *msgbuf)
if (errno == EAGAIN || errno == ENOBUFS ||
errno == EINTR) /* try later */
return (0);
@@ -116,11 +170,9 @@ buf_write(int sock, struct buf *buf)
return (-2); return (-2);
} }
- if (buf->rpos + n < buf->size) { /* not all data written yet */ - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0;
- buf = next) {
- next = TAILQ_NEXT(buf, entry);
- if (buf->rpos + n >= buf->size) {
- n -= buf->size - buf->rpos;
- buf_dequeue(msgbuf, buf);
- } else {
- buf->rpos += n; - buf->rpos += n;
- return (0); - n = 0;
- } else - }
- return (1); - }
+ msgbuf_drain(msgbuf, n); + msgbuf_drain(msgbuf, n);
+
+ return (0);
}
void return (0);
@@ -139,6 +191,24 @@ msgbuf_init(struct msgbuf *msgbuf) }
@@ -201,6 +191,24 @@ msgbuf_init(struct msgbuf *msgbuf)
} }
void void
@ -210,43 +74,24 @@ diff -u -p -r1.1.1.1 -r1.1.1.4
msgbuf_clear(struct msgbuf *msgbuf) msgbuf_clear(struct msgbuf *msgbuf)
{ {
struct buf *buf; struct buf *buf;
@@ -151,14 +221,14 @@ int @@ -213,7 +221,7 @@ int
msgbuf_write(struct msgbuf *msgbuf) msgbuf_write(struct msgbuf *msgbuf)
{ {
struct iovec iov[IOV_MAX]; struct iovec iov[IOV_MAX];
- struct buf *buf, *next; - struct buf *buf, *next;
- int i = 0;
+ struct buf *buf; + struct buf *buf;
+ unsigned int i = 0; unsigned int i = 0;
ssize_t n; ssize_t n;
struct msghdr msg; struct msghdr msg;
struct cmsghdr *cmsg; @@ -270,17 +278,7 @@ msgbuf_write(struct msgbuf *msgbuf)
union {
- struct cmsghdr hdr;
- char buf[CMSG_SPACE(sizeof(int))];
+ struct cmsghdr hdr;
+ char buf[CMSG_SPACE(sizeof(int))];
} cmsgbuf;
bzero(&iov, sizeof(iov));
@@ -167,7 +237,7 @@ msgbuf_write(struct msgbuf *msgbuf)
if (i >= IOV_MAX)
break;
iov[i].iov_base = buf->buf + buf->rpos;
- iov[i].iov_len = buf->size - buf->rpos;
+ iov[i].iov_len = buf->wpos - buf->rpos;
i++;
if (buf->fd != -1)
break;
@@ -208,17 +278,7 @@ msgbuf_write(struct msgbuf *msgbuf)
buf->fd = -1; buf->fd = -1;
} }
- for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0;
- buf = next) { - buf = next) {
- next = TAILQ_NEXT(buf, entry); - next = TAILQ_NEXT(buf, entry);
- if (buf->rpos + n >= buf->size) { - if (buf->rpos + n >= buf->wpos) {
- n -= buf->size - buf->rpos; - n -= buf->wpos - buf->rpos;
- buf_dequeue(msgbuf, buf); - buf_dequeue(msgbuf, buf);
- } else { - } else {
- buf->rpos += n; - buf->rpos += n;

View file

@ -1,31 +1,12 @@
Index: bgpd/carp.c Index: bgpd/carp.c
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/carp.c,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/carp.c,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.6
retrieving revision 1.4 retrieving revision 1.4
diff -u -p -r1.1.1.1 -r1.4 diff -u -p -r1.1.1.6 -r1.4
--- bgpd/carp.c 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/carp.c 14 Feb 2010 20:19:57 -0000 1.1.1.6
+++ bgpd/carp.c 22 Oct 2009 15:10:02 -0000 1.4 +++ bgpd/carp.c 22 Oct 2009 15:10:02 -0000 1.4
@@ -1,4 +1,4 @@ @@ -93,9 +93,8 @@ carp_demote_shutdown(void)
-/* $OpenBSD: carp.c,v 1.5 2007/04/23 14:52:28 claudio Exp $ */
+/* $OpenBSD: carp.c,v 1.6 2008/09/10 15:00:01 tobias Exp $ */
/*
* Copyright (c) 2006 Henning Brauer <henning@openbsd.org>
@@ -72,8 +72,11 @@ carp_demote_init(char *group, int force)
}
/* only demote if this group already is demoted */
- if ((level = carp_demote_get(group)) == -1)
+ if ((level = carp_demote_get(group)) == -1) {
+ free(c->group);
+ free(c);
return (-1);
+ }
if (level > 0 || force)
c->do_demote = 1;
@@ -90,9 +93,8 @@ carp_demote_shutdown(void)
while ((c = TAILQ_FIRST(&carpgroups)) != NULL) { while ((c = TAILQ_FIRST(&carpgroups)) != NULL) {
TAILQ_REMOVE(&carpgroups, c, entry); TAILQ_REMOVE(&carpgroups, c, entry);
@ -37,7 +18,7 @@ diff -u -p -r1.1.1.1 -r1.4
free(c->group); free(c->group);
free(c); free(c);
@@ -102,6 +104,9 @@ carp_demote_shutdown(void) @@ -105,6 +104,9 @@ carp_demote_shutdown(void)
int int
carp_demote_get(char *group) carp_demote_get(char *group)
{ {
@ -47,7 +28,7 @@ diff -u -p -r1.1.1.1 -r1.4
int s; int s;
struct ifgroupreq ifgr; struct ifgroupreq ifgr;
@@ -124,6 +129,7 @@ carp_demote_get(char *group) @@ -127,6 +129,7 @@ carp_demote_get(char *group)
close(s); close(s);
return ((int)ifgr.ifgr_attrib.ifg_carp_demoted); return ((int)ifgr.ifgr_attrib.ifg_carp_demoted);
@ -55,7 +36,7 @@ diff -u -p -r1.1.1.1 -r1.4
} }
int int
@@ -156,6 +162,9 @@ carp_demote_set(char *group, int demote) @@ -159,6 +162,9 @@ carp_demote_set(char *group, int demote)
int int
carp_demote_ioctl(char *group, int demote) carp_demote_ioctl(char *group, int demote)
{ {
@ -65,7 +46,7 @@ diff -u -p -r1.1.1.1 -r1.4
int s, res; int s, res;
struct ifgroupreq ifgr; struct ifgroupreq ifgr;
@@ -178,4 +187,5 @@ carp_demote_ioctl(char *group, int demot @@ -181,4 +187,5 @@ carp_demote_ioctl(char *group, int demot
close(s); close(s);
return (res); return (res);

View file

@ -1,23 +1,38 @@
Index: bgpd/config.c Index: bgpd/config.c
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/config.c,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/config.c,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.6
retrieving revision 1.1.1.2 retrieving revision 1.1.1.7
diff -u -p -r1.1.1.1 -r1.1.1.2 diff -u -p -r1.1.1.6 -r1.1.1.7
--- bgpd/config.c 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/config.c 14 Feb 2010 20:19:57 -0000 1.1.1.6
+++ bgpd/config.c 9 Jul 2009 16:49:54 -0000 1.1.1.2 +++ bgpd/config.c 14 Feb 2010 20:27:06 -0000 1.1.1.7
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.50 2007/10/13 16:35:20 deraadt Exp $ */ -/* $OpenBSD: config.c,v 1.51 2009/01/26 23:10:02 claudio Exp $ */
+/* $OpenBSD: config.c,v 1.51 2009/01/26 23:10:02 claudio Exp $ */ +/* $OpenBSD: config.c,v 1.52 2009/12/01 14:28:05 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org>
@@ -145,7 +145,7 @@ get_bgpid(void) @@ -208,7 +208,7 @@ host_v4(const char *s, struct bgpd_addr
cur = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr; return (0);
if ((cur & localnet) == localnet) /* skip 127/8 */ }
continue;
- if (cur > ip) - h->af = AF_INET;
+ if (ntohl(cur) > ntohl(ip)) + h->aid = AID_INET;
ip = cur; h->v4.s_addr = ina.s_addr;
*len = bits;
@@ -225,13 +225,7 @@ host_v6(const char *s, struct bgpd_addr
hints.ai_socktype = SOCK_DGRAM; /*dummy*/
hints.ai_flags = AI_NUMERICHOST;
if (getaddrinfo(s, "0", &hints, &res) == 0) {
- h->af = AF_INET6;
- memcpy(&h->v6,
- &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr,
- sizeof(h->v6));
- h->scope_id =
- ((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id;
-
+ sa2addr(res->ai_addr, h);
freeaddrinfo(res);
return (1);
} }
freeifaddrs(ifap);

View file

@ -1,18 +1,54 @@
Index: bgpd/control.c Index: bgpd/control.c
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/control.c,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/control.c,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.7
retrieving revision 1.1.1.3 retrieving revision 1.1.1.8
diff -u -p -r1.1.1.1 -r1.1.1.3 diff -u -p -r1.1.1.7 -r1.1.1.8
--- bgpd/control.c 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/control.c 14 Feb 2010 20:19:57 -0000 1.1.1.7
+++ bgpd/control.c 22 Oct 2009 14:24:02 -0000 1.1.1.3 +++ bgpd/control.c 14 Feb 2010 20:27:06 -0000 1.1.1.8
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.60 2008/05/11 01:08:05 henning Exp $ */ -/* $OpenBSD: control.c,v 1.61 2009/05/05 20:09:19 sthen Exp $ */
+/* $OpenBSD: control.c,v 1.61 2009/05/05 20:09:19 sthen Exp $ */ +/* $OpenBSD: control.c,v 1.68 2010/01/13 06:02:37 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -328,11 +328,11 @@ control_dispatch_msg(struct pollfd *pfd, @@ -53,7 +53,7 @@ control_init(int restricted, char *path)
if (unlink(path) == -1)
if (errno != ENOENT) {
- log_warn("unlink %s", path);
+ log_warn("control_init: unlink %s", path);
close(fd);
return (-1);
}
@@ -123,14 +123,14 @@ control_accept(int listenfd, int restric
if ((connfd = accept(listenfd,
(struct sockaddr *)&sun, &len)) == -1) {
if (errno != EWOULDBLOCK && errno != EINTR)
- log_warn("session_control_accept");
+ log_warn("control_accept: accept");
return (0);
}
session_socket_blockmode(connfd, BM_NONBLOCK);
if ((ctl_conn = malloc(sizeof(struct ctl_conn))) == NULL) {
- log_warn("session_control_accept");
+ log_warn("control_accept");
close(connfd);
return (0);
}
@@ -191,7 +191,8 @@ control_dispatch_msg(struct pollfd *pfd,
{
struct imsg imsg;
struct ctl_conn *c;
- int n;
+ ssize_t n;
+ int verbose;
struct peer *p;
struct ctl_neighbor *neighbor;
struct ctl_show_rib_request *ribreq;
@@ -328,13 +329,19 @@ control_dispatch_msg(struct pollfd *pfd,
control_result(c, CTL_RES_OK); control_result(c, CTL_RES_OK);
break; break;
case IMSG_CTL_NEIGHBOR_DOWN: case IMSG_CTL_NEIGHBOR_DOWN:
@ -22,21 +58,57 @@ diff -u -p -r1.1.1.1 -r1.1.1.3
break; break;
case IMSG_CTL_NEIGHBOR_CLEAR: case IMSG_CTL_NEIGHBOR_CLEAR:
- bgp_fsm(p, EVNT_STOP); - bgp_fsm(p, EVNT_STOP);
+ session_stop(p, ERR_CEASE_ADMIN_RESET); - timer_set(p, Timer_IdleHold,
timer_set(p, Timer_IdleHold, - SESSION_CLEAR_DELAY);
SESSION_CLEAR_DELAY); + if (!p->conf.down) {
+ session_stop(p,
+ ERR_CEASE_ADMIN_RESET);
+ timer_set(p, Timer_IdleHold,
+ SESSION_CLEAR_DELAY);
+ } else {
+ session_stop(p,
+ ERR_CEASE_ADMIN_DOWN);
+ }
control_result(c, CTL_RES_OK); control_result(c, CTL_RES_OK);
@@ -396,6 +396,13 @@ control_dispatch_msg(struct pollfd *pfd, break;
control_result(c, CTL_RES_NOCAP); case IMSG_CTL_NEIGHBOR_RREFRESH:
@@ -370,7 +377,7 @@ control_dispatch_msg(struct pollfd *pfd,
neighbor->descr[PEER_DESCR_LEN - 1] = 0;
ribreq->peerid = 0;
p = NULL;
- if (neighbor->addr.af) {
+ if (neighbor->addr.aid) {
p = getpeerbyaddr(&neighbor->addr);
if (p == NULL) {
control_result(c,
@@ -397,8 +404,7 @@ control_dispatch_msg(struct pollfd *pfd,
break; break;
} }
+ if ((imsg.hdr.type == IMSG_CTL_SHOW_RIB_PREFIX) if ((imsg.hdr.type == IMSG_CTL_SHOW_RIB_PREFIX)
+ && (ribreq->prefix.af != AF_INET) - && (ribreq->prefix.af != AF_INET)
+ && (ribreq->prefix.af != AF_INET6)) { - && (ribreq->prefix.af != AF_INET6)) {
+ /* malformed request, must specify af */ + && (ribreq->prefix.aid == AID_UNSPEC)) {
+ control_result(c, CTL_RES_PARSE_ERROR); /* malformed request, must specify af */
+ break; control_result(c, CTL_RES_PARSE_ERROR);
+ } break;
c->ibuf.pid = imsg.hdr.pid; @@ -425,6 +431,20 @@ control_dispatch_msg(struct pollfd *pfd,
imsg_compose_rde(imsg.hdr.type, imsg.hdr.pid, imsg_compose_rde(imsg.hdr.type, 0,
imsg.data, imsg.hdr.len - IMSG_HEADER_SIZE); imsg.data, imsg.hdr.len - IMSG_HEADER_SIZE);
break;
+ case IMSG_CTL_LOG_VERBOSE:
+ if (imsg.hdr.len != IMSG_HEADER_SIZE +
+ sizeof(verbose))
+ break;
+
+ /* forward to other processes */
+ imsg_compose_parent(imsg.hdr.type, imsg.hdr.pid,
+ imsg.data, imsg.hdr.len - IMSG_HEADER_SIZE);
+ imsg_compose_rde(imsg.hdr.type, 0,
+ imsg.data, imsg.hdr.len - IMSG_HEADER_SIZE);
+
+ memcpy(&verbose, imsg.data, sizeof(verbose));
+ log_verbose(verbose);
+ break;
default:
break;
}

View file

@ -1,267 +1,26 @@
Index: bgpd/imsg.c Index: bgpd/imsg.c
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/imsg.c,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/imsg.c,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.6
retrieving revision 1.1.1.3 retrieving revision 1.1.1.7
diff -u -p -r1.1.1.1 -r1.1.1.3 diff -u -p -r1.1.1.6 -r1.1.1.7
--- bgpd/imsg.c 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/imsg.c 14 Feb 2010 20:19:57 -0000 1.1.1.6
+++ bgpd/imsg.c 10 Aug 2009 21:09:57 -0000 1.1.1.3 +++ bgpd/imsg.c 14 Feb 2010 20:27:06 -0000 1.1.1.7
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.c,v 1.42 2008/03/24 16:11:02 deraadt Exp $ */ -/* $OpenBSD: imsg.c,v 1.47 2009/06/08 08:30:06 dlg Exp $ */
+/* $OpenBSD: imsg.c,v 1.48 2009/08/08 18:33:40 nicm Exp $ */ +/* $OpenBSD: imsg.c,v 1.48 2009/08/08 18:33:40 nicm Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -16,7 +16,9 @@ @@ -263,6 +263,9 @@ imsg_flush(struct imsgbuf *ibuf)
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/socket.h>
#include <sys/uio.h>
#include <errno.h>
@@ -24,7 +26,9 @@
#include <string.h>
#include <unistd.h>
-#include "bgpd.h"
+#include "imsg.h"
+
+int imsg_get_fd(struct imsgbuf *);
void void
imsg_init(struct imsgbuf *ibuf, int fd) imsg_clear(struct imsgbuf *ibuf)
@@ -37,14 +41,14 @@ imsg_init(struct imsgbuf *ibuf, int fd)
TAILQ_INIT(&ibuf->fds);
}
-int
+ssize_t
imsg_read(struct imsgbuf *ibuf)
{ {
struct msghdr msg; - while (ibuf->w.queued)
struct cmsghdr *cmsg; - msgbuf_clear(&ibuf->w);
union {
struct cmsghdr hdr;
- char buf[CMSG_SPACE(sizeof(int) * 16)];
+ char buf[CMSG_SPACE(sizeof(int) * 16)];
} cmsgbuf;
struct iovec iov;
ssize_t n;
@@ -52,6 +56,7 @@ imsg_read(struct imsgbuf *ibuf)
struct imsg_fd *ifd;
bzero(&msg, sizeof(msg));
+
iov.iov_base = ibuf->r.buf + ibuf->r.wpos;
iov.iov_len = sizeof(ibuf->r.buf) - ibuf->r.wpos;
msg.msg_iov = &iov;
@@ -61,7 +66,6 @@ imsg_read(struct imsgbuf *ibuf)
if ((n = recvmsg(ibuf->fd, &msg, 0)) == -1) {
if (errno != EINTR && errno != EAGAIN) {
- log_warn("imsg_read: pipe read error");
return (-1);
}
return (-2);
@@ -74,19 +78,20 @@ imsg_read(struct imsgbuf *ibuf)
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_RIGHTS) {
fd = (*(int *)CMSG_DATA(cmsg));
- if ((ifd = calloc(1, sizeof(struct imsg_fd))) == NULL)
- fatal("imsg_read calloc");
+ if ((ifd = calloc(1, sizeof(struct imsg_fd))) == NULL) {
+ /* XXX: this return can leak */
+ return (-1);
+ }
ifd->fd = fd;
TAILQ_INSERT_TAIL(&ibuf->fds, ifd, entry);
- } else
- log_warn("imsg_read: got unexpected ctl data level %d "
- "type %d", cmsg->cmsg_level, cmsg->cmsg_type);
+ }
+ /* we do not handle other ctl data level */
}
return (n);
}
-int
+ssize_t
imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
{
size_t av, left, datalen;
@@ -99,18 +104,21 @@ imsg_get(struct imsgbuf *ibuf, struct im
memcpy(&imsg->hdr, ibuf->r.buf, sizeof(imsg->hdr));
if (imsg->hdr.len < IMSG_HEADER_SIZE ||
imsg->hdr.len > MAX_IMSGSIZE) {
- log_warnx("imsg_get: imsg hdr len %u out of bounds, type=%u",
- imsg->hdr.len, imsg->hdr.type);
+ errno = ERANGE;
return (-1);
}
if (imsg->hdr.len > av)
return (0);
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
ibuf->r.rptr = ibuf->r.buf + IMSG_HEADER_SIZE;
- if ((imsg->data = malloc(datalen)) == NULL) {
- log_warn("imsg_get");
+ if ((imsg->data = malloc(datalen)) == NULL)
return (-1);
- }
+
+ if (imsg->hdr.flags & IMSGF_HASFD)
+ imsg->fd = imsg_get_fd(ibuf);
+ else
+ imsg->fd = -1;
+
memcpy(imsg->data, ibuf->r.rptr, datalen);
if (imsg->hdr.len < av) {
@@ -124,11 +132,10 @@ imsg_get(struct imsgbuf *ibuf, struct im
}
int
-imsg_compose(struct imsgbuf *ibuf, enum imsg_type type, u_int32_t peerid,
- pid_t pid, int fd, const void *data, u_int16_t datalen)
+imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
+ pid_t pid, int fd, void *data, u_int16_t datalen)
{
struct buf *wbuf;
- int n;
if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL)
return (-1);
@@ -138,33 +145,55 @@ imsg_compose(struct imsgbuf *ibuf, enum
wbuf->fd = fd;
- if ((n = imsg_close(ibuf, wbuf)) < 0)
+ imsg_close(ibuf, wbuf);
+
+ return (1);
+}
+
+int
+imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
+ pid_t pid, int fd, const struct iovec *iov, int iovcnt)
+{
+ struct buf *wbuf;
+ int i, datalen = 0;
+
+ for (i = 0; i < iovcnt; i++)
+ datalen += iov[i].iov_len;
+
+ if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL)
return (-1);
- return (n);
+ for (i = 0; i < iovcnt; i++)
+ if (imsg_add(wbuf, iov[i].iov_base, iov[i].iov_len) == -1)
+ return (-1);
+
+ wbuf->fd = fd;
+
+ imsg_close(ibuf, wbuf);
+
+ return (1);
}
+/* ARGSUSED */
struct buf *
-imsg_create(struct imsgbuf *ibuf, enum imsg_type type, u_int32_t peerid,
+imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
pid_t pid, u_int16_t datalen)
{
struct buf *wbuf;
struct imsg_hdr hdr;
- if (datalen > MAX_IMSGSIZE - IMSG_HEADER_SIZE) {
- log_warnx("imsg_create: len %u > MAX_IMSGSIZE; "
- "type %u peerid %lu", datalen + IMSG_HEADER_SIZE,
- type, peerid);
+ datalen += IMSG_HEADER_SIZE;
+ if (datalen > MAX_IMSGSIZE) {
+ errno = ERANGE;
return (NULL);
}
- hdr.len = datalen + IMSG_HEADER_SIZE;
hdr.type = type;
+ hdr.flags = 0;
hdr.peerid = peerid;
if ((hdr.pid = pid) == 0)
hdr.pid = ibuf->pid;
- if ((wbuf = buf_open(hdr.len)) == NULL) {
- log_warn("imsg_create: buf_open");
+ if ((wbuf = buf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) {
return (NULL);
}
if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1)
@@ -174,28 +203,30 @@ imsg_create(struct imsgbuf *ibuf, enum i
}
int
-imsg_add(struct buf *msg, const void *data, u_int16_t datalen)
+imsg_add(struct buf *msg, void *data, u_int16_t datalen)
{
if (datalen)
if (buf_add(msg, data, datalen) == -1) {
- log_warnx("imsg_add: buf_add error");
buf_free(msg);
return (-1);
}
return (datalen);
}
-int
+void
imsg_close(struct imsgbuf *ibuf, struct buf *msg)
{
- int n;
+ struct imsg_hdr *hdr;
- if ((n = buf_close(&ibuf->w, msg)) < 0) {
- log_warnx("imsg_close: buf_close error");
- buf_free(msg);
- return (-1);
- }
- return (n);
+ hdr = (struct imsg_hdr *)msg->buf;
+
+ hdr->flags &= ~IMSGF_HASFD;
+ if (msg->fd != -1)
+ hdr->flags |= IMSGF_HASFD;
+
+ hdr->len = (u_int16_t)msg->wpos;
+
+ buf_close(&ibuf->w, msg);
}
void
@@ -219,3 +250,22 @@ imsg_get_fd(struct imsgbuf *ibuf)
return (fd);
}
+
+int
+imsg_flush(struct imsgbuf *ibuf)
+{
+ while (ibuf->w.queued)
+ if (msgbuf_write(&ibuf->w) < 0)
+ return (-1);
+ return (0);
+}
+
+void
+imsg_clear(struct imsgbuf *ibuf)
+{
+ int fd; + int fd;
+ +
+ msgbuf_clear(&ibuf->w); + msgbuf_clear(&ibuf->w);
+ while ((fd = imsg_get_fd(ibuf)) != -1) + while ((fd = imsg_get_fd(ibuf)) != -1)
+ close(fd); + close(fd);
+} }

View file

@ -1,116 +1,16 @@
Index: bgpd/imsg.h Index: bgpd/imsg.h
=================================================================== ===================================================================
RCS file: bgpd/imsg.h RCS file: /home/cvs/private/hrs/openbgpd/bgpd/imsg.h,v
diff -N bgpd/imsg.h retrieving revision 1.1.1.5
--- /dev/null 1 Jan 1970 00:00:00 -0000 retrieving revision 1.1.1.6
+++ bgpd/imsg.h 22 Oct 2009 14:24:02 -0000 1.1.1.2 diff -u -p -r1.1.1.5 -r1.1.1.6
@@ -0,0 +1,109 @@ --- bgpd/imsg.h 14 Feb 2010 20:19:57 -0000 1.1.1.5
+/* $OpenBSD: imsg.h,v 1.3 2009/06/07 05:56:24 eric Exp $ */ +++ bgpd/imsg.h 14 Feb 2010 20:27:06 -0000 1.1.1.6
+ @@ -90,6 +90,7 @@ void buf_free(struct buf *);
+/* void msgbuf_init(struct msgbuf *);
+ * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> void msgbuf_clear(struct msgbuf *);
+ * Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org> int msgbuf_write(struct msgbuf *);
+ * 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 OR PROFITS, 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 <sys/tree.h>
+
+#define READ_BUF_SIZE 65535
+#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
+#define MAX_IMSGSIZE 16384
+
+struct buf {
+ TAILQ_ENTRY(buf) entry;
+ u_char *buf;
+ size_t size;
+ size_t max;
+ size_t wpos;
+ size_t rpos;
+ int fd;
+};
+
+struct msgbuf {
+ TAILQ_HEAD(, buf) bufs;
+ u_int32_t queued;
+ int fd;
+};
+
+struct buf_read {
+ u_char buf[READ_BUF_SIZE];
+ u_char *rptr;
+ size_t wpos;
+};
+
+struct imsg_fd {
+ TAILQ_ENTRY(imsg_fd) entry;
+ int fd;
+};
+
+struct imsgbuf {
+ TAILQ_HEAD(, imsg_fd) fds;
+ struct buf_read r;
+ struct msgbuf w;
+ int fd;
+ pid_t pid;
+};
+
+#define IMSGF_HASFD 1
+
+struct imsg_hdr {
+ u_int32_t type;
+ u_int16_t len;
+ u_int16_t flags;
+ u_int32_t peerid;
+ u_int32_t pid;
+};
+
+struct imsg {
+ struct imsg_hdr hdr;
+ int fd;
+ void *data;
+};
+
+
+/* buffer.c */
+struct buf *buf_open(size_t);
+struct buf *buf_dynamic(size_t, size_t);
+int buf_add(struct buf *, const void *, size_t);
+void *buf_reserve(struct buf *, size_t);
+void *buf_seek(struct buf *, size_t, size_t);
+size_t buf_size(struct buf *);
+size_t buf_left(struct buf *);
+void buf_close(struct msgbuf *, struct buf *);
+int buf_write(struct msgbuf *);
+void buf_free(struct buf *);
+void msgbuf_init(struct msgbuf *);
+void msgbuf_clear(struct msgbuf *);
+int msgbuf_write(struct msgbuf *);
+void msgbuf_drain(struct msgbuf *, size_t); +void msgbuf_drain(struct msgbuf *, size_t);
+
+/* imsg.c */ /* imsg.c */
+void imsg_init(struct imsgbuf *, int); void imsg_init(struct imsgbuf *, int);
+ssize_t imsg_read(struct imsgbuf *);
+ssize_t imsg_get(struct imsgbuf *, struct imsg *);
+int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
+ int, void *, u_int16_t);
+int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
+ int, const struct iovec *, int);
+struct buf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
+ u_int16_t);
+int imsg_add(struct buf *, void *, u_int16_t);
+void imsg_close(struct imsgbuf *, struct buf *);
+void imsg_free(struct imsg *);
+int imsg_flush(struct imsgbuf *);
+void imsg_clear(struct imsgbuf *);

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,74 @@
Index: bgpd/log.c
===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/log.c,v
retrieving revision 1.1.1.5
retrieving revision 1.1.1.6
diff -u -p -r1.1.1.5 -r1.1.1.6
--- bgpd/log.c 14 Feb 2010 20:19:57 -0000 1.1.1.5
+++ bgpd/log.c 14 Feb 2010 20:27:06 -0000 1.1.1.6
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.50 2007/04/23 13:04:24 claudio Exp $ */
+/* $OpenBSD: log.c,v 1.53 2009/12/03 19:20:35 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -32,6 +32,7 @@
#include "log.h"
int debug;
+int verbose;
void logit(int, const char *, ...);
@@ -42,8 +43,9 @@ log_fmt_peer(const struct peer_config *p
char *pfmt, *p;
ip = log_addr(&peer->remote_addr);
- if ((peer->remote_addr.af == AF_INET && peer->remote_masklen != 32) ||
- (peer->remote_addr.af == AF_INET6 && peer->remote_masklen != 128)) {
+ if ((peer->remote_addr.aid == AID_INET && peer->remote_masklen != 32) ||
+ (peer->remote_addr.aid == AID_INET6 &&
+ peer->remote_masklen != 128)) {
if (asprintf(&p, "%s/%u", ip, peer->remote_masklen) == -1)
fatal(NULL);
} else {
@@ -69,6 +71,7 @@ log_init(int n_debug)
extern char *__progname;
debug = n_debug;
+ verbose = n_debug;
if (!debug)
openlog(__progname, LOG_PID | LOG_NDELAY, LOG_DAEMON);
@@ -77,6 +80,12 @@ log_init(int n_debug)
}
void
+log_verbose(int v)
+{
+ verbose = v;
+}
+
+void
logit(int pri, const char *fmt, ...)
{
va_list ap;
@@ -193,7 +202,7 @@ log_debug(const char *emsg, ...)
{
va_list ap;
- if (debug) {
+ if (verbose) {
va_start(ap, emsg);
vlog(LOG_DEBUG, emsg, ap);
va_end(ap);
@@ -318,6 +327,9 @@ log_conn_attempt(const struct peer *peer
b = log_sockaddr(sa);
logit(LOG_INFO, "connection from non-peer %s refused", b);
} else {
+ /* only log if there is a chance that the session may come up */
+ if (peer->conf.down && peer->state == STATE_IDLE)
+ return;
p = log_fmt_peer(&peer->conf);
logit(LOG_INFO, "Connection attempt from %s while session is "
"in state %s", p, statenames[peer->state]);

View file

@ -1,21 +0,0 @@
Index: bgpd/log.h
===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/log.h,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.1 -r1.1.1.2
--- bgpd/log.h 30 Jun 2009 05:46:15 -0000 1.1.1.1
+++ bgpd/log.h 9 Jul 2009 16:49:54 -0000 1.1.1.2
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.h,v 1.10 2007/12/23 18:26:13 henning Exp $ */
+/* $OpenBSD: log.h,v 1.11 2008/09/11 14:49:58 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -119,5 +119,6 @@ static const char * const timernames[] =
"HoldTimer",
"IdleHoldTimer",
"IdleHoldResetTimer",
+ "CarpUndemoteTimer",
""
};

File diff suppressed because it is too large Load diff

View file

@ -1,208 +1,23 @@
Index: bgpd/mrt.h Index: bgpd/mrt.h
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/mrt.h,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/mrt.h,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.6
retrieving revision 1.1.1.2 retrieving revision 1.1.1.7
diff -u -p -r1.1.1.1 -r1.1.1.2 diff -u -p -r1.1.1.6 -r1.1.1.7
--- bgpd/mrt.h 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/mrt.h 14 Feb 2010 20:19:57 -0000 1.1.1.6
+++ bgpd/mrt.h 9 Jul 2009 16:49:54 -0000 1.1.1.2 +++ bgpd/mrt.h 14 Feb 2010 20:27:06 -0000 1.1.1.7
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: mrt.h,v 1.16 2007/05/30 04:28:27 msf Exp $ */ -/* $OpenBSD: mrt.h,v 1.23 2009/06/29 12:22:16 claudio Exp $ */
+/* $OpenBSD: mrt.h,v 1.23 2009/06/29 12:22:16 claudio Exp $ */ +/* $OpenBSD: mrt.h,v 1.24 2009/10/26 09:27:58 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -20,12 +20,10 @@ @@ -303,7 +303,7 @@ void mrt_dump_state(struct mrt *, u_in
struct peer *);
#include "bgpd.h"
-/* In cases of failure wait at least MRT_MIN_RETRY. */
-#define MRT_MIN_RETRY 300
-
/*
- * MRT binary packet format as used by zebra.
+ * MRT binary packet format
* For more info see:
+ * draft-ietf-grow-mrt-04.txt, "MRT routing information export format"
* http://www.quagga.net/docs/docs-multi/Packet-Binary-Dump-Format.html
*/
@@ -38,24 +36,33 @@
* +--------+--------+--------+--------+
* | length | length of packet excluding this header
* +--------+--------+--------+--------+
+ *
+ * ET types include an additional 32bit microsecond field comming after the
+ * length field.
*/
#define MRT_HEADER_SIZE 12
enum MRT_MSG_TYPES {
- MSG_NULL,
+ MSG_NULL, /* 0 empty msg (deprecated) */
MSG_START, /* 1 sender is starting up */
- MSG_DIE, /* 2 receiver should shut down */
+ MSG_DIE, /* 2 receiver should shut down (deprecated) */
MSG_I_AM_DEAD, /* 3 sender is shutting down */
- MSG_PEER_DOWN, /* 4 sender's peer is down */
- MSG_PROTOCOL_BGP, /* 5 msg is a BGP packet */
+ MSG_PEER_DOWN, /* 4 sender's peer is down (deprecated) */
+ MSG_PROTOCOL_BGP, /* 5 msg is a BGP packet (deprecated) */
MSG_PROTOCOL_RIP, /* 6 msg is a RIP packet */
- MSG_PROTOCOL_IDRP, /* 7 msg is an IDRP packet */
+ MSG_PROTOCOL_IDRP, /* 7 msg is an IDRP packet (deprecated) */
MSG_PROTOCOL_RIPNG, /* 8 msg is a RIPNG packet */
- MSG_PROTOCOL_BGP4PLUS, /* 9 msg is a BGP4+ packet */
- MSG_PROTOCOL_BGP4PLUS1, /* 10 msg is a BGP4+ (draft 01) packet */
+ MSG_PROTOCOL_BGP4PLUS, /* 9 msg is a BGP4+ packet (deprecated) */
+ MSG_PROTOCOL_BGP4PLUS1, /* 10 msg is a BGP4+ (draft 01) (deprecated) */
MSG_PROTOCOL_OSPF, /* 11 msg is an OSPF packet */
MSG_TABLE_DUMP, /* 12 routing table dump */
- MSG_PROTOCOL_BGP4MP=16 /* 16 zebras own packet format */
+ MSG_TABLE_DUMP_V2, /* 13 routing table dump */
+ MSG_PROTOCOL_BGP4MP=16, /* 16 zebras own packet format */
+ MSG_PROTOCOL_BGP4MP_ET=17,
+ MSG_PROTOCOL_ISIS=32, /* 32 msg is a ISIS package */
+ MSG_PROTOCOL_ISIS_ET=33,
+ MSG_PROTOCOL_OSPFV3=48, /* 48 msg is a OSPFv3 package */
+ MSG_PROTOCOL_OSPFV3_ET=49
};
/*
@@ -64,15 +71,20 @@ enum MRT_MSG_TYPES {
* In most cases this is the format to choose to dump updates et al.
*/
enum MRT_BGP4MP_TYPES {
- BGP4MP_STATE_CHANGE=0, /* state change */
- BGP4MP_MESSAGE=1, /* bgp message */
- BGP4MP_ENTRY=2, /* table dumps */
- BGP4MP_SNAPSHOT=3
+ BGP4MP_STATE_CHANGE, /* state change */
+ BGP4MP_MESSAGE, /* bgp message */
+ BGP4MP_ENTRY, /* table dumps (deprecated) */
+ BGP4MP_SNAPSHOT, /* file name for dump (deprecated) */
+ BGP4MP_STATE_CHANGE_AS4,
+ BGP4MP_MESSAGE_AS4 /* same as BGP4MP_MESSAGE with 4byte AS */
};
/* size of the BGP4MP headers without payload */
#define MRT_BGP4MP_IPv4_HEADER_SIZE 16
#define MRT_BGP4MP_IPv6_HEADER_SIZE 40
+/* 4-byte AS variants of the previous */
+#define MRT_BGP4MP_AS4_IPv4_HEADER_SIZE 20
+#define MRT_BGP4MP_AS4_IPv6_HEADER_SIZE 44
/* If the type is PROTOCOL_BGP4MP and the subtype is either BGP4MP_STATE_CHANGE
* or BGP4MP_MESSAGE the message consists of a common header plus the payload.
@@ -110,6 +122,7 @@ enum MRT_BGP4MP_TYPES {
*/
#define MRT_BGP4MP_IPv4_ENTRY_SIZE 18
#define MRT_BGP4MP_IPv6_ENTRY_SIZE 30
+#define MRT_BGP4MP_MAX_PREFIXLEN 17
/*
* The "new" table dump format consists of messages of type PROTOCOL_BGP4MP
* and subtype BGP4MP_ENTRY.
@@ -151,9 +164,9 @@ enum MRT_BGP4MP_TYPES {
* +--------+--------+--------+--------+
* | prefix |
* +--------+--------+--------+--------+
- * | plen | status | originated
+ * | plen | status | originated time
* +--------+--------+--------+--------+
- * originated | peer_ip
+ * originated time | peer_ip
* +--------+--------+--------+--------+
* peer_ip | peer_as |
* +--------+--------+--------+--------+
@@ -166,8 +179,7 @@ enum MRT_BGP4MP_TYPES {
*
*
* View is normaly 0 and seqnum just a simple counter for this dump.
- * The status seems to be 1 by default but probably something to indicate
- * the status of a prefix would be more useful.
+ * The status field is unused and should be set to 1.
*/
/* size of the dump header until attr_len */
@@ -186,10 +198,14 @@ enum MRT_BGP_TYPES {
and announcements) */
MSG_BGP_PREF_UPDATE, /* tlv preferences followed by raw update */
MSG_BGP_STATE_CHANGE, /* state change */
- MSG_BGP_SYNC
+ MSG_BGP_SYNC, /* file name for a table dump */
+ MSG_BGP_OPEN, /* BGP open messages */
+ MSG_BGP_NOTIFY, /* BGP notify messages */
+ MSG_BGP_KEEPALIVE /* BGP keepalives */
};
-/* if type MSG_PROTOCOL_BGP and subtype MSG_BGP_UPDATE
+/* if type MSG_PROTOCOL_BGP and subtype MSG_BGP_UPDATE, MSG_BGP_OPEN,
+ * MSG_BGP_NOTIFY or MSG_BGP_KEEPALIVE
*
* +--------+--------+--------+--------+
* | source_as | source_ip
@@ -225,7 +241,7 @@ enum MRT_BGP_TYPES {
/*
* if type MSG_PROTOCOL_BGP and subtype MSG_BGP_SYNC OR
* if type MSG_PROTOCOL_BGP4MP and subtype BGP4MP_SNAPSHOT
- * What is this for?
+ * *DEPRECATED*
*
* +--------+--------+--------+--------+
* | view | filename
@@ -255,22 +271,22 @@ enum mrt_state {
};
struct mrt {
- enum mrt_type type;
+ char rib[PEER_DESCR_LEN];
+ struct msgbuf wbuf;
+ LIST_ENTRY(mrt) entry;
u_int32_t peer_id;
u_int32_t group_id;
- u_int32_t queued;
- int fd;
- TAILQ_HEAD(, buf) bufs;
- LIST_ENTRY(mrt) entry;
+ 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))
@@ -278,16 +294,17 @@ struct mrt_config {
struct peer;
struct prefix;
-struct pt_entry;
+struct rib_entry;
/* prototypes */
-int mrt_dump_bgp_msg(struct mrt *, void *, u_int16_t,
- struct peer *, struct bgpd_config *);
-int mrt_dump_state(struct mrt *, u_int16_t, u_int16_t,
- struct peer *, struct bgpd_config *);
+void mrt_dump_bgp_msg(struct mrt *, void *, u_int16_t,
+ struct peer *);
+void mrt_dump_state(struct mrt *, u_int16_t, u_int16_t,
+ struct peer *);
void mrt_clear_seq(void); void mrt_clear_seq(void);
-void mrt_dump_upcall(struct pt_entry *, void *); void mrt_dump_upcall(struct rib_entry *, void *);
-int mrt_write(struct mrt *); -void mrt_dump_done(void *);
+void mrt_dump_upcall(struct rib_entry *, void *); +void mrt_done(void *);
+void mrt_dump_done(void *); void mrt_write(struct mrt *);
+void mrt_write(struct mrt *);
void mrt_clean(struct mrt *); void mrt_clean(struct mrt *);
void mrt_init(struct imsgbuf *, struct imsgbuf *); void mrt_init(struct imsgbuf *, struct imsgbuf *);
int mrt_timeout(struct mrt_head *);

View file

@ -1,14 +0,0 @@
Index: bgpd/name2id.c
===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/name2id.c,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.1 -r1.1.1.2
--- bgpd/name2id.c 30 Jun 2009 05:46:15 -0000 1.1.1.1
+++ bgpd/name2id.c 9 Jul 2009 16:49:54 -0000 1.1.1.2
@@ -1,4 +1,4 @@
-/* $OpenBSD: name2id.c,v 1.7 2006/05/02 14:41:26 claudio Exp $ */
+/* $OpenBSD: name2id.c,v 1.9 2009/06/04 04:46:42 claudio Exp $ */
/*
* Copyright (c) 2004, 2005 Henning Brauer <henning@openbsd.org>

File diff suppressed because it is too large Load diff

View file

@ -1,81 +1,120 @@
Index: bgpd/pfkey.c Index: bgpd/pfkey.c
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/pfkey.c,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/pfkey.c,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.6
retrieving revision 1.1.1.2 retrieving revision 1.1.1.7
diff -u -p -r1.1.1.1 -r1.1.1.2 diff -u -p -r1.1.1.6 -r1.1.1.7
--- bgpd/pfkey.c 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/pfkey.c 14 Feb 2010 20:19:57 -0000 1.1.1.6
+++ bgpd/pfkey.c 9 Jul 2009 16:49:54 -0000 1.1.1.2 +++ bgpd/pfkey.c 14 Feb 2010 20:27:06 -0000 1.1.1.7
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: pfkey.c,v 1.34 2006/10/26 14:26:49 henning Exp $ */ -/* $OpenBSD: pfkey.c,v 1.37 2009/04/21 15:25:52 henning Exp $ */
+/* $OpenBSD: pfkey.c,v 1.37 2009/04/21 15:25:52 henning Exp $ */ +/* $OpenBSD: pfkey.c,v 1.40 2009/12/14 17:38:18 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -36,7 +36,8 @@ @@ -74,6 +74,7 @@ pfkey_send(int sd, uint8_t satype, uint8
#define ROUNDUP(x) (((x) + (PFKEY2_CHUNK - 1)) & ~(PFKEY2_CHUNK - 1)) int len = 0;
#define IOV_CNT 20
-static u_int32_t sadb_msg_seq = 1;
+static u_int32_t sadb_msg_seq = 0;
+static u_int32_t pid = 0; /* should pid_t but pfkey needs u_int32_t */
static int fd;
int pfkey_reply(int, u_int32_t *);
@@ -74,6 +75,9 @@ pfkey_send(int sd, uint8_t satype, uint8
int iov_cnt; int iov_cnt;
struct sockaddr_storage ssrc, sdst, speer, smask, dmask; struct sockaddr_storage ssrc, sdst, speer, smask, dmask;
+ struct sockaddr *saptr;
+ if (!pid) if (!pid)
+ pid = getpid(); pid = getpid();
+ @@ -81,22 +82,17 @@ pfkey_send(int sd, uint8_t satype, uint8
/* we need clean sockaddr... no ports set */ /* we need clean sockaddr... no ports set */
bzero(&ssrc, sizeof(ssrc)); bzero(&ssrc, sizeof(ssrc));
bzero(&smask, sizeof(smask)); bzero(&smask, sizeof(smask));
@@ -129,8 +133,8 @@ pfkey_send(int sd, uint8_t satype, uint8 - switch (src->af) {
- case AF_INET:
- ((struct sockaddr_in *)&ssrc)->sin_addr = src->v4;
- ssrc.ss_len = sizeof(struct sockaddr_in);
- ssrc.ss_family = AF_INET;
+ if ((saptr = addr2sa(src, 0)))
+ memcpy(&ssrc, saptr, sizeof(ssrc));
+ switch (src->aid) {
+ case AID_INET:
memset(&((struct sockaddr_in *)&smask)->sin_addr, 0xff, 32/8);
break;
- case AF_INET6:
- memcpy(&((struct sockaddr_in6 *)&ssrc)->sin6_addr,
- &src->v6, sizeof(struct in6_addr));
- ssrc.ss_len = sizeof(struct sockaddr_in6);
- ssrc.ss_family = AF_INET6;
+ case AID_INET6:
memset(&((struct sockaddr_in6 *)&smask)->sin6_addr, 0xff,
128/8);
break;
- case 0:
+ case AID_UNSPEC:
ssrc.ss_len = sizeof(struct sockaddr);
break;
default:
@@ -107,22 +103,17 @@ pfkey_send(int sd, uint8_t satype, uint8
bzero(&smsg, sizeof(smsg)); bzero(&sdst, sizeof(sdst));
smsg.sadb_msg_version = PF_KEY_V2; bzero(&dmask, sizeof(dmask));
- smsg.sadb_msg_seq = sadb_msg_seq++; - switch (dst->af) {
- smsg.sadb_msg_pid = getpid(); - case AF_INET:
+ smsg.sadb_msg_seq = ++sadb_msg_seq; - ((struct sockaddr_in *)&sdst)->sin_addr = dst->v4;
+ smsg.sadb_msg_pid = pid; - sdst.ss_len = sizeof(struct sockaddr_in);
smsg.sadb_msg_len = sizeof(smsg) / 8; - sdst.ss_family = AF_INET;
smsg.sadb_msg_type = mtype; + if ((saptr = addr2sa(dst, 0)))
smsg.sadb_msg_satype = satype; + memcpy(&sdst, saptr, sizeof(sdst));
@@ -415,10 +419,23 @@ pfkey_reply(int sd, u_int32_t *spip) + switch (dst->aid) {
u_int8_t *data; + case AID_INET:
ssize_t len; memset(&((struct sockaddr_in *)&dmask)->sin_addr, 0xff, 32/8);
break;
- case AF_INET6:
- memcpy(&((struct sockaddr_in6 *)&sdst)->sin6_addr,
- &dst->v6, sizeof(struct in6_addr));
- sdst.ss_len = sizeof(struct sockaddr_in6);
- sdst.ss_family = AF_INET6;
+ case AID_INET6:
memset(&((struct sockaddr_in6 *)&dmask)->sin6_addr, 0xff,
128/8);
break;
- case 0:
+ case AID_UNSPEC:
sdst.ss_len = sizeof(struct sockaddr);
break;
default:
@@ -220,8 +211,8 @@ pfkey_send(int sd, uint8_t satype, uint8
sa_dst.sadb_address_exttype = SADB_X_EXT_DST_FLOW;
- if (recv(sd, &hdr, sizeof(hdr), MSG_PEEK) != sizeof(hdr)) { bzero(&smask, sizeof(smask));
- log_warn("pfkey peek"); - switch (src->af) {
- return (-1); - case AF_INET:
+ for (;;) { + switch (src->aid) {
+ if (recv(sd, &hdr, sizeof(hdr), MSG_PEEK) != sizeof(hdr)) { + case AID_INET:
+ log_warn("pfkey peek"); smask.ss_len = sizeof(struct sockaddr_in);
+ return (-1); smask.ss_family = AF_INET;
+ } memset(&((struct sockaddr_in *)&smask)->sin_addr,
+ @@ -233,7 +224,7 @@ pfkey_send(int sd, uint8_t satype, uint8
+ if (hdr.sadb_msg_seq == sadb_msg_seq && htons(0xffff);
+ hdr.sadb_msg_pid == pid)
+ break;
+
+ /* not ours, discard */
+ if (read(sd, &hdr, sizeof(hdr)) == -1) {
+ log_warn("pfkey read");
+ return (-1);
+ }
} }
+ break;
if (hdr.sadb_msg_errno != 0) { - case AF_INET6:
errno = hdr.sadb_msg_errno; + case AID_INET6:
if (errno == ESRCH) smask.ss_len = sizeof(struct sockaddr_in6);
@@ -497,6 +514,8 @@ pfkey_sa_remove(struct bgpd_addr *src, s smask.ss_family = AF_INET6;
int memset(&((struct sockaddr_in6 *)&smask)->sin6_addr,
pfkey_md5sig_establish(struct peer *p) @@ -247,8 +238,8 @@ pfkey_send(int sd, uint8_t satype, uint8
{ break;
+ sleep(1); }
+ bzero(&dmask, sizeof(dmask));
if (!p->auth.spi_out) - switch (dst->af) {
if (pfkey_sa_add(&p->auth.local_addr, &p->conf.remote_addr, - case AF_INET:
p->conf.auth.md5key_len, p->conf.auth.md5key, + switch (dst->aid) {
+ case AID_INET:
dmask.ss_len = sizeof(struct sockaddr_in);
dmask.ss_family = AF_INET;
memset(&((struct sockaddr_in *)&dmask)->sin_addr,
@@ -260,7 +251,7 @@ pfkey_send(int sd, uint8_t satype, uint8
htons(0xffff);
}
break;
- case AF_INET6:
+ case AID_INET6:
dmask.ss_len = sizeof(struct sockaddr_in6);
dmask.ss_family = AF_INET6;
memset(&((struct sockaddr_in6 *)&dmask)->sin6_addr,

View file

@ -1,30 +0,0 @@
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ bgpd/pfkey_compat.c 8 Feb 2007 10:31:16 -0000
@@ -0,0 +1,27 @@
+#include "bgpd.h"
+#include "session.h"
+
+int
+pfkey_establish(struct peer *p)
+{
+ if (p->conf.auth.method)
+ return (-1);
+ return (0);
+}
+
+int
+pfkey_remove(struct peer *p)
+{
+ if (p->conf.auth.method)
+ return (-1);
+ return (0);
+}
+
+int
+pfkey_init(struct bgpd_sysdep *sysdep)
+{
+ log_warnx("no kernel support for PF_KEY");
+ sysdep->no_pfkey = 1;
+ return (0);
+}
+

View file

@ -0,0 +1,23 @@
Index: bgpd/pftable.c
===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/pftable.c,v
retrieving revision 1.1.1.5
retrieving revision 1.1.1.6
diff -u -p -r1.1.1.5 -r1.1.1.6
--- bgpd/pftable.c 14 Feb 2010 20:19:57 -0000 1.1.1.5
+++ bgpd/pftable.c 14 Feb 2010 20:27:06 -0000 1.1.1.6
@@ -1,4 +1,4 @@
-/* $OpenBSD: pftable.c,v 1.5 2005/07/01 09:19:24 claudio Exp $ */
+/* $OpenBSD: pftable.c,v 1.6 2009/12/01 14:28:05 claudio Exp $ */
/*
* Copyright (c) 2004 Damien Miller <djm@openbsd.org>
@@ -214,7 +214,7 @@ pftable_add_work(const char *table, stru
bzero(pfa, sizeof(*pfa));
memcpy(&pfa->pfra_u, &addr->ba, (len + 7U) / 8);
- pfa->pfra_af = addr->af;
+ pfa->pfra_af = aid2af(addr->aid);
pfa->pfra_net = len;
pft->naddrs++;

View file

@ -1,18 +1,18 @@
Index: bgpd/printconf.c Index: bgpd/printconf.c
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/printconf.c,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/printconf.c,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.7
retrieving revision 1.5 retrieving revision 1.6
diff -u -p -r1.1.1.1 -r1.5 diff -u -p -r1.1.1.7 -r1.6
--- bgpd/printconf.c 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/printconf.c 14 Feb 2010 20:19:57 -0000 1.1.1.7
+++ bgpd/printconf.c 22 Oct 2009 15:10:02 -0000 1.5 +++ bgpd/printconf.c 4 Feb 2010 16:22:23 -0000 1.6
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: printconf.c,v 1.65 2007/11/22 11:37:25 henning Exp $ */ -/* $OpenBSD: printconf.c,v 1.70 2009/06/06 01:10:29 claudio Exp $ */
+/* $OpenBSD: printconf.c,v 1.70 2009/06/06 01:10:29 claudio Exp $ */ +/* $OpenBSD: printconf.c,v 1.77 2009/12/17 09:32:59 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -19,10 +19,14 @@ @@ -19,6 +19,9 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -22,40 +22,117 @@ diff -u -p -r1.1.1.1 -r1.5
#include "bgpd.h" #include "bgpd.h"
#include "mrt.h" #include "mrt.h"
#include "session.h" @@ -27,6 +30,8 @@
+#include "rde.h"
void print_op(enum comp_ops); void print_op(enum comp_ops);
void print_community(int, int); void print_community(int, int);
@@ -185,6 +189,8 @@ print_mainconf(struct bgpd_config *conf) +void print_extcommunity(struct filter_extcommunity *);
printf("holdtime %u\n", conf->holdtime); +void print_origin(u_int8_t);
if (conf->min_holdtime) void print_set(struct filter_set_head *);
printf("holdtime min %u\n", conf->min_holdtime); void print_mainconf(struct bgpd_config *);
+ if (conf->connectretry) void print_network(struct network_config *);
+ printf("connect-retry %u\n", conf->connectretry); @@ -34,7 +39,7 @@ void print_peer(struct peer_config *,
const char *);
const char *print_auth_alg(u_int8_t);
const char *print_enc_alg(u_int8_t);
-const char *print_safi(u_int8_t);
+void print_announce(struct peer_config *, const char *);
void print_rule(struct peer *, struct filter_rule *);
const char * mrt_type(enum mrt_type);
void print_mrt(u_int32_t, u_int32_t, const char *, const char *);
@@ -94,6 +99,45 @@ print_community(int as, int type)
}
if (conf->flags & BGPD_FLAG_NO_FIB_UPDATE) void
printf("fib-update no\n"); +print_extcommunity(struct filter_extcommunity *c)
@@ -200,9 +206,6 @@ print_mainconf(struct bgpd_config *conf) +{
if (conf->flags & BGPD_FLAG_DECISION_MED_ALWAYS) + switch (c->type & EXT_COMMUNITY_VALUE) {
printf("rde med compare always\n"); + case EXT_COMMUNITY_TWO_AS:
+ printf("%s %i:%i", log_ext_subtype(c->subtype),
+ c->data.ext_as.as, c->data.ext_as.val);
+ break;
+ case EXT_COMMUNITY_IPV4:
+ printf("%s %s:%i", log_ext_subtype(c->subtype),
+ inet_ntoa(c->data.ext_ip.addr), c->data.ext_ip.val);
+ break;
+ case EXT_COMMUNITY_FOUR_AS:
+ printf("%s %s:%i", log_ext_subtype(c->subtype),
+ log_as(c->data.ext_as4.as4), c->data.ext_as.val);
+ break;
+ case EXT_COMMUNITY_OPAQUE:
+ printf("%s 0x%llx", log_ext_subtype(c->subtype),
+ c->data.ext_opaq);
+ break;
+ default:
+ printf("0x%x 0x%llx", c->type, c->data.ext_opaq);
+ break;
+ }
+}
+
+void
+print_origin(u_int8_t o)
+{
+ if (o == ORIGIN_IGP)
+ printf("igp ");
+ else if (o == ORIGIN_EGP)
+ printf("egp ");
+ else if (o == ORIGIN_INCOMPLETE)
+ printf("incomplete ");
+ else
+ printf("%u ", o);
+}
+
+void
print_set(struct filter_set_head *set)
{
struct filter_set *s;
@@ -161,11 +205,25 @@ print_set(struct filter_set_head *set)
case ACTION_RTLABEL:
printf("rtlabel %s ", s->action.rtlabel);
break;
+ case ACTION_SET_ORIGIN:
+ printf("origin ");
+ print_origin(s->action.origin);
+ break;
case ACTION_RTLABEL_ID:
case ACTION_PFTABLE_ID:
/* not possible */
printf("king bula saiz: config broken");
break;
+ case ACTION_SET_EXT_COMMUNITY:
+ printf("ext-community ");
+ print_extcommunity(&s->action.ext_community);
+ printf(" ");
+ break;
+ case ACTION_DEL_EXT_COMMUNITY:
+ printf("ext-community delete ");
+ print_extcommunity(&s->action.ext_community);
+ printf(" ");
+ break;
}
}
printf("}");
@@ -263,8 +321,8 @@ print_peer(struct peer_config *p, struct
char *method;
struct in_addr ina;
- if (conf->flags & BGPD_FLAG_DECISION_TRANS_AS) - if ((p->remote_addr.af == AF_INET && p->remote_masklen != 32) ||
- printf("transparent-as yes\n"); - (p->remote_addr.af == AF_INET6 && p->remote_masklen != 128))
- + if ((p->remote_addr.aid == AID_INET && p->remote_masklen != 32) ||
if (conf->log & BGPD_LOG_UPDATES) + (p->remote_addr.aid == AID_INET6 && p->remote_masklen != 128))
printf("log updates\n"); printf("%sneighbor %s/%u {\n", c, log_addr(&p->remote_addr),
p->remote_masklen);
@@ -271,6 +274,8 @@ print_peer(struct peer_config *p, struct else
printf("%sneighbor %s {\n", c, log_addr(&p->remote_addr)); @@ -281,7 +339,7 @@ print_peer(struct peer_config *p, struct
if (p->descr[0]) printf("%s\tmultihop %u\n", c, p->distance);
printf("%s\tdescr \"%s\"\n", c, p->descr); if (p->passive)
+ if (p->rib[0]) printf("%s\tpassive\n", c);
+ printf("%s\trib \"%s\"\n", c, p->rib); - if (p->local_addr.af)
if (p->remote_as) + if (p->local_addr.aid)
printf("%s\tremote-as %s\n", c, log_as(p->remote_as)); printf("%s\tlocal-address %s\n", c, log_addr(&p->local_addr));
if (p->down) if (p->max_prefix) {
@@ -293,6 +298,12 @@ print_peer(struct peer_config *p, struct printf("%s\tmax-prefix %u", c, p->max_prefix);
@@ -295,6 +353,12 @@ print_peer(struct peer_config *p, struct
printf("%s\tholdtime min %u\n", c, p->min_holdtime); printf("%s\tholdtime min %u\n", c, p->min_holdtime);
if (p->announce_capa == 0) if (p->announce_capa == 0)
printf("%s\tannounce capabilities no\n", c); printf("%s\tannounce capabilities no\n", c);
@ -68,12 +145,10 @@ diff -u -p -r1.1.1.1 -r1.5
if (p->announce_type == ANNOUNCE_SELF) if (p->announce_type == ANNOUNCE_SELF)
printf("%s\tannounce self\n", c); printf("%s\tannounce self\n", c);
else if (p->announce_type == ANNOUNCE_NONE) else if (p->announce_type == ANNOUNCE_NONE)
@@ -320,6 +331,12 @@ print_peer(struct peer_config *p, struct @@ -324,6 +388,10 @@ print_peer(struct peer_config *p, struct
printf("%s\tdemote %s\n", c, p->demote_group);
if (p->if_depend[0])
printf("%s\tdepend on \"%s\"\n", c, p->if_depend); printf("%s\tdepend on \"%s\"\n", c, p->if_depend);
+ if (p->flags & PEERFLAG_TRANS_AS) if (p->flags & PEERFLAG_TRANS_AS)
+ printf("%s\ttransparent-as yes\n", c); printf("%s\ttransparent-as yes\n", c);
+#if defined(IPV6_LINKLOCAL_PEER) +#if defined(IPV6_LINKLOCAL_PEER)
+ if (p->lliface[0]) + if (p->lliface[0])
+ printf("%s\tinterface %s\n", c, p->lliface); + printf("%s\tinterface %s\n", c, p->lliface);
@ -81,64 +156,57 @@ diff -u -p -r1.1.1.1 -r1.5
if (p->auth.method == AUTH_MD5SIG) if (p->auth.method == AUTH_MD5SIG)
printf("%s\ttcp md5sig\n", c); printf("%s\ttcp md5sig\n", c);
@@ -419,10 +436,12 @@ print_rule(struct peer *peer_l, struct f @@ -354,8 +422,7 @@ print_peer(struct peer_config *p, struct
printf("deny "); if (p->ttlsec)
else printf("%s\tttl-security yes\n", c);
printf("match ");
-
if (r->quick)
printf("quick ");
+ if (r->rib[0]) - printf("%s\tannounce IPv4 %s\n", c, print_safi(p->capabilities.mp_v4));
+ printf("rib %s ", r->rib); - printf("%s\tannounce IPv6 %s\n", c, print_safi(p->capabilities.mp_v6));
+ + print_announce(p, c);
if (r->dir == DIR_IN)
printf("from "); if (p->softreconfig_in == 1)
else if (r->dir == DIR_OUT) printf("%s\tsoftreconfig in yes\n", c);
@@ -532,12 +551,14 @@ print_mrt(u_int32_t pid, u_int32_t gid, @@ -399,17 +466,14 @@ print_enc_alg(u_int8_t alg)
LIST_FOREACH(m, xmrt_l, entry)
if ((gid != 0 && m->group_id == gid) ||
(m->peer_id == pid && m->group_id == gid)) {
+ printf("%s%sdump ", prep, prep2);
+ if (m->rib[0])
+ printf("rib %s ", m->rib);
if (MRT2MC(m)->ReopenTimerInterval == 0)
- printf("%s%sdump %s %s\n", prep, prep2,
- mrt_type(m->type), MRT2MC(m)->name);
+ printf("%s %s\n", mrt_type(m->type),
+ MRT2MC(m)->name);
else
- printf("%s%sdump %s %s %d\n", prep, prep2,
- mrt_type(m->type),
+ printf("%s %s %d\n", mrt_type(m->type),
MRT2MC(m)->name,
MRT2MC(m)->ReopenTimerInterval);
} }
@@ -602,16 +623,25 @@ peer_compare(const void *aa, const void }
-const char *
-print_safi(u_int8_t safi)
+void
+print_announce(struct peer_config *p, const char *c)
{
- switch (safi) {
- case SAFI_NONE:
- return ("none");
- case SAFI_UNICAST:
- return ("unicast");
- default:
- return ("?");
- }
+ u_int8_t aid;
+
+ for (aid = 0; aid < AID_MAX; aid++)
+ if (p->capabilities.mp[aid])
+ printf("%s\tannounce %s\n", c, aid2str(aid));
} }
void void
-print_config(struct bgpd_config *conf, struct network_head *net_l, @@ -455,14 +519,14 @@ print_rule(struct peer *peer_l, struct f
- struct peer *peer_l, struct filter_head *rules_l, struct mrt_head *mrt_l) } else
+print_config(struct bgpd_config *conf, struct rib_names *rib_l, printf("any ");
+ struct network_head *net_l, struct peer *peer_l,
+ struct filter_head *rules_l, struct mrt_head *mrt_l) - if (r->match.prefix.addr.af)
{ + if (r->match.prefix.addr.aid)
struct filter_rule *r; printf("prefix %s/%u ", log_addr(&r->match.prefix.addr),
struct network *n; r->match.prefix.len);
+ struct rde_rib *rr;
- if (r->match.prefix.addr.af == 0 && r->match.prefixlen.af) {
- if (r->match.prefixlen.af == AF_INET)
+ if (r->match.prefix.addr.aid == 0 && r->match.prefixlen.aid) {
+ if (r->match.prefixlen.aid == AID_INET)
printf("inet ");
- if (r->match.prefixlen.af == AF_INET6)
+ if (r->match.prefixlen.aid == AID_INET6)
printf("inet6 ");
}
xmrt_l = mrt_l;
printf("\n");
print_mainconf(conf);
printf("\n");
+ SIMPLEQ_FOREACH(rr, rib_l, entry) {
+ if (rr->flags & F_RIB_NOEVALUATE)
+ printf("rde rib %s no evaluate\n", rr->name);
+ else
+ printf("rde rib %s\n", rr->name);
+ }
+ printf("\n");
TAILQ_FOREACH(n, net_l, entry)
print_network(&n->net);
printf("\n");

File diff suppressed because it is too large Load diff

View file

@ -1,311 +1,161 @@
Index: bgpd/rde.h Index: bgpd/rde.h
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/rde.h,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/rde.h,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.8
retrieving revision 1.1.1.4 retrieving revision 1.1.1.9
diff -u -p -r1.1.1.1 -r1.1.1.4 diff -u -p -r1.1.1.8 -r1.1.1.9
--- bgpd/rde.h 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/rde.h 14 Feb 2010 20:19:57 -0000 1.1.1.8
+++ bgpd/rde.h 22 Oct 2009 14:24:02 -0000 1.1.1.4 +++ bgpd/rde.h 14 Feb 2010 20:27:06 -0000 1.1.1.9
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: rde.h,v 1.102 2008/01/23 08:11:32 claudio Exp $ */ -/* $OpenBSD: rde.h,v 1.120 2009/06/06 01:10:29 claudio Exp $ */
+/* $OpenBSD: rde.h,v 1.121 2009/08/06 08:53:11 claudio Exp $ */ +/* $OpenBSD: rde.h,v 1.129 2010/01/13 06:02:37 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and
@@ -42,6 +42,7 @@ LIST_HEAD(rde_peer_head, rde_peer); @@ -56,12 +56,9 @@ struct rde_peer {
LIST_HEAD(aspath_head, rde_aspath); struct bgpd_addr local_v6_addr;
RB_HEAD(uptree_prefix, update_prefix); struct uptree_prefix up_prefix;
RB_HEAD(uptree_attr, update_attr); struct uptree_attr up_attrs;
+RB_HEAD(rib_tree, rib_entry); - struct uplist_attr updates;
TAILQ_HEAD(uplist_prefix, update_prefix); - struct uplist_prefix withdraws;
TAILQ_HEAD(uplist_attr, update_attr); - struct uplist_attr updates6;
- struct uplist_prefix withdraws6;
@@ -66,13 +67,13 @@ struct rde_peer { - struct capabilities capa_announced;
- struct capabilities capa_received;
+ struct uplist_attr updates[AID_MAX];
+ struct uplist_prefix withdraws[AID_MAX];
+ struct capabilities capa;
u_int64_t prefix_rcvd_update;
u_int64_t prefix_rcvd_withdraw;
u_int64_t prefix_sent_update; u_int64_t prefix_sent_update;
u_int64_t prefix_sent_withdraw; @@ -163,6 +160,7 @@ LIST_HEAD(prefix_head, prefix);
u_int32_t prefix_cnt; /* # of prefixes */
- u_int32_t adjrib_cnt; /* # of p. in Adj-RIB-In */
u_int32_t remote_bgpid; /* host byte order! */
u_int32_t up_pcnt;
u_int32_t up_acnt;
u_int32_t up_nlricnt;
u_int32_t up_wcnt;
enum peer_state state;
+ u_int16_t ribid;
u_int16_t short_as;
u_int8_t reconf_in; /* in filter changed */
u_int8_t reconf_out; /* out filter changed */
@@ -107,8 +108,8 @@ enum attrtypes {
ATTR_MP_REACH_NLRI=14,
ATTR_MP_UNREACH_NLRI=15,
ATTR_EXT_COMMUNITIES=16,
- ATTR_NEW_ASPATH=17,
- ATTR_NEW_AGGREGATOR=18
+ ATTR_AS4_PATH=17,
+ ATTR_AS4_AGGREGATOR=18
};
/* attribute flags. 4 low order bits reserved */
@@ -154,16 +155,16 @@ LIST_HEAD(prefix_head, prefix);
#define F_ATTR_MED_ANNOUNCE 0x00020
#define F_ATTR_MP_REACH 0x00040
#define F_ATTR_MP_UNREACH 0x00080
-#define F_ATTR_AS4BYTE_NEW 0x00100 /* NEW_ASPATH or NEW_AGGREGATOR */
+#define F_ATTR_AS4BYTE_NEW 0x00100 /* AS4_PATH or AS4_AGGREGATOR */
#define F_ATTR_LOOP 0x00200 /* path would cause a route loop */
-#define F_PREFIX_ANNOUNCED 0x01000
+#define F_PREFIX_ANNOUNCED 0x00400
+#define F_ANN_DYNAMIC 0x00800
+#define F_NEXTHOP_SELF 0x01000
#define F_NEXTHOP_REJECT 0x02000 #define F_NEXTHOP_REJECT 0x02000
#define F_NEXTHOP_BLACKHOLE 0x04000 #define F_NEXTHOP_BLACKHOLE 0x04000
#define F_NEXTHOP_NOMODIFY 0x08000 #define F_NEXTHOP_NOMODIFY 0x08000
-#define F_NEXTHOP_SELF 0x10000
+#define F_ATTR_PARSE_ERR 0x10000 +#define F_ATTR_PARSE_ERR 0x10000
#define F_ATTR_LINKED 0x20000 #define F_ATTR_LINKED 0x20000
-#define F_LOCAL 0x40000 /* Local-RIB */
-#define F_ORIGINAL 0x80000 /* Adj-RIB-In */
#define ORIGIN_IGP 0 @@ -220,14 +218,14 @@ struct nexthop {
@@ -184,7 +185,6 @@ struct rde_aspath { /* generic entry without address specific part */
u_int32_t weight; /* low prio lpref */ struct pt_entry {
u_int32_t prefix_cnt; /* # of prefixes */
u_int32_t active_cnt; /* # of active prefixes */
- u_int32_t adjrib_cnt; /* # of p. in Adj-RIB-In */
u_int32_t flags; /* internally used */
u_int16_t rtlabelid; /* route label id */
u_int16_t pftableid; /* pf table id */
@@ -223,53 +223,72 @@ struct pt_entry {
RB_ENTRY(pt_entry) pt_e; RB_ENTRY(pt_entry) pt_e;
sa_family_t af; - sa_family_t af;
+ u_int8_t aid;
u_int8_t prefixlen; u_int8_t prefixlen;
- struct prefix_head prefix_h; u_int16_t refcnt;
- struct prefix *active; /* for fast access */
+ u_int16_t refcnt;
}; };
struct pt_entry4 { struct pt_entry4 {
RB_ENTRY(pt_entry) pt_e; RB_ENTRY(pt_entry) pt_e;
sa_family_t af; - sa_family_t af;
+ u_int8_t aid;
u_int8_t prefixlen; u_int8_t prefixlen;
- struct prefix_head prefix_h; u_int16_t refcnt;
- struct prefix *active; /* for fast access */
+ u_int16_t refcnt;
struct in_addr prefix4; struct in_addr prefix4;
- /* @@ -235,12 +233,25 @@ struct pt_entry4 {
- * Route Flap Damping structures
- * Currently I think they belong into the prefix but for the moment
- * we just ignore the dampening at all.
- */
};
struct pt_entry6 { struct pt_entry6 {
RB_ENTRY(pt_entry) pt_e; RB_ENTRY(pt_entry) pt_e;
sa_family_t af; - sa_family_t af;
+ u_int8_t aid;
u_int8_t prefixlen; u_int8_t prefixlen;
- struct prefix_head prefix_h; u_int16_t refcnt;
- struct prefix *active; /* for fast access */
+ u_int16_t refcnt;
struct in6_addr prefix6; struct in6_addr prefix6;
}; };
-struct pt_context { +struct pt_entry_vpn4 {
- union { + RB_ENTRY(pt_entry) pt_e;
- struct pt_entry p; + u_int8_t aid;
- struct pt_entry4 p4; + u_int8_t prefixlen;
- struct pt_entry6 p6; + u_int16_t refcnt;
- } pu; + struct in_addr prefix4;
-#define ctx_p pu.p + u_int64_t rd;
-#define ctx_p4 pu.p4 + u_int8_t labelstack[21];
-#define ctx_p6 pu.p6 + u_int8_t labellen;
- /* only count and done should be accessed by callers */ + u_int8_t pad1;
- unsigned int count; + u_int8_t pad2;
- int done;
-};
+struct rib_context {
+ LIST_ENTRY(rib_context) entry;
+ struct rib_entry *ctx_re;
+ struct rib *ctx_rib;
+ void (*ctx_upcall)(struct rib_entry *, void *);
+ void (*ctx_done)(void *);
+ void (*ctx_wait)(void *);
+ void *ctx_arg;
+ unsigned int ctx_count;
+ sa_family_t ctx_af;
+}; +};
+ +
+struct rib_entry { struct rib_context {
+ RB_ENTRY(rib_entry) rib_e; LIST_ENTRY(rib_context) entry;
+ struct prefix_head prefix_h; struct rib_entry *ctx_re;
+ struct prefix *active; /* for fast access */ @@ -250,7 +261,7 @@ struct rib_context {
+ struct pt_entry *prefix; void (*ctx_wait)(void *);
+ u_int16_t ribid; void *ctx_arg;
+ u_int16_t flags; unsigned int ctx_count;
+}; - sa_family_t ctx_af;
+ + u_int8_t ctx_aid;
+enum rib_state {
+ RIB_NONE,
+ RIB_NEW,
+ RIB_ACTIVE,
+ RIB_DELETE
+};
+
+struct rib {
+ char name[PEER_DESCR_LEN];
+ struct rib_tree rib;
+ enum rib_state state;
+ u_int16_t flags;
+ u_int16_t id;
+};
+
+#define F_RIB_ENTRYLOCK 0x0001
+#define F_RIB_NOEVALUATE 0x0002
+#define F_RIB_NOFIB 0x0004
+#define RIB_FAILED 0xffff
struct prefix {
- LIST_ENTRY(prefix) prefix_l, path_l;
+ LIST_ENTRY(prefix) rib_l, path_l;
struct rde_aspath *aspath;
struct pt_entry *prefix;
+ struct rib_entry *rib; /* NULL for Adj-RIB-In */
time_t lastchange;
- u_int32_t flags;
}; };
extern struct rde_memstats rdemem; struct rib_entry {
@@ -282,7 +301,8 @@ void rde_send_pftable(u_int16_t, struc @@ -264,6 +275,7 @@ struct rib_entry {
u_int8_t, int);
void rde_send_pftable_commit(void);
-void rde_generate_updates(struct prefix *, struct prefix *); enum rib_state {
+void rde_generate_updates(u_int16_t, struct prefix *, RIB_NONE,
+ struct prefix *); + RIB_NEW,
u_int32_t rde_local_as(void); RIB_ACTIVE,
int rde_noevaluate(void); RIB_DELETE
int rde_decisionflags(void); };
@@ -291,6 +311,8 @@ int rde_as4byte(struct rde_peer *); @@ -342,9 +354,13 @@ int aspath_loopfree(struct aspath *, u
/* rde_attr.c */ int aspath_compare(struct aspath *, struct aspath *);
int attr_write(void *, u_int16_t, u_int8_t, u_int8_t, void *, u_char *aspath_prepend(struct aspath *, u_int32_t, int, u_int16_t *);
u_int16_t); int aspath_match(struct aspath *, enum as_spec, u_int32_t);
+int attr_writebuf(struct buf *, u_int8_t, u_int8_t, void *, -int community_match(void *, u_int16_t, int, int);
+ u_int16_t); +int community_match(struct rde_aspath *, int, int);
void attr_init(u_int32_t); int community_set(struct rde_aspath *, int, int);
void attr_shutdown(void);
int attr_optadd(struct rde_aspath *, u_int8_t, u_int8_t,
@@ -327,10 +349,24 @@ int community_set(struct rde_aspath *,
void community_delete(struct rde_aspath *, int, int); void community_delete(struct rde_aspath *, int, int);
+int community_ext_set(struct rde_aspath *,
+ struct filter_extcommunity *, u_int16_t);
+void community_ext_delete(struct rde_aspath *,
+ struct filter_extcommunity *, u_int16_t);
/* rde_rib.c */ /* rde_rib.c */
+extern u_int16_t rib_size; extern u_int16_t rib_size;
+extern struct rib *ribs; @@ -356,7 +372,7 @@ void rib_free(struct rib *);
+ struct rib_entry *rib_get(struct rib *, struct bgpd_addr *, int);
+u_int16_t rib_new(int, char *, u_int16_t); struct rib_entry *rib_lookup(struct rib *, struct bgpd_addr *);
+u_int16_t rib_find(char *); void rib_dump(struct rib *, void (*)(struct rib_entry *, void *),
+void rib_free(struct rib *); - void *, sa_family_t);
+struct rib_entry *rib_get(struct rib *, struct bgpd_addr *, int); + void *, u_int8_t);
+struct rib_entry *rib_lookup(struct rib *, struct bgpd_addr *); void rib_dump_r(struct rib_context *);
+void rib_dump(struct rib *, void (*)(struct rib_entry *, void *), void rib_dump_runner(void);
+ void *, sa_family_t); int rib_dump_pending(void);
+void rib_dump_r(struct rib_context *); @@ -395,7 +411,7 @@ void prefix_network_clean(struct rde_p
+void rib_dump_runner(void);
+int rib_dump_pending(void);
+
void path_init(u_int32_t);
void path_shutdown(void);
-void path_update(struct rde_peer *, struct rde_aspath *,
- struct bgpd_addr *, int, u_int32_t);
+int path_update(struct rib *, struct rde_peer *,
+ struct rde_aspath *, struct bgpd_addr *, int);
int path_compare(struct rde_aspath *, struct rde_aspath *);
struct rde_aspath *path_lookup(struct rde_aspath *, struct rde_peer *);
void path_remove(struct rde_aspath *);
@@ -343,18 +379,20 @@ void path_put(struct rde_aspath *);
#define PREFIX_SIZE(x) (((x) + 7) / 8 + 1)
int prefix_compare(const struct bgpd_addr *,
const struct bgpd_addr *, int);
-struct prefix *prefix_get(struct rde_peer *, struct bgpd_addr *, int,
- u_int32_t);
-struct pt_entry *prefix_add(struct rde_aspath *, struct bgpd_addr *, int,
- u_int32_t);
-struct pt_entry *prefix_move(struct rde_aspath *, struct prefix *, u_int32_t);
-void prefix_remove(struct rde_peer *, struct bgpd_addr *, int,
- u_int32_t);
+struct prefix *prefix_get(struct rib *, struct rde_peer *,
+ struct bgpd_addr *, int, u_int32_t);
+int prefix_add(struct rib *, struct rde_aspath *,
+ struct bgpd_addr *, int);
+void prefix_move(struct rde_aspath *, struct prefix *);
+int prefix_remove(struct rib *, struct rde_peer *,
+ struct bgpd_addr *, int, u_int32_t);
int prefix_write(u_char *, int, struct bgpd_addr *, u_int8_t);
-struct prefix *prefix_bypeer(struct pt_entry *, struct rde_peer *, u_int32_t);
-void prefix_updateall(struct rde_aspath *, enum nexthop_state);
+struct prefix *prefix_bypeer(struct rib_entry *, struct rde_peer *,
+ u_int32_t);
+void prefix_updateall(struct rde_aspath *, enum nexthop_state,
+ enum nexthop_state);
void prefix_destroy(struct prefix *);
-void prefix_network_clean(struct rde_peer *, time_t);
+void prefix_network_clean(struct rde_peer *, time_t, u_int32_t);
void nexthop_init(u_int32_t); void nexthop_init(u_int32_t);
void nexthop_shutdown(void); void nexthop_shutdown(void);
@@ -368,7 +406,7 @@ struct nexthop *nexthop_get(struct bgpd_ void nexthop_modify(struct rde_aspath *, struct bgpd_addr *,
int nexthop_compare(struct nexthop *, struct nexthop *); - enum action_types, sa_family_t);
+ enum action_types, u_int8_t);
/* rde_decide.c */ void nexthop_link(struct rde_aspath *);
-void prefix_evaluate(struct prefix *, struct pt_entry *); void nexthop_unlink(struct rde_aspath *);
+void prefix_evaluate(struct prefix *, struct rib_entry *); int nexthop_delete(struct nexthop *);
@@ -415,12 +431,15 @@ int up_generate(struct rde_peer *, str
/* rde_update.c */ void up_generate_updates(struct filter_head *, struct rde_peer *,
void up_init(struct rde_peer *); struct prefix *, struct prefix *);
@@ -387,24 +425,34 @@ u_char *up_dump_mp_unreach(u_char *, u_ void up_generate_default(struct filter_head *, struct rde_peer *,
u_char *up_dump_mp_reach(u_char *, u_int16_t *, struct rde_peer *); - sa_family_t);
+ u_int8_t);
+int up_generate_marker(struct rde_peer *, u_int8_t);
int up_dump_prefix(u_char *, int, struct uplist_prefix *,
struct rde_peer *);
int up_dump_attrnlri(u_char *, int, struct rde_peer *);
-u_char *up_dump_mp_unreach(u_char *, u_int16_t *, struct rde_peer *);
-u_char *up_dump_mp_reach(u_char *, u_int16_t *, struct rde_peer *);
+u_char *up_dump_mp_unreach(u_char *, u_int16_t *, struct rde_peer *,
+ u_int8_t);
+int up_dump_mp_reach(u_char *, u_int16_t *, struct rde_peer *,
+ u_int8_t);
/* rde_prefix.c */ /* rde_prefix.c */
-void pt_init(void); #define pt_empty(pt) ((pt)->refcnt == 0)
-void pt_shutdown(void); @@ -452,8 +471,7 @@ enum filter_actions rde_filter(u_int16_t
-int pt_empty(struct pt_entry *); struct rde_aspath *, struct bgpd_addr *, u_int8_t,
-void pt_getaddr(struct pt_entry *, struct bgpd_addr *); struct rde_peer *, enum directions);
+#define pt_empty(pt) ((pt)->refcnt == 0)
+#define pt_ref(pt) do { \
+ ++(pt)->refcnt; \
+ if ((pt)->refcnt == 0) \
+ fatalx("pt_ref: overflow"); \
+} while(0)
+#define pt_unref(pt) do { \
+ if ((pt)->refcnt == 0) \
+ fatalx("pt_unref: underflow"); \
+ --(pt)->refcnt; \
+} while(0)
+
+void pt_init(void);
+void pt_shutdown(void);
+void pt_getaddr(struct pt_entry *, struct bgpd_addr *);
+struct pt_entry *pt_fill(struct bgpd_addr *, int);
struct pt_entry *pt_get(struct bgpd_addr *, int);
struct pt_entry *pt_add(struct bgpd_addr *, int);
-void pt_remove(struct pt_entry *);
+void pt_remove(struct pt_entry *);
struct pt_entry *pt_lookup(struct bgpd_addr *);
-void pt_dump(void (*)(struct pt_entry *, void *), void *,
- sa_family_t);
-void pt_dump_r(void (*)(struct pt_entry *, void *), void *,
- sa_family_t, struct pt_context *);
+int pt_prefix_cmp(const struct pt_entry *, const struct pt_entry *);
+
/* rde_filter.c */
-enum filter_actions rde_filter(struct rde_aspath **, struct filter_head *,
- struct rde_peer *, struct rde_aspath *,
- struct bgpd_addr *, u_int8_t, struct rde_peer *,
- enum directions);
+enum filter_actions rde_filter(u_int16_t, struct rde_aspath **,
+ struct filter_head *, struct rde_peer *,
+ struct rde_aspath *, struct bgpd_addr *, u_int8_t,
+ struct rde_peer *, enum directions);
void rde_apply_set(struct rde_aspath *, struct filter_set_head *, void rde_apply_set(struct rde_aspath *, struct filter_set_head *,
sa_family_t, struct rde_peer *, struct rde_peer *); - sa_family_t, struct rde_peer *, struct rde_peer *);
int rde_filter_community(struct rde_aspath *, int, int); -int rde_filter_community(struct rde_aspath *, int, int);
+ u_int8_t, struct rde_peer *, struct rde_peer *);
int rde_filter_equal(struct filter_head *, struct filter_head *,
struct rde_peer *, enum directions);

View file

@ -1,14 +1,14 @@
Index: bgpd/rde_attr.c Index: bgpd/rde_attr.c
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/rde_attr.c,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/rde_attr.c,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.6
retrieving revision 1.3 retrieving revision 1.4
diff -u -p -r1.1.1.1 -r1.3 diff -u -p -r1.1.1.6 -r1.4
--- bgpd/rde_attr.c 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/rde_attr.c 14 Feb 2010 20:19:57 -0000 1.1.1.6
+++ bgpd/rde_attr.c 9 Jul 2009 17:22:14 -0000 1.3 +++ bgpd/rde_attr.c 4 Feb 2010 16:22:23 -0000 1.4
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: rde_attr.c,v 1.76.2.1 2009/02/18 20:30:36 claudio Exp $ */ -/* $OpenBSD: rde_attr.c,v 1.79 2009/03/19 06:52:59 claudio Exp $ */
+/* $OpenBSD: rde_attr.c,v 1.79 2009/03/19 06:52:59 claudio Exp $ */ +/* $OpenBSD: rde_attr.c,v 1.81 2009/12/18 15:51:37 claudio Exp $ */
/* /*
* Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
@ -34,44 +34,222 @@ diff -u -p -r1.1.1.1 -r1.3
#include "bgpd.h" #include "bgpd.h"
#include "rde.h" #include "rde.h"
@@ -62,6 +69,31 @@ attr_write(void *p, u_int16_t p_len, u_i @@ -971,13 +978,26 @@ aspath_match(struct aspath *a, enum as_s
return (tot_len); return (0);
}
+/*
+ * Functions handling communities and extended communities.
+ */
+
+int community_ext_conv(struct filter_extcommunity *, u_int16_t, u_int64_t *);
+
int
-community_match(void *data, u_int16_t len, int as, int type)
+community_match(struct rde_aspath *asp, int as, int type)
{
- u_int8_t *p = data;
- u_int16_t eas, etype;
+ struct attr *a;
+ u_int8_t *p;
+ u_int16_t eas, etype, len;
- len >>= 2; /* divide by four */
+ a = attr_optget(asp, ATTR_COMMUNITIES);
+ if (a == NULL)
+ /* no communities, no match */
+ return (0);
+
+ len = a->len / 4;
+ p = a->data;
for (; len > 0; len--) {
eas = *p++;
@@ -1000,7 +1020,6 @@ community_set(struct rde_aspath *asp, in
u_int8_t *p = NULL;
unsigned int i, ncommunities = 0;
u_int8_t f = ATTR_OPTIONAL|ATTR_TRANSITIVE;
- u_int8_t t = ATTR_COMMUNITIES;
attr = attr_optget(asp, ATTR_COMMUNITIES);
if (attr != NULL) {
@@ -1017,7 +1036,7 @@ community_set(struct rde_aspath *asp, in
p += 4;
}
- if (ncommunities++ >= 0x3fff)
+ if (ncommunities++ >= USHRT_MAX / 4)
/* overflow */
return (0);
@@ -1032,11 +1051,10 @@ community_set(struct rde_aspath *asp, in
if (attr != NULL) {
memcpy(p + 4, attr->data, attr->len);
f = attr->flags;
- t = attr->type;
attr_free(asp, attr);
}
- attr_optadd(asp, f, t, p, ncommunities << 2);
+ attr_optadd(asp, f, ATTR_COMMUNITIES, p, ncommunities << 2);
free(p);
return (1);
@@ -1049,7 +1067,7 @@ community_delete(struct rde_aspath *asp,
u_int8_t *p, *n;
u_int16_t l, len = 0;
u_int16_t eas, etype;
- u_int8_t f, t;
+ u_int8_t f;
attr = attr_optget(asp, ATTR_COMMUNITIES);
if (attr == NULL)
@@ -1100,10 +1118,146 @@ community_delete(struct rde_aspath *asp,
}
f = attr->flags;
- t = attr->type;
attr_free(asp, attr);
- attr_optadd(asp, f, t, n, len);
+ attr_optadd(asp, f, ATTR_COMMUNITIES, n, len);
+ free(n);
+}
+
+int
+community_ext_set(struct rde_aspath *asp, struct filter_extcommunity *c,
+ u_int16_t neighas)
+{
+ struct attr *attr;
+ u_int8_t *p = NULL;
+ u_int64_t community;
+ unsigned int i, ncommunities = 0;
+ u_int8_t f = ATTR_OPTIONAL|ATTR_TRANSITIVE;
+
+ if (community_ext_conv(c, neighas, &community))
+ return (0);
+
+ attr = attr_optget(asp, ATTR_EXT_COMMUNITIES);
+ if (attr != NULL) {
+ p = attr->data;
+ ncommunities = attr->len / 8; /* 64bit per ext-community */
+ }
+
+ /* first check if the community is not already set */
+ for (i = 0; i < ncommunities; i++) {
+ if (memcmp(&community, p, sizeof(community)) == 0)
+ /* already present, nothing todo */
+ return (1);
+ p += sizeof(community);
+ }
+
+ if (ncommunities++ >= USHRT_MAX / sizeof(community))
+ /* overflow */
+ return (0);
+
+ if ((p = malloc(ncommunities * sizeof(community))) == NULL)
+ fatal("community_ext_set");
+
+ memcpy(p, &community, sizeof(community));
+ if (attr != NULL) {
+ memcpy(p + sizeof(community), attr->data, attr->len);
+ f = attr->flags;
+ attr_free(asp, attr);
+ }
+
+ attr_optadd(asp, f, ATTR_EXT_COMMUNITIES, p,
+ ncommunities * sizeof(community));
+
+ free(p);
+ return (1);
+}
+
+void
+community_ext_delete(struct rde_aspath *asp, struct filter_extcommunity *c,
+ u_int16_t neighas)
+{
+ struct attr *attr;
+ u_int8_t *p, *n;
+ u_int64_t community;
+ u_int16_t l, len = 0;
+ u_int8_t f;
+
+ if (community_ext_conv(c, neighas, &community))
+ return;
+
+ attr = attr_optget(asp, ATTR_EXT_COMMUNITIES);
+ if (attr == NULL)
+ /* no attr nothing to do */
+ return;
+
+ p = attr->data;
+ for (l = 0; l < attr->len; l += sizeof(community)) {
+ if (memcmp(&community, p + l, sizeof(community)) == 0)
+ /* match */
+ continue;
+ len += sizeof(community);
+ }
+
+ if (len == 0) {
+ attr_free(asp, attr);
+ return;
+ }
+
+ if ((n = malloc(len)) == NULL)
+ fatal("community_delete");
+
+ p = attr->data;
+ for (l = 0; l < len && p < attr->data + attr->len;
+ p += sizeof(community)) {
+ if (memcmp(&community, p, sizeof(community)) == 0)
+ /* match */
+ continue;
+ memcpy(n + l, p, sizeof(community));
+ l += sizeof(community);
+ }
+
+ f = attr->flags;
+
+ attr_free(asp, attr);
+ attr_optadd(asp, f, ATTR_EXT_COMMUNITIES, n, len);
free(n);
} }
+int +int
+attr_writebuf(struct buf *buf, u_int8_t flags, u_int8_t type, void *data, +community_ext_conv(struct filter_extcommunity *c, u_int16_t neighas,
+ u_int16_t data_len) + u_int64_t *community)
+{ +{
+ u_char hdr[4]; + u_int64_t com;
+ u_int32_t ip;
+ +
+ if (data_len > 255) { + com = (u_int64_t)c->type << 56;
+ flags |= ATTR_EXTLEN; + switch (c->type & EXT_COMMUNITY_VALUE) {
+ hdr[2] = (data_len >> 8) & 0xff; + case EXT_COMMUNITY_TWO_AS:
+ hdr[3] = data_len & 0xff; + com |= (u_int64_t)c->subtype << 48;
+ } else { + com |= (u_int64_t)c->data.ext_as.as << 32;
+ flags &= ~ATTR_EXTLEN; + com |= c->data.ext_as.val;
+ hdr[2] = data_len & 0xff; + break;
+ case EXT_COMMUNITY_IPV4:
+ com |= (u_int64_t)c->subtype << 48;
+ ip = ntohl(c->data.ext_ip.addr.s_addr);
+ com |= (u_int64_t)ip << 16;
+ com |= c->data.ext_ip.val;
+ break;
+ case EXT_COMMUNITY_FOUR_AS:
+ com |= (u_int64_t)c->subtype << 48;
+ com |= (u_int64_t)c->data.ext_as4.as4 << 16;
+ com |= c->data.ext_as4.val;
+ break;
+ case EXT_COMMUNITY_OPAQUE:
+ com |= (u_int64_t)c->subtype << 48;
+ com |= c->data.ext_opaq & EXT_COMMUNITY_OPAQUE_MAX;
+ break;
+ default:
+ com |= c->data.ext_opaq & 0xffffffffffffffULL;
+ break;
+ } + }
+ +
+ hdr[0] = flags; + *community = htobe64(com);
+ hdr[1] = type;
+ +
+ if (buf_add(buf, hdr, flags & ATTR_EXTLEN ? 4 : 3) == -1)
+ return (-1);
+ if (buf_add(buf, data, data_len) == -1)
+ return (-1);
+ return (0); + return (0);
+} +}
+
/* optional attribute specific functions */
int attr_diff(struct attr *, struct attr *);
struct attr *attr_alloc(u_int8_t, u_int8_t, const void *, u_int16_t);
@@ -588,7 +620,7 @@ aspath_merge(struct rde_aspath *a, struc
ascnt = aspath_count(attr->data, attr->len);
if (ascnt > a->aspath->ascnt) {
- /* ASPATH is shorter then NEW_ASPATH no way to merge */
+ /* ASPATH is shorter then AS4_PATH no way to merge */
attr_free(a, attr);
return;
}

View file

@ -1,27 +1,18 @@
Index: bgpd/rde_decide.c Index: bgpd/rde_decide.c
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/rde_decide.c,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/rde_decide.c,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.6
retrieving revision 1.2 retrieving revision 1.2
diff -u -p -r1.1.1.1 -r1.2 diff -u -p -r1.1.1.6 -r1.2
--- bgpd/rde_decide.c 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/rde_decide.c 14 Feb 2010 20:19:57 -0000 1.1.1.6
+++ bgpd/rde_decide.c 22 Oct 2009 15:12:21 -0000 1.2 +++ bgpd/rde_decide.c 22 Oct 2009 15:12:21 -0000 1.2
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: rde_decide.c,v 1.51 2008/05/08 09:51:46 henning Exp $ */ -/* $OpenBSD: rde_decide.c,v 1.58 2009/06/29 14:10:13 claudio Exp $ */
+/* $OpenBSD: rde_decide.c,v 1.59 2009/08/06 08:53:11 claudio Exp $ */ +/* $OpenBSD: rde_decide.c,v 1.59 2009/08/06 08:53:11 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -115,15 +115,15 @@ prefix_cmp(struct prefix *p1, struct pre @@ -118,6 +118,12 @@ prefix_cmp(struct prefix *p1, struct pre
if (p2 == NULL)
return (1);
- /* only prefixes in the Local-RIB are eligible */
- if (!(p1->flags & F_LOCAL))
- return (-1);
- if (!(p2->flags & F_LOCAL))
- return (1);
-
asp1 = p1->aspath; asp1 = p1->aspath;
asp2 = p2->aspath; asp2 = p2->aspath;
@ -34,104 +25,21 @@ diff -u -p -r1.1.1.1 -r1.2
/* only loop free pathes are eligible */ /* only loop free pathes are eligible */
if (asp1->flags & F_ATTR_LOOP) if (asp1->flags & F_ATTR_LOOP)
return (-1); return (-1);
@@ -201,9 +201,16 @@ prefix_cmp(struct prefix *p1, struct pre @@ -204,7 +210,7 @@ prefix_cmp(struct prefix *p1, struct pre
&p2->aspath->peer->remote_addr, }
sizeof(p1->aspath->peer->remote_addr)));
+ /* 12. for announced prefixes prefer dynamic routes */
+ if ((asp1->flags & F_ANN_DYNAMIC) != (asp2->flags & F_ANN_DYNAMIC)) {
+ if (asp1->flags & F_ANN_DYNAMIC)
+ return (1);
+ else
+ return (-1);
+ }
+
fatalx("Uh, oh a politician in the decision process"); fatalx("Uh, oh a politician in the decision process");
- /* NOTREACHED */ - /* NOTREACHED */
- return (0);
+ return(0); /* NOTREACHED */ + return(0); /* NOTREACHED */
} }
/* /*
@@ -212,59 +219,59 @@ prefix_cmp(struct prefix *p1, struct pre @@ -245,7 +251,7 @@ prefix_evaluate(struct prefix *p, struct
* The to evaluate prefix must not be in the prefix list.
*/
void
-prefix_evaluate(struct prefix *p, struct pt_entry *pte)
+prefix_evaluate(struct prefix *p, struct rib_entry *re)
{
struct prefix *xp;
- if (rde_noevaluate()) {
+ if (re->flags & F_RIB_NOEVALUATE || rde_noevaluate()) {
/* decision process is turned off */
if (p != NULL)
- LIST_INSERT_HEAD(&pte->prefix_h, p, prefix_l);
- if (pte->active != NULL) {
- pte->active->aspath->active_cnt--;
- pte->active = NULL;
+ LIST_INSERT_HEAD(&re->prefix_h, p, rib_l);
+ if (re->active != NULL) {
+ re->active->aspath->active_cnt--;
+ re->active = NULL;
}
return;
} }
if (p != NULL) { xp = LIST_FIRST(&re->prefix_h);
- if (LIST_EMPTY(&pte->prefix_h)) - if (xp == NULL || xp->aspath->flags & F_ATTR_LOOP ||
- LIST_INSERT_HEAD(&pte->prefix_h, p, prefix_l);
+ if (LIST_EMPTY(&re->prefix_h))
+ LIST_INSERT_HEAD(&re->prefix_h, p, rib_l);
else {
- LIST_FOREACH(xp, &pte->prefix_h, prefix_l)
+ LIST_FOREACH(xp, &re->prefix_h, rib_l)
if (prefix_cmp(p, xp) > 0) {
- LIST_INSERT_BEFORE(xp, p, prefix_l);
+ LIST_INSERT_BEFORE(xp, p, rib_l);
break;
- } else if (LIST_NEXT(xp, prefix_l) == NULL) {
+ } else if (LIST_NEXT(xp, rib_l) == NULL) {
/* if xp last element ... */
- LIST_INSERT_AFTER(xp, p, prefix_l);
+ LIST_INSERT_AFTER(xp, p, rib_l);
break;
}
}
}
- xp = LIST_FIRST(&pte->prefix_h);
- if (xp == NULL || !(xp->flags & F_LOCAL) ||
- xp->aspath->flags & F_ATTR_LOOP ||
+ xp = LIST_FIRST(&re->prefix_h);
+ if (xp == NULL || xp->aspath->flags & (F_ATTR_LOOP|F_ATTR_PARSE_ERR) || + if (xp == NULL || xp->aspath->flags & (F_ATTR_LOOP|F_ATTR_PARSE_ERR) ||
(xp->aspath->nexthop != NULL && (xp->aspath->nexthop != NULL &&
xp->aspath->nexthop->state != NEXTHOP_REACH)) xp->aspath->nexthop->state != NEXTHOP_REACH))
/* xp is ineligible */ /* xp is ineligible */
xp = NULL;
- if (pte->active != xp) {
+ if (re->active != xp) {
/* need to generate an update */
- if (pte->active != NULL)
- pte->active->aspath->active_cnt--;
+ if (re->active != NULL)
+ re->active->aspath->active_cnt--;
/*
- * Send update with remove for pte->active and add for xp
+ * Send update with remove for re->active and add for xp
* but remember that xp may be NULL aka ineligible.
* Additional decision may be made by the called functions.
*/
- rde_generate_updates(xp, pte->active);
- rde_send_kroute(xp, pte->active);
+ rde_generate_updates(re->ribid, xp, re->active);
+ if ((re->flags & F_RIB_NOFIB) == 0)
+ rde_send_kroute(xp, re->active);
- pte->active = xp;
+ re->active = xp;
if (xp != NULL)
xp->aspath->active_cnt++;
}

View file

@ -1,27 +1,18 @@
Index: bgpd/rde_filter.c Index: bgpd/rde_filter.c
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/rde_filter.c,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/rde_filter.c,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.7
retrieving revision 1.4 retrieving revision 1.5
diff -u -p -r1.1.1.1 -r1.4 diff -u -p -r1.1.1.7 -r1.5
--- bgpd/rde_filter.c 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/rde_filter.c 14 Feb 2010 20:19:57 -0000 1.1.1.7
+++ bgpd/rde_filter.c 10 Aug 2009 21:20:05 -0000 1.4 +++ bgpd/rde_filter.c 4 Feb 2010 16:22:23 -0000 1.5
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: rde_filter.c,v 1.54 2008/06/15 10:19:21 claudio Exp $ */ -/* $OpenBSD: rde_filter.c,v 1.56 2009/06/06 01:10:29 claudio Exp $ */
+/* $OpenBSD: rde_filter.c,v 1.57 2009/08/06 08:53:11 claudio Exp $ */ +/* $OpenBSD: rde_filter.c,v 1.61 2009/12/18 15:51:37 claudio Exp $ */
/* /*
* Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
@@ -30,7 +30,7 @@ int rde_filter_match(struct filter_rule @@ -40,6 +40,13 @@ rde_filter(u_int16_t ribid, struct rde_a
int filterset_equal(struct filter_set_head *, struct filter_set_head *);
enum filter_actions
-rde_filter(struct rde_aspath **new, struct filter_head *rules,
+rde_filter(u_int16_t ribid, struct rde_aspath **new, struct filter_head *rules,
struct rde_peer *peer, struct rde_aspath *asp, struct bgpd_addr *prefix,
u_int8_t prefixlen, struct rde_peer *from, enum directions dir)
{
@@ -40,9 +40,18 @@ rde_filter(struct rde_aspath **new, stru
if (new != NULL) if (new != NULL)
*new = NULL; *new = NULL;
@ -35,26 +26,148 @@ diff -u -p -r1.1.1.1 -r1.4
TAILQ_FOREACH(f, rules, entry) { TAILQ_FOREACH(f, rules, entry) {
if (dir != f->dir) if (dir != f->dir)
continue; continue;
+ if (dir == DIR_IN && f->peer.ribid != ribid) @@ -59,7 +66,7 @@ rde_filter(u_int16_t ribid, struct rde_a
+ continue; /* ... and use the copy from now on */
if (f->peer.groupid != 0 && asp = *new;
f->peer.groupid != peer->conf.groupid) }
continue; - rde_apply_set(asp, &f->set, prefix->af,
@@ -283,8 +292,11 @@ rde_filter_match(struct filter_rule *f, + rde_apply_set(asp, &f->set, prefix->aid,
from, peer);
}
if (f->action != ACTION_NONE)
@@ -73,7 +80,7 @@ rde_filter(u_int16_t ribid, struct rde_a
void
rde_apply_set(struct rde_aspath *asp, struct filter_set_head *sh,
- sa_family_t af, struct rde_peer *from, struct rde_peer *peer)
+ u_int8_t aid, struct rde_peer *from, struct rde_peer *peer)
{
struct filter_set *set;
u_char *np;
@@ -167,7 +174,7 @@ rde_apply_set(struct rde_aspath *asp, st
case ACTION_SET_NEXTHOP_NOMODIFY:
case ACTION_SET_NEXTHOP_SELF:
nexthop_modify(asp, &set->action.nexthop, set->type,
- af);
+ aid);
break;
case ACTION_SET_COMMUNITY:
switch (set->action.community.as) {
@@ -243,6 +250,17 @@ rde_apply_set(struct rde_aspath *asp, st
asp->rtlabelid = set->action.id;
rtlabel_ref(asp->rtlabelid);
break;
+ case ACTION_SET_ORIGIN:
+ asp->origin = set->action.origin;
+ break;
+ case ACTION_SET_EXT_COMMUNITY:
+ community_ext_set(asp, &set->action.ext_community,
+ peer->conf.remote_as);
+ break;
+ case ACTION_DEL_EXT_COMMUNITY:
+ community_ext_delete(asp, &set->action.ext_community,
+ peer->conf.remote_as);
+ break;
}
}
}
@@ -281,12 +299,12 @@ rde_filter_match(struct filter_rule *f,
break;
}
- if (rde_filter_community(asp, as, type) == 0)
+ if (community_match(asp, as, type) == 0)
return (0); return (0);
} }
- if (f->match.prefix.addr.af != 0 && - if (f->match.prefix.addr.af != 0) {
- f->match.prefix.addr.af == prefix->af) { - if (f->match.prefix.addr.af != prefix->af)
+ if (f->match.prefix.addr.af != 0) { + if (f->match.prefix.addr.aid != 0) {
+ if (f->match.prefix.addr.af != prefix->af) + if (f->match.prefix.addr.aid != prefix->aid)
+ /* don't use IPv4 rules for IPv6 and vice versa */ /* don't use IPv4 rules for IPv6 and vice versa */
+ return (0);
+
if (prefix_compare(prefix, &f->match.prefix.addr,
f->match.prefix.len))
return (0); return (0);
@@ -614,4 +626,5 @@ filterset_name(enum action_types type)
@@ -322,7 +340,7 @@ rde_filter_match(struct filter_rule *f,
} else if (f->match.prefixlen.op != OP_NONE) {
/* only prefixlen without a prefix */
- if (f->match.prefixlen.af != prefix->af)
+ if (f->match.prefixlen.aid != prefix->aid)
/* don't use IPv4 rules for IPv6 and vice versa */
return (0);
@@ -356,19 +374,6 @@ rde_filter_match(struct filter_rule *f,
}
int
-rde_filter_community(struct rde_aspath *asp, int as, int type)
-{
- struct attr *a;
-
- a = attr_optget(asp, ATTR_COMMUNITIES);
- if (a == NULL)
- /* no communities, no match */
- return (0);
-
- return (community_match(a->data, a->len, as, type));
-}
-
-int
rde_filter_equal(struct filter_head *a, struct filter_head *b,
struct rde_peer *peer, enum directions dir)
{
@@ -476,6 +481,12 @@ filterset_cmp(struct filter_set *a, stru
return (a->action.community.type - b->action.community.type);
}
+ if (a->type == ACTION_SET_EXT_COMMUNITY ||
+ a->type == ACTION_DEL_EXT_COMMUNITY) { /* a->type == b->type */
+ return (memcmp(&a->action.ext_community,
+ &b->action.ext_community, sizeof(a->action.ext_community)));
+ }
+
if (a->type == ACTION_SET_NEXTHOP && b->type == ACTION_SET_NEXTHOP) {
/*
* This is the only interesting case, all others are considered
@@ -483,7 +494,7 @@ filterset_cmp(struct filter_set *a, stru
* reject it at the same time. Allow one IPv4 and one IPv6
* per filter set or only one of the other nexthop modifiers.
*/
- return (a->action.nexthop.af - b->action.nexthop.af);
+ return (a->action.nexthop.aid - b->action.nexthop.aid);
}
/* equal */
@@ -574,6 +585,19 @@ filterset_equal(struct filter_set_head *
if (strcmp(as, bs) == 0)
continue;
break;
+ case ACTION_SET_ORIGIN:
+ if (a->type == b->type &&
+ a->action.origin == b->action.origin)
+ continue;
+ break;
+ case ACTION_SET_EXT_COMMUNITY:
+ case ACTION_DEL_EXT_COMMUNITY:
+ if (a->type == b->type && memcmp(
+ &a->action.ext_community,
+ &b->action.ext_community,
+ sizeof(a->action.ext_community)) == 0)
+ continue;
+ break;
}
/* compare failed */
return (0);
@@ -616,7 +640,14 @@ filterset_name(enum action_types type)
case ACTION_RTLABEL:
case ACTION_RTLABEL_ID:
return ("rtlabel");
+ case ACTION_SET_ORIGIN:
+ return ("origin");
+ case ACTION_SET_EXT_COMMUNITY:
+ return ("ext-community");
+ case ACTION_DEL_EXT_COMMUNITY:
+ return ("ext-community delete");
} }
fatalx("filterset_name: got lost"); fatalx("filterset_name: got lost");

View file

@ -1,332 +1,294 @@
Index: bgpd/rde_prefix.c Index: bgpd/rde_prefix.c
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/rde_prefix.c,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/rde_prefix.c,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.6
retrieving revision 1.3 retrieving revision 1.4
diff -u -p -r1.1.1.1 -r1.3 diff -u -p -r1.1.1.6 -r1.4
--- bgpd/rde_prefix.c 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/rde_prefix.c 14 Feb 2010 20:19:57 -0000 1.1.1.6
+++ bgpd/rde_prefix.c 9 Jul 2009 17:22:14 -0000 1.3 +++ bgpd/rde_prefix.c 4 Feb 2010 16:22:23 -0000 1.4
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: rde_prefix.c,v 1.25 2007/05/11 11:27:59 claudio Exp $ */ -/* $OpenBSD: rde_prefix.c,v 1.29 2009/05/30 18:27:17 claudio Exp $ */
+/* $OpenBSD: rde_prefix.c,v 1.29 2009/05/30 18:27:17 claudio Exp $ */ +/* $OpenBSD: rde_prefix.c,v 1.31 2010/01/13 06:02:37 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -40,46 +40,30 @@ @@ -38,15 +38,16 @@
* pt_lookup: lookup a IP in the prefix table. Mainly for "show ip bgp".
* pt_empty: returns true if there is no bgp prefix linked to the pt_entry.
* pt_init: initialize prefix table. * pt_init: initialize prefix table.
* pt_alloc?: allocate a AF specific pt_entry. Internal function. - * pt_alloc?: allocate a AF specific pt_entry. Internal function.
+ * pt_alloc: allocate a AF specific pt_entry. Internal function.
* pt_free: free a pt_entry. Internal function. * pt_free: free a pt_entry. Internal function.
- * pt_restart used to restart a tree walk at the spot it was aborted earlier.
*/ */
/* internal prototypes */ /* internal prototypes */
static struct pt_entry4 *pt_alloc4(void); -static struct pt_entry4 *pt_alloc4(void);
static struct pt_entry6 *pt_alloc6(void); -static struct pt_entry6 *pt_alloc6(void);
+static struct pt_entry *pt_alloc(struct pt_entry *);
static void pt_free(struct pt_entry *); static void pt_free(struct pt_entry *);
-static struct pt_entry *pt_restart(struct pt_context *);
-int pt_prefix_cmp(const struct pt_entry *, const struct pt_entry *); +size_t pt_sizes[AID_MAX] = AID_PTSIZE;
- +
-#define MIN_PREFIX 0
-#define MAX_PREFIX 32
RB_HEAD(pt_tree, pt_entry); RB_HEAD(pt_tree, pt_entry);
RB_PROTOTYPE(pt_tree, pt_entry, pt_e, pt_prefix_cmp); RB_PROTOTYPE(pt_tree, pt_entry, pt_e, pt_prefix_cmp);
RB_GENERATE(pt_tree, pt_entry, pt_e, pt_prefix_cmp); RB_GENERATE(pt_tree, pt_entry, pt_e, pt_prefix_cmp);
@@ -70,17 +71,24 @@ void
-struct pt_tree pttable4; pt_getaddr(struct pt_entry *pte, struct bgpd_addr *addr)
-struct pt_tree pttable6;
+struct pt_tree pttable;
void
pt_init(void)
{ {
- RB_INIT(&pttable4); bzero(addr, sizeof(struct bgpd_addr));
- RB_INIT(&pttable6); - switch (pte->af) {
+ RB_INIT(&pttable); - case AF_INET:
- addr->af = pte->af;
+ addr->aid = pte->aid;
+ switch (addr->aid) {
+ case AID_INET:
addr->v4 = ((struct pt_entry4 *)pte)->prefix4;
break;
- case AF_INET6:
- addr->af = pte->af;
+ case AID_INET6:
memcpy(&addr->v6, &((struct pt_entry6 *)pte)->prefix6,
sizeof(addr->v6));
/* XXX scope_id ??? */
break;
+ case AID_VPN_IPv4:
+ addr->vpn4.addr = ((struct pt_entry_vpn4 *)pte)->prefix4;
+ addr->vpn4.rd = ((struct pt_entry_vpn4 *)pte)->rd;
+ addr->vpn4.labellen = ((struct pt_entry_vpn4 *)pte)->labellen;
+ memcpy(addr->vpn4.labelstack,
+ ((struct pt_entry_vpn4 *)pte)->labelstack,
+ addr->vpn4.labellen);
+ break;
default:
fatalx("pt_getaddr: unknown af");
} }
@@ -89,33 +97,49 @@ pt_getaddr(struct pt_entry *pte, struct
void
pt_shutdown(void)
{
- if (!RB_EMPTY(&pttable4))
- log_debug("pt_shutdown: IPv4 tree is not empty.");
- if (!RB_EMPTY(&pttable6))
- log_debug("pt_shutdown: IPv6 tree is not empty.");
-}
-
-int
-pt_empty(struct pt_entry *pte)
-{
- return LIST_EMPTY(&pte->prefix_h);
+ if (!RB_EMPTY(&pttable))
+ log_debug("pt_shutdown: tree is not empty.");
}
void
@@ -103,14 +87,15 @@ pt_getaddr(struct pt_entry *pte, struct
}
struct pt_entry * struct pt_entry *
-pt_get(struct bgpd_addr *prefix, int prefixlen) pt_fill(struct bgpd_addr *prefix, int prefixlen)
+pt_fill(struct bgpd_addr *prefix, int prefixlen)
{ {
- struct pt_entry4 pte4; - static struct pt_entry4 pte4;
- struct pt_entry6 pte6; - static struct pt_entry6 pte6;
- in_addr_t addr_hbo;
+ static struct pt_entry4 pte4; + static struct pt_entry4 pte4;
+ static struct pt_entry6 pte6; + static struct pt_entry6 pte6;
in_addr_t addr_hbo; + static struct pt_entry_vpn4 pte_vpn4;
+ in_addr_t addr_hbo;
switch (prefix->af) { - switch (prefix->af) {
case AF_INET: - case AF_INET:
+ bzero(&pte4, sizeof(pte4)); + switch (prefix->aid) {
+ case AID_INET:
bzero(&pte4, sizeof(pte4));
+ pte4.aid = prefix->aid;
if (prefixlen > 32) if (prefixlen > 32)
fatalx("pt_get: bad IPv4 prefixlen"); - fatalx("pt_get: bad IPv4 prefixlen");
pte4.af = AF_INET; - pte4.af = AF_INET;
@@ -118,24 +103,33 @@ pt_get(struct bgpd_addr *prefix, int pre + fatalx("pt_fill: bad IPv4 prefixlen");
addr_hbo = ntohl(prefix->v4.s_addr);
pte4.prefix4.s_addr = htonl(addr_hbo & pte4.prefix4.s_addr = htonl(addr_hbo &
prefixlen2mask(prefixlen)); prefixlen2mask(prefixlen));
pte4.prefixlen = prefixlen; pte4.prefixlen = prefixlen;
- return RB_FIND(pt_tree, &pttable4, (struct pt_entry *)&pte4); return ((struct pt_entry *)&pte4);
+ return ((struct pt_entry *)&pte4); - case AF_INET6:
case AF_INET6: + case AID_INET6:
+ bzero(&pte6, sizeof(pte6)); bzero(&pte6, sizeof(pte6));
+ pte6.aid = prefix->aid;
if (prefixlen > 128) if (prefixlen > 128)
fatalx("pt_get: bad IPv6 prefixlen"); fatalx("pt_get: bad IPv6 prefixlen");
pte6.af = AF_INET6; - pte6.af = AF_INET6;
pte6.prefixlen = prefixlen; pte6.prefixlen = prefixlen;
inet6applymask(&pte6.prefix6, &prefix->v6, prefixlen); inet6applymask(&pte6.prefix6, &prefix->v6, prefixlen);
- return RB_FIND(pt_tree, &pttable6, (struct pt_entry *)&pte6); return ((struct pt_entry *)&pte6);
+ return ((struct pt_entry *)&pte6); + case AID_VPN_IPv4:
+ bzero(&pte_vpn4, sizeof(pte_vpn4));
+ pte_vpn4.aid = prefix->aid;
+ if (prefixlen > 32)
+ fatalx("pt_fill: bad IPv4 prefixlen");
+ addr_hbo = ntohl(prefix->vpn4.addr.s_addr);
+ pte_vpn4.prefix4.s_addr = htonl(addr_hbo &
+ prefixlen2mask(prefixlen));
+ pte_vpn4.prefixlen = prefixlen;
+ pte_vpn4.rd = prefix->vpn4.rd;
+ pte_vpn4.labellen = prefix->vpn4.labellen;
+ memcpy(pte_vpn4.labelstack, prefix->vpn4.labelstack,
+ prefix->vpn4.labellen);
+ return ((struct pt_entry *)&pte_vpn4);
default: default:
log_warnx("pt_get: unknown af"); - log_warnx("pt_get: unknown af");
+ return (NULL);
}
- return (NULL); - return (NULL);
+} + fatalx("pt_fill: unknown af");
+ }
+struct pt_entry * + /* NOT REACHED */
+pt_get(struct bgpd_addr *prefix, int prefixlen) + return (NULL);
+{
+ struct pt_entry *pte;
+
+ pte = pt_fill(prefix, prefixlen);
+ return RB_FIND(pt_tree, &pttable, pte);
} }
struct pt_entry * struct pt_entry *
@@ -131,34 +155,9 @@ struct pt_entry *
pt_add(struct bgpd_addr *prefix, int prefixlen) pt_add(struct bgpd_addr *prefix, int prefixlen)
{ {
- struct pt_tree *tree = NULL;
struct pt_entry *p = NULL; struct pt_entry *p = NULL;
struct pt_entry4 *p4; - struct pt_entry4 *p4;
struct pt_entry6 *p6; - struct pt_entry6 *p6;
@@ -152,7 +146,6 @@ pt_add(struct bgpd_addr *prefix, int pre - in_addr_t addr_hbo;
p4->prefix4.s_addr = htonl(addr_hbo &
prefixlen2mask(prefixlen));
p = (struct pt_entry *)p4;
- tree = &pttable4;
break;
case AF_INET6:
p6 = pt_alloc6();
@@ -162,15 +155,13 @@ pt_add(struct bgpd_addr *prefix, int pre
p6->prefixlen = prefixlen;
inet6applymask(&p6->prefix6, &prefix->v6, prefixlen);
p = (struct pt_entry *)p6;
- tree = &pttable6;
break;
default:
fatalx("pt_add: unknown af");
}
- LIST_INIT(&p->prefix_h);
- if (RB_INSERT(pt_tree, tree, p) != NULL) {
- log_warnx("prefix_add: insert failed");
+ if (RB_INSERT(pt_tree, &pttable, p) != NULL) {
+ log_warnx("pt_add: insert failed");
return (NULL);
}
@@ -181,101 +172,35 @@ void
pt_remove(struct pt_entry *pte)
{
if (!pt_empty(pte))
- fatalx("pt_remove: entry not empty");
- -
- switch (pte->af) { - switch (prefix->af) {
- case AF_INET: - case AF_INET:
- if (RB_REMOVE(pt_tree, &pttable4, pte) == NULL) - p4 = pt_alloc4();
- log_warnx("pt_remove: remove failed."); - if (prefixlen > 32)
- fatalx("pt_add: bad IPv4 prefixlen");
- p4->af = AF_INET;
- p4->prefixlen = prefixlen;
- addr_hbo = ntohl(prefix->v4.s_addr);
- p4->prefix4.s_addr = htonl(addr_hbo &
- prefixlen2mask(prefixlen));
- p = (struct pt_entry *)p4;
- break; - break;
- case AF_INET6: - case AF_INET6:
- if (RB_REMOVE(pt_tree, &pttable6, pte) == NULL) - p6 = pt_alloc6();
- log_warnx("pt_remove: remove failed."); - if (prefixlen > 128)
- fatalx("pt_add: bad IPv6 prefixlen");
- p6->af = AF_INET6;
- p6->prefixlen = prefixlen;
- inet6applymask(&p6->prefix6, &prefix->v6, prefixlen);
- p = (struct pt_entry *)p6;
- break; - break;
- default: - default:
- fatalx("pt_remove: unknown af"); - fatalx("pt_add: unknown af");
- } - }
+ fatalx("pt_remove: entry still holds references"); +
+ p = pt_fill(prefix, prefixlen);
+ p = pt_alloc(p);
+ if (RB_REMOVE(pt_tree, &pttable, pte) == NULL) if (RB_INSERT(pt_tree, &pttable, p) != NULL) {
+ log_warnx("pt_remove: remove failed."); log_warnx("pt_add: insert failed");
pt_free(pte); @@ -183,13 +182,14 @@ struct pt_entry *
} pt_lookup(struct bgpd_addr *addr)
struct pt_entry *
-pt_lookup(struct bgpd_addr *prefix)
+pt_lookup(struct bgpd_addr *addr)
{ {
struct pt_entry *p; struct pt_entry *p;
int i; - int i;
+ int i = 0;
- switch (prefix->af) { - switch (addr->af) {
+ switch (addr->af) { - case AF_INET:
case AF_INET: + switch (addr->aid) {
- for (i = 32; i >= 0; i--) { + case AID_INET:
- p = pt_get(prefix, i); + case AID_VPN_IPv4:
- if (p != NULL) i = 32;
- return (p);
- }
+ i = 32;
break; break;
case AF_INET6: - case AF_INET6:
- for (i = 128; i >= 0; i--) { + case AID_INET6:
- p = pt_get(prefix, i); i = 128;
- if (p != NULL)
- return (p);
- }
+ i = 128;
break; break;
default: default:
fatalx("pt_lookup: unknown af"); @@ -206,17 +206,18 @@ pt_lookup(struct bgpd_addr *addr)
}
- return (NULL);
-}
-
-void
-pt_dump(void (*upcall)(struct pt_entry *, void *), void *arg, sa_family_t af)
-{
- if (af == AF_INET || af == AF_UNSPEC)
- pt_dump_r(upcall, arg, AF_INET, NULL);
- if (af == AF_INET6 || af == AF_UNSPEC)
- pt_dump_r(upcall, arg, AF_INET6, NULL);
-}
-
-void
-pt_dump_r(void (*upcall)(struct pt_entry *, void *), void *arg,
- sa_family_t af, struct pt_context *ctx)
-{
- struct pt_entry *p;
- unsigned int i;
-
- if (ctx == NULL || ctx->ctx_p.af != af) {
- switch (af) {
- case AF_INET:
- p = RB_MIN(pt_tree, &pttable4);
- break;
- case AF_INET6:
- p = RB_MIN(pt_tree, &pttable6);
- break;
- default:
- return;
- }
- } else
- p = pt_restart(ctx);
-
- for (i = 0; p != NULL; p = RB_NEXT(pt_tree, unused, p)) {
- if (ctx && i++ >= ctx->count) {
- /* store next start point */
- switch (p->af) {
- case AF_INET:
- ctx->ctx_p4 = *(struct pt_entry4 *)p;
- break;
- case AF_INET6:
- ctx->ctx_p6 = *(struct pt_entry6 *)p;
- break;
- default:
- fatalx("pt_dump_r: unknown af");
- }
- return;
- }
- upcall(p, arg);
+ for (; i >= 0; i--) {
+ p = pt_get(addr, i);
+ if (p != NULL)
+ return (p);
}
-
- if (ctx)
- ctx->done = 1;
+ return (NULL);
}
int int
@@ -285,8 +210,10 @@ pt_prefix_cmp(const struct pt_entry *a, pt_prefix_cmp(const struct pt_entry *a, const struct pt_entry *b)
const struct pt_entry6 *a6, *b6; {
int i; - const struct pt_entry4 *a4, *b4;
- const struct pt_entry6 *a6, *b6;
- int i;
+ const struct pt_entry4 *a4, *b4;
+ const struct pt_entry6 *a6, *b6;
+ const struct pt_entry_vpn4 *va4, *vb4;
+ int i;
- if (a->af != b->af) - if (a->af > b->af)
- fatalx("king bula sez: comparing pears with apples"); + if (a->aid > b->aid)
+ if (a->af > b->af) return (1);
- if (a->af < b->af)
+ if (a->aid < b->aid)
return (-1);
- switch (a->af) {
- case AF_INET:
+ switch (a->aid) {
+ case AID_INET:
a4 = (const struct pt_entry4 *)a;
b4 = (const struct pt_entry4 *)b;
if (ntohl(a4->prefix4.s_addr) > ntohl(b4->prefix4.s_addr))
@@ -228,7 +229,7 @@ pt_prefix_cmp(const struct pt_entry *a,
if (a4->prefixlen < b4->prefixlen)
return (-1);
return (0);
- case AF_INET6:
+ case AID_INET6:
a6 = (const struct pt_entry6 *)a;
b6 = (const struct pt_entry6 *)b;
@@ -242,49 +243,49 @@ pt_prefix_cmp(const struct pt_entry *a,
if (a6->prefixlen > b6->prefixlen)
return (1);
return (0);
+ case AID_VPN_IPv4:
+ va4 = (const struct pt_entry_vpn4 *)a;
+ vb4 = (const struct pt_entry_vpn4 *)b;
+ if (ntohl(va4->prefix4.s_addr) > ntohl(vb4->prefix4.s_addr))
+ return (1); + return (1);
+ if (a->af < b->af) + if (ntohl(va4->prefix4.s_addr) < ntohl(vb4->prefix4.s_addr))
+ return (-1); + return (-1);
+ if (va4->prefixlen > vb4->prefixlen)
switch (a->af) { + return (1);
case AF_INET: + if (va4->prefixlen < vb4->prefixlen)
@@ -361,56 +288,3 @@ pt_free(struct pt_entry *pte) + return (-1);
+ if (betoh64(va4->rd) > betoh64(vb4->rd))
+ return (1);
+ if (betoh64(va4->rd) < betoh64(vb4->rd))
+ return (-1);
+ return (0);
default:
fatalx("pt_prefix_cmp: unknown af");
} }
return (-1);
}
-/* returns a zeroed pt_entry function may not return on fail */
-static struct pt_entry4 *
-pt_alloc4(void)
+/*
+ * Returns a pt_entry cloned from the one passed in.
+ * Function may not return on failure.
+ */
+static struct pt_entry *
+pt_alloc(struct pt_entry *op)
{
- struct pt_entry4 *p;
+ struct pt_entry *p;
- p = calloc(1, sizeof(*p));
+ p = malloc(pt_sizes[op->aid]);
if (p == NULL)
fatal("pt_alloc");
- rdemem.pt4_cnt++;
- return (p);
-}
+ rdemem.pt_cnt[op->aid]++;
+ memcpy(p, op, pt_sizes[op->aid]);
-static struct pt_entry6 *
-pt_alloc6(void)
-{
- struct pt_entry6 *p;
-
- p = calloc(1, sizeof(*p));
- if (p == NULL)
- fatal("pt_alloc");
- rdemem.pt6_cnt++;
return (p);
}
static void
pt_free(struct pt_entry *pte)
{
- switch (pte->af) {
- case AF_INET:
- rdemem.pt4_cnt--;
- break;
- case AF_INET6:
- rdemem.pt6_cnt--;
- break;
- default:
- break;
- }
+ rdemem.pt_cnt[pte->aid]--;
free(pte); free(pte);
} }
-
-static struct pt_entry *
-pt_restart(struct pt_context *ctx)
-{
- struct pt_entry *tmp, *prev = NULL;
- int comp;
-
- /* first select correct tree */
- switch (ctx->ctx_p.af) {
- case AF_INET:
- tmp = RB_ROOT(&pttable4);
- break;
- case AF_INET6:
- tmp = RB_ROOT(&pttable6);
- break;
- default:
- fatalx("pt_restart: unknown af");
- }
-
- /* then try to find the element */
- while (tmp) {
- prev = tmp;
- comp = pt_prefix_cmp(&ctx->ctx_p, tmp);
- if (comp < 0)
- tmp = RB_LEFT(tmp, pt_e);
- else if (comp > 0)
- tmp = RB_RIGHT(tmp, pt_e);
- else
- return (tmp);
- }
-
- /* no match, empty tree */
- if (prev == NULL)
- return (NULL);
-
- /*
- * no perfect match
- * if last element was bigger use that as new start point
- */
- if (comp < 0)
- return (prev);
-
- /* backtrack until parent is bigger */
- do {
- prev = RB_PARENT(prev, pt_e);
- if (prev == NULL)
- /* all elements in the tree are smaler */
- return (NULL);
- comp = pt_prefix_cmp(&ctx->ctx_p, prev);
- } while (comp > 0);
-
- return (prev);
-}

File diff suppressed because it is too large Load diff

View file

@ -1,18 +1,18 @@
Index: bgpd/rde_update.c Index: bgpd/rde_update.c
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/rde_update.c,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/rde_update.c,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.7
retrieving revision 1.4 retrieving revision 1.6
diff -u -p -r1.1.1.1 -r1.4 diff -u -p -r1.1.1.7 -r1.6
--- bgpd/rde_update.c 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/rde_update.c 14 Feb 2010 20:19:57 -0000 1.1.1.7
+++ bgpd/rde_update.c 10 Aug 2009 21:20:05 -0000 1.4 +++ bgpd/rde_update.c 14 Feb 2010 19:53:36 -0000 1.6
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: rde_update.c,v 1.61 2007/11/27 01:13:54 claudio Exp $ */ -/* $OpenBSD: rde_update.c,v 1.68 2009/06/06 01:10:29 claudio Exp $ */
+/* $OpenBSD: rde_update.c,v 1.69 2009/08/06 08:53:11 claudio Exp $ */ +/* $OpenBSD: rde_update.c,v 1.77 2010/01/13 06:02:37 claudio Exp $ */
/* /*
* Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
@@ -17,10 +17,17 @@ @@ -17,19 +17,26 @@
*/ */
#include <sys/types.h> #include <sys/types.h>
#include <sys/queue.h> #include <sys/queue.h>
@ -30,7 +30,120 @@ diff -u -p -r1.1.1.1 -r1.4
#include "bgpd.h" #include "bgpd.h"
#include "rde.h" #include "rde.h"
@@ -270,6 +277,8 @@ up_test_update(struct rde_peer *peer, st
in_addr_t up_get_nexthop(struct rde_peer *, struct rde_aspath *);
int up_generate_mp_reach(struct rde_peer *, struct update_attr *,
- struct rde_aspath *, sa_family_t);
+ struct rde_aspath *, u_int8_t);
int up_generate_attr(struct rde_peer *, struct update_attr *,
- struct rde_aspath *, sa_family_t);
+ struct rde_aspath *, u_int8_t);
/* update stuff. */
struct update_prefix {
@@ -65,10 +72,12 @@ RB_GENERATE(uptree_attr, update_attr, en
void
up_init(struct rde_peer *peer)
{
- TAILQ_INIT(&peer->updates);
- TAILQ_INIT(&peer->withdraws);
- TAILQ_INIT(&peer->updates6);
- TAILQ_INIT(&peer->withdraws6);
+ u_int8_t i;
+
+ for (i = 0; i < AID_MAX; i++) {
+ TAILQ_INIT(&peer->updates[i]);
+ TAILQ_INIT(&peer->withdraws[i]);
+ }
RB_INIT(&peer->up_prefix);
RB_INIT(&peer->up_attrs);
peer->up_pcnt = 0;
@@ -103,8 +112,10 @@ up_clear(struct uplist_attr *updates, st
void
up_down(struct rde_peer *peer)
{
- up_clear(&peer->updates, &peer->withdraws);
- up_clear(&peer->updates6, &peer->withdraws6);
+ u_int8_t i;
+
+ for (i = 0; i < AID_MAX; i++)
+ up_clear(&peer->updates[i], &peer->withdraws[i]);
RB_INIT(&peer->up_prefix);
RB_INIT(&peer->up_attrs);
@@ -120,19 +131,19 @@ up_prefix_cmp(struct update_prefix *a, s
{
int i;
- if (a->prefix.af < b->prefix.af)
+ if (a->prefix.aid < b->prefix.aid)
return (-1);
- if (a->prefix.af > b->prefix.af)
+ if (a->prefix.aid > b->prefix.aid)
return (1);
- switch (a->prefix.af) {
- case AF_INET:
+ switch (a->prefix.aid) {
+ case AID_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:
+ case AID_INET6:
i = memcmp(&a->prefix.v6, &b->prefix.v6,
sizeof(struct in6_addr));
if (i > 0)
@@ -140,6 +151,25 @@ up_prefix_cmp(struct update_prefix *a, s
if (i < 0)
return (-1);
break;
+ case AID_VPN_IPv4:
+ if (betoh64(a->prefix.vpn4.rd) < betoh64(b->prefix.vpn4.rd))
+ return (-1);
+ if (betoh64(a->prefix.vpn4.rd) > betoh64(b->prefix.vpn4.rd))
+ return (1);
+ 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);
+ if (a->prefixlen < b->prefixlen)
+ return (-1);
+ if (a->prefixlen > b->prefixlen)
+ return (1);
+ if (a->prefix.vpn4.labellen < b->prefix.vpn4.labellen)
+ return (-1);
+ if (a->prefix.vpn4.labellen > b->prefix.vpn4.labellen)
+ return (1);
+ return (memcmp(a->prefix.vpn4.labelstack,
+ b->prefix.vpn4.labelstack, a->prefix.vpn4.labellen));
default:
fatalx("pt_prefix_cmp: unknown af");
}
@@ -174,18 +204,8 @@ up_add(struct rde_peer *peer, struct upd
struct uplist_attr *upl = NULL;
struct uplist_prefix *wdl = NULL;
- switch (p->prefix.af) {
- case AF_INET:
- upl = &peer->updates;
- wdl = &peer->withdraws;
- break;
- case AF_INET6:
- upl = &peer->updates6;
- wdl = &peer->withdraws6;
- break;
- default:
- fatalx("up_add: unknown AF");
- }
+ upl = &peer->updates[p->prefix.aid];
+ wdl = &peer->withdraws[p->prefix.aid];
/* 1. search for attr */
if (a != NULL && (na = RB_FIND(uptree_attr, &peer->up_attrs, a)) ==
@@ -270,21 +290,14 @@ up_test_update(struct rde_peer *peer, st
/* Do not send routes back to sender */ /* Do not send routes back to sender */
return (0); return (0);
@ -39,154 +152,461 @@ diff -u -p -r1.1.1.1 -r1.4
if (p->aspath->flags & F_ATTR_LOOP) if (p->aspath->flags & F_ATTR_LOOP)
fatalx("try to send out a looped path"); fatalx("try to send out a looped path");
@@ -360,7 +369,7 @@ up_generate(struct rde_peer *peer, struc pt_getaddr(p->prefix, &addr);
if (asp) { - switch (addr.af) {
ua = calloc(1, sizeof(struct update_attr)); - case AF_INET:
if (ua == NULL) - if (peer->capa_announced.mp_v4 == SAFI_NONE &&
- fatal("up_generate_updates"); - peer->capa_received.mp_v6 != SAFI_NONE)
+ fatal("up_generate"); - return (-1);
- break;
- case AF_INET6:
- if (peer->capa_announced.mp_v6 == SAFI_NONE)
- return (-1);
- break;
- }
+ if (peer->capa.mp[addr.aid] == 0)
+ return (-1);
if (up_generate_attr(peer, ua, asp, addr->af) == -1) { if (p->aspath->peer->conf.ebgp == 0 && peer->conf.ebgp == 0) {
log_warnx("generation of bgp path attributes failed"); /*
@@ -379,7 +388,7 @@ up_generate(struct rde_peer *peer, struc @@ -325,13 +338,13 @@ up_test_update(struct rde_peer *peer, st
up = calloc(1, sizeof(struct update_prefix));
if (up == NULL)
- fatal("up_generate_updates");
+ fatal("up_generate");
up->prefix = *addr;
up->prefixlen = prefixlen;
@@ -404,9 +413,9 @@ up_generate_updates(struct filter_head *
return;
pt_getaddr(old->prefix, &addr);
- if (rde_filter(NULL, rules, peer, old->aspath, &addr,
- old->prefix->prefixlen, old->aspath->peer, DIR_OUT) ==
- ACTION_DENY)
+ if (rde_filter(peer->ribid, NULL, rules, peer, old->aspath,
+ &addr, old->prefix->prefixlen, old->aspath->peer,
+ DIR_OUT) == ACTION_DENY)
return;
/* withdraw prefix */
@@ -423,9 +432,9 @@ up_generate_updates(struct filter_head *
} }
pt_getaddr(new->prefix, &addr); /* well known communities */
- if (rde_filter(&asp, rules, peer, new->aspath, &addr, - if (rde_filter_community(p->aspath,
- new->prefix->prefixlen, new->aspath->peer, DIR_OUT) == + if (community_match(p->aspath,
- ACTION_DENY) { COMMUNITY_WELLKNOWN, COMMUNITY_NO_ADVERTISE))
+ if (rde_filter(peer->ribid, &asp, rules, peer, new->aspath, return (0);
+ &addr, new->prefix->prefixlen, new->aspath->peer, - if (peer->conf.ebgp && rde_filter_community(p->aspath,
+ DIR_OUT) == ACTION_DENY) { + if (peer->conf.ebgp && community_match(p->aspath,
path_put(asp); COMMUNITY_WELLKNOWN, COMMUNITY_NO_EXPORT))
up_generate_updates(rules, peer, NULL, old); return (0);
return; - if (peer->conf.ebgp && rde_filter_community(p->aspath,
@@ -473,8 +482,8 @@ up_generate_default(struct filter_head * + if (peer->conf.ebgp && community_match(p->aspath,
bzero(&addr, sizeof(addr)); COMMUNITY_WELLKNOWN, COMMUNITY_NO_EXPSUBCONFED))
addr.af = af; return (0);
- if (rde_filter(&fasp, rules, peer, asp, &addr, 0, NULL, DIR_OUT) == @@ -362,7 +375,7 @@ up_generate(struct rde_peer *peer, struc
- ACTION_DENY) { if (ua == NULL)
+ if (rde_filter(peer->ribid, &fasp, rules, peer, asp, &addr, 0, NULL, fatal("up_generate");
+ DIR_OUT) == ACTION_DENY) {
path_put(fasp);
path_put(asp);
return;
@@ -617,7 +626,7 @@ up_generate_attr(struct rde_peer *peer,
u_char *pdata;
u_int32_t tmp32;
in_addr_t nexthop;
- int r, ismp = 0, neednewpath = 0;
+ int flags, r, ismp = 0, neednewpath = 0;
u_int16_t len = sizeof(up_attr_buf), wlen = 0, plen;
u_int8_t l;
@@ -629,7 +638,7 @@ up_generate_attr(struct rde_peer *peer, - if (up_generate_attr(peer, ua, asp, addr->af) == -1) {
+ if (up_generate_attr(peer, ua, asp, addr->aid) == -1) {
/* aspath */ log_warnx("generation of bgp path attributes failed");
if (!peer->conf.ebgp || free(ua);
- rde_decisionflags() & BGPD_FLAG_DECISION_TRANS_AS)
+ peer->conf.flags & PEERFLAG_TRANS_AS)
pdata = aspath_prepend(a->aspath, rde_local_as(), 0, &plen);
else
pdata = aspath_prepend(a->aspath, rde_local_as(), 1, &plen);
@@ -762,25 +771,29 @@ up_generate_attr(struct rde_peer *peer,
/* NEW to OLD conversion when going sending stuff to a 2byte AS peer */
if (neednewpath) {
if (!peer->conf.ebgp ||
- rde_decisionflags() & BGPD_FLAG_DECISION_TRANS_AS)
+ peer->conf.flags & PEERFLAG_TRANS_AS)
pdata = aspath_prepend(a->aspath, rde_local_as(), 0,
&plen);
else
pdata = aspath_prepend(a->aspath, rde_local_as(), 1,
&plen);
+ flags = ATTR_OPTIONAL|ATTR_TRANSITIVE;
+ if (!(a->flags & F_PREFIX_ANNOUNCED))
+ flags |= ATTR_PARTIAL;
if (plen == 0)
r = 0;
- else if ((r = attr_write(up_attr_buf + wlen, len,
- ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_NEW_ASPATH,
- pdata, plen)) == -1)
+ else if ((r = attr_write(up_attr_buf + wlen, len, flags,
+ ATTR_AS4_PATH, pdata, plen)) == -1)
return (-1); return (-1);
@@ -444,18 +457,12 @@ up_generate_updates(struct filter_head *
/* send a default route to the specified peer */
void
up_generate_default(struct filter_head *rules, struct rde_peer *peer,
- sa_family_t af)
+ u_int8_t aid)
{
struct rde_aspath *asp, *fasp;
struct bgpd_addr addr;
- if (peer->capa_received.mp_v4 == SAFI_NONE &&
- peer->capa_received.mp_v6 != SAFI_NONE &&
- af == AF_INET)
- return;
-
- if (peer->capa_received.mp_v6 == SAFI_NONE &&
- af == AF_INET6)
+ if (peer->capa.mp[aid] == 0)
return;
asp = path_get();
@@ -471,7 +478,7 @@ up_generate_default(struct filter_head *
/* filter as usual */
bzero(&addr, sizeof(addr));
- addr.af = af;
+ addr.aid = aid;
if (rde_filter(peer->ribid, &fasp, rules, peer, asp, &addr, 0, NULL,
DIR_OUT) == ACTION_DENY) {
@@ -491,6 +498,43 @@ up_generate_default(struct filter_head *
path_put(asp);
}
+/* generate a EoR marker in the update list. This is a horrible hack. */
+int
+up_generate_marker(struct rde_peer *peer, u_int8_t aid)
+{
+ struct update_attr *ua;
+ struct update_attr *na = NULL;
+ struct uplist_attr *upl = NULL;
+
+ ua = calloc(1, sizeof(struct update_attr));
+ if (ua == NULL)
+ fatal("up_generate_marker");
+
+ upl = &peer->updates[aid];
+
+ /* 1. search for attr */
+ if ((na = RB_FIND(uptree_attr, &peer->up_attrs, ua)) == NULL) {
+ /* 1.1 if not found -> add */
+ TAILQ_INIT(&ua->prefix_h);
+ if (RB_INSERT(uptree_attr, &peer->up_attrs, ua) != NULL) {
+ log_warnx("uptree_attr insert failed");
+ /* cleanup */
+ free(ua);
+ return (-1);
+ }
+ TAILQ_INSERT_TAIL(upl, ua, attr_l);
+ peer->up_acnt++;
+ } else {
+ /* 1.2 if found -> use that, free ua */
+ free(ua);
+ ua = na;
+ /* move to end of update queue */
+ TAILQ_REMOVE(upl, ua, attr_l);
+ TAILQ_INSERT_TAIL(upl, ua, attr_l);
+ }
+ return (0);
+}
+
u_char up_attr_buf[4096];
/* only for IPv4 */
@@ -551,28 +595,41 @@ up_get_nexthop(struct rde_peer *peer, st
int
up_generate_mp_reach(struct rde_peer *peer, struct update_attr *upa,
- struct rde_aspath *a, sa_family_t af)
+ struct rde_aspath *a, u_int8_t aid)
{
u_int16_t tmp;
- switch (af) {
- case AF_INET6:
+ switch (aid) {
+ case AID_INET6:
upa->mpattr_len = 21; /* AFI + SAFI + NH LEN + NH + Reserved */
upa->mpattr = malloc(upa->mpattr_len);
if (upa->mpattr == NULL)
fatal("up_generate_mp_reach");
- tmp = htons(AFI_IPv6);
+ if (aid2afi(aid, &tmp, &upa->mpattr[2]))
+ fatalx("up_generate_mp_reachi: bad AID");
+ tmp = htons(tmp);
memcpy(upa->mpattr, &tmp, sizeof(tmp));
- upa->mpattr[2] = SAFI_UNICAST;
upa->mpattr[3] = sizeof(struct in6_addr);
upa->mpattr[20] = 0; /* Reserved must be 0 */
/* nexthop dance see also up_get_nexthop() */
- if (peer->conf.ebgp == 0) {
+ if (a->flags & F_NEXTHOP_NOMODIFY) {
+ /* no modify flag set */
+ if (a->nexthop == NULL)
+ memcpy(&upa->mpattr[4], &peer->local_v6_addr.v6,
+ sizeof(struct in6_addr));
+ else
+ memcpy(&upa->mpattr[4],
+ &a->nexthop->exit_nexthop.v6,
+ sizeof(struct in6_addr));
+ } else if (a->flags & F_NEXTHOP_SELF)
+ memcpy(&upa->mpattr[4], &peer->local_v6_addr.v6,
+ sizeof(struct in6_addr));
+ else if (!peer->conf.ebgp) {
/* ibgp */
if (a->nexthop == NULL ||
- (a->nexthop->exit_nexthop.af == AF_INET6 &&
- memcmp(&a->nexthop->exit_nexthop.v6,
+ (a->nexthop->exit_nexthop.aid == AID_INET6 &&
+ !memcmp(&a->nexthop->exit_nexthop.v6,
&peer->remote_addr.v6, sizeof(struct in6_addr))))
memcpy(&upa->mpattr[4], &peer->local_v6_addr.v6,
sizeof(struct in6_addr));
@@ -603,6 +660,68 @@ up_generate_mp_reach(struct rde_peer *pe
memcpy(&upa->mpattr[4], &peer->local_v6_addr.v6,
sizeof(struct in6_addr));
return (0);
+ case AID_VPN_IPv4:
+ upa->mpattr_len = 17; /* AFI + SAFI + NH LEN + NH + Reserved */
+ upa->mpattr = calloc(upa->mpattr_len, 1);
+ if (upa->mpattr == NULL)
+ fatal("up_generate_mp_reach");
+ if (aid2afi(aid, &tmp, &upa->mpattr[2]))
+ fatalx("up_generate_mp_reachi: bad AID");
+ tmp = htons(tmp);
+ memcpy(upa->mpattr, &tmp, sizeof(tmp));
+ upa->mpattr[3] = sizeof(u_int64_t) + sizeof(struct in_addr);
+
+ /* nexthop dance see also up_get_nexthop() */
+ if (a->flags & F_NEXTHOP_NOMODIFY) {
+ /* no modify flag set */
+ if (a->nexthop == NULL)
+ memcpy(&upa->mpattr[12],
+ &peer->local_v4_addr.v4,
+ sizeof(struct in_addr));
+ else
+ /* nexthops are stored as IPv4 addrs */
+ memcpy(&upa->mpattr[12],
+ &a->nexthop->exit_nexthop.v4,
+ sizeof(struct in_addr));
+ } else if (a->flags & F_NEXTHOP_SELF)
+ memcpy(&upa->mpattr[12], &peer->local_v4_addr.v4,
+ sizeof(struct in_addr));
+ else if (!peer->conf.ebgp) {
+ /* ibgp */
+ if (a->nexthop == NULL ||
+ (a->nexthop->exit_nexthop.aid == AID_INET &&
+ !memcmp(&a->nexthop->exit_nexthop.v4,
+ &peer->remote_addr.v4, sizeof(struct in_addr))))
+ memcpy(&upa->mpattr[12],
+ &peer->local_v4_addr.v4,
+ sizeof(struct in_addr));
+ else
+ memcpy(&upa->mpattr[12],
+ &a->nexthop->exit_nexthop.v4,
+ sizeof(struct in_addr));
+ } else if (peer->conf.distance == 1) {
+ /* ebgp directly connected */
+ if (a->nexthop != NULL &&
+ a->nexthop->flags & NEXTHOP_CONNECTED)
+ if (prefix_compare(&peer->remote_addr,
+ &a->nexthop->nexthop_net,
+ a->nexthop->nexthop_netlen) == 0) {
+ /*
+ * nexthop and peer are in the same
+ * subnet
+ */
+ memcpy(&upa->mpattr[12],
+ &a->nexthop->exit_nexthop.v4,
+ sizeof(struct in_addr));
+ return (0);
+ }
+ memcpy(&upa->mpattr[12], &peer->local_v4_addr.v4,
+ sizeof(struct in_addr));
+ } else
+ /* ebgp multihop */
+ memcpy(&upa->mpattr[12], &peer->local_v4_addr.v4,
+ sizeof(struct in_addr));
+ return (0);
default:
break;
}
@@ -611,7 +730,7 @@ up_generate_mp_reach(struct rde_peer *pe
int
up_generate_attr(struct rde_peer *peer, struct update_attr *upa,
- struct rde_aspath *a, sa_family_t af)
+ struct rde_aspath *a, u_int8_t aid)
{
struct attr *oa, *newaggr = NULL;
u_char *pdata;
@@ -643,8 +762,8 @@ up_generate_attr(struct rde_peer *peer,
wlen += r; len -= r; wlen += r; len -= r;
free(pdata); free(pdata);
}
if (newaggr) { - switch (af) {
- if ((r = attr_write(up_attr_buf + wlen, len, - case AF_INET:
- ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_NEW_AGGREGATOR, + switch (aid) {
- newaggr->data, newaggr->len)) == -1) + case AID_INET:
+ flags = ATTR_OPTIONAL|ATTR_TRANSITIVE; nexthop = up_get_nexthop(peer, a);
+ if (!(a->flags & F_PREFIX_ANNOUNCED)) if ((r = attr_write(up_attr_buf + wlen, len, ATTR_WELL_KNOWN,
+ flags |= ATTR_PARTIAL; ATTR_NEXTHOP, &nexthop, 4)) == -1)
+ if ((r = attr_write(up_attr_buf + wlen, len, flags, @@ -659,9 +778,11 @@ up_generate_attr(struct rde_peer *peer,
+ ATTR_AS4_AGGREGATOR, newaggr->data, newaggr->len)) == -1) /*
* The old MED from other peers MUST not be announced to others
* unless the MED is originating from us or the peer is an IBGP one.
+ * Only exception are routers with "transparent-as yes" set.
*/
if (a->flags & F_ATTR_MED && (peer->conf.ebgp == 0 ||
- a->flags & F_ATTR_MED_ANNOUNCE)) {
+ a->flags & F_ATTR_MED_ANNOUNCE ||
+ peer->conf.flags & PEERFLAG_TRANS_AS)) {
tmp32 = htonl(a->med);
if ((r = attr_write(up_attr_buf + wlen, len, ATTR_OPTIONAL,
ATTR_MED, &tmp32, 4)) == -1)
@@ -791,7 +912,7 @@ up_generate_attr(struct rde_peer *peer,
/* write mp attribute to different buffer */
if (ismp)
- if (up_generate_mp_reach(peer, upa, a, AF_INET6) == -1)
+ if (up_generate_mp_reach(peer, upa, a, aid) == -1)
return (-1); return (-1);
wlen += r; len -= r;
}
@@ -913,13 +926,7 @@ up_dump_mp_unreach(u_char *buf, u_int16_
return (NULL);
datalen += 3; /* afi + safi */ /* the bgp path attributes are now stored in the global buf */
- if (datalen > 255) { @@ -810,6 +931,7 @@ up_dump_prefix(u_char *buf, int len, str
- attrlen += 2 + datalen; {
- flags |= ATTR_EXTLEN; struct update_prefix *upp;
int r, wpos = 0;
+ u_int8_t i;
while ((upp = TAILQ_FIRST(prefix_head)) != NULL) {
if ((r = prefix_write(buf + wpos, len - wpos,
@@ -820,13 +942,14 @@ up_dump_prefix(u_char *buf, int len, str
log_warnx("dequeuing update failed.");
TAILQ_REMOVE(upp->prefix_h, upp, prefix_l);
peer->up_pcnt--;
- if (upp->prefix_h == &peer->withdraws ||
- upp->prefix_h == &peer->withdraws6) {
- peer->up_wcnt--;
- peer->prefix_sent_withdraw++;
- } else { - } else {
- attrlen += 1 + datalen; - peer->up_nlricnt--;
- buf++; - peer->prefix_sent_update++;
- } + for (i = 0; i < AID_MAX; i++) {
+ + if (upp->prefix_h == &peer->withdraws[i]) {
/* prepend header, need to do it reverse */ + peer->up_wcnt--;
/* safi & afi */ + peer->prefix_sent_withdraw++;
buf[--wpos] = SAFI_UNICAST;
@@ -929,11 +936,15 @@ up_dump_mp_unreach(u_char *buf, u_int16_
/* attribute length */
if (datalen > 255) {
+ attrlen += 2 + datalen;
+ flags |= ATTR_EXTLEN;
wpos -= sizeof(u_int16_t);
tmp = htons(datalen);
memcpy(buf + wpos, &tmp, sizeof(u_int16_t));
- } else
+ } else { + } else {
+ attrlen += 1 + datalen; + peer->up_nlricnt--;
buf[--wpos] = (u_char)datalen; + peer->prefix_sent_update++;
+ } + }
}
free(upp);
}
@@ -844,16 +967,21 @@ up_dump_attrnlri(u_char *buf, int len, s
* It is possible that a queued path attribute has no nlri prefix.
* Ignore and remove those path attributes.
*/
- while ((upa = TAILQ_FIRST(&peer->updates)) != NULL)
+ while ((upa = TAILQ_FIRST(&peer->updates[AID_INET])) != NULL)
if (TAILQ_EMPTY(&upa->prefix_h)) {
+ attr_len = upa->attr_len;
if (RB_REMOVE(uptree_attr, &peer->up_attrs,
upa) == NULL)
log_warnx("dequeuing update failed.");
- TAILQ_REMOVE(&peer->updates, upa, attr_l);
+ TAILQ_REMOVE(&peer->updates[AID_INET], upa, attr_l);
free(upa->attr);
free(upa->mpattr);
free(upa);
peer->up_acnt--;
+ /* XXX horrible hack,
+ * if attr_len is 0, it is a EoR marker */
+ if (attr_len == 0)
+ return (-1);
} else
break;
/* mp attribute */ @@ -884,7 +1012,7 @@ up_dump_attrnlri(u_char *buf, int len, s
buf[--wpos] = (u_char)ATTR_MP_UNREACH_NLRI; if (TAILQ_EMPTY(&upa->prefix_h)) {
@@ -954,7 +965,7 @@ up_dump_mp_unreach(u_char *buf, u_int16_ if (RB_REMOVE(uptree_attr, &peer->up_attrs, upa) == NULL)
/* total length includes the two 2-bytes length fields. */ log_warnx("dequeuing update failed.");
*len = attrlen + 2 * sizeof(u_int16_t); - TAILQ_REMOVE(&peer->updates, upa, attr_l);
+ TAILQ_REMOVE(&peer->updates[AID_INET], upa, attr_l);
- return (buf); free(upa->attr);
+ return (buf + wpos); free(upa->mpattr);
free(upa);
@@ -895,12 +1023,13 @@ up_dump_attrnlri(u_char *buf, int len, s
} }
u_char * u_char *
-up_dump_mp_unreach(u_char *buf, u_int16_t *len, struct rde_peer *peer)
+up_dump_mp_unreach(u_char *buf, u_int16_t *len, struct rde_peer *peer,
+ u_int8_t aid)
{
int wpos;
u_int16_t datalen, tmp;
u_int16_t attrlen = 2; /* attribute header (without len) */
- u_int8_t flags = ATTR_OPTIONAL;
+ u_int8_t flags = ATTR_OPTIONAL, safi;
/*
* reserve space for withdraw len, attr len, the attribute header
@@ -912,7 +1041,7 @@ up_dump_mp_unreach(u_char *buf, u_int16_
return (NULL);
datalen = up_dump_prefix(buf + wpos, *len - wpos,
- &peer->withdraws6, peer);
+ &peer->withdraws[aid], peer);
if (datalen == 0)
return (NULL);
@@ -920,9 +1049,11 @@ up_dump_mp_unreach(u_char *buf, u_int16_
/* prepend header, need to do it reverse */
/* safi & afi */
- buf[--wpos] = SAFI_UNICAST;
+ if (aid2afi(aid, &tmp, &safi))
+ fatalx("up_dump_mp_unreach: bad AID");
+ buf[--wpos] = safi;
wpos -= sizeof(u_int16_t);
- tmp = htons(AFI_IPv6);
+ tmp = htons(tmp);
memcpy(buf + wpos, &tmp, sizeof(u_int16_t));
/* attribute length */
@@ -959,33 +1090,39 @@ up_dump_mp_unreach(u_char *buf, u_int16_
return (buf + wpos);
}
-u_char *
-up_dump_mp_reach(u_char *buf, u_int16_t *len, struct rde_peer *peer)
+int
+up_dump_mp_reach(u_char *buf, u_int16_t *len, struct rde_peer *peer,
+ u_int8_t aid)
{
struct update_attr *upa;
int wpos;
- u_int16_t datalen, tmp;
+ u_int16_t attr_len, datalen, tmp;
u_int8_t flags = ATTR_OPTIONAL;
/*
* It is possible that a queued path attribute has no nlri prefix.
* Ignore and remove those path attributes.
*/
- while ((upa = TAILQ_FIRST(&peer->updates6)) != NULL)
+ while ((upa = TAILQ_FIRST(&peer->updates[aid])) != NULL)
if (TAILQ_EMPTY(&upa->prefix_h)) {
+ attr_len = upa->attr_len;
if (RB_REMOVE(uptree_attr, &peer->up_attrs,
upa) == NULL)
log_warnx("dequeuing update failed.");
- TAILQ_REMOVE(&peer->updates6, upa, attr_l);
+ TAILQ_REMOVE(&peer->updates[aid], upa, attr_l);
free(upa->attr);
free(upa->mpattr);
free(upa);
peer->up_acnt--;
+ /* XXX horrible hack,
+ * if attr_len is 0, it is a EoR marker */
+ if (attr_len == 0)
+ return (-1);
} else
break;
if (upa == NULL)
- return (NULL);
+ return (-2);
/*
* reserve space for attr len, the attributes, the
@@ -993,12 +1130,12 @@ up_dump_mp_reach(u_char *buf, u_int16_t
*/
wpos = 2 + 2 + upa->attr_len + 4 + upa->mpattr_len;
if (*len < wpos)
- return (NULL);
+ return (-2);
datalen = up_dump_prefix(buf + wpos, *len - wpos,
&upa->prefix_h, peer);
if (datalen == 0)
- return (NULL);
+ return (-2);
if (upa->mpattr_len == 0 || upa->mpattr == NULL)
fatalx("mulitprotocol update without MP attrs");
@@ -1038,7 +1175,7 @@ up_dump_mp_reach(u_char *buf, u_int16_t
if (TAILQ_EMPTY(&upa->prefix_h)) {
if (RB_REMOVE(uptree_attr, &peer->up_attrs, upa) == NULL)
log_warnx("dequeuing update failed.");
- TAILQ_REMOVE(&peer->updates6, upa, attr_l);
+ TAILQ_REMOVE(&peer->updates[aid], upa, attr_l);
free(upa->attr);
free(upa->mpattr);
free(upa);
@@ -1046,6 +1183,5 @@ up_dump_mp_reach(u_char *buf, u_int16_t
}
*len = datalen + 4;
- return (buf + wpos);
+ return (wpos);
}
-

File diff suppressed because it is too large Load diff

View file

@ -1,32 +1,43 @@
Index: bgpd/session.h Index: bgpd/session.h
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/session.h,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/session.h,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.7
retrieving revision 1.1.1.3 retrieving revision 1.1.1.8
diff -u -p -r1.1.1.1 -r1.1.1.3 diff -u -p -r1.1.1.7 -r1.1.1.8
--- bgpd/session.h 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/session.h 14 Feb 2010 20:19:57 -0000 1.1.1.7
+++ bgpd/session.h 22 Oct 2009 14:24:02 -0000 1.1.1.3 +++ bgpd/session.h 14 Feb 2010 20:27:06 -0000 1.1.1.8
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: session.h,v 1.98 2008/05/08 09:53:12 henning Exp $ */ -/* $OpenBSD: session.h,v 1.101 2009/06/05 20:26:38 claudio Exp $ */
+/* $OpenBSD: session.h,v 1.101 2009/06/05 20:26:38 claudio Exp $ */ +/* $OpenBSD: session.h,v 1.104 2009/12/31 15:34:02 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -171,6 +171,7 @@ enum Timer { @@ -189,6 +189,7 @@ struct peer {
Timer_Hold, struct {
Timer_IdleHold, struct capabilities ann;
Timer_IdleHoldReset, struct capabilities peer;
+ Timer_CarpUndemote, + struct capabilities neg;
Timer_Max } capa;
struct {
struct bgpd_addr local_addr;
@@ -217,7 +218,7 @@ struct peer {
u_int8_t passive;
}; };
@@ -227,13 +228,15 @@ struct ctl_timer { -struct peer *peers;
+extern struct peer *peers;
struct ctl_timer {
enum Timer type;
@@ -226,16 +227,14 @@ struct ctl_timer {
/* session.c */
void session_socket_blockmode(int, enum blockmodes); void session_socket_blockmode(int, enum blockmodes);
pid_t session_main(struct bgpd_config *, struct peer *, -pid_t session_main(struct bgpd_config *, struct peer *,
struct network_head *, struct filter_head *, - struct network_head *, struct filter_head *,
- struct mrt_head *, int[2], int[2], int[2], int[2]); - struct mrt_head *, struct rib_names *,
+ struct mrt_head *, struct rib_names *, - int[2], int[2], int[2], int[2]);
+ int[2], int[2], int[2], int[2]); +pid_t session_main(int[2], int[2], int[2], int[2], char *, char *);
void bgp_fsm(struct peer *, enum session_events); void bgp_fsm(struct peer *, enum session_events);
int session_neighbor_rrefresh(struct peer *p); int session_neighbor_rrefresh(struct peer *p);
struct peer *getpeerbyaddr(struct bgpd_addr *); struct peer *getpeerbyaddr(struct bgpd_addr *);
@ -37,26 +48,14 @@ diff -u -p -r1.1.1.1 -r1.1.1.3
/* log.c */ /* log.c */
char *log_fmt_peer(const struct peer_config *); char *log_fmt_peer(const struct peer_config *);
@@ -254,8 +257,8 @@ void prepare_listeners(struct bgpd_conf @@ -255,9 +254,7 @@ int merge_config(struct bgpd_config *,
void prepare_listeners(struct bgpd_config *);
/* rde.c */ /* rde.c */
pid_t rde_main(struct bgpd_config *, struct peer *, struct network_head *, -pid_t rde_main(struct bgpd_config *, struct peer *, struct network_head *,
- struct filter_head *, struct mrt_head *, int[2], int[2], int[2], - struct filter_head *, struct mrt_head *, struct rib_names *,
- int[2], int); - int[2], int[2], int[2], int[2], int);
+ struct filter_head *, struct mrt_head *, struct rib_names *, +pid_t rde_main(int[2], int[2], int[2], int[2], int);
+ int[2], int[2], int[2], int[2], int);
/* control.c */ /* control.c */
int control_init(int, char *); int control_init(int, char *);
@@ -270,8 +273,9 @@ int pfkey_remove(struct peer *);
int pfkey_init(struct bgpd_sysdep *);
/* printconf.c */
-void print_config(struct bgpd_config *, struct network_head *, struct peer *,
- struct filter_head *, struct mrt_head *);
+void print_config(struct bgpd_config *, struct rib_names *,
+ struct network_head *, struct peer *, struct filter_head *,
+ struct mrt_head *);
/* carp.c */
int carp_demote_init(char *, int);

View file

@ -1,14 +0,0 @@
Index: bgpd/timer.c
===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/timer.c,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.1 -r1.1.1.2
--- bgpd/timer.c 30 Jun 2009 05:46:15 -0000 1.1.1.1
+++ bgpd/timer.c 9 Jul 2009 16:49:54 -0000 1.1.1.2
@@ -1,4 +1,4 @@
-/* $OpenBSD: timer.c,v 1.12.2.1 2009/02/20 07:20:15 henning Exp $ */
+/* $OpenBSD: timer.c,v 1.13 2009/01/21 20:32:53 henning Exp $ */
/*
* Copyright (c) 2003-2007 Henning Brauer <henning@openbsd.org>

View file

@ -1,14 +1,14 @@
Index: bgpd/util.c Index: bgpd/util.c
=================================================================== ===================================================================
RCS file: /home/cvs/private/hrs/openbgpd/bgpd/util.c,v RCS file: /home/cvs/private/hrs/openbgpd/bgpd/util.c,v
retrieving revision 1.1.1.1 retrieving revision 1.1.1.6
retrieving revision 1.3 retrieving revision 1.4
diff -u -p -r1.1.1.1 -r1.3 diff -u -p -r1.1.1.6 -r1.4
--- bgpd/util.c 30 Jun 2009 05:46:15 -0000 1.1.1.1 --- bgpd/util.c 14 Feb 2010 20:19:57 -0000 1.1.1.6
+++ bgpd/util.c 9 Jul 2009 17:22:14 -0000 1.3 +++ bgpd/util.c 4 Feb 2010 16:22:23 -0000 1.4
@@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.4 2008/03/17 20:40:04 henning Exp $ */ -/* $OpenBSD: util.c,v 1.6 2009/06/12 16:42:53 claudio Exp $ */
+/* $OpenBSD: util.c,v 1.6 2009/06/12 16:42:53 claudio Exp $ */ +/* $OpenBSD: util.c,v 1.10 2010/01/13 06:02:37 claudio Exp $ */
/* /*
* Copyright (c) 2006 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2006 Claudio Jeker <claudio@openbsd.org>
@ -22,42 +22,176 @@ diff -u -p -r1.1.1.1 -r1.3
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netdb.h> #include <netdb.h>
@@ -143,7 +146,7 @@ aspath_snprint(char *buf, size_t size, v @@ -33,10 +36,20 @@ log_addr(const struct bgpd_addr *addr)
UPDATE(); {
} static char buf[48];
}
- /* ensure that we have a valid C-string especially for emtpy as path */
+ /* ensure that we have a valid C-string especially for empty as path */
if (size > 0)
*buf = '\0';
@@ -250,3 +253,29 @@ aspath_extract(const void *seg, int pos) - if (inet_ntop(addr->af, &addr->ba, buf, sizeof(buf)) == NULL)
memcpy(&as, ptr, sizeof(u_int32_t)); - return ("?");
return (ntohl(as)); - else
+ switch (addr->aid) {
+ case AID_INET:
+ case AID_INET6:
+ if (inet_ntop(aid2af(addr->aid), &addr->ba, buf,
+ sizeof(buf)) == NULL)
+ return ("?");
+ return (buf);
+ case AID_VPN_IPv4:
+ if (inet_ntop(AF_INET, &addr->vpn4.addr, buf,
+ sizeof(buf)) == NULL)
+ return ("?");
return (buf);
+ }
+ return ("???");
}
const char *
@@ -90,6 +103,32 @@ log_as(u_int32_t as)
return (buf);
}
+/* XXX this function does not check if the type/subtype combo is
+ * actually valid. */
+const char *
+log_ext_subtype(u_int8_t subtype)
+{
+ static char etype[6];
+
+ switch (subtype) {
+ case EXT_COMMUNITY_ROUTE_TGT:
+ return ("rt"); /* route target */
+ case EXT_CUMMUNITY_ROUTE_ORIG:
+ return ("soo"); /* source of origin */
+ case EXT_COMMUNITY_OSPF_DOM_ID:
+ return ("odi"); /* ospf domain id */
+ case EXT_COMMUNITY_OSPF_RTR_TYPE:
+ return ("ort"); /* ospf route type */
+ case EXT_COMMUNITY_OSPF_RTR_ID:
+ return ("ori"); /* ospf router id */
+ case EXT_COMMUNITY_BGP_COLLECT:
+ return ("bdc"); /* bgp data collection */
+ default:
+ snprintf(etype, sizeof(etype), "[%i]", (int)subtype);
+ return (etype);
+ }
+}
+
int
aspath_snprint(char *buf, size_t size, void *data, u_int16_t len)
{
@@ -276,3 +315,115 @@ inet6applymask(struct in6_addr *dest, co
for (i = 0; i < 16; i++)
dest->s6_addr[i] = src->s6_addr[i] & mask.s6_addr[i];
} }
+ +
+in_addr_t +/* address family translation functions */
+prefixlen2mask(u_int8_t prefixlen) +const struct aid aid_vals[AID_MAX] = AID_VALS;
+{
+ if (prefixlen == 0)
+ return (0);
+ +
+ return (0xffffffff << (32 - prefixlen)); +const char *
+aid2str(u_int8_t aid)
+{
+ if (aid < AID_MAX)
+ return (aid_vals[aid].name);
+ return ("unknown AID");
+}
+
+int
+aid2afi(u_int8_t aid, u_int16_t *afi, u_int8_t *safi)
+{
+ if (aid < AID_MAX) {
+ *afi = aid_vals[aid].afi;
+ *safi = aid_vals[aid].safi;
+ return (0);
+ }
+ return (-1);
+}
+
+int
+afi2aid(u_int16_t afi, u_int8_t safi, u_int8_t *aid)
+{
+ u_int8_t i;
+
+ for (i = 0; i < AID_MAX; i++)
+ if (aid_vals[i].afi == afi && aid_vals[i].safi == safi) {
+ *aid = i;
+ return (0);
+ }
+
+ return (-1);
+}
+
+sa_family_t
+aid2af(u_int8_t aid)
+{
+ if (aid < AID_MAX)
+ return (aid_vals[aid].af);
+ return (AF_UNSPEC);
+}
+
+int
+af2aid(sa_family_t af, u_int8_t safi, u_int8_t *aid)
+{
+ u_int8_t i;
+
+ if (safi == 0) /* default to unicast subclass */
+ safi = SAFI_UNICAST;
+
+ for (i = 0; i < AID_MAX; i++)
+ if (aid_vals[i].af == af && aid_vals[i].safi == safi) {
+ *aid = i;
+ return (0);
+ }
+
+ return (-1);
+}
+
+struct sockaddr *
+addr2sa(struct bgpd_addr *addr, u_int16_t port)
+{
+ static struct sockaddr_storage ss;
+ struct sockaddr_in *sa_in = (struct sockaddr_in *)&ss;
+ struct sockaddr_in6 *sa_in6 = (struct sockaddr_in6 *)&ss;
+
+ if (addr->aid == AID_UNSPEC)
+ return (NULL);
+
+ bzero(&ss, sizeof(ss));
+ switch (addr->aid) {
+ case AID_INET:
+ sa_in->sin_family = AF_INET;
+ sa_in->sin_len = sizeof(struct sockaddr_in);
+ sa_in->sin_addr.s_addr = addr->v4.s_addr;
+ sa_in->sin_port = htons(port);
+ break;
+ case AID_INET6:
+ sa_in6->sin6_family = AF_INET6;
+ sa_in6->sin6_len = sizeof(struct sockaddr_in6);
+ memcpy(&sa_in6->sin6_addr, &addr->v6,
+ sizeof(sa_in6->sin6_addr));
+ sa_in6->sin6_port = htons(port);
+ sa_in6->sin6_scope_id = addr->scope_id;
+ break;
+ }
+
+ return ((struct sockaddr *)&ss);
+} +}
+ +
+void +void
+inet6applymask(struct in6_addr *dest, const struct in6_addr *src, int prefixlen) +sa2addr(struct sockaddr *sa, struct bgpd_addr *addr)
+{ +{
+ struct in6_addr mask; + struct sockaddr_in *sa_in = (struct sockaddr_in *)sa;
+ int i; + struct sockaddr_in6 *sa_in6 = (struct sockaddr_in6 *)sa;
+ +
+ bzero(&mask, sizeof(mask)); + bzero(addr, sizeof(*addr));
+ for (i = 0; i < prefixlen / 8; i++) + switch (sa->sa_family) {
+ mask.s6_addr[i] = 0xff; + case AF_INET:
+ i = prefixlen % 8; + addr->aid = AID_INET;
+ if (i) + memcpy(&addr->v4, &sa_in->sin_addr, sizeof(addr->v4));
+ mask.s6_addr[prefixlen / 8] = 0xff00 >> i; + break;
+ + case AF_INET6:
+ for (i = 0; i < 16; i++) + addr->aid = AID_INET6;
+ dest->s6_addr[i] = src->s6_addr[i] & mask.s6_addr[i]; + memcpy(&addr->v6, &sa_in6->sin6_addr, sizeof(addr->v6));
+ addr->scope_id = sa_in6->sin6_scope_id; /* I hate v6 */
+ break;
+ }
+} +}

View file

@ -3,10 +3,10 @@ Index: openbsd-compat/openbsd-compat.h
RCS file: openbsd-compat/openbsd-compat.h RCS file: openbsd-compat/openbsd-compat.h
diff -N openbsd-compat/openbsd-compat.h diff -N openbsd-compat/openbsd-compat.h
--- /dev/null 1 Jan 1970 00:00:00 -0000 --- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openbsd-compat/openbsd-compat.h 9 Jul 2009 17:22:14 -0000 1.3 +++ openbsd-compat/openbsd-compat.h 4 Feb 2010 16:22:51 -0000 1.4
@@ -0,0 +1,46 @@ @@ -0,0 +1,87 @@
+/* +/*
+ * $hrs: openbgpd/openbsd-compat/openbsd-compat.h,v 1.3 2009/07/09 17:22:14 hrs Exp $ + * $hrs: openbgpd/openbsd-compat/openbsd-compat.h,v 1.4 2010/02/04 16:22:51 hrs Exp $
+ */ + */
+ +
+#ifndef _OPENBSD_COMPAT_H +#ifndef _OPENBSD_COMPAT_H
@ -50,4 +50,45 @@ diff -N openbsd-compat/openbsd-compat.h
+#define RTP_MASK 0x7f +#define RTP_MASK 0x7f
+#define RTP_DOWN 0x80 /* route/link is down */ +#define RTP_DOWN 0x80 /* route/link is down */
+ +
+/* missing LINK_STATE_* macros in net/if.h */
+#define LINK_STATE_INVALID LINK_STATE_UNKNOWN /* link invalid */
+#define LINK_STATE_KALIVE_DOWN 7 /* keepalive reports down */
+#define LINK_STATE_HALF_DUPLEX 5 /* link is up and half duplex */
+#define LINK_STATE_FULL_DUPLEX 6 /* link is up and full duplex */
+
+/*
+ * Status bit descriptions for the various interface types.
+ */
+struct if_status_description {
+ unsigned char ifs_type;
+ unsigned char ifs_state;
+ const char *ifs_string;
+};
+
+#define LINK_STATE_DESC_MATCH(_ifs, _t, _s) \
+ (((_ifs)->ifs_type == (_t) || (_ifs)->ifs_type == 0) && \
+ (_ifs)->ifs_state == (_s))
+
+#define LINK_STATE_DESCRIPTIONS { \
+ { IFT_ETHER, LINK_STATE_DOWN, "no carrier" }, \
+ \
+ { IFT_IEEE80211, LINK_STATE_DOWN, "no network" }, \
+ \
+ { IFT_PPP, LINK_STATE_DOWN, "no carrier" }, \
+ \
+ { IFT_CARP, LINK_STATE_DOWN, "backup" }, \
+ { IFT_CARP, LINK_STATE_UP, "master" }, \
+ { IFT_CARP, LINK_STATE_HALF_DUPLEX, "master" }, \
+ { IFT_CARP, LINK_STATE_FULL_DUPLEX, "master" }, \
+ \
+ { 0, LINK_STATE_UP, "active" }, \
+ { 0, LINK_STATE_HALF_DUPLEX, "active" }, \
+ { 0, LINK_STATE_FULL_DUPLEX, "active" }, \
+ \
+/* { 0, LINK_STATE_UNKNOWN, "unknown" }, */ \
+ { 0, LINK_STATE_INVALID, "invalid" }, \
+ { 0, LINK_STATE_DOWN, "down" }, \
+ { 0, LINK_STATE_KALIVE_DOWN, "keepalive down" }, \
+ { 0, 0, NULL } \
+}
+#endif /* _OPENBSD_COMPAT_H */ +#endif /* _OPENBSD_COMPAT_H */

View file

@ -2,7 +2,4 @@ OpenBGPD is a FREE implementation of the Border Gateway Protocol, Version 4.
It allows ordinary machines to be used as routers exchanging routes with It allows ordinary machines to be used as routers exchanging routes with
other systems speaking the BGP protocol. other systems speaking the BGP protocol.
WWW: http://www.openbgp.org/ WWW: http://www.openbgpd.org/
- Florent Thoumie
flz@xbsd.org

View file

@ -1,4 +1,5 @@
#!/bin/sh #!/bin/sh
# $FreeBSD$
case $2 in case $2 in
POST-INSTALL) POST-INSTALL)