Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Device.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ func DeviceFactory(objectPath dbus.ObjectPath) (Device, error) {
return NewDeviceWired(objectPath)
case NmDeviceTypeWifi:
return NewDeviceWireless(objectPath)
case NmDeviceTypeVlan:
return NewDeviceVlan(objectPath)
}

return d, nil
Expand Down
69 changes: 69 additions & 0 deletions DeviceVlan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package gonetworkmanager

import (
"encoding/json"

"github.com/godbus/dbus/v5"
)

const (
DeviceVlanInterface = DeviceInterface + ".Vlan"

// Properties
DeviceVlanPropertyCarrier = DeviceVlanInterface + ".Carrier" // readable b
DeviceVlanPropertyParent = DeviceVlanInterface + ".Parent" // readable o
DeviceVlanPropertyVlanId = DeviceVlanInterface + ".VlanId" // readable u
)

// DeviceVlan Virtual LAN Device
type DeviceVlan interface {
Device

// GetPropertyCarrier Indicates whether the physical carrier is found (e.g. whether a cable is plugged in or not).
// DEPRECATED: check for the "carrier" flag in the "InterfaceFlags" property on the "org.freedesktop.NetworkManager.Device" interface.
GetPropertyCarrier() (bool, error)

// GetPropertyParent The object path of the parent device.
GetPropertyParent() (Device, error)

// GetPropertyVlanId The VLAN ID of this VLAN interface
GetPropertyVlanId() (uint32, error)
}

func NewDeviceVlan(objectPath dbus.ObjectPath) (DeviceVlan, error) {
var d deviceVlan
return &d, d.init(NetworkManagerInterface, objectPath)
}

type deviceVlan struct {
device
}

func (d *deviceVlan) GetPropertyParent() (Device, error) {
path, err := d.getObjectProperty(DeviceVlanPropertyParent)
if err != nil || path == "/" {
return nil, err
}
return DeviceFactory(path)
}

func (d *deviceVlan) GetPropertyVlanId() (uint32, error) {
return d.getUint32Property(DeviceVlanPropertyVlanId)
}

func (d *deviceVlan) GetPropertyCarrier() (bool, error) {
return d.getBoolProperty(DeviceVlanPropertyCarrier)
}

func (d *deviceVlan) MarshalJSON() ([]byte, error) {
m, err := d.device.marshalMap()
if err != nil {
return nil, err
}

m["HwAddress"], _ = d.GetPropertyHwAddress()
m["Parent"], _ = d.GetPropertyParent()
m["Carrier"], _ = d.GetPropertyCarrier()
m["VlanId"], _ = d.GetPropertyVlanId()
return json.Marshal(m)
}