@@ 15,29 15,21 @@ import (
)
// From: https://networkmanager.dev/docs/api/latest/nm-dbus-types.html
-const (
- // Note: commented out so that staticcheck passes, but leaving since it was
- // mildly annoying to copy/paste this here and these will probably(?) be
- // used in the future.
- // nm_device_type_ethernet uint32 = 1
- // nm_device_type_wifi uint32 = 2
- // nm_device_type_modem uint32 = 8
- // nm_device_type_wireguard uint32 = 29
-
- nm_device_state_unknown uint32 = 0
- nm_device_state_unmanaged uint32 = 10
- nm_device_state_unavailable uint32 = 20
- nm_device_state_disconnected uint32 = 30
- nm_device_state_prepare uint32 = 40
- nm_device_state_config uint32 = 50
- nm_device_state_need_auth uint32 = 60
- nm_device_state_ip_config uint32 = 70
- nm_device_state_ip_check uint32 = 80
- nm_device_state_secondaries uint32 = 90
- nm_device_state_activated uint32 = 100
- nm_device_state_deactivating uint32 = 110
- nm_device_state_failed uint32 = 120
-)
+var nm_states map[uint32]string = map[uint32]string{
+ 0: "NM_DEVICE_STATE_UNKNOWN",
+ 10: "NM_DEVICE_STATE_UNMANAGED",
+ 20: "NM_DEVICE_STATE_UNAVAILABLE",
+ 30: "NM_DEVICE_STATE_DISCONNECTED",
+ 40: "NM_DEVICE_STATE_PREPARE",
+ 50: "NM_DEVICE_STATE_CONFIG",
+ 60: "NM_DEVICE_STATE_NEED_AUTH",
+ 70: "NM_DEVICE_STATE_IP_CONFIG",
+ 80: "NM_DEVICE_STATE_IP_CHECK",
+ 90: "NM_DEVICE_STATE_SECONDARIES",
+ 100: "NM_DEVICE_STATE_ACTIVATED",
+ 110: "NM_DEVICE_STATE_DEACTIVATING",
+ 120: "NM_DEVICE_STATE_FAILED",
+}
type NetMan struct {
ns chan NSMsg
@@ 107,14 99,14 @@ func (n *NetMan) signalHandler(sig *dbus.Signal) {
// signals...
newState := sig.Body[0].(uint32)
- switch newState {
- case nm_device_state_activated:
+ switch nm_states[newState] {
+ case "NM_DEVICE_STATE_ACTIVATED":
fallthrough
- case nm_device_state_unmanaged:
+ case "NM_DEVICE_STATE_UNMANAGED":
// sometimes connections enter this state while another "up" connection
// exists, so make sure DNS is refreshed
fallthrough
- case nm_device_state_unavailable:
+ case "NM_DEVICE_STATE_UNAVAILABLE":
select {
case <-time.After(500 * time.Millisecond):
n.log.Println("netman: timed out trying to send latest list of nameservers")