"Fossies" - the Fresh Open Source Software Archive

Member "open-fcoe-3.19/fcoe-utils/contrib/fcoe-setup.sh" (15 Apr 2015, 1627 Bytes) of package /linux/misc/open-fcoe-3.19.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/bash
    2 #
    3 # fcoe-setup.sh
    4 #
    5 # Create VLAN interface for FCoE
    6 #
    7 
    8 scan_vlan() {
    9     local ifname=$1
   10     local vlan=$2
   11 
   12     cat /proc/net/vlan/config | tail +3 | while read vif s1 vid s2 if ; do
   13     if [ "$if" = "$ifname" ] && [ "$vid" == "$vlan" ] ; then
   14         echo "$vif"
   15     fi
   16     done
   17 }
   18 
   19 create_vlan () {
   20     local ifname=$1
   21     local vlan=$2
   22     local vif
   23 
   24     vif=$(scan_vlan $ifname $vlan)
   25 
   26     if [ -z "$vif" ] ; then
   27         vif="$ifname.$vlan"
   28         ip link add dev $vif link $ifname type vlan id $vlan
   29     fi
   30     ip link set $vif up
   31     echo "$vif"
   32 }
   33 
   34 check_ifcfg () {
   35     local vif=$1
   36     local ifname=$2
   37     local vid=$3
   38     local ifcfg=/etc/sysconfig/network/ifcfg-$vif
   39 
   40     if [ -f "$ifcfg" ] ; then
   41     echo "Interface is configured properly"
   42     else
   43     echo "Creating ifcfg configuration ifcfg-$vif"
   44     cat > $ifcfg <<EOF
   45 BOOTPROTO="static"
   46 STARTMODE="onboot"
   47 ETHERDEVICE="$ifname"
   48 USERCONTROL="no"
   49 INTERFACETYPE="vlan"
   50 EOF
   51     fi
   52 }
   53 
   54 check_fcoe () {
   55     local vif=$1
   56     local fcoecfg=/etc/fcoe/cfg-$vif
   57 
   58     if [ -f "$fcoecfg" ] ; then
   59     echo "FCoE is configured properly"
   60     else
   61     echo "Creating FCoE configuration cfg-$vif"
   62     cat > $fcoecfg <<EOF
   63 FCOE_ENABLE="yes"
   64 DCB_REQUIRED="yes"
   65 EOF
   66     fi
   67 }
   68 
   69 ifname=$1
   70 if [ -z "$ifname" ] ; then
   71     echo "No Interface given!"
   72     exit 1
   73 fi
   74 if [ ! -d /sys/class/net/$ifname ] ; then
   75     echo "Interface $ifname does not exist!"
   76     exit 2
   77 fi
   78 
   79 fipvlan -i $ifname | while read ifname vlan; do
   80     echo "Found FCF forwarder on VLAN $vlan"
   81     vif=$(create_vlan $ifname $vlan)
   82     echo "Using VLAN interface $vif"
   83     check_ifcfg $vif $ifname $vlan
   84     check_fcoe $vif
   85 done
   86 
   87 exit 0