b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen This file is part of systemd.
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen Copyright 2013-2014 Tom Gundersen <teg@jklm.no>
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen systemd is free software; you can redistribute it and/or modify it
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen under the terms of the GNU Lesser General Public License as published by
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen the Free Software Foundation; either version 2.1 of the License, or
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen (at your option) any later version.
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen systemd is distributed in the hope that it will be useful, but
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen Lesser General Public License for more details.
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen You should have received a copy of the GNU Lesser General Public License
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen _cleanup_address_free_ Address *address = NULL;
920b52e4909d9dc812817fd8b82f83ca23a11c91Thomas Hindoe Paaboel Andersen link->ipv4ll_address = false;
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen r = sd_ipv4ll_get_address(link->ipv4ll, &addr);
79008bddf679a5e0900369950eb346c9fa687107Lennart Poettering log_link_debug(link, "IPv4 link-local release %u.%u.%u.%u", ADDRESS_FMT_VAL(addr));
e53fc357a9bb9d0a5362ccc4246d598cb0febd5eLennart Poettering log_link_error_errno(link, r, "Could not allocate address: %m");
91b5f997316ddc77d26f9a7a5e24c335484586bdTom Gundersen address_remove(address, link, &link_address_remove_handler);
e53fc357a9bb9d0a5362ccc4246d598cb0febd5eLennart Poettering log_link_error_errno(link, r, "Could not allocate route: %m");
91b5f997316ddc77d26f9a7a5e24c335484586bdTom Gundersen route_remove(route, link, &link_route_remove_handler);
1c4baffc1895809bae9ac36b670af90a4cb9cd7dTom Gundersenstatic int ipv4ll_route_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen if (r < 0 && r != -EEXIST) {
e53fc357a9bb9d0a5362ccc4246d598cb0febd5eLennart Poettering log_link_error_errno(link, r, "could not set ipv4ll route: %m");
1c4baffc1895809bae9ac36b670af90a4cb9cd7dTom Gundersenstatic int ipv4ll_address_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen if (r < 0 && r != -EEXIST) {
e53fc357a9bb9d0a5362ccc4246d598cb0febd5eLennart Poettering log_link_error_errno(link, r, "could not set ipv4ll address: %m");
45af44d47da6933b260c734ad9ff721f63f80a4dTom Gundersen } else if (r >= 0)
200a0868fcdf7b95f3d8d1fda3aa2aef48d84fddTom Gundersen manager_rtnl_process_address(rtnl, m, link->manager);
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersenstatic int ipv4ll_address_claimed(sd_ipv4ll *ll, Link *link) {
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen _cleanup_address_free_ Address *ll_addr = NULL;
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen else if (r < 0)
79008bddf679a5e0900369950eb346c9fa687107Lennart Poettering log_link_debug(link, "IPv4 link-local claim %u.%u.%u.%u",
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen ll_addr->broadcast.s_addr = ll_addr->in_addr.in.s_addr | htonl(0xfffffffflu >> ll_addr->prefixlen);
6666907869fb3bc7fe6a6025540db5b887c7a78bTom Gundersen r = address_configure(ll_addr, link, ipv4ll_address_handler, false);
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen r = route_configure(route, link, ipv4ll_route_handler);
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersenstatic void ipv4ll_handler(sd_ipv4ll *ll, int event, void *userdata){
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
b45e4eb679ad0c9a77c4fe6e404c8842d4097fdbTom Gundersen log_link_warning(link, "IPv4 link-local unknown event: %d", event);
e0ee46f29028e291eb67f435aff1b6202d75d9d6Lennart Poettering assert(link->network->link_local & ADDRESS_FAMILY_IPV4);
dbe81cbd2a93088236a2e4e41eeb33378940f7b9Martin Pitt r = net_get_unique_predictable_data(link->udev_device, &seed);
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen if (r >= 0) {
dbe81cbd2a93088236a2e4e41eeb33378940f7b9Martin Pitt r = sd_ipv4ll_set_address_seed(link->ipv4ll, (unsigned)seed);
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen r = sd_ipv4ll_attach_event(link->ipv4ll, NULL, 0);
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen r = sd_ipv4ll_set_mac(link->ipv4ll, &link->mac);
b22d8a00f48f3c5fc4510b4acd3e1a43e731e592Tom Gundersen r = sd_ipv4ll_set_index(link->ipv4ll, link->ifindex);