Data Structures | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes

IpMap Class Reference

Map from IP addresses to client data. More...

#include <IpMap.h>

Collaboration diagram for IpMap:
Collaboration graph
[legend]

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.
selfmark (sockaddr const *min, sockaddr const *max, void *data=0)
 Mark a range.
selfmark (in_addr_t min, in_addr_t max, void *data=0)
 Mark a range.
selfmark (IpAddr const &min, IpAddr const &max, void *data=0)
 Mark a range.
selfmark (in_addr_t addr, void *data=0)
 Mark an IPv4 address addr with data.
selfmark (IpEndpoint const *min, IpEndpoint const *max, void *data=0)
 Mark a range.
selfmark (IpEndpoint const *addr, void *data=0)
 Mark an address addr with data.
selfunmark (sockaddr const *min, sockaddr const *max)
 Unmark addresses.
selfunmark (IpEndpoint const *min, IpEndpoint const *max)
 Unmark addresses (overload).
selfunmark (in_addr_t min, in_addr_t max)
 Unmark overload.
selffill (sockaddr const *min, sockaddr const *max, void *data=0)
 Fill addresses.
selffill (IpEndpoint const *min, IpEndpoint const *max, void *data=0)
 Fill addresses (overload).
selffill (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.
selfclear ()
 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::Ip4Mapforce4 ()
 Print all spans.
ts::detail::Ip6Mapforce6 ()
 Force the IPv6 map to exist.

Protected Attributes

ts::detail::Ip4Map_m4
 Map of IPv4 addresses.
ts::detail::Ip6Map_m6
 Map of IPv6 addresses.

Detailed Description

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.


Member Typedef Documentation

typedef IpMap IpMap::self

Self reference type.

Definition at line 257 of file IpMap.h.


Constructor & Destructor Documentation

IpMap::IpMap (  )  [inline]

Default constructor.

Definition at line 604 of file IpMap.h.

IpMap::~IpMap (  ) 

Destructor.

Definition at line 1250 of file IpMap.cc.

References _m4, and _m6.


Member Function Documentation

IpMap::iterator IpMap::begin (  )  const
IpMap & IpMap::clear ( void   ) 

Remove all addresses from the map.

Note:
This is much faster than unmark.
Returns:
This object.

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.

Returns:
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.
Parameters:
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.

Note:
Convenience overload for IpAddr.
Returns:
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.
Parameters:
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.

Note:
Covenience overload for IPv4.
Returns:
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.
Parameters:
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.

Note:
Convenience overload for IpEndpoint.
Returns:
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.
Parameters:
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]
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.

Note:
This is useful for filling in first match tables because data for already present addresses is not changed.
Returns:
This object.

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]

Print all spans.

Returns:
This map. Force the IPv4 map to exist.
The IPv4 map.

Definition at line 1256 of file IpMap.cc.

References _m4.

Referenced by fill(), and mark().

ts::detail::Ip6Map * IpMap::force6 (  )  [inline, protected]

Force the IPv6 map to exist.

Returns:
The IPv6 map.

Definition at line 1262 of file IpMap.cc.

References _m6.

Referenced by fill(), and mark().

size_t IpMap::getCount (  )  const
IpMap & IpMap::mark ( IpAddr const &  min,
IpAddr const &  max,
void *  data = 0 
) [inline]

Mark a range.

All addresses in the range [ min , max ] are marked with data.

Note:
Convenience overload for IPv4 addresses.
Returns:
This object.
Parameters:
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]

Mark an IPv4 address addr with data.

This is equivalent to calling mark(addr, addr, data).

Note:
Convenience overload for IPv4 addresses.
Returns:
This object.
Parameters:
addr Address (network order).
data Client data.

Definition at line 532 of file IpMap.h.

References mark().

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.

Returns:
This object.
Parameters:
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.

Note:
Convenience overload for IPv4 addresses.
Returns:
This object.
Parameters:
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.

Note:
Convenience overload.
Returns:
This object.
Parameters:
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).

Note:
Convenience overload.
Returns:
This object.
Parameters:
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.

Returns:
This object.
Parameters:
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.

Parameters:
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.

Note:
Intended for debugging, not general client use.

Field Documentation

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().

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().


The documentation for this class was generated from the following files: