networkd-dhcp4.c revision 8eb9058dc1f99a5eb9b8726a978fcc0720837a10
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013-2014 Tom Gundersen <teg@jklm.no>
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "hostname-util.h"
#include "networkd-link.h"
#include "network-internal.h"
#include "dhcp-lease-internal.h"
void *userdata) {
int r;
link->dhcp4_messages --;
r = sd_netlink_message_get_errno(m);
if (r < 0 && r != -EEXIST) {
strerror(-r));
}
if (!link->dhcp4_messages) {
link->dhcp4_configured = true;
}
return 1;
}
struct sd_dhcp_route *static_routes;
int r, n, i;
if (r < 0 && r != -ENOENT) {
"DHCP error: could not get gateway: %s",
strerror(-r));
return r;
}
if (r >= 0) {
if (r < 0) {
"DHCP error: could not get address: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not allocate route: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not allocate route: %s",
strerror(-r));
return r;
}
/* The dhcp netmask may mask out the gateway. Add an explicit
* route for the gw host so that we can route no matter the
* netmask or existing kernel route tables. */
if (r < 0) {
"could not set host route: %s",
strerror(-r));
return r;
}
link->dhcp4_messages ++;
if (r < 0) {
"could not set routes: %s",
strerror(-r));
return r;
}
link->dhcp4_messages ++;
}
if (n == -ENOENT)
return 0;
if (n < 0) {
"DHCP error: could not get routes: %s",
strerror(-n));
return n;
}
for (i = 0; i < n; i++) {
if (r < 0) {
strerror(-r));
return r;
}
if (r < 0) {
"could not set host route: %s",
strerror(-r));
return r;
}
link->dhcp4_messages ++;
}
return 0;
}
unsigned prefixlen = 0;
int r;
struct sd_dhcp_route *routes;
int n, i;
if (n >= 0) {
for (i = 0; i < n; i++) {
if (r >= 0) {
}
}
}
}
r = address_new_dynamic(&address);
if (r >= 0) {
if (r >= 0) {
if (r >= 0) {
}
if (r >= 0) {
}
}
if (r >= 0) {
if (r >= 0)
}
}
if (r < 0) {
"DHCP error: could not reset MTU");
return r;
}
}
}
else
if (r >= 0 || hostname) {
if (r < 0)
"Failed to set transient hostname to '%s': %m",
hostname);
}
}
link->dhcp4_configured = false;
return 0;
}
void *userdata) {
int r;
r = sd_netlink_message_get_errno(m);
if (r < 0 && r != -EEXIST) {
strerror(-r));
} else if (r >= 0)
return 1;
}
unsigned prefixlen;
int r;
r = address_new_dynamic(&addr);
if (r < 0)
return r;
/* use update rather than configure so that we will update the
* lifetime of an existing address if it has already been configured */
if (r < 0)
return r;
return 0;
}
int r;
if (r < 0) {
strerror(-r));
return r;
}
link->dhcp4_configured = false;
if (r < 0) {
strerror(-r));
return r;
}
if (r < 0) {
strerror(-r));
return r;
}
&lifetime);
if (r < 0) {
"DHCP error: no lifetime: %s",
strerror(-r));
return r;
}
}
if (r < 0) {
strerror(-r));
return r;
}
return 0;
}
unsigned prefixlen;
int r;
if (r < 0)
if (r < 0)
if (r < 0)
if (r < 0 && r != -ENOENT)
if (r >= 0)
"PREFIXLEN=%u", prefixlen,
NULL);
else
"PREFIXLEN=%u", prefixlen,
NULL);
if (r >= 0) {
if (r < 0)
}
}
else
if (r >= 0 || hostname) {
if (r < 0)
}
}
if (r < 0) {
return r;
}
}
if (r < 0) {
return r;
}
return 0;
}
int r = 0;
return;
switch (event) {
case DHCP_EVENT_EXPIRED:
case DHCP_EVENT_STOP:
case DHCP_EVENT_IP_CHANGE:
"DHCPv4 connection considered system critical, ignoring request to reconfigure it.");
return;
}
if (link->dhcp_lease) {
r = dhcp_lease_lost(link);
if (r < 0) {
return;
}
}
if (event == DHCP_EVENT_IP_CHANGE) {
if (r < 0) {
return;
}
}
break;
case DHCP_EVENT_RENEW:
if (r < 0) {
return;
}
break;
case DHCP_EVENT_IP_ACQUIRE:
if (r < 0) {
return;
}
break;
default:
if (event < 0)
"DHCP error: client failed: %s",
else
"DHCP unknown event: %d",
event);
break;
}
return;
}
int r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
}
if (r < 0)
return r;
}
if (r < 0)
return r;
if (r < 0)
return r;
}
/* Always acquire the timezone */
if (r < 0)
return r;
if (!hostname)
return -ENOMEM;
} else
if (!is_localhost(hn)) {
if (r < 0)
return r;
}
}
if (r < 0)
return r;
}
case DHCP_CLIENT_ID_DUID:
/* Library defaults to this. */
break;
case DHCP_CLIENT_ID_MAC:
if (r < 0)
return r;
break;
default:
assert_not_reached("Unknown client identifier type.");
}
return 0;
}