Skip to content

Commit d3873ea

Browse files
committed
Don't compile in IPv6 to the firewall when IPv6 is disabled.
1 parent 6101271 commit d3873ea

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

lib/firewall/firewall.cc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
#include <timeout.hh>
1313
#include <vector>
1414

15+
#if CHERIOT_RTOS_OPTION_IPv6 == true
16+
# define ENABLE_IPV6
17+
# define if_ipv6(x) x
18+
#else
19+
# define if_ipv6(x)
20+
#endif
21+
1522
namespace
1623
{
1724
// TODO These should probably be in their own library.
@@ -48,8 +55,10 @@ namespace
4855
enum class EtherType : uint16_t
4956
{
5057
IPv4 = 0x0008,
58+
#ifdef ENABLE_IPV6
5159
IPv6 = 0xDD86,
52-
ARP = 0x0608,
60+
#endif
61+
ARP = 0x0608,
5362
};
5463

5564
const char *ethertype_as_string(EtherType etherType)
@@ -58,8 +67,10 @@ namespace
5867
{
5968
case EtherType::IPv4:
6069
return "IPv4";
70+
#ifdef ENABLE_IPV6
6171
case EtherType::IPv6:
6272
return "IPv6";
73+
#endif
6374
case EtherType::ARP:
6475
return "ARP";
6576
default:
@@ -479,15 +490,18 @@ namespace
479490
}
480491
return ret;
481492
}
493+
#ifdef ENABLE_IPV6
482494
// For now, permit all outbound IPv6 packets.
495+
// FIXME: Check the firewall for IPv6!
483496
case EtherType::IPv6:
484497
{
485498
Debug::log("Permitting outbound IPv6 packet");
486499
return true;
487500
break;
488501
}
502+
#endif
489503
}
490-
return true;
504+
return false;
491505
}
492506

493507
bool packet_filter_ingress(const uint8_t *data, size_t length)
@@ -503,9 +517,12 @@ namespace
503517
reinterpret_cast<EthernetHeader *>(const_cast<uint8_t *>(data));
504518
switch (ethernetHeader->etherType)
505519
{
520+
#ifdef ENABLE_IPV6
506521
// For now, testing with v6 disabled.
522+
// FIXME: Check the firewall for IPv6!
507523
case EtherType::IPv6:
508524
return true;
525+
#endif
509526
case EtherType::ARP:
510527
Debug::log("Saw ARP frame");
511528
return true;
@@ -704,6 +721,7 @@ namespace
704721
}
705722
} // namespace
706723

724+
#ifdef ENABLE_IPV6
707725
void firewall_add_tcpipv6_endpoint(uint8_t *remoteAddress,
708726
uint16_t localPort,
709727
uint16_t remotePort)
@@ -748,3 +766,5 @@ void firewall_remove_udpipv6_remote_endpoint(uint8_t *remoteAddress,
748766
IPProtocolNumber::UDP, *copy, localPort, remotePort);
749767
}
750768
}
769+
770+
#endif

lib/firewall/xmake.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11

22
compartment("Firewall")
33
add_includedirs("../../include")
4+
on_load(function(target)
5+
target:add('options', "IPv6")
6+
local IPv6 = get_config("IPv6")
7+
target:add("defines", "CHERIOT_RTOS_OPTION_IPv6=" .. tostring(IPv6))
8+
end)
49
--FIXME: The FreeRTOS compat headers need to work with this mode!
510
--add_defines("CHERIOT_NO_AMBIENT_MALLOC", "CHERIOT_NO_NEW_DELETE")
611
add_files("firewall.cc")

lib/netapi/NetAPI.cc

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ SObj network_socket_connect_tcp(Timeout *timeout,
6363
Debug::log("Failed to resolve host");
6464
return nullptr;
6565
}
66-
bool isIPv6 = address.kind == NetworkAddress::AddressKindIPv6;
66+
bool isIPv6 = address.kind == NetworkAddress::AddressKindIPv6;
67+
if constexpr (!UseIPv6)
68+
{
69+
if (isIPv6)
70+
{
71+
Debug::log("IPv6 is not supported");
72+
return nullptr;
73+
}
74+
}
6775
auto sealedSocket = network_socket_create_and_bind(
6876
timeout, mallocCapability, isIPv6, ConnectionTypeTCP);
6977
auto kind = network_socket_kind(sealedSocket);
@@ -148,8 +156,16 @@ NetworkAddress network_socket_udp_authorise_host(Timeout *timeout,
148156
}
149157
if (isIPv6)
150158
{
151-
firewall_add_udpipv6_endpoint(
152-
address.ipv6, kind.localPort, ntohs(host->port));
159+
if constexpr (!UseIPv6)
160+
{
161+
Debug::log("IPv6 is not supported");
162+
return {NetworkAddress::AddressKindInvalid};
163+
}
164+
else
165+
{
166+
firewall_add_udpipv6_endpoint(
167+
address.ipv6, kind.localPort, ntohs(host->port));
168+
}
153169
}
154170
else
155171
{

lib/tcpip/network_wrapper.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ int network_socket_close(Timeout *t, SObj mallocCapability, SObj sealedSocket)
580580
// happen in practice and has no impact for us.
581581
FreeRTOS_shutdown(socket->socket, FREERTOS_SHUT_RDWR);
582582
auto localPort = ntohs(socket->socket->usLocalPort);
583-
if (socket->socket->bits.bIsIPv6)
583+
if (UseIPv6 && socket->socket->bits.bIsIPv6)
584584
{
585585
if (isTCP)
586586
{

0 commit comments

Comments
 (0)