Contiki-NG
Loading...
Searching...
No Matches
nat64.c File Reference

NAT64 core — dispatches IPv6 packets to protocol-specific handlers (UDP via kernel sockets, TCP via splice proxy, ICMPv6 Echo via unprivileged ICMP sockets) and synthesizes ICMPv6 Destination Unreachable errors back to the IoT node when forwarding fails. More...

#include "nat64.h"
#include "nat64-platform.h"
#include "nat64-dns64.h"
#include "nat64-tcp.h"
#include "ipv6/ip64-addr.h"
#include "net/ipv6/tcpip.h"
#include <string.h>
#include "sys/log.h"

Go to the source code of this file.

Functions

static bool ipv4_dst_is_forbidden (const uip_ip4addr_t *addr)
 Reject IPv4 destinations that must not be reached via NAT64.
 
bool nat64_is_ip64_addr (const uip_ip6addr_t *addr)
 Check whether an IPv6 address embeds an IPv4 address via the NAT64 prefix.
 
static int handle_udp_output (const uint8_t *pkt, const struct v6hdr *ip6, const uip_ip4addr_t *dst4, uint16_t payload_len)
 Forward an outbound IPv6/UDP datagram to its IPv4 destination.
 
static int handle_icmp6_output (const uint8_t *pkt, const struct v6hdr *ip6, const uip_ip4addr_t *dst4, uint16_t payload_len)
 Translate an outbound ICMPv6 Echo Request to ICMPv4 and send it.
 
int nat64_output (const uint8_t *ipv6_pkt, uint16_t len)
 Process an outgoing IPv6 packet destined for an IPv4 host.
 
void nat64_activate (void)
 Initialize the NAT64 gateway.
 
ICMPv6 Destination Unreachable synthesis

The gateway synthesizes ICMPv6 errors toward the IoT node when a packet cannot be delivered (forbidden destination, connection refused, host unreachable, session table exhaustion, ...).

The errors are queued and drained by nat64_flush_icmp6() from the platform layer's select loop, to avoid re-entrancy with tcpip_input() from output paths.

void nat64_queue_icmp6_unreach (const uint8_t *invoking_pkt, uint16_t invoking_len, uint8_t code)
 Queue an ICMPv6 Destination Unreachable for delivery to the IoT node.
 
void nat64_queue_icmp6_unreach_tuple (const uip_ip6addr_t *ip6_src, uint16_t src_port, const uip_ip4addr_t *ip4_dst, uint16_t dst_port, uint8_t ipproto, uint8_t code)
 Queue an ICMPv6 Destination Unreachable for a 5-tuple whose connection failed.
 
void nat64_flush_icmp6 (void)
 Drain the queue of pending ICMPv6 errors into the uIP stack.
 
Platform-to-core callbacks

Called by the platform layer (e.g., the select loop in nat64-sock.c) when data arrives on an IPv4 socket or a TCP connection changes state.

Each callback fabricates the corresponding IPv6 packet and injects it into the uIP stack via tcpip_input().

void nat64_udp_input (struct nat64_session *s, const uint8_t *payload, uint16_t len)
 Inject a UDP response from an IPv4 server.
 
void nat64_icmp_input (struct nat64_session *s, const uint8_t *icmp_pkt, uint16_t len)
 Inject an ICMPv4 Echo Reply received from an IPv4 host.
 

Detailed Description

NAT64 core — dispatches IPv6 packets to protocol-specific handlers (UDP via kernel sockets, TCP via splice proxy, ICMPv6 Echo via unprivileged ICMP sockets) and synthesizes ICMPv6 Destination Unreachable errors back to the IoT node when forwarding fails.

Author
Nicolas Tsiftes nicol.nosp@m.as.t.nosp@m.sifte.nosp@m.s@ri.nosp@m..se

Definition in file nat64.c.