46 lines
No EOL
1.1 KiB
Text
46 lines
No EOL
1.1 KiB
Text
port_t v6_out = 64;
|
|
port_t v4_out = 16;
|
|
|
|
/* nat64 */
|
|
/*
|
|
>>> int(ipaddress.IPv4Address("10.0.0.0"))
|
|
167772160
|
|
>>> int(ipaddress.IPv6Address("2001:db8:42::"))
|
|
42540766411362381960998550477184434176
|
|
*/
|
|
|
|
ipv6_addr_t v6_src = 42540766411362381960998550477184434176; /* 2001:db8:42:: -> v6 source range*/
|
|
ipv6_addr_t v6_dst = 42540766411362381960998550477184434176; /* 2001:db8:42:: -> v6 source range*/
|
|
ipv6_addr_t nat64_prefix = 42540766411362381960998550477184434176; /* 2001:db8:42:: -> v6 destination range */
|
|
ipv4_addr_t v4_dst = 167772160; /* 10.0.0.0 -> v4 destination range */
|
|
|
|
|
|
/* if it is ipv6, we always translate to IPv4 and output on v4_out */
|
|
if(hdr.ipv6.isValid()) {
|
|
nat64_static(v6_src, v4_dst, nat64_prefix);
|
|
|
|
if(hdr.udp.isValid()) {
|
|
delta_udp_from_v6_to_v4
|
|
}
|
|
|
|
if(hdr.tcp.isValid()) {
|
|
delta_tcp_from_v6_to_v4
|
|
}
|
|
|
|
set_egress_port(v4_out);
|
|
|
|
} else if(hdr.ipv4.isValid()) {
|
|
nat46_static(v6_dst, v4_dst, nat64_prefix);
|
|
|
|
if(hdr.udp.isValid()) {
|
|
delta_udp_from_v4_to_v6
|
|
}
|
|
|
|
if(hdr.tcp.isValid()) {
|
|
delta_tcp_from_v4_to_v6
|
|
}
|
|
|
|
set_egress_port(v6_out);
|
|
} else {
|
|
set_egress_port(4);
|
|
} |