xfrm.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. proto_xfrm_setup() {
  9. local cfg="$1"
  10. local mode="xfrm"
  11. local tunlink ifid mtu zone
  12. json_get_vars tunlink ifid mtu zone
  13. [ -z "$tunlink" ] && {
  14. proto_notify_error "$cfg" NO_TUNLINK
  15. proto_block_restart "$cfg"
  16. exit
  17. }
  18. [ -z "$ifid" ] && {
  19. proto_notify_error "$cfg" NO_IFID
  20. proto_block_restart "$cfg"
  21. exit
  22. }
  23. ( proto_add_host_dependency "$cfg" '' "$tunlink" )
  24. proto_init_update "$cfg" 1
  25. proto_add_tunnel
  26. json_add_string mode "$mode"
  27. json_add_int mtu "${mtu:-1280}"
  28. json_add_string link "$tunlink"
  29. json_add_object 'data'
  30. [ -n "$ifid" ] && json_add_int ifid "$ifid"
  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_xfrm_teardown() {
  39. local cfg="$1"
  40. }
  41. proto_xfrm_init_config() {
  42. no_device=1
  43. available=1
  44. proto_config_add_int "mtu"
  45. proto_config_add_string "tunlink"
  46. proto_config_add_string "zone"
  47. proto_config_add_int "ifid"
  48. }
  49. [ -n "$INCLUDE_ONLY" ] || {
  50. [ -f /lib/modules/$(uname -r)/xfrm_interface.ko -o -d /sys/module/xfrm_interface ] && add_protocol xfrm
  51. }