Hi Christian,
On 04/11/2018 04:00 PM, Christian Spielberger wrote:
Adds a dbus property called LastAddressConflict and a signal to
notify if
the property changes.
s/dbus/D-Bus/
--- > doc/service-api.txt | 32 ++++++++++++++++++++
include/acd.h | 5 +++-
include/network.h | 4 +++
include/service.h | 1 +
src/acd.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
src/network.c | 12 +++++++-
src/service.c | 11 +++++++
7 files changed, 146 insertions(+), 3 deletions(-)
diff --git a/doc/service-api.txt b/doc/service-api.txt
index b5b4fab..ac597bc 100644
--- a/doc/service-api.txt
+++ b/doc/service-api.txt
@@ -513,3 +513,35 @@ Properties string State [readonly]
Same values as mDNS property. The mDNS
represents the actual system configuration
while this allows user configuration.
+
+ dict LastAddressConflict [readonly]
+
+ This property contains information about the previously detected
+ address conflict. If there has been no address conflict then
+ IPv4 Address is "0.0.0.0", Ethernet Address is
"00:00:00:00:00:00",
+ Timestamp is zero and Resolved is true.
+
+ dict IPv4 [readonly]
+
+ string Address [readonly]
+
+ The IPv4 address which had a conflict.
+
+ dict Ethernet [readonly]
+
+ string Address [readonly]
+
+ The ethernet device address (MAC address) of the conflicting
+ host.
+
+ int64 Timestamp [readonly]
+
+ A timestamp when the conflict was detected in microseconds
+ since January 1, 1970 UTC.
+
+ bool Resolved [readonly]
+
+ Set to false when an address conflict occurs.
+ If a previous conflict could be resolved by probing another
+ IPv4 address (which is not an IPv4LL) then this boolean is set
+ to true.
diff --git a/include/acd.h b/include/acd.h
index dc7e570..69d740d 100644
--- a/include/acd.h
+++ b/include/acd.h
@@ -25,6 +25,7 @@
#include <stdint.h>
#include <glib.h>
+#include <gdbus.h>
This include looks wrong. I don't think we export the gdbus.h header
file and I don't see why you need.
#ifdef __cplusplus
extern "C" {
@@ -34,7 +35,7 @@ struct _acd_host;
typedef struct _acd_host acd_host;
-acd_host *acdhost_new(int ifindex);
+acd_host *acdhost_new(int ifindex, const char* path);
int acdhost_start(acd_host *acd, uint32_t ip);
void acdhost_stop(acd_host *acd);
@@ -52,6 +53,8 @@ void acdhost_register_event(acd_host *acd,
ACDHostEventFunc func,
gpointer user_data);
+void acdhost_append_dbus_property(acd_host *acd, DBusMessageIter *dict);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/network.h b/include/network.h
index 4fc20c1..22463cc 100644
--- a/include/network.h
+++ b/include/network.h
@@ -24,6 +24,7 @@
#include <stdbool.h>
#include <stdint.h>
empty line here
+#include <dbus/dbus.h>
#include <connman/device.h>
#include <connman/ipconfig.h>
@@ -162,6 +163,9 @@ struct connman_network_driver {
int connman_network_driver_register(struct connman_network_driver *driver);
void connman_network_driver_unregister(struct connman_network_driver *driver);
+void connman_network_append_acddbus(DBusMessageIter *dict,
+ struct connman_network *network);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/service.h b/include/service.h
index 958e7fd..c958375 100644
--- a/include/service.h
+++ b/include/service.h
@@ -117,6 +117,7 @@ enum connman_service_type connman_service_get_type(struct
connman_service *servi
char *connman_service_get_interface(struct connman_service *service);
const char *connman_service_get_domainname(struct connman_service *service);
+const char *connman_service_get_dbuspath(struct connman_service *service);
char **connman_service_get_nameservers(struct connman_service *service);
char **connman_service_get_timeservers_config(struct connman_service *service);
char **connman_service_get_timeservers(struct connman_service *service);
diff --git a/src/acd.c b/src/acd.c
index cdd2569..f10e3d7 100644
--- a/src/acd.c
+++ b/src/acd.c
@@ -21,6 +21,7 @@
#include <connman/log.h>
#include <connman/inet.h>
#include <glib.h>
+#include <connman/dbus.h>
group the header file with the other connman includes.
#include "src/shared/arp.h"
#include "src/shared/random.h"
#include <errno.h>
@@ -52,6 +53,13 @@ struct _acd_host {
uint8_t mac_address[6];
uint32_t requested_ip; /* host byte order */
+ /* address conflict fields */
+ uint32_t ac_ip; /* host byte order */
+ uint8_t ac_mac[6];
+ gint64 ac_timestamp;
+ bool ac_resolved;
+ const char *path;
+
bool listen_on;
int listener_sockfd;
unsigned int retry_times;
@@ -80,6 +88,9 @@ static gboolean send_announce_packet(gpointer acd_data);
static gboolean acd_announce_timeout(gpointer acd_data);
static gboolean acd_defend_timeout(gpointer acd_data);
+/* for DBus property */
s/DBus/D-Bus/
+static void report_conflict(acd_host *acd);
+
static void debug(acd_host *acd, const char *format, ...)
{
char str[256];
@@ -93,7 +104,7 @@ static void debug(acd_host *acd, const char *format, ...)
va_end(ap);
}
-acd_host *acdhost_new(int ifindex)
+acd_host *acdhost_new(int ifindex, const char *path)
{
acd_host *acd;
@@ -133,6 +144,12 @@ acd_host *acdhost_new(int ifindex)
acd->ipv4_conflict_cb = NULL;
acd->ipv4_max_conflicts_cb = NULL;
+ acd->ac_ip = 0;
+ memset(acd->ac_mac, 0, sizeof(acd->ac_mac));
+ acd->ac_timestamp = 0;
+ acd->ac_resolved = true;
+ acd->path = path;
+
return acd;
error:
@@ -346,6 +363,11 @@ static gboolean acd_defend_timeout(gpointer acd_data)
return FALSE;
}
+static bool is_link_local(uint32_t ip)
+{
+ return (ip & LINKLOCAL_ADDR) == LINKLOCAL_ADDR;
+}
+
static gboolean acd_announce_timeout(gpointer acd_data)
{
acd_host *acd = acd_data;
@@ -362,6 +384,11 @@ static gboolean acd_announce_timeout(gpointer acd_data)
debug(acd, "switching to monitor mode");
acd->state = ACD_MONITOR;
+ if (!acd->ac_resolved && !is_link_local(acd->requested_ip)) {
+ acd->ac_resolved = true;
+ report_conflict(acd);
+ }
+
if (acd->ipv4_available_cb)
acd->ipv4_available_cb(acd,
acd->ipv4_available_data);
@@ -438,6 +465,14 @@ static int acd_recv_arp_packet(acd_host *acd) {
}
if (acd->conflicts < MAX_CONFLICTS) {
+ if (!is_link_local(acd->requested_ip)) {
+ acd->ac_ip = acd->requested_ip;
+ memcpy(acd->ac_mac, arp.arp_sha, sizeof(acd->ac_mac));
+ acd->ac_timestamp = g_get_real_time();
+ acd->ac_resolved = false;
+ report_conflict(acd);
+ }
+
acdhost_stop(acd);
/* we need a new request_ip */
@@ -483,3 +518,50 @@ void acdhost_register_event(acd_host *acd,
}
}
+static void append_ac_mac(DBusMessageIter *iter, void *user_data)
+{
+ acd_host *acd = user_data;
+ char mac[32];
+ uint8_t *m = acd->ac_mac;
+ const char *str = mac;
empty line here between decleration and implementation.
+ snprintf(mac, sizeof(mac),
"%02x:%02x:%02x:%02x:%02x:%02x",
+ m[0], m[1], m[2], m[3], m[4], m[5]);
+ connman_dbus_dict_append_basic(iter, "Address", DBUS_TYPE_STRING, &str);
+}
+
Thanks,
Daniel