From cd5d451eefc8a604a0cbd18aa53a43dedba1659b Mon Sep 17 00:00:00 2001 From: Olivier Lemasle Date: Wed, 27 Oct 2021 22:42:09 +0200 Subject: [PATCH] provider/cloudstack: use nm to get metadata address Currently, Ignition tries to use networkd DHCP leases to get the metadata service address in CloudStack provider. As Fedora CoreOS switched to NetworkManager, CloudStack metadata cannot be found anymore. With this commit, Ignition uses several methods in order to find the address of the CloudStack Virtual Router (which serves the metadata service): 1. A DNS request on "data-server"; 2. The DHCP option "dhcp_server_identifier" as returned by NetworkManager (queried using DBus) 3. The current process (networkd DHCP leases) 4. The default gateway (as defined in /proc/net/route) Cf. https://github.com/coreos/fedora-coreos-tracker/issues/716 --- go.mod | 1 + go.sum | 3 + internal/distro/distro.go | 2 + internal/networkmanager/networkmanager.go | 68 ++ internal/providers/cloudstack/cloudstack.go | 162 +++- .../Wifx/gonetworkmanager/AccessPoint.go | 169 ++++ .../Wifx/gonetworkmanager/ActiveConnection.go | 272 +++++++ .../Wifx/gonetworkmanager/Checkpoint.go | 79 ++ .../Wifx/gonetworkmanager/Connection.go | 163 ++++ .../Wifx/gonetworkmanager/DHCP4Config.go | 56 ++ .../Wifx/gonetworkmanager/DHCP6Config.go | 54 ++ .../Wifx/gonetworkmanager/Device.go | 359 +++++++++ .../Wifx/gonetworkmanager/DeviceDummy.go | 44 + .../Wifx/gonetworkmanager/DeviceGeneric.go | 53 ++ .../Wifx/gonetworkmanager/DeviceIpTunnel.go | 150 ++++ .../Wifx/gonetworkmanager/DeviceStatistics.go | 74 ++ .../Wifx/gonetworkmanager/DeviceWired.go | 80 ++ .../Wifx/gonetworkmanager/DeviceWireless.go | 194 +++++ .../Wifx/gonetworkmanager/IP4Config.go | 321 ++++++++ .../Wifx/gonetworkmanager/IP6Config.go | 215 +++++ .../github.com/Wifx/gonetworkmanager/LICENSE | 45 ++ .../Wifx/gonetworkmanager/NetworkManager.go | 752 ++++++++++++++++++ .../Wifx/gonetworkmanager/README.md | 19 + .../Wifx/gonetworkmanager/Settings.go | 129 +++ .../Wifx/gonetworkmanager/VpnConnection.go | 45 ++ .../github.com/Wifx/gonetworkmanager/enums.go | 290 +++++++ .../github.com/Wifx/gonetworkmanager/go.mod | 5 + .../github.com/Wifx/gonetworkmanager/go.sum | 2 + .../gonetworkmanager/nm80211apflags_string.go | 24 + .../gonetworkmanager/nm80211apsec_string.go | 63 ++ .../gonetworkmanager/nm80211mode_string.go | 26 + .../nmactivationstateflag_string.go | 51 ++ .../nmactiveconnectionstate_string.go | 27 + .../gonetworkmanager/nmcapability_string.go | 24 + .../nmcheckpointcreateflags_string.go | 39 + .../gonetworkmanager/nmconnectivity_string.go | 27 + .../gonetworkmanager/nmdevicestate_string.go | 49 ++ .../gonetworkmanager/nmdevicetype_string.go | 53 ++ .../Wifx/gonetworkmanager/nmmetered_string.go | 27 + .../Wifx/gonetworkmanager/nmstate_string.go | 53 ++ .../github.com/Wifx/gonetworkmanager/utils.go | 269 +++++++ vendor/modules.txt | 3 + 42 files changed, 4523 insertions(+), 18 deletions(-) create mode 100644 internal/networkmanager/networkmanager.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/AccessPoint.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/ActiveConnection.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/Checkpoint.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/Connection.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/DHCP4Config.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/DHCP6Config.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/Device.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/DeviceDummy.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/DeviceGeneric.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/DeviceIpTunnel.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/DeviceStatistics.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/DeviceWired.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/DeviceWireless.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/IP4Config.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/IP6Config.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/LICENSE create mode 100644 vendor/github.com/Wifx/gonetworkmanager/NetworkManager.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/README.md create mode 100644 vendor/github.com/Wifx/gonetworkmanager/Settings.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/VpnConnection.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/enums.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/go.mod create mode 100644 vendor/github.com/Wifx/gonetworkmanager/go.sum create mode 100644 vendor/github.com/Wifx/gonetworkmanager/nm80211apflags_string.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/nm80211apsec_string.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/nm80211mode_string.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/nmactivationstateflag_string.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/nmactiveconnectionstate_string.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/nmcapability_string.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/nmcheckpointcreateflags_string.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/nmconnectivity_string.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/nmdevicestate_string.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/nmdevicetype_string.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/nmmetered_string.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/nmstate_string.go create mode 100644 vendor/github.com/Wifx/gonetworkmanager/utils.go diff --git a/go.mod b/go.mod index 1ddcfe642..3f6d619ba 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( cloud.google.com/go v0.58.0 cloud.google.com/go/storage v1.9.0 + github.com/Wifx/gonetworkmanager v0.3.0 github.com/aws/aws-sdk-go v1.30.28 github.com/coreos/go-semver v0.3.0 github.com/coreos/go-systemd/v22 v22.0.0 diff --git a/go.sum b/go.sum index ccdd87377..c2db74afe 100644 --- a/go.sum +++ b/go.sum @@ -38,6 +38,8 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Wifx/gonetworkmanager v0.3.0 h1:Gn5uD11cBG6qg9w0NENjTjMNZ5Asz0zxRo7t2twPQ84= +github.com/Wifx/gonetworkmanager v0.3.0/go.mod h1:EdhHf2O00IZXfMv9LC6CS6SgTwcMTg/ZSDhGvch0cs8= github.com/aws/aws-sdk-go v1.30.28 h1:SaPM7dlmp7h3Lj1nJ4jdzOkTdom08+g20k7AU5heZYg= github.com/aws/aws-sdk-go v1.30.28/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -64,6 +66,7 @@ github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9 github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/godbus/dbus/v5 v5.0.2/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME= github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= diff --git a/internal/distro/distro.go b/internal/distro/distro.go index c4b23ea29..b5cd5f3ed 100644 --- a/internal/distro/distro.go +++ b/internal/distro/distro.go @@ -29,6 +29,7 @@ var ( // initrd file paths kernelCmdlinePath = "/proc/cmdline" bootIDPath = "/proc/sys/kernel/random/boot_id" + routeFilePath = "/proc/net/route" // initramfs directory containing distro-provided base config systemConfigDir = "/usr/lib/ignition" @@ -84,6 +85,7 @@ func DiskByPartUUIDDir() string { return diskByPartUUIDDir } func KernelCmdlinePath() string { return kernelCmdlinePath } func BootIDPath() string { return bootIDPath } +func RouteFilePath() string { return routeFilePath } func SystemConfigDir() string { return fromEnv("SYSTEM_CONFIG_DIR", systemConfigDir) } func GroupaddCmd() string { return groupaddCmd } diff --git a/internal/networkmanager/networkmanager.go b/internal/networkmanager/networkmanager.go new file mode 100644 index 000000000..062198a68 --- /dev/null +++ b/internal/networkmanager/networkmanager.go @@ -0,0 +1,68 @@ +// Copyright 2021 Red Hat, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package networkmanager + +import ( + "fmt" + + "github.com/Wifx/gonetworkmanager" +) + +type DHCPOptions map[string]string + +// GetDHCPOptions returns a map where keys are the interface names, for the +// network interfaces where DHCP is enabled, and values the maps of DHCP options +// +// This uses the NetworkManager DBus API. +func GetDHCPOptions() (map[string]DHCPOptions, error) { + // Create a new instance of gonetworkmanager + nm, err := gonetworkmanager.NewNetworkManager() + if err != nil { + return nil, err + } + + // Get network devices + devices, err := nm.GetPropertyDevices() + if err != nil { + return nil, err + } + + res := make(map[string]DHCPOptions) + + for _, device := range devices { + interfaceName, err := device.GetPropertyInterface() + if err != nil { + return nil, err + } + dhcpd, err := device.GetPropertyDHCP4Config() + if err != nil { + return nil, err + } + if dhcpd == nil { + continue + } + + dhcpo, err := dhcpd.GetPropertyOptions() + if err != nil { + return nil, err + } + res[interfaceName] = make(DHCPOptions) + for k, v := range dhcpo { + res[interfaceName][k] = fmt.Sprintf("%v", v) + } + } + + return res, nil +} diff --git a/internal/providers/cloudstack/cloudstack.go b/internal/providers/cloudstack/cloudstack.go index 2a86f0c21..6b3887b36 100644 --- a/internal/providers/cloudstack/cloudstack.go +++ b/internal/providers/cloudstack/cloudstack.go @@ -13,7 +13,8 @@ // limitations under the License. // The CloudStack provider fetches configurations from the userdata available in -// the config-drive. +// both the config-drive as well as the network metadata service. Whichever +// responds first is the config that is used. // NOTE: This provider is still EXPERIMENTAL. package cloudstack @@ -21,6 +22,7 @@ package cloudstack import ( "bufio" "context" + "encoding/hex" "fmt" "io/ioutil" "net" @@ -34,6 +36,7 @@ import ( "github.com/coreos/ignition/v2/config/v3_4_experimental/types" "github.com/coreos/ignition/v2/internal/distro" "github.com/coreos/ignition/v2/internal/log" + "github.com/coreos/ignition/v2/internal/networkmanager" "github.com/coreos/ignition/v2/internal/providers/util" "github.com/coreos/ignition/v2/internal/resource" @@ -43,7 +46,8 @@ import ( const ( configDriveUserdataPath = "/cloudstack/userdata/user_data.txt" - LeaseRetryInterval = 500 * time.Millisecond + retryInterval = 500 * time.Millisecond + dataServerDNSName = "data-server" ) func FetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) { @@ -87,7 +91,7 @@ func FetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) { }) dispatch("metadata service", func() ([]byte, error) { - return fetchConfigFromMetadataService(f) + return fetchConfigFromMetadataService(ctx, f) }) Loop: @@ -133,21 +137,90 @@ func findLease() (*os.File, error) { return nil, fmt.Errorf("could not list interfaces: %v", err) } + for _, iface := range ifaces { + lease, err := os.Open(fmt.Sprintf("/run/systemd/netif/leases/%d", iface.Index)) + if os.IsNotExist(err) { + continue + } else if err != nil { + return nil, err + } else { + return lease, nil + } + } + + return nil, fmt.Errorf("no leases found") +} + +func getVirtualRouterAddress(ctx context.Context, logger *log.Logger) (string, error) { for { - for _, iface := range ifaces { - lease, err := os.Open(fmt.Sprintf("/run/systemd/netif/leases/%d", iface.Index)) - if os.IsNotExist(err) { - continue - } else if err != nil { - return nil, err - } else { - return lease, nil - } + // Try "data-server" DNS entry first + if addr, err := getDataServerByDNS(); err != nil { + logger.Info("Could not find virtual router using DNS: %s", err.Error()) + // continue with NetworkManager + } else { + logger.Info("Virtual router address found using DNS: %s", addr) + return addr, nil + } + + // Then use NetworkManager to get the server option via DHCP + if addr, err := getNetworkManagerDHCPServerOption(); err != nil { + logger.Info("Could not find virtual router using NetworkManager DHCP server option: %s", err.Error()) + // continue with networkd + } else { + logger.Info("Virtual router address found using NetworkManager DHCP server option: %s", addr) + return addr, nil + } + + // Then try networkd + if addr, err := getDHCPServerAddress(); err != nil { + logger.Info("Could not find server address in DHCP networkd leases: %s", err.Error()) + // continue with default gateway + } else { + logger.Info("Virtual router address found using DHCP networkd leases: %s", addr) + return addr, nil + } + + // Fallback on default gateway + if addr, err := getDefaultGateway(); err != nil { + logger.Info("Could not find default gateway: %s", err.Error()) + } else { + logger.Info("Fallback on default gateway: %s", addr) + return addr, nil + } + + select { + case <-time.After(retryInterval): + case <-ctx.Done(): + return "", ctx.Err() } + } +} - fmt.Printf("No leases found. Waiting...") - time.Sleep(LeaseRetryInterval) +func getDataServerByDNS() (string, error) { + addrs, err := net.LookupHost(dataServerDNSName) + if err != nil { + return "", fmt.Errorf("could not execute DNS lookup: %v", err) + } + + for _, addr := range addrs { + return addr, nil + } + return "", fmt.Errorf("DNS Entry %s not found", dataServerDNSName) +} + +func getNetworkManagerDHCPServerOption() (string, error) { + options, err := networkmanager.GetDHCPOptions() + if err != nil { + return "", err } + for _, netIface := range options { + for k, v := range netIface { + if k == "dhcp_server_identifier" { + return v, nil + } + } + } + return "", fmt.Errorf("no DHCP option dhcp_server_identifier in NetworkManager") } func getDHCPServerAddress() (string, error) { @@ -174,6 +247,59 @@ func getDHCPServerAddress() (string, error) { return address, nil } +func getDefaultGateway() (string, error) { + file, err := os.Open(distro.RouteFilePath()) + if err != nil { + return "", fmt.Errorf("cannot read routes: %v", err) + } + defer file.Close() + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := scanner.Text() + + // Ignore headers + if strings.HasPrefix(line, "Iface") { + continue + } + + fields := strings.Fields(line) + if len(fields) < 3 { + return "", fmt.Errorf("cannot parse route files") + } + if fields[1] == "00000000" { + // destination is "0.0.0.0", so the gateway is the default gateway + gw, err := parseIP(fields[2]) + if err != nil { + return "", fmt.Errorf("cannot parse route files: %v", err) + } + return gw, nil + } + } + + if err := scanner.Err(); err != nil { + return "", fmt.Errorf("cannot parse route files: %v", err) + } + + return "", fmt.Errorf("default gateway not found") +} + +// parseIP takes the reverse hex IP address string from rooute +// file and converts it to dotted decimal IPv4 format. +func parseIP(str string) (string, error) { + if str == "" { + return "", fmt.Errorf("input is empty") + } + bytes, err := hex.DecodeString(str) + if err != nil { + return "", err + } + if len(bytes) != 4 { + return "", fmt.Errorf("invalid IPv4 address %s", str) + } + return net.IPv4(bytes[3], bytes[2], bytes[1], bytes[0]).String(), nil +} + func fetchConfigFromDevice(logger *log.Logger, ctx context.Context, label string) ([]byte, error) { for !labelExists(label) { logger.Debug("config drive (%q) not found. Waiting...", label) @@ -214,19 +340,19 @@ func fetchConfigFromDevice(logger *log.Logger, ctx context.Context, label string return ioutil.ReadFile(filepath.Join(mnt, configDriveUserdataPath)) } -func fetchConfigFromMetadataService(f *resource.Fetcher) ([]byte, error) { - addr, err := getDHCPServerAddress() +func fetchConfigFromMetadataService(ctx context.Context, f *resource.Fetcher) ([]byte, error) { + addr, err := getVirtualRouterAddress(ctx, f.Logger) if err != nil { return nil, err } - metadataServiceUrl := url.URL{ + metadataServiceURL := url.URL{ Scheme: "http", Host: addr, Path: "/latest/user-data", } - res, err := f.FetchToBuffer(metadataServiceUrl, resource.FetchOptions{}) + res, err := f.FetchToBuffer(metadataServiceURL, resource.FetchOptions{}) // the metadata server exists but doesn't contain any actual metadata, // assume that there is no config specified diff --git a/vendor/github.com/Wifx/gonetworkmanager/AccessPoint.go b/vendor/github.com/Wifx/gonetworkmanager/AccessPoint.go new file mode 100644 index 000000000..bad167e0c --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/AccessPoint.go @@ -0,0 +1,169 @@ +package gonetworkmanager + +import ( + "encoding/json" + + "github.com/godbus/dbus/v5" +) + +const ( + AccessPointInterface = NetworkManagerInterface + ".AccessPoint" + + /* Properties */ + AccessPointPropertyFlags = AccessPointInterface + ".Flags" // readable u + AccessPointPropertyWpaFlags = AccessPointInterface + ".WpaFlags" // readable u + AccessPointPropertyRsnFlags = AccessPointInterface + ".RsnFlags" // readable u + AccessPointPropertySsid = AccessPointInterface + ".Ssid" // readable ay + AccessPointPropertyFrequency = AccessPointInterface + ".Frequency" // readable u + AccessPointPropertyHwAddress = AccessPointInterface + ".HwAddress" // readable s + AccessPointPropertyMode = AccessPointInterface + ".Mode" // readable u + AccessPointPropertyMaxBitrate = AccessPointInterface + ".MaxBitrate" // readable u + AccessPointPropertyStrength = AccessPointInterface + ".Strength" // readable y + AccessPointPropertyLastSeen = AccessPointInterface + ".LastSeen" // readable i +) + +type AccessPoint interface { + GetPath() dbus.ObjectPath + + // GetFlags gets flags describing the capabilities of the access point. + GetPropertyFlags() (uint32, error) + + // GetWPAFlags gets flags describing the access point's capabilities + // according to WPA (Wifi Protected Access). + GetPropertyWPAFlags() (uint32, error) + + // GetRSNFlags gets flags describing the access point's capabilities + // according to the RSN (Robust Secure Network) protocol. + GetPropertyRSNFlags() (uint32, error) + + // GetSSID returns the Service Set Identifier identifying the access point. + GetPropertySSID() (string, error) + + // GetFrequency gets the radio channel frequency in use by the access point, + // in MHz. + GetPropertyFrequency() (uint32, error) + + // GetHWAddress gets the hardware address (BSSID) of the access point. + GetPropertyHWAddress() (string, error) + + // GetMode describes the operating mode of the access point. + GetPropertyMode() (Nm80211Mode, error) + + // GetMaxBitrate gets the maximum bitrate this access point is capable of, in + // kilobits/second (Kb/s). + GetPropertyMaxBitrate() (uint32, error) + + // GetStrength gets the current signal quality of the access point, in + // percent. + GetPropertyStrength() (uint8, error) + + MarshalJSON() ([]byte, error) +} + +func NewAccessPoint(objectPath dbus.ObjectPath) (AccessPoint, error) { + var a accessPoint + return &a, a.init(NetworkManagerInterface, objectPath) +} + +type accessPoint struct { + dbusBase +} + +func (a *accessPoint) GetPath() dbus.ObjectPath { + return a.obj.Path() +} + +func (a *accessPoint) GetPropertyFlags() (uint32, error) { + return a.getUint32Property(AccessPointPropertyFlags) +} + +func (a *accessPoint) GetPropertyWPAFlags() (uint32, error) { + return a.getUint32Property(AccessPointPropertyWpaFlags) +} + +func (a *accessPoint) GetPropertyRSNFlags() (uint32, error) { + return a.getUint32Property(AccessPointPropertyRsnFlags) +} + +func (a *accessPoint) GetPropertySSID() (string, error) { + r, err := a.getSliceByteProperty(AccessPointPropertySsid) + if err != nil { + return "", err + } + return string(r), nil +} + +func (a *accessPoint) GetPropertyFrequency() (uint32, error) { + return a.getUint32Property(AccessPointPropertyFrequency) +} + +func (a *accessPoint) GetPropertyHWAddress() (string, error) { + return a.getStringProperty(AccessPointPropertyHwAddress) +} + +func (a *accessPoint) GetPropertyMode() (Nm80211Mode, error) { + r, err := a.getUint32Property(AccessPointPropertyMode) + if err != nil { + return Nm80211ModeUnknown, err + } + return Nm80211Mode(r), nil +} + +func (a *accessPoint) GetPropertyMaxBitrate() (uint32, error) { + return a.getUint32Property(AccessPointPropertyMaxBitrate) +} + +func (a *accessPoint) GetPropertyStrength() (uint8, error) { + return a.getUint8Property(AccessPointPropertyStrength) +} + +func (a *accessPoint) MarshalJSON() ([]byte, error) { + Flags, err := a.GetPropertyFlags() + if err != nil { + return nil, err + } + WPAFlags, err := a.GetPropertyWPAFlags() + if err != nil { + return nil, err + } + RSNFlags, err := a.GetPropertyRSNFlags() + if err != nil { + return nil, err + } + SSID, err := a.GetPropertySSID() + if err != nil { + return nil, err + } + Frequency, err := a.GetPropertyFrequency() + if err != nil { + return nil, err + } + HWAddress, err := a.GetPropertyHWAddress() + if err != nil { + return nil, err + } + Mode, err := a.GetPropertyMode() + if err != nil { + return nil, err + } + MaxBitrate, err := a.GetPropertyMaxBitrate() + if err != nil { + return nil, err + } + Strength, err := a.GetPropertyStrength() + if err != nil { + return nil, err + } + + return json.Marshal(map[string]interface{}{ + "Flags": Flags, + "WPAFlags": WPAFlags, + "RSNFlags": RSNFlags, + "SSID": SSID, + "Frequency": Frequency, + "HWAddress": HWAddress, + "Mode": Mode.String(), + "MaxBitrate": MaxBitrate, + "Strength": Strength, + }) +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/ActiveConnection.go b/vendor/github.com/Wifx/gonetworkmanager/ActiveConnection.go new file mode 100644 index 000000000..3f6e3dc69 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/ActiveConnection.go @@ -0,0 +1,272 @@ +package gonetworkmanager + +import ( + "fmt" + "github.com/godbus/dbus/v5" +) + +const ( + ActiveConnectionInterface = NetworkManagerInterface + ".Connection.Active" + + /* Properties */ + ActiveConnectionPropertyConnection = ActiveConnectionInterface + ".Connection" // readable o + ActiveConnectionPropertySpecificObject = ActiveConnectionInterface + ".SpecificObject" // readable o + ActiveConnectionPropertyId = ActiveConnectionInterface + ".Id" // readable s + ActiveConnectionPropertyUuid = ActiveConnectionInterface + ".Uuid" // readable s + ActiveConnectionPropertyType = ActiveConnectionInterface + ".Type" // readable s + ActiveConnectionPropertyDevices = ActiveConnectionInterface + ".Devices" // readable ao + ActiveConnectionPropertyState = ActiveConnectionInterface + ".State" // readable u + ActiveConnectionPropertyStateFlags = ActiveConnectionInterface + ".StateFlags" // readable u + ActiveConnectionPropertyDefault = ActiveConnectionInterface + ".Default" // readable b + ActiveConnectionPropertyIp4Config = ActiveConnectionInterface + ".Ip4Config" // readable o + ActiveConnectionPropertyDhcp4Config = ActiveConnectionInterface + ".Dhcp4Config" // readable o + ActiveConnectionPropertyDefault6 = ActiveConnectionInterface + ".Default6" // readable b + ActiveConnectionPropertyIp6Config = ActiveConnectionInterface + ".Ip6Config" // readable o + ActiveConnectionPropertyDhcp6Config = ActiveConnectionInterface + ".Dhcp6Config" // readable o + ActiveConnectionPropertyVpn = ActiveConnectionInterface + ".Vpn" // readable b + ActiveConnectionPropertyMaster = ActiveConnectionInterface + ".Master" // readable o + + /* Signals */ + ActiveConnectionSignalStateChanged = "StateChanged" // u state, u reason + +) + +type ActiveConnection interface { + GetPath() dbus.ObjectPath + + // GetConnectionSettings gets connection object of the connection. + GetPropertyConnection() (Connection, error) + + // GetSpecificObject gets a specific object associated with the active connection. + GetPropertySpecificObject() (AccessPoint, error) + + // GetID gets the ID of the connection. + GetPropertyID() (string, error) + + // GetUUID gets the UUID of the connection. + GetPropertyUUID() (string, error) + + // GetType gets the type of the connection. + GetPropertyType() (string, error) + + // GetDevices gets array of device objects which are part of this active connection. + GetPropertyDevices() ([]Device, error) + + // GetState gets the state of the connection. + GetPropertyState() (NmActiveConnectionState, error) + + // GetStateFlags gets the state flags of the connection. + GetPropertyStateFlags() (uint32, error) + + // GetDefault gets the default IPv4 flag of the connection. + GetPropertyDefault() (bool, error) + + // GetIP4Config gets the IP4Config of the connection. + GetPropertyIP4Config() (IP4Config, error) + + // GetDHCP4Config gets the DHCP6Config of the connection. + GetPropertyDHCP4Config() (DHCP4Config, error) + + // GetDefault gets the default IPv6 flag of the connection. + GetPropertyDefault6() (bool, error) + + // GetIP6Config gets the IP6Config of the connection. + GetPropertyIP6Config() (IP6Config, error) + + // GetDHCP6Config gets the DHCP4Config of the connection. + GetPropertyDHCP6Config() (DHCP6Config, error) + + // GetVPN gets the VPN flag of the connection. + GetPropertyVPN() (bool, error) + + // GetMaster gets the master device of the connection. + GetPropertyMaster() (Device, error) + + SubscribeState(receiver chan StateChange, exit chan struct{}) (err error) +} + +func NewActiveConnection(objectPath dbus.ObjectPath) (ActiveConnection, error) { + var a activeConnection + return &a, a.init(NetworkManagerInterface, objectPath) +} + +type activeConnection struct { + dbusBase +} + +func (a *activeConnection) GetPath() dbus.ObjectPath { + return a.obj.Path() +} + +func (a *activeConnection) GetPropertyConnection() (Connection, error) { + path, err := a.getObjectProperty(ActiveConnectionPropertyConnection) + if err != nil { + return nil, err + } + con, err := NewConnection(path) + if err != nil { + return nil, err + } + return con, nil +} + +func (a *activeConnection) GetPropertySpecificObject() (AccessPoint, error) { + path, err := a.getObjectProperty(ActiveConnectionPropertySpecificObject) + if err != nil { + return nil, err + } + ap, err := NewAccessPoint(path) + if err != nil { + return nil, err + } + return ap, nil +} + +func (a *activeConnection) GetPropertyID() (string, error) { + return a.getStringProperty(ActiveConnectionPropertyId) +} + +func (a *activeConnection) GetPropertyUUID() (string, error) { + return a.getStringProperty(ActiveConnectionPropertyUuid) +} + +func (a *activeConnection) GetPropertyType() (string, error) { + return a.getStringProperty(ActiveConnectionPropertyType) +} + +func (a *activeConnection) GetPropertyDevices() ([]Device, error) { + paths, err := a.getSliceObjectProperty(ActiveConnectionPropertyDevices) + if err != nil { + return nil, err + } + devices := make([]Device, len(paths)) + for i, path := range paths { + devices[i], err = DeviceFactory(path) + if err != nil { + return nil, err + } + } + return devices, nil +} +func (a *activeConnection) GetPropertyState() (NmActiveConnectionState, error) { + v, err := a.getUint32Property(ActiveConnectionPropertyState) + return NmActiveConnectionState(v), err +} + +func (a *activeConnection) GetPropertyStateFlags() (uint32, error) { + return a.getUint32Property(ActiveConnectionPropertyStateFlags) +} + +func (a *activeConnection) GetPropertyDefault() (bool, error) { + b, err := a.getProperty(ActiveConnectionPropertyDefault) + if err != nil { + return false, err + } + return b.(bool), nil +} + +func (a *activeConnection) GetPropertyIP4Config() (IP4Config, error) { + path, err := a.getObjectProperty(ActiveConnectionPropertyIp4Config) + if err != nil || path == "/" { + return nil, err + } + return NewIP4Config(path) +} + +func (a *activeConnection) GetPropertyDHCP4Config() (DHCP4Config, error) { + path, err := a.getObjectProperty(ActiveConnectionPropertyDhcp4Config) + if err != nil || path == "/" { + return nil, err + } + return NewDHCP4Config(path) +} + +func (a *activeConnection) GetPropertyDefault6() (bool, error) { + return a.getBoolProperty(ActiveConnectionPropertyDefault6) +} + +func (a *activeConnection) GetPropertyIP6Config() (IP6Config, error) { + path, err := a.getObjectProperty(ActiveConnectionPropertyIp6Config) + if err != nil || path == "/" { + return nil, err + } + + return NewIP6Config(path) +} + +func (a *activeConnection) GetPropertyDHCP6Config() (DHCP6Config, error) { + path, err := a.getObjectProperty(ActiveConnectionPropertyDhcp6Config) + if err != nil || path == "/" { + return nil, err + } + + return NewDHCP6Config(path) +} + +func (a *activeConnection) GetPropertyVPN() (bool, error) { + ret, err := a.getProperty(ActiveConnectionPropertyVpn) + if err != nil { + return false, err + } + return ret.(bool), nil +} + +func (a *activeConnection) GetPropertyMaster() (Device, error) { + path, err := a.getObjectProperty(ActiveConnectionPropertyMaster) + if err != nil || path == "/" { + return nil, err + } + return DeviceFactory(path) +} + +type StateChange struct { + State NmActiveConnectionState + Reason NmActiveConnectionStateReason +} + +func (a *activeConnection) SubscribeState(receiver chan StateChange, exit chan struct{}) (err error) { + + channel := make(chan *dbus.Signal, 1) + + a.conn.Signal(channel) + + err = a.conn.AddMatchSignal( + dbus.WithMatchInterface(ActiveConnectionInterface), + dbus.WithMatchMember(ActiveConnectionSignalStateChanged), + dbus.WithMatchObjectPath(a.GetPath()), + ) + if err != nil { + return err + } + + go func() { + for { + select { + case signal, ok := <-channel: + + if !ok { + err = fmt.Errorf("connection closed for %s", ActiveConnectionSignalStateChanged) + return + } + + if signal.Path != a.GetPath() || signal.Name != ActiveConnectionInterface+"."+ActiveConnectionSignalStateChanged { + continue + } + + stateChange := StateChange{ + State: NmActiveConnectionState(signal.Body[0].(uint32)), + Reason: NmActiveConnectionStateReason(signal.Body[1].(uint32)), + } + + receiver <- stateChange + + case <-exit: + a.conn.RemoveSignal(channel) + close(channel) + return + } + } + }() + + return +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/Checkpoint.go b/vendor/github.com/Wifx/gonetworkmanager/Checkpoint.go new file mode 100644 index 000000000..cccf063cd --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/Checkpoint.go @@ -0,0 +1,79 @@ +package gonetworkmanager + +import ( + "encoding/json" + + "github.com/godbus/dbus/v5" +) + +const ( + CheckpointInterface = NetworkManagerInterface + ".Checkpoint" + + /* Properties */ + CheckpointPropertyDevices = CheckpointInterface + ".Devices" // readable ao + CheckpointPropertyCreated = CheckpointInterface + ".Created" // readable x + CheckpointPropertyRollbackTimeout = CheckpointInterface + ".RollbackTimeout" // readable u +) + +type Checkpoint interface { + GetPath() dbus.ObjectPath + + // Array of object paths for devices which are part of this checkpoint. + GetPropertyDevices() ([]Device, error) + + // The timestamp (in CLOCK_BOOTTIME milliseconds) of checkpoint creation. + GetPropertyCreated() (int64, error) + + // Timeout in seconds for automatic rollback, or zero. + GetPropertyRollbackTimeout() (uint32, error) + + MarshalJSON() ([]byte, error) +} + +func NewCheckpoint(objectPath dbus.ObjectPath) (Checkpoint, error) { + var c checkpoint + return &c, c.init(NetworkManagerInterface, objectPath) +} + +type checkpoint struct { + dbusBase +} + +func (c *checkpoint) GetPropertyDevices() ([]Device, error) { + devicesPaths, err := c.getSliceObjectProperty(CheckpointPropertyDevices) + if err != nil { + return nil, err + } + + devices := make([]Device, len(devicesPaths)) + for i, path := range devicesPaths { + devices[i], err = NewDevice(path) + if err != nil { + return devices, err + } + } + + return devices, nil +} + +func (c *checkpoint) GetPropertyCreated() (int64, error) { + return c.getInt64Property(CheckpointPropertyCreated) +} + +func (c *checkpoint) GetPropertyRollbackTimeout() (uint32, error) { + return c.getUint32Property(CheckpointPropertyRollbackTimeout) +} + +func (c *checkpoint) GetPath() dbus.ObjectPath { + return c.obj.Path() +} + +func (c *checkpoint) MarshalJSON() ([]byte, error) { + m := make(map[string]interface{}) + + m["Devices"], _ = c.GetPropertyDevices() + m["Created"], _ = c.GetPropertyCreated() + m["RollbackTimeout"], _ = c.GetPropertyRollbackTimeout() + + return json.Marshal(m) +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/Connection.go b/vendor/github.com/Wifx/gonetworkmanager/Connection.go new file mode 100644 index 000000000..103117877 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/Connection.go @@ -0,0 +1,163 @@ +package gonetworkmanager + +import ( + "encoding/json" + + "github.com/godbus/dbus/v5" +) + +const ( + ConnectionInterface = SettingsInterface + ".Connection" + + /* Methods */ + ConnectionUpdate = ConnectionInterface + ".Update" + ConnectionUpdateUnsaved = ConnectionInterface + ".UpdateUnsaved" + ConnectionDelete = ConnectionInterface + ".Delete" + ConnectionGetSettings = ConnectionInterface + ".GetSettings" + ConnectionGetSecrets = ConnectionInterface + ".GetSecrets" + ConnectionClearSecrets = ConnectionInterface + ".ClearSecrets" + ConnectionSave = ConnectionInterface + ".Save" + ConnectionUpdate2 = ConnectionInterface + ".Update2" + + /* Properties */ + ConnectionPropertyUnsaved = ConnectionInterface + ".Unsaved" // readable b + ConnectionPropertyFlags = ConnectionInterface + ".Flags" // readable u + ConnectionPropertyFilename = ConnectionInterface + ".Filename" // readable s +) + +//type ConnectionSettings map[string]map[string]interface{} +type ConnectionSettings map[string]map[string]interface{} + +type Connection interface { + GetPath() dbus.ObjectPath + + // Update the connection with new settings and properties (replacing all previous settings and properties) and save the connection to disk. Secrets may be part of the update request, and will be either stored in persistent storage or sent to a Secret Agent for storage, depending on the flags associated with each secret. + Update(settings ConnectionSettings) error + + // Update the connection with new settings and properties (replacing all previous settings and properties) but do not immediately save the connection to disk. Secrets may be part of the update request and may sent to a Secret Agent for storage, depending on the flags associated with each secret. Use the 'Save' method to save these changes to disk. Note that unsaved changes will be lost if the connection is reloaded from disk (either automatically on file change or due to an explicit ReloadConnections call). + UpdateUnsaved(settings ConnectionSettings) error + + // Delete the connection. + Delete() error + + // GetSettings gets the settings maps describing this network configuration. + // This will never include any secrets required for connection to the + // network, as those are often protected. Secrets must be requested + // separately using the GetSecrets() method. + GetSettings() (ConnectionSettings, error) + + // Get the secrets belonging to this network configuration. Only secrets from + // persistent storage or a Secret Agent running in the requestor's session + // will be returned. The user will never be prompted for secrets as a result + // of this request. + GetSecrets(settingName string) (ConnectionSettings, error) + + // Clear the secrets belonging to this network connection profile. + ClearSecrets() error + + // Saves a "dirty" connection (that had previously been updated with UpdateUnsaved) to persistent storage. + Save() error + + // If set, indicates that the in-memory state of the connection does not match the on-disk state. This flag will be set when UpdateUnsaved() is called or when any connection details change, and cleared when the connection is saved to disk via Save() or from internal operations. + GetPropertyUnsaved() (bool, error) + + // Additional flags of the connection profile. + GetPropertyFlags() (uint32, error) + + // File that stores the connection in case the connection is file-backed. + GetPropertyFilename() (string, error) + + MarshalJSON() ([]byte, error) +} + +func NewConnection(objectPath dbus.ObjectPath) (Connection, error) { + var c connection + return &c, c.init(NetworkManagerInterface, objectPath) +} + +type connection struct { + dbusBase +} + +func (c *connection) GetPath() dbus.ObjectPath { + return c.obj.Path() +} + +func (c *connection) Update(settings ConnectionSettings) error { + return c.call(ConnectionUpdate, settings) +} + +func (c *connection) UpdateUnsaved(settings ConnectionSettings) error { + return c.call(ConnectionUpdateUnsaved, settings) +} + +func (c *connection) Delete() error { + return c.call(ConnectionDelete) +} + +func (c *connection) GetSettings() (ConnectionSettings, error) { + var settings map[string]map[string]dbus.Variant + err := c.callWithReturn(&settings, ConnectionGetSettings) + + if err != nil { + return nil, err + } + + rv := make(ConnectionSettings) + + for k1, v1 := range settings { + rv[k1] = make(map[string]interface{}) + + for k2, v2 := range v1 { + rv[k1][k2] = v2.Value() + } + } + + return rv, nil +} + +func (c *connection) GetSecrets(settingName string) (ConnectionSettings, error) { + var settings map[string]map[string]dbus.Variant + err := c.callWithReturn(&settings, ConnectionGetSecrets, settingName) + + if err != nil { + return nil, err + } + + rv := make(ConnectionSettings) + + for k1, v1 := range settings { + rv[k1] = make(map[string]interface{}) + + for k2, v2 := range v1 { + rv[k1][k2] = v2.Value() + } + } + + return rv, nil +} + +func (c *connection) ClearSecrets() error { + return c.call(ConnectionClearSecrets) +} + +func (c *connection) Save() error { + return c.call(ConnectionSave) +} + +func (c *connection) GetPropertyUnsaved() (bool, error) { + return c.getBoolProperty(ConnectionPropertyUnsaved) +} + +func (c *connection) GetPropertyFlags() (uint32, error) { + return c.getUint32Property(ConnectionPropertyFlags) +} + +func (c *connection) GetPropertyFilename() (string, error) { + return c.getStringProperty(ConnectionPropertyFilename) +} + +func (c *connection) MarshalJSON() ([]byte, error) { + s, _ := c.GetSettings() + return json.Marshal(s) +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/DHCP4Config.go b/vendor/github.com/Wifx/gonetworkmanager/DHCP4Config.go new file mode 100644 index 000000000..f946f20a0 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/DHCP4Config.go @@ -0,0 +1,56 @@ +package gonetworkmanager + +import ( + "encoding/json" + + "github.com/godbus/dbus/v5" +) + +const ( + DHCP4ConfigInterface = NetworkManagerInterface + ".DHCP4Config" + + // Properties + DHCP4ConfigPropertyOptions = DHCP4ConfigInterface + ".Options" +) + +type DHCP4Options map[string]interface{} + +type DHCP4Config interface { + // GetOptions gets options map of configuration returned by the IPv4 DHCP server. + GetPropertyOptions() (DHCP4Options, error) + + MarshalJSON() ([]byte, error) +} + +func NewDHCP4Config(objectPath dbus.ObjectPath) (DHCP4Config, error) { + var c dhcp4Config + return &c, c.init(NetworkManagerInterface, objectPath) +} + +type dhcp4Config struct { + dbusBase +} + +func (c *dhcp4Config) GetPropertyOptions() (DHCP4Options, error) { + options, err := c.getMapStringVariantProperty(DHCP4ConfigPropertyOptions) + rv := make(DHCP4Options) + if err != nil { + return rv, err + } + + for k, v := range options { + rv[k] = v.Value() + } + + return rv, nil +} + +func (c *dhcp4Config) MarshalJSON() ([]byte, error) { + Options, err := c.GetPropertyOptions() + if err != nil { + return nil, err + } + return json.Marshal(map[string]interface{}{ + "Options": Options, + }) +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/DHCP6Config.go b/vendor/github.com/Wifx/gonetworkmanager/DHCP6Config.go new file mode 100644 index 000000000..2dde63c01 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/DHCP6Config.go @@ -0,0 +1,54 @@ +package gonetworkmanager + +import ( + "encoding/json" + + "github.com/godbus/dbus/v5" +) + +const ( + DHCP6ConfigInterface = NetworkManagerInterface + ".DHCP6Config" + + // Properties + DHCP6ConfigPropertyOptions = DHCP6ConfigInterface + ".Options" +) + +type DHCP6Options map[string]interface{} + +type DHCP6Config interface { + // GetOptions gets options map of configuration returned by the IPv4 DHCP server. + GetPropertyOptions() (DHCP6Options, error) + + MarshalJSON() ([]byte, error) +} + +func NewDHCP6Config(objectPath dbus.ObjectPath) (DHCP6Config, error) { + var c dhcp6Config + return &c, c.init(NetworkManagerInterface, objectPath) +} + +type dhcp6Config struct { + dbusBase +} + +func (c *dhcp6Config) GetPropertyOptions() (DHCP6Options, error) { + options, err := c.getMapStringVariantProperty(DHCP6ConfigPropertyOptions) + rv := make(DHCP6Options) + + if err != nil { + return rv, err + } + + for k, v := range options { + rv[k] = v.Value() + } + + return rv, nil +} + +func (c *dhcp6Config) MarshalJSON() ([]byte, error) { + m := make(map[string]interface{}) + m["Options"], _ = c.GetPropertyOptions() + + return json.Marshal(m) +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/Device.go b/vendor/github.com/Wifx/gonetworkmanager/Device.go new file mode 100644 index 000000000..ab25eba40 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/Device.go @@ -0,0 +1,359 @@ +package gonetworkmanager + +import ( + "encoding/json" + + "github.com/godbus/dbus/v5" +) + +const ( + DeviceInterface = NetworkManagerInterface + ".Device" + + /* Methods */ + DeviceReapply = DeviceInterface + ".Reapply" + DeviceGetAppliedConnection = DeviceInterface + ".GetAppliedConnection" + DeviceDisconnect = DeviceInterface + ".Disconnect" + DeviceDelete = DeviceInterface + ".Delete" + + /* Properties */ + DevicePropertyUdi = DeviceInterface + ".Udi" // readable s + DevicePropertyInterface = DeviceInterface + ".Interface" // readable s + DevicePropertyIpInterface = DeviceInterface + ".IpInterface" // readable s + DevicePropertyDriver = DeviceInterface + ".Driver" // readable s + DevicePropertyDriverVersion = DeviceInterface + ".DriverVersion" // readable s + DevicePropertyFirmwareVersion = DeviceInterface + ".FirmwareVersion" // readable s + DevicePropertyCapabilities = DeviceInterface + ".Capabilities" // readable u + DevicePropertyState = DeviceInterface + ".State" // readable u + DevicePropertyStateReason = DeviceInterface + ".StateReason" // readable (uu) + DevicePropertyActiveConnection = DeviceInterface + ".ActiveConnection" // readable o + DevicePropertyIp4Config = DeviceInterface + ".Ip4Config" // readable o + DevicePropertyDhcp4Config = DeviceInterface + ".Dhcp4Config" // readable o + DevicePropertyIp6Config = DeviceInterface + ".Ip6Config" // readable o + DevicePropertyDhcp6Config = DeviceInterface + ".Dhcp6Config" // readable o + DevicePropertyManaged = DeviceInterface + ".Managed" // readwrite b + DevicePropertyAutoconnect = DeviceInterface + ".Autoconnect" // readwrite b + DevicePropertyFirmwareMissing = DeviceInterface + ".FirmwareMissing" // readable b + DevicePropertyNmPluginMissing = DeviceInterface + ".NmPluginMissing" // readable b + DevicePropertyDeviceType = DeviceInterface + ".DeviceType" // readable u + DevicePropertyAvailableConnections = DeviceInterface + ".AvailableConnections" // readable ao + DevicePropertyPhysicalPortId = DeviceInterface + ".PhysicalPortId" // readable s + DevicePropertyMtu = DeviceInterface + ".Mtu" // readable u + DevicePropertyMetered = DeviceInterface + ".Metered" // readable u + DevicePropertyLldpNeighbors = DeviceInterface + ".LldpNeighbors" // readable aa{sv} + DevicePropertyReal = DeviceInterface + ".Real" // readable b + DevicePropertyIp4Connectivity = DeviceInterface + ".Ip4Connectivity" // readable u +) + +func DeviceFactory(objectPath dbus.ObjectPath) (Device, error) { + d, err := NewDevice(objectPath) + if err != nil { + return nil, err + } + + deviceType, err := d.GetPropertyDeviceType() + if err != nil { + return nil, err + } + + switch deviceType { + case NmDeviceTypeDummy: + return NewDeviceDummy(objectPath) + case NmDeviceTypeGeneric: + return NewDeviceGeneric(objectPath) + case NmDeviceTypeIpTunnel: + return NewDeviceIpTunnel(objectPath) + case NmDeviceTypeEthernet: + return NewDeviceWired(objectPath) + case NmDeviceTypeWifi: + return NewDeviceWireless(objectPath) + } + + return d, nil +} + +type Device interface { + GetPath() dbus.ObjectPath + + // Attempts to update the configuration of a device without deactivating it. NetworkManager has the concept of connections, which are profiles that contain the configuration for a networking device. Those connections are exposed via D-Bus as individual objects that can be created, modified and deleted. When activating such a settings-connection on a device, the settings-connection is cloned to become an applied-connection and used to configure the device (see GetAppliedConnection). Subsequent modification of the settings-connection don't propagate automatically to the device's applied-connection (with exception of the firewall-zone and the metered property). For the changes to take effect, you can either re-activate the settings-connection, or call Reapply. The Reapply call allows you to directly update the applied-connection and reconfigure the device. Reapply can also be useful if the currently applied-connection is equal to the connection that is about to be reapplied. This allows to reconfigure the device and revert external changes like removing or adding an IP address (which NetworkManager doesn't revert automatically because it is assumed that the user made these changes intentionally outside of NetworkManager). Reapply can make the applied-connection different from the settings-connection, just like updating the settings-connection can make them different. + // connection: The optional connection settings that will be reapplied on the device. If empty, the currently active settings-connection will be used. The connection cannot arbitrarly differ from the current applied-connection otherwise the call will fail. Only certain changes are supported, like adding or removing IP addresses. + // versionId: If non-zero, the current version id of the applied-connection must match. The current version id can be retrieved via GetAppliedConnection. This optional argument allows to catch concurrent modifications between the GetAppliedConnection call and Reapply. + // flags: Flags which would modify the behavior of the Reapply call. There are no flags defined currently and the users should use the value of 0. + Reapply(connection Connection, versionId uint64, flags uint32) error + + // Disconnects a device and prevents the device from automatically activating further connections without user intervention. + Disconnect() error + + // Deletes a software device from NetworkManager and removes the interface from the system. The method returns an error when called for a hardware device. + Delete() error + + // Operating-system specific transient device hardware identifier. This is an opaque string representing the underlying hardware for the device, and shouldn't be used to keep track of individual devices. For some device types (Bluetooth, Modems) it is an identifier used by the hardware service (ie bluez or ModemManager) to refer to that device, and client programs use it get additional information from those services which NM does not provide. The Udi is not guaranteed to be consistent across reboots or hotplugs of the hardware. If you're looking for a way to uniquely track each device in your application, use the object path. If you're looking for a way to track a specific piece of hardware across reboot or hotplug, use a MAC address or USB serial number. + GetPropertyUdi() (string, error) + + // The name of the device's control (and often data) interface. Note that non UTF-8 characters are backslash escaped, so the resulting name may be longer then 15 characters. Use g_strcompress() to revert the escaping. + GetPropertyInterface() (string, error) + + // The name of the device's data interface when available. This property may not refer to the actual data interface until the device has successfully established a data connection, indicated by the device's State becoming ACTIVATED. Note that non UTF-8 characters are backslash escaped, so the resulting name may be longer then 15 characters. Use g_strcompress() to revert the escaping. + GetPropertyIpInterface() (string, error) + + // The driver handling the device. Non-UTF-8 sequences are backslash escaped. Use g_strcompress() to revert. + GetPropertyDriver() (string, error) + + // The version of the driver handling the device. Non-UTF-8 sequences are backslash escaped. Use g_strcompress() to revert. + GetPropertyDriverVersion() (string, error) + + // The firmware version for the device. Non-UTF-8 sequences are backslash escaped. Use g_strcompress() to revert. + GetPropertyFirmwareVersion() (string, error) + + // The current state of the device. + GetPropertyState() (NmDeviceState, error) + + // Object path of an ActiveConnection object that "owns" this device during activation. The ActiveConnection object tracks the life-cycle of a connection to a specific network and implements the org.freedesktop.NetworkManager.Connection.Active D-Bus interface. + GetPropertyActiveConnection() (ActiveConnection, error) + + // Object path of the Ip4Config object describing the configuration of the device. Only valid when the device is in the NM_DEVICE_STATE_ACTIVATED state. + GetPropertyIP4Config() (IP4Config, error) + + // Object path of the Dhcp4Config object describing the DHCP options returned by the DHCP server. Only valid when the device is in the NM_DEVICE_STATE_ACTIVATED state. + GetPropertyDHCP4Config() (DHCP4Config, error) + + // Object path of the Ip6Config object describing the configuration of the device. Only valid when the device is in the NM_DEVICE_STATE_ACTIVATED state. + GetPropertyIP6Config() (IP6Config, error) + + // Object path of the Dhcp6Config object describing the DHCP options returned by the DHCP server. Only valid when the device is in the NM_DEVICE_STATE_ACTIVATED state. + GetPropertyDHCP6Config() (DHCP6Config, error) + + // Whether or not this device is managed by NetworkManager. Setting this property has a similar effect to configuring the device as unmanaged via the keyfile.unmanaged-devices setting in NetworkManager.conf. Changes to this value are not persistent and lost after NetworkManager restart. + GetPropertyManaged() (bool, error) + SetPropertyManaged(bool) error + + // If TRUE, indicates the device is allowed to autoconnect. If FALSE, manual intervention is required before the device will automatically connect to a known network, such as activating a connection using the device, or setting this property to TRUE. This property cannot be set to TRUE for default-unmanaged devices, since they never autoconnect. + GetPropertyAutoConnect() (bool, error) + + // If TRUE, indicates the device is likely missing firmware necessary for its operation. + GetPropertyFirmwareMissing() (bool, error) + + // If TRUE, indicates the NetworkManager plugin for the device is likely missing or misconfigured. + GetPropertyNmPluginMissing() (bool, error) + + // The general type of the network device; ie Ethernet, Wi-Fi, etc. + GetPropertyDeviceType() (NmDeviceType, error) + + // An array of object paths of every configured connection that is currently 'available' through this device. + GetPropertyAvailableConnections() ([]Connection, error) + + // If non-empty, an (opaque) indicator of the physical network port associated with the device. This can be used to recognize when two seemingly-separate hardware devices are actually just different virtual interfaces to the same physical port. + GetPropertyPhysicalPortId() (string, error) + + // The device MTU (maximum transmission unit). + GetPropertyMtu() (uint32, error) + + // True if the device exists, or False for placeholder devices that do not yet exist but could be automatically created by NetworkManager if one of their AvailableConnections was activated. + GetPropertyReal() (bool, error) + + MarshalJSON() ([]byte, error) +} + +func NewDevice(objectPath dbus.ObjectPath) (Device, error) { + var d device + return &d, d.init(NetworkManagerInterface, objectPath) +} + +type device struct { + dbusBase +} + +func (d *device) GetPath() dbus.ObjectPath { + return d.obj.Path() +} + +func (d *device) Reapply(connection Connection, versionId uint64, flags uint32) error { + return d.call(DeviceReapply, connection, versionId, flags) +} + +func (d *device) Disconnect() error { + return d.call(DeviceDisconnect) +} + +func (d *device) Delete() error { + return d.call(DeviceDelete) +} + +func (d *device) GetPropertyUdi() (string, error) { + return d.getStringProperty(DevicePropertyUdi) +} + +func (d *device) GetPropertyInterface() (string, error) { + return d.getStringProperty(DevicePropertyInterface) +} + +func (d *device) GetPropertyIpInterface() (string, error) { + return d.getStringProperty(DevicePropertyIpInterface) +} + +func (d *device) GetPropertyDriver() (string, error) { + return d.getStringProperty(DevicePropertyDriver) +} + +func (d *device) GetPropertyDriverVersion() (string, error) { + return d.getStringProperty(DevicePropertyDriverVersion) +} + +func (d *device) GetPropertyFirmwareVersion() (string, error) { + return d.getStringProperty(DevicePropertyFirmwareVersion) +} + +func (d *device) GetPropertyState() (NmDeviceState, error) { + r, err := d.getUint32Property(DevicePropertyState) + if err != nil { + return NmDeviceStateFailed, err + } + return NmDeviceState(r), nil +} + +func (d *device) GetPropertyActiveConnection() (ActiveConnection, error) { + path, err := d.getObjectProperty(DevicePropertyActiveConnection) + if err != nil || path == "/" { + return nil, err + } + + return NewActiveConnection(path) +} + +func (d *device) GetPropertyIP4Config() (IP4Config, error) { + path, err := d.getObjectProperty(DevicePropertyIp4Config) + if err != nil || path == "/" { + return nil, err + } + + return NewIP4Config(path) +} + +func (d *device) GetPropertyDHCP4Config() (DHCP4Config, error) { + path, err := d.getObjectProperty(DevicePropertyDhcp4Config) + if err != nil || path == "/" { + return nil, err + } + + return NewDHCP4Config(path) +} + +func (d *device) GetPropertyIP6Config() (IP6Config, error) { + path, err := d.getObjectProperty(DevicePropertyIp6Config) + if err != nil || path == "/" { + return nil, err + } + + return NewIP6Config(path) +} + +func (d *device) GetPropertyDHCP6Config() (DHCP6Config, error) { + path, err := d.getObjectProperty(DevicePropertyDhcp6Config) + if err != nil || path == "/" { + return nil, err + } + + return NewDHCP6Config(path) +} + +func (d *device) GetPropertyManaged() (bool, error) { + return d.getBoolProperty(DevicePropertyManaged) +} + +func (d *device) SetPropertyManaged(managed bool) error { + return d.setProperty(DevicePropertyManaged, managed) +} + +func (d *device) GetPropertyAutoConnect() (bool, error) { + return d.getBoolProperty(DevicePropertyAutoconnect) +} + +func (d *device) GetPropertyFirmwareMissing() (bool, error) { + return d.getBoolProperty(DevicePropertyFirmwareMissing) +} + +func (d *device) GetPropertyNmPluginMissing() (bool, error) { + return d.getBoolProperty(DevicePropertyNmPluginMissing) +} + +func (d *device) GetPropertyDeviceType() (NmDeviceType, error) { + v, err := d.getUint32Property(DevicePropertyDeviceType) + return NmDeviceType(v), err +} + +func (d *device) GetPropertyAvailableConnections() ([]Connection, error) { + connPaths, err := d.getSliceObjectProperty(DevicePropertyAvailableConnections) + if err != nil { + return nil, err + } + + conns := make([]Connection, len(connPaths)) + for i, path := range connPaths { + conns[i], err = NewConnection(path) + if err != nil { + return conns, err + } + } + + return conns, nil +} + +func (d *device) GetPropertyPhysicalPortId() (string, error) { + return d.getStringProperty(DevicePropertyPhysicalPortId) +} + +func (d *device) GetPropertyMtu() (uint32, error) { + return d.getUint32Property(DevicePropertyMtu) +} + +func (d *device) GetPropertyReal() (bool, error) { + return d.getBoolProperty(DevicePropertyReal) +} + +func (d *device) marshalMap() (map[string]interface{}, error) { + Interface, err := d.GetPropertyInterface() + if err != nil { + return nil, err + } + IpInterface, err := d.GetPropertyIpInterface() + if err != nil { + return nil, err + } + State, err := d.GetPropertyState() + if err != nil { + return nil, err + } + IP4Config, err := d.GetPropertyIP4Config() + if err != nil { + return nil, err + } + DHCP4Config, err := d.GetPropertyDHCP4Config() + if err != nil { + return nil, err + } + DeviceType, err := d.GetPropertyDeviceType() + if err != nil { + return nil, err + } + AvailableConnections, err := d.GetPropertyAvailableConnections() + if err != nil { + return nil, err + } + + return map[string]interface{}{ + "Interface": Interface, + "IP interface": IpInterface, + "State": State.String(), + "IP4Config": IP4Config, + "DHCP4Config": DHCP4Config, + "DeviceType": DeviceType.String(), + "AvailableConnections": AvailableConnections, + }, nil +} + +func (d *device) MarshalJSON() ([]byte, error) { + m, err := d.marshalMap() + if err != nil { + return nil, err + } + return json.Marshal(m) +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/DeviceDummy.go b/vendor/github.com/Wifx/gonetworkmanager/DeviceDummy.go new file mode 100644 index 000000000..c92a396b9 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/DeviceDummy.go @@ -0,0 +1,44 @@ +package gonetworkmanager + +import ( + "encoding/json" + + "github.com/godbus/dbus/v5" +) + +const ( + DeviceDummyInterface = DeviceInterface + ".Dummy" + + /* Properties */ + DeviceDummyPropertyHwAddress = DeviceDummyInterface + ".HwAddress" // readable s +) + +type DeviceDummy interface { + Device + + // Hardware address of the device. + GetPropertyHwAddress() (string, error) +} + +func NewDeviceDummy(objectPath dbus.ObjectPath) (DeviceDummy, error) { + var d deviceDummy + return &d, d.init(NetworkManagerInterface, objectPath) +} + +type deviceDummy struct { + device +} + +func (d *deviceDummy) GetPropertyHwAddress() (string, error) { + return d.getStringProperty(DeviceDummyPropertyHwAddress) +} + +func (d *deviceDummy) MarshalJSON() ([]byte, error) { + m, err := d.device.marshalMap() + if err != nil { + return nil, err + } + + m["HwAddress"], _ = d.GetPropertyHwAddress() + return json.Marshal(m) +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/DeviceGeneric.go b/vendor/github.com/Wifx/gonetworkmanager/DeviceGeneric.go new file mode 100644 index 000000000..19d401e89 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/DeviceGeneric.go @@ -0,0 +1,53 @@ +package gonetworkmanager + +import ( + "encoding/json" + + "github.com/godbus/dbus/v5" +) + +const ( + DeviceGenericInterface = DeviceInterface + ".Generic" + + // Properties + DeviceGenericPropertyHwAddress = DeviceGenericInterface + ".HwAddress" // readable s + DeviceGenericPropertyTypeDescription = DeviceGenericInterface + ".TypeDescription" // readable s +) + +type DeviceGeneric interface { + Device + + // Active hardware address of the device. + GetPropertyHwAddress() (string, error) + + // A (non-localized) description of the interface type, if known. + GetPropertyTypeDescription() (string, error) +} + +func NewDeviceGeneric(objectPath dbus.ObjectPath) (DeviceGeneric, error) { + var d deviceGeneric + return &d, d.init(NetworkManagerInterface, objectPath) +} + +type deviceGeneric struct { + device +} + +func (d *deviceGeneric) GetPropertyHwAddress() (string, error) { + return d.getStringProperty(DeviceGenericPropertyHwAddress) +} + +func (d *deviceGeneric) GetPropertyTypeDescription() (string, error) { + return d.getStringProperty(DeviceGenericPropertyTypeDescription) +} + +func (d *deviceGeneric) MarshalJSON() ([]byte, error) { + m, err := d.device.marshalMap() + if err != nil { + return nil, err + } + + m["HwAddress"], _ = d.GetPropertyHwAddress() + m["TypeDescription"], _ = d.GetPropertyTypeDescription() + return json.Marshal(m) +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/DeviceIpTunnel.go b/vendor/github.com/Wifx/gonetworkmanager/DeviceIpTunnel.go new file mode 100644 index 000000000..7fc43449d --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/DeviceIpTunnel.go @@ -0,0 +1,150 @@ +package gonetworkmanager + +import ( + "encoding/json" + + "github.com/godbus/dbus/v5" +) + +const ( + DeviceIpTunnelInterface = DeviceInterface + ".IPTunnel" + + // Properties + DeviceIpTunnelPropertyHwAddress = DeviceIpTunnelInterface + "HwAddress" // readable s + DeviceIpTunnelPropertyMode = DeviceIpTunnelInterface + ".Mode" // readable u + DeviceIpTunnelPropertyParent = DeviceIpTunnelInterface + ".Parent" // readable o + DeviceIpTunnelPropertyLocal = DeviceIpTunnelInterface + ".Local" // readable s + DeviceIpTunnelPropertyRemote = DeviceIpTunnelInterface + ".Remote" // readable s + DeviceIpTunnelPropertyTtl = DeviceIpTunnelInterface + ".Ttl" // readable y + DeviceIpTunnelPropertyTos = DeviceIpTunnelInterface + ".Tos" // readable y + DeviceIpTunnelPropertyPathMtuDiscovery = DeviceIpTunnelInterface + ".PathMtuDiscovery" // readable b + DeviceIpTunnelPropertyInputKey = DeviceIpTunnelInterface + ".InputKey" // readable s + DeviceIpTunnelPropertyOutputKey = DeviceIpTunnelInterface + ".OutputKey" // readable s + DeviceIpTunnelPropertyEncapsulationLimit = DeviceIpTunnelInterface + ".EncapsulationLimit" // readable y + DeviceIpTunnelPropertyFlowLabel = DeviceIpTunnelInterface + ".FlowLabel" // readable u + DeviceIpTunnelPropertyFlags = DeviceIpTunnelInterface + ".Flags" // readable u + +) + +type DeviceIpTunnel interface { + Device + + // The tunneling mode + GetPropertyMode() (uint32, error) + + // The object path of the parent device. + GetPropertyParent() (Device, error) + + // The local endpoint of the tunnel. + GetPropertyLocal() (string, error) + + // The remote endpoint of the tunnel. + GetPropertyRemote() (string, error) + + // The TTL assigned to tunneled packets. 0 is a special value meaning that packets inherit the TTL value + GetPropertyTtl() (uint8, error) + + // The type of service (IPv4) or traffic class (IPv6) assigned to tunneled packets. + GetPropertyTos() (uint8, error) + + // Whether path MTU discovery is enabled on this tunnel. + GetPropertyPathMtuDiscovery() (bool, error) + + // The key used for incoming packets. + GetPropertyInputKey() (string, error) + + // The key used for outgoing packets. + GetPropertyOutputKey() (string, error) + + // How many additional levels of encapsulation are permitted to be prepended to packets. This property applies only to IPv6 tunnels. + GetPropertyEncapsulationLimit() (uint8, error) + + // The flow label to assign to tunnel packets. This property applies only to IPv6 tunnels. + GetPropertyFlowLabel() (uint32, error) + + // Tunnel flags. + GetPropertyFlags() (uint32, error) +} + +func NewDeviceIpTunnel(objectPath dbus.ObjectPath) (DeviceIpTunnel, error) { + var d deviceIpTunnel + return &d, d.init(NetworkManagerInterface, objectPath) +} + +type deviceIpTunnel struct { + device +} + +func (d *deviceIpTunnel) GetPropertyMode() (uint32, error) { + return d.getUint32Property(DeviceIpTunnelPropertyMode) +} + +func (d *deviceIpTunnel) GetPropertyParent() (Device, error) { + path, err := d.getObjectProperty(DeviceIpTunnelPropertyParent) + if err != nil || path == "/" { + return nil, err + } + + return DeviceFactory(path) +} + +func (d *deviceIpTunnel) GetPropertyLocal() (string, error) { + return d.getStringProperty(DeviceIpTunnelPropertyLocal) +} + +func (d *deviceIpTunnel) GetPropertyRemote() (string, error) { + return d.getStringProperty(DeviceIpTunnelPropertyRemote) +} + +func (d *deviceIpTunnel) GetPropertyTtl() (uint8, error) { + return d.getUint8Property(DeviceIpTunnelPropertyTtl) +} + +func (d *deviceIpTunnel) GetPropertyTos() (uint8, error) { + return d.getUint8Property(DeviceIpTunnelPropertyTos) +} + +func (d *deviceIpTunnel) GetPropertyPathMtuDiscovery() (bool, error) { + return d.getBoolProperty(DeviceIpTunnelPropertyPathMtuDiscovery) +} + +func (d *deviceIpTunnel) GetPropertyInputKey() (string, error) { + return d.getStringProperty(DeviceIpTunnelPropertyInputKey) +} + +func (d *deviceIpTunnel) GetPropertyOutputKey() (string, error) { + return d.getStringProperty(DeviceIpTunnelPropertyOutputKey) +} + +func (d *deviceIpTunnel) GetPropertyEncapsulationLimit() (uint8, error) { + return d.getUint8Property(DeviceIpTunnelPropertyEncapsulationLimit) +} + +func (d *deviceIpTunnel) GetPropertyFlowLabel() (uint32, error) { + return d.getUint32Property(DeviceIpTunnelPropertyFlowLabel) +} + +func (d *deviceIpTunnel) GetPropertyFlags() (uint32, error) { + return d.getUint32Property(DeviceIpTunnelPropertyFlags) +} + +func (d *deviceIpTunnel) MarshalJSON() ([]uint8, error) { + m, err := d.device.marshalMap() + if err != nil { + return nil, err + } + + m["Mode"], _ = d.GetPropertyMode() + m["Parent"], _ = d.GetPropertyParent() + m["Local"], _ = d.GetPropertyLocal() + m["Remote"], _ = d.GetPropertyRemote() + m["Ttl"], _ = d.GetPropertyTtl() + m["Tos"], _ = d.GetPropertyTos() + m["PathMtuDiscovery"], _ = d.GetPropertyPathMtuDiscovery() + m["InputKey"], _ = d.GetPropertyInputKey() + m["OutputKey"], _ = d.GetPropertyOutputKey() + m["EncapsulationLimit"], _ = d.GetPropertyEncapsulationLimit() + m["FlowLabel"], _ = d.GetPropertyFlowLabel() + m["Flags"], _ = d.GetPropertyFlags() + return json.Marshal(m) +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/DeviceStatistics.go b/vendor/github.com/Wifx/gonetworkmanager/DeviceStatistics.go new file mode 100644 index 000000000..5beb20924 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/DeviceStatistics.go @@ -0,0 +1,74 @@ +package gonetworkmanager + +import ( + "encoding/json" + + "github.com/godbus/dbus/v5" +) + +const ( + DeviceStatisticsInterface = DeviceInterface + ".Statistics" + + // Properties + DeviceStatisticsPropertyRefreshRateMs = DeviceStatisticsInterface + ".RefreshRateMs" // readwrite u + DeviceStatisticsPropertyTxBytes = DeviceStatisticsInterface + ".TxBytes" // readable t + DeviceStatisticsPropertyRxBytes = DeviceStatisticsInterface + ".RxBytes" // readable t +) + +type DeviceStatistics interface { + GetPath() dbus.ObjectPath + + // Refresh rate of the rest of properties of this interface. The properties are guaranteed to be refreshed each RefreshRateMs milliseconds in case the underlying counter has changed too. If zero, there is no guaranteed refresh rate of the properties. + GetPropertyRefreshRateMs() (uint32, error) + + SetPropertyRefreshRateMs(uint32) (error) + + // Number of transmitted bytes + GetPropertyTxBytes() (uint64, error) + + // Number of received bytes + GetPropertyRxBytes() (uint64, error) +} + +func NewDeviceStatistics(objectPath dbus.ObjectPath) (DeviceStatistics, error) { + var d deviceStatistics + return &d, d.init(NetworkManagerInterface, objectPath) +} + +type deviceStatistics struct { + dbusBase +} + +func (d *deviceStatistics) GetPath() dbus.ObjectPath { + return d.obj.Path() +} + +func (d *deviceStatistics) GetPropertyRefreshRateMs() (uint32, error) { + return d.getUint32Property(DeviceStatisticsPropertyRefreshRateMs) +} + +func (d *deviceStatistics) SetPropertyRefreshRateMs(rate uint32) (error) { + return d.setProperty(DeviceStatisticsPropertyRefreshRateMs, rate) +} + +func (d *deviceStatistics) GetPropertyTxBytes() (uint64, error) { + return d.getUint64Property(DeviceStatisticsPropertyTxBytes) +} + +func (d *deviceStatistics) GetPropertyRxBytes() (uint64, error) { + return d.getUint64Property(DeviceStatisticsPropertyRxBytes) +} + +func (d *deviceStatistics) marshalMap() map[string]interface{} { + return map[string]interface{}{} +} + +func (d *deviceStatistics) MarshalJSON() ([]byte, error) { + m := make(map[string]interface{}) + + m["RefreshRateMs"], _ = d.GetPropertyRefreshRateMs() + m["TxBytes"], _ = d.GetPropertyTxBytes() + m["RxBytes"], _ = d.GetPropertyRxBytes() + + return json.Marshal(m) +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/DeviceWired.go b/vendor/github.com/Wifx/gonetworkmanager/DeviceWired.go new file mode 100644 index 000000000..b40e971a5 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/DeviceWired.go @@ -0,0 +1,80 @@ +package gonetworkmanager + +import ( + "encoding/json" + + "github.com/godbus/dbus/v5" +) + +const ( + DeviceWiredInterface = DeviceInterface + ".Wired" + + // Properties + DeviceWiredPropertyHwAddress = DeviceWiredInterface + ".HwAddress" // readable s + DeviceWiredPropertyPermHwAddress = DeviceWiredInterface + ".PermHwAddress" // readable s + DeviceWiredPropertySpeed = DeviceWiredInterface + ".Speed" // readable u + DeviceWiredPropertyS390Subchannels = DeviceWiredInterface + ".S390Subchannels" // readable as + DeviceWiredPropertyCarrier = DeviceWiredInterface + ".Carrier" // readable b +) + +type DeviceWired interface { + Device + + // Active hardware address of the device. + GetPropertyHwAddress() (string, error) + + // Permanent hardware address of the device. + GetPropertyPermHwAddress() (string, error) + + // Design speed of the device, in megabits/second (Mb/s). + GetPropertySpeed() (uint32, error) + + // Array of S/390 subchannels for S/390 or z/Architecture devices. + GetPropertyS390Subchannels() ([]string, error) + + // Indicates whether the physical carrier is found (e.g. whether a cable is plugged in or not). + GetPropertyCarrier() (bool, error) +} + +func NewDeviceWired(objectPath dbus.ObjectPath) (DeviceWired, error) { + var d deviceWired + return &d, d.init(NetworkManagerInterface, objectPath) +} + +type deviceWired struct { + device +} + +func (d *deviceWired) GetPropertyHwAddress() (string, error) { + return d.getStringProperty(DeviceWiredPropertyHwAddress) +} + +func (d *deviceWired) GetPropertyPermHwAddress() (string, error) { + return d.getStringProperty(DeviceWiredPropertyPermHwAddress) +} + +func (d *deviceWired) GetPropertySpeed() (uint32, error) { + return d.getUint32Property(DeviceWiredPropertySpeed) +} + +func (d *deviceWired) GetPropertyS390Subchannels() ([]string, error) { + return d.getSliceStringProperty(DeviceWiredPropertyS390Subchannels) +} + +func (d *deviceWired) GetPropertyCarrier() (bool, error) { + return d.getBoolProperty(DeviceWiredPropertyCarrier) +} + +func (d *deviceWired) MarshalJSON() ([]byte, error) { + m, err := d.device.marshalMap() + if err != nil { + return nil, err + } + + m["HwAddress"], _ = d.GetPropertyHwAddress() + m["PermHwAddress"], _ = d.GetPropertyPermHwAddress() + m["Speed"], _ = d.GetPropertySpeed() + m["S390Subchannels"], _ = d.GetPropertyS390Subchannels() + m["Carrier"], _ = d.GetPropertyCarrier() + return json.Marshal(m) +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/DeviceWireless.go b/vendor/github.com/Wifx/gonetworkmanager/DeviceWireless.go new file mode 100644 index 000000000..187406d07 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/DeviceWireless.go @@ -0,0 +1,194 @@ +package gonetworkmanager + +import ( + "encoding/json" + + "github.com/godbus/dbus/v5" +) + +const ( + DeviceWirelessInterface = DeviceInterface + ".Wireless" + + // Methods + DeviceWirelessGetAccessPoints = DeviceWirelessInterface + ".GetAccessPoints" + DeviceWirelessGetAllAccessPoints = DeviceWirelessInterface + ".GetAllAccessPoints" + DeviceWirelessRequestScan = DeviceWirelessInterface + ".RequestScan" + + // Properties + DeviceWirelessPropertyHwAddress = DeviceWirelessInterface + ".HwAddress" // readable s + DeviceWirelessPropertyPermHwAddress = DeviceWirelessInterface + ".PermHwAddress" // readable s + DeviceWirelessPropertyMode = DeviceWirelessInterface + ".Mode" // readable u + DeviceWirelessPropertyBitrate = DeviceWirelessInterface + ".Bitrate" // readable u + DeviceWirelessPropertyAccessPoints = DeviceWirelessInterface + ".AccessPoints" // readable ao + DeviceWirelessPropertyActiveAccessPoint = DeviceWirelessInterface + ".ActiveAccessPoint" // readable o + DeviceWirelessPropertyWirelessCapabilities = DeviceWirelessInterface + ".WirelessCapabilities" // readable u + DeviceWirelessPropertyLastScan = DeviceWirelessInterface + ".LastScan" // readable x +) + +type DeviceWireless interface { + Device + + // GetAccessPoints gets the list of access points visible to this device. + // Note that this list does not include access points which hide their SSID. + // To retrieve a list of all access points (including hidden ones) use the + // GetAllAccessPoints() method. + GetAccessPoints() ([]AccessPoint, error) + + // GetAllAccessPoints gets the list of all access points visible to this + // device, including hidden ones for which the SSID is not yet known. + GetAllAccessPoints() ([]AccessPoint, error) + + // Request the device to scan. To know when the scan is finished, use the + // "PropertiesChanged" signal from "org.freedesktop.DBus.Properties" to listen + // to changes to the "LastScan" property. + RequestScan() error + + // The active hardware address of the device. + GetPropertyHwAddress() (string, error) + + // The permanent hardware address of the device. + GetPropertyPermHwAddress() (string, error) + + // The operating mode of the wireless device. + GetPropertyMode() (Nm80211Mode, error) + + // The bit rate currently used by the wireless device, in kilobits/second (Kb/s). + GetPropertyBitrate() (uint32, error) + + // List of object paths of access point visible to this wireless device. + GetPropertyAccessPoints() ([]AccessPoint, error) + + // Object path of the access point currently used by the wireless device. + GetPropertyActiveAccessPoint() (AccessPoint, error) + + // The capabilities of the wireless device. + GetPropertyWirelessCapabilities() (uint32, error) + + // The timestamp (in CLOCK_BOOTTIME milliseconds) for the last finished + // network scan. A value of -1 means the device never scanned for access + // points. + GetPropertyLastScan() (int64, error) +} + +func NewDeviceWireless(objectPath dbus.ObjectPath) (DeviceWireless, error) { + var d deviceWireless + return &d, d.init(NetworkManagerInterface, objectPath) +} + +type deviceWireless struct { + device +} + +func (d *deviceWireless) GetAccessPoints() ([]AccessPoint, error) { + var apPaths []dbus.ObjectPath + err := d.callWithReturn(&apPaths, DeviceWirelessGetAccessPoints) + + if err != nil { + return nil, err + } + + aps := make([]AccessPoint, len(apPaths)) + + for i, path := range apPaths { + aps[i], err = NewAccessPoint(path) + if err != nil { + return aps, err + } + } + + return aps, nil +} + +func (d *deviceWireless) GetAllAccessPoints() ([]AccessPoint, error) { + var apPaths []dbus.ObjectPath + err := d.callWithReturn(&apPaths, DeviceWirelessGetAllAccessPoints) + + if err != nil { + return nil, err + } + + aps := make([]AccessPoint, len(apPaths)) + + for i, path := range apPaths { + aps[i], err = NewAccessPoint(path) + if err != nil { + return aps, err + } + } + + return aps, nil +} + +func (d *deviceWireless) RequestScan() error { + var options map[string]interface{} + return d.obj.Call(DeviceWirelessRequestScan, 0, options).Store() +} + +func (d *deviceWireless) GetPropertyHwAddress() (string, error) { + return d.getStringProperty(DeviceWirelessPropertyHwAddress) +} + +func (d *deviceWireless) GetPropertyPermHwAddress() (string, error) { + return d.getStringProperty(DeviceWirelessPropertyPermHwAddress) +} + +func (d *deviceWireless) GetPropertyMode() (Nm80211Mode, error) { + v, err := d.getUint32Property(DeviceWirelessPropertyMode) + return Nm80211Mode(v), err +} + +func (d *deviceWireless) GetPropertyBitrate() (uint32, error) { + return d.getUint32Property(DeviceWirelessPropertyBitrate) +} + +func (d *deviceWireless) GetPropertyAccessPoints() ([]AccessPoint, error) { + apPaths, err := d.getSliceObjectProperty(DeviceWirelessPropertyAccessPoints) + if err != nil { + return nil, err + } + + ap := make([]AccessPoint, len(apPaths)) + for i, path := range apPaths { + ap[i], err = NewAccessPoint(path) + if err != nil { + return ap, err + } + } + + return ap, nil +} + +func (d *deviceWireless) GetPropertyActiveAccessPoint() (AccessPoint, error) { + path, err := d.getObjectProperty(DeviceWirelessPropertyActiveAccessPoint) + if err != nil || path == "/" { + return nil, err + } + + return NewAccessPoint(path) +} + +func (d *deviceWireless) GetPropertyWirelessCapabilities() (uint32, error) { + return d.getUint32Property(DeviceWirelessPropertyWirelessCapabilities) +} + +func (d *deviceWireless) GetPropertyLastScan() (int64, error) { + return d.getInt64Property(DeviceWirelessPropertyLastScan) +} + +func (d *deviceWireless) MarshalJSON() ([]byte, error) { + m, err := d.device.marshalMap() + if err != nil { + return nil, err + } + + m["AccessPoints"], _ = d.GetPropertyAccessPoints() + m["HwAddress"], _ = d.GetPropertyHwAddress() + m["PermHwAddress"], _ = d.GetPropertyPermHwAddress() + m["Mode"], _ = d.GetPropertyMode() + m["Bitrate"], _ = d.GetPropertyBitrate() + m["AccessPoints"], _ = d.GetPropertyAccessPoints() + m["ActiveAccessPoint"], _ = d.GetPropertyActiveAccessPoint() + m["WirelessCapabilities"], _ = d.GetPropertyWirelessCapabilities() + m["LastScan"], _ = d.GetPropertyLastScan() + return json.Marshal(m) +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/IP4Config.go b/vendor/github.com/Wifx/gonetworkmanager/IP4Config.go new file mode 100644 index 000000000..fd965698a --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/IP4Config.go @@ -0,0 +1,321 @@ +package gonetworkmanager + +import ( + "encoding/json" + "errors" + + "github.com/godbus/dbus/v5" +) + +const ( + IP4ConfigInterface = NetworkManagerInterface + ".IP4Config" + + /* Properties */ + IP4ConfigPropertyAddresses = IP4ConfigInterface + ".Addresses" // readable aau + IP4ConfigPropertyAddressData = IP4ConfigInterface + ".AddressData" // readable aa{sv} + IP4ConfigPropertyGateway = IP4ConfigInterface + ".Gateway" // readable s + IP4ConfigPropertyRoutes = IP4ConfigInterface + ".Routes" // readable aau + IP4ConfigPropertyRouteData = IP4ConfigInterface + ".RouteData" // readable aa{sv} + IP4ConfigPropertyNameservers = IP4ConfigInterface + ".Nameservers" // readable au + IP4ConfigPropertyNameserverData = IP4ConfigInterface + ".NameserverData" // readable aa{sv} + IP4ConfigPropertyDomains = IP4ConfigInterface + ".Domains" // readable as + IP4ConfigPropertySearches = IP4ConfigInterface + ".Searches" // readable as + IP4ConfigPropertyDnsOptions = IP4ConfigInterface + ".DnsOptions" // readable as + IP4ConfigPropertyDnsPriority = IP4ConfigInterface + ".DnsPriority" // readable i + IP4ConfigPropertyWinsServers = IP4ConfigInterface + ".WinsServers" // readable au + IP4ConfigPropertyWinsServerData = IP4ConfigInterface + ".WinsServerData" // readable as +) + +// Deprecated: use IP4AddressData instead +type IP4Address struct { + Address string + Prefix uint8 + Gateway string +} + +type IP4AddressData struct { + Address string + Prefix uint8 +} + +// Deprecated: use IP4RouteData instead +type IP4Route struct { + Route string + Prefix uint8 + NextHop string + Metric uint8 +} + +type IP4RouteData struct { + Destination string + Prefix uint8 + NextHop string + Metric uint8 + AdditionalAttributes map[string]string +} + +type IP4NameserverData struct { + Address string +} + +type IP4Config interface { + // Array of arrays of IPv4 address/prefix/gateway. All 3 elements of each array are in network byte order. Essentially: [(addr, prefix, gateway), (addr, prefix, gateway), ...] + // Deprecated: use AddressData and Gateway + GetPropertyAddresses() ([]IP4Address, error) + + // Array of IP address data objects. All addresses will include "address" (an IP address string), and "prefix" (a uint). Some addresses may include additional attributes. + GetPropertyAddressData() ([]IP4AddressData, error) + + // The gateway in use. + GetPropertyGateway() (string, error) + + // Arrays of IPv4 route/prefix/next-hop/metric. All 4 elements of each tuple are in network byte order. 'route' and 'next hop' are IPv4 addresses, while prefix and metric are simple unsigned integers. Essentially: [(route, prefix, next-hop, metric), (route, prefix, next-hop, metric), ...] + // Deprecated: use RouteData + GetPropertyRoutes() ([]IP4Route, error) + + // Array of IP route data objects. All routes will include "dest" (an IP address string) and "prefix" (a uint). Some routes may include "next-hop" (an IP address string), "metric" (a uint), and additional attributes. + GetPropertyRouteData() ([]IP4RouteData, error) + + // The nameservers in use. + // Deprecated: use NameserverData + GetPropertyNameservers() ([]string, error) + + // The nameservers in use. Currently only the value "address" is recognized (with an IP address string). + GetPropertyNameserverData() ([]IP4NameserverData, error) + + // A list of domains this address belongs to. + GetPropertyDomains() ([]string, error) + + // A list of dns searches. + GetPropertySearches() ([]string, error) + + // A list of DNS options that modify the behavior of the DNS resolver. See resolv.conf(5) manual page for the list of supported options. + GetPropertyDnsOptions() ([]string, error) + + // The relative priority of DNS servers. + GetPropertyDnsPriority() (uint32, error) + + // The Windows Internet Name Service servers associated with the connection. + GetPropertyWinsServerData() ([]string, error) + + MarshalJSON() ([]byte, error) +} + +func NewIP4Config(objectPath dbus.ObjectPath) (IP4Config, error) { + var c ip4Config + return &c, c.init(NetworkManagerInterface, objectPath) +} + +type ip4Config struct { + dbusBase +} + +// Deprecated: use GetPropertyAddressData +func (c *ip4Config) GetPropertyAddresses() ([]IP4Address, error) { + addresses, err := c.getSliceSliceUint32Property(IP4ConfigPropertyAddresses) + ret := make([]IP4Address, len(addresses)) + + if err != nil { + return ret, err + } + + for i, parts := range addresses { + ret[i] = IP4Address{ + Address: ip4ToString(parts[0]), + Prefix: uint8(parts[1]), + Gateway: ip4ToString(parts[2]), + } + } + + return ret, nil +} + +func (c *ip4Config) GetPropertyAddressData() ([]IP4AddressData, error) { + addresses, err := c.getSliceMapStringVariantProperty(IP4ConfigPropertyAddressData) + ret := make([]IP4AddressData, len(addresses)) + + if err != nil { + return ret, err + } + + for i, address := range addresses { + prefix, ok := address["prefix"].Value().(uint32) + if !ok { + return ret, errors.New("unexpected variant type for address prefix") + } + + address, ok := address["address"].Value().(string) + if !ok { + return ret, errors.New("unexpected variant type for address") + } + + ret[i] = IP4AddressData{ + Address: address, + Prefix: uint8(prefix), + } + } + + return ret, nil +} + +func (c *ip4Config) GetPropertyGateway() (string, error) { + return c.getStringProperty(IP4ConfigPropertyGateway) +} + +// Deprecated: use GetPropertyRouteData +func (c *ip4Config) GetPropertyRoutes() ([]IP4Route, error) { + routes, err := c.getSliceSliceUint32Property(IP4ConfigPropertyRoutes) + ret := make([]IP4Route, len(routes)) + + if err != nil { + return ret, err + } + + for i, parts := range routes { + ret[i] = IP4Route{ + Route: ip4ToString(parts[0]), + Prefix: uint8(parts[1]), + NextHop: ip4ToString(parts[2]), + Metric: uint8(parts[3]), + } + } + + return ret, nil +} + +func (c *ip4Config) GetPropertyRouteData() ([]IP4RouteData, error) { + routesData, err := c.getSliceMapStringVariantProperty(IP4ConfigPropertyRouteData) + routes := make([]IP4RouteData, len(routesData)) + + if err != nil { + return routes, err + } + + for index, routeData := range routesData { + + route := IP4RouteData{} + + for routeDataAttributeName, routeDataAttribute := range routeData { + switch routeDataAttributeName { + case "dest": + destination, ok := routeDataAttribute.Value().(string) + if !ok { + return routes, errors.New("unexpected variant type for dest") + } + route.Destination = destination + case "prefix": + prefix, ok := routeDataAttribute.Value().(uint32) + if !ok { + return routes, errors.New("unexpected variant type for prefix") + } + route.Prefix = uint8(prefix) + case "next-hop": + nextHop, ok := routeDataAttribute.Value().(string) + if !ok { + return routes, errors.New("unexpected variant type for next-hop") + } + route.NextHop = nextHop + case "metric": + metric, ok := routeDataAttribute.Value().(uint32) + if !ok { + return routes, errors.New("unexpected variant type for metric") + } + route.Metric = uint8(metric) + default: + if route.AdditionalAttributes == nil { + route.AdditionalAttributes = make(map[string]string) + } + route.AdditionalAttributes[routeDataAttributeName] = routeDataAttribute.String() + } + } + + routes[index] = route + } + return routes, nil +} + +// Deprecated: use GetPropertyNameserverData +func (c *ip4Config) GetPropertyNameservers() ([]string, error) { + nameservers, err := c.getSliceUint32Property(IP4ConfigPropertyNameservers) + ret := make([]string, len(nameservers)) + + if err != nil { + return ret, err + } + + for i, ns := range nameservers { + ret[i] = ip4ToString(ns) + } + + return ret, nil +} + +func (c *ip4Config) GetPropertyNameserverData() ([]IP4NameserverData, error) { + nameserversData, err := c.getSliceMapStringVariantProperty(IP4ConfigPropertyNameserverData) + nameservers := make([]IP4NameserverData, len(nameserversData)) + + if err != nil { + return nameservers, err + } + + for _, nameserverData := range nameserversData { + address, ok := nameserverData["address"].Value().(string) + + if !ok { + return nameservers, errors.New("unexpected variant type for address") + } + + nameserver := IP4NameserverData{ + Address: address, + } + + nameservers = append(nameservers, nameserver) + } + return nameservers, nil +} + +func (c *ip4Config) GetPropertyDomains() ([]string, error) { + return c.getSliceStringProperty(IP4ConfigPropertyDomains) +} + +func (c *ip4Config) GetPropertySearches() ([]string, error) { + return c.getSliceStringProperty(IP4ConfigPropertySearches) +} + +func (c *ip4Config) GetPropertyDnsOptions() ([]string, error) { + return c.getSliceStringProperty(IP4ConfigPropertyDnsOptions) +} + +func (c *ip4Config) GetPropertyDnsPriority() (uint32, error) { + return c.getUint32Property(IP4ConfigPropertyDnsPriority) +} + +func (c *ip4Config) GetPropertyWinsServerData() ([]string, error) { + return c.getSliceStringProperty(IP4ConfigPropertyWinsServerData) +} + +func (c *ip4Config) MarshalJSON() ([]byte, error) { + Addresses, err := c.GetPropertyAddressData() + if err != nil { + return nil, err + } + Routes, err := c.GetPropertyRouteData() + if err != nil { + return nil, err + } + Nameservers, err := c.GetPropertyNameserverData() + if err != nil { + return nil, err + } + Domains, err := c.GetPropertyDomains() + if err != nil { + return nil, err + } + + return json.Marshal(map[string]interface{}{ + "Addresses": Addresses, + "Routes": Routes, + "Nameservers": Nameservers, + "Domains": Domains, + }) +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/IP6Config.go b/vendor/github.com/Wifx/gonetworkmanager/IP6Config.go new file mode 100644 index 000000000..548f2cae2 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/IP6Config.go @@ -0,0 +1,215 @@ +package gonetworkmanager + +import ( + "encoding/json" + "errors" + + "github.com/godbus/dbus/v5" +) + +const ( + IP6ConfigInterface = NetworkManagerInterface + ".IP6Config" + + /* Properties */ + IP6ConfigPropertyAddresses = IP6ConfigInterface + ".Addresses" // readable a(ayuay) + IP6ConfigPropertyAddressData = IP6ConfigInterface + ".AddressData" // readable aa{sv} + IP6ConfigPropertyGateway = IP6ConfigInterface + ".Gateway" // readable s + IP6ConfigPropertyRoutes = IP6ConfigInterface + ".Routes" // readable a(ayuayu) + IP6ConfigPropertyRouteData = IP6ConfigInterface + ".RouteData" // readable aa{sv} + IP6ConfigPropertyNameservers = IP6ConfigInterface + ".Nameservers" // readable aay + IP6ConfigPropertyDomains = IP6ConfigInterface + ".Domains" // readable as + IP6ConfigPropertySearches = IP6ConfigInterface + ".Searches" // readable as + IP6ConfigPropertyDnsOptions = IP6ConfigInterface + ".DnsOptions" // readable as + IP6ConfigPropertyDnsPriority = IP6ConfigInterface + ".DnsPriority" // readable i +) + +// Deprecated: use IP6AddressData instead +type IP6Address struct { + Address string + Prefix uint8 + Gateway string +} + +type IP6AddressData struct { + Address string + Prefix uint8 +} + +// Deprecated: use IP6RouteData instead +type IP6Route struct { + Route string + Prefix uint8 + NextHop string + Metric uint8 +} + +type IP6RouteData struct { + Destination string + Prefix uint8 + NextHop string + Metric uint8 + AdditionalAttributes map[string]string +} + +type IP6Config interface { + + // Array of IP address data objects. All addresses will include "address" (an IP address string), and "prefix" (a uint). Some addresses may include additional attributes. + GetPropertyAddressData() ([]IP6AddressData, error) + + // The gateway in use. + GetPropertyGateway() (string, error) + + // Array of IP route data objects. All routes will include "dest" (an IP address string) and "prefix" (a uint). Some routes may include "next-hop" (an IP address string), "metric" (a uint), and additional attributes. + GetPropertyRouteData() ([]IP6RouteData, error) + + // GetNameservers gets the nameservers in use. + GetPropertyNameservers() ([][]byte, error) + + // A list of domains this address belongs to. + GetPropertyDomains() ([]string, error) + + // A list of dns searches. + GetPropertySearches() ([]string, error) + + // A list of DNS options that modify the behavior of the DNS resolver. See resolv.conf(5) manual page for the list of supported options. + GetPropertyDnsOptions() ([]string, error) + + // The relative priority of DNS servers. + GetPropertyDnsPriority() (uint32, error) + + MarshalJSON() ([]byte, error) +} + +func NewIP6Config(objectPath dbus.ObjectPath) (IP6Config, error) { + var c ip6Config + return &c, c.init(NetworkManagerInterface, objectPath) +} + +type ip6Config struct { + dbusBase +} + +func (c *ip6Config) GetPropertyAddressData() ([]IP6AddressData, error) { + addresses, err := c.getSliceMapStringVariantProperty(IP6ConfigPropertyAddressData) + ret := make([]IP6AddressData, len(addresses)) + + if err != nil { + return ret, err + } + + for i, address := range addresses { + prefix, ok := address["prefix"].Value().(uint32) + if !ok { + return ret, errors.New("unexpected variant type for prefix") + } + + address, ok := address["address"].Value().(string) + if !ok { + return ret, errors.New("unexpected variant type for address") + } + + ret[i] = IP6AddressData{ + Address: address, + Prefix: uint8(prefix), + } + } + + return ret, nil +} + +func (c *ip6Config) GetPropertyGateway() (string, error) { + return c.getStringProperty(IP6ConfigPropertyGateway) +} + +func (c *ip6Config) GetPropertyRouteData() ([]IP6RouteData, error) { + routesData, err := c.getSliceMapStringVariantProperty(IP6ConfigPropertyRouteData) + routes := make([]IP6RouteData, len(routesData)) + + if err != nil { + return routes, err + } + + for index, routeData := range routesData { + + route := IP6RouteData{} + + for routeDataAttributeName, routeDataAttribute := range routeData { + switch routeDataAttributeName { + case "dest": + destination, ok := routeDataAttribute.Value().(string) + if !ok { + return routes, errors.New("unexpected variant type for dest") + } + route.Destination = destination + case "prefix": + prefix, ok := routeDataAttribute.Value().(uint32) + if !ok { + return routes, errors.New("unexpected variant type for prefix") + } + route.Prefix = uint8(prefix) + case "next-hop": + nextHop, ok := routeDataAttribute.Value().(string) + if !ok { + return routes, errors.New("unexpected variant type for next-hop") + } + route.NextHop = nextHop + case "metric": + metric, ok := routeDataAttribute.Value().(uint32) + if !ok { + return routes, errors.New("unexpected variant type for metric") + } + route.Metric = uint8(metric) + default: + if route.AdditionalAttributes == nil { + route.AdditionalAttributes = make(map[string]string) + } + route.AdditionalAttributes[routeDataAttributeName] = routeDataAttribute.String() + } + } + + routes[index] = route + } + return routes, nil +} + +func (c *ip6Config) GetPropertyNameservers() ([][]byte, error) { + nameservers, err := c.getSliceSliceByteProperty(IP6ConfigPropertyNameservers) + ret := make([][]byte, len(nameservers)) + + if err != nil { + return ret, err + } + + for i, nameserver := range nameservers { + ret[i] = nameserver + } + + return ret, nil +} + +func (c *ip6Config) GetPropertyDomains() ([]string, error) { + return c.getSliceStringProperty(IP6ConfigPropertyDomains) +} + +func (c *ip6Config) GetPropertySearches() ([]string, error) { + return c.getSliceStringProperty(IP6ConfigPropertySearches) +} + +func (c *ip6Config) GetPropertyDnsOptions() ([]string, error) { + return c.getSliceStringProperty(IP6ConfigPropertyDnsOptions) +} + +func (c *ip6Config) GetPropertyDnsPriority() (uint32, error) { + return c.getUint32Property(IP6ConfigPropertyDnsPriority) +} + +func (c *ip6Config) MarshalJSON() ([]byte, error) { + m := make(map[string]interface{}) + + m["Addresses"], _ = c.GetPropertyAddressData() + m["Routes"], _ = c.GetPropertyRouteData() + m["Nameservers"], _ = c.GetPropertyNameservers() + m["Domains"], _ = c.GetPropertyDomains() + + return json.Marshal(m) +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/LICENSE b/vendor/github.com/Wifx/gonetworkmanager/LICENSE new file mode 100644 index 000000000..8896b2c24 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/LICENSE @@ -0,0 +1,45 @@ +The MIT License (MIT) + +Copyright (c) 2019 Wifx Sàrl + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------ + +The MIT License (MIT) + +Copyright (c) 2016 Bellerophon Mobile + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/Wifx/gonetworkmanager/NetworkManager.go b/vendor/github.com/Wifx/gonetworkmanager/NetworkManager.go new file mode 100644 index 000000000..190004cfd --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/NetworkManager.go @@ -0,0 +1,752 @@ +package gonetworkmanager + +import ( + "encoding/json" + + "github.com/godbus/dbus/v5" +) + +const ( + NetworkManagerInterface = "org.freedesktop.NetworkManager" + NetworkManagerObjectPath = "/org/freedesktop/NetworkManager" + + /* Methods */ + NetworkManagerReload = NetworkManagerInterface + ".Reload" + NetworkManagerGetDevices = NetworkManagerInterface + ".GetDevices" + NetworkManagerGetAllDevices = NetworkManagerInterface + ".GetAllDevices" + NetworkManagerGetDeviceByIpIface = NetworkManagerInterface + ".GetDeviceByIpIface" + NetworkManagerActivateConnection = NetworkManagerInterface + ".ActivateConnection" + NetworkManagerAddAndActivateConnection = NetworkManagerInterface + ".AddAndActivateConnection" + NetworkManagerAddAndActivateConnection2 = NetworkManagerInterface + ".AddAndActivateConnection2" + NetworkManagerDeactivateConnection = NetworkManagerInterface + ".DeactivateConnection" + NetworkManagerSleep = NetworkManagerInterface + ".Sleep" + NetworkManagerEnable = NetworkManagerInterface + ".Enable" + NetworkManagerGetPermissions = NetworkManagerInterface + ".GetPermissions" + NetworkManagerSetLogging = NetworkManagerInterface + ".SetLogging" + NetworkManagerGetLogging = NetworkManagerInterface + ".GetLogging" + NetworkManagerCheckConnectivity = NetworkManagerInterface + ".CheckConnectivity" + NetworkManagerState = NetworkManagerInterface + ".state" + NetworkManagerCheckpointCreate = NetworkManagerInterface + ".CheckpointCreate" + NetworkManagerCheckpointDestroy = NetworkManagerInterface + ".CheckpointDestroy" + NetworkManagerCheckpointRollback = NetworkManagerInterface + ".CheckpointRollback" + NetworkManagerCheckpointAdjustRollbackTimeout = NetworkManagerInterface + ".CheckpointAdjustRollbackTimeout" + + /* Property */ + NetworkManagerPropertyDevices = NetworkManagerInterface + ".Devices" // readable ao + NetworkManagerPropertyAllDevices = NetworkManagerInterface + ".AllDevices" // readable ao + NetworkManagerPropertyCheckpoints = NetworkManagerInterface + ".Checkpoints" // readable ao + NetworkManagerPropertyNetworkingEnabled = NetworkManagerInterface + ".NetworkingEnabled" // readable b + NetworkManagerPropertyWirelessEnabled = NetworkManagerInterface + ".WirelessEnabled" // readwrite b + NetworkManagerPropertyWirelessHardwareEnabled = NetworkManagerInterface + ".WirelessHardwareEnabled" // readable b + NetworkManagerPropertyWwanEnabled = NetworkManagerInterface + ".WwanEnabled" // readwrite b + NetworkManagerPropertyWwanHardwareEnabled = NetworkManagerInterface + ".WwanHardwareEnabled" // readable b + NetworkManagerPropertyWimaxEnabled = NetworkManagerInterface + ".WimaxEnabled" // readwrite b + NetworkManagerPropertyWimaxHardwareEnabled = NetworkManagerInterface + ".WimaxHardwareEnabled" // readable b + NetworkManagerPropertyActiveConnections = NetworkManagerInterface + ".ActiveConnections" // readable ao + NetworkManagerPropertyPrimaryConnection = NetworkManagerInterface + ".PrimaryConnection" // readable o + NetworkManagerPropertyPrimaryConnectionType = NetworkManagerInterface + ".PrimaryConnectionType" // readable s + NetworkManagerPropertyMetered = NetworkManagerInterface + ".Metered" // readable u + NetworkManagerPropertyActivatingConnection = NetworkManagerInterface + ".ActivatingConnection" // readable o + NetworkManagerPropertyStartup = NetworkManagerInterface + ".Startup" // readable b + NetworkManagerPropertyVersion = NetworkManagerInterface + ".Version" // readable s + NetworkManagerPropertyCapabilities = NetworkManagerInterface + ".Capabilities" // readable au + NetworkManagerPropertyState = NetworkManagerInterface + ".State" // readable u + NetworkManagerPropertyConnectivity = NetworkManagerInterface + ".Connectivity" // readable u + NetworkManagerPropertyConnectivityCheckAvailable = NetworkManagerInterface + ".ConnectivityCheckAvailable" // readable b + NetworkManagerPropertyConnectivityCheckEnabled = NetworkManagerInterface + ".ConnectivityCheckEnabled" // readwrite b + NetworkManagerPropertyGlobalDnsConfiguration = NetworkManagerInterface + ".GlobalDnsConfiguration" // readwrite a{sv} +) + +type NetworkManager interface { + /* METHODS */ + + // Reload NetworkManager's configuration and perform certain updates, like flushing a cache or rewriting external state to disk. This is similar to sending SIGHUP to NetworkManager but it allows for more fine-grained control over what to reload (see flags). It also allows non-root access via PolicyKit and contrary to signals it is synchronous. + // No flags (0x00) means to reload everything that is supported which is identical to sending a SIGHUP. + // (0x01) means to reload the NetworkManager.conf configuration from disk. Note that this does not include connections, which can be reloaded via Setting's ReloadConnections. + // (0x02) means to update DNS configuration, which usually involves writing /etc/resolv.conf anew. + // (0x04) means to restart the DNS plugin. This is for example useful when using dnsmasq plugin, which uses additional configuration in /etc/NetworkManager/dnsmasq.d. If you edit those files, you can restart the DNS plugin. This action shortly interrupts name resolution. Note that flags may affect each other. For example, restarting the DNS plugin (0x04) implicitly updates DNS too (0x02). Or when reloading the configuration (0x01), changes to DNS setting also cause a DNS update (0x02). However, (0x01) does not involve restarting the DNS plugin (0x04) or update resolv.conf (0x02), unless the DNS related configuration changes in NetworkManager.conf. + Reload(flags uint32) error + + // Get the list of realized network devices. + GetDevices() ([]Device, error) + + // Get the list of all network devices. + GetAllDevices() ([]Device, error) + + // Return the object path of the network device referenced by its IP interface name. Note that some devices (usually modems) only have an IP interface name when they are connected. + GetDeviceByIpIface(interfaceId string) (Device, error) + + // Activate a connection using the supplied device. + ActivateConnection(connection Connection, device Device, specificObject *dbus.Object) (ActiveConnection, error) + + // Adds a new connection using the given details (if any) as a template (automatically filling in missing settings with the capabilities of the given device), then activate the new connection. Cannot be used for VPN connections at this time. + AddAndActivateConnection(connection map[string]map[string]interface{}, device Device) (ActiveConnection, error) + + // ActivateWirelessConnection requests activating access point to network device + ActivateWirelessConnection(connection Connection, device Device, accessPoint AccessPoint) (ActiveConnection, error) + + // AddAndActivateWirelessConnection adds a new connection profile to the network device it has been + // passed. It then activates the connection to the passed access point. The first parameter contains + // additional information for the connection (most probably the credentials). + // Example contents for connection are: + // connection := make(map[string]map[string]interface{}) + // connection["802-11-wireless"] = make(map[string]interface{}) + // connection["802-11-wireless"]["security"] = "802-11-wireless-security" + // connection["802-11-wireless-security"] = make(map[string]interface{}) + // connection["802-11-wireless-security"]["key-mgmt"] = "wpa-psk" + // connection["802-11-wireless-security"]["psk"] = password + AddAndActivateWirelessConnection(connection map[string]map[string]interface{}, device Device, accessPoint AccessPoint) (ActiveConnection, error) + + // Deactivate an active connection. + DeactivateConnection(connection ActiveConnection) error + + // Control the NetworkManager daemon's sleep state. When asleep, all interfaces that it manages are deactivated. When awake, devices are available to be activated. This command should not be called directly by users or clients; it is intended for system suspend/resume tracking. + // sleepnWake: Indicates whether the NetworkManager daemon should sleep or wake. + Sleep(sleepNWake bool) error + + // Control whether overall networking is enabled or disabled. When disabled, all interfaces that NM manages are deactivated. When enabled, all managed interfaces are re-enabled and available to be activated. This command should be used by clients that provide to users the ability to enable/disable all networking. + // enableNDisable: If FALSE, indicates that all networking should be disabled. If TRUE, indicates that NetworkManager should begin managing network devices. + Enable(enableNDisable bool) error + + // Re-check the network connectivity state. + CheckConnectivity() error + + // The overall networking state as determined by the NetworkManager daemon, based on the state of network devices under its management. + State() (NmState, error) + + // Create a checkpoint of the current networking configuration for given interfaces. If rollback_timeout is not zero, a rollback is automatically performed after the given timeout. + // devices: A list of device paths for which a checkpoint should be created. An empty list means all devices. + // rollbackTimeout: The time in seconds until NetworkManager will automatically rollback to the checkpoint. Set to zero for infinite. + // flags: Flags for the creation. + // returns: On success, the new checkpoint. + CheckpointCreate(devices []Device, rollbackTimeout uint32, flags uint32) (Checkpoint, error) + + // Destroy a previously created checkpoint. + // checkpoint: The checkpoint to be destroyed. Set to empty to cancel all pending checkpoints. + CheckpointDestroy(checkpoint Checkpoint) error + + // Rollback a checkpoint before the timeout is reached. + // checkpoint: The checkpoint to be rolled back. + // result: On return, a dictionary of devices and results. Devices are represented by their original D-Bus path; each result is a RollbackResult. + CheckpointRollback(checkpoint Checkpoint) (result map[dbus.ObjectPath]NmRollbackResult, err error) + + // Reset the timeout for rollback for the checkpoint. + // Since: 1.12 + // addTimeout: number of seconds from ~now~ in which the timeout will expire. Set to 0 to disable the timeout. Note that the added seconds start counting from now, not "Created" timestamp or the previous expiration time. Note that the "Created" property of the checkpoint will stay unchanged by this call. However, the "RollbackTimeout" will be recalculated to give the approximate new expiration time. The new "RollbackTimeout" property will be approximate up to one second precision, which is the accuracy of the property. + CheckpointAdjustRollbackTimeout(checkpoint Checkpoint, addTimeout uint32) error + + /* PROPERTIES */ + + // The list of realized network devices. Realized devices are those which have backing resources (eg from the kernel or a management daemon like ModemManager, teamd, etc). + GetPropertyDevices() ([]Device, error) + + // The list of both realized and un-realized network devices. Un-realized devices are software devices which do not yet have backing resources, but for which backing resources can be created if the device is activated. + GetPropertyAllDevices() ([]Device, error) + + // The list of active checkpoints. + GetPropertyCheckpoints() ([]Checkpoint, error) + + // Indicates if overall networking is currently enabled or not. See the Enable() method. + GetPropertyNetworkingEnabled() (bool, error) + + // Indicates if wireless is currently enabled or not. + GetPropertyWirelessEnabled() (bool, error) + SetPropertyWirelessEnabled(bool) error + + // Indicates if the wireless hardware is currently enabled, i.e. the state of the RF kill switch. + GetPropertyWirelessHardwareEnabled() (bool, error) + + // Indicates if mobile broadband devices are currently enabled or not. + GetPropertyWwanEnabled() (bool, error) + + // Indicates if the mobile broadband hardware is currently enabled, i.e. the state of the RF kill switch. + GetPropertyWwanHardwareEnabled() (bool, error) + + // Indicates if WiMAX devices are currently enabled or not. + GetPropertyWimaxEnabled() (bool, error) + + // Indicates if the WiMAX hardware is currently enabled, i.e. the state of the RF kill switch. + GetPropertyWimaxHardwareEnabled() (bool, error) + + // List of active connection object paths. + GetPropertyActiveConnections() ([]ActiveConnection, error) + + // The object path of the "primary" active connection being used to access the network. In particular, if there is no VPN active, or the VPN does not have the default route, then this indicates the connection that has the default route. If there is a VPN active with the default route, then this indicates the connection that contains the route to the VPN endpoint. + GetPropertyPrimaryConnection() (Connection, error) + + // The connection type of the "primary" active connection being used to access the network. This is the same as the Type property on the object indicated by PrimaryConnection. + GetPropertyPrimaryConnectionType() (string, error) + + // Indicates whether the connectivity is metered. This is equivalent to the metered property of the device associated with the primary connection. + GetPropertyMetered() (NmMetered, error) + + // The object path of an active connection that is currently being activated and which is expected to become the new PrimaryConnection when it finishes activating. + GetPropertyActivatingConnection() (ActiveConnection, error) + + // Indicates whether NM is still starting up; this becomes FALSE when NM has finished attempting to activate every connection that it might be able to activate at startup. + GetPropertyStartup() (bool, error) + + // NetworkManager version. + GetPropertyVersion() (string, error) + + // The current set of capabilities. See NMCapability for currently defined capability numbers. The array is guaranteed to be sorted in ascending order without duplicates. + GetPropertyCapabilities() ([]NmCapability, error) + + // The overall state of the NetworkManager daemon. + // This takes state of all active connections and the connectivity state into account to produce a single indicator of the network accessibility status. + // The graphical shells may use this property to provide network connection status indication and applications may use this to check if Internet connection is accessible. Shell that is able to cope with captive portals should use the "Connectivity" property to decide whether to present a captive portal authentication dialog. + GetPropertyState() (NmState, error) + + // The result of the last connectivity check. The connectivity check is triggered automatically when a default connection becomes available, periodically and by calling a CheckConnectivity() method. + // This property is in general useful for the graphical shell to determine whether the Internet access is being hijacked by an authentication gateway (a "captive portal"). In such case it would typically present a web browser window to give the user a chance to authenticate and call CheckConnectivity() when the user submits a form or dismisses the window. + // To determine the whether the user is able to access the Internet without dealing with captive portals (e.g. to provide a network connection indicator or disable controls that require Internet access), the "State" property is more suitable. + GetPropertyConnectivity() (NmConnectivity, error) + + // Indicates whether connectivity checking service has been configured. This may return true even if the service is not currently enabled. + // This is primarily intended for use in a privacy control panel, as a way to determine whether to show an option to enable/disable the feature. + GetPropertyConnectivityCheckAvailable() (bool, error) + + // Indicates whether connectivity checking is enabled. This property can also be written to to disable connectivity checking (as a privacy control panel might want to do). + GetPropertyConnectivityCheckEnabled() (bool, error) + + // Dictionary of global DNS settings where the key is one of "searches", "options" and "domains". The values for the "searches" and "options" keys are string arrays describing the list of search domains and resolver options, respectively. The value of the "domains" key is a second-level dictionary, where each key is a domain name, and each key's value is a third-level dictionary with the keys "servers" and "options". "servers" is a string array of DNS servers, "options" is a string array of domain-specific options. + //GetPropertyGlobalDnsConfiguration() []interface{} + + Subscribe() <-chan *dbus.Signal + Unsubscribe() + + MarshalJSON() ([]byte, error) +} + +func NewNetworkManager() (NetworkManager, error) { + var nm networkManager + return &nm, nm.init(NetworkManagerInterface, NetworkManagerObjectPath) +} + +type networkManager struct { + dbusBase + + sigChan chan *dbus.Signal +} + +func (nm *networkManager) Reload(flags uint32) error { + return nm.call(NetworkManagerReload, flags) +} + +func (nm *networkManager) GetDevices() (devices []Device, err error) { + var devicePaths []dbus.ObjectPath + err = nm.callWithReturn(&devicePaths, NetworkManagerGetDevices) + if err != nil { + return + } + + devices = make([]Device, len(devicePaths)) + + for i, path := range devicePaths { + devices[i], err = DeviceFactory(path) + if err != nil { + return + } + } + + return +} + +func (nm *networkManager) GetAllDevices() (devices []Device, err error) { + var devicePaths []dbus.ObjectPath + + err = nm.callWithReturn(&devicePaths, NetworkManagerGetAllDevices) + if err != nil { + return + } + + devices = make([]Device, len(devicePaths)) + + for i, path := range devicePaths { + devices[i], err = DeviceFactory(path) + if err != nil { + return + } + } + + return +} + +func (nm *networkManager) GetDeviceByIpIface(interfaceId string) (device Device, err error) { + var devicePath dbus.ObjectPath + + err = nm.callWithReturn(&devicePath, NetworkManagerGetDeviceByIpIface, interfaceId) + if err != nil { + return + } + + device, err = DeviceFactory(devicePath) + if err != nil { + return + } + + return +} + +func (nm *networkManager) ActivateConnection(connection Connection, device Device, specificObject *dbus.Object) (ac ActiveConnection, err error) { + var connectionPath dbus.ObjectPath + + var devicePath dbus.ObjectPath + if device != nil { + devicePath = device.GetPath() + } else { + devicePath = "/" + } + + var specificObjectPath dbus.ObjectPath + if specificObject != nil { + specificObjectPath = specificObject.Path() + } else { + specificObjectPath = "/" + } + + err = nm.callWithReturn(&connectionPath, NetworkManagerActivateConnection, connection.GetPath(), devicePath, specificObjectPath) + if err != nil { + return + } + + ac, err = NewActiveConnection(connectionPath) + if err != nil { + return + } + + return +} + +func (nm *networkManager) AddAndActivateConnection(connection map[string]map[string]interface{}, d Device) (ac ActiveConnection, err error) { + var opath1 dbus.ObjectPath + var opath2 dbus.ObjectPath + + var devicePath dbus.ObjectPath + if d != nil { + devicePath = d.GetPath() + } + + err = nm.callWithReturn2(&opath1, &opath2, NetworkManagerAddAndActivateConnection, connection, devicePath, dbus.ObjectPath("/")) + if err != nil { + return + } + + ac, err = NewActiveConnection(opath2) + if err != nil { + return + } + + return +} + +func (nm *networkManager) ActivateWirelessConnection(c Connection, d Device, ap AccessPoint) (ac ActiveConnection, err error) { + var opath dbus.ObjectPath + err = nm.callWithReturn(&opath, NetworkManagerActivateConnection, c.GetPath(), d.GetPath(), ap.GetPath()) + if err != nil { + return nil, err + } + + ac, err = NewActiveConnection(opath) + if err != nil { + return nil, err + } + + return +} + +func (nm *networkManager) AddAndActivateWirelessConnection(connection map[string]map[string]interface{}, d Device, ap AccessPoint) (ac ActiveConnection, err error) { + var opath1 dbus.ObjectPath + var opath2 dbus.ObjectPath + + err = nm.callWithReturn2(&opath1, &opath2, NetworkManagerAddAndActivateConnection, connection, d.GetPath(), ap.GetPath()) + if err != nil { + return + } + + ac, err = NewActiveConnection(opath2) + if err != nil { + return + } + return +} + +func (nm *networkManager) DeactivateConnection(c ActiveConnection) error { + return nm.call(NetworkManagerDeactivateConnection, c.GetPath()) +} + +func (nm *networkManager) Sleep(sleepNWake bool) error { + return nm.call(NetworkManagerSleep, sleepNWake) +} + +func (nm *networkManager) Enable(enableNDisable bool) error { + return nm.call(NetworkManagerEnable, enableNDisable) +} + +func (nm *networkManager) CheckConnectivity() error { + return nm.call(NetworkManagerCheckConnectivity) +} + +func (nm *networkManager) State() (state NmState, err error) { + err = nm.callWithReturn(&state, NetworkManagerState) + return +} + +func (nm *networkManager) CheckpointCreate(devices []Device, rollbackTimeout uint32, flags uint32) (cp Checkpoint, err error) { + + var devicePaths []dbus.ObjectPath + if len(devices) > 0 { + var devicePaths []dbus.ObjectPath + for _, device := range devices { + devicePaths = append(devicePaths, device.GetPath()) + } + } + + var checkpointPath dbus.ObjectPath + err = nm.callWithReturn(&checkpointPath, NetworkManagerCheckpointCreate, devicePaths, rollbackTimeout, flags) + if err != nil { + return + } + + cp, err = NewCheckpoint(checkpointPath) + return +} + +func (nm *networkManager) CheckpointDestroy(checkpoint Checkpoint) error { + if checkpoint == nil { + return nm.call(NetworkManagerCheckpointDestroy) + } else { + return nm.call(NetworkManagerCheckpointDestroy, checkpoint.GetPath()) + } +} + +func (nm *networkManager) CheckpointRollback(checkpoint Checkpoint) (results map[dbus.ObjectPath]NmRollbackResult, err error) { + + var ret map[dbus.ObjectPath]NmRollbackResult + + err = nm.callWithReturn(&ret, NetworkManagerCheckpointRollback, checkpoint.GetPath()) + if err != nil { + return + } + + results = map[dbus.ObjectPath]NmRollbackResult{} + for devicePath, result := range ret { + results[devicePath] = result + } + + return +} + +func (nm *networkManager) CheckpointAdjustRollbackTimeout(checkpoint Checkpoint, addTimeout uint32) error { + return nm.call(NetworkManagerCheckpointAdjustRollbackTimeout, checkpoint, addTimeout) +} + +/* PROPERTIES */ + +func (nm *networkManager) GetPropertyDevices() ([]Device, error) { + devicesPaths, err := nm.getSliceObjectProperty(NetworkManagerPropertyDevices) + if err != nil { + return nil, err + } + + devices := make([]Device, len(devicesPaths)) + for i, path := range devicesPaths { + devices[i], err = NewDevice(path) + if err != nil { + return devices, err + } + } + + return devices, nil +} + +func (nm *networkManager) GetPropertyAllDevices() ([]Device, error) { + devicesPaths, err := nm.getSliceObjectProperty(NetworkManagerPropertyAllDevices) + if err != nil { + return nil, err + } + + devices := make([]Device, len(devicesPaths)) + for i, path := range devicesPaths { + devices[i], err = NewDevice(path) + if err != nil { + return devices, err + } + } + + return devices, nil +} + +func (nm *networkManager) GetPropertyCheckpoints() ([]Checkpoint, error) { + checkpointsPaths, err := nm.getSliceObjectProperty(NetworkManagerPropertyCheckpoints) + if err != nil { + return nil, err + } + + checkpoints := make([]Checkpoint, len(checkpointsPaths)) + for i, path := range checkpointsPaths { + checkpoints[i], err = NewCheckpoint(path) + if err != nil { + return checkpoints, err + } + } + + return checkpoints, nil +} + +func (nm *networkManager) GetPropertyNetworkingEnabled() (bool, error) { + return nm.getBoolProperty(NetworkManagerPropertyNetworkingEnabled) +} + +func (nm *networkManager) GetPropertyWirelessEnabled() (bool, error) { + return nm.getBoolProperty(NetworkManagerPropertyWirelessEnabled) +} + +func (nm *networkManager) SetPropertyWirelessEnabled(enabled bool) error { + return nm.setProperty(NetworkManagerPropertyWirelessEnabled, enabled) +} + +func (nm *networkManager) GetPropertyWirelessHardwareEnabled() (bool, error) { + return nm.getBoolProperty(NetworkManagerPropertyWirelessHardwareEnabled) +} + +func (nm *networkManager) GetPropertyWwanEnabled() (bool, error) { + return nm.getBoolProperty(NetworkManagerPropertyWwanEnabled) +} + +func (nm *networkManager) GetPropertyWwanHardwareEnabled() (bool, error) { + return nm.getBoolProperty(NetworkManagerPropertyWwanHardwareEnabled) +} + +func (nm *networkManager) GetPropertyWimaxEnabled() (bool, error) { + return nm.getBoolProperty(NetworkManagerPropertyWimaxEnabled) +} + +func (nm *networkManager) GetPropertyWimaxHardwareEnabled() (bool, error) { + return nm.getBoolProperty(NetworkManagerPropertyWimaxHardwareEnabled) +} + +func (nm *networkManager) GetPropertyActiveConnections() ([]ActiveConnection, error) { + acPaths, err := nm.getSliceObjectProperty(NetworkManagerPropertyActiveConnections) + if err != nil { + return nil, err + } + + ac := make([]ActiveConnection, len(acPaths)) + for i, path := range acPaths { + ac[i], err = NewActiveConnection(path) + if err != nil { + return ac, err + } + } + + return ac, nil +} + +func (nm *networkManager) GetPropertyPrimaryConnection() (Connection, error) { + connectionPath, err := nm.getObjectProperty(NetworkManagerPropertyPrimaryConnection) + + if err != nil { + return nil, err + } + + return NewConnection(connectionPath) +} + +func (nm *networkManager) GetPropertyPrimaryConnectionType() (string, error) { + return nm.getStringProperty(NetworkManagerPropertyPrimaryConnectionType) +} + +func (nm *networkManager) GetPropertyMetered() (NmMetered, error) { + v, err := nm.getUint32Property(NetworkManagerPropertyMetered) + return NmMetered(v), err +} + +func (nm *networkManager) GetPropertyActivatingConnection() (ActiveConnection, error) { + panic("implement me") +} + +func (nm *networkManager) GetPropertyStartup() (bool, error) { + return nm.getBoolProperty(NetworkManagerPropertyStartup) +} + +func (nm *networkManager) GetPropertyVersion() (string, error) { + return nm.getStringProperty(NetworkManagerPropertyVersion) +} + +func (nm *networkManager) GetPropertyCapabilities() ([]NmCapability, error) { + panic("implement me") +} + +func (nm *networkManager) GetPropertyState() (NmState, error) { + v, err := nm.getUint32Property(NetworkManagerPropertyState) + return NmState(v), err +} + +func (nm *networkManager) GetPropertyConnectivity() (NmConnectivity, error) { + v, err := nm.getUint32Property(NetworkManagerPropertyConnectivity) + return NmConnectivity(v), err +} + +func (nm *networkManager) GetPropertyConnectivityCheckAvailable() (bool, error) { + return nm.getBoolProperty(NetworkManagerPropertyConnectivityCheckAvailable) +} + +func (nm *networkManager) GetPropertyConnectivityCheckEnabled() (bool, error) { + return nm.getBoolProperty(NetworkManagerPropertyConnectivityCheckEnabled) +} + +func (nm *networkManager) Subscribe() <-chan *dbus.Signal { + if nm.sigChan != nil { + return nm.sigChan + } + + nm.subscribeNamespace(NetworkManagerObjectPath) + nm.sigChan = make(chan *dbus.Signal, 10) + nm.conn.Signal(nm.sigChan) + + return nm.sigChan +} + +func (nm *networkManager) Unsubscribe() { + nm.conn.RemoveSignal(nm.sigChan) + nm.sigChan = nil +} + +func (nm *networkManager) MarshalJSON() ([]byte, error) { + + Devices, err := nm.GetPropertyDevices() + if err != nil { + return nil, err + } + + AllDevices, err := nm.GetPropertyAllDevices() + if err != nil { + return nil, err + } + + Checkpoints, err := nm.GetPropertyCheckpoints() + if err != nil { + return nil, err + } + + NetworkingEnabled, err := nm.GetPropertyNetworkingEnabled() + if err != nil { + return nil, err + } + + WirelessEnabled, err := nm.GetPropertyWirelessEnabled() + if err != nil { + return nil, err + } + + WirelessHardwareEnabled, err := nm.GetPropertyWirelessHardwareEnabled() + if err != nil { + return nil, err + } + + WwanEnabled, err := nm.GetPropertyWwanEnabled() + if err != nil { + return nil, err + } + + WwanHardwareEnabled, err := nm.GetPropertyWwanHardwareEnabled() + if err != nil { + return nil, err + } + + WimaxEnabled, err := nm.GetPropertyWimaxEnabled() + if err != nil { + return nil, err + } + + WimaxHardwareEnabled, err := nm.GetPropertyWimaxHardwareEnabled() + if err != nil { + return nil, err + } + + ActiveConnections, err := nm.GetPropertyActiveConnections() + if err != nil { + return nil, err + } + + PrimaryConnection, err := nm.GetPropertyPrimaryConnection() + if err != nil { + return nil, err + } + + PrimaryConnectionType, err := nm.GetPropertyPrimaryConnectionType() + if err != nil { + return nil, err + } + + Metered, err := nm.GetPropertyMetered() + if err != nil { + return nil, err + } + + ActivatingConnection, err := nm.GetPropertyActivatingConnection() + if err != nil { + return nil, err + } + + Startup, err := nm.GetPropertyStartup() + if err != nil { + return nil, err + } + + Version, err := nm.GetPropertyVersion() + if err != nil { + return nil, err + } + + Capabilities, err := nm.GetPropertyCapabilities() + if err != nil { + return nil, err + } + + State, err := nm.GetPropertyState() + if err != nil { + return nil, err + } + + Connectivity, err := nm.GetPropertyConnectivity() + if err != nil { + return nil, err + } + + ConnectivityCheckAvailable, err := nm.GetPropertyConnectivityCheckAvailable() + if err != nil { + return nil, err + } + + ConnectivityCheckEnabled, err := nm.GetPropertyConnectivityCheckEnabled() + if err != nil { + return nil, err + } + + return json.Marshal(map[string]interface{}{ + "Devices": Devices, + "AllDevices": AllDevices, + "Checkpoints": Checkpoints, + "NetworkingEnabled": NetworkingEnabled, + "WirelessEnabled": WirelessEnabled, + "WirelessHardwareEnabled": WirelessHardwareEnabled, + "WwanEnabled": WwanEnabled, + "WwanHardwareEnabled": WwanHardwareEnabled, + "WimaxEnabled": WimaxEnabled, + "WimaxHardwareEnabled": WimaxHardwareEnabled, + "ActiveConnections": ActiveConnections, + "PrimaryConnection": PrimaryConnection, + "PrimaryConnectionType": PrimaryConnectionType, + "Metered": Metered, + "ActivatingConnection": ActivatingConnection, + "Startup": Startup, + "Version": Version, + "Capabilities": Capabilities, + "State": State, + "Connectivity": Connectivity, + "ConnectivityCheckAvailable": ConnectivityCheckAvailable, + "ConnectivityCheckEnabled": ConnectivityCheckEnabled, + }) +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/README.md b/vendor/github.com/Wifx/gonetworkmanager/README.md new file mode 100644 index 000000000..c4ad2d5bc --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/README.md @@ -0,0 +1,19 @@ +[![GoDoc](https://godoc.org/github.com/Wifx/gonetworkmanager?status.svg)](https://pkg.go.dev/github.com/Wifx/gonetworkmanager) +[![Go build](https://github.com/Wifx/gonetworkmanager/workflows/Go/badge.svg)](https://github.com/Wifx/gonetworkmanager/actions?query=workflow%3AGo) + +gonetworkmanager +================ + +Go D-Bus bindings for NetworkManager 1.16. + +Tested with NetworkManager 1.16.0. + +[NetworkManager 1.16 D-Bus Spec](https://developer.gnome.org/NetworkManager/1.16/spec.html) + +## Backward compatibility + +The library should also be compatible with NetworkManager 0.9.8.10. + +## Usage + +You can find some examples in the [examples](examples) directory. diff --git a/vendor/github.com/Wifx/gonetworkmanager/Settings.go b/vendor/github.com/Wifx/gonetworkmanager/Settings.go new file mode 100644 index 000000000..bb38af51e --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/Settings.go @@ -0,0 +1,129 @@ +package gonetworkmanager + +import ( + "github.com/godbus/dbus/v5" +) + +const ( + SettingsInterface = NetworkManagerInterface + ".Settings" + SettingsObjectPath = NetworkManagerObjectPath + "/Settings" + + /* Methods */ + SettingsListConnections = SettingsInterface + ".ListConnections" + SettingsGetConnectionByUUID = SettingsInterface + ".GetConnectionByUuid" + SettingsAddConnection = SettingsInterface + ".AddConnection" + SettingsAddConnectionUnsaved = SettingsInterface + ".AddConnectionUnsaved" + SettingsLoadConnections = SettingsInterface + ".LoadConnections" + SettingsReloadConnections = SettingsInterface + ".ReloadConnections" + SettingsSaveHostname = SettingsInterface + ".SaveHostname" + + /* Properties */ + SettingsPropertyConnections = SettingsInterface + ".Connections" // readable ao + SettingsPropertyHostname = SettingsInterface + ".Hostname" // readable s + SettingsPropertyCanModify = SettingsInterface + ".CanModify" // readable b +) + +type Settings interface { + // ListConnections gets list the saved network connections known to NetworkManager + ListConnections() ([]Connection, error) + + // ReloadConnections tells NetworkManager to reload all connection files from disk, including noticing any added or deleted connection files. + ReloadConnections() error + + // GetConnectionByUUID gets the connection, given that connection's UUID. + GetConnectionByUUID(uuid string) (Connection, error) + + // AddConnection adds new connection and save it to disk. + AddConnection(settings ConnectionSettings) (Connection, error) + + // Add new connection but do not save it to disk immediately. This operation does not start the network connection unless (1) device is idle and able to connect to the network described by the new connection, and (2) the connection is allowed to be started automatically. Use the 'Save' method on the connection to save these changes to disk. Note that unsaved changes will be lost if the connection is reloaded from disk (either automatically on file change or due to an explicit ReloadConnections call). + AddConnectionUnsaved(settings ConnectionSettings) (Connection, error) + + // Save the hostname to persistent configuration. + SaveHostname(hostname string) error + + // If true, adding and modifying connections is supported. + GetPropertyCanModify() (bool, error) + + // The machine hostname stored in persistent configuration. + GetPropertyHostname() (string, error) +} + +func NewSettings() (Settings, error) { + var s settings + return &s, s.init(NetworkManagerInterface, SettingsObjectPath) +} + +type settings struct { + dbusBase +} + +func (s *settings) ListConnections() ([]Connection, error) { + var connectionPaths []dbus.ObjectPath + + err := s.callWithReturn(&connectionPaths, SettingsListConnections) + if err != nil { + return nil, err + } + + connections := make([]Connection, len(connectionPaths)) + + for i, path := range connectionPaths { + connections[i], err = NewConnection(path) + if err != nil { + return connections, err + } + } + + return connections, nil +} + +// ReloadConnections tells NetworkManager to reload (and apply) configuration files +// from disk taking notice of any added or removed connections. +func (s *settings) ReloadConnections() error { + return s.call(SettingsReloadConnections) +} + +// GetConnectionByUUID gets the connection, given that connection's UUID. +func (s *settings) GetConnectionByUUID(uuid string) (Connection, error) { + var path dbus.ObjectPath + err := s.callWithReturn(&path, SettingsGetConnectionByUUID, uuid) + if err != nil { + return nil, err + } + + return NewConnection(path) +} + +func (s *settings) AddConnection(settings ConnectionSettings) (Connection, error) { + var path dbus.ObjectPath + err := s.callWithReturn(&path, SettingsAddConnection, settings) + if err != nil { + return nil, err + } + + return NewConnection(path) +} + +func (s *settings) AddConnectionUnsaved(settings ConnectionSettings) (Connection, error) { + var path dbus.ObjectPath + err := s.callWithReturn(&path, SettingsAddConnectionUnsaved, settings) + + if err != nil { + return nil, err + } + + return NewConnection(path) +} + +func (s *settings) SaveHostname(hostname string) error { + return s.call(SettingsSaveHostname, hostname) +} + +func (s *settings) GetPropertyHostname() (string, error) { + return s.getStringProperty(SettingsPropertyHostname) +} + +func (s *settings) GetPropertyCanModify() (bool, error) { + return s.getBoolProperty(SettingsPropertyCanModify) +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/VpnConnection.go b/vendor/github.com/Wifx/gonetworkmanager/VpnConnection.go new file mode 100644 index 000000000..bdaa013e7 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/VpnConnection.go @@ -0,0 +1,45 @@ +package gonetworkmanager + +import ( + "github.com/godbus/dbus/v5" +) + +const ( + VpnConnectionInterface = NetworkManagerInterface + ".VPN.Connection" + + /* Properties */ + VpnConnectionPropertyVpnState = VpnConnectionInterface + ".VpnState" // readable u + VpnConnectionPropertyBanner = VpnConnectionInterface + ".Banner" // readable s +) + +type VpnConnection interface { + GetPath() dbus.ObjectPath + + // The VPN-specific state of the connection. + GetPropertyVpnState() (NmVpnConnectionState, error) + + // The banner string of the VPN connection. + GetPropertyBanner() (string, error) +} + +func NewVpnConnection(objectPath dbus.ObjectPath) (VpnConnection, error) { + var a vpnConnection + return &a, a.init(NetworkManagerInterface, objectPath) +} + +type vpnConnection struct { + dbusBase +} + +func (a *vpnConnection) GetPath() dbus.ObjectPath { + return a.obj.Path() +} + +func (a *vpnConnection) GetPropertyVpnState() (NmVpnConnectionState, error) { + v, err := a.getUint32Property(VpnConnectionPropertyVpnState) + return NmVpnConnectionState(v), err +} + +func (a *vpnConnection) GetPropertyBanner() (string, error) { + return a.getStringProperty(VpnConnectionPropertyBanner) +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/enums.go b/vendor/github.com/Wifx/gonetworkmanager/enums.go new file mode 100644 index 000000000..69dbca155 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/enums.go @@ -0,0 +1,290 @@ +package gonetworkmanager + +//go:generate stringer -type=NmConnectivity +type NmConnectivity uint32 + +const ( + NmConnectivityUnknown NmConnectivity = 0 // Network connectivity is unknown. This means the connectivity checks are disabled (e.g. on server installations) or has not run yet. The graphical shell should assume the Internet connection might be available and not present a captive portal window. + NmConnectivityNone NmConnectivity = 1 // The host is not connected to any network. There's no active connection that contains a default route to the internet and thus it makes no sense to even attempt a connectivity check. The graphical shell should use this state to indicate the network connection is unavailable. + NmConnectivityPortal NmConnectivity = 2 // The Internet connection is hijacked by a captive portal gateway. The graphical shell may open a sandboxed web browser window (because the captive portals typically attempt a man-in-the-middle attacks against the https connections) for the purpose of authenticating to a gateway and retrigger the connectivity check with CheckConnectivity() when the browser window is dismissed. + NmConnectivityLimited NmConnectivity = 3 // The host is connected to a network, does not appear to be able to reach the full Internet, but a captive portal has not been detected. + NmConnectivityFull NmConnectivity = 4 // The host is connected to a network, and appears to be able to reach the full Internet. +) + +//go:generate stringer -type=NmState +type NmState uint32 + +const ( + NmStateUnknown NmState = 0 // Networking state is unknown. This indicates a daemon error that makes it unable to reasonably assess the state. In such event the applications are expected to assume Internet connectivity might be present and not disable controls that require network access. The graphical shells may hide the network accessibility indicator altogether since no meaningful status indication can be provided. + NmStateAsleep NmState = 10 // Networking is not enabled, the system is being suspended or resumed from suspend. + NmStateDisconnected NmState = 20 // There is no active network connection. The graphical shell should indicate no network connectivity and the applications should not attempt to access the network. + NmStateDisconnecting NmState = 30 // Network connections are being cleaned up. The applications should tear down their network sessions. + NmStateConnecting NmState = 40 // A network connection is being started The graphical shell should indicate the network is being connected while the applications should still make no attempts to connect the network. + NmStateConnectedLocal NmState = 50 // There is only local IPv4 and/or IPv6 connectivity, but no default route to access the Internet. The graphical shell should indicate no network connectivity. + NmStateConnectedSite NmState = 60 // There is only site-wide IPv4 and/or IPv6 connectivity. This means a default route is available, but the Internet connectivity check (see "Connectivity" property) did not succeed. The graphical shell should indicate limited network connectivity. + NmStateConnectedGlobal NmState = 70 // There is global IPv4 and/or IPv6 Internet connectivity This means the Internet connectivity check succeeded, the graphical shell should indicate full network connectivity. +) + +//go:generate stringer -type=NmCheckpointCreateFlags +type NmCheckpointCreateFlags uint32 + +const ( + NmCheckpointCreateFlagsNone NmCheckpointCreateFlags = 0 // no flags + NmCheckpointCreateFlagsDestroyAll NmCheckpointCreateFlags = 0x01 // when creating a new checkpoint, destroy all existing ones. + NmCheckpointCreateFlagsDeleteNewConnections NmCheckpointCreateFlags = 0x02 // upon rollback, delete any new connection added after the checkpoint (Since: 1.6) + NmCheckpointCreateFlagsDisconnectNewDevices NmCheckpointCreateFlags = 0x04 // upon rollback, disconnect any new device appeared after the checkpoint (Since: 1.6) + NmCheckpointCreateFlagsAllowOverlapping NmCheckpointCreateFlags = 0x08 // by default, creating a checkpoint fails if there are already existing checkoints that reference the same devices. With this flag, creation of such checkpoints is allowed, however, if an older checkpoint that references overlapping devices gets rolled back, it will automatically destroy this checkpoint during rollback. This allows to create several overlapping checkpoints in parallel, and rollback to them at will. With the special case that rolling back to an older checkpoint will invalidate all overlapping younger checkpoints. This opts-in that the checkpoint can be automatically destroyed by the rollback of an older checkpoint. (Since: 1.12) +) + +//go:generate stringer -type=NmCapability +type NmCapability uint32 + +const ( + NmCapabilityTeam NmCapability = 1 // Teams can be managed +) + +//go:generate stringer -type=NmMetered +type NmMetered uint32 + +const ( + NmMeteredUnknown NmMetered = 0 // The metered status is unknown + NmMeteredYes NmMetered = 1 // Metered, the value was statically set + NmMeteredNo NmMetered = 2 // Not metered, the value was statically set + NmMeteredGuessYes NmMetered = 3 // Metered, the value was guessed + NmMeteredGuessNo NmMetered = 4 // Not metered, the value was guessed +) + +//go:generate stringer -type=NmDeviceState +type NmDeviceState uint32 + +const ( + NmDeviceStateUnknown NmDeviceState = 0 // the device's state is unknown + NmDeviceStateUnmanaged NmDeviceState = 10 // the device is recognized, but not managed by NetworkManager + NmDeviceStateUnavailable NmDeviceState = 20 // the device is managed by NetworkManager, but is not available for use. Reasons may include the wireless switched off, missing firmware, no ethernet carrier, missing supplicant or modem manager, etc. + NmDeviceStateDisconnected NmDeviceState = 30 // the device can be activated, but is currently idle and not connected to a network. + NmDeviceStatePrepare NmDeviceState = 40 // the device is preparing the connection to the network. This may include operations like changing the MAC address, setting physical link properties, and anything else required to connect to the requested network. + NmDeviceStateConfig NmDeviceState = 50 // the device is connecting to the requested network. This may include operations like associating with the Wi-Fi AP, dialing the modem, connecting to the remote Bluetooth device, etc. + NmDeviceStateNeedAuth NmDeviceState = 60 // the device requires more information to continue connecting to the requested network. This includes secrets like WiFi passphrases, login passwords, PIN codes, etc. + NmDeviceStateIpConfig NmDeviceState = 70 // the device is requesting IPv4 and/or IPv6 addresses and routing information from the network. + NmDeviceStateIpCheck NmDeviceState = 80 // the device is checking whether further action is required for the requested network connection. This may include checking whether only local network access is available, whether a captive portal is blocking access to the Internet, etc. + NmDeviceStateSecondaries NmDeviceState = 90 // the device is waiting for a secondary connection (like a VPN) which must activated before the device can be activated + NmDeviceStateActivated NmDeviceState = 100 // the device has a network connection, either local or global. + NmDeviceStateDeactivating NmDeviceState = 110 // a disconnection from the current network connection was requested, and the device is cleaning up resources used for that connection. The network connection may still be valid. + NmDeviceStateFailed NmDeviceState = 120 // the device failed to connect to the requested network and is cleaning up the connection request +) + +//go:generate stringer -type=NmActiveConnectionState +type NmActiveConnectionState uint32 + +const ( + NmActiveConnectionStateUnknown NmActiveConnectionState = 0 // The state of the connection is unknown + NmActiveConnectionStateActivating NmActiveConnectionState = 1 // A network connection is being prepared + NmActiveConnectionStateActivated NmActiveConnectionState = 2 // There is a connection to the network + NmActiveConnectionStateDeactivating NmActiveConnectionState = 3 // The network connection is being torn down and cleaned up + NmActiveConnectionStateDeactivated NmActiveConnectionState = 4 // The network connection is disconnected and will be removed +) + +//go:generate stringer -type=NmActivationStateFlag +type NmActivationStateFlag uint32 + +const ( + NmActivationStateFlagNone NmActivationStateFlag = 0x00 // an alias for numeric zero, no flags set. + NmActivationStateFlagIsMaster NmActivationStateFlag = 0x01 // the device is a master. + NmActivationStateFlagIsSlave NmActivationStateFlag = 0x02 // the device is a slave. + NmActivationStateFlagLayer2Ready NmActivationStateFlag = 0x04 // layer2 is activated and ready. + NmActivationStateFlagIp4Ready NmActivationStateFlag = 0x08 // IPv4 setting is completed. + NmActivationStateFlagIp6Ready NmActivationStateFlag = 0x10 // IPv6 setting is completed. + NmActivationStateFlagMasterHasSlaves NmActivationStateFlag = 0x20 // The master has any slave devices attached. This only makes sense if the device is a master. + NmActivationStateFlagLifetimeBoundToProfileVisibility NmActivationStateFlag = 0x40 // the lifetime of the activation is bound to the visilibity of the connection profile, which in turn depends on "connection.permissions" and whether a session for the user exists. Since: 1.16 +) + +//go:generate stringer -type=NmDeviceType +type NmDeviceType uint32 + +const ( + NmDeviceTypeUnknown NmDeviceType = 0 // unknown device + NmDeviceTypeGeneric NmDeviceType = 14 // generic support for unrecognized device types + NmDeviceTypeEthernet NmDeviceType = 1 // a wired ethernet device + NmDeviceTypeWifi NmDeviceType = 2 // an 802.11 Wi-Fi device + NmDeviceTypeUnused1 NmDeviceType = 3 // not used + NmDeviceTypeUnused2 NmDeviceType = 4 // not used + NmDeviceTypeBt NmDeviceType = 5 // a Bluetooth device supporting PAN or DUN access protocols + NmDeviceTypeOlpcMesh NmDeviceType = 6 // an OLPC XO mesh networking device + NmDeviceTypeWimax NmDeviceType = 7 // an 802.16e Mobile WiMAX broadband device + NmDeviceTypeModem NmDeviceType = 8 // a modem supporting analog telephone, CDMA/EVDO, GSM/UMTS, or LTE network access protocols + NmDeviceTypeInfiniband NmDeviceType = 9 // an IP-over-InfiniBand device + NmDeviceTypeBond NmDeviceType = 10 // a bond master interface + NmDeviceTypeVlan NmDeviceType = 11 // an 802.1Q VLAN interface + NmDeviceTypeAdsl NmDeviceType = 12 // ADSL modem + NmDeviceTypeBridge NmDeviceType = 13 // a bridge master interface + NmDeviceTypeTeam NmDeviceType = 15 // a team master interface + NmDeviceTypeTun NmDeviceType = 16 // a TUN or TAP interface + NmDeviceTypeIpTunnel NmDeviceType = 17 // a IP tunnel interface + NmDeviceTypeMacvlan NmDeviceType = 18 // a MACVLAN interface + NmDeviceTypeVxlan NmDeviceType = 19 // a VXLAN interface + NmDeviceTypeVeth NmDeviceType = 20 // a VETH interface + NmDeviceTypeMacsec NmDeviceType = 21 // a MACsec interface + NmDeviceTypeDummy NmDeviceType = 22 // a dummy interface + NmDeviceTypePpp NmDeviceType = 23 // a PPP interface + NmDeviceTypeOvsInterface NmDeviceType = 24 // a Open vSwitch interface + NmDeviceTypeOvsPort NmDeviceType = 25 // a Open vSwitch port + NmDeviceTypeOvsBridge NmDeviceType = 26 // a Open vSwitch bridge + NmDeviceTypeWpan NmDeviceType = 27 // a IEEE 802.15.4 (WPAN) MAC Layer Device + NmDeviceType6lowpan NmDeviceType = 28 // 6LoWPAN interface + NmDeviceTypeWireguard NmDeviceType = 29 // a WireGuard interface + NmDeviceTypeWifiP2p NmDeviceType = 30 // an 802.11 Wi-Fi P2P device (Since: 1.16) +) + +//go:generate stringer -type=Nm80211APFlags +type Nm80211APFlags uint32 + +const ( + Nm80211APFlagsNone Nm80211APFlags = 0x0 + Nm80211APFlagsPrivacy Nm80211APFlags = 0x1 +) + +//go:generate stringer -type=Nm80211APSec +type Nm80211APSec uint32 + +const ( + Nm80211APSecNone Nm80211APSec = 0x0 + Nm80211APSecPairWEP40 Nm80211APSec = 0x1 + Nm80211APSecPairWEP104 Nm80211APSec = 0x2 + Nm80211APSecPairTKIP Nm80211APSec = 0x4 + Nm80211APSecPairCCMP Nm80211APSec = 0x8 + Nm80211APSecGroupWEP40 Nm80211APSec = 0x10 + Nm80211APSecGroupWEP104 Nm80211APSec = 0x20 + Nm80211APSecGroupTKIP Nm80211APSec = 0x40 + Nm80211APSecGroupCCMP Nm80211APSec = 0x80 + Nm80211APSecKeyMgmtPSK Nm80211APSec = 0x100 + Nm80211APSecKeyMgmt8021X Nm80211APSec = 0x200 +) + +//go:generate stringer -type=Nm80211Mode +type Nm80211Mode uint32 + +const ( + Nm80211ModeUnknown Nm80211Mode = 0 + Nm80211ModeAdhoc Nm80211Mode = 1 + Nm80211ModeInfra Nm80211Mode = 2 + Nm80211ModeAp Nm80211Mode = 3 +) + +//go:generate stringer -type=NmActiveConnectionState +type NmVpnConnectionState uint32 + +const ( + NmVpnConnectionUnknown = 0 //The state of the VPN connection is unknown. + NmVpnConnectionPrepare = 1 //The VPN connection is preparing to connect. + NmVpnConnectionNeedAuth = 2 //The VPN connection needs authorization credentials. + NmVpnConnectionConnect = 3 //The VPN connection is being established. + NmVpnConnectionIpConfigGet = 4 //The VPN connection is getting an IP address. + NmVpnConnectionActivated = 5 //The VPN connection is active. + NmVpnConnectionFailed = 6 //The VPN connection failed. + NmVpnConnectionDisconnected = 7 //The VPN connection is disconnected. +) + +//go:generate stringer -type=NmDeviceStateReason +type NmDeviceStateReason uint32 + +const ( + NmDeviceStateReasonNone = 0 // No reason given + NmDeviceStateReasonUnknown = 1 // Unknown error + NmDeviceStateReasonNowManaged = 2 // Device is now managed + NmDeviceStateReasonNowUnmanaged = 3 // Device is now unmanaged + NmDeviceStateReasonConfigFailed = 4 // The device could not be readied for configuration + NmDeviceStateReasonIpConfigUnavailable = 5 // IP configuration could not be reserved (no available address, timeout, etc) + NmDeviceStateReasonIpConfigExpired = 6 // The IP config is no longer valid + NmDeviceStateReasonNoSecrets = 7 // Secrets were required, but not provided + NmDeviceStateReasonSupplicantDisconnect = 8 // 802.1x supplicant disconnected + NmDeviceStateReasonSupplicantConfigFailed = 9 // 802.1x supplicant configuration failed + NmDeviceStateReasonSupplicantFailed = 10 // 802.1x supplicant failed + NmDeviceStateReasonSupplicantTimeout = 11 // 802.1x supplicant took too long to authenticate + NmDeviceStateReasonPppStartFailed = 12 // PPP service failed to start + NmDeviceStateReasonPppDisconnect = 13 // PPP service disconnected + NmDeviceStateReasonPppFailed = 14 // PPP failed + NmDeviceStateReasonDhcpStartFailed = 15 // DHCP client failed to start + NmDeviceStateReasonDhcpError = 16 // DHCP client error + NmDeviceStateReasonDhcpFailed = 17 // DHCP client failed + NmDeviceStateReasonSharedStartFailed = 18 // Shared connection service failed to start + NmDeviceStateReasonSharedFailed = 19 // Shared connection service failed + NmDeviceStateReasonAutoipStartFailed = 20 // AutoIP service failed to start + NmDeviceStateReasonAutoipError = 21 // AutoIP service error + NmDeviceStateReasonAutoipFailed = 22 // AutoIP service failed + NmDeviceStateReasonModemBusy = 23 // The line is busy + NmDeviceStateReasonModemNoDialTone = 24 // No dial tone + NmDeviceStateReasonModemNoCarrier = 25 // No carrier could be established + NmDeviceStateReasonModemDialTimeout = 26 // The dialing request timed out + NmDeviceStateReasonModemDialFailed = 27 // The dialing attempt failed + NmDeviceStateReasonModemInitFailed = 28 // Modem initialization failed + NmDeviceStateReasonGsmApnFailed = 29 // Failed to select the specified APN + NmDeviceStateReasonGsmRegistrationNotSearching = 30 // Not searching for networks + NmDeviceStateReasonGsmRegistrationDenied = 31 // Network registration denied + NmDeviceStateReasonGsmRegistrationTimeout = 32 // Network registration timed out + NmDeviceStateReasonGsmRegistrationFailed = 33 // Failed to register with the requested network + NmDeviceStateReasonGsmPinCheckFailed = 34 // PIN check failed + NmDeviceStateReasonFirmwareMissing = 35 // Necessary firmware for the device may be missing + NmDeviceStateReasonRemoved = 36 // The device was removed + NmDeviceStateReasonSleeping = 37 // NetworkManager went to sleep + NmDeviceStateReasonConnectionRemoved = 38 // The device's active connection disappeared + NmDeviceStateReasonUserRequested = 39 // Device disconnected by user or client + NmDeviceStateReasonCarrier = 40 // Carrier/link changed + NmDeviceStateReasonConnectionAssumed = 41 // The device's existing connection was assumed + NmDeviceStateReasonSupplicantAvailable = 42 // The supplicant is now available + NmDeviceStateReasonModemNotFound = 43 // The modem could not be found + NmDeviceStateReasonBtFailed = 44 // The Bluetooth connection failed or timed out + NmDeviceStateReasonGsmSimNotInserted = 45 // GSM Modem's SIM Card not inserted + NmDeviceStateReasonGsmSimPinRequired = 46 // GSM Modem's SIM Pin required + NmDeviceStateReasonGsmSimPukRequired = 47 // GSM Modem's SIM Puk required + NmDeviceStateReasonGsmSimWrong = 48 // GSM Modem's SIM wrong + NmDeviceStateReasonInfinibandMode = 49 // InfiniBand device does not support connected mode + NmDeviceStateReasonDependencyFailed = 50 // A dependency of the connection failed + NmDeviceStateReasonBr2684Failed = 51 // Problem with the RFC 2684 Ethernet over ADSL bridge + NmDeviceStateReasonModemManagerUnavailable = 52 // ModemManager not running + NmDeviceStateReasonSsidNotFound = 53 // The Wi-Fi network could not be found + NmDeviceStateReasonSecondaryConnectionFailed = 54 // A secondary connection of the base connection failed + NmDeviceStateReasonDcbFcoeFailed = 55 // DCB or FCoE setup failed + NmDeviceStateReasonTeamdControlFailed = 56 // teamd control failed + NmDeviceStateReasonModemFailed = 57 // Modem failed or no longer available + NmDeviceStateReasonModemAvailable = 58 // Modem now ready and available + NmDeviceStateReasonSimPinIncorrect = 59 // SIM PIN was incorrect + NmDeviceStateReasonNewActivation = 60 // New connection activation was enqueued + NmDeviceStateReasonParentChanged = 61 // the device's parent changed + NmDeviceStateReasonParentManagedChanged = 62 // the device parent's management changed + NmDeviceStateReasonOvsdbFailed = 63 // problem communicating with Open vSwitch database + NmDeviceStateReasonIpAddressDuplicate = 64 // a duplicate IP address was detected + NmDeviceStateReasonIpMethodUnsupported = 65 // The selected IP method is not supported + NmDeviceStateReasonSriovConfigurationFailed = 66 // configuration of SR-IOV parameters failed + NmDeviceStateReasonPeerNotFound = 67 // The Wi-Fi P2P peer could not be found +) + +//go:generate stringer -type=NmActiveConnectionStateReason +type NmActiveConnectionStateReason uint32 + +const ( + NmActiveConnectionStateReasonUnknown = 0 // The reason for the active connection state change is unknown. + NmActiveConnectionStateReasonNone = 1 // No reason was given for the active connection state change. + NmActiveConnectionStateReasonUserDisconnected = 2 // The active connection changed state because the user disconnected it. + NmActiveConnectionStateReasonDeviceDisconnected = 3 // The active connection changed state because the device it was using was disconnected. + NmActiveConnectionStateReasonServiceStopped = 4 // The service providing the VPN connection was stopped. + NmActiveConnectionStateReasonIpConfigInvalid = 5 // The IP config of the active connection was invalid. + NmActiveConnectionStateReasonConnectTimeout = 6 // The connection attempt to the VPN service timed out. + NmActiveConnectionStateReasonServiceStartTimeout = 7 // A timeout occurred while starting the service providing the VPN connection. + NmActiveConnectionStateReasonServiceStartFailed = 8 // Starting the service providing the VPN connection failed. + NmActiveConnectionStateReasonNoSecrets = 9 // Necessary secrets for the connection were not provided. + NmActiveConnectionStateReasonLoginFailed = 10 // Authentication to the server failed. + NmActiveConnectionStateReasonConnectionRemoved = 11 // The connection was deleted from settings. + NmActiveConnectionStateReasonDependencyFailed = 12 // Master connection of this connection failed to activate. + NmActiveConnectionStateReasonDeviceRealizeFailed = 13 // Could not create the software device link. + NmActiveConnectionStateReasonDeviceRemoved = 14 // The device this connection depended on disappeared. +) + +//go:generate stringer -type=NmRollbackResult +type NmRollbackResult uint32 + +const ( + NmRollbackResultOk = 0 // the rollback succeeded. + NmRollbackResultErrNoDevice = 1 // the device no longer exists. + NmRollbackResultErrDeviceUnmanaged = 2 // the device is now unmanaged. + NmRollbackResultErrFailed = 3 // other errors during rollback. +) diff --git a/vendor/github.com/Wifx/gonetworkmanager/go.mod b/vendor/github.com/Wifx/gonetworkmanager/go.mod new file mode 100644 index 000000000..63441ed01 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/go.mod @@ -0,0 +1,5 @@ +module github.com/Wifx/gonetworkmanager + +go 1.12 + +require github.com/godbus/dbus/v5 v5.0.2 diff --git a/vendor/github.com/Wifx/gonetworkmanager/go.sum b/vendor/github.com/Wifx/gonetworkmanager/go.sum new file mode 100644 index 000000000..f0856ca48 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/go.sum @@ -0,0 +1,2 @@ +github.com/godbus/dbus/v5 v5.0.2 h1:QtWdZQyXTEn7S0LXv9nVxPUiT37d1i7UntpRTiKM86E= +github.com/godbus/dbus/v5 v5.0.2/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= diff --git a/vendor/github.com/Wifx/gonetworkmanager/nm80211apflags_string.go b/vendor/github.com/Wifx/gonetworkmanager/nm80211apflags_string.go new file mode 100644 index 000000000..8213550aa --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/nm80211apflags_string.go @@ -0,0 +1,24 @@ +// Code generated by "stringer -type=Nm80211APFlags"; DO NOT EDIT. + +package gonetworkmanager + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[Nm80211APFlagsNone-0] + _ = x[Nm80211APFlagsPrivacy-1] +} + +const _Nm80211APFlags_name = "Nm80211APFlagsNoneNm80211APFlagsPrivacy" + +var _Nm80211APFlags_index = [...]uint8{0, 18, 39} + +func (i Nm80211APFlags) String() string { + if i >= Nm80211APFlags(len(_Nm80211APFlags_index)-1) { + return "Nm80211APFlags(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _Nm80211APFlags_name[_Nm80211APFlags_index[i]:_Nm80211APFlags_index[i+1]] +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/nm80211apsec_string.go b/vendor/github.com/Wifx/gonetworkmanager/nm80211apsec_string.go new file mode 100644 index 000000000..8461909eb --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/nm80211apsec_string.go @@ -0,0 +1,63 @@ +// Code generated by "stringer -type=Nm80211APSec"; DO NOT EDIT. + +package gonetworkmanager + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[Nm80211APSecNone-0] + _ = x[Nm80211APSecPairWEP40-1] + _ = x[Nm80211APSecPairWEP104-2] + _ = x[Nm80211APSecPairTKIP-4] + _ = x[Nm80211APSecPairCCMP-8] + _ = x[Nm80211APSecGroupWEP40-16] + _ = x[Nm80211APSecGroupWEP104-32] + _ = x[Nm80211APSecGroupTKIP-64] + _ = x[Nm80211APSecGroupCCMP-128] + _ = x[Nm80211APSecKeyMgmtPSK-256] + _ = x[Nm80211APSecKeyMgmt8021X-512] +} + +const ( + _Nm80211APSec_name_0 = "Nm80211APSecNoneNm80211APSecPairWEP40Nm80211APSecPairWEP104" + _Nm80211APSec_name_1 = "Nm80211APSecPairTKIP" + _Nm80211APSec_name_2 = "Nm80211APSecPairCCMP" + _Nm80211APSec_name_3 = "Nm80211APSecGroupWEP40" + _Nm80211APSec_name_4 = "Nm80211APSecGroupWEP104" + _Nm80211APSec_name_5 = "Nm80211APSecGroupTKIP" + _Nm80211APSec_name_6 = "Nm80211APSecGroupCCMP" + _Nm80211APSec_name_7 = "Nm80211APSecKeyMgmtPSK" + _Nm80211APSec_name_8 = "Nm80211APSecKeyMgmt8021X" +) + +var ( + _Nm80211APSec_index_0 = [...]uint8{0, 16, 37, 59} +) + +func (i Nm80211APSec) String() string { + switch { + case 0 <= i && i <= 2: + return _Nm80211APSec_name_0[_Nm80211APSec_index_0[i]:_Nm80211APSec_index_0[i+1]] + case i == 4: + return _Nm80211APSec_name_1 + case i == 8: + return _Nm80211APSec_name_2 + case i == 16: + return _Nm80211APSec_name_3 + case i == 32: + return _Nm80211APSec_name_4 + case i == 64: + return _Nm80211APSec_name_5 + case i == 128: + return _Nm80211APSec_name_6 + case i == 256: + return _Nm80211APSec_name_7 + case i == 512: + return _Nm80211APSec_name_8 + default: + return "Nm80211APSec(" + strconv.FormatInt(int64(i), 10) + ")" + } +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/nm80211mode_string.go b/vendor/github.com/Wifx/gonetworkmanager/nm80211mode_string.go new file mode 100644 index 000000000..477062f9e --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/nm80211mode_string.go @@ -0,0 +1,26 @@ +// Code generated by "stringer -type=Nm80211Mode"; DO NOT EDIT. + +package gonetworkmanager + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[Nm80211ModeUnknown-0] + _ = x[Nm80211ModeAdhoc-1] + _ = x[Nm80211ModeInfra-2] + _ = x[Nm80211ModeAp-3] +} + +const _Nm80211Mode_name = "Nm80211ModeUnknownNm80211ModeAdhocNm80211ModeInfraNm80211ModeAp" + +var _Nm80211Mode_index = [...]uint8{0, 18, 34, 50, 63} + +func (i Nm80211Mode) String() string { + if i >= Nm80211Mode(len(_Nm80211Mode_index)-1) { + return "Nm80211Mode(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _Nm80211Mode_name[_Nm80211Mode_index[i]:_Nm80211Mode_index[i+1]] +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/nmactivationstateflag_string.go b/vendor/github.com/Wifx/gonetworkmanager/nmactivationstateflag_string.go new file mode 100644 index 000000000..6444a2cc4 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/nmactivationstateflag_string.go @@ -0,0 +1,51 @@ +// Code generated by "stringer -type=NmActivationStateFlag"; DO NOT EDIT. + +package gonetworkmanager + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[NmActivationStateFlagNone-0] + _ = x[NmActivationStateFlagIsMaster-1] + _ = x[NmActivationStateFlagIsSlave-2] + _ = x[NmActivationStateFlagLayer2Ready-4] + _ = x[NmActivationStateFlagIp4Ready-8] + _ = x[NmActivationStateFlagIp6Ready-16] + _ = x[NmActivationStateFlagMasterHasSlaves-32] + _ = x[NmActivationStateFlagLifetimeBoundToProfileVisibility-64] +} + +const ( + _NmActivationStateFlag_name_0 = "NmActivationStateFlagNoneNmActivationStateFlagIsMasterNmActivationStateFlagIsSlave" + _NmActivationStateFlag_name_1 = "NmActivationStateFlagLayer2Ready" + _NmActivationStateFlag_name_2 = "NmActivationStateFlagIp4Ready" + _NmActivationStateFlag_name_3 = "NmActivationStateFlagIp6Ready" + _NmActivationStateFlag_name_4 = "NmActivationStateFlagMasterHasSlaves" + _NmActivationStateFlag_name_5 = "NmActivationStateFlagLifetimeBoundToProfileVisibility" +) + +var ( + _NmActivationStateFlag_index_0 = [...]uint8{0, 25, 54, 82} +) + +func (i NmActivationStateFlag) String() string { + switch { + case 0 <= i && i <= 2: + return _NmActivationStateFlag_name_0[_NmActivationStateFlag_index_0[i]:_NmActivationStateFlag_index_0[i+1]] + case i == 4: + return _NmActivationStateFlag_name_1 + case i == 8: + return _NmActivationStateFlag_name_2 + case i == 16: + return _NmActivationStateFlag_name_3 + case i == 32: + return _NmActivationStateFlag_name_4 + case i == 64: + return _NmActivationStateFlag_name_5 + default: + return "NmActivationStateFlag(" + strconv.FormatInt(int64(i), 10) + ")" + } +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/nmactiveconnectionstate_string.go b/vendor/github.com/Wifx/gonetworkmanager/nmactiveconnectionstate_string.go new file mode 100644 index 000000000..ad2e4ce0c --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/nmactiveconnectionstate_string.go @@ -0,0 +1,27 @@ +// Code generated by "stringer -type=NmActiveConnectionState"; DO NOT EDIT. + +package gonetworkmanager + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[NmActiveConnectionStateUnknown-0] + _ = x[NmActiveConnectionStateActivating-1] + _ = x[NmActiveConnectionStateActivated-2] + _ = x[NmActiveConnectionStateDeactivating-3] + _ = x[NmActiveConnectionStateDeactivated-4] +} + +const _NmActiveConnectionState_name = "NmActiveConnectionStateUnknownNmActiveConnectionStateActivatingNmActiveConnectionStateActivatedNmActiveConnectionStateDeactivatingNmActiveConnectionStateDeactivated" + +var _NmActiveConnectionState_index = [...]uint8{0, 30, 63, 95, 130, 164} + +func (i NmActiveConnectionState) String() string { + if i >= NmActiveConnectionState(len(_NmActiveConnectionState_index)-1) { + return "NmActiveConnectionState(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _NmActiveConnectionState_name[_NmActiveConnectionState_index[i]:_NmActiveConnectionState_index[i+1]] +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/nmcapability_string.go b/vendor/github.com/Wifx/gonetworkmanager/nmcapability_string.go new file mode 100644 index 000000000..2fcbf34fe --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/nmcapability_string.go @@ -0,0 +1,24 @@ +// Code generated by "stringer -type=NmCapability"; DO NOT EDIT. + +package gonetworkmanager + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[NmCapabilityTeam-1] +} + +const _NmCapability_name = "NmCapabilityTeam" + +var _NmCapability_index = [...]uint8{0, 16} + +func (i NmCapability) String() string { + i -= 1 + if i >= NmCapability(len(_NmCapability_index)-1) { + return "NmCapability(" + strconv.FormatInt(int64(i+1), 10) + ")" + } + return _NmCapability_name[_NmCapability_index[i]:_NmCapability_index[i+1]] +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/nmcheckpointcreateflags_string.go b/vendor/github.com/Wifx/gonetworkmanager/nmcheckpointcreateflags_string.go new file mode 100644 index 000000000..8e7cc99d6 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/nmcheckpointcreateflags_string.go @@ -0,0 +1,39 @@ +// Code generated by "stringer -type=NmCheckpointCreateFlags"; DO NOT EDIT. + +package gonetworkmanager + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[NmCheckpointCreateFlagsNone-0] + _ = x[NmCheckpointCreateFlagsDestroyAll-1] + _ = x[NmCheckpointCreateFlagsDeleteNewConnections-2] + _ = x[NmCheckpointCreateFlagsDisconnectNewDevices-4] + _ = x[NmCheckpointCreateFlagsAllowOverlapping-8] +} + +const ( + _NmCheckpointCreateFlags_name_0 = "NmCheckpointCreateFlagsNoneNmCheckpointCreateFlagsDestroyAllNmCheckpointCreateFlagsDeleteNewConnections" + _NmCheckpointCreateFlags_name_1 = "NmCheckpointCreateFlagsDisconnectNewDevices" + _NmCheckpointCreateFlags_name_2 = "NmCheckpointCreateFlagsAllowOverlapping" +) + +var ( + _NmCheckpointCreateFlags_index_0 = [...]uint8{0, 27, 60, 103} +) + +func (i NmCheckpointCreateFlags) String() string { + switch { + case 0 <= i && i <= 2: + return _NmCheckpointCreateFlags_name_0[_NmCheckpointCreateFlags_index_0[i]:_NmCheckpointCreateFlags_index_0[i+1]] + case i == 4: + return _NmCheckpointCreateFlags_name_1 + case i == 8: + return _NmCheckpointCreateFlags_name_2 + default: + return "NmCheckpointCreateFlags(" + strconv.FormatInt(int64(i), 10) + ")" + } +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/nmconnectivity_string.go b/vendor/github.com/Wifx/gonetworkmanager/nmconnectivity_string.go new file mode 100644 index 000000000..cb8605bb1 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/nmconnectivity_string.go @@ -0,0 +1,27 @@ +// Code generated by "stringer -type=NmConnectivity"; DO NOT EDIT. + +package gonetworkmanager + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[NmConnectivityUnknown-0] + _ = x[NmConnectivityNone-1] + _ = x[NmConnectivityPortal-2] + _ = x[NmConnectivityLimited-3] + _ = x[NmConnectivityFull-4] +} + +const _NmConnectivity_name = "NmConnectivityUnknownNmConnectivityNoneNmConnectivityPortalNmConnectivityLimitedNmConnectivityFull" + +var _NmConnectivity_index = [...]uint8{0, 21, 39, 59, 80, 98} + +func (i NmConnectivity) String() string { + if i >= NmConnectivity(len(_NmConnectivity_index)-1) { + return "NmConnectivity(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _NmConnectivity_name[_NmConnectivity_index[i]:_NmConnectivity_index[i+1]] +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/nmdevicestate_string.go b/vendor/github.com/Wifx/gonetworkmanager/nmdevicestate_string.go new file mode 100644 index 000000000..1243ea74f --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/nmdevicestate_string.go @@ -0,0 +1,49 @@ +// Code generated by "stringer -type=NmDeviceState"; DO NOT EDIT. + +package gonetworkmanager + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[NmDeviceStateUnknown-0] + _ = x[NmDeviceStateUnmanaged-10] + _ = x[NmDeviceStateUnavailable-20] + _ = x[NmDeviceStateDisconnected-30] + _ = x[NmDeviceStatePrepare-40] + _ = x[NmDeviceStateConfig-50] + _ = x[NmDeviceStateNeedAuth-60] + _ = x[NmDeviceStateIpConfig-70] + _ = x[NmDeviceStateIpCheck-80] + _ = x[NmDeviceStateSecondaries-90] + _ = x[NmDeviceStateActivated-100] + _ = x[NmDeviceStateDeactivating-110] + _ = x[NmDeviceStateFailed-120] +} + +const _NmDeviceState_name = "NmDeviceStateUnknownNmDeviceStateUnmanagedNmDeviceStateUnavailableNmDeviceStateDisconnectedNmDeviceStatePrepareNmDeviceStateConfigNmDeviceStateNeedAuthNmDeviceStateIpConfigNmDeviceStateIpCheckNmDeviceStateSecondariesNmDeviceStateActivatedNmDeviceStateDeactivatingNmDeviceStateFailed" + +var _NmDeviceState_map = map[NmDeviceState]string{ + 0: _NmDeviceState_name[0:20], + 10: _NmDeviceState_name[20:42], + 20: _NmDeviceState_name[42:66], + 30: _NmDeviceState_name[66:91], + 40: _NmDeviceState_name[91:111], + 50: _NmDeviceState_name[111:130], + 60: _NmDeviceState_name[130:151], + 70: _NmDeviceState_name[151:172], + 80: _NmDeviceState_name[172:192], + 90: _NmDeviceState_name[192:216], + 100: _NmDeviceState_name[216:238], + 110: _NmDeviceState_name[238:263], + 120: _NmDeviceState_name[263:282], +} + +func (i NmDeviceState) String() string { + if str, ok := _NmDeviceState_map[i]; ok { + return str + } + return "NmDeviceState(" + strconv.FormatInt(int64(i), 10) + ")" +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/nmdevicetype_string.go b/vendor/github.com/Wifx/gonetworkmanager/nmdevicetype_string.go new file mode 100644 index 000000000..d5003b5f4 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/nmdevicetype_string.go @@ -0,0 +1,53 @@ +// Code generated by "stringer -type=NmDeviceType"; DO NOT EDIT. + +package gonetworkmanager + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[NmDeviceTypeUnknown-0] + _ = x[NmDeviceTypeGeneric-14] + _ = x[NmDeviceTypeEthernet-1] + _ = x[NmDeviceTypeWifi-2] + _ = x[NmDeviceTypeUnused1-3] + _ = x[NmDeviceTypeUnused2-4] + _ = x[NmDeviceTypeBt-5] + _ = x[NmDeviceTypeOlpcMesh-6] + _ = x[NmDeviceTypeWimax-7] + _ = x[NmDeviceTypeModem-8] + _ = x[NmDeviceTypeInfiniband-9] + _ = x[NmDeviceTypeBond-10] + _ = x[NmDeviceTypeVlan-11] + _ = x[NmDeviceTypeAdsl-12] + _ = x[NmDeviceTypeBridge-13] + _ = x[NmDeviceTypeTeam-15] + _ = x[NmDeviceTypeTun-16] + _ = x[NmDeviceTypeIpTunnel-17] + _ = x[NmDeviceTypeMacvlan-18] + _ = x[NmDeviceTypeVxlan-19] + _ = x[NmDeviceTypeVeth-20] + _ = x[NmDeviceTypeMacsec-21] + _ = x[NmDeviceTypeDummy-22] + _ = x[NmDeviceTypePpp-23] + _ = x[NmDeviceTypeOvsInterface-24] + _ = x[NmDeviceTypeOvsPort-25] + _ = x[NmDeviceTypeOvsBridge-26] + _ = x[NmDeviceTypeWpan-27] + _ = x[NmDeviceType6lowpan-28] + _ = x[NmDeviceTypeWireguard-29] + _ = x[NmDeviceTypeWifiP2p-30] +} + +const _NmDeviceType_name = "NmDeviceTypeUnknownNmDeviceTypeEthernetNmDeviceTypeWifiNmDeviceTypeUnused1NmDeviceTypeUnused2NmDeviceTypeBtNmDeviceTypeOlpcMeshNmDeviceTypeWimaxNmDeviceTypeModemNmDeviceTypeInfinibandNmDeviceTypeBondNmDeviceTypeVlanNmDeviceTypeAdslNmDeviceTypeBridgeNmDeviceTypeGenericNmDeviceTypeTeamNmDeviceTypeTunNmDeviceTypeIpTunnelNmDeviceTypeMacvlanNmDeviceTypeVxlanNmDeviceTypeVethNmDeviceTypeMacsecNmDeviceTypeDummyNmDeviceTypePppNmDeviceTypeOvsInterfaceNmDeviceTypeOvsPortNmDeviceTypeOvsBridgeNmDeviceTypeWpanNmDeviceType6lowpanNmDeviceTypeWireguardNmDeviceTypeWifiP2p" + +var _NmDeviceType_index = [...]uint16{0, 19, 39, 55, 74, 93, 107, 127, 144, 161, 183, 199, 215, 231, 249, 268, 284, 299, 319, 338, 355, 371, 389, 406, 421, 445, 464, 485, 501, 520, 541, 560} + +func (i NmDeviceType) String() string { + if i >= NmDeviceType(len(_NmDeviceType_index)-1) { + return "NmDeviceType(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _NmDeviceType_name[_NmDeviceType_index[i]:_NmDeviceType_index[i+1]] +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/nmmetered_string.go b/vendor/github.com/Wifx/gonetworkmanager/nmmetered_string.go new file mode 100644 index 000000000..0723c1351 --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/nmmetered_string.go @@ -0,0 +1,27 @@ +// Code generated by "stringer -type=NmMetered"; DO NOT EDIT. + +package gonetworkmanager + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[NmMeteredUnknown-0] + _ = x[NmMeteredYes-1] + _ = x[NmMeteredNo-2] + _ = x[NmMeteredGuessYes-3] + _ = x[NmMeteredGuessNo-4] +} + +const _NmMetered_name = "NmMeteredUnknownNmMeteredYesNmMeteredNoNmMeteredGuessYesNmMeteredGuessNo" + +var _NmMetered_index = [...]uint8{0, 16, 28, 39, 56, 72} + +func (i NmMetered) String() string { + if i >= NmMetered(len(_NmMetered_index)-1) { + return "NmMetered(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _NmMetered_name[_NmMetered_index[i]:_NmMetered_index[i+1]] +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/nmstate_string.go b/vendor/github.com/Wifx/gonetworkmanager/nmstate_string.go new file mode 100644 index 000000000..30dcaf49f --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/nmstate_string.go @@ -0,0 +1,53 @@ +// Code generated by "stringer -type=NmState"; DO NOT EDIT. + +package gonetworkmanager + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[NmStateUnknown-0] + _ = x[NmStateAsleep-10] + _ = x[NmStateDisconnected-20] + _ = x[NmStateDisconnecting-30] + _ = x[NmStateConnecting-40] + _ = x[NmStateConnectedLocal-50] + _ = x[NmStateConnectedSite-60] + _ = x[NmStateConnectedGlobal-70] +} + +const ( + _NmState_name_0 = "NmStateUnknown" + _NmState_name_1 = "NmStateAsleep" + _NmState_name_2 = "NmStateDisconnected" + _NmState_name_3 = "NmStateDisconnecting" + _NmState_name_4 = "NmStateConnecting" + _NmState_name_5 = "NmStateConnectedLocal" + _NmState_name_6 = "NmStateConnectedSite" + _NmState_name_7 = "NmStateConnectedGlobal" +) + +func (i NmState) String() string { + switch { + case i == 0: + return _NmState_name_0 + case i == 10: + return _NmState_name_1 + case i == 20: + return _NmState_name_2 + case i == 30: + return _NmState_name_3 + case i == 40: + return _NmState_name_4 + case i == 50: + return _NmState_name_5 + case i == 60: + return _NmState_name_6 + case i == 70: + return _NmState_name_7 + default: + return "NmState(" + strconv.FormatInt(int64(i), 10) + ")" + } +} diff --git a/vendor/github.com/Wifx/gonetworkmanager/utils.go b/vendor/github.com/Wifx/gonetworkmanager/utils.go new file mode 100644 index 000000000..1a2d3dc0b --- /dev/null +++ b/vendor/github.com/Wifx/gonetworkmanager/utils.go @@ -0,0 +1,269 @@ +package gonetworkmanager + +import ( + "encoding/binary" + "fmt" + "net" + + "github.com/godbus/dbus/v5" +) + +const ( + dbusMethodAddMatch = "org.freedesktop.DBus.AddMatch" +) + +type dbusBase struct { + conn *dbus.Conn + obj dbus.BusObject +} + +func (d *dbusBase) init(iface string, objectPath dbus.ObjectPath) error { + var err error + + d.conn, err = dbus.SystemBus() + if err != nil { + return err + } + + d.obj = d.conn.Object(iface, objectPath) + + return nil +} + +func (d *dbusBase) call(method string, args ...interface{}) error { + return d.obj.Call(method, 0, args...).Err +} + +func (d *dbusBase) callWithReturn(ret interface{}, method string, args ...interface{}) error { + return d.obj.Call(method, 0, args...).Store(ret) +} + +func (d *dbusBase) callWithReturn2(ret1 interface{}, ret2 interface{}, method string, args ...interface{}) error { + return d.obj.Call(method, 0, args...).Store(ret1, ret2) +} + +func (d *dbusBase) subscribe(iface, member string) { + rule := fmt.Sprintf("type='signal',interface='%s',path='%s',member='%s'", + iface, d.obj.Path(), NetworkManagerInterface) + d.conn.BusObject().Call(dbusMethodAddMatch, 0, rule) +} + +func (d *dbusBase) subscribeNamespace(namespace string) { + rule := fmt.Sprintf("type='signal',path_namespace='%s'", namespace) + d.conn.BusObject().Call(dbusMethodAddMatch, 0, rule) +} + +func (d *dbusBase) getProperty(iface string) (interface{}, error) { + variant, err := d.obj.GetProperty(iface) + return variant.Value(), err +} + +func (d *dbusBase) setProperty(iface string, value interface{}) (error) { + err := d.obj.SetProperty(iface, dbus.MakeVariant(value)) + return err +} + +func (d *dbusBase) getObjectProperty(iface string) (value dbus.ObjectPath, err error) { + prop, err := d.getProperty(iface) + if err != nil { + return + } + value, ok := prop.(dbus.ObjectPath) + if !ok { + err = makeErrVariantType(iface) + return + } + return +} + +func (d *dbusBase) getSliceObjectProperty(iface string) (value []dbus.ObjectPath, err error) { + prop, err := d.getProperty(iface) + if err != nil { + return + } + value, ok := prop.([]dbus.ObjectPath) + if !ok { + err = makeErrVariantType(iface) + return + } + return +} + +func (d *dbusBase) getBoolProperty(iface string) (value bool, err error) { + prop, err := d.getProperty(iface) + if err != nil { + return + } + value, ok := prop.(bool) + if !ok { + err = makeErrVariantType(iface) + return + } + return +} + +func (d *dbusBase) getStringProperty(iface string) (value string, err error) { + prop, err := d.getProperty(iface) + if err != nil { + return + } + value, ok := prop.(string) + if !ok { + err = makeErrVariantType(iface) + return + } + return +} + +func (d *dbusBase) getSliceStringProperty(iface string) (value []string, err error) { + prop, err := d.getProperty(iface) + if err != nil { + return + } + value, ok := prop.([]string) + if !ok { + err = makeErrVariantType(iface) + return + } + return +} + +func (d *dbusBase) getSliceSliceByteProperty(iface string) (value [][]byte, err error) { + prop, err := d.getProperty(iface) + if err != nil { + return + } + value, ok := prop.([][]byte) + if !ok { + err = makeErrVariantType(iface) + return + } + return +} + +func (d *dbusBase) getMapStringVariantProperty(iface string) (value map[string]dbus.Variant, err error) { + prop, err := d.getProperty(iface) + if err != nil { + return + } + value, ok := prop.(map[string]dbus.Variant) + if !ok { + err = makeErrVariantType(iface) + return + } + return +} + +func (d *dbusBase) getUint8Property(iface string) (value uint8, err error) { + prop, err := d.getProperty(iface) + if err != nil { + return + } + value, ok := prop.(uint8) + if !ok { + err = makeErrVariantType(iface) + return + } + return +} + +func (d *dbusBase) getUint32Property(iface string) (value uint32, err error) { + prop, err := d.getProperty(iface) + if err != nil { + return + } + value, ok := prop.(uint32) + if !ok { + err = makeErrVariantType(iface) + return + } + return +} + +func (d *dbusBase) getInt64Property(iface string) (value int64, err error) { + prop, err := d.getProperty(iface) + if err != nil { + return + } + value, ok := prop.(int64) + if !ok { + err = makeErrVariantType(iface) + return + } + return +} + +func (d *dbusBase) getUint64Property(iface string) (value uint64, err error) { + prop, err := d.getProperty(iface) + if err != nil { + return + } + value, ok := prop.(uint64) + if !ok { + err = makeErrVariantType(iface) + return + } + return +} + +func (d *dbusBase) getSliceUint32Property(iface string) (value []uint32, err error) { + prop, err := d.getProperty(iface) + if err != nil { + return + } + value, ok := prop.([]uint32) + if !ok { + err = makeErrVariantType(iface) + return + } + return +} + +func (d *dbusBase) getSliceSliceUint32Property(iface string) (value [][]uint32, err error) { + prop, err := d.getProperty(iface) + if err != nil { + return + } + value, ok := prop.([][]uint32) + if !ok { + err = makeErrVariantType(iface) + return + } + return +} + +func (d *dbusBase) getSliceMapStringVariantProperty(iface string) (value []map[string]dbus.Variant, err error) { + prop, err := d.getProperty(iface) + if err != nil { + return + } + value, ok := prop.([]map[string]dbus.Variant) + if !ok { + err = makeErrVariantType(iface) + return + } + return +} + +func (d *dbusBase) getSliceByteProperty(iface string) (value []byte, err error) { + prop, err := d.getProperty(iface) + if err != nil { + return + } + value, ok := prop.([]byte) + if !ok { + err = makeErrVariantType(iface) + return + } + return +} + +func makeErrVariantType(iface string) error { + return fmt.Errorf("unexpected variant type for '%s'", iface) +} + +func ip4ToString(ip uint32) string { + bs := []byte{0, 0, 0, 0} + binary.LittleEndian.PutUint32(bs, ip) + return net.IP(bs).String() +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 3e804ebc5..863be92b4 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -12,6 +12,9 @@ cloud.google.com/go/internal/version cloud.google.com/go/storage # github.com/BurntSushi/toml v0.3.1 github.com/BurntSushi/toml +# github.com/Wifx/gonetworkmanager v0.3.0 +## explicit +github.com/Wifx/gonetworkmanager # github.com/aws/aws-sdk-go v1.30.28 ## explicit github.com/aws/aws-sdk-go/aws