Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Sebastian Schrader
Kea
Commits
f8a23579
Commit
f8a23579
authored
May 11, 2018
by
Francis Dupont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[5617] Moved selector init to library
parent
593ddeae
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
102 additions
and
67 deletions
+102
-67
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp4/dhcp4_srv.cc
+1
-42
src/bin/dhcp6/dhcp6_srv.cc
src/bin/dhcp6/dhcp6_srv.cc
+1
-21
src/lib/dhcpsrv/cfg_subnets4.cc
src/lib/dhcpsrv/cfg_subnets4.cc
+50
-1
src/lib/dhcpsrv/cfg_subnets4.h
src/lib/dhcpsrv/cfg_subnets4.h
+10
-1
src/lib/dhcpsrv/cfg_subnets6.cc
src/lib/dhcpsrv/cfg_subnets6.cc
+30
-1
src/lib/dhcpsrv/cfg_subnets6.h
src/lib/dhcpsrv/cfg_subnets6.h
+10
-1
No files found.
src/bin/dhcp4/dhcp4_srv.cc
View file @
f8a23579
...
...
@@ -500,48 +500,7 @@ Dhcpv4Srv::selectSubnet(const Pkt4Ptr& query, bool& drop,
Subnet4Ptr
subnet
;
SubnetSelector
selector
;
selector
.
ciaddr_
=
query
->
getCiaddr
();
selector
.
giaddr_
=
query
->
getGiaddr
();
selector
.
local_address_
=
query
->
getLocalAddr
();
selector
.
remote_address_
=
query
->
getRemoteAddr
();
selector
.
client_classes_
=
query
->
classes_
;
selector
.
iface_name_
=
query
->
getIface
();
// If the link-selection sub-option is present, extract its value.
// "The link-selection sub-option is used by any DHCP relay agent
// that desires to specify a subnet/link for a DHCP client request
// that it is relaying but needs the subnet/link specification to
// be different from the IP address the DHCP server should use
// when communicating with the relay agent." (RFC 3527)
//
// Try first Relay Agent Link Selection sub-option
OptionPtr
rai
=
query
->
getOption
(
DHO_DHCP_AGENT_OPTIONS
);
if
(
rai
)
{
OptionCustomPtr
rai_custom
=
boost
::
dynamic_pointer_cast
<
OptionCustom
>
(
rai
);
if
(
rai_custom
)
{
OptionPtr
link_select
=
rai_custom
->
getOption
(
RAI_OPTION_LINK_SELECTION
);
if
(
link_select
)
{
OptionBuffer
link_select_buf
=
link_select
->
getData
();
if
(
link_select_buf
.
size
()
==
sizeof
(
uint32_t
))
{
selector
.
option_select_
=
IOAddress
::
fromBytes
(
AF_INET
,
&
link_select_buf
[
0
]);
}
}
}
}
else
{
// Or Subnet Selection option
OptionPtr
sbnsel
=
query
->
getOption
(
DHO_SUBNET_SELECTION
);
if
(
sbnsel
)
{
OptionCustomPtr
oc
=
boost
::
dynamic_pointer_cast
<
OptionCustom
>
(
sbnsel
);
if
(
oc
)
{
selector
.
option_select_
=
oc
->
readAddress
();
}
}
}
const
SubnetSelector
&
selector
=
CfgSubnets4
::
initSelector
(
query
);
CfgMgr
&
cfgmgr
=
CfgMgr
::
instance
();
subnet
=
cfgmgr
.
getCurrentCfg
()
->
getCfgSubnets4
()
->
selectSubnet
(
selector
);
...
...
src/bin/dhcp6/dhcp6_srv.cc
View file @
f8a23579
...
...
@@ -1305,31 +1305,11 @@ Dhcpv6Srv::sanityCheck(const Pkt6Ptr& pkt, RequirementLevel clientid,
Subnet6Ptr
Dhcpv6Srv
::
selectSubnet
(
const
Pkt6Ptr
&
question
,
bool
&
drop
)
{
// Initialize subnet selector with the values used to select the subnet.
SubnetSelector
selector
;
selector
.
iface_name_
=
question
->
getIface
();
selector
.
remote_address_
=
question
->
getRemoteAddr
();
selector
.
first_relay_linkaddr_
=
IOAddress
(
"::"
);
selector
.
client_classes_
=
question
->
classes_
;
// Initialize fields specific to relayed messages.
if
(
!
question
->
relay_info_
.
empty
())
{
BOOST_REVERSE_FOREACH
(
Pkt6
::
RelayInfo
relay
,
question
->
relay_info_
)
{
if
(
!
relay
.
linkaddr_
.
isV6Zero
()
&&
!
relay
.
linkaddr_
.
isV6LinkLocal
())
{
selector
.
first_relay_linkaddr_
=
relay
.
linkaddr_
;
break
;
}
}
selector
.
interface_id_
=
question
->
getAnyRelayOption
(
D6O_INTERFACE_ID
,
Pkt6
::
RELAY_GET_FIRST
);
}
const
SubnetSelector
&
selector
=
CfgSubnets6
::
initSelector
(
question
);
Subnet6Ptr
subnet
=
CfgMgr
::
instance
().
getCurrentCfg
()
->
getCfgSubnets6
()
->
selectSubnet
(
selector
);
// Let's execute all callouts registered for subnet6_receive
if
(
HooksManager
::
calloutsPresent
(
Hooks
.
hook_index_subnet6_select_
))
{
CalloutHandlePtr
callout_handle
=
getCalloutHandle
(
question
);
...
...
src/lib/dhcpsrv/cfg_subnets4.cc
View file @
f8a23579
// Copyright (C) 2014-201
7
Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-201
8
Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
...
...
@@ -6,6 +6,7 @@
#include <config.h>
#include <dhcp/iface_mgr.h>
#include <dhcp/option_custom.h>
#include <dhcpsrv/cfg_subnets4.h>
#include <dhcpsrv/dhcpsrv_log.h>
#include <dhcpsrv/lease_mgr_factory.h>
...
...
@@ -75,6 +76,54 @@ CfgSubnets4::hasSubnetWithServerId(const asiolink::IOAddress& server_id) const {
return
(
subnet_it
!=
index
.
cend
());
}
SubnetSelector
CfgSubnets4
::
initSelector
(
const
Pkt4Ptr
&
query
)
{
SubnetSelector
selector
;
selector
.
ciaddr_
=
query
->
getCiaddr
();
selector
.
giaddr_
=
query
->
getGiaddr
();
selector
.
local_address_
=
query
->
getLocalAddr
();
selector
.
remote_address_
=
query
->
getRemoteAddr
();
selector
.
client_classes_
=
query
->
classes_
;
selector
.
iface_name_
=
query
->
getIface
();
// If the link-selection sub-option is present, extract its value.
// "The link-selection sub-option is used by any DHCP relay agent
// that desires to specify a subnet/link for a DHCP client request
// that it is relaying but needs the subnet/link specification to
// be different from the IP address the DHCP server should use
// when communicating with the relay agent." (RFC 3527)
//
// Try first Relay Agent Link Selection sub-option
OptionPtr
rai
=
query
->
getOption
(
DHO_DHCP_AGENT_OPTIONS
);
if
(
rai
)
{
OptionCustomPtr
rai_custom
=
boost
::
dynamic_pointer_cast
<
OptionCustom
>
(
rai
);
if
(
rai_custom
)
{
OptionPtr
link_select
=
rai_custom
->
getOption
(
RAI_OPTION_LINK_SELECTION
);
if
(
link_select
)
{
OptionBuffer
link_select_buf
=
link_select
->
getData
();
if
(
link_select_buf
.
size
()
==
sizeof
(
uint32_t
))
{
selector
.
option_select_
=
IOAddress
::
fromBytes
(
AF_INET
,
&
link_select_buf
[
0
]);
}
}
}
}
else
{
// Or Subnet Selection option
OptionPtr
sbnsel
=
query
->
getOption
(
DHO_SUBNET_SELECTION
);
if
(
sbnsel
)
{
OptionCustomPtr
oc
=
boost
::
dynamic_pointer_cast
<
OptionCustom
>
(
sbnsel
);
if
(
oc
)
{
selector
.
option_select_
=
oc
->
readAddress
();
}
}
}
return
(
selector
);
}
Subnet4Ptr
CfgSubnets4
::
selectSubnet4o6
(
const
SubnetSelector
&
selector
)
const
{
...
...
src/lib/dhcpsrv/cfg_subnets4.h
View file @
f8a23579
// Copyright (C) 2014-201
7
Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-201
8
Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
...
...
@@ -9,6 +9,7 @@
#include <asiolink/io_address.h>
#include <cc/cfg_to_element.h>
#include <dhcp/pkt4.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/subnet_id.h>
#include <dhcpsrv/subnet_selector.h>
...
...
@@ -99,6 +100,14 @@ public:
/// @return true if there is a subnet with a specified server identifier.
bool
hasSubnetWithServerId
(
const
asiolink
::
IOAddress
&
server_id
)
const
;
/// @brief Build selector from a client's message.
///
/// @note: code moved from server.
///
/// @param query client's message.
/// @return filled selector.
static
SubnetSelector
initSelector
(
const
Pkt4Ptr
&
query
);
/// @brief Returns a pointer to the selected subnet.
///
/// This method tries to retrieve the subnet for the client using various
...
...
src/lib/dhcpsrv/cfg_subnets6.cc
View file @
f8a23579
// Copyright (C) 2014-201
7
Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-201
8
Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h>
#include <dhcp/dhcp6.h>
#include <dhcp/option_custom.h>
#include <dhcpsrv/cfg_subnets6.h>
#include <dhcpsrv/dhcpsrv_log.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcpsrv/subnet_id.h>
#include <dhcpsrv/addr_utilities.h>
#include <stats/stats_mgr.h>
#include <boost/foreach.hpp>
#include <string.h>
#include <sstream>
...
...
@@ -66,6 +69,32 @@ CfgSubnets6::getByPrefix(const std::string& subnet_text) const {
return
((
subnet_it
!=
index
.
cend
())
?
(
*
subnet_it
)
:
ConstSubnet6Ptr
());
}
SubnetSelector
CfgSubnets6
::
initSelector
(
const
Pkt6Ptr
&
query
)
{
// Initialize subnet selector with the values used to select the subnet.
SubnetSelector
selector
;
selector
.
iface_name_
=
query
->
getIface
();
selector
.
remote_address_
=
query
->
getRemoteAddr
();
selector
.
first_relay_linkaddr_
=
IOAddress
(
"::"
);
selector
.
client_classes_
=
query
->
classes_
;
// Initialize fields specific to relayed messages.
if
(
!
query
->
relay_info_
.
empty
())
{
BOOST_REVERSE_FOREACH
(
Pkt6
::
RelayInfo
relay
,
query
->
relay_info_
)
{
if
(
!
relay
.
linkaddr_
.
isV6Zero
()
&&
!
relay
.
linkaddr_
.
isV6LinkLocal
())
{
selector
.
first_relay_linkaddr_
=
relay
.
linkaddr_
;
break
;
}
}
selector
.
interface_id_
=
query
->
getAnyRelayOption
(
D6O_INTERFACE_ID
,
Pkt6
::
RELAY_GET_FIRST
);
}
return
(
selector
);
}
Subnet6Ptr
CfgSubnets6
::
selectSubnet
(
const
SubnetSelector
&
selector
)
const
{
Subnet6Ptr
subnet
;
...
...
src/lib/dhcpsrv/cfg_subnets6.h
View file @
f8a23579
// Copyright (C) 2014-201
7
Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-201
8
Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
...
...
@@ -9,6 +9,7 @@
#include <asiolink/io_address.h>
#include <dhcp/option.h>
#include <dhcp/pkt6.h>
#include <cc/cfg_to_element.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/subnet_id.h>
...
...
@@ -92,6 +93,14 @@ public:
/// subnet doesn't exist.
ConstSubnet6Ptr
getByPrefix
(
const
std
::
string
&
subnet_prefix
)
const
;
/// @brief Build selector from a client's message.
///
/// @note: code moved from server.
///
/// @param query client's message.
/// @return filled selector.
static
SubnetSelector
initSelector
(
const
Pkt6Ptr
&
query
);
/// @brief Selects a subnet using parameters specified in the selector.
///
/// This method tries to retrieve the subnet for the client using various
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment