From a20f9d3e8118e7e58f2850d3ed60ec6a317acc9f Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 13:49:50 -0700 Subject: [PATCH] Move internals' PDU helpers into their own files --- include/tins/detail/pdu_helpers.h | 66 +++++++ include/tins/detail/type_traits.h | 1 + include/tins/internals.h | 32 +--- src/CMakeLists.txt | 1 + src/detail/pdu_helpers.cpp | 298 ++++++++++++++++++++++++++++++ src/dhcp.cpp | 1 - src/dot1q.cpp | 2 +- src/ethernetII.cpp | 3 +- src/internals.cpp | 270 --------------------------- src/ip.cpp | 3 +- src/ip_reassembler.cpp | 2 +- src/ipsec.cpp | 2 +- src/ipv6.cpp | 3 +- src/pktap.cpp | 2 +- src/sll.cpp | 2 +- src/snap.cpp | 2 +- src/tcp.cpp | 1 - 17 files changed, 382 insertions(+), 309 deletions(-) create mode 100644 include/tins/detail/pdu_helpers.h create mode 100644 src/detail/pdu_helpers.cpp diff --git a/include/tins/detail/pdu_helpers.h b/include/tins/detail/pdu_helpers.h new file mode 100644 index 0000000..77cc767 --- /dev/null +++ b/include/tins/detail/pdu_helpers.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef TINS_PDU_HELPERS_H +#define TINS_PDU_HELPERS_H + +#include "../constants.h" +#include "../config.h" +#include "../pdu.h" + +/** + * \cond + */ + +namespace Tins { +namespace Internals { + +PDU* pdu_from_flag(Constants::Ethernet::e flag, const uint8_t* buffer, + uint32_t size, bool rawpdu_on_no_match = true); +PDU* pdu_from_flag(Constants::IP::e flag, const uint8_t* buffer, + uint32_t size, bool rawpdu_on_no_match = true); +#ifdef TINS_HAVE_PCAP +PDU* pdu_from_dlt_flag(int flag, const uint8_t* buffer, + uint32_t size, bool rawpdu_on_no_match = true); +#endif // TINS_HAVE_PCAP +PDU* pdu_from_flag(PDU::PDUType type, const uint8_t* buffer, uint32_t size); + +Constants::Ethernet::e pdu_flag_to_ether_type(PDU::PDUType flag); +PDU::PDUType ether_type_to_pdu_flag(Constants::Ethernet::e flag); +Constants::IP::e pdu_flag_to_ip_type(PDU::PDUType flag); +PDU::PDUType ip_type_to_pdu_flag(Constants::IP::e flag); + +} // Internals +} // Tins + +/** + * \endcond + */ + +#endif // TINS_PDU_HELPERS_H diff --git a/include/tins/detail/type_traits.h b/include/tins/detail/type_traits.h index f133d5c..99fbc4b 100644 --- a/include/tins/detail/type_traits.h +++ b/include/tins/detail/type_traits.h @@ -34,6 +34,7 @@ #include "../cxxstd.h" #if TINS_IS_CXX11 #include + #include #endif namespace Tins { diff --git a/include/tins/internals.h b/include/tins/internals.h index caddac4..d6697af 100644 --- a/include/tins/internals.h +++ b/include/tins/internals.h @@ -30,43 +30,19 @@ #ifndef TINS_INTERNALS_H #define TINS_INTERNALS_H -#include #include -#include "constants.h" -#include "pdu.h" -#include "hw_address.h" -#include "macros.h" #include "detail/type_traits.h" +#include "detail/address_helpers.h" +#include "detail/icmp_extension_helpers.h" +#include "detail/smart_ptr.h" +#include "detail/pdu_helpers.h" /** * \cond */ namespace Tins { -namespace Memory { - -class InputMemoryStream; -} // Memory -class IPv4Address; -class IPv6Address; -class ICMPExtensionsStructure; - namespace Internals { -PDU* pdu_from_flag(Constants::Ethernet::e flag, const uint8_t* buffer, - uint32_t size, bool rawpdu_on_no_match = true); -PDU* pdu_from_flag(Constants::IP::e flag, const uint8_t* buffer, - uint32_t size, bool rawpdu_on_no_match = true); -#ifdef TINS_HAVE_PCAP -PDU* pdu_from_dlt_flag(int flag, const uint8_t* buffer, - uint32_t size, bool rawpdu_on_no_match = true); -#endif // TINS_HAVE_PCAP -PDU* pdu_from_flag(PDU::PDUType type, const uint8_t* buffer, uint32_t size); - -Constants::Ethernet::e pdu_flag_to_ether_type(PDU::PDUType flag); -PDU::PDUType ether_type_to_pdu_flag(Constants::Ethernet::e flag); -Constants::IP::e pdu_flag_to_ip_type(PDU::PDUType flag); -PDU::PDUType ip_type_to_pdu_flag(Constants::IP::e flag); - // Compares sequence numbers as defined by RFC 1982. int seq_compare(uint32_t seq1, uint32_t seq2); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b4f1730..58e4920 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,7 @@ set(SOURCES crypto.cpp detail/address_helpers.cpp detail/icmp_extension_helpers.cpp + detail/pdu_helpers.cpp dhcp.cpp dhcpv6.cpp dns.cpp diff --git a/src/detail/pdu_helpers.cpp b/src/detail/pdu_helpers.cpp new file mode 100644 index 0000000..ea15ee5 --- /dev/null +++ b/src/detail/pdu_helpers.cpp @@ -0,0 +1,298 @@ +/* + * Copyright (c) 2017, Matias Fontanini + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "detail/pdu_helpers.h" +#ifdef TINS_HAVE_PCAP + #include +#endif // TINS_HAVE_PCAP +#include "ip.h" +#include "ethernetII.h" +#include "ieee802_3.h" +#include "radiotap.h" +#include "dot11/dot11_base.h" +#include "ipv6.h" +#include "tcp.h" +#include "udp.h" +#include "ipsec.h" +#include "icmp.h" +#include "loopback.h" +#include "sll.h" +#include "ppi.h" +#include "icmpv6.h" +#include "mpls.h" +#include "arp.h" +#include "eapol.h" +#include "rawpdu.h" +#include "dot1q.h" +#include "pppoe.h" +#include "pdu_allocator.h" + +namespace Tins { +namespace Internals { + +Tins::PDU* pdu_from_flag(Constants::Ethernet::e flag, + const uint8_t* buffer, + uint32_t size, + bool rawpdu_on_no_match) { + switch (flag) { + case Tins::Constants::Ethernet::IP: + return new IP(buffer, size); + case Constants::Ethernet::IPV6: + return new IPv6(buffer, size); + case Tins::Constants::Ethernet::ARP: + return new ARP(buffer, size); + case Tins::Constants::Ethernet::PPPOED: + case Tins::Constants::Ethernet::PPPOES: + return new PPPoE(buffer, size); + case Tins::Constants::Ethernet::EAPOL: + return EAPOL::from_bytes(buffer, size); + case Tins::Constants::Ethernet::VLAN: + case Tins::Constants::Ethernet::QINQ: + case Tins::Constants::Ethernet::OLD_QINQ: + return new Dot1Q(buffer, size); + case Tins::Constants::Ethernet::MPLS: + return new MPLS(buffer, size); + default: + { + PDU* pdu = Internals::allocate( + static_cast(flag), + buffer, + size + ); + if (pdu) { + return pdu; + } + } + return rawpdu_on_no_match ? new RawPDU(buffer, size) : 0; + }; +} + +Tins::PDU* pdu_from_flag(Constants::IP::e flag, + const uint8_t* buffer, + uint32_t size, + bool rawpdu_on_no_match) { + switch (flag) { + case Constants::IP::PROTO_IPIP: + return new Tins::IP(buffer, size); + case Constants::IP::PROTO_TCP: + return new Tins::TCP(buffer, size); + case Constants::IP::PROTO_UDP: + return new Tins::UDP(buffer, size); + case Constants::IP::PROTO_ICMP: + return new Tins::ICMP(buffer, size); + case Constants::IP::PROTO_ICMPV6: + return new Tins::ICMPv6(buffer, size); + case Constants::IP::PROTO_IPV6: + return new Tins::IPv6(buffer, size); + case Constants::IP::PROTO_AH: + return new Tins::IPSecAH(buffer, size); + case Constants::IP::PROTO_ESP: + return new Tins::IPSecESP(buffer, size); + default: + break; + } + if (rawpdu_on_no_match) { + return new Tins::RawPDU(buffer, size); + } + return 0; +} + +#ifdef TINS_HAVE_PCAP +PDU* pdu_from_dlt_flag(int flag, + const uint8_t* buffer, + uint32_t size, + bool rawpdu_on_no_match) { + switch (flag) { + case DLT_EN10MB: + return new EthernetII(buffer, size); + + #ifdef TINS_HAVE_DOT11 + case DLT_IEEE802_11_RADIO: + return new RadioTap(buffer, size); + case DLT_IEEE802_11: + return Dot11::from_bytes(buffer, size); + #else // TINS_HAVE_DOT11 + case DLT_IEEE802_11_RADIO: + case DLT_IEEE802_11: + throw protocol_disabled(); + #endif // TINS_HAVE_DOT11 + + case DLT_NULL: + return new Loopback(buffer, size); + case DLT_LINUX_SLL: + return new SLL(buffer, size); + case DLT_PPI: + return new PPI(buffer, size); + default: + return rawpdu_on_no_match ? new RawPDU(buffer, size) : 0; + }; +} +#endif // TINS_HAVE_PCAP + +Tins::PDU* pdu_from_flag(PDU::PDUType type, const uint8_t* buffer, uint32_t size) { + switch(type) { + case Tins::PDU::ETHERNET_II: + return new Tins::EthernetII(buffer, size); + case Tins::PDU::IP: + return new Tins::IP(buffer, size); + case Tins::PDU::IPv6: + return new Tins::IPv6(buffer, size); + case Tins::PDU::ARP: + return new Tins::ARP(buffer, size); + case Tins::PDU::IEEE802_3: + return new Tins::IEEE802_3(buffer, size); + case Tins::PDU::PPPOE: + return new Tins::PPPoE(buffer, size); + #ifdef TINS_HAVE_DOT11 + case Tins::PDU::RADIOTAP: + return new Tins::RadioTap(buffer, size); + case Tins::PDU::DOT11: + case Tins::PDU::DOT11_ACK: + case Tins::PDU::DOT11_ASSOC_REQ: + case Tins::PDU::DOT11_ASSOC_RESP: + case Tins::PDU::DOT11_AUTH: + case Tins::PDU::DOT11_BEACON: + case Tins::PDU::DOT11_BLOCK_ACK: + case Tins::PDU::DOT11_BLOCK_ACK_REQ: + case Tins::PDU::DOT11_CF_END: + case Tins::PDU::DOT11_DATA: + case Tins::PDU::DOT11_CONTROL: + case Tins::PDU::DOT11_DEAUTH: + case Tins::PDU::DOT11_DIASSOC: + case Tins::PDU::DOT11_END_CF_ACK: + case Tins::PDU::DOT11_MANAGEMENT: + case Tins::PDU::DOT11_PROBE_REQ: + case Tins::PDU::DOT11_PROBE_RESP: + case Tins::PDU::DOT11_PS_POLL: + case Tins::PDU::DOT11_REASSOC_REQ: + case Tins::PDU::DOT11_REASSOC_RESP: + case Tins::PDU::DOT11_RTS: + case Tins::PDU::DOT11_QOS_DATA: + return Tins::Dot11::from_bytes(buffer, size); + #endif // TINS_HAVE_DOT11 + default: + return 0; + }; +} + +Constants::Ethernet::e pdu_flag_to_ether_type(PDU::PDUType flag) { + switch (flag) { + case PDU::IP: + return Constants::Ethernet::IP; + case PDU::IPv6: + return Constants::Ethernet::IPV6; + case PDU::ARP: + return Constants::Ethernet::ARP; + case PDU::DOT1Q: + return Constants::Ethernet::VLAN; + case PDU::PPPOE: + return Constants::Ethernet::PPPOED; + case PDU::MPLS: + return Constants::Ethernet::MPLS; + case PDU::RSNEAPOL: + case PDU::RC4EAPOL: + return Constants::Ethernet::EAPOL; + default: + if (Internals::pdu_type_registered(flag)) { + return static_cast( + Internals::pdu_type_to_id(flag) + ); + } + return Constants::Ethernet::UNKNOWN; + } +} + +PDU::PDUType ether_type_to_pdu_flag(Constants::Ethernet::e flag) { + switch (flag) { + case Constants::Ethernet::IP: + return PDU::IP; + case Constants::Ethernet::IPV6: + return PDU::IPv6; + case Constants::Ethernet::ARP: + return PDU::ARP; + case Constants::Ethernet::VLAN: + return PDU::DOT1Q; + case Constants::Ethernet::PPPOED: + return PDU::PPPOE; + //case PDU::RSNEAPOL + //case PDU::RC4EAPOL: + // return Constants::Ethernet::EAPOL; + default: + return PDU::UNKNOWN; + } +} + +Constants::IP::e pdu_flag_to_ip_type(PDU::PDUType flag) { + switch(flag) { + case PDU::IP: + return Constants::IP::PROTO_IPIP; + case PDU::IPv6: + return Constants::IP::PROTO_IPV6; + case PDU::TCP: + return Constants::IP::PROTO_TCP; + case PDU::UDP: + return Constants::IP::PROTO_UDP; + case PDU::ICMP: + return Constants::IP::PROTO_ICMP; + case PDU::ICMPv6: + return Constants::IP::PROTO_ICMPV6; + case PDU::IPSEC_AH: + return Constants::IP::PROTO_AH; + case PDU::IPSEC_ESP: + return Constants::IP::PROTO_ESP; + default: + return static_cast(0xff); + }; +} + +PDU::PDUType ip_type_to_pdu_flag(Constants::IP::e flag) { + switch(flag) { + case Constants::IP::PROTO_IPIP: + return PDU::IP; + case Constants::IP::PROTO_IPV6: + return PDU::IPv6; + case Constants::IP::PROTO_TCP: + return PDU::TCP; + case Constants::IP::PROTO_UDP: + return PDU::UDP; + case Constants::IP::PROTO_ICMP: + return PDU::ICMP; + case Constants::IP::PROTO_ICMPV6: + return PDU::ICMPv6; + case Constants::IP::PROTO_AH: + return PDU::IPSEC_AH; + case Constants::IP::PROTO_ESP: + return PDU::IPSEC_ESP; + default: + return PDU::UNKNOWN; + }; +} + +} // Internals +} // Tins \ No newline at end of file diff --git a/src/dhcp.cpp b/src/dhcp.cpp index 46dd78f..051e303 100644 --- a/src/dhcp.cpp +++ b/src/dhcp.cpp @@ -33,7 +33,6 @@ #include "endianness.h" #include "dhcp.h" #include "ethernetII.h" -#include "internals.h" #include "exceptions.h" #include "memory_helpers.h" diff --git a/src/dot1q.cpp b/src/dot1q.cpp index 5fca01c..f3f5fed 100644 --- a/src/dot1q.cpp +++ b/src/dot1q.cpp @@ -30,9 +30,9 @@ #include #include #include "dot1q.h" -#include "internals.h" #include "exceptions.h" #include "memory_helpers.h" +#include "detail/pdu_helpers.h" using Tins::Memory::InputMemoryStream; using Tins::Memory::OutputMemoryStream; diff --git a/src/ethernetII.cpp b/src/ethernetII.cpp index df85505..8dcdbaa 100644 --- a/src/ethernetII.cpp +++ b/src/ethernetII.cpp @@ -39,8 +39,8 @@ #include #include #endif -#include "config.h" #include "ethernetII.h" +#include "config.h" #include "packet_sender.h" #include "rawpdu.h" #include "pppoe.h" @@ -51,6 +51,7 @@ #include "internals.h" #include "exceptions.h" #include "memory_helpers.h" +#include "detail/pdu_helpers.h" using std::equal; diff --git a/src/internals.cpp b/src/internals.cpp index 740d9eb..78c63fb 100644 --- a/src/internals.cpp +++ b/src/internals.cpp @@ -28,280 +28,10 @@ */ #include "internals.h" -#ifdef TINS_HAVE_PCAP - #include -#endif // TINS_HAVE_PCAP -#include "ip.h" -#include "ethernetII.h" -#include "ieee802_3.h" -#include "radiotap.h" -#include "dot11/dot11_base.h" -#include "ipv6.h" -#include "tcp.h" -#include "udp.h" -#include "ipsec.h" -#include "icmp.h" -#include "loopback.h" -#include "sll.h" -#include "ppi.h" -#include "icmpv6.h" -#include "mpls.h" -#include "arp.h" -#include "eapol.h" -#include "rawpdu.h" -#include "dot1q.h" -#include "pppoe.h" -#include "exceptions.h" -#include "ip_address.h" -#include "ipv6_address.h" -#include "pdu_allocator.h" -#include "memory_helpers.h" - -using std::string; - -using Tins::Memory::InputMemoryStream; namespace Tins { namespace Internals { -Tins::PDU* pdu_from_flag(Constants::Ethernet::e flag, - const uint8_t* buffer, - uint32_t size, - bool rawpdu_on_no_match) { - switch (flag) { - case Tins::Constants::Ethernet::IP: - return new IP(buffer, size); - case Constants::Ethernet::IPV6: - return new IPv6(buffer, size); - case Tins::Constants::Ethernet::ARP: - return new ARP(buffer, size); - case Tins::Constants::Ethernet::PPPOED: - case Tins::Constants::Ethernet::PPPOES: - return new PPPoE(buffer, size); - case Tins::Constants::Ethernet::EAPOL: - return EAPOL::from_bytes(buffer, size); - case Tins::Constants::Ethernet::VLAN: - case Tins::Constants::Ethernet::QINQ: - case Tins::Constants::Ethernet::OLD_QINQ: - return new Dot1Q(buffer, size); - case Tins::Constants::Ethernet::MPLS: - return new MPLS(buffer, size); - default: - { - PDU* pdu = Internals::allocate( - static_cast(flag), - buffer, - size - ); - if (pdu) { - return pdu; - } - } - return rawpdu_on_no_match ? new RawPDU(buffer, size) : 0; - }; -} - -Tins::PDU* pdu_from_flag(Constants::IP::e flag, - const uint8_t* buffer, - uint32_t size, - bool rawpdu_on_no_match) { - switch (flag) { - case Constants::IP::PROTO_IPIP: - return new Tins::IP(buffer, size); - case Constants::IP::PROTO_TCP: - return new Tins::TCP(buffer, size); - case Constants::IP::PROTO_UDP: - return new Tins::UDP(buffer, size); - case Constants::IP::PROTO_ICMP: - return new Tins::ICMP(buffer, size); - case Constants::IP::PROTO_ICMPV6: - return new Tins::ICMPv6(buffer, size); - case Constants::IP::PROTO_IPV6: - return new Tins::IPv6(buffer, size); - case Constants::IP::PROTO_AH: - return new Tins::IPSecAH(buffer, size); - case Constants::IP::PROTO_ESP: - return new Tins::IPSecESP(buffer, size); - default: - break; - } - if (rawpdu_on_no_match) { - return new Tins::RawPDU(buffer, size); - } - return 0; -} - -#ifdef TINS_HAVE_PCAP -PDU* pdu_from_dlt_flag(int flag, - const uint8_t* buffer, - uint32_t size, - bool rawpdu_on_no_match) { - switch (flag) { - case DLT_EN10MB: - return new EthernetII(buffer, size); - - #ifdef TINS_HAVE_DOT11 - case DLT_IEEE802_11_RADIO: - return new RadioTap(buffer, size); - case DLT_IEEE802_11: - return Dot11::from_bytes(buffer, size); - #else // TINS_HAVE_DOT11 - case DLT_IEEE802_11_RADIO: - case DLT_IEEE802_11: - throw protocol_disabled(); - #endif // TINS_HAVE_DOT11 - - case DLT_NULL: - return new Loopback(buffer, size); - case DLT_LINUX_SLL: - return new SLL(buffer, size); - case DLT_PPI: - return new PPI(buffer, size); - default: - return rawpdu_on_no_match ? new RawPDU(buffer, size) : 0; - }; -} -#endif // TINS_HAVE_PCAP - -Tins::PDU* pdu_from_flag(PDU::PDUType type, const uint8_t* buffer, uint32_t size) { - switch(type) { - case Tins::PDU::ETHERNET_II: - return new Tins::EthernetII(buffer, size); - case Tins::PDU::IP: - return new Tins::IP(buffer, size); - case Tins::PDU::IPv6: - return new Tins::IPv6(buffer, size); - case Tins::PDU::ARP: - return new Tins::ARP(buffer, size); - case Tins::PDU::IEEE802_3: - return new Tins::IEEE802_3(buffer, size); - case Tins::PDU::PPPOE: - return new Tins::PPPoE(buffer, size); - #ifdef TINS_HAVE_DOT11 - case Tins::PDU::RADIOTAP: - return new Tins::RadioTap(buffer, size); - case Tins::PDU::DOT11: - case Tins::PDU::DOT11_ACK: - case Tins::PDU::DOT11_ASSOC_REQ: - case Tins::PDU::DOT11_ASSOC_RESP: - case Tins::PDU::DOT11_AUTH: - case Tins::PDU::DOT11_BEACON: - case Tins::PDU::DOT11_BLOCK_ACK: - case Tins::PDU::DOT11_BLOCK_ACK_REQ: - case Tins::PDU::DOT11_CF_END: - case Tins::PDU::DOT11_DATA: - case Tins::PDU::DOT11_CONTROL: - case Tins::PDU::DOT11_DEAUTH: - case Tins::PDU::DOT11_DIASSOC: - case Tins::PDU::DOT11_END_CF_ACK: - case Tins::PDU::DOT11_MANAGEMENT: - case Tins::PDU::DOT11_PROBE_REQ: - case Tins::PDU::DOT11_PROBE_RESP: - case Tins::PDU::DOT11_PS_POLL: - case Tins::PDU::DOT11_REASSOC_REQ: - case Tins::PDU::DOT11_REASSOC_RESP: - case Tins::PDU::DOT11_RTS: - case Tins::PDU::DOT11_QOS_DATA: - return Tins::Dot11::from_bytes(buffer, size); - #endif // TINS_HAVE_DOT11 - default: - return 0; - }; -} - -Constants::Ethernet::e pdu_flag_to_ether_type(PDU::PDUType flag) { - switch (flag) { - case PDU::IP: - return Constants::Ethernet::IP; - case PDU::IPv6: - return Constants::Ethernet::IPV6; - case PDU::ARP: - return Constants::Ethernet::ARP; - case PDU::DOT1Q: - return Constants::Ethernet::VLAN; - case PDU::PPPOE: - return Constants::Ethernet::PPPOED; - case PDU::MPLS: - return Constants::Ethernet::MPLS; - case PDU::RSNEAPOL: - case PDU::RC4EAPOL: - return Constants::Ethernet::EAPOL; - default: - if (Internals::pdu_type_registered(flag)) { - return static_cast( - Internals::pdu_type_to_id(flag) - ); - } - return Constants::Ethernet::UNKNOWN; - } -} - -PDU::PDUType ether_type_to_pdu_flag(Constants::Ethernet::e flag) { - switch (flag) { - case Constants::Ethernet::IP: - return PDU::IP; - case Constants::Ethernet::IPV6: - return PDU::IPv6; - case Constants::Ethernet::ARP: - return PDU::ARP; - case Constants::Ethernet::VLAN: - return PDU::DOT1Q; - case Constants::Ethernet::PPPOED: - return PDU::PPPOE; - //case PDU::RSNEAPOL - //case PDU::RC4EAPOL: - // return Constants::Ethernet::EAPOL; - default: - return PDU::UNKNOWN; - } -} - -Constants::IP::e pdu_flag_to_ip_type(PDU::PDUType flag) { - switch(flag) { - case PDU::IP: - return Constants::IP::PROTO_IPIP; - case PDU::IPv6: - return Constants::IP::PROTO_IPV6; - case PDU::TCP: - return Constants::IP::PROTO_TCP; - case PDU::UDP: - return Constants::IP::PROTO_UDP; - case PDU::ICMP: - return Constants::IP::PROTO_ICMP; - case PDU::ICMPv6: - return Constants::IP::PROTO_ICMPV6; - case PDU::IPSEC_AH: - return Constants::IP::PROTO_AH; - case PDU::IPSEC_ESP: - return Constants::IP::PROTO_ESP; - default: - return static_cast(0xff); - }; -} - -PDU::PDUType ip_type_to_pdu_flag(Constants::IP::e flag) { - switch(flag) { - case Constants::IP::PROTO_IPIP: - return PDU::IP; - case Constants::IP::PROTO_IPV6: - return PDU::IPv6; - case Constants::IP::PROTO_TCP: - return PDU::TCP; - case Constants::IP::PROTO_UDP: - return PDU::UDP; - case Constants::IP::PROTO_ICMP: - return PDU::ICMP; - case Constants::IP::PROTO_ICMPV6: - return PDU::ICMPv6; - case Constants::IP::PROTO_AH: - return PDU::IPSEC_AH; - case Constants::IP::PROTO_ESP: - return PDU::IPSEC_ESP; - default: - return PDU::UNKNOWN; - }; -} - int seq_compare(uint32_t seq1, uint32_t seq2) { // As defined by RFC 1982 - 2 ^ (SERIAL_BITS - 1) static const uint32_t seq_number_diff = 2147483648U; diff --git a/src/ip.cpp b/src/ip.cpp index 6eb0c7a..cd892fd 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -45,8 +45,9 @@ #include "exceptions.h" #include "pdu_allocator.h" #include "memory_helpers.h" -#include "internals.h" #include "utils/checksum_utils.h" +#include "detail/pdu_helpers.h" +#include "pdu_allocator.h" using std::list; using std::min; diff --git a/src/ip_reassembler.cpp b/src/ip_reassembler.cpp index 61c9578..12b4aeb 100644 --- a/src/ip_reassembler.cpp +++ b/src/ip_reassembler.cpp @@ -30,8 +30,8 @@ #include "ip.h" #include "rawpdu.h" #include "constants.h" -#include "internals.h" #include "ip_reassembler.h" +#include "detail/pdu_helpers.h" using std::make_pair; diff --git a/src/ipsec.cpp b/src/ipsec.cpp index 688053b..e925c2e 100644 --- a/src/ipsec.cpp +++ b/src/ipsec.cpp @@ -29,9 +29,9 @@ #include #include "ipsec.h" -#include "internals.h" #include "rawpdu.h" #include "memory_helpers.h" +#include "detail/pdu_helpers.h" using std::memcpy; using std::copy; diff --git a/src/ipv6.cpp b/src/ipv6.cpp index ba766a0..00e3f57 100644 --- a/src/ipv6.cpp +++ b/src/ipv6.cpp @@ -41,8 +41,9 @@ #include "rawpdu.h" #include "exceptions.h" #include "pdu_allocator.h" -#include "internals.h" #include "memory_helpers.h" +#include "detail/pdu_helpers.h" +#include "pdu_allocator.h" using std::copy; diff --git a/src/pktap.cpp b/src/pktap.cpp index 60df8a6..7bb6f24 100644 --- a/src/pktap.cpp +++ b/src/pktap.cpp @@ -31,9 +31,9 @@ #include #include "exceptions.h" #include "pktap.h" -#include "internals.h" #include "exceptions.h" #include "memory_helpers.h" +#include "detail/pdu_helpers.h" using Tins::Memory::InputMemoryStream; diff --git a/src/sll.cpp b/src/sll.cpp index 289b6fd..c21d062 100644 --- a/src/sll.cpp +++ b/src/sll.cpp @@ -30,9 +30,9 @@ #include #include #include "sll.h" -#include "internals.h" #include "exceptions.h" #include "memory_helpers.h" +#include "detail/pdu_helpers.h" using Tins::Memory::InputMemoryStream; using Tins::Memory::OutputMemoryStream; diff --git a/src/snap.cpp b/src/snap.cpp index 33010f1..f27545d 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -38,9 +38,9 @@ #include "arp.h" #include "ip.h" #include "eapol.h" -#include "internals.h" #include "exceptions.h" #include "memory_helpers.h" +#include "detail/pdu_helpers.h" using Tins::Memory::InputMemoryStream; using Tins::Memory::OutputMemoryStream; diff --git a/src/tcp.cpp b/src/tcp.cpp index fec72fa..37a0572 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -35,7 +35,6 @@ #include "constants.h" #include "rawpdu.h" #include "exceptions.h" -#include "internals.h" #include "memory_helpers.h" #include "utils/checksum_utils.h"