forked from Wifx/gonetworkmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeviceIpTunnel.go
150 lines (115 loc) · 5.16 KB
/
DeviceIpTunnel.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
package gonetworkmanager
import (
"encoding/json"
"github.com/godbus/dbus/v5"
)
const (
DeviceIpTunnelInterface = DeviceInterface + ".IPTunnel"
// Properties
DeviceIpTunnelPropertyHwAddress = DeviceIpTunnelInterface + "HwAddress" // readable s
DeviceIpTunnelPropertyMode = DeviceIpTunnelInterface + ".Mode" // readable u
DeviceIpTunnelPropertyParent = DeviceIpTunnelInterface + ".Parent" // readable o
DeviceIpTunnelPropertyLocal = DeviceIpTunnelInterface + ".Local" // readable s
DeviceIpTunnelPropertyRemote = DeviceIpTunnelInterface + ".Remote" // readable s
DeviceIpTunnelPropertyTtl = DeviceIpTunnelInterface + ".Ttl" // readable y
DeviceIpTunnelPropertyTos = DeviceIpTunnelInterface + ".Tos" // readable y
DeviceIpTunnelPropertyPathMtuDiscovery = DeviceIpTunnelInterface + ".PathMtuDiscovery" // readable b
DeviceIpTunnelPropertyInputKey = DeviceIpTunnelInterface + ".InputKey" // readable s
DeviceIpTunnelPropertyOutputKey = DeviceIpTunnelInterface + ".OutputKey" // readable s
DeviceIpTunnelPropertyEncapsulationLimit = DeviceIpTunnelInterface + ".EncapsulationLimit" // readable y
DeviceIpTunnelPropertyFlowLabel = DeviceIpTunnelInterface + ".FlowLabel" // readable u
DeviceIpTunnelPropertyFlags = DeviceIpTunnelInterface + ".Flags" // readable u
)
type DeviceIpTunnel interface {
Device
// The tunneling mode
GetPropertyMode() (uint32, error)
// The object path of the parent device.
GetPropertyParent() (Device, error)
// The local endpoint of the tunnel.
GetPropertyLocal() (string, error)
// The remote endpoint of the tunnel.
GetPropertyRemote() (string, error)
// The TTL assigned to tunneled packets. 0 is a special value meaning that packets inherit the TTL value
GetPropertyTtl() (uint8, error)
// The type of service (IPv4) or traffic class (IPv6) assigned to tunneled packets.
GetPropertyTos() (uint8, error)
// Whether path MTU discovery is enabled on this tunnel.
GetPropertyPathMtuDiscovery() (bool, error)
// The key used for incoming packets.
GetPropertyInputKey() (string, error)
// The key used for outgoing packets.
GetPropertyOutputKey() (string, error)
// How many additional levels of encapsulation are permitted to be prepended to packets. This property applies only to IPv6 tunnels.
GetPropertyEncapsulationLimit() (uint8, error)
// The flow label to assign to tunnel packets. This property applies only to IPv6 tunnels.
GetPropertyFlowLabel() (uint32, error)
// Tunnel flags.
GetPropertyFlags() (uint32, error)
}
func NewDeviceIpTunnel(objectPath dbus.ObjectPath) (DeviceIpTunnel, error) {
var d deviceIpTunnel
return &d, d.init(NetworkManagerInterface, objectPath)
}
type deviceIpTunnel struct {
device
}
func (d *deviceIpTunnel) GetPropertyMode() (uint32, error) {
return d.getUint32Property(DeviceIpTunnelPropertyMode)
}
func (d *deviceIpTunnel) GetPropertyParent() (Device, error) {
path, err := d.getObjectProperty(DeviceIpTunnelPropertyParent)
if err != nil || path == "/" {
return nil, err
}
return DeviceFactory(path)
}
func (d *deviceIpTunnel) GetPropertyLocal() (string, error) {
return d.getStringProperty(DeviceIpTunnelPropertyLocal)
}
func (d *deviceIpTunnel) GetPropertyRemote() (string, error) {
return d.getStringProperty(DeviceIpTunnelPropertyRemote)
}
func (d *deviceIpTunnel) GetPropertyTtl() (uint8, error) {
return d.getUint8Property(DeviceIpTunnelPropertyTtl)
}
func (d *deviceIpTunnel) GetPropertyTos() (uint8, error) {
return d.getUint8Property(DeviceIpTunnelPropertyTos)
}
func (d *deviceIpTunnel) GetPropertyPathMtuDiscovery() (bool, error) {
return d.getBoolProperty(DeviceIpTunnelPropertyPathMtuDiscovery)
}
func (d *deviceIpTunnel) GetPropertyInputKey() (string, error) {
return d.getStringProperty(DeviceIpTunnelPropertyInputKey)
}
func (d *deviceIpTunnel) GetPropertyOutputKey() (string, error) {
return d.getStringProperty(DeviceIpTunnelPropertyOutputKey)
}
func (d *deviceIpTunnel) GetPropertyEncapsulationLimit() (uint8, error) {
return d.getUint8Property(DeviceIpTunnelPropertyEncapsulationLimit)
}
func (d *deviceIpTunnel) GetPropertyFlowLabel() (uint32, error) {
return d.getUint32Property(DeviceIpTunnelPropertyFlowLabel)
}
func (d *deviceIpTunnel) GetPropertyFlags() (uint32, error) {
return d.getUint32Property(DeviceIpTunnelPropertyFlags)
}
func (d *deviceIpTunnel) MarshalJSON() ([]uint8, error) {
m, err := d.device.marshalMap()
if err != nil {
return nil, err
}
m["Mode"], _ = d.GetPropertyMode()
m["Parent"], _ = d.GetPropertyParent()
m["Local"], _ = d.GetPropertyLocal()
m["Remote"], _ = d.GetPropertyRemote()
m["Ttl"], _ = d.GetPropertyTtl()
m["Tos"], _ = d.GetPropertyTos()
m["PathMtuDiscovery"], _ = d.GetPropertyPathMtuDiscovery()
m["InputKey"], _ = d.GetPropertyInputKey()
m["OutputKey"], _ = d.GetPropertyOutputKey()
m["EncapsulationLimit"], _ = d.GetPropertyEncapsulationLimit()
m["FlowLabel"], _ = d.GetPropertyFlowLabel()
m["Flags"], _ = d.GetPropertyFlags()
return json.Marshal(m)
}