]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Added log() statement to allow logging from config files.
authorDamien Neil <source@isc.org>
Tue, 22 Aug 2000 21:51:39 +0000 (21:51 +0000)
committerDamien Neil <source@isc.org>
Tue, 22 Aug 2000 21:51:39 +0000 (21:51 +0000)
common/conflex.c
common/dhcp-eval.5
common/execute.c
common/parse.c
includes/dhctoken.h
includes/statement.h

index eeb0b0bd314f1c03b91fb23c7fd46cbfc659f570..0315a133a916bd6ed26a336a90b4b1d74bba96c4 100644 (file)
@@ -43,7 +43,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: conflex.c,v 1.77 2000/06/24 06:17:52 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: conflex.c,v 1.78 2000/08/22 21:51:27 neild Exp $ Copyright (c) 1995-2000 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -578,6 +578,8 @@ static enum dhcp_token intern (atom, dfv)
                        return DNS_DELETE;
                if (!strcasecmp (atom + 1, "omain"))
                        return DOMAIN;
+               if (!strcasecmp (atom + 1, "ebug"))
+                       return TOKEN_DEBUG;
                if (!strcasecmp (atom + 1, "eny"))
                        return DENY;
                if (!strcasecmp (atom + 1, "eleted"))
@@ -641,10 +643,14 @@ static enum dhcp_token intern (atom, dfv)
                                return ELSIF;
                        break;
                }
+               if (!strcasecmp (atom + 1, "rror"))
+                       return ERROR;
                if (!strcasecmp (atom + 1, "val"))
                        return EVAL;
                break;
              case 'f':
+               if (!strcasecmp (atom + 1, "atal"))
+                       return FATAL;
                if (!strcasecmp (atom + 1, "ilename"))
                        return FILENAME;
                if (!strcasecmp (atom + 1, "ixed-address"))
@@ -687,6 +693,8 @@ static enum dhcp_token intern (atom, dfv)
                        return INTEGER;
                if (!strcasecmp (atom + 1, "nfinite"))
                        return INFINITE;
+               if (!strcasecmp (atom + 1, "nfo"))
+                       return INFO;
                if (!strcasecmp (atom + 1, "p-address"))
                        return IP_ADDRESS;
                if (!strcasecmp (atom + 1, "nitial-interval"))
@@ -721,6 +729,8 @@ static enum dhcp_token intern (atom, dfv)
                        return LET;
                if (!strcasecmp (atom + 1, "oad"))
                        return LOAD;
+               if (!strcasecmp (atom + 1, "og"))
+                       return LOG;
                break;
              case 'm':
                if (!strncasecmp (atom + 1, "ax", 2)) {
index 0e7e26bed80cf4e0d3ac24667bf34814271af715..7d33bd6756f8bd66149898be91f3991c654e6b96 100644 (file)
@@ -350,6 +350,17 @@ the current time and the time that the lease expires.
 Any number between zero and the maximum representable size may be
 specified as a numeric expression.
 .RE
+.SH REFERENCE: LOGGING
+Logging statements may be used to send information to the standard logging
+channels.  A logging statement includes an optional priority (\fBfatal\fR,
+\fBerror\fR, \fBinfo\fR, or \fBdebug\fR), and a data expression.
+.PP
+.B log (\fIpriority\fB, \fIdata-expr\FB)\fR
+.PP
+Logging statements take only a single data expression argument, so if you
+want to output multiple data values, you will need to use the \fBconcat\fR
+operator to concatenate them.
+.RE
 .SH REFERENCE: DYNAMIC DNS UPDATES
 .PP
 The DHCP client and server have the ability to dynamically update the
index e1c18c4b21be9bc00ec5e54bae469ea40b589faf..6daf1c924d235f192d1cf44d66b3a15ce961308a 100644 (file)
@@ -43,7 +43,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: execute.c,v 1.36 2000/07/27 09:02:32 mellon Exp $ Copyright (c) 1998-2000 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: execute.c,v 1.37 2000/08/22 21:51:29 neild Exp $ Copyright (c) 1998-2000 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -383,6 +383,40 @@ int execute_statements (packet, lease, in_options, out_options, scope,
                                binding_scope_dereference (&ns, MDL);
                        break;
 
+                     case log_statement:
+                       memset (&ds, 0, sizeof ds);
+                       status = (evaluate_data_expression
+                                 (&ds, packet, lease, in_options,
+                                  out_options, scope, r -> data.log.expr));
+                       
+#if defined (DEBUG_EXPRESSIONS)
+                       log_debug ("exec: log");
+#endif
+
+                       if (status) {
+                               switch (r -> data.log.priority) {
+                               case log_priority_fatal:
+                                       log_fatal ("%.*s", (int)ds.len,
+                                                  ds.buffer -> data);
+                                       break;
+                               case log_priority_error:
+                                       log_error ("%.*s", (int)ds.len,
+                                                  ds.buffer -> data);
+                                       break;
+                               case log_priority_debug:
+                                       log_debug ("%.*s", (int)ds.len,
+                                                  ds.buffer -> data);
+                                       break;
+                               case log_priority_info:
+                                       log_info ("%.*s", (int)ds.len,
+                                                 ds.buffer -> data);
+                                       break;
+                               }
+                               data_string_forget (&ds, MDL);
+                       }
+
+                       break;
+
                      default:
                        log_fatal ("bogus statement type %d", r -> op);
                }
index 30f7c641721ff848aac6265571c1c31a9f18a3e2..aa30e75e116dfee663e388163101a56b4f6ad05e 100644 (file)
@@ -43,7 +43,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: parse.c,v 1.78 2000/08/03 20:59:36 neild Exp $ Copyright (c) 1995-2000 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: parse.c,v 1.79 2000/08/22 21:51:30 neild Exp $ Copyright (c) 1995-2000 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -1650,6 +1650,71 @@ int parse_executable_statement (result, cfile, lose, case_context)
                parse_semi (cfile);
                break;
 
+             case LOG:
+                     /** XXXDPN: At work. **/
+               token = next_token (&val, cfile);
+
+               if (!executable_statement_allocate (result, MDL))
+                       log_fatal ("no memory for log statement.");
+               (*result) -> op = log_statement;
+
+               token = next_token (&val, cfile);
+               if (token != LPAREN) {
+                       parse_warn (cfile, "left parenthesis expected.");
+                       skip_to_semi (cfile);
+                       *lose = 1;
+                       return 0;
+               }
+
+               token = peek_token (&val, cfile);
+               i = 1;
+               if (token == FATAL) {
+                       (*result) -> data.log.priority = log_priority_fatal;
+               } else if (token == ERROR) {
+                       (*result) -> data.log.priority = log_priority_error;
+               } else if (token == TOKEN_DEBUG) {
+                       (*result) -> data.log.priority = log_priority_debug;
+               } else if (token == INFO) {
+                       (*result) -> data.log.priority = log_priority_info;
+               } else {
+                       (*result) -> data.log.priority = log_priority_debug;
+                       i = 0;
+               }
+               if (i) {
+                       token = next_token (&val, cfile);
+                       token = next_token (&val, cfile);
+                       if (token != COMMA) {
+                               parse_warn (cfile, "comma expected.");
+                               skip_to_semi (cfile);
+                               *lose = 1;
+                               return 0;
+                       }
+               }
+
+               if (!(parse_data_expression
+                     (&(*result) -> data.log.expr, cfile, lose))) {
+                       skip_to_semi (cfile);
+                       *lose = 1;
+                       return 0;
+               }
+
+               token = next_token (&val, cfile);
+               if (token != RPAREN) {
+                       parse_warn (cfile, "right parenthesis expected.");
+                       skip_to_semi (cfile);
+                       *lose = 1;
+                       return 0;
+               }
+
+               token = next_token (&val, cfile);
+               if (token != SEMI) {
+                       parse_warn (cfile, "semicolon expected.");
+                       skip_to_semi (cfile);
+                       *lose = 1;
+                       return 0;
+               }
+               break;
+                       
                /* Not really a statement, but we parse it here anyway
                   because it's appropriate for all DHCP agents with
                   parsers. */
@@ -1661,6 +1726,7 @@ int parse_executable_statement (result, cfile, lose, case_context)
                zone -> name = parse_host_name (cfile);
                if (!zone -> name) {
                      badzone:
+                       parse_warn (cfile, "expecting hostname.");
                        *lose = 1;
                        skip_to_semi (cfile);
                        dns_zone_dereference (&zone, MDL);
@@ -1693,7 +1759,7 @@ int parse_executable_statement (result, cfile, lose, case_context)
                        return 0;
                }
                return 1;
-                       
+
              default:
                if (config_universe && is_identifier (token)) {
                        option = (struct option *)0;
index 5330074fb148921edc81d3613d2f8e7e12dc55dc..533535ba05c69e0d67c74b1c26e99873f2d01d8a 100644 (file)
@@ -278,7 +278,12 @@ enum dhcp_token {
        TOKEN_RESERVED = 577,
        TOKEN_BOOTP = 578,
        TOKEN_NEXT = 579,
-       OMAPI = 580
+       OMAPI = 580,
+       LOG = 581,
+       FATAL = 582,
+       ERROR = 583,
+       TOKEN_DEBUG = 584,
+       INFO = 585
 };
 
 #define is_identifier(x)       ((x) >= FIRST_TOKEN &&  \
index 353e21dd0ed423188417ce85512186424b19ec09..80898000717cbf10ef43fa1dcf14d2f1f55dbb5b 100644 (file)
@@ -62,7 +62,8 @@ struct executable_statement {
                set_statement,
                unset_statement,
                let_statement,
-               define_statement
+               define_statement,
+               log_statement
        } op;
        union {
                struct {
@@ -94,6 +95,15 @@ struct executable_statement {
                        struct executable_statement *statements;
                } set, let;
                char *unset;
+               struct {
+                       enum {
+                               log_priority_fatal,
+                               log_priority_error,
+                               log_priority_debug,
+                               log_priority_info
+                       } priority;
+                       struct expression *expr;
+               } log;
        } data;
 };