16 #include <boost/algorithm/string.hpp>
30 : enum_base<l3_proto_t>(v, s)
37 return (*
this == IPV6);
43 return (*
this == IPV4);
61 else if (*
this == IPV6)
63 else if (*
this == MPLS)
85 : enum_base<nh_proto_t>(v, s)
99 const ip_dscp_t ip_dscp_t::DSCP_CS0(0,
"CS0");
100 const ip_dscp_t ip_dscp_t::DSCP_CS1(8,
"CS1");
101 const ip_dscp_t ip_dscp_t::DSCP_CS2(16,
"CS2");
102 const ip_dscp_t ip_dscp_t::DSCP_CS3(24,
"CS3");
103 const ip_dscp_t ip_dscp_t::DSCP_CS4(32,
"CS4");
104 const ip_dscp_t ip_dscp_t::DSCP_CS5(40,
"CS5");
105 const ip_dscp_t ip_dscp_t::DSCP_CS6(48,
"CS6");
106 const ip_dscp_t ip_dscp_t::DSCP_CS7(50,
"CS7");
107 const ip_dscp_t ip_dscp_t::DSCP_AF11(10,
"AF11");
108 const ip_dscp_t ip_dscp_t::DSCP_AF12(12,
"AF12");
109 const ip_dscp_t ip_dscp_t::DSCP_AF13(14,
"AF13");
110 const ip_dscp_t ip_dscp_t::DSCP_AF21(18,
"AF21");
111 const ip_dscp_t ip_dscp_t::DSCP_AF22(20,
"AF22");
112 const ip_dscp_t ip_dscp_t::DSCP_AF23(22,
"AF23");
113 const ip_dscp_t ip_dscp_t::DSCP_AF31(26,
"AF31");
114 const ip_dscp_t ip_dscp_t::DSCP_AF32(28,
"AF32");
115 const ip_dscp_t ip_dscp_t::DSCP_AF33(30,
"AF33");
116 const ip_dscp_t ip_dscp_t::DSCP_AF41(34,
"AF41");
117 const ip_dscp_t ip_dscp_t::DSCP_AF42(36,
"AF42");
118 const ip_dscp_t ip_dscp_t::DSCP_AF43(38,
"AF43");
119 const ip_dscp_t ip_dscp_t::DSCP_EF(46,
"EF");
149 : m_addr(boost::asio::
ip::
address::from_string(s))
194 if (m_len == o.m_len) {
195 return (m_addr < o.m_addr);
197 return (m_len < o.m_len);
204 return (m_len == o.m_len && m_addr == o.m_addr);
210 return (!(*
this == o));
216 std::ostringstream s;
218 s << m_addr.to_string() <<
"/" << std::to_string(m_len);
229 std::array<uint8_t, 16>
a;
230 std::copy(bytes, bytes + 16, std::begin(
a));
231 boost::asio::ip::address_v6 v6(
a);
234 std::array<uint8_t, 4>
a;
235 std::copy(bytes, bytes + 4, std::begin(
a));
236 boost::asio::ip::address_v4 v4(
a);
251 memcpy(array,
addr.to_bytes().data(), 16);
257 memcpy(array,
addr.to_bytes().data(), 4);
291 if (m_addr.is_v6()) {
308 boost::asio::ip::address_v4
310 const boost::asio::ip::address_v4& addr2)
313 a = addr1.to_ulong() | addr2.to_ulong();
314 boost::asio::ip::address_v4
addr(
a);
318 boost::asio::ip::address_v4
operator&(
const boost::asio::ip::address_v4& addr1,
319 const boost::asio::ip::address_v4& addr2)
322 a = addr1.to_ulong() & addr2.to_ulong();
323 boost::asio::ip::address_v4
addr(
a);
327 boost::asio::ip::address_v4
operator~(
const boost::asio::ip::address_v4& addr1)
330 a = ~addr1.to_ulong();
331 boost::asio::ip::address_v4
addr(
a);
335 boost::asio::ip::address_v6
337 const boost::asio::ip::address_v6& addr2)
339 boost::asio::ip::address_v6::bytes_type b1 = addr1.to_bytes();
340 boost::asio::ip::address_v6::bytes_type b2 = addr2.to_bytes();
342 for (boost::asio::ip::address_v6::bytes_type::size_type ii = 0;
343 ii < b1.max_size(); ii++) {
347 boost::asio::ip::address_v6
addr(b1);
351 boost::asio::ip::address_v6
operator&(
const boost::asio::ip::address_v6& addr1,
352 const boost::asio::ip::address_v6& addr2)
354 boost::asio::ip::address_v6::bytes_type b1 = addr1.to_bytes();
355 boost::asio::ip::address_v6::bytes_type b2 = addr2.to_bytes();
357 for (boost::asio::ip::address_v6::bytes_type::size_type ii = 0;
358 ii < b1.max_size(); ii++) {
362 boost::asio::ip::address_v6
addr(b1);
366 boost::asio::ip::address_v6
operator~(
const boost::asio::ip::address_v6& addr1)
368 boost::asio::ip::address_v6::bytes_type b1 = addr1.to_bytes();
370 for (boost::asio::ip::address_v6::bytes_type::size_type ii = 0;
371 ii < b1.max_size(); ii++) {
375 boost::asio::ip::address_v6
addr(b1);
383 return (addr1.to_v6() | addr2.to_v6());
385 return (addr1.to_v4() | addr2.to_v4());
392 return (addr1.to_v6() & addr2.to_v6());
394 return (addr1.to_v4() & addr2.to_v4());
400 return ~(addr1.to_v6());
402 return ~(addr1.to_v4());
408 if (m_addr.is_v6()) {
409 boost::asio::ip::address_v6::bytes_type
b =
414 for (boost::asio::ip::address_v6::bytes_type::size_type ii = 0;
415 ii <
b.max_size(); ii++) {
416 for (int8_t bit = 7; bit >= 0 && n_bits; bit--) {
424 return (boost::asio::ip::address_v6(
b));
430 return (boost::asio::ip::address_v4(
a));
439 pfx.m_addr = pfx.m_addr & pfx.
mask();
449 pfx.m_addr = pfx.m_addr | ~pfx.
mask();
529 if (m_gaddr.is_v6()) {
551 if (m_len == o.m_len) {
552 if (m_saddr == o.m_saddr)
553 return (m_gaddr < o.m_gaddr);
555 return (m_saddr < o.m_saddr);
557 return (m_len < o.m_len);
564 return (m_len == o.m_len && m_gaddr == o.m_gaddr && m_saddr == o.m_saddr);
570 return (!(*
this == o));
576 std::ostringstream s;
578 s <<
"(" << m_saddr.to_string() <<
"," << m_gaddr.to_string() <<
"/"
579 << std::to_string(m_len) <<
")";