#include <unistd.h>
#include <stdbool.h>
+#include "netdbus.h"
#include "ip-conflict-detect.h"
#include "network-state.h"
#include "log.h"
int ioctl_sock;
static bool initial_bursts = true;
bool is_ip_conflict_detect_enabled = false;
+bool is_ip_conflict_detect_running = false;
static gboolean send_arp(gpointer data);
-static void __netconfig_wifi_notify_ip_conflict(char *state, char *mac);
+static void __netconfig_wifi_notify_ip_conflict(const char *interface_name,
+ char *state, char *mac);
ip_conflict_state_e conflict_state = NETCONFIG_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED;
struct sock_data *sd;
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);
+ __netconfig_wifi_notify_ip_conflict(netconfig_get_default_ifname(),
+ "resolved", GRATUITOUS_ARP_MAC_ADDR);
initial_bursts = true;
}
int zero_mac = strcmp(tbuf , GRATUITOUS_ARP_MAC_ADDR);
if (zero_mac == 0) {
- DBG("Broadcast packet.\n");
+ DBG("Broadcast packet.");
goto skip;
}
DBG("our mac= %s source mac= %s target mac= %s", netconfig_get_default_mac_address(), sbuf, tbuf);
mac_cmp = strcmp(tbuf , netconfig_get_default_mac_address());
if (mac_cmp != 0) {
- INFO("Packet not intended to us.\n");
+ INFO("Packet not intended to us.");
goto out;
}
skip:
if ((mac_cmp != 0) && (__convert_uchar_to_uint(arp_recv.s_IPaddr) == target_ip)) {
sd->iteration = 0;
if (conflict_state != NETCONFIG_IP_CONFLICT_STATE_CONFLICT_DETECTED) {
- INFO("ip conflict is detected !\n");
+ INFO("ip conflict is detected !");
conflict_state = NETCONFIG_IP_CONFLICT_STATE_CONFLICT_DETECTED;
- __netconfig_wifi_notify_ip_conflict("conflict", sbuf);
+ __netconfig_wifi_notify_ip_conflict(
+ netconfig_get_default_ifname(),
+ "conflict", sbuf);
sd->timeout = BURST_ARP_SEND_TIME;
}
return -1;
if ((sd->chk_conflict_sd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ARP))) == -1) {
- INFO("socket Failed.\n");
+ INFO("socket Failed.");
return -1;
}
}
if (ioctl(sd->chk_conflict_sd, SIOCGIFINDEX, &net_ifr) == -1) {
- INFO("ioctl Failed. Error..... = %s\n",
+ INFO("ioctl Failed. Error..... = %s",
strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
goto err;
}
if (sendto(sd->chk_conflict_sd, &arp, sizeof(arp), 0,
(struct sockaddr*)&addr, sizeof(addr)) < 0) {
- INFO("Sending ARP Packet Failed. Error. = %s\n",
+ INFO("Sending ARP Packet Failed. Error. = %s",
strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
__close_channel_and_sock(sd);
if (__open_channel_and_sock(sd) == -1)
INFO("__open_channel_and_sock failed");
goto err;
} else {
- DBG("Sent ARP Packet \n");
+ /* DBG("Sent ARP Packet"); */
}
if (sd->timer_id) {
struct sock_data * start_ip_conflict_mon(void)
{
- if (is_ip_conflict_detect_enabled == true) {
+ if (is_ip_conflict_detect_enabled == false) {
+ INFO("ip_conflict_detect is disabled");
+ return NULL;
+ }
+
+ if (is_ip_conflict_detect_running == true) {
INFO("detection mode is set to true");
return NULL;
}
sd->timeout = td.initial_time;
send_arp(sd);
- is_ip_conflict_detect_enabled = true;
+ is_ip_conflict_detect_running = true;
conflict_state = NETCONFIG_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED;
return sd;
}
g_free(sd);
sd = NULL;
- is_ip_conflict_detect_enabled = false;
+ is_ip_conflict_detect_running = false;
conflict_state = NETCONFIG_IP_CONFLICT_STATE_UNKNOWN;
INFO("Monitoring stopped");
}
-static void __netconfig_wifi_notify_ip_conflict(char *state, char *mac)
+static void __netconfig_wifi_notify_ip_conflict(const char *interface_name,
+ char *state, char *mac)
{
GVariantBuilder *builder = NULL;
g_variant_builder_add(builder, "{sv}", "state", g_variant_new_string(state));
g_variant_builder_add(builder, "{sv}", "mac", g_variant_new_string(mac));
- wifi_emit_ip_conflict_event((Wifi *)get_wifi_object(), g_variant_builder_end(builder));
+ wifi_emit_ip_conflict_event((Wifi *)get_wifi_object(),
+ interface_name, g_variant_builder_end(builder));
g_variant_builder_unref(builder);
/* send notification using net-popup */
}
gboolean handle_ip_conflict_set_enable(Wifi *wifi, GDBusMethodInvocation *context,
- bool detect)
+ const gchar *ifname, bool detect)
{
g_return_val_if_fail(wifi != NULL, TRUE);
if (detect == false) {
- if (sd != NULL)
+ if (is_ip_conflict_detect_enabled == true) {
stop_ip_conflict_mon();
- else {
+ is_ip_conflict_detect_enabled = false;
+ } else {
netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "AlreadyExists");
return TRUE;
}
} else {
- if (sd == NULL) {
- if (start_ip_conflict_mon() == NULL) {
- INFO("Failed to start IP conflict monitoring");
- netconfig_error_dbus_method_return(context,
- NETCONFIG_ERROR_INTERNAL, "Failed");
- return TRUE;
+ if (is_ip_conflict_detect_enabled == false) {
+ is_ip_conflict_detect_enabled = true;
+ const char *def_profile = netconfig_get_default_profile();
+ if (netconfig_is_wifi_profile(def_profile) ||
+ netconfig_is_ethernet_profile(def_profile)) {
+ if (start_ip_conflict_mon() == NULL) {
+ INFO("Failed to start IP conflict monitoring");
+ netconfig_error_dbus_method_return(context,
+ NETCONFIG_ERROR_INTERNAL, "Failed");
+ return TRUE;
+ }
}
} else {
netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "AlreadyExists");
return TRUE;
}
-gboolean handle_is_ip_conflict_detect_enabled(Wifi *wifi, GDBusMethodInvocation *context)
+gboolean handle_is_ip_conflict_detect_enabled(Wifi *wifi, GDBusMethodInvocation *context,
+ const gchar *ifname)
{
g_return_val_if_fail(wifi != NULL, TRUE);
GVariant *param = NULL;
return TRUE;
}
-gboolean handle_set_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *context, guint initial_time)
+gboolean handle_set_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *context,
+ const gchar *ifname, guint initial_time)
{
g_return_val_if_fail(wifi != NULL, TRUE);
INFO("%d", initial_time);
return TRUE;
}
-gboolean handle_get_ip_conflict_state(Wifi *wifi, GDBusMethodInvocation *context)
+gboolean handle_get_ip_conflict_state(Wifi *wifi, GDBusMethodInvocation *context,
+ const gchar *ifname)
{
g_return_val_if_fail(wifi != NULL, TRUE);
GVariant *param = NULL;
return TRUE;
}
-gboolean handle_get_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *context)
+gboolean handle_get_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *context,
+ const gchar *ifname)
{
g_return_val_if_fail(wifi != NULL, TRUE);
GVariant *param = NULL;