Fix sending DHCP_MAX_SIZE option.
Move DHCP_PARAM_REQ message types out of the options[] structure. Make ipchange.c:translation_option() less insane.
This commit is contained in:
parent
811cc67e16
commit
d4171420a1
@ -176,20 +176,31 @@ static void deconfig_if(void)
|
|||||||
close(sockfd);
|
close(sockfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void translate_option(int sockfd, struct dhcpMessage *packet, int opt)
|
static void translate_option(int sockfd, struct dhcpMessage *packet,
|
||||||
|
unsigned char code)
|
||||||
{
|
{
|
||||||
char buf[256], buf2[256];
|
char buf[256], buf2[256];
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
int i;
|
int i;
|
||||||
|
struct dhcp_option *opt = NULL;
|
||||||
|
|
||||||
if (!packet)
|
if (!packet)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
for (i = 0; options[i].code; ++i) {
|
||||||
|
if (options[i].code == code) {
|
||||||
|
opt = &options[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!opt)
|
||||||
|
return;
|
||||||
|
|
||||||
memset(buf, '\0', sizeof(buf));
|
memset(buf, '\0', sizeof(buf));
|
||||||
memset(buf2, '\0', sizeof(buf2));
|
memset(buf2, '\0', sizeof(buf2));
|
||||||
|
|
||||||
p = get_option(packet, options[opt].code);
|
p = get_option(packet, code);
|
||||||
if (fill_options(buf2, p, &options[opt], sizeof buf2 - 1) == -1)
|
if (fill_options(buf2, p, opt, sizeof buf2 - 1) == -1)
|
||||||
return;
|
return;
|
||||||
snprintf(buf, sizeof buf, "%s:", buf2);
|
snprintf(buf, sizeof buf, "%s:", buf2);
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
@ -221,14 +232,14 @@ static void bound_if(struct dhcpMessage *packet)
|
|||||||
snprintf(buf, sizeof buf, "ip:%s:", ip);
|
snprintf(buf, sizeof buf, "ip:%s:", ip);
|
||||||
sockwrite(sockfd, buf, strlen(buf));
|
sockwrite(sockfd, buf, strlen(buf));
|
||||||
|
|
||||||
translate_option(sockfd, packet, 0); // Subnet
|
translate_option(sockfd, packet, DHCP_SUBNET);
|
||||||
translate_option(sockfd, packet, 2); // Router
|
translate_option(sockfd, packet, DHCP_ROUTER);
|
||||||
translate_option(sockfd, packet, 5); // DNS
|
translate_option(sockfd, packet, DHCP_DNS_SERVER);
|
||||||
translate_option(sockfd, packet, 9); // Hostname
|
translate_option(sockfd, packet, DHCP_HOST_NAME);
|
||||||
translate_option(sockfd, packet, 11); // Domain
|
translate_option(sockfd, packet, DHCP_DOMAIN_NAME);
|
||||||
translate_option(sockfd, packet, 15); // MTU
|
translate_option(sockfd, packet, DHCP_MTU);
|
||||||
translate_option(sockfd, packet, 16); // Broadcast
|
translate_option(sockfd, packet, DHCP_BROADCAST);
|
||||||
translate_option(sockfd, packet, 17); // WINS
|
translate_option(sockfd, packet, DHCP_WINS_SERVER);
|
||||||
|
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
}
|
}
|
||||||
|
@ -22,23 +22,23 @@ enum {
|
|||||||
/* supported options are easily added here */
|
/* supported options are easily added here */
|
||||||
struct dhcp_option options[] = {
|
struct dhcp_option options[] = {
|
||||||
/* name[10] flags code */
|
/* name[10] flags code */
|
||||||
{"subnet" , OPTION_IP | OPTION_REQ, 0x01},
|
{"subnet" , OPTION_IP, 0x01},
|
||||||
{"timezone" , OPTION_S32, 0x02},
|
{"timezone" , OPTION_S32, 0x02},
|
||||||
{"router" , OPTION_IP | OPTION_LIST | OPTION_REQ, 0x03},
|
{"router" , OPTION_IP | OPTION_LIST, 0x03},
|
||||||
{"timesvr" , OPTION_IP | OPTION_LIST, 0x04},
|
{"timesvr" , OPTION_IP | OPTION_LIST, 0x04},
|
||||||
{"namesvr" , OPTION_IP | OPTION_LIST, 0x05},
|
{"namesvr" , OPTION_IP | OPTION_LIST, 0x05},
|
||||||
{"dns" , OPTION_IP | OPTION_LIST | OPTION_REQ, 0x06},
|
{"dns" , OPTION_IP | OPTION_LIST, 0x06},
|
||||||
{"logsvr" , OPTION_IP | OPTION_LIST, 0x07},
|
{"logsvr" , OPTION_IP | OPTION_LIST, 0x07},
|
||||||
{"cookiesvr", OPTION_IP | OPTION_LIST, 0x08},
|
{"cookiesvr", OPTION_IP | OPTION_LIST, 0x08},
|
||||||
{"lprsvr" , OPTION_IP | OPTION_LIST, 0x09},
|
{"lprsvr" , OPTION_IP | OPTION_LIST, 0x09},
|
||||||
{"hostname" , OPTION_STRING | OPTION_REQ, 0x0c},
|
{"hostname" , OPTION_STRING, 0x0c},
|
||||||
{"bootsize" , OPTION_U16, 0x0d},
|
{"bootsize" , OPTION_U16, 0x0d},
|
||||||
{"domain" , OPTION_STRING | OPTION_REQ, 0x0f},
|
{"domain" , OPTION_STRING, 0x0f},
|
||||||
{"swapsvr" , OPTION_IP, 0x10},
|
{"swapsvr" , OPTION_IP, 0x10},
|
||||||
{"rootpath" , OPTION_STRING, 0x11},
|
{"rootpath" , OPTION_STRING, 0x11},
|
||||||
{"ipttl" , OPTION_U8, 0x17},
|
{"ipttl" , OPTION_U8, 0x17},
|
||||||
{"mtu" , OPTION_U16, 0x1a},
|
{"mtu" , OPTION_U16, 0x1a},
|
||||||
{"broadcast", OPTION_IP | OPTION_REQ, 0x1c},
|
{"broadcast", OPTION_IP, 0x1c},
|
||||||
{"ntpsrv" , OPTION_IP | OPTION_LIST, 0x2a},
|
{"ntpsrv" , OPTION_IP | OPTION_LIST, 0x2a},
|
||||||
{"wins" , OPTION_IP | OPTION_LIST, 0x2c},
|
{"wins" , OPTION_IP | OPTION_LIST, 0x2c},
|
||||||
{"requestip", OPTION_IP, 0x32},
|
{"requestip", OPTION_IP, 0x32},
|
||||||
@ -46,6 +46,7 @@ struct dhcp_option options[] = {
|
|||||||
{"dhcptype" , OPTION_U8, 0x35},
|
{"dhcptype" , OPTION_U8, 0x35},
|
||||||
{"serverid" , OPTION_IP, 0x36},
|
{"serverid" , OPTION_IP, 0x36},
|
||||||
{"message" , OPTION_STRING, 0x38},
|
{"message" , OPTION_STRING, 0x38},
|
||||||
|
{"maxsize" , OPTION_U16, 0x39},
|
||||||
{"tftp" , OPTION_STRING, 0x42},
|
{"tftp" , OPTION_STRING, 0x42},
|
||||||
{"bootfile" , OPTION_STRING, 0x43},
|
{"bootfile" , OPTION_STRING, 0x43},
|
||||||
{"" , 0x00, 0x00}
|
{"" , 0x00, 0x00}
|
||||||
@ -249,18 +250,28 @@ struct option_set *find_option(struct option_set *opt_list, char code)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add a paramater request list for stubborn DHCP servers. Pull the data
|
// List of options that will be sent on the parameter request list to the
|
||||||
* from the struct in options.c. Don't do bounds checking here because it
|
// remote DHCP server.
|
||||||
* goes towards the head of the packet. */
|
static unsigned char req_opts[] = {
|
||||||
|
DHCP_SUBNET,
|
||||||
|
DHCP_ROUTER,
|
||||||
|
DHCP_DNS_SERVER,
|
||||||
|
DHCP_HOST_NAME,
|
||||||
|
DHCP_DOMAIN_NAME,
|
||||||
|
DHCP_BROADCAST,
|
||||||
|
0x00
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Add a paramater request list for stubborn DHCP servers. Don't do bounds */
|
||||||
|
/* checking here because it goes towards the head of the packet. */
|
||||||
void add_requests(struct dhcpMessage *packet)
|
void add_requests(struct dhcpMessage *packet)
|
||||||
{
|
{
|
||||||
int end = end_option(packet->options);
|
int end = end_option(packet->options);
|
||||||
int i, len = 0;
|
int i, len = 0;
|
||||||
|
|
||||||
packet->options[end + OPT_CODE] = DHCP_PARAM_REQ;
|
packet->options[end + OPT_CODE] = DHCP_PARAM_REQ;
|
||||||
for (i = 0; options[i].code; i++)
|
for (i = 0; req_opts[i]; i++)
|
||||||
if (options[i].flags & OPTION_REQ)
|
packet->options[end + OPT_DATA + len++] = req_opts[i];
|
||||||
packet->options[end + OPT_DATA + len++] = options[i].code;
|
|
||||||
packet->options[end + OPT_LEN] = len;
|
packet->options[end + OPT_LEN] = len;
|
||||||
packet->options[end + OPT_DATA + len] = DHCP_END;
|
packet->options[end + OPT_DATA + len] = DHCP_END;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,6 @@ enum {
|
|||||||
OPTION_S32
|
OPTION_S32
|
||||||
};
|
};
|
||||||
|
|
||||||
#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 */
|
#define OPTION_LIST 0x20 /* There can be a list of 1 or more of these */
|
||||||
|
|
||||||
struct dhcp_option {
|
struct dhcp_option {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user