 |
ISC DHCP
4.3.5
A reference DHCPv4 and DHCPv6 implementation
|
|
Go to the documentation of this file.
31 #include <sys/types.h>
35 in_options, out_options, scope, statements,
61 while (r && !(result && *result)) {
65 case statements_statement:
66 #if defined (DEBUG_EXPRESSIONS)
74 #if defined (DEBUG_EXPRESSIONS)
75 log_debug (
"exec: statements returns %d", status);
92 #if defined (DEBUG_EXPRESSIONS)
104 #if defined (DEBUG_EXPRESSIONS)
110 if (r->
data.
on.statements)
116 #if defined (DEBUG_EXPRESSIONS)
122 if (r->
data.
on.statements)
130 case switch_statement:
131 #if defined (DEBUG_EXPRESSIONS)
136 in_options, out_options, scope,
139 #if defined (DEBUG_EXPRESSIONS)
140 log_debug (
"exec: switch: case %lx", (
unsigned long)e);
145 in_options, out_options, scope, e,
157 case default_statement:
164 out_options, scope, r->
data.
ie.expr));
166 #if defined (DEBUG_EXPRESSIONS)
168 ? (rc ?
"true" :
"false")
176 in_options, out_options, scope,
186 #if defined (DEBUG_EXPRESSIONS)
188 (status ?
"succeeded" :
"failed"));
194 case execute_statement: {
195 #ifdef ENABLE_EXECUTE
202 argv =
dmalloc((argc + 2) *
sizeof(*argv),
MDL);
214 log_debug(
"execute_statement argv[0] = %s", argv[0]);
218 memset (&ds, 0,
sizeof(ds));
227 memcpy(argv[i], ds.
data,
230 log_debug(
"execute_statement argv[%d] = %s", i, argv[i]);
234 log_debug(
"execute_statement failed argv[%d]", i);
244 if ((p = fork()) > 0) {
246 waitpid(p, &status, 0);
253 execvp(argv[0], argv);
254 log_error(
"Unable to execute %s: %m", argv[0]);
261 for (i = 0; i <= argc; i++) {
268 log_fatal(
"Impossible case at %s:%d (ENABLE_EXECUTE "
269 "is not defined).",
MDL);
274 case return_statement:
278 out_options, scope, r ->
data.retval,
MDL);
279 #if defined (DEBUG_EXPRESSIONS)
281 (status ?
"succeeded" :
"failed"));
288 #if defined (DEBUG_EXPRESSIONS)
291 :
"<unnamed class>"));
296 case break_statement:
297 #if defined (DEBUG_EXPRESSIONS)
302 case supersede_option_statement:
303 case send_option_statement:
304 #if defined (DEBUG_EXPRESSIONS)
306 (r->
op == supersede_option_statement
307 ?
"supersede" :
"send"),
310 goto option_statement;
312 case default_option_statement:
313 #if defined (DEBUG_EXPRESSIONS)
317 goto option_statement;
319 case append_option_statement:
320 #if defined (DEBUG_EXPRESSIONS)
324 goto option_statement;
326 case prepend_option_statement:
327 #if defined (DEBUG_EXPRESSIONS)
338 case define_statement:
347 log_error(
"set %s: can't allocate scope",
353 #if defined (DEBUG_EXPRESSIONS)
380 if (r->
op == set_statement) {
384 in_options, out_options,
404 #if defined (DEBUG_EXPRESSIONS)
406 (
binding && status ?
"" :
" (failed)"));
412 case unset_statement:
413 if (!scope || !*scope)
423 #if defined (DEBUG_EXPRESSIONS)
425 (status ?
"found" :
"not found"));
432 #if defined (DEBUG_EXPRESSIONS)
450 (e->data.let.name + 1),
468 in_options, out_options,
469 scope, e->data.set.expr,
MDL));
474 #if defined (DEBUG_EXPRESSIONS)
475 log_debug(
"exec: let %s%s", e->data.let.name,
476 (
binding && status ?
"" :
"failed"));
480 if (!e->data.let.statements) {
481 }
else if (e->data.let.statements->op ==
483 e = e->data.let.statements;
491 in_options, out_options,
492 &ns, e->data.let.statements,
on_star);
499 memset (&ds, 0,
sizeof ds);
505 #if defined (DEBUG_EXPRESSIONS)
510 switch (r->
data.
log.priority) {
511 case log_priority_fatal:
515 case log_priority_error:
519 case log_priority_debug:
523 case log_priority_info:
533 case vendor_opt_statement:
538 in_options, out_options, scope);
573 struct group *limiting_group;
605 for (limit = limiting_group; limit; limit = limit ->
next) {
613 in_options, out_options, scope,
629 #if defined (POINTER_DEBUG)
638 if ((*ptr) ->
refcnt > 0) {
643 if ((*ptr) ->
refcnt < 0) {
645 #if defined (DEBUG_RC_HISTORY)
646 dump_rc_history (*ptr);
648 #if defined (POINTER_DEBUG)
658 switch ((*ptr) ->
op) {
660 if ((*ptr) ->
data.statements)
666 if ((*ptr) ->
data.on.statements)
672 if ((*ptr) ->
data.s_switch.statements)
675 if ((*ptr) ->
data.s_switch.expr)
681 if ((*ptr) ->
data.s_switch.expr)
687 if ((*ptr) ->
data.ie.expr)
690 if ((*ptr) ->
data.ie.tc)
693 if ((*ptr) ->
data.ie.fc)
699 if ((*ptr) ->
data.eval)
705 if ((*ptr) ->
data.eval)
711 if ((*ptr)->data.set.name)
713 if ((*ptr)->data.set.expr)
719 if ((*ptr)->data.unset)
724 if ((*ptr)->data.execute.command)
726 if ((*ptr)->data.execute.arglist)
736 if ((*ptr) ->
data.option)
756 #if defined ENABLE_EXECUTE
760 const char *s, *t, *dot;
774 fprintf (
file,
"on ");
777 fprintf (
file,
"%sexpiry", s);
781 fprintf (
file,
"%scommit", s);
785 fprintf (
file,
"%srelease", s);
788 if (r ->
data.on.statements) {
789 fprintf (
file,
" {");
791 r ->
data.on.statements,
802 fprintf (
file,
"switch (");
804 r ->
data.s_switch.expr,
809 col,
indent,
" ",
"",
"{");
818 fprintf (
file,
"case ");
820 r ->
data.s_switch.expr,
828 fprintf (
file,
"default: ");
833 fprintf (
file,
"if ");
841 if (x ->
data.ie.fc &&
845 fprintf (
file,
"} elsif ");
853 if (x ->
data.ie.fc) {
855 fprintf (
file,
"} else {");
865 fprintf (
file,
"eval ");
873 fprintf (
file,
"return;");
883 fprintf (
file,
"break;");
889 goto option_statement;
893 goto option_statement;
897 goto option_statement;
917 fprintf (
file,
"%s %s%s%s = ", s, t, dot,
919 col = (
indent + strlen (s) + strlen (t) +
920 strlen (dot) + strlen (r ->
data.option ->
937 fprintf (
file,
"set ");
939 "",
"", r ->
data.set.name);
950 fprintf (
file,
"unset ");
952 "",
"", r ->
data.set.name);
959 fprintf (
file,
"log ");
962 switch (r ->
data.log.priority) {
993 #ifdef ENABLE_EXECUTE
1012 log_fatal(
"Impossible case at %s:%d (ENABLE_EXECUTE "
1013 "is not defined).",
MDL);
1019 fprintf (
file,
"parse-vendor-option;");
1048 memset (&ds, 0,
sizeof ds);
1049 memset (&cd, 0,
sizeof cd);
1053 out_options, scope, expr,
1056 for (s = stmt; s; s = s -> next) {
1057 if (s -> op == case_statement) {
1060 in_options, out_options,
1062 if (sub && cd.
len == ds.
len &&
1080 in_options, out_options,
1084 for (s = stmt; s; s = s->
next) {
1085 if (s -> op == case_statement) {
1088 in_options, out_options,
1090 if (sub && n == c) {
1102 for (s = stmt; s; s = s->
next)
1103 if (s->
op == default_statement)
1113 int (*callback) (
struct
1116 void *vp,
int condp)
1121 for (foo = stmt; foo; foo = foo->
next) {
1122 if ((*callback) (foo, vp, condp) != 0)
1158 (foo->
data.
on.statements, callback, vp, 1)))
1176 (foo->
data.
let.statements, callback, vp, 0)))
struct option_cache * option
struct executable_statement::@7::@9 on
int token_print_indent_concat(FILE *file, int col, int indent, const char *prefix, const char *suffix,...)
void log_fatal(const char *,...) __attribute__((__format__(__printf__
int executable_statement_reference(struct executable_statement **ptr, struct executable_statement *bp, const char *file, int line)
struct executable_statement * on_expiry
int option_cache_dereference(struct option_cache **ptr, const char *file, int line)
int fundef_reference(struct fundef **ptr, struct fundef *src, const char *file, int line)
int binding_scope_dereference(struct binding_scope **ptr, const char *file, int line)
void indent_spaces(FILE *file, int indent)
int executable_statement_dereference(struct executable_statement **ptr, const char *file, int line)
struct executable_statement * on_commit
void parse_vendor_option(struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *out_options, struct binding_scope **scope)
Parse a vendor option (option 43)
struct executable_statement::@7::@11 set
union executable_statement::@7 data
void expression_dereference(struct expression **eptr, const char *file, int line)
void data_string_forget(struct data_string *data, const char *file, int line)
int execute_statements(struct binding_value **result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *out_options, struct binding_scope **scope, struct executable_statement *statements, struct on_star *on_star)
struct binding_value * value
const unsigned char * data
struct executable_statement::@7::@8 ie
struct executable_statement * statements
struct binding * bindings
@ default_option_statement
struct expression * c_case
@ append_option_statement
int binding_value_dereference(struct binding_value **v, const char *file, int line)
int evaluate_data_expression(struct data_string *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct expression *expr, const char *file, int line)
@ prepend_option_statement
void execute_statements_in_scope(struct binding_value **result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *out_options, struct binding_scope **scope, struct group *group, struct group *limiting_group, struct on_star *on_star)
int find_matching_case(struct executable_statement **ep, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *out_options, struct binding_scope **scope, struct expression *expr, struct executable_statement *stmt)
int binding_value_allocate(struct binding_value **cptr, const char *file, int line)
int evaluate_expression(struct binding_value **result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct expression *expr, const char *file, int line)
int evaluate_boolean_expression(int *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct expression *expr)
void write_statements(FILE *file, struct executable_statement *statements, int indent)
int int log_info(const char *,...) __attribute__((__format__(__printf__
int write_expression(FILE *file, struct expression *expr, int col, int indent, int firstp)
void dfree(void *, const char *, int)
int evaluate_numeric_expression(unsigned long *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct expression *expr)
int binding_scope_allocate(struct binding_scope **ptr, const char *file, int line)
enum executable_statement::statement_op op
#define rc_register(file, line, reference, addr, refcnt, d, f)
int log_error(const char *,...) __attribute__((__format__(__printf__
int is_data_expression(struct expression *expr)
int token_indent_data_string(FILE *file, int col, int indent, const char *prefix, const char *suffix, struct data_string *data)
int binding_scope_reference(struct binding_scope **ptr, struct binding_scope *bp, const char *file, int line)
struct expression::expr_union::@25 arg
struct binding_scope * outer
struct executable_statement::@7::@11 let
struct executable_statement::@7::@13 execute
struct executable_statement::@7::@10 s_switch
struct executable_statement * statements
struct binding * find_binding(struct binding_scope *scope, const char *name)
union expression::expr_union data
struct executable_statement::@7::@12 log
int executable_statement_foreach(struct executable_statement *stmt, int(*callback)(struct executable_statement *, void *, int), void *vp, int condp)
void * dmalloc(size_t, const char *, int)
int token_print_indent(FILE *file, int col, int indent, const char *prefix, const char *suffix, const char *buf)
struct executable_statement * on_release
int int int log_debug(const char *,...) __attribute__((__format__(__printf__
struct executable_statement * next
@ supersede_option_statement
union binding_value::value value
void classify(struct packet *packet, struct class *class)
struct universe dhcp_universe
enum binding_value::@15 type
void set_option(struct universe *universe, struct option_state *options, struct option_cache *option, enum statement_op op)
struct universe * universe