mirror of
https://gitlab.isc.org/isc-projects/dhcp
synced 2025-08-29 13:28:14 +00:00
Add support for passing arbitrary options to server and for providing default options when the server doesn't provide them; remove client_identifier and hostname - these are just options.
This commit is contained in:
parent
e07ac89ae9
commit
ac9d14a9c1
@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char copyright[] =
|
static char copyright[] =
|
||||||
"$Id: clparse.c,v 1.2 1997/02/19 10:53:16 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
|
"$Id: clparse.c,v 1.3 1997/02/22 08:38:32 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include "dhcpd.h"
|
#include "dhcpd.h"
|
||||||
@ -142,9 +142,9 @@ void read_client_leases ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* client-declaration :==
|
/* client-declaration :==
|
||||||
HOSTNAME string |
|
SEND option-decl |
|
||||||
|
DEFAULT option-decl |
|
||||||
hardware-declaration |
|
hardware-declaration |
|
||||||
client-identifier-declaration |
|
|
||||||
REQUEST option-list |
|
REQUEST option-list |
|
||||||
REQUIRE option-list |
|
REQUIRE option-list |
|
||||||
TIMEOUT number |
|
TIMEOUT number |
|
||||||
@ -161,24 +161,19 @@ void parse_client_statement (cfile, ip, config)
|
|||||||
{
|
{
|
||||||
int token;
|
int token;
|
||||||
char *val;
|
char *val;
|
||||||
char *t, *n;
|
|
||||||
u_int8_t buf [1024];
|
|
||||||
|
|
||||||
switch (next_token (&val, cfile)) {
|
switch (next_token (&val, cfile)) {
|
||||||
case HOSTNAME:
|
case SEND:
|
||||||
config -> dns_hostname = parse_string (cfile);
|
parse_option_decl (cfile, &config -> send_options [0]);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case CLIENT_IDENTIFIER:
|
case DEFAULT:
|
||||||
config -> cid_len = parse_X (cfile, buf, sizeof buf);
|
parse_option_decl (cfile, &config -> defaults [0]);
|
||||||
if (config -> cid_len == 0)
|
return;
|
||||||
break;
|
|
||||||
config -> client_identifier = malloc (config -> cid_len + 1);
|
case MEDIA:
|
||||||
if (!config -> client_identifier)
|
parse_string_list (cfile, &config -> media, 1);
|
||||||
error ("no memory for client identifier.");
|
return;
|
||||||
memcpy (config -> client_identifier, buf, config -> cid_len);
|
|
||||||
config -> client_identifier [config -> cid_len] = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HARDWARE:
|
case HARDWARE:
|
||||||
if (ip) {
|
if (ip) {
|
||||||
@ -547,7 +542,7 @@ void parse_client_lease_statement (cfile, is_static)
|
|||||||
FIXED_ADDR ip_address |
|
FIXED_ADDR ip_address |
|
||||||
FILENAME string |
|
FILENAME string |
|
||||||
SERVER_NAME string |
|
SERVER_NAME string |
|
||||||
option-decl |
|
OPTION option-decl |
|
||||||
RENEW time-decl |
|
RENEW time-decl |
|
||||||
REBIND time-decl |
|
REBIND time-decl |
|
||||||
EXPIRE time-decl */
|
EXPIRE time-decl */
|
||||||
@ -578,6 +573,10 @@ void parse_client_lease_declaration (cfile, lease, ipp)
|
|||||||
parse_ip_addr (cfile, &lease -> address);
|
parse_ip_addr (cfile, &lease -> address);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MEDIUM:
|
||||||
|
parse_string_list (cfile, &lease -> medium, 0);
|
||||||
|
return;
|
||||||
|
|
||||||
case FILENAME:
|
case FILENAME:
|
||||||
lease -> filename = parse_string (cfile);
|
lease -> filename = parse_string (cfile);
|
||||||
return;
|
return;
|
||||||
@ -836,3 +835,53 @@ void parse_option_decl (cfile, options)
|
|||||||
memcpy (options [option -> code].data, hunkbuf, hunkix + nul_term);
|
memcpy (options [option -> code].data, hunkbuf, hunkix + nul_term);
|
||||||
options [option -> code].len = hunkix;
|
options [option -> code].len = hunkix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void parse_string_list (cfile, lp, multiple)
|
||||||
|
FILE *cfile;
|
||||||
|
struct string_list **lp;
|
||||||
|
int multiple;
|
||||||
|
{
|
||||||
|
int token;
|
||||||
|
char *val;
|
||||||
|
struct string_list *cur, *tmp;
|
||||||
|
|
||||||
|
/* Find the last medium in the media list. */
|
||||||
|
if (*lp) {
|
||||||
|
for (cur = *lp; cur -> next; cur = cur -> next)
|
||||||
|
;
|
||||||
|
} else {
|
||||||
|
cur = (struct string_list *)0;
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
token = next_token (&val, cfile);
|
||||||
|
if (token != STRING) {
|
||||||
|
parse_warn ("Expecting media options.");
|
||||||
|
skip_to_semi (cfile);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp = (struct string_list *)malloc (strlen (val) + 1 +
|
||||||
|
sizeof
|
||||||
|
(struct string_list *));
|
||||||
|
if (!tmp)
|
||||||
|
error ("no memory for string list entry.");
|
||||||
|
|
||||||
|
strcpy (tmp -> string, val);
|
||||||
|
tmp -> next = (struct string_list *)0;
|
||||||
|
|
||||||
|
/* Store this medium at the end of the media list. */
|
||||||
|
if (cur)
|
||||||
|
cur -> next = tmp;
|
||||||
|
else
|
||||||
|
*lp = tmp;
|
||||||
|
cur = tmp;
|
||||||
|
|
||||||
|
token = next_token (&val, cfile);
|
||||||
|
} while (multiple && token == COMMA);
|
||||||
|
|
||||||
|
if (token != SEMI) {
|
||||||
|
parse_warn ("expecting semicolon.");
|
||||||
|
skip_to_semi (cfile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
85
clparse.c
85
clparse.c
@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char copyright[] =
|
static char copyright[] =
|
||||||
"$Id: clparse.c,v 1.2 1997/02/19 10:53:16 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
|
"$Id: clparse.c,v 1.3 1997/02/22 08:38:32 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include "dhcpd.h"
|
#include "dhcpd.h"
|
||||||
@ -142,9 +142,9 @@ void read_client_leases ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* client-declaration :==
|
/* client-declaration :==
|
||||||
HOSTNAME string |
|
SEND option-decl |
|
||||||
|
DEFAULT option-decl |
|
||||||
hardware-declaration |
|
hardware-declaration |
|
||||||
client-identifier-declaration |
|
|
||||||
REQUEST option-list |
|
REQUEST option-list |
|
||||||
REQUIRE option-list |
|
REQUIRE option-list |
|
||||||
TIMEOUT number |
|
TIMEOUT number |
|
||||||
@ -161,24 +161,19 @@ void parse_client_statement (cfile, ip, config)
|
|||||||
{
|
{
|
||||||
int token;
|
int token;
|
||||||
char *val;
|
char *val;
|
||||||
char *t, *n;
|
|
||||||
u_int8_t buf [1024];
|
|
||||||
|
|
||||||
switch (next_token (&val, cfile)) {
|
switch (next_token (&val, cfile)) {
|
||||||
case HOSTNAME:
|
case SEND:
|
||||||
config -> dns_hostname = parse_string (cfile);
|
parse_option_decl (cfile, &config -> send_options [0]);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case CLIENT_IDENTIFIER:
|
case DEFAULT:
|
||||||
config -> cid_len = parse_X (cfile, buf, sizeof buf);
|
parse_option_decl (cfile, &config -> defaults [0]);
|
||||||
if (config -> cid_len == 0)
|
return;
|
||||||
break;
|
|
||||||
config -> client_identifier = malloc (config -> cid_len + 1);
|
case MEDIA:
|
||||||
if (!config -> client_identifier)
|
parse_string_list (cfile, &config -> media, 1);
|
||||||
error ("no memory for client identifier.");
|
return;
|
||||||
memcpy (config -> client_identifier, buf, config -> cid_len);
|
|
||||||
config -> client_identifier [config -> cid_len] = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HARDWARE:
|
case HARDWARE:
|
||||||
if (ip) {
|
if (ip) {
|
||||||
@ -547,7 +542,7 @@ void parse_client_lease_statement (cfile, is_static)
|
|||||||
FIXED_ADDR ip_address |
|
FIXED_ADDR ip_address |
|
||||||
FILENAME string |
|
FILENAME string |
|
||||||
SERVER_NAME string |
|
SERVER_NAME string |
|
||||||
option-decl |
|
OPTION option-decl |
|
||||||
RENEW time-decl |
|
RENEW time-decl |
|
||||||
REBIND time-decl |
|
REBIND time-decl |
|
||||||
EXPIRE time-decl */
|
EXPIRE time-decl */
|
||||||
@ -578,6 +573,10 @@ void parse_client_lease_declaration (cfile, lease, ipp)
|
|||||||
parse_ip_addr (cfile, &lease -> address);
|
parse_ip_addr (cfile, &lease -> address);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MEDIUM:
|
||||||
|
parse_string_list (cfile, &lease -> medium, 0);
|
||||||
|
return;
|
||||||
|
|
||||||
case FILENAME:
|
case FILENAME:
|
||||||
lease -> filename = parse_string (cfile);
|
lease -> filename = parse_string (cfile);
|
||||||
return;
|
return;
|
||||||
@ -836,3 +835,53 @@ void parse_option_decl (cfile, options)
|
|||||||
memcpy (options [option -> code].data, hunkbuf, hunkix + nul_term);
|
memcpy (options [option -> code].data, hunkbuf, hunkix + nul_term);
|
||||||
options [option -> code].len = hunkix;
|
options [option -> code].len = hunkix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void parse_string_list (cfile, lp, multiple)
|
||||||
|
FILE *cfile;
|
||||||
|
struct string_list **lp;
|
||||||
|
int multiple;
|
||||||
|
{
|
||||||
|
int token;
|
||||||
|
char *val;
|
||||||
|
struct string_list *cur, *tmp;
|
||||||
|
|
||||||
|
/* Find the last medium in the media list. */
|
||||||
|
if (*lp) {
|
||||||
|
for (cur = *lp; cur -> next; cur = cur -> next)
|
||||||
|
;
|
||||||
|
} else {
|
||||||
|
cur = (struct string_list *)0;
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
token = next_token (&val, cfile);
|
||||||
|
if (token != STRING) {
|
||||||
|
parse_warn ("Expecting media options.");
|
||||||
|
skip_to_semi (cfile);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp = (struct string_list *)malloc (strlen (val) + 1 +
|
||||||
|
sizeof
|
||||||
|
(struct string_list *));
|
||||||
|
if (!tmp)
|
||||||
|
error ("no memory for string list entry.");
|
||||||
|
|
||||||
|
strcpy (tmp -> string, val);
|
||||||
|
tmp -> next = (struct string_list *)0;
|
||||||
|
|
||||||
|
/* Store this medium at the end of the media list. */
|
||||||
|
if (cur)
|
||||||
|
cur -> next = tmp;
|
||||||
|
else
|
||||||
|
*lp = tmp;
|
||||||
|
cur = tmp;
|
||||||
|
|
||||||
|
token = next_token (&val, cfile);
|
||||||
|
} while (multiple && token == COMMA);
|
||||||
|
|
||||||
|
if (token != SEMI) {
|
||||||
|
parse_warn ("expecting semicolon.");
|
||||||
|
skip_to_semi (cfile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user