relayd: improve config validation with -n
authortb <tb@openbsd.org>
Sat, 10 Aug 2024 05:47:29 +0000 (05:47 +0000)
committertb <tb@openbsd.org>
Sat, 10 Aug 2024 05:47:29 +0000 (05:47 +0000)
pf's rule names are limited by 32 characters, so lower the length bounds
for redirect names and tags that relayd accepts as valid config but would
later fail to load into pf. Also display the offending name on error.

from Mark Johnston
ok florian

usr.sbin/relayd/parse.y
usr.sbin/relayd/relayd.h

index 739ff16..eea485c 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: parse.y,v 1.256 2024/06/17 08:02:57 sashan Exp $      */
+/*     $OpenBSD: parse.y,v 1.257 2024/08/10 05:47:29 tb Exp $  */
 
 /*
  * Copyright (c) 2007 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -490,7 +490,7 @@ rdr         : REDIRECT STRING       {
                        if (strlcpy(srv->conf.name, $2,
                            sizeof(srv->conf.name)) >=
                            sizeof(srv->conf.name)) {
-                               yyerror("redirection name truncated");
+                               yyerror("redirection name truncated: %s", $2);
                                free($2);
                                free(srv);
                                YYERROR;
@@ -628,7 +628,8 @@ rdroptsl    : forwardmode TO tablespec interface    {
                        if (strlcpy(rdr->conf.tag, $3,
                            sizeof(rdr->conf.tag)) >=
                            sizeof(rdr->conf.tag)) {
-                               yyerror("redirection tag name truncated");
+                               yyerror("redirection tag name truncated: %s",
+                                   $3);
                                free($3);
                                YYERROR;
                        }
index 2f55c2b..ce8cabd 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: relayd.h,v 1.273 2024/06/17 08:02:57 sashan Exp $     */
+/*     $OpenBSD: relayd.h,v 1.274 2024/08/10 05:47:29 tb Exp $ */
 
 /*
  * Copyright (c) 2006 - 2016 Reyk Floeter <reyk@openbsd.org>
@@ -57,9 +57,7 @@
 #define LABEL_NAME_SIZE                1024
 #define TAG_NAME_SIZE          64
 #define TABLE_NAME_SIZE                64
-#define        RD_TAG_NAME_SIZE        64
 #define        RT_LABEL_SIZE           32
-#define SRV_NAME_SIZE          64
 #define MAX_NAME_SIZE          64
 #define SRV_MAX_VIRTS          16
 #define TLS_NAME_SIZE          512
@@ -545,8 +543,8 @@ struct rdr_config {
        objid_t                  backup_id;
        int                      mode;
        union hashkey            key;
-       char                     name[SRV_NAME_SIZE];
-       char                     tag[RD_TAG_NAME_SIZE];
+       char                     name[PF_TABLE_NAME_SIZE];
+       char                     tag[PF_TAG_NAME_SIZE];
        struct timeval           timeout;
 };