-/* $OpenBSD: parse.y,v 1.445 2023/04/05 08:04:28 claudio Exp $ */
+/* $OpenBSD: parse.y,v 1.446 2023/04/05 08:37:21 claudio Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
#include <unistd.h>
#include <errno.h>
#include <limits.h>
+#include <netdb.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
static struct rtr_config *get_rtr(struct bgpd_addr *);
static int insert_rtr(struct rtr_config *);
static int merge_aspa_set(uint32_t, struct aspa_tas_l *, time_t);
+static int getservice(char *);
static struct bgpd_config *conf;
static struct network_head *netconf;
%type <v.number> yesno inout restricted expires enforce
%type <v.number> validity aspa_validity
%type <v.number> addpathextra addpathmax
+%type <v.number> port
%type <v.string> string
%type <v.addr> address
%type <v.prefix> prefix addrspec
}
currtr->local_addr = $2;
}
- | PORT NUMBER {
- if ($2 < 1 || $2 > USHRT_MAX) {
- yyerror("port must be between %u and %u",
- 1, USHRT_MAX);
- YYERROR;
- }
+ | PORT port {
currtr->remote_port = $2;
}
;
memcpy(&la->sa, sa, la->sa_len);
TAILQ_INSERT_TAIL(conf->listen_addrs, la, entry);
}
- | LISTEN ON address PORT NUMBER {
+ | LISTEN ON address PORT port {
struct listen_addr *la;
struct sockaddr *sa;
- if ($5 < 1 || $5 > USHRT_MAX) {
- yyerror("port must be between %u and %u",
- 1, USHRT_MAX);
- YYERROR;
- }
-
if ((la = calloc(1, sizeof(struct listen_addr))) ==
NULL)
fatal("parse conf_main listen on calloc");
}
;
+port : NUMBER {
+ if ($1 < 1 || $1 > USHRT_MAX) {
+ yyerror("port must be between %u and %u",
+ 1, USHRT_MAX);
+ YYERROR;
+ }
+ $$ = $1;
+ }
+ | STRING {
+ if (($$ = getservice($1)) == -1) {
+ yyerror("unknown port '%s'", $1);
+ free($1);
+ YYERROR;
+ }
+ free($1);
+ }
+ ;
+
inout : IN { $$ = 1; }
| OUT { $$ = 0; }
;
else
curpeer->conf.flags &= ~PEERFLAG_NO_AS_SET;
}
- | PORT NUMBER {
- if ($2 < 1 || $2 > USHRT_MAX) {
- yyerror("port must be between %u and %u",
- 1, USHRT_MAX);
- YYERROR;
- }
+ | PORT port {
curpeer->conf.remote_port = $2;
}
| RDE EVALUATE STRING {
return 0;
}
+
+static int
+getservice(char *n)
+{
+ struct servent *s;
+
+ s = getservbyname(n, "tcp");
+ if (s == NULL)
+ s = getservbyname(n, "udp");
+ if (s == NULL)
+ return -1;
+ return s->s_port;
+}