summaryrefslogtreecommitdiff
path: root/usr.sbin/hoststated
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2007-01-08 17:10:24 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2007-01-08 17:10:24 +0000
commita8ceb925622f6defc5bbfc477d8ce1dcde3ad490 (patch)
treeef10dc7ff1c66c991a24c37dab14333708981907 /usr.sbin/hoststated
parentef09dc0c49bab419694a1d6703348fdee0e041ad (diff)
allow to use service names in addition to numerical port numbers in
the configuration file, eg. "real port http". > From Pierre-Yves Ritschard (pyr at spootnik dot org) ok claudio@
Diffstat (limited to 'usr.sbin/hoststated')
-rw-r--r--usr.sbin/hoststated/check_tcp.c6
-rw-r--r--usr.sbin/hoststated/parse.y61
-rw-r--r--usr.sbin/hoststated/pfe_filter.c4
3 files changed, 48 insertions, 23 deletions
diff --git a/usr.sbin/hoststated/check_tcp.c b/usr.sbin/hoststated/check_tcp.c
index 888edb8da31..21cd84ce45d 100644
--- a/usr.sbin/hoststated/check_tcp.c
+++ b/usr.sbin/hoststated/check_tcp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: check_tcp.c,v 1.5 2007/01/08 13:37:26 reyk Exp $ */
+/* $OpenBSD: check_tcp.c,v 1.6 2007/01/08 17:10:23 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -48,11 +48,11 @@ check_tcp(struct ctl_tcp_event *cte)
switch (cte->host->ss.ss_family) {
case AF_INET:
((struct sockaddr_in *)&cte->host->ss)->sin_port =
- htons(cte->table->port);
+ cte->table->port;
break;
case AF_INET6:
((struct sockaddr_in6 *)&cte->host->ss)->sin6_port =
- htons(cte->table->port);
+ cte->table->port;
break;
}
diff --git a/usr.sbin/hoststated/parse.y b/usr.sbin/hoststated/parse.y
index 785a835874c..96f58cde81f 100644
--- a/usr.sbin/hoststated/parse.y
+++ b/usr.sbin/hoststated/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.11 2007/01/08 16:50:04 reyk Exp $ */
+/* $OpenBSD: parse.y,v 1.12 2007/01/08 17:10:23 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -106,7 +106,7 @@ typedef struct {
%token ERROR
%token <v.string> STRING
%type <v.string> interface
-%type <v.number> number
+%type <v.number> number port
%type <v.host> host
%type <v.tv> timeout
@@ -135,6 +135,39 @@ number : STRING {
}
;
+port : PORT STRING {
+ const char *estr;
+ struct servent *servent;
+
+ $$ = strtonum($2, 1, USHRT_MAX, &estr);
+ if (estr) {
+ if (errno == ERANGE) {
+ yyerror("port %s is out of range", $2);
+ free($2);
+ YYERROR;
+ }
+ servent = getservbyname($2, "tcp");
+ if (servent == NULL) {
+ yyerror("port %s is invalid", $2);
+ free($2);
+ YYERROR;
+ }
+ $$ = servent->s_port;
+ } else
+ $$ = htons($$);
+ free($2);
+ }
+ | PORT HTTP {
+ struct servent *servent;
+
+ servent = getservbyname("http", "tcp");
+ if (servent == NULL)
+ $$ = htons(80);
+ else
+ $$ = servent->s_port;
+ }
+ ;
+
varset : STRING '=' STRING {
if (symset($1, $3, 0) == -1)
fatal("cannot store variable");
@@ -262,22 +295,16 @@ serviceoptsl : TABLE STRING {
free($3);
}
}
- | VIRTUAL IP STRING PORT number interface {
- if ($5 < 1 || $5 > USHRT_MAX) {
- yyerror("invalid port number: %d", $5);
- free($3);
- free($6);
- YYERROR;
- }
+ | VIRTUAL IP STRING port interface {
if (host($3, &service->virts,
- SRV_MAX_VIRTS, htons($5), $6) <= 0) {
+ SRV_MAX_VIRTS, $4, $5) <= 0) {
yyerror("invalid virtual ip: %s", $3);
free($3);
- free($6);
+ free($5);
YYERROR;
}
free($3);
- free($6);
+ free($5);
}
| DISABLE { service->flags |= F_DISABLE; }
| STICKYADDR { service->flags |= F_STICKY; }
@@ -401,12 +428,8 @@ tableoptsl : host {
}
free($5);
}
- | REAL PORT number {
- if ($3 < 1 || $3 >= USHRT_MAX) {
- yyerror("invalid port number: %d", $3);
- YYERROR;
- }
- table->port = $3;
+ | REAL port {
+ table->port = $2;
}
| DISABLE { table->flags |= F_DISABLE; }
;
@@ -750,7 +773,9 @@ parse_config(struct hostated *x_conf, const char *filename, int opts)
return (NULL);
}
infile = filename;
+ setservent(1);
yyparse();
+ endservent();
fclose(fin);
/* Free macros and check which have not been used. */
diff --git a/usr.sbin/hoststated/pfe_filter.c b/usr.sbin/hoststated/pfe_filter.c
index dba7980325e..fe56b2a95cb 100644
--- a/usr.sbin/hoststated/pfe_filter.c
+++ b/usr.sbin/hoststated/pfe_filter.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe_filter.c,v 1.5 2007/01/08 13:37:26 reyk Exp $ */
+/* $OpenBSD: pfe_filter.c,v 1.6 2007/01/08 17:10:23 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -310,7 +310,7 @@ sync_ruleset(struct hostated *env, struct service *service, int enable)
if (ioctl(env->pf->dev, DIOCADDADDR, &pio) == -1)
fatal("sync_ruleset: cannot add address to pool");
- rio.rule.rpool.proxy_port[0] = service->table->port;
+ rio.rule.rpool.proxy_port[0] = ntohs(service->table->port);
rio.rule.rpool.port_op = PF_OP_EQ;
rio.rule.rpool.opts = PF_POOL_ROUNDROBIN;
if (service->flags & F_STICKY)