Skip to content

Commit

Permalink
unify template format: use %Mn and %Nn
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui committed Sep 2, 2014
1 parent 1e81214 commit 058bea8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
17 changes: 10 additions & 7 deletions packages/lime-system/files/etc/config/lime-defaults
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
# Beware this file is not supposed to store specific configuration, like "config net eth0"

# The options marked with "# Parametrizable with \Mn\"
# can include \Mn\ templates that will be substituted
# The options marked with "# Parametrizable with %Mn, %Nn"
# can include %Mn templates that will be substituted
# with the n'th byte of the primary_interface MAC
# and %Nn templates that will be replaced by a "network-identifier" byte,
# calculated from the hash of the ap_ssid value, so that all the nodes that
# form a mesh cloud (share the same ap_ssid) will produce the same value

# System option

config lime system
option hostname 'LiMeNode-\M4\\M5\\M6\' # Parametrizable with \Mn\
option hostname 'LiMeNode-%M4%M5%M6' # Parametrizable with %Mn, %Nn


# Network general option

config lime network
option primary_interface eth0 # The mac address of this device will be used in different places
option main_ipv4_address '10.N1.N2.0/24' # Parametrizable with \Mn\
option main_ipv6_address 'fddf:caN1:N2N3:0000::/64' # Parametrizable with \Mn\
option primary_interface eth0 # The mac address of this device will be used in different places
option main_ipv4_address '10.%N1.%N2.0/24' # Parametrizable with %Mn, %Nn
option main_ipv6_address 'fddf:ca%N1:%N2%N3:0000::/64' # Parametrizable with %Mn, %Nn
list protocols adhoc
list protocols lan
list protocols anygw
list protocols batadv:11
list protocols bmx6:13
list resolvers 8.8.8.8 # DNS servers node will use
list resolvers 8.8.8.8 # DNS servers node will use
list resolvers 2001:4860:4860::8844


Expand Down
4 changes: 2 additions & 2 deletions packages/lime-system/files/usr/lib/lua/lime/network.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ function network.primary_address(offset)
local ipv6_template = utils.applyMacTemplate16(config.get("network", "main_ipv6_address"), pm)

local hex = utils.hex
ipv4_template = ipv4_template:gsub("N1", n1):gsub("N2", n2):gsub("N3", n3)
ipv6_template = ipv6_template:gsub("N1", hex(n1)):gsub("N2", hex(n2)):gsub("N3", hex(n3))
ipv4_template = ipv4_template:gsub("%%N1", n1 ):gsub("%%N2", n2 ):gsub("%%N3", n3 )
ipv6_template = ipv6_template:gsub("%%N1", hex(n1)):gsub("%%N2", hex(n2)):gsub("%%N3", hex(n3))

hexsuffix = hex((m4 * 256*256 + m5 * 256 + m6) + offset)
return network.generate_host(ip.IPv4(ipv4_template), hexsuffix),
Expand Down
4 changes: 2 additions & 2 deletions packages/lime-system/files/usr/lib/lua/lime/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ function utils.isModuleAvailable(name)
end

function utils.applyMacTemplate16(template, mac)
for i=1,6,1 do template = template:gsub("\\M"..i.."\\", mac[i]) end
for i=1,6,1 do template = template:gsub("%%M"..i, mac[i]) end
return template
end

function utils.applyMacTemplate10(template, mac)
for i=1,6,1 do template = template:gsub("\\M"..i.."\\", tonumber(mac[i], 16)) end
for i=1,6,1 do template = template:gsub("%%M"..i, tonumber(mac[i], 16)) end
return template
end

Expand Down

0 comments on commit 058bea8

Please sign in to comment.