Commit 70fcfb12 authored by Christian Spielberger's avatar Christian Spielberger Committed by Slava Monich

util: Add function __connman_util_random_delay_ms

ACD needs random IPv4 addresses as fallback (IPv4LL address) and random delays
between sent ARP probe and ARP announce packets. Hence, this patch moves
ipv4ll_random_delay_ms() to src/util.c in order to be available generally. It
replaces the calls of the obsolete function in gdhcp/client.c.

Conflicts:
	connman/Makefile.am
	connman/gdhcp/client.c
parent f2680621
......@@ -42,6 +42,10 @@ gdbus_libgdbus_internal_la_SOURCES = gdbus/gdbus.h \
gdbus/mainloop.c gdbus/watch.c \
gdbus/object.c gdbus/client.c gdbus/polkit.c
if BACKTRACE
backtrace_sources = src/backtrace.c
endif
gdhcp_sources = gdhcp/gdhcp.h gdhcp/common.h gdhcp/common.c gdhcp/client.c \
gdhcp/server.c gdhcp/ipv4ll.h gdhcp/ipv4ll.c gdhcp/unaligned.h
......@@ -397,12 +401,13 @@ tools_wpad_test_LDADD = @GLIB_LIBS@ -lresolv
tools_stats_tool_LDADD = @GLIB_LIBS@
tools_dhcp_test_SOURCES = $(gdhcp_sources) src/wakeup_timer.c tools/dhcp-test.c
tools_dhcp_test_LDADD = @GLIB_LIBS@
tools_dhcp_test_SOURCES = $(backtrace_sources) src/wakeup_timer.c src/log.c \
src/util.c $(gdhcp_sources) tools/dhcp-test.c
tools_dhcp_test_LDADD = @GLIB_LIBS@ -ldl
tools_dhcp_server_test_SOURCES = $(gdhcp_sources) src/wakeup_timer.c \
tools/dhcp-server-test.c
tools_dhcp_server_test_LDADD = @GLIB_LIBS@
tools_dhcp_server_test_SOURCES = $(backtrace_sources) src/log.c src/util.c \
$(gdhcp_sources) src/wakeup_timer.c tools/dhcp-server-test.c
tools_dhcp_server_test_LDADD = @GLIB_LIBS@ -ldl
tools_dbus_test_SOURCES = tools/dbus-test.c
tools_dbus_test_LDADD = gdbus/libgdbus-internal.la @GLIB_LIBS@ @DBUS_LIBS@
......
......@@ -43,6 +43,7 @@
#include <glib.h>
#include "../src/connman.h"
#include "gdhcp.h"
#include "common.h"
#include "ipv4ll.h"
......@@ -582,7 +583,7 @@ static gboolean send_probe_packet(gpointer dhcp_data)
if (dhcp_client->retry_times < PROBE_NUM) {
/*add a random timeout in range of PROBE_MIN to PROBE_MAX*/
timeout = ipv4ll_random_delay_ms(PROBE_MAX-PROBE_MIN);
timeout = __connman_util_random_delay_ms(PROBE_MAX-PROBE_MIN);
timeout += PROBE_MIN*1000;
} else
timeout = (ANNOUNCE_WAIT * 1000);
......@@ -1404,7 +1405,7 @@ static void ipv4ll_start(GDHCPClient *dhcp_client)
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);
timeout = __connman_util_random_delay_ms(PROBE_WAIT);
dhcp_client->retry_times++;
dhcp_client->timeout = connman_wakeup_timer_add_full(G_PRIORITY_HIGH,
......@@ -1494,7 +1495,7 @@ static int ipv4ll_recv_arp_packet(GDHCPClient *dhcp_client)
dhcp_client->retry_times++;
dhcp_client->timeout =
connman_wakeup_timer_add_full(G_PRIORITY_HIGH,
ipv4ll_random_delay_ms(PROBE_WAIT),
__connman_util_random_delay_ms(PROBE_WAIT),
send_probe_packet,
dhcp_client,
NULL);
......
......@@ -52,17 +52,6 @@ uint32_t ipv4ll_random_ip(void)
return ((LINKLOCAL_ADDR + 0x0100) + tmp);
}
/**
* Return a random delay in range of zero to secs*1000
*/
guint ipv4ll_random_delay_ms(guint secs)
{
uint64_t rand;
dhcp_get_random(&rand);
return rand % (secs * 1000);
}
int ipv4ll_send_arp_packet(uint8_t* source_eth, uint32_t source_ip,
uint32_t target_ip, int ifindex)
{
......
......@@ -44,7 +44,6 @@ extern "C" {
#define DEFEND_INTERVAL 10
uint32_t ipv4ll_random_ip(void);
guint ipv4ll_random_delay_ms(guint secs);
int ipv4ll_send_arp_packet(uint8_t* source_eth, uint32_t source_ip,
uint32_t target_ip, int ifindex);
int ipv4ll_arp_socket(int ifindex);
......
......@@ -1141,6 +1141,7 @@ enum connman_access __connman_access_tech_set_property
enum connman_access default_access);
int __connman_util_get_random(uint64_t *val);
unsigned int __connman_util_random_delay_ms(unsigned int secs);
int __connman_util_init(void);
void __connman_util_cleanup(void);
......
......@@ -86,3 +86,14 @@ void __connman_util_cleanup(void)
f = -1;
}
/**
* Return a random delay in range of zero to secs*1000 milli seconds.
*/
unsigned int __connman_util_random_delay_ms(unsigned int secs)
{
uint64_t rand;
__connman_util_get_random(&rand);
return rand % (secs * 1000);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment