1
// $Id: interface-read.c 1980 2005-03-24 12:44:17Z ensc $ --*- c -*--
3
// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5
// This program is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; version 2 of the License.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include "interface.h"
25
#include <lib_internal/filecfg.h>
26
#include <lib_internal/util.h>
28
#include <netinet/in.h>
29
#include <arpa/inet.h>
32
readEntryStr(PathInfo const *cfgdir, char const *file, char const *dflt)
34
return FileCfg_readEntryStr(cfgdir, file, false, dflt);
38
readEntryFlag(PathInfo const *cfgdir, char const *file, bool dflt)
40
return FileCfg_readEntryFlag(cfgdir, file, dflt);
44
assumeNonNull(PathInfo const *cfgdir, char const *file, char const *val)
48
WRITE_MSG(2, "vserver-start: no value configured for '");
49
Vwrite (2, cfgdir->d, cfgdir->l);
57
Iface_read(struct Interface *res, PathInfo *cfgdir,
58
struct Interface const *dflt)
67
// skip 'disabled' interfaces
68
if (readEntryFlag(cfgdir, "disabled", false)) return true;
70
ip = readEntryStr (cfgdir, "ip", 0);
71
mask = readEntryStr (cfgdir, "mask", 0);
72
prefix = readEntryStr (cfgdir, "prefix", 0);
73
extip = readEntryStr (cfgdir, "extip", 0);
74
bcast = readEntryStr (cfgdir, "bcast", 0);
75
res->mac = readEntryStr (cfgdir, "mac", 0);
76
res->name = readEntryStr (cfgdir, "name", 0);
77
res->dev = readEntryStr (cfgdir, "dev", dflt ? dflt->dev : 0);
78
res->scope = readEntryStr (cfgdir, "scope", dflt ? dflt->scope : 0);
79
res->nodev = readEntryFlag(cfgdir, "nodev", false);
80
res->direct = !readEntryFlag(cfgdir, "indirect", false);
81
res->up = !readEntryFlag(cfgdir, "down", false);
84
assumeNonNull(cfgdir, "ip", ip) +
85
assumeNonNull(cfgdir, "dev", res->dev) +
86
(dflt->addr.ipv4.mask>0) ? 0 : (
87
(mask ? 0 : assumeNonNull(cfgdir, "prefix", prefix)) +
88
(prefix ? 0 : assumeNonNull(cfgdir, "mask", mask))
93
WRITE_MSG(2, "vserver-start: both 'prefix' and 'mask' specified in '");
94
Vwrite (2, cfgdir->d, cfgdir->l);
100
res->addr.ipv4.bcast = inet_addr(bcast);
103
res->addr.ipv4.ip = inet_addr(ip);
106
res->addr.ipv4.extip = inet_addr(extip);
109
int p = atoi(prefix);
111
WRITE_MSG(2, "vserver-start: invalid 'prefix' specified in '");
112
Vwrite (2, cfgdir->d, cfgdir->l);
117
res->addr.ipv4.mask = htonl(-1u << (32-p));
120
res->addr.ipv4.mask = inet_addr(mask);
122
res->addr.ipv4.mask = dflt->addr.ipv4.mask;
127
free(const_cast(void *)(bcast));
128
free(const_cast(void *)(extip));
129
free(const_cast(void *)(ip));
130
free(const_cast(void *)(mask));
131
free(const_cast(void *)(prefix));