fastd.pl 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. my $cfg = $CONFIG->{fastd_mesh_vpn};
  2. my $backbone = $cfg->{backbone};
  3. my $add_methods = '';
  4. for (@{$cfg->{methods}}) {
  5. $add_methods .= "uci add_list fastd.mesh_vpn.method='$_'\n";
  6. }
  7. my $set_peer_limit;
  8. if ($backbone->{limit}) {
  9. $set_peer_limit = "uci_set fastd mesh_vpn_backbone peer_limit '$backbone->{limit}'\n";
  10. }
  11. else {
  12. $set_peer_limit = "uci_remove fastd mesh_vpn_backbone peer_limit\n";
  13. }
  14. print <<END;
  15. #/bin/sh
  16. . /lib/functions.sh
  17. . /lib/gluon/functions/sysconfig.sh
  18. . /lib/gluon/functions/users.sh
  19. add_user gluon-fastd 800
  20. uci_add fastd fastd mesh_vpn
  21. uci_remove fastd mesh_vpn config
  22. uci_remove fastd mesh_vpn config_peer_dir
  23. uci_set fastd mesh_vpn user 'gluon-fastd'
  24. uci_set fastd mesh_vpn syslog_level 'verbose'
  25. uci_set fastd mesh_vpn interface 'mesh-vpn'
  26. uci_set fastd mesh_vpn mode 'tap'
  27. uci_set fastd mesh_vpn mtu '$cfg->{mtu}'
  28. uci_set fastd mesh_vpn secure_handshakes '1'
  29. uci_remove fastd mesh_vpn method
  30. $add_methods
  31. uci_remove fastd mesh_vpn_backbone
  32. uci_add fastd peer_group mesh_vpn_backbone
  33. uci_set fastd mesh_vpn_backbone enabled '1'
  34. uci_set fastd mesh_vpn_backbone net 'mesh_vpn'
  35. $set_peer_limit
  36. END
  37. foreach my $name (sort keys %{$backbone->{peers}}) {
  38. my $peer = $backbone->{peers}->{$name};
  39. print <<EOF;
  40. uci_remove fastd 'mesh_vpn_backbone_peer_$name'
  41. uci_add fastd peer 'mesh_vpn_backbone_peer_$name'
  42. uci_set fastd 'mesh_vpn_backbone_peer_$name' enabled '1'
  43. uci_set fastd 'mesh_vpn_backbone_peer_$name' net 'mesh_vpn'
  44. uci_set fastd 'mesh_vpn_backbone_peer_$name' group 'mesh_vpn_backbone'
  45. uci_set fastd 'mesh_vpn_backbone_peer_$name' key '$peer->{key}'
  46. EOF
  47. for (@{$peer->{remotes}}) {
  48. print "uci add_list fastd.mesh_vpn_backbone_peer_$name.remote='$_'\n";
  49. }
  50. }
  51. print <<'END';
  52. uci_add network interface mesh_vpn
  53. uci_set network mesh_vpn ifname 'mesh-vpn'
  54. uci_set network mesh_vpn proto 'batadv'
  55. uci_set network mesh_vpn mesh 'bat0'
  56. uci_set network mesh_vpn mesh_no_rebroadcast '1'
  57. mainaddr=$(sysconfig primary_mac)
  58. oIFS="$IFS"; IFS=":"; set -- $mainaddr; IFS="$oIFS"
  59. b2mask=0x02
  60. vpnaddr=$(printf "%02x:%s:%s:%02x:%s:%s" $(( 0x$1 | $b2mask )) $2 $3 $(( (0x$4 + 1) % 0x100 )) $5 $6)
  61. uci_set network mesh_vpn macaddr "$vpnaddr"
  62. uci_commit fastd
  63. uci_commit network
  64. END