libbgp  0.6
A C++ BGP Library.
Public Member Functions | Static Public Member Functions | List of all members
libbgp::Prefix6 Class Reference

IPv6 Route/Prefix related utilities. More...

#include <prefix6.h>

Inheritance diagram for libbgp::Prefix6:
Inheritance graph
[legend]
Collaboration diagram for libbgp::Prefix6:
Collaboration graph
[legend]

Public Member Functions

 Prefix6 ()
 Construct a new Prefix6 object.
 
 Prefix6 (const uint8_t prefix[16], uint8_t length)
 Construct a new Prefix6 object. More...
 
 Prefix6 (const char *prefix, uint8_t length)
 Construct a new Prefix6 object. More...
 
ssize_t parse (const uint8_t *buffer, size_t buf_sz)
 Parse a IPv6 NLRI prefix from buffer. More...
 
ssize_t write (uint8_t *buffer, size_t buf_sz) const
 Write a IPv6 prefix to NLRI buffer. More...
 
bool includes (const uint8_t address[16]) const
 Test if an address is inside this prefix. More...
 
bool includes (const char *address) const
 Test if an address is inside this prefix. More...
 
bool includes (const Prefix &other) const
 Test if another prefix is inside this prefix. More...
 
bool includes (const uint8_t prefix[16], uint8_t length) const
 Test if another prefix is inside this prefix. More...
 
bool includes (const char *prefix, uint8_t length) const
 Test if another prefix is inside this prefix. More...
 
bool operator== (const Prefix &other) const
 Test if two routes are equals. More...
 
bool operator> (const Prefix &other) const
 
bool operator< (const Prefix &other) const
 
bool operator>= (const Prefix &other) const
 
bool operator<= (const Prefix &other) const
 
bool operator!= (const Prefix &other) const
 
bool set (const uint8_t prefix[16], uint8_t length)
 Set route. More...
 
bool setPrefix (const uint8_t prefix[16])
 Set prefix. More...
 
bool setLength (uint8_t length)
 Set netmask. More...
 
void getPrefix (uint8_t prefix[16]) const
 Get prefix. More...
 
uint8_t getLength () const
 Get netmask. More...
 
void getMask (uint8_t mask[16]) const
 Get netmask. More...
 

Static Public Member Functions

static bool Includes (const uint8_t prefix[16], uint8_t length, const uint8_t address[16])
 Test if an address is inside a prefix. More...
 
static bool Includes (const uint8_t prefix_a[16], uint8_t length_a, const uint8_t prefix_b[16], uint8_t length_b)
 Test if a prefix is inside another prefix. More...
 

Additional Inherited Members

- Public Attributes inherited from libbgp::Prefix
Afi afi
 

Detailed Description

IPv6 Route/Prefix related utilities.

Definition at line 27 of file prefix6.h.

Constructor & Destructor Documentation

◆ Prefix6() [1/2]

libbgp::Prefix6::Prefix6 ( const uint8_t  prefix[16],
uint8_t  length 
)

Construct a new Prefix6 object.

Parameters
prefixPrefix as bytes array.
lengthNetmask of the prefix in CIDR notation.

Definition at line 215 of file prefix6.cc.

◆ Prefix6() [2/2]

libbgp::Prefix6::Prefix6 ( const char *  prefix,
uint8_t  length 
)

Construct a new Prefix6 object.

Parameters
prefixPrefix as IPv6 string.
lengthNetmask of the prefix in CIDR notation.

Definition at line 227 of file prefix6.cc.

Member Function Documentation

◆ getLength()

uint8_t libbgp::Prefix6::getLength ( ) const

Get netmask.

Returns
uint8_t The netmask in CIDR notation.

Definition at line 459 of file prefix6.cc.

◆ getMask()

void libbgp::Prefix6::getMask ( uint8_t  mask[16]) const

Get netmask.

Parameters
maskBytes array to store the netmask.
Exceptions
bad_route_lengthNetmask invalid.

Definition at line 469 of file prefix6.cc.

References libbgp::cidr_to_mask6().

◆ getPrefix()

void libbgp::Prefix6::getPrefix ( uint8_t  prefix[16]) const

Get prefix.

Parameters
prefixBytes array to store the prefix.

Definition at line 450 of file prefix6.cc.

◆ Includes() [1/2]

bool libbgp::Prefix6::Includes ( const uint8_t  prefix[16],
uint8_t  length,
const uint8_t  address[16] 
)
static

Test if an address is inside a prefix.

Parameters
prefixThe prefix.
lengthThe netmask of the prefix in CIDR notation.
addressThe address to test against.
Returns
true The address is in the prefix.
false The address in not in the prefix.

Definition at line 279 of file prefix6.cc.

