#!/bin/sh #---------------------------------------------------------------------------- # /etc/rc.d/circuits.net - net circuits # # Last Update: $Id$ #---------------------------------------------------------------------------- # $1 = circuit information file # $2 = variable receiving an error message (if any) net_circuit_add() { circ_dev=$(circuit_get_interface $circ_net_if) if [ -z "$circ_dev" ] then eval $2=\"could not translate interface \$circ_net_if\" return 1 fi circuit_allocate_device net circ_alias cat >> $1 </dev/null fi return 0 } # Input: # $1 = circuit identifier # $2 = layer-3 protocol # $3 = operation: "change" or "down" # Exit code: # (when operation is "down") # 0 if at least one address has been removed, 1 otherwise net_circuit_change() { local id=$1 l3prot=$2 op=$3 circ_dev circ_net_address old new addr circuit_read_field $id circ_dev circuit_read_field $id circ_net_address_${l3prot} circ_net_address case $op in change) circuit_lock $id net_circuit_change circuit_read_field $id circ_net_address_${l3prot}_resolved old new=$(circuit_resolve_address $circ_net_address $l3prot) circuit_write_field $id circ_net_address_${l3prot}_resolved "$new" circuit_unlock $id net_circuit_change for addr in $(list_unique $(list_sub "$old" $new)) do net_circuit_remove_address_$l3prot $id $circ_dev $addr done for addr in $(list_unique $(list_sub "$new" $old)) do net_circuit_add_address_$l3prot $id $circ_dev $addr done ;; down) circuit_lock $id net_circuit_change circuit_read_field $id circ_net_address_${l3prot}_resolved old circuit_write_field $id circ_net_address_${l3prot}_resolved "" circuit_unlock $id net_circuit_change for addr in $old do net_circuit_remove_address_$l3prot $id $circ_dev $addr done [ -n "$old" ] ;; esac } # Input: # $1 = identifier of circuit adding/removing a prefix # $2 = layer-3 protocol net_circuit_prefix_change() { local id=$1 l3prot=$2 circ type addr for circ in $(circuit_get_by_state ready semionline online) do circuit_read_field $circ circ_type type if [ "$type" = "net" ] then circuit_read_field $circ circ_net_address_${l3prot} addr if list_is_in $id $(circuit_get_address_dependees "$addr") then net_circuit_change $circ $l3prot change fi fi done }