Get configuration returned by the IPv4 DHCP server.
This commit is contained in:
parent
e9eb8e5842
commit
394a1ac2cd
3 changed files with 77 additions and 0 deletions
48
DHCP4Config.go
Normal file
48
DHCP4Config.go
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
package gonetworkmanager
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/godbus/dbus"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DHCP4ConfigInterface = NetworkManagerInterface + ".DHCP4Config"
|
||||||
|
|
||||||
|
DHCP4ConfigPropertyOptions = DHCP4ConfigInterface + ".Options"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DHCP4Options map[string]interface{}
|
||||||
|
|
||||||
|
type DHCP4Config interface {
|
||||||
|
// GetOptions gets options map of configuration returned by the IPv4 DHCP server.
|
||||||
|
GetOptions() DHCP4Options
|
||||||
|
|
||||||
|
MarshalJSON() ([]byte, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDHCP4Config(objectPath dbus.ObjectPath) (DHCP4Config, error) {
|
||||||
|
var c dhcp4Config
|
||||||
|
return &c, c.init(NetworkManagerInterface, objectPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
type dhcp4Config struct {
|
||||||
|
dbusBase
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *dhcp4Config) GetOptions() DHCP4Options {
|
||||||
|
options := c.getMapStringVariantProperty(DHCP4ConfigPropertyOptions)
|
||||||
|
rv := make(DHCP4Options)
|
||||||
|
|
||||||
|
for k, v := range options {
|
||||||
|
rv[k] = v.Value()
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *dhcp4Config) MarshalJSON() ([]byte, error) {
|
||||||
|
return json.Marshal(map[string]interface{}{
|
||||||
|
"Options": c.GetOptions(),
|
||||||
|
})
|
||||||
|
}
|
21
Device.go
21
Device.go
|
@ -14,6 +14,7 @@ const (
|
||||||
DevicePropertyIP4Config = DeviceInterface + ".Ip4Config"
|
DevicePropertyIP4Config = DeviceInterface + ".Ip4Config"
|
||||||
DevicePropertyDeviceType = DeviceInterface + ".DeviceType"
|
DevicePropertyDeviceType = DeviceInterface + ".DeviceType"
|
||||||
DevicePropertyAvailableConnections = DeviceInterface + ".AvailableConnections"
|
DevicePropertyAvailableConnections = DeviceInterface + ".AvailableConnections"
|
||||||
|
DevicePropertyDhcp4Config = DeviceInterface + ".Dhcp4Config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeviceFactory(objectPath dbus.ObjectPath) (Device, error) {
|
func DeviceFactory(objectPath dbus.ObjectPath) (Device, error) {
|
||||||
|
@ -43,6 +44,11 @@ type Device interface {
|
||||||
// state.
|
// state.
|
||||||
GetIP4Config() IP4Config
|
GetIP4Config() IP4Config
|
||||||
|
|
||||||
|
// GetDHCP4Config gets the Dhcp4Config object describing the configuration of the
|
||||||
|
// device. Only valid when the device is in the NM_DEVICE_STATE_ACTIVATED
|
||||||
|
// state.
|
||||||
|
GetDHCP4Config() DHCP4Config
|
||||||
|
|
||||||
// GetDeviceType gets the general type of the network device; ie Ethernet,
|
// GetDeviceType gets the general type of the network device; ie Ethernet,
|
||||||
// WiFi, etc.
|
// WiFi, etc.
|
||||||
GetDeviceType() NmDeviceType
|
GetDeviceType() NmDeviceType
|
||||||
|
@ -85,6 +91,20 @@ func (d *device) GetIP4Config() IP4Config {
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *device) GetDHCP4Config() DHCP4Config {
|
||||||
|
path := d.getObjectProperty(DevicePropertyDhcp4Config)
|
||||||
|
if path == "/" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg, err := NewDHCP4Config(path)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
|
|
||||||
func (d *device) GetDeviceType() NmDeviceType {
|
func (d *device) GetDeviceType() NmDeviceType {
|
||||||
return NmDeviceType(d.getUint32Property(DevicePropertyDeviceType))
|
return NmDeviceType(d.getUint32Property(DevicePropertyDeviceType))
|
||||||
}
|
}
|
||||||
|
@ -109,6 +129,7 @@ func (d *device) marshalMap() map[string]interface{} {
|
||||||
"Interface": d.GetInterface(),
|
"Interface": d.GetInterface(),
|
||||||
"State": d.GetState().String(),
|
"State": d.GetState().String(),
|
||||||
"IP4Config": d.GetIP4Config(),
|
"IP4Config": d.GetIP4Config(),
|
||||||
|
"DHCP4Config": d.GetDHCP4Config(),
|
||||||
"DeviceType": d.GetDeviceType().String(),
|
"DeviceType": d.GetDeviceType().String(),
|
||||||
"AvailableConnections": d.GetAvailableConnections(),
|
"AvailableConnections": d.GetAvailableConnections(),
|
||||||
}
|
}
|
||||||
|
|
8
utils.go
8
utils.go
|
@ -92,6 +92,14 @@ func (d *dbusBase) getSliceStringProperty(iface string) []string {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *dbusBase) getMapStringVariantProperty(iface string) map[string]dbus.Variant {
|
||||||
|
value, ok := d.getProperty(iface).(map[string]dbus.Variant)
|
||||||
|
if !ok {
|
||||||
|
panic(makeErrVariantType(iface))
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
func (d *dbusBase) getUint8Property(iface string) uint8 {
|
func (d *dbusBase) getUint8Property(iface string) uint8 {
|
||||||
value, ok := d.getProperty(iface).(uint8)
|
value, ok := d.getProperty(iface).(uint8)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
Reference in a new issue