networkd-dhcp4.c revision 39745a5afb24ba0c877122aa1967d58f02c5435f
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering This file is part of systemd.
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering Copyright 2013-2014 Tom Gundersen <teg@jklm.no>
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering systemd is free software; you can redistribute it and/or modify it
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering under the terms of the GNU Lesser General Public License as published by
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering (at your option) any later version.
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering systemd is distributed in the hope that it will be useful, but
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering Lesser General Public License for more details.
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering You should have received a copy of the GNU Lesser General Public License
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
6482f6269c87d2249e52e889a63adbdd50f2d691Ronny Chevalierstatic int dhcp4_route_handler(sd_netlink *rtnl, sd_netlink_message *m,
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering if (r < 0 && r != -EEXIST) {
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering log_link_error(link, "could not set DHCPv4 route: %s",
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poetteringstatic int link_set_dhcp_routes(Link *link) {
85a428c69465b047731b6abb5005f01824f1444eLennart Poettering r = sd_dhcp_lease_get_router(link->dhcp_lease, &gateway);
af9792ac7f39354f80e9006c42c2400c5e41c447Lennart Poettering if (r < 0 && r != -ENOENT) {
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering "DHCP error: could not get gateway: %s",
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering _cleanup_route_free_ Route *route = NULL;
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering _cleanup_route_free_ Route *route_gw = NULL;
2d62c530d2b4c2730abff715b7342f1402114513Lennart Poettering r = sd_dhcp_lease_get_address(link->dhcp_lease, &address);
f9cd6be10ece07e10488c05e270a0b5860779864Lennart Poettering "DHCP error: could not get address: %s",
f9cd6be10ece07e10488c05e270a0b5860779864Lennart Poettering r = route_new_dynamic(&route, RTPROT_DHCP);
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering "Could not allocate route: %s",
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering r = route_new_dynamic(&route_gw, RTPROT_DHCP);
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering "Could not allocate route: %s",
ed4ba7e4f652150310d062ffbdfefb4521ce1054Lennart Poettering /* The dhcp netmask may mask out the gateway. Add an explicit
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering * route for the gw host so that we can route no matter the
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering * netmask or existing kernel route tables. */
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek route_gw->scope = RT_SCOPE_LINK;
dc3a1b76a6a6f9dfe9b451f534587251b50a0685Lennart Poettering route_gw->metrics = link->network->dhcp_route_metric;
dc3a1b76a6a6f9dfe9b451f534587251b50a0685Lennart Poettering r = route_configure(route_gw, link, &dhcp4_route_handler);
7801356442578ff6e1c65844eb9e65c819af4660Zbigniew Jędrzejewski-Szmek "could not set host route: %s",
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering route->metrics = link->network->dhcp_route_metric;
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering r = route_configure(route, link, &dhcp4_route_handler);
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering "could not set routes: %s",
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering n = sd_dhcp_lease_get_routes(link->dhcp_lease, &static_routes);
de0671ee7fe465e108f62dcbbbe9366f81dd9e9aZbigniew Jędrzejewski-Szmek "DHCP error: could not get routes: %s",
de0671ee7fe465e108f62dcbbbe9366f81dd9e9aZbigniew Jędrzejewski-Szmek for (i = 0; i < n; i++) {
de0671ee7fe465e108f62dcbbbe9366f81dd9e9aZbigniew Jędrzejewski-Szmek _cleanup_route_free_ Route *route = NULL;
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering r = route_new_dynamic(&route, RTPROT_DHCP);
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering log_link_error(link, "Could not allocate route: %s",
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering route->in_addr.in = static_routes[i].gw_addr;
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering route->dst_addr.in = static_routes[i].dst_addr;
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering route->dst_prefixlen = static_routes[i].dst_prefixlen;
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering route->metrics = link->network->dhcp_route_metric;
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering r = route_configure(route, link, &dhcp4_route_handler);
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering "could not set host route: %s",
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering _cleanup_address_free_ Address *address = NULL;
unsigned prefixlen = 0;
if (r >= 0 || hostname) {
hostname);
void *userdata) {
r = sd_netlink_message_get_errno(m);
if (r < 0 && r != -EEXIST) {
strerror(-r));
unsigned prefixlen;
strerror(-r));
strerror(-r));
strerror(-r));
&lifetime);
strerror(-r));
strerror(-r));
unsigned prefixlen;
if (r < 0 && r != -ENOENT)
NULL);
NULL);
if (r >= 0 || hostname) {
switch (event) {
case DHCP_EVENT_EXPIRED:
case DHCP_EVENT_STOP:
case DHCP_EVENT_IP_CHANGE:
case DHCP_EVENT_RENEW:
case DHCP_EVENT_IP_ACQUIRE:
if (event < 0)
event);
if (!hostname)
return -ENOMEM;
case DHCP_CLIENT_ID_DUID:
case DHCP_CLIENT_ID_MAC: