1
0

gnunet-proto.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/sh
  2. # gnunet.sh - GNUnet proto for netifd
  3. # Copyright (c) 2016 OpenWrt.org
  4. [ -n "$INCLUDE_ONLY" ] || {
  5. . /lib/functions.sh
  6. . /lib/functions/network.sh
  7. . ../netifd-proto.sh
  8. init_proto "$@"
  9. }
  10. proto_gnunet_setup() {
  11. local cfg="$1"
  12. local iface="$2"
  13. local ipv4_addr ipv6_addr prefix ipaddr ip6addr
  14. local configfile="/var/run/gnunet/gnunet.conf"
  15. local gnunet_iftype
  16. for gnit in dns exit vpn; do
  17. local i1="$(gnunet-config -c $configfile -s $gnit -o IFNAME 2>/dev/null)"
  18. local i2="$(gnunet-config -c $configfile -s $gnit -o TUN_IFNAME 2>/dev/null)"
  19. [ "$i1" = "$iface" -o "$i2" = "$iface" ] && gnunet_iftype="$gnit"
  20. done
  21. if [ -z "$iface" -o -z "$gnunet_iftype" ]; then
  22. proto_setup_failed "$cfg"
  23. return
  24. fi
  25. proto_init_update "$iface" 1
  26. ipaddr="$(gnunet-config -c $configfile -s $gnunet_iftype -o IPV4ADDR 2>/dev/null)"
  27. ipmask="$(gnunet-config -c $configfile -s $gnunet_iftype -o IPV4MASK 2>/dev/null)"
  28. ip6addr="$(gnunet-config -c $configfile -s $gnunet_iftype -o IPV6ADDR 2>/dev/null)"
  29. ip6prefix="$(gnunet-config -c $configfile -s $gnunet_iftype -o IPV6PREFIX 2>/dev/null)"
  30. [ -n "$ipaddr" ] && proto_add_ipv4_address "$ipaddr" "$ipmask"
  31. [ -n "$ip6addr" ] && proto_add_ipv6_address "$ip6addr" "$ip6prefix"
  32. proto_send_update "$cfg"
  33. }
  34. proto_gnunet_teardown() {
  35. return
  36. }
  37. [ -n "$INCLUDE_ONLY" ] || {
  38. add_protocol gnunet
  39. }