Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFS Gluon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
firmware
FFS Gluon
Commits
e87e0926
Unverified
Commit
e87e0926
authored
1 year ago
by
Maciej Krüger
Browse files
Options
Downloads
Patches
Plain Diff
gluon-core: add ethernet module
parent
395f7fc2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
package/gluon-core/luasrc/usr/lib/lua/gluon/ethernet.lua
+83
-0
83 additions, 0 deletions
package/gluon-core/luasrc/usr/lib/lua/gluon/ethernet.lua
with
83 additions
and
0 deletions
package/gluon-core/luasrc/usr/lib/lua/gluon/ethernet.lua
0 → 100644
+
83
−
0
View file @
e87e0926
local
util
=
require
'gluon.util'
local
unistd
=
require
'posix.unistd'
local
dirent
=
require
'posix.dirent'
local
uci
=
require
(
'simple-uci'
).
cursor
()
local
M
=
{}
local
function
has_devtype
(
iface_dir
,
devtype
)
return
util
.
file_contains_line
(
iface_dir
..
'/uevent'
,
'DEVTYPE='
..
devtype
)
end
local
function
is_physical
(
iface_dir
)
return
unistd
.
access
(
iface_dir
..
'/device'
)
==
0
end
local
function
is_swconfig
()
local
has
=
false
uci
:
foreach
(
"system"
,
"switch"
,
function
()
has
=
true
end
)
uci
:
foreach
(
"system"
,
"switch_vlan"
,
function
()
has
=
true
end
)
return
has
end
local
function
interfaces_raw
()
local
eth_ifaces
=
{}
local
ifaces_dir
=
'/sys/class/net/'
for
iface
in
dirent
.
files
(
ifaces_dir
)
do
if
iface
~=
'.'
and
iface
~=
'..'
then
local
iface_dir
=
ifaces_dir
..
iface
if
is_physical
(
iface_dir
)
and
not
has_devtype
(
iface_dir
,
'wlan'
)
then
table.insert
(
eth_ifaces
,
iface
)
end
end
end
return
eth_ifaces
end
-- In comparison to interfaces_raw, this skips non-DSA ports on DSA devices,
-- as for ex. hap ac² has a special eth0 that shouldn't be touched
function
M
.
interfaces
()
local
intfs
=
interfaces_raw
()
if
M
.
get_switch_type
()
==
'dsa'
then
local
new_intfs
=
{}
for
_
,
intf
in
ipairs
(
intfs
)
do
if
has_devtype
(
'/sys/class/net/'
..
intf
,
'dsa'
)
then
table.insert
(
new_intfs
,
intf
)
end
end
return
new_intfs
end
return
intfs
end
function
M
.
is_vlan
(
intf
)
return
has_devtype
(
'/sys/class/net/'
..
intf
,
'vlan'
)
end
function
M
.
get_switch_type
()
if
is_swconfig
()
then
return
'swconfig'
end
for
_
,
intf
in
ipairs
(
interfaces_raw
())
do
if
has_devtype
(
'/sys/class/net/'
..
intf
,
'dsa'
)
then
return
'dsa'
end
end
return
'none'
end
return
M
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