diff options
author | Eugene Yakubovich <eyakubovich@gmail.com> | 2014-06-27 15:00:06 -0700 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-06-29 15:18:21 +0200 |
commit | e1ea665edac17d75fce01b72dadfa3211b60df2c (patch) | |
tree | 9f1d4c8ae93862cf5ebae973cd48d053ef34c0dd /src/network/test-network.c | |
parent | ed942a9eb22d50f667909ad6184b45015d28d054 (diff) |
Add support for DHCP static route options
This adds support for DHCP options 33 and 121: Static Route and
Classless Static Route. To enable this feature, set UseRoutes=true
in .network file. Returned routes are added to the routing table.
Diffstat (limited to 'src/network/test-network.c')
-rw-r--r-- | src/network/test-network.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/network/test-network.c b/src/network/test-network.c index eb6ebe70b3..75e70fae14 100644 --- a/src/network/test-network.c +++ b/src/network/test-network.c @@ -21,6 +21,7 @@ #include "networkd.h" #include "network-internal.h" +#include "dhcp-lease-internal.h" static void test_deserialize_in_addr(void) { _cleanup_free_ struct in_addr *addresses = NULL; @@ -53,6 +54,63 @@ static void test_deserialize_in_addr(void) { assert_se(!memcmp(&f, &addresses6[2], sizeof(struct in6_addr))); } +static void test_deserialize_dhcp_routes(void) { + size_t size, allocated; + + { + _cleanup_free_ struct sd_dhcp_route *routes = NULL; + assert_se(deserialize_dhcp_routes(&routes, &size, &allocated, "") >= 0); + assert_se(size == 0); + } + + { + /* no errors */ + _cleanup_free_ struct sd_dhcp_route *routes = NULL; + const char *routes_string = "192.168.0.0/16,192.168.0.1 10.1.2.0/24,10.1.2.1 0.0.0.0/0,10.0.1.1"; + + assert_se(deserialize_dhcp_routes(&routes, &size, &allocated, routes_string) >= 0); + + assert_se(size == 3); + assert_se(routes[0].dst_addr.s_addr == inet_addr("192.168.0.0")); + assert_se(routes[0].gw_addr.s_addr == inet_addr("192.168.0.1")); + assert_se(routes[0].dst_prefixlen == 16); + + assert_se(routes[1].dst_addr.s_addr == inet_addr("10.1.2.0")); + assert_se(routes[1].gw_addr.s_addr == inet_addr("10.1.2.1")); + assert_se(routes[1].dst_prefixlen == 24); + + assert_se(routes[2].dst_addr.s_addr == inet_addr("0.0.0.0")); + assert_se(routes[2].gw_addr.s_addr == inet_addr("10.0.1.1")); + assert_se(routes[2].dst_prefixlen == 0); + } + + { + /* error in second word */ + _cleanup_free_ struct sd_dhcp_route *routes = NULL; + const char *routes_string = "192.168.0.0/16,192.168.0.1 10.1.2.0#24,10.1.2.1 0.0.0.0/0,10.0.1.1"; + + assert_se(deserialize_dhcp_routes(&routes, &size, &allocated, routes_string) >= 0); + + assert_se(size == 2); + assert_se(routes[0].dst_addr.s_addr == inet_addr("192.168.0.0")); + assert_se(routes[0].gw_addr.s_addr == inet_addr("192.168.0.1")); + assert_se(routes[0].dst_prefixlen == 16); + + assert_se(routes[2].dst_addr.s_addr == inet_addr("0.0.0.0")); + assert_se(routes[2].gw_addr.s_addr == inet_addr("10.0.1.1")); + assert_se(routes[2].dst_prefixlen == 0); + } + + { + /* error in every word */ + _cleanup_free_ struct sd_dhcp_route *routes = NULL; + const char *routes_string = "192.168.0.0/55,192.168.0.1 10.1.2.0#24,10.1.2.1 0.0.0.0/0,10.0.1.X"; + + assert_se(deserialize_dhcp_routes(&routes, &size, &allocated, routes_string) >= 0); + assert_se(size == 0); + } +} + static void test_load_config(Manager *manager) { /* TODO: should_reload, is false if the config dirs do not exist, so * so we can't do this test here, move it to a test for paths_check_timestamps @@ -125,6 +183,7 @@ int main(void) { struct udev_device *loopback; test_deserialize_in_addr(); + test_deserialize_dhcp_routes(); test_address_equality(); assert_se(manager_new(&manager) >= 0); |