loopback-setup.c revision 4fb7242cbbed0d865eb343548b8f0ee0fee71d85
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
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 <errno.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "util.h"
#include "macro.h"
#include "loopback-setup.h"
#include "socket-util.h"
#include "sd-rtnl.h"
#include "rtnl-util.h"
int r;
(*counter) --;
r = sd_rtnl_message_get_errno(m);
return r == -EEXIST ? 0 : r;
}
static int add_addresses(sd_rtnl *rtnl, int if_loopback, struct in_addr *ipv4_address, int *counter) {
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;
(*counter) ++;
if (!socket_ipv6_is_supported())
return 0;
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;
(*counter) ++;
return 0;
}
static int start_interface(sd_rtnl *rtnl, int if_loopback, struct in_addr *ipv4_address, int *counter) {
int r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
(*counter) ++;
return 0;
}
static int check_loopback(void) {
int r;
union {
struct sockaddr_in in;
} sa = {
};
/* If we failed to set up the loop back device, check whether
* it might already be set up */
if (fd < 0)
return -errno;
r = 1;
else
return r;
}
int loopback_setup(void) {
int r, if_loopback, counter = 0;
bool eperm = false;
struct in_addr ipv4_address;
errno = 0;
if (if_loopback <= 0)
r = sd_rtnl_open(0, &rtnl);
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
while (counter > 0) {
r = sd_rtnl_wait(rtnl, 0);
if (r < 0)
return r;
r = sd_rtnl_process(rtnl, 0);
if (r < 0) {
if (r == -EPERM)
eperm = true;
else {
return r;
}
}
}
if (eperm && check_loopback() < 0) {
return -EPERM;
}
return 0;
}