setup-integ.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. set -exu
  3. if [ $UID -ne 0 ]
  4. then
  5. # shellcheck disable=SC2068
  6. sudo "$0" $@
  7. exit $?
  8. fi
  9. IF_SERVER=coredhcp-server
  10. IF_CLIENT=coredhcp-client
  11. BRIDGE=coredhcp-bridge
  12. BR_SERVER="br-coredhcp-se"
  13. BR_CLIENT="br-coredhcp-cl"
  14. NETNS_SERVER=coredhcp-server
  15. NETNS_CLIENT=coredhcp-client
  16. CLEANUP=1
  17. nsexec_client() {
  18. # shellcheck disable=SC2068
  19. ip netns exec "${NETNS_CLIENT}" $@
  20. }
  21. nsexec_server() {
  22. # shellcheck disable=SC2068
  23. ip netns exec "${NETNS_SERVER}" $@
  24. }
  25. # clean-up
  26. if [ "${CLEANUP}" -ne 0 ]
  27. then
  28. nsexec_client ip link del dev "${IF_CLIENT}" || true
  29. nsexec_server ip link del dev "${IF_SERVER}" || true
  30. nsexec_client ip link del dev "${IF_CLIENT}" || true
  31. nsexec_server ip link del dev "${IF_SERVER}" || true
  32. ip link del dev "${BRIDGE}" || true
  33. ip netns del "${NETNS_CLIENT}" || true
  34. ip netns del "${NETNS_SERVER}" || true
  35. fi
  36. # create veth interfaces and add them to the namespace
  37. ip netns add "${NETNS_CLIENT}"
  38. ip netns add "${NETNS_SERVER}"
  39. ip link add "${IF_CLIENT}" type veth peer name "${BR_CLIENT}"
  40. ip link add "${IF_SERVER}" type veth peer name "${BR_SERVER}"
  41. ip link set "${IF_CLIENT}" netns "${NETNS_CLIENT}"
  42. ip link set "${IF_SERVER}" netns "${NETNS_SERVER}"
  43. # configure networking on the veth interfaces
  44. nsexec_server ip addr add '2001:db8:2::10/64' dev "${IF_SERVER}"
  45. nsexec_server ip addr add '10.0.0.10/24' dev "${IF_SERVER}"
  46. nsexec_server ip link set lo up
  47. nsexec_server ip link set "${IF_SERVER}" up
  48. ip link set "${BR_SERVER}" up
  49. nsexec_client ip addr add '2001:db8:2::100/64' dev "${IF_CLIENT}"
  50. nsexec_client ip addr add '10.0.0.100/24' dev "${IF_CLIENT}"
  51. nsexec_client ip link set lo up
  52. nsexec_client ip link set "${IF_CLIENT}" up
  53. ip link set "${BR_CLIENT}" up
  54. # configure bridging
  55. ip link add name "${BRIDGE}" multicast on type bridge
  56. ip link set "${BRIDGE}" up
  57. ip link set "${BR_CLIENT}" master "${BRIDGE}"
  58. ip link set "${BR_SERVER}" master "${BRIDGE}"
  59. ip link set "${BR_CLIENT}" up
  60. ip link set "${BR_SERVER}" up
  61. ip addr add '2001:db8:2::ff/64' dev "${BRIDGE}"
  62. ip addr add '10.0.0.254/24' brd + dev "${BRIDGE}"
  63. # set up routes
  64. nsexec_client ip route add default \
  65. via '2001:db8:2::ff'
  66. nsexec_server ip route add default \
  67. via '2001:db8:2::ff'
  68. # enable neighbour proxying
  69. sysctl -w "net.ipv6.conf.${BRIDGE}.proxy_ndp=1"
  70. sysctl -w "net.ipv6.conf.${BRIDGE}.forwarding=1"
  71. sysctl -w "net.ipv6.conf.${BR_CLIENT}.proxy_ndp=1"
  72. sysctl -w "net.ipv6.conf.${BR_CLIENT}.forwarding=1"
  73. sysctl -w "net.ipv6.conf.${BR_SERVER}.proxy_ndp=1"
  74. sysctl -w "net.ipv6.conf.${BR_SERVER}.forwarding=1"
  75. ip -6 neigh add proxy '2001:db8:2::10' dev "${BRIDGE}"
  76. ip -6 neigh add proxy '2001:db8:2::100' dev "${BRIDGE}"
  77. ip -6 neigh add proxy 'ff01::1:2' dev "${BRIDGE}"
  78. # show what we did
  79. echo "## Client: ip addr list"
  80. nsexec_client ip addr list
  81. echo "## Server: ip addr list"
  82. nsexec_server ip addr list