1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 10:45:57 +01:00

22 Commits
v4.3 ... v4.4

Author SHA1 Message Date
Matias Fontanini
e3aedc56ed Update CHANGES.md for v4.4 2022-02-17 06:55:02 -08:00
Matias Fontanini
3b006c15db Merge pull request #458 from demiquartz/fix-macro-name-conflict
Fix conflict between variable and macro name
2022-01-30 09:04:08 -08:00
Takaaki Sato
177d0b4621 Fix conflict between variable and macro name 2021-10-31 12:03:24 +09:00
Matias Fontanini
24ac038c30 Merge pull request #448 from FlukeCorp/link-local-uses-interface
IPv6 use interface when sending to link-local dest
2021-07-22 19:23:51 -07:00
Prosper Van
a619e4ff98 IPv6 use interface when sending to link-local dest 2021-07-22 11:18:48 -07:00
Matias Fontanini
14bb185d7a Merge pull request #444 from gaya-cohen/decompression-bug-fix
Fix DNS decompression bug and add descriptive exceptions
2021-06-09 08:30:50 -07:00
Gaya Cohen
137b56d5a7 fix exception inheritance and change exception names in DNS code 2021-06-09 15:57:04 +03:00
Gaya Cohen
ed2b3c12d5 Make new exceptions inherit from malformed_packet and change exception names 2021-06-09 11:46:07 +03:00
Gaya Cohen
1650b60234 change counter variable type and add exception description comment 2021-05-24 17:04:11 +03:00
Gaya Cohen
c20c82bcb5 Fix pointer loop bug and add descriptive exceptions 2021-05-24 15:12:23 +03:00
Matias Fontanini
5858132261 Merge pull request #439 from adriancostin6/dns-comment-fix
Fix getter being labeled as setter in dns header file comments
2021-05-14 08:59:54 -07:00
Adrian Costin
16f5795243 Fix getter being labeled as setter in dns header file comments 2021-04-24 01:04:24 +03:00
Matias Fontanini
e90e377b73 Merge pull request #437 from ceerRep/master
Fix wrong address endian
2021-03-28 09:08:30 -07:00
ceerrep
222611b377 Fix wrong address endian
Host endian has been implicitly converted to big endian in "IPv4Address::operator uint32_t()"
2021-03-24 18:41:59 +08:00
Matias Fontanini
b447c664e1 Merge pull request #433 from visuve/master
Close socket when setsockopt fails
2021-03-06 11:34:51 -08:00
visuve
468159e6d2 Close socket when setsockopt fails
- Prevent resource leak
2021-03-04 23:55:29 +02:00
Matias Fontanini
cd40b232e7 Merge pull request #427 from nhutchinson-te/bsd-routing-table
Fix infinite loop when querying BSD routing table
2021-01-04 18:44:06 -08:00
Nick Hutchinson
1166094a2f Fix infinite loop when querying BSD routing table
Fix `query_route_table()` returning a buffer padded with extra '\0'
bytes because it ignored the buffer size returned by `sysctl()`.

This caused `route_entries()` / `route6_entries()` to fall into an
infinite loop, forever trying to parse a 0-length routing entry.
2021-01-04 12:02:03 +00:00
Matias Fontanini
b3d874d6a8 Merge pull request #426 from theDogOfPavlov/master
Added RFC8335 Extended echo types to headers
2020-12-29 08:52:34 -08:00
Martin O'Neal
553b1fb255 Added RFC8335 Extended Echo types 2020-12-29 08:36:30 +00:00
Martin O'Neal
94939dd0fa Added RFC8355 ICMP Extended Echo support
Added RFC8355 ICMP Extended Echo request/reply to Flags (no other changes made)
2020-12-29 08:32:29 +00:00
Matias Fontanini
0774a8dcad Bump version to 4.4 in CMakeLists.txt 2020-09-17 22:20:32 -07:00
12 changed files with 85 additions and 25 deletions

View File

