Page MenuHomeFreeBSD

/usr/libexec/flua: Add bindings for libifconfig
Needs ReviewPublic

Authored by freqlabs on Jun 25 2020, 11:08 AM.


Group Reviewers

Add Lua bindings for libifconfig to flua.

Throwing this on phab to see if anyone has a use case for it. Otherwise, I don't have plans to commit it yet. libifconfig really should have more features.

Test Plan

ifcfg = require('ifconfig').open()
ucl = require('ucl')

ifaces = ifcfg:foreach_iface(function(_, iface, ifs)
    local name = iface:name()
    ifs[name] = {
        media = ifcfg:get_media(name),
        status = ifcfg:get_status(name),
        capabilities = ifcfg:get_capability(name),
        groups = ifcfg:get_groups(name),
        metric = ifcfg:get_metric(name),
        mtu = ifcfg:get_mtu(name),
        nd6 = ifcfg:get_nd6(name),
        lagg_status = ifcfg:get_lagg_status(name),
        laggdev = ifcfg:get_laggport_laggdev(name),
        addresses = ifcfg:foreach_ifaddr(iface, function(_, addr, addrs)
            table.insert(addrs, ifcfg:addr_info(addr))
            return addrs
        end, {})
    return ifs
end, {})

function yaml(obj)
    print(ucl.to_format(obj, "yaml"))



Diff Detail

rS FreeBSD src repository - subversion
Lint Skipped
Unit Tests Skipped

Event Timeline

Tossing kp in the mix for the giggles of it

Perhaps useful for network testing purposes?

I can see some potential for automation and orchestration.

Without immediate users for this it's probably a bit early to commit this, but I like the notion.
If nothing else it gives a bit more sample code of how we can wrap things in Lua, and I could also see use cases for base-system scripting where we may want something other than shell to do things in.

Thanks for the feedback. Definitely early days for all this. I'm continuing the work over on gitlab to avoid too much phabricator spam for the time being :)

linimon retitled this revision from flua: Add bindings for libifconfig to /usr/libexec/flua: Add bindings for libifconfig.Jun 26 2020, 7:57 AM
freqlabs edited the summary of this revision. (Show Details)

Updated diff to include man page, example code, build as a lua module instead of embedded in flua.
Diff is based on flua-libjail going in first.

There is still quite a bit of functionality missing from libifconfig that makes this feel poorly fleshed out.

From the first look the man page should be fine. Did you run igor and mandoc -Tlint against it?