diff --git a/internal/distro/rhel86/distro.go b/internal/distro/rhel86/distro.go index 7703fd1c1..f961729ff 100644 --- a/internal/distro/rhel86/distro.go +++ b/internal/distro/rhel86/distro.go @@ -1025,6 +1025,26 @@ func newDistro(distroName string) distro.Distro { Serial: "serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1", Timeout: 10, }, + UdevRules: &osbuild.UdevRulesStageOptions{ + Filename: "/etc/udev/rules.d/68-azure-sriov-nm-unmanaged.rules", + Rules: osbuild.UdevRules{ + osbuild.UdevRuleComment{ + Comment: []string{ + "Accelerated Networking on Azure exposes a new SRIOV interface to the VM.", + "This interface is transparently bonded to the synthetic interface,", + "so NetworkManager should just ignore any SRIOV interfaces.", + }, + }, + osbuild.NewUdevRule( + []osbuild.UdevKV{ + {K: "SUBSYSTEM", O: "==", V: "net"}, + {K: "DRIVERS", O: "==", V: "hv_pci"}, + {K: "ACTION", O: "==", V: "add"}, + {K: "ENV", A: "NM_UNMANAGED", O: "=", V: "1"}, + }, + ), + }, + }, DefaultTarget: "multi-user.target", }, kernelOptions: "ro crashkernel=auto console=tty1 console=ttyS0 earlyprintk=ttyS0 rootdelay=300", diff --git a/internal/osbuild2/udev_rules_stage.go b/internal/osbuild2/udev_rules_stage.go index e170e98e9..b5a865219 100644 --- a/internal/osbuild2/udev_rules_stage.go +++ b/internal/osbuild2/udev_rules_stage.go @@ -5,29 +5,29 @@ import ( "regexp" ) -type OpType int +type udevOpType int const ( - OpMatch OpType = 0 - OpAssign OpType = 1 + udevOpMatch udevOpType = 0 + udevOpAssign udevOpType = 1 ) -var ops = map[string]OpType{ - "=": OpAssign, - "+=": OpAssign, - "-=": OpAssign, - ":=": OpAssign, - "==": OpMatch, - "!=": OpMatch, +var ops = map[string]udevOpType{ + "=": udevOpAssign, + "+=": udevOpAssign, + "-=": udevOpAssign, + ":=": udevOpAssign, + "==": udevOpMatch, + "!=": udevOpMatch, } -type KeyType struct { +type udevKeyType struct { Arg bool Assign bool Match bool } -var keys = map[string]KeyType{ +var keys = map[string]udevKeyType{ "ACTION": {Match: true}, "DEVPATH": {Match: true}, "KERNEL": {Match: true}, @@ -62,7 +62,7 @@ var keys = map[string]KeyType{ "IMPORT": {Arg: true, Assign: true}, } -func validate_op(key, op, val, arg string) error { +func udevOpValidate(key, op, val, arg string) error { if key == "" { return fmt.Errorf("key is required") } @@ -89,8 +89,8 @@ func validate_op(key, op, val, arg string) error { return fmt.Errorf("'%s' operator is not supported", op) } - if (opType == OpMatch && !keyInfo.Match) || - (opType == OpAssign && !keyInfo.Assign) { + if (opType == udevOpMatch && !keyInfo.Match) || + (opType == udevOpAssign && !keyInfo.Assign) { return fmt.Errorf("key '%s' does not support '%s'", key, op) } @@ -182,7 +182,7 @@ type UdevOpSimple struct { } func (o UdevOpSimple) validate() error { - err := validate_op(o.Key, o.Op, o.Value, "") + err := udevOpValidate(o.Key, o.Op, o.Value, "") if err != nil { err = fmt.Errorf("invalid op: %v", err) } @@ -201,7 +201,7 @@ type UdevOpArg struct { func (UdevOpArg) isUdevOp() {} func (o UdevOpArg) validate() error { - err := validate_op(o.Key.Name, o.Op, o.Value, o.Key.Arg) + err := udevOpValidate(o.Key.Name, o.Op, o.Value, o.Key.Arg) if err != nil { err = fmt.Errorf("invalid op: %v", err) } diff --git a/test/data/manifests/rhel_85-x86_64-azure_rhui-boot.json b/test/data/manifests/rhel_85-x86_64-azure_rhui-boot.json index 4c3066c7e..ef218a882 100644 --- a/test/data/manifests/rhel_85-x86_64-azure_rhui-boot.json +++ b/test/data/manifests/rhel_85-x86_64-azure_rhui-boot.json @@ -2864,6 +2864,46 @@ } } }, + { + "type": "org.osbuild.udev.rules", + "options": { + "filename": "/etc/udev/rules.d/68-azure-sriov-nm-unmanaged.rules", + "rules": [ + { + "comment": [ + "Accelerated Networking on Azure exposes a new SRIOV interface to the VM.", + "This interface is transparently bonded to the synthetic interface,", + "so NetworkManager should just ignore any SRIOV interfaces." + ] + }, + [ + { + "key": "SUBSYSTEM", + "op": "==", + "val": "net" + }, + { + "key": "DRIVERS", + "op": "==", + "val": "hv_pci" + }, + { + "key": "ACTION", + "op": "==", + "val": "add" + }, + { + "key": { + "name": "ENV", + "arg": "NM_UNMANAGED" + }, + "op": "=", + "val": "1" + } + ] + ] + } + }, { "type": "org.osbuild.fstab", "options": { diff --git a/test/data/manifests/rhel_86-x86_64-azure_rhui-boot.json b/test/data/manifests/rhel_86-x86_64-azure_rhui-boot.json index 46b95e5d9..0b7293459 100644 --- a/test/data/manifests/rhel_86-x86_64-azure_rhui-boot.json +++ b/test/data/manifests/rhel_86-x86_64-azure_rhui-boot.json @@ -2876,6 +2876,46 @@ } } }, + { + "type": "org.osbuild.udev.rules", + "options": { + "filename": "/etc/udev/rules.d/68-azure-sriov-nm-unmanaged.rules", + "rules": [ + { + "comment": [ + "Accelerated Networking on Azure exposes a new SRIOV interface to the VM.", + "This interface is transparently bonded to the synthetic interface,", + "so NetworkManager should just ignore any SRIOV interfaces." + ] + }, + [ + { + "key": "SUBSYSTEM", + "op": "==", + "val": "net" + }, + { + "key": "DRIVERS", + "op": "==", + "val": "hv_pci" + }, + { + "key": "ACTION", + "op": "==", + "val": "add" + }, + { + "key": { + "name": "ENV", + "arg": "NM_UNMANAGED" + }, + "op": "=", + "val": "1" + } + ] + ] + } + }, { "type": "org.osbuild.fstab", "options": { diff --git a/test/data/manifests/rhel_87-x86_64-azure_rhui-boot.json b/test/data/manifests/rhel_87-x86_64-azure_rhui-boot.json index 404352626..214e796d9 100644 --- a/test/data/manifests/rhel_87-x86_64-azure_rhui-boot.json +++ b/test/data/manifests/rhel_87-x86_64-azure_rhui-boot.json @@ -2876,6 +2876,46 @@ } } }, + { + "type": "org.osbuild.udev.rules", + "options": { + "filename": "/etc/udev/rules.d/68-azure-sriov-nm-unmanaged.rules", + "rules": [ + { + "comment": [ + "Accelerated Networking on Azure exposes a new SRIOV interface to the VM.", + "This interface is transparently bonded to the synthetic interface,", + "so NetworkManager should just ignore any SRIOV interfaces." + ] + }, + [ + { + "key": "SUBSYSTEM", + "op": "==", + "val": "net" + }, + { + "key": "DRIVERS", + "op": "==", + "val": "hv_pci" + }, + { + "key": "ACTION", + "op": "==", + "val": "add" + }, + { + "key": { + "name": "ENV", + "arg": "NM_UNMANAGED" + }, + "op": "=", + "val": "1" + } + ] + ] + } + }, { "type": "org.osbuild.fstab", "options": {