Merge "Change default period of ARP probe to 20 seconds" into tizen
[platform/core/connectivity/net-config.git] / src / ip-conflict-detect.c
index 7169398..a12c3ed 100755 (executable)
 #define MAC_ADDRESS_LENGTH 6
 #define WLAN_MAC_ADDR_MAX 20
 #define ARP_SOURCE_IP "0.0.0.0"
+#define INITIAL_BURST_ARP_COUNT 5
 
-#define MIN_ARP_SEND_TIME 2000
+#define CONFLICT_REMOVE_ITERATION_LIMIT 4
+#define MIN_ARP_SEND_TIME 20000
+#define BURST_ARP_SEND_TIME 3000
 #define MAX_ARP_SEND_TIME 32000
 #define GRATUITOUS_ARP_MAC_ADDR "00:00:00:00:00:00"
 #define UCHAR_TO_ADDRESS(hwaddr, buf) do {\
@@ -90,6 +93,7 @@ static struct timer_data td = {
 };
 
 int ioctl_sock;
+static bool initial_bursts = true;
 bool is_ip_conflict_detect_enabled = true;
 static gboolean send_arp(gpointer data);
 static void __netconfig_wifi_notify_ip_conflict(char *state, char *mac);
@@ -126,10 +130,12 @@ static gboolean __arp_reply_timeout_cb(gpointer data)
        if (sd->timer_id != -1)
                g_source_remove(sd->timer_id);
 
-       if (conflict_state != NETCONFIG_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED && sd->iteration == 5) {
+       if (conflict_state != NETCONFIG_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED &&
+                       sd->iteration == CONFLICT_REMOVE_ITERATION_LIMIT) {
                sd->iteration = 0;
                conflict_state = NETCONFIG_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED;
                __netconfig_wifi_notify_ip_conflict("resolved", GRATUITOUS_ARP_MAC_ADDR);
+               initial_bursts = true;
        }
 
        sd->timer_id = g_timeout_add(sd->timeout, send_arp, sd);
@@ -189,6 +195,7 @@ skip:
                                INFO("ip conflict is detected !\n");
                                conflict_state = NETCONFIG_IP_CONFLICT_STATE_CONFLICT_DETECTED;
                                __netconfig_wifi_notify_ip_conflict("conflict", sbuf);
+                               sd->timeout = BURST_ARP_SEND_TIME;
                        }
 
                        if (sd->arp_reply_timer != -1) {
@@ -221,6 +228,15 @@ static gboolean send_arp(gpointer data)
        int ifindex = 0;
        errno = 0;
        const char *default_ip = NULL;
+       static int initial_send_arp_count = 0;
+
+       if (initial_bursts && initial_send_arp_count >= INITIAL_BURST_ARP_COUNT) {
+               initial_bursts = false;
+               initial_send_arp_count = 0;
+       }
+
+       if (initial_bursts)
+               initial_send_arp_count++;
 
        const char *mac = netconfig_get_default_mac_address();
        if (mac == NULL)
@@ -303,7 +319,10 @@ static gboolean send_arp(gpointer data)
 
        g_source_remove(sd->timer_id);
 
-       sd->timeout = td.initial_time;
+       if (conflict_state == NETCONFIG_IP_CONFLICT_STATE_CONFLICT_DETECTED || initial_bursts)
+               sd->timeout = BURST_ARP_SEND_TIME;
+       else
+               sd->timeout = td.initial_time;
 
        /* Adding timeout callback for arp request */
        sd->arp_reply_timer = g_timeout_add(1000, __arp_reply_timeout_cb,
@@ -324,6 +343,7 @@ struct sock_data * start_ip_conflict_mon(void)
        }
 
        char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
+       initial_bursts = true;
 
        sd = g_try_malloc0(sizeof(struct sock_data));
        if (sd == NULL) {