Send connman mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.01.org/mailman/listinfo/connman
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."
Today's Topics:
1. [PATCH 02/27] dhcp: Use shared get_random() function
(Christian Spielberger)
2. [PATCH 01/27] shared: Add functions for random number
generation (Christian Spielberger)
3. [PATCH v2 00/27] implement Address Conflict Detection
(Christian Spielberger)
4. [PATCH 03/27] shared: Add low-level ARP functions
(Christian Spielberger)
----------------------------------------------------------------------
Message: 1
Date: Wed, 11 Apr 2018 16:00:22 +0200
From: Christian Spielberger <[email protected]>
To: Daniel Wagner <[email protected]>
Cc: [email protected], Christian Spielberger
<[email protected]>
Subject: [PATCH 02/27] dhcp: Use shared get_random() function
Message-ID:
<[email protected]>
In gdhcp replace local functions for random number generation by new shared
functions. So dhcp_get_random() and dhcp_cleanup_random() are removed and
replaced by get_random() and cleanup_random().
---
gdhcp/client.c | 8 ++++----
gdhcp/common.c | 39 ++-------------------------------------
gdhcp/gdhcp.h | 3 ---
gdhcp/ipv4ll.c | 2 +-
src/dhcp.c | 3 ++-
src/main.c | 3 +++
6 files changed, 12 insertions(+), 46 deletions(-)
diff --git a/gdhcp/client.c b/gdhcp/client.c
index 7284624..f46ced4 100644
--- a/gdhcp/client.c
+++ b/gdhcp/client.c
@@ -520,7 +520,7 @@ static int send_release(GDHCPClient *dhcp_client,
debug(dhcp_client, "sending DHCP release request");
init_packet(dhcp_client, &packet, DHCPRELEASE);
- dhcp_get_random(&rand);
+ get_random(&rand);
packet.xid = rand;
packet.ciaddr = htonl(ciaddr);
@@ -1688,7 +1688,7 @@ static gboolean continue_rebound(gpointer user_data)
/*recalculate remaining rebind time*/
dhcp_client->T2 >>= 1;
if (dhcp_client->T2 > 60) {
- dhcp_get_random(&rand);
+ get_random(&rand);
dhcp_client->t2_timeout =
g_timeout_add_full(G_PRIORITY_HIGH,
dhcp_client->T2 * 1000 + (rand % 2000)
- 1000,
@@ -1736,7 +1736,7 @@ static gboolean continue_renew (gpointer user_data)
dhcp_client->T1 >>= 1;
if (dhcp_client->T1 > 60) {
- dhcp_get_random(&rand);
+ get_random(&rand);
dhcp_client->t1_timeout = g_timeout_add_full(G_PRIORITY_HIGH,
dhcp_client->T1 * 1000 + (rand % 2000) - 1000,
continue_renew,
@@ -2830,7 +2830,7 @@ int g_dhcp_client_start(GDHCPClient *dhcp_client, const
char *last_address)
if (re != 0)
return re;
- dhcp_get_random(&rand);
+ get_random(&rand);
dhcp_client->xid = rand;
dhcp_client->start = time(NULL);
}
diff --git a/gdhcp/common.c b/gdhcp/common.c
index 6f81671..26f9db1 100644
--- a/gdhcp/common.c
+++ b/gdhcp/common.c
@@ -37,6 +37,7 @@
#include <arpa/inet.h>
#include <fcntl.h>
+#include "../src/shared/random.h"
#include "gdhcp.h"
#include "common.h"
@@ -60,42 +61,6 @@ static const DHCPOption client_options[] = {
{ OPTION_UNKNOWN, 0x00 },
};
-#define URANDOM "/dev/urandom"
-static int random_fd = -1;
-
-int dhcp_get_random(uint64_t *val)
-{
- int r;
-
- if (random_fd < 0) {
- random_fd = open(URANDOM, O_RDONLY);
- if (random_fd < 0) {
- r = -errno;
- *val = random();
-
- return r;
- }
- }
-
- if (read(random_fd, val, sizeof(uint64_t)) < 0) {
- r = -errno;
- *val = random();
-
- return r;
- }
-
- return 0;
-}
-
-void dhcp_cleanup_random(void)
-{
- if (random_fd < 0)
- return;
-
- close(random_fd);
- random_fd = -1;
-}
-
GDHCPOptionType dhcp_get_code_type(uint8_t code)
{
int i;
@@ -400,7 +365,7 @@ void dhcpv6_init_header(struct dhcpv6_packet *packet,
uint8_t type)
packet->message = type;
- dhcp_get_random(&rand);
+ get_random(&rand);
id = rand;
packet->transaction_id[0] = (id >> 16) & 0xff;
diff --git a/gdhcp/gdhcp.h b/gdhcp/gdhcp.h
index eaf6a74..1285431 100644
--- a/gdhcp/gdhcp.h
+++ b/gdhcp/gdhcp.h
@@ -232,9 +232,6 @@ void g_dhcp_server_set_save_lease(GDHCPServer *dhcp_server,
void g_dhcp_server_set_lease_added_cb(GDHCPServer *dhcp_server,
GDHCPLeaseAddedCb cb);
-int dhcp_get_random(uint64_t *val);
-void dhcp_cleanup_random(void);
-
#ifdef __cplusplus
}
#endif
diff --git a/gdhcp/ipv4ll.c b/gdhcp/ipv4ll.c
index 2ef4823..3183348 100644
--- a/gdhcp/ipv4ll.c
+++ b/gdhcp/ipv4ll.c
@@ -47,7 +47,7 @@ uint32_t ipv4ll_random_ip(void)
uint64_t rand;
do {
- dhcp_get_random(&rand);
+ get_random(&rand);
tmp = rand;
tmp = tmp & IN_CLASSB_HOST;
} while (tmp > (IN_CLASSB_HOST - 0x0200));
diff --git a/src/dhcp.c b/src/dhcp.c
index 1af1eb5..615ad4a 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -39,6 +39,7 @@
#include <glib.h>
+#include "src/shared/random.h"
#include "connman.h"
#define RATE_LIMIT_INTERVAL 60 /* delay between successive attempts */
@@ -762,5 +763,5 @@ void __connman_dhcp_cleanup(void)
g_hash_table_destroy(ipconfig_table);
ipconfig_table = NULL;
- dhcp_cleanup_random();
+ cleanup_random();
}
diff --git a/src/main.c b/src/main.c
index 318bf02..dda54bb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -37,6 +37,7 @@
#include <gdbus.h>
+#include "shared/random.h"
#include "connman.h"
#define DEFAULT_INPUT_REQUEST_TIMEOUT (120 * 1000)
@@ -868,5 +869,7 @@ int main(int argc, char *argv[])
g_free(option_debug);
g_free(option_wifi);
+ cleanup_random();
+
return 0;
}
--
2.7.4
------------------------------
Message: 2
Date: Wed, 11 Apr 2018 16:00:21 +0200
From: Christian Spielberger <[email protected]>
To: Daniel Wagner <[email protected]>
Cc: [email protected], Christian Spielberger
<[email protected]>
Subject: [PATCH 01/27] shared: Add functions for random number
generation
Message-ID:
<[email protected]>
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 a new file src/shared/random.[h|c] in order to
be available generally.
---
Makefile.am | 8 +++---
gdhcp/client.c | 7 ++---
gdhcp/ipv4ll.c | 13 ++-------
gdhcp/ipv4ll.h | 1 -
src/shared/random.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/shared/random.h | 30 +++++++++++++++++++++
6 files changed, 119 insertions(+), 18 deletions(-)
create mode 100644 src/shared/random.c
create mode 100644 src/shared/random.h
diff --git a/Makefile.am b/Makefile.am
index 97f1c87..21ef474 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -48,7 +48,8 @@ backtrace_sources = src/backtrace.c
endif
shared_sources = src/shared/util.h src/shared/util.c \
- src/shared/netlink.h src/shared/netlink.c
+ src/shared/netlink.h src/shared/netlink.c \
+ src/shared/random.h src/shared/random.c
if DATAFILES
@@ -350,10 +351,11 @@ 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_SOURCES = $(gdhcp_sources) $(shared_sources) tools/dhcp-test.c
tools_dhcp_test_LDADD = @GLIB_LIBS@
-tools_dhcp_server_test_SOURCES = $(gdhcp_sources) tools/dhcp-server-test.c
+tools_dhcp_server_test_SOURCES = $(gdhcp_sources) $(shared_sources) \
+ tools/dhcp-server-test.c
tools_dhcp_server_test_LDADD = @GLIB_LIBS@
tools_dbus_test_SOURCES = tools/dbus-test.c
diff --git a/gdhcp/client.c b/gdhcp/client.c
index 6735778..7284624 100644
--- a/gdhcp/client.c
+++ b/gdhcp/client.c
@@ -43,6 +43,7 @@
#include <glib.h>
+#include "src/shared/random.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 = 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 = 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),
+ random_delay_ms(PROBE_WAIT),
send_probe_packet,
dhcp_client,
NULL);
diff --git a/gdhcp/ipv4ll.c b/gdhcp/ipv4ll.c
index d900198..2ef4823 100644
--- a/gdhcp/ipv4ll.c
+++ b/gdhcp/ipv4ll.c
@@ -33,6 +33,8 @@
#include <arpa/inet.h>
#include <glib.h>
+
+#include "src/shared/random.h"
#include "ipv4ll.h"
#include "common.h"
@@ -52,17 +54,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 bee8138..bf8c363 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/shared/random.c b/src/shared/random.c
new file mode 100644
index 0000000..906404a
--- /dev/null
+++ b/src/shared/random.c
@@ -0,0 +1,78 @@
+/*
+ *
+ * Random number generation
+ *
+ * based on IPv4 Local Link library with GLib integration,
+ * Copyright (C) 2009-2010 Aldebaran Robotics. All rights reserved.
+ *
+ * Copyright (C) 2018 Commend International. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "src/shared/random.h"
+
+#define URANDOM "/dev/urandom"
+
+static int random_fd = -1;
+
+int get_random(uint64_t *val)
+{
+ int r;
+
+ if (random_fd < 0) {
+ random_fd = open(URANDOM, O_RDONLY);
+ if (random_fd < 0) {
+ r = -errno;
+ *val = random();
+
+ return r;
+ }
+ }
+
+ if (read(random_fd, val, sizeof(uint64_t)) < 0) {
+ r = -errno;
+ *val = random();
+
+ return r;
+ }
+
+ return 0;
+}
+
+void cleanup_random(void)
+{
+ if (random_fd < 0)
+ return;
+
+ close(random_fd);
+ random_fd = -1;
+}
+
+/**
+ * Return a random delay in range of zero to secs*1000
+ */
+unsigned int random_delay_ms(unsigned int secs)
+{
+ uint64_t rand;
+
+ get_random(&rand);
+ return rand % (secs * 1000);
+}
+
diff --git a/src/shared/random.h b/src/shared/random.h
new file mode 100644
index 0000000..10614b1
--- /dev/null
+++ b/src/shared/random.h
@@ -0,0 +1,30 @@
+/*
+ *
+ * Random number generation library
+ *
+ * based on IPv4 Local Link library with GLib integration,
+ * Copyright (C) 2009-2010 Aldebaran Robotics. All rights reserved.
+ *
+ * Copyright (C) 2018 Commend International. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef SHARED_RANDOM_H
+#define SHARED_RANDOM_H
+
+#include <stdint.h>
+
+int get_random(uint64_t *val);
+void cleanup_random(void);
+unsigned int random_delay_ms(unsigned int secs);
+
+#endif
--
2.7.4
------------------------------
Message: 3
Date: Wed, 11 Apr 2018 16:00:20 +0200
From: Christian Spielberger <[email protected]>
To: Daniel Wagner <[email protected]>
Cc: [email protected], Christian Spielberger
<[email protected]>
Subject: [PATCH v2 00/27] implement Address Conflict Detection
Message-ID:
<[email protected]>
This patch series implements Address Conflict Detection (ACD) according to
RFC-5227. The review comments of the RFC PATCH series (thanks Daniel!) have
been taken into account:
- building with make distcheck each patch
- move code from service.c to network.c
- added documentation for the DBus API (patch 21)
- other cleanup
Patches 1 to 6 are unrelated and move common code to src/shared and adds
utility functions.
Patch 7 to 17 adds new files for ACD functionality. The IPv4LL code in gdhcp was
used as a basis for implementing ACD.
High-level conflict handling is placed in network, Patches 18 to 20.
Patch 21 adds a DBus property to inform about ACD.
Patch 22 to 25 adds sending of DHCP decline message in case an address conflict
is detected.
Patch 26 is for sending dbus signal also after the address defend failed and
own ip address is lost.
Patch 27 adds a DHCP decline also if second DHCP lease also has a conflict.
Christian Spielberger (26):
shared: Add functions for random number generation
dhcp: Use shared get_random() function
shared: Add low-level ARP functions
shared/arp: Add function get_interface_mac_address()
shared/arp: Add random_ip()
inet: Add function connman_inet_is_ifup()
Add Address Conflict Detection support (RFC 5227)
acd: add struct acd_host
acd: add functions start/stop_listening
acd: add send_probe_packet
acd: add send_announce_packet
acd: add callback function pointers
acd: add acdhost_start and acdhost_stop
acd: add acd_defend_timeout and acd_announce_timeout
acd: add handling of received arp packets
acd: add callback registration
network: init and start of acd
network: add content of acd callback functions
network: add ipv4ll as fallback for acd
acd: add dbus property for address conflict
dhcp: add sending of DHCP decline
network: add function for delayed dhcp start
acd: add acdhost_get_conflicts_count
network: send DHCP decline in case of address conflict
acd: report address lost case per dbus also
network: also send DHCP DECLINE after second DHCP try
Peter Meerwald-Stadler (1):
doc: Add documentation for AddressConflictDetection
Makefile.am | 17 +-
doc/connman.conf.5.in | 10 +
doc/service-api.txt | 32 +++
gdhcp/client.c | 88 ++++----
gdhcp/common.c | 39 +---
gdhcp/gdhcp.h | 4 +-
gdhcp/ipv4ll.c | 88 +-------
gdhcp/ipv4ll.h | 55 -----
include/acd.h | 64 ++++++
include/inet.h | 1 +
include/network.h | 6 +
include/service.h | 1 +
src/acd.c | 577 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/connman.h | 1 +
src/dhcp.c | 27 ++-
src/inet.c | 34 +++
src/main.c | 16 ++
src/network.c | 338 +++++++++++++++++++++++++++++
src/service.c | 11 +
src/shared/arp.c | 164 ++++++++++++++
src/shared/arp.h | 49 +++++
src/shared/random.c | 78 +++++++
src/shared/random.h | 30 +++
23 files changed, 1498 insertions(+), 232 deletions(-)
delete mode 100644 gdhcp/ipv4ll.h
create mode 100644 include/acd.h
create mode 100644 src/acd.c
create mode 100644 src/shared/arp.c
create mode 100644 src/shared/arp.h
create mode 100644 src/shared/random.c
create mode 100644 src/shared/random.h
--
2.7.4
------------------------------
Message: 4
Date: Wed, 11 Apr 2018 16:00:23 +0200
From: Christian Spielberger <[email protected]>
To: Daniel Wagner <[email protected]>
Cc: [email protected], Christian Spielberger
<[email protected]>
Subject: [PATCH 03/27] shared: Add low-level ARP functions
Message-ID:
<[email protected]>
We took the local functions for sending ARP packets in gdhcp and put them
into new source files src/shared/arp.[h|c]. This will be helpful for ACD
(Address Conflict Detection).
---
Makefile.am | 3 +-
gdhcp/client.c | 9 ++---
gdhcp/ipv4ll.c | 75 ++------------------------------------
gdhcp/ipv4ll.h | 17 +--------
src/shared/arp.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/shared/arp.h | 42 ++++++++++++++++++++++
6 files changed, 160 insertions(+), 94 deletions(-)
create mode 100644 src/shared/arp.c
create mode 100644 src/shared/arp.h
diff --git a/Makefile.am b/Makefile.am
index 21ef474..23c5171 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -49,7 +49,8 @@ endif
shared_sources = src/shared/util.h src/shared/util.c \
src/shared/netlink.h src/shared/netlink.c \
- src/shared/random.h src/shared/random.c
+ src/shared/random.h src/shared/random.c \
+ src/shared/arp.h src/shared/arp.c
if DATAFILES
diff --git a/gdhcp/client.c b/gdhcp/client.c
index f46ced4..14c83b6 100644
--- a/gdhcp/client.c
+++ b/gdhcp/client.c
@@ -43,7 +43,8 @@
#include <glib.h>
-#include "src/shared/random.h"
+#include "../src/shared/random.h"
+#include "../src/shared/arp.h"
#include "gdhcp.h"
#include "common.h"
#include "ipv4ll.h"
@@ -552,7 +553,7 @@ static gboolean send_probe_packet(gpointer dhcp_data)
dhcp_client->state = IPV4LL_PROBE;
switch_listening_mode(dhcp_client, L_ARP);
}
- ipv4ll_send_arp_packet(dhcp_client->mac_address, 0,
+ send_arp_packet(dhcp_client->mac_address, 0,
dhcp_client->requested_ip, dhcp_client->ifindex);
if (dhcp_client->retry_times < PROBE_NUM) {
@@ -581,7 +582,7 @@ static gboolean send_announce_packet(gpointer dhcp_data)
debug(dhcp_client, "sending IPV4LL announce request");
- ipv4ll_send_arp_packet(dhcp_client->mac_address,
+ send_arp_packet(dhcp_client->mac_address,
dhcp_client->requested_ip,
dhcp_client->requested_ip,
dhcp_client->ifindex);
@@ -1568,7 +1569,7 @@ static int switch_listening_mode(GDHCPClient *dhcp_client,
dhcp_client->interface,
AF_INET);
} else if (listen_mode == L_ARP)
- listener_sockfd = ipv4ll_arp_socket(dhcp_client->ifindex);
+ listener_sockfd = arp_socket(dhcp_client->ifindex);
else
return -EIO;
diff --git a/gdhcp/ipv4ll.c b/gdhcp/ipv4ll.c
index 3183348..dc0e4e8 100644
--- a/gdhcp/ipv4ll.c
+++ b/gdhcp/ipv4ll.c
@@ -34,7 +34,8 @@
#include <glib.h>
-#include "src/shared/random.h"
+#include "../src/shared/random.h"
+#include "../src/shared/arp.h"
#include "ipv4ll.h"
#include "common.h"
@@ -54,75 +55,3 @@ uint32_t ipv4ll_random_ip(void)
return ((LINKLOCAL_ADDR + 0x0100) + tmp);
}
-int ipv4ll_send_arp_packet(uint8_t* source_eth, uint32_t source_ip,
- uint32_t target_ip, int ifindex)
-{
- struct sockaddr_ll dest;
- struct ether_arp p;
- uint32_t ip_source;
- uint32_t ip_target;
- int fd, n;
-
- fd = socket(PF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
- if (fd < 0)
- return -errno;
-
- memset(&dest, 0, sizeof(dest));
- memset(&p, 0, sizeof(p));
-
- dest.sll_family = AF_PACKET;
- dest.sll_protocol = htons(ETH_P_ARP);
- dest.sll_ifindex = ifindex;
- dest.sll_halen = ETH_ALEN;
- memset(dest.sll_addr, 0xFF, ETH_ALEN);
- if (bind(fd, (struct sockaddr *)&dest, sizeof(dest)) < 0) {
- int err = errno;
- close(fd);
- return -err;
- }
-
- ip_source = htonl(source_ip);
- ip_target = htonl(target_ip);
- p.arp_hrd = htons(ARPHRD_ETHER);
- p.arp_pro = htons(ETHERTYPE_IP);
- p.arp_hln = ETH_ALEN;
- p.arp_pln = 4;
- p.arp_op = htons(ARPOP_REQUEST);
-
- memcpy(&p.arp_sha, source_eth, ETH_ALEN);
- memcpy(&p.arp_spa, &ip_source, sizeof(p.arp_spa));
- memcpy(&p.arp_tpa, &ip_target, sizeof(p.arp_tpa));
-
- n = sendto(fd, &p, sizeof(p), 0,
- (struct sockaddr*) &dest, sizeof(dest));
- if (n < 0)
- n = -errno;
-
- close(fd);
-
- return n;
-}
-
-int ipv4ll_arp_socket(int ifindex)
-{
- int fd;
- struct sockaddr_ll sock;
-
- fd = socket(PF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
- if (fd < 0)
- return fd;
-
- memset(&sock, 0, sizeof(sock));
-
- sock.sll_family = AF_PACKET;
- sock.sll_protocol = htons(ETH_P_ARP);
- sock.sll_ifindex = ifindex;
-
- if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) != 0) {
- int err = errno;
- close(fd);
- return -err;
- }
-
- return fd;
-}
diff --git a/gdhcp/ipv4ll.h b/gdhcp/ipv4ll.h
index bf8c363..315ca3d 100644
--- a/gdhcp/ipv4ll.h
+++ b/gdhcp/ipv4ll.h
@@ -22,7 +22,7 @@
#ifndef __G_IPV4LL_H
#define __G_IPV4LL_H
-#include <glib.h>
+#include <stdint.h>
#ifdef __cplusplus
extern "C" {
@@ -31,22 +31,7 @@ extern "C" {
/* 169.254.0.0 */
#define LINKLOCAL_ADDR 0xa9fe0000
-/* See RFC 3927 */
-#define PROBE_WAIT 1
-#define PROBE_NUM 3
-#define PROBE_MIN 1
-#define PROBE_MAX 2
-#define ANNOUNCE_WAIT 2
-#define ANNOUNCE_NUM 2
-#define ANNOUNCE_INTERVAL 2
-#define MAX_CONFLICTS 10
-#define RATE_LIMIT_INTERVAL 60
-#define DEFEND_INTERVAL 10
-
uint32_t ipv4ll_random_ip(void);
-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);
#ifdef __cplusplus
}
diff --git a/src/shared/arp.c b/src/shared/arp.c
new file mode 100644
index 0000000..e6c06fd
--- /dev/null
+++ b/src/shared/arp.c
@@ -0,0 +1,108 @@
+/*
+ *
+ * Connection Manager
+ *
+ * based on IPv4 Local Link library with GLib integration,
+ * Copyright (C) 2009-2010 Aldebaran Robotics. All rights reserved.
+ *
+ * Copyright (C) 2018 Commend International. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <netpacket/packet.h>
+#include <net/ethernet.h>
+#include <netinet/if_ether.h>
+#include <net/if_arp.h>
+
+#include <arpa/inet.h>
+
+#include "src/shared/arp.h"
+
+int send_arp_packet(uint8_t* source_eth, uint32_t source_ip,
+ uint32_t target_ip, int ifindex)
+{
+ struct sockaddr_ll dest;
+ struct ether_arp p;
+ uint32_t ip_source;
+ uint32_t ip_target;
+ int fd, n;
+
+ fd = socket(PF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+ if (fd < 0)
+ return -errno;
+
+ memset(&dest, 0, sizeof(dest));
+ memset(&p, 0, sizeof(p));
+
+ dest.sll_family = AF_PACKET;
+ dest.sll_protocol = htons(ETH_P_ARP);
+ dest.sll_ifindex = ifindex;
+ dest.sll_halen = ETH_ALEN;
+ memset(dest.sll_addr, 0xFF, ETH_ALEN);
+ if (bind(fd, (struct sockaddr *)&dest, sizeof(dest)) < 0) {
+ int err = errno;
+ close(fd);
+ return -err;
+ }
+
+ ip_source = htonl(source_ip);
+ ip_target = htonl(target_ip);
+ p.arp_hrd = htons(ARPHRD_ETHER);
+ p.arp_pro = htons(ETHERTYPE_IP);
+ p.arp_hln = ETH_ALEN;
+ p.arp_pln = 4;
+ p.arp_op = htons(ARPOP_REQUEST);
+
+ memcpy(&p.arp_sha, source_eth, ETH_ALEN);
+ memcpy(&p.arp_spa, &ip_source, sizeof(p.arp_spa));
+ memcpy(&p.arp_tpa, &ip_target, sizeof(p.arp_tpa));
+
+ n = sendto(fd, &p, sizeof(p), 0,
+ (struct sockaddr*) &dest, sizeof(dest));
+ if (n < 0)
+ n = -errno;
+
+ close(fd);
+
+ return n;
+}
+
+int arp_socket(int ifindex)
+{
+ int fd;
+ struct sockaddr_ll sock;
+
+ fd = socket(PF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+ if (fd < 0)
+ return fd;
+
+ memset(&sock, 0, sizeof(sock));
+
+ sock.sll_family = AF_PACKET;
+ sock.sll_protocol = htons(ETH_P_ARP);
+ sock.sll_ifindex = ifindex;
+
+ if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) != 0) {
+ int err = errno;
+ close(fd);
+ return -err;
+ }
+
+ return fd;
+}
diff --git a/src/shared/arp.h b/src/shared/arp.h
new file mode 100644
index 0000000..259e962
--- /dev/null
+++ b/src/shared/arp.h
@@ -0,0 +1,42 @@
+/*
+ *
+ * Connection Manager
+ *
+ * based on IPv4 Local Link library with GLib integration,
+ * Copyright (C) 2009-2010 Aldebaran Robotics. All rights reserved.
+ *
+ * Copyright (C) 2018 Commend International. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef SHARED_ARP_H
+#define SHARED_ARP_H
+
+#include <stdint.h>
+
+/* IPv4 Link-Local (RFC 3927), IPv4 Address Conflict Detection (RFC 5227) */
+#define PROBE_WAIT 1
+#define PROBE_NUM 3
+#define PROBE_MIN 1
+#define PROBE_MAX 2
+#define ANNOUNCE_WAIT 2
+#define ANNOUNCE_NUM 2
+#define ANNOUNCE_INTERVAL 2
+#define MAX_CONFLICTS 10
+#define RATE_LIMIT_INTERVAL 60
+#define DEFEND_INTERVAL 10
+
+int send_arp_packet(uint8_t* source_eth, uint32_t source_ip,
+ uint32_t target_ip, int ifindex);
+int arp_socket(int ifindex);
+
+#endif
--
2.7.4
------------------------------
Subject: Digest Footer
_______________________________________________
connman mailing list
[email protected]
https://lists.01.org/mailman/listinfo/connman
------------------------------
End of connman Digest, Vol 30, Issue 4
**************************************