# $Id: Makefile.multinode-NetBSD,v 1.5 2024/11/11 17:58:20 wiz Exp $
# Source: http://mail-index.NetBSD.org/netbsd-help/2005/03/25/0005.html
#
# Starts up two qemu instances and networks bridges them to the local
# ethernet (ETHER_IF}.  Works best with NetBSD configured to use serial
# consoles in DISK[12]
#
# Usage:
#	sudo make netbsd1
#	sudo make netbsd2
#
#  - Hubert Feyrer <hubert@feyrer.de>
#

#NETBSD_NOGFX=
NETBSD_NOGFX=		-nographic

ETHER_IF=	tlp0
QEMU_RAM=	20
DISK1=		harddisk.netbsd1
DISK2=		harddisk.netbsd2


all: netbsd1 netbsd2

netbsd1: bridge 
	ifconfig tap1 create up	     || echo tap1: already there
	brconfig bridge0 add tap1 up || echo tap1: already on bridge0
	brconfig bridge0 -learn tap1 # real hub mode, step 1b
	brconfig bridge0 flush	# real hub mode, step 2
	qemu \	
		-m ${QEMU_RAM} \
		${NETBSD_NOGFX} \
		-boot c \
		-net tap,fd=3,ifname=tap1 3<>/dev/tap1 \
		-net nic,macaddr=de:ad:be:ef:00:01 \
		${DISK1}
	brconfig bridge0 delete tap1 
	ifconfig tap1 destroy

netbsd2: bridge
	ifconfig tap2 create up	     || echo tap2: already there
	brconfig bridge0 add tap2 up || echo tap2: already on bridge0
	brconfig bridge0 -learn tap2 # real hub mode, step 1c
	brconfig bridge0 flush	     # real hub mode, step 2
	qemu \
		-m ${QEMU_RAM} \
		${NETBSD_NOGFX} \
		-boot c \
		-net tap,fd=3,ifname=tap2 3<>/dev/tap2 \
		-net nic,macaddr=de:ad:be:ef:00:02 \
		${DISK2}
	brconfig bridge0 delete tap2
	ifconfig tap2 destroy
	
bridge:
	ifconfig bridge0 create	  || echo bridge0: already there
	brconfig bridge0 add ${ETHER_IF} || echo bridge0: ${ETHER_IF} already there
	brconfig bridge0 -learn ${ETHER_IF} # real hub mode, step 1a
