libbgp  0.6
A C++ BGP Library.
prefix6.h
Go to the documentation of this file.
1 
11 #ifndef BGP_PREFIX6_H_
12 #define BGP_PREFIX6_H_
13 #include <stdint.h>
14 #include <unistd.h>
15 #include "prefix.h"
16 
17 namespace libbgp {
18 
19 bool cidr_to_mask6(uint8_t src, uint8_t dst[16]);
20 bool mask_ipv6(const uint8_t prefix[16], uint8_t mask, uint8_t masked_addr[16]);
21 bool v6addr_is_zero(const uint8_t prefix[16]);
22 
27 class Prefix6 : public Prefix {
28 public:
29  Prefix6();
30  Prefix6(const uint8_t prefix[16], uint8_t length);
31  Prefix6(const char* prefix, uint8_t length);
32 
33  ssize_t parse(const uint8_t *buffer, size_t buf_sz);
34  ssize_t write(uint8_t *buffer, size_t buf_sz) const;
35 
36  // static utility functions for route include test
37  static bool Includes (const uint8_t prefix[16], uint8_t length, const uint8_t address[16]);
38  static bool Includes (const uint8_t prefix_a[16], uint8_t length_a, const uint8_t prefix_b[16], uint8_t length_b);
39 
40  // test if address in prefix
41  bool includes (const uint8_t address[16]) const;
42  bool includes (const char* address) const;
43 
44  // test if route other is sub-prefix
45  bool includes (const Prefix &other) const;
46  bool includes (const uint8_t prefix[16], uint8_t length) const;
47  bool includes (const char* prefix, uint8_t length) const;
48 
49  // test if length & prefix equals to other
50  bool operator== (const Prefix &other) const;
51 
52  // test if length smaller (prefix size bigger) then other. prefix must be
53  // same to do this.
54  bool operator> (const Prefix &other) const;
55 
56  // test if length bigger (prefix size smaller) then other. prefix must be
57  // same to do this.
58  bool operator< (const Prefix &other) const;
59 
60  bool operator>= (const Prefix &other) const;
61  bool operator<= (const Prefix &other) const;
62  bool operator!= (const Prefix &other) const;
63 
64  bool set(const uint8_t prefix[16], uint8_t length);
65  bool setPrefix(const uint8_t prefix[16]);
66  bool setLength(uint8_t length);
67  void getPrefix(uint8_t prefix[16]) const;
68  uint8_t getLength() const;
69  void getMask(uint8_t mask[16]) const;
70 
71 private:
72  uint8_t length;
73  uint8_t prefix[16];
74 };
75 
76 }
77 
78 #endif // BGP_PREFIX6_H_
IPv6 Route/Prefix related utilities.
Definition: prefix6.h:27
static bool Includes(const uint8_t prefix[16], uint8_t length, const uint8_t address[16])
Test if an address is inside a prefix.
Definition: prefix6.cc:279
uint8_t getLength() const
Get netmask.
Definition: prefix6.cc:459
bool cidr_to_mask6(uint8_t src, uint8_t dst[16])
Convert IPv6 mask in CIDR notation to bytes array.
Definition: prefix6.cc:158
Route/Prefix related utilities.
bool operator==(const Prefix &other) const
Test if two routes are equals.
Definition: prefix6.cc:378
bool includes(const uint8_t address[16]) const
Test if an address is inside this prefix.
Definition: prefix6.cc:315
Prefix6()
Construct a new Prefix6 object.
Definition: prefix6.cc:203
bool v6addr_is_zero(const uint8_t prefix[16])
Test if a IPv6 addresss is all zero.
Definition: prefix6.cc:195
bool setPrefix(const uint8_t prefix[16])
Set prefix.
Definition: prefix6.cc:427
Definition: bgp-afi.h:14
bool mask_ipv6(const uint8_t prefix[16], uint8_t mask, uint8_t masked_addr[16])
Mask a IPv6 address with given netmask.
Definition: prefix6.cc:173
ssize_t parse(const uint8_t *buffer, size_t buf_sz)
Parse a IPv6 NLRI prefix from buffer.
Definition: prefix6.cc:242
Route/Prefix related utilities.
Definition: prefix.h:25
void getPrefix(uint8_t prefix[16]) const
Get prefix.
Definition: prefix6.cc:450
ssize_t write(uint8_t *buffer, size_t buf_sz) const
Write a IPv6 prefix to NLRI buffer.
Definition: prefix6.cc:262
bool setLength(uint8_t length)
Set netmask.
Definition: prefix6.cc:439
void getMask(uint8_t mask[16]) const
Get netmask.
Definition: prefix6.cc:469