summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-rtnl/test-rtnl.c
diff options
context:
space:
mode:
authorSusant Sahani <susant@redhat.com>2014-03-07 20:38:02 +0530
committerTom Gundersen <teg@jklm.no>2014-03-07 17:39:04 +0100
commit4e9e7f1836b0c8f612f2beb3447d6144f9244d26 (patch)
treeca2332f80683c69d3ce01cb31ff90b79397089c9 /src/libsystemd/sd-rtnl/test-rtnl.c
parentb2cdc6664ef6b56e47d38649d69b9943d9f9f5d0 (diff)
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.]
Diffstat (limited to 'src/libsystemd/sd-rtnl/test-rtnl.c')
-rw-r--r--src/libsystemd/sd-rtnl/test-rtnl.c26
1 files changed, 26 insertions, 0 deletions
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);