cjdroute 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #! /bin/sh
  2. # PROVIDE: cjdroute
  3. # REQUIRE: networking
  4. # KEYWORD: shutdown
  5. # Add the following line to /etc/rc.conf to enable cjdroute:
  6. # cjdroute_enable="YES"
  7. . /etc/rc.subr
  8. name="cjdroute"
  9. rcvar="cjdroute_enable"
  10. load_rc_config $name
  11. : ${cjdroute_config:=/usr/local/etc/cjdroute.conf}
  12. command="/usr/local/bin/cjdroute"
  13. command_args=" < ${cjdroute_config}"
  14. start_cmd="${name}_start"
  15. stop_cmd="${name}_stop"
  16. test ! -d /var/run/cjdroute/ && mkdir /var/run/cjdroute/
  17. if_cjd="$(cat /usr/local/etc/cjdroute.conf | egrep -o '"tunDevice": "t[a,u][p,n][0-9]{1,2}"' | egrep -o 't[a,u][p,n][0-9]{1,2}')"
  18. cjdroute_start() {
  19. test ! -f /usr/local/etc/cjdroute.conf && (
  20. logger -s -t cjdroute "Generate a configuration in /usr/local/etc/cjdroute.conf"
  21. exit 1
  22. )
  23. if [ "$if_cjd" = "" ]; then logger -s -t cjdroute "Tunnel adapter not found. Specify adapter name in cjdroute.conf."; exit 1; fi
  24. /sbin/ifconfig $if_cjd >/dev/null 2>&1
  25. if [ "$?" = 0 ] ; then ifconfig $if_cjd destroy; fi
  26. /sbin/ifconfig $if_cjd create || logger -s -t cjdroute "Failed to create ${if_cjd} adapter"
  27. /usr/local/bin/cjdroute < /usr/local/etc/cjdroute.conf &
  28. /sbin/route -6 add fc00::/8 -iface $if_cjd
  29. }
  30. cjdroute_stop() {
  31. logger -s -t cjdroute "Stopping cjdroute"
  32. if [ "$rc_pid" != "" ]; then
  33. kill -TERM $rc_pid ; fi
  34. /sbin/ifconfig $if_cjd >/dev/null 1>/dev/null 2>dev/null
  35. if [ "$?" = 0 ]; then /sbin/ifconfig $if_cjd destroy || logger -s -t cjdroute "Failed to destroy $if_cjd adapter"; fi
  36. }
  37. load_rc_config $name
  38. : ${cjdroute_enable:=no}
  39. run_rc_command "$1"