summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libsystemd/sd-rtnl/rtnl-message.c45
-rw-r--r--src/libsystemd/sd-rtnl/test-rtnl.c26
-rw-r--r--src/systemd/sd-rtnl.h3
3 files changed, 74 insertions, 0 deletions
diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c
index dd3a8fb1d2..fca1ff667a 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 dc210426cc..6ecd6603ae 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, &eth_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 886a66ec72..a171978bcf 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);