GNS3 Docker Images
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

68 lines
2.2 KiB

  1. #!/bin/sh
  2. #
  3. # Startup script for Open vSwitch
  4. #
  5. # Copyright (C) 2015 GNS3 Technologies Inc.
  6. # Copyright (C) 2019 Bernhard Ehlers
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. cust_init="/etc/openvswitch/init.sh"
  21. export PATH="$PATH:/usr/share/openvswitch/scripts"
  22. if [ ! -f "/etc/openvswitch/conf.db" ]; then
  23. # init database and start the daemons
  24. cat /proc/sys/kernel/random/uuid > /etc/openvswitch/system-id.conf
  25. ovs-ctl --system-id=random start
  26. # add bridges br0..br3
  27. x=0
  28. while [ $x -lt 4 ]; do
  29. ovs-vsctl add-br br$x
  30. ovs-vsctl set bridge br$x datapath_type=netdev
  31. x=$((x+1))
  32. done
  33. # add eth interfaces without network configuration to br0
  34. sed -n 's/^ *\(eth[0-9]*\):.*/\1/p' /proc/net/dev | while read -r if; do
  35. ofport=${if#eth}
  36. [ "$ofport" -eq 0 ] && ofport=1000
  37. grep -q -s -E \
  38. "^[[:blank:]]*iface[[:blank:]]+${if}[[:blank:].:]" \
  39. /etc/network/interfaces || \
  40. ovs-vsctl add-port br0 "$if" -- \
  41. set interface "$if" ofport_request="$ofport"
  42. done
  43. else
  44. # use existing database and start the daemons
  45. ovs-ctl --system-id=random start
  46. fi
  47. # activate internal bridge interfaces
  48. ovs-vsctl --bare -f table --columns=name find interface type=internal | while read -r if; do
  49. ip link set dev "$if" up
  50. done
  51. # configure non-lo/eth interfaces of /etc/network/interfaces
  52. sed -n -E -e '/^[[:blank:]]*iface[[:blank:]]+(lo|eth)/d' \
  53. -e 's/^[[:blank:]]*iface[[:blank:]]+([a-zA-Z][^[:blank:]]*).*/\1/p' \
  54. /etc/network/interfaces | \
  55. while read -r if; do
  56. ifup -f "$if"
  57. done
  58. # run custom initialization script
  59. [ -f "$cust_init" ] && [ -x "$cust_init" ] && "$cust_init"