Hi,
this diff implements the “include” statement, like other daemons.
Also the config file can be split between different files (in my case, a big 
list of client is generated from a script, and I don’t want to modify 
dhcpd.conf).

Although, I am not even sure if this diff is decent and if it’s a good idea.
Have a good day :)


Index: conflex.c
===================================================================
RCS file: /cvs/src/usr.sbin/dhcpd/conflex.c,v
retrieving revision 1.19
diff -u -p -u -p -r1.19 conflex.c
--- conflex.c   24 Apr 2017 14:58:36 -0000      1.19
+++ conflex.c   10 May 2018 23:30:56 -0000
@@ -321,6 +321,7 @@ static const struct keywords {
        { "hardware",                   TOK_HARDWARE },
        { "host",                       TOK_HOST },
        { "hostname",                   TOK_HOSTNAME },
+       { "include",                    TOK_INCLUDE },
        { "ipsec-tunnel",               TOK_IPSEC_TUNNEL },
        { "lease",                      TOK_LEASE },
        { "max-lease-time",             TOK_MAX_LEASE_TIME },
Index: confpars.c
===================================================================
RCS file: /cvs/src/usr.sbin/dhcpd/confpars.c,v
retrieving revision 1.33
diff -u -p -u -p -r1.33 confpars.c
--- confpars.c  24 Apr 2017 14:58:36 -0000      1.33
+++ confpars.c  10 May 2018 23:30:56 -0000
@@ -329,6 +329,23 @@ parse_statement(FILE *cfile, struct grou
                        parse_warn("use-host-decl-names not allowed here.");
                group->use_host_decl_names = parse_boolean(cfile);
                break;
+
+       case TOK_INCLUDE:
+               group->include = parse_string(cfile);
+               if ((cfile = fopen(group->include, "r")) == NULL)
+                       fatal("Can't open %s", group->include);
+               do {
+                       token = peek_token(&val, cfile);
+                       if (token == EOF)
+                               break;
+                       declaration = parse_statement(cfile, &root_group,
+                                                       ROOT_GROUP,
+                                                       NULL,
+                                                       declaration);
+               } while (1);
+               token = next_token(&val, cfile); /* Clear the peek buffer */
+               fclose(cfile);
+               break;

        case TOK_USE_LEASE_ADDR_FOR_DEFAULT_ROUTE:
                group->use_lease_addr_for_default_route =
Index: dhcpd.conf.5
===================================================================
RCS file: /cvs/src/usr.sbin/dhcpd/dhcpd.conf.5,v
retrieving revision 1.23
diff -u -p -u -p -r1.23 dhcpd.conf.5
--- dhcpd.conf.5        1 Mar 2018 20:48:11 -0000       1.23
+++ dhcpd.conf.5        10 May 2018 23:30:56 -0000
@@ -873,6 +873,25 @@ into its response (DHCP ACK or NAK) per
 In other words if the client sends the option it will receive it back.
 By default, this flag is on
 and client identifiers will be echoed back to the client.
+.Pp
+The
+.Ic include
+statement allows additional configuration files to be included:
+.Pp
+.D1 Ic include Qq Ar filename ;
+.Pp
+For example:
+.Bd -literal -offset indent
+include "/etc/dhcpd.conf.hosts";
+include "/etc/dhcpd.conf.office1";
+include "/etc/dhcpd.conf.office2";
+.Ed
+.Pp
+You can split the client declarations into different files.
+It could be use in order to keep
+.Nm
+small and easy to read, and if you want to generate clients declaration
+from an external script.
 .Sh REFERENCE: OPTION STATEMENTS
 DHCP option statements are documented in the
 .Xr dhcp-options 5
Index: dhcpd.h
===================================================================
RCS file: /cvs/src/usr.sbin/dhcpd/dhcpd.h,v
retrieving revision 1.66
diff -u -p -u -p -r1.66 dhcpd.h
--- dhcpd.h     4 Aug 2017 02:01:46 -0000       1.66
+++ dhcpd.h     10 May 2018 23:30:56 -0000
@@ -196,6 +196,7 @@ struct group {
        int allow_booting;
        int get_lease_hostnames;
        int use_host_decl_names;
+       char *include;
        int use_lease_addr_for_default_route;
        int authoritative;
        int always_reply_rfc1048;
Index: dhctoken.h
===================================================================
RCS file: /cvs/src/usr.sbin/dhcpd/dhctoken.h,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 dhctoken.h
--- dhctoken.h  24 Apr 2017 14:58:36 -0000      1.8
+++ dhctoken.h  10 May 2018 23:30:56 -0000
@@ -92,6 +92,7 @@
 #define TOK_ALWAYS_REPLY_RFC1048       335
 #define TOK_IPSEC_TUNNEL               336
 #define TOK_ECHO_CLIENT_ID             337
+#define TOK_INCLUDE                    338

 #define is_identifier(x)       ((x) >= TOK_FIRST_TOKEN &&      \
                                 (x) != TOK_STRING &&   \

Reply via email to