Wifx / gonetworkmanager

Go D-Bus bindings for NetworkManager
Other
96 stars 42 forks source link

Cannot set ipv4 routes property #34

Closed cmbbr closed 1 year ago

cmbbr commented 1 year ago

I'm currently working with this library to manage the connections on my Raspberry. I'm able to add and activate a connection with no problem. image

However, eventhough I'm able to update some fields of the connection previously created like id, route-metric, etc. I can't seem to set new "ipv4.routes".

I have tried updating "routes" and "route-data" but none of them had any effect on my connection.

image

Am I missing something? Is there any other property I need to change in order to be able to set the routes?

Thank you in advance

mullerch commented 1 year ago

What's your version of nm ? "routes" is deprecated, you should use route-data insted. Please update your example and paste it as code.

How do you check the "effect"?

cmbbr commented 1 year ago

NM version is 1.32.10

Here's the example where I use route-data


import (
    "fmt"
    "github.com/Wifx/gonetworkmanager"
)

const (
    ethernetType = "802-3-ethernet"
)

func main() {
    /* New network manager instance */
    networkManager, _ := gonetworkmanager.NewNetworkManager()
    settings, _ := gonetworkmanager.NewSettings()

    /* New connection */
    connection := make(map[string]map[string]interface{})
    connection["connection"] = make(map[string]interface{})
    connection["connection"]["id"] = "myeth"
    connection["connection"]["type"] = ethernetType

    /* Add connection */
    connAdded, err := settings.AddConnection(connection)
    if err != nil {
        fmt.Println(err)
        return
    }

    /* Update route-data property */
    routeData := make([]map[string]interface{}, 1)
    routeData[0] = make(map[string]interface{})
    routeData[0]["dest"] = "10.39.3.0"
    routeData[0]["prefix"] = 24
    routeData[0]["next-hop"] = "192.168.100.1"

    updateConnectionError := connAdded.Update(gonetworkmanager.ConnectionSettings{
        "connection": map[string]interface{}{
            "id":   "myeth2",
            "type": ethernetType,
        },
        "ipv4": map[string]interface{}{
            "route-metric": 2,
            "method":       "auto",
            "route-data":   routeData,
        },
    })

    if updateConnectionError != nil {
        fmt.Println(updateConnectionError)
        return
    }

    /* Get devices */
    devicesList, _ := networkManager.GetPropertyAllDevices()
    for _, device := range devicesList {
        deviceType, _ := device.GetPropertyDeviceType()
        fmt.Println(deviceType)
        if deviceType.String() == "NmDeviceTypeEthernet" {
            _, _ = networkManager.ActivateConnection(connAdded, device, nil)
        }
    }
}

I check the "effect" like I do when I add routes manually using nmcli. I use the command route inside my device and I also do nmcli c show on my connection and none of them show the route I added in my example.

mullerch commented 1 year ago

It's been a while I didn't developped with nm, but I'll do my best to help.

  1. Updating a route with gonetworkmaanger (latest) and nm 1.28 using route-data works, I've just tested it in a similar way.
    • The file on disk (/etc/NetworkManager/...) gets updated (when using Update)
    • Changes are visible with nmcli con show <con>
  2. I would not try to change the connection id on the update operation if the goal is to test routes settings update only
cmbbr commented 1 year ago

Hi, thanks for your help.

  1. I now have nm 1.28 version but still not getting any results on changing the routes. Did you run my code in your test or was it a different example? And if so, could you share the differences?
  2. Ok, that part's removed now
mullerch commented 1 year ago

I run my own code. I don't add and update, just an update of an existing connection. I can't help much more. You should just go on with debugging: simplify the code, split the steps (maybe adding and updating straight after needs temporization), validate your data (with nmcli)

mullerch commented 1 year ago

I clsoe this issue as it does not appears to be a bug. If you need help, please open a Q/A disucssion.