X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd%2Fsd-rtnl%2Ftest-rtnl.c;h=6ecd6603ae25de55efcf30d4741094ea4c3b0bf9;hb=82923adfe5c4fa09cc91fd2a2e374c936cd4a186;hp=dd74e76ed4d27842b5eff76c846a76aa70fb505a;hpb=12e0f830f592ec4c6bb49ac7ae1e0e84f74105e3;p=elogind.git diff --git a/src/libsystemd/sd-rtnl/test-rtnl.c b/src/libsystemd/sd-rtnl/test-rtnl.c index dd74e76ed..6ecd6603a 100644 --- a/src/libsystemd/sd-rtnl/test-rtnl.c +++ b/src/libsystemd/sd-rtnl/test-rtnl.c @@ -28,6 +28,7 @@ #include "rtnl-util.h" #include "event-util.h" #include "missing.h" +#include "rtnl-internal.h" static void test_link_configure(sd_rtnl *rtnl, int ifindex) { _cleanup_rtnl_message_unref_ sd_rtnl_message *message; @@ -63,7 +64,11 @@ static void test_link_get(sd_rtnl *rtnl, int ifindex) { unsigned int mtu = 1500; unsigned int *mtu_reply; void *data; + char *str_data; 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); @@ -123,8 +128,44 @@ static void test_link_get(sd_rtnl *rtnl, int ifindex) { } } + assert_se(sd_rtnl_message_read_string(r, IFLA_IFNAME, &str_data) == 0); + + assert_se(sd_rtnl_message_read_u8(r, IFLA_CARRIER, &u8_data) == 0); + assert_se(sd_rtnl_message_read_u8(r, IFLA_OPERSTATE, &u8_data) == 0); + assert_se(sd_rtnl_message_read_u8(r, IFLA_LINKMODE, &u8_data) == 0); + + assert_se(sd_rtnl_message_read_u32(r, IFLA_MTU, &u32_data) == 0); + assert_se(sd_rtnl_message_read_u32(r, IFLA_GROUP, &u32_data) == 0); + assert_se(sd_rtnl_message_read_u32(r, IFLA_TXQLEN, &u32_data) == 0); + 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); } @@ -134,7 +175,9 @@ static void test_route(void) { uint32_t index = 2; uint16_t type; void *data; + uint32_t u32_data; int r; + struct rtmsg *rtm; r = sd_rtnl_message_new_route(NULL, &req, RTM_NEWROUTE, AF_INET); if (r < 0) { @@ -165,6 +208,19 @@ static void test_route(void) { assert_se(sd_rtnl_message_read(req, &type, &data) > 0); assert_se(type == RTA_OIF); assert_se(*(uint32_t *) data == index); + + rtm = NLMSG_DATA(req->hdr); + r = rtnl_message_parse(req, + &req->rta_offset_tb, + &req->rta_tb_size, + RTA_MAX, + RTM_RTA(rtm), + RTM_PAYLOAD(req->hdr)); + + assert_se(sd_rtnl_message_read_u32(req, RTA_GATEWAY, &u32_data) == 0); + assert_se(sd_rtnl_message_read_u32(req, RTA_OIF, &u32_data) == 0); + + assert_se((req = sd_rtnl_message_unref(req)) == NULL); } static void test_multiple(void) { @@ -226,6 +282,8 @@ static void test_event_loop(int ifindex) { assert_se(sd_event_run(event, 0) >= 0); assert_se(sd_rtnl_detach_event(rtnl) >= 0); + + assert_se((rtnl = sd_rtnl_unref(rtnl)) == NULL); } static int pipe_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) { @@ -255,6 +313,8 @@ static void test_async(int ifindex) { assert_se(sd_rtnl_wait(rtnl, 0) >= 0); assert_se(sd_rtnl_process(rtnl, &r) >= 0); + + assert_se((rtnl = sd_rtnl_unref(rtnl)) == NULL); } static void test_pipe(int ifindex) { @@ -277,12 +337,17 @@ static void test_pipe(int ifindex) { assert_se(sd_rtnl_wait(rtnl, 0) >= 0); assert_se(sd_rtnl_process(rtnl, NULL) >= 0); } + + assert_se((rtnl = sd_rtnl_unref(rtnl)) == NULL); } static void test_container(void) { _cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL; uint16_t type; + uint32_t u32_data; void *data; + int r; + struct ifinfomsg *ifi; assert_se(sd_rtnl_message_new_link(NULL, &m, RTM_NEWLINK, 0) >= 0); @@ -302,6 +367,7 @@ static void test_container(void) { assert_se(sd_rtnl_message_read(m, &type, &data) >= 0); assert_se(type == IFLA_LINKINFO); assert_se(data == NULL); +/* assert_se(sd_rtnl_message_read(m, &type, &data) >= 0); assert_se(type == IFLA_INFO_KIND); assert_se(streq("kind", (char *)data)); @@ -318,6 +384,20 @@ static void test_container(void) { assert_se(streq("kind", (char *)data)); assert_se(sd_rtnl_message_read(m, &type, &data) == 0); assert_se(sd_rtnl_message_exit_container(m) >= 0); +*/ + + ifi = NLMSG_DATA(m->hdr); + r = rtnl_message_parse(m, + &m->rta_offset_tb, + &m->rta_tb_size, + IFLA_MAX, + IFLA_RTA(ifi), + IFLA_PAYLOAD(m->hdr)); + if(r < 0) + return; + + assert_se(sd_rtnl_message_read_u32(m, IFLA_LINKINFO, &u32_data) == 0); + assert_se(sd_rtnl_message_exit_container(m) == -EINVAL); } @@ -332,6 +412,8 @@ static void test_match(void) { assert_se(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 1); assert_se(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 1); assert_se(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 0); + + assert_se((rtnl = sd_rtnl_unref(rtnl)) == NULL); } int main(void) { @@ -384,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);