Closed cmbbr closed 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"?
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.
It's been a while I didn't developped with nm, but I'll do my best to help.
nmcli con show <con>
Hi, thanks for your help.
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)
I clsoe this issue as it does not appears to be a bug. If you need help, please open a Q/A disucssion.
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.
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.
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