networkd-link.c revision ecd2f2c5947d9e2f4d6792c2a3a90b8ced6a5b3e
/*-*- 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"
const char *mac;
struct ether_addr *mac_addr;
const char *ifname;
int r;
if (!link)
return -ENOMEM;
return -EINVAL;
if (mac) {
if (mac_addr)
}
if (r < 0)
return r;
return 0;
}
if (!link)
return;
}
int r;
assert(m);
if (link) {
return -EEXIST;
}
if (r < 0)
return r;
if (r < 0)
return r == -ENOENT ? 0 : r;
if (r < 0)
return r;
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;
}
int r;
return link_enter_configured(link);
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);
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;
}
int r;
return link_enter_set_routes(link);
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 1;
}
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,
"org.freedesktop.hostname1",
"/org/freedesktop/hostname1",
"org.freedesktop.hostname1",
"SetHostname",
&m);
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)
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;
}
r = dhcp_lease_lost(link);
if (r < 0) {
return;
}
if (event == DHCP_EVENT_IP_CHANGE) {
if (r < 0) {
return;
}
}
break;
case DHCP_EVENT_IP_ACQUIRE:
if (r < 0) {
return;
}
break;
default:
if (event < 0)
else
break;
}
return;
}
int 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;
}
}
}
}
return 0;
}
int r;
return 1;
r = sd_rtnl_message_get_errno(m);
if (r < 0) {
"MESSAGE=%s: could not bring up interface: %s",
"ERRNO=%d", -r,
NULL);
return 1;
}
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;
}
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;
}
}
return 0;
}
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;
if (r < 0) {
return r;
}
return link_enter_enslave(link);
}
unsigned flags;
void *data;
int r;
assert(m);
return 0;
r = sd_rtnl_message_link_get_flags(m, &flags);
if (r < 0) {
return r;
}
link->original_mtu);
}
}
}