From: Tomek Mrugalski Date: Fri, 19 Aug 2011 15:12:12 +0000 (+0200) Subject: [1186] Initial libdhcp skeleton implementation. X-Git-Tag: perftcpdns_before_epoll~86^2~46 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d647a4589362d2b6efee86e58c9fb38e7084deb4;p=thirdparty%2Fkea.git [1186] Initial libdhcp skeleton implementation. --- diff --git a/configure.ac b/configure.ac index b0f5f45fd4..438883d3a8 100644 --- a/configure.ac +++ b/configure.ac @@ -870,6 +870,8 @@ AC_CONFIG_FILES([Makefile src/lib/dns/python/Makefile src/lib/dns/python/tests/Makefile src/lib/dns/benchmarks/Makefile + src/lib/dhcp/Makefile + src/lib/dhcp/tests/Makefile src/lib/exceptions/Makefile src/lib/exceptions/tests/Makefile src/lib/datasrc/Makefile diff --git a/doc/Doxyfile b/doc/Doxyfile index 8be9098bd7..ee5aaf83bc 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -574,7 +574,7 @@ INPUT = ../src/lib/exceptions ../src/lib/cc \ ../src/lib/log/compiler ../src/lib/asiolink/ ../src/lib/nsas \ ../src/lib/testutils ../src/lib/cache ../src/lib/server_common/ \ ../src/bin/sockcreator/ ../src/lib/util/ \ - ../src/lib/resolve ../src/lib/acl ../src/bin/dhcp6 + ../src/lib/resolve ../src/lib/acl ../src/bin/dhcp6 ../src/lib/dhcp # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is diff --git a/src/bin/dhcp6/Makefile.am b/src/bin/dhcp6/Makefile.am index 805d6bbccb..a131e2c4db 100644 --- a/src/bin/dhcp6/Makefile.am +++ b/src/bin/dhcp6/Makefile.am @@ -31,11 +31,12 @@ spec_config.h: spec_config.h.pre BUILT_SOURCES = spec_config.h pkglibexec_PROGRAMS = b10-dhcp6 -b10_dhcp6_SOURCES = main.cc iface_mgr.cc pkt6.cc dhcp6_srv.cc -b10_dhcp6_SOURCES += iface_mgr.h pkt6.h dhcp6_srv.h dhcp6.h +b10_dhcp6_SOURCES = main.cc iface_mgr.cc dhcp6_srv.cc +b10_dhcp6_SOURCES += iface_mgr.h dhcp6_srv.h b10_dhcp6_LDADD = $(top_builddir)/src/lib/datasrc/libdatasrc.la b10_dhcp6_LDADD += $(top_builddir)/src/lib/dns/libdns++.la b10_dhcp6_LDADD += $(top_builddir)/src/lib/util/libutil.la +b10_dhcp6_LDADD += $(top_builddir)/src/lib/dhcp/libdhcp.la b10_dhcp6_LDADD += $(top_builddir)/src/lib/config/libcfgclient.la b10_dhcp6_LDADD += $(top_builddir)/src/lib/cc/libcc.la b10_dhcp6_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la diff --git a/src/bin/dhcp6/dhcp6.h b/src/bin/dhcp6/dhcp6.h deleted file mode 100644 index b5512f31df..0000000000 --- a/src/bin/dhcp6/dhcp6.h +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright (C) 2006-2011 Internet Systems Consortium, Inc. ("ISC") -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - -#ifndef DHCP6_H -#define DHCP6_H - -/* DHCPv6 Option codes: */ - -#define D6O_CLIENTID 1 /* RFC3315 */ -#define D6O_SERVERID 2 -#define D6O_IA_NA 3 -#define D6O_IA_TA 4 -#define D6O_IAADDR 5 -#define D6O_ORO 6 -#define D6O_PREFERENCE 7 -#define D6O_ELAPSED_TIME 8 -#define D6O_RELAY_MSG 9 -/* Option code 10 unassigned. */ -#define D6O_AUTH 11 -#define D6O_UNICAST 12 -#define D6O_STATUS_CODE 13 -#define D6O_RAPID_COMMIT 14 -#define D6O_USER_CLASS 15 -#define D6O_VENDOR_CLASS 16 -#define D6O_VENDOR_OPTS 17 -#define D6O_INTERFACE_ID 18 -#define D6O_RECONF_MSG 19 -#define D6O_RECONF_ACCEPT 20 -#define D6O_SIP_SERVERS_DNS 21 /* RFC3319 */ -#define D6O_SIP_SERVERS_ADDR 22 /* RFC3319 */ -#define D6O_NAME_SERVERS 23 /* RFC3646 */ -#define D6O_DOMAIN_SEARCH 24 /* RFC3646 */ -#define D6O_IA_PD 25 /* RFC3633 */ -#define D6O_IAPREFIX 26 /* RFC3633 */ -#define D6O_NIS_SERVERS 27 /* RFC3898 */ -#define D6O_NISP_SERVERS 28 /* RFC3898 */ -#define D6O_NIS_DOMAIN_NAME 29 /* RFC3898 */ -#define D6O_NISP_DOMAIN_NAME 30 /* RFC3898 */ -#define D6O_SNTP_SERVERS 31 /* RFC4075 */ -#define D6O_INFORMATION_REFRESH_TIME 32 /* RFC4242 */ -#define D6O_BCMCS_SERVER_D 33 /* RFC4280 */ -#define D6O_BCMCS_SERVER_A 34 /* RFC4280 */ -/* 35 is unassigned */ -#define D6O_GEOCONF_CIVIC 36 /* RFC4776 */ -#define D6O_REMOTE_ID 37 /* RFC4649 */ -#define D6O_SUBSCRIBER_ID 38 /* RFC4580 */ -#define D6O_CLIENT_FQDN 39 /* RFC4704 */ -#define D6O_PANA_AGENT 40 /* paa-option */ -#define D6O_NEW_POSIX_TIMEZONE 41 /* RFC4833 */ -#define D6O_NEW_TZDB_TIMEZONE 42 /* RFC4833 */ -#define D6O_ERO 43 /* RFC4994 */ -#define D6O_LQ_QUERY 44 /* RFC5007 */ -#define D6O_CLIENT_DATA 45 /* RFC5007 */ -#define D6O_CLT_TIME 46 /* RFC5007 */ -#define D6O_LQ_RELAY_DATA 47 /* RFC5007 */ -#define D6O_LQ_CLIENT_LINK 48 /* RFC5007 */ - -/* - * Status Codes, from RFC 3315 section 24.4, and RFC 3633, 5007. - */ -#define STATUS_Success 0 -#define STATUS_UnspecFail 1 -#define STATUS_NoAddrsAvail 2 -#define STATUS_NoBinding 3 -#define STATUS_NotOnLink 4 -#define STATUS_UseMulticast 5 -#define STATUS_NoPrefixAvail 6 -#define STATUS_UnknownQueryType 7 -#define STATUS_MalformedQuery 8 -#define STATUS_NotConfigured 9 -#define STATUS_NotAllowed 10 - -/* - * DHCPv6 message types, defined in section 5.3 of RFC 3315 - */ -#define DHCPV6_SOLICIT 1 -#define DHCPV6_ADVERTISE 2 -#define DHCPV6_REQUEST 3 -#define DHCPV6_CONFIRM 4 -#define DHCPV6_RENEW 5 -#define DHCPV6_REBIND 6 -#define DHCPV6_REPLY 7 -#define DHCPV6_RELEASE 8 -#define DHCPV6_DECLINE 9 -#define DHCPV6_RECONFIGURE 10 -#define DHCPV6_INFORMATION_REQUEST 11 -#define DHCPV6_RELAY_FORW 12 -#define DHCPV6_RELAY_REPL 13 -#define DHCPV6_LEASEQUERY 14 -#define DHCPV6_LEASEQUERY_REPLY 15 - -extern const char *dhcpv6_type_names[]; -extern const int dhcpv6_type_name_max; - -/* DUID type definitions (RFC3315 section 9). - */ -#define DUID_LLT 1 -#define DUID_EN 2 -#define DUID_LL 3 - -/* Offsets into IA_*'s where Option spaces commence. */ -#define IA_NA_OFFSET 12 /* IAID, T1, T2, all 4 octets each */ -#define IA_TA_OFFSET 4 /* IAID only, 4 octets */ -#define IA_PD_OFFSET 12 /* IAID, T1, T2, all 4 octets each */ - -/* Offset into IAADDR's where Option spaces commence. */ -#define IAADDR_OFFSET 24 - -/* Offset into IAPREFIX's where Option spaces commence. */ -#define IAPREFIX_OFFSET 25 - -/* Offset into LQ_QUERY's where Option spaces commence. */ -#define LQ_QUERY_OFFSET 17 - -/* - * DHCPv6 well-known multicast addressess, from section 5.1 of RFC 3315 - */ -#define ALL_DHCP_RELAY_AGENTS_AND_SERVERS "ff02::1:2" -#define ALL_DHCP_SERVERS "ff05::1:3" - -#define DHCP6_CLIENT_PORT 546 -#define DHCP6_SERVER_PORT 547 - -/* - * DHCPv6 Retransmission Constants (RFC3315 section 5.5, RFC 5007) - */ - -#define SOL_MAX_DELAY 1 -#define SOL_TIMEOUT 1 -#define SOL_MAX_RT 120 -#define REQ_TIMEOUT 1 -#define REQ_MAX_RT 30 -#define REQ_MAX_RC 10 -#define CNF_MAX_DELAY 1 -#define CNF_TIMEOUT 1 -#define CNF_MAX_RT 4 -#define CNF_MAX_RD 10 -#define REN_TIMEOUT 10 -#define REN_MAX_RT 600 -#define REB_TIMEOUT 10 -#define REB_MAX_RT 600 -#define INF_MAX_DELAY 1 -#define INF_TIMEOUT 1 -#define INF_MAX_RT 120 -#define REL_TIMEOUT 1 -#define REL_MAX_RC 5 -#define DEC_TIMEOUT 1 -#define DEC_MAX_RC 5 -#define REC_TIMEOUT 2 -#define REC_MAX_RC 8 -#define HOP_COUNT_LIMIT 32 -#define LQ6_TIMEOUT 1 -#define LQ6_MAX_RT 10 -#define LQ6_MAX_RC 5 - -/* Leasequery query-types (RFC 5007) */ - -#define LQ6QT_BY_ADDRESS 1 -#define LQ6QT_BY_CLIENTID 2 - -/* - * DUID time starts 2000-01-01. - * This constant is the number of seconds since 1970-01-01, - * when the Unix epoch began. - */ -#define DUID_TIME_EPOCH 946684800 - -/* Information-Request Time option (RFC 4242) */ - -#define IRT_DEFAULT 86400 -#define IRT_MINIMUM 600 - -#endif diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index 4d9244f865..dd5156455e 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -12,7 +12,7 @@ // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. -#include "dhcp6/pkt6.h" +#include "dhcp/pkt6.h" #include "dhcp6/iface_mgr.h" #include "dhcp6/dhcp6_srv.h" diff --git a/src/bin/dhcp6/iface_mgr.cc b/src/bin/dhcp6/iface_mgr.cc index 1e2551a76e..a08db2c1d8 100644 --- a/src/bin/dhcp6/iface_mgr.cc +++ b/src/bin/dhcp6/iface_mgr.cc @@ -18,8 +18,8 @@ #include #include +#include "dhcp/dhcp6.h" #include "dhcp6/iface_mgr.h" -#include "dhcp6/dhcp6.h" #include "exceptions/exceptions.h" using namespace std; diff --git a/src/bin/dhcp6/iface_mgr.h b/src/bin/dhcp6/iface_mgr.h index 39061dafc1..d4badac498 100644 --- a/src/bin/dhcp6/iface_mgr.h +++ b/src/bin/dhcp6/iface_mgr.h @@ -17,7 +17,7 @@ #include #include "io_address.h" -#include "dhcp6/pkt6.h" +#include "dhcp/pkt6.h" namespace isc { diff --git a/src/bin/dhcp6/tests/Makefile.am b/src/bin/dhcp6/tests/Makefile.am index ae9d8e3173..4ed870f2f5 100644 --- a/src/bin/dhcp6/tests/Makefile.am +++ b/src/bin/dhcp6/tests/Makefile.am @@ -45,11 +45,9 @@ if HAVE_GTEST TESTS += dhcp6_unittests -dhcp6_unittests_SOURCES = ../pkt6.h ../pkt6.cc -dhcp6_unittests_SOURCES += ../iface_mgr.h ../iface_mgr.cc +dhcp6_unittests_SOURCES = ../iface_mgr.h ../iface_mgr.cc dhcp6_unittests_SOURCES += ../dhcp6_srv.h ../dhcp6_srv.cc dhcp6_unittests_SOURCES += dhcp6_unittests.cc -dhcp6_unittests_SOURCES += pkt6_unittest.cc dhcp6_unittests_SOURCES += iface_mgr_unittest.cc dhcp6_unittests_SOURCES += dhcp6_srv_unittest.cc @@ -58,6 +56,7 @@ dhcp6_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS) dhcp6_unittests_LDADD = $(GTEST_LDADD) dhcp6_unittests_LDADD += $(SQLITE_LIBS) dhcp6_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la +dhcp6_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libdhcp.la dhcp6_unittests_LDADD += $(top_builddir)/src/lib/config/libcfgclient.la dhcp6_unittests_LDADD += $(top_builddir)/src/lib/cc/libcc.la dhcp6_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la diff --git a/src/bin/dhcp6/tests/iface_mgr_unittest.cc b/src/bin/dhcp6/tests/iface_mgr_unittest.cc index c9a9d724c0..589aeb0358 100644 --- a/src/bin/dhcp6/tests/iface_mgr_unittest.cc +++ b/src/bin/dhcp6/tests/iface_mgr_unittest.cc @@ -21,7 +21,7 @@ #include #include "io_address.h" -#include "dhcp6/pkt6.h" +#include "dhcp/pkt6.h" #include "dhcp6/iface_mgr.h" using namespace std; diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 04eee45f8d..c825e662af 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -1,3 +1,3 @@ -SUBDIRS = exceptions util log cryptolink dns cc config acl xfr bench \ - asiolink asiodns nsas cache resolve testutils datasrc \ - server_common python +SUBDIRS = exceptions util log cryptolink dns cc config python xfr \ + bench asiolink asiodns nsas cache resolve testutils datasrc \ + acl server_common dhcp diff --git a/src/lib/dhcp/Makefile.am b/src/lib/dhcp/Makefile.am new file mode 100644 index 0000000000..ba3241cda7 --- /dev/null +++ b/src/lib/dhcp/Makefile.am @@ -0,0 +1,32 @@ +SUBDIRS = . tests + +AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib +AM_CPPFLAGS += -I$(top_srcdir)/src/lib/asiolink +AM_CPPFLAGS += -I$(top_builddir)/src/lib/asiolink +AM_CPPFLAGS += $(BOOST_INCLUDES) + +CLEANFILES = *.gcno *.gcda + +lib_LTLIBRARIES = libdhcp.la +libdhcp_la_SOURCES = +libdhcp_la_SOURCES += libdhcp.cc libdhcp.h +libdhcp_la_SOURCES += dhcp6.h +libdhcp_la_SOURCES += pkt6.cc pkt6.h + +EXTRA_DIST = README +EXTRA_DIST += logimpl_messages.mes +EXTRA_DIST += log_messages.mes + +# Note: the ordering matters: -Wno-... must follow -Wextra (defined in +# B10_CXXFLAGS) +libdhcp_la_CXXFLAGS = $(AM_CXXFLAGS) +if USE_GXX +libdhcp_la_CXXFLAGS += -Wall +endif +if USE_CLANGPP +# Same for clang++, but we need to turn off -Werror completely. +libdhcp_la_CXXFLAGS += -Wall +endif +libdhcp_la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES) +libdhcp_la_LDFLAGS = $(LOG4CPLUS_LDFLAGS) +libdhcp_la_LIBADD = $(top_builddir)/src/lib/util/libutil.la diff --git a/src/lib/dhcp/README b/src/lib/dhcp/README new file mode 100644 index 0000000000..6c5353d003 --- /dev/null +++ b/src/lib/dhcp/README @@ -0,0 +1,11 @@ +This directory holds implementation for libdhcp. + + +Basic Ideas +=========== + + +Notes +===== +This work just begun. Don't expect to see much useful code here. +We are working on it. \ No newline at end of file diff --git a/src/lib/dhcp/dhcp6.h b/src/lib/dhcp/dhcp6.h new file mode 100644 index 0000000000..b3ee0bfd7b --- /dev/null +++ b/src/lib/dhcp/dhcp6.h @@ -0,0 +1,184 @@ +// Copyright (C) 2006-2011 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#ifndef DHCP6_H +#define DHCP6_H + +/* DHCPv6 Option codes: */ + +#define D6O_CLIENTID 1 /* RFC3315 */ +#define D6O_SERVERID 2 +#define D6O_IA_NA 3 +#define D6O_IA_TA 4 +#define D6O_IAADDR 5 +#define D6O_ORO 6 +#define D6O_PREFERENCE 7 +#define D6O_ELAPSED_TIME 8 +#define D6O_RELAY_MSG 9 +/* Option code 10 unassigned. */ +#define D6O_AUTH 11 +#define D6O_UNICAST 12 +#define D6O_STATUS_CODE 13 +#define D6O_RAPID_COMMIT 14 +#define D6O_USER_CLASS 15 +#define D6O_VENDOR_CLASS 16 +#define D6O_VENDOR_OPTS 17 +#define D6O_INTERFACE_ID 18 +#define D6O_RECONF_MSG 19 +#define D6O_RECONF_ACCEPT 20 +#define D6O_SIP_SERVERS_DNS 21 /* RFC3319 */ +#define D6O_SIP_SERVERS_ADDR 22 /* RFC3319 */ +#define D6O_NAME_SERVERS 23 /* RFC3646 */ +#define D6O_DOMAIN_SEARCH 24 /* RFC3646 */ +#define D6O_IA_PD 25 /* RFC3633 */ +#define D6O_IAPREFIX 26 /* RFC3633 */ +#define D6O_NIS_SERVERS 27 /* RFC3898 */ +#define D6O_NISP_SERVERS 28 /* RFC3898 */ +#define D6O_NIS_DOMAIN_NAME 29 /* RFC3898 */ +#define D6O_NISP_DOMAIN_NAME 30 /* RFC3898 */ +#define D6O_SNTP_SERVERS 31 /* RFC4075 */ +#define D6O_INFORMATION_REFRESH_TIME 32 /* RFC4242 */ +#define D6O_BCMCS_SERVER_D 33 /* RFC4280 */ +#define D6O_BCMCS_SERVER_A 34 /* RFC4280 */ +/* 35 is unassigned */ +#define D6O_GEOCONF_CIVIC 36 /* RFC4776 */ +#define D6O_REMOTE_ID 37 /* RFC4649 */ +#define D6O_SUBSCRIBER_ID 38 /* RFC4580 */ +#define D6O_CLIENT_FQDN 39 /* RFC4704 */ +#define D6O_PANA_AGENT 40 /* paa-option */ +#define D6O_NEW_POSIX_TIMEZONE 41 /* RFC4833 */ +#define D6O_NEW_TZDB_TIMEZONE 42 /* RFC4833 */ +#define D6O_ERO 43 /* RFC4994 */ +#define D6O_LQ_QUERY 44 /* RFC5007 */ +#define D6O_CLIENT_DATA 45 /* RFC5007 */ +#define D6O_CLT_TIME 46 /* RFC5007 */ +#define D6O_LQ_RELAY_DATA 47 /* RFC5007 */ +#define D6O_LQ_CLIENT_LINK 48 /* RFC5007 */ + +/* + * Status Codes, from RFC 3315 section 24.4, and RFC 3633, 5007. + */ +#define STATUS_Success 0 +#define STATUS_UnspecFail 1 +#define STATUS_NoAddrsAvail 2 +#define STATUS_NoBinding 3 +#define STATUS_NotOnLink 4 +#define STATUS_UseMulticast 5 +#define STATUS_NoPrefixAvail 6 +#define STATUS_UnknownQueryType 7 +#define STATUS_MalformedQuery 8 +#define STATUS_NotConfigured 9 +#define STATUS_NotAllowed 10 + +/* + * DHCPv6 message types, defined in section 5.3 of RFC 3315 + */ +#define DHCPV6_SOLICIT 1 +#define DHCPV6_ADVERTISE 2 +#define DHCPV6_REQUEST 3 +#define DHCPV6_CONFIRM 4 +#define DHCPV6_RENEW 5 +#define DHCPV6_REBIND 6 +#define DHCPV6_REPLY 7 +#define DHCPV6_RELEASE 8 +#define DHCPV6_DECLINE 9 +#define DHCPV6_RECONFIGURE 10 +#define DHCPV6_INFORMATION_REQUEST 11 +#define DHCPV6_RELAY_FORW 12 +#define DHCPV6_RELAY_REPL 13 +#define DHCPV6_LEASEQUERY 14 +#define DHCPV6_LEASEQUERY_REPLY 15 + +extern const char *dhcpv6_type_names[]; +extern const int dhcpv6_type_name_max; + +/* DUID type definitions (RFC3315 section 9). + */ +#define DUID_LLT 1 +#define DUID_EN 2 +#define DUID_LL 3 + +/* Offsets into IA_*'s where Option spaces commence. */ +#define IA_NA_OFFSET 12 /* IAID, T1, T2, all 4 octets each */ +#define IA_TA_OFFSET 4 /* IAID only, 4 octets */ +#define IA_PD_OFFSET 12 /* IAID, T1, T2, all 4 octets each */ + +/* Offset into IAADDR's where Option spaces commence. */ +#define IAADDR_OFFSET 24 + +/* Offset into IAPREFIX's where Option spaces commence. */ +#define IAPREFIX_OFFSET 25 + +/* Offset into LQ_QUERY's where Option spaces commence. */ +#define LQ_QUERY_OFFSET 17 + +/* + * DHCPv6 well-known multicast addressess, from section 5.1 of RFC 3315 + */ +#define ALL_DHCP_RELAY_AGENTS_AND_SERVERS "ff02::1:2" +#define ALL_DHCP_SERVERS "ff05::1:3" + +#define DHCP6_CLIENT_PORT 546 +#define DHCP6_SERVER_PORT 547 + +/* + * DHCPv6 Retransmission Constants (RFC3315 section 5.5, RFC 5007) + */ + +#define SOL_MAX_DELAY 1 +#define SOL_TIMEOUT 1 +#define SOL_MAX_RT 120 +#define REQ_TIMEOUT 1 +#define REQ_MAX_RT 30 +#define REQ_MAX_RC 10 +#define CNF_MAX_DELAY 1 +#define CNF_TIMEOUT 1 +#define CNF_MAX_RT 4 +#define CNF_MAX_RD 10 +#define REN_TIMEOUT 10 +#define REN_MAX_RT 600 +#define REB_TIMEOUT 10 +#define REB_MAX_RT 600 +#define INF_MAX_DELAY 1 +#define INF_TIMEOUT 1 +#define INF_MAX_RT 120 +#define REL_TIMEOUT 1 +#define REL_MAX_RC 5 +#define DEC_TIMEOUT 1 +#define DEC_MAX_RC 5 +#define REC_TIMEOUT 2 +#define REC_MAX_RC 8 +#define HOP_COUNT_LIMIT 32 +#define LQ6_TIMEOUT 1 +#define LQ6_MAX_RT 10 +#define LQ6_MAX_RC 5 + +/* Leasequery query-types (RFC 5007) */ + +#define LQ6QT_BY_ADDRESS 1 +#define LQ6QT_BY_CLIENTID 2 + +/* + * DUID time starts 2000-01-01. + * This constant is the number of seconds since 1970-01-01, + * when the Unix epoch began. + */ +#define DUID_TIME_EPOCH 946684800 + +/* Information-Request Time option (RFC 4242) */ + +#define IRT_DEFAULT 86400 +#define IRT_MINIMUM 600 + +#endif diff --git a/src/bin/dhcp6/pkt6.cc b/src/lib/dhcp/pkt6.cc similarity index 96% rename from src/bin/dhcp6/pkt6.cc rename to src/lib/dhcp/pkt6.cc index 5dcab86fe5..5f1fa85fca 100644 --- a/src/bin/dhcp6/pkt6.cc +++ b/src/lib/dhcp/pkt6.cc @@ -13,8 +13,8 @@ // PERFORMANCE OF THIS SOFTWARE. -#include "dhcp6/dhcp6.h" -#include "dhcp6/pkt6.h" +#include "dhcp/dhcp6.h" +#include "dhcp/pkt6.h" #include namespace isc { diff --git a/src/bin/dhcp6/pkt6.h b/src/lib/dhcp/pkt6.h similarity index 100% rename from src/bin/dhcp6/pkt6.h rename to src/lib/dhcp/pkt6.h diff --git a/src/lib/dhcp/tests/Makefile.am b/src/lib/dhcp/tests/Makefile.am new file mode 100644 index 0000000000..65a6694681 --- /dev/null +++ b/src/lib/dhcp/tests/Makefile.am @@ -0,0 +1,40 @@ +SUBDIRS = . + +AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib +AM_CPPFLAGS += -I$(top_srcdir)/src/lib/asiolink +AM_CPPFLAGS += -I$(top_builddir)/src/lib/asiolink +AM_CPPFLAGS += $(BOOST_INCLUDES) +AM_CXXFLAGS = $(B10_CXXFLAGS) + +if USE_STATIC_LINK +AM_LDFLAGS = -static +endif + +CLEANFILES = *.gcno *.gcda + +TESTS = +if HAVE_GTEST +TESTS += libdhcp_unittests +libdhcp_unittests_SOURCES = run_unittests.cc +libdhcp_unittests_SOURCES += ../libdhcp.h ../libdhcp.cc libdhcp_unittest.cc +libdhcp_unittests_SOURCES += ../pkt6.h ../pkt6.cc pkt6_unittest.cc + +libdhcp_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(LOG4CPLUS_INCLUDES) +libdhcp_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS) + +libdhcp_unittests_CXXFLAGS = $(AM_CXXFLAGS) +if USE_CLANGPP +# This is to workaround unused variables tcout and tcerr in +# log4cplus's streams.h. +libdhcp_unittests_CXXFLAGS += -Wno-unused-variable +endif +libdhcp_unittests_LDADD = $(GTEST_LDADD) +libdhcp_unittests_LDADD += $(top_builddir)/src/lib/log/liblog.la +libdhcp_unittests_LDADD += $(top_builddir)/src/lib/util/unittests/libutil_unittests.la +libdhcp_unittests_LDADD += $(top_builddir)/src/lib/util/libutil.la +libdhcp_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la +libdhcp_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la +libdhcp_unittests_LDADD += $(top_builddir)/src/lib/util/unittests/libutil_unittests.la +endif + +noinst_PROGRAMS = $(TESTS) diff --git a/src/lib/dhcp/tests/libdhcp_unittest.cc b/src/lib/dhcp/tests/libdhcp_unittest.cc new file mode 100644 index 0000000000..9a2151ce7b --- /dev/null +++ b/src/lib/dhcp/tests/libdhcp_unittest.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include +#include +#include + +#include +#include + +#include "dhcp/libdhcp.h" + +using namespace std; +using namespace isc; +using namespace isc::dhcp; + +namespace { +class LibDhcpTest : public ::testing::Test { +public: + LibDhcpTest() { + } +}; + +TEST_F(LibDhcpTest, basic) { + // dummy test + + // an attempt to bind this socket will fail. + EXPECT_EQ(LibDHCP::version(), "0"); +} + +} diff --git a/src/bin/dhcp6/tests/pkt6_unittest.cc b/src/lib/dhcp/tests/pkt6_unittest.cc similarity index 98% rename from src/bin/dhcp6/tests/pkt6_unittest.cc rename to src/lib/dhcp/tests/pkt6_unittest.cc index 5054c45f67..9bf31f7318 100644 --- a/src/bin/dhcp6/tests/pkt6_unittest.cc +++ b/src/lib/dhcp/tests/pkt6_unittest.cc @@ -20,7 +20,7 @@ #include -#include "dhcp6/pkt6.h" +#include "dhcp/pkt6.h" using namespace std; using namespace isc;