diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-06-30 04:09:51 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-06-30 04:46:04 +0900 |
commit | 04ed9949375042954e51d8218185558ce70ef3e9 (patch) | |
tree | 1e2132b42ee954decb0ba79963c64f4712ef15de /src/network | |
parent | ca5ad760a5ab5d8e281ef675dd703db30620d5a6 (diff) | |
download | systemd-04ed9949375042954e51d8218185558ce70ef3e9.tar.gz |
network: move DHCP6 related code from networkd-manager.c to networkd-dhcp6.c
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/networkd-dhcp6.c | 131 | ||||
-rw-r--r-- | src/network/networkd-dhcp6.h | 2 | ||||
-rw-r--r-- | src/network/networkd-manager.c | 122 | ||||
-rw-r--r-- | src/network/networkd-manager.h | 4 |
4 files changed, 130 insertions, 129 deletions
diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c index 1b119684dd..286b9071ae 100644 --- a/src/network/networkd-dhcp6.c +++ b/src/network/networkd-dhcp6.c @@ -21,6 +21,9 @@ #include "radv-internal.h" static int dhcp6_lease_address_acquired(sd_dhcp6_client *client, Link *link); +static Link *dhcp6_prefix_get(Manager *m, struct in6_addr *addr); +static int dhcp6_prefix_add(Manager *m, struct in6_addr *addr, Link *link); +static int dhcp6_prefix_remove_all(Manager *m, Link *link); static bool dhcp6_get_prefix_delegation(Link *link) { if (!link->network) @@ -91,7 +94,7 @@ static int dhcp6_pd_prefix_assign(Link *link, struct in6_addr *prefix, if (r < 0 && r != -EEXIST) return r; - r = manager_dhcp6_prefix_add(link->manager, prefix, link); + r = dhcp6_prefix_add(link->manager, prefix, link); if (r < 0) return r; @@ -105,7 +108,7 @@ static int dhcp6_route_remove_handler(sd_netlink *nl, sd_netlink_message *m, Lin r = sd_netlink_message_get_errno(m); if (r < 0) - log_link_debug_errno(link, r, "Received error on unreachable route removal for DHCPv6 delegated subnetl: %m"); + log_link_debug_errno(link, r, "Received error on unreachable route removal for DHCPv6 delegated subnet: %m"); return 1; } @@ -203,7 +206,7 @@ static int dhcp6_pd_prefix_distribute(Link *dhcp6_link, Iterator *i, if (!dhcp6_get_prefix_delegation(link)) continue; - assigned_link = manager_dhcp6_prefix_get(manager, &prefix.in6); + assigned_link = dhcp6_prefix_get(manager, &prefix.in6); if (assigned_link && assigned_link != link) continue; @@ -489,7 +492,7 @@ static void dhcp6_handler(sd_dhcp6_client *client, int event, void *userdata) { log_link_warning(link, "DHCPv6 lease lost"); (void) dhcp6_lease_pd_prefix_lost(client, link); - (void) manager_dhcp6_prefix_remove_all(link->manager, link); + (void) dhcp6_prefix_remove_all(link->manager, link); link->dhcp6_configured = false; break; @@ -686,3 +689,123 @@ int dhcp6_configure(Link *link) { return 0; } + +static Link *dhcp6_prefix_get(Manager *m, struct in6_addr *addr) { + assert_return(m, NULL); + assert_return(addr, NULL); + + return hashmap_get(m->dhcp6_prefixes, addr); +} + +static int dhcp6_route_add_handler(sd_netlink *nl, sd_netlink_message *m, Link *link) { + int r; + + assert(link); + + r = sd_netlink_message_get_errno(m); + if (r < 0 && r != -EEXIST) + log_link_debug_errno(link, r, "Received error adding DHCPv6 Prefix Delegation route: %m"); + + return 0; +} + +static int dhcp6_prefix_add(Manager *m, struct in6_addr *addr, Link *link) { + _cleanup_free_ struct in6_addr *a = NULL; + _cleanup_free_ char *buf = NULL; + Link *assigned_link; + Route *route; + int r; + + assert_return(m, -EINVAL); + assert_return(addr, -EINVAL); + + r = route_add(link, AF_INET6, (union in_addr_union *) addr, 64, + 0, 0, 0, &route); + if (r < 0) + return r; + + r = route_configure(route, link, dhcp6_route_add_handler); + if (r < 0) + return r; + + (void) in_addr_to_string(AF_INET6, (union in_addr_union *) addr, &buf); + log_link_debug(link, "Adding prefix route %s/64", strnull(buf)); + + assigned_link = hashmap_get(m->dhcp6_prefixes, addr); + if (assigned_link) { + assert(assigned_link == link); + return 0; + } + + a = newdup(struct in6_addr, addr, 1); + if (!a) + return -ENOMEM; + + r = hashmap_ensure_allocated(&m->dhcp6_prefixes, &in6_addr_hash_ops); + if (r < 0) + return r; + + r = hashmap_put(m->dhcp6_prefixes, a, link); + if (r < 0) + return r; + + TAKE_PTR(a); + link_ref(link); + return 0; +} + +static int dhcp6_prefix_remove_handler(sd_netlink *nl, sd_netlink_message *m, Link *link) { + int r; + + assert(link); + + r = sd_netlink_message_get_errno(m); + if (r < 0) + log_link_debug_errno(link, r, "Received error on DHCPv6 Prefix Delegation route removal: %m"); + + return 1; +} + +int dhcp6_prefix_remove(Manager *m, struct in6_addr *addr) { + _cleanup_free_ struct in6_addr *a = NULL; + _cleanup_(link_unrefp) Link *l = NULL; + _cleanup_free_ char *buf = NULL; + Route *route; + int r; + + assert_return(m, -EINVAL); + assert_return(addr, -EINVAL); + + l = hashmap_remove2(m->dhcp6_prefixes, addr, (void **) &a); + if (!l) + return -EINVAL; + + (void) sd_radv_remove_prefix(l->radv, addr, 64); + r = route_get(l, AF_INET6, (union in_addr_union *) addr, 64, 0, 0, 0, &route); + if (r < 0) + return r; + + r = route_remove(route, l, dhcp6_prefix_remove_handler); + if (r < 0) + return r; + + (void) in_addr_to_string(AF_INET6, (union in_addr_union *) addr, &buf); + log_link_debug(l, "Removing prefix route %s/64", strnull(buf)); + + return 0; +} + +static int dhcp6_prefix_remove_all(Manager *m, Link *link) { + struct in6_addr *addr; + Iterator i; + Link *l; + + assert_return(m, -EINVAL); + assert_return(link, -EINVAL); + + HASHMAP_FOREACH_KEY(l, addr, m->dhcp6_prefixes, i) + if (l == link) + (void) dhcp6_prefix_remove(m, addr); + + return 0; +} diff --git a/src/network/networkd-dhcp6.h b/src/network/networkd-dhcp6.h index 465c62ba7b..26d810f40c 100644 --- a/src/network/networkd-dhcp6.h +++ b/src/network/networkd-dhcp6.h @@ -6,8 +6,10 @@ #include "conf-parser.h" typedef struct Link Link; +typedef struct Manager Manager; int dhcp6_request_prefix_delegation(Link *link); int dhcp6_configure(Link *link); int dhcp6_request_address(Link *link, int ir); int dhcp6_lease_pd_prefix_lost(sd_dhcp6_client *client, Link* link); +int dhcp6_prefix_remove(Manager *m, struct in6_addr *addr); diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 294516879c..e838f4b18a 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -1314,126 +1314,6 @@ static int manager_dirty_handler(sd_event_source *s, void *userdata) { return 1; } -Link *manager_dhcp6_prefix_get(Manager *m, struct in6_addr *addr) { - assert_return(m, NULL); - assert_return(addr, NULL); - - return hashmap_get(m->dhcp6_prefixes, addr); -} - -static int dhcp6_route_add_handler(sd_netlink *nl, sd_netlink_message *m, Link *link) { - int r; - - assert(link); - - r = sd_netlink_message_get_errno(m); - if (r < 0 && r != -EEXIST) - log_link_debug_errno(link, r, "Received error adding DHCPv6 Prefix Delegation route: %m"); - - return 0; -} - -int manager_dhcp6_prefix_add(Manager *m, struct in6_addr *addr, Link *link) { - _cleanup_free_ struct in6_addr *a = NULL; - _cleanup_free_ char *buf = NULL; - Link *assigned_link; - Route *route; - int r; - - assert_return(m, -EINVAL); - assert_return(addr, -EINVAL); - - r = route_add(link, AF_INET6, (union in_addr_union *) addr, 64, - 0, 0, 0, &route); - if (r < 0) - return r; - - r = route_configure(route, link, dhcp6_route_add_handler); - if (r < 0) - return r; - - (void) in_addr_to_string(AF_INET6, (union in_addr_union *) addr, &buf); - log_link_debug(link, "Adding prefix route %s/64", strnull(buf)); - - assigned_link = hashmap_get(m->dhcp6_prefixes, addr); - if (assigned_link) { - assert(assigned_link == link); - return 0; - } - - a = newdup(struct in6_addr, addr, 1); - if (!a) - return -ENOMEM; - - r = hashmap_ensure_allocated(&m->dhcp6_prefixes, &in6_addr_hash_ops); - if (r < 0) - return r; - - r = hashmap_put(m->dhcp6_prefixes, a, link); - if (r < 0) - return r; - - TAKE_PTR(a); - link_ref(link); - return 0; -} - -static int dhcp6_route_remove_handler(sd_netlink *nl, sd_netlink_message *m, Link *link) { - int r; - - assert(link); - - r = sd_netlink_message_get_errno(m); - if (r < 0) - log_link_debug_errno(link, r, "Received error on DHCPv6 Prefix Delegation route removal: %m"); - - return 1; -} - -static int manager_dhcp6_prefix_remove(Manager *m, struct in6_addr *addr) { - _cleanup_free_ struct in6_addr *a = NULL; - _cleanup_(link_unrefp) Link *l = NULL; - _cleanup_free_ char *buf = NULL; - Route *route; - int r; - - assert_return(m, -EINVAL); - assert_return(addr, -EINVAL); - - l = hashmap_remove2(m->dhcp6_prefixes, addr, (void **) &a); - if (!l) - return -EINVAL; - - (void) sd_radv_remove_prefix(l->radv, addr, 64); - r = route_get(l, AF_INET6, (union in_addr_union *) addr, 64, 0, 0, 0, &route); - if (r < 0) - return r; - - r = route_remove(route, l, dhcp6_route_remove_handler); - if (r < 0) - return r; - - (void) in_addr_to_string(AF_INET6, (union in_addr_union *) addr, &buf); - log_link_debug(l, "Removing prefix route %s/64", strnull(buf)); - - return 0; -} - -int manager_dhcp6_prefix_remove_all(Manager *m, Link *link) { - struct in6_addr *addr; - Iterator i; - Link *l; - - assert_return(m, -EINVAL); - assert_return(link, -EINVAL); - - HASHMAP_FOREACH_KEY(l, addr, m->dhcp6_prefixes, i) - if (l == link) - (void) manager_dhcp6_prefix_remove(m, addr); - - return 0; -} - int manager_new(Manager **ret) { _cleanup_(manager_freep) Manager *m = NULL; int r; @@ -1506,7 +1386,7 @@ void manager_free(Manager *m) { free(m->state_file); while ((a = hashmap_first_key(m->dhcp6_prefixes))) - (void) manager_dhcp6_prefix_remove(m, a); + (void) dhcp6_prefix_remove(m, a); hashmap_free(m->dhcp6_prefixes); while ((link = hashmap_steal_first(m->links))) { diff --git a/src/network/networkd-manager.h b/src/network/networkd-manager.h index e0ec45aa2f..9b3b05bccc 100644 --- a/src/network/networkd-manager.h +++ b/src/network/networkd-manager.h @@ -96,8 +96,4 @@ int manager_set_hostname(Manager *m, const char *hostname); int manager_set_timezone(Manager *m, const char *timezone); int manager_request_product_uuid(Manager *m, Link *link); -Link *manager_dhcp6_prefix_get(Manager *m, struct in6_addr *addr); -int manager_dhcp6_prefix_add(Manager *m, struct in6_addr *addr, Link *link); -int manager_dhcp6_prefix_remove_all(Manager *m, Link *link); - DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free); |