0029-vxlan-add-new-package-for-netifd-VXLAN-proto.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Fri, 10 Mar 2017 01:23:50 +0100
  3. Subject: vxlan: add new package for netifd VXLAN proto
  4. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
  5. diff --git a/package/network/config/vxlan/Makefile b/package/network/config/vxlan/Makefile
  6. new file mode 100644
  7. index 0000000000000000000000000000000000000000..a471d4e90cbe30c1d1dd01dbf7553995d8c0485e
  8. --- /dev/null
  9. +++ b/package/network/config/vxlan/Makefile
  10. @@ -0,0 +1,32 @@
  11. +include $(TOPDIR)/rules.mk
  12. +
  13. +PKG_NAME:=vxlan
  14. +PKG_VERSION:=1
  15. +PKG_LICENSE:=GPL-2.0
  16. +
  17. +include $(INCLUDE_DIR)/package.mk
  18. +
  19. +define Package/vxlan
  20. + SECTION:=net
  21. + CATEGORY:=Network
  22. + MAINTAINER:=Matthias Schiffer <mschiffer@universe-factory.net>
  23. + TITLE:=Virtual eXtensible LAN config support
  24. + DEPENDS:=+kmod-vxlan
  25. +endef
  26. +
  27. +define Package/vxlan/description
  28. + Virtual eXtensible LAN config support in /etc/config/network.
  29. +endef
  30. +
  31. +define Build/Compile
  32. +endef
  33. +
  34. +define Build/Configure
  35. +endef
  36. +
  37. +define Package/vxlan/install
  38. + $(INSTALL_DIR) $(1)/lib/netifd/proto
  39. + $(INSTALL_BIN) ./files/vxlan.sh $(1)/lib/netifd/proto/vxlan.sh
  40. +endef
  41. +
  42. +$(eval $(call BuildPackage,vxlan))
  43. diff --git a/package/network/config/vxlan/files/vxlan.sh b/package/network/config/vxlan/files/vxlan.sh
  44. new file mode 100755
  45. index 0000000000000000000000000000000000000000..27ccd8f12759f69c7c226cac0c923335b8ccc6a8
  46. --- /dev/null
  47. +++ b/package/network/config/vxlan/files/vxlan.sh
  48. @@ -0,0 +1,148 @@
  49. +#!/bin/sh
  50. +
  51. +[ -n "$INCLUDE_ONLY" ] || {
  52. + . /lib/functions.sh
  53. + . /lib/functions/network.sh
  54. + . ../netifd-proto.sh
  55. + init_proto "$@"
  56. +}
  57. +
  58. +vxlan_generic_setup() {
  59. + local cfg="$1"
  60. + local mode="$2"
  61. + local local="$3"
  62. + local remote="$4"
  63. +
  64. + local link="$cfg"
  65. +
  66. + local port vid ttl tos mtu macaddr zone
  67. + json_get_vars port vid ttl tos mtu macaddr zone
  68. +
  69. +
  70. + proto_init_update "$link" 1
  71. +
  72. + proto_add_tunnel
  73. + json_add_string mode "$mode"
  74. +
  75. + [ -n "$tunlink" ] && json_add_string link "$tunlink"
  76. + [ -n "$local" ] && json_add_string local "$local"
  77. + [ -n "$remote" ] && json_add_string remote "$remote"
  78. +
  79. + [ -n "$ttl" ] && json_add_int ttl "$ttl"
  80. + [ -n "$tos" ] && json_add_string tos "$tos"
  81. + [ -n "$mtu" ] && json_add_int mtu "$mtu"
  82. +
  83. + json_add_object 'data'
  84. + [ -n "$port" ] && json_add_int port "$port"
  85. + [ -n "$vid" ] && json_add_int id "$vid"
  86. + [ -n "$macaddr" ] && json_add_string macaddr "$macaddr"
  87. + json_close_object
  88. +
  89. + proto_close_tunnel
  90. +
  91. + proto_add_data
  92. + [ -n "$zone" ] && json_add_string zone "$zone"
  93. + proto_close_data
  94. +
  95. + proto_send_update "$cfg"
  96. +}
  97. +
  98. +proto_vxlan_setup() {
  99. + local cfg="$1"
  100. +
  101. + local ipaddr peeraddr
  102. + json_get_vars ipaddr peeraddr tunlink
  103. +
  104. + [ -z "$peeraddr" ] && {
  105. + proto_notify_error "$cfg" "MISSING_ADDRESS"
  106. + proto_block_restart "$cfg"
  107. + exit
  108. + }
  109. +
  110. + ( proto_add_host_dependency "$cfg" '' "$tunlink" )
  111. +
  112. + [ -z "$ipaddr" ] && {
  113. + local wanif="$tunlink"
  114. + if [ -z "$wanif" ] && ! network_find_wan wanif; then
  115. + proto_notify_error "$cfg" "NO_WAN_LINK"
  116. + exit
  117. + fi
  118. +
  119. + if ! network_get_ipaddr ipaddr "$wanif"; then
  120. + proto_notify_error "$cfg" "NO_WAN_LINK"
  121. + exit
  122. + fi
  123. + }
  124. +
  125. + vxlan_generic_setup "$cfg" 'vxlan' "$ipaddr" "$peeraddr"
  126. +}
  127. +
  128. +proto_vxlan6_setup() {
  129. + local cfg="$1"
  130. +
  131. + local ip6addr peer6addr
  132. + json_get_vars ip6addr peer6addr tunlink
  133. +
  134. + [ -z "$peer6addr" ] && {
  135. + proto_notify_error "$cfg" "MISSING_ADDRESS"
  136. + proto_block_restart "$cfg"
  137. + exit
  138. + }
  139. +
  140. + ( proto_add_host_dependency "$cfg" '' "$tunlink" )
  141. +
  142. + [ -z "$ip6addr" ] && {
  143. + local wanif="$tunlink"
  144. + if [ -z "$wanif" ] && ! network_find_wan6 wanif; then
  145. + proto_notify_error "$cfg" "NO_WAN_LINK"
  146. + exit
  147. + fi
  148. +
  149. + if ! network_get_ipaddr6 ip6addr "$wanif"; then
  150. + proto_notify_error "$cfg" "NO_WAN_LINK"
  151. + exit
  152. + fi
  153. + }
  154. +
  155. + vxlan_generic_setup "$cfg" 'vxlan6' "$ip6addr" "$peer6addr"
  156. +}
  157. +
  158. +proto_vxlan_teardown() {
  159. + local cfg="$1"
  160. +}
  161. +
  162. +proto_vxlan6_teardown() {
  163. + local cfg="$1"
  164. +}
  165. +
  166. +vxlan_generic_init_config() {
  167. + no_device=1
  168. + available=1
  169. +
  170. + proto_config_add_string "tunlink"
  171. + proto_config_add_string "zone"
  172. +
  173. + proto_config_add_int "vid"
  174. + proto_config_add_int "port"
  175. + proto_config_add_int "ttl"
  176. + proto_config_add_int "tos"
  177. + proto_config_add_int "mtu"
  178. + proto_config_add_string "macaddr"
  179. +}
  180. +
  181. +proto_vxlan_init_config() {
  182. + vxlan_generic_init_config
  183. + proto_config_add_string "ipaddr"
  184. + proto_config_add_string "peeraddr"
  185. +}
  186. +
  187. +proto_vxlan6_init_config() {
  188. + vxlan_generic_init_config
  189. + proto_config_add_string "ip6addr"
  190. + proto_config_add_string "peer6addr"
  191. +}
  192. +
  193. +[ -n "$INCLUDE_ONLY" ] || {
  194. + add_protocol vxlan
  195. + add_protocol vxlan6
  196. +}