#!/bin/bash

pickup_defaults
init_netprofile
pickup_options

is_no "$IFUP_PARENTS" || \
	: ${HOST:?HOST must be set for $NAME}

if profiled_filename PROF_BRCTL "$MYIFACEDIR/brctl"; then
	print_error "ignoring brctl-style options in $PROF_BRCTL"
fi

[ -x "${BRIDGE:=$DEFAULT_BRIDGE}" ] || {
	print_error "$BRIDGE does not exist or is not executable. Try installing iproute2 RPM."
	exit 1
}

$IP link add $NAME type bridge
$IP link set $NAME type bridge $BRIDGE_OPTIONS

is_yes "$VLAN_AWARE" && {
	[ -f /sys/class/net/$NAME/bridge/vlan_filtering ] && {
		printf '%s' 1 > /sys/class/net/$NAME/bridge/vlan_filtering && print_progress
	}
}

for host in $HOST; do
	$IP link set $host master $NAME && print_progress
	is_yes "$VLAN_AWARE" && {
		if [ -n "$VIDS" ]; then
			for vid in $VIDS; do
				$BRIDGE vlan add dev $host vid $vid && print_progress
			done
		fi
	}
done

exit 0
