add "wpad" DHCP option. Spotted some optimization opportunities: -80 bytes
This commit is contained in:
parent
48237b0c88
commit
c90c3f30a8
@ -95,7 +95,8 @@ struct option_set *find_option(struct option_set *opt_list, char code)
|
||||
|
||||
|
||||
/* add an option to the opt_list */
|
||||
static void attach_option(struct option_set **opt_list, struct dhcp_option *option, char *buffer, int length)
|
||||
static void attach_option(struct option_set **opt_list,
|
||||
const struct dhcp_option *option, char *buffer, int length)
|
||||
{
|
||||
struct option_set *existing, *new, **curr;
|
||||
|
||||
@ -135,7 +136,7 @@ static int read_opt(const char *const_line, void *arg)
|
||||
{
|
||||
struct option_set **opt_list = arg;
|
||||
char *opt, *val, *endptr;
|
||||
struct dhcp_option *option;
|
||||
const struct dhcp_option *option;
|
||||
int retval = 0, length;
|
||||
char buffer[8];
|
||||
char *line;
|
||||
@ -144,16 +145,21 @@ static int read_opt(const char *const_line, void *arg)
|
||||
|
||||
/* Cheat, the only const line we'll actually get is "" */
|
||||
line = (char *) const_line;
|
||||
if (!(opt = strtok(line, " \t="))) return 0;
|
||||
opt = strtok(line, " \t=");
|
||||
if (!opt) return 0;
|
||||
|
||||
for (option = dhcp_options; option->code; option++)
|
||||
option = dhcp_options;
|
||||
while (1) {
|
||||
if (!option->code)
|
||||
return 0;
|
||||
if (!strcasecmp(option->name, opt))
|
||||
break;
|
||||
|
||||
if (!option->code) return 0;
|
||||
option++;
|
||||
}
|
||||
|
||||
do {
|
||||
if (!(val = strtok(NULL, ", \t"))) break;
|
||||
val = strtok(NULL, ", \t");
|
||||
if (!val) break;
|
||||
length = option_lengths[option->flags & TYPE_MASK];
|
||||
retval = 0;
|
||||
opt = buffer; /* new meaning for variable opt */
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
|
||||
/* supported options are easily added here */
|
||||
struct dhcp_option dhcp_options[] = {
|
||||
const struct dhcp_option dhcp_options[] = {
|
||||
/* name[10] flags code */
|
||||
{"subnet", OPTION_IP | OPTION_REQ, 0x01},
|
||||
{"timezone", OPTION_S32, 0x02},
|
||||
@ -43,11 +43,13 @@ struct dhcp_option dhcp_options[] = {
|
||||
{"tftp", OPTION_STRING, 0x42},
|
||||
{"bootfile", OPTION_STRING, 0x43},
|
||||
{"userclass", OPTION_STRING, 0x4D},
|
||||
/* MSIE's "Web Proxy Autodiscovery Protocol" support */
|
||||
{"wpad", OPTION_STRING, 0xfc},
|
||||
{"", 0x00, 0x00}
|
||||
};
|
||||
|
||||
/* Lengths of the different option types */
|
||||
int option_lengths[] = {
|
||||
const unsigned char option_lengths[] = {
|
||||
[OPTION_IP] = 4,
|
||||
[OPTION_IP_PAIR] = 8,
|
||||
[OPTION_BOOLEAN] = 1,
|
||||
@ -150,7 +152,7 @@ int add_option_string(uint8_t *optionptr, uint8_t *string)
|
||||
/* add a one to four byte option to a packet */
|
||||
int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data)
|
||||
{
|
||||
struct dhcp_option *dh;
|
||||
const struct dhcp_option *dh;
|
||||
|
||||
for (dh = dhcp_options; dh->code; dh++) {
|
||||
if (dh->code == code) {
|
||||
|
@ -26,8 +26,8 @@ struct dhcp_option {
|
||||
uint8_t code;
|
||||
};
|
||||
|
||||
extern struct dhcp_option dhcp_options[];
|
||||
extern int option_lengths[];
|
||||
extern const struct dhcp_option dhcp_options[];
|
||||
extern const unsigned char option_lengths[];
|
||||
|
||||
uint8_t *get_option(struct dhcpMessage *packet, int code);
|
||||
int end_option(uint8_t *optionptr);
|
||||
|
@ -54,7 +54,8 @@ static int mton(struct in_addr *mask)
|
||||
|
||||
|
||||
/* Fill dest with the text of option 'option'. */
|
||||
static void fill_options(char *dest, uint8_t *option, struct dhcp_option *type_p)
|
||||
static void fill_options(char *dest, uint8_t *option,
|
||||
const struct dhcp_option *type_p)
|
||||
{
|
||||
int type, optlen;
|
||||
uint16_t val_u16;
|
||||
@ -152,7 +153,8 @@ static char **fill_envp(struct dhcpMessage *packet)
|
||||
|
||||
|
||||
for (i = 0; dhcp_options[i].code; i++) {
|
||||
if (!(temp = get_option(packet, dhcp_options[i].code)))
|
||||
temp = get_option(packet, dhcp_options[i].code);
|
||||
if (temp)
|
||||
continue;
|
||||
envp[j] = xmalloc(upper_length(temp[OPT_LEN - 2],
|
||||
dhcp_options[i].flags & TYPE_MASK) + strlen(dhcp_options[i].name) + 2);
|
||||
|
Loading…
x
Reference in New Issue
Block a user