summaryrefslogtreecommitdiff
path: root/src/dumm
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@corsac.net>2012-06-28 21:16:07 +0200
committerYves-Alexis Perez <corsac@corsac.net>2012-06-28 21:16:07 +0200
commitb34738ed08c2227300d554b139e2495ca5da97d6 (patch)
tree62f33b52820f2e49f0e53c0f8c636312037c8054 /src/dumm
parent0a9d51a49042a68daa15b0c74a2b7f152f52606b (diff)
downloadvyos-strongswan-b34738ed08c2227300d554b139e2495ca5da97d6.tar.gz
vyos-strongswan-b34738ed08c2227300d554b139e2495ca5da97d6.zip
Imported Upstream version 4.6.4
Diffstat (limited to 'src/dumm')
-rw-r--r--src/dumm/Makefile.am9
-rw-r--r--src/dumm/Makefile.in70
-rw-r--r--src/dumm/bridge.c45
-rw-r--r--src/dumm/cowfs.c40
-rw-r--r--src/dumm/dumm.c130
-rw-r--r--src/dumm/ext/dumm.c14
-rw-r--r--src/dumm/guest.c138
-rw-r--r--src/dumm/iface.c90
-rw-r--r--src/dumm/iface.h10
-rw-r--r--src/dumm/mconsole.c45
10 files changed, 260 insertions, 331 deletions
diff --git a/src/dumm/Makefile.am b/src/dumm/Makefile.am
index b7fb3f7c8..8b8cebcd8 100644
--- a/src/dumm/Makefile.am
+++ b/src/dumm/Makefile.am
@@ -1,7 +1,7 @@
EXTRA_DIST = ext/dumm.c ext/README \
ext/lib/dumm.rb ext/lib/dumm/guest.rb
-lib_LTLIBRARIES = libdumm.la
+ipseclib_LTLIBRARIES = libdumm.la
ipsec_PROGRAMS = dumm irdumm
libdumm_la_SOURCES = dumm.c dumm.h guest.c guest.h iface.c iface.h \
@@ -9,10 +9,9 @@ libdumm_la_SOURCES = dumm.c dumm.h guest.c guest.h iface.c iface.h \
dumm_SOURCES = main.c
irdumm_SOURCES = irdumm.c
-libdumm_la_LIBADD = $(top_builddir)/src/libstrongswan/libstrongswan.la \
- -lbridge -lfuse -lutil
-dumm_LDADD = libdumm.la ${gtk_LIBS}
-irdumm_LDADD = libdumm.la -lruby1.8
+libdumm_la_LIBADD = -lbridge -lfuse -lutil $(top_builddir)/src/libstrongswan/libstrongswan.la
+dumm_LDADD = libdumm.la ${gtk_LIBS} $(top_builddir)/src/libstrongswan/libstrongswan.la
+irdumm_LDADD = libdumm.la -lruby1.8 $(top_builddir)/src/libstrongswan/libstrongswan.la
INCLUDES = -I$(top_srcdir)/src/libstrongswan ${gtk_CFLAGS} \
${RUBYINCLUDE}
diff --git a/src/dumm/Makefile.in b/src/dumm/Makefile.in
index 4a8f142ca..bd172b701 100644
--- a/src/dumm/Makefile.in
+++ b/src/dumm/Makefile.in
@@ -74,8 +74,8 @@ am__nobase_list = $(am__nobase_strip_setup); \
am__base_list = \
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
-am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(ipsecdir)"
-LTLIBRARIES = $(lib_LTLIBRARIES)
+am__installdirs = "$(DESTDIR)$(ipseclibdir)" "$(DESTDIR)$(ipsecdir)"
+LTLIBRARIES = $(ipseclib_LTLIBRARIES)
libdumm_la_DEPENDENCIES = \
$(top_builddir)/src/libstrongswan/libstrongswan.la
am_libdumm_la_OBJECTS = dumm.lo guest.lo iface.lo bridge.lo \
@@ -85,10 +85,12 @@ PROGRAMS = $(ipsec_PROGRAMS)
am_dumm_OBJECTS = main.$(OBJEXT)
dumm_OBJECTS = $(am_dumm_OBJECTS)
am__DEPENDENCIES_1 =
-dumm_DEPENDENCIES = libdumm.la $(am__DEPENDENCIES_1)
+dumm_DEPENDENCIES = libdumm.la $(am__DEPENDENCIES_1) \
+ $(top_builddir)/src/libstrongswan/libstrongswan.la
am_irdumm_OBJECTS = irdumm.$(OBJEXT)
irdumm_OBJECTS = $(am_irdumm_OBJECTS)
-irdumm_DEPENDENCIES = libdumm.la
+irdumm_DEPENDENCIES = libdumm.la \
+ $(top_builddir)/src/libstrongswan/libstrongswan.la
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
@@ -198,6 +200,9 @@ am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
+attest_plugins = @attest_plugins@
+axis2c_CFLAGS = @axis2c_CFLAGS@
+axis2c_LIBS = @axis2c_LIBS@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
@@ -206,6 +211,7 @@ build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
c_plugins = @c_plugins@
+clearsilver_LIBS = @clearsilver_LIBS@
datadir = @datadir@
datarootdir = @datarootdir@
dbusservicedir = @dbusservicedir@
@@ -222,11 +228,13 @@ host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
+imcvdir = @imcvdir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
ipsecdir = @ipsecdir@
ipsecgroup = @ipsecgroup@
+ipseclibdir = @ipseclibdir@
ipsecuser = @ipsecuser@
libcharon_plugins = @libcharon_plugins@
libdir = @libdir@
@@ -270,6 +278,7 @@ sharedstatedir = @sharedstatedir@
soup_CFLAGS = @soup_CFLAGS@
soup_LIBS = @soup_LIBS@
srcdir = @srcdir@
+starter_plugins = @starter_plugins@
strongswan_conf = @strongswan_conf@
sysconfdir = @sysconfdir@
systemdsystemunitdir = @systemdsystemunitdir@
@@ -283,17 +292,15 @@ xml_LIBS = @xml_LIBS@
EXTRA_DIST = ext/dumm.c ext/README \
ext/lib/dumm.rb ext/lib/dumm/guest.rb
-lib_LTLIBRARIES = libdumm.la
+ipseclib_LTLIBRARIES = libdumm.la
libdumm_la_SOURCES = dumm.c dumm.h guest.c guest.h iface.c iface.h \
bridge.c bridge.h mconsole.c mconsole.h cowfs.h cowfs.c
dumm_SOURCES = main.c
irdumm_SOURCES = irdumm.c
-libdumm_la_LIBADD = $(top_builddir)/src/libstrongswan/libstrongswan.la \
- -lbridge -lfuse -lutil
-
-dumm_LDADD = libdumm.la ${gtk_LIBS}
-irdumm_LDADD = libdumm.la -lruby1.8
+libdumm_la_LIBADD = -lbridge -lfuse -lutil $(top_builddir)/src/libstrongswan/libstrongswan.la
+dumm_LDADD = libdumm.la ${gtk_LIBS} $(top_builddir)/src/libstrongswan/libstrongswan.la
+irdumm_LDADD = libdumm.la -lruby1.8 $(top_builddir)/src/libstrongswan/libstrongswan.la
INCLUDES = -I$(top_srcdir)/src/libstrongswan ${gtk_CFLAGS} \
${RUBYINCLUDE}
@@ -332,39 +339,39 @@ $(top_srcdir)/configure: $(am__configure_deps)
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
-install-libLTLIBRARIES: $(lib_LTLIBRARIES)
+install-ipseclibLTLIBRARIES: $(ipseclib_LTLIBRARIES)
@$(NORMAL_INSTALL)
- test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
- @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
+ test -z "$(ipseclibdir)" || $(MKDIR_P) "$(DESTDIR)$(ipseclibdir)"
+ @list='$(ipseclib_LTLIBRARIES)'; test -n "$(ipseclibdir)" || list=; \
list2=; for p in $$list; do \
if test -f $$p; then \
list2="$$list2 $$p"; \
else :; fi; \
done; \
test -z "$$list2" || { \
- echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
- $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(ipseclibdir)'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(ipseclibdir)"; \
}
-uninstall-libLTLIBRARIES:
+uninstall-ipseclibLTLIBRARIES:
@$(NORMAL_UNINSTALL)
- @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
+ @list='$(ipseclib_LTLIBRARIES)'; test -n "$(ipseclibdir)" || list=; \
for p in $$list; do \
$(am__strip_dir) \
- echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \
- $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(ipseclibdir)/$$f'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(ipseclibdir)/$$f"; \
done
-clean-libLTLIBRARIES:
- -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
- @list='$(lib_LTLIBRARIES)'; for p in $$list; do \
+clean-ipseclibLTLIBRARIES:
+ -test -z "$(ipseclib_LTLIBRARIES)" || rm -f $(ipseclib_LTLIBRARIES)
+ @list='$(ipseclib_LTLIBRARIES)'; for p in $$list; do \
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
test "$$dir" != "$$p" || dir=.; \
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libdumm.la: $(libdumm_la_OBJECTS) $(libdumm_la_DEPENDENCIES)
- $(LINK) -rpath $(libdir) $(libdumm_la_OBJECTS) $(libdumm_la_LIBADD) $(LIBS)
+ $(LINK) -rpath $(ipseclibdir) $(libdumm_la_OBJECTS) $(libdumm_la_LIBADD) $(LIBS)
install-ipsecPROGRAMS: $(ipsec_PROGRAMS)
@$(NORMAL_INSTALL)
test -z "$(ipsecdir)" || $(MKDIR_P) "$(DESTDIR)$(ipsecdir)"
@@ -543,7 +550,7 @@ check-am: all-am
check: check-am
all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) all-local
installdirs:
- for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(ipsecdir)"; do \
+ for dir in "$(DESTDIR)$(ipseclibdir)" "$(DESTDIR)$(ipsecdir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-am
@@ -573,7 +580,7 @@ maintainer-clean-generic:
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
-clean-am: clean-generic clean-ipsecPROGRAMS clean-libLTLIBRARIES \
+clean-am: clean-generic clean-ipsecPROGRAMS clean-ipseclibLTLIBRARIES \
clean-libtool clean-local mostlyclean-am
distclean: distclean-am
@@ -594,13 +601,14 @@ info: info-am
info-am:
-install-data-am: install-data-local install-ipsecPROGRAMS
+install-data-am: install-data-local install-ipsecPROGRAMS \
+ install-ipseclibLTLIBRARIES
install-dvi: install-dvi-am
install-dvi-am:
-install-exec-am: install-libLTLIBRARIES
+install-exec-am:
install-html: install-html-am
@@ -640,25 +648,25 @@ ps: ps-am
ps-am:
-uninstall-am: uninstall-ipsecPROGRAMS uninstall-libLTLIBRARIES
+uninstall-am: uninstall-ipsecPROGRAMS uninstall-ipseclibLTLIBRARIES
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS all all-am all-local check check-am clean \
- clean-generic clean-ipsecPROGRAMS clean-libLTLIBRARIES \
+ clean-generic clean-ipsecPROGRAMS clean-ipseclibLTLIBRARIES \
clean-libtool clean-local ctags distclean distclean-compile \
distclean-generic distclean-libtool distclean-tags distdir dvi \
dvi-am html html-am info info-am install install-am \
install-data install-data-am install-data-local install-dvi \
install-dvi-am install-exec install-exec-am install-html \
install-html-am install-info install-info-am \
- install-ipsecPROGRAMS install-libLTLIBRARIES install-man \
+ install-ipsecPROGRAMS install-ipseclibLTLIBRARIES install-man \
install-pdf install-pdf-am install-ps install-ps-am \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
pdf pdf-am ps ps-am tags uninstall uninstall-am \
- uninstall-ipsecPROGRAMS uninstall-libLTLIBRARIES
+ uninstall-ipsecPROGRAMS uninstall-ipseclibLTLIBRARIES
all-local: ext
diff --git a/src/dumm/bridge.c b/src/dumm/bridge.c
index 9c63beed9..85b6471b6 100644
--- a/src/dumm/bridge.c
+++ b/src/dumm/bridge.c
@@ -37,26 +37,20 @@ struct private_bridge_t {
*/
bool iface_control(char *name, bool up);
-/**
- * Implementation of bridge_t.get_name.
- */
-static char* get_name(private_bridge_t *this)
+METHOD(bridge_t, get_name, char*,
+ private_bridge_t *this)
{
return this->name;
}
-/**
- * Implementation of bridge_t.create_iface_enumerator.
- */
-static enumerator_t* create_iface_enumerator(private_bridge_t *this)
+METHOD(bridge_t, create_iface_enumerator, enumerator_t*,
+ private_bridge_t *this)
{
return this->ifaces->create_enumerator(this->ifaces);
}
-/**
- * Implementation of bridge_t.disconnect_iface.
- */
-static bool disconnect_iface(private_bridge_t *this, iface_t *iface)
+METHOD(bridge_t, disconnect_iface, bool,
+ private_bridge_t *this, iface_t *iface)
{
enumerator_t *enumerator;
iface_t *current = NULL;
@@ -90,10 +84,8 @@ static bool disconnect_iface(private_bridge_t *this, iface_t *iface)
return good;
}
-/**
- * Implementation of bridge_t.connect_iface.
- */
-static bool connect_iface(private_bridge_t *this, iface_t *iface)
+METHOD(bridge_t, connect_iface, bool,
+ private_bridge_t *this, iface_t *iface)
{
if (br_add_interface(this->name, iface->get_hostif(iface)) != 0)
{
@@ -111,10 +103,8 @@ static bool connect_iface(private_bridge_t *this, iface_t *iface)
*/
static int instances = 0;
-/**
- * Implementation of bridge_t.destroy.
- */
-static void destroy(private_bridge_t *this)
+METHOD(bridge_t, destroy, void,
+ private_bridge_t *this)
{
enumerator_t *enumerator;
iface_t *iface;
@@ -161,12 +151,15 @@ bridge_t *bridge_create(char *name)
}
}
- this = malloc_thing(private_bridge_t);
- this->public.get_name = (char*(*)(bridge_t*))get_name;
- this->public.create_iface_enumerator = (enumerator_t*(*)(bridge_t*))create_iface_enumerator;
- this->public.disconnect_iface = (bool(*)(bridge_t*, iface_t *iface))disconnect_iface;
- this->public.connect_iface = (bool(*)(bridge_t*, iface_t *iface))connect_iface;
- this->public.destroy = (void*)destroy;
+ INIT(this,
+ .public = {
+ .get_name = _get_name,
+ .create_iface_enumerator = _create_iface_enumerator,
+ .disconnect_iface = _disconnect_iface,
+ .connect_iface = _connect_iface,
+ .destroy = _destroy,
+ }
+ );
if (br_add_bridge(name) != 0)
{
diff --git a/src/dumm/cowfs.c b/src/dumm/cowfs.c
index b92be53e0..f708a293b 100644
--- a/src/dumm/cowfs.c
+++ b/src/dumm/cowfs.c
@@ -835,10 +835,8 @@ static struct fuse_operations cowfs_operations = {
.init = cowfs_init,
};
-/**
- * Implementation of cowfs_t.add_overlay.
- */
-static bool add_overlay(private_cowfs_t *this, char *path)
+METHOD(cowfs_t, add_overlay, bool,
+ private_cowfs_t *this, char *path)
{
overlay_t *over = malloc_thing(overlay_t);
over->fd = open(path, O_RDONLY | O_DIRECTORY);
@@ -856,10 +854,8 @@ static bool add_overlay(private_cowfs_t *this, char *path)
return TRUE;
}
-/**
- * Implementation of cowfs_t.del_overlay.
- */
-static bool del_overlay(private_cowfs_t *this, char *path)
+METHOD(cowfs_t, del_overlay, bool,
+ private_cowfs_t *this, char *path)
{
bool removed;
char real[PATH_MAX];
@@ -869,10 +865,8 @@ static bool del_overlay(private_cowfs_t *this, char *path)
return removed;
}
-/**
- * Implementation of cowfs_t.pop_overlay.
- */
-static bool pop_overlay(private_cowfs_t *this)
+METHOD(cowfs_t, pop_overlay, bool,
+ private_cowfs_t *this)
{
overlay_t *over;
this->lock->write_lock(this->lock);
@@ -886,10 +880,8 @@ static bool pop_overlay(private_cowfs_t *this)
return TRUE;
}
-/**
- * stop, umount and destroy a cowfs FUSE filesystem
- */
-static void destroy(private_cowfs_t *this)
+METHOD(cowfs_t, destroy, void,
+ private_cowfs_t *this)
{
fuse_exit(this->fuse);
fuse_unmount(this->mount, this->chan);
@@ -911,12 +903,16 @@ static void destroy(private_cowfs_t *this)
cowfs_t *cowfs_create(char *master, char *host, char *mount)
{
struct fuse_args args = {0, NULL, 0};
- private_cowfs_t *this = malloc_thing(private_cowfs_t);
-
- this->public.add_overlay = (bool(*)(cowfs_t*, char *path))add_overlay;
- this->public.del_overlay = (bool(*)(cowfs_t*, char *path))del_overlay;
- this->public.pop_overlay = (bool(*)(cowfs_t*))pop_overlay;
- this->public.destroy = (void(*)(cowfs_t*))destroy;
+ private_cowfs_t *this;
+
+ INIT(this,
+ .public = {
+ .add_overlay = _add_overlay,
+ .del_overlay = _del_overlay,
+ .pop_overlay = _pop_overlay,
+ .destroy = _destroy,
+ }
+ );
this->master_fd = open(master, O_RDONLY | O_DIRECTORY);
if (this->master_fd < 0)
diff --git a/src/dumm/dumm.c b/src/dumm/dumm.c
index 8cd413519..59751fa09 100644
--- a/src/dumm/dumm.c
+++ b/src/dumm/dumm.c
@@ -49,11 +49,8 @@ struct private_dumm_t {
linked_list_t *bridges;
};
-/**
- * Implementation of dumm_t.create_guest.
- */
-static guest_t* create_guest(private_dumm_t *this, char *name, char *kernel,
- char *master, char *args)
+METHOD(dumm_t, create_guest, guest_t*,
+ private_dumm_t *this, char *name, char *kernel, char *master, char *args)
{
guest_t *guest;
@@ -65,18 +62,14 @@ static guest_t* create_guest(private_dumm_t *this, char *name, char *kernel,
return guest;
}
-/**
- * Implementation of dumm_t.create_guest_enumerator.
- */
-static enumerator_t* create_guest_enumerator(private_dumm_t *this)
+METHOD(dumm_t, create_guest_enumerator, enumerator_t*,
+ private_dumm_t *this)
{
return this->guests->create_enumerator(this->guests);
}
-/**
- * Implementation of dumm_t.delete_guest.
- */
-static void delete_guest(private_dumm_t *this, guest_t *guest)
+METHOD(dumm_t, delete_guest, void,
+ private_dumm_t *this, guest_t *guest)
{
if (this->guests->remove(this->guests, guest, NULL))
{
@@ -93,10 +86,8 @@ static void delete_guest(private_dumm_t *this, guest_t *guest)
}
}
-/**
- * Implementation of dumm_t.create_bridge.
- */
-static bridge_t* create_bridge(private_dumm_t *this, char *name)
+METHOD(dumm_t, create_bridge, bridge_t*,
+ private_dumm_t *this, char *name)
{
bridge_t *bridge;
@@ -108,18 +99,14 @@ static bridge_t* create_bridge(private_dumm_t *this, char *name)
return bridge;
}
-/**
- * Implementation of dumm_t.create_bridge_enumerator.
- */
-static enumerator_t* create_bridge_enumerator(private_dumm_t *this)
+METHOD(dumm_t, create_bridge_enumerator, enumerator_t*,
+ private_dumm_t *this)
{
return this->bridges->create_enumerator(this->bridges);
}
-/**
- * Implementation of dumm_t.delete_bridge.
- */
-static void delete_bridge(private_dumm_t *this, bridge_t *bridge)
+METHOD(dumm_t, delete_bridge, void,
+ private_dumm_t *this, bridge_t *bridge)
{
if (this->bridges->remove(this->bridges, bridge, NULL))
{
@@ -127,10 +114,8 @@ static void delete_bridge(private_dumm_t *this, bridge_t *bridge)
}
}
-/**
- * Implementation of dumm_t.add_overlay.
- */
-static bool add_overlay(private_dumm_t *this, char *dir)
+METHOD(dumm_t, add_overlay, bool,
+ private_dumm_t *this, char *dir)
{
enumerator_t *enumerator;
guest_t *guest;
@@ -184,10 +169,8 @@ error:
return FALSE;
}
-/**
- * Implementation of dumm_t.del_overlay.
- */
-static bool del_overlay(private_dumm_t *this, char *dir)
+METHOD(dumm_t, del_overlay, bool,
+ private_dumm_t *this, char *dir)
{
bool ret = FALSE;
enumerator_t *enumerator;
@@ -209,10 +192,8 @@ static bool del_overlay(private_dumm_t *this, char *dir)
return ret;
}
-/**
- * Implementation of dumm_t.pop_overlay.
- */
-static bool pop_overlay(private_dumm_t *this)
+METHOD(dumm_t, pop_overlay, bool,
+ private_dumm_t *this)
{
bool ret = FALSE;
enumerator_t *enumerator;
@@ -240,10 +221,8 @@ static void clear_template(private_dumm_t *this)
}
}
-/**
- * Implementation of dumm_t.load_template.
- */
-static bool load_template(private_dumm_t *this, char *name)
+METHOD(dumm_t, load_template, bool,
+ private_dumm_t *this, char *name)
{
clear_template(this);
if (name == NULL)
@@ -287,10 +266,8 @@ typedef struct {
enumerator_t *inner;
} template_enumerator_t;
-/**
- * Implementation of template_enumerator_t.enumerate.
- */
-static bool template_enumerate(template_enumerator_t *this, char **template)
+METHOD(enumerator_t, template_enumerate, bool,
+ template_enumerator_t *this, char **template)
{
struct stat st;
char *rel;
@@ -306,25 +283,24 @@ static bool template_enumerate(template_enumerator_t *this, char **template)
return FALSE;
}
-/**
- * Implementation of template_enumerator_t.destroy.
- */
-static void template_enumerator_destroy(template_enumerator_t *this)
+METHOD(enumerator_t, template_enumerator_destroy, void,
+ template_enumerator_t *this)
{
this->inner->destroy(this->inner);
free(this);
}
-/**
- * Implementation of dumm_t.create_template_enumerator.
- */
-static enumerator_t* create_template_enumerator(private_dumm_t *this)
+METHOD(dumm_t, create_template_enumerator, enumerator_t*,
+ private_dumm_t *this)
{
template_enumerator_t *enumerator;
- enumerator = malloc_thing(template_enumerator_t);
- enumerator->public.enumerate = (void*)template_enumerate;
- enumerator->public.destroy = (void*)template_enumerator_destroy;
- enumerator->inner = enumerator_create_directory(TEMPLATE_DIR);
+ INIT(enumerator,
+ .public = {
+ .enumerate = (void*)_template_enumerate,
+ .destroy = (void*)_template_enumerator_destroy,
+ },
+ .inner = enumerator_create_directory(TEMPLATE_DIR),
+ );
if (!enumerator->inner)
{
free(enumerator);
@@ -333,10 +309,8 @@ static enumerator_t* create_template_enumerator(private_dumm_t *this)
return &enumerator->public;
}
-/**
- * Implementation of dumm_t.destroy.
- */
-static void destroy(private_dumm_t *this)
+METHOD(dumm_t, destroy, void,
+ private_dumm_t *this)
{
enumerator_t *enumerator;
guest_t *guest;
@@ -402,20 +376,24 @@ static void load_guests(private_dumm_t *this)
dumm_t *dumm_create(char *dir)
{
char cwd[PATH_MAX];
- private_dumm_t *this = malloc_thing(private_dumm_t);
-
- this->public.create_guest = (guest_t*(*)(dumm_t*,char*,char*,char*,char*))create_guest;
- this->public.create_guest_enumerator = (enumerator_t*(*)(dumm_t*))create_guest_enumerator;
- this->public.delete_guest = (void(*)(dumm_t*,guest_t*))delete_guest;
- this->public.create_bridge = (bridge_t*(*)(dumm_t*, char *name))create_bridge;
- this->public.create_bridge_enumerator = (enumerator_t*(*)(dumm_t*))create_bridge_enumerator;
- this->public.delete_bridge = (void(*)(dumm_t*,bridge_t*))delete_bridge;
- this->public.add_overlay = (bool(*)(dumm_t*,char*))add_overlay;
- this->public.del_overlay = (bool(*)(dumm_t*,char*))del_overlay;
- this->public.pop_overlay = (bool(*)(dumm_t*))pop_overlay;
- this->public.load_template = (bool(*)(dumm_t*,char*))load_template;
- this->public.create_template_enumerator = (enumerator_t*(*)(dumm_t*))create_template_enumerator;
- this->public.destroy = (void(*)(dumm_t*))destroy;
+ private_dumm_t *this;
+
+ INIT(this,
+ .public = {
+ .create_guest = _create_guest,
+ .create_guest_enumerator = _create_guest_enumerator,
+ .delete_guest = _delete_guest,
+ .create_bridge = _create_bridge,
+ .create_bridge_enumerator = _create_bridge_enumerator,
+ .delete_bridge = _delete_bridge,
+ .add_overlay = _add_overlay,
+ .del_overlay = _del_overlay,
+ .pop_overlay = _pop_overlay,
+ .load_template = _load_template,
+ .create_template_enumerator = _create_template_enumerator,
+ .destroy = _destroy,
+ },
+ );
if (dir && *dir == '/')
{
@@ -440,11 +418,11 @@ dumm_t *dumm_create(char *dir)
this->dir = strdup(cwd);
}
}
- this->template = NULL;
if (asprintf(&this->guest_dir, "%s/%s", this->dir, GUEST_DIR) < 0)
{
this->guest_dir = NULL;
}
+
this->guests = linked_list_create();
this->bridges = linked_list_create();
diff --git a/src/dumm/ext/dumm.c b/src/dumm/ext/dumm.c
index a9c7cb8bd..ca9b29388 100644
--- a/src/dumm/ext/dumm.c
+++ b/src/dumm/ext/dumm.c
@@ -594,21 +594,22 @@ static VALUE iface_add_addr(VALUE self, VALUE name)
{
iface_t *iface;
host_t *addr;
+ int bits;
- addr = host_create_from_string(StringValuePtr(name), 0);
+ addr = host_create_from_subnet(StringValuePtr(name), &bits);
if (!addr)
{
rb_raise(rb_eArgError, "invalid IP address");
}
Data_Get_Struct(self, iface_t, iface);
- if (!iface->add_address(iface, addr))
+ if (!iface->add_address(iface, addr, bits))
{
addr->destroy(addr);
rb_raise(rb_eRuntimeError, "adding address failed");
}
if (rb_block_given_p()) {
rb_yield(self);
- iface->delete_address(iface, addr);
+ iface->delete_address(iface, addr, bits);
}
addr->destroy(addr);
return self;
@@ -647,21 +648,22 @@ static VALUE iface_del_addr(VALUE self, VALUE vaddr)
{
iface_t *iface;
host_t *addr;
+ int bits;
- addr = host_create_from_string(StringValuePtr(vaddr), 0);
+ addr = host_create_from_subnet(StringValuePtr(vaddr), &bits);
if (!addr)
{
rb_raise(rb_eArgError, "invalid IP address");
}
Data_Get_Struct(self, iface_t, iface);
- if (!iface->delete_address(iface, addr))
+ if (!iface->delete_address(iface, addr, bits))
{
addr->destroy(addr);
rb_raise(rb_eRuntimeError, "address not found");
}
if (rb_block_given_p()) {
rb_yield(self);
- iface->add_address(iface, addr);
+ iface->add_address(iface, addr, bits);
}
addr->destroy(addr);
return self;
diff --git a/src/dumm/guest.c b/src/dumm/guest.c
index 36d048dcf..336f6effa 100644
--- a/src/dumm/guest.c
+++ b/src/dumm/guest.c
@@ -82,18 +82,14 @@ ENUM(guest_state_names, GUEST_STOPPED, GUEST_STOPPING,
"STOPPING",
);
-/**
- * Implementation of guest_t.get_name.
- */
-static char* get_name(private_guest_t *this)
+METHOD(guest_t, get_name, char*,
+ private_guest_t *this)
{
return this->name;
}
-/**
- * Implementation of guest_t.create_iface.
- */
-static iface_t* create_iface(private_guest_t *this, char *name)
+METHOD(guest_t, create_iface, iface_t*,
+ private_guest_t *this, char *name)
{
enumerator_t *enumerator;
iface_t *iface;
@@ -126,10 +122,8 @@ static iface_t* create_iface(private_guest_t *this, char *name)
return iface;
}
-/**
- * Implementation of guest_t.destroy_iface.
- */
-static void destroy_iface(private_guest_t *this, iface_t *iface)
+METHOD(guest_t, destroy_iface, void,
+ private_guest_t *this, iface_t *iface)
{
enumerator_t *enumerator;
iface_t *current;
@@ -147,26 +141,20 @@ static void destroy_iface(private_guest_t *this, iface_t *iface)
enumerator->destroy(enumerator);
}
-/**
- * Implementation of guest_t.create_iface_enumerator.
- */
-static enumerator_t* create_iface_enumerator(private_guest_t *this)
+METHOD(guest_t, create_iface_enumerator, enumerator_t*,
+ private_guest_t *this)
{
return this->ifaces->create_enumerator(this->ifaces);
}
-/**
- * Implementation of guest_t.get_state.
- */
-static guest_state_t get_state(private_guest_t *this)
+METHOD(guest_t, get_state, guest_state_t,
+ private_guest_t *this)
{
return this->state;
}
-/**
- * Implementation of guest_t.get_pid.
- */
-static pid_t get_pid(private_guest_t *this)
+METHOD(guest_t, get_pid, pid_t,
+ private_guest_t *this)
{
return this->pid;
}
@@ -193,10 +181,8 @@ static char* write_arg(char **pos, size_t *left, char *format, ...)
return res;
}
-/**
- * Implementation of guest_t.stop.
- */
-static void stop(private_guest_t *this, idle_function_t idle)
+METHOD(guest_t, stop, void,
+ private_guest_t *this, idle_function_t idle)
{
if (this->state != GUEST_STOPPED)
{
@@ -236,11 +222,9 @@ void savepid(private_guest_t *this)
}
}
-/**
- * Implementation of guest_t.start.
- */
-static bool start(private_guest_t *this, invoke_function_t invoke, void* data,
- idle_function_t idle)
+METHOD(guest_t, start, bool,
+ private_guest_t *this, invoke_function_t invoke, void* data,
+ idle_function_t idle)
{
char buf[2048];
char *notify;
@@ -296,10 +280,8 @@ static bool start(private_guest_t *this, invoke_function_t invoke, void* data,
return TRUE;
}
-/**
- * Implementation of guest_t.add_overlay.
- */
-static bool add_overlay(private_guest_t *this, char *path)
+METHOD(guest_t, add_overlay, bool,
+ private_guest_t *this, char *path)
{
if (path == NULL)
{
@@ -319,18 +301,14 @@ static bool add_overlay(private_guest_t *this, char *path)
return this->cowfs->add_overlay(this->cowfs, path);
}
-/**
- * Implementation of guest_t.del_overlay.
- */
-static bool del_overlay(private_guest_t *this, char *path)
+METHOD(guest_t, del_overlay, bool,
+ private_guest_t *this, char *path)
{
return this->cowfs->del_overlay(this->cowfs, path);
}
-/**
- * Implementation of guest_t.pop_overlay.
- */
-static bool pop_overlay(private_guest_t *this)
+METHOD(guest_t, pop_overlay, bool,
+ private_guest_t *this)
{
return this->cowfs->pop_overlay(this->cowfs);
}
@@ -356,11 +334,9 @@ static int vexec(private_guest_t *this, void(*cb)(void*,char*,size_t), void *dat
return -1;
}
-/**
- * Implementation of guest_t.exec
- */
-static int exec(private_guest_t *this, void(*cb)(void*,char*,size_t), void *data,
- char *cmd, ...)
+METHOD(guest_t, exec, int,
+ private_guest_t *this, void(*cb)(void*,char*,size_t), void *data,
+ char *cmd, ...)
{
int res;
va_list args;
@@ -411,11 +387,9 @@ static void exec_str_cb(exec_str_t *data, char *buf, size_t len)
}
}
-/**
- * Implementation of guest_t.exec_str
- */
-static int exec_str(private_guest_t *this, void(*cb)(void*,char*), bool lines,
- void *data, char *cmd, ...)
+METHOD(guest_t, exec_str, int,
+ private_guest_t *this, void(*cb)(void*,char*), bool lines, void *data,
+ char *cmd, ...)
{
int res;
va_list args;
@@ -448,10 +422,8 @@ static int exec_str(private_guest_t *this, void(*cb)(void*,char*), bool lines,
return res;
}
-/**
- * Implementation of guest_t.sigchild.
- */
-static void sigchild(private_guest_t *this)
+METHOD(guest_t, sigchild, void,
+ private_guest_t *this)
{
DESTROY_IF(this->mconsole);
this->mconsole = NULL;
@@ -537,10 +509,8 @@ bool saveargs(private_guest_t *this, char *args)
return retval;
}
-/**
- * Implementation of guest_t.destroy.
- */
-static void destroy(private_guest_t *this)
+METHOD(guest_t, destroy, void,
+ private_guest_t *this)
{
stop(this, NULL);
umount_unionfs(this);
@@ -562,23 +532,27 @@ static private_guest_t *guest_create_generic(char *parent, char *name,
bool create)
{
char cwd[PATH_MAX];
- private_guest_t *this = malloc_thing(private_guest_t);
-
- this->public.get_name = (void*)get_name;
- this->public.get_pid = (pid_t(*)(guest_t*))get_pid;
- this->public.get_state = (guest_state_t(*)(guest_t*))get_state;
- this->public.create_iface = (iface_t*(*)(guest_t*,char*))create_iface;
- this->public.destroy_iface = (void(*)(guest_t*,iface_t*))destroy_iface;
- this->public.create_iface_enumerator = (enumerator_t*(*)(guest_t*))create_iface_enumerator;
- this->public.start = (void*)start;
- this->public.stop = (void*)stop;
- this->public.add_overlay = (bool(*)(guest_t*,char*))add_overlay;
- this->public.del_overlay = (bool(*)(guest_t*,char*))del_overlay;
- this->public.pop_overlay = (bool(*)(guest_t*))pop_overlay;
- this->public.exec = (int(*)(guest_t*, void(*cb)(void*,char*,size_t),void*,char*,...))exec;
- this->public.exec_str = (int(*)(guest_t*, void(*cb)(void*,char*),bool,void*,char*,...))exec_str;
- this->public.sigchild = (void(*)(guest_t*))sigchild;
- this->public.destroy = (void*)destroy;
+ private_guest_t *this;
+
+ INIT(this,
+ .public = {
+ .get_name = _get_name,
+ .get_pid = _get_pid,
+ .get_state = _get_state,
+ .create_iface = _create_iface,
+ .destroy_iface = _destroy_iface,
+ .create_iface_enumerator = _create_iface_enumerator,
+ .start = _start,
+ .stop = _stop,
+ .add_overlay = _add_overlay,
+ .del_overlay = _del_overlay,
+ .pop_overlay = _pop_overlay,
+ .exec = _exec,
+ .exec_str = _exec_str,
+ .sigchild = _sigchild,
+ .destroy = _destroy,
+ }
+ );
if (*parent == '/' || getcwd(cwd, sizeof(cwd)) == NULL)
{
@@ -611,13 +585,9 @@ static private_guest_t *guest_create_generic(char *parent, char *name,
free(this);
return NULL;
}
- this->pid = 0;
this->state = GUEST_STOPPED;
- this->mconsole = NULL;
this->ifaces = linked_list_create();
- this->args = NULL;
this->name = strdup(name);
- this->cowfs = NULL;
return this;
}
diff --git a/src/dumm/iface.c b/src/dumm/iface.c
index 1b5b7d717..214387e88 100644
--- a/src/dumm/iface.c
+++ b/src/dumm/iface.c
@@ -83,29 +83,23 @@ bool iface_control(char *name, bool up)
return good;
}
-/**
- * Implementation of iface_t.get_guestif.
- */
-static char* get_guestif(private_iface_t *this)
+METHOD(iface_t, get_guestif, char*,
+ private_iface_t *this)
{
return this->guestif;
}
-/**
- * Implementation of iface_t.get_hostif.
- */
-static char* get_hostif(private_iface_t *this)
+METHOD(iface_t, get_hostif, char*,
+ private_iface_t *this)
{
return this->hostif;
}
-/**
- * Implementation of iface_t.add_address
- */
-static bool add_address(private_iface_t *this, host_t *addr)
+METHOD(iface_t, add_address, bool,
+ private_iface_t *this, host_t *addr, int bits)
{
return (this->guest->exec(this->guest, NULL, NULL,
- "exec ip addr add %H dev %s", addr, this->guestif) == 0);
+ "exec ip addr add %H/%d dev %s", addr, bits, this->guestif) == 0);
}
/**
@@ -128,10 +122,8 @@ static void destroy_address_list(linked_list_t *list)
list->destroy_offset(list, offsetof(host_t, destroy));
}
-/**
- * Implementation of iface_t.create_address_enumerator
- */
-static enumerator_t* create_address_enumerator(private_iface_t *this)
+METHOD(iface_t, create_address_enumerator, enumerator_t*,
+ private_iface_t *this)
{
linked_list_t *addresses = linked_list_create();
this->guest->exec_str(this->guest, (void(*)(void*,char*))compile_address_list,
@@ -143,19 +135,15 @@ static enumerator_t* create_address_enumerator(private_iface_t *this)
(void(*)(void*))destroy_address_list, addresses);
}
-/**
- * Implementation of iface_t.delete_address
- */
-static bool delete_address(private_iface_t *this, host_t *addr)
+METHOD(iface_t, delete_address, bool,
+ private_iface_t *this, host_t *addr, int bits)
{
return (this->guest->exec(this->guest, NULL, NULL,
- "exec ip addr del %H dev %s", addr, this->guestif) == 0);
+ "exec ip addr del %H/%d dev %s", addr, bits, this->guestif) == 0);
}
-/**
- * Implementation of iface_t.set_bridge.
- */
-static void set_bridge(private_iface_t *this, bridge_t *bridge)
+METHOD(iface_t, set_bridge, void,
+ private_iface_t *this, bridge_t *bridge)
{
if (this->bridge == NULL && bridge)
{
@@ -170,18 +158,14 @@ static void set_bridge(private_iface_t *this, bridge_t *bridge)
this->bridge = bridge;
}
-/**
- * Implementation of iface_t.get_bridge
- */
-static bridge_t *get_bridge(private_iface_t *this)
+METHOD(iface_t, get_bridge, bridge_t*,
+ private_iface_t *this)
{
return this->bridge;
}
-/**
- * Implementation of iface_t.get_guest
- */
-static guest_t* get_guest(private_iface_t *this)
+METHOD(iface_t, get_guest, guest_t*,
+ private_iface_t *this)
{
return this->guest;
}
@@ -250,10 +234,8 @@ static char* create_tap(private_iface_t *this)
return strdup(ifr.ifr_name);
}
-/**
- * Implementation of iface_t.destroy.
- */
-static void destroy(private_iface_t *this)
+METHOD(iface_t, destroy, void,
+ private_iface_t *this)
{
if (this->bridge)
{
@@ -273,23 +255,25 @@ static void destroy(private_iface_t *this)
*/
iface_t *iface_create(char *name, guest_t *guest, mconsole_t *mconsole)
{
- private_iface_t *this = malloc_thing(private_iface_t);
-
- this->public.get_hostif = (char*(*)(iface_t*))get_hostif;
- this->public.get_guestif = (char*(*)(iface_t*))get_guestif;
- this->public.add_address = (bool(*)(iface_t*, host_t *addr))add_address;
- this->public.create_address_enumerator = (enumerator_t*(*)(iface_t*))create_address_enumerator;
- this->public.delete_address = (bool(*)(iface_t*, host_t *addr))delete_address;
- this->public.set_bridge = (void(*)(iface_t*, bridge_t*))set_bridge;
- this->public.get_bridge = (bridge_t*(*)(iface_t*))get_bridge;
- this->public.get_guest = (guest_t*(*)(iface_t*))get_guest;
- this->public.destroy = (void*)destroy;
+ private_iface_t *this;
- this->mconsole = mconsole;
- this->guestif = strdup(name);
- this->guest = guest;
+ INIT(this,
+ .public = {
+ .get_hostif = _get_hostif,
+ .get_guestif = _get_guestif,
+ .add_address = _add_address,
+ .create_address_enumerator = _create_address_enumerator,
+ .delete_address = _delete_address,
+ .set_bridge = _set_bridge,
+ .get_bridge = _get_bridge,
+ .get_guest = _get_guest,
+ .destroy = _destroy,
+ },
+ .mconsole = mconsole,
+ .guestif = strdup(name),
+ .guest = guest,
+ );
this->hostif = create_tap(this);
- this->bridge = NULL;
if (this->hostif == NULL)
{
destroy_tap(this);
diff --git a/src/dumm/iface.h b/src/dumm/iface.h
index dabefaa17..e96ee508c 100644
--- a/src/dumm/iface.h
+++ b/src/dumm/iface.h
@@ -50,10 +50,11 @@ struct iface_t {
/**
* Add an address to the interface.
*
- * @param addr address to add to interface
+ * @param addr address to add to the interface
+ * @param bits network prefix length in bits
* @return TRUE if address added
*/
- bool (*add_address)(iface_t *this, host_t *addr);
+ bool (*add_address)(iface_t *this, host_t *addr, int bits);
/**
* Create an enumerator over all installed addresses.
@@ -65,10 +66,13 @@ struct iface_t {
/**
* Remove an address from an interface.
*
+ * @note The network prefix length has to be the same as used in add_address
+ *
* @param addr address to remove
+ * @param bits network prefix length in bits
* @return TRUE if address removed
*/
- bool (*delete_address)(iface_t *this, host_t *addr);
+ bool (*delete_address)(iface_t *this, host_t *addr, int bits);
/**
* Set the bridge this interface is attached to.
diff --git a/src/dumm/mconsole.c b/src/dumm/mconsole.c
index 7d982a54c..de70b7e69 100644
--- a/src/dumm/mconsole.c
+++ b/src/dumm/mconsole.c
@@ -168,10 +168,8 @@ static void ignore(void *data, char *buf, size_t len)
{
}
-/**
- * Implementation of mconsole_t.add_iface.
- */
-static bool add_iface(private_mconsole_t *this, char *guest, char *host)
+METHOD(mconsole_t, add_iface, bool,
+ private_mconsole_t *this, char *guest, char *host)
{
int tries = 0;
@@ -186,10 +184,8 @@ static bool add_iface(private_mconsole_t *this, char *guest, char *host)
return FALSE;
}
-/**
- * Implementation of mconsole_t.del_iface.
- */
-static bool del_iface(private_mconsole_t *this, char *guest)
+METHOD(mconsole_t, del_iface, bool,
+ private_mconsole_t *this, char *guest)
{
if (request(this, NULL, NULL, "remove %s", guest) != 0)
{
@@ -198,11 +194,9 @@ static bool del_iface(private_mconsole_t *this, char *guest)
return TRUE;
}
-/**
- * Implementation of mconsole_t.exec
- */
-static int exec(private_mconsole_t *this, void(*cb)(void*,char*,size_t),
- void *data, char *cmd)
+METHOD(mconsole_t, exec, int,
+ private_mconsole_t *this, void(*cb)(void*,char*,size_t), void *data,
+ char *cmd)
{
return request(this, cb, data, "%s", cmd);
}
@@ -223,10 +217,8 @@ static void wait_bootup(private_mconsole_t *this)
}
}
-/**
- * Implementation of mconsole_t.destroy.
- */
-static void destroy(private_mconsole_t *this)
+METHOD(mconsole_t, destroy, void,
+ private_mconsole_t *this)
{
close(this->console);
close(this->notify);
@@ -327,14 +319,17 @@ static bool setup_console(private_mconsole_t *this)
*/
mconsole_t *mconsole_create(char *notify, void(*idle)(void))
{
- private_mconsole_t *this = malloc_thing(private_mconsole_t);
-
- this->public.add_iface = (bool(*)(mconsole_t*, char *guest, char *host))add_iface;
- this->public.del_iface = (bool(*)(mconsole_t*, char *guest))del_iface;
- this->public.exec = (int(*)(mconsole_t*, void(*cb)(void*,char*,size_t), void *data, char *cmd))exec;
- this->public.destroy = (void*)destroy;
-
- this->idle = idle;
+ private_mconsole_t *this;
+
+ INIT(this,
+ .public = {
+ .add_iface = _add_iface,
+ .del_iface = _del_iface,
+ .exec = _exec,
+ .destroy = _destroy,
+ },
+ .idle = idle,
+ );
if (!wait_for_notify(this, notify))
{