networkd-link.c revision a748b692dd1e436ca1ff56b8d567c065c2539e5a
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 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 "networkd.h"
#include "libudev-private.h"
#include "util.h"
#include "bus-util.h"
#include "net-util.h"
#include "dhcp-lease-internal.h"
const char *mac;
struct ether_addr *mac_addr;
const char *ifname;
int r;
if (!link)
return -ENOMEM;
return -EINVAL;
if (r < 0)
return r;
if (mac) {
if (mac_addr)
}
if (r < 0)
return r;
return 0;
}
if (!link)
return;
}
assert(m);
if (!link)
return -ENODEV;
return 0;
}
return 0;
}
}
int r;
link->route_messages --;
return 1;
r = sd_rtnl_message_get_errno(m);
if (r < 0 && r != -EEXIST)
"MESSAGE=%s: could not set route: %s",
"ERRNO=%d", -r,
NULL);
/* we might have received an old reply after moving back to SETTING_ADDRESSES,
* ignore it */
}
return 1;
}
struct in_addr a;
int r;
return link_enter_configured(link);
if (r < 0) {
"could not set routes: %s", strerror(-r));
return r;
}
link->route_messages ++;
}
if (r < 0 && r != -ENOENT) {
strerror(-r));
return r;
}
if (r != -ENOENT) {
r = route_new_dynamic(&route);
if (r < 0) {
strerror(-r));
return r;
}
if (r < 0) {
"could not set routes: %s", strerror(-r));
return r;
}
link->route_messages ++;
}
}
if (link->dhcp_lease) {
if (r < 0) {
strerror(-r));
return r;
}
r = route_new_dynamic(&route);
if (r < 0) {
strerror(-r));
return r;
}
if (r < 0) {
"could not set routes: %s", strerror(-r));
return r;
}
link->route_messages ++;
}
return 0;
}
int r;
assert(m);
return 1;
r = sd_rtnl_message_get_errno(m);
if (r < 0 && r != -ENOENT)
"MESSAGE=%s: could not drop route: %s",
"ERRNO=%d", -r,
NULL);
return 0;
}
int r;
assert(m);
link->addr_messages --;
return 1;
r = sd_rtnl_message_get_errno(m);
if (r < 0 && r != -EEXIST)
"MESSAGE=%s: could not set address: %s",
"ERRNO=%d", -r,
NULL);
if (link->addr_messages == 0) {
}
return 1;
}
struct in_addr a;
int r;
return link_enter_set_routes(link);
if (r < 0) {
"could not set addresses: %s", strerror(-r));
return r;
}
link->addr_messages ++;
}
if (r < 0 && r != -ENOENT) {
strerror(-r));
return r;
}
if (r != -ENOENT) {
r = address_new_dynamic(&ll_addr);
if (r < 0) {
return r;
}
if (r < 0) {
"could not set addresses: %s", strerror(-r));
return r;
}
link->addr_messages ++;
}
}
if (link->dhcp_lease) {
unsigned prefixlen;
if (r < 0) {
strerror(-r));
return r;
}
if (r < 0) {
strerror(-r));
return r;
}
r = address_new_dynamic(&address);
if (r < 0) {
strerror(-r));
return r;
}
if (r < 0) {
"could not set addresses: %s", strerror(-r));
return r;
}
link->addr_messages ++;
}
return 0;
}
int r;
assert(m);
return 1;
r = sd_rtnl_message_get_errno(m);
if (r < 0 && r != -ENOENT)
"MESSAGE=%s: could not drop address: %s",
"ERRNO=%d", -r,
NULL);
return 0;
}
static int set_hostname_handler(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
int r;
r = sd_bus_message_get_errno(m);
if (r < 0)
return 1;
}
int r = 0;
if (!bus) { /* TODO: replace by assert when we can rely on kdbus */
log_info("Not connected to system bus, ignoring transient hostname.");
return 0;
}
bus,
&m,
"org.freedesktop.hostname1",
"/org/freedesktop/hostname1",
"org.freedesktop.hostname1",
"SetHostname");
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
}
int r;
assert(m);
return 1;
r = sd_rtnl_message_get_errno(m);
if (r < 0)
"MESSAGE=%s: could not set MTU: %s",
"ERRNO=%d", -r,
NULL);
return 1;
}
int r;
if (r < 0) {
return r;
}
if (r < 0) {
return r;
}
if (r < 0) {
"Could not send rtnetlink message: %s", strerror(-r));
return r;
}
return 0;
}
unsigned prefixlen;
int r;
r = address_new_dynamic(&address);
if (r >= 0) {
}
if (r < 0) {
return r;
}
}
}
if (r >= 0 && hostname) {
if (r < 0)
log_error("Failed to reset transient hostname");
}
}
return 0;
}
unsigned prefixlen;
struct in_addr *nameservers;
int r;
if (r < 0) {
strerror(-r));
return r;
}
if (r < 0) {
strerror(-r));
return r;
}
if (r < 0) {
strerror(-r));
return r;
}
if (r < 0) {
strerror(-r));
return r;
}
"MESSAGE=%s: DHCPv4 address %u.%u.%u.%u/%u via %u.%u.%u.%u",
"ADDRESS=%u.%u.%u.%u",
"PREFIXLEN=%u",
"GATEWAY=%u.%u.%u.%u",
NULL);
if (r >= 0) {
if (r < 0)
log_error("Failed to update resolv.conf");
}
}
if (r >= 0) {
if (r < 0)
}
}
const char *hostname;
if (r >= 0) {
if (r < 0)
log_error("Failed to set transient hostname "
"to '%s'", hostname);
}
}
return 0;
}
int r;
return;
switch (event) {
case DHCP_EVENT_NO_LEASE:
break;
case DHCP_EVENT_EXPIRED:
case DHCP_EVENT_STOP:
case DHCP_EVENT_IP_CHANGE:
"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;
}
}
if (r < 0) {
return;
}
}
break;
case DHCP_EVENT_IP_ACQUIRE:
if (r < 0) {
return;
}
if (r < 0) {
return;
}
}
break;
default:
if (event < 0)
else
break;
}
return;
}
int r;
if (r >= 0) {
r = address_new_dynamic(&address);
if (r < 0) {
return r;
}
r = route_new_dynamic(&route);
if (r < 0) {
strerror(-r));
return r;
}
}
return 0;
}
int r;
if (r < 0)
return r;
"MESSAGE=%s: IPv4 link-local address %u.%u.%u.%u",
NULL);
return 0;
}
int r;
switch(event) {
case IPV4LL_EVENT_STOP:
case IPV4LL_EVENT_CONFLICT:
if (r < 0) {
return;
}
break;
case IPV4LL_EVENT_BIND:
if (r < 0) {
return;
}
break;
default:
if (event < 0)
else
break;
}
}
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 (!link->dhcp_client) {
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;
}
return 0;
}
int r;
return 0;
return 0;
if (flags & IFF_LOWER_UP) {
r = link_acquire_conf(link);
if (r < 0) {
return r;
}
}
} else {
if (r < 0) {
return r;
}
}
if (r < 0) {
return r;
}
}
}
}
return 0;
}
int r;
return 1;
r = sd_rtnl_message_get_errno(m);
if (r >= 0)
else
"MESSAGE=%s: could not bring up interface: %s",
"ERRNO=%d", -r,
NULL);
return 1;
}
int r;
if (r < 0) {
return r;
}
if (r < 0) {
return r;
}
if (r < 0) {
"Could not send rtnetlink message: %s", strerror(-r));
return r;
}
return 0;
}
int r;
if (r < 0) {
return r;
}
return link_enter_set_addresses(link);
return 0;
}
int r;
return 1;
r = sd_rtnl_message_get_errno(m);
if (r < 0) {
"MESSAGE=%s: could not enslave: %s",
"ERRNO=%d", -r,
NULL);
return 1;
}
return 1;
}
Iterator i;
int r;
return link_enslaved(link);
"MESSAGE=%s: enslaving by '%s'",
NULL);
if (r < 0) {
"MESSAGE=%s: could not enslave by '%s': %s",
NULL);
return r;
}
}
"MESSAGE=%s: enslaving by '%s'",
NULL);
if (r < 0) {
"MESSAGE=%s: could not enslave by '%s': %s",
NULL);
return r;
}
}
"MESSAGE=%s: enslaving by '%s'",
if (r < 0) {
"MESSAGE=%s: could not enslave by '%s': %s",
return r;
}
}
"MESSAGE=%s: enslaving by '%s'",
if (r < 0) {
"MESSAGE=%s: could not enslave by '%s': %s",
return r;
}
}
return 0;
}
void *userdata) {
int r;
return 1;
r = sd_rtnl_message_get_errno(m);
if (r < 0) {
"MESSAGE=%s: could not get state: %s",
"ERRNO=%d", -r,
NULL);
return 1;
}
link_update(link, m);
return 1;
}
int r;
if (r < 0) {
return r;
}
if (r < 0) {
"Could not send rtnetlink message: %s", strerror(-r));
return r;
}
return 0;
}
int r;
r = link_getlink(link);
if (r < 0)
return r;
return link_enter_enslave(link);
}
int r;
assert(m);
if (r < 0)
return r;
if (r < 0)
return r == -ENOENT ? 0 : r;
if (r < 0)
return r;
r = link_configure(link);
if (r < 0)
return r;
return 0;
}
unsigned flags;
int r;
assert(m);
return 0;
!link->original_mtu) {
if (r >= 0)
}
if (r >= 0) {
"%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
}
r = sd_rtnl_message_link_get_flags(m, &flags);
if (r < 0) {
return r;
}
}
int r;
if (r < 0)
goto finish;
if (r < 0)
goto finish;
fprintf(f,
"# This is private data. Do not parse.\n"
"STATE=%s\n",
if (link->dhcp_lease) {
const char *lease_file = "/run/systemd/network/leases/test.lease";
if (r < 0)
goto finish;
}
fflush(f);
r = -errno;
}
if (r < 0)
return r;
}
static const char* const link_state_table[_LINK_STATE_MAX] = {
[LINK_STATE_ENSLAVING] = "configuring",
[LINK_STATE_SETTING_ADDRESSES] = "configuring",
[LINK_STATE_SETTING_ROUTES] = "configuring",
[LINK_STATE_CONFIGURED] = "configured",
[LINK_STATE_FAILED] = "failed",
};