Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sebastian Schrader
Kea
Commits
5054d0ed
Commit
5054d0ed
authored
Dec 20, 2012
by
Tomek Mrugalski
🛰
Browse files
[2320] Lease4 and Lease6 now have common ancestor.
parent
2039944b
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/lib/dhcpsrv/lease_mgr.cc
View file @
5054d0ed
...
...
@@ -32,13 +32,18 @@ using namespace std;
namespace
isc
{
namespace
dhcp
{
Lease
::
Lease
(
const
isc
::
asiolink
::
IOAddress
&
addr
,
uint32_t
t1
,
uint32_t
t2
,
uint32_t
valid_lft
,
SubnetID
subnet_id
,
time_t
cltt
)
:
addr_
(
addr
),
t1_
(
t1
),
t2_
(
t2
),
valid_lft_
(
valid_lft
),
cltt_
(
cltt
),
subnet_id_
(
subnet_id
),
fixed_
(
false
),
fqdn_fwd_
(
false
),
fqdn_rev_
(
false
)
{
}
Lease6
::
Lease6
(
LeaseType
type
,
const
isc
::
asiolink
::
IOAddress
&
addr
,
DuidPtr
duid
,
uint32_t
iaid
,
uint32_t
preferred
,
uint32_t
valid
,
uint32_t
t1
,
uint32_t
t2
,
SubnetID
subnet_id
,
uint8_t
prefixlen
)
:
addr_
(
addr
),
type_
(
type
),
prefixlen_
(
prefixlen
),
iaid_
(
iaid
),
duid_
(
duid
),
preferred_lft_
(
preferred
),
valid_lft_
(
valid
),
t1_
(
t1
),
t2_
(
t2
),
subnet_id_
(
subnet_id
),
fixed_
(
false
),
fqdn_fwd_
(
false
),
fqdn_rev_
(
false
)
{
:
Lease
(
addr
,
t1
,
t2
,
valid
,
subnet_id
,
0
/*cltt*/
),
type_
(
type
),
prefixlen_
(
prefixlen
),
iaid_
(
iaid
),
duid_
(
duid
),
preferred_lft_
(
preferred
)
{
if
(
!
duid
)
{
isc_throw
(
InvalidOperation
,
"DUID must be specified for a lease"
);
}
...
...
@@ -46,7 +51,7 @@ Lease6::Lease6(LeaseType type, const isc::asiolink::IOAddress& addr,
cltt_
=
time
(
NULL
);
}
bool
Lease
6
::
expired
()
const
{
bool
Lease
::
expired
()
const
{
// Let's use int64 to avoid problems with negative/large uint32 values
int64_t
expire_time
=
cltt_
+
valid_lft_
;
...
...
@@ -63,7 +68,7 @@ std::string LeaseMgr::getParameter(const std::string& name) const {
}
std
::
string
Lease6
::
toText
()
{
Lease6
::
toText
()
const
{
ostringstream
stream
;
stream
<<
"Type: "
<<
static_cast
<
int
>
(
type_
)
<<
" ("
;
...
...
@@ -91,6 +96,21 @@ Lease6::toText() {
return
(
stream
.
str
());
}
std
::
string
Lease4
::
toText
()
const
{
ostringstream
stream
;
stream
<<
"Address: "
<<
addr_
.
toText
()
<<
"
\n
"
<<
"Valid life: "
<<
valid_lft_
<<
"
\n
"
<<
"T1: "
<<
t1_
<<
"
\n
"
<<
"T2: "
<<
t2_
<<
"
\n
"
<<
"Cltt: "
<<
cltt_
<<
"
\n
"
<<
"Subnet ID: "
<<
subnet_id_
<<
"
\n
"
;
return
(
stream
.
str
());
}
bool
Lease4
::
operator
==
(
const
Lease4
&
other
)
const
{
return
(
...
...
src/lib/dhcpsrv/lease_mgr.h
View file @
5054d0ed
...
...
@@ -108,38 +108,19 @@ public:
isc
::
Exception
(
file
,
line
,
what
)
{}
};
/// @brief
Structure that holds a lease for IPv4 addres
s
/// @brief
a common structure for IPv4 and IPv6 lease
s
///
/// For performance reasons it is a simple structure, not a class. If we chose
/// make it a class, all fields would have to made private and getters/setters
/// would be required. As this is a critical part of the code that will be used
/// extensively, direct access is warranted.
struct
Lease4
{
/// @brief Maximum size of a hardware address
static
const
size_t
HWADDR_MAX
=
20
;
/// IPv4 address
isc
::
asiolink
::
IOAddress
addr_
;
/// @brief Address extension
///
/// It is envisaged that in some cases IPv4 address will be accompanied
/// with some additional data. One example of such use are Address + Port
/// solutions (or Port-restricted Addresses), where several clients may get
/// the same address, but different port ranges. This feature is not
/// expected to be widely used. Under normal circumstances, the value
/// should be 0.
uint32_t
ext_
;
/// This structure holds all information that is common between IPv4 and IPv6
/// leases.
struct
Lease
{
/// @brief Hardware address
std
::
vector
<
uint8_t
>
hwaddr_
;
Lease
(
const
isc
::
asiolink
::
IOAddress
&
addr
,
uint32_t
t1
,
uint32_t
t2
,
uint32_t
valid_lft
,
SubnetID
subnet_id
,
time_t
cltt
)
;
/// @brief
Client identifier
/// @brief
IPv4 ot IPv6 address
///
/// @todo Should this be a pointer to a client ID or the ID itself?
/// Compare with the DUID in the Lease6 structure.
ClientIdPtr
client_id_
;
/// IPv4, IPv6 address or, in the case of a prefix delegation, the prefix.
isc
::
asiolink
::
IOAddress
addr_
;
/// @brief Renewal timer
///
...
...
@@ -201,6 +182,46 @@ struct Lease4 {
/// system administrator.
std
::
string
comments_
;
/// @brief Convert Lease to Printable Form
///
/// @return String form of the lease
virtual
std
::
string
toText
()
const
=
0
;
/// @brief returns true if the lease is expired
/// @return true if the lease is expired
bool
expired
()
const
;
};
/// @brief Structure that holds a lease for IPv4 address
///
/// For performance reasons it is a simple structure, not a class. If we chose
/// make it a class, all fields would have to made private and getters/setters
/// would be required. As this is a critical part of the code that will be used
/// extensively, direct access is warranted.
struct
Lease4
:
public
Lease
{
/// @brief Maximum size of a hardware address
static
const
size_t
HWADDR_MAX
=
20
;
/// @brief Address extension
///
/// It is envisaged that in some cases IPv4 address will be accompanied
/// with some additional data. One example of such use are Address + Port
/// solutions (or Port-restricted Addresses), where several clients may get
/// the same address, but different port ranges. This feature is not
/// expected to be widely used. Under normal circumstances, the value
/// should be 0.
uint32_t
ext_
;
/// @brief Hardware address
std
::
vector
<
uint8_t
>
hwaddr_
;
/// @brief Client identifier
///
/// @todo Should this be a pointer to a client ID or the ID itself?
/// Compare with the DUID in the Lease6 structure.
ClientIdPtr
client_id_
;
/// @brief Constructor
///
/// @param addr IPv4 address as unsigned 32-bit integer in network byte
...
...
@@ -215,18 +236,16 @@ struct Lease4 {
Lease4
(
uint32_t
addr
,
const
uint8_t
*
hwaddr
,
size_t
hwaddr_len
,
const
uint8_t
*
clientid
,
size_t
clientid_len
,
uint32_t
valid_lft
,
time_t
cltt
,
uint32_t
subnet_id
)
:
addr_
(
addr
),
ext_
(
0
),
hwaddr_
(
hwaddr
,
hwaddr
+
hwaddr_len
),
client_id_
(
new
ClientId
(
clientid
,
clientid_len
)),
t1_
(
0
),
t2_
(
0
),
valid_lft_
(
valid_lft
),
cltt_
(
cltt
),
subnet_id_
(
subnet_id
),
fixed_
(
false
),
hostname_
(),
fqdn_fwd_
(
false
),
fqdn_rev_
(
false
),
comments_
()
{}
:
Lease
(
addr
,
0
,
0
,
valid_lft
,
subnet_id
,
cltt
),
ext_
(
0
),
hwaddr_
(
hwaddr
,
hwaddr
+
hwaddr_len
),
client_id_
(
new
ClientId
(
clientid
,
clientid_len
))
{
}
/// @brief Default Constructor
///
/// Initialize fields that don't have a default constructor.
Lease4
()
:
addr_
(
0
)
,
fixed_
(
false
),
fqdn_fwd_
(
false
),
fqdn_rev_
(
false
)
{
}
Lease4
()
:
Lease
(
0
,
0
,
0
,
0
,
0
,
0
)
{
}
/// @brief Compare two leases for equality
///
...
...
@@ -240,6 +259,11 @@ struct Lease4 {
return
(
!
operator
==
(
other
));
}
/// @brief Convert Lease to Printable Form
///
/// @return String form of the lease
virtual
std
::
string
toText
()
const
;
/// @todo: Add DHCPv4 failover related fields here
};
...
...
@@ -257,7 +281,7 @@ typedef std::vector<Lease4Ptr> Lease4Collection;
/// make it a class, all fields would have to made private and getters/setters
/// would be required. As this is a critical part of the code that will be used
/// extensively, direct access is warranted.
struct
Lease6
{
struct
Lease6
:
public
Lease
{
/// @brief Type of lease contents
typedef
enum
{
...
...
@@ -266,11 +290,6 @@ struct Lease6 {
LEASE_IA_PD
/// the lease contains IPv6 prefix (for prefix delegation)
}
LeaseType
;
/// @brief IPv6 address
///
/// IPv6 address or, in the case of a prefix delegation, the prefix.
isc
::
asiolink
::
IOAddress
addr_
;
/// @brief Lease type
///
/// One of normal address, temporary address, or prefix.
...
...
@@ -297,69 +316,6 @@ struct Lease6 {
/// assigned or renewed (cltt), expressed in seconds.
uint32_t
preferred_lft_
;
/// @brief valid lifetime
///
/// This parameter specifies the valid lifetime since the lease waa
/// assigned/renewed (cltt), expressed in seconds.
uint32_t
valid_lft_
;
/// @brief T1 timer
///
/// Specifies renewal time. Although technically it is a property of the
/// IA container and not the address itself, since our data model does not
/// define a separate IA entity, we are keeping it in the lease. In the
/// case of multiple addresses/prefixes for the same IA, each must have
/// consistent T1 and T2 values. This is specified in seconds since cltt.
/// The value will also be useful for failover to calculate the next
/// expected client transmission time.
uint32_t
t1_
;
/// @brief T2 timer
///
/// Specifies rebinding time. Although technically it is a property of the
/// IA container and not the address itself, since our data model does not
/// define a separate IA entity, we are keeping it in the lease. In the
/// case of multiple addresses/prefixes for the same IA, each must have
/// consistent T1 and T2 values. This is specified in seconds since cltt.
uint32_t
t2_
;
/// @brief Client last transmission time
///
/// Specifies a timestamp giving the time when the last transmission from a
/// client was received.
time_t
cltt_
;
/// @brief Subnet identifier
///
/// Specifies the identification of the subnet to which the lease belongs.
SubnetID
subnet_id_
;
/// @brief Fixed lease?
///
/// Fixed leases are kept after they are released/expired.
bool
fixed_
;
/// @brief Client hostname
///
/// This field may be empty
std
::
string
hostname_
;
/// @brief Forward zone updated?
///
/// Set true if the DNS AAAA record for this lease has been updated.
bool
fqdn_fwd_
;
/// @brief Reverse zone updated?
///
/// Set true if the DNS PTR record for this lease has been updated.
bool
fqdn_rev_
;
/// @brief Lease comments
///
/// Currently not used. It may be used for keeping comments made by the
/// system administrator.
std
::
string
comments_
;
/// @todo: Add DHCPv6 failover related fields here
/// @brief Constructor
...
...
@@ -370,18 +326,9 @@ struct Lease6 {
/// @brief Constructor
///
/// Initialize fields that don't have a default constructor.
Lease6
()
:
addr_
(
"::"
),
type_
(
LEASE_IA_NA
),
fixed_
(
false
),
fqdn_fwd_
(
false
),
fqdn_rev_
(
false
)
{}
/// @brief Convert Lease6 to Printable Form
///
/// @return String form of the lease
std
::
string
toText
();
/// @brief returns true if the lease is expired
/// @return true if the lease is expired
bool
expired
()
const
;
Lease6
()
:
Lease
(
isc
::
asiolink
::
IOAddress
(
"::"
),
0
,
0
,
0
,
0
,
0
),
type_
(
LEASE_IA_NA
)
{
}
/// @brief Compare two leases for equality
///
...
...
@@ -394,6 +341,11 @@ struct Lease6 {
bool
operator
!=
(
const
Lease6
&
other
)
const
{
return
(
!
operator
==
(
other
));
}
/// @brief Convert Lease to Printable Form
///
/// @return String form of the lease
virtual
std
::
string
toText
()
const
;
};
/// @brief Pointer to a Lease6 structure.
...
...
src/lib/dhcpsrv/memfile_lease_mgr.h
View file @
5054d0ed
...
...
@@ -225,8 +225,8 @@ protected:
// IPv6 address that are unique. That particular key is a member
// of the Lease6 structure, is of type IOAddress and can be accessed
// by doing &Lease6::addr_
boost
::
multi_index
::
ordered_unique
<
boost
::
multi_index
::
member
<
Lease
6
,
isc
::
asiolink
::
IOAddress
,
&
Lease
6
::
addr_
>
boost
::
multi_index
::
ordered_unique
<
boost
::
multi_index
::
member
<
Lease
,
isc
::
asiolink
::
IOAddress
,
&
Lease
::
addr_
>
>
>
>
Lease6Storage
;
// Let the whole contraption be called Lease6Storage.
...
...
@@ -238,4 +238,3 @@ protected:
};
// end of isc namespace
#endif // MEMFILE_LEASE_MGR
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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