add init.d scripts to a) write temporary config file and b) start babel
This commit is contained in:
		
							parent
							
								
									b43f9663c0
								
							
						
					
					
						commit
						6a38400ae1
					
				
							
								
								
									
										28
									
								
								package/gluon-mesh-babel/files/etc/init.d/gluon-mesh-babeld-0
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										28
									
								
								package/gluon-mesh-babel/files/etc/init.d/gluon-mesh-babeld-0
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/lua
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local site = require 'gluon.site_config'
 | 
				
			||||||
 | 
					local gmesh = require 'gluon.mesh'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					--local interfaces='/lib/gluon/core/mesh_interfaces' 
 | 
				
			||||||
 | 
					local babelconf='/var/etc/gluon-babel.conf'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					file = io.open(babelconf, "w")
 | 
				
			||||||
 | 
					file:write("ipv6-subtrees true\n")
 | 
				
			||||||
 | 
					file:write("export-table 10\n")
 | 
				
			||||||
 | 
					file:write("import-table 255\n")
 | 
				
			||||||
 | 
					file:write("import-table 11\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for interface in gmesh.interfaces() do 
 | 
				
			||||||
 | 
						file:write("interface " .. interface .. "\n")
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					if site.mesh_on_wan then
 | 
				
			||||||
 | 
						file:write("interface  br-wan\n")
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					file:write(" redistribute ip " .. site.prefix6 .. " eq 128  allow\n")
 | 
				
			||||||
 | 
					file:write(" redistribute ip " .. site.babel_mesh.prefix .. " eq 128  allow\n")
 | 
				
			||||||
 | 
					file:write(" redistribute local  deny\n")
 | 
				
			||||||
 | 
					file:write(" redistribute ip ::/0 eq 0  allow\n")
 | 
				
			||||||
 | 
					file:close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										37
									
								
								package/gluon-mesh-babel/files/etc/init.d/gluon-mesh-babeld-1
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										37
									
								
								package/gluon-mesh-babel/files/etc/init.d/gluon-mesh-babeld-1
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,37 @@
 | 
				
			|||||||
 | 
					#!/bin/sh /etc/rc.common
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					. $IPKG_INSTROOT/lib/functions/network.sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					START=70
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pidfile='/var/run/babeld.pid'
 | 
				
			||||||
 | 
					CONFIGFILE='/var/etc/gluon-babel.conf'
 | 
				
			||||||
 | 
					EXTRA_COMMANDS="status"
 | 
				
			||||||
 | 
					EXTRA_HELP="        status Dump Babel's table to the log file."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					start() {
 | 
				
			||||||
 | 
						mkdir -p /var/lib
 | 
				
			||||||
 | 
						mkdir -p /var/etc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/usr/sbin/babeld -D -I "$pidfile" -c "$CONFIGFILE"
 | 
				
			||||||
 | 
						# Wait for the pidfile to appear
 | 
				
			||||||
 | 
						for i in 1 2
 | 
				
			||||||
 | 
						do
 | 
				
			||||||
 | 
							[ -f "$pidfile" ] || sleep 1
 | 
				
			||||||
 | 
						done
 | 
				
			||||||
 | 
						[ -f "$pidfile" ] || (echo "Failed to start babeld"; exit 42)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					stop() {
 | 
				
			||||||
 | 
						[ -f "$pidfile" ] && kill $(cat $pidfile)
 | 
				
			||||||
 | 
					  # avoid race-condition on restart: wait for
 | 
				
			||||||
 | 
					  # babeld to die for real.
 | 
				
			||||||
 | 
					  [ -f "$pidfile" ] && sleep 1
 | 
				
			||||||
 | 
					  [ -f "$pidfile" ] && sleep 1
 | 
				
			||||||
 | 
					  [ -f "$pidfile" ] && sleep 1
 | 
				
			||||||
 | 
					  [ -f "$pidfile" ] && exit 42
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					status() {
 | 
				
			||||||
 | 
						[ -f "$pidfile" ] && kill -USR1 $(cat $pidfile)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -2,39 +2,12 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
local uci = require('luci.model.uci').cursor()
 | 
					local uci = require('luci.model.uci').cursor()
 | 
				
			||||||
local site = require 'gluon.site_config'
 | 
					local site = require 'gluon.site_config'
 | 
				
			||||||
local interfaces='/lib/gluon/core/mesh_interfaces' 
 | 
					--local gmesh = require 'gluon.mesh'
 | 
				
			||||||
local babelconf='/var/etc/gluon-babel.conf'
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- TODO: do we need settings for more interfaces in the firewall?
 | 
				
			||||||
if site.mesh_on_wan then
 | 
					if site.mesh_on_wan then
 | 
				
			||||||
  uci:section('babeld', 'interface', 'mesh_wan',
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
      ifname = 'br-wan',
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  uci:add_to_set('firewall', 'mesh_babel', 'network', 'wan')
 | 
					  uci:add_to_set('firewall', 'mesh_babel', 'network', 'wan')
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					 | 
				
			||||||
file = io.open(babelconf, "w")
 | 
					 | 
				
			||||||
file:write("ipv6-subtrees true\n")
 | 
					 | 
				
			||||||
file:write("export-table 10\n")
 | 
					 | 
				
			||||||
file:write("import-table 255\n")
 | 
					 | 
				
			||||||
file:write("import-table 11\n")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pcall( function() 
 | 
					 | 
				
			||||||
  for interface in io.lines(interfaces) do 
 | 
					 | 
				
			||||||
    local section = interface:gsub('[^%w_]','_')
 | 
					 | 
				
			||||||
    file:write("interface " .. interface .. "\n")
 | 
					 | 
				
			||||||
  end
 | 
					 | 
				
			||||||
end)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
file:write(" redistribute ip " .. site.prefix6 .. " eq 128  allow\n")
 | 
					 | 
				
			||||||
file:write(" redistribute ip " .. site.babel_mesh.prefix .. " eq 128  allow\n")
 | 
					 | 
				
			||||||
file:write(" redistribute local  deny\n")
 | 
					 | 
				
			||||||
file:write(" redistribute ip ::/0 eq 0  allow\n")
 | 
					 | 
				
			||||||
file:close()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
uci:add_to_set('firewall', 'mesh_babel', 'network', 'client')
 | 
					uci:add_to_set('firewall', 'mesh_babel', 'network', 'client')
 | 
				
			||||||
uci:add_to_set('firewall', 'mesh_babel', 'network', 'local_node4')
 | 
					uci:add_to_set('firewall', 'mesh_babel', 'network', 'local_node4')
 | 
				
			||||||
uci:add_to_set('firewall', 'mesh_babel', 'network', 'local_node6')
 | 
					uci:add_to_set('firewall', 'mesh_babel', 'network', 'local_node6')
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user