Cache the last configured dhcp packet in ifchange.c. Only send updates that

differ from what already existed.
This commit is contained in:
Nicholas J. Kain 2011-07-04 21:40:32 -04:00
parent 9ef66af020
commit 88804e0102
2 changed files with 14 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/* ifchange.c - functions to call the interface change daemon
* Time-stamp: <2011-07-04 20:48:03 njk>
* Time-stamp: <2011-07-04 21:35:02 njk>
*
* (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
*
@ -39,6 +39,8 @@
#include "io.h"
#include "ifchange.h"
static struct dhcpmsg cfg_packet;
// Fill buf with the ifchd command text of option 'option'.
// Returns 0 if successful, -1 if nothing was filled in.
static int ifchd_cmd(char *buf, size_t buflen, uint8_t *option, ssize_t optlen,
@ -168,14 +170,16 @@ void ifchange_deconfig(void)
snprintf(buf, sizeof buf, "ip:0.0.0.0:");
sockwrite(sockfd, buf, strlen(buf));
memset(&cfg_packet, 0, sizeof cfg_packet);
close(sockfd);
}
static void send_cmd(int sockfd, struct dhcpmsg *packet, uint8_t code)
{
char buf[256];
uint8_t *optdata;
ssize_t optlen;
uint8_t *optdata, *olddata;
ssize_t optlen, oldlen;
if (!packet)
return;
@ -184,6 +188,9 @@ static void send_cmd(int sockfd, struct dhcpmsg *packet, uint8_t code)
optdata = get_option_data(packet, code, &optlen);
if (!optlen)
return;
olddata = get_option_data(&cfg_packet, code, &oldlen);
if (oldlen == optlen && !memcmp(optdata, olddata, optlen))
return;
if (ifchd_cmd(buf, sizeof buf, optdata, optlen, code) == -1)
return;
sockwrite(sockfd, buf, strlen(buf));
@ -216,5 +223,7 @@ void ifchange_bind(struct dhcpmsg *packet)
send_cmd(sockfd, packet, DHCP_BROADCAST);
send_cmd(sockfd, packet, DHCP_WINS_SERVER);
memcpy(&cfg_packet, packet, sizeof cfg_packet);
close(sockfd);
}

View File

@ -1,5 +1,5 @@
/* options.c - DHCP options handling
* Time-stamp: <2011-03-30 18:29:18 nk>
* Time-stamp: <2011-07-04 21:37:34 njk>
*
* (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
*
@ -162,7 +162,7 @@ static uint8_t *do_get_option_data(uint8_t *buf, ssize_t buflen, int code,
}
buf += buf[1] + 2;
}
log_warning("Bad dhcp data: unmarked end of options field");
// End of options field was unmarked: no option data
*optlen = 0;
return NULL;
}