#!/bin/sh

set -eu

prefix="10.1"
count="${1:-$(nproc)}"

for net in $(seq 1 $count); do
	ns="newpid$net"
	veth="veth$net"
	ceth="ceth$net"

	ip netns add $ns 2> /dev/null || :

	ip link del $veth 2> /dev/null || :
	ip link add $veth type veth peer name $ceth
	ip link set $ceth netns $ns
	ip a add $prefix.$net.1/24 dev $veth
	ip link set $veth up
	ip netns exec $ns ip link set lo up
	ip netns exec $ns ip a add $prefix.$net.2/24 dev $ceth
	ip netns exec $ns ip link set $ceth up
	ip netns exec $ns ip r add default via $prefix.$net.1
done

# forwarding and masquerading handled in ferm.conf
