confile.c revision e892973e391aa93f4aac144527400ae24ad68032
/*
* 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
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "parse.h"
#include "utils.h"
static int config_pts(const char *, char *, struct lxc_conf *);
static int config_tty(const char *, char *, struct lxc_conf *);
static int config_cgroup(const char *, char *, struct lxc_conf *);
static int config_mount(const char *, char *, struct lxc_conf *);
static int config_rootfs(const char *, char *, struct lxc_conf *);
static int config_utsname(const char *, char *, struct lxc_conf *);
static int config_network_type(const char *, char *, struct lxc_conf *);
static int config_network_flags(const char *, char *, struct lxc_conf *);
static int config_network_link(const char *, char *, struct lxc_conf *);
static int config_network_name(const char *, char *, struct lxc_conf *);
static int config_network_veth_pair(const char *, char *, struct lxc_conf *);
static int config_network_macvlan_mode(const char *, char *, struct lxc_conf *);
static int config_network_hwaddr(const char *, char *, struct lxc_conf *);
static int config_network_vlan_id(const char *, char *, struct lxc_conf *);
static int config_network_mtu(const char *, char *, struct lxc_conf *);
static int config_network_ipv4(const char *, char *, struct lxc_conf *);
static int config_network_ipv6(const char *, char *, struct lxc_conf *);
struct config {
char *name;
};
{ "lxc.pts", config_pts },
{ "lxc.tty", config_tty },
{ "lxc.cgroup", config_cgroup },
{ "lxc.mount", config_mount },
{ "lxc.rootfs", config_rootfs },
{ "lxc.utsname", config_utsname },
{ "lxc.network.type", config_network_type },
{ "lxc.network.flags", config_network_flags },
{ "lxc.network.link", config_network_link },
{ "lxc.network.name", config_network_name },
{ "lxc.network.macvlan.mode", config_network_macvlan_mode },
{ "lxc.network.veth.pair", config_network_veth_pair },
{ "lxc.network.hwaddr", config_network_hwaddr },
{ "lxc.network.mtu", config_network_mtu },
{ "lxc.network.vlan.id", config_network_vlan_id },
{ "lxc.network.ipv4", config_network_ipv4 },
{ "lxc.network.ipv6", config_network_ipv6 },
};
{
int i;
for (i = 0; i < config_size; i++)
return &config[i];
return NULL;
}
{
struct lxc_netdev *netdev;
if (!netdev) {
SYSERROR("failed to allocate memory");
return -1;
}
if (!list) {
SYSERROR("failed to allocate memory");
return -1;
}
else {
return -1;
}
return 0;
}
{
return 32 - IN_CLASSA_NSHIFT;
return 32 - IN_CLASSB_NSHIFT;
return 32 - IN_CLASSC_NSHIFT;
return 0;
}
{
struct lxc_netdev *netdev;
if (lxc_list_empty(network)) {
ERROR("network is not created for '%s' = '%s' option",
return NULL;
}
if (!netdev) {
ERROR("no network device defined for '%s' = '%s' option",
return NULL;
}
return netdev;
}
{
return -1;
}
if (!*valuep) {
return -1;
}
return 0;
}
#ifndef MACVLAN_MODE_PRIVATE
# define MACVLAN_MODE_PRIVATE 1
#endif
#ifndef MACVLAN_MODE_VEPA
# define MACVLAN_MODE_VEPA 2
#endif
#ifndef MACVLAN_MODE_BRIDGE
# define MACVLAN_MODE_BRIDGE 4
#endif
{
struct mc_mode {
char *name;
int mode;
} m[] = {
{ "private", MACVLAN_MODE_PRIVATE },
{ "vepa", MACVLAN_MODE_VEPA },
{ "bridge", MACVLAN_MODE_BRIDGE },
};
int i;
for (i = 0; i < sizeof(m)/sizeof(m[0]); i++) {
continue;
return 0;
}
return -1;
}
{
struct lxc_netdev *netdev;
if (!netdev)
return -1;
return 0;
}
{
struct lxc_netdev *netdev;
if (!netdev)
return -1;
}
{
struct lxc_netdev *netdev;
if (!netdev)
return -1;
}
{
struct lxc_netdev *netdev;
if (!netdev)
return -1;
}
{
struct lxc_netdev *netdev;
if (!netdev)
return -1;
}
{
struct lxc_netdev *netdev;
if (!netdev)
return -1;
return -1;
}
return 0;
}
{
struct lxc_netdev *netdev;
if (!netdev)
return -1;
return -1;
return 0;
}
{
struct lxc_netdev *netdev;
if (!netdev)
return -1;
return -1;
}
return 0;
}
{
struct lxc_netdev *netdev;
struct lxc_inetdev *inetdev;
if (!netdev)
return -1;
if (!inetdev) {
SYSERROR("failed to allocate ipv4 address");
return -1;
}
if (!list) {
SYSERROR("failed to allocate memory");
return -1;
}
if (cursor) {
*cursor = '\0';
}
if (slash) {
*slash = '\0';
}
if (!addr) {
ERROR("no address specified");
return -1;
}
return -1;
}
if (bcast)
return -1;
}
/* no prefix specified, determine it from the network class */
return 0;
}
{
struct lxc_netdev *netdev;
struct lxc_inet6dev *inet6dev;
char *slash;
char *netmask;
if (!netdev)
return -1;
if (!inet6dev) {
SYSERROR("failed to allocate ipv6 address");
return -1;
}
if (!list) {
SYSERROR("failed to allocate memory");
return -1;
}
if (slash) {
*slash = '\0';
}
return -1;
}
return 0;
}
{
return 0;
}
{
return 0;
}
{
char *subkey;
struct lxc_cgroup *cgelem;
if (!subkey)
return -1;
return -1;
return -1;
if (!cglist)
return -1;
if (!cgelem) {
return -1;
}
return 0;
}
{
return -1;
}
return -1;
}
return 0;
}
{
char *fstab_token = "lxc.mount";
char *token = "lxc.mount.entry";
char *subkey;
char *mntelem;
if (!subkey) {
if (!subkey)
return -1;
}
return -1;
if (!mntlist)
return -1;
return 0;
}
{
return -1;
}
return -1;
}
return 0;
}
{
if (!utsname) {
SYSERROR("failed to allocate memory");
return -1;
}
ERROR("node name '%s' is too long",
return -1;
}
return 0;
}
{
char *dot;
char *key;
char *value;
if (lxc_is_line_empty(line))
return 0;
if (line[0] == '#')
return 0;
if (!dot) {
return -1;
}
*dot = '\0';
if (!config) {
return -1;
}
}
{
char buffer[MAXPATHLEN];
}