Some options are never sent to ifchd, but we unfortunately would need to

sacrifice type checking to remove them from the options table.  It may
be worth doing that, but I want to audit each call point before.
This commit is contained in:
Nicholas J. Kain 2011-07-25 04:26:34 -04:00
parent e4a4c58856
commit 31d6d4cd92
5 changed files with 20 additions and 15 deletions

View File

@ -15,5 +15,6 @@
#define CMD_BROADCAST "bcast"
#define CMD_NTPSVR "ntp"
#define CMD_WINS "wins"
#define CMD_NULL "NULL"
#endif

View File

@ -504,7 +504,7 @@ static int validate_dhcp_packet(struct client_state_t *cs, int len,
return 0;
}
ssize_t optlen;
uint8_t *temp = get_option_data(packet, DCODE_MESSAGE_TYPE, &optlen);
uint8_t *temp = get_option_data(packet, DCODE_MSGTYPE, &optlen);
if (!temp) {
log_line("Packet does not specify a DHCP message type. Ignoring.");
return 0;
@ -584,7 +584,7 @@ static struct dhcpmsg init_packet(char type, uint32_t xid)
.options[0] = DCODE_END,
.xid = xid,
};
add_u8_option(&packet, DCODE_MESSAGE_TYPE, type);
add_u8_option(&packet, DCODE_MSGTYPE, type);
memcpy(packet.chaddr, client_config.arp, 6);
add_option_clientid(&packet);
return packet;
@ -594,7 +594,7 @@ int send_discover(struct client_state_t *cs)
{
struct dhcpmsg packet = init_packet(DHCPDISCOVER, cs->xid);
if (cs->clientAddr)
add_u32_option(&packet, DCODE_REQUESTED_IP, cs->clientAddr);
add_u32_option(&packet, DCODE_REQIP, cs->clientAddr);
add_u16_option(&packet, DCODE_MAX_SIZE,
htons(sizeof(struct ip_udp_dhcp_packet)));
add_option_request_list(&packet);
@ -608,7 +608,7 @@ int send_selecting(struct client_state_t *cs)
{
char clibuf[INET_ADDRSTRLEN];
struct dhcpmsg packet = init_packet(DHCPREQUEST, cs->xid);
add_u32_option(&packet, DCODE_REQUESTED_IP, cs->clientAddr);
add_u32_option(&packet, DCODE_REQIP, cs->clientAddr);
add_u32_option(&packet, DCODE_SERVER_ID, cs->serverAddr);
add_u16_option(&packet, DCODE_MAX_SIZE,
htons(sizeof(struct ip_udp_dhcp_packet)));
@ -638,7 +638,7 @@ int send_rebind(struct client_state_t *cs)
{
struct dhcpmsg packet = init_packet(DHCPREQUEST, cs->xid);
packet.ciaddr = cs->clientAddr;
add_u32_option(&packet, DCODE_REQUESTED_IP, cs->clientAddr);
add_u32_option(&packet, DCODE_REQIP, cs->clientAddr);
add_u16_option(&packet, DCODE_MAX_SIZE,
htons(sizeof(struct ip_udp_dhcp_packet)));
add_option_request_list(&packet);
@ -651,7 +651,7 @@ int send_rebind(struct client_state_t *cs)
int send_decline(struct client_state_t *cs, uint32_t server)
{
struct dhcpmsg packet = init_packet(DHCPDECLINE, cs->xid);
add_u32_option(&packet, DCODE_REQUESTED_IP, cs->clientAddr);
add_u32_option(&packet, DCODE_REQIP, cs->clientAddr);
add_u32_option(&packet, DCODE_SERVER_ID, server);
log_line("Sending a decline message...");
return send_dhcp_raw(&packet);
@ -661,7 +661,7 @@ int send_release(struct client_state_t *cs)
{
struct dhcpmsg packet = init_packet(DHCPRELEASE, libc_random_u32());
packet.ciaddr = cs->clientAddr;
add_u32_option(&packet, DCODE_REQUESTED_IP, cs->clientAddr);
add_u32_option(&packet, DCODE_REQIP, cs->clientAddr);
add_u32_option(&packet, DCODE_SERVER_ID, cs->serverAddr);
log_line("Sending a release message...");
return send_dhcp_cooked(cs, &packet);

View File

@ -40,8 +40,6 @@ struct dhcp_option {
char name[6];
};
#define DCODE_PADDING 0x00
// Marks an option that will be sent on the parameter request list to the
// remote DHCP server.
#define OPTION_REQ 16
@ -53,7 +51,6 @@ struct dhcp_option {
// useful part and helps for safety checks and determining what options to
// send in the initial DHCP option request packet.
static const struct dhcp_option options[] = {
// code type name
{DCODE_SUBNET , OPTION_IP | OPTION_LIST | OPTION_REQ, CMD_SUBNET },
{DCODE_TIMEZONE , OPTION_S32, CMD_TIMEZONE },
{DCODE_ROUTER , OPTION_IP | OPTION_REQ, CMD_ROUTER },
@ -66,7 +63,13 @@ static const struct dhcp_option options[] = {
{DCODE_BROADCAST, OPTION_IP | OPTION_REQ, CMD_BROADCAST},
{DCODE_NTPSVR , OPTION_IP | OPTION_LIST, CMD_NTPSVR },
{DCODE_WINS , OPTION_IP | OPTION_LIST, CMD_WINS },
{0x00 , OPTION_NONE, "NULL" }
// Past this point, these options are not useful for client configuration.
{DCODE_REQIP , OPTION_IP, CMD_NULL },
{DCODE_LEASET , OPTION_U32, CMD_NULL },
{DCODE_MSGTYPE , OPTION_U8, CMD_NULL },
{DCODE_SERVER_ID, OPTION_IP, CMD_NULL },
{DCODE_MAX_SIZE , OPTION_U16, CMD_NULL },
{0x00 , OPTION_NONE, CMD_NULL }
};
enum option_type option_type(uint8_t code)

View File

@ -30,6 +30,7 @@
#include "dhcp.h"
#define DCODE_PADDING 0x00
#define DCODE_SUBNET 0x01
#define DCODE_TIMEZONE 0x02
#define DCODE_ROUTER 0x03
@ -42,10 +43,10 @@
#define DCODE_BROADCAST 0x1c
#define DCODE_NTPSVR 0x2a
#define DCODE_WINS 0x2c
#define DCODE_REQUESTED_IP 0x32
#define DCODE_LEASE_TIME 0x33
#define DCODE_REQIP 0x32
#define DCODE_LEASET 0x33
#define DCODE_OVERLOAD 0x34
#define DCODE_MESSAGE_TYPE 0x35
#define DCODE_MSGTYPE 0x35
#define DCODE_SERVER_ID 0x36
#define DCODE_PARAM_REQ 0x37
#define DCODE_MAX_SIZE 0x39

View File

@ -219,7 +219,7 @@ static void an_packet(struct client_state_t *cs, struct dhcpmsg *packet,
if (!validate_serverid(cs, packet, "a DHCP ACK"))
return;
ssize_t optlen;
uint8_t *temp = get_option_data(packet, DCODE_LEASE_TIME, &optlen);
uint8_t *temp = get_option_data(packet, DCODE_LEASET, &optlen);
cs->leaseStartTime = curms();
if (!temp) {
log_line("No lease time received, assuming 1h.");