Move add_requests() from dhcpmsg.c to options.c. Fixes a layering violation.
Document an ugly-as-hell code bit in ifchange.c. Add some debugging messages for the netlink response code. Clean headers a bit more.
This commit is contained in:
parent
3c85228aaf
commit
811cc67e16
@ -99,22 +99,6 @@ static void init_packet(struct dhcpMessage *packet, char type)
|
||||
add_option_string(packet->options, (unsigned char *)&vendor_id);
|
||||
}
|
||||
|
||||
/* Add a paramater request list for stubborn DHCP servers. Pull the data
|
||||
* from the struct in options.c. Don't do bounds checking here because it
|
||||
* goes towards the head of the packet. */
|
||||
static void add_requests(struct dhcpMessage *packet)
|
||||
{
|
||||
int end = end_option(packet->options);
|
||||
int i, len = 0;
|
||||
|
||||
packet->options[end + OPT_CODE] = DHCP_PARAM_REQ;
|
||||
for (i = 0; options[i].code; i++)
|
||||
if (options[i].flags & OPTION_REQ)
|
||||
packet->options[end + OPT_DATA + len++] = options[i].code;
|
||||
packet->options[end + OPT_LEN] = len;
|
||||
packet->options[end + OPT_DATA + len] = DHCP_END;
|
||||
}
|
||||
|
||||
#define MAC_BCAST_ADDR (unsigned char *) "\xff\xff\xff\xff\xff\xff"
|
||||
/* Wrapper that broadcasts a raw dhcp packet on the bound interface. */
|
||||
static int bcast_raw_packet(struct dhcpMessage *packet)
|
||||
|
@ -69,7 +69,7 @@ static int fill_options(char *dest, unsigned char *option,
|
||||
|
||||
if (!option)
|
||||
return -1;
|
||||
int len = option[OPT_LEN - 2];
|
||||
int len = option[-1]; // XXX: WTF ugly as all hell
|
||||
|
||||
odest = dest;
|
||||
|
||||
|
@ -132,6 +132,7 @@ static void nl_handlemsg(struct nlmsghdr *msg, unsigned int len,
|
||||
if (cs->dhcpState == DS_BOUND) {
|
||||
/* arp_check_gw(cs); */
|
||||
} else if (cs->dhcpState != DS_INIT_SELECTING) {
|
||||
log_line("nl: taking down interface");
|
||||
// Same as packet.c: line 258
|
||||
ifchange(NULL, IFCHANGE_DECONFIG);
|
||||
cs->dhcpState = DS_INIT_SELECTING;
|
||||
|
@ -13,6 +13,12 @@
|
||||
#include "log.h"
|
||||
#include "malloc.h"
|
||||
|
||||
enum {
|
||||
OPT_CODE = 0,
|
||||
OPT_LEN = 1,
|
||||
OPT_DATA = 2
|
||||
};
|
||||
|
||||
/* supported options are easily added here */
|
||||
struct dhcp_option options[] = {
|
||||
/* name[10] flags code */
|
||||
@ -242,3 +248,19 @@ struct option_set *find_option(struct option_set *opt_list, char code)
|
||||
return opt_list;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Add a paramater request list for stubborn DHCP servers. Pull the data
|
||||
* from the struct in options.c. Don't do bounds checking here because it
|
||||
* goes towards the head of the packet. */
|
||||
void add_requests(struct dhcpMessage *packet)
|
||||
{
|
||||
int end = end_option(packet->options);
|
||||
int i, len = 0;
|
||||
|
||||
packet->options[end + OPT_CODE] = DHCP_PARAM_REQ;
|
||||
for (i = 0; options[i].code; i++)
|
||||
if (options[i].flags & OPTION_REQ)
|
||||
packet->options[end + OPT_DATA + len++] = options[i].code;
|
||||
packet->options[end + OPT_LEN] = len;
|
||||
packet->options[end + OPT_DATA + len] = DHCP_END;
|
||||
}
|
||||
|
@ -68,12 +68,6 @@ enum {
|
||||
#define OPTION_REQ 0x10 /* have the client request this option */
|
||||
#define OPTION_LIST 0x20 /* There can be a list of 1 or more of these */
|
||||
|
||||
enum {
|
||||
OPT_CODE = 0,
|
||||
OPT_LEN = 1,
|
||||
OPT_DATA = 2
|
||||
};
|
||||
|
||||
struct dhcp_option {
|
||||
char name[10];
|
||||
char flags;
|
||||
@ -103,4 +97,6 @@ int add_option_string(unsigned char *optionptr, unsigned char *string);
|
||||
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);
|
||||
|
||||
void add_requests(struct dhcpMessage *packet);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user