References libbgp::mask_ipv6().

Referenced by includes().

◆ Includes() [2/2]

bool libbgp::Prefix6::Includes ( const uint8_t  prefix_a[16],
uint8_t  length_a,
const uint8_t  prefix_b[16],
uint8_t  length_b 
)
static

Test if a prefix is inside another prefix.

Parameters
prefix_aThe prefix.
length_aThe netmask of the prefix in CIDR notation.
prefix_bThe orefix to test against.
length_bThe netmask of the prefix to test against in CIDR notation.
Returns
true prefix_b is in prefix_a.
false prefix_b is not in prefix_a.

Definition at line 298 of file prefix6.cc.

References libbgp::mask_ipv6().

◆ includes() [1/5]

bool libbgp::Prefix6::includes ( const uint8_t  address[16]) const

Test if an address is inside this prefix.

Parameters
addressThe address.
Returns
true The address is in the prefix.
false The address in not in the prefix.

Definition at line 315 of file prefix6.cc.

References Includes().

Referenced by includes().

◆ includes() [2/5]

bool libbgp::Prefix6::includes ( const char *  address) const

Test if an address is inside this prefix.

Parameters
addressThe address in IPv6 string format.
Returns
true The address is in the prefix.
false The address in not in the prefix.

Definition at line 326 of file prefix6.cc.

References includes().

◆ includes() [3/5]

bool libbgp::Prefix6::includes ( const Prefix other) const
virtual

Test if another prefix is inside this prefix.

Parameters
otherThe other prefix.
Returns
true The other prefix is in this prefix.
false The other prefix is not in this prefix.

Implements libbgp::Prefix.

Definition at line 339 of file prefix6.cc.

◆ includes() [4/5]

bool libbgp::Prefix6::includes ( const uint8_t  prefix[16],
uint8_t  length 
) const

Test if another prefix is inside this prefix.

Parameters
prefixThe other prefix.
lengthNetmask of the other prefix in CIDR notation.
Returns
true The other prefix is in this prefix.
false The other prefix is not in this prefix.

Definition at line 353 of file prefix6.cc.

References Includes().

◆ includes() [5/5]

bool libbgp::Prefix6::includes ( const char *  prefix,
uint8_t  length 
) const

Test if another prefix is inside this prefix.

Parameters
prefixThe other prefix in IPv6 string notation.
lengthNetmask of the other prefix in CIDR notation.
Returns
true The other prefix is in this prefix.
false The other prefix is not in this prefix.

Definition at line 365 of file prefix6.cc.

References Includes().

◆ operator==()

bool libbgp::Prefix6::operator== ( const Prefix other) const
virtual

Test if two routes are equals.

Parameters
otherThe other route object.
Returns
true The routes are equal.
false The routes are different.

Implements libbgp::Prefix.

Definition at line 378 of file prefix6.cc.

◆ parse()

ssize_t libbgp::Prefix6::parse ( const uint8_t *  buffer,
size_t  buf_sz 
)
virtual

Parse a IPv6 NLRI prefix from buffer.

Parameters
bufferBuffer to parse from.
buf_szSize of the buffer.
Returns
ssize_t Bytes read.
Return values
-1Failed to parse prefix.
>=0Bytes read.

Implements libbgp::Prefix.

Definition at line 242 of file prefix6.cc.

◆ set()

bool libbgp::Prefix6::set ( const uint8_t  prefix[16],
uint8_t  length 
)

Set route.

Parameters
prefixPrefix.
lengthThe netmask in CIDR notation.
Returns
true Route set.
false Failed to set route.s

Definition at line 416 of file prefix6.cc.

References setLength(), and setPrefix().

◆ setLength()

bool libbgp::Prefix6::setLength ( uint8_t  length)

Set netmask.

Parameters
lengthThe netmask in CIDR notation.
Returns
true Netmask set.
false Failed to set netmask.

Definition at line 439 of file prefix6.cc.

Referenced by set().

◆ setPrefix()

bool libbgp::Prefix6::setPrefix ( const uint8_t  prefix[16])

Set prefix.

Parameters
prefixPrefix to set.
Returns
true Prefix set.
false Failed to set prefix.

Definition at line 427 of file prefix6.cc.

Referenced by set().

◆ write()

ssize_t libbgp::Prefix6::write ( uint8_t *  buffer,
size_t  buf_sz 
) const
virtual

Write a IPv6 prefix to NLRI buffer.

Parameters
bufferBuffer to write to.
buf_szSize of the buffer (max write size).
Returns
ssize_t Bytes written.
Return values
-1Failed to write.
>=0Bytes written.

Implements libbgp::Prefix.

Definition at line 262 of file prefix6.cc.


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