Changeset View
Changeset View
Standalone View
Standalone View
share/examples/flua/libifconfig.lua
- This file was added.
Property | Old Value | New Value |
---|---|---|
File Mode | null | 100755 |
#!/usr/libexec/flua | |||||
--[[ | |||||
/*- | |||||
* SPDX-License-Identifier: BSD-2-Clause | |||||
* | |||||
* Copyright (c) 2020, Ryan Moeller <freqlabs@FreeBSD.org> | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in the | |||||
* documentation and/or other materials provided with the distribution. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* | |||||
* $FreeBSD$ | |||||
*/ | |||||
]]-- | |||||
-- ex: et sw=4: | |||||
local ifcfg = require('ifconfig').open() | |||||
local ifaces = ifcfg:foreach_iface(function(_, iface, ifs) | |||||
local name = iface:name() | |||||
ifs[name] = { | |||||
flags = iface:flags(), | |||||
media = ifcfg:get_media(name), | |||||
status = ifcfg:get_status(name), | |||||
capabilities = ifcfg:get_capabilities(name), | |||||
groups = ifcfg:get_groups(name), | |||||
metric = ifcfg:get_metric(name), | |||||
mtu = ifcfg:get_mtu(name), | |||||
nd6 = ifcfg:get_nd6(name), | |||||
bridge_status = ifcfg:get_bridge_status(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, {}), | |||||
sfp = (function() | |||||
local info = ifcfg:get_sfp_info(name) | |||||
return info and { | |||||
info = info, | |||||
vendor_info = ifcfg:get_sfp_vendor_info(name), | |||||
status = ifcfg:get_sfp_status(name), | |||||
-- Not generally interesting, | |||||
-- but for completeness: | |||||
-- dump = tostring(ifcfg:get_sfp_dump(name)), | |||||
} | |||||
end)(), | |||||
} | |||||
return ifs | |||||
end, {}) | |||||
print(ucl.to_json(ifaces)) |