Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # You don't usually need to touch this file at all, the full configuration
  4. # of the bridge can be done in a standard way on /etc/network/interfaces.
  5.  
  6. # Have a look at /usr/share/doc/bridge-utils/README.Debian.gz if you want
  7. # more info about the way on wich a bridge is set up on Debian.
  8.  
  9. if [ ! -x /usr/sbin/brctl ]
  10. then
  11. exit 0
  12. fi
  13.  
  14. case "$IF_BRIDGE_PORTS" in
  15. "")
  16. exit 0
  17. ;;
  18. none)
  19. INTERFACES=""
  20. ;;
  21. *)
  22. INTERFACES="$IF_BRIDGE_PORTS"
  23. ;;
  24. esac
  25.  
  26. brctl addbr $IFACE &&
  27.  
  28. for i in $INTERFACES
  29. do
  30. if [ "$i" = "all" ]; then
  31. i=$(grep eth /proc/net/dev|sed 's/\(\ *\)\(eth[^:]*\)\(.*\)/\2/')
  32. fi
  33. for port in $i
  34. do
  35. if [ -x /etc/network/if-pre-up.d/vlan ]; then
  36. env IFACE=$port /etc/network/if-pre-up.d/vlan
  37. fi
  38. if [ "$IF_BRIDGE_HW" ]
  39. then
  40. ifconfig $port down; ifconfig $port hw ether $IF_BRIDGE_HW
  41. fi
  42. brctl addif $IFACE $port && ifconfig $port 0.0.0.0 up
  43. done
  44. done
  45.  
  46. if [ "$IF_BRIDGE_AGEING" ]
  47. then
  48. brctl setageing $IFACE $IF_BRIDGE_AGEING
  49. fi
  50.  
  51. if [ "$IF_BRIDGE_BRIDGEPRIO" ]
  52. then
  53. brctl setbridgeprio $IFACE $IF_BRIDGE_BRIDGEPRIO
  54. fi
  55.  
  56. if [ "$IF_BRIDGE_FD" ]
  57. then
  58. brctl setfd $IFACE $IF_BRIDGE_FD
  59. fi
  60.  
  61. if [ "$IF_BRIDGE_GCINT" ]
  62. then
  63. brctl setgcint $IFACE $IF_BRIDGE_GCINT
  64. fi
  65.  
  66. if [ "$IF_BRIDGE_HELLO" ]
  67. then
  68. brctl sethello $IFACE $IF_BRIDGE_HELLO
  69. fi
  70.  
  71. if [ "$IF_BRIDGE_MAXAGE" ]
  72. then
  73. brctl setmaxage $IFACE $IF_BRIDGE_MAXAGE
  74. fi
  75.  
  76. if [ "$IF_BRIDGE_PATHCOST" ]
  77. then
  78. brctl setpathcost $IFACE $IF_BRIDGE_PATHCOST
  79. fi
  80.  
  81. if [ "$IF_BRIDGE_PORTPRIO" ]
  82. then
  83. brctl setportprio $IFACE $IF_BRIDGE_PORTPRIO
  84. fi
  85.  
  86. if [ "$IF_BRIDGE_STP" ]
  87. then
  88. brctl stp $IFACE $IF_BRIDGE_STP
  89. fi
  90.  
  91.  
  92. ifconfig $IFACE 0.0.0.0 up
  93.  
  94.  
  95. if [ "$IF_BRIDGE_MAXWAIT" ]
  96. then
  97. MAXWAIT=$IF_BRIDGE_MAXWAIT
  98. else
  99. MAXWAIT=$(brctl showstp $IFACE|sed -n 's/^.*forward delay[ ]*\(.*\)\..*bridge forward delay[ ]*\(.*\)\..*$/\1 \2/p')
  100. if [ "$MAXWAIT" ]
  101. then
  102. if [ ${MAXWAIT% *} -gt ${MAXWAIT#* } ]
  103. then
  104. MAXWAIT=$((2*(${MAXWAIT% *}+1)))
  105. else
  106. MAXWAIT=$((2*(${MAXWAIT#* }+1)))
  107. fi
  108. else
  109. if [ "$IF_BRIDGE_FD" ]
  110. then
  111. MAXWAIT=$((2*(${IF_BRIDGE_FD%.*}+1)))
  112. else
  113. MAXWAIT=32
  114. fi
  115. /bin/echo -e "\nWaiting $MAXWAIT seconds for $IFACE to get ready."
  116. sleep $MAXWAIT
  117. MAXWAIT=0
  118. fi
  119. fi
  120.  
  121. if [ "$MAXWAIT" != 0 ]
  122. then
  123. /bin/echo -e "\nWaiting for $IFACE to get ready (MAXWAIT is $MAXWAIT seconds)."
  124.  
  125. unset BREADY
  126. COUNT=0
  127.  
  128. while [ ! "$BREADY" -a $COUNT -lt $MAXWAIT ]
  129. do
  130. sleep 1
  131. COUNT=$(($COUNT+1))
  132. BREADY=true
  133. for i in $(brctl showstp $IFACE|sed -n 's/^.*port id.*state[ ]*\(.*\)$/\1/p')
  134. do
  135. if [ "$i" != "forwarding" -a "$i" != "blocking" ]
  136. then
  137. unset BREADY
  138. fi
  139. done
  140. done
  141.  
  142. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement