5
5
"fmt"
6
6
"net"
7
7
"os/exec"
8
+ "regexp"
8
9
)
9
10
10
11
type VXLANInterface struct {
@@ -30,6 +31,11 @@ func ListVXLANInterfaces() ([]VXLANInterface, error) {
30
31
return vxlanDevices , fmt .Errorf ("running ip command failed: %s" , string (out ))
31
32
}
32
33
34
+ out , err = fixInvalidIproute2JSON (out )
35
+ if err != nil {
36
+ return vxlanDevices , fmt .Errorf ("failed to fix invalid VXLAN VNI: %w" , err )
37
+ }
38
+
33
39
if err := json .Unmarshal (out , & ipLinks ); err != nil {
34
40
return vxlanDevices , fmt .Errorf ("unmarshaling ip command output failed: %w" , err )
35
41
}
@@ -63,3 +69,21 @@ func RemoveLink(name string) error {
63
69
64
70
return nil
65
71
}
72
+
73
+ // fixInvalidIproute2JSON cleans up invalid JSON output produced by the
74
+ // iproute2 command in arm64. Currently, the Ubuntu package combines the VXLAN
75
+ // VNI value with the fan-map extension, resulting in invalid JSON.
76
+ func fixInvalidIproute2JSON (input []byte ) ([]byte , error ) {
77
+ output := string (input )
78
+
79
+ // Target the specific case where numeric VXLAN VNI values are concatenated
80
+ // with text (like "0fan-map") without proper JSON quoting
81
+ re , err := regexp .Compile (`"id":\s*([0-9]+[a-zA-Z][a-zA-Z0-9_-]*)` )
82
+ if err != nil {
83
+ return nil , fmt .Errorf ("failed to compile invalid VXLAN VNI regexp: %w" , err )
84
+ }
85
+
86
+ // Enclose the entire VNI value in double quotes
87
+ output = re .ReplaceAllString (output , `"id":"$1"` )
88
+ return []byte (output ), nil
89
+ }
0 commit comments