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 write(2, cfgdir->d, cfgdir->l);
57 Iface_read(struct Interface *res, PathInfo *cfgdir,
58 struct Interface const *dflt)
67 ip = readEntryStr (cfgdir, "ip", 0);
68 mask = readEntryStr (cfgdir, "mask", 0);
69 prefix = readEntryStr (cfgdir, "prefix", 0);
70 extip = readEntryStr (cfgdir, "extip", 0);
71 bcast = readEntryStr (cfgdir, "bcast", 0);
72 res->mac = readEntryStr (cfgdir, "mac", 0);
73 res->name = readEntryStr (cfgdir, "name", 0);
74 res->dev = readEntryStr (cfgdir, "dev", dflt ? dflt->dev : 0);
75 res->scope = readEntryStr (cfgdir, "scope", dflt ? dflt->scope : 0);
76 res->nodev = readEntryFlag(cfgdir, "nodev", false);
77 res->direct = !readEntryFlag(cfgdir, "indirect", false);
78 res->up = !readEntryFlag(cfgdir, "down", false);
81 assumeNonNull(cfgdir, "ip", ip) +
82 assumeNonNull(cfgdir, "dev", res->dev) +
83 (dflt->addr.ipv4.mask>0) ? 0 : (
84 (mask ? 0 : assumeNonNull(cfgdir, "prefix", prefix)) +
85 (prefix ? 0 : assumeNonNull(cfgdir, "mask", mask))
90 WRITE_MSG(2, "vserver-start: both 'prefix' and 'mask' specified in '");
91 write(2, cfgdir->d, cfgdir->l);
97 res->addr.ipv4.bcast = inet_addr(bcast);
100 res->addr.ipv4.ip = inet_addr(ip);
103 res->addr.ipv4.extip = inet_addr(extip);
106 int p = atoi(prefix);
108 WRITE_MSG(2, "vserver-start: invalid 'prefix' specified in '");
109 write(2, cfgdir->d, cfgdir->l);
114 res->addr.ipv4.mask = htonl(-1u << (32-p));
117 res->addr.ipv4.mask = inet_addr(mask);
119 res->addr.ipv4.mask = dflt->addr.ipv4.mask;
124 free(const_cast(void *)(bcast));
125 free(const_cast(void *)(extip));
126 free(const_cast(void *)(ip));
127 free(const_cast(void *)(mask));
128 free(const_cast(void *)(prefix));