Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
ffbs-gluon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ffbs
ffbs-gluon
Commits
cd09c95e
Unverified
Commit
cd09c95e
authored
5 years ago
by
Matthias Schiffer
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #1956 from freifunk-gluon/primary-mac-cleanup
Primary MAC logic refactoring
parents
75684ecf
2e265e03
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac
+119
-58
119 additions, 58 deletions
package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac
package/gluon-core/luasrc/usr/lib/lua/gluon/platform.lua
+2
-2
2 additions, 2 deletions
package/gluon-core/luasrc/usr/lib/lua/gluon/platform.lua
with
121 additions
and
60 deletions
package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac
+
119
−
58
View file @
cd09c95e
...
...
@@ -4,75 +4,136 @@ local sysconfig = require 'gluon.sysconfig'
if
sysconfig
.
primary_mac
then
os.exit
(
0
)
os.exit
(
0
)
end
local
util
=
require
'gluon.util'
local
platform
=
require
'gluon.platform'
local
util
=
require
'gluon.util'
local
try_files
=
{
'/sys/class/net/eth0/address'
}
local
function
sysfs
(
...
)
local
path
=
string.format
(
...
)
return
function
()
local
addr
=
util
.
readfile
(
path
)
if
addr
then
return
util
.
trim
(
addr
)
end
end
end
if
not
(
util
.
contains
({
'x86'
,
'brcm2708'
},
platform
.
get_target
())
or
platform
.
match
(
'ar71xx'
,
'mikrotik'
)
)
then
table.insert
(
try_files
,
1
,
'/sys/class/ieee80211/phy0/macaddress'
)
local
function
eth
(
index
)
return
sysfs
(
'/sys/class/net/eth%d/address'
,
index
)
end
if
platform
.
match
(
'ar71xx'
,
'generic'
,
{
'tl-wdr3600'
,
'tl-wdr4300'
,
'tl-wr902ac-v1'
})
then
table.insert
(
try_files
,
1
,
'/sys/class/ieee80211/phy1/macaddress'
)
elseif
platform
.
match
(
'ar71xx'
,
'generic'
,
{
'a40'
,
'a60'
,
'archer-c25-v1'
,
'archer-c60-v2'
,
'archer-c7-v4'
,
'archer-c7-v5'
,
'carambola2'
,
'koala'
,
'mr600'
,
'mr600v2'
,
'mr900'
,
'mr900v2'
,
'mr1750'
,
'mr1750v2'
,
'om2p'
,
'om2pv2'
,
'om2pv4'
,
'om2p-hs'
,
'om2p-hsv2'
,
'om2p-hsv3'
,
'om2p-hsv4'
,
'om2p-lc'
,
'om5p'
,
'om5p-an'
,
'om5p-ac'
,
'om5p-acv2'
,
'unifi-outdoor-plus'
,
'unifiac-lite'
,
'unifiac-pro'
})
then
table.insert
(
try_files
,
1
,
'/sys/class/net/eth0/address'
)
elseif
platform
.
match
(
'ar71xx'
,
'generic'
,
{
'archer-c5'
,
'archer-c58-v1'
,
'archer-c59-v1'
,
'archer-c60-v1'
,
'archer-c7'
})
then
table.insert
(
try_files
,
1
,
'/sys/class/net/eth1/address'
)
elseif
platform
.
match
(
'ar71xx'
,
'nand'
,
{
'hiveap-121'
})
then
table.insert
(
try_files
,
1
,
'/sys/class/net/eth0/address'
)
elseif
platform
.
match
(
'ath79'
,
'generic'
,
{
'ocedo,raccoon'
})
then
table.insert
(
try_files
,
1
,
'/sys/class/net/eth0/address'
)
elseif
platform
.
match
(
'ipq40xx'
,
'generic'
,
{
'avm,fritzbox-4040'
,
'openmesh,a42'
,
'openmesh,a62'
})
then
table.insert
(
try_files
,
1
,
'/sys/class/net/eth0/address'
)
elseif
platform
.
match
(
'ipq806x'
,
'generic'
,
{
'netgear,r7800'
})
then
table.insert
(
try_files
,
1
,
'/sys/class/net/eth1/address'
)
elseif
platform
.
match
(
'mpc85xx'
,
'p1020'
,
{
'aerohive,hiveap-330'
})
then
table.insert
(
try_files
,
1
,
'/sys/class/net/eth0/address'
)
elseif
platform
.
match
(
'mpc85xx'
,
'p1020'
,
{
'ocedo,panda'
})
then
table.insert
(
try_files
,
1
,
'/sys/class/net/eth1/address'
)
elseif
platform
.
match
(
'ramips'
,
'mt7620'
,
{
'miwifi-mini'
,
'tplink,c2-v1'
,
'c20-v1'
,
'c20i'
,
'c50'
})
then
table.insert
(
try_files
,
1
,
'/sys/class/net/eth0/address'
)
elseif
platform
.
match
(
'ramips'
,
'mt7621'
,
{
'dir-860l-b1'
})
then
table.insert
(
try_files
,
1
,
'/sys/class/ieee80211/phy1/macaddress'
)
local
function
phy
(
index
)
return
sysfs
(
'/sys/class/ieee80211/phy%d/macaddress'
,
index
)
end
for
_
,
file
in
ipairs
(
try_files
)
do
local
addr
=
util
.
readfile
(
file
)
-- Entries are matched in the order they are listed
local
primary_addrs
=
{
{
eth
(
0
),
{
{
'x86'
},
{
'brcm2708'
},
{
'ar71xx'
,
'generic'
,
{
'a40'
,
'a60'
,
'archer-c25-v1'
,
'archer-c60-v2'
,
'archer-c7-v4'
,
'archer-c7-v5'
,
'carambola2'
,
'koala'
,
'mr600'
,
'mr600v2'
,
'mr900'
,
'mr900v2'
,
'mr1750'
,
'mr1750v2'
,
'om2p'
,
'om2pv2'
,
'om2pv4'
,
'om2p-hs'
,
'om2p-hsv2'
,
'om2p-hsv3'
,
'om2p-hsv4'
,
'om2p-lc'
,
'om5p'
,
'om5p-an'
,
'om5p-ac'
,
'om5p-acv2'
,
'unifi-outdoor-plus'
,
'unifiac-lite'
,
'unifiac-pro'
,
}},
{
'ar71xx'
,
'mikrotik'
},
{
'ar71xx'
,
'nand'
,
{
'hiveap-121'
,
}},
{
'ath79'
,
'generic'
,
{
'ocedo,raccoon'
,
}},
{
'ipq40xx'
,
'generic'
,
{
'avm,fritzbox-4040'
,
'openmesh,a42'
,
'openmesh,a62'
,
}},
{
'mpc85xx'
,
'p1020'
,
{
'aerohive,hiveap-330'
,
}},
{
'ramips'
,
'mt7620'
,
{
'miwifi-mini'
,
'tplink,c2-v1'
,
'c20-v1'
,
'c20i'
,
'c50'
,
}},
}},
{
eth
(
1
),
{
{
'ar71xx'
,
'generic'
,
{
'archer-c5'
,
'archer-c58-v1'
,
'archer-c59-v1'
,
'archer-c60-v1'
,
'archer-c7'
,
}},
{
'ipq806x'
,
'generic'
,
{
'netgear,r7800'
,
}},
{
'mpc85xx'
,
'p1020'
,
{
'ocedo,panda'
,
}},
}},
{
phy
(
1
),
{
{
'ar71xx'
,
'generic'
,
{
'tl-wdr3600'
,
'tl-wdr4300'
,
'tl-wr902ac-v1'
,
}},
{
'ramips'
,
'mt7621'
,
{
'dir-860l-b1'
,
}},
}},
-- phy0 default
{
phy
(
0
),
{
{},
-- matches everything
}},
-- eth0 fallback when phy0 does not exist
{
eth
(
0
),
{
{},
-- matches everything
}},
}
if
addr
then
sysconfig
.
primary_mac
=
util
.
trim
(
addr
)
break
end
for
_
,
matcher
in
ipairs
(
primary_addrs
)
do
local
f
,
matches
=
unpack
(
matcher
)
for
_
,
match
in
ipairs
(
matches
)
do
if
platform
.
match
(
unpack
(
match
))
then
local
addr
=
f
()
if
addr
then
sysconfig
.
primary_mac
=
addr
return
end
end
end
end
error
(
'no primary MAC address found'
)
This diff is collapsed.
Click to expand it.
package/gluon-core/luasrc/usr/lib/lua/gluon/platform.lua
+
2
−
2
View file @
cd09c95e
...
...
@@ -7,11 +7,11 @@ local M = setmetatable({}, {
})
function
M
.
match
(
target
,
subtarget
,
boards
)
if
M
.
get_target
()
~=
target
then
if
target
and
M
.
get_target
()
~=
target
then
return
false
end
if
M
.
get_subtarget
()
~=
subtarget
then
if
subtarget
and
M
.
get_subtarget
()
~=
subtarget
then
return
false
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment