Compare commits
5 Commits
e46abbccca
...
d284179272
Author | SHA1 | Date | |
---|---|---|---|
d284179272 | |||
7a4314baee | |||
1bc8fd7873 | |||
dd124e49dd | |||
0b0efde12c |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
*.img
|
||||
*.bin
|
||||
result
|
||||
result
|
||||
result-*
|
@ -50,7 +50,7 @@
|
||||
inherit name;
|
||||
type = "bundle";
|
||||
contents = builtins.map (d: d.name) contents;
|
||||
buildInputs = dependencies ++ (lib.debug.traceSeqN 2 contents contents);
|
||||
buildInputs = dependencies ++ contents;
|
||||
dependencies = builtins.map (d: d.name) dependencies;
|
||||
shell = "${busybox}/bin/sh";
|
||||
builder = ./builder.sh;
|
||||
@ -80,6 +80,6 @@ in {
|
||||
};
|
||||
services = {
|
||||
inherit longrun oneshot bundle target;
|
||||
output = service: name: "/run/services/outputs/${service.name}/${name}";
|
||||
output = service: name: "/run/s6-rc/scandir/${service.name}/data/outputs/${name}";
|
||||
};
|
||||
}
|
||||
|
@ -1,10 +1,57 @@
|
||||
{
|
||||
liminix
|
||||
, busybox
|
||||
, writeShellScript
|
||||
} :
|
||||
let inherit (liminix.services) longrun;
|
||||
let
|
||||
inherit (liminix.services) longrun;
|
||||
script = writeShellScript "udhcp-notify" ''
|
||||
action=$1
|
||||
env > /run/udhcp.values
|
||||
|
||||
set_address() {
|
||||
ip address replace $ip/$mask dev $interface
|
||||
mkdir -p data/outputs
|
||||
for i in lease mask ip router siaddr dns serverid subnet opt53 interface ; do
|
||||
echo ''${!i} > data/outputs/$i
|
||||
done
|
||||
}
|
||||
case $action in
|
||||
deconfig)
|
||||
ip address flush $interface
|
||||
ip link set up dev $interface
|
||||
;;
|
||||
bound)
|
||||
# this doesn't actually replace, it adds a new address.
|
||||
set_address
|
||||
;;
|
||||
renew)
|
||||
set_address
|
||||
;;
|
||||
nak)
|
||||
echo "received NAK on $interface"
|
||||
;;
|
||||
esac
|
||||
'';
|
||||
|
||||
in
|
||||
interface: { ... } @ args: longrun {
|
||||
name = "${interface.device}.udhcp";
|
||||
run = "${busybox}/bin/udhcpc -f -i ${interface.device}";
|
||||
run = "${busybox}/bin/udhcpc -f -i ${interface.device} -s ${script}";
|
||||
}
|
||||
|
||||
# lease=86400
|
||||
# mask=24
|
||||
# ip=10.0.2.15
|
||||
# router=10.0.2.2
|
||||
# siaddr=10.0.2.2
|
||||
# dns=10.0.2.3
|
||||
# serverid=10.0.2.2
|
||||
# subnet=255.255.255.0
|
||||
# SHLVL=2
|
||||
# opt53=05
|
||||
# interface=eth0
|
||||
# PATH=/nix/store/npy692wik809z3vdwrkrj2wixjkr33kp-busybox-mips-unknown-linux-musl-1.35.0/bin:/nix/store/
|
||||
# pj0b27l5728cypa5mmagz0q8ibzpik0h-execline-mips-unknown-linux-musl-2.9.0.1-bin/bin:/nix/store/rfjiw4dnv29daqc9971qmica1h86l0s0-s6-linux-init-mips-unknown-linux-musl-1.0.8.0-bin/bin:/nix/store/4wn3jm7yy2gfi0is0yy75lifbq5zjwz7-s6-rc-mips-unknown-linux-musl-0.5.3.2-bin/bin:/usr/bin:/bin
|
||||
# _=/nix/store/npy692wik809z3vdwrkrj2wixjkr33kp-busybox-mips-unknown-linux-musl-1.35.0/bin/env
|
||||
# /
|
||||
|
@ -3,7 +3,9 @@
|
||||
export DEVICE=${DEVICE-qemu}
|
||||
export TMPDIR=${TMPDIR-/tmp}
|
||||
|
||||
NIX_PATH=liminix=`pwd`:$NIX_PATH
|
||||
|
||||
for i in tests/*/run.sh; do
|
||||
echo $i
|
||||
$i $* || exit 1
|
||||
(cd `dirname $i`; ./`basename $i` $* ) || exit 1
|
||||
done
|
||||
|
@ -1,5 +1,5 @@
|
||||
set -e
|
||||
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build -I liminix-config=./tests/smoke/configuration.nix --arg device "import ./devices/$DEVICE.nix" -A outputs.kernel.vmlinux -o vmlinux $*
|
||||
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '<liminix>' -I liminix-config=../smoke/configuration.nix --arg device "import <liminix/devices/$DEVICE.nix>" -A outputs.kernel.vmlinux -o vmlinux $*
|
||||
|
||||
TESTS=$(cat <<"EOF"
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/service/s6-linux-init-runleveld/notification-fd f 0644 0 0 echo -n "3" |qprint -d
|
||||
/service/s6-linux-init-runleveld/run f 0755 0 0 echo -n " hello=0A newline=0A" |qprint -d
|
||||
/service/s6-linux-init-runleveld/run f 0755 0 0 echo -n "hello=0Aworld=0A" |qprint -d
|
||||
/service/s6-linux-init-runleveld d 0755 0 0
|
||||
/service/s6-linux-init-shutdownd/fifo i 0600 0 0 f
|
||||
/service/s6-linux-init-shutdownd/run f 0755 0 0 echo -n "s6-linux-init/bin/s6-linux-init-shutdownd -c =22/etc/s6-linux-init/current=22 -g 3000=0A" |qprint -d
|
||||
|
@ -2,16 +2,16 @@ set -e
|
||||
|
||||
expr=$(cat <<"EXPR"
|
||||
let
|
||||
overlay = import ./overlay.nix;
|
||||
nixpkgs = import <nixpkgs> ( {overlays = [overlay]; });
|
||||
structure = import ./tests/pseudofiles/structure.nix;
|
||||
overlay = import <liminix/overlay.nix>;
|
||||
nixpkgs = import <nixpkgs> { overlays = [overlay]; };
|
||||
structure = import ./structure.nix;
|
||||
in nixpkgs.pkgs.pseudofile "pseudo.s6-init" structure
|
||||
EXPR
|
||||
)
|
||||
)
|
||||
|
||||
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build -E "${expr}" -o tests/pseudofiles/result $*
|
||||
diff tests/pseudofiles/result tests/pseudofiles/result.expected
|
||||
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build -E "${expr}" -o result $*
|
||||
diff result result.expected
|
||||
test -f /tmp/out.squashfs && rm /tmp/out.squashfs
|
||||
nix-shell -p squashfsTools -p qprint --run "mksquashfs - /tmp/out.squashfs -p '/ d 755 0 0' -pf tests/pseudofiles/result -quiet -no-progress"
|
||||
nix-shell -p squashfsTools -p qprint --run "mksquashfs - /tmp/out.squashfs -p '/ d 755 0 0' -pf result -quiet -no-progress"
|
||||
foo="$(nix-shell -p squashfsTools --run 'unsquashfs -cat /tmp/out.squashfs service/s6-linux-init-runleveld/run')"
|
||||
test "$foo" = "$(printf "hello\nworld")"
|
||||
|
@ -1,14 +1,14 @@
|
||||
set -e
|
||||
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build -I liminix-config=./tests/smoke/configuration.nix --arg device "import ./devices/$DEVICE.nix" -o smoke.img
|
||||
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '<liminix>' -I liminix-config=./configuration.nix --arg device "import <liminix/devices/$DEVICE.nix>" -A outputs.squashfs -o smoke.img $*
|
||||
|
||||
TESTS=$(cat <<"EOF"
|
||||
|
||||
trap 'echo "command $(eval echo $BASH_COMMAND) failed with exit code $?"; exit $?' ERR
|
||||
dest_path=${TMPDIR}/smoke.img-$$
|
||||
echo $dest_path
|
||||
unsquashfs -q -d $dest_path smoke.img
|
||||
unsquashfs -q -d $dest_path -excludes smoke.img /dev
|
||||
cd $dest_path;
|
||||
db=*-s6-rc-db/compiled/
|
||||
db=nix/store/*-s6-rc-db/compiled/
|
||||
test -d $db
|
||||
chmod -R +w $db
|
||||
# check we have closure of config.services (lo.link.service exists only
|
||||
|
28
tests/support/ppp-server/README.md
Normal file
28
tests/support/ppp-server/README.md
Normal file
@ -0,0 +1,28 @@
|
||||
# ppp-server
|
||||
|
||||
To test a router, we need an upstream connection. In this directory,
|
||||
find
|
||||
|
||||
* run.sh, a script that will start a RouterOS image in qemu.
|
||||
Login when prompted, username is "admin", blank password
|
||||
* routeros.config, a set of commands you can feed into routeros
|
||||
to set up PPPoE
|
||||
|
||||
To get the chr-7.5.img image, visit https://mikrotik.com/download and
|
||||
look in the section titled "Cloud Hosted Router" for "Raw disk image"
|
||||
|
||||
You may need to open your firewall a bit to allow multicast packets
|
||||
so that the upstream and the liminix qemu instances may communicate
|
||||
|
||||
config.networking.firewall.extraCommands = ''
|
||||
ip46tables -A nixos-fw -m pkttype --pkt-type multicast -p udp --dport 1234:1236 -j nixos-fw-accept
|
||||
'';
|
||||
|
||||
## To connect to the routeros serial
|
||||
|
||||
The Qemu instance running RouterOS is headless, but it creates
|
||||
two unix sockets for serial port and monitor.
|
||||
|
||||
socat -,raw,echo=0,icanon=0,isig=0,icrnl=0,escape=0x0f tests/support/ppp-server/qemu-console
|
||||
|
||||
socat -,raw,echo=0,icanon=0,isig=0,icrnl=0,escape=0x0f tests/support/ppp-server/qemu-monitor
|
12
tests/support/ppp-server/chr.sh
Executable file
12
tests/support/ppp-server/chr.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env sh
|
||||
/nix/store/ydwiiagdhczynh2lbqh418rglibv93rv-qemu-host-cpu-only-7.0.0/bin/qemu-kvm \
|
||||
-M q35 -display none \
|
||||
-m 1024 \
|
||||
-accel kvm \
|
||||
-daemonize \
|
||||
-serial unix:qemu-console,server,nowait -monitor unix:qemu-monitor,server,nowait \
|
||||
-drive file=chr-7.5.img,format=raw,if=virtio \
|
||||
-netdev socket,id=access,mcast=230.0.0.1:1234 \
|
||||
-device virtio-net-pci,disable-legacy=on,disable-modern=off,netdev=access,mac=ba:ad:1d:ea:11:02 \
|
||||
-netdev socket,id=world,mcast=230.0.0.1:1236 \
|
||||
-device virtio-net-pci,disable-legacy=on,disable-modern=off,netdev=world,mac=ba:ad:1d:ea:11:01
|
24
tests/support/ppp-server/routeros.config
Normal file
24
tests/support/ppp-server/routeros.config
Normal file
@ -0,0 +1,24 @@
|
||||
# sep/23/2022 21:05:02 by RouterOS 7.5
|
||||
# software id =
|
||||
#
|
||||
# run "/export show-sensitive" to recreate this
|
||||
#
|
||||
/interface ethernet
|
||||
set [ find default-name=ether1 ] disable-running-check=no name=access
|
||||
set [ find default-name=ether2 ] disable-running-check=no name=world
|
||||
/disk
|
||||
set sata1 disabled=no
|
||||
/interface wireless security-profiles
|
||||
set [ find default=yes ] supplicant-identity=MikroTik
|
||||
/ip pool
|
||||
add name=pppoe-pool ranges=192.168.100.10-192.168.100.99
|
||||
/port
|
||||
set 0 name=serial0
|
||||
/ppp profile
|
||||
add local-address=192.168.100.1 name=pppoe-profile remote-address=pppoe-pool
|
||||
/interface pppoe-server server
|
||||
add default-profile=pppoe-profile disabled=no interface=access service-name=internet
|
||||
/ip dhcp-client
|
||||
add interface=*1
|
||||
/ppp secret
|
||||
add name=db123@a.1 password=NotReallyTheSecret profile=pppoe-profile service=pppoe
|
Loading…
Reference in New Issue
Block a user