Handle option lists properly in script.c.
This commit is contained in:
parent
9d7ad2f11c
commit
c0703fc8c9
@ -187,41 +187,41 @@ struct option_set *find_option(struct option_set *opt_list, char code)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* add an option to the opt_list */
|
/* /\* add an option to the opt_list *\/ */
|
||||||
void attach_option(struct option_set **opt_list, struct dhcp_option *option,
|
/* void attach_option(struct option_set **opt_list, struct dhcp_option *option, */
|
||||||
char *buffer, int length)
|
/* char *buffer, int length) */
|
||||||
{
|
/* { */
|
||||||
struct option_set *existing, *new, **curr;
|
/* struct option_set *existing, *new, **curr; */
|
||||||
|
|
||||||
/* add it to an existing option */
|
/* /\* add it to an existing option *\/ */
|
||||||
if ((existing = find_option(*opt_list, option->code))) {
|
/* if ((existing = find_option(*opt_list, option->code))) { */
|
||||||
log_line("Attaching option %s to existing member of list",
|
/* log_line("Attaching option %s to existing member of list", */
|
||||||
option->name);
|
/* option->name); */
|
||||||
if (option->flags & OPTION_LIST) {
|
/* if (option->flags & OPTION_LIST) { */
|
||||||
if (existing->data[OPT_LEN] + length <= 255) {
|
/* if (existing->data[OPT_LEN] + length <= 255) { */
|
||||||
existing->data = realloc(existing->data,
|
/* existing->data = realloc(existing->data, */
|
||||||
existing->data[OPT_LEN] + length + 2);
|
/* existing->data[OPT_LEN] + length + 2); */
|
||||||
memcpy(existing->data + existing->data[OPT_LEN] + 2, buffer,
|
/* memcpy(existing->data + existing->data[OPT_LEN] + 2, buffer, */
|
||||||
length);
|
/* length); */
|
||||||
existing->data[OPT_LEN] += length;
|
/* existing->data[OPT_LEN] += length; */
|
||||||
} /* else, ignore the data; we could put this in a second option
|
/* } /\* else, ignore the data; we could put this in a second option */
|
||||||
in the future */
|
/* in the future *\/ */
|
||||||
} /* else, ignore the new data */
|
/* } /\* else, ignore the new data *\/ */
|
||||||
} else {
|
/* } else { */
|
||||||
log_line("Attaching option %s to list", option->name);
|
/* log_line("Attaching option %s to list", option->name); */
|
||||||
|
|
||||||
/* make a new option */
|
/* /\* make a new option *\/ */
|
||||||
new = xmalloc(sizeof(struct option_set));
|
/* new = xmalloc(sizeof(struct option_set)); */
|
||||||
new->data = xmalloc(length + 2);
|
/* new->data = xmalloc(length + 2); */
|
||||||
new->data[OPT_CODE] = option->code;
|
/* new->data[OPT_CODE] = option->code; */
|
||||||
new->data[OPT_LEN] = length;
|
/* new->data[OPT_LEN] = length; */
|
||||||
memcpy(new->data + 2, buffer, length);
|
/* memcpy(new->data + 2, buffer, length); */
|
||||||
|
|
||||||
curr = opt_list;
|
/* curr = opt_list; */
|
||||||
while (*curr && (*curr)->data[OPT_CODE] < option->code)
|
/* while (*curr && (*curr)->data[OPT_CODE] < option->code) */
|
||||||
curr = &(*curr)->next;
|
/* curr = &(*curr)->next; */
|
||||||
|
|
||||||
new->next = *curr;
|
/* new->next = *curr; */
|
||||||
*curr = new;
|
/* *curr = new; */
|
||||||
}
|
/* } */
|
||||||
}
|
/* } */
|
||||||
|
@ -35,6 +35,6 @@ int end_option(unsigned char *optionptr);
|
|||||||
int add_option_string(unsigned char *optionptr, unsigned char *string);
|
int add_option_string(unsigned char *optionptr, unsigned char *string);
|
||||||
int add_simple_option(unsigned char *optionptr, unsigned char code, uint32_t data);
|
int add_simple_option(unsigned char *optionptr, unsigned char code, uint32_t data);
|
||||||
struct option_set *find_option(struct option_set *opt_list, char code);
|
struct option_set *find_option(struct option_set *opt_list, char code);
|
||||||
void attach_option(struct option_set **opt_list, struct dhcp_option *option, char *buffer, int length);
|
/* void attach_option(struct option_set **opt_list, struct dhcp_option *option, char *buffer, int length); */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -78,6 +78,9 @@ static void fill_options(char *dest, unsigned char *option,
|
|||||||
*(dest++) = '/';
|
*(dest++) = '/';
|
||||||
option += 4;
|
option += 4;
|
||||||
optlen = 4;
|
optlen = 4;
|
||||||
|
dest += sprintip(dest, maxlen - (dest - odest), "", option);
|
||||||
|
optlen = option_lengths[type];
|
||||||
|
break;
|
||||||
case OPTION_IP: /* Works regardless of host byte order. */
|
case OPTION_IP: /* Works regardless of host byte order. */
|
||||||
dest += sprintip(dest, maxlen - (dest - odest), "", option);
|
dest += sprintip(dest, maxlen - (dest - odest), "", option);
|
||||||
break;
|
break;
|
||||||
@ -117,7 +120,9 @@ static void fill_options(char *dest, unsigned char *option,
|
|||||||
}
|
}
|
||||||
option += optlen;
|
option += optlen;
|
||||||
len -= optlen;
|
len -= optlen;
|
||||||
if (len <= 0) break;
|
if (len <= 0)
|
||||||
|
break;
|
||||||
|
*(dest++) = ':';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user