udhcp: s/dhcp_option/dhcp_optflag/g
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
9c0ea86caa
commit
c03602baa4
@ -18,7 +18,7 @@ const uint8_t MAC_BCAST_ADDR[6] ALIGN2 = {
|
|||||||
* See RFC2132 for more options.
|
* See RFC2132 for more options.
|
||||||
* OPTION_REQ: these options are requested by udhcpc (unless -o).
|
* OPTION_REQ: these options are requested by udhcpc (unless -o).
|
||||||
*/
|
*/
|
||||||
const struct dhcp_option dhcp_options[] = {
|
const struct dhcp_optflag dhcp_optflags[] = {
|
||||||
/* flags code */
|
/* flags code */
|
||||||
{ OPTION_IP | OPTION_REQ, 0x01 }, /* DHCP_SUBNET */
|
{ OPTION_IP | OPTION_REQ, 0x01 }, /* DHCP_SUBNET */
|
||||||
{ OPTION_S32 , 0x02 }, /* DHCP_TIME_OFFSET */
|
{ OPTION_S32 , 0x02 }, /* DHCP_TIME_OFFSET */
|
||||||
@ -76,7 +76,7 @@ const struct dhcp_option dhcp_options[] = {
|
|||||||
* for udhcpc stript, and for setting options for udhcpd via
|
* for udhcpc stript, and for setting options for udhcpd via
|
||||||
* "opt OPTION_NAME OPTION_VALUE" directives in udhcpd.conf file.
|
* "opt OPTION_NAME OPTION_VALUE" directives in udhcpd.conf file.
|
||||||
*/
|
*/
|
||||||
/* Must match dhcp_options[] order */
|
/* Must match dhcp_optflags[] order */
|
||||||
const char dhcp_option_strings[] ALIGN1 =
|
const char dhcp_option_strings[] ALIGN1 =
|
||||||
"subnet" "\0" /* DHCP_SUBNET */
|
"subnet" "\0" /* DHCP_SUBNET */
|
||||||
"timezone" "\0" /* DHCP_TIME_OFFSET */
|
"timezone" "\0" /* DHCP_TIME_OFFSET */
|
||||||
@ -278,9 +278,9 @@ void FAST_FUNC udhcp_add_binary_option(struct dhcp_packet *packet, uint8_t *addo
|
|||||||
/* Add an one to four byte option to a packet */
|
/* Add an one to four byte option to a packet */
|
||||||
void FAST_FUNC udhcp_add_simple_option(struct dhcp_packet *packet, uint8_t code, uint32_t data)
|
void FAST_FUNC udhcp_add_simple_option(struct dhcp_packet *packet, uint8_t code, uint32_t data)
|
||||||
{
|
{
|
||||||
const struct dhcp_option *dh;
|
const struct dhcp_optflag *dh;
|
||||||
|
|
||||||
for (dh = dhcp_options; dh->code; dh++) {
|
for (dh = dhcp_optflags; dh->code; dh++) {
|
||||||
if (dh->code == code) {
|
if (dh->code == code) {
|
||||||
uint8_t option[6], len;
|
uint8_t option[6], len;
|
||||||
|
|
||||||
@ -330,7 +330,7 @@ int FAST_FUNC udhcp_str2nip(const char *str, void *arg)
|
|||||||
/* helper: add an option to the opt_list */
|
/* helper: add an option to the opt_list */
|
||||||
static NOINLINE void attach_option(
|
static NOINLINE void attach_option(
|
||||||
struct option_set **opt_list,
|
struct option_set **opt_list,
|
||||||
const struct dhcp_option *option,
|
const struct dhcp_optflag *optflag,
|
||||||
char *buffer,
|
char *buffer,
|
||||||
int length)
|
int length)
|
||||||
{
|
{
|
||||||
@ -339,11 +339,11 @@ static NOINLINE void attach_option(
|
|||||||
char *allocated = NULL;
|
char *allocated = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
existing = udhcp_find_option(*opt_list, option->code);
|
existing = udhcp_find_option(*opt_list, optflag->code);
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
log2("Attaching option %02x to list", option->code);
|
log2("Attaching option %02x to list", optflag->code);
|
||||||
#if ENABLE_FEATURE_UDHCP_RFC3397
|
#if ENABLE_FEATURE_UDHCP_RFC3397
|
||||||
if ((option->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) {
|
if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) {
|
||||||
/* reuse buffer and length for RFC1035-formatted string */
|
/* reuse buffer and length for RFC1035-formatted string */
|
||||||
allocated = buffer = (char *)dname_enc(NULL, 0, buffer, &length);
|
allocated = buffer = (char *)dname_enc(NULL, 0, buffer, &length);
|
||||||
}
|
}
|
||||||
@ -351,12 +351,12 @@ static NOINLINE void attach_option(
|
|||||||
/* make a new option */
|
/* make a new option */
|
||||||
new = xmalloc(sizeof(*new));
|
new = xmalloc(sizeof(*new));
|
||||||
new->data = xmalloc(length + OPT_DATA);
|
new->data = xmalloc(length + OPT_DATA);
|
||||||
new->data[OPT_CODE] = option->code;
|
new->data[OPT_CODE] = optflag->code;
|
||||||
new->data[OPT_LEN] = length;
|
new->data[OPT_LEN] = length;
|
||||||
memcpy(new->data + OPT_DATA, buffer, length);
|
memcpy(new->data + OPT_DATA, buffer, length);
|
||||||
|
|
||||||
curr = opt_list;
|
curr = opt_list;
|
||||||
while (*curr && (*curr)->data[OPT_CODE] < option->code)
|
while (*curr && (*curr)->data[OPT_CODE] < optflag->code)
|
||||||
curr = &(*curr)->next;
|
curr = &(*curr)->next;
|
||||||
|
|
||||||
new->next = *curr;
|
new->next = *curr;
|
||||||
@ -364,14 +364,14 @@ static NOINLINE void attach_option(
|
|||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (option->flags & OPTION_LIST) {
|
if (optflag->flags & OPTION_LIST) {
|
||||||
unsigned old_len;
|
unsigned old_len;
|
||||||
|
|
||||||
/* add it to an existing option */
|
/* add it to an existing option */
|
||||||
log1("Attaching option %02x to existing member of list", option->code);
|
log1("Attaching option %02x to existing member of list", optflag->code);
|
||||||
old_len = existing->data[OPT_LEN];
|
old_len = existing->data[OPT_LEN];
|
||||||
#if ENABLE_FEATURE_UDHCP_RFC3397
|
#if ENABLE_FEATURE_UDHCP_RFC3397
|
||||||
if ((option->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) {
|
if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) {
|
||||||
/* reuse buffer and length for RFC1035-formatted string */
|
/* reuse buffer and length for RFC1035-formatted string */
|
||||||
allocated = buffer = (char *)dname_enc(existing->data + OPT_DATA, old_len, buffer, &length);
|
allocated = buffer = (char *)dname_enc(existing->data + OPT_DATA, old_len, buffer, &length);
|
||||||
}
|
}
|
||||||
@ -380,7 +380,7 @@ static NOINLINE void attach_option(
|
|||||||
/* actually 255 is ok too, but adding a space can overlow it */
|
/* actually 255 is ok too, but adding a space can overlow it */
|
||||||
|
|
||||||
existing->data = xrealloc(existing->data, OPT_DATA + 1 + old_len + length);
|
existing->data = xrealloc(existing->data, OPT_DATA + 1 + old_len + length);
|
||||||
if ((option->flags & OPTION_TYPE_MASK) == OPTION_STRING) {
|
if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING) {
|
||||||
/* add space separator between STRING options in a list */
|
/* add space separator between STRING options in a list */
|
||||||
existing->data[OPT_DATA + old_len] = ' ';
|
existing->data[OPT_DATA + old_len] = ' ';
|
||||||
old_len++;
|
old_len++;
|
||||||
@ -401,7 +401,7 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg)
|
|||||||
struct option_set **opt_list = arg;
|
struct option_set **opt_list = arg;
|
||||||
char *opt, *val, *endptr;
|
char *opt, *val, *endptr;
|
||||||
char *str;
|
char *str;
|
||||||
const struct dhcp_option *option;
|
const struct dhcp_optflag *optflag;
|
||||||
int retval, length;
|
int retval, length;
|
||||||
char buffer[8] ALIGNED(4);
|
char buffer[8] ALIGNED(4);
|
||||||
uint16_t *result_u16 = (uint16_t *) buffer;
|
uint16_t *result_u16 = (uint16_t *) buffer;
|
||||||
@ -413,17 +413,17 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg)
|
|||||||
if (!opt)
|
if (!opt)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
option = &dhcp_options[udhcp_option_idx(opt)];
|
optflag = &dhcp_optflags[udhcp_option_idx(opt)];
|
||||||
|
|
||||||
retval = 0;
|
retval = 0;
|
||||||
do {
|
do {
|
||||||
val = strtok(NULL, ", \t");
|
val = strtok(NULL, ", \t");
|
||||||
if (!val)
|
if (!val)
|
||||||
break;
|
break;
|
||||||
length = dhcp_option_lengths[option->flags & OPTION_TYPE_MASK];
|
length = dhcp_option_lengths[optflag->flags & OPTION_TYPE_MASK];
|
||||||
retval = 0;
|
retval = 0;
|
||||||
opt = buffer; /* new meaning for variable opt */
|
opt = buffer; /* new meaning for variable opt */
|
||||||
switch (option->flags & OPTION_TYPE_MASK) {
|
switch (optflag->flags & OPTION_TYPE_MASK) {
|
||||||
case OPTION_IP:
|
case OPTION_IP:
|
||||||
retval = udhcp_str2nip(val, buffer);
|
retval = udhcp_str2nip(val, buffer);
|
||||||
break;
|
break;
|
||||||
@ -486,8 +486,8 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (retval)
|
if (retval)
|
||||||
attach_option(opt_list, option, opt, length);
|
attach_option(opt_list, optflag, opt, length);
|
||||||
} while (retval && option->flags & OPTION_LIST);
|
} while (retval && optflag->flags & OPTION_LIST);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ enum {
|
|||||||
#define DHCP_MINTYPE DHCPDISCOVER
|
#define DHCP_MINTYPE DHCPDISCOVER
|
||||||
#define DHCP_MAXTYPE DHCPINFORM
|
#define DHCP_MAXTYPE DHCPINFORM
|
||||||
|
|
||||||
struct dhcp_option {
|
struct dhcp_optflag {
|
||||||
uint8_t flags;
|
uint8_t flags;
|
||||||
uint8_t code;
|
uint8_t code;
|
||||||
};
|
};
|
||||||
@ -167,7 +167,7 @@ struct option_set {
|
|||||||
struct option_set *next;
|
struct option_set *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const struct dhcp_option dhcp_options[];
|
extern const struct dhcp_optflag dhcp_optflags[];
|
||||||
extern const char dhcp_option_strings[];
|
extern const char dhcp_option_strings[];
|
||||||
extern const uint8_t dhcp_option_lengths[];
|
extern const uint8_t dhcp_option_lengths[];
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ static int mton(uint32_t mask)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create "opt_name=opt_value" string */
|
/* Create "opt_name=opt_value" string */
|
||||||
static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_option *type_p, const char *opt_name)
|
static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_optflag *optflag, const char *opt_name)
|
||||||
{
|
{
|
||||||
unsigned upper_length;
|
unsigned upper_length;
|
||||||
int len, type, optlen;
|
int len, type, optlen;
|
||||||
@ -89,7 +89,7 @@ static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_
|
|||||||
|
|
||||||
/* option points to OPT_DATA, need to go back and get OPT_LEN */
|
/* option points to OPT_DATA, need to go back and get OPT_LEN */
|
||||||
len = option[OPT_LEN - OPT_DATA];
|
len = option[OPT_LEN - OPT_DATA];
|
||||||
type = type_p->flags & OPTION_TYPE_MASK;
|
type = optflag->flags & OPTION_TYPE_MASK;
|
||||||
optlen = dhcp_option_lengths[type];
|
optlen = dhcp_option_lengths[type];
|
||||||
upper_length = len_of_option_as_string[type] * ((unsigned)len / (unsigned)optlen);
|
upper_length = len_of_option_as_string[type] * ((unsigned)len / (unsigned)optlen);
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_
|
|||||||
optlen = 4;
|
optlen = 4;
|
||||||
case OPTION_IP:
|
case OPTION_IP:
|
||||||
dest += sprint_nip(dest, "", option);
|
dest += sprint_nip(dest, "", option);
|
||||||
// TODO: it can be a list only if (type_p->flags & OPTION_LIST).
|
// TODO: it can be a list only if (optflag->flags & OPTION_LIST).
|
||||||
// Should we bail out/warn if we see multi-ip option which is
|
// Should we bail out/warn if we see multi-ip option which is
|
||||||
// not allowed to be such? For example, DHCP_BROADCAST...
|
// not allowed to be such? For example, DHCP_BROADCAST...
|
||||||
break;
|
break;
|
||||||
@ -237,10 +237,10 @@ static char **fill_envp(struct dhcp_packet *packet)
|
|||||||
uint8_t over = 0;
|
uint8_t over = 0;
|
||||||
|
|
||||||
if (packet) {
|
if (packet) {
|
||||||
for (i = 0; dhcp_options[i].code; i++) {
|
for (i = 0; dhcp_optflags[i].code; i++) {
|
||||||
if (udhcp_get_option(packet, dhcp_options[i].code)) {
|
if (udhcp_get_option(packet, dhcp_optflags[i].code)) {
|
||||||
num_options++;
|
num_options++;
|
||||||
if (dhcp_options[i].code == DHCP_SUBNET)
|
if (dhcp_optflags[i].code == DHCP_SUBNET)
|
||||||
num_options++; /* for mton */
|
num_options++; /* for mton */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -269,14 +269,14 @@ static char **fill_envp(struct dhcp_packet *packet)
|
|||||||
opt_name = dhcp_option_strings;
|
opt_name = dhcp_option_strings;
|
||||||
i = 0;
|
i = 0;
|
||||||
while (*opt_name) {
|
while (*opt_name) {
|
||||||
temp = udhcp_get_option(packet, dhcp_options[i].code);
|
temp = udhcp_get_option(packet, dhcp_optflags[i].code);
|
||||||
if (!temp)
|
if (!temp)
|
||||||
goto next;
|
goto next;
|
||||||
*curr = xmalloc_optname_optval(temp, &dhcp_options[i], opt_name);
|
*curr = xmalloc_optname_optval(temp, &dhcp_optflags[i], opt_name);
|
||||||
putenv(*curr++);
|
putenv(*curr++);
|
||||||
|
|
||||||
/* Fill in a subnet bits option for things like /24 */
|
/* Fill in a subnet bits option for things like /24 */
|
||||||
if (dhcp_options[i].code == DHCP_SUBNET) {
|
if (dhcp_optflags[i].code == DHCP_SUBNET) {
|
||||||
uint32_t subnet;
|
uint32_t subnet;
|
||||||
move_from_unaligned32(subnet, temp);
|
move_from_unaligned32(subnet, temp);
|
||||||
*curr = xasprintf("mask=%d", mton(subnet));
|
*curr = xasprintf("mask=%d", mton(subnet));
|
||||||
@ -366,8 +366,8 @@ static void add_client_options(struct dhcp_packet *packet)
|
|||||||
int end = udhcp_end_option(packet->options);
|
int end = udhcp_end_option(packet->options);
|
||||||
int i, len = 0;
|
int i, len = 0;
|
||||||
|
|
||||||
for (i = 0; (c = dhcp_options[i].code) != 0; i++) {
|
for (i = 0; (c = dhcp_optflags[i].code) != 0; i++) {
|
||||||
if (( (dhcp_options[i].flags & OPTION_REQ)
|
if (( (dhcp_optflags[i].flags & OPTION_REQ)
|
||||||
&& !client_config.no_default_options
|
&& !client_config.no_default_options
|
||||||
)
|
)
|
||||||
|| (client_config.opt_mask[c >> 3] & (1 << (c & 7)))
|
|| (client_config.opt_mask[c >> 3] & (1 << (c & 7)))
|
||||||
@ -905,7 +905,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
while (list_O) {
|
while (list_O) {
|
||||||
char *optstr = llist_pop(&list_O);
|
char *optstr = llist_pop(&list_O);
|
||||||
unsigned n = udhcp_option_idx(optstr);
|
unsigned n = udhcp_option_idx(optstr);
|
||||||
n = dhcp_options[n].code;
|
n = dhcp_optflags[n].code;
|
||||||
client_config.opt_mask[n >> 3] |= 1 << (n & 7);
|
client_config.opt_mask[n >> 3] |= 1 << (n & 7);
|
||||||
}
|
}
|
||||||
while (list_x) {
|
while (list_x) {
|
||||||
|
Loading…
Reference in New Issue
Block a user