From 1715270e901acc0c8439e0337a5cdf7e37b87b83 Mon Sep 17 00:00:00 2001 From: Peter Hessler Date: Thu, 5 May 2011 10:20:25 +0000 Subject: Allow a user to specify the route priority OK reyk@ claudio@ sthen@ --- usr.sbin/relayd/parse.y | 17 +++++++++++++++-- usr.sbin/relayd/pfe_route.c | 8 +++++--- usr.sbin/relayd/relayd.conf.5 | 10 ++++++++-- usr.sbin/relayd/relayd.h | 3 ++- 4 files changed, 30 insertions(+), 8 deletions(-) (limited to 'usr.sbin/relayd') diff --git a/usr.sbin/relayd/parse.y b/usr.sbin/relayd/parse.y index 0c8ae637fb8..be62a7a17da 100644 --- a/usr.sbin/relayd/parse.y +++ b/usr.sbin/relayd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.152 2011/04/12 12:43:13 reyk Exp $ */ +/* $OpenBSD: parse.y,v 1.153 2011/05/05 10:20:24 phessler Exp $ */ /* * Copyright (c) 2007, 2008 Reyk Floeter @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -145,7 +146,7 @@ typedef struct { %token EXTERNAL FILENAME FILTER FORWARD FROM HASH HEADER HOST ICMP %token INCLUDE INET INET6 INTERFACE INTERVAL IP LABEL LISTEN %token LOADBALANCE LOG LOOKUP MARK MARKED MODE NAT NO DESTINATION -%token NODELAY NOTHING ON PARENT PATH PORT PREFORK PROTO +%token NODELAY NOTHING ON PARENT PATH PORT PREFORK PRIORITY PROTO %token QUERYSTR REAL REDIRECT RELAY REMOVE REQUEST RESPONSE RETRY %token RETURN ROUNDROBIN ROUTE SACK SCRIPT SEND SESSION SOCKET SPLICE %token SSL STICKYADDR STYLE TABLE TAG TCP TIMEOUT TO ROUTER RTLABEL @@ -1622,6 +1623,17 @@ hostflags : RETRY NUMBER { } hst->conf.parentid = $2; } + | PRIORITY NUMBER { + if (hst->conf.priority) { + yyerror("priority already set"); + YYERROR; + } + if ($2 < 0 || $2 > RTP_MAX) { + yyerror("invalid priority value: %d\n", $2); + YYERROR; + } + hst->conf.priority = $2; + } | IP TTL NUMBER { if (hst->conf.ttl) { yyerror("ttl value already set"); @@ -1774,6 +1786,7 @@ lookup(char *s) { "path", PATH }, { "port", PORT }, { "prefork", PREFORK }, + { "priority", PRIORITY }, { "protocol", PROTO }, { "query", QUERYSTR }, { "real", REAL }, diff --git a/usr.sbin/relayd/pfe_route.c b/usr.sbin/relayd/pfe_route.c index 1189b4dee6f..9c084b2bf36 100644 --- a/usr.sbin/relayd/pfe_route.c +++ b/usr.sbin/relayd/pfe_route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfe_route.c,v 1.1 2009/08/13 13:51:21 reyk Exp $ */ +/* $OpenBSD: pfe_route.c,v 1.2 2011/05/05 10:20:24 phessler Exp $ */ /* * Copyright (c) 2009 Reyk Floeter @@ -91,10 +91,11 @@ sync_routes(struct relayd *env, struct router *rt) continue; log_debug("sync_routes: " - "router %s route %s/%d gateway %s %s", + "router %s route %s/%d gateway %s %s priority %d", rt->rt_conf.name, buf, nr->nr_conf.prefixlen, host->conf.name, - HOST_ISUP(host->up) ? "up" : "down"); + HOST_ISUP(host->up) ? "up" : "down", + host->conf.priority); crt.id = nr->nr_conf.id; crt.hostid = host->conf.id; @@ -139,6 +140,7 @@ pfe_route(struct relayd *env, struct ctl_netroute *crt) rm.rm_hdr.rtm_seq = env->sc_rtseq++; rm.rm_hdr.rtm_addrs = RTA_DST | RTA_GATEWAY; rm.rm_hdr.rtm_tableid = nr->nr_router->rt_conf.rtable; + rm.rm_hdr.rtm_priority = host->conf.priority; if (strlen(nr->nr_router->rt_conf.label)) { rm.rm_hdr.rtm_addrs |= RTA_LABEL; diff --git a/usr.sbin/relayd/relayd.conf.5 b/usr.sbin/relayd/relayd.conf.5 index 1f2ae29d828..e6deb0cc144 100644 --- a/usr.sbin/relayd/relayd.conf.5 +++ b/usr.sbin/relayd/relayd.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: relayd.conf.5,v 1.120 2011/04/30 07:52:33 sthen Exp $ +.\" $OpenBSD: relayd.conf.5,v 1.121 2011/05/05 10:20:24 phessler Exp $ .\" .\" Copyright (c) 2006, 2007 Reyk Floeter .\" Copyright (c) 2006, 2007 Pierre-Yves Ritschard @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: April 30 2011 $ +.Dd $Mdocdate: May 5 2011 $ .Dt RELAYD.CONF 5 .Os .Sh NAME @@ -200,6 +200,12 @@ starting with 1; it can be shown with the .Xr relayctl 8 .Ic show summary commands. +.It Ic priority Ar number +Change the route priority used when adding a route. +If not specified, the kernel will set a priority of 8 (RTP_STATIC). +In ordinary use, a fallback route should be added statically with a very +high (e.g. 52) priority. +Unused in all other modes. .It Ic retry Ar number The optional retry option adds a tolerance for failed host checks; the check will be retried for diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h index fcc7b753f44..b5511948632 100644 --- a/usr.sbin/relayd/relayd.h +++ b/usr.sbin/relayd/relayd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: relayd.h,v 1.144 2011/04/24 10:07:43 bluhm Exp $ */ +/* $OpenBSD: relayd.h,v 1.145 2011/05/05 10:20:24 phessler Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard @@ -273,6 +273,7 @@ struct host_config { char name[MAXHOSTNAMELEN]; struct sockaddr_storage ss; int ttl; + int priority; }; struct host { -- cgit v1.2.3