diff --git a/ActiveConnection.go b/ActiveConnection.go index e7c3018..c24bb31 100644 --- a/ActiveConnection.go +++ b/ActiveConnection.go @@ -67,7 +67,7 @@ type ActiveConnection interface { GetIP6Config() IP6Config // GetDHCP6Config gets the DHCP4Config of the connection. - //GetDHCP6Config() DHCP6Config + GetDHCP6Config() DHCP6Config // GetVPN gets the VPN flag of the connection. GetVPN() bool @@ -185,18 +185,18 @@ func (a *activeConnection) GetIP6Config() IP6Config { return r } -//func (a *activeConnection) GetDHCP6Config() DHCP6Config { -// path := a.getObjectProperty(ActiveConnectionPropertyDhcp6Config) -// if path == "/" { -// return nil -// } +func (a *activeConnection) GetDHCP6Config() DHCP6Config { + path := a.getObjectProperty(ActiveConnectionPropertyDhcp6Config) + if path == "/" { + return nil + } -// r, err := NewDHCP6Config(path) -// if err != nil { -// panic(err) -// } -// return r -//} + r, err := NewDHCP6Config(path) + if err != nil { + panic(err) + } + return r +} func (a *activeConnection) GetVPN() bool { ret := a.getProperty(ActiveConnectionPropertyVpn) diff --git a/DHCP6Config.go b/DHCP6Config.go new file mode 100644 index 0000000..c5ba383 --- /dev/null +++ b/DHCP6Config.go @@ -0,0 +1,48 @@ +package gonetworkmanager + +import ( + "encoding/json" + + "github.com/godbus/dbus" +) + +const ( + DHCP6ConfigInterface = NetworkManagerInterface + ".DHCP6Config" + + DHCP6ConfigPropertyOptions = DHCP6ConfigInterface + ".Options" +) + +type DHCP6Options map[string]interface{} + +type DHCP6Config interface { + // GetOptions gets options map of configuration returned by the IPv4 DHCP server. + GetOptions() DHCP6Options + + MarshalJSON() ([]byte, error) +} + +func NewDHCP6Config(objectPath dbus.ObjectPath) (DHCP6Config, error) { + var c dhcp6Config + return &c, c.init(NetworkManagerInterface, objectPath) +} + +type dhcp6Config struct { + dbusBase +} + +func (c *dhcp6Config) GetOptions() DHCP6Options { + options := c.getMapStringVariantProperty(DHCP6ConfigPropertyOptions) + rv := make(DHCP6Options) + + for k, v := range options { + rv[k] = v.Value() + } + + return rv +} + +func (c *dhcp6Config) MarshalJSON() ([]byte, error) { + return json.Marshal(map[string]interface{}{ + "Options": c.GetOptions(), + }) +}