gluon-client-bridge: add default next-node MAC address

The next-node MAC address doesn't need to be unique in different
communities, so we can as well add a default value.
This commit is contained in:
Matthias Schiffer 2017-06-26 22:45:42 +02:00
parent f9f68535aa
commit 08e667ba2e
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C
6 changed files with 39 additions and 23 deletions

View File

@ -80,9 +80,6 @@
-- anycast IPs of all nodes
ip4 = '10.xxx.0.xxx',
ip6 = 'fdxx:xxxx:xxxx::xxxx',
-- anycast MAC of all nodes
mac = 'xe:xx:xx:xx:xx:xx',
},
-- Options specific to routing protocols (optional)

View File

@ -114,7 +114,7 @@ wifi24 \: optional
interface's ESSID. This is the WiFi the clients connect to.
``mesh`` requires a single parameter, a string, named ``id`` which sets the
mesh id, also visible as an open WiFi in some network managers. Usually you
mesh id, also visible as an open WiFi in some network managers. Usually you
don't want users to connect to this mesh-SSID, so use a cryptic id that no
one will accidentally mistake for the client WiFi.
@ -154,10 +154,14 @@ next_node \: package
next_node = {
ip4 = '10.23.42.1',
ip6 = 'fdca:ffee:babe:1::1',
mac = 'ca:ff:ee:ba:be:00'
mac = '16:41:95:40:f7:dc'
}
The IPv4 next-node address is optional.
All values of this section are optional. If the IPv4 or IPv6 address is
omitted, there will be no IPv4 or IPv6 anycast address. The MAC address
defaults to ``16:41:95:40:f7:dc``; this value usually doesn't need to be
changed, but it can be adjusted to match existing deployments that use a
different value.
mesh \: optional
Options specific to routing protocols.
@ -284,7 +288,7 @@ mesh_on_wan \: optional
mesh_on_lan \: optional
Enables the mesh on the LAN port (``true`` or ``false``).
::
mesh_on_lan = true,
poe_passthrough \: optional

View File

@ -1,15 +1,15 @@
need_string_match('next_node.mac', '^%x[02468aAcCeE]:%x%x:%x%x:%x%x:%x%x:%x%x$')
need_string_match('next_node.mac', '^%x[02468aAcCeE]:%x%x:%x%x:%x%x:%x%x:%x%x$', false)
if need_string_match('next_node.ip4', '^%d+.%d+.%d+.%d+$', false) then
need_string_match('prefix4', '^%d+.%d+.%d+.%d+/%d+$')
need_string_match('prefix4', '^%d+.%d+.%d+.%d+/%d+$')
end
need_string_match('next_node.ip6', '^[%x:]+$', false)
for _, config in ipairs({'wifi24', 'wifi5'}) do
if need_table(config .. '.ap', nil, false) then
need_string(config .. '.ap.ssid')
need_boolean(config .. '.ap.disabled', false)
end
if need_table(config .. '.ap', nil, false) then
need_string(config .. '.ap.ssid')
need_boolean(config .. '.ap.disabled', false)
end
end

View File

@ -1,16 +1,20 @@
#!/usr/bin/lua
local client_bridge = require 'gluon.client_bridge'
local site = require 'gluon.site_config'
local sysconfig = require 'gluon.sysconfig'
local uci = require('simple-uci').cursor()
local next_node = site.next_node or {}
uci:delete('network', 'local_node_dev')
uci:section('network', 'device', 'local_node_dev', {
type = 'veth',
name = 'local-node',
macaddr = site.next_node.mac,
macaddr = client_bridge.next_node_macaddr(),
peer_name = 'local-port',
peer_macaddr = sysconfig.primary_mac,
})
@ -18,13 +22,13 @@ uci:section('network', 'device', 'local_node_dev', {
local ip4, ip6
if site.next_node.ip4 then
if next_node.ip4 then
local plen = site.prefix4:match('/%d+$')
ip4 = site.next_node.ip4 .. plen
ip4 = next_node.ip4 .. plen
end
if site.next_node.ip6 then
ip6 = site.next_node.ip6 .. '/128'
if next_node.ip6 then
ip6 = next_node.ip6 .. '/128'
end
uci:delete('network', 'local_node')

View File

@ -0,0 +1,8 @@
local site = require 'gluon.site_config'
module 'gluon.client_bridge'
function next_node_macaddr()
return (site.next_node or {}).mac or '16:41:95:40:f7:dc'
end

View File

@ -1,10 +1,13 @@
local client_bridge = require 'gluon.client_bridge'
local site = require 'gluon.site_config'
local next_node = site.next_node
local next_node = site.next_node or {}
rule('FORWARD --logical-out br-client -o bat0 -d ' .. next_node.mac .. ' -j DROP')
rule('OUTPUT --logical-out br-client -o bat0 -d ' .. next_node.mac .. ' -j DROP')
rule('FORWARD --logical-out br-client -o bat0 -s ' .. next_node.mac .. ' -j DROP')
rule('OUTPUT --logical-out br-client -o bat0 -s ' .. next_node.mac .. ' -j DROP')
local macaddr = client_bridge.next_node_macaddr()
rule('FORWARD --logical-out br-client -o bat0 -d ' .. macaddr .. ' -j DROP')
rule('OUTPUT --logical-out br-client -o bat0 -d ' .. macaddr .. ' -j DROP')
rule('FORWARD --logical-out br-client -o bat0 -s ' .. macaddr .. ' -j DROP')
rule('OUTPUT --logical-out br-client -o bat0 -s ' .. macaddr .. ' -j DROP')
if next_node.ip4 then
rule('FORWARD --logical-out br-client -o bat0 -p ARP --arp-ip-src ' .. next_node.ip4 .. ' -j DROP')