From: Damien Neil Date: Tue, 22 Aug 2000 21:51:39 +0000 (+0000) Subject: Added log() statement to allow logging from config files. X-Git-Tag: V3-BETA-2-PATCH-1~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7a9c2939025133a1cfb250a7547637c1058340f;p=thirdparty%2Fdhcp.git Added log() statement to allow logging from config files. --- diff --git a/common/conflex.c b/common/conflex.c index eeb0b0bd3..0315a133a 100644 --- a/common/conflex.c +++ b/common/conflex.c @@ -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)) { diff --git a/common/dhcp-eval.5 b/common/dhcp-eval.5 index 0e7e26bed..7d33bd675 100644 --- a/common/dhcp-eval.5 +++ b/common/dhcp-eval.5 @@ -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 diff --git a/common/execute.c b/common/execute.c index e1c18c4b2..6daf1c924 100644 --- a/common/execute.c +++ b/common/execute.c @@ -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); } diff --git a/common/parse.c b/common/parse.c index 30f7c6417..aa30e75e1 100644 --- a/common/parse.c +++ b/common/parse.c @@ -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; diff --git a/includes/dhctoken.h b/includes/dhctoken.h index 5330074fb..533535ba0 100644 --- a/includes/dhctoken.h +++ b/includes/dhctoken.h @@ -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 && \ diff --git a/includes/statement.h b/includes/statement.h index 353e21dd0..808980007 100644 --- a/includes/statement.h +++ b/includes/statement.h @@ -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; };