Compare commits
59 commits
v0.2.0
...
debian/sid
Author | SHA1 | Date | |
---|---|---|---|
|
4bf9baa1ae | ||
|
4f3d9f75bb | ||
|
2bcf3024d7 | ||
|
7c88972fa9 | ||
|
0c7d517e5c | ||
|
b7689fcc97 | ||
|
bad9eff45e | ||
|
5cd4632c13 | ||
|
8d3aeb2b07 | ||
|
6d60429bb2 | ||
|
0025aa8f8a | ||
|
f7fd789c27 | ||
|
58824d8cc3 | ||
|
8fe336a60b | ||
|
4d20decb7a | ||
|
24634585a3 | ||
|
1efc60bbcd | ||
|
377c54056d | ||
|
4c34afc9ca | ||
|
b7605d46fa | ||
|
e65e7f4ca9 | ||
|
3eae45e0c6 | ||
|
d1c9063d26 | ||
|
b4b8ef48ed | ||
|
ec47b1991d | ||
|
f53c0a6412 | ||
|
24266a326a | ||
|
e0c2698607 | ||
|
c9388ff6e6 | ||
|
4b20a2d51a | ||
|
a1ddfeaa9c | ||
|
19203e6d79 | ||
|
0080a5c9db | ||
|
bfc40dcb21 | ||
|
ba0310894b | ||
|
3ba9bbd706 | ||
|
44424b8ca7 | ||
|
6582e83911 | ||
|
fa58062497 | ||
|
234b0e848e | ||
|
fd171d0928 | ||
|
771559372e | ||
|
085876362a | ||
|
e67f06a4ab | ||
|
97d8aa8b42 | ||
|
594bfca331 | ||
|
e6d07eb88c | ||
|
37696d341d | ||
|
10daa7f841 | ||
|
41ad7838fe | ||
|
bccd98f07a | ||
|
0369d842fa | ||
|
ff992cedc5 | ||
|
aeb83621f6 | ||
|
91c676f015 | ||
|
dbb5cee305 | ||
|
b933f11d15 | ||
|
41fe7adda8 | ||
|
ac6a5d93da |
46 changed files with 1638 additions and 306 deletions
26
.github/workflows/go.yml
vendored
Normal file
26
.github/workflows/go.yml
vendored
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
name: Go
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Set up Go 1.13
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: 1.13
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: go build -v examples/devices/devices.go
|
25
.gitignore
vendored
Normal file
25
.gitignore
vendored
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# If you prefer the allow list template instead of the deny list, see community template:
|
||||||
|
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
||||||
|
#
|
||||||
|
# Binaries for programs and plugins
|
||||||
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Test binary, built with `go test -c`
|
||||||
|
*.test
|
||||||
|
|
||||||
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
|
*.out
|
||||||
|
|
||||||
|
# Dependency directories (remove the comment below to include it)
|
||||||
|
# vendor/
|
||||||
|
|
||||||
|
# Go workspace file
|
||||||
|
go.work
|
||||||
|
|
||||||
|
.idea/
|
||||||
|
/.pc/
|
||||||
|
/_build/
|
67
.gitlab-ci.yml
Normal file
67
.gitlab-ci.yml
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
# Is performed before the scripts in the stages step
|
||||||
|
before_script:
|
||||||
|
- source /etc/profile
|
||||||
|
|
||||||
|
# Defines stages which are to be executed
|
||||||
|
stages:
|
||||||
|
- build
|
||||||
|
- upload
|
||||||
|
- release
|
||||||
|
|
||||||
|
.setup_script: &setup_scripts
|
||||||
|
- apt-get update
|
||||||
|
- apt-get -y build-dep .
|
||||||
|
- apt-get -y install dpkg-dev
|
||||||
|
|
||||||
|
.compile: &compile
|
||||||
|
stage: compile
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
script:
|
||||||
|
- *setup_scripts
|
||||||
|
- dpkg-buildpackage -b
|
||||||
|
- mkdir -p ./build/{release,debug}
|
||||||
|
- find ../ -name "*.deb" -not -name "*dbgsym*" -exec mv {} ./build/release/ \;
|
||||||
|
- find ../ -name "*dbgsym*.deb" -exec mv {} ./build/debug/ \;
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- build/release/*
|
||||||
|
- build/debug/*
|
||||||
|
untracked: true
|
||||||
|
|
||||||
|
build:
|
||||||
|
<<: *compile
|
||||||
|
stage: build
|
||||||
|
|
||||||
|
upload:
|
||||||
|
stage: upload
|
||||||
|
dependencies:
|
||||||
|
- build
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
script:
|
||||||
|
- find ./build/release -name "*.deb"
|
||||||
|
- debs=( $( find ./build/release -name "*.deb" ) )
|
||||||
|
- assets=""
|
||||||
|
- for d in ${debs[@]};do
|
||||||
|
- file=$( basename ${d} )
|
||||||
|
- url="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${CI_COMMIT_TAG}/${file}"
|
||||||
|
- assets="${assets} --assets-link {\"name\":\"${file}\",\"url\":\"${url}\",\"link_type\":\"other\"} "
|
||||||
|
- "curl --header \"JOB-TOKEN: $CI_JOB_TOKEN\" --upload-file \"${d}\" \"${url}\""
|
||||||
|
- done
|
||||||
|
- echo "ASSETS_ARG=${assets}" >> assets.env
|
||||||
|
artifacts:
|
||||||
|
reports:
|
||||||
|
dotenv: assets.env
|
||||||
|
|
||||||
|
release:
|
||||||
|
stage: release
|
||||||
|
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
script:
|
||||||
|
- echo "making release!"
|
||||||
|
- echo ${ASSETS_ARG}
|
||||||
|
- release-cli create --name "Release ${CI_COMMIT_TAG}" --tag-name "${CI_COMMIT_TAG}" ${ASSETS_ARG}
|
||||||
|
tags:
|
||||||
|
- x86_64
|
|
@ -25,38 +25,39 @@ const (
|
||||||
type AccessPoint interface {
|
type AccessPoint interface {
|
||||||
GetPath() dbus.ObjectPath
|
GetPath() dbus.ObjectPath
|
||||||
|
|
||||||
// GetFlags gets flags describing the capabilities of the access point.
|
// GetPropertyFlags gets flags describing the capabilities of the access point.
|
||||||
GetPropertyFlags() (uint32, error)
|
GetPropertyFlags() (uint32, error)
|
||||||
|
|
||||||
// GetWPAFlags gets flags describing the access point's capabilities
|
// GetPropertyWPAFlags gets flags describing the access point's capabilities
|
||||||
// according to WPA (Wifi Protected Access).
|
// according to WPA (Wi-Fi Protected Access).
|
||||||
GetPropertyWPAFlags() (uint32, error)
|
GetPropertyWPAFlags() (uint32, error)
|
||||||
|
|
||||||
// GetRSNFlags gets flags describing the access point's capabilities
|
// GetPropertyRSNFlags gets flags describing the access point's capabilities
|
||||||
// according to the RSN (Robust Secure Network) protocol.
|
// according to the RSN (Robust Secure Network) protocol.
|
||||||
GetPropertyRSNFlags() (uint32, error)
|
GetPropertyRSNFlags() (uint32, error)
|
||||||
|
|
||||||
// GetSSID returns the Service Set Identifier identifying the access point.
|
// GetPropertySSID returns the Service Set Identifier identifying the access point.
|
||||||
GetPropertySSID() (string, error)
|
GetPropertySSID() (string, error)
|
||||||
|
|
||||||
// GetFrequency gets the radio channel frequency in use by the access point,
|
// GetPropertyFrequency gets the radio channel frequency in use by the access point, in MHz.
|
||||||
// in MHz.
|
|
||||||
GetPropertyFrequency() (uint32, error)
|
GetPropertyFrequency() (uint32, error)
|
||||||
|
|
||||||
// GetHWAddress gets the hardware address (BSSID) of the access point.
|
// GetPropertyHWAddress gets the hardware address (BSSID) of the access point.
|
||||||
GetPropertyHWAddress() (string, error)
|
GetPropertyHWAddress() (string, error)
|
||||||
|
|
||||||
// GetMode describes the operating mode of the access point.
|
// GetPropertyMode describes the operating mode of the access point.
|
||||||
GetPropertyMode() (Nm80211Mode, error)
|
GetPropertyMode() (Nm80211Mode, error)
|
||||||
|
|
||||||
// GetMaxBitrate gets the maximum bitrate this access point is capable of, in
|
// GetPropertyMaxBitrate gets the maximum bitrate this access point is capable of, in kilobits/second (Kb/s).
|
||||||
// kilobits/second (Kb/s).
|
|
||||||
GetPropertyMaxBitrate() (uint32, error)
|
GetPropertyMaxBitrate() (uint32, error)
|
||||||
|
|
||||||
// GetStrength gets the current signal quality of the access point, in
|
// GetPropertyStrength gets the current signal quality of the access point, in percent.
|
||||||
// percent.
|
|
||||||
GetPropertyStrength() (uint8, error)
|
GetPropertyStrength() (uint8, error)
|
||||||
|
|
||||||
|
// GetPropertyLastSeen The timestamp (in CLOCK_BOOTTIME seconds) for the last time the access point was found in scan results.
|
||||||
|
// A value of -1 means the access point has never been found in scan results.
|
||||||
|
GetPropertyLastSeen() (int32, error)
|
||||||
|
|
||||||
MarshalJSON() ([]byte, error)
|
MarshalJSON() ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,6 +118,10 @@ func (a *accessPoint) GetPropertyStrength() (uint8, error) {
|
||||||
return a.getUint8Property(AccessPointPropertyStrength)
|
return a.getUint8Property(AccessPointPropertyStrength)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *accessPoint) GetPropertyLastSeen() (int32, error) {
|
||||||
|
return a.getInt32Property(AccessPointPropertyLastSeen)
|
||||||
|
}
|
||||||
|
|
||||||
func (a *accessPoint) MarshalJSON() ([]byte, error) {
|
func (a *accessPoint) MarshalJSON() ([]byte, error) {
|
||||||
Flags, err := a.GetPropertyFlags()
|
Flags, err := a.GetPropertyFlags()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -154,6 +159,10 @@ func (a *accessPoint) MarshalJSON() ([]byte, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
LastSeen, err := a.GetPropertyLastSeen()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return json.Marshal(map[string]interface{}{
|
return json.Marshal(map[string]interface{}{
|
||||||
"Flags": Flags,
|
"Flags": Flags,
|
||||||
|
@ -165,5 +174,6 @@ func (a *accessPoint) MarshalJSON() ([]byte, error) {
|
||||||
"Mode": Mode.String(),
|
"Mode": Mode.String(),
|
||||||
"MaxBitrate": MaxBitrate,
|
"MaxBitrate": MaxBitrate,
|
||||||
"Strength": Strength,
|
"Strength": Strength,
|
||||||
|
"LastSeen": LastSeen,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package gonetworkmanager
|
package gonetworkmanager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/godbus/dbus/v5"
|
"github.com/godbus/dbus/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,58 +26,64 @@ const (
|
||||||
ActiveConnectionPropertyDhcp6Config = ActiveConnectionInterface + ".Dhcp6Config" // readable o
|
ActiveConnectionPropertyDhcp6Config = ActiveConnectionInterface + ".Dhcp6Config" // readable o
|
||||||
ActiveConnectionPropertyVpn = ActiveConnectionInterface + ".Vpn" // readable b
|
ActiveConnectionPropertyVpn = ActiveConnectionInterface + ".Vpn" // readable b
|
||||||
ActiveConnectionPropertyMaster = ActiveConnectionInterface + ".Master" // readable o
|
ActiveConnectionPropertyMaster = ActiveConnectionInterface + ".Master" // readable o
|
||||||
|
|
||||||
|
/* Signals */
|
||||||
|
ActiveConnectionSignalStateChanged = "StateChanged" // u state, u reason
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ActiveConnection interface {
|
type ActiveConnection interface {
|
||||||
GetPath() dbus.ObjectPath
|
GetPath() dbus.ObjectPath
|
||||||
|
|
||||||
// GetConnectionSettings gets connection object of the connection.
|
// GetPropertyConnection gets connection object of the connection.
|
||||||
GetPropertyConnection() (Connection, error)
|
GetPropertyConnection() (Connection, error)
|
||||||
|
|
||||||
// GetSpecificObject gets a specific object associated with the active connection.
|
// GetPropertySpecificObject gets a specific object associated with the active connection.
|
||||||
GetPropertySpecificObject() (AccessPoint, error)
|
GetPropertySpecificObject() (AccessPoint, error)
|
||||||
|
|
||||||
// GetID gets the ID of the connection.
|
// GetPropertyID gets the ID of the connection.
|
||||||
GetPropertyID() (string, error)
|
GetPropertyID() (string, error)
|
||||||
|
|
||||||
// GetUUID gets the UUID of the connection.
|
// GetPropertyUUID gets the UUID of the connection.
|
||||||
GetPropertyUUID() (string, error)
|
GetPropertyUUID() (string, error)
|
||||||
|
|
||||||
// GetType gets the type of the connection.
|
// GetPropertyType gets the type of the connection.
|
||||||
GetPropertyType() (string, error)
|
GetPropertyType() (string, error)
|
||||||
|
|
||||||
// GetDevices gets array of device objects which are part of this active connection.
|
// GetPropertyDevices gets array of device objects which are part of this active connection.
|
||||||
GetPropertyDevices() ([]Device, error)
|
GetPropertyDevices() ([]Device, error)
|
||||||
|
|
||||||
// GetState gets the state of the connection.
|
// GetPropertyState gets the state of the connection.
|
||||||
GetPropertyState() (NmActiveConnectionState, error)
|
GetPropertyState() (NmActiveConnectionState, error)
|
||||||
|
|
||||||
// GetStateFlags gets the state flags of the connection.
|
// GetPropertyStateFlags gets the state flags of the connection.
|
||||||
GetPropertyStateFlags() (uint32, error)
|
GetPropertyStateFlags() (uint32, error)
|
||||||
|
|
||||||
// GetDefault gets the default IPv4 flag of the connection.
|
// GetPropertyDefault gets the default IPv4 flag of the connection.
|
||||||
GetPropertyDefault() (bool, error)
|
GetPropertyDefault() (bool, error)
|
||||||
|
|
||||||
// GetIP4Config gets the IP4Config of the connection.
|
// GetPropertyIP4Config gets the IP4Config of the connection.
|
||||||
GetPropertyIP4Config() (IP4Config, error)
|
GetPropertyIP4Config() (IP4Config, error)
|
||||||
|
|
||||||
// GetDHCP4Config gets the DHCP6Config of the connection.
|
// GetPropertyDHCP4Config gets the DHCP6Config of the connection.
|
||||||
GetPropertyDHCP4Config() (DHCP4Config, error)
|
GetPropertyDHCP4Config() (DHCP4Config, error)
|
||||||
|
|
||||||
// GetDefault gets the default IPv6 flag of the connection.
|
// GetPropertyDefault6 gets the default IPv6 flag of the connection.
|
||||||
GetPropertyDefault6() (bool, error)
|
GetPropertyDefault6() (bool, error)
|
||||||
|
|
||||||
// GetIP6Config gets the IP6Config of the connection.
|
// GetPropertyIP6Config gets the IP6Config of the connection.
|
||||||
GetPropertyIP6Config() (IP6Config, error)
|
GetPropertyIP6Config() (IP6Config, error)
|
||||||
|
|
||||||
// GetDHCP6Config gets the DHCP4Config of the connection.
|
// GetPropertyDHCP6Config gets the DHCP4Config of the connection.
|
||||||
GetPropertyDHCP6Config() (DHCP6Config, error)
|
GetPropertyDHCP6Config() (DHCP6Config, error)
|
||||||
|
|
||||||
// GetVPN gets the VPN flag of the connection.
|
// GetPropertyVPN gets the VPN flag of the connection.
|
||||||
GetPropertyVPN() (bool, error)
|
GetPropertyVPN() (bool, error)
|
||||||
|
|
||||||
// GetMaster gets the master device of the connection.
|
// GetPropertyMaster gets the master device of the connection.
|
||||||
GetPropertyMaster() (Device, error)
|
GetPropertyMaster() (Device, error)
|
||||||
|
|
||||||
|
SubscribeState(receiver chan StateChange, exit chan struct{}) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewActiveConnection(objectPath dbus.ObjectPath) (ActiveConnection, error) {
|
func NewActiveConnection(objectPath dbus.ObjectPath) (ActiveConnection, error) {
|
||||||
|
@ -211,3 +219,56 @@ func (a *activeConnection) GetPropertyMaster() (Device, error) {
|
||||||
}
|
}
|
||||||
return DeviceFactory(path)
|
return DeviceFactory(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type StateChange struct {
|
||||||
|
Path dbus.ObjectPath
|
||||||
|
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.Name != ActiveConnectionInterface+"."+ActiveConnectionSignalStateChanged {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
stateChange := StateChange{
|
||||||
|
Path: signal.Path,
|
||||||
|
State: NmActiveConnectionState(signal.Body[0].(uint32)),
|
||||||
|
Reason: NmActiveConnectionStateReason(signal.Body[1].(uint32)),
|
||||||
|
}
|
||||||
|
|
||||||
|
receiver <- stateChange
|
||||||
|
|
||||||
|
case <-exit:
|
||||||
|
a.conn.RemoveSignal(channel)
|
||||||
|
close(channel)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
85
CHANGELOG.md
Normal file
85
CHANGELOG.md
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project since will be documented in this file.
|
||||||
|
|
||||||
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [2.1.0] - 2023-01-19
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Add device auto-connect setter
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Connection settings route and address data types
|
||||||
|
|
||||||
|
## [2.0.0] - 2022-11-22
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
- Update go-dbus to v5.1.0
|
||||||
|
- **BREAKING CHANGE** : Generic recursive settings map dbus variants decoding
|
||||||
|
|
||||||
|
## [0.5.0] - 2022-11-22
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Godoc standard comment prefix
|
||||||
|
- DnsManager
|
||||||
|
- Device: GetIp4Connectivity
|
||||||
|
- Constants for Nm80211APSec
|
||||||
|
- Add gitignore
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- CheckpointCreate: fix devicePaths variable scope
|
||||||
|
|
||||||
|
## [0.4.0] - 2022-01-17
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- AccessPoint: add LastSeen property
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Examples: move examples to their own subfolders
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- DeviceWireless: remove duplicated fields
|
||||||
|
- PrimaryConnection: use ActiveConnection type
|
||||||
|
- SubscribeState: add the path to the recieved chan type, catch connect event for ActiveConnection
|
||||||
|
|
||||||
|
## [0.3.0] - 2020-03-26
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- SetPropertyManaged (@joseffilzmaier)
|
||||||
|
- GetConnectionByUUID (@paulburlumi)
|
||||||
|
- VpnConnection
|
||||||
|
- ActiveConnectionSignalStateChanged
|
||||||
|
- CheckpointRollback
|
||||||
|
- SetPropertyWirelessEnabled (@Raqbit)
|
||||||
|
- Settings.ReloadConnections (@appnostic-io)
|
||||||
|
|
||||||
|
Static connection example (@everactivemilligan)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- GetPropertyRouteData panic (@zhengdelun)
|
||||||
|
|
||||||
|
## [0.2.0] - 2020-03-06
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- added missing flag for Reload
|
||||||
|
- added parameter specific_object for AddAndActivateConnection
|
||||||
|
- Fix CheckpointCreateand GetPropertyCheckpoints
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Add property setter helper
|
||||||
|
- Add Device.SetPropertyRefreshRateMs
|
||||||
|
- Add Device.Reapply
|
|
@ -18,13 +18,13 @@ const (
|
||||||
type Checkpoint interface {
|
type Checkpoint interface {
|
||||||
GetPath() dbus.ObjectPath
|
GetPath() dbus.ObjectPath
|
||||||
|
|
||||||
// Array of object paths for devices which are part of this checkpoint.
|
// GetPropertyDevices Array of object paths for devices which are part of this checkpoint.
|
||||||
GetPropertyDevices() ([]Device, error)
|
GetPropertyDevices() ([]Device, error)
|
||||||
|
|
||||||
// The timestamp (in CLOCK_BOOTTIME milliseconds) of checkpoint creation.
|
// GetPropertyCreated The timestamp (in CLOCK_BOOTTIME milliseconds) of checkpoint creation.
|
||||||
GetPropertyCreated() (int64, error)
|
GetPropertyCreated() (int64, error)
|
||||||
|
|
||||||
// Timeout in seconds for automatic rollback, or zero.
|
// GetPropertyRollbackTimeout Timeout in seconds for automatic rollback, or zero.
|
||||||
GetPropertyRollbackTimeout() (uint32, error)
|
GetPropertyRollbackTimeout() (uint32, error)
|
||||||
|
|
||||||
MarshalJSON() ([]byte, error)
|
MarshalJSON() ([]byte, error)
|
||||||
|
|
|
@ -2,7 +2,6 @@ package gonetworkmanager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/godbus/dbus/v5"
|
"github.com/godbus/dbus/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,7 +33,7 @@ type Connection interface {
|
||||||
// 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 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(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 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
|
UpdateUnsaved(settings ConnectionSettings) error
|
||||||
|
|
||||||
// Delete the connection.
|
// Delete the connection.
|
||||||
|
@ -46,25 +45,25 @@ type Connection interface {
|
||||||
// separately using the GetSecrets() method.
|
// separately using the GetSecrets() method.
|
||||||
GetSettings() (ConnectionSettings, error)
|
GetSettings() (ConnectionSettings, error)
|
||||||
|
|
||||||
// Get the secrets belonging to this network configuration. Only secrets from
|
// GetSecrets Get the secrets belonging to this network configuration. Only secrets from
|
||||||
// persistent storage or a Secret Agent running in the requestor's session
|
// 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
|
// will be returned. The user will never be prompted for secrets as a result
|
||||||
// of this request.
|
// of this request.
|
||||||
GetSecrets(settingName string) (ConnectionSettings, error)
|
GetSecrets(settingName string) (ConnectionSettings, error)
|
||||||
|
|
||||||
// Clear the secrets belonging to this network connection profile.
|
// ClearSecrets Clear the secrets belonging to this network connection profile.
|
||||||
ClearSecrets() error
|
ClearSecrets() error
|
||||||
|
|
||||||
// Saves a "dirty" connection (that had previously been updated with UpdateUnsaved) to persistent storage.
|
// Save a "dirty" connection (that had previously been updated with UpdateUnsaved) to persistent storage.
|
||||||
Save() error
|
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 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)
|
GetPropertyUnsaved() (bool, error)
|
||||||
|
|
||||||
// Additional flags of the connection profile.
|
// GetPropertyFlags Additional flags of the connection profile.
|
||||||
GetPropertyFlags() (uint32, error)
|
GetPropertyFlags() (uint32, error)
|
||||||
|
|
||||||
// File that stores the connection in case the connection is file-backed.
|
// GetPropertyFilename File that stores the connection in case the connection is file-backed.
|
||||||
GetPropertyFilename() (string, error)
|
GetPropertyFilename() (string, error)
|
||||||
|
|
||||||
MarshalJSON() ([]byte, error)
|
MarshalJSON() ([]byte, error)
|
||||||
|
@ -97,44 +96,66 @@ func (c *connection) Delete() error {
|
||||||
|
|
||||||
func (c *connection) GetSettings() (ConnectionSettings, error) {
|
func (c *connection) GetSettings() (ConnectionSettings, error) {
|
||||||
var settings map[string]map[string]dbus.Variant
|
var settings map[string]map[string]dbus.Variant
|
||||||
err := c.callWithReturn(&settings, ConnectionGetSettings)
|
|
||||||
|
|
||||||
if err != nil {
|
if err := c.callWithReturn(&settings, ConnectionGetSettings); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
rv := make(ConnectionSettings)
|
return decodeSettings(settings), nil
|
||||||
|
|
||||||
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) {
|
func (c *connection) GetSecrets(settingName string) (ConnectionSettings, error) {
|
||||||
var settings map[string]map[string]dbus.Variant
|
var settings map[string]map[string]dbus.Variant
|
||||||
err := c.callWithReturn(&settings, ConnectionGetSecrets, settingName)
|
|
||||||
|
|
||||||
if err != nil {
|
if err := c.callWithReturn(&settings, ConnectionGetSecrets, settingName); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
rv := make(ConnectionSettings)
|
return decodeSettings(settings), nil
|
||||||
|
}
|
||||||
|
|
||||||
for k1, v1 := range settings {
|
func decodeSettings(input map[string]map[string]dbus.Variant) (settings ConnectionSettings) {
|
||||||
rv[k1] = make(map[string]interface{})
|
valueMap := ConnectionSettings{}
|
||||||
|
for key, data := range input {
|
||||||
|
valueMap[key] = decode(data).(map[string]interface{})
|
||||||
|
}
|
||||||
|
return valueMap
|
||||||
|
}
|
||||||
|
|
||||||
for k2, v2 := range v1 {
|
func decode(input interface{}) (value interface{}) {
|
||||||
rv[k1][k2] = v2.Value()
|
if variant, isVariant := input.(dbus.Variant); isVariant {
|
||||||
|
return decode(variant.Value())
|
||||||
|
} else if inputMap, isMap := input.(map[string]dbus.Variant); isMap {
|
||||||
|
return decodeMap(inputMap)
|
||||||
|
} else if inputArray, isArray := input.([]dbus.Variant); isArray {
|
||||||
|
return decodeArray(inputArray)
|
||||||
|
} else if inputArray, isArray := input.([]map[string]dbus.Variant); isArray {
|
||||||
|
return decodeMapArray(inputArray)
|
||||||
|
} else {
|
||||||
|
return input
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv, nil
|
func decodeArray(input []dbus.Variant) (value []interface{}) {
|
||||||
|
for _, data := range input {
|
||||||
|
value = append(value, decode(data))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeMapArray(input []map[string]dbus.Variant) (value []map[string]interface{}) {
|
||||||
|
for _, data := range input {
|
||||||
|
value = append(value, decodeMap(data))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeMap(input map[string]dbus.Variant) (value map[string]interface{}) {
|
||||||
|
value = map[string]interface{}{}
|
||||||
|
for key, data := range input {
|
||||||
|
value[key] = decode(data)
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *connection) ClearSecrets() error {
|
func (c *connection) ClearSecrets() error {
|
||||||
|
|
173
Connection_test.go
Normal file
173
Connection_test.go
Normal file
|
@ -0,0 +1,173 @@
|
||||||
|
package gonetworkmanager
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/godbus/dbus/v5"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDecodeSettings(t *testing.T) {
|
||||||
|
settings := map[string]map[string]dbus.Variant{
|
||||||
|
"ipv4": {
|
||||||
|
"address-data": dbus.MakeVariant([]map[string]dbus.Variant{
|
||||||
|
{
|
||||||
|
"address": dbus.MakeVariant("192.168.1.156"),
|
||||||
|
"prefix": dbus.MakeVariant(24),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
"dns-search": dbus.MakeVariant([]string{}),
|
||||||
|
"method": dbus.MakeVariant("manual"),
|
||||||
|
"route-data": dbus.MakeVariant([]map[string]dbus.Variant{}),
|
||||||
|
"routes": dbus.MakeVariant([][]uint32{}),
|
||||||
|
"addresses": dbus.MakeVariant([][]uint32{
|
||||||
|
{
|
||||||
|
2617354432,
|
||||||
|
24,
|
||||||
|
16885952,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
"gateway": dbus.MakeVariant("192.168.1.1"),
|
||||||
|
"route-metric": dbus.MakeVariant(100),
|
||||||
|
"dhcp-timeout": dbus.MakeVariant(45),
|
||||||
|
},
|
||||||
|
"ipv6": {
|
||||||
|
"addr-gen-mode": dbus.MakeVariant(3),
|
||||||
|
"address-data": dbus.MakeVariant([]map[string]dbus.Variant{}),
|
||||||
|
"routes": dbus.MakeVariant([][]interface{}{}),
|
||||||
|
"dns-search": dbus.MakeVariant([]string{}),
|
||||||
|
"method": dbus.MakeVariant("auto"),
|
||||||
|
"route-data": dbus.MakeVariant([]map[string]dbus.Variant{}),
|
||||||
|
"dhcp-timeout": dbus.MakeVariant(45),
|
||||||
|
"route-metric": dbus.MakeVariant(100),
|
||||||
|
"addresses": dbus.MakeVariant([][]interface{}{}),
|
||||||
|
},
|
||||||
|
"proxy": {},
|
||||||
|
"connection": {
|
||||||
|
"uuid": dbus.MakeVariant("390e5c2b-7312-415e-80e6-7b94a5c24fc3"),
|
||||||
|
"autoconnect-priority": dbus.MakeVariant(1),
|
||||||
|
"autoconnect-retries": dbus.MakeVariant(0),
|
||||||
|
"id": dbus.MakeVariant("main"),
|
||||||
|
"interface-name": dbus.MakeVariant("eth0"),
|
||||||
|
"permissions": dbus.MakeVariant([]string{}),
|
||||||
|
"timestamp": dbus.MakeVariant(1669049774),
|
||||||
|
"type": dbus.MakeVariant("802-3-ethernet"),
|
||||||
|
},
|
||||||
|
"802-3-ethernet": {
|
||||||
|
"auto-negotiate": dbus.MakeVariant(false),
|
||||||
|
"mac-address-blacklist": dbus.MakeVariant([]string{}),
|
||||||
|
"s390-options": dbus.MakeVariant(map[string]string{}),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
result := decodeSettings(settings)
|
||||||
|
|
||||||
|
expected := ConnectionSettings{
|
||||||
|
"ipv4": {
|
||||||
|
"address-data": []map[string]interface{}{
|
||||||
|
{
|
||||||
|
"address": "192.168.1.156",
|
||||||
|
"prefix": 24,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"dns-search": []string{},
|
||||||
|
"method": "manual",
|
||||||
|
"route-data": []map[string]interface{}(nil),
|
||||||
|
"routes": [][]uint32{},
|
||||||
|
"addresses": [][]uint32{
|
||||||
|
{
|
||||||
|
2617354432,
|
||||||
|
24,
|
||||||
|
16885952,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"gateway": "192.168.1.1",
|
||||||
|
"route-metric": 100,
|
||||||
|
"dhcp-timeout": 45,
|
||||||
|
},
|
||||||
|
"ipv6": {
|
||||||
|
"addr-gen-mode": 3,
|
||||||
|
"address-data": []map[string]interface{}(nil),
|
||||||
|
"routes": [][]interface{}{},
|
||||||
|
"dns-search": []string{},
|
||||||
|
"method": "auto",
|
||||||
|
"route-data": []map[string]interface{}(nil),
|
||||||
|
"dhcp-timeout": 45,
|
||||||
|
"route-metric": 100,
|
||||||
|
"addresses": [][]interface{}{},
|
||||||
|
},
|
||||||
|
"proxy": {},
|
||||||
|
"connection": {
|
||||||
|
"uuid": "390e5c2b-7312-415e-80e6-7b94a5c24fc3",
|
||||||
|
"autoconnect-priority": 1,
|
||||||
|
"autoconnect-retries": 0,
|
||||||
|
"id": "main",
|
||||||
|
"interface-name": "eth0",
|
||||||
|
"permissions": []string{},
|
||||||
|
"timestamp": 1669049774,
|
||||||
|
"type": "802-3-ethernet",
|
||||||
|
},
|
||||||
|
"802-3-ethernet": {
|
||||||
|
"auto-negotiate": false,
|
||||||
|
"mac-address-blacklist": []string{},
|
||||||
|
"s390-options": map[string]string{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(result, expected) {
|
||||||
|
t.Fatalf("failed: \nexpected: %#v\nresult : %#v", expected, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDecode(t *testing.T) {
|
||||||
|
ipSettings := map[string]dbus.Variant{
|
||||||
|
"address-data": dbus.MakeVariant([]map[string]dbus.Variant{
|
||||||
|
{
|
||||||
|
"address": dbus.MakeVariant("192.168.1.156"),
|
||||||
|
"prefix": dbus.MakeVariant(24),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
"dns-search": dbus.MakeVariant([]string{}),
|
||||||
|
"method": dbus.MakeVariant("manual"),
|
||||||
|
"route-data": dbus.MakeVariant([]map[string]dbus.Variant{}),
|
||||||
|
"routes": dbus.MakeVariant([][]uint32{}),
|
||||||
|
"addresses": dbus.MakeVariant([][]uint32{
|
||||||
|
{
|
||||||
|
2617354432,
|
||||||
|
24,
|
||||||
|
16885952,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
"gateway": dbus.MakeVariant("192.168.1.1"),
|
||||||
|
"route-metric": dbus.MakeVariant(100),
|
||||||
|
"dhcp-timeout": dbus.MakeVariant(45),
|
||||||
|
}
|
||||||
|
|
||||||
|
result := decode(ipSettings)
|
||||||
|
|
||||||
|
expected := map[string]interface{}{
|
||||||
|
"address-data": []map[string]interface{}{
|
||||||
|
{
|
||||||
|
"address": "192.168.1.156",
|
||||||
|
"prefix": 24,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"dns-search": []string{},
|
||||||
|
"method": "manual",
|
||||||
|
"route-data": []map[string]interface{}(nil),
|
||||||
|
"routes": [][]uint32{},
|
||||||
|
"addresses": [][]uint32{
|
||||||
|
{
|
||||||
|
2617354432,
|
||||||
|
24,
|
||||||
|
16885952,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"gateway": "192.168.1.1",
|
||||||
|
"route-metric": 100,
|
||||||
|
"dhcp-timeout": 45,
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(result, expected) {
|
||||||
|
t.Fatalf("failed: \nexpected: %#v\nresult : %#v", expected, result)
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,7 +16,7 @@ const (
|
||||||
type DHCP4Options map[string]interface{}
|
type DHCP4Options map[string]interface{}
|
||||||
|
|
||||||
type DHCP4Config interface {
|
type DHCP4Config interface {
|
||||||
// GetOptions gets options map of configuration returned by the IPv4 DHCP server.
|
// GetPropertyOptions GetOptions gets options map of configuration returned by the IPv4 DHCP server.
|
||||||
GetPropertyOptions() (DHCP4Options, error)
|
GetPropertyOptions() (DHCP4Options, error)
|
||||||
|
|
||||||
MarshalJSON() ([]byte, error)
|
MarshalJSON() ([]byte, error)
|
||||||
|
|
|
@ -16,7 +16,7 @@ const (
|
||||||
type DHCP6Options map[string]interface{}
|
type DHCP6Options map[string]interface{}
|
||||||
|
|
||||||
type DHCP6Config interface {
|
type DHCP6Config interface {
|
||||||
// GetOptions gets options map of configuration returned by the IPv4 DHCP server.
|
// GetPropertyOptions GetOptions gets options map of configuration returned by the IPv4 DHCP server.
|
||||||
GetPropertyOptions() (DHCP6Options, error)
|
GetPropertyOptions() (DHCP6Options, error)
|
||||||
|
|
||||||
MarshalJSON() ([]byte, error)
|
MarshalJSON() ([]byte, error)
|
||||||
|
|
66
Device.go
66
Device.go
|
@ -74,81 +74,86 @@ func DeviceFactory(objectPath dbus.ObjectPath) (Device, error) {
|
||||||
type Device interface {
|
type Device interface {
|
||||||
GetPath() dbus.ObjectPath
|
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.
|
// Reapply 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.
|
// 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.
|
// 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.
|
// 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
|
Reapply(connection Connection, versionId uint64, flags uint32) error
|
||||||
|
|
||||||
// Disconnects a device and prevents the device from automatically activating further connections without user intervention.
|
// Disconnect a device and prevents the device from automatically activating further connections without user intervention.
|
||||||
Disconnect() error
|
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 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
|
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 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)
|
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 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)
|
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 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)
|
GetPropertyIpInterface() (string, error)
|
||||||
|
|
||||||
// The driver handling the device. Non-UTF-8 sequences are backslash escaped. Use g_strcompress() to revert.
|
// GetPropertyDriver The driver handling the device. Non-UTF-8 sequences are backslash escaped. Use g_strcompress() to revert.
|
||||||
GetPropertyDriver() (string, error)
|
GetPropertyDriver() (string, error)
|
||||||
|
|
||||||
// The version of the driver handling the device. Non-UTF-8 sequences are backslash escaped. Use g_strcompress() to revert.
|
// GetPropertyDriverVersion The version of the driver handling the device. Non-UTF-8 sequences are backslash escaped. Use g_strcompress() to revert.
|
||||||
GetPropertyDriverVersion() (string, error)
|
GetPropertyDriverVersion() (string, error)
|
||||||
|
|
||||||
// The firmware version for the device. Non-UTF-8 sequences are backslash escaped. Use g_strcompress() to revert.
|
// GetPropertyFirmwareVersion The firmware version for the device. Non-UTF-8 sequences are backslash escaped. Use g_strcompress() to revert.
|
||||||
GetPropertyFirmwareVersion() (string, error)
|
GetPropertyFirmwareVersion() (string, error)
|
||||||
|
|
||||||
// The current state of the device.
|
// GetPropertyState The current state of the device.
|
||||||
GetPropertyState() (NmDeviceState, error)
|
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 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)
|
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 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)
|
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 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)
|
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 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)
|
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 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)
|
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 Whether 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)
|
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 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)
|
GetPropertyAutoConnect() (bool, error)
|
||||||
|
SetPropertyAutoConnect(bool) error
|
||||||
|
|
||||||
// If TRUE, indicates the device is likely missing firmware necessary for its operation.
|
// GetPropertyFirmwareMissing If TRUE, indicates the device is likely missing firmware necessary for its operation.
|
||||||
GetPropertyFirmwareMissing() (bool, error)
|
GetPropertyFirmwareMissing() (bool, error)
|
||||||
|
|
||||||
// If TRUE, indicates the NetworkManager plugin for the device is likely missing or misconfigured.
|
// GetPropertyNmPluginMissing If TRUE, indicates the NetworkManager plugin for the device is likely missing or misconfigured.
|
||||||
GetPropertyNmPluginMissing() (bool, error)
|
GetPropertyNmPluginMissing() (bool, error)
|
||||||
|
|
||||||
// The general type of the network device; ie Ethernet, Wi-Fi, etc.
|
// GetPropertyDeviceType The general type of the network device; ie Ethernet, Wi-Fi, etc.
|
||||||
GetPropertyDeviceType() (NmDeviceType, error)
|
GetPropertyDeviceType() (NmDeviceType, error)
|
||||||
|
|
||||||
// An array of object paths of every configured connection that is currently 'available' through this device.
|
// GetPropertyAvailableConnections An array of object paths of every configured connection that is currently 'available' through this device.
|
||||||
GetPropertyAvailableConnections() ([]Connection, error)
|
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 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)
|
GetPropertyPhysicalPortId() (string, error)
|
||||||
|
|
||||||
// The device MTU (maximum transmission unit).
|
// GetPropertyMtu The device MTU (maximum transmission unit).
|
||||||
GetPropertyMtu() (uint32, error)
|
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 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)
|
GetPropertyReal() (bool, error)
|
||||||
|
|
||||||
|
// The result of the last IPv4 connectivity check.
|
||||||
|
GetPropertyIp4Connectivity() (NmConnectivity, error)
|
||||||
|
|
||||||
MarshalJSON() ([]byte, error)
|
MarshalJSON() ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,10 +263,18 @@ func (d *device) GetPropertyManaged() (bool, error) {
|
||||||
return d.getBoolProperty(DevicePropertyManaged)
|
return d.getBoolProperty(DevicePropertyManaged)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *device) SetPropertyManaged(managed bool) error {
|
||||||
|
return d.setProperty(DevicePropertyManaged, managed)
|
||||||
|
}
|
||||||
|
|
||||||
func (d *device) GetPropertyAutoConnect() (bool, error) {
|
func (d *device) GetPropertyAutoConnect() (bool, error) {
|
||||||
return d.getBoolProperty(DevicePropertyAutoconnect)
|
return d.getBoolProperty(DevicePropertyAutoconnect)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *device) SetPropertyAutoConnect(managed bool) error {
|
||||||
|
return d.setProperty(DevicePropertyAutoconnect, managed)
|
||||||
|
}
|
||||||
|
|
||||||
func (d *device) GetPropertyFirmwareMissing() (bool, error) {
|
func (d *device) GetPropertyFirmwareMissing() (bool, error) {
|
||||||
return d.getBoolProperty(DevicePropertyFirmwareMissing)
|
return d.getBoolProperty(DevicePropertyFirmwareMissing)
|
||||||
}
|
}
|
||||||
|
@ -304,6 +317,11 @@ func (d *device) GetPropertyReal() (bool, error) {
|
||||||
return d.getBoolProperty(DevicePropertyReal)
|
return d.getBoolProperty(DevicePropertyReal)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *device) GetPropertyIp4Connectivity() (NmConnectivity, error) {
|
||||||
|
u, err := d.getUint32Property(DevicePropertyIp4Connectivity)
|
||||||
|
return NmConnectivity(u), err
|
||||||
|
}
|
||||||
|
|
||||||
func (d *device) marshalMap() (map[string]interface{}, error) {
|
func (d *device) marshalMap() (map[string]interface{}, error) {
|
||||||
Interface, err := d.GetPropertyInterface()
|
Interface, err := d.GetPropertyInterface()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -17,10 +17,10 @@ const (
|
||||||
type DeviceGeneric interface {
|
type DeviceGeneric interface {
|
||||||
Device
|
Device
|
||||||
|
|
||||||
// Active hardware address of the device.
|
// GetPropertyHwAddress Active hardware address of the device.
|
||||||
GetPropertyHwAddress() (string, error)
|
GetPropertyHwAddress() (string, error)
|
||||||
|
|
||||||
// A (non-localized) description of the interface type, if known.
|
// GetPropertyTypeDescription A (non-localized) description of the interface type, if known.
|
||||||
GetPropertyTypeDescription() (string, error)
|
GetPropertyTypeDescription() (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,40 +29,40 @@ const (
|
||||||
type DeviceIpTunnel interface {
|
type DeviceIpTunnel interface {
|
||||||
Device
|
Device
|
||||||
|
|
||||||
// The tunneling mode
|
// GetPropertyMode The tunneling mode
|
||||||
GetPropertyMode() (uint32, error)
|
GetPropertyMode() (uint32, error)
|
||||||
|
|
||||||
// The object path of the parent device.
|
// GetPropertyParent The object path of the parent device.
|
||||||
GetPropertyParent() (Device, error)
|
GetPropertyParent() (Device, error)
|
||||||
|
|
||||||
// The local endpoint of the tunnel.
|
// GetPropertyLocal The local endpoint of the tunnel.
|
||||||
GetPropertyLocal() (string, error)
|
GetPropertyLocal() (string, error)
|
||||||
|
|
||||||
// The remote endpoint of the tunnel.
|
// GetPropertyRemote The remote endpoint of the tunnel.
|
||||||
GetPropertyRemote() (string, error)
|
GetPropertyRemote() (string, error)
|
||||||
|
|
||||||
// The TTL assigned to tunneled packets. 0 is a special value meaning that packets inherit the TTL value
|
// GetPropertyTtl The TTL assigned to tunneled packets. 0 is a special value meaning that packets inherit the TTL value
|
||||||
GetPropertyTtl() (uint8, error)
|
GetPropertyTtl() (uint8, error)
|
||||||
|
|
||||||
// The type of service (IPv4) or traffic class (IPv6) assigned to tunneled packets.
|
// GetPropertyTos The type of service (IPv4) or traffic class (IPv6) assigned to tunneled packets.
|
||||||
GetPropertyTos() (uint8, error)
|
GetPropertyTos() (uint8, error)
|
||||||
|
|
||||||
// Whether path MTU discovery is enabled on this tunnel.
|
// GetPropertyPathMtuDiscovery Whether path MTU discovery is enabled on this tunnel.
|
||||||
GetPropertyPathMtuDiscovery() (bool, error)
|
GetPropertyPathMtuDiscovery() (bool, error)
|
||||||
|
|
||||||
// The key used for incoming packets.
|
// GetPropertyInputKey The key used for incoming packets.
|
||||||
GetPropertyInputKey() (string, error)
|
GetPropertyInputKey() (string, error)
|
||||||
|
|
||||||
// The key used for outgoing packets.
|
// GetPropertyOutputKey The key used for outgoing packets.
|
||||||
GetPropertyOutputKey() (string, error)
|
GetPropertyOutputKey() (string, error)
|
||||||
|
|
||||||
// How many additional levels of encapsulation are permitted to be prepended to packets. This property applies only to IPv6 tunnels.
|
// GetPropertyEncapsulationLimit How many additional levels of encapsulation are permitted to be prepended to packets. This property applies only to IPv6 tunnels.
|
||||||
GetPropertyEncapsulationLimit() (uint8, error)
|
GetPropertyEncapsulationLimit() (uint8, error)
|
||||||
|
|
||||||
// The flow label to assign to tunnel packets. This property applies only to IPv6 tunnels.
|
// GetPropertyFlowLabel The flow label to assign to tunnel packets. This property applies only to IPv6 tunnels.
|
||||||
GetPropertyFlowLabel() (uint32, error)
|
GetPropertyFlowLabel() (uint32, error)
|
||||||
|
|
||||||
// Tunnel flags.
|
// GetPropertyFlags Tunnel flags.
|
||||||
GetPropertyFlags() (uint32, error)
|
GetPropertyFlags() (uint32, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,15 @@ const (
|
||||||
type DeviceStatistics interface {
|
type DeviceStatistics interface {
|
||||||
GetPath() dbus.ObjectPath
|
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 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)
|
GetPropertyRefreshRateMs() (uint32, error)
|
||||||
|
|
||||||
SetPropertyRefreshRateMs(uint32) (error)
|
SetPropertyRefreshRateMs(uint32) error
|
||||||
|
|
||||||
// Number of transmitted bytes
|
// GetPropertyTxBytes Number of transmitted bytes
|
||||||
GetPropertyTxBytes() (uint64, error)
|
GetPropertyTxBytes() (uint64, error)
|
||||||
|
|
||||||
// Number of received bytes
|
// GetPropertyRxBytes Number of received bytes
|
||||||
GetPropertyRxBytes() (uint64, error)
|
GetPropertyRxBytes() (uint64, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ func (d *deviceStatistics) GetPropertyRefreshRateMs() (uint32, error) {
|
||||||
return d.getUint32Property(DeviceStatisticsPropertyRefreshRateMs)
|
return d.getUint32Property(DeviceStatisticsPropertyRefreshRateMs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *deviceStatistics) SetPropertyRefreshRateMs(rate uint32) (error) {
|
func (d *deviceStatistics) SetPropertyRefreshRateMs(rate uint32) error {
|
||||||
return d.setProperty(DeviceStatisticsPropertyRefreshRateMs, rate)
|
return d.setProperty(DeviceStatisticsPropertyRefreshRateMs, rate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,19 +20,19 @@ const (
|
||||||
type DeviceWired interface {
|
type DeviceWired interface {
|
||||||
Device
|
Device
|
||||||
|
|
||||||
// Active hardware address of the device.
|
// GetPropertyHwAddress Active hardware address of the device.
|
||||||
GetPropertyHwAddress() (string, error)
|
GetPropertyHwAddress() (string, error)
|
||||||
|
|
||||||
// Permanent hardware address of the device.
|
// GetPropertyPermHwAddress Permanent hardware address of the device.
|
||||||
GetPropertyPermHwAddress() (string, error)
|
GetPropertyPermHwAddress() (string, error)
|
||||||
|
|
||||||
// Design speed of the device, in megabits/second (Mb/s).
|
// GetPropertySpeed Design speed of the device, in megabits/second (Mb/s).
|
||||||
GetPropertySpeed() (uint32, error)
|
GetPropertySpeed() (uint32, error)
|
||||||
|
|
||||||
// Array of S/390 subchannels for S/390 or z/Architecture devices.
|
// GetPropertyS390Subchannels Array of S/390 subchannels for S/390 or z/Architecture devices.
|
||||||
GetPropertyS390Subchannels() ([]string, error)
|
GetPropertyS390Subchannels() ([]string, error)
|
||||||
|
|
||||||
// Indicates whether the physical carrier is found (e.g. whether a cable is plugged in or not).
|
// GetPropertyCarrier Indicates whether the physical carrier is found (e.g. whether a cable is plugged in or not).
|
||||||
GetPropertyCarrier() (bool, error)
|
GetPropertyCarrier() (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,33 +38,33 @@ type DeviceWireless interface {
|
||||||
// device, including hidden ones for which the SSID is not yet known.
|
// device, including hidden ones for which the SSID is not yet known.
|
||||||
GetAllAccessPoints() ([]AccessPoint, error)
|
GetAllAccessPoints() ([]AccessPoint, error)
|
||||||
|
|
||||||
// Request the device to scan. To know when the scan is finished, use the
|
// RequestScan Request the device to scan. To know when the scan is finished, use the
|
||||||
// "PropertiesChanged" signal from "org.freedesktop.DBus.Properties" to listen
|
// "PropertiesChanged" signal from "org.freedesktop.DBus.Properties" to listen
|
||||||
// to changes to the "LastScan" property.
|
// to changes to the "LastScan" property.
|
||||||
RequestScan() error
|
RequestScan() error
|
||||||
|
|
||||||
// The active hardware address of the device.
|
// GetPropertyHwAddress The active hardware address of the device.
|
||||||
GetPropertyHwAddress() (string, error)
|
GetPropertyHwAddress() (string, error)
|
||||||
|
|
||||||
// The permanent hardware address of the device.
|
// GetPropertyPermHwAddress The permanent hardware address of the device.
|
||||||
GetPropertyPermHwAddress() (string, error)
|
GetPropertyPermHwAddress() (string, error)
|
||||||
|
|
||||||
// The operating mode of the wireless device.
|
// GetPropertyMode The operating mode of the wireless device.
|
||||||
GetPropertyMode() (Nm80211Mode, error)
|
GetPropertyMode() (Nm80211Mode, error)
|
||||||
|
|
||||||
// The bit rate currently used by the wireless device, in kilobits/second (Kb/s).
|
// GetPropertyBitrate The bit rate currently used by the wireless device, in kilobits/second (Kb/s).
|
||||||
GetPropertyBitrate() (uint32, error)
|
GetPropertyBitrate() (uint32, error)
|
||||||
|
|
||||||
// List of object paths of access point visible to this wireless device.
|
// GetPropertyAccessPoints List of object paths of access point visible to this wireless device.
|
||||||
GetPropertyAccessPoints() ([]AccessPoint, error)
|
GetPropertyAccessPoints() ([]AccessPoint, error)
|
||||||
|
|
||||||
// Object path of the access point currently used by the wireless device.
|
// GetPropertyActiveAccessPoint Object path of the access point currently used by the wireless device.
|
||||||
GetPropertyActiveAccessPoint() (AccessPoint, error)
|
GetPropertyActiveAccessPoint() (AccessPoint, error)
|
||||||
|
|
||||||
// The capabilities of the wireless device.
|
// GetPropertyWirelessCapabilities The capabilities of the wireless device.
|
||||||
GetPropertyWirelessCapabilities() (uint32, error)
|
GetPropertyWirelessCapabilities() (uint32, error)
|
||||||
|
|
||||||
// The timestamp (in CLOCK_BOOTTIME milliseconds) for the last finished
|
// GetPropertyLastScan The timestamp (in CLOCK_BOOTTIME milliseconds) for the last finished
|
||||||
// network scan. A value of -1 means the device never scanned for access
|
// network scan. A value of -1 means the device never scanned for access
|
||||||
// points.
|
// points.
|
||||||
GetPropertyLastScan() (int64, error)
|
GetPropertyLastScan() (int64, error)
|
||||||
|
@ -186,7 +186,6 @@ func (d *deviceWireless) MarshalJSON() ([]byte, error) {
|
||||||
m["PermHwAddress"], _ = d.GetPropertyPermHwAddress()
|
m["PermHwAddress"], _ = d.GetPropertyPermHwAddress()
|
||||||
m["Mode"], _ = d.GetPropertyMode()
|
m["Mode"], _ = d.GetPropertyMode()
|
||||||
m["Bitrate"], _ = d.GetPropertyBitrate()
|
m["Bitrate"], _ = d.GetPropertyBitrate()
|
||||||
m["AccessPoints"], _ = d.GetPropertyAccessPoints()
|
|
||||||
m["ActiveAccessPoint"], _ = d.GetPropertyActiveAccessPoint()
|
m["ActiveAccessPoint"], _ = d.GetPropertyActiveAccessPoint()
|
||||||
m["WirelessCapabilities"], _ = d.GetPropertyWirelessCapabilities()
|
m["WirelessCapabilities"], _ = d.GetPropertyWirelessCapabilities()
|
||||||
m["LastScan"], _ = d.GetPropertyLastScan()
|
m["LastScan"], _ = d.GetPropertyLastScan()
|
||||||
|
|
96
DnsManager.go
Normal file
96
DnsManager.go
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
package gonetworkmanager
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/godbus/dbus/v5"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DnsManagerInterface = NetworkManagerInterface + ".DnsManager"
|
||||||
|
DnsManagerObjectPath = "/org/freedesktop/NetworkManager/DnsManager"
|
||||||
|
|
||||||
|
/* Property */
|
||||||
|
DnsManagerPropertyMode = DnsManagerInterface + ".Mode" // readable s
|
||||||
|
DnsManagerPropertyRcManager = DnsManagerInterface + ".RcManager" // readable s
|
||||||
|
DnsManagerPropertyConfiguration = DnsManagerInterface + ".Configuration" // readable aa{sv}
|
||||||
|
)
|
||||||
|
|
||||||
|
type DnsConfigurationData struct {
|
||||||
|
Nameservers []string
|
||||||
|
Priority int32
|
||||||
|
Interface string
|
||||||
|
Vpn bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type DnsManager interface {
|
||||||
|
GetPath() dbus.ObjectPath
|
||||||
|
GetPropertyMode() (string, error)
|
||||||
|
GetPropertyRcManager() (string, error)
|
||||||
|
GetPropertyConfiguration() ([]DnsConfigurationData, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type dnsManager struct {
|
||||||
|
dbusBase
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDnsManager() (DnsManager, error) {
|
||||||
|
var d dnsManager
|
||||||
|
return &d, d.init(NetworkManagerInterface, DnsManagerObjectPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dnsManager) GetPath() dbus.ObjectPath {
|
||||||
|
return d.obj.Path()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dnsManager) GetPropertyMode() (string, error) {
|
||||||
|
return d.getStringProperty(DnsManagerPropertyMode)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dnsManager) GetPropertyRcManager() (string, error) {
|
||||||
|
return d.getStringProperty(DnsManagerPropertyRcManager)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dnsManager) GetPropertyConfiguration() ([]DnsConfigurationData, error) {
|
||||||
|
configurations, err := d.getSliceMapStringVariantProperty(DnsManagerPropertyConfiguration)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ret := make([]DnsConfigurationData, len(configurations))
|
||||||
|
for i, conf := range configurations {
|
||||||
|
if serversVar, exist := conf["nameservers"]; exist {
|
||||||
|
servers, ok := serversVar.Value().([]string)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("unexpected variant type for nameservers")
|
||||||
|
}
|
||||||
|
ret[i].Nameservers = servers
|
||||||
|
}
|
||||||
|
|
||||||
|
if priorityVar, exist := conf["priority"]; exist {
|
||||||
|
priority, ok := priorityVar.Value().(int32)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("unexpected variant type for priority")
|
||||||
|
}
|
||||||
|
ret[i].Priority = priority
|
||||||
|
}
|
||||||
|
|
||||||
|
if interfaceVar, exist := conf["interface"]; exist {
|
||||||
|
iface, ok := interfaceVar.Value().(string)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("unexpected variant type for interface")
|
||||||
|
}
|
||||||
|
ret[i].Interface = iface
|
||||||
|
}
|
||||||
|
|
||||||
|
if vpnVar, exist := conf["vpn"]; exist {
|
||||||
|
vpn, ok := vpnVar.Value().(bool)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("unexpected variant type for vpn")
|
||||||
|
}
|
||||||
|
ret[i].Vpn = vpn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
|
}
|
31
IP4Config.go
31
IP4Config.go
|
@ -59,43 +59,43 @@ type IP4NameserverData struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type IP4Config interface {
|
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), ...]
|
// GetPropertyAddresses 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
|
// Deprecated: use AddressData and Gateway
|
||||||
GetPropertyAddresses() ([]IP4Address, error)
|
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 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)
|
GetPropertyAddressData() ([]IP4AddressData, error)
|
||||||
|
|
||||||
// The gateway in use.
|
// GetPropertyGateway The gateway in use.
|
||||||
GetPropertyGateway() (string, error)
|
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), ...]
|
// GetPropertyRoutes 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
|
// Deprecated: use RouteData
|
||||||
GetPropertyRoutes() ([]IP4Route, error)
|
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 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)
|
GetPropertyRouteData() ([]IP4RouteData, error)
|
||||||
|
|
||||||
// The nameservers in use.
|
// GetPropertyNameservers The nameservers in use.
|
||||||
// Deprecated: use NameserverData
|
// Deprecated: use NameserverData
|
||||||
GetPropertyNameservers() ([]string, error)
|
GetPropertyNameservers() ([]string, error)
|
||||||
|
|
||||||
// The nameservers in use. Currently only the value "address" is recognized (with an IP address string).
|
// GetPropertyNameserverData The nameservers in use. Currently only the value "address" is recognized (with an IP address string).
|
||||||
GetPropertyNameserverData() ([]IP4NameserverData, error)
|
GetPropertyNameserverData() ([]IP4NameserverData, error)
|
||||||
|
|
||||||
// A list of domains this address belongs to.
|
// GetPropertyDomains A list of domains this address belongs to.
|
||||||
GetPropertyDomains() ([]string, error)
|
GetPropertyDomains() ([]string, error)
|
||||||
|
|
||||||
// A list of dns searches.
|
// GetPropertySearches A list of dns searches.
|
||||||
GetPropertySearches() ([]string, error)
|
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 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)
|
GetPropertyDnsOptions() ([]string, error)
|
||||||
|
|
||||||
// The relative priority of DNS servers.
|
// GetPropertyDnsPriority The relative priority of DNS servers.
|
||||||
GetPropertyDnsPriority() (uint32, error)
|
GetPropertyDnsPriority() (uint32, error)
|
||||||
|
|
||||||
// The Windows Internet Name Service servers associated with the connection.
|
// GetPropertyWinsServerData The Windows Internet Name Service servers associated with the connection.
|
||||||
GetPropertyWinsServerData() ([]string, error)
|
GetPropertyWinsServerData() ([]string, error)
|
||||||
|
|
||||||
MarshalJSON() ([]byte, error)
|
MarshalJSON() ([]byte, error)
|
||||||
|
@ -191,7 +191,7 @@ func (c *ip4Config) GetPropertyRouteData() ([]IP4RouteData, error) {
|
||||||
return routes, err
|
return routes, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, routeData := range routesData {
|
for index, routeData := range routesData {
|
||||||
|
|
||||||
route := IP4RouteData{}
|
route := IP4RouteData{}
|
||||||
|
|
||||||
|
@ -222,11 +222,14 @@ func (c *ip4Config) GetPropertyRouteData() ([]IP4RouteData, error) {
|
||||||
}
|
}
|
||||||
route.Metric = uint8(metric)
|
route.Metric = uint8(metric)
|
||||||
default:
|
default:
|
||||||
|
if route.AdditionalAttributes == nil {
|
||||||
|
route.AdditionalAttributes = make(map[string]string)
|
||||||
|
}
|
||||||
route.AdditionalAttributes[routeDataAttributeName] = routeDataAttribute.String()
|
route.AdditionalAttributes[routeDataAttributeName] = routeDataAttribute.String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
routes = append(routes, route)
|
routes[index] = route
|
||||||
}
|
}
|
||||||
return routes, nil
|
return routes, nil
|
||||||
}
|
}
|
||||||
|
|
23
IP6Config.go
23
IP6Config.go
|
@ -53,28 +53,28 @@ type IP6RouteData struct {
|
||||||
|
|
||||||
type IP6Config interface {
|
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 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)
|
GetPropertyAddressData() ([]IP6AddressData, error)
|
||||||
|
|
||||||
// The gateway in use.
|
// GetPropertyGateway The gateway in use.
|
||||||
GetPropertyGateway() (string, error)
|
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 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)
|
GetPropertyRouteData() ([]IP6RouteData, error)
|
||||||
|
|
||||||
// GetNameservers gets the nameservers in use.
|
// GetPropertyNameservers GetNameservers gets the nameservers in use.
|
||||||
GetPropertyNameservers() ([][]byte, error)
|
GetPropertyNameservers() ([][]byte, error)
|
||||||
|
|
||||||
// A list of domains this address belongs to.
|
// GetPropertyDomains A list of domains this address belongs to.
|
||||||
GetPropertyDomains() ([]string, error)
|
GetPropertyDomains() ([]string, error)
|
||||||
|
|
||||||
// A list of dns searches.
|
// GetPropertySearches A list of dns searches.
|
||||||
GetPropertySearches() ([]string, error)
|
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 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)
|
GetPropertyDnsOptions() ([]string, error)
|
||||||
|
|
||||||
// The relative priority of DNS servers.
|
// GetPropertyDnsPriority The relative priority of DNS servers.
|
||||||
GetPropertyDnsPriority() (uint32, error)
|
GetPropertyDnsPriority() (uint32, error)
|
||||||
|
|
||||||
MarshalJSON() ([]byte, error)
|
MarshalJSON() ([]byte, error)
|
||||||
|
@ -129,7 +129,7 @@ func (c *ip6Config) GetPropertyRouteData() ([]IP6RouteData, error) {
|
||||||
return routes, err
|
return routes, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, routeData := range routesData {
|
for index, routeData := range routesData {
|
||||||
|
|
||||||
route := IP6RouteData{}
|
route := IP6RouteData{}
|
||||||
|
|
||||||
|
@ -160,11 +160,14 @@ func (c *ip6Config) GetPropertyRouteData() ([]IP6RouteData, error) {
|
||||||
}
|
}
|
||||||
route.Metric = uint8(metric)
|
route.Metric = uint8(metric)
|
||||||
default:
|
default:
|
||||||
|
if route.AdditionalAttributes == nil {
|
||||||
|
route.AdditionalAttributes = make(map[string]string)
|
||||||
|
}
|
||||||
route.AdditionalAttributes[routeDataAttributeName] = routeDataAttribute.String()
|
route.AdditionalAttributes[routeDataAttributeName] = routeDataAttribute.String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
routes = append(routes, route)
|
routes[index] = route
|
||||||
}
|
}
|
||||||
return routes, nil
|
return routes, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,19 +67,19 @@ type NetworkManager interface {
|
||||||
// (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.
|
// (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
|
Reload(flags uint32) error
|
||||||
|
|
||||||
// Get the list of realized network devices.
|
// GetDevices Get the list of realized network devices.
|
||||||
GetDevices() ([]Device, error)
|
GetDevices() ([]Device, error)
|
||||||
|
|
||||||
// Get the list of all network devices.
|
// GetAllDevices Get the list of all network devices.
|
||||||
GetAllDevices() ([]Device, error)
|
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 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)
|
GetDeviceByIpIface(interfaceId string) (Device, error)
|
||||||
|
|
||||||
// Activate a connection using the supplied device.
|
// ActivateConnection Activate a connection using the supplied device.
|
||||||
ActivateConnection(connection Connection, device Device) (ActiveConnection, error)
|
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 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)
|
AddAndActivateConnection(connection map[string]map[string]interface{}, device Device) (ActiveConnection, error)
|
||||||
|
|
||||||
// ActivateWirelessConnection requests activating access point to network device
|
// ActivateWirelessConnection requests activating access point to network device
|
||||||
|
@ -97,110 +97,116 @@ type NetworkManager interface {
|
||||||
// connection["802-11-wireless-security"]["psk"] = password
|
// connection["802-11-wireless-security"]["psk"] = password
|
||||||
AddAndActivateWirelessConnection(connection map[string]map[string]interface{}, device Device, accessPoint AccessPoint) (ActiveConnection, error)
|
AddAndActivateWirelessConnection(connection map[string]map[string]interface{}, device Device, accessPoint AccessPoint) (ActiveConnection, error)
|
||||||
|
|
||||||
// Deactivate an active connection.
|
// DeactivateConnection Deactivate an active connection.
|
||||||
DeactivateConnection(connection ActiveConnection) error
|
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.
|
// Sleep 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.
|
// sleepnWake: Indicates whether the NetworkManager daemon should sleep or wake.
|
||||||
Sleep(sleepNWake bool) error
|
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.
|
// Enable 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.
|
// enableNDisable: If FALSE, indicates that all networking should be disabled. If TRUE, indicates that NetworkManager should begin managing network devices.
|
||||||
Enable(enableNDisable bool) error
|
Enable(enableNDisable bool) error
|
||||||
|
|
||||||
// Re-check the network connectivity state.
|
// CheckConnectivity Re-check the network connectivity state.
|
||||||
CheckConnectivity() error
|
CheckConnectivity() error
|
||||||
|
|
||||||
// The overall networking state as determined by the NetworkManager daemon, based on the state of network devices under its management.
|
// State The overall networking state as determined by the NetworkManager daemon, based on the state of network devices under its management.
|
||||||
State() (NmState, error)
|
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.
|
// CheckpointCreate 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.
|
// 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.
|
// rollbackTimeout: The time in seconds until NetworkManager will automatically rollback to the checkpoint. Set to zero for infinite.
|
||||||
// flags: Flags for the creation.
|
// flags: Flags for the creation.
|
||||||
// returns: On success, the new checkpoint.
|
// returns: On success, the new checkpoint.
|
||||||
CheckpointCreate(devices []Device, rollbackTimeout uint32, flags []NmCheckpointCreateFlags) (Checkpoint, error)
|
CheckpointCreate(devices []Device, rollbackTimeout uint32, flags uint32) (Checkpoint, error)
|
||||||
|
|
||||||
// Destroy a previously created checkpoint.
|
// CheckpointDestroy Destroy a previously created checkpoint.
|
||||||
// checkpoint: The checkpoint to be destroyed. Set to empty to cancel all pending checkpoints.
|
// checkpoint: The checkpoint to be destroyed. Set to empty to cancel all pending checkpoints.
|
||||||
CheckpointDestroy(checkpoint Checkpoint) error
|
CheckpointDestroy(checkpoint Checkpoint) error
|
||||||
|
|
||||||
// Reset the timeout for rollback for the checkpoint.
|
// CheckpointRollback 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)
|
||||||
|
|
||||||
|
// CheckpointAdjustRollbackTimeout Reset the timeout for rollback for the checkpoint.
|
||||||
// Since: 1.12
|
// 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.
|
// 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
|
CheckpointAdjustRollbackTimeout(checkpoint Checkpoint, addTimeout uint32) error
|
||||||
|
|
||||||
/* PROPERTIES */
|
/* 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 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)
|
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 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)
|
GetPropertyAllDevices() ([]Device, error)
|
||||||
|
|
||||||
// The list of active checkpoints.
|
// GetPropertyCheckpoints The list of active checkpoints.
|
||||||
GetPropertyCheckpoints() ([]Checkpoint, error)
|
GetPropertyCheckpoints() ([]Checkpoint, error)
|
||||||
|
|
||||||
// Indicates if overall networking is currently enabled or not. See the Enable() method.
|
// GetPropertyNetworkingEnabled Indicates if overall networking is currently enabled or not. See the Enable() method.
|
||||||
GetPropertyNetworkingEnabled() (bool, error)
|
GetPropertyNetworkingEnabled() (bool, error)
|
||||||
|
|
||||||
// Indicates if wireless is currently enabled or not.
|
// GetPropertyWirelessEnabled Indicates if wireless is currently enabled or not.
|
||||||
GetPropertyWirelessEnabled() (bool, error)
|
GetPropertyWirelessEnabled() (bool, error)
|
||||||
|
SetPropertyWirelessEnabled(bool) error
|
||||||
|
|
||||||
// Indicates if the wireless hardware is currently enabled, i.e. the state of the RF kill switch.
|
// GetPropertyWirelessHardwareEnabled Indicates if the wireless hardware is currently enabled, i.e. the state of the RF kill switch.
|
||||||
GetPropertyWirelessHardwareEnabled() (bool, error)
|
GetPropertyWirelessHardwareEnabled() (bool, error)
|
||||||
|
|
||||||
// Indicates if mobile broadband devices are currently enabled or not.
|
// GetPropertyWwanEnabled Indicates if mobile broadband devices are currently enabled or not.
|
||||||
GetPropertyWwanEnabled() (bool, error)
|
GetPropertyWwanEnabled() (bool, error)
|
||||||
|
|
||||||
// Indicates if the mobile broadband hardware is currently enabled, i.e. the state of the RF kill switch.
|
// GetPropertyWwanHardwareEnabled Indicates if the mobile broadband hardware is currently enabled, i.e. the state of the RF kill switch.
|
||||||
GetPropertyWwanHardwareEnabled() (bool, error)
|
GetPropertyWwanHardwareEnabled() (bool, error)
|
||||||
|
|
||||||
// Indicates if WiMAX devices are currently enabled or not.
|
// GetPropertyWimaxEnabled Indicates if WiMAX devices are currently enabled or not.
|
||||||
GetPropertyWimaxEnabled() (bool, error)
|
GetPropertyWimaxEnabled() (bool, error)
|
||||||
|
|
||||||
// Indicates if the WiMAX hardware is currently enabled, i.e. the state of the RF kill switch.
|
// GetPropertyWimaxHardwareEnabled Indicates if the WiMAX hardware is currently enabled, i.e. the state of the RF kill switch.
|
||||||
GetPropertyWimaxHardwareEnabled() (bool, error)
|
GetPropertyWimaxHardwareEnabled() (bool, error)
|
||||||
|
|
||||||
// List of active connection object paths.
|
// GetPropertyActiveConnections List of active connection object paths.
|
||||||
GetPropertyActiveConnections() ([]ActiveConnection, error)
|
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 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)
|
GetPropertyPrimaryConnection() (ActiveConnection, 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 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)
|
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 Indicates whether the connectivity is metered. This is equivalent to the metered property of the device associated with the primary connection.
|
||||||
GetPropertyMetered() (NmMetered, error)
|
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 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)
|
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 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)
|
GetPropertyStartup() (bool, error)
|
||||||
|
|
||||||
// NetworkManager version.
|
// GetPropertyVersion NetworkManager version.
|
||||||
GetPropertyVersion() (string, error)
|
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 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)
|
GetPropertyCapabilities() ([]NmCapability, error)
|
||||||
|
|
||||||
// The overall state of the NetworkManager daemon.
|
// GetPropertyState 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.
|
// 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.
|
// 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)
|
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.
|
// GetPropertyConnectivity 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.
|
// 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.
|
// 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)
|
GetPropertyConnectivity() (NmConnectivity, error)
|
||||||
|
|
||||||
// Indicates whether connectivity checking service has been configured. This may return true even if the service is not currently enabled.
|
// GetPropertyConnectivityCheckAvailable 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.
|
// 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)
|
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 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)
|
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.
|
// 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.
|
||||||
|
@ -282,14 +288,29 @@ func (nm *networkManager) GetDeviceByIpIface(interfaceId string) (device Device,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nm *networkManager) ActivateConnection(c Connection, d Device) (ac ActiveConnection, err error) {
|
func (nm *networkManager) ActivateConnection(connection Connection, device Device, specificObject *dbus.Object) (ac ActiveConnection, err error) {
|
||||||
var opath dbus.ObjectPath
|
var connectionPath dbus.ObjectPath
|
||||||
err = nm.callWithReturn(&opath, NetworkManagerActivateConnection, c.GetPath(), d.GetPath(), 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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ac, err = NewActiveConnection(opath)
|
ac, err = NewActiveConnection(connectionPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -301,7 +322,12 @@ func (nm *networkManager) AddAndActivateConnection(connection map[string]map[str
|
||||||
var opath1 dbus.ObjectPath
|
var opath1 dbus.ObjectPath
|
||||||
var opath2 dbus.ObjectPath
|
var opath2 dbus.ObjectPath
|
||||||
|
|
||||||
err = nm.callWithReturn2(&opath1, &opath2, NetworkManagerAddAndActivateConnection, connection, d.GetPath(), 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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -366,22 +392,17 @@ func (nm *networkManager) State() (state NmState, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nm *networkManager) CheckpointCreate(devices []Device, rollbackTimeout uint32, flags []NmCheckpointCreateFlags) (cp Checkpoint, err error) {
|
func (nm *networkManager) CheckpointCreate(devices []Device, rollbackTimeout uint32, flags uint32) (cp Checkpoint, err error) {
|
||||||
var intFlags uint32 = 0
|
|
||||||
for _, flag := range flags {
|
|
||||||
intFlags |= uint32(flag)
|
|
||||||
}
|
|
||||||
|
|
||||||
var devicePaths []dbus.ObjectPath
|
var devicePaths []dbus.ObjectPath
|
||||||
if len(devices) > 0 {
|
if len(devices) > 0 {
|
||||||
devicePaths := []dbus.ObjectPath{}
|
|
||||||
for _, device := range devices {
|
for _, device := range devices {
|
||||||
devicePaths = append(devicePaths, device.GetPath())
|
devicePaths = append(devicePaths, device.GetPath())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var checkpointPath dbus.ObjectPath
|
var checkpointPath dbus.ObjectPath
|
||||||
err = nm.callWithReturn(&checkpointPath, NetworkManagerCheckpointCreate, devicePaths, rollbackTimeout, intFlags)
|
err = nm.callWithReturn(&checkpointPath, NetworkManagerCheckpointCreate, devicePaths, rollbackTimeout, flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -398,6 +419,23 @@ func (nm *networkManager) CheckpointDestroy(checkpoint Checkpoint) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
func (nm *networkManager) CheckpointAdjustRollbackTimeout(checkpoint Checkpoint, addTimeout uint32) error {
|
||||||
return nm.call(NetworkManagerCheckpointAdjustRollbackTimeout, checkpoint, addTimeout)
|
return nm.call(NetworkManagerCheckpointAdjustRollbackTimeout, checkpoint, addTimeout)
|
||||||
}
|
}
|
||||||
|
@ -463,6 +501,10 @@ func (nm *networkManager) GetPropertyWirelessEnabled() (bool, error) {
|
||||||
return nm.getBoolProperty(NetworkManagerPropertyWirelessEnabled)
|
return nm.getBoolProperty(NetworkManagerPropertyWirelessEnabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nm *networkManager) SetPropertyWirelessEnabled(enabled bool) error {
|
||||||
|
return nm.setProperty(NetworkManagerPropertyWirelessEnabled, enabled)
|
||||||
|
}
|
||||||
|
|
||||||
func (nm *networkManager) GetPropertyWirelessHardwareEnabled() (bool, error) {
|
func (nm *networkManager) GetPropertyWirelessHardwareEnabled() (bool, error) {
|
||||||
return nm.getBoolProperty(NetworkManagerPropertyWirelessHardwareEnabled)
|
return nm.getBoolProperty(NetworkManagerPropertyWirelessHardwareEnabled)
|
||||||
}
|
}
|
||||||
|
@ -500,14 +542,14 @@ func (nm *networkManager) GetPropertyActiveConnections() ([]ActiveConnection, er
|
||||||
return ac, nil
|
return ac, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nm *networkManager) GetPropertyPrimaryConnection() (Connection, error) {
|
func (nm *networkManager) GetPropertyPrimaryConnection() (ActiveConnection, error) {
|
||||||
connectionPath, err := nm.getObjectProperty(NetworkManagerPropertyPrimaryConnection)
|
activeConnectionPath, err := nm.getObjectProperty(NetworkManagerPropertyPrimaryConnection)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewConnection(connectionPath)
|
return NewActiveConnection(activeConnectionPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nm *networkManager) GetPropertyPrimaryConnectionType() (string, error) {
|
func (nm *networkManager) GetPropertyPrimaryConnectionType() (string, error) {
|
||||||
|
|
39
README.md
39
README.md
|
@ -1,18 +1,35 @@
|
||||||
|
[](https://pkg.go.dev/github.com/Wifx/gonetworkmanager)
|
||||||
|
[](https://github.com/Wifx/gonetworkmanager/actions?query=workflow%3AGo)
|
||||||
|
|
||||||
gonetworkmanager
|
gonetworkmanager
|
||||||
================
|
================
|
||||||
|
|
||||||
Go D-Bus bindings for NetworkManager 1.16.
|
Go D-Bus bindings for [NetworkManager](https://networkmanager.dev/).
|
||||||
|
|
||||||
Tested with NetworkManager 1.16.0.
|
|
||||||
|
|
||||||
[](https://godoc.org/github.com/Wifx/gonetworkmanager)
|
|
||||||
|
|
||||||
[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
|
## Usage
|
||||||
|
|
||||||
You can find some examples in the [examples](examples) directory.
|
You can find some examples in the [examples](examples) directory.
|
||||||
|
|
||||||
|
## External documentations
|
||||||
|
|
||||||
|
- [NetworkManager D-Bus Spec](https://networkmanager.dev/docs/api/latest/spec.html)
|
||||||
|
- [nm-settings-dbus](https://networkmanager.dev/docs/api/latest/nm-settings-dbus.html)
|
||||||
|
|
||||||
|
|
||||||
|
## Backward compatibility
|
||||||
|
|
||||||
|
The library is most likely compatible with NetworkManager 0.9 to 1.40.
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
|
||||||
|
Tested with NetworkManager 1.40.0.
|
||||||
|
|
||||||
|
There are no automated tests for this library. Tests are made manually on a best-effort basis. Unit tests PRs are welcome.
|
||||||
|
|
||||||
|
## Development and contributions
|
||||||
|
|
||||||
|
There is no active development workforce from the maintainer. PRs are welcome.
|
||||||
|
|
||||||
|
## Issues
|
||||||
|
|
||||||
|
Before reporting an issue, please test the scenario with nmcli (if possible) to ensure the problem comes from the library.
|
||||||
|
|
33
Settings.go
33
Settings.go
|
@ -10,7 +10,7 @@ const (
|
||||||
|
|
||||||
/* Methods */
|
/* Methods */
|
||||||
SettingsListConnections = SettingsInterface + ".ListConnections"
|
SettingsListConnections = SettingsInterface + ".ListConnections"
|
||||||
SettingsGetConnectionByUuid = SettingsInterface + ".GetConnectionByUuid"
|
SettingsGetConnectionByUUID = SettingsInterface + ".GetConnectionByUuid"
|
||||||
SettingsAddConnection = SettingsInterface + ".AddConnection"
|
SettingsAddConnection = SettingsInterface + ".AddConnection"
|
||||||
SettingsAddConnectionUnsaved = SettingsInterface + ".AddConnectionUnsaved"
|
SettingsAddConnectionUnsaved = SettingsInterface + ".AddConnectionUnsaved"
|
||||||
SettingsLoadConnections = SettingsInterface + ".LoadConnections"
|
SettingsLoadConnections = SettingsInterface + ".LoadConnections"
|
||||||
|
@ -27,19 +27,25 @@ type Settings interface {
|
||||||
// ListConnections gets list the saved network connections known to NetworkManager
|
// ListConnections gets list the saved network connections known to NetworkManager
|
||||||
ListConnections() ([]Connection, error)
|
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 adds new connection and save it to disk.
|
||||||
AddConnection(settings ConnectionSettings) (Connection, error)
|
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 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)
|
AddConnectionUnsaved(settings ConnectionSettings) (Connection, error)
|
||||||
|
|
||||||
// Save the hostname to persistent configuration.
|
// SaveHostname Save the hostname to persistent configuration.
|
||||||
SaveHostname(hostname string) error
|
SaveHostname(hostname string) error
|
||||||
|
|
||||||
// If true, adding and modifying connections is supported.
|
// GetPropertyCanModify If true, adding and modifying connections is supported.
|
||||||
GetPropertyCanModify() (bool, error)
|
GetPropertyCanModify() (bool, error)
|
||||||
|
|
||||||
// The machine hostname stored in persistent configuration.
|
// GetPropertyHostname The machine hostname stored in persistent configuration.
|
||||||
GetPropertyHostname() (string, error)
|
GetPropertyHostname() (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +78,23 @@ func (s *settings) ListConnections() ([]Connection, error) {
|
||||||
return connections, nil
|
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) {
|
func (s *settings) AddConnection(settings ConnectionSettings) (Connection, error) {
|
||||||
var path dbus.ObjectPath
|
var path dbus.ObjectPath
|
||||||
err := s.callWithReturn(&path, SettingsAddConnection, settings)
|
err := s.callWithReturn(&path, SettingsAddConnection, settings)
|
||||||
|
|
45
VpnConnection.go
Normal file
45
VpnConnection.go
Normal file
|
@ -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
|
||||||
|
|
||||||
|
// GetPropertyVpnState The VPN-specific state of the connection.
|
||||||
|
GetPropertyVpnState() (NmVpnConnectionState, error)
|
||||||
|
|
||||||
|
// GetPropertyBanner 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)
|
||||||
|
}
|
7
debian/.gitignore
vendored
Normal file
7
debian/.gitignore
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
*.debhelper
|
||||||
|
*.log
|
||||||
|
*.substvars
|
||||||
|
/.debhelper/
|
||||||
|
/debhelper-build-stamp
|
||||||
|
/files
|
||||||
|
/golang-github-wifx-gonetworkmanager-dev/
|
17
debian/changelog
vendored
Normal file
17
debian/changelog
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
golang-github-wifx-gonetworkmanager (2.1.0-3) unstable; urgency=medium
|
||||||
|
|
||||||
|
* revert meta changes
|
||||||
|
|
||||||
|
-- Penelope Gwen <support@pogmom.me> Tue, 11 Jun 2024 16:51:58 -0600
|
||||||
|
|
||||||
|
golang-github-wifx-gonetworkmanager (2.1.0-2) unstable; urgency=medium
|
||||||
|
|
||||||
|
* update packaging meta
|
||||||
|
|
||||||
|
-- Penelope Gwen <support@pogmom.me> Tue, 11 Jun 2024 16:13:39 -0600
|
||||||
|
|
||||||
|
golang-github-wifx-gonetworkmanager (2.1.0-1) unstable; urgency=medium
|
||||||
|
|
||||||
|
* Initial debian package
|
||||||
|
|
||||||
|
-- Penelope Gwen <support@pogmom.me> Tue, 11 Jun 2024 14:44:53 -0600
|
62
debian/control
vendored
Normal file
62
debian/control
vendored
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
Source: golang-github-wifx-gonetworkmanager
|
||||||
|
Section: golang
|
||||||
|
Priority: optional
|
||||||
|
Maintainer: Penelope Gwen <support@pogmom.me>
|
||||||
|
Uploaders: Penelope Gwen <support@pogmom.me>
|
||||||
|
Rules-Requires-Root: no
|
||||||
|
Build-Depends: debhelper-compat (= 13),
|
||||||
|
dh-sequence-golang,
|
||||||
|
golang-any,
|
||||||
|
golang-dbus-dev,
|
||||||
|
golang-github-google-uuid-dev
|
||||||
|
Testsuite: autopkgtest-pkg-go
|
||||||
|
Standards-Version: 4.6.2
|
||||||
|
Homepage: https://git.pogmom.me/pogmommy/gonetworkmanager
|
||||||
|
XS-Go-Import-Path: github.com/Wifx/gonetworkmanager
|
||||||
|
|
||||||
|
Package: golang-github-wifx-gonetworkmanager-dev
|
||||||
|
Architecture: all
|
||||||
|
Multi-Arch: foreign
|
||||||
|
Depends: golang-dbus-dev,
|
||||||
|
golang-github-google-uuid-dev,
|
||||||
|
${misc:Depends}
|
||||||
|
Description: Go D-Bus bindings for NetworkManager (library)
|
||||||
|
GoDoc (https://pkg.go.dev/github.com/Wifx/gonetworkmanager) Go build
|
||||||
|
(https://github.com/Wifx/gonetworkmanager/actions?query=workflow%3AGo)
|
||||||
|
.
|
||||||
|
gonetworkmanager
|
||||||
|
.
|
||||||
|
Go D-Bus bindings for NetworkManager (https://networkmanager.dev/).
|
||||||
|
.
|
||||||
|
Usage
|
||||||
|
.
|
||||||
|
You can find some examples in the (/examples) directory.
|
||||||
|
.
|
||||||
|
External documentations
|
||||||
|
.
|
||||||
|
* NetworkManager D-Bus Spec
|
||||||
|
(https://networkmanager.dev/docs/api/latest/spec.html)
|
||||||
|
* nm-settings-dbus (https://networkmanager.dev/docs/api/latest/nm-settings-
|
||||||
|
dbus.html)
|
||||||
|
.
|
||||||
|
Backward compatibility
|
||||||
|
.
|
||||||
|
The library is most likely compatible with NetworkManager 0.9 to 1.40.
|
||||||
|
.
|
||||||
|
Tests
|
||||||
|
.
|
||||||
|
Tested with NetworkManager 1.40.0.
|
||||||
|
.
|
||||||
|
There are no automated tests for this library. Tests are made manually
|
||||||
|
on a best-effort basis. Unit tests PRs are welcome.
|
||||||
|
.
|
||||||
|
Development and contributions
|
||||||
|
.
|
||||||
|
There is no active development workforce from the maintainer. PRs are
|
||||||
|
welcome.
|
||||||
|
.
|
||||||
|
Issues
|
||||||
|
.
|
||||||
|
Before reporting an issue, please test the scenario with nmcli (if
|
||||||
|
possible) to ensure the problem comes from the library.
|
||||||
|
|
106
debian/copyright
vendored
Normal file
106
debian/copyright
vendored
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||||
|
Source: https://github.com/Wifx/gonetworkmanager
|
||||||
|
Upstream-Name: gonetworkmanager
|
||||||
|
Upstream-Contact: Wifx <support@iot.wifx.net>
|
||||||
|
|
||||||
|
Files: *
|
||||||
|
Copyright: 2019 Wifx
|
||||||
|
License: 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.
|
||||||
|
|
||||||
|
Files: debian/*
|
||||||
|
Copyright: 2024 Penelope Gwen <support@pogmom.me>
|
||||||
|
License: Opinionated Queer License
|
||||||
|
PERMISSIONS
|
||||||
|
.
|
||||||
|
The creators of this Work (“The Licensor”) grant permission
|
||||||
|
to any person, group or legal entity that doesn't violate the prohibitions below (“The User”),
|
||||||
|
to do everything with this Work that would otherwise infringe their copyright or any patent claims,
|
||||||
|
subject to the following conditions:
|
||||||
|
.
|
||||||
|
OBLIGATIONS
|
||||||
|
.
|
||||||
|
The User must give appropriate credit to the Licensor,
|
||||||
|
provide a copy of this license or a (clickable, if the medium allows) link to
|
||||||
|
oql.avris.it/license/v1.1,
|
||||||
|
and indicate whether and what kind of changes were made.
|
||||||
|
The User may do so in any reasonable manner,
|
||||||
|
but not in any way that suggests the Licensor endorses the User or their use.
|
||||||
|
.
|
||||||
|
PROHIBITIONS
|
||||||
|
.
|
||||||
|
No one may use this Work for prejudiced or bigoted purposes, including but not limited to:
|
||||||
|
racism, xenophobia, queerphobia, queer exclusionism, homophobia, transphobia, enbyphobia, misogyny.
|
||||||
|
.
|
||||||
|
No one may use this Work to inflict or facilitate violence or abuse of human rights as defined in the
|
||||||
|
Universal Declaration of Human Rights.
|
||||||
|
.
|
||||||
|
No law enforcement, carceral institutions, immigration enforcement entities, military entities or military contractors
|
||||||
|
may use the Work for any reason. This also applies to any individuals employed by those entities.
|
||||||
|
.
|
||||||
|
No business entity where the ratio of pay (salaried, freelance, stocks, or other benefits)
|
||||||
|
between the highest and lowest individual in the entity is greater than 50 : 1
|
||||||
|
may use the Work for any reason.
|
||||||
|
.
|
||||||
|
No private business run for profit with more than a thousand employees
|
||||||
|
may use the Work for any reason.
|
||||||
|
.
|
||||||
|
Unless the User has made substantial changes to the Work,
|
||||||
|
or uses it only as a part of a new work (eg. as a library, as a part of an anthology, etc.),
|
||||||
|
they are prohibited from selling the Work.
|
||||||
|
That prohibition includes processing the Work with machine learning models.
|
||||||
|
.
|
||||||
|
SANCTIONS
|
||||||
|
.
|
||||||
|
If the Licensor notifies the User that they have not complied with the rules of the license,
|
||||||
|
they can keep their license by complying within 30 days after the notice.
|
||||||
|
If they do not do so, their license ends immediately.
|
||||||
|
.
|
||||||
|
WARRANTY
|
||||||
|
.
|
||||||
|
This Work is provided “as is”, without warranty of any kind, express or implied.
|
||||||
|
The Licensor will not be liable to anyone for any damages related to the Work or this license,
|
||||||
|
under any kind of legal claim as far as the law allows.
|
3
debian/gbp.conf
vendored
Normal file
3
debian/gbp.conf
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[DEFAULT]
|
||||||
|
debian-branch = debian/sid
|
||||||
|
dist = DEP14
|
4
debian/rules
vendored
Executable file
4
debian/rules
vendored
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/usr/bin/make -f
|
||||||
|
|
||||||
|
%:
|
||||||
|
dh $@ --builddirectory=_build --buildsystem=golang
|
1
debian/source/format
vendored
Normal file
1
debian/source/format
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
3.0 (quilt)
|
5
debian/upstream/metadata
vendored
Normal file
5
debian/upstream/metadata
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
Bug-Database: https://github.com/Wifx/gonetworkmanager/issues
|
||||||
|
Bug-Submit: https://github.com/Wifx/gonetworkmanager/issues/new
|
||||||
|
Repository: https://github.com/Wifx/gonetworkmanager.git
|
||||||
|
Repository-Browse: https://github.com/Wifx/gonetworkmanager
|
4
debian/watch
vendored
Normal file
4
debian/watch
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
version=4
|
||||||
|
opts="filenamemangle=s%(?:.*?)?v?(\d[\d.]*)\.tar\.gz%@PACKAGE@-$1.tar.gz%,\
|
||||||
|
uversionmangle=s/(\d)[_\.\-\+]?(RC|rc|pre|dev|beta|alpha)[.]?(\d*)$/$1~$2$3/" \
|
||||||
|
https://github.com/Wifx/gonetworkmanager/tags .*/v?(\d\S*)\.tar\.gz debian
|
122
enums.go
122
enums.go
|
@ -158,6 +158,9 @@ const (
|
||||||
Nm80211APSecGroupCCMP Nm80211APSec = 0x80
|
Nm80211APSecGroupCCMP Nm80211APSec = 0x80
|
||||||
Nm80211APSecKeyMgmtPSK Nm80211APSec = 0x100
|
Nm80211APSecKeyMgmtPSK Nm80211APSec = 0x100
|
||||||
Nm80211APSecKeyMgmt8021X Nm80211APSec = 0x200
|
Nm80211APSecKeyMgmt8021X Nm80211APSec = 0x200
|
||||||
|
Nm80211APSecKeyMgmtSAE Nm80211APSec = 0x400
|
||||||
|
Nm80211APSecKeyMgmtOWE Nm80211APSec = 0x800
|
||||||
|
Nm80211APSecKeyMgmtOWETM Nm80211APSec = 0x1000
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate stringer -type=Nm80211Mode
|
//go:generate stringer -type=Nm80211Mode
|
||||||
|
@ -169,3 +172,122 @@ const (
|
||||||
Nm80211ModeInfra Nm80211Mode = 2
|
Nm80211ModeInfra Nm80211Mode = 2
|
||||||
Nm80211ModeAp Nm80211Mode = 3
|
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.
|
||||||
|
)
|
||||||
|
|
|
@ -2,7 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Wifx/gonetworkmanager"
|
"github.com/Wifx/gonetworkmanager/v2"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
184
examples/static_connect/static_connect.go
Normal file
184
examples/static_connect/static_connect.go
Normal file
|
@ -0,0 +1,184 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/Wifx/gonetworkmanager/v2"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ethernetType = "802-3-ethernet"
|
||||||
|
ethernetSection = "802-3-ethernet"
|
||||||
|
ethernetSectionAutoNegotiate = "auto-negotiate"
|
||||||
|
connectionSection = "connection"
|
||||||
|
connectionSectionID = "id"
|
||||||
|
connectionSectionType = "type"
|
||||||
|
connectionSectionUUID = "uuid"
|
||||||
|
connectionSectionIfaceName = "interface-name"
|
||||||
|
connectionSectionAutoconnect = "autoconnect"
|
||||||
|
ip4Section = "ipv4"
|
||||||
|
ip4SectionAddressData = "address-data"
|
||||||
|
ip4SectionAddresses = "addresses"
|
||||||
|
ip4SectionAddress = "address"
|
||||||
|
ip4SectionPrefix = "prefix"
|
||||||
|
ip4SectionMethod = "method"
|
||||||
|
ip4SectionGateway = "gateway"
|
||||||
|
ip4SectionNeverDefault = "never-default"
|
||||||
|
ip6Section = "ipv6"
|
||||||
|
ip6SectionMethod = "method"
|
||||||
|
|
||||||
|
connectionID = "My Connection"
|
||||||
|
interfaceName = "eth1"
|
||||||
|
desiredIPAddress = "192.168.1.1"
|
||||||
|
desiredGatewayAddress = "192.168.1.1"
|
||||||
|
desiredIPAddressNumerical = 16885952
|
||||||
|
desiredIPPrefix = 24
|
||||||
|
desiredGatewayAddressNumerical = 16885952
|
||||||
|
|
||||||
|
// Allows for static ip
|
||||||
|
desiredIP4Method = "manual"
|
||||||
|
|
||||||
|
// Would like this to be "disabled" however not supported
|
||||||
|
// in the current network manager stack
|
||||||
|
desiredIP6Method = "ignore"
|
||||||
|
)
|
||||||
|
|
||||||
|
func printVersion() error {
|
||||||
|
/* Create new instance of gonetworkmanager */
|
||||||
|
nm, err := gonetworkmanager.NewNetworkManager()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't really need the network manager object per se
|
||||||
|
// however knowing the version isn't bad
|
||||||
|
var nmVersion string
|
||||||
|
nmVersion, err = nm.GetPropertyVersion()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Network Manager Version: " + nmVersion)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkForExistingConnection() (bool, error) {
|
||||||
|
// See if our connection already exists
|
||||||
|
settings, err := gonetworkmanager.NewSettings()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
currentConnections, err := settings.ListConnections()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range currentConnections {
|
||||||
|
connectionSettings, settingsError := v.GetSettings()
|
||||||
|
if settingsError != nil {
|
||||||
|
fmt.Println("settings error, continuing")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
currentConnectionSection := connectionSettings[connectionSection]
|
||||||
|
if currentConnectionSection[connectionSectionID] == connectionID {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func createNewConnection() error {
|
||||||
|
|
||||||
|
connection := make(map[string]map[string]interface{})
|
||||||
|
connection[ethernetSection] = make(map[string]interface{})
|
||||||
|
connection[ethernetSection][ethernetSectionAutoNegotiate] = false
|
||||||
|
connection[connectionSection] = make(map[string]interface{})
|
||||||
|
connection[connectionSection][connectionSectionID] = connectionID
|
||||||
|
connection[connectionSection][connectionSectionType] = ethernetType
|
||||||
|
connectionUUID, err := uuid.NewUUID()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
connection[connectionSection][connectionSectionUUID] = connectionUUID.String()
|
||||||
|
connection[connectionSection][connectionSectionIfaceName] = interfaceName
|
||||||
|
connection[connectionSection][connectionSectionAutoconnect] = true
|
||||||
|
connection[ip4Section] = make(map[string]interface{})
|
||||||
|
|
||||||
|
addressData := make([]map[string]interface{}, 1)
|
||||||
|
|
||||||
|
addressData[0] = make(map[string]interface{})
|
||||||
|
addressData[0][ip4SectionAddress] = desiredIPAddress
|
||||||
|
addressData[0][ip4SectionPrefix] = desiredIPPrefix
|
||||||
|
|
||||||
|
connection[ip4Section][ip4SectionAddressData] = addressData
|
||||||
|
|
||||||
|
// order defined by network manager
|
||||||
|
addresses := make([]uint32, 3)
|
||||||
|
addresses[0] = desiredIPAddressNumerical
|
||||||
|
addresses[1] = desiredIPPrefix
|
||||||
|
addresses[2] = desiredGatewayAddressNumerical
|
||||||
|
|
||||||
|
addressArray := make([][]uint32, 1)
|
||||||
|
addressArray[0] = addresses
|
||||||
|
connection[ip4Section][ip4SectionAddresses] = addressArray
|
||||||
|
|
||||||
|
connection[ip4Section][ip4SectionGateway] = desiredGatewayAddress
|
||||||
|
connection[ip4Section][ip4SectionMethod] = desiredIP4Method
|
||||||
|
connection[ip4Section][ip4SectionNeverDefault] = true
|
||||||
|
|
||||||
|
connection[ip6Section] = make(map[string]interface{})
|
||||||
|
connection[ip6Section][ip6SectionMethod] = desiredIP6Method
|
||||||
|
|
||||||
|
settings, err := gonetworkmanager.NewSettings()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = settings.AddConnection(connection)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
// show the version
|
||||||
|
if printVersion() != nil {
|
||||||
|
fmt.Println("failed to find version. Is NetworkManager running?")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// See if our connection already exists
|
||||||
|
doesExist, err := checkForExistingConnection()
|
||||||
|
|
||||||
|
// if an error then we are done.
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the connection already exists we are done.
|
||||||
|
if doesExist == true {
|
||||||
|
fmt.Println("connection already exists, nothing to do.")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// create the new connection
|
||||||
|
err = createNewConnection()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Print("added " + connectionID + " to the system.")
|
||||||
|
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
7
go.mod
7
go.mod
|
@ -1,5 +1,8 @@
|
||||||
module github.com/Wifx/gonetworkmanager
|
module github.com/Wifx/gonetworkmanager/v2
|
||||||
|
|
||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require github.com/godbus/dbus/v5 v5.0.2
|
require (
|
||||||
|
github.com/godbus/dbus/v5 v5.1.0
|
||||||
|
github.com/google/uuid v1.3.0
|
||||||
|
)
|
||||||
|
|
6
go.sum
6
go.sum
|
@ -1,2 +1,4 @@
|
||||||
github.com/godbus/dbus/v5 v5.0.2 h1:QtWdZQyXTEn7S0LXv9nVxPUiT37d1i7UntpRTiKM86E=
|
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
|
||||||
github.com/godbus/dbus/v5 v5.0.2/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
|
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||||
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
// Code generated by "stringer -type=Nm80211APFlags"; DO NOT EDIT
|
// Code generated by "stringer -type=Nm80211APFlags"; DO NOT EDIT.
|
||||||
|
|
||||||
package gonetworkmanager
|
package gonetworkmanager
|
||||||
|
|
||||||
import "fmt"
|
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"
|
const _Nm80211APFlags_name = "Nm80211APFlagsNoneNm80211APFlagsPrivacy"
|
||||||
|
|
||||||
|
@ -10,7 +18,7 @@ var _Nm80211APFlags_index = [...]uint8{0, 18, 39}
|
||||||
|
|
||||||
func (i Nm80211APFlags) String() string {
|
func (i Nm80211APFlags) String() string {
|
||||||
if i >= Nm80211APFlags(len(_Nm80211APFlags_index)-1) {
|
if i >= Nm80211APFlags(len(_Nm80211APFlags_index)-1) {
|
||||||
return fmt.Sprintf("Nm80211APFlags(%d)", i)
|
return "Nm80211APFlags(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
}
|
}
|
||||||
return _Nm80211APFlags_name[_Nm80211APFlags_index[i]:_Nm80211APFlags_index[i+1]]
|
return _Nm80211APFlags_name[_Nm80211APFlags_index[i]:_Nm80211APFlags_index[i+1]]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,54 +1,51 @@
|
||||||
// Code generated by "stringer -type=Nm80211APSec"; DO NOT EDIT
|
// Code generated by "stringer -type=Nm80211APSec"; DO NOT EDIT.
|
||||||
|
|
||||||
package gonetworkmanager
|
package gonetworkmanager
|
||||||
|
|
||||||
import "fmt"
|
import "strconv"
|
||||||
|
|
||||||
const (
|
func _() {
|
||||||
_Nm80211APSec_name_0 = "Nm80211APSecNoneNm80211APSecPairWEP40Nm80211APSecPairWEP104"
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
_Nm80211APSec_name_1 = "Nm80211APSecPairTKIP"
|
// Re-run the stringer command to generate them again.
|
||||||
_Nm80211APSec_name_2 = "Nm80211APSecPairCCMP"
|
var x [1]struct{}
|
||||||
_Nm80211APSec_name_3 = "Nm80211APSecGroupWEP40"
|
_ = x[Nm80211APSecNone-0]
|
||||||
_Nm80211APSec_name_4 = "Nm80211APSecGroupWEP104"
|
_ = x[Nm80211APSecPairWEP40-1]
|
||||||
_Nm80211APSec_name_5 = "Nm80211APSecGroupTKIP"
|
_ = x[Nm80211APSecPairWEP104-2]
|
||||||
_Nm80211APSec_name_6 = "Nm80211APSecGroupCCMP"
|
_ = x[Nm80211APSecPairTKIP-4]
|
||||||
_Nm80211APSec_name_7 = "Nm80211APSecKeyMgmtPSK"
|
_ = x[Nm80211APSecPairCCMP-8]
|
||||||
_Nm80211APSec_name_8 = "Nm80211APSecKeyMgmt8021X"
|
_ = x[Nm80211APSecGroupWEP40-16]
|
||||||
)
|
_ = x[Nm80211APSecGroupWEP104-32]
|
||||||
|
_ = x[Nm80211APSecGroupTKIP-64]
|
||||||
|
_ = x[Nm80211APSecGroupCCMP-128]
|
||||||
|
_ = x[Nm80211APSecKeyMgmtPSK-256]
|
||||||
|
_ = x[Nm80211APSecKeyMgmt8021X-512]
|
||||||
|
_ = x[Nm80211APSecKeyMgmtSAE-1024]
|
||||||
|
_ = x[Nm80211APSecKeyMgmtOWE-2048]
|
||||||
|
_ = x[Nm80211APSecKeyMgmtOWETM-4096]
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
const _Nm80211APSec_name = "Nm80211APSecNoneNm80211APSecPairWEP40Nm80211APSecPairWEP104Nm80211APSecPairTKIPNm80211APSecPairCCMPNm80211APSecGroupWEP40Nm80211APSecGroupWEP104Nm80211APSecGroupTKIPNm80211APSecGroupCCMPNm80211APSecKeyMgmtPSKNm80211APSecKeyMgmt8021XNm80211APSecKeyMgmtSAENm80211APSecKeyMgmtOWENm80211APSecKeyMgmtOWETM"
|
||||||
_Nm80211APSec_index_0 = [...]uint8{0, 16, 37, 59}
|
|
||||||
_Nm80211APSec_index_1 = [...]uint8{0, 20}
|
var _Nm80211APSec_map = map[Nm80211APSec]string{
|
||||||
_Nm80211APSec_index_2 = [...]uint8{0, 20}
|
0: _Nm80211APSec_name[0:16],
|
||||||
_Nm80211APSec_index_3 = [...]uint8{0, 22}
|
1: _Nm80211APSec_name[16:37],
|
||||||
_Nm80211APSec_index_4 = [...]uint8{0, 23}
|
2: _Nm80211APSec_name[37:59],
|
||||||
_Nm80211APSec_index_5 = [...]uint8{0, 21}
|
4: _Nm80211APSec_name[59:79],
|
||||||
_Nm80211APSec_index_6 = [...]uint8{0, 21}
|
8: _Nm80211APSec_name[79:99],
|
||||||
_Nm80211APSec_index_7 = [...]uint8{0, 22}
|
16: _Nm80211APSec_name[99:121],
|
||||||
_Nm80211APSec_index_8 = [...]uint8{0, 24}
|
32: _Nm80211APSec_name[121:144],
|
||||||
)
|
64: _Nm80211APSec_name[144:165],
|
||||||
|
128: _Nm80211APSec_name[165:186],
|
||||||
|
256: _Nm80211APSec_name[186:208],
|
||||||
|
512: _Nm80211APSec_name[208:232],
|
||||||
|
1024: _Nm80211APSec_name[232:254],
|
||||||
|
2048: _Nm80211APSec_name[254:276],
|
||||||
|
4096: _Nm80211APSec_name[276:300],
|
||||||
|
}
|
||||||
|
|
||||||
func (i Nm80211APSec) String() string {
|
func (i Nm80211APSec) String() string {
|
||||||
switch {
|
if str, ok := _Nm80211APSec_map[i]; ok {
|
||||||
case 0 <= i && i <= 2:
|
return str
|
||||||
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 fmt.Sprintf("Nm80211APSec(%d)", i)
|
|
||||||
}
|
}
|
||||||
|
return "Nm80211APSec(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,18 @@
|
||||||
// Code generated by "stringer -type=Nm80211Mode"; DO NOT EDIT
|
// Code generated by "stringer -type=Nm80211Mode"; DO NOT EDIT.
|
||||||
|
|
||||||
package gonetworkmanager
|
package gonetworkmanager
|
||||||
|
|
||||||
import "fmt"
|
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"
|
const _Nm80211Mode_name = "Nm80211ModeUnknownNm80211ModeAdhocNm80211ModeInfraNm80211ModeAp"
|
||||||
|
|
||||||
|
@ -10,7 +20,7 @@ var _Nm80211Mode_index = [...]uint8{0, 18, 34, 50, 63}
|
||||||
|
|
||||||
func (i Nm80211Mode) String() string {
|
func (i Nm80211Mode) String() string {
|
||||||
if i >= Nm80211Mode(len(_Nm80211Mode_index)-1) {
|
if i >= Nm80211Mode(len(_Nm80211Mode_index)-1) {
|
||||||
return fmt.Sprintf("Nm80211Mode(%d)", i)
|
return "Nm80211Mode(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
}
|
}
|
||||||
return _Nm80211Mode_name[_Nm80211Mode_index[i]:_Nm80211Mode_index[i+1]]
|
return _Nm80211Mode_name[_Nm80211Mode_index[i]:_Nm80211Mode_index[i+1]]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,19 @@
|
||||||
// Code generated by "stringer -type=NmConnectivity"; DO NOT EDIT
|
// Code generated by "stringer -type=NmConnectivity"; DO NOT EDIT.
|
||||||
|
|
||||||
package gonetworkmanager
|
package gonetworkmanager
|
||||||
|
|
||||||
import "fmt"
|
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"
|
const _NmConnectivity_name = "NmConnectivityUnknownNmConnectivityNoneNmConnectivityPortalNmConnectivityLimitedNmConnectivityFull"
|
||||||
|
|
||||||
|
@ -10,7 +21,7 @@ var _NmConnectivity_index = [...]uint8{0, 21, 39, 59, 80, 98}
|
||||||
|
|
||||||
func (i NmConnectivity) String() string {
|
func (i NmConnectivity) String() string {
|
||||||
if i >= NmConnectivity(len(_NmConnectivity_index)-1) {
|
if i >= NmConnectivity(len(_NmConnectivity_index)-1) {
|
||||||
return fmt.Sprintf("NmConnectivity(%d)", i)
|
return "NmConnectivity(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
}
|
}
|
||||||
return _NmConnectivity_name[_NmConnectivity_index[i]:_NmConnectivity_index[i+1]]
|
return _NmConnectivity_name[_NmConnectivity_index[i]:_NmConnectivity_index[i+1]]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,29 @@
|
||||||
// Code generated by "stringer -type=NmDeviceState"; DO NOT EDIT
|
// Code generated by "stringer -type=NmDeviceState"; DO NOT EDIT.
|
||||||
|
|
||||||
package gonetworkmanager
|
package gonetworkmanager
|
||||||
|
|
||||||
import "fmt"
|
import "strconv"
|
||||||
|
|
||||||
const _NmDeviceState_name = "NmDeviceStateUnknownNmDeviceStateUnmanagedNmDeviceStateUnavailableNmDeviceStateDisconnectedNmDeviceStatePrepareNmDeviceStateConfigNmDeviceStateNeed_authNmDeviceStateIp_configNmDeviceStateIp_checkNmDeviceStateSecondariesNmDeviceStateActivatedNmDeviceStateDeactivatingNmDeviceStateFailed"
|
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{
|
var _NmDeviceState_map = map[NmDeviceState]string{
|
||||||
0: _NmDeviceState_name[0:20],
|
0: _NmDeviceState_name[0:20],
|
||||||
|
@ -13,18 +32,18 @@ var _NmDeviceState_map = map[NmDeviceState]string{
|
||||||
30: _NmDeviceState_name[66:91],
|
30: _NmDeviceState_name[66:91],
|
||||||
40: _NmDeviceState_name[91:111],
|
40: _NmDeviceState_name[91:111],
|
||||||
50: _NmDeviceState_name[111:130],
|
50: _NmDeviceState_name[111:130],
|
||||||
60: _NmDeviceState_name[130:152],
|
60: _NmDeviceState_name[130:151],
|
||||||
70: _NmDeviceState_name[152:174],
|
70: _NmDeviceState_name[151:172],
|
||||||
80: _NmDeviceState_name[174:195],
|
80: _NmDeviceState_name[172:192],
|
||||||
90: _NmDeviceState_name[195:219],
|
90: _NmDeviceState_name[192:216],
|
||||||
100: _NmDeviceState_name[219:241],
|
100: _NmDeviceState_name[216:238],
|
||||||
110: _NmDeviceState_name[241:266],
|
110: _NmDeviceState_name[238:263],
|
||||||
120: _NmDeviceState_name[266:285],
|
120: _NmDeviceState_name[263:282],
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i NmDeviceState) String() string {
|
func (i NmDeviceState) String() string {
|
||||||
if str, ok := _NmDeviceState_map[i]; ok {
|
if str, ok := _NmDeviceState_map[i]; ok {
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("NmDeviceState(%d)", i)
|
return "NmDeviceState(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,53 @@
|
||||||
// Code generated by "stringer -type=NmDeviceType"; DO NOT EDIT
|
// Code generated by "stringer -type=NmDeviceType"; DO NOT EDIT.
|
||||||
|
|
||||||
package gonetworkmanager
|
package gonetworkmanager
|
||||||
|
|
||||||
import "fmt"
|
import "strconv"
|
||||||
|
|
||||||
const _NmDeviceType_name = "NmDeviceTypeUnknownNmDeviceTypeEthernetNmDeviceTypeWifiNmDeviceTypeUnused1NmDeviceTypeUnused2NmDeviceTypeBtNmDeviceTypeOlpcMeshNmDeviceTypeWimaxNmDeviceTypeModemNmDeviceTypeInfinibandNmDeviceTypeBondNmDeviceTypeVlanNmDeviceTypeAdslNmDeviceTypeBridgeNmDeviceTypeGenericNmDeviceTypeTeam"
|
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]
|
||||||
|
}
|
||||||
|
|
||||||
var _NmDeviceType_index = [...]uint16{0, 19, 39, 55, 74, 93, 107, 127, 144, 161, 183, 199, 215, 231, 249, 268, 284}
|
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 {
|
func (i NmDeviceType) String() string {
|
||||||
if i >= NmDeviceType(len(_NmDeviceType_index)-1) {
|
if i >= NmDeviceType(len(_NmDeviceType_index)-1) {
|
||||||
return fmt.Sprintf("NmDeviceType(%d)", i)
|
return "NmDeviceType(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
}
|
}
|
||||||
return _NmDeviceType_name[_NmDeviceType_index[i]:_NmDeviceType_index[i+1]]
|
return _NmDeviceType_name[_NmDeviceType_index[i]:_NmDeviceType_index[i+1]]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,22 @@
|
||||||
// Code generated by "stringer -type=NmState"; DO NOT EDIT
|
// Code generated by "stringer -type=NmState"; DO NOT EDIT.
|
||||||
|
|
||||||
package gonetworkmanager
|
package gonetworkmanager
|
||||||
|
|
||||||
import "fmt"
|
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 (
|
const (
|
||||||
_NmState_name_0 = "NmStateUnknown"
|
_NmState_name_0 = "NmStateUnknown"
|
||||||
|
@ -15,17 +29,6 @@ const (
|
||||||
_NmState_name_7 = "NmStateConnectedGlobal"
|
_NmState_name_7 = "NmStateConnectedGlobal"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
_NmState_index_0 = [...]uint8{0, 14}
|
|
||||||
_NmState_index_1 = [...]uint8{0, 13}
|
|
||||||
_NmState_index_2 = [...]uint8{0, 19}
|
|
||||||
_NmState_index_3 = [...]uint8{0, 20}
|
|
||||||
_NmState_index_4 = [...]uint8{0, 17}
|
|
||||||
_NmState_index_5 = [...]uint8{0, 21}
|
|
||||||
_NmState_index_6 = [...]uint8{0, 20}
|
|
||||||
_NmState_index_7 = [...]uint8{0, 22}
|
|
||||||
)
|
|
||||||
|
|
||||||
func (i NmState) String() string {
|
func (i NmState) String() string {
|
||||||
switch {
|
switch {
|
||||||
case i == 0:
|
case i == 0:
|
||||||
|
@ -45,6 +48,6 @@ func (i NmState) String() string {
|
||||||
case i == 70:
|
case i == 70:
|
||||||
return _NmState_name_7
|
return _NmState_name_7
|
||||||
default:
|
default:
|
||||||
return fmt.Sprintf("NmState(%d)", i)
|
return "NmState(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
15
utils.go
15
utils.go
|
@ -58,7 +58,7 @@ func (d *dbusBase) getProperty(iface string) (interface{}, error) {
|
||||||
return variant.Value(), err
|
return variant.Value(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dbusBase) setProperty(iface string, value interface{}) (error) {
|
func (d *dbusBase) setProperty(iface string, value interface{}) error {
|
||||||
err := d.obj.SetProperty(iface, dbus.MakeVariant(value))
|
err := d.obj.SetProperty(iface, dbus.MakeVariant(value))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -180,6 +180,19 @@ func (d *dbusBase) getUint32Property(iface string) (value uint32, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *dbusBase) getInt32Property(iface string) (value int32, err error) {
|
||||||
|
prop, err := d.getProperty(iface)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
value, ok := prop.(int32)
|
||||||
|
if !ok {
|
||||||
|
err = makeErrVariantType(iface)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (d *dbusBase) getInt64Property(iface string) (value int64, err error) {
|
func (d *dbusBase) getInt64Property(iface string) (value int64, err error) {
|
||||||
prop, err := d.getProperty(iface)
|
prop, err := d.getProperty(iface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Reference in a new issue