mirror of
https://gitlab.isc.org/isc-projects/dhcp
synced 2025-09-04 00:05:30 +00:00
Pass client state to eval functions.
This commit is contained in:
@@ -43,17 +43,18 @@
|
|||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char copyright[] =
|
static char copyright[] =
|
||||||
"$Id: execute.c,v 1.40 2000/10/10 23:22:39 mellon Exp $ Copyright (c) 1998-2000 The Internet Software Consortium. All rights reserved.\n";
|
"$Id: execute.c,v 1.41 2000/11/28 22:50:38 mellon Exp $ Copyright (c) 1998-2000 The Internet Software Consortium. All rights reserved.\n";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include "dhcpd.h"
|
#include "dhcpd.h"
|
||||||
#include <omapip/omapip_p.h>
|
#include <omapip/omapip_p.h>
|
||||||
|
|
||||||
int execute_statements (result, packet, lease, in_options, out_options, scope,
|
int execute_statements (result, packet, lease, client_state,
|
||||||
statements)
|
in_options, out_options, scope, statements)
|
||||||
struct binding_value **result;
|
struct binding_value **result;
|
||||||
struct packet *packet;
|
struct packet *packet;
|
||||||
struct lease *lease;
|
struct lease *lease;
|
||||||
|
struct client_state *client_state;
|
||||||
struct option_state *in_options;
|
struct option_state *in_options;
|
||||||
struct option_state *out_options;
|
struct option_state *out_options;
|
||||||
struct binding_scope **scope;
|
struct binding_scope **scope;
|
||||||
@@ -84,8 +85,8 @@ int execute_statements (result, packet, lease, in_options, out_options, scope,
|
|||||||
log_debug ("exec: statements");
|
log_debug ("exec: statements");
|
||||||
#endif
|
#endif
|
||||||
status = execute_statements (result, packet, lease,
|
status = execute_statements (result, packet, lease,
|
||||||
in_options, out_options,
|
client_state, in_options,
|
||||||
scope,
|
out_options, scope,
|
||||||
r -> data.statements);
|
r -> data.statements);
|
||||||
#if defined (DEBUG_EXPRESSIONS)
|
#if defined (DEBUG_EXPRESSIONS)
|
||||||
log_debug ("exec: statements returns %d", status);
|
log_debug ("exec: statements returns %d", status);
|
||||||
@@ -140,7 +141,7 @@ int execute_statements (result, packet, lease, in_options, out_options, scope,
|
|||||||
log_debug ("exec: switch");
|
log_debug ("exec: switch");
|
||||||
#endif
|
#endif
|
||||||
status = (find_matching_case
|
status = (find_matching_case
|
||||||
(&e, packet, lease,
|
(&e, packet, lease, client_state,
|
||||||
in_options, out_options, scope,
|
in_options, out_options, scope,
|
||||||
r -> data.s_switch.expr,
|
r -> data.s_switch.expr,
|
||||||
r -> data.s_switch.statements));
|
r -> data.s_switch.statements));
|
||||||
@@ -149,7 +150,7 @@ int execute_statements (result, packet, lease, in_options, out_options, scope,
|
|||||||
#endif
|
#endif
|
||||||
if (status) {
|
if (status) {
|
||||||
if (!(execute_statements
|
if (!(execute_statements
|
||||||
(result, packet, lease,
|
(result, packet, lease, client_state,
|
||||||
in_options, out_options, scope, e))) {
|
in_options, out_options, scope, e))) {
|
||||||
executable_statement_dereference
|
executable_statement_dereference
|
||||||
(&e, MDL);
|
(&e, MDL);
|
||||||
@@ -166,7 +167,8 @@ int execute_statements (result, packet, lease, in_options, out_options, scope,
|
|||||||
|
|
||||||
case if_statement:
|
case if_statement:
|
||||||
status = (evaluate_boolean_expression
|
status = (evaluate_boolean_expression
|
||||||
(&rc, packet, lease, in_options,
|
(&rc, packet,
|
||||||
|
lease, client_state, in_options,
|
||||||
out_options, scope, r -> data.ie.expr));
|
out_options, scope, r -> data.ie.expr));
|
||||||
|
|
||||||
#if defined (DEBUG_EXPRESSIONS)
|
#if defined (DEBUG_EXPRESSIONS)
|
||||||
@@ -178,7 +180,7 @@ int execute_statements (result, packet, lease, in_options, out_options, scope,
|
|||||||
if (!status)
|
if (!status)
|
||||||
rc = 0;
|
rc = 0;
|
||||||
if (!execute_statements
|
if (!execute_statements
|
||||||
(result, packet, lease,
|
(result, packet, lease, client_state,
|
||||||
in_options, out_options, scope,
|
in_options, out_options, scope,
|
||||||
rc ? r -> data.ie.true : r -> data.ie.false))
|
rc ? r -> data.ie.true : r -> data.ie.false))
|
||||||
return 0;
|
return 0;
|
||||||
@@ -187,7 +189,7 @@ int execute_statements (result, packet, lease, in_options, out_options, scope,
|
|||||||
case eval_statement:
|
case eval_statement:
|
||||||
status = evaluate_expression
|
status = evaluate_expression
|
||||||
((struct binding_value **)0,
|
((struct binding_value **)0,
|
||||||
packet, lease, in_options,
|
packet, lease, client_state, in_options,
|
||||||
out_options, scope, r -> data.eval);
|
out_options, scope, r -> data.eval);
|
||||||
#if defined (DEBUG_EXPRESSIONS)
|
#if defined (DEBUG_EXPRESSIONS)
|
||||||
log_debug ("exec: evaluate: %s",
|
log_debug ("exec: evaluate: %s",
|
||||||
@@ -197,7 +199,8 @@ int execute_statements (result, packet, lease, in_options, out_options, scope,
|
|||||||
|
|
||||||
case return_statement:
|
case return_statement:
|
||||||
status = evaluate_expression
|
status = evaluate_expression
|
||||||
(result, packet, lease, in_options,
|
(result, packet,
|
||||||
|
lease, client_state, in_options,
|
||||||
out_options, scope, r -> data.retval);
|
out_options, scope, r -> data.retval);
|
||||||
#if defined (DEBUG_EXPRESSIONS)
|
#if defined (DEBUG_EXPRESSIONS)
|
||||||
log_debug ("exec: return: %s",
|
log_debug ("exec: return: %s",
|
||||||
@@ -299,9 +302,9 @@ int execute_statements (result, packet, lease, in_options, out_options, scope,
|
|||||||
if (r -> op == set_statement) {
|
if (r -> op == set_statement) {
|
||||||
status = (evaluate_expression
|
status = (evaluate_expression
|
||||||
(&binding -> value, packet,
|
(&binding -> value, packet,
|
||||||
lease, in_options,
|
lease, client_state,
|
||||||
out_options, scope,
|
in_options, out_options,
|
||||||
r -> data.set.expr));
|
scope, r -> data.set.expr));
|
||||||
} else {
|
} else {
|
||||||
if (!(binding_value_allocate
|
if (!(binding_value_allocate
|
||||||
(&binding -> value, MDL))) {
|
(&binding -> value, MDL))) {
|
||||||
@@ -330,9 +333,6 @@ int execute_statements (result, packet, lease, in_options, out_options, scope,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
binding = find_binding (*scope, r -> data.unset);
|
binding = find_binding (*scope, r -> data.unset);
|
||||||
#if defined (DEBUG_EXPRESSIONS)
|
|
||||||
log_debug ("exec: unset %s", r -> data.unset);
|
|
||||||
#endif
|
|
||||||
if (binding) {
|
if (binding) {
|
||||||
if (binding -> value)
|
if (binding -> value)
|
||||||
binding_value_dereference
|
binding_value_dereference
|
||||||
@@ -379,6 +379,7 @@ int execute_statements (result, packet, lease, in_options, out_options, scope,
|
|||||||
if (ns && binding) {
|
if (ns && binding) {
|
||||||
status = (evaluate_expression
|
status = (evaluate_expression
|
||||||
(&binding -> value, packet, lease,
|
(&binding -> value, packet, lease,
|
||||||
|
client_state,
|
||||||
in_options, out_options,
|
in_options, out_options,
|
||||||
scope, e -> data.set.expr));
|
scope, e -> data.set.expr));
|
||||||
binding -> next = ns -> bindings;
|
binding -> next = ns -> bindings;
|
||||||
@@ -400,6 +401,7 @@ int execute_statements (result, packet, lease, in_options, out_options, scope,
|
|||||||
*scope, MDL);
|
*scope, MDL);
|
||||||
execute_statements
|
execute_statements
|
||||||
(result, packet, lease,
|
(result, packet, lease,
|
||||||
|
client_state,
|
||||||
in_options, out_options,
|
in_options, out_options,
|
||||||
&ns, e -> data.let.statements);
|
&ns, e -> data.let.statements);
|
||||||
}
|
}
|
||||||
@@ -410,7 +412,8 @@ int execute_statements (result, packet, lease, in_options, out_options, scope,
|
|||||||
case log_statement:
|
case log_statement:
|
||||||
memset (&ds, 0, sizeof ds);
|
memset (&ds, 0, sizeof ds);
|
||||||
status = (evaluate_data_expression
|
status = (evaluate_data_expression
|
||||||
(&ds, packet, lease, in_options,
|
(&ds, packet,
|
||||||
|
lease, client_state, in_options,
|
||||||
out_options, scope, r -> data.log.expr));
|
out_options, scope, r -> data.log.expr));
|
||||||
|
|
||||||
#if defined (DEBUG_EXPRESSIONS)
|
#if defined (DEBUG_EXPRESSIONS)
|
||||||
@@ -461,11 +464,13 @@ int execute_statements (result, packet, lease, in_options, out_options, scope,
|
|||||||
specific scopes, so we recursively traverse the scope list, executing
|
specific scopes, so we recursively traverse the scope list, executing
|
||||||
the most outer scope first. */
|
the most outer scope first. */
|
||||||
|
|
||||||
void execute_statements_in_scope (result, packet, lease, in_options,
|
void execute_statements_in_scope (result, packet,
|
||||||
out_options, scope, group, limiting_group)
|
lease, client_state, in_options, out_options,
|
||||||
|
scope, group, limiting_group)
|
||||||
struct binding_value **result;
|
struct binding_value **result;
|
||||||
struct packet *packet;
|
struct packet *packet;
|
||||||
struct lease *lease;
|
struct lease *lease;
|
||||||
|
struct client_state *client_state;
|
||||||
struct option_state *in_options;
|
struct option_state *in_options;
|
||||||
struct option_state *out_options;
|
struct option_state *out_options;
|
||||||
struct binding_scope **scope;
|
struct binding_scope **scope;
|
||||||
@@ -507,11 +512,12 @@ void execute_statements_in_scope (result, packet, lease, in_options,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (group -> next)
|
if (group -> next)
|
||||||
execute_statements_in_scope (result, packet, lease,
|
execute_statements_in_scope (result, packet,
|
||||||
|
lease, client_state,
|
||||||
in_options, out_options, scope,
|
in_options, out_options, scope,
|
||||||
group -> next, limiting_group);
|
group -> next, limiting_group);
|
||||||
execute_statements (result, packet, lease, in_options, out_options,
|
execute_statements (result, packet, lease, client_state, in_options,
|
||||||
scope, group -> statements);
|
out_options, scope, group -> statements);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dereference or free any subexpressions of a statement being freed. */
|
/* Dereference or free any subexpressions of a statement being freed. */
|
||||||
@@ -856,6 +862,7 @@ void write_statements (file, statements, indent)
|
|||||||
|
|
||||||
int find_matching_case (struct executable_statement **ep,
|
int find_matching_case (struct executable_statement **ep,
|
||||||
struct packet *packet, struct lease *lease,
|
struct packet *packet, struct lease *lease,
|
||||||
|
struct client_state *client_state,
|
||||||
struct option_state *in_options,
|
struct option_state *in_options,
|
||||||
struct option_state *out_options,
|
struct option_state *out_options,
|
||||||
struct binding_scope **scope,
|
struct binding_scope **scope,
|
||||||
@@ -873,14 +880,15 @@ int find_matching_case (struct executable_statement **ep,
|
|||||||
memset (&cd, 0, sizeof cd);
|
memset (&cd, 0, sizeof cd);
|
||||||
|
|
||||||
status = (evaluate_data_expression (&ds, packet, lease,
|
status = (evaluate_data_expression (&ds, packet, lease,
|
||||||
in_options, out_options,
|
client_state, in_options,
|
||||||
scope, expr));
|
out_options, scope, expr));
|
||||||
if (status) {
|
if (status) {
|
||||||
for (s = stmt; s; s = s -> next) {
|
for (s = stmt; s; s = s -> next) {
|
||||||
if (s -> op == case_statement) {
|
if (s -> op == case_statement) {
|
||||||
sub = (evaluate_data_expression
|
sub = (evaluate_data_expression
|
||||||
(&cd, packet, lease, in_options,
|
(&cd, packet, lease, client_state,
|
||||||
out_options, scope, s -> data.c_case));
|
in_options, out_options,
|
||||||
|
scope, s -> data.c_case));
|
||||||
if (sub && cd.len == ds.len &&
|
if (sub && cd.len == ds.len &&
|
||||||
!memcmp (cd.data, ds.data, cd.len))
|
!memcmp (cd.data, ds.data, cd.len))
|
||||||
{
|
{
|
||||||
@@ -898,6 +906,7 @@ int find_matching_case (struct executable_statement **ep,
|
|||||||
} else {
|
} else {
|
||||||
unsigned long n, c;
|
unsigned long n, c;
|
||||||
status = evaluate_numeric_expression (&n, packet, lease,
|
status = evaluate_numeric_expression (&n, packet, lease,
|
||||||
|
client_state,
|
||||||
in_options, out_options,
|
in_options, out_options,
|
||||||
scope, expr);
|
scope, expr);
|
||||||
|
|
||||||
@@ -905,8 +914,9 @@ int find_matching_case (struct executable_statement **ep,
|
|||||||
for (s = stmt; s; s = s -> next) {
|
for (s = stmt; s; s = s -> next) {
|
||||||
if (s -> op == case_statement) {
|
if (s -> op == case_statement) {
|
||||||
sub = (evaluate_numeric_expression
|
sub = (evaluate_numeric_expression
|
||||||
(&c, packet, lease, in_options,
|
(&c, packet, lease, client_state,
|
||||||
out_options, scope, s -> data.c_case));
|
in_options, out_options,
|
||||||
|
scope, s -> data.c_case));
|
||||||
if (sub && n == c) {
|
if (sub && n == c) {
|
||||||
executable_statement_reference
|
executable_statement_reference
|
||||||
(ep, s -> next, MDL);
|
(ep, s -> next, MDL);
|
||||||
|
Reference in New Issue
Block a user