uint32_t server, uint32_t ciaddr)
{
struct dhcp_packet packet;
+ uint64_t rand;
debug(dhcp_client, "sending DHCP release request");
init_packet(dhcp_client, &packet, DHCPRELEASE);
- packet.xid = rand();
+ dhcp_get_random(&rand);
+ packet.xid = rand;
packet.ciaddr = htonl(ciaddr);
dhcp_add_option_uint32(&packet, DHCP_SERVER_ID, server);
/* if requested_ip is not valid, pick a new address*/
if (dhcp_client->requested_ip == 0) {
debug(dhcp_client, "pick a new random address");
- dhcp_client->requested_ip = ipv4ll_random_ip(0);
+ dhcp_client->requested_ip = ipv4ll_random_ip();
}
debug(dhcp_client, "sending IPV4LL probe request");
static void ipv4ll_start(GDHCPClient *dhcp_client)
{
guint timeout;
- int seed;
remove_timeouts(dhcp_client);
dhcp_client->retry_times = 0;
dhcp_client->requested_ip = 0;
- /*try to start with a based mac address ip*/
- seed = (dhcp_client->mac_address[4] << 8 | dhcp_client->mac_address[4]);
- dhcp_client->requested_ip = ipv4ll_random_ip(seed);
+ dhcp_client->requested_ip = ipv4ll_random_ip();
/*first wait a random delay to avoid storm of arp request on boot*/
timeout = ipv4ll_random_delay_ms(PROBE_WAIT);
static gboolean continue_rebound(gpointer user_data)
{
GDHCPClient *dhcp_client = user_data;
+ uint64_t rand;
switch_listening_mode(dhcp_client, L2);
send_request(dhcp_client);
/*recalculate remaining rebind time*/
dhcp_client->T2 >>= 1;
if (dhcp_client->T2 > 60) {
+ dhcp_get_random(&rand);
dhcp_client->t2_timeout =
g_timeout_add_full(G_PRIORITY_HIGH,
- dhcp_client->T2 * 1000 + (rand() % 2000) - 1000,
+ dhcp_client->T2 * 1000 + (rand % 2000) - 1000,
continue_rebound,
dhcp_client,
NULL);
static gboolean continue_renew (gpointer user_data)
{
GDHCPClient *dhcp_client = user_data;
+ uint64_t rand;
switch_listening_mode(dhcp_client, L3);
send_request(dhcp_client);
dhcp_client->T1 >>= 1;
if (dhcp_client->T1 > 60) {
+ dhcp_get_random(&rand);
dhcp_client->t1_timeout = g_timeout_add_full(G_PRIORITY_HIGH,
- dhcp_client->T1 * 1000 + (rand() % 2000) - 1000,
+ dhcp_client->T1 * 1000 + (rand % 2000) - 1000,
continue_renew,
dhcp_client,
NULL);
rapid_commit = dhcpv6_get_option(packet6, pkt_len,
G_DHCPV6_RAPID_COMMIT,
&option_len, &count);
- if (!rapid_commit || option_len == 0 ||
+ if (!rapid_commit || option_len != 0 ||
count != 1)
/* RFC 3315, 17.1.4 */
return TRUE;
{
int re;
uint32_t addr;
+ uint64_t rand;
if (dhcp_client->type == G_DHCP_IPV6) {
if (dhcp_client->information_req_cb) {
if (re != 0)
return re;
- dhcp_client->xid = rand();
+ dhcp_get_random(&rand);
+ dhcp_client->xid = rand;
dhcp_client->start = time(NULL);
}
return dhcp_client->ifindex;
}
+char *g_dhcp_client_get_server_address(GDHCPClient *dhcp_client)
+{
+ if (!dhcp_client)
+ return NULL;
+
+ return get_ip(dhcp_client->server_ip);
+}
+
char *g_dhcp_client_get_address(GDHCPClient *dhcp_client)
{
return g_strdup(dhcp_client->assigned_ip);