diff options
-rw-r--r-- | usr.sbin/bgpd/bgpd.conf.5 | 19 | ||||
-rw-r--r-- | usr.sbin/bgpd/bgpd.h | 4 | ||||
-rw-r--r-- | usr.sbin/bgpd/parse.y | 33 | ||||
-rw-r--r-- | usr.sbin/bgpd/printconf.c | 8 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde.h | 3 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_decide.c | 20 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_filter.c | 20 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_rib.c | 8 |
8 files changed, 101 insertions, 14 deletions
diff --git a/usr.sbin/bgpd/bgpd.conf.5 b/usr.sbin/bgpd/bgpd.conf.5 index 0db4f1bdafa..eb3ab76300a 100644 --- a/usr.sbin/bgpd/bgpd.conf.5 +++ b/usr.sbin/bgpd/bgpd.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: bgpd.conf.5,v 1.47 2005/04/12 14:22:46 claudio Exp $ +.\" $OpenBSD: bgpd.conf.5,v 1.48 2005/04/12 14:32:00 claudio Exp $ .\" .\" Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org> .\" Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -892,6 +892,23 @@ Prepend the local AS .Ar number times to the .Em AS path . +.Pp +.It Ic weight Ar number +The +.Em weight +is used to tip prefixes with equal long AS pathes in one or +the other direction. +It weights a prefix at a very late stage in the decision process. +If +.Ar number +starts with a plus or minus sign, the +.Em weight +will be adjusted by adding or subtracting +.Ar number ; +otherwise it will be set to +.Ar number . +.Em Weight +is a local non-transitive attribute and a bgpd specific extension. .El .Sh FILES .Bl -tag -width "/etc/bgpd.conf" -compact diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index a1fd5298bc4..909f7fe5c0b 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.162 2005/03/28 15:16:46 henning Exp $ */ +/* $OpenBSD: bgpd.h,v 1.163 2005/04/12 14:32:00 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -544,6 +544,8 @@ enum action_types { ACTION_SET_RELATIVE_LOCALPREF, ACTION_SET_MED, ACTION_SET_RELATIVE_MED, + ACTION_SET_WEIGHT, + ACTION_SET_RELATIVE_WEIGHT, ACTION_SET_PREPEND_SELF, ACTION_SET_PREPEND_PEER, ACTION_SET_NEXTHOP, diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y index 0eddbd03158..a2d47a30084 100644 --- a/usr.sbin/bgpd/parse.y +++ b/usr.sbin/bgpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.157 2005/04/12 14:26:58 claudio Exp $ */ +/* $OpenBSD: parse.y,v 1.158 2005/04/12 14:32:00 claudio Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -152,7 +152,7 @@ typedef struct { %token FROM TO ANY %token PREFIX PREFIXLEN SOURCEAS TRANSITAS COMMUNITY %token SET LOCALPREF MED METRIC NEXTHOP REJECT BLACKHOLE NOMODIFY -%token PREPEND_SELF PREPEND_PEER PFTABLE +%token PREPEND_SELF PREPEND_PEER PFTABLE WEIGHT %token ERROR %token IPSEC ESP AH SPI IKE %token <v.string> STRING @@ -1206,6 +1206,32 @@ filter_set_opt : LOCALPREF number { $$->type = ACTION_SET_RELATIVE_MED; $$->action.relative = -$3; } + | WEIGHT number { + if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) + fatal(NULL); + $$->type = ACTION_SET_WEIGHT; + $$->action.metric = $2; + } + | WEIGHT '+' number { + if ($3 > INT_MAX) { + yyerror("weight to big: max %u", INT_MAX); + YYERROR; + } + if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) + fatal(NULL); + $$->type = ACTION_SET_RELATIVE_WEIGHT; + $$->action.metric = $3; + } + | WEIGHT '-' number { + if ($3 > INT_MAX) { + yyerror("weight to small: min -%u", INT_MAX); + YYERROR; + } + if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) + fatal(NULL); + $$->type = ACTION_SET_RELATIVE_WEIGHT; + $$->action.relative = -$3; + } | NEXTHOP address { if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); @@ -1417,7 +1443,8 @@ lookup(char *s) { "tcp", TCP}, { "to", TO}, { "transit-as", TRANSITAS}, - { "transparent-as", TRANSPARENT} + { "transparent-as", TRANSPARENT}, + { "weight", WEIGHT} }; const struct keywords *p; diff --git a/usr.sbin/bgpd/printconf.c b/usr.sbin/bgpd/printconf.c index a5b90a16273..2464a9faa54 100644 --- a/usr.sbin/bgpd/printconf.c +++ b/usr.sbin/bgpd/printconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printconf.c,v 1.38 2005/04/07 23:45:21 henning Exp $ */ +/* $OpenBSD: printconf.c,v 1.39 2005/04/12 14:32:00 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -95,6 +95,12 @@ print_set(struct filter_set_head *set) case ACTION_SET_RELATIVE_MED: printf("metric %+d ", s->action.relative); break; + case ACTION_SET_WEIGHT: + printf("weight %u ", s->action.metric); + break; + case ACTION_SET_RELATIVE_WEIGHT: + printf("weight %+d ", s->action.relative); + break; case ACTION_SET_NEXTHOP: printf("nexthop %s ", log_addr(&s->action.nexthop)); break; diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h index c61a6523c7b..dc09c897489 100644 --- a/usr.sbin/bgpd/rde.h +++ b/usr.sbin/bgpd/rde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.h,v 1.63 2005/03/11 12:54:20 claudio Exp $ */ +/* $OpenBSD: rde.h,v 1.64 2005/04/12 14:32:00 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and @@ -161,6 +161,7 @@ struct rde_aspath { char pftable[PFTABLE_LEN]; u_int32_t med; /* multi exit disc */ u_int32_t lpref; /* local pref */ + u_int32_t weight; /* low prio lpref */ u_int16_t flags; /* internally used */ u_int16_t prefix_cnt; /* # of prefixes */ u_int16_t active_cnt; /* # of active prefixes */ diff --git a/usr.sbin/bgpd/rde_decide.c b/usr.sbin/bgpd/rde_decide.c index 6f3a7116df0..98117ae4ae0 100644 --- a/usr.sbin/bgpd/rde_decide.c +++ b/usr.sbin/bgpd/rde_decide.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_decide.c,v 1.40 2004/11/11 10:35:15 claudio Exp $ */ +/* $OpenBSD: rde_decide.c,v 1.41 2005/04/12 14:32:01 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> @@ -154,21 +154,31 @@ prefix_cmp(struct prefix *p1, struct prefix *p2) return -1; } - /* 7. nexthop costs. NOT YET -> IGNORE */ + /* + * 7. local tie-breaker, this weight is here to tip equal long AS + * pathes in one or the other direction. It happens more and more + * that AS pathes are equally long and so traffic engineering needs + * a metric that weights a prefix at a very late stage in the + * decision process. + */ + if ((asp1->weight - asp2->weight) != 0) + return (asp1->weight - asp2->weight); + + /* 8. nexthop costs. NOT YET -> IGNORE */ /* - * 8. older route (more stable) wins but only if route-age + * 9. older route (more stable) wins but only if route-age * evaluation is enabled. */ if (rde_decisionflags() & BGPD_FLAG_DECISION_ROUTEAGE) if ((p2->lastchange - p1->lastchange) != 0) return (p2->lastchange - p1->lastchange); - /* 9. lowest BGP Id wins */ + /* 10. lowest BGP Id wins */ if ((p2->peer->remote_bgpid - p1->peer->remote_bgpid) != 0) return (p2->peer->remote_bgpid - p1->peer->remote_bgpid); - /* 10. lowest peer address wins (IPv4 is better than IPv6) */ + /* 11. lowest peer address wins (IPv4 is better than IPv6) */ if (memcmp(&p1->peer->remote_addr, &p2->peer->remote_addr, sizeof(p1->peer->remote_addr)) != 0) return (-memcmp(&p1->peer->remote_addr, &p2->peer->remote_addr, diff --git a/usr.sbin/bgpd/rde_filter.c b/usr.sbin/bgpd/rde_filter.c index 65b48ff379d..756afc2afdd 100644 --- a/usr.sbin/bgpd/rde_filter.c +++ b/usr.sbin/bgpd/rde_filter.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_filter.c,v 1.26 2005/03/14 17:32:04 claudio Exp $ */ +/* $OpenBSD: rde_filter.c,v 1.27 2005/04/12 14:32:01 claudio Exp $ */ /* * Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org> @@ -131,6 +131,24 @@ rde_apply_set(struct rde_aspath *asp, struct filter_set_head *sh, asp->med += set->action.relative; } break; + case ACTION_SET_WEIGHT: + asp->weight = set->action.metric; + break; + case ACTION_SET_RELATIVE_WEIGHT: + if (set->action.relative > 0) { + if (set->action.relative + asp->weight < + asp->weight) + asp->weight = UINT_MAX; + else + asp->weight += set->action.relative; + } else { + if ((u_int32_t)-set->action.relative > + asp->weight) + asp->weight = 0; + else + asp->weight += set->action.relative; + } + break; case ACTION_SET_PREPEND_SELF: /* don't apply if this is a incoming default override */ if (dir == DIR_DEFAULT_IN) diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c index b45f4e4aa5e..6a47462580e 100644 --- a/usr.sbin/bgpd/rde_rib.c +++ b/usr.sbin/bgpd/rde_rib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_rib.c,v 1.65 2005/03/26 12:46:52 claudio Exp $ */ +/* $OpenBSD: rde_rib.c,v 1.66 2005/04/12 14:32:01 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> @@ -128,6 +128,10 @@ path_compare(struct rde_aspath *a, struct rde_aspath *b) return (1); if (a->lpref < b->lpref) return (-1); + if (a->weight > b->weight) + return (1); + if (a->weight < b->weight) + return (-1); r = strcmp(a->pftable, b->pftable); if (r == 0) @@ -266,6 +270,7 @@ path_copy(struct rde_aspath *asp) nasp->nexthop = asp->nexthop; nasp->med = asp->med; nasp->lpref = asp->lpref; + nasp->weight = asp->weight; nasp->origin = asp->origin; nasp->flags = asp->flags & ~F_ATTR_LINKED; @@ -290,6 +295,7 @@ path_get(void) asp->origin = ORIGIN_INCOMPLETE; asp->lpref = DEFAULT_LPREF; /* med = 0 */ + /* weight = 0 */ return (asp); } |