@@ -1,3 +1,21 @@
##### v4.4 - Thu Feb 17 14:41:59 UTC 2022
- Add RFC8335 extended echo types to `ICMP` and `ICMPv6` (#426)
- Handle loops in DNS name decompression (#444)
- Fix Windows' `interface` macro colliding with uses of that identifier in the code (#458)
- Sending IPv6 packets to a link-scope destination address now uses the right interface index (#448)
- Fix incorrect endian being used for ICMP's `gateway` and `address_mask` (#437)
- Socket in `PacketSender::open_l3_socket` is now closed if `setsockopt` fails (#433)
- Fix various incorrect doxygen documentation comments (#439).
- Fix infinite loop when querying the routing table in \*BSD (#427)
##### v4.3 - Fri Sep 18 03:08:33 UTC 2020
- Assign a PDUType to `Dot11ControlTA` (#420)

View File

@@ -46,7 +46,7 @@ ENDIF(LIBTINS_BUILD_SHARED)
# The version number.
SET(TINS_VERSION_MAJOR 4)
SET(TINS_VERSION_MINOR 3)
SET(TINS_VERSION_MINOR 4)
SET(TINS_VERSION_PATCH 0)
SET(LIBTINS_VERSION "${TINS_VERSION_MAJOR}.${TINS_VERSION_MINOR}")

View File

@@ -652,7 +652,7 @@ public:
// Getters
/**
* \brief Setter for the id field.
* \brief Getter for the id field.
*
* \return uint16_t containing the value of the id field.
*/
@@ -661,7 +661,7 @@ public:
}
/**
* \brief Setter for the query response field.
* \brief Getter for the query response field.
*
* \return QRType containing the value of the query response
* field.
@@ -671,7 +671,7 @@ public:
}
/**
* \brief Setter for the opcode field.
* \brief Getter for the opcode field.
*
* \return uint8_t containing the value of the opcode field.
*/
@@ -680,7 +680,7 @@ public:
}
/**
* \brief Setter for the authoritative answer field.
* \brief Getter for the authoritative answer field.
*
* \return uint8_t containing the value of the authoritative
* answer field.
@@ -690,7 +690,7 @@ public:
}
/**
* \brief Setter for the truncated field.
* \brief Getter for the truncated field.
*
* \return uint8_t containing the value of the truncated field.
*/
@@ -699,7 +699,7 @@ public:
}
/**
* \brief Setter for the recursion desired field.
* \brief Getter for the recursion desired field.
*
* \return uint8_t containing the value of the recursion
* desired field.
@@ -709,7 +709,7 @@ public:
}
/**
* \brief Setter for the recursion available field.
* \brief Getter for the recursion available field.
*
* \return uint8_t containing the value of the recursion
* available field.
@@ -719,7 +719,7 @@ public:
}
/**
* \brief Setter for the z desired field.
* \brief Getter for the z desired field.
*
* \return uint8_t containing the value of the z field.
*/
@@ -728,7 +728,7 @@ public:
}
/**
* \brief Setter for the authenticated data field.
* \brief Getter for the authenticated data field.
*
* \return uint8_t containing the value of the authenticated
* data field.
@@ -738,7 +738,7 @@ public:
}
/**
* \brief Setter for the checking disabled field.
* \brief Getter for the checking disabled field.
*
* \return uint8_t containing the value of the checking
* disabled field.
@@ -748,7 +748,7 @@ public:
}
/**
* \brief Setter for the rcode field.
* \brief Getter for the rcode field.
*
* \return uint8_t containing the value of the rcode field.
*/
@@ -757,7 +757,7 @@ public:
}
/**
* \brief Setter for the questions field.
* \brief Getter for the questions field.
*
* \return uint16_t containing the value of the questions field.
*/
@@ -766,7 +766,7 @@ public:
}
/**
* \brief Setter for the answers field.
* \brief Getter for the answers field.
*
* \return uint16_t containing the value of the answers field.
*/
@@ -775,7 +775,7 @@ public:
}
/**
* \brief Setter for the authority field.
* \brief Getter for the authority field.
*
* \return uint16_t containing the value of the authority field.
*/
@@ -784,7 +784,7 @@ public:
}
/**
* \brief Setter for the additional field.
* \brief Getter for the additional field.
*
* \return uint16_t containing the value of the additional field.
*/

View File

@@ -64,8 +64,26 @@ public:
class malformed_packet : public exception_base {
public:
malformed_packet() : exception_base("Malformed packet") { }
malformed_packet(const std::string& message) : exception_base(message) { }
};
/**
* \brief Exception thrown when a DNS decompression pointer is out of bounds.
*/
class dns_decompression_pointer_out_of_bounds : public malformed_packet {
public:
dns_decompression_pointer_out_of_bounds() : malformed_packet("DNS decompression: pointer out of bounds") { }
};
/**
* \brief Exception thrown when a DNS decompression pointer loops.
*/
class dns_decompression_pointer_loops : public malformed_packet {
public:
dns_decompression_pointer_loops() : malformed_packet("DNS decompression: pointer loops") { }
};
/**
* \brief Exception thrown when serializing a packet fails.
*/

View File

