Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Kea
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
426
Issues
426
List
Boards
Labels
Service Desk
Milestones
Merge Requests
64
Merge Requests
64
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
ISC Open Source Projects
Kea
Commits
8f2a1f8a
Commit
8f2a1f8a
authored
Dec 10, 2015
by
Marcin Siodelski
Browse files
Options
Browse Files
Download
Plain Diff
[master] Merge branch 'trac4106'
parents
ed7edadc
96a612f4
Changes
27
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
1897 additions
and
15 deletions
+1897
-15
src/bin/dhcp4/Makefile.am
src/bin/dhcp4/Makefile.am
+1
-0
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp4/ctrl_dhcp4_srv.cc
+11
-0
src/bin/dhcp4/dhcp4_dhcp4o6_ipc.cc
src/bin/dhcp4/dhcp4_dhcp4o6_ipc.cc
+89
-0
src/bin/dhcp4/dhcp4_dhcp4o6_ipc.h
src/bin/dhcp4/dhcp4_dhcp4o6_ipc.h
+74
-0
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp4/json_config_parser.cc
+13
-2
src/bin/dhcp4/tests/Makefile.am
src/bin/dhcp4/tests/Makefile.am
+1
-0
src/bin/dhcp4/tests/dhcp4_dhcp4o6_ipc_unittest.cc
src/bin/dhcp4/tests/dhcp4_dhcp4o6_ipc_unittest.cc
+173
-0
src/bin/dhcp6/Makefile.am
src/bin/dhcp6/Makefile.am
+1
-0
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
+11
-0
src/bin/dhcp6/dhcp6_dhcp4o6_ipc.cc
src/bin/dhcp6/dhcp6_dhcp4o6_ipc.cc
+79
-0
src/bin/dhcp6/dhcp6_dhcp4o6_ipc.h
src/bin/dhcp6/dhcp6_dhcp4o6_ipc.h
+61
-0
src/bin/dhcp6/dhcp6_srv.cc
src/bin/dhcp6/dhcp6_srv.cc
+8
-0
src/bin/dhcp6/json_config_parser.cc
src/bin/dhcp6/json_config_parser.cc
+12
-1
src/bin/dhcp6/tests/Makefile.am
src/bin/dhcp6/tests/Makefile.am
+1
-1
src/bin/dhcp6/tests/dhcp6_dhcp4o6_ipc_unittest.cc
src/bin/dhcp6/tests/dhcp6_dhcp4o6_ipc_unittest.cc
+130
-0
src/lib/dhcp/tests/pkt_filter6_test_stub.cc
src/lib/dhcp/tests/pkt_filter6_test_stub.cc
+64
-3
src/lib/dhcp/tests/pkt_filter6_test_stub.h
src/lib/dhcp/tests/pkt_filter6_test_stub.h
+11
-6
src/lib/dhcpsrv/Makefile.am
src/lib/dhcpsrv/Makefile.am
+1
-0
src/lib/dhcpsrv/dhcp4o6_ipc.cc
src/lib/dhcpsrv/dhcp4o6_ipc.cc
+266
-0
src/lib/dhcpsrv/dhcp4o6_ipc.h
src/lib/dhcpsrv/dhcp4o6_ipc.h
+134
-0
src/lib/dhcpsrv/srv_config.cc
src/lib/dhcpsrv/srv_config.cc
+2
-2
src/lib/dhcpsrv/srv_config.h
src/lib/dhcpsrv/srv_config.h
+24
-0
src/lib/dhcpsrv/tests/Makefile.am
src/lib/dhcpsrv/tests/Makefile.am
+1
-0
src/lib/dhcpsrv/tests/dhcp4o6_ipc_unittest.cc
src/lib/dhcpsrv/tests/dhcp4o6_ipc_unittest.cc
+577
-0
src/lib/dhcpsrv/testutils/Makefile.am
src/lib/dhcpsrv/testutils/Makefile.am
+2
-0
src/lib/dhcpsrv/testutils/dhcp4o6_test_ipc.cc
src/lib/dhcpsrv/testutils/dhcp4o6_test_ipc.cc
+50
-0
src/lib/dhcpsrv/testutils/dhcp4o6_test_ipc.h
src/lib/dhcpsrv/testutils/dhcp4o6_test_ipc.h
+100
-0
No files found.
src/bin/dhcp4/Makefile.am
View file @
8f2a1f8a
...
@@ -62,6 +62,7 @@ libdhcp4_la_SOURCES += ctrl_dhcp4_srv.cc ctrl_dhcp4_srv.h
...
@@ -62,6 +62,7 @@ libdhcp4_la_SOURCES += ctrl_dhcp4_srv.cc ctrl_dhcp4_srv.h
libdhcp4_la_SOURCES
+=
json_config_parser.cc json_config_parser.h
libdhcp4_la_SOURCES
+=
json_config_parser.cc json_config_parser.h
libdhcp4_la_SOURCES
+=
dhcp4_log.cc dhcp4_log.h
libdhcp4_la_SOURCES
+=
dhcp4_log.cc dhcp4_log.h
libdhcp4_la_SOURCES
+=
dhcp4_srv.cc dhcp4_srv.h
libdhcp4_la_SOURCES
+=
dhcp4_srv.cc dhcp4_srv.h
libdhcp4_la_SOURCES
+=
dhcp4_dhcp4o6_ipc.cc dhcp4_dhcp4o6_ipc.h
libdhcp4_la_SOURCES
+=
kea_controller.cc
libdhcp4_la_SOURCES
+=
kea_controller.cc
...
...
src/bin/dhcp4/ctrl_dhcp4_srv.cc
View file @
8f2a1f8a
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
#include <cc/data.h>
#include <cc/data.h>
#include <dhcp4/ctrl_dhcp4_srv.h>
#include <dhcp4/ctrl_dhcp4_srv.h>
#include <dhcp4/dhcp4_log.h>
#include <dhcp4/dhcp4_log.h>
#include <dhcp4/dhcp4_dhcp4o6_ipc.h>
#include <hooks/hooks_manager.h>
#include <hooks/hooks_manager.h>
#include <dhcp4/json_config_parser.h>
#include <dhcp4/json_config_parser.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/cfgmgr.h>
...
@@ -185,6 +186,16 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
...
@@ -185,6 +186,16 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
return
(
isc
::
config
::
createAnswer
(
1
,
err
.
str
()));
return
(
isc
::
config
::
createAnswer
(
1
,
err
.
str
()));
}
}
// Setup DHCPv4-over-DHCPv6 IPC
try
{
Dhcp4to6Ipc
::
instance
().
open
();
}
catch
(
const
std
::
exception
&
ex
)
{
std
::
ostringstream
err
;
err
<<
"error starting DHCPv4-over-DHCPv6 IPC "
" after server reconfiguration: "
<<
ex
.
what
();
return
(
isc
::
config
::
createAnswer
(
1
,
err
.
str
()));
}
// Configuration may change active interfaces. Therefore, we have to reopen
// Configuration may change active interfaces. Therefore, we have to reopen
// sockets according to new configuration. It is possible that this
// sockets according to new configuration. It is possible that this
// operation will fail for some interfaces but the openSockets function
// operation will fail for some interfaces but the openSockets function
...
...
src/bin/dhcp4/dhcp4_dhcp4o6_ipc.cc
0 → 100644
View file @
8f2a1f8a
// Copyright (C) 2015 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 <config.h>
#include <util/buffer.h>
#include <dhcp/iface_mgr.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcp4/dhcp4_dhcp4o6_ipc.h>
using
namespace
std
;
namespace
isc
{
namespace
dhcp
{
Dhcp4to6Ipc
::
Dhcp4to6Ipc
()
:
Dhcp4o6IpcBase
()
{
}
Dhcp4to6Ipc
&
Dhcp4to6Ipc
::
instance
()
{
static
Dhcp4to6Ipc
dhcp4to6_ipc
;
return
(
dhcp4to6_ipc
);
}
void
Dhcp4to6Ipc
::
open
()
{
uint32_t
port
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getDhcp4o6Port
();
if
(
port
==
0
)
{
Dhcp4o6IpcBase
::
close
();
return
;
}
int
old_fd
=
socket_fd_
;
socket_fd_
=
Dhcp4o6IpcBase
::
open
(
static_cast
<
uint16_t
>
(
port
),
ENDPOINT_TYPE_V4
);
if
((
old_fd
==
-
1
)
&&
(
socket_fd_
!=
old_fd
))
{
IfaceMgr
::
instance
().
addExternalSocket
(
socket_fd_
,
Dhcp4to6Ipc
::
handler
);
}
}
void
Dhcp4to6Ipc
::
handler
()
{
Dhcp4to6Ipc
&
ipc
=
Dhcp4to6Ipc
::
instance
();
// Reset received message in case we return from this method before the
// received message pointer is updated.
ipc
.
received_
.
reset
();
// Receive message from the IPC socket.
Pkt6Ptr
pkt
=
ipc
.
receive
();
if
(
!
pkt
)
{
return
;
}
// Each message must contain option holding DHCPv4 message.
OptionCollection
msgs
=
pkt
->
getOptions
(
D6O_DHCPV4_MSG
);
if
(
msgs
.
empty
())
{
isc_throw
(
Dhcp4o6IpcError
,
"DHCPv4 message option not present in the"
" DHCPv4o6 message received by the DHCPv4 server"
);
}
else
if
(
msgs
.
size
()
>
1
)
{
isc_throw
(
Dhcp4o6IpcError
,
"expected exactly one DHCPv4 message within"
" DHCPv4 message option received by the DHCPv4 server"
);
}
OptionPtr
msg
=
msgs
.
begin
()
->
second
;
if
(
!
msg
)
{
isc_throw
(
Dhcp4o6IpcError
,
"null DHCPv4 message option in the"
" DHCPv4o6 message received by the DHCPv4 server"
);
}
// Record this message.
ipc
.
received_
.
reset
(
new
Pkt4o6
(
msg
->
getData
(),
pkt
));
}
Pkt4o6Ptr
&
Dhcp4to6Ipc
::
getReceived
()
{
return
(
received_
);
}
};
// namespace dhcp
};
// namespace isc
src/bin/dhcp4/dhcp4_dhcp4o6_ipc.h
0 → 100644
View file @
8f2a1f8a
// Copyright (C) 2015 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 DHCP4_DHCP4O6_IPC_H
#define DHCP4_DHCP4O6_IPC_H
/// @file dhcp4_dhcp4o6_ipc.h Defines the Dhcp4o6Ipc class.
/// This file defines the class Kea uses to act as the DHCPv4 server
/// side of DHCPv4-over-DHCPv6 communication between servers.
///
#include <dhcp/pkt4o6.h>
#include <dhcpsrv/dhcp4o6_ipc.h>
#include <boost/shared_ptr.hpp>
namespace
isc
{
namespace
dhcp
{
/// @brief Handles DHCPv4-over-DHCPv6 IPC on the DHCPv4 server side
class
Dhcp4to6Ipc
:
public
Dhcp4o6IpcBase
{
protected:
/// @brief Constructor
///
/// Default constructor
Dhcp4to6Ipc
();
/// @brief Destructor.
virtual
~
Dhcp4to6Ipc
()
{
}
public:
/// @brief Returns pointer to the sole instance of Dhcp4o6Ipc
///
/// Dhcp4to6Ipc is a singleton class
///
/// @return the only existing instance of DHCP4o6 IPC
static
Dhcp4to6Ipc
&
instance
();
/// @brief Open communication socket
///
/// Call base open method and sets the handler/callback when needed
virtual
void
open
();
/// @brief On receive handler
///
/// The handler processes the DHCPv4-query DHCPv6 packet and
/// sends the DHCPv4-response DHCPv6 packet back to the DHCPv6 server
static
void
handler
();
/// @brief Returns last received packet
///
/// @return a reference to a shared pointer to the last received packet
/// @note This reference should be cleared after use
Pkt4o6Ptr
&
getReceived
();
private:
/// @brief last received packet
Pkt4o6Ptr
received_
;
};
}
// namespace isc
}
// namespace dhcp
#endif
src/bin/dhcp4/json_config_parser.cc
View file @
8f2a1f8a
...
@@ -422,9 +422,10 @@ DhcpConfigParser* createGlobalDhcp4ConfigParser(const std::string& config_id,
...
@@ -422,9 +422,10 @@ DhcpConfigParser* createGlobalDhcp4ConfigParser(const std::string& config_id,
if
((
config_id
.
compare
(
"valid-lifetime"
)
==
0
)
||
if
((
config_id
.
compare
(
"valid-lifetime"
)
==
0
)
||
(
config_id
.
compare
(
"renew-timer"
)
==
0
)
||
(
config_id
.
compare
(
"renew-timer"
)
==
0
)
||
(
config_id
.
compare
(
"rebind-timer"
)
==
0
)
||
(
config_id
.
compare
(
"rebind-timer"
)
==
0
)
||
(
config_id
.
compare
(
"decline-probation-period"
)
==
0
)
)
{
(
config_id
.
compare
(
"decline-probation-period"
)
==
0
)
||
(
config_id
.
compare
(
"dhcp4o6-port"
)
==
0
)
)
{
parser
=
new
Uint32Parser
(
config_id
,
parser
=
new
Uint32Parser
(
config_id
,
globalContext
()
->
uint32_values_
);
globalContext
()
->
uint32_values_
);
}
else
if
(
config_id
.
compare
(
"interfaces-config"
)
==
0
)
{
}
else
if
(
config_id
.
compare
(
"interfaces-config"
)
==
0
)
{
parser
=
new
IfacesConfigParser4
();
parser
=
new
IfacesConfigParser4
();
}
else
if
(
config_id
.
compare
(
"subnet4"
)
==
0
)
{
}
else
if
(
config_id
.
compare
(
"subnet4"
)
==
0
)
{
...
@@ -472,6 +473,7 @@ DhcpConfigParser* createGlobalDhcp4ConfigParser(const std::string& config_id,
...
@@ -472,6 +473,7 @@ DhcpConfigParser* createGlobalDhcp4ConfigParser(const std::string& config_id,
///
///
/// - echo-client-id
/// - echo-client-id
/// - decline-probation-period
/// - decline-probation-period
/// - dhcp4o6-port
void
setGlobalParameters4
()
{
void
setGlobalParameters4
()
{
// Although the function is modest for now, it is certain that the number
// Although the function is modest for now, it is certain that the number
// of global switches will increase over time, hence the name.
// of global switches will increase over time, hence the name.
...
@@ -494,6 +496,15 @@ void setGlobalParameters4() {
...
@@ -494,6 +496,15 @@ void setGlobalParameters4() {
}
catch
(...)
{
}
catch
(...)
{
// That's not really needed.
// That's not really needed.
}
}
// Set the DHCPv4-over-DHCPv6 interserver port.
try
{
uint32_t
dhcp4o6_port
=
globalContext
()
->
uint32_values_
->
getOptionalParam
(
"dhcp4o6-port"
,
0
);
CfgMgr
::
instance
().
getStagingCfg
()
->
setDhcp4o6Port
(
dhcp4o6_port
);
}
catch
(...)
{
// Ignore errors. This flag is optional
}
}
}
isc
::
data
::
ConstElementPtr
isc
::
data
::
ConstElementPtr
...
...
src/bin/dhcp4/tests/Makefile.am
View file @
8f2a1f8a
...
@@ -92,6 +92,7 @@ dhcp4_unittests_SOURCES += release_unittest.cc
...
@@ -92,6 +92,7 @@ dhcp4_unittests_SOURCES += release_unittest.cc
dhcp4_unittests_SOURCES
+=
out_of_range_unittest.cc
dhcp4_unittests_SOURCES
+=
out_of_range_unittest.cc
dhcp4_unittests_SOURCES
+=
decline_unittest.cc
dhcp4_unittests_SOURCES
+=
decline_unittest.cc
dhcp4_unittests_SOURCES
+=
kea_controller_unittest.cc
dhcp4_unittests_SOURCES
+=
kea_controller_unittest.cc
dhcp4_unittests_SOURCES
+=
dhcp4_dhcp4o6_ipc_unittest.cc
nodist_dhcp4_unittests_SOURCES
=
marker_file.h test_libraries.h
nodist_dhcp4_unittests_SOURCES
=
marker_file.h test_libraries.h
...
...
src/bin/dhcp4/tests/dhcp4_dhcp4o6_ipc_unittest.cc
0 → 100644
View file @
8f2a1f8a
// Copyright (C) 2015 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 <config.h>
#include <asiolink/io_address.h>
#include <dhcp/pkt4o6.h>
#include <dhcp/pkt6.h>
#include <dhcp/tests/iface_mgr_test_config.h>
#include <dhcp4/dhcp4_dhcp4o6_ipc.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/testutils/dhcp4o6_test_ipc.h>
#include <gtest/gtest.h>
#include <stdint.h>
using
namespace
isc
;
using
namespace
isc
::
asiolink
;
using
namespace
isc
::
dhcp
;
using
namespace
isc
::
dhcp
::
test
;
using
namespace
isc
::
util
;
namespace
{
/// @brief Port number used in tests.
const
uint16_t
TEST_PORT
=
32000
;
/// @brief Define short name for the test IPC.
typedef
Dhcp4o6TestIpc
TestIpc
;
/// @brief Test fixture class for DHCPv4 endpoint of DHCPv4o6 IPC.
class
Dhcp4to6IpcTest
:
public
::
testing
::
Test
{
public:
/// @brief Constructor
///
/// Configures IPC to use a test port. It also provides a fake
/// configuration of interfaces.
Dhcp4to6IpcTest
()
:
iface_mgr_test_config_
(
true
)
{
configurePort
(
TEST_PORT
);
}
/// @brief Configure DHCP4o6 port.
///
/// @param port New port.
void
configurePort
(
const
uint16_t
port
);
/// @brief Creates an instance of the DHCPv4o6 Message option.
///
/// @return Pointer to the instance of the DHCPv4-query Message option.
OptionPtr
createDHCPv4MsgOption
()
const
;
private:
/// @brief Provides fake configuration of interfaces.
IfaceMgrTestConfig
iface_mgr_test_config_
;
};
void
Dhcp4to6IpcTest
::
configurePort
(
const
uint16_t
port
)
{
CfgMgr
::
instance
().
getStagingCfg
()
->
setDhcp4o6Port
(
port
);
}
OptionPtr
Dhcp4to6IpcTest
::
createDHCPv4MsgOption
()
const
{
// Create the DHCPv4 message.
Pkt4Ptr
pkt
(
new
Pkt4
(
DHCPREQUEST
,
1234
));
// Make a wire representation of the DHCPv4 message.
pkt
->
pack
();
OutputBuffer
&
output_buffer
=
pkt
->
getBuffer
();
const
uint8_t
*
data
=
static_cast
<
const
uint8_t
*>
(
output_buffer
.
getData
());
OptionBuffer
option_buffer
(
data
,
data
+
output_buffer
.
getLength
());
// Create the DHCPv4 Message option holding the created message.
OptionPtr
opt_msg
(
new
Option
(
Option
::
V6
,
D6O_DHCPV4_MSG
,
option_buffer
));
return
(
opt_msg
);
}
// This test verifies that the DHCPv4 endpoint of the DHCPv4o6 IPC can
// receive messages.
TEST_F
(
Dhcp4to6IpcTest
,
receive
)
{
// Create instance of the IPC endpoint under test.
Dhcp4to6Ipc
&
ipc
=
Dhcp4to6Ipc
::
instance
();
// Create instance of the IPC endpoint being used as a source of messages.
TestIpc
src_ipc
(
TEST_PORT
,
TestIpc
::
ENDPOINT_TYPE_V6
);
// Open both endpoints.
ASSERT_NO_THROW
(
ipc
.
open
());
ASSERT_NO_THROW
(
src_ipc
.
open
());
// Create message to be sent over IPC.
Pkt6Ptr
pkt
(
new
Pkt6
(
DHCPV6_DHCPV4_QUERY
,
1234
));
pkt
->
addOption
(
createDHCPv4MsgOption
());
pkt
->
setIface
(
"eth0"
);
pkt
->
setRemoteAddr
(
IOAddress
(
"2001:db8:1::123"
));
ASSERT_NO_THROW
(
pkt
->
pack
());
// Send and wait up to 1 second to receive it.
ASSERT_NO_THROW
(
src_ipc
.
send
(
pkt
));
ASSERT_NO_THROW
(
IfaceMgr
::
instance
().
receive6
(
1
,
0
));
// Make sure that the message has been received.
Pkt4o6Ptr
pkt_received
=
ipc
.
getReceived
();
ASSERT_TRUE
(
pkt_received
);
Pkt6Ptr
pkt6_received
=
pkt_received
->
getPkt6
();
ASSERT_TRUE
(
pkt6_received
);
EXPECT_EQ
(
"eth0"
,
pkt6_received
->
getIface
());
EXPECT_EQ
(
"2001:db8:1::123"
,
pkt6_received
->
getRemoteAddr
().
toText
());
}
// This test verifies that message with multiple DHCPv4 query options
// is rejected.
TEST_F
(
Dhcp4to6IpcTest
,
receiveMultipleQueries
)
{
// Create instance of the IPC endpoint under test.
Dhcp4to6Ipc
&
ipc
=
Dhcp4to6Ipc
::
instance
();
// Create instance of the IPC endpoint being used as a source of messages.
TestIpc
src_ipc
(
TEST_PORT
,
TestIpc
::
ENDPOINT_TYPE_V6
);
// Open both endpoints.
ASSERT_NO_THROW
(
ipc
.
open
());
ASSERT_NO_THROW
(
src_ipc
.
open
());
// Create message to be sent over IPC.
Pkt6Ptr
pkt
(
new
Pkt6
(
DHCPV6_DHCPV4_QUERY
,
1234
));
// Add two DHCPv4 query options.
pkt
->
addOption
(
createDHCPv4MsgOption
());
pkt
->
addOption
(
createDHCPv4MsgOption
());
pkt
->
setIface
(
"eth0"
);
pkt
->
setRemoteAddr
(
IOAddress
(
"2001:db8:1::123"
));
ASSERT_NO_THROW
(
pkt
->
pack
());
// Send message.
ASSERT_NO_THROW
(
src_ipc
.
send
(
pkt
));
// Reception handler should throw exception.
EXPECT_THROW
(
IfaceMgr
::
instance
().
receive6
(
1
,
0
),
Dhcp4o6IpcError
);
}
// This test verifies that message with no DHCPv4 query options is rejected.
TEST_F
(
Dhcp4to6IpcTest
,
receiveNoQueries
)
{
// Create instance of the IPC endpoint under test.
Dhcp4to6Ipc
&
ipc
=
Dhcp4to6Ipc
::
instance
();
// Create instance of the IPC endpoint being used as a source of messages.
TestIpc
src_ipc
(
TEST_PORT
,
TestIpc
::
ENDPOINT_TYPE_V6
);
// Open both endpoints.
ASSERT_NO_THROW
(
ipc
.
open
());
ASSERT_NO_THROW
(
src_ipc
.
open
());
// Create message to be sent over IPC without DHCPv4 query option.
Pkt6Ptr
pkt
(
new
Pkt6
(
DHCPV6_DHCPV4_QUERY
,
1234
));
pkt
->
setIface
(
"eth0"
);
pkt
->
setRemoteAddr
(
IOAddress
(
"2001:db8:1::123"
));
ASSERT_NO_THROW
(
pkt
->
pack
());
// Send message.
ASSERT_NO_THROW
(
src_ipc
.
send
(
pkt
));
// Reception handler should throw exception.
EXPECT_THROW
(
IfaceMgr
::
instance
().
receive6
(
1
,
0
),
Dhcp4o6IpcError
);
}
}
// end of anonymous namespace
src/bin/dhcp6/Makefile.am
View file @
8f2a1f8a
...
@@ -63,6 +63,7 @@ libdhcp6_la_SOURCES += dhcp6_log.cc dhcp6_log.h
...
@@ -63,6 +63,7 @@ libdhcp6_la_SOURCES += dhcp6_log.cc dhcp6_log.h
libdhcp6_la_SOURCES
+=
dhcp6_srv.cc dhcp6_srv.h
libdhcp6_la_SOURCES
+=
dhcp6_srv.cc dhcp6_srv.h
libdhcp6_la_SOURCES
+=
ctrl_dhcp6_srv.cc ctrl_dhcp6_srv.h
libdhcp6_la_SOURCES
+=
ctrl_dhcp6_srv.cc ctrl_dhcp6_srv.h
libdhcp6_la_SOURCES
+=
json_config_parser.cc json_config_parser.h
libdhcp6_la_SOURCES
+=
json_config_parser.cc json_config_parser.h
libdhcp6_la_SOURCES
+=
dhcp6_dhcp4o6_ipc.cc dhcp6_dhcp4o6_ipc.h
libdhcp6_la_SOURCES
+=
kea_controller.cc
libdhcp6_la_SOURCES
+=
kea_controller.cc
...
...
src/bin/dhcp6/ctrl_dhcp6_srv.cc
View file @
8f2a1f8a
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#include <dhcp/libdhcp++.h>
#include <dhcp/libdhcp++.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcp6/ctrl_dhcp6_srv.h>
#include <dhcp6/ctrl_dhcp6_srv.h>
#include <dhcp6/dhcp6_dhcp4o6_ipc.h>
#include <dhcp6/dhcp6_log.h>
#include <dhcp6/dhcp6_log.h>
#include <dhcp6/json_config_parser.h>
#include <dhcp6/json_config_parser.h>
#include <hooks/hooks_manager.h>
#include <hooks/hooks_manager.h>
...
@@ -209,6 +210,16 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
...
@@ -209,6 +210,16 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
return
(
isc
::
config
::
createAnswer
(
1
,
err
.
str
()));
return
(
isc
::
config
::
createAnswer
(
1
,
err
.
str
()));
}
}
// Setup DHCPv4-over-DHCPv6 IPC
try
{
Dhcp6to4Ipc
::
instance
().
open
();
}
catch
(
const
std
::
exception
&
ex
)
{
std
::
ostringstream
err
;
err
<<
"error starting DHCPv4-over-DHCPv6 IPC "
" after server reconfiguration: "
<<
ex
.
what
();
return
(
isc
::
config
::
createAnswer
(
1
,
err
.
str
()));
}
// Configuration may change active interfaces. Therefore, we have to reopen
// Configuration may change active interfaces. Therefore, we have to reopen
// sockets according to new configuration. It is possible that this
// sockets according to new configuration. It is possible that this
// operation will fail for some interfaces but the openSockets function
// operation will fail for some interfaces but the openSockets function
...
...
src/bin/dhcp6/dhcp6_dhcp4o6_ipc.cc
0 → 100644
View file @
8f2a1f8a
// Copyright (C) 2015 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 <config.h>
#include <util/buffer.h>
#include <dhcp/iface_mgr.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcp6/dhcp6_dhcp4o6_ipc.h>
using
namespace
std
;
namespace
isc
{
namespace
dhcp
{
Dhcp6to4Ipc
::
Dhcp6to4Ipc
()
:
Dhcp4o6IpcBase
()
{}
Dhcp6to4Ipc
&
Dhcp6to4Ipc
::
instance
()
{
static
Dhcp6to4Ipc
dhcp6to4_ipc
;
return
(
dhcp6to4_ipc
);
}
void
Dhcp6to4Ipc
::
open
()
{
uint32_t
port
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getDhcp4o6Port
();
if
(
port
==
0
)
{
Dhcp4o6IpcBase
::
close
();
return
;
}
int
old_fd
=
socket_fd_
;
socket_fd_
=
Dhcp4o6IpcBase
::
open
(
static_cast
<
uint16_t
>
(
port
),
ENDPOINT_TYPE_V6
);
if
((
old_fd
==
-
1
)
&&
(
socket_fd_
!=
old_fd
))
{
IfaceMgr
::
instance
().
addExternalSocket
(
socket_fd_
,
Dhcp6to4Ipc
::
handler
);
}
}
void
Dhcp6to4Ipc
::
handler
()
{
Dhcp6to4Ipc
&
ipc
=
Dhcp6to4Ipc
::
instance
();
// Receive message from IPC.
Pkt6Ptr
pkt
=
ipc
.
receive
();
if
(
!
pkt
)
{
return
;
}
// The received message has been unpacked by the receive() function. This
// method could have modified the message so it's better to pack() it
// again because we'll be forwarding it to a client.
isc
::
util
::
OutputBuffer
&
buf
=
pkt
->
getBuffer
();
buf
.
clear
();
pkt
->
pack
();
uint8_t
msg_type
=
pkt
->
getType
();
if
((
msg_type
==
DHCPV6_RELAY_FORW
)
||
(
msg_type
==
DHCPV6_RELAY_REPL
))
{
pkt
->
setRemotePort
(
DHCP6_SERVER_PORT
);
}
else
{
pkt
->
setRemotePort
(
DHCP6_CLIENT_PORT
);
}
// Forward packet to the client.
IfaceMgr
::
instance
().
send
(
pkt
);
// processStatsSent(pkt);
}
};
// namespace dhcp
};
// namespace isc
src/bin/dhcp6/dhcp6_dhcp4o6_ipc.h
0 → 100644
View file @
8f2a1f8a
// Copyright (C) 2015 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_DHCP4O6_IPC_H
#define DHCP6_DHCP4O6_IPC_H
/// @file dhcp6_dhcp4o6_ipc.h Defines the Dhcp4o6Ipc class.
/// This file defines the class Kea uses to act as the DHCPv6 server
/// side of DHCPv4-over-DHCPv6 communication between servers.
///
#include <dhcpsrv/dhcp4o6_ipc.h>
#include <boost/shared_ptr.hpp>
namespace
isc
{
namespace
dhcp
{
/// @brief Handles DHCPv4-over-DHCPv6 IPC on the DHCPv6 server side
class
Dhcp6to4Ipc
:
public
Dhcp4o6IpcBase
{
protected:
/// @brief Constructor
///
/// Default constructor
Dhcp6to4Ipc
();
/// @brief Destructor.
virtual
~
Dhcp6to4Ipc
()
{
}
public:
/// @brief Returns pointer to the sole instance of Dhcp4o6Ipc
///
/// Dhcp4o6Ipc is a singleton class
///
/// @return the only existing instance of DHCP4o6 IPC
static
Dhcp6to4Ipc
&
instance
();
/// @brief Open communication socket
///
/// Call base open method and sets the handler/callback when needed
virtual
void
open
();
/// @brief On receive handler
///
/// The handler sends the DHCPv6 packet back to the remote address
static
void
handler
();
};