Skip to content

Commit a619e4f

Browse files
committed
IPv6 use interface when sending to link-local dest
1 parent f46dee9 commit a619e4f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

include/tins/packet_sender.h

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

src/ipv6.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,16 @@ void IPv6::write_serialization(uint8_t* buffer, uint32_t total_sz) {
366366
}
367367

368368
#ifndef BSD
369-
void IPv6::send(PacketSender& sender, const NetworkInterface &) {
369+
void IPv6::send(PacketSender& sender, const NetworkInterface& interface) {
370370
sockaddr_in6 link_addr;
371371
const PacketSender::SocketType type = PacketSender::IPV6_SOCKET;
372372
link_addr.sin6_family = AF_INET6;
373373
link_addr.sin6_port = 0;
374+
// Required to set sin6_scope_id to interface index as stated in RFC2553.
375+
// https://datatracker.ietf.org/doc/html/rfc2553#section-3.3
376+
if (IPv6Address(header_.dst_addr).is_local_unicast()) {
377+
link_addr.sin6_scope_id = interface.id();
378+
}
374379
memcpy((uint8_t*)&link_addr.sin6_addr, header_.dst_addr, address_type::address_size);
375380
sender.send_l3(*this, (struct sockaddr*)&link_addr, sizeof(link_addr), type);
376381
}

0 commit comments

Comments
 (0)