loopback-setup.c revision fc25d7f8050f262fa6cafeb2a1032e6eb3e7b412
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering This file is part of systemd.
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering Copyright 2010 Lennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering systemd is free software; you can redistribute it and/or modify it
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering under the terms of the GNU Lesser General Public License as published by
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering (at your option) any later version.
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering systemd is distributed in the hope that it will be useful, but
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering Lesser General Public License for more details.
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering You should have received a copy of the GNU Lesser General Public License
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poetteringstatic int pipe_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering return r == -EEXIST ? 0 : r;
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poetteringstatic int add_adresses(sd_rtnl *rtnl, int if_loopback, uint32_t ipv4_address, int *counter) {
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *ipv4 = NULL, *ipv6 = NULL;
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering r = sd_rtnl_message_addr_new(RTM_NEWADDR, if_loopback, AF_INET, 8, IFA_F_PERMANENT, RT_SCOPE_HOST, &ipv4);
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering r = sd_rtnl_message_append(ipv4, IFA_LOCAL, &ipv4_address);
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering r = sd_rtnl_call_async(rtnl, ipv4, &pipe_handler, counter, 0, NULL);
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering r = sd_rtnl_message_addr_new(RTM_NEWADDR, if_loopback, AF_INET6, 128, 0, 0, &ipv6);
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering r = sd_rtnl_message_append(ipv6, IFA_LOCAL, &in6addr_loopback);
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering r = sd_rtnl_call_async(rtnl, ipv6, &pipe_handler, counter, 0, NULL);
(*counter) ++;
static int check_loopback(void) {
} sa = {
if (fd < 0)
return -errno;
int loopback_setup(void) {
bool eperm = false;
errno = 0;
if (if_loopback <= 0)
while (counter > 0) {
if (r == -EPERM)
eperm = true;
return -EPERM;