1
1
package utils
2
2
3
3
import (
4
- "encoding/json"
5
4
"fmt"
6
5
"net"
7
6
"os/exec"
7
+
8
+ "gopkg.in/yaml.v2"
8
9
)
9
10
10
11
type VXLANInterface struct {
@@ -13,12 +14,12 @@ type VXLANInterface struct {
13
14
}
14
15
15
16
var ipLinks []struct {
16
- IfName string `json:"ifname"`
17
+ IfName string `json:"ifname" yaml:"ifname" `
17
18
LinkInfo struct {
18
19
InfoData struct {
19
- Port * int `json:"port"`
20
- } `json:"info_data"`
21
- } `json:"linkinfo"`
20
+ Port * int `json:"port" yaml:"port" `
21
+ } `json:"info_data" yaml:"info_data" `
22
+ } `json:"linkinfo" yaml:"linkinfo" `
22
23
}
23
24
24
25
func ListVXLANInterfaces () ([]VXLANInterface , error ) {
@@ -30,7 +31,12 @@ func ListVXLANInterfaces() ([]VXLANInterface, error) {
30
31
return vxlanDevices , fmt .Errorf ("running ip command failed: %s" , string (out ))
31
32
}
32
33
33
- if err := json .Unmarshal (out , & ipLinks ); err != nil {
34
+ // NOTE: (mateoflorido) Parsing as YAML cleans up invalid JSON output
35
+ // produced by the iproute2 command in arm64. Currently, the Ubuntu package
36
+ // combines the VXLAN VNI value with the fan-map extension, resulting in
37
+ // invalid JSON, but a valid YAML.
38
+ // https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2121908
39
+ if err := yaml .Unmarshal (out , & ipLinks ); err != nil {
34
40
return vxlanDevices , fmt .Errorf ("unmarshaling ip command output failed: %w" , err )
35
41
}
36
42
0 commit comments