[systemd-commits] 4 commits - src/network TODO
Tom Gundersen
tomegun at kemper.freedesktop.org
Sat May 17 11:52:39 PDT 2014
TODO | 4 +++
src/network/networkd-address.c | 43 +++++++++++++++++++++++++++++++++++++
src/network/networkd-link.c | 41 +++++++++++++++++++++++++++++------
src/network/networkd.h | 3 ++
src/network/test-network.c | 47 +++++++++++++++++++++++++++++++++++++++++
5 files changed, 131 insertions(+), 7 deletions(-)
New commits:
commit 16cd414ba0ae3f420cbf30f1250e2573d2cafc51
Author: Tom Gundersen <teg at jklm.no>
Date: Fri May 16 21:25:46 2014 +0200
networkd: log - only log about udev initalization on debug level
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 9c93776..87a8d9f 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1697,7 +1697,7 @@ int link_initialized(Link *link, struct udev_device *device) {
if (device)
link->udev_device = udev_device_ref(device);
- log_info_link(link, "udev initialized link");
+ log_debug_link(link, "udev initialized link");
r = network_get(link->manager, device, link->ifname, &link->mac, &network);
if (r == -ENOENT) {
@@ -1890,7 +1890,7 @@ int link_add(Manager *m, sd_rtnl_message *message, Link **ret) {
if (udev_device_get_is_initialized(device) <= 0) {
/* not yet ready */
- log_info_link(link, "udev initializing link...");
+ log_debug_link(link, "udev initializing link...");
return 0;
}
}
commit 428fd0a75873d63b9d567f9db7871551d1ee0d62
Author: Tom Gundersen <teg at jklm.no>
Date: Fri May 16 00:28:22 2014 +0200
networkd: keep list of active addresses
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index d3777c8..9c93776 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -96,11 +96,18 @@ static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
}
static void link_free(Link *link) {
+ Address *address;
+
if (!link)
return;
assert(link->manager);
+ while ((address = link->addresses)) {
+ LIST_REMOVE(addresses, link->addresses, address);
+ address_free(address);
+ }
+
sd_dhcp_client_unref(link->dhcp_client);
sd_dhcp_lease_unref(link->dhcp_lease);
@@ -1715,7 +1722,9 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *use
Link *link = NULL;
uint16_t type;
_cleanup_address_free_ Address *address = NULL;
+ Address *ad;
char buf[INET6_ADDRSTRLEN];
+ bool address_dropped = false;
int r, ifindex;
assert(rtnl);
@@ -1784,15 +1793,33 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *use
return 0;
}
+ LIST_FOREACH(addresses, ad, link->addresses) {
+ if (address_equal(ad, address)) {
+ LIST_REMOVE(addresses, link->addresses, ad);
+
+ address_free(ad);
+
+ address_dropped = true;
+
+ break;
+ }
+ }
+
switch (type) {
case RTM_NEWADDR:
- log_info_link(link, "added address: %s/%u", buf,
- address->prefixlen);
- break;
+ if (!address_dropped)
+ log_debug_link(link, "added address: %s/%u", buf,
+ address->prefixlen);
+ LIST_PREPEND(addresses, link->addresses, address);
+ address = NULL;
+
+ break;
case RTM_DELADDR:
- log_info_link(link, "removed address: %s/%u", buf,
- address->prefixlen);
+ if (address_dropped)
+ log_debug_link(link, "removed address: %s/%u", buf,
+ address->prefixlen);
+
break;
default:
assert_not_reached("Received invalid RTNL message type");
diff --git a/src/network/networkd.h b/src/network/networkd.h
index d5154aa..30a29c7 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -232,6 +232,8 @@ struct Link {
unsigned route_messages;
unsigned enslaving;
+ LIST_HEAD(Address, addresses);
+
sd_dhcp_client *dhcp_client;
sd_dhcp_lease *dhcp_lease;
char *lease_file;
commit 9505d3c6deda0452c22ab2ed47bca74b98d87a17
Author: Tom Gundersen <teg at jklm.no>
Date: Fri May 16 00:27:56 2014 +0200
networkd: IP address equality
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 6977fe7..34863b2 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -508,3 +508,46 @@ int config_parse_label(const char *unit,
return 0;
}
+
+bool address_equal(Address *a1, Address *a2) {
+ /* same object */
+ if (a1 == a2)
+ return true;
+
+ /* one, but not both, is NULL */
+ if (!a1 || !a2)
+ return false;
+
+ if (a1->family != a2->family)
+ return false;
+
+ switch (a1->family) {
+ /* use the same notion of equality as the kernel does */
+ case AF_UNSPEC:
+ return true;
+
+ case AF_INET:
+ if (a1->prefixlen != a2->prefixlen)
+ return false;
+ else {
+ uint32_t b1, b2;
+
+ b1 = be32toh(a1->in_addr.in.s_addr);
+ b2 = be32toh(a2->in_addr.in.s_addr);
+
+ return (b1 >> (32 - a1->prefixlen)) == (b2 >> (32 - a1->prefixlen));
+ }
+
+ case AF_INET6:
+ {
+ uint64_t *b1, *b2;
+
+ b1 = (uint64_t*)&a1->in_addr.in6;
+ b2 = (uint64_t*)&a2->in_addr.in6;
+
+ return (((b1[0] ^ b2[0]) | (b1[1] ^ b2[1])) == 0UL);
+ }
+ default:
+ assert_not_reached("Invalid address family");
+ }
+}
diff --git a/src/network/networkd.h b/src/network/networkd.h
index eaaf259..d5154aa 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -386,6 +386,7 @@ void address_free(Address *address);
int address_configure(Address *address, Link *link, sd_rtnl_message_handler_t callback);
int address_update(Address *address, Link *link, sd_rtnl_message_handler_t callback);
int address_drop(Address *address, Link *link, sd_rtnl_message_handler_t callback);
+bool address_equal(Address *a1, Address *a2);
DEFINE_TRIVIAL_CLEANUP_FUNC(Address*, address_free);
#define _cleanup_address_free_ _cleanup_(address_freep)
diff --git a/src/network/test-network.c b/src/network/test-network.c
index 38d57cc..a0e04f8 100644
--- a/src/network/test-network.c
+++ b/src/network/test-network.c
@@ -42,11 +42,58 @@ static void test_network_get(Manager *manager, struct udev_device *loopback) {
assert_se(!network);
}
+static void test_address_equality(void) {
+ Address *a1, *a2;
+
+ assert_se(address_new_dynamic(&a1) >= 0);
+ assert_se(address_new_dynamic(&a2) >= 0);
+
+ assert_se(address_equal(NULL, NULL));
+ assert_se(!address_equal(a1, NULL));
+ assert_se(!address_equal(NULL, a2));
+ assert_se(address_equal(a1, a2));
+
+ a1->family = AF_INET;
+ assert_se(!address_equal(a1, a2));
+
+ a2->family = AF_INET;
+ assert_se(address_equal(a1, a2));
+
+ assert_se(inet_pton(AF_INET, "192.168.3.9", &a1->in_addr.in));
+ assert_se(!address_equal(a1, a2));
+ assert_se(inet_pton(AF_INET, "192.168.3.9", &a2->in_addr.in));
+ assert_se(address_equal(a1, a2));
+
+ a1->prefixlen = 10;
+ assert_se(!address_equal(a1, a2));
+ a2->prefixlen = 10;
+ assert_se(address_equal(a1, a2));
+
+ assert_se(inet_pton(AF_INET, "192.168.3.10", &a2->in_addr.in));
+ assert_se(address_equal(a1, a2));
+
+ a1->family = AF_INET6;
+ assert_se(!address_equal(a1, a2));
+
+ a2->family = AF_INET6;
+ assert_se(inet_pton(AF_INET6, "2001:4ca0:4f01::2", &a1->in_addr.in6));
+ assert_se(inet_pton(AF_INET6, "2001:4ca0:4f01::2", &a2->in_addr.in6));
+ assert_se(address_equal(a1, a2));
+
+ a2->prefixlen = 8;
+ assert_se(address_equal(a1, a2));
+
+ assert_se(inet_pton(AF_INET6, "2001:4ca0:4f01::1", &a2->in_addr.in6));
+ assert_se(!address_equal(a1, a2));
+}
+
int main(void) {
_cleanup_manager_free_ Manager *manager = NULL;
struct udev *udev;
struct udev_device *loopback;
+ test_address_equality();
+
assert_se(manager_new(&manager) >= 0);
test_load_config(manager);
commit ac976532063da637a70af3e39e0e1876267018ed
Author: Tom Gundersen <teg at jklm.no>
Date: Fri May 16 00:26:37 2014 +0200
TODO
diff --git a/TODO b/TODO
index 0e2e2d4..015faf6 100644
--- a/TODO
+++ b/TODO
@@ -709,6 +709,10 @@ Features:
- export timezone information
- FORCERENEW
+* dhcp:
+ - export timezone information
+ - FORCERENEW
+
External:
* dbus:
More information about the systemd-commits
mailing list