summaryrefslogtreecommitdiff
path: root/src/libcharon/plugins/dhcp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcharon/plugins/dhcp')
-rw-r--r--src/libcharon/plugins/dhcp/Makefile.am18
-rw-r--r--src/libcharon/plugins/dhcp/Makefile.in590
-rw-r--r--src/libcharon/plugins/dhcp/dhcp_plugin.c81
-rw-r--r--src/libcharon/plugins/dhcp/dhcp_plugin.h42
-rw-r--r--src/libcharon/plugins/dhcp/dhcp_provider.c194
-rw-r--r--src/libcharon/plugins/dhcp/dhcp_provider.h54
-rw-r--r--src/libcharon/plugins/dhcp/dhcp_socket.c758
-rw-r--r--src/libcharon/plugins/dhcp/dhcp_socket.h60
-rw-r--r--src/libcharon/plugins/dhcp/dhcp_transaction.c184
-rw-r--r--src/libcharon/plugins/dhcp/dhcp_transaction.h109
10 files changed, 2090 insertions, 0 deletions
diff --git a/src/libcharon/plugins/dhcp/Makefile.am b/src/libcharon/plugins/dhcp/Makefile.am
new file mode 100644
index 000000000..45d7536be
--- /dev/null
+++ b/src/libcharon/plugins/dhcp/Makefile.am
@@ -0,0 +1,18 @@
+
+INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/libhydra \
+ -I$(top_srcdir)/src/libcharon
+
+AM_CFLAGS = -rdynamic
+
+if MONOLITHIC
+noinst_LTLIBRARIES = libstrongswan-dhcp.la
+else
+plugin_LTLIBRARIES = libstrongswan-dhcp.la
+endif
+
+libstrongswan_dhcp_la_SOURCES = dhcp_plugin.h dhcp_plugin.c \
+ dhcp_provider.h dhcp_provider.c \
+ dhcp_socket.h dhcp_socket.c \
+ dhcp_transaction.h dhcp_transaction.c
+
+libstrongswan_dhcp_la_LDFLAGS = -module -avoid-version
diff --git a/src/libcharon/plugins/dhcp/Makefile.in b/src/libcharon/plugins/dhcp/Makefile.in
new file mode 100644
index 000000000..7606b963c
--- /dev/null
+++ b/src/libcharon/plugins/dhcp/Makefile.in
@@ -0,0 +1,590 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = src/libcharon/plugins/dhcp
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/config/libtool.m4 \
+ $(top_srcdir)/m4/config/ltoptions.m4 \
+ $(top_srcdir)/m4/config/ltsugar.m4 \
+ $(top_srcdir)/m4/config/ltversion.m4 \
+ $(top_srcdir)/m4/config/lt~obsolete.m4 \
+ $(top_srcdir)/m4/macros/with.m4 \
+ $(top_srcdir)/m4/macros/enable-disable.m4 \
+ $(top_srcdir)/configure.in
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+ *) f=$$p;; \
+ esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+ if (++n[$$2] == $(am__install_max)) \
+ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+ END { for (dir in files) print dir, files[dir] }'
+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)$(plugindir)"
+LTLIBRARIES = $(noinst_LTLIBRARIES) $(plugin_LTLIBRARIES)
+libstrongswan_dhcp_la_LIBADD =
+am_libstrongswan_dhcp_la_OBJECTS = dhcp_plugin.lo dhcp_provider.lo \
+ dhcp_socket.lo dhcp_transaction.lo
+libstrongswan_dhcp_la_OBJECTS = $(am_libstrongswan_dhcp_la_OBJECTS)
+libstrongswan_dhcp_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(libstrongswan_dhcp_la_LDFLAGS) $(LDFLAGS) -o $@
+@MONOLITHIC_FALSE@am_libstrongswan_dhcp_la_rpath = -rpath $(plugindir)
+@MONOLITHIC_TRUE@am_libstrongswan_dhcp_la_rpath =
+DEFAULT_INCLUDES = -I.@am__isrc@
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+ $(LDFLAGS) -o $@
+SOURCES = $(libstrongswan_dhcp_la_SOURCES)
+DIST_SOURCES = $(libstrongswan_dhcp_la_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+ALLOCA = @ALLOCA@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BTLIB = @BTLIB@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLIB = @DLLIB@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GPERF = @GPERF@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LEX = @LEX@
+LEXLIB = @LEXLIB@
+LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+MYSQLCFLAG = @MYSQLCFLAG@
+MYSQLCONFIG = @MYSQLCONFIG@
+MYSQLLIB = @MYSQLLIB@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PERL = @PERL@
+PKG_CONFIG = @PKG_CONFIG@
+PTHREADLIB = @PTHREADLIB@
+RANLIB = @RANLIB@
+RTLIB = @RTLIB@
+RUBY = @RUBY@
+RUBYINCLUDE = @RUBYINCLUDE@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SOCKLIB = @SOCKLIB@
+STRIP = @STRIP@
+VERSION = @VERSION@
+YACC = @YACC@
+YFLAGS = @YFLAGS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+default_pkcs11 = @default_pkcs11@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+gtk_CFLAGS = @gtk_CFLAGS@
+gtk_LIBS = @gtk_LIBS@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+ipsecdir = @ipsecdir@
+ipsecgid = @ipsecgid@
+ipsecgroup = @ipsecgroup@
+ipsecuid = @ipsecuid@
+ipsecuser = @ipsecuser@
+libdir = @libdir@
+libexecdir = @libexecdir@
+libhydra_plugins = @libhydra_plugins@
+libstrongswan_plugins = @libstrongswan_plugins@
+linux_headers = @linux_headers@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+nm_CFLAGS = @nm_CFLAGS@
+nm_LIBS = @nm_LIBS@
+nm_ca_dir = @nm_ca_dir@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+piddir = @piddir@
+plugindir = @plugindir@
+pluto_plugins = @pluto_plugins@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+random_device = @random_device@
+resolv_conf = @resolv_conf@
+routing_table = @routing_table@
+routing_table_prio = @routing_table_prio@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+strongswan_conf = @strongswan_conf@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+urandom_device = @urandom_device@
+xml_CFLAGS = @xml_CFLAGS@
+xml_LIBS = @xml_LIBS@
+INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/libhydra \
+ -I$(top_srcdir)/src/libcharon
+
+AM_CFLAGS = -rdynamic
+@MONOLITHIC_TRUE@noinst_LTLIBRARIES = libstrongswan-dhcp.la
+@MONOLITHIC_FALSE@plugin_LTLIBRARIES = libstrongswan-dhcp.la
+libstrongswan_dhcp_la_SOURCES = dhcp_plugin.h dhcp_plugin.c \
+ dhcp_provider.h dhcp_provider.c \
+ dhcp_socket.h dhcp_socket.c \
+ dhcp_transaction.h dhcp_transaction.c
+
+libstrongswan_dhcp_la_LDFLAGS = -module -avoid-version
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/libcharon/plugins/dhcp/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --gnu src/libcharon/plugins/dhcp/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstLTLIBRARIES:
+ -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
+ @list='$(noinst_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
+install-pluginLTLIBRARIES: $(plugin_LTLIBRARIES)
+ @$(NORMAL_INSTALL)
+ test -z "$(plugindir)" || $(MKDIR_P) "$(DESTDIR)$(plugindir)"
+ @list='$(plugin_LTLIBRARIES)'; test -n "$(plugindir)" || 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)$(plugindir)'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(plugindir)"; \
+ }
+
+uninstall-pluginLTLIBRARIES:
+ @$(NORMAL_UNINSTALL)
+ @list='$(plugin_LTLIBRARIES)'; test -n "$(plugindir)" || list=; \
+ for p in $$list; do \
+ $(am__strip_dir) \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(plugindir)/$$f'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(plugindir)/$$f"; \
+ done
+
+clean-pluginLTLIBRARIES:
+ -test -z "$(plugin_LTLIBRARIES)" || rm -f $(plugin_LTLIBRARIES)
+ @list='$(plugin_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
+libstrongswan-dhcp.la: $(libstrongswan_dhcp_la_OBJECTS) $(libstrongswan_dhcp_la_DEPENDENCIES)
+ $(libstrongswan_dhcp_la_LINK) $(am_libstrongswan_dhcp_la_rpath) $(libstrongswan_dhcp_la_OBJECTS) $(libstrongswan_dhcp_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dhcp_plugin.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dhcp_provider.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dhcp_socket.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dhcp_transaction.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ set x; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LTLIBRARIES)
+installdirs:
+ for dir in "$(DESTDIR)$(plugindir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \
+ clean-pluginLTLIBRARIES mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-pluginLTLIBRARIES
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-pluginLTLIBRARIES
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+ clean-libtool clean-noinstLTLIBRARIES clean-pluginLTLIBRARIES \
+ 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-dvi install-dvi-am install-exec \
+ install-exec-am install-html install-html-am install-info \
+ install-info-am install-man install-pdf install-pdf-am \
+ install-pluginLTLIBRARIES 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-pluginLTLIBRARIES
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/libcharon/plugins/dhcp/dhcp_plugin.c b/src/libcharon/plugins/dhcp/dhcp_plugin.c
new file mode 100644
index 000000000..829fd6356
--- /dev/null
+++ b/src/libcharon/plugins/dhcp/dhcp_plugin.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2010 Martin Willi
+ * Copyright (C) 2010 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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 General Public License
+ * for more details.
+ */
+
+#include "dhcp_plugin.h"
+
+#include <hydra.h>
+#include <daemon.h>
+
+#include "dhcp_socket.h"
+#include "dhcp_provider.h"
+
+typedef struct private_dhcp_plugin_t private_dhcp_plugin_t;
+
+/**
+ * private data of dhcp plugin
+ */
+struct private_dhcp_plugin_t {
+
+ /**
+ * implements plugin interface
+ */
+ dhcp_plugin_t public;
+
+ /**
+ * DHCP communication socket
+ */
+ dhcp_socket_t *socket;
+
+ /**
+ * Attribute provider
+ */
+ dhcp_provider_t *provider;
+};
+
+METHOD(plugin_t, destroy, void,
+ private_dhcp_plugin_t *this)
+{
+ hydra->attributes->remove_provider(hydra->attributes,
+ &this->provider->provider);
+ this->provider->destroy(this->provider);
+ this->socket->destroy(this->socket);
+ free(this);
+}
+
+/**
+ * Plugin constructor.
+ */
+plugin_t *dhcp_plugin_create()
+{
+ private_dhcp_plugin_t *this;
+
+ INIT(this,
+ .public.plugin.destroy = _destroy,
+ .socket = dhcp_socket_create(),
+ );
+
+ if (!this->socket)
+ {
+ free(this);
+ return NULL;
+ }
+
+ this->provider = dhcp_provider_create(this->socket);
+ hydra->attributes->add_provider(hydra->attributes,
+ &this->provider->provider);
+
+ return &this->public.plugin;
+}
+
diff --git a/src/libcharon/plugins/dhcp/dhcp_plugin.h b/src/libcharon/plugins/dhcp/dhcp_plugin.h
new file mode 100644
index 000000000..b21b44d28
--- /dev/null
+++ b/src/libcharon/plugins/dhcp/dhcp_plugin.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2010 Martin Willi
+ * Copyright (C) 2010 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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 General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup dhcp dhcp
+ * @ingroup cplugins
+ *
+ * @defgroup dhcp_plugin dhcp_plugin
+ * @{ @ingroup dhcp
+ */
+
+#ifndef DHCP_PLUGIN_H_
+#define DHCP_PLUGIN_H_
+
+#include <plugins/plugin.h>
+
+typedef struct dhcp_plugin_t dhcp_plugin_t;
+
+/**
+ * DHCP based attribute provider plugin.
+ */
+struct dhcp_plugin_t {
+
+ /**
+ * implements plugin interface
+ */
+ plugin_t plugin;
+};
+
+#endif /** DHCP_PLUGIN_H_ @}*/
diff --git a/src/libcharon/plugins/dhcp/dhcp_provider.c b/src/libcharon/plugins/dhcp/dhcp_provider.c
new file mode 100644
index 000000000..dbcceb6ce
--- /dev/null
+++ b/src/libcharon/plugins/dhcp/dhcp_provider.c
@@ -0,0 +1,194 @@
+/*
+ * Copyright (C) 2010 Martin Willi
+ * Copyright (C) 2010 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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 General Public License
+ * for more details.
+ */
+
+#include "dhcp_provider.h"
+
+#include <utils/hashtable.h>
+#include <threading/mutex.h>
+
+typedef struct private_dhcp_provider_t private_dhcp_provider_t;
+
+/**
+ * Private data of an dhcp_provider_t object.
+ */
+struct private_dhcp_provider_t {
+
+ /**
+ * Public dhcp_provider_t interface.
+ */
+ dhcp_provider_t public;
+
+ /**
+ * Completed DHCP transactions
+ */
+ hashtable_t *transactions;
+
+ /**
+ * Lock for transactions
+ */
+ mutex_t *mutex;
+
+ /**
+ * DHCP communication socket
+ */
+ dhcp_socket_t *socket;
+};
+
+/**
+ * Hashtable hash function
+ */
+static u_int hash(void *key)
+{
+ return (uintptr_t)key;
+}
+
+/**
+ * Hashtable equals function
+ */
+static bool equals(void *a, void *b)
+{
+ return a == b;
+}
+
+/**
+ * Hash ID and host to a key
+ */
+static uintptr_t hash_id_host(identification_t *id, host_t *host)
+{
+ return chunk_hash_inc(id->get_encoding(id),
+ chunk_hash(host->get_address(host)));
+}
+
+/**
+ * Hash a DHCP transaction to a key, using address and id
+ */
+static uintptr_t hash_transaction(dhcp_transaction_t *transaction)
+{
+ return hash_id_host(transaction->get_identity(transaction),
+ transaction->get_address(transaction));
+}
+
+METHOD(attribute_provider_t, acquire_address, host_t*,
+ private_dhcp_provider_t *this, char *pool,
+ identification_t *id, host_t *requested)
+{
+ if (streq(pool, "dhcp"))
+ {
+ dhcp_transaction_t *transaction, *old;
+ host_t *vip;
+
+ transaction = this->socket->enroll(this->socket, id);
+ if (!transaction)
+ {
+ return NULL;
+ }
+ vip = transaction->get_address(transaction);
+ vip = vip->clone(vip);
+ this->mutex->lock(this->mutex);
+ old = this->transactions->put(this->transactions,
+ (void*)hash_transaction(transaction), transaction);
+ this->mutex->unlock(this->mutex);
+ DESTROY_IF(old);
+ return vip;
+ }
+ return NULL;
+}
+
+METHOD(attribute_provider_t, release_address, bool,
+ private_dhcp_provider_t *this, char *pool,
+ host_t *address, identification_t *id)
+{
+ if (streq(pool, "dhcp"))
+ {
+ dhcp_transaction_t *transaction;
+
+ this->mutex->lock(this->mutex);
+ transaction = this->transactions->remove(this->transactions,
+ (void*)hash_id_host(id, address));
+ this->mutex->unlock(this->mutex);
+ if (transaction)
+ {
+ this->socket->release(this->socket, transaction);
+ transaction->destroy(transaction);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+METHOD(attribute_provider_t, create_attribute_enumerator, enumerator_t*,
+ private_dhcp_provider_t *this, identification_t *id, host_t *vip)
+{
+ dhcp_transaction_t *transaction;
+
+ if (!vip)
+ {
+ return NULL;
+ }
+ this->mutex->lock(this->mutex);
+ transaction = this->transactions->get(this->transactions,
+ (void*)hash_id_host(id, vip));
+ if (!transaction)
+ {
+ this->mutex->unlock(this->mutex);
+ return NULL;
+ }
+ return enumerator_create_cleaner(
+ transaction->create_attribute_enumerator(transaction),
+ (void*)this->mutex->unlock, this->mutex);
+}
+
+METHOD(dhcp_provider_t, destroy, void,
+ private_dhcp_provider_t *this)
+{
+ enumerator_t *enumerator;
+ dhcp_transaction_t *value;
+ void *key;
+
+ enumerator = this->transactions->create_enumerator(this->transactions);
+ while (enumerator->enumerate(enumerator, &key, &value))
+ {
+ value->destroy(value);
+ }
+ enumerator->destroy(enumerator);
+ this->transactions->destroy(this->transactions);
+ this->mutex->destroy(this->mutex);
+ free(this);
+}
+
+/**
+ * See header
+ */
+dhcp_provider_t *dhcp_provider_create(dhcp_socket_t *socket)
+{
+ private_dhcp_provider_t *this;
+
+ INIT(this,
+ .public = {
+ .provider = {
+ .acquire_address = _acquire_address,
+ .release_address = _release_address,
+ .create_attribute_enumerator = _create_attribute_enumerator,
+ },
+ .destroy = _destroy,
+ },
+ .socket = socket,
+ .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
+ .transactions = hashtable_create(hash, equals, 8),
+ );
+
+ return &this->public;
+}
+
diff --git a/src/libcharon/plugins/dhcp/dhcp_provider.h b/src/libcharon/plugins/dhcp/dhcp_provider.h
new file mode 100644
index 000000000..e720e876c
--- /dev/null
+++ b/src/libcharon/plugins/dhcp/dhcp_provider.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2010 Martin Willi
+ * Copyright (C) 2010 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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 General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup dhcp_provider dhcp_provider
+ * @{ @ingroup dhcp
+ */
+
+#ifndef DHCP_PROVIDER_H_
+#define DHCP_PROVIDER_H_
+
+typedef struct dhcp_provider_t dhcp_provider_t;
+
+#include "dhcp_socket.h"
+
+#include <attributes/attribute_provider.h>
+
+/**
+ * DHCP based attribute provider.
+ */
+struct dhcp_provider_t {
+
+ /**
+ * Implements attribute_provier_t interface.
+ */
+ attribute_provider_t provider;
+
+ /**
+ * Destroy a dhcp_provider_t.
+ */
+ void (*destroy)(dhcp_provider_t *this);
+};
+
+/**
+ * Create a dhcp_provider instance.
+ *
+ * @param socket socket to use for DHCP communication
+ * @return provider instance
+ */
+dhcp_provider_t *dhcp_provider_create(dhcp_socket_t *socket);
+
+#endif /** DHCP_PROVIDER_H_ @}*/
diff --git a/src/libcharon/plugins/dhcp/dhcp_socket.c b/src/libcharon/plugins/dhcp/dhcp_socket.c
new file mode 100644
index 000000000..f61b3a60e
--- /dev/null
+++ b/src/libcharon/plugins/dhcp/dhcp_socket.c
@@ -0,0 +1,758 @@
+/*
+ * Copyright (C) 2010 Martin Willi
+ * Copyright (C) 2010 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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 General Public License
+ * for more details.
+ */
+
+#include "dhcp_socket.h"
+
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <netinet/udp.h>
+#include <linux/if_arp.h>
+#include <linux/if_ether.h>
+#include <linux/filter.h>
+
+#include <utils/linked_list.h>
+#include <utils/identification.h>
+#include <threading/mutex.h>
+#include <threading/condvar.h>
+#include <threading/thread.h>
+
+#include <daemon.h>
+#include <processing/jobs/callback_job.h>
+
+#define DHCP_SERVER_PORT 67
+#define DHCP_CLIENT_PORT 68
+#define DHCP_TRIES 5
+
+typedef struct private_dhcp_socket_t private_dhcp_socket_t;
+
+/**
+ * Private data of an dhcp_socket_t object.
+ */
+struct private_dhcp_socket_t {
+
+ /**
+ * Public dhcp_socket_t interface.
+ */
+ dhcp_socket_t public;
+
+ /**
+ * Random number generator
+ */
+ rng_t *rng;
+
+ /**
+ * List of transactions in DISCOVER
+ */
+ linked_list_t *discover;
+
+ /**
+ * List of transactions in REQUEST
+ */
+ linked_list_t *request;
+
+ /**
+ * List of successfully completed transactions
+ */
+ linked_list_t *completed;
+
+ /**
+ * Lock for transactions
+ */
+ mutex_t *mutex;
+
+ /**
+ * Condvar to wait for transaction completion
+ */
+ condvar_t *condvar;
+
+ /**
+ * Threads waiting in condvar
+ */
+ int waiting;
+
+ /**
+ * DHCP send socket
+ */
+ int send;
+
+ /**
+ * DHCP receive socket
+ */
+ int receive;
+
+ /**
+ * Do we use per-identity or random leases (and MAC addresses)
+ */
+ bool identity_lease;
+
+ /**
+ * DHCP server address, or broadcast
+ */
+ host_t *dst;
+
+ /**
+ * Callback job receiving DHCP responses
+ */
+ callback_job_t *job;
+};
+
+/**
+ * DHCP opcode (or BOOTP actually)
+ */
+typedef enum {
+ BOOTREQUEST = 1,
+ BOOTREPLY = 2,
+} dhcp_opcode_t;
+
+/**
+ * Some DHCP options used
+ */
+typedef enum {
+ DHCP_DNS_SERVER = 6,
+ DHCP_HOST_NAME = 12,
+ DHCP_NBNS_SERVER = 44,
+ DHCP_REQUESTED_IP = 50,
+ DHCP_MESSAGE_TYPE = 53,
+ DHCP_SERVER_ID = 54,
+ DHCP_PARAM_REQ_LIST = 55,
+ DHCP_CLIENT_ID = 61,
+ DHCP_OPTEND = 255,
+} dhcp_option_type_t;
+
+/**
+ * DHCP messages types in the DHCP_MESSAGE_TYPE option
+ */
+typedef enum {
+ DHCP_DISCOVER = 1,
+ DHCP_OFFER = 2,
+ DHCP_REQUEST = 3,
+ DHCP_DECLINE = 4,
+ DHCP_ACK = 5,
+ DHCP_NAK = 6,
+ DHCP_RELEASE = 7,
+ DHCP_INFORM = 8,
+} dhcp_message_type_t;
+/**
+ * DHCP option encoding, a TLV
+ */
+typedef struct __attribute__((packed)) {
+ u_int8_t type;
+ u_int8_t len;
+ char data[];
+} dhcp_option_t;
+
+/**
+ * DHCP message format, with a maximum size options buffer
+ */
+typedef struct __attribute__((packed)) {
+ u_int8_t opcode;
+ u_int8_t hw_type;
+ u_int8_t hw_addr_len;
+ u_int8_t hop_count;
+ u_int32_t transaction_id;
+ u_int16_t number_of_seconds;
+ u_int16_t flags;
+ u_int32_t client_address;
+ u_int32_t your_address;
+ u_int32_t server_address;
+ u_int32_t gateway_address;
+ char client_hw_addr[6];
+ char client_hw_padding[10];
+ char server_hostname[64];
+ char boot_filename[128];
+ u_int32_t magic_cookie;
+ char options[252];
+} dhcp_t;
+
+/**
+ * Prepare a DHCP message for a given transaction
+ */
+static int prepare_dhcp(private_dhcp_socket_t *this,
+ dhcp_transaction_t *transaction,
+ dhcp_message_type_t type, dhcp_t *dhcp)
+{
+ chunk_t chunk, broadcast = chunk_from_chars(0xFF,0xFF,0xFF,0xFF);
+ identification_t *identity;
+ dhcp_option_t *option;
+ int optlen = 0;
+ host_t *src;
+ u_int32_t id;
+
+ memset(dhcp, 0, sizeof(*dhcp));
+ dhcp->opcode = BOOTREQUEST;
+ dhcp->hw_type = ARPHRD_ETHER;
+ dhcp->hw_addr_len = 6;
+ dhcp->transaction_id = transaction->get_id(transaction);
+ if (chunk_equals(broadcast, this->dst->get_address(this->dst)))
+ {
+ /* TODO: send with 0.0.0.0 source address */
+ }
+ else
+ {
+ /* act as relay agent */
+ src = charon->kernel_interface->get_source_addr(
+ charon->kernel_interface, this->dst, NULL);
+ if (src)
+ {
+ memcpy(&dhcp->gateway_address, src->get_address(src).ptr,
+ sizeof(dhcp->gateway_address));
+ src->destroy(src);
+ }
+ }
+
+ identity = transaction->get_identity(transaction);
+ chunk = identity->get_encoding(identity);
+ /* magic bytes, a locally administered unicast MAC */
+ dhcp->client_hw_addr[0] = 0x7A;
+ dhcp->client_hw_addr[1] = 0xA7;
+ /* with ID specific postfix */
+ if (this->identity_lease)
+ {
+ id = htonl(chunk_hash(chunk));
+ }
+ else
+ {
+ id = transaction->get_id(transaction);
+ }
+ memcpy(&dhcp->client_hw_addr[2], &id, sizeof(id));
+
+ dhcp->magic_cookie = htonl(0x63825363);
+
+ option = (dhcp_option_t*)&dhcp->options[optlen];
+ option->type = DHCP_MESSAGE_TYPE;
+ option->len = 1;
+ option->data[0] = type;
+ optlen += sizeof(dhcp_option_t) + option->len;
+
+ if (identity->get_type(identity) == ID_FQDN)
+ {
+ option = (dhcp_option_t*)&dhcp->options[optlen];
+ option->type = DHCP_HOST_NAME;
+ option->len = min(chunk.len, 64);
+ memcpy(option->data, chunk.ptr, option->len);
+ optlen += sizeof(dhcp_option_t) + option->len;
+ }
+
+ option = (dhcp_option_t*)&dhcp->options[optlen];
+ option->type = DHCP_CLIENT_ID;
+ option->len = min(chunk.len, 64);
+ memcpy(option->data, chunk.ptr, option->len);
+ optlen += sizeof(dhcp_option_t) + option->len;
+
+ return optlen;
+}
+
+/**
+ * Send a DHCP message with given options length
+ */
+static bool send_dhcp(private_dhcp_socket_t *this,
+ dhcp_transaction_t *transaction, dhcp_t *dhcp, int optlen)
+{
+ host_t *dst;
+ ssize_t len;
+
+ dst = transaction->get_server(transaction);
+ if (!dst)
+ {
+ dst = this->dst;
+ }
+ len = offsetof(dhcp_t, magic_cookie) + ((optlen + 4) / 64 * 64 + 64);
+ return sendto(this->send, dhcp, len, 0, dst->get_sockaddr(dst),
+ *dst->get_sockaddr_len(dst)) == len;
+}
+
+/**
+ * Send DHCP discover using a given transaction
+ */
+static bool discover(private_dhcp_socket_t *this,
+ dhcp_transaction_t *transaction)
+{
+ dhcp_option_t *option;
+ dhcp_t dhcp;
+ int optlen;
+
+ optlen = prepare_dhcp(this, transaction, DHCP_DISCOVER, &dhcp);
+
+ DBG1(DBG_CFG, "sending DHCP DISCOVER to %H", this->dst);
+
+ option = (dhcp_option_t*)&dhcp.options[optlen];
+ option->type = DHCP_PARAM_REQ_LIST;
+ option->len = 2;
+ option->data[0] = DHCP_DNS_SERVER;
+ option->data[1] = DHCP_NBNS_SERVER;
+ optlen += sizeof(dhcp_option_t) + option->len;
+
+ dhcp.options[optlen++] = DHCP_OPTEND;
+
+ if (!send_dhcp(this, transaction, &dhcp, optlen))
+ {
+ DBG1(DBG_CFG, "sending DHCP DISCOVER failed: %s", strerror(errno));
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/**
+ * Send DHCP request using a given transaction
+ */
+static bool request(private_dhcp_socket_t *this,
+ dhcp_transaction_t *transaction)
+{
+ dhcp_option_t *option;
+ dhcp_t dhcp;
+ host_t *offer, *server;
+ chunk_t chunk;
+ int optlen;
+
+ optlen = prepare_dhcp(this, transaction, DHCP_REQUEST, &dhcp);
+
+ offer = transaction->get_address(transaction);
+ server = transaction->get_server(transaction);
+ if (!offer || !server)
+ {
+ return FALSE;
+ }
+ DBG1(DBG_CFG, "sending DHCP REQUEST for %H to %H", offer, server);
+
+ option = (dhcp_option_t*)&dhcp.options[optlen];
+ option->type = DHCP_REQUESTED_IP;
+ option->len = 4;
+ chunk = offer->get_address(offer);
+ memcpy(option->data, chunk.ptr, min(chunk.len, option->len));
+ optlen += sizeof(dhcp_option_t) + option->len;
+
+ option = (dhcp_option_t*)&dhcp.options[optlen];
+ option->type = DHCP_SERVER_ID;
+ option->len = 4;
+ chunk = server->get_address(server);
+ memcpy(option->data, chunk.ptr, min(chunk.len, option->len));
+ optlen += sizeof(dhcp_option_t) + option->len;
+
+ option = (dhcp_option_t*)&dhcp.options[optlen];
+ option->type = DHCP_PARAM_REQ_LIST;
+ option->len = 2;
+ option->data[0] = DHCP_DNS_SERVER;
+ option->data[1] = DHCP_NBNS_SERVER;
+ optlen += sizeof(dhcp_option_t) + option->len;
+
+ dhcp.options[optlen++] = DHCP_OPTEND;
+
+ if (!send_dhcp(this, transaction, &dhcp, optlen))
+ {
+ DBG1(DBG_CFG, "sending DHCP REQUEST failed: %s", strerror(errno));
+ return FALSE;
+ }
+ return TRUE;
+}
+
+METHOD(dhcp_socket_t, enroll, dhcp_transaction_t*,
+ private_dhcp_socket_t *this, identification_t *identity)
+{
+ dhcp_transaction_t *transaction;
+ u_int32_t id;
+ int try;
+
+ this->rng->get_bytes(this->rng, sizeof(id), (u_int8_t*)&id);
+ transaction = dhcp_transaction_create(id, identity);
+
+ this->mutex->lock(this->mutex);
+ this->discover->insert_last(this->discover, transaction);
+ try = 1;
+ while (try <= DHCP_TRIES && discover(this, transaction))
+ {
+ if (!this->condvar->timed_wait(this->condvar, this->mutex, 1000 * try) &&
+ this->request->find_first(this->request, NULL,
+ (void**)&transaction) == SUCCESS)
+ {
+ break;
+ }
+ try++;
+ }
+ if (this->discover->remove(this->discover, transaction, NULL))
+ { /* no OFFER received */
+ this->mutex->unlock(this->mutex);
+ transaction->destroy(transaction);
+ DBG1(DBG_CFG, "DHCP DISCOVER timed out");
+ return NULL;
+ }
+
+ try = 1;
+ while (try <= DHCP_TRIES && request(this, transaction))
+ {
+ if (!this->condvar->timed_wait(this->condvar, this->mutex, 1000 * try) &&
+ this->completed->remove(this->completed, transaction, NULL))
+ {
+ break;
+ }
+ try++;
+ }
+ if (this->request->remove(this->request, transaction, NULL))
+ { /* no ACK received */
+ this->mutex->unlock(this->mutex);
+ transaction->destroy(transaction);
+ DBG1(DBG_CFG, "DHCP REQUEST timed out");
+ return NULL;
+ }
+ this->mutex->unlock(this->mutex);
+
+ return transaction;
+}
+
+METHOD(dhcp_socket_t, release, void,
+ private_dhcp_socket_t *this, dhcp_transaction_t *transaction)
+{
+ dhcp_option_t *option;
+ dhcp_t dhcp;
+ host_t *release, *server;
+ chunk_t chunk;
+ int optlen;
+
+ optlen = prepare_dhcp(this, transaction, DHCP_RELEASE, &dhcp);
+
+ release = transaction->get_address(transaction);
+ server = transaction->get_server(transaction);
+ if (!release || !server)
+ {
+ return;
+ }
+ DBG1(DBG_CFG, "sending DHCP RELEASE for %H to %H", release, server);
+
+ chunk = release->get_address(release);
+ memcpy(&dhcp.client_address, chunk.ptr,
+ min(chunk.len, sizeof(dhcp.client_address)));
+
+ option = (dhcp_option_t*)&dhcp.options[optlen];
+ option->type = DHCP_SERVER_ID;
+ option->len = 4;
+ chunk = server->get_address(server);
+ memcpy(option->data, chunk.ptr, min(chunk.len, option->len));
+ optlen += sizeof(dhcp_option_t) + option->len;
+
+ dhcp.options[optlen++] = DHCP_OPTEND;
+
+ if (!send_dhcp(this, transaction, &dhcp, optlen))
+ {
+ DBG1(DBG_CFG, "sending DHCP RELEASE failed: %s", strerror(errno));
+ }
+}
+
+/**
+ * Handle a DHCP OFFER
+ */
+static void handle_offer(private_dhcp_socket_t *this, dhcp_t *dhcp, int optlen)
+{
+ dhcp_transaction_t *transaction = NULL;
+ enumerator_t *enumerator;
+ host_t *offer, *server;
+
+ offer = host_create_from_chunk(AF_INET,
+ chunk_from_thing(dhcp->your_address), 0);
+ server = host_create_from_chunk(AF_INET,
+ chunk_from_thing(dhcp->server_address), DHCP_SERVER_PORT);
+
+ this->mutex->lock(this->mutex);
+ enumerator = this->discover->create_enumerator(this->discover);
+ while (enumerator->enumerate(enumerator, &transaction))
+ {
+ if (transaction->get_id(transaction) == dhcp->transaction_id)
+ {
+ DBG1(DBG_CFG, "received DHCP OFFER %H from %H", offer, server);
+ this->discover->remove_at(this->discover, enumerator);
+ this->request->insert_last(this->request, transaction);
+ transaction->set_address(transaction, offer->clone(offer));
+ transaction->set_server(transaction, server->clone(server));
+ break;
+ }
+ }
+ enumerator->destroy(enumerator);
+
+ if (transaction)
+ {
+ int optsize, optpos = 0, pos;
+ dhcp_option_t *option;
+
+ while (optlen > sizeof(dhcp_option_t))
+ {
+ option = (dhcp_option_t*)&dhcp->options[optpos];
+ optsize = sizeof(dhcp_option_t) + option->len;
+ if (option->type == DHCP_OPTEND || optlen < optsize)
+ {
+ break;
+ }
+ if (option->type == DHCP_DNS_SERVER ||
+ option->type == DHCP_NBNS_SERVER)
+ {
+ for (pos = 0; pos + 4 <= option->len; pos += 4)
+ {
+ transaction->add_attribute(transaction, option->type ==
+ DHCP_DNS_SERVER ? INTERNAL_IP4_DNS : INTERNAL_IP4_NBNS,
+ chunk_create((char*)&option->data[pos], 4));
+ }
+ }
+ optlen -= optsize;
+ optpos += optsize;
+ }
+ }
+ this->mutex->unlock(this->mutex);
+ this->condvar->broadcast(this->condvar);
+ offer->destroy(offer);
+ server->destroy(server);
+}
+
+/**
+ * Handle a DHCP ACK
+ */
+static void handle_ack(private_dhcp_socket_t *this, dhcp_t *dhcp, int optlen)
+{
+ dhcp_transaction_t *transaction;
+ enumerator_t *enumerator;
+ host_t *offer;
+
+ offer = host_create_from_chunk(AF_INET,
+ chunk_from_thing(dhcp->your_address), 0);
+
+ this->mutex->lock(this->mutex);
+ enumerator = this->request->create_enumerator(this->request);
+ while (enumerator->enumerate(enumerator, &transaction))
+ {
+ if (transaction->get_id(transaction) == dhcp->transaction_id)
+ {
+ DBG1(DBG_CFG, "received DHCP ACK for %H", offer);
+ this->request->remove_at(this->request, enumerator);
+ this->completed->insert_last(this->completed, transaction);
+ break;
+ }
+ }
+ enumerator->destroy(enumerator);
+ this->mutex->unlock(this->mutex);
+ this->condvar->broadcast(this->condvar);
+ offer->destroy(offer);
+}
+
+/**
+ * Receive DHCP responses
+ */
+static job_requeue_t receive_dhcp(private_dhcp_socket_t *this)
+{
+ struct sockaddr_ll addr;
+ socklen_t addr_len = sizeof(addr);
+ struct __attribute__((packed)) {
+ struct iphdr ip;
+ struct udphdr udp;
+ dhcp_t dhcp;
+ } packet;
+ int oldstate, optlen, origoptlen, optsize, optpos = 0;
+ ssize_t len;
+ dhcp_option_t *option;
+
+ oldstate = thread_cancelability(TRUE);
+ len = recvfrom(this->receive, &packet, sizeof(packet), 0,
+ (struct sockaddr*)&addr, &addr_len);
+ thread_cancelability(oldstate);
+
+ if (len >= sizeof(struct iphdr) + sizeof(struct udphdr) +
+ offsetof(dhcp_t, options))
+ {
+ origoptlen = optlen = len - sizeof(struct iphdr) +
+ sizeof(struct udphdr) + offsetof(dhcp_t, options);
+ while (optlen > sizeof(dhcp_option_t))
+ {
+ option = (dhcp_option_t*)&packet.dhcp.options[optpos];
+ optsize = sizeof(dhcp_option_t) + option->len;
+ if (option->type == DHCP_OPTEND || optlen < optsize)
+ {
+ break;
+ }
+ if (option->type == DHCP_MESSAGE_TYPE && option->len == 1)
+ {
+ switch (option->data[0])
+ {
+ case DHCP_OFFER:
+ handle_offer(this, &packet.dhcp, origoptlen);
+ break;
+ case DHCP_ACK:
+ handle_ack(this, &packet.dhcp, origoptlen);
+ default:
+ break;
+ }
+ break;
+ }
+ optlen -= optsize;
+ optpos += optsize;
+ }
+ }
+ return JOB_REQUEUE_DIRECT;
+}
+
+METHOD(dhcp_socket_t, destroy, void,
+ private_dhcp_socket_t *this)
+{
+ if (this->job)
+ {
+ this->job->cancel(this->job);
+ }
+ while (this->waiting)
+ {
+ this->condvar->signal(this->condvar);
+ }
+ if (this->send > 0)
+ {
+ close(this->send);
+ }
+ if (this->receive > 0)
+ {
+ close(this->receive);
+ }
+ this->mutex->destroy(this->mutex);
+ this->condvar->destroy(this->condvar);
+ this->discover->destroy_offset(this->discover,
+ offsetof(dhcp_transaction_t, destroy));
+ this->request->destroy_offset(this->request,
+ offsetof(dhcp_transaction_t, destroy));
+ this->completed->destroy_offset(this->completed,
+ offsetof(dhcp_transaction_t, destroy));
+ DESTROY_IF(this->rng);
+ DESTROY_IF(this->dst);
+ free(this);
+}
+
+/**
+ * See header
+ */
+dhcp_socket_t *dhcp_socket_create()
+{
+ private_dhcp_socket_t *this;
+ struct sockaddr_in src;
+ int on = 1;
+ struct sock_filter dhcp_filter_code[] = {
+ BPF_STMT(BPF_LD+BPF_B+BPF_ABS,
+ offsetof(struct iphdr, protocol)),
+ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, IPPROTO_UDP, 0, 16),
+ BPF_STMT(BPF_LD+BPF_H+BPF_ABS, sizeof(struct iphdr) +
+ offsetof(struct udphdr, source)),
+ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, DHCP_SERVER_PORT, 0, 14),
+ BPF_STMT(BPF_LD+BPF_H+BPF_ABS, sizeof(struct iphdr) +
+ offsetof(struct udphdr, dest)),
+ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, DHCP_CLIENT_PORT, 0, 2),
+ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, DHCP_SERVER_PORT, 0, 1),
+ BPF_JUMP(BPF_JMP+BPF_JA, 0, 0, 10),
+ BPF_STMT(BPF_LD+BPF_B+BPF_ABS, sizeof(struct iphdr) +
+ sizeof(struct udphdr) + offsetof(dhcp_t, opcode)),
+ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, BOOTREPLY, 0, 8),
+ BPF_STMT(BPF_LD+BPF_B+BPF_ABS, sizeof(struct iphdr) +
+ sizeof(struct udphdr) + offsetof(dhcp_t, hw_type)),
+ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, ARPHRD_ETHER, 0, 6),
+ BPF_STMT(BPF_LD+BPF_B+BPF_ABS, sizeof(struct iphdr) +
+ sizeof(struct udphdr) + offsetof(dhcp_t, hw_addr_len)),
+ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 6, 0, 4),
+ BPF_STMT(BPF_LD+BPF_W+BPF_ABS, sizeof(struct iphdr) +
+ sizeof(struct udphdr) + offsetof(dhcp_t, magic_cookie)),
+ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x63825363, 0, 2),
+ BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0),
+ BPF_STMT(BPF_RET+BPF_A, 0),
+ BPF_STMT(BPF_RET+BPF_K, 0),
+ };
+ struct sock_fprog dhcp_filter = {
+ sizeof(dhcp_filter_code) / sizeof(struct sock_filter),
+ dhcp_filter_code,
+ };
+
+ INIT(this,
+ .public = {
+ .enroll = _enroll,
+ .release = _release,
+ .destroy = _destroy,
+ },
+ .rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK),
+ .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
+ .condvar = condvar_create(CONDVAR_TYPE_DEFAULT),
+ .discover = linked_list_create(),
+ .request = linked_list_create(),
+ .completed = linked_list_create(),
+ );
+
+ if (!this->rng)
+ {
+ DBG1(DBG_CFG, "unable to create RNG");
+ destroy(this);
+ return NULL;
+ }
+ this->identity_lease = lib->settings->get_bool(lib->settings,
+ "charon.plugins.dhcp.identity_lease", FALSE);
+ this->dst = host_create_from_string(lib->settings->get_str(lib->settings,
+ "charon.plugins.dhcp.server", "255.255.255.255"),
+ DHCP_SERVER_PORT);
+ if (!this->dst)
+ {
+ DBG1(DBG_CFG, "configured DHCP server address invalid");
+ destroy(this);
+ return NULL;
+ }
+
+ this->send = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (this->send == -1)
+ {
+ DBG1(DBG_CFG, "unable to create DHCP send socket: %s", strerror(errno));
+ destroy(this);
+ return NULL;
+ }
+ if (setsockopt(this->send, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1)
+ {
+ DBG1(DBG_CFG, "unable to reuse DHCP socket address: %s", strerror(errno));
+ destroy(this);
+ return NULL;
+ }
+ if (setsockopt(this->send, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) == -1)
+ {
+ DBG1(DBG_CFG, "unable to broadcast on DHCP socket: %s", strerror(errno));
+ destroy(this);
+ return NULL;
+ }
+ src.sin_family = AF_INET;
+ src.sin_port = htons(DHCP_CLIENT_PORT);
+ src.sin_addr.s_addr = INADDR_ANY;
+ if (bind(this->send, (struct sockaddr*)&src, sizeof(src)) == -1)
+ {
+ DBG1(DBG_CFG, "unable to bind DHCP send socket: %s", strerror(errno));
+ destroy(this);
+ return NULL;
+ }
+
+ this->receive = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
+ if (this->receive == -1)
+ {
+ DBG1(DBG_NET, "opening DHCP receive socket failed: %s", strerror(errno));
+ destroy(this);
+ return NULL;
+ }
+ if (setsockopt(this->receive, SOL_SOCKET, SO_ATTACH_FILTER,
+ &dhcp_filter, sizeof(dhcp_filter)) < 0)
+ {
+ DBG1(DBG_CFG, "installing DHCP socket filter failed: %s",
+ strerror(errno));
+ destroy(this);
+ return NULL;
+ }
+
+ this->job = callback_job_create((callback_job_cb_t)receive_dhcp,
+ this, NULL, NULL);
+ charon->processor->queue_job(charon->processor, (job_t*)this->job);
+
+ return &this->public;
+}
+
diff --git a/src/libcharon/plugins/dhcp/dhcp_socket.h b/src/libcharon/plugins/dhcp/dhcp_socket.h
new file mode 100644
index 000000000..0a8398aba
--- /dev/null
+++ b/src/libcharon/plugins/dhcp/dhcp_socket.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2010 Martin Willi
+ * Copyright (C) 2010 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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 General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup dhcp_socket dhcp_socket
+ * @{ @ingroup dhcp
+ */
+
+#ifndef DHCP_SOCKET_H_
+#define DHCP_SOCKET_H_
+
+typedef struct dhcp_socket_t dhcp_socket_t;
+
+#include "dhcp_transaction.h"
+
+/**
+ * DHCP socket implementation
+ */
+struct dhcp_socket_t {
+
+ /**
+ * Enroll a client address using DHCP.
+ *
+ * @param identity peer identity to enroll an address for
+ * @return completed DHCP transaction, NULL on failure
+ */
+ dhcp_transaction_t* (*enroll)(dhcp_socket_t *this,
+ identification_t *identity);
+
+ /**
+ * Release an enrolled DHCP address.
+ *
+ * @param transaction transaction returned by enroll
+ */
+ void (*release)(dhcp_socket_t *this, dhcp_transaction_t *transaction);
+
+ /**
+ * Destroy a dhcp_socket_t.
+ */
+ void (*destroy)(dhcp_socket_t *this);
+};
+
+/**
+ * Create a dhcp_socket instance.
+ */
+dhcp_socket_t *dhcp_socket_create();
+
+#endif /** DHCP_SOCKET_H_ @}*/
diff --git a/src/libcharon/plugins/dhcp/dhcp_transaction.c b/src/libcharon/plugins/dhcp/dhcp_transaction.c
new file mode 100644
index 000000000..83f822dd8
--- /dev/null
+++ b/src/libcharon/plugins/dhcp/dhcp_transaction.c
@@ -0,0 +1,184 @@
+/*
+ * Copyright (C) 2010 Martin Willi
+ * Copyright (C) 2010 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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 General Public License
+ * for more details.
+ */
+
+#include "dhcp_transaction.h"
+
+#include <utils/linked_list.h>
+
+typedef struct private_dhcp_transaction_t private_dhcp_transaction_t;
+
+/**
+ * Private data of an dhcp_transaction_t object.
+ */
+struct private_dhcp_transaction_t {
+
+ /**
+ * Public dhcp_transaction_t interface.
+ */
+ dhcp_transaction_t public;
+
+ /**
+ * DHCP transaction ID
+ */
+ u_int32_t id;
+
+ /**
+ * Peer identity
+ */
+ identification_t *identity;
+
+ /**
+ * received DHCP address
+ */
+ host_t *address;
+
+ /**
+ * discovered DHCP server address
+ */
+ host_t *server;
+
+ /**
+ * List of added attributes, as attribute_entry_t
+ */
+ linked_list_t *attributes;
+};
+
+/**
+ * Entry for an added attribute
+ */
+typedef struct {
+ configuration_attribute_type_t type;
+ chunk_t data;
+} attribute_entry_t;
+
+METHOD(dhcp_transaction_t, get_id, u_int32_t,
+ private_dhcp_transaction_t *this)
+{
+ return this->id;
+}
+
+METHOD(dhcp_transaction_t, get_identity, identification_t*,
+ private_dhcp_transaction_t *this)
+{
+ return this->identity;
+}
+
+METHOD(dhcp_transaction_t, set_address, void,
+ private_dhcp_transaction_t *this, host_t *address)
+{
+ DESTROY_IF(this->address);
+ this->address = address;
+}
+
+METHOD(dhcp_transaction_t, get_address, host_t*,
+ private_dhcp_transaction_t *this)
+{
+ return this->address;
+}
+
+METHOD(dhcp_transaction_t, set_server, void,
+ private_dhcp_transaction_t *this, host_t *server)
+{
+ DESTROY_IF(this->server);
+ this->server = server;
+}
+
+METHOD(dhcp_transaction_t, get_server, host_t*,
+ private_dhcp_transaction_t *this)
+{
+ return this->server;
+}
+
+METHOD(dhcp_transaction_t, add_attribute, void,
+ private_dhcp_transaction_t *this, configuration_attribute_type_t type,
+ chunk_t data)
+{
+ attribute_entry_t *entry;
+
+ INIT(entry,
+ .type = type,
+ .data = chunk_clone(data),
+ );
+ this->attributes->insert_last(this->attributes, entry);
+}
+
+/**
+ * Filter function to map entries to type/data
+ */
+static bool attribute_filter(void *null, attribute_entry_t **entry,
+ configuration_attribute_type_t *type,
+ void **dummy, chunk_t *data)
+{
+ *type = (*entry)->type;
+ *data = (*entry)->data;
+ return TRUE;
+}
+
+METHOD(dhcp_transaction_t, create_attribute_enumerator, enumerator_t*,
+ private_dhcp_transaction_t *this)
+{
+ return enumerator_create_filter(
+ this->attributes->create_enumerator(this->attributes),
+ (void*)attribute_filter, NULL, NULL);
+}
+
+/**
+ * Clean up an attribute entry
+ */
+static void attribute_entry_destroy(attribute_entry_t *entry)
+{
+ free(entry->data.ptr);
+ free(entry);
+}
+
+METHOD(dhcp_transaction_t, destroy, void,
+ private_dhcp_transaction_t *this)
+{
+ this->identity->destroy(this->identity);
+ DESTROY_IF(this->address);
+ DESTROY_IF(this->server);
+ this->attributes->destroy_function(this->attributes,
+ (void*)attribute_entry_destroy);
+ free(this);
+}
+
+/**
+ * See header
+ */
+dhcp_transaction_t *dhcp_transaction_create(u_int32_t id,
+ identification_t *identity)
+{
+ private_dhcp_transaction_t *this;
+
+ INIT(this,
+ .public = {
+ .get_id = _get_id,
+ .get_identity = _get_identity,
+ .set_address = _set_address,
+ .get_address = _get_address,
+ .set_server = _set_server,
+ .get_server = _get_server,
+ .add_attribute = _add_attribute,
+ .create_attribute_enumerator = _create_attribute_enumerator,
+ .destroy = _destroy,
+ },
+ .id = id,
+ .identity = identity->clone(identity),
+ .attributes = linked_list_create(),
+ );
+
+ return &this->public;
+}
+
diff --git a/src/libcharon/plugins/dhcp/dhcp_transaction.h b/src/libcharon/plugins/dhcp/dhcp_transaction.h
new file mode 100644
index 000000000..19c163f88
--- /dev/null
+++ b/src/libcharon/plugins/dhcp/dhcp_transaction.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2010 Martin Willi
+ * Copyright (C) 2010 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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 General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup dhcp_transaction dhcp_transaction
+ * @{ @ingroup dhcp
+ */
+
+#ifndef DHCP_TRANSACTION_H_
+#define DHCP_TRANSACTION_H_
+
+#include <utils/host.h>
+#include <utils/identification.h>
+#include <attributes/attributes.h>
+
+typedef struct dhcp_transaction_t dhcp_transaction_t;
+
+/**
+ * DHCP transaction class.
+ */
+struct dhcp_transaction_t {
+
+ /**
+ * Get the DCHP transaction ID.
+ *
+ * @return DHCP transaction identifier
+ */
+ u_int32_t (*get_id)(dhcp_transaction_t *this);
+
+ /**
+ * Get the peer identity this transaction is used for.
+ *
+ * @return peer Identity
+ */
+ identification_t* (*get_identity)(dhcp_transaction_t *this);
+
+ /**
+ * Set the DHCP address received using this transaction.
+ *
+ * @param host received DHCP address
+ */
+ void (*set_address)(dhcp_transaction_t *this, host_t *address);
+
+ /**
+ * Get the DHCP address received using this transaction.
+ *
+ * @return received DHCP address
+ */
+ host_t* (*get_address)(dhcp_transaction_t *this);
+
+ /**
+ * Set the DCHP server address discovered.
+ *
+ * @param server DHCP server address
+ */
+ void (*set_server)(dhcp_transaction_t *this, host_t *server);
+
+ /**
+ * Get the DHCP server address.
+ *
+ * @return DHCP server address
+ */
+ host_t* (*get_server)(dhcp_transaction_t *this);
+
+ /**
+ * An an additional attribute to serve to peer.
+ *
+ * @param type type of attribute
+ * @param data attribute data
+ */
+ void (*add_attribute)(dhcp_transaction_t *this,
+ configuration_attribute_type_t type, chunk_t data);
+
+ /**
+ * Create an enumerator over added attributes.
+ *
+ * @return enumerator over (configuration_attribute_t, chunk_t)
+ */
+ enumerator_t* (*create_attribute_enumerator)(dhcp_transaction_t *this);
+
+ /**
+ * Destroy a dhcp_transaction_t.
+ */
+ void (*destroy)(dhcp_transaction_t *this);
+};
+
+/**
+ * Create a dhcp_transaction instance.
+ *
+ * @param id DHCP transaction identifier
+ * @param identity peer identity this transaction is used for
+ * @return transaction instance
+ */
+dhcp_transaction_t *dhcp_transaction_create(u_int32_t id,
+ identification_t *identity);
+
+#endif /** DHCP_TRANSACTION_H_ @}*/