X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fip-conflict-detect.c;h=b941e5e685219beb120a2c23360cf81d3589f6d0;hb=46a7bfcb29ca7642cae080ca393cf145d15fb232;hp=fab3976274821e6317a87efcf612a4caae8118bb;hpb=e78da8e36da620e75fcb5f37888704ec4ca1248a;p=platform%2Fcore%2Fconnectivity%2Fnet-config.git diff --git a/src/ip-conflict-detect.c b/src/ip-conflict-detect.c index fab3976..b941e5e 100755 --- a/src/ip-conflict-detect.c +++ b/src/ip-conflict-detect.c @@ -94,7 +94,7 @@ static struct timer_data td = { int ioctl_sock; static bool initial_bursts = true; -bool is_ip_conflict_detect_enabled = true; +bool is_ip_conflict_detect_enabled = false; static gboolean send_arp(gpointer data); static void __netconfig_wifi_notify_ip_conflict(char *state, char *mac); ip_conflict_state_e conflict_state = NETCONFIG_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED; @@ -127,8 +127,6 @@ static gboolean __arp_reply_timeout_cb(gpointer data) sd->iteration++; sd->arp_reply_timer = -1; - if (sd->timer_id != -1) - g_source_remove(sd->timer_id); if (conflict_state != NETCONFIG_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED && sd->iteration == CONFLICT_REMOVE_ITERATION_LIMIT) { @@ -138,6 +136,8 @@ static gboolean __arp_reply_timeout_cb(gpointer data) initial_bursts = true; } + if (sd->timer_id > 0) + g_source_remove(sd->timer_id); sd->timer_id = g_timeout_add(sd->timeout, send_arp, sd); return G_SOURCE_REMOVE; } @@ -228,6 +228,7 @@ static gboolean send_arp(gpointer data) int ifindex = 0; errno = 0; const char *default_ip = NULL; + const char *if_name = NULL; static int initial_send_arp_count = 0; if (initial_bursts && initial_send_arp_count >= INITIAL_BURST_ARP_COUNT) { @@ -274,7 +275,14 @@ static gboolean send_arp(gpointer data) memset(&net_ifr, 0, sizeof(net_ifr)); /* ifreq structure creation */ - size_t if_name_len = strlen(netconfig_get_default_ifname()); + if_name = netconfig_get_default_ifname(); + size_t if_name_len = strlen(if_name); + + if (if_name_len == 0) { + INFO("Error : Unable to get interface name "); + goto err; + } + if (if_name_len < sizeof(net_ifr.ifr_name)) { memcpy(net_ifr.ifr_name, netconfig_get_default_ifname(), if_name_len); net_ifr.ifr_name[if_name_len] = 0; @@ -284,8 +292,8 @@ static gboolean send_arp(gpointer data) } if (ioctl(sd->chk_conflict_sd, SIOCGIFINDEX, &net_ifr) == -1) { - strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER); - INFO("ioctl Failed. Error..... = %s\n", error_buf); + INFO("ioctl Failed. Error..... = %s\n", + strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER)); goto err; } @@ -298,8 +306,8 @@ static gboolean send_arp(gpointer data) memcpy(addr.sll_addr, broadcast_addr, ETHER_ADDR_LEN); if (sendto(sd->chk_conflict_sd, &arp, sizeof(arp), 0, (struct sockaddr*)&addr, sizeof(addr)) < 0) { - strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER); - INFO("Sending ARP Packet Failed. Error. = %s\n", error_buf); + INFO("Sending ARP Packet Failed. Error. = %s\n", + strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER)); /* close socket */ if (-1 < sd->chk_conflict_sd) { close(sd->chk_conflict_sd); @@ -309,8 +317,8 @@ static gboolean send_arp(gpointer data) /* reopen socket */ if ((sd->chk_conflict_sd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ARP))) == -1) { INFO("socket %d", sd->chk_conflict_sd); - strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER); - INFO("socket Failed. Error = %s\n", error_buf); + INFO("socket Failed. Error = %s\n", + strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER)); } goto err; } else { @@ -318,6 +326,7 @@ static gboolean send_arp(gpointer data) } g_source_remove(sd->timer_id); + sd->timer_id = 0; if (conflict_state == NETCONFIG_IP_CONFLICT_STATE_CONFLICT_DETECTED || initial_bursts) sd->timeout = BURST_ARP_SEND_TIME; @@ -337,8 +346,8 @@ err: struct sock_data * start_ip_conflict_mon(void) { - if (is_ip_conflict_detect_enabled == false) { - INFO("detection mode is set to false"); + if (is_ip_conflict_detect_enabled == true) { + INFO("detection mode is set to true"); return NULL; } @@ -356,8 +365,8 @@ struct sock_data * start_ip_conflict_mon(void) sd->iteration = 0; if ((sd->chk_conflict_sd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ARP))) == -1) { - strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER); - INFO("socket Failed. Error = %s\n", error_buf); + INFO("socket Failed. Error = %s\n", + strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER)); g_free(sd); return NULL; } else { @@ -383,6 +392,8 @@ struct sock_data * start_ip_conflict_mon(void) sd->timeout = td.initial_time; send_arp(sd); + is_ip_conflict_detect_enabled = true; + conflict_state = NETCONFIG_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED; return sd; } } @@ -414,6 +425,8 @@ void stop_ip_conflict_mon() } g_free(sd); sd = NULL; + is_ip_conflict_detect_enabled = false; + conflict_state = NETCONFIG_IP_CONFLICT_STATE_UNKNOWN; INFO("Monitoring stopped"); } @@ -444,8 +457,6 @@ gboolean handle_ip_conflict_set_enable(Wifi *wifi, GDBusMethodInvocation *contex if (detect == false) { - is_ip_conflict_detect_enabled = false; - conflict_state = NETCONFIG_IP_CONFLICT_STATE_UNKNOWN; if (sd != NULL) stop_ip_conflict_mon(); else { @@ -454,8 +465,6 @@ gboolean handle_ip_conflict_set_enable(Wifi *wifi, GDBusMethodInvocation *contex return TRUE; } } else { - is_ip_conflict_detect_enabled = true; - conflict_state = NETCONFIG_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED; if (sd == NULL) { if (start_ip_conflict_mon() == NULL) { INFO("Failed to start IP conflict monitoring"); @@ -487,7 +496,8 @@ gboolean handle_is_ip_conflict_detect_enabled(Wifi *wifi, GDBusMethodInvocation gboolean handle_set_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *context, guint initial_time) { g_return_val_if_fail(wifi != NULL, TRUE); - if (initial_time < MAX_ARP_SEND_TIME && initial_time > MIN_ARP_SEND_TIME) { + INFO("%d", initial_time); + if (initial_time > MAX_ARP_SEND_TIME || initial_time < MIN_ARP_SEND_TIME) { netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "Failed"); return TRUE;