Commit 7a3ae47b authored by Gio's avatar Gio

lime-proto-bgp: read configuration instead of hardcoded values

parent a6e27ced
......@@ -16,7 +16,7 @@ function proto.configure(args)
proto.configured = true
local ipv4, ipv6 = network.primary_address()
local bgpPeers = {{remoteIP="10.1.152.10", remoteAS=37922, localAS=97922}}
local localAS = args[2] or 64496
local base_template = [[
router id $1;
......@@ -32,6 +32,20 @@ protocol kernel {
}
]]
for _,proto in pairs(config.get("network", "protocols")) do
if proto == "lan" then
base_template = base_template .. [[
protocol direct {
interface "br-lan";
}
]]
break
end
end
local bird4_config = utils.expandVars(base_template, ipv4:host():string())
local bird6_config = utils.expandVars(base_template, ipv6:host():string())
local peer_template = [[
protocol bgp {
import all;
......@@ -42,22 +56,19 @@ protocol bgp {
}
]]
for _,peer in pairs(bgpPeers) do
base_template = base_template .. utils.expandVars(peer_template, peer)
end
for _,proto in pairs(config.get("network", "protocols")) do
if proto == "lan" then
base_template = base_template .. [[
protocol direct {
interface "br-lan";
}
]]
break
local function apply_peer_template(s)
s.localAS = localAS
if string.find(s.remoteIP, ":", 1, true) then
bird6_config = bird6_config .. utils.expandVars(peer_template, s)
elseif string.find(s.remoteIP, ".", 1, true) then
bird4_config = bird4_config .. utils.expandVars(peer_template, s)
end
end
config.foreach("bgp_peer", apply_peer_template)
fs.writefile("/etc/bird4.conf", utils.expandVars(base_template, ipv4:host():string()))
fs.writefile("/etc/bird4.conf", bird4_config)
fs.writefile("/etc/bird6.conf", bird6_config)
end
function proto.setup_interface(ifname, args)
......
......@@ -25,6 +25,7 @@
# list protocols anygw
# list protocols batadv:%N1 # Parametrizable with %Nn
# list protocols bmx6:13
# list protocols bgp:65551 # BGP protocol take AS number as param
# list resolvers 8.8.8.8 # DNS servers node will use
# list resolvers 2001:4860:4860::8844
......@@ -77,3 +78,15 @@
# option switch_dev 'switch0' # If your ethernet device is connected to a switch chip you must specify it
# option switch_cpu_port '0' # Refer to switch port map of your device on openwrt wiki to know CPU port index
# list switch_ports '4' # List switch ports on with you want the vlan being passed
### Proto BGP specific sections
### One section for each BGP peer
#config bgp_peer peer1
# option remoteIP '192.0.2.6'
# option remoteAS '65550'
#config bgp_peer peer2
# option remoteIP '2001:db8::c001'
# option remoteAS '65549'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment