Create VLAN prototype host scripts.

This is intended to be used with the guest_vlans launcher argument.

Bug: 111320496
Test: Ran up/down scripts with and without cuttlefish-common running.
Change-Id: Ia750943510a1096801649e046c0022765a1a140b
diff --git a/tools/vlan_prototype_down.sh b/tools/vlan_prototype_down.sh
new file mode 100755
index 0000000..1db2bf9
--- /dev/null
+++ b/tools/vlan_prototype_down.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+# Delete the host networks for the VLAN prototype.
+# Runs as root.
+# Use at your own risk.
+
+delete_interface() {
+	bridge="$(printf cvd-v${1}br-%02d $2)"
+	tap="$(printf cvd-${1}vlan-%02d $2)"
+	network="${3}.$((4*$2 - 4))/30"
+
+	/sbin/ifconfig "${tap}" down
+	ip link delete "${tap}"
+
+	if [ -f /var/run/cuttlefish-dnsmasq-"${bridge}".pid ]; then
+		kill $(cat /var/run/cuttlefish-dnsmasq-"${bridge}".pid)
+	fi
+
+	iptables -t nat -D POSTROUTING -s "${network}" -j MASQUERADE
+
+	/sbin/ifconfig "${bridge}" down
+	/sbin/brctl delbr "${bridge}"
+}
+
+delete_interface w 1 192.168.93
+delete_interface m 1 192.168.94
+delete_interface i 1 192.168.95
+
+ip link delete cvd-net-01
diff --git a/tools/vlan_prototype_up.sh b/tools/vlan_prototype_up.sh
new file mode 100755
index 0000000..fbeef40
--- /dev/null
+++ b/tools/vlan_prototype_up.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+# Create the host networks for the VLAN prototype.
+# Runs as root.
+# Use at your own risk.
+
+create_interface() {
+	bridge="$(printf cvd-v${1}br-%02d $2)"
+	tap="$(printf cvd-${1}vlan-%02d $2)"
+	gateway="${3}.$((4*$2 - 3))"
+	network="${3}.$((4*$2 - 4))/30"
+	netmask="255.255.255.252"
+	dhcp_range="${3}.$((4*$2 - 2)),${3}.$((4*$2 - 2))"
+
+	/sbin/brctl addbr "${bridge}"
+	/sbin/brctl stp "${bridge}" off
+	/sbin/brctl setfd "${bridge}" 0
+	/sbin/ifconfig "${bridge}" "${gateway}" netmask "${netmask}" up
+
+	iptables -t nat -A POSTROUTING -s "${network}" -j MASQUERADE
+
+	dnsmasq \
+	--strict-order \
+	--except-interface=lo \
+	--interface="${bridge}" \
+	--listen-address="${gateway}" \
+	--bind-interfaces \
+	--dhcp-range="${dhcp_range}" \
+	--conf-file="" \
+	--pid-file=/var/run/cuttlefish-dnsmasq-"${bridge}".pid \
+	--dhcp-leasefile=/var/run/cuttlefish-dnsmasq-"${bridge}".leases \
+	--dhcp-no-override
+
+	ip link add link cvd-net-01 name "${tap}" type vlan id ${4}
+	/sbin/ifconfig "${tap}" 0.0.0.0 up
+	/sbin/brctl addif "${bridge}" "${tap}"
+}
+
+ip tuntap add dev cvd-net-01 mode tap group cvdnetwork
+ifconfig cvd-net-01 0.0.0.0 up
+
+create_interface w 1 192.168.93 11
+create_interface m 1 192.168.94 12
+create_interface i 1 192.168.95 13