[systemd-commits] 2 commits - src/libsystemd src/network src/systemd
Tom Gundersen
tomegun at kemper.freedesktop.org
Fri Mar 7 09:16:24 PST 2014
src/libsystemd/sd-rtnl/rtnl-message.c | 45 +++++++++++++++++++++++++++++++++
src/libsystemd/sd-rtnl/test-rtnl.c | 26 +++++++++++++++++++
src/network/networkd-link.c | 46 ++++++++++++----------------------
src/systemd/sd-rtnl.h | 3 ++
4 files changed, 91 insertions(+), 29 deletions(-)
New commits:
commit 9842de0d93dc895800a43ccf1d04e5174f0ffea8
Author: Tom Gundersen <teg at jklm.no>
Date: Fri Mar 7 17:34:38 2014 +0100
networkd: use new rtnl_message_read() API
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 416eb56..785e8d5 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1328,8 +1328,6 @@ int link_configure(Link *link) {
int link_update(Link *link, sd_rtnl_message *m) {
unsigned flags;
- void *data;
- uint16_t type;
int r;
assert(link);
@@ -1344,34 +1342,24 @@ int link_update(Link *link, sd_rtnl_message *m) {
return r;
}
- while (sd_rtnl_message_read(m, &type, &data) > 0) {
- switch(type) {
- case IFLA_MTU:
- if (link->network->dhcp && link->network->dhcp_mtu &&
- !link->original_mtu) {
- link->original_mtu = *(uint16_t *) data;
- log_debug_link(link, "saved original MTU: %"
- PRIu16, link->original_mtu);
- }
-
- break;
- case IFLA_ADDRESS:
- if (memcmp(&link->mac.ether_addr_octet, &data,
- ETH_ALEN)) {
- memcpy(&link->mac, data, ETH_ALEN);
-
- log_debug_link(link, "updated MAC address: "
- "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
- link->mac.ether_addr_octet[0],
- link->mac.ether_addr_octet[1],
- link->mac.ether_addr_octet[2],
- link->mac.ether_addr_octet[3],
- link->mac.ether_addr_octet[4],
- link->mac.ether_addr_octet[5]);
- }
+ if (link->network->dhcp && link->network->dhcp_mtu &&
+ !link->original_mtu) {
+ r = sd_rtnl_message_read_u16(m, IFLA_MTU, &link->original_mtu);
+ if (r >= 0)
+ log_debug_link(link, "saved original MTU: %"
+ PRIu16, link->original_mtu);
+ }
- break;
- }
+ r = sd_rtnl_message_read_ether_addr(m, IFLA_ADDRESS, &link->mac);
+ if (r >= 0) {
+ log_debug_link(link, "MAC address: "
+ "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
+ link->mac.ether_addr_octet[0],
+ link->mac.ether_addr_octet[1],
+ link->mac.ether_addr_octet[2],
+ link->mac.ether_addr_octet[3],
+ link->mac.ether_addr_octet[4],
+ link->mac.ether_addr_octet[5]);
}
return link_update_flags(link, flags);
commit 4e9e7f1836b0c8f612f2beb3447d6144f9244d26
Author: Susant Sahani <susant at redhat.com>
Date: Fri Mar 7 20:38:02 2014 +0530
sd-rtnl: introduce read ether and ip address functions
This patch introduces reading ethernet address and IPV4/IPv6
as well which is based on table based look up.
[tomegun: rename read_ether() to read_ether_addr() to match the append function.]
diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c
index dd3a8fb..fca1ff6 100644
--- a/src/libsystemd/sd-rtnl/rtnl-message.c
+++ b/src/libsystemd/sd-rtnl/rtnl-message.c
@@ -876,6 +876,51 @@ int sd_rtnl_message_read_u32(sd_rtnl_message *m, unsigned short type, uint32_t *
return 0;
}
+int sd_rtnl_message_read_ether_addr(sd_rtnl_message *m, unsigned short type, struct ether_addr *data) {
+ int r;
+ void *attr_data;
+
+ assert_return(data, -EINVAL);
+
+ r = rtnl_message_read_internal(m, type, &attr_data);
+ if(r < 0)
+ return r;
+
+ memcpy(data, attr_data, sizeof(struct ether_addr));
+
+ return 0;
+}
+
+int sd_rtnl_message_read_in_addr(sd_rtnl_message *m, unsigned short type, struct in_addr *data) {
+ int r;
+ void *attr_data;
+
+ assert_return(data, -EINVAL);
+
+ r = rtnl_message_read_internal(m, type, &attr_data);
+ if(r < 0)
+ return r;
+
+ memcpy(data, attr_data, sizeof(struct in_addr));
+
+ return 0;
+}
+
+int sd_rtnl_message_read_in6_addr(sd_rtnl_message *m, unsigned short type, struct in6_addr *data) {
+ int r;
+ void *attr_data;
+
+ assert_return(data, -EINVAL);
+
+ r = rtnl_message_read_internal(m, type, &attr_data);
+ if(r < 0)
+ return r;
+
+ memcpy(data, attr_data, sizeof(struct in6_addr));
+
+ return 0;
+}
+
int sd_rtnl_message_exit_container(sd_rtnl_message *m) {
assert_return(m, -EINVAL);
assert_return(m->sealed, -EINVAL);
diff --git a/src/libsystemd/sd-rtnl/test-rtnl.c b/src/libsystemd/sd-rtnl/test-rtnl.c
index dc21042..6ecd660 100644
--- a/src/libsystemd/sd-rtnl/test-rtnl.c
+++ b/src/libsystemd/sd-rtnl/test-rtnl.c
@@ -68,6 +68,7 @@ static void test_link_get(sd_rtnl *rtnl, int ifindex) {
uint16_t type;
uint8_t u8_data;
uint32_t u32_data;
+ struct ether_addr eth_data;
assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
assert_se(m);
@@ -139,9 +140,33 @@ static void test_link_get(sd_rtnl *rtnl, int ifindex) {
assert_se(sd_rtnl_message_read_u32(r, IFLA_NUM_TX_QUEUES, &u32_data) == 0);
assert_se(sd_rtnl_message_read_u32(r, IFLA_NUM_RX_QUEUES, &u32_data) == 0);
+ assert_se(sd_rtnl_message_read_ether_addr(r, IFLA_ADDRESS, ð_data) == 0);
+
+ assert_se(sd_rtnl_flush(rtnl) >= 0);
+ assert_se((m = sd_rtnl_message_unref(m)) == NULL);
+ assert_se((r = sd_rtnl_message_unref(r)) == NULL);
+}
+
+
+static void test_address_get(sd_rtnl *rtnl, int ifindex) {
+ sd_rtnl_message *m;
+ sd_rtnl_message *r;
+ struct in_addr in_data;
+
+ assert_se(sd_rtnl_message_new_addr(rtnl, &m, RTM_GETADDR, ifindex, AF_INET) >= 0);
+ assert_se(m);
+
+ assert_se(sd_rtnl_call(rtnl, m, -1, &r) == 1);
+
+ assert_se(sd_rtnl_message_read_in_addr(r, IFA_LOCAL, &in_data) == 0);
+ assert_se(sd_rtnl_message_read_in_addr(r, IFA_ADDRESS, &in_data) == 0);
+ assert_se(sd_rtnl_message_read_in_addr(r, IFA_LABEL, &in_data) == 0);
+ assert_se(sd_rtnl_message_read_in_addr(r, IFA_CACHEINFO, &in_data) == 0);
+
assert_se(sd_rtnl_flush(rtnl) >= 0);
assert_se((m = sd_rtnl_message_unref(m)) == NULL);
assert_se((r = sd_rtnl_message_unref(r)) == NULL);
+
}
static void test_route(void) {
@@ -441,6 +466,7 @@ int main(void) {
assert_se((r = sd_rtnl_message_unref(r)) == NULL);
test_link_get(rtnl, if_loopback);
+ test_address_get(rtnl, if_loopback);
assert_se(sd_rtnl_flush(rtnl) >= 0);
assert_se((m = sd_rtnl_message_unref(m)) == NULL);
diff --git a/src/systemd/sd-rtnl.h b/src/systemd/sd-rtnl.h
index 886a66e..a171978 100644
--- a/src/systemd/sd-rtnl.h
+++ b/src/systemd/sd-rtnl.h
@@ -107,6 +107,9 @@ int sd_rtnl_message_read_string(sd_rtnl_message *m, unsigned short type, char **
int sd_rtnl_message_read_u8(sd_rtnl_message *m, unsigned short type, uint8_t *data);
int sd_rtnl_message_read_u16(sd_rtnl_message *m, unsigned short type, uint16_t *data);
int sd_rtnl_message_read_u32(sd_rtnl_message *m, unsigned short type, uint32_t *data);
+int sd_rtnl_message_read_ether_addr(sd_rtnl_message *m, unsigned short type, struct ether_addr *data);
+int sd_rtnl_message_read_in_addr(sd_rtnl_message *m, unsigned short type, struct in_addr *data);
+int sd_rtnl_message_read_in6_addr(sd_rtnl_message *m, unsigned short type, struct in6_addr *data);
int sd_rtnl_message_exit_container(sd_rtnl_message *m);
int sd_rtnl_message_rewind(sd_rtnl_message *m);
More information about the systemd-commits
mailing list