X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fnetwork%2Fnetworkd-address.c;h=539bd98b52c98f1a5b5e5a41b0e14bf90d5876b7;hp=ce015004de7e6209ca25f1cbcf2606d12dce26a9;hb=16aa63a00b5b1db23a9c0b8de350ebf482d90cd0;hpb=11bf3cced13c885ca215c108cb0bdb7a148520d6 diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index ce015004d..539bd98b5 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -41,8 +41,7 @@ int address_new_static(Network *network, unsigned section, Address **ret) { _cleanup_address_free_ Address *address = NULL; if (section) { - uint64_t key = section; - address = hashmap_get(network->addresses_by_section, &key); + address = hashmap_get(network->addresses_by_section, UINT_TO_PTR(section)); if (address) { *ret = address; address = NULL; @@ -63,7 +62,8 @@ int address_new_static(Network *network, unsigned section, Address **ret) { if (section) { address->section = section; - hashmap_put(network->addresses_by_section, &address->section, address); + hashmap_put(network->addresses_by_section, + UINT_TO_PTR(address->section), address); } *ret = address; @@ -96,7 +96,7 @@ void address_free(Address *address) { if (address->section) hashmap_remove(address->network->addresses_by_section, - &address->section); + UINT_TO_PTR(address->section)); } free(address); @@ -144,6 +144,8 @@ int address_drop(Address *address, Link *link, return r; } + link_ref(link); + return 0; } @@ -225,13 +227,15 @@ int address_update(Address *address, Link *link, return r; } + link_ref(link); + return 0; } static int address_acquire(Link *link, Address *original, Address **ret) { union in_addr_union in_addr = {}; struct in_addr broadcast = {}; - Address *na = NULL; + _cleanup_address_free_ Address *na = NULL; int r; assert(link); @@ -274,11 +278,8 @@ static int address_acquire(Link *link, Address *original, Address **ret) { if (original->label) { na->label = strdup(original->label); - - if (!na->label) { - free(na); + if (!na->label) return -ENOMEM; - } } na->broadcast = broadcast; @@ -287,6 +288,8 @@ static int address_acquire(Link *link, Address *original, Address **ret) { LIST_PREPEND(addresses, link->pool_addresses, na); *ret = na; + na = NULL; + return 0; } @@ -342,13 +345,25 @@ int address_configure(Address *address, Link *link, return r; } - if (address->family == AF_INET) { - r = sd_rtnl_message_append_in_addr(req, IFA_BROADCAST, &address->broadcast); + if (!in_addr_null(address->family, &address->in_addr_peer)) { + if (address->family == AF_INET) + r = sd_rtnl_message_append_in_addr(req, IFA_ADDRESS, &address->in_addr_peer.in); + else if (address->family == AF_INET6) + r = sd_rtnl_message_append_in6_addr(req, IFA_ADDRESS, &address->in_addr_peer.in6); if (r < 0) { - log_error("Could not append IFA_BROADCAST attribute: %s", + log_error("Could not append IFA_ADDRESS attribute: %s", strerror(-r)); return r; } + } else { + if (address->family == AF_INET) { + r = sd_rtnl_message_append_in_addr(req, IFA_BROADCAST, &address->broadcast); + if (r < 0) { + log_error("Could not append IFA_BROADCAST attribute: %s", + strerror(-r)); + return r; + } + } } if (address->label) { @@ -360,60 +375,21 @@ int address_configure(Address *address, Link *link, } } - r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL); + r = sd_rtnl_message_append_cache_info(req, IFA_CACHEINFO, + &address->cinfo); if (r < 0) { - log_error("Could not send rtnetlink message: %s", strerror(-r)); + log_error("Could not append IFA_CACHEINFO attribute: %s", + strerror(-r)); return r; } - return 0; -} - -int config_parse_dns(const char *unit, - const char *filename, - unsigned line, - const char *section, - unsigned section_line, - const char *lvalue, - int ltype, - const char *rvalue, - void *data, - void *userdata) { - Network *network = userdata; - Address *tail; - _cleanup_address_free_ Address *n = NULL; - int r; - - assert(filename); - assert(section); - assert(lvalue); - assert(rvalue); - assert(network); - - r = address_new_dynamic(&n); - if (r < 0) - return r; - - r = net_parse_inaddr(rvalue, &n->family, &n->in_addr); + r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL); if (r < 0) { - log_syntax(unit, LOG_ERR, filename, line, EINVAL, - "DNS address is invalid, ignoring assignment: %s", rvalue); - return 0; - } - - if (streq(lvalue, "DNS")) { - LIST_FIND_TAIL(addresses, network->dns, tail); - LIST_INSERT_AFTER(addresses, network->dns, tail, n); - } else if (streq(lvalue, "NTP")) { - LIST_FIND_TAIL(addresses, network->ntp, tail); - LIST_INSERT_AFTER(addresses, network->ntp, tail, n); - } else { - log_syntax(unit, LOG_ERR, filename, line, EINVAL, - "Key is invalid, ignoring assignment: %s=%s", lvalue, rvalue); - return 0; + log_error("Could not send rtnetlink message: %s", strerror(-r)); + return r; } - n = NULL; + link_ref(link); return 0; } @@ -475,6 +451,7 @@ int config_parse_address(const char *unit, Network *network = userdata; _cleanup_address_free_ Address *n = NULL; _cleanup_free_ char *address = NULL; + union in_addr_union *addr; const char *e; int r; @@ -494,6 +471,11 @@ int config_parse_address(const char *unit, if (r < 0) return r; + if (streq(lvalue, "Address")) + addr = &n->in_addr; + else + addr = &n->in_addr_peer; + /* Address=address/prefixlen */ /* prefixlen */ @@ -519,7 +501,7 @@ int config_parse_address(const char *unit, return log_oom(); } - r = net_parse_inaddr(address, &n->family, &n->in_addr); + r = net_parse_inaddr(address, &n->family, addr); if (r < 0) { log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Address is invalid, ignoring assignment: %s", address);