Contiki-NG
Loading...
Searching...
No Matches
nat64-tcp.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026, RISE Research Institutes of Sweden AB.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/**
32 * \addtogroup nat64
33 * @{
34 *
35 * \file
36 * NAT64 TCP splice proxy.
37 *
38 * Terminates TCP on both the IPv6 and IPv4 sides and splices
39 * the data streams. Per-session sequence number state lets
40 * the proxy generate IoT-side ACKs and RFC 6528-compliant
41 * ISNs without translating headers across address families.
42 * \author
43 * Nicolas Tsiftes <nicolas.tsiftes@ri.se>
44 */
45
46#ifndef NAT64_TCP_H_
47#define NAT64_TCP_H_
48
49#include <stdbool.h>
50#include <stdint.h>
51#include "nat64-platform.h"
52
53/**
54 * \brief Initialize the TCP splice proxy.
55 *
56 * Clears the per-session sequence number state table.
57 */
58void nat64_tcp_init(void);
59
60/**
61 * \brief Set the 128-bit secret key for TCP ISN generation.
62 * \param key 16 bytes of cryptographically random data.
63 *
64 * Must be called before any TCP sessions are created.
65 * The key is used as input to HMAC-SHA-256 per RFC 6528.
66 */
67void nat64_tcp_set_isn_secret(const uint8_t key[16]);
68
69/**
70 * \brief Process an outgoing IPv6+TCP packet from an IoT node.
71 * \param pkt Pointer to the raw IPv6 packet.
72 * \param len Total packet length in bytes.
73 * \return 1 if the packet was handled, 0 otherwise.
74 *
75 * Handles SYN (initiates connect), data (forwards to server),
76 * FIN (half-closes), and RST (aborts).
77 */
78int nat64_tcp_output(const uint8_t *pkt, uint16_t len);
79
80/**
81 * \brief Flush deferred TCP ACKs.
82 *
83 * Called from the platform select loop, outside the uip_buf processing
84 * path, to avoid re-entrancy with tcpip_input().
85 */
86void nat64_tcp_flush_acks(void);
87
88/**
89 * \brief Check whether a session has buffered data awaiting delivery.
90 * \param s The session to check.
91 * \return true if data is pending, false otherwise.
92 *
93 * Used by the platform layer to suppress reading from the IPv4 socket
94 * while previous data is still being paced to the IoT node.
95 */
96bool nat64_tcp_has_pending_data(const struct nat64_session *s);
97
98/**
99 * \brief Check whether the IoT node has already half-closed the session.
100 * \param s The session to check.
101 * \return true if the IoT-side FIN has been received, false otherwise.
102 *
103 * Used by the platform layer when the IPv4 server closes its end: if
104 * the IoT side had already FIN'd, both halves are now closed and the
105 * platform can destroy the session immediately rather than waiting
106 * for the idle timer to reap it.
107 */
108bool nat64_tcp_peer_fin_received(const struct nat64_session *s);
109
110/**
111 * \brief Free any TCP sequence state associated with a session.
112 * \param s The session being closed.
113 *
114 * Must be called when a session is closed or expires to prevent
115 * stale seqstate from matching if the session slot is reused.
116 */
117void nat64_tcp_free_seqstate(const struct nat64_session *s);
118
119/** @} */
120
121#endif /* NAT64_TCP_H_ */
void nat64_tcp_flush_acks(void)
Flush deferred TCP ACKs.
Definition nat64-tcp.c:629
bool nat64_tcp_has_pending_data(const struct nat64_session *s)
Check whether a session has buffered data awaiting delivery.
Definition nat64-tcp.c:752
void nat64_tcp_free_seqstate(const struct nat64_session *s)
Free any TCP sequence state associated with a session.
Definition nat64-tcp.c:766
bool nat64_tcp_peer_fin_received(const struct nat64_session *s)
Check whether the IoT node has already half-closed the session.
Definition nat64-tcp.c:759
void nat64_tcp_set_isn_secret(const uint8_t key[16])
Set the 128-bit secret key for TCP ISN generation.
Definition nat64-tcp.c:746
int nat64_tcp_output(const uint8_t *pkt, uint16_t len)
Process an outgoing IPv6+TCP packet from an IoT node.
Definition nat64-tcp.c:393
void nat64_tcp_init(void)
Initialize the TCP splice proxy.
Definition nat64-tcp.c:740
NAT64 platform interface — socket-based.
A NAT64 session binding an IoT node's IPv6 flow to an IPv4 socket.