From ece9fd7bc8fe7ddded22dc83aaf44542b74161f7 Mon Sep 17 00:00:00 2001 From: Koen Smets Date: Wed, 19 Jun 2024 20:34:35 +0200 Subject: [PATCH 1/4] feat(mvrp): Support Multiple VLAN Registration protocol (MVRP). Closes #492 and #493. --- routeros/resource_interface_bridge.go | 6 ++++++ routeros/resource_interface_bridge_port.go | 18 ++++++++++++++++++ routeros/resource_interface_bridge_vlan.go | 8 ++++++++ routeros/resource_interface_vlan.go | 12 ++++++++++-- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/routeros/resource_interface_bridge.go b/routeros/resource_interface_bridge.go index 00923630..c3646d96 100644 --- a/routeros/resource_interface_bridge.go +++ b/routeros/resource_interface_bridge.go @@ -192,6 +192,12 @@ func ResourceInterfaceBridge() *schema.Resource { ValidateFunc: validation.StringInSlice([]string{"disabled", "permanent", "temporary-query"}, false), RequiredWith: []string{"igmp_snooping"}, }, + "mvrp": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Enables MVRP for bridge. It ensures that the MAC address 01:80:C2:00:00:21 is trapped and not forwarded, the vlan-filtering must be enabled.", + }, KeyName: PropNameForceNewRw, "port_cost_mode": { Type: schema.TypeString, diff --git a/routeros/resource_interface_bridge_port.go b/routeros/resource_interface_bridge_port.go index d5e4a66b..9b1a2474 100644 --- a/routeros/resource_interface_bridge_port.go +++ b/routeros/resource_interface_bridge_port.go @@ -228,6 +228,24 @@ func ResourceInterfaceBridgePort() *schema.Resource { DiffSuppressFunc: AlwaysPresentNotUserProvided, ValidateFunc: validation.StringInSlice([]string{"disabled", "permanent", "temporary-query"}, false), }, + "mvrp_applicant_state": { + Type: schema.TypeString, + Optional: true, + Default: "normal-participant", + Description: "MVRP applicant options: " + + "- non-participant - port does not send any MRP messages; " + + "- normal-participant - port participates normally in MRP exchanges.", + ValidateFunc: validation.StringInSlice([]string{"non-participant", "normal-participant"}, false), + }, + "mvrp_registrar_state": { + Type: schema.TypeString, + Optional: true, + Default: "normal", + Description: "MVRP registrar options: " + + "- fixed - port ignores all MRP messages, and remains Registered (IN) in all configured vlans. " + + "- normal - port receives MRP messages and handles them according to the standard.", + ValidateFunc: validation.StringInSlice([]string{"fixed", "normal"}, false), + }, // This field has a string value because on the x86 architecture there is no good way to validate // values up to 4294967295. And in this case, an overflow occurs with an errors: // "Cannot use 4294967295 (untyped int constant) as int value in argument to validation.IntBetween (overflows)" diff --git a/routeros/resource_interface_bridge_vlan.go b/routeros/resource_interface_bridge_vlan.go index 66fcb1e5..f5e89844 100644 --- a/routeros/resource_interface_bridge_vlan.go +++ b/routeros/resource_interface_bridge_vlan.go @@ -51,6 +51,14 @@ func ResourceInterfaceBridgeVlan() *schema.Resource { }, KeyDisabled: PropDisabledRw, KeyDynamic: PropDynamicRo, + "mvrp_forbiden": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "Ports that ignore all MRP messages and remains Not Registered (MT), as well as disables applicant from declaring specific VLAN ID.", + }, "tagged": { Type: schema.TypeList, Optional: true, diff --git a/routeros/resource_interface_vlan.go b/routeros/resource_interface_vlan.go index 19be9be8..6b99ff4c 100644 --- a/routeros/resource_interface_vlan.go +++ b/routeros/resource_interface_vlan.go @@ -22,8 +22,16 @@ func ResourceInterfaceVlan() *schema.Resource { KeyLoopProtectStatus: PropLoopProtectStatusRo, KeyMacAddress: PropMacAddressRo, KeyMtu: PropMtuRw(), - KeyName: PropNameForceNewRw, - KeyRunning: PropRunningRo, + "mvrp": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Specifies whether this VLAN should declare its attributes through Multiple VLAN Registration Protocol (MVRP) as an applicant. " + + "It can be used to register the VLAN with connected bridges that support MVRP. " + + "This property only has an effect when use-service-tag is disabled.", + }, + KeyName: PropNameForceNewRw, + KeyRunning: PropRunningRo, "use_service_tag": { Type: schema.TypeBool, Optional: true, From 8400b218791e482f6220abb1b0e0adaafaec88e7 Mon Sep 17 00:00:00 2001 From: Koen Smets Date: Wed, 19 Jun 2024 20:44:26 +0200 Subject: [PATCH 2/4] feat(mvrp): fix typo --- routeros/resource_interface_bridge_vlan.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routeros/resource_interface_bridge_vlan.go b/routeros/resource_interface_bridge_vlan.go index f5e89844..f93b9296 100644 --- a/routeros/resource_interface_bridge_vlan.go +++ b/routeros/resource_interface_bridge_vlan.go @@ -51,7 +51,7 @@ func ResourceInterfaceBridgeVlan() *schema.Resource { }, KeyDisabled: PropDisabledRw, KeyDynamic: PropDynamicRo, - "mvrp_forbiden": { + "mvrp_forbidden": { Type: schema.TypeList, Optional: true, Elem: &schema.Schema{ From 4fd2d57ff11616cf4781f892d7a5e66c5f7bb9dc Mon Sep 17 00:00:00 2001 From: Koen Smets Date: Wed, 19 Jun 2024 21:05:46 +0200 Subject: [PATCH 3/4] feat(mvrp): add DiffSuppressFunc and remove defaults to fix tests when using RouterOS < 7.15 --- routeros/resource_interface_bridge.go | 9 +++++---- routeros/resource_interface_bridge_port.go | 12 +++++++----- routeros/resource_interface_bridge_vlan.go | 3 ++- routeros/resource_interface_vlan.go | 5 +++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/routeros/resource_interface_bridge.go b/routeros/resource_interface_bridge.go index c3646d96..2009cdd6 100644 --- a/routeros/resource_interface_bridge.go +++ b/routeros/resource_interface_bridge.go @@ -193,10 +193,11 @@ func ResourceInterfaceBridge() *schema.Resource { RequiredWith: []string{"igmp_snooping"}, }, "mvrp": { - Type: schema.TypeBool, - Optional: true, - Default: false, - Description: "Enables MVRP for bridge. It ensures that the MAC address 01:80:C2:00:00:21 is trapped and not forwarded, the vlan-filtering must be enabled.", + Type: schema.TypeBool, + Optional: true, + //Default: false, + Description: "Enables MVRP for bridge (available since RouterOS 7.15). It ensures that the MAC address 01:80:C2:00:00:21 is trapped and not forwarded, the vlan-filtering must be enabled.", + DiffSuppressFunc: AlwaysPresentNotUserProvided, }, KeyName: PropNameForceNewRw, "port_cost_mode": { diff --git a/routeros/resource_interface_bridge_port.go b/routeros/resource_interface_bridge_port.go index 9b1a2474..01f64857 100644 --- a/routeros/resource_interface_bridge_port.go +++ b/routeros/resource_interface_bridge_port.go @@ -231,20 +231,22 @@ func ResourceInterfaceBridgePort() *schema.Resource { "mvrp_applicant_state": { Type: schema.TypeString, Optional: true, - Default: "normal-participant", - Description: "MVRP applicant options: " + + //Default: "normal-participant", + Description: "MVRP applicant options (available since RouterOS 7.15): " + "- non-participant - port does not send any MRP messages; " + "- normal-participant - port participates normally in MRP exchanges.", - ValidateFunc: validation.StringInSlice([]string{"non-participant", "normal-participant"}, false), + ValidateFunc: validation.StringInSlice([]string{"non-participant", "normal-participant"}, false), + DiffSuppressFunc: AlwaysPresentNotUserProvided, }, "mvrp_registrar_state": { Type: schema.TypeString, Optional: true, Default: "normal", - Description: "MVRP registrar options: " + + Description: "MVRP registrar options (available since RouterOS 7.15): " + "- fixed - port ignores all MRP messages, and remains Registered (IN) in all configured vlans. " + "- normal - port receives MRP messages and handles them according to the standard.", - ValidateFunc: validation.StringInSlice([]string{"fixed", "normal"}, false), + ValidateFunc: validation.StringInSlice([]string{"fixed", "normal"}, false), + DiffSuppressFunc: AlwaysPresentNotUserProvided, }, // This field has a string value because on the x86 architecture there is no good way to validate // values up to 4294967295. And in this case, an overflow occurs with an errors: diff --git a/routeros/resource_interface_bridge_vlan.go b/routeros/resource_interface_bridge_vlan.go index f93b9296..c5661d2b 100644 --- a/routeros/resource_interface_bridge_vlan.go +++ b/routeros/resource_interface_bridge_vlan.go @@ -57,7 +57,8 @@ func ResourceInterfaceBridgeVlan() *schema.Resource { Elem: &schema.Schema{ Type: schema.TypeString, }, - Description: "Ports that ignore all MRP messages and remains Not Registered (MT), as well as disables applicant from declaring specific VLAN ID.", + Description: "Ports that ignore all MRP messages and remains Not Registered (MT), as well as disables applicant from declaring specific VLAN ID (available since RouterOS 7.15).", + DiffSuppressFunc: AlwaysPresentNotUserProvided, }, "tagged": { Type: schema.TypeList, diff --git a/routeros/resource_interface_vlan.go b/routeros/resource_interface_vlan.go index 6b99ff4c..a4271b3a 100644 --- a/routeros/resource_interface_vlan.go +++ b/routeros/resource_interface_vlan.go @@ -25,10 +25,11 @@ func ResourceInterfaceVlan() *schema.Resource { "mvrp": { Type: schema.TypeBool, Optional: true, - Default: false, - Description: "Specifies whether this VLAN should declare its attributes through Multiple VLAN Registration Protocol (MVRP) as an applicant. " + + //Default: false, + Description: "Specifies whether this VLAN should declare its attributes through Multiple VLAN Registration Protocol (MVRP) as an applicant (available since RouterOS 7.15). " + "It can be used to register the VLAN with connected bridges that support MVRP. " + "This property only has an effect when use-service-tag is disabled.", + DiffSuppressFunc: AlwaysPresentNotUserProvided, }, KeyName: PropNameForceNewRw, KeyRunning: PropRunningRo, From 7d648b2d2b83f483f5ea081e55ed78a251332f7d Mon Sep 17 00:00:00 2001 From: Koen Smets Date: Wed, 19 Jun 2024 21:09:27 +0200 Subject: [PATCH 4/4] feat(mvrp): add DiffSuppressFunc and remove defaults to fix tests when using RouterOS < 7.15 --- routeros/resource_interface_bridge_port.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routeros/resource_interface_bridge_port.go b/routeros/resource_interface_bridge_port.go index 01f64857..9f2a29ab 100644 --- a/routeros/resource_interface_bridge_port.go +++ b/routeros/resource_interface_bridge_port.go @@ -241,7 +241,7 @@ func ResourceInterfaceBridgePort() *schema.Resource { "mvrp_registrar_state": { Type: schema.TypeString, Optional: true, - Default: "normal", + //Default: "normal", Description: "MVRP registrar options (available since RouterOS 7.15): " + "- fixed - port ignores all MRP messages, and remains Registered (IN) in all configured vlans. " + "- normal - port receives MRP messages and handles them according to the standard.",