summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Hankins <dhankins@isc.org>2009-07-06 23:29:52 +0000
committerDavid Hankins <dhankins@isc.org>2009-07-06 23:29:52 +0000
commit33ea4622a865e0cc545c7d89d2b222e1198e9ac3 (patch)
treec5284ed5b090a669eed653156743f446ebcf78cf
parent8ef5db715e202470cece3c62750aafe5a475594b (diff)
downloadisc-dhcp-33ea4622a865e0cc545c7d89d2b222e1198e9ac3.tar.gz
- Added a configuration function, 'gethostname()', which calls the system
function of the same name and presents the results as a data expression. This function can be used to incorporate the system level hostname of the system the DHCP software is operating on in responses or queries (such as including a failover partner's hostname in a dhcp message or binding scope, or having a DHCP client send any system hostname in the host-name or FQDN options by default). [ISC-Bugs #17351]
-rw-r--r--RELNOTES8
-rw-r--r--client/dhclient.conf2
-rw-r--r--common/conflex.c9
-rw-r--r--common/dhcp-eval.512
-rw-r--r--common/parse.c16
-rw-r--r--common/print.c7
-rw-r--r--common/tree.c48
-rw-r--r--includes/dhctoken.h3
-rw-r--r--includes/tree.h3
9 files changed, 101 insertions, 7 deletions
diff --git a/RELNOTES b/RELNOTES
index aa1fa1bf..0a6237f9 100644
--- a/RELNOTES
+++ b/RELNOTES
@@ -58,6 +58,14 @@ work on other platforms. Please report any problems and suggested fixes to
please carefully review the documentation of this parameter in the
dhcpd.conf(5) manpage before determining to use it yourself.
+- Added a configuration function, 'gethostname()', which calls the system
+ function of the same name and presents the results as a data expression.
+ This function can be used to incorporate the system level hostname of
+ the system the DHCP software is operating on in responses or queries (such
+ as including a failover partner's hostname in a dhcp message or binding
+ scope, or having a DHCP client send any system hostname in the host-name or
+ FQDN options by default).
+
Changes since 4.1.0 (bug fixes)
- Remove infinite loop in token_print_indent_concat().
diff --git a/client/dhclient.conf b/client/dhclient.conf
index 147e0045..64c6ce11 100644
--- a/client/dhclient.conf
+++ b/client/dhclient.conf
@@ -1,4 +1,4 @@
-send host-name "andare.fugue.com";
+send host-name = pick-first-value(gethostname(), "ISC-dhclient");
send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;
send dhcp-lease-time 3600;
supersede domain-name "fugue.com home.vix.com";
diff --git a/common/conflex.c b/common/conflex.c
index 2ce94840..41edb89a 100644
--- a/common/conflex.c
+++ b/common/conflex.c
@@ -984,12 +984,17 @@ intern(char *atom, enum dhcp_token dfv) {
return TOKEN_FREE;
break;
case 'g':
+ if (!strncasecmp(atom + 1, "et", 2)) {
+ if (!strcasecmp(atom + 3, "-lease-hostnames"))
+ return GET_LEASE_HOSTNAMES;
+ if (!strcasecmp(atom + 3, "hostname"))
+ return GETHOSTNAME;
+ break;
+ }
if (!strcasecmp (atom + 1, "iaddr"))
return GIADDR;
if (!strcasecmp (atom + 1, "roup"))
return GROUP;
- if (!strcasecmp (atom + 1, "et-lease-hostnames"))
- return GET_LEASE_HOSTNAMES;
break;
case 'h':
if (!strcasecmp(atom + 1, "ash"))
diff --git a/common/dhcp-eval.5 b/common/dhcp-eval.5
index 1bde0b2b..d497da9d 100644
--- a/common/dhcp-eval.5
+++ b/common/dhcp-eval.5
@@ -1,4 +1,4 @@
-.\" $Id: dhcp-eval.5,v 1.27 2007/06/07 15:52:29 dhankins Exp $
+.\" $Id: dhcp-eval.5,v 1.28 2009/07/06 23:29:51 dhankins Exp $
.\"
.\" Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC")
.\" Copyright (c) 1996-2003 by Internet Software Consortium
@@ -247,6 +247,16 @@ The \fBconfig-option\fR operator returns the value for the specified option
that the DHCP client or server has been configured to send.
.RE
.PP
+.B gethostname()
+.PP
+.RS 0.25i
+The \fBgethostname()\fR function returns a data string whose contents are a
+character string, the results of calling gethostname() on the local
+system with a size limit of 255 bytes (not including NULL terminator). This
+can be used for example to configure dhclient to send the local hostname
+without knowing the local hostname at the time dhclient.conf is written.
+.RE
+.PP
.B hardware
.PP
.RS 0.25i
diff --git a/common/parse.c b/common/parse.c
index d2842b48..feaec7df 100644
--- a/common/parse.c
+++ b/common/parse.c
@@ -4503,6 +4503,22 @@ int parse_non_binary (expr, cfile, lose, context)
goto norparen;
break;
+ /* This parses 'gethostname()'. */
+ case GETHOSTNAME:
+ token = next_token(&val, NULL, cfile);
+ if (!expression_allocate(expr, MDL))
+ log_fatal("can't allocate expression");
+ (*expr)->op = expr_gethostname;
+
+ token = next_token(NULL, NULL, cfile);
+ if (token != LPAREN)
+ goto nolparen;
+
+ token = next_token(NULL, NULL, cfile);
+ if (token != RPAREN)
+ goto norparen;
+ break;
+
/* Not a valid start to an expression... */
default:
if (token != NAME && token != NUMBER_OR_NAME)
diff --git a/common/print.c b/common/print.c
index a95198d7..6592b889 100644
--- a/common/print.c
+++ b/common/print.c
@@ -1062,6 +1062,13 @@ static unsigned print_subexpression (expr, buf, len)
return rv;
}
+ case expr_gethostname:
+ if (len > 13) {
+ strcpy(buf, "(gethostname)");
+ return 13;
+ }
+ break;
+
default:
log_fatal("Impossible case at %s:%d (undefined expression "
"%d).", MDL, expr->op);
diff --git a/common/tree.c b/common/tree.c
index 5244a196..2e4616f3 100644
--- a/common/tree.c
+++ b/common/tree.c
@@ -951,6 +951,7 @@ int evaluate_dns_expression (result, packet, lease, client_state, in_options,
case expr_config_option:
case expr_leased_address:
case expr_null:
+ case expr_gethostname:
log_error ("Data opcode in evaluate_dns_expression: %d",
expr -> op);
return 0;
@@ -1376,6 +1377,7 @@ int evaluate_boolean_expression (result, packet, lease, client_state,
case expr_null:
case expr_filename:
case expr_sname:
+ case expr_gethostname:
log_error ("Data opcode in evaluate_boolean_expression: %d",
expr -> op);
return 0;
@@ -2299,6 +2301,39 @@ int evaluate_data_expression (result, packet, lease, client_state,
#endif
return s0;
+ /* Provide the system's local hostname as a return value. */
+ case expr_gethostname:
+ /*
+ * Allocate a buffer to return.
+ *
+ * The largest valid hostname is maybe 64 octets at a single
+ * label, or 255 octets if you think a hostname is allowed
+ * to contain labels (plus termination).
+ */
+ memset(result, 0, sizeof(*result));
+ if (!buffer_allocate(&result->buffer, 255, file, line)) {
+ log_error("data: gethostname(): no memory for buffer");
+ return 0;
+ }
+ result->data = result->buffer->data;
+
+ /*
+ * On successful completion, gethostname() resturns 0. It may
+ * not null-terminate the string if there was insufficient
+ * space.
+ */
+ if (!gethostname((char *)result->buffer->data, 255)) {
+ if (result->buffer->data[255] == '\0')
+ result->len =
+ strlen((char *)result->buffer->data);
+ else
+ result->len = 255;
+ return 1;
+ }
+
+ data_string_forget(result, MDL);
+ return 0;
+
case expr_check:
case expr_equal:
case expr_not_equal:
@@ -2420,6 +2455,7 @@ int evaluate_numeric_expression (result, packet, lease, client_state,
case expr_config_option:
case expr_leased_address:
case expr_null:
+ case expr_gethostname:
log_error ("Data opcode in evaluate_numeric_expression: %d",
expr -> op);
return 0;
@@ -3202,6 +3238,7 @@ void expression_dereference (eptr, file, line)
case expr_exists:
case expr_known:
case expr_null:
+ case expr_gethostname:
break;
default:
@@ -3261,7 +3298,8 @@ int is_data_expression (expr)
expr->op == expr_host_decl_name ||
expr->op == expr_leased_address ||
expr->op == expr_config_option ||
- expr->op == expr_null);
+ expr->op == expr_null ||
+ expr->op == expr_gethostname);
}
int is_numeric_expression (expr)
@@ -3364,6 +3402,7 @@ static int op_val (op)
case expr_binary_or:
case expr_binary_xor:
case expr_client_state:
+ case expr_gethostname:
return 100;
case expr_equal:
@@ -3457,6 +3496,7 @@ enum expression_context op_context (op)
case expr_arg:
case expr_funcall:
case expr_function:
+ case expr_gethostname:
return context_any;
case expr_equal:
@@ -3988,6 +4028,11 @@ int write_expression (file, expr, col, indent, firstp)
col = token_print_indent (file, col, indent, "", "", ")");
break;
+ case expr_gethostname:
+ col = token_print_indent(file, col, indent, "", "",
+ "gethostname()");
+ break;
+
default:
log_fatal ("invalid expression type in print_expression: %d",
expr -> op);
@@ -4241,6 +4286,7 @@ int data_subexpression_length (int *rv,
case expr_binary_or:
case expr_binary_xor:
case expr_client_state:
+ case expr_gethostname:
return 0;
}
return 0;
diff --git a/includes/dhctoken.h b/includes/dhctoken.h
index 01ed1303..d47506a0 100644
--- a/includes/dhctoken.h
+++ b/includes/dhctoken.h
@@ -355,7 +355,8 @@ enum dhcp_token {
FIXED_PREFIX6 = 658,
ANYCAST_MAC = 659,
CONFLICT_DONE = 660,
- AUTO_PARTNER_DOWN = 661
+ AUTO_PARTNER_DOWN = 661,
+ GETHOSTNAME = 662
};
#define is_identifier(x) ((x) >= FIRST_TOKEN && \
diff --git a/includes/tree.h b/includes/tree.h
index e7bde430..9c37bcc5 100644
--- a/includes/tree.h
+++ b/includes/tree.h
@@ -197,7 +197,8 @@ enum expr_op {
expr_ucase,
expr_lcase,
expr_regex_match,
- expr_iregex_match
+ expr_iregex_match,
+ expr_gethostname
};
struct expression {