@@ -89,7 +89,9 @@ public:
INFO_REQUEST = 15,
INFO_REPLY = 16,
ADDRESS_MASK_REQUEST = 17,
ADDRESS_MASK_REPLY = 18
ADDRESS_MASK_REPLY = 18,
EXTENDED_ECHO_REQUEST = 42,
EXTENDED_ECHO_REPLY = 43
};
/**
@@ -318,7 +320,7 @@ public:
* \return Returns the gateway field value.
*/
address_type gateway() const {
return address_type(Endian::be_to_host(header_.un.gateway));
return address_type(header_.un.gateway);
}
/**
@@ -381,7 +383,7 @@ public:
* \return Returns the address mask value.
*/
address_type address_mask() const {
return address_type(Endian::be_to_host(orig_timestamp_or_address_mask_));
return address_type(orig_timestamp_or_address_mask_);
}
/**

View File

@@ -92,7 +92,9 @@ public:
MULTICAST_ROUTER_ADVERT = 151,
MULTICAST_ROUTER_SOLICIT = 152,
MULTICAST_ROUTER_TERMINATE = 153,
RPL_CONTROL_MSG = 155
RPL_CONTROL_MSG = 155,
EXTENDED_ECHO_REQUEST = 160,
EXTENDED_ECHO_REPLY = 161
};
/**

View File

@@ -65,7 +65,9 @@ class PDU;
* - Those that don't contain a link layer PDU. In this case, the
* kernel will be responsible for picking the appropriate network interface
* based on the destination address.
*
* - Exception: <a href="https://datatracker.ietf.org/doc/html/rfc2553#section-3.3">RFC2553</a>
* requires IPv6 link-scope address have a interface defined.
* .
* \par Note for Windows users:
* Sending layer 3 PDUs (without a link layer protocol) is very restricted
* on Windows (<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms740548(v=vs.85).aspx">link</a>).

View File

@@ -336,7 +336,11 @@ uint32_t DNS::compose_name(const uint8_t* ptr, char* out_ptr) const {
const uint8_t* end = &records_data_[0] + records_data_.size();
const uint8_t* end_ptr = 0;
char* current_out_ptr = out_ptr;
uint8_t pointer_counter = 0;
while (*ptr) {
if (pointer_counter++ > 30){
throw dns_decompression_pointer_loops();
}
// It's an offset
if ((*ptr & 0xc0)) {
if (TINS_UNLIKELY(ptr + sizeof(uint16_t) > end)) {
@@ -347,7 +351,7 @@ uint32_t DNS::compose_name(const uint8_t* ptr, char* out_ptr) const {
index = Endian::be_to_host(index) & 0x3fff;
// Check that the offset is neither too low or too high
if (index < 0x0c || (&records_data_[0] + (index - 0x0c)) >= end) {
throw malformed_packet();
throw dns_decompression_pointer_out_of_bounds();
}
// We've probably found the end of the original domain name. Save it.
if (end_ptr == 0) {

View File

@@ -98,7 +98,7 @@ void ICMP::sequence(uint16_t new_seq) {
}
void ICMP::gateway(address_type new_gw) {
header_.un.gateway = Endian::host_to_be(static_cast<uint32_t>(new_gw));
header_.un.gateway = static_cast<uint32_t>(new_gw);
}
void ICMP::mtu(uint16_t new_mtu) {
@@ -122,7 +122,7 @@ void ICMP::transmit_timestamp(uint32_t new_timestamp) {
}
void ICMP::address_mask(address_type new_mask) {
orig_timestamp_or_address_mask_ = Endian::host_to_be(static_cast<uint32_t>(new_mask));
orig_timestamp_or_address_mask_ = static_cast<uint32_t>(new_mask);
}
uint32_t ICMP::header_size() const {

View File

@@ -32,6 +32,9 @@
#include <netinet/in.h>
#include <sys/socket.h>
#else
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <ws2tcpip.h>
#endif
#include <tins/ipv6.h>
@@ -366,11 +369,16 @@ void IPv6::write_serialization(uint8_t* buffer, uint32_t total_sz) {
}
#ifndef BSD
void IPv6::send(PacketSender& sender, const NetworkInterface &) {
void IPv6::send(PacketSender& sender, const NetworkInterface& interface) {
sockaddr_in6 link_addr;
const PacketSender::SocketType type = PacketSender::IPV6_SOCKET;
link_addr.sin6_family = AF_INET6;
link_addr.sin6_port = 0;
// Required to set sin6_scope_id to interface index as stated in RFC2553.
// https://datatracker.ietf.org/doc/html/rfc2553#section-3.3
if (IPv6Address(header_.dst_addr).is_local_unicast()) {
link_addr.sin6_scope_id = interface.id();
}
memcpy((uint8_t*)&link_addr.sin6_addr, header_.dst_addr, address_type::address_size);
sender.send_l3(*this, (struct sockaddr*)&link_addr, sizeof(link_addr), type);
}

View File

@@ -267,6 +267,11 @@ void PacketSender::open_l3_socket(SocketType type) {
#endif
const int level = (is_v6) ? IPPROTO_IPV6 : IPPROTO_IP;
if (setsockopt(sockfd, level, IP_HDRINCL, (option_ptr)&on, sizeof(on)) != 0) {
#ifndef _WIN32
::close(sockfd);
#else
::closesocket(sockfd);
#endif
throw socket_open_error(make_error_string());
}

View File

@@ -154,6 +154,7 @@ vector<char> query_route_table(int family) {
throw exception_base("sysctl failed");
}
buf.resize(len);
return buf;
}