vxlan.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/bin/sh
  2. [ -n "$INCLUDE_ONLY" ] || {
  3. . /lib/functions.sh
  4. . /lib/functions/network.sh
  5. . ../netifd-proto.sh
  6. init_proto "$@"
  7. }
  8. vxlan_generic_setup() {
  9. local cfg="$1"
  10. local mode="$2"
  11. local local="$3"
  12. local remote="$4"
  13. local link="$cfg"
  14. local port vid ttl tos mtu macaddr zone rxcsum txcsum
  15. json_get_vars port vid ttl tos mtu macaddr zone rxcsum txcsum
  16. proto_init_update "$link" 1
  17. proto_add_tunnel
  18. json_add_string mode "$mode"
  19. [ -n "$tunlink" ] && json_add_string link "$tunlink"
  20. [ -n "$local" ] && json_add_string local "$local"
  21. [ -n "$remote" ] && json_add_string remote "$remote"
  22. [ -n "$ttl" ] && json_add_int ttl "$ttl"
  23. [ -n "$tos" ] && json_add_string tos "$tos"
  24. [ -n "$mtu" ] && json_add_int mtu "$mtu"
  25. json_add_object 'data'
  26. [ -n "$port" ] && json_add_int port "$port"
  27. [ -n "$vid" ] && json_add_int id "$vid"
  28. [ -n "$macaddr" ] && json_add_string macaddr "$macaddr"
  29. [ -n "$rxcsum" ] && json_add_boolean rxcsum "$rxcsum"
  30. [ -n "$txcsum" ] && json_add_boolean txcsum "$txcsum"
  31. json_close_object
  32. proto_close_tunnel
  33. proto_add_data
  34. [ -n "$zone" ] && json_add_string zone "$zone"
  35. proto_close_data
  36. proto_send_update "$cfg"
  37. }
  38. proto_vxlan_setup() {
  39. local cfg="$1"
  40. local ipaddr peeraddr
  41. json_get_vars ipaddr peeraddr tunlink
  42. [ -z "$peeraddr" ] && {
  43. proto_notify_error "$cfg" "MISSING_ADDRESS"
  44. proto_block_restart "$cfg"
  45. exit
  46. }
  47. ( proto_add_host_dependency "$cfg" '' "$tunlink" )
  48. [ -z "$ipaddr" ] && {
  49. local wanif="$tunlink"
  50. if [ -z "$wanif" ] && ! network_find_wan wanif; then
  51. proto_notify_error "$cfg" "NO_WAN_LINK"
  52. exit
  53. fi
  54. if ! network_get_ipaddr ipaddr "$wanif"; then
  55. proto_notify_error "$cfg" "NO_WAN_LINK"
  56. exit
  57. fi
  58. }
  59. vxlan_generic_setup "$cfg" 'vxlan' "$ipaddr" "$peeraddr"
  60. }
  61. proto_vxlan6_setup() {
  62. local cfg="$1"
  63. local ip6addr peer6addr
  64. json_get_vars ip6addr peer6addr tunlink
  65. [ -z "$peer6addr" ] && {
  66. proto_notify_error "$cfg" "MISSING_ADDRESS"
  67. proto_block_restart "$cfg"
  68. exit
  69. }
  70. ( proto_add_host_dependency "$cfg" '' "$tunlink" )
  71. [ -z "$ip6addr" ] && {
  72. local wanif="$tunlink"
  73. if [ -z "$wanif" ] && ! network_find_wan6 wanif; then
  74. proto_notify_error "$cfg" "NO_WAN_LINK"
  75. exit
  76. fi
  77. if ! network_get_ipaddr6 ip6addr "$wanif"; then
  78. proto_notify_error "$cfg" "NO_WAN_LINK"
  79. exit
  80. fi
  81. }
  82. vxlan_generic_setup "$cfg" 'vxlan6' "$ip6addr" "$peer6addr"
  83. }
  84. proto_vxlan_teardown() {
  85. local cfg="$1"
  86. }
  87. proto_vxlan6_teardown() {
  88. local cfg="$1"
  89. }
  90. vxlan_generic_init_config() {
  91. no_device=1
  92. available=1
  93. proto_config_add_string "tunlink"
  94. proto_config_add_string "zone"
  95. proto_config_add_int "vid"
  96. proto_config_add_int "port"
  97. proto_config_add_int "ttl"
  98. proto_config_add_int "tos"
  99. proto_config_add_int "mtu"
  100. proto_config_add_string "macaddr"
  101. }
  102. proto_vxlan_init_config() {
  103. vxlan_generic_init_config
  104. proto_config_add_string "ipaddr"
  105. proto_config_add_string "peeraddr"
  106. }
  107. proto_vxlan6_init_config() {
  108. vxlan_generic_init_config
  109. proto_config_add_string "ip6addr"
  110. proto_config_add_string "peer6addr"
  111. }
  112. [ -n "$INCLUDE_ONLY" ] || {
  113. add_protocol vxlan
  114. add_protocol vxlan6
  115. }