Fix some neats, add IPv6 basic testing in LAN

This commit is contained in:
Sergio R. Caprile committed 2026-06-12 16:20:39 -03:00
1 parent 6b589b6900
commit 2006f8302a
11 files changed
+157 -89

No files matched your search

+35 -5
View File
@@ -219,7 +219,12 @@ static int fetch(struct mg_mgr *mgr, char *buf, const char *url,
static void test_http_client(struct mg_mgr *mgr) {
char buf[FETCH_BUF_SIZE];
int rc = 0;
const bool ipv6 = MG_ENABLE_IPV6;
const bool ipv6 =
#ifdef IPV6_NOROUTING
0; // GitHub does not route IPv6 (as far as I can tell)
#else
MG_ENABLE_IPV6;
#endif
#if MG_TLS
if (ipv6) {
rc = fetch(mgr, buf, "https://ipv6.google.com",
@@ -350,6 +355,7 @@ static void test_mqtt_connsubpub(struct mg_mgr *mgr) {
data.url = strdup(MQTT_URL);
#endif
#endif // MG_TLS
mg_mgr_poll(mgr, 0); // update interface timing
s_conn = mg_mqtt_connect(mgr, data.url, &opts, mqtt_fn, &data);
ASSERT(s_conn != NULL);
for (int i = 0; i < 1000 && s_conn != NULL && !s_conn->is_closing; i++) {
@@ -359,16 +365,40 @@ static void test_mqtt_connsubpub(struct mg_mgr *mgr) {
ASSERT(data.passed);
mg_mgr_poll(mgr, 0);
free(data.url);
#if 0
#if defined(MQTT_HOST) && MG_ENABLE_IPV6
#if MG_ENABLE_IPV6 && defined(MQTT_HOST) && MG_TLS != MG_TLS_BUILTIN
if (host_ip6 == NULL) {
printf("\nMQTT_HOST defined but no HOST_IPV6 provided, skipping MQTT IPV6 tests\n");
return;
}
printf("HOST_IPV6: %s\n", host_ip6);
data.url = mg_mprintf("mqtt://[%s]:1883", host_ip6);
#if MG_TLS
#if MG_TLS != MG_TLS_BUILTIN
#if defined(MQTT_HOST)
data.url = mg_mprintf("mqtts://[%s]:8883", host_ip6);
#else
printf("\nMQTT[S] tests over IPv6 require MQTT_HOST, skipping\n");
return;
//data.url = strdup(MQTTS_URL);
#endif
#else // MG_TLS != MG_TLS_BUILTIN
#if defined(MQTT_HOST)
printf("\nAssuming MQTT_HOST is NOT 1.3, ignoring it for MQTTS tests\n");
printf("\nMQTT[S] tests over IPv6 require MQTT_HOST, skipping\n");
return;
#endif
printf("\nMQTT[S] tests over IPv6 require MQTT_HOST, skipping\n");
return;
//data.url = strdup(MQTTS_URL);
#endif
#else // MG_TLS
#ifdef MQTT_HOST
data.url = mg_mprintf("mqtt://[%s]:1883", host_ip6);
#else
printf("\nMQTT[S] tests over IPv6 require MQTT_HOST, skipping\n");
return;
//data.url = strdup(MQTT_URL);
#endif
#endif // MG_TLS
data.passed = false;
s_conn = mg_mqtt_connect(mgr, data.url, &opts, mqtt_fn, &data);
ASSERT(s_conn != NULL);
+11
View File
@@ -0,0 +1,11 @@
interface mg_bridge0
{
AdvSendAdvert on;
AdvRASrcAddress {
fe80::01ff:fe02:0301;
};
prefix 2001:db8:1:0::/64 {
AdvOnLink on;
AdvAutonomous on;
};
};
+31 -14
View File
@@ -1,10 +1,14 @@
#!/bin/sh
# Use separate addresses for gateway, DHCP, and host, in order to force using ARP and ND
BRIDGE=mg_bridge0
BRIDGE_BROADCAST=192.168.32.255
BRIDGE_IP=192.168.32.1
BRIDGE_IP=192.168.32.2
BRIDGE_NETWORK=192.168.32.0/24
BRIDGE_MASK=255.255.255.0
BRIDGE_IPV6=fe80::01ff:fe02:0301
GATEWAY_IP=192.168.32.1 # dhcp.conf serves 192.168.32.1 as gateway
HOST_IP=192.168.32.3
BRIDGE_IPV6=fe80::01ff:fe02:0301 # radvd.conf uses this address as its own
HOST_IPV6=fe80::01ff:fe02:0303
# Host outside network interface is 'eth0'
TAP=tap0
@@ -14,20 +18,26 @@ timeout 1s ifconfig
timeout 1s sudo route -n # see our gateway
timeout 1s bridge link
timeout 1s bridge fdb
timeout 1s sudo ip -6 route show
echo
# Package installation
echo "Package installation"
sudo apt-get -y install isc-dhcp-server net-tools
# sudo apt-get -y install build-essential sshpassecho "Network configuration script: Bridge"
sudo apt-get -y install isc-dhcp-server net-tools radvd
sudo systemctl stop radvd # just in case they think it is cool to start it
# sudo apt-get -y install build-essential sshpass
echo
echo "Network configuration script: Bridge"
sudo ip link add $BRIDGE type bridge # Create brige
sudo ifconfig $BRIDGE $BRIDGE_IP netmask $BRIDGE_MASK up
sudo ifconfig $BRIDGE:1 $GATEWAY_IP netmask $BRIDGE_MASK up
sudo ifconfig $BRIDGE:2 $HOST_IP netmask $BRIDGE_MASK up
sudo ip -6 addr add $BRIDGE_IPV6/64 dev $BRIDGE
sudo ip -6 addr add $HOST_IPV6/64 dev $BRIDGE:1
echo
echo "Network configuration script: TAP"
sudo ip link add $BRIDGE type bridge # Create brige
sudo ifconfig $BRIDGE $BRIDGE_IP netmask $BRIDGE_MASK up
sudo ip -6 addr add $BRIDGE_IPV6/64 dev $BRIDGE
echo
echo "Create $TAP attached to $BRIDGE"
sudo ip tuntap add dev $TAP mode tap # Create tuntap
sudo ip link set $TAP master $BRIDGE # Link tap-bridge
@@ -51,12 +61,11 @@ echo
HOST_IFC=$BRIDGE
export HOST_IFC
echo "Host inside network interface is $BRIDGE"
echo
# Setup DHCP server
echo "Network configuration script: DHCP server"
echo "Serving from $BRIDGE_IP"
HOST_IP=$BRIDGE_IP
export HOST_IP
echo "Serving from $BRIDGE_IP, gateway should be $GATEWAY_IP"
echo "dhcpd.conf:"
cat test/dhcpd.conf
echo
@@ -64,9 +73,14 @@ sudo cp test/dhcpd.conf /etc/dhcp/dhcpd.conf
sudo chmod a+w /var/lib/dhcp/*
sudo dhcpd mg_bridge0 &
echo
HOST_IPV6=$BRIDGE_IPV6
echo "radvd listening at $BRIDGE_IPV6"
sudo ip link set $BRIDGE up # there's no physical port, so we need to set link up for radvd to work
sudo radvd -n -d 5 -C test/radvd.conf &
echo
echo "Host listening at $HOST_IP and $HOST_IPV6"
export HOST_IP
export HOST_IPV6
echo "Listening at $BRIDGE_IPV6"
echo
# Do we have connectivity ?
echo "Check connectivity:"
@@ -74,6 +88,8 @@ wget https://cesanta.com/robots.txt
echo robots.txt:
cat robots.txt
rm robots.txt
wget https://ipv6.google.com/
rm index.html
echo
# Confirm OK
@@ -82,3 +98,4 @@ timeout 1s ifconfig
timeout 1s sudo route -n
timeout 1s bridge fdb
timeout 1s bridge link
timeout 1s sudo ip -6 route show