diff options
author | Christian Spielberger <christian.spielberger@gmail.com> | 2018-05-15 12:35:08 +0200 |
---|---|---|
committer | Daniel Wagner <wagi@monom.org> | 2018-05-24 22:17:38 +0200 |
commit | 9c8e700742598316aae7e13ed3737b5dddab5ac6 (patch) | |
tree | ef9bf7d7622c998d38690131278c7b095bff78b6 | |
parent | 026ec02f78e9812a907044013095afbd4c5138ba (diff) | |
download | connman-9c8e700742598316aae7e13ed3737b5dddab5ac6.tar.gz |
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.
-rw-r--r-- | Makefile.am | 14 | ||||
-rw-r--r-- | gdhcp/client.c | 7 | ||||
-rw-r--r-- | gdhcp/ipv4ll.c | 11 | ||||
-rw-r--r-- | gdhcp/ipv4ll.h | 1 | ||||
-rw-r--r-- | src/connman.h | 1 | ||||
-rw-r--r-- | src/util.c | 11 |
6 files changed, 26 insertions, 19 deletions
diff --git a/Makefile.am b/Makefile.am index c94164f7..edd19697 100644 --- a/Makefile.am +++ b/Makefile.am @@ -32,6 +32,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 @@ -355,11 +359,13 @@ tools_wpad_test_LDADD = @GLIB_LIBS@ -lresolv tools_stats_tool_LDADD = @GLIB_LIBS@ -tools_dhcp_test_SOURCES = $(gdhcp_sources) tools/dhcp-test.c -tools_dhcp_test_LDADD = @GLIB_LIBS@ +tools_dhcp_test_SOURCES = $(backtrace_sources) 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) 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) 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@ diff --git a/gdhcp/client.c b/gdhcp/client.c index 67357782..1f01b575 100644 --- a/gdhcp/client.c +++ b/gdhcp/client.c @@ -43,6 +43,7 @@ #include <glib.h> +#include "../src/connman.h" #include "gdhcp.h" #include "common.h" #include "ipv4ll.h" @@ -556,7 +557,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); @@ -1376,7 +1377,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 = g_timeout_add_full(G_PRIORITY_HIGH, @@ -1466,7 +1467,7 @@ static int ipv4ll_recv_arp_packet(GDHCPClient *dhcp_client) dhcp_client->retry_times++; dhcp_client->timeout = g_timeout_add_full(G_PRIORITY_HIGH, - ipv4ll_random_delay_ms(PROBE_WAIT), + __connman_util_random_delay_ms(PROBE_WAIT), send_probe_packet, dhcp_client, NULL); diff --git a/gdhcp/ipv4ll.c b/gdhcp/ipv4ll.c index d9001987..10bbc763 100644 --- a/gdhcp/ipv4ll.c +++ b/gdhcp/ipv4ll.c @@ -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) { diff --git a/gdhcp/ipv4ll.h b/gdhcp/ipv4ll.h index bee8138a..bf8c3636 100644 --- a/gdhcp/ipv4ll.h +++ b/gdhcp/ipv4ll.h @@ -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); diff --git a/src/connman.h b/src/connman.h index 82e77d37..8f8d26a3 100644 --- a/src/connman.h +++ b/src/connman.h @@ -1072,5 +1072,6 @@ int __connman_machine_init(void); void __connman_machine_cleanup(void); 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); @@ -91,3 +91,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); +} |