Map from IP addresses to client data. More...
#include <IpMap.h>
Data Structures | |
class | iterator |
Iterator over nodes / intervals. More... | |
class | Node |
Public API for intervals in the map. More... | |
Public Types | |
typedef IpMap | self |
Self reference type. | |
Public Member Functions | |
IpMap () | |
Default constructor. | |
~IpMap () | |
Destructor. | |
self & | mark (sockaddr const *min, sockaddr const *max, void *data=0) |
Mark a range. | |
self & | mark (in_addr_t min, in_addr_t max, void *data=0) |
Mark a range. | |
self & | mark (IpAddr const &min, IpAddr const &max, void *data=0) |
Mark a range. | |
self & | mark (in_addr_t addr, void *data=0) |
Mark an IPv4 address addr with data. | |
self & | mark (IpEndpoint const *min, IpEndpoint const *max, void *data=0) |
Mark a range. | |
self & | mark (IpEndpoint const *addr, void *data=0) |
Mark an address addr with data. | |
self & | unmark (sockaddr const *min, sockaddr const *max) |
Unmark addresses. | |
self & | unmark (IpEndpoint const *min, IpEndpoint const *max) |
Unmark addresses (overload). | |
self & | unmark (in_addr_t min, in_addr_t max) |
Unmark overload. | |
self & | fill (sockaddr const *min, sockaddr const *max, void *data=0) |
Fill addresses. | |
self & | fill (IpEndpoint const *min, IpEndpoint const *max, void *data=0) |
Fill addresses (overload). | |
self & | fill (in_addr_t min, in_addr_t max, void *data=0) |
Fill addresses (overload). | |
bool | contains (sockaddr const *target, void **ptr=0) const |
Test for membership. | |
bool | contains (in_addr_t target, void **ptr=0) const |
Test for membership. | |
bool | contains (IpEndpoint const *target, void **ptr=0) const |
Test for membership. | |
bool | contains (IpAddr const &target, void **ptr=0) const |
Test for membership. | |
self & | clear () |
Remove all addresses from the map. | |
iterator | begin () const |
Iterator for first element. | |
iterator | end () const |
Iterator past last element. | |
size_t | getCount () const |
void | validate () |
Validate internal data structures. | |
Protected Member Functions | |
ts::detail::Ip4Map * | force4 () |
Print all spans. | |
ts::detail::Ip6Map * | force6 () |
Force the IPv6 map to exist. | |
Protected Attributes | |
ts::detail::Ip4Map * | _m4 |
Map of IPv4 addresses. | |
ts::detail::Ip6Map * | _m6 |
Map of IPv6 addresses. |
Map from IP addresses to client data.
Conceptually this class maps the entire space of IP addresses to client data. Client data is stored as a (void*). Memory management of the data is left to the client. The interface supports marking ranges of addresses with a specific client data. Marking takes a painter's algorithm approach -- any marking overwrites any previous marking on an address. Details of marking calls are discarded and only the final results are kept. That is, a client cannot unmark expliticly any previous marking. Only a specific range of addresses can be unmarked.
Both IPv4 and IPv6 are supported in the same map. Mixed ranges are not supported (any particular range of addresses must be a single protocol but ranges of both types can be in the map).
Use mark
to mark / set / add addresses to the map. Use unmark
to unset addresses (setting the client data to 0 does not remove the address -- this is for the convenience of clients that do not need data, only membership). contains
tests for membership and retrieves the client data.
Ranges can be marked and unmarked arbitrarily. The internal representation keeps a minimal set of ranges to describe the current addresses. Search time is O(log n) where n is the number of disjoint ranges. Marking and unmarking can take O(log n) and may require memory allocation / deallocation although this is minimized.
Definition at line 255 of file IpMap.h.
typedef IpMap IpMap::self |
IpMap::iterator IpMap::begin | ( | ) | const |
Iterator for first element.
Definition at line 1373 of file IpMap.cc.
References _m4, _m6, and ts::detail::IpMapBase< N >::getHead().
Referenced by IpMap_Fill(), IpMapTestPrint(), LogFilterIP::LogFilterIP(), LogFilterIP::operator==(), IpAllow::Print(), and IpMatcher< Data, Result >::Print().
IpMap & IpMap::clear | ( | void | ) |
Remove all addresses from the map.
unmark
. Definition at line 1366 of file IpMap.cc.
References _m4, _m6, and ts::detail::IpMapBase< N >::clear().
Referenced by IpMap_Basic(), and IpMap_Fill().
bool IpMap::contains | ( | sockaddr const * | target, | |
void ** | ptr = 0 | |||
) | const |
Test for membership.
true
if the address is in the map, false
if not. If the address is in the map and ptr is not NULL
, *ptr
is set to the client data for the address. target | Search target (network order). | |
ptr | Client data return. |
Definition at line 1268 of file IpMap.cc.
References _m4, _m6, ats_ip4_addr_cast(), ats_ip6_cast(), and ts::detail::IpMapBase< N >::contains().
Referenced by check_n_attach_prefetch_transform(), UnixNetProcessor::connect_re_internal(), contains(), IpMap_Basic(), IpMap_Fill(), IpMap_Unmark(), IpAllow::match(), and IpMatcher< Data, Result >::Match().
bool IpMap::contains | ( | IpAddr const & | target, | |
void ** | ptr = 0 | |||
) | const [inline] |
Test for membership.
IpAddr
.true
if the address is in the map, false
if not. If the address is in the map and ptr is not NULL
, *ptr
is set to the client data for the address. target | Search target (network order). | |
ptr | Client data return. |
Definition at line 564 of file IpMap.h.
References IpEndpoint::assign(), contains(), and IpEndpoint::sa.
bool IpMap::contains | ( | in_addr_t | target, | |
void ** | ptr = 0 | |||
) | const |
Test for membership.
true
if the address is in the map, false
if not. If the address is in the map and ptr is not NULL
, *ptr
is set to the client data for the address. target | Search target (network order). | |
ptr | Client data return. |
Definition at line 1279 of file IpMap.cc.
References _m4, and ts::detail::IpMapBase< N >::contains().
bool IpMap::contains | ( | IpEndpoint const * | target, | |
void ** | ptr = 0 | |||
) | const [inline] |
Test for membership.
IpEndpoint
.true
if the address is in the map, false
if not. If the address is in the map and ptr is not NULL
, *ptr
is set to the client data for the address. target | Search target (network order). | |
ptr | Client data return. |
Definition at line 559 of file IpMap.h.
References contains(), and IpEndpoint::sa.
IpMap::iterator IpMap::end | ( | ) | const [inline] |
Iterator past last element.
Definition at line 571 of file IpMap.h.
Referenced by IpMap_Fill(), IpMapTestPrint(), LogFilterIP::LogFilterIP(), LogFilterIP::operator==(), IpAllow::Print(), and IpMatcher< Data, Result >::Print().
IpMap & IpMap::fill | ( | IpEndpoint const * | min, | |
IpEndpoint const * | max, | |||
void * | data = 0 | |||
) | [inline] |
Fill addresses (overload).
Definition at line 555 of file IpMap.h.
References fill(), and IpEndpoint::sa.
IpMap & IpMap::fill | ( | in_addr_t | min, | |
in_addr_t | max, | |||
void * | data = 0 | |||
) |
Fill addresses (overload).
Definition at line 1352 of file IpMap.cc.
References ts::detail::IpMapBase< N >::fill(), and force4().
IpMap & IpMap::fill | ( | sockaddr const * | min, | |
sockaddr const * | max, | |||
void * | data = 0 | |||
) |
Fill addresses.
This background fills using the range. All addresses in the range that are not present in the map are added. No previously present address is changed.
Definition at line 1333 of file IpMap.cc.
References ats_ip4_addr_cast(), ats_ip6_cast(), ts::detail::IpMapBase< N >::fill(), force4(), force6(), and ink_assert.
Referenced by fill(), IpMap_Basic(), and IpMap_Fill().
ts::detail::Ip4Map * IpMap::force4 | ( | ) | [inline, protected] |
ts::detail::Ip6Map * IpMap::force6 | ( | ) | [inline, protected] |
size_t IpMap::getCount | ( | ) | const |
Definition at line 1358 of file IpMap.cc.
References _m4, _m6, and ts::detail::IpMapBase< N >::getCount().
Referenced by LogFilterIP::display(), LogFilterIP::display_as_XML(), IpMap_Basic(), IpMap_Fill(), IpMap_Unmark(), IpAllow::Print(), and IpMatcher< Data, Result >::Print().
Mark a range.
All addresses in the range [ min , max ] are marked with data.
min | Minimum address (network order). | |
max | Maximum address (network order). | |
data | Client data. |
Definition at line 536 of file IpMap.h.
References IpEndpoint::assign(), mark(), and IpEndpoint::sa.
IpMap & IpMap::mark | ( | in_addr_t | addr, | |
void * | data = 0 | |||
) | [inline] |
IpMap & IpMap::mark | ( | sockaddr const * | min, | |
sockaddr const * | max, | |||
void * | data = 0 | |||
) |
Mark a range.
All addresses in the range [ min , max ] are marked with data.
min | Minimum value in range. | |
max | Maximum value in range. | |
data | Client data payload. |
Definition at line 1284 of file IpMap.cc.
References ats_ip4_addr_cast(), ats_ip6_cast(), force4(), force6(), ink_assert, and ts::detail::IpMapBase< N >::mark().
Referenced by IpMap_Basic(), IpMap_Unmark(), Load_IpMap_From_File(), LogFilterIP::LogFilterIP(), mark(), and IpMatcher< Data, Result >::NewEntry().
IpMap & IpMap::mark | ( | in_addr_t | min, | |
in_addr_t | max, | |||
void * | data = 0 | |||
) |
Mark a range.
All addresses in the range [ min , max ] are marked with data.
min | Minimum address (network order). | |
max | Maximum address (network order). | |
data | Client data. |
Definition at line 1303 of file IpMap.cc.
References force4(), and ts::detail::IpMapBase< N >::mark().
IpMap & IpMap::mark | ( | IpEndpoint const * | min, | |
IpEndpoint const * | max, | |||
void * | data = 0 | |||
) | [inline] |
Mark a range.
All addresses in the range [ min , max ] are marked with data.
min | Minimum address (network order). | |
max | Maximum address (network order). | |
data | Client data. |
Definition at line 547 of file IpMap.h.
References mark(), and IpEndpoint::sa.
IpMap & IpMap::mark | ( | IpEndpoint const * | addr, | |
void * | data = 0 | |||
) | [inline] |
Mark an address addr with data.
This is equivalent to calling mark(addr, addr, data)
.
addr | Address (network order). | |
data | Client data. |
Definition at line 543 of file IpMap.h.
References mark(), and IpEndpoint::sa.
IpMap & IpMap::unmark | ( | sockaddr const * | min, | |
sockaddr const * | max | |||
) |
Unmark addresses.
All addresses in the range [ min , max ] are cleared (removed from the map), no longer marked.
min | Minimum value. | |
max | Maximum value. |
Definition at line 1309 of file IpMap.cc.
References _m4, _m6, ats_ip4_addr_cast(), ats_ip6_cast(), ink_assert, and ts::detail::IpMapBase< N >::unmark().
Referenced by IpMap_Basic(), IpMap_Unmark(), and unmark().
IpMap & IpMap::unmark | ( | IpEndpoint const * | min, | |
IpEndpoint const * | max | |||
) | [inline] |
Unmark addresses (overload).
Definition at line 551 of file IpMap.h.
References IpEndpoint::sa, and unmark().
IpMap & IpMap::unmark | ( | in_addr_t | min, | |
in_addr_t | max | |||
) |
Unmark overload.
min | Minimum of range to unmark. | |
max | Maximum of range to unmark. |
Definition at line 1327 of file IpMap.cc.
References _m4, and ts::detail::IpMapBase< N >::unmark().
void IpMap::validate | ( | ) |
Validate internal data structures.
ts::detail::Ip4Map* IpMap::_m4 [protected] |
Map of IPv4 addresses.
Definition at line 527 of file IpMap.h.
Referenced by begin(), clear(), contains(), force4(), getCount(), IpMap::iterator::operator++(), IpMap::iterator::operator--(), unmark(), and ~IpMap().
ts::detail::Ip6Map* IpMap::_m6 [protected] |
Map of IPv6 addresses.
Definition at line 528 of file IpMap.h.
Referenced by begin(), clear(), contains(), force6(), getCount(), IpMap::iterator::operator++(), IpMap::iterator::operator--(), unmark(), and ~IpMap().