forked from Wifx/gonetworkmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActiveConnection.go
213 lines (173 loc) · 6.84 KB
/
ActiveConnection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
package gonetworkmanager
import (
"github.com/godbus/dbus/v5"
)
const (
ActiveConnectionInterface = NetworkManagerInterface + ".Connection.Active"
/* Properties */
ActiveConnectionPropertyConnection = ActiveConnectionInterface + ".Connection" // readable o
ActiveConnectionPropertySpecificObject = ActiveConnectionInterface + ".SpecificObject" // readable o
ActiveConnectionPropertyId = ActiveConnectionInterface + ".Id" // readable s
ActiveConnectionPropertyUuid = ActiveConnectionInterface + ".Uuid" // readable s
ActiveConnectionPropertyType = ActiveConnectionInterface + ".Type" // readable s
ActiveConnectionPropertyDevices = ActiveConnectionInterface + ".Devices" // readable ao
ActiveConnectionPropertyState = ActiveConnectionInterface + ".State" // readable u
ActiveConnectionPropertyStateFlags = ActiveConnectionInterface + ".StateFlags" // readable u
ActiveConnectionPropertyDefault = ActiveConnectionInterface + ".Default" // readable b
ActiveConnectionPropertyIp4Config = ActiveConnectionInterface + ".Ip4Config" // readable o
ActiveConnectionPropertyDhcp4Config = ActiveConnectionInterface + ".Dhcp4Config" // readable o
ActiveConnectionPropertyDefault6 = ActiveConnectionInterface + ".Default6" // readable b
ActiveConnectionPropertyIp6Config = ActiveConnectionInterface + ".Ip6Config" // readable o
ActiveConnectionPropertyDhcp6Config = ActiveConnectionInterface + ".Dhcp6Config" // readable o
ActiveConnectionPropertyVpn = ActiveConnectionInterface + ".Vpn" // readable b
ActiveConnectionPropertyMaster = ActiveConnectionInterface + ".Master" // readable o
)
type ActiveConnection interface {
GetPath() dbus.ObjectPath
// GetConnectionSettings gets connection object of the connection.
GetPropertyConnection() (Connection, error)
// GetSpecificObject gets a specific object associated with the active connection.
GetPropertySpecificObject() (AccessPoint, error)
// GetID gets the ID of the connection.
GetPropertyID() (string, error)
// GetUUID gets the UUID of the connection.
GetPropertyUUID() (string, error)
// GetType gets the type of the connection.
GetPropertyType() (string, error)
// GetDevices gets array of device objects which are part of this active connection.
GetPropertyDevices() ([]Device, error)
// GetState gets the state of the connection.
GetPropertyState() (NmActiveConnectionState, error)
// GetStateFlags gets the state flags of the connection.
GetPropertyStateFlags() (uint32, error)
// GetDefault gets the default IPv4 flag of the connection.
GetPropertyDefault() (bool, error)
// GetIP4Config gets the IP4Config of the connection.
GetPropertyIP4Config() (IP4Config, error)
// GetDHCP4Config gets the DHCP6Config of the connection.
GetPropertyDHCP4Config() (DHCP4Config, error)
// GetDefault gets the default IPv6 flag of the connection.
GetPropertyDefault6() (bool, error)
// GetIP6Config gets the IP6Config of the connection.
GetPropertyIP6Config() (IP6Config, error)
// GetDHCP6Config gets the DHCP4Config of the connection.
GetPropertyDHCP6Config() (DHCP6Config, error)
// GetVPN gets the VPN flag of the connection.
GetPropertyVPN() (bool, error)
// GetMaster gets the master device of the connection.
GetPropertyMaster() (Device, error)
}
func NewActiveConnection(objectPath dbus.ObjectPath) (ActiveConnection, error) {
var a activeConnection
return &a, a.init(NetworkManagerInterface, objectPath)
}
type activeConnection struct {
dbusBase
}
func (a *activeConnection) GetPath() dbus.ObjectPath {
return a.obj.Path()
}
func (a *activeConnection) GetPropertyConnection() (Connection, error) {
path, err := a.getObjectProperty(ActiveConnectionPropertyConnection)
if err != nil {
return nil, err
}
con, err := NewConnection(path)
if err != nil {
return nil, err
}
return con, nil
}
func (a *activeConnection) GetPropertySpecificObject() (AccessPoint, error) {
path, err := a.getObjectProperty(ActiveConnectionPropertySpecificObject)
if err != nil {
return nil, err
}
ap, err := NewAccessPoint(path)
if err != nil {
return nil, err
}
return ap, nil
}
func (a *activeConnection) GetPropertyID() (string, error) {
return a.getStringProperty(ActiveConnectionPropertyId)
}
func (a *activeConnection) GetPropertyUUID() (string, error) {
return a.getStringProperty(ActiveConnectionPropertyUuid)
}
func (a *activeConnection) GetPropertyType() (string, error) {
return a.getStringProperty(ActiveConnectionPropertyType)
}
func (a *activeConnection) GetPropertyDevices() ([]Device, error) {
paths, err := a.getSliceObjectProperty(ActiveConnectionPropertyDevices)
if err != nil {
return nil, err
}
devices := make([]Device, len(paths))
for i, path := range paths {
devices[i], err = DeviceFactory(path)
if err != nil {
return nil, err
}
}
return devices, nil
}
func (a *activeConnection) GetPropertyState() (NmActiveConnectionState, error) {
v, err := a.getUint32Property(ActiveConnectionPropertyState)
return NmActiveConnectionState(v), err
}
func (a *activeConnection) GetPropertyStateFlags() (uint32, error) {
return a.getUint32Property(ActiveConnectionPropertyStateFlags)
}
func (a *activeConnection) GetPropertyDefault() (bool, error) {
b, err := a.getProperty(ActiveConnectionPropertyDefault)
if err != nil {
return false, err
}
return b.(bool), nil
}
func (a *activeConnection) GetPropertyIP4Config() (IP4Config, error) {
path, err := a.getObjectProperty(ActiveConnectionPropertyIp4Config)
if err != nil || path == "/" {
return nil, err
}
return NewIP4Config(path)
}
func (a *activeConnection) GetPropertyDHCP4Config() (DHCP4Config, error) {
path, err := a.getObjectProperty(ActiveConnectionPropertyDhcp4Config)
if err != nil || path == "/" {
return nil, err
}
return NewDHCP4Config(path)
}
func (a *activeConnection) GetPropertyDefault6() (bool, error) {
return a.getBoolProperty(ActiveConnectionPropertyDefault6)
}
func (a *activeConnection) GetPropertyIP6Config() (IP6Config, error) {
path, err := a.getObjectProperty(ActiveConnectionPropertyIp6Config)
if err != nil || path == "/" {
return nil, err
}
return NewIP6Config(path)
}
func (a *activeConnection) GetPropertyDHCP6Config() (DHCP6Config, error) {
path, err := a.getObjectProperty(ActiveConnectionPropertyDhcp6Config)
if err != nil || path == "/" {
return nil, err
}
return NewDHCP6Config(path)
}
func (a *activeConnection) GetPropertyVPN() (bool, error) {
ret, err := a.getProperty(ActiveConnectionPropertyVpn)
if err != nil {
return false, err
}
return ret.(bool), nil
}
func (a *activeConnection) GetPropertyMaster() (Device, error) {
path, err := a.getObjectProperty(ActiveConnectionPropertyMaster)
if err != nil || path == "/" {
return nil, err
}
return DeviceFactory(path)
}