mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-12 15:39:00 +08:00
Merge pull request #1886 from jfsimon1981/master
Release MIP tests using tuntap
This commit is contained in:
commit
5d712b6f54
5
.github/workflows/test.yml
vendored
5
.github/workflows/test.yml
vendored
@ -9,8 +9,8 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
cc: [gcc, clang, g++, clang++]
|
||||
# target: [test, mip_test]
|
||||
target: [test]
|
||||
target: [test, mip_test]
|
||||
# target: [test]
|
||||
ssl: [MBEDTLS, OPENSSL]
|
||||
name: linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }}
|
||||
env:
|
||||
@ -18,6 +18,7 @@ jobs:
|
||||
SSL: ${{ matrix.ssl }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: ./test/setup_ga_network.sh
|
||||
- run: sudo apt-get update ; sudo apt-get install libmbedtls-dev
|
||||
- run: make ${{ matrix.target }}
|
||||
s390:
|
||||
|
@ -183,14 +183,25 @@ static void test_http_fetch(void) {
|
||||
// Zero init fields required (C/C++ style diverge)
|
||||
#ifndef __cplusplus
|
||||
struct mip_driver driver = {.tx = tap_tx, .up = tap_up, .rx = tap_rx};
|
||||
struct mip_if mif = {.use_dhcp = true, .driver = &driver, .driver_data = &fd};
|
||||
// DHCP
|
||||
// struct mip_if mif = {.use_dhcp = true, .driver = &driver, .driver_data = &fd};
|
||||
// Static
|
||||
// 192.168.32.2/24 gw 192.168.32.1
|
||||
struct mip_if mif = {.use_dhcp = false, \
|
||||
.ip=0x0220a8c0 , .mask=0x00ffffff, .gw=0x0120a8c0, \
|
||||
.driver = &driver, .driver_data = &fd};
|
||||
|
||||
#else
|
||||
struct mip_driver driver {};
|
||||
driver.tx = tap_tx;
|
||||
driver.up = tap_up;
|
||||
driver.rx = tap_rx;
|
||||
struct mip_if mif {};
|
||||
mif.use_dhcp = true;
|
||||
// mif.use_dhcp = true; // DHCP
|
||||
mif.use_dhcp = false; // Static IP
|
||||
mif.ip = 0x0220a8c0; // 192.168.32.2
|
||||
mif.mask = 0x00ffffff; // 255.255.255.0
|
||||
mif.gw = 0x0120a8c0; // 192.168.32.1
|
||||
mif.driver = &driver;
|
||||
mif.driver_data = &fd;
|
||||
#endif
|
||||
@ -201,17 +212,19 @@ static void test_http_fetch(void) {
|
||||
mip_init(&mgr, &mif);
|
||||
MG_INFO(("Init done, starting main loop"));
|
||||
|
||||
// DHCP lease
|
||||
// Stack initialization, Network configuration (DHCP lease, ...)
|
||||
{
|
||||
if (mif.ip) printf("MIF configuration error: not configured for DHCP\n");
|
||||
ASSERT(!mif.ip); // Check we are set for DHCP
|
||||
if (mif.ip) MG_INFO(("MIF configuration: Static IP"));
|
||||
else MG_INFO(("MIF configuration: DHCP"));
|
||||
MG_INFO(("Opened TAP interface: %s", iface));
|
||||
// ASSERT(!mif.ip); // Check we are set for DHCP
|
||||
int pc = 500; // Timout on DHCP lease 500 ~ approx 5s (typical delay <1s)
|
||||
while (((pc--)>0)/* & !mif.ip*/) {
|
||||
while (((pc--)>0) /*& !mif.ip*/) {
|
||||
mg_mgr_poll(&mgr, 100);
|
||||
usleep(10000); // 10 ms
|
||||
}
|
||||
if (!mif.ip) printf("DHCP lease failed.\n");
|
||||
ASSERT(mif.ip); // We have a received lease
|
||||
if (!mif.ip) printf("No ip assigned (DHCP lease may have failed).\n");
|
||||
ASSERT(mif.ip); // We have an IP (lease or static)
|
||||
}
|
||||
|
||||
// Simple HTTP fetch
|
||||
@ -250,6 +263,6 @@ int main(void) {
|
||||
test_queue();
|
||||
test_statechange();
|
||||
test_http_fetch();
|
||||
printf("SUCCESS\n");
|
||||
printf("SUCCESS. Total tests: %d\n", s_num_tests);
|
||||
return 0;
|
||||
}
|
||||
|
55
test/setup_ga_network.sh
Executable file
55
test/setup_ga_network.sh
Executable file
@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
|
||||
# see our network configuration
|
||||
echo "Network configuration:"
|
||||
timeout 1s ifconfig
|
||||
timeout 1s sudo route -n # see our gateway
|
||||
timeout 1s bridge link
|
||||
timeout 1s bridge fdb
|
||||
echo
|
||||
|
||||
echo "Network configuration script: Bridge"
|
||||
BRIDGE=mg_bridge0
|
||||
BRIDGE_IP=192.168.32.1
|
||||
BRIDGE_MASK=255.255.255.0
|
||||
BRIDGE_IP_MASK=192.168.32.0/24
|
||||
BRIDGE_BROADCAST=192.168.32.255
|
||||
PHY=eth0
|
||||
TAP=tap0
|
||||
|
||||
sudo ip link add $BRIDGE type bridge # Create brige
|
||||
sudo ifconfig $BRIDGE $BRIDGE_IP netmask $BRIDGE_MASK up
|
||||
echo "Network configuration script: TAP"
|
||||
|
||||
echo "Create $TAP"
|
||||
sudo ip tuntap add dev $TAP mode tap # Create tuntap
|
||||
sudo ip link set $TAP master $BRIDGE # Link tap-bridge
|
||||
sudo ip link set $TAP up
|
||||
echo "Network configuration script: NAT"
|
||||
|
||||
sudo iptables -A FORWARD -d $BRIDGE_IP_MASK -o $BRIDGE -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
|
||||
sudo iptables -A FORWARD -s $BRIDGE_IP_MASK -i $BRIDGE -j ACCEPT
|
||||
sudo iptables -A FORWARD -i $BRIDGE -o $BRIDGE -j ACCEPT
|
||||
sudo iptables -A FORWARD -o $BRIDGE -j REJECT --reject-with icmp-port-unreachable
|
||||
sudo iptables -A FORWARD -i $BRIDGE -j REJECT --reject-with icmp-port-unreachable
|
||||
sudo iptables -t nat -A POSTROUTING -s $BRIDGE_IP_MASK -d 224.0.0.0/24 -j RETURN
|
||||
sudo iptables -t nat -A POSTROUTING -s $BRIDGE_IP_MASK -d 255.255.255.255/32 -j RETURN
|
||||
sudo iptables -t nat -A POSTROUTING -s $BRIDGE_IP_MASK ! -d $BRIDGE_IP_MASK -p tcp -j MASQUERADE --to-ports 1024-65535
|
||||
sudo iptables -t nat -A POSTROUTING -s $BRIDGE_IP_MASK ! -d $BRIDGE_IP_MASK -p udp -j MASQUERADE --to-ports 1024-65535
|
||||
sudo iptables -t nat -A POSTROUTING -s $BRIDGE_IP_MASK ! -d $BRIDGE_IP_MASK -j MASQUERADE
|
||||
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
|
||||
|
||||
# Do we have connectivity ?
|
||||
echo "Check connectivity:"
|
||||
wget https://cesanta.com/robots.txt
|
||||
echo robots.txt:
|
||||
cat robots.txt
|
||||
rm robots.txt
|
||||
echo
|
||||
|
||||
# Confirm OK
|
||||
echo "Done:"
|
||||
timeout 1s ifconfig
|
||||
timeout 1s sudo route -n
|
||||
timeout 1s bridge fdb
|
||||
timeout 1s bridge link
|
Loading…
Reference in New Issue
Block a user