conf.c revision 5e97c3fcce787a5bc0f8ceef43aa3e05195b480a
/*
* lxc: linux Container library
*
* (C) Copyright IBM Corp. 2007, 2008
*
* Authors:
* Daniel Lezcano <dlezcano at fr.ibm.com>
*
* modify it 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.
*
* This library 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 this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <dirent.h>
#include <mntent.h>
#include <unistd.h>
#include <fcntl.h>
#include <network.h>
#include <list.h>
#include <conf.h>
#include <log.h>
#include <lxc.h>
#define MAXHWLEN 18
#define MAXINDEXLEN 20
#define MAXLINELEN 128
typedef int (*instanciate_cb)(const char *dirname,
struct netdev_conf {
const char *type;
int count;
};
static int instanciate_veth(const char *, const char *, pid_t);
static int instanciate_macvlan(const char *, const char *, pid_t);
static int instanciate_phys(const char *, const char *, pid_t);
static struct netdev_conf netdev_conf[] = {
{ "veth", instanciate_veth, 0 },
{ "macvlan", instanciate_macvlan, 0, },
{ "phys", instanciate_phys, 0, },
};
{
return 0;
return 1;
}
{
int n;
if (n < 0) {
return -1;
}
while (n--) {
lxc_log_error("callback failed");
return -1;
}
}
return 0;
}
{
FILE *f;
int err = -1;
if (!f) {
return -1;
}
goto out;
err = 0;
out:
fclose(f);
return err;
}
{
char *f;
if (fd < 0)
goto out;
goto out_write;
err = 0;
out:
free(f);
return err;
unlink(f);
goto out;
}
{
char *f, *token;
if (fd < 0) {
ret = 1;
goto out;
}
if (ret < 0)
goto out;
if (token)
*token = '\0';
ret = 0;
out:
free(f);
return ret;
}
{
char *info;
int ret;
return ret;
}
{
char addr[INET6_ADDRSTRLEN];
char bcast[INET_ADDRSTRLEN];
return -1;
}
if (fd < 0) {
goto err;
}
lxc_log_syserror("failed to convert ipv4 address");
goto err;
}
lxc_log_syserror("failed to convert ipv4 broadcast");
goto err;
}
else
lxc_log_syserror("failed to write address info");
goto err;
}
}
} else {
lxc_log_syserror("failed to convert ipv4 address");
goto err;
}
lxc_log_syserror("failed to write address info to %s",
file);
goto err;
}
}
}
err = 0;
out:
return err;
err:
goto out;
}
{
int err = -1;
char dir[MAXPATHLEN];
return -1;
}
goto out_link;
}
goto out_newname;
}
goto out_up;
}
goto out_hwaddr;
}
goto out_ipv4;
}
goto out_ipv6;
}
err = 0;
out:
return err;
goto out;
}
{
char path[MAXPATHLEN];
if (!utsname)
return 0;
lxc_log_error("failed to write the utsname info");
return -1;
}
return 0;
}
{
struct network *n;
int err = -1;
if (list_empty(network))
return 0;
goto out;
}
lxc_log_error("invalid network configuration type %d",
n->type);
goto out;
}
lxc_log_error("failed to configure network type %s",
goto out;
}
}
err = 0;
out:
return err;
}
{
if (!cgroup)
return 0;
return 0;
}
{
int ret;
char *path;
if (!chroot)
return 0;
return ret;
}
{
char *path;
char c = '\0';
int ret = -1;
if (!fstab)
return 0;
if (outfd < 0) {
goto out;
}
if (infd < 0) {
goto out;
}
goto out;
}
goto out;
}
/* fixup length */
goto out;
}
if (src == MAP_FAILED) {
goto out;
}
if (dst == MAP_FAILED) {
goto out;
}
ret = 0;
out:
return ret;
}
static int unconfigure_ip_addresses(const char *dirname)
{
char path[MAXPATHLEN];
return 0;
}
{
char *path;
return 0;
}
static int unconfigure_network(const char *name)
{
char *dirname;
if (!conf_has_network(name))
return 0;
return 0;
}
static int unconfigure_cgroup(const char *name)
{
return 0;
}
static int unconfigure_chroot(const char *name)
{
char *path;
return 0;
}
static int unconfigure_mount(const char *name)
{
char *path;
if (!conf_has_fstab(name))
return 0;
return 0;
}
static int unconfigure_utsname(const char *name)
{
char *path;
if (!conf_has_utsname(name))
return 0;
return 0;
}
static int setup_utsname(const char *name)
{
int ret;
char *path;
if (!conf_has_utsname(name))
return 0;
if (ret < 0) {
lxc_log_syserror("failed to read utsname info");
goto out;
}
lxc_log_syserror("failed to set the hostname to '%s'",
goto out;
}
ret = 0;
out:
return ret;
}
static int setup_chroot(const char *name)
{
int ret = -1;
goto out;
}
lxc_log_syserror("failed to change to home directory");
goto out;
}
}
ret = 0;
out:
return ret;
}
static int setup_mount(const char *name)
{
char *path;
int ret = -1;
if (!conf_has_fstab(name))
return 0;
if (!file) {
return 0;
goto out;
}
lxc_log_syserror("failed to mount '%s' on '%s'",
goto out;
}
}
ret = 0;
out:
return ret;
}
{
int p = 24;
if (cursor) {
*cursor = '\0';
if (cursor)
*cursor = '\0';
}
if (slash) {
*slash = '\0';
}
if (prefix)
return -1;
}
return 0;
}
{
int p = 24;
if (cursor) {
*cursor = '\0';
if (cursor)
*cursor = '\0';
}
if (slash) {
*slash = '\0';
}
if (prefix)
return -1;
}
return 0;
}
{
return -1;
}
if (fd < 0) {
perror("socket");
return -1;
}
if (ret)
perror("ioctl");
return ret;
}
{
struct stat s;
int ret = 0;
return ret;
}
{
struct stat s;
int ret = 0;
return ret;
}
{
char *path;
char strindex[MAXINDEXLEN];
char *current_ifname = ifname;
lxc_log_error("failed to read ifindex info");
goto out;
}
if (!ifindex) {
goto out;
}
lxc_log_error("no interface corresponding to index '%d'",
ifindex);
goto out;
}
lxc_log_error("failed to rename %s->%s",
goto out;
}
}
lxc_log_error("failed to setup hw address for '%s'",
goto out;
}
}
lxc_log_error("failed to setup ip addresses for '%s'",
ifname);
goto out;
}
lxc_log_error("failed to setup ipv6 addresses for '%s'",
ifname);
goto out;
}
if (device_up(current_ifname)) {
goto out;
}
/* the network is up, make the loopback up too */
if (device_up("lo")) {
lxc_log_error("failed to set the loopback up");
goto out;
}
}
ret = 0;
out:
return ret;
}
static int setup_network(const char *name)
{
char *dirname;
int ret = -1;
if (!conf_has_network(name))
return 0;
return ret;
}
{
int ret;
char *path;
if (!ret) {
ret = 1;
goto out;
}
ret = 0;
goto out;
}
out:
return ret;
}
{
if (!conf)
return 0;
lxc_log_error("failed to configure the utsname");
return -1;
}
lxc_log_error("failed to configure the network");
return -1;
}
lxc_log_error("failed to configure the control group");
return -1;
}
lxc_log_error("failed to configure the chroot");
return -1;
}
lxc_log_error("failed to configure the mount points");
return -1;
}
return 0;
}
int lxc_unconfigure(const char *name)
{
if (unconfigure_utsname(name))
lxc_log_error("failed to cleanup utsname");
if (unconfigure_network(name))
lxc_log_error("failed to cleanup the network");
if (unconfigure_cgroup(name))
lxc_log_error("failed to cleanup cgroup");
if (unconfigure_chroot(name))
lxc_log_error("failed to cleanup chroot");
if (unconfigure_mount(name))
lxc_log_error("failed to cleanup mount");
return 0;
}
{
lxc_log_error("failed to read bridge info");
goto out;
}
goto out;
}
if (!ifindex) {
goto out;
}
goto out;
}
goto out;
}
}
ret = 0;
out:
return ret;
}
{
lxc_log_error("failed to read bridge info");
goto out;
}
goto out;
}
if (!ifindex) {
goto out;
}
goto out;
}
ret = 0;
out:
return ret;
}
{
lxc_log_error("failed to read link info");
goto out;
}
if (!ifindex) {
goto out;
}
goto out;
}
ret = 0;
out:
return ret;
}
{
return -1;
}
{
char *dirname;
int ret;
return ret;
}
{
goto out;
}
lxc_log_error("interface with index %d does not exist",
ifindex);
goto out;
}
goto out;
}
ret = 0;
out:
return ret;
}
{
char *dirname;
int ret;
return ret;
}
{
lxc_log_error("failed to instantiate the network devices");
return -1;
}
lxc_log_error("failed to move the netdev to the container");
return -1;
}
return 0;
}
{
char strindex[MAXINDEXLEN];
char path[MAXPATHLEN];
int i, ifindex;
lxc_log_error("failed to read ifindex info");
return -1;
}
if (!ifindex) {
return -1;
}
/* TODO : temporary code - needs wait on namespace */
for (i = 0; i < 120; i++) {
break;
if (!i)
else
sleep(1);
}
/* do not delete a physical network device */
if (device_delete(ifname)) {
}
return 0;
}
static int delete_netdev(const char *name)
{
char *dirname;
int ret;
return ret;
}
int conf_destroy_network(const char *name)
{
if (delete_netdev(name)) {
lxc_log_error("failed to remove the network devices");
return -1;
}
return 0;
}
{
if (setup_utsname(name)) {
return -1;
}
if (setup_network(name)) {
return -1;
}
if (setup_mount(name)) {
return -1;
}
if (setup_chroot(name)) {
return -1;
}
return 0;
}