Skip to content

Commit

Permalink
ff-mesh-vpn-tunneldigger: init
Browse files Browse the repository at this point in the history
This is a dump of the former core package gluon-mesh-vpn-tunneldigger:

https://github.com/freifunk-gluon/gluon/tree/c2dc338abfbebb34dcf62124dc09be85fa88f8ef/package/gluon-mesh-vpn-tunneldigger

Only neccesary changes have been made.
  • Loading branch information
herbetom committed Jan 4, 2024
1 parent 661f553 commit 920e5e3
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ff-mesh-vpn-tunneldigger/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=ff-mesh-vpn-tunneldigger
PKG_VERSION:=0.0.1
PKG_RELEASE:=1

PKG_LICENSE:=BSD-2-Clause

include $(TOPDIR)/../package/gluon.mk

define Package/$(PKG_NAME)
TITLE:=Support for connecting meshes via tunneldigger/L2TPv3 pseudowire
DEPENDS:=+gluon-core +gluon-mesh-vpn-core +tunneldigger +simple-tc
endef

$(eval $(call BuildPackageGluon,$(PKG_NAME)))
13 changes: 13 additions & 0 deletions ff-mesh-vpn-tunneldigger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ff-mesh-vpn-tunneldigger

This package is based on the former core gluon package [gluon-mesh-vpn-tunneldigger](https://github.com/freifunk-gluon/gluon/tree/c2dc338abfbebb34dcf62124dc09be85fa88f8ef/package/gluon-mesh-vpn-tunneldigger).

It you want to keep using tunneldigger you need to take the following steps:

- `modules`: add this repo as described in the [README.md](../README.md#using-this-repository)
- `image-customization.lua`: remove the `mesh-vpn-tunneldigger` feature
- `image-customization.lua`: add the `config-mode-mesh-vpn` feature:
`features({'config-mode-mesh-vpn'})`
Not needed if you don't use the config mode or don't want to enable configuration of VPN settings via the config mode.
- `image-customization.lua`: add the `ff-mesh-vpn-tunneldigger` package:
`packages({'ff-mesh-vpn-tunneldigger'})`
2 changes: 2 additions & 0 deletions ff-mesh-vpn-tunneldigger/check_site.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
need_string_array(in_domain({'mesh_vpn', 'tunneldigger', 'brokers'}))
need_number({'mesh_vpn', 'tunneldigger', 'mtu'})
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
/etc/init.d/tunneldigger stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
/etc/init.d/tunneldigger start
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/5 * * * * /usr/bin/tunneldigger-watchdog
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/lua

local site = require 'gluon.site'
local util = require 'gluon.util'
local vpn_core = require 'gluon.mesh-vpn'

local uci = require('simple-uci').cursor()


uci:section('tunneldigger', 'broker', 'mesh_vpn', {
uuid = util.node_id(),
interface = vpn_core.get_interface(),
bind_interface = 'br-wan',
group = 'gluon-mesh-vpn',
broker_selection = 'usage',
address = site.mesh_vpn.tunneldigger.brokers(),
})

uci:save('tunneldigger')
31 changes: 31 additions & 0 deletions ff-mesh-vpn-tunneldigger/luasrc/usr/bin/tunneldigger-watchdog
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/lua

local uci = require('simple-uci').cursor()

local function restart_tunneldigger()
os.execute('logger -t tunneldigger-watchdog "Restarting Tunneldigger."')
os.execute('/etc/init.d/tunneldigger restart')
end

local function has_mesh_vpn_neighbours()
local handle = io.popen('batctl o', 'r')
if not handle then
return false
end
for line in handle:lines() do
if line:find('mesh%-vpn') then
handle:close()
return true
end
end
handle:close()
return false
end

if uci:get_bool('tunneldigger', 'mesh_vpn', 'enabled') then
if not has_mesh_vpn_neighbours() then
os.execute('logger -t tunneldigger-watchdog "No vpn-mesh neighbours found."')
restart_tunneldigger()
return
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
local uci = require('simple-uci').cursor()

local site = require 'gluon.site'
local vpn_core = require 'gluon.mesh-vpn'

local M = {}

function M.public_key()
return nil
end

function M.enable(val)
uci:set('tunneldigger', 'mesh_vpn', 'enabled', val)
uci:save('tunneldigger')
end

function M.active()
return site.mesh_vpn.tunneldigger() ~= nil
end

function M.set_limit(ingress_limit, egress_limit)
if ingress_limit ~= nil then
uci:set('tunneldigger', 'mesh_vpn', 'limit_bw_down', ingress_limit)
else
uci:delete('tunneldigger', 'mesh_vpn', 'limit_bw_down')
end

if egress_limit ~= nil then
uci:section('simple-tc', 'interface', 'mesh_vpn', {
ifname = vpn_core.get_interface(),
enabled = true,
limit_egress = egress_limit,
})
else
uci:delete('simple-tc', 'mesh_vpn')
end

uci:save('tunneldigger')
uci:save('simple-tc')
end

function M.mtu()
return site.mesh_vpn.tunneldigger.mtu()
end

return M

0 comments on commit 920e5e3

Please # to comment.