Skip to content

Commit

Permalink
IPv6 use interface when sending to link-local dest
Browse files Browse the repository at this point in the history
  • Loading branch information
fluke-pvan committed Jul 22, 2021
1 parent f46dee9 commit a619e4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion include/tins/packet_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>).
Expand Down
7 changes: 6 additions & 1 deletion src/ipv6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,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);
}
Expand Down

0 comments on commit a619e4f

Please sign in to comment.