Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
nat64-standalone.c
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
/**
33
* \file
34
* Standalone native NAT64 translator: lets a single node reach IPv4
35
* hosts through NAT64 without a border router or tun device.
36
*
37
* NAT64 normally lives in a border router, which provides the uIP
38
* fallback interface and initializes the translator. This module is a
39
* native-platform stand-in: a fallback interface that hands the node's
40
* own 64:ff9b::/96 datagrams to the NAT64 service, which translates
41
* them over host IPv4 sockets. Its module-macros.h wires
42
* UIP_FALLBACK_INTERFACE to this interface, so building the module is
43
* all an application has to do.
44
*
45
* \author Nicolas Tsiftes <nicolas.tsiftes@ri.se>
46
*/
47
#include "contiki.h"
48
#include "
net/ipv6/uip.h
"
49
#include "
nat64.h
"
50
#include "
nat64-platform.h
"
51
#include "
nat64-standalone.h
"
52
53
#include "
sys/log.h
"
54
#define LOG_MODULE "NAT64-SA"
55
#define LOG_LEVEL LOG_LEVEL_INFO
56
57
/*---------------------------------------------------------------------------*/
58
/*
59
* Called once at startup via UIP_FALLBACK_INTERFACE.init(). Bring up the
60
* socket translator when NAT64 is enabled. There is no default route to undo
61
* here: module-macros.h sets NATIVE_WITH_IPV6_DEFAULT_ROUTE=0, so the platform
62
* never adds one.
63
*/
64
static
void
65
init
(
void
)
66
{
67
if
(
nat64_is_enabled
()) {
68
nat64_platform_init
();
69
LOG_INFO(
"standalone NAT64 translator active (no border router, no tun)\n"
);
70
}
71
}
72
/*---------------------------------------------------------------------------*/
73
/*
74
* uIP hands packets with no matching route here. Translate NAT64-prefix
75
* destinations through the NAT64 service; a lone node can reach nothing else,
76
* so drop the rest.
77
*/
78
static
int
79
output(
void
)
80
{
81
if
(
uip_len
== 0) {
82
return
0;
83
}
84
if
(
nat64_is_ip64_addr
(&
UIP_IP_BUF
->destipaddr)) {
85
return
nat64_output
(
uip_buf
,
uip_len
);
86
}
87
LOG_DBG(
"dropping off-link packet to non-NAT64 destination "
);
88
LOG_DBG_6ADDR(&
UIP_IP_BUF
->destipaddr);
89
LOG_DBG_(
"\n"
);
90
return
0;
91
}
92
/*---------------------------------------------------------------------------*/
93
const
struct
uip_fallback_interface
nat64_standalone_interface
= { init, output };
94
/*---------------------------------------------------------------------------*/
init
static int init(void)
Definition
cc2538-rf.c:556
nat64_platform_init
bool nat64_platform_init(void)
Initialize the platform layer.
Definition
nat64-sock.c:690
nat64_is_ip64_addr
bool nat64_is_ip64_addr(const uip_ip6addr_t *addr)
Check whether an IPv6 address embeds an IPv4 address via the NAT64 prefix.
Definition
nat64.c:397
nat64_output
int nat64_output(const uint8_t *pkt, uint16_t len)
Process an outgoing IPv6 packet destined for an IPv4 host.
Definition
nat64.c:514
nat64_is_enabled
bool nat64_is_enabled(void)
Check whether the NAT64 gateway has been enabled at runtime.
Definition
nat64-sock.c:724
UIP_IP_BUF
#define UIP_IP_BUF
Direct access to IPv6 header.
Definition
uip.h:71
uip_buf
#define uip_buf
Macro to access uip_aligned_buf as an array of bytes.
Definition
uip.h:465
uip_len
uint16_t uip_len
The length of the packet in the uip_buf buffer.
Definition
uip6.c:159
log.h
Header file for the logging system.
nat64-platform.h
NAT64 platform interface — socket-based.
nat64_standalone_interface
const struct uip_fallback_interface nat64_standalone_interface
uIP fallback interface that translates the node's own NAT64-prefix traffic over host IPv4 sockets.
Definition
nat64-standalone.c:93
nat64-standalone.h
Standalone native NAT64 translator – see nat64-standalone.c.
nat64.h
NAT64 gateway core API.
uip.h
Header file for the uIP TCP/IP stack.
os
services
nat64
native
standalone
nat64-standalone.c
Generated on
for Contiki-NG by
1.17.0