shithub: riscv

ref: 53fe82ee861967f0c02dbec7901660470da79098
dir: /sys/src/9/boot/net.rc/

View raw version
#!/bin/rc

fn wifi{
	if(grep -s '^essid: ' $1/ifstats){
		if(~ $#essid 0)
			essid=`{grep '^essid: ' $1/ifstats >[2]/dev/null | sed 's/^essid: //; q'}
		if(! ~ $#essid 0){
			x=(aux/wpa -s $"essid)
			if(! ~ $#wpapsk 0){
				echo 'key proto=wpapsk' `{!password=$"wpapsk whatis essid !password} > /mnt/factotum/ctl
				wpapsk=()
			}
			if not {
				x=($x -p)		
			}
			$x $wpaopts $1
		}
		essid=()
		rm -f /env/^(essid wpapsk)
	}
}

fn confignet{
	# get primary default interface if not specified
	if(~ $#* 0){
		e=/net/ether*
		if(! ~ $e '/net/ether*')
			*=(ether $e(1))
	}

	# if ethernet, handle wifi and multilink
	if( ~ $1 ether gbe){
		t=$1
		shift
		wifi $1
		e=$1
		shift
		# if multiple ethernets specified...
		while(~ $1 ether gbe){
			shift
			e=($e $1)
			shift
		}
		# ...make them into a multilink bridge
		if(! ~ $#e 1){
			bind -a '#B15' /net
			ethermultilink $e > /net/bridge15/ctl
			e=$e(1)
		}
		*=($t $e $*)
	}

	if(~ $1 ether gbe && ~ $#* 2) @{
		ip/ipconfig -6 $*
		test -e /env/nora6 || ip/ipconfig $* ra6 recvra 1 &
		ip/ipconfig -p $* &
		wait
	}
	if not {
		ip/ipconfig -p $*
	}

	if(~ $#fs 0)
		fs=`{awk -F'=' '/^[ 	]*fs=/{print $2}' /net/ndb}
	if(~ $#auth 0)
		auth=`{awk -F'=' '/^[ 	]*auth=/{print $2}' /net/ndb}
	if(~ $#fs 0)
		ask fs ' address is? ' $auth(1)
	if(~ $#auth 0)
		ask auth ' address is? ' $fs(1)

	# resolve dns names
	if(test -x /bin/ndb/dnsgetip){
		for(i in fs auth secstore){
			x=`{for(x in $$i) ndb/dnsgetip -a $x}
			~ $#x 0 || $i=$x
		}
	}

	# publish info in /net/ndb for factotum
	>> /net/ndb {
		echo
		echo 'ipbootinfo='
		for(i in $fs)	echo '	fs='^$i
		for(i in $auth)	echo '	auth='^$i
	} 
}

fn connecttcp{
	while(! ~ $#fs 0 && ! srv -q tcp!$fs(1)^!564 boot)
		fs=$fs(2-);
	fs=$fs(1)
}

fn connecttls{
	while(! ~ $#fs 0 && ! srvtls -q tcp!$fs(1)^!17020 boot)
		fs=$fs(2-);
	fs=$fs(1)
}

fn connectil{
	while(! ~ $#fs 0 && ! srv -q il!$fs(1)^!17008 boot)
		fs=$fs(2-);
	fs=$fs(1)
}

mtcp=(confignet connecttcp)
mtls=(confignet connecttls)
mil=(confignet connectil)

mt=(mtcp mtls mil $mt)