Просмотр исходного кода

Closes #21098: Add LAG mode and hash policy fields to Interface (#23684)

Arthur Hanson 1 день назад
Родитель
Сommit
8fb7f899e2

+ 18 - 0
docs/models/dcim/interface.md

@@ -109,6 +109,24 @@ Interfaces can be bridged to other interfaces on a device in two manners: symmet
 
 
 Physical interfaces may be arranged into link aggregation groups (LAGs, also known as "trunks") and associated with a parent LAG (virtual) interface. LAG interfaces can be recursively nested to model bonding of trunk groups. Like all virtual interfaces, LAG interfaces cannot be connected physically.
 Physical interfaces may be arranged into link aggregation groups (LAGs, also known as "trunks") and associated with a parent LAG (virtual) interface. LAG interfaces can be recursively nested to model bonding of trunk groups. Like all virtual interfaces, LAG interfaces cannot be connected physically.
 
 
+### LAG Mode
+
+The link aggregation mode of a LAG interface. (This field may be set only on interfaces of type LAG.) Choices include:
+
+| Mode           | Group   | Linux bonding mode |
+|----------------|---------|--------------------|
+| LACP (802.3ad) | Generic | `802.3ad`          |
+| Static         | Generic | `balance-xor`      |
+| Active-Backup  | Generic | `active-backup`    |
+| Balance-RR     | Linux   | `balance-rr`       |
+| Balance-TLB    | Linux   | `balance-tlb`      |
+| Balance-ALB    | Linux   | `balance-alb`      |
+| Broadcast      | Linux   | `broadcast`        |
+
+### LAG Hash Policy
+
+The transmit hash policy used to distribute traffic across the members of a LAG interface: layer 2, layer 2+3, layer 3+4, encapsulated layer 2+3, encapsulated layer 3+4, or VLAN + source MAC. (This field may be set only on LAG interfaces whose mode is LACP or static.)
+
 ### PoE Mode
 ### PoE Mode
 
 
 The power over Ethernet (PoE) mode for this interface. (This field must be left empty for interfaces which do not support PoE.) Choices include:
 The power over Ethernet (PoE) mode for this interface. (This field must be left empty for interfaces which do not support PoE.) Choices include:

+ 10 - 8
netbox/dcim/api/serializers_/device_components.py

@@ -314,6 +314,8 @@ class InterfaceSerializer(
     rf_channel = ChoiceField(choices=WirelessChannelChoices, required=False, allow_blank=True)
     rf_channel = ChoiceField(choices=WirelessChannelChoices, required=False, allow_blank=True)
     poe_mode = ChoiceField(choices=InterfacePoEModeChoices, required=False, allow_blank=True)
     poe_mode = ChoiceField(choices=InterfacePoEModeChoices, required=False, allow_blank=True)
     poe_type = ChoiceField(choices=InterfacePoETypeChoices, required=False, allow_blank=True)
     poe_type = ChoiceField(choices=InterfacePoETypeChoices, required=False, allow_blank=True)
+    lag_mode = ChoiceField(choices=InterfaceLAGModeChoices, required=False, allow_blank=True)
+    lag_hash_policy = ChoiceField(choices=InterfaceLAGHashPolicyChoices, required=False, allow_blank=True)
     untagged_vlan = VLANSerializer(nested=True, required=False, allow_null=True)
     untagged_vlan = VLANSerializer(nested=True, required=False, allow_null=True)
     tagged_vlans = SerializedPKRelatedField(
     tagged_vlans = SerializedPKRelatedField(
         queryset=VLAN.objects.all(),
         queryset=VLAN.objects.all(),
@@ -356,14 +358,14 @@ class InterfaceSerializer(
         model = Interface
         model = Interface
         fields = [
         fields = [
             'id', 'url', 'display_url', 'display', 'device', 'vdcs', 'module', 'name', 'label', 'type', 'channels',
             'id', 'url', 'display_url', 'display', 'device', 'vdcs', 'module', 'name', 'label', 'type', 'channels',
-            'channel_id', 'enabled',
-            'parent', 'bridge', 'bridge_interfaces', 'lag', 'mtu', 'mac_address', 'primary_mac_address',
-            'mac_addresses', 'speed', 'duplex', 'wwn', 'mgmt_only', 'description', 'mode', 'rf_role', 'rf_channel',
-            'poe_mode', 'poe_type', 'rf_channel_frequency', 'rf_channel_width', 'tx_power', 'untagged_vlan',
-            'tagged_vlans', 'qinq_svlan', 'vlan_translation_policy', 'mark_connected', 'cable', 'cable_end',
-            'wireless_link', 'link_peers', 'link_peers_type', 'wireless_lans', 'vrf', 'l2vpn_termination',
-            'connected_endpoints', 'connected_endpoints_type', 'connected_endpoints_reachable', 'owner', 'tags',
-            'custom_fields', 'created', 'last_updated', 'count_ipaddresses', 'count_fhrp_groups', '_occupied',
+            'channel_id', 'enabled', 'parent', 'bridge', 'bridge_interfaces', 'lag', 'mtu', 'mac_address',
+            'primary_mac_address', 'mac_addresses', 'speed', 'duplex', 'wwn', 'mgmt_only', 'description', 'mode',
+            'rf_role', 'rf_channel', 'poe_mode', 'poe_type', 'lag_mode', 'lag_hash_policy', 'rf_channel_frequency',
+            'rf_channel_width', 'tx_power', 'untagged_vlan', 'tagged_vlans', 'qinq_svlan', 'vlan_translation_policy',
+            'mark_connected', 'cable', 'cable_end', 'wireless_link', 'link_peers', 'link_peers_type', 'wireless_lans',
+            'vrf', 'l2vpn_termination', 'connected_endpoints', 'connected_endpoints_type',
+            'connected_endpoints_reachable', 'owner', 'tags', 'custom_fields', 'created', 'last_updated',
+            'count_ipaddresses', 'count_fhrp_groups', '_occupied',
         ]
         ]
         brief_fields = ('id', 'url', 'display', 'device', 'name', 'description', 'cable', '_occupied')
         brief_fields = ('id', 'url', 'display', 'device', 'name', 'description', 'cable', '_occupied')
 
 

+ 55 - 0
netbox/dcim/choices.py

@@ -1661,6 +1661,61 @@ class InterfaceModeChoices(ChoiceSet):
     )
     )
 
 
 
 
+class InterfaceLAGModeChoices(ChoiceSet):
+
+    MODE_LACP = 'lacp'
+    MODE_STATIC = 'static'
+    MODE_ACTIVE_BACKUP = 'active-backup'
+    MODE_BALANCE_RR = 'balance-rr'
+    MODE_BALANCE_TLB = 'balance-tlb'
+    MODE_BALANCE_ALB = 'balance-alb'
+    MODE_BROADCAST = 'broadcast'
+
+    CHOICES = (
+        (
+            _('Generic'),
+            (
+                Choice(MODE_LACP, _('LACP (802.3ad)'), description=_('Dynamic link aggregation negotiated via LACP')),
+                Choice(
+                    MODE_STATIC, _('Static'),
+                    description=_('Static aggregation with hash-based balancing (balance-xor)'),
+                ),
+                Choice(MODE_ACTIVE_BACKUP, _('Active-Backup'), description=_('One active member; others on standby')),
+            ),
+        ),
+        (
+            _('Linux'),
+            (
+                Choice(MODE_BALANCE_RR, _('Balance-RR'), description=_('Round-robin transmission across members')),
+                Choice(MODE_BALANCE_TLB, _('Balance-TLB'), description=_('Adaptive transmit load balancing')),
+                Choice(
+                    MODE_BALANCE_ALB, _('Balance-ALB'), description=_('Adaptive transmit and receive load balancing')
+                ),
+                Choice(MODE_BROADCAST, _('Broadcast'), description=_('Transmit on all members')),
+            ),
+        ),
+    )
+
+
+class InterfaceLAGHashPolicyChoices(ChoiceSet):
+
+    POLICY_LAYER2 = 'layer2'
+    POLICY_LAYER2_3 = 'layer2+3'
+    POLICY_LAYER3_4 = 'layer3+4'
+    POLICY_ENCAP2_3 = 'encap2+3'
+    POLICY_ENCAP3_4 = 'encap3+4'
+    POLICY_VLAN_SRCMAC = 'vlan+srcmac'
+
+    CHOICES = (
+        Choice(POLICY_LAYER2, _('Layer 2')),
+        Choice(POLICY_LAYER2_3, _('Layer 2+3')),
+        Choice(POLICY_LAYER3_4, _('Layer 3+4')),
+        Choice(POLICY_ENCAP2_3, _('Encapsulated Layer 2+3')),
+        Choice(POLICY_ENCAP3_4, _('Encapsulated Layer 3+4')),
+        Choice(POLICY_VLAN_SRCMAC, _('VLAN + Source MAC')),
+    )
+
+
 class InterfacePoEModeChoices(ChoiceSet):
 class InterfacePoEModeChoices(ChoiceSet):
 
 
     MODE_PD = 'pd'
     MODE_PD = 'pd'

+ 7 - 1
netbox/dcim/constants.py

@@ -2,7 +2,7 @@ import re
 
 
 from django.db.models import Q
 from django.db.models import Q
 
 
-from .choices import InterfaceTypeChoices
+from .choices import InterfaceLAGModeChoices, InterfaceTypeChoices
 
 
 # Exclude SVG images (unsupported by PIL)
 # Exclude SVG images (unsupported by PIL)
 DEVICETYPE_IMAGE_FORMATS = 'image/bmp,image/gif,image/jpeg,image/png,image/tiff,image/webp'
 DEVICETYPE_IMAGE_FORMATS = 'image/bmp,image/gif,image/jpeg,image/png,image/tiff,image/webp'
@@ -94,6 +94,12 @@ NONCONNECTABLE_IFACE_TYPES = VIRTUAL_IFACE_TYPES + WIRELESS_IFACE_TYPES + [
     InterfaceTypeChoices.TYPE_CHANNEL,
     InterfaceTypeChoices.TYPE_CHANNEL,
 ]
 ]
 
 
+# LAG modes which select a member interface by transmit hash (Linux bonding xmit_hash_policy)
+LAG_HASH_MODES = (
+    InterfaceLAGModeChoices.MODE_LACP,
+    InterfaceLAGModeChoices.MODE_STATIC,
+)
+
 
 
 #
 #
 # MAC blocks
 # MAC blocks

+ 8 - 0
netbox/dcim/filtersets.py

@@ -2563,6 +2563,14 @@ class InterfaceFilterSet(
         choices=InterfacePoETypeChoices,
         choices=InterfacePoETypeChoices,
         distinct=False,
         distinct=False,
     )
     )
+    lag_mode = django_filters.MultipleChoiceFilter(
+        choices=InterfaceLAGModeChoices,
+        distinct=False,
+    )
+    lag_hash_policy = django_filters.MultipleChoiceFilter(
+        choices=InterfaceLAGHashPolicyChoices,
+        distinct=False,
+    )
     type = django_filters.MultipleChoiceFilter(
     type = django_filters.MultipleChoiceFilter(
         choices=InterfaceTypeChoices,
         choices=InterfaceTypeChoices,
         distinct=False,
         distinct=False,

+ 17 - 3
netbox/dcim/forms/bulk_edit.py

@@ -1963,6 +1963,18 @@ class InterfaceBulkEditForm(
         initial='',
         initial='',
         label=_('PoE type')
         label=_('PoE type')
     )
     )
+    lag_mode = ChoiceField(
+        choices=add_blank_choice(InterfaceLAGModeChoices),
+        required=False,
+        initial='',
+        label=_('LAG mode')
+    )
+    lag_hash_policy = ChoiceField(
+        choices=add_blank_choice(InterfaceLAGHashPolicyChoices),
+        required=False,
+        initial='',
+        label=_('LAG hash policy')
+    )
     mark_connected = forms.NullBooleanField(
     mark_connected = forms.NullBooleanField(
         label=_('Mark connected'),
         label=_('Mark connected'),
         required=False,
         required=False,
@@ -2050,6 +2062,7 @@ class InterfaceBulkEditForm(
         FieldSet('vrf', 'wwn', name=_('Addressing')),
         FieldSet('vrf', 'wwn', name=_('Addressing')),
         FieldSet('vdcs', 'mtu', 'tx_power', 'enabled', 'mgmt_only', 'mark_connected', name=_('Operation')),
         FieldSet('vdcs', 'mtu', 'tx_power', 'enabled', 'mgmt_only', 'mark_connected', name=_('Operation')),
         FieldSet('poe_mode', 'poe_type', name=_('PoE')),
         FieldSet('poe_mode', 'poe_type', name=_('PoE')),
+        FieldSet('lag_mode', 'lag_hash_policy', name=_('LAG')),
         FieldSet('parent', 'channel_id', 'bridge', 'lag', name=_('Related Interfaces')),
         FieldSet('parent', 'channel_id', 'bridge', 'lag', name=_('Related Interfaces')),
         FieldSet(
         FieldSet(
             'mode', 'vlan_group', 'untagged_vlan', 'qinq_svlan', 'vlan_translation_policy', name=_('802.1Q Switching')
             'mode', 'vlan_group', 'untagged_vlan', 'qinq_svlan', 'vlan_translation_policy', name=_('802.1Q Switching')
@@ -2066,9 +2079,10 @@ class InterfaceBulkEditForm(
         ),
         ),
     )
     )
     nullable_fields = (
     nullable_fields = (
-        'module', 'label', 'channels', 'channel_id', 'parent', 'bridge', 'lag', 'speed', 'duplex', 'wwn', 'vdcs',
-        'mtu', 'description', 'poe_mode', 'poe_type', 'mode', 'rf_channel', 'rf_channel_frequency', 'rf_channel_width',
-        'tx_power', 'untagged_vlan', 'tagged_vlans', 'qinq_svlan', 'vrf', 'wireless_lans', 'vlan_translation_policy',
+        'module', 'label', 'channels', 'channel_id', 'parent', 'bridge', 'lag', 'speed', 'duplex', 'wwn', 'vdcs', 'mtu',
+        'description', 'poe_mode', 'poe_type', 'lag_mode', 'lag_hash_policy', 'mode', 'rf_channel',
+        'rf_channel_frequency', 'rf_channel_width', 'tx_power', 'untagged_vlan', 'tagged_vlans', 'qinq_svlan', 'vrf',
+        'wireless_lans', 'vlan_translation_policy',
     )
     )
 
 
     def __init__(self, *args, **kwargs):
     def __init__(self, *args, **kwargs):

+ 14 - 2
netbox/dcim/forms/bulk_import.py

@@ -1209,6 +1209,18 @@ class InterfaceImportForm(OwnerCSVMixin, NetBoxModelImportForm):
         required=False,
         required=False,
         help_text=_('PoE type')
         help_text=_('PoE type')
     )
     )
+    lag_mode = CSVChoiceField(
+        label=_('LAG mode'),
+        choices=InterfaceLAGModeChoices,
+        required=False,
+        help_text=_('LAG mode')
+    )
+    lag_hash_policy = CSVChoiceField(
+        label=_('LAG hash policy'),
+        choices=InterfaceLAGHashPolicyChoices,
+        required=False,
+        help_text=_('LAG hash policy')
+    )
     mode = CSVChoiceField(
     mode = CSVChoiceField(
         label=_('Mode'),
         label=_('Mode'),
         choices=InterfaceModeChoices,
         choices=InterfaceModeChoices,
@@ -1268,8 +1280,8 @@ class InterfaceImportForm(OwnerCSVMixin, NetBoxModelImportForm):
         fields = (
         fields = (
             'device', 'name', 'label', 'parent', 'bridge', 'lag', 'type', 'channels', 'channel_id', 'speed', 'duplex',
             'device', 'name', 'label', 'parent', 'bridge', 'lag', 'type', 'channels', 'channel_id', 'speed', 'duplex',
             'enabled', 'mark_connected', 'wwn', 'vdcs', 'mtu', 'mgmt_only', 'description', 'poe_mode', 'poe_type',
             'enabled', 'mark_connected', 'wwn', 'vdcs', 'mtu', 'mgmt_only', 'description', 'poe_mode', 'poe_type',
-            'mode', 'vlan_group', 'untagged_vlan', 'tagged_vlans', 'qinq_svlan', 'vrf', 'rf_role', 'rf_channel',
-            'rf_channel_frequency', 'rf_channel_width', 'tx_power', 'owner', 'tags'
+            'lag_mode', 'lag_hash_policy', 'mode', 'vlan_group', 'untagged_vlan', 'tagged_vlans', 'qinq_svlan', 'vrf',
+            'rf_role', 'rf_channel', 'rf_channel_frequency', 'rf_channel_width', 'tx_power', 'owner', 'tags'
         )
         )
 
 
     def __init__(self, data=None, *args, **kwargs):
     def __init__(self, data=None, *args, **kwargs):

+ 11 - 0
netbox/dcim/forms/filtersets.py

@@ -2035,6 +2035,7 @@ class InterfaceFilterForm(PathEndpointFilterForm, DeviceComponentFilterForm):
         ),
         ),
         FieldSet('vrf_id', 'l2vpn_id', 'mac_address', 'wwn', name=_('Addressing')),
         FieldSet('vrf_id', 'l2vpn_id', 'mac_address', 'wwn', name=_('Addressing')),
         FieldSet('poe_mode', 'poe_type', name=_('PoE')),
         FieldSet('poe_mode', 'poe_type', name=_('PoE')),
+        FieldSet('lag_mode', 'lag_hash_policy', name=_('LAG')),
         FieldSet('mode', 'vlan_translation_policy_id', name=_('802.1Q Switching')),
         FieldSet('mode', 'vlan_translation_policy_id', name=_('802.1Q Switching')),
         FieldSet('rf_role', 'rf_channel', 'rf_channel_width', 'tx_power', name=_('Wireless')),
         FieldSet('rf_role', 'rf_channel', 'rf_channel_width', 'tx_power', name=_('Wireless')),
         FieldSet('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id', name=_('Location')),
         FieldSet('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id', name=_('Location')),
@@ -2117,6 +2118,16 @@ class InterfaceFilterForm(PathEndpointFilterForm, DeviceComponentFilterForm):
         required=False,
         required=False,
         label=_('PoE type')
         label=_('PoE type')
     )
     )
+    lag_mode = forms.MultipleChoiceField(
+        choices=InterfaceLAGModeChoices,
+        required=False,
+        label=_('LAG mode')
+    )
+    lag_hash_policy = forms.MultipleChoiceField(
+        choices=InterfaceLAGHashPolicyChoices,
+        required=False,
+        label=_('LAG hash policy')
+    )
     mode = forms.MultipleChoiceField(
     mode = forms.MultipleChoiceField(
         choices=InterfaceModeChoices,
         choices=InterfaceModeChoices,
         required=False,
         required=False,

+ 43 - 5
netbox/dcim/forms/model_forms.py

@@ -2044,6 +2044,7 @@ class InterfaceForm(InterfaceCommonForm, ModularDeviceComponentForm):
     type = ChoiceField(
     type = ChoiceField(
         label=_('Type'),
         label=_('Type'),
         choices=InterfaceTypeChoices,
         choices=InterfaceTypeChoices,
+        widget=HTMXSelect(hx_target_id='lag-attributes'),
     )
     )
     duplex = TypedChoiceField(
     duplex = TypedChoiceField(
         label=_('Duplex'),
         label=_('Duplex'),
@@ -2060,6 +2061,17 @@ class InterfaceForm(InterfaceCommonForm, ModularDeviceComponentForm):
         choices=add_blank_choice(InterfacePoETypeChoices),
         choices=add_blank_choice(InterfacePoETypeChoices),
         required=False,
         required=False,
     )
     )
+    lag_mode = TypedChoiceField(
+        label=_('LAG mode'),
+        choices=add_blank_choice(InterfaceLAGModeChoices),
+        required=False,
+        widget=HTMXSelect(hx_target_id='lag-attributes'),
+    )
+    lag_hash_policy = TypedChoiceField(
+        label=_('LAG hash policy'),
+        choices=add_blank_choice(InterfaceLAGHashPolicyChoices),
+        required=False,
+    )
     mode = TypedChoiceField(
     mode = TypedChoiceField(
         label=_('802.1Q Mode'),
         label=_('802.1Q Mode'),
         choices=add_blank_choice(InterfaceModeChoices),
         choices=add_blank_choice(InterfaceModeChoices),
@@ -2185,6 +2197,7 @@ class InterfaceForm(InterfaceCommonForm, ModularDeviceComponentForm):
         FieldSet('vdcs', 'mtu', 'tx_power', 'enabled', 'mgmt_only', 'mark_connected', name=_('Operation')),
         FieldSet('vdcs', 'mtu', 'tx_power', 'enabled', 'mgmt_only', 'mark_connected', name=_('Operation')),
         FieldSet('parent', 'channel_id', 'bridge', 'lag', name=_('Related Interfaces')),
         FieldSet('parent', 'channel_id', 'bridge', 'lag', name=_('Related Interfaces')),
         FieldSet('poe_mode', 'poe_type', name=_('PoE')),
         FieldSet('poe_mode', 'poe_type', name=_('PoE')),
+        FieldSet('lag_mode', 'lag_hash_policy', name=_('LAG'), html_id='lag-attributes'),
         FieldSet(
         FieldSet(
             'mode', 'vlan_group', 'untagged_vlan', 'tagged_vlans', 'qinq_svlan', 'vlan_translation_policy',
             'mode', 'vlan_group', 'untagged_vlan', 'tagged_vlans', 'qinq_svlan', 'vlan_translation_policy',
             name=_('802.1Q Switching'),
             name=_('802.1Q Switching'),
@@ -2199,11 +2212,11 @@ class InterfaceForm(InterfaceCommonForm, ModularDeviceComponentForm):
     class Meta:
     class Meta:
         model = Interface
         model = Interface
         fields = [
         fields = [
-            'device', 'module', 'vdcs', 'name', 'label', 'type', 'channels', 'channel_id', 'speed', 'duplex',
-            'enabled', 'parent', 'bridge', 'lag', 'wwn', 'mtu', 'mgmt_only', 'mark_connected', 'description',
-            'poe_mode', 'poe_type', 'mode', 'rf_role', 'rf_channel', 'rf_channel_frequency', 'rf_channel_width',
-            'tx_power', 'wireless_lans', 'untagged_vlan', 'tagged_vlans', 'qinq_svlan', 'vlan_translation_policy',
-            'vrf', 'owner', 'tags',
+            'device', 'module', 'vdcs', 'name', 'label', 'type', 'channels', 'channel_id', 'speed', 'duplex', 'enabled',
+            'parent', 'bridge', 'lag', 'wwn', 'mtu', 'mgmt_only', 'mark_connected', 'description', 'poe_mode',
+            'poe_type', 'lag_mode', 'lag_hash_policy', 'mode', 'rf_role', 'rf_channel', 'rf_channel_frequency',
+            'rf_channel_width', 'tx_power', 'wireless_lans', 'untagged_vlan', 'tagged_vlans', 'qinq_svlan',
+            'vlan_translation_policy', 'vrf', 'owner', 'tags',
         ]
         ]
         widgets = {
         widgets = {
             'speed': NumberWithOptions(
             'speed': NumberWithOptions(
@@ -2211,6 +2224,31 @@ class InterfaceForm(InterfaceCommonForm, ModularDeviceComponentForm):
             ),
             ),
         }
         }
 
 
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+
+        # LAG attributes apply only to LAG interfaces, and a hash policy only to LAG modes which hash
+        if get_field_value(self, 'type') != InterfaceTypeChoices.TYPE_LAG:
+            del self.fields['lag_mode']
+            del self.fields['lag_hash_policy']
+        else:
+            # Read a submitted mode directly, as get_field_value() treats a cleared (blank) mode as unset
+            if self.is_bound and 'lag_mode' in self.data:
+                lag_mode = self.data['lag_mode']
+            else:
+                lag_mode = get_field_value(self, 'lag_mode')
+            if lag_mode not in LAG_HASH_MODES:
+                del self.fields['lag_hash_policy']
+
+    def clean(self):
+        super().clean()
+
+        # Clear any LAG attributes which no longer apply
+        if 'lag_mode' not in self.fields:
+            self.instance.lag_mode = None
+        if 'lag_hash_policy' not in self.fields:
+            self.instance.lag_hash_policy = None
+
 
 
 class FrontPortForm(FrontPortFormMixin, ModularDeviceComponentForm):
 class FrontPortForm(FrontPortFormMixin, ModularDeviceComponentForm):
     type = ChoiceField(
     type = ChoiceField(

+ 4 - 0
netbox/dcim/graphql/enums.py

@@ -22,6 +22,8 @@ __all__ = (
     'FluidTypeEnum',
     'FluidTypeEnum',
     'InterfaceDuplexEnum',
     'InterfaceDuplexEnum',
     'InterfaceKindEnum',
     'InterfaceKindEnum',
+    'InterfaceLAGHashPolicyEnum',
+    'InterfaceLAGModeEnum',
     'InterfaceModeEnum',
     'InterfaceModeEnum',
     'InterfacePoEModeEnum',
     'InterfacePoEModeEnum',
     'InterfacePoETypeEnum',
     'InterfacePoETypeEnum',
@@ -71,6 +73,8 @@ FluidTypeEnum = strawberry.enum(FluidTypeChoices.as_enum(prefix='fluid'))
 InterfaceDuplexEnum = strawberry.enum(InterfaceDuplexChoices.as_enum(prefix='duplex'))
 InterfaceDuplexEnum = strawberry.enum(InterfaceDuplexChoices.as_enum(prefix='duplex'))
 InterfaceKindEnum = strawberry.enum(InterfaceKindChoices.as_enum(prefix='kind'))
 InterfaceKindEnum = strawberry.enum(InterfaceKindChoices.as_enum(prefix='kind'))
 InterfaceModeEnum = strawberry.enum(InterfaceModeChoices.as_enum(prefix='mode'))
 InterfaceModeEnum = strawberry.enum(InterfaceModeChoices.as_enum(prefix='mode'))
+InterfaceLAGModeEnum = strawberry.enum(InterfaceLAGModeChoices.as_enum(prefix='mode'))
+InterfaceLAGHashPolicyEnum = strawberry.enum(InterfaceLAGHashPolicyChoices.as_enum(prefix='policy'))
 InterfacePoEModeEnum = strawberry.enum(InterfacePoEModeChoices.as_enum(prefix='mode'))
 InterfacePoEModeEnum = strawberry.enum(InterfacePoEModeChoices.as_enum(prefix='mode'))
 InterfacePoETypeEnum = strawberry.enum(InterfacePoETypeChoices.as_enum())
 InterfacePoETypeEnum = strawberry.enum(InterfacePoETypeChoices.as_enum())
 InterfaceTypeEnum = strawberry.enum(InterfaceTypeChoices.as_enum(prefix='type'))
 InterfaceTypeEnum = strawberry.enum(InterfaceTypeChoices.as_enum(prefix='type'))

+ 6 - 0
netbox/dcim/graphql/filters.py

@@ -603,6 +603,12 @@ class InterfaceFilter(
     poe_type: BaseFilterLookup[Annotated['InterfacePoETypeEnum', strawberry.lazy('dcim.graphql.enums')]] | None = (
     poe_type: BaseFilterLookup[Annotated['InterfacePoETypeEnum', strawberry.lazy('dcim.graphql.enums')]] | None = (
         strawberry_django.filter_field()
         strawberry_django.filter_field()
     )
     )
+    lag_mode: BaseFilterLookup[Annotated['InterfaceLAGModeEnum', strawberry.lazy('dcim.graphql.enums')]] | None = (
+        strawberry_django.filter_field()
+    )
+    lag_hash_policy: (
+        BaseFilterLookup[Annotated['InterfaceLAGHashPolicyEnum', strawberry.lazy('dcim.graphql.enums')]] | None
+    ) = strawberry_django.filter_field()
     wireless_link: Annotated['WirelessLinkFilter', strawberry.lazy('wireless.graphql.filters')] | None = (
     wireless_link: Annotated['WirelessLinkFilter', strawberry.lazy('wireless.graphql.filters')] | None = (
         strawberry_django.filter_field()
         strawberry_django.filter_field()
     )
     )

+ 23 - 0
netbox/dcim/migrations/0255_interface_lag_hash_policy_interface_lag_mode.py

@@ -0,0 +1,23 @@
+# Generated by Django 6.1.3 on 2026-11-20 18:48
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("dcim", "0254_moduletype_images"),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name="interface",
+            name="lag_hash_policy",
+            field=models.CharField(blank=True, max_length=50, null=True),
+        ),
+        migrations.AddField(
+            model_name="interface",
+            name="lag_mode",
+            field=models.CharField(blank=True, max_length=50, null=True),
+        ),
+    ]

+ 25 - 1
netbox/dcim/models/device_components.py

@@ -1139,6 +1139,20 @@ class Interface(
         null=True,
         null=True,
         verbose_name=_('PoE type')
         verbose_name=_('PoE type')
     )
     )
+    lag_mode = models.CharField(
+        max_length=50,
+        choices=InterfaceLAGModeChoices,
+        blank=True,
+        null=True,
+        verbose_name=_('LAG mode')
+    )
+    lag_hash_policy = models.CharField(
+        max_length=50,
+        choices=InterfaceLAGHashPolicyChoices,
+        blank=True,
+        null=True,
+        verbose_name=_('LAG hash policy')
+    )
     wireless_link = models.ForeignKey(
     wireless_link = models.ForeignKey(
         to='wireless.WirelessLink',
         to='wireless.WirelessLink',
         on_delete=models.SET_NULL,
         on_delete=models.SET_NULL,
@@ -1194,7 +1208,7 @@ class Interface(
     clone_fields = (
     clone_fields = (
         'device', 'module', 'parent', 'bridge', 'lag', 'type', 'channels', 'mgmt_only', 'mtu', 'mode', 'speed',
         'device', 'module', 'parent', 'bridge', 'lag', 'type', 'channels', 'mgmt_only', 'mtu', 'mode', 'speed',
         'duplex', 'rf_role', 'rf_channel', 'rf_channel_frequency', 'rf_channel_width', 'tx_power', 'poe_mode',
         'duplex', 'rf_role', 'rf_channel', 'rf_channel_frequency', 'rf_channel_width', 'tx_power', 'poe_mode',
-        'poe_type', 'vrf',
+        'poe_type', 'lag_mode', 'lag_hash_policy', 'vrf',
     )
     )
 
 
     class Meta(ModularComponentModel.Meta):
     class Meta(ModularComponentModel.Meta):
@@ -1319,6 +1333,16 @@ class Interface(
                     )
                     )
                 })
                 })
 
 
+        # LAG attributes may only be set on LAG interfaces
+        if self.lag_mode and not self.is_lag:
+            raise ValidationError({'lag_mode': _("LAG mode may be set only on LAG interfaces.")})
+        if self.lag_hash_policy and not self.is_lag:
+            raise ValidationError({'lag_hash_policy': _("LAG hash policy may be set only on LAG interfaces.")})
+        if self.lag_hash_policy and self.lag_mode not in LAG_HASH_MODES:
+            raise ValidationError({
+                'lag_hash_policy': _("LAG hash policy may be set only for LACP or static LAG modes."),
+            })
+
         # Wireless validation
         # Wireless validation
 
 
         # RF channel may only be set for wireless interfaces
         # RF channel may only be set for wireless interfaces

+ 7 - 7
netbox/dcim/tables/devices.py

@@ -723,13 +723,13 @@ class InterfaceTable(BaseInterfaceTable, ModularDeviceComponentTable, PathEndpoi
     class Meta(DeviceComponentTable.Meta):
     class Meta(DeviceComponentTable.Meta):
         model = models.Interface
         model = models.Interface
         fields = (
         fields = (
-            'pk', 'id', 'name', 'device', 'module_bay', 'module', 'label', 'enabled', 'type', 'channels',
-            'channel_id', 'mgmt_only', 'mtu', 'speed', 'speed_formatted', 'duplex', 'mode', 'mac_addresses',
-            'primary_mac_address', 'wwn', 'poe_mode', 'poe_type', 'rf_role', 'rf_channel', 'rf_channel_frequency',
-            'rf_channel_width', 'tx_power', 'description', 'mark_connected', 'cable', 'cable_color', 'wireless_link',
-            'wireless_lans', 'link_peer', 'connection', 'tags', 'vdcs', 'vrf', 'l2vpn', 'tunnel', 'ip_addresses',
-            'fhrp_groups', 'untagged_vlan', 'tagged_vlans', 'qinq_svlan', 'inventory_items', 'created', 'last_updated',
-            'vlan_translation_policy',
+            'pk', 'id', 'name', 'device', 'module_bay', 'module', 'label', 'enabled', 'type', 'channels', 'channel_id',
+            'mgmt_only', 'mtu', 'speed', 'speed_formatted', 'duplex', 'mode', 'mac_addresses', 'primary_mac_address',
+            'wwn', 'poe_mode', 'poe_type', 'lag_mode', 'lag_hash_policy', 'rf_role', 'rf_channel',
+            'rf_channel_frequency', 'rf_channel_width', 'tx_power', 'description', 'mark_connected', 'cable',
+            'cable_color', 'wireless_link', 'wireless_lans', 'link_peer', 'connection', 'tags', 'vdcs', 'vrf', 'l2vpn',
+            'tunnel', 'ip_addresses', 'fhrp_groups', 'untagged_vlan', 'tagged_vlans', 'qinq_svlan', 'inventory_items',
+            'created', 'last_updated', 'vlan_translation_policy',
         )
         )
         default_columns = ('pk', 'name', 'device', 'label', 'enabled', 'type', 'description')
         default_columns = ('pk', 'name', 'device', 'label', 'enabled', 'type', 'description')
 
 

+ 73 - 0
netbox/dcim/tests/test_api.py

@@ -4739,6 +4739,13 @@ class InterfaceTestCase(Mixins.FieldPrefetchMixin, Mixins.ComponentTraceMixin, A
                 'parent': channelized_parent.pk,
                 'parent': channelized_parent.pk,
                 'channel_id': 1,
                 'channel_id': 1,
             },
             },
+            {
+                'device': device.pk,
+                'name': 'Interface 11',
+                'type': InterfaceTypeChoices.TYPE_LAG,
+                'lag_mode': InterfaceLAGModeChoices.MODE_LACP,
+                'lag_hash_policy': InterfaceLAGHashPolicyChoices.POLICY_LAYER3_4,
+            },
         ]
         ]
 
 
     def _perform_interface_test_with_invalid_data(self, mode: str = None, invalid_data: dict = {}):
     def _perform_interface_test_with_invalid_data(self, mode: str = None, invalid_data: dict = {}):
@@ -4923,6 +4930,72 @@ class InterfaceTestCase(Mixins.FieldPrefetchMixin, Mixins.ComponentTraceMixin, A
         # Tagged-all mode, qinq service vlan
         # Tagged-all mode, qinq service vlan
         self._perform_interface_test_with_invalid_data(InterfaceModeChoices.MODE_TAGGED_ALL, invalid_data)
         self._perform_interface_test_with_invalid_data(InterfaceModeChoices.MODE_TAGGED_ALL, invalid_data)
 
 
+    def test_lag_attributes_on_non_lag_interface(self):
+        self.add_permissions('dcim.add_interface')
+
+        for field, value in (
+            ('lag_mode', InterfaceLAGModeChoices.MODE_LACP),
+            ('lag_hash_policy', InterfaceLAGHashPolicyChoices.POLICY_LAYER2),
+        ):
+            self._perform_interface_test_with_invalid_data(None, {field: value})
+
+    def test_lag_hash_policy_without_hash_mode(self):
+        self.add_permissions('dcim.add_interface')
+        data = {
+            'device': Device.objects.first().pk,
+            'name': 'bond0',
+            'type': InterfaceTypeChoices.TYPE_LAG,
+            'lag_mode': InterfaceLAGModeChoices.MODE_ACTIVE_BACKUP,
+            'lag_hash_policy': InterfaceLAGHashPolicyChoices.POLICY_LAYER3_4,
+        }
+
+        response = self.client.post(self._get_list_url(), data, format='json', **self.header)
+        self.assertHttpStatus(response, status.HTTP_400_BAD_REQUEST)
+        self.assertIn('lag_hash_policy', response.json())
+
+    def test_change_lag_mode_to_non_hash_mode(self):
+        """Changing to a non-hashing LAG mode via the API requires explicitly clearing the hash policy."""
+        self.add_permissions('dcim.change_interface')
+        lag = Interface.objects.create(
+            device=Device.objects.first(),
+            name='bond0',
+            type=InterfaceTypeChoices.TYPE_LAG,
+            lag_mode=InterfaceLAGModeChoices.MODE_LACP,
+            lag_hash_policy=InterfaceLAGHashPolicyChoices.POLICY_LAYER3_4,
+        )
+        url = self._get_detail_url(lag)
+
+        data = {'lag_mode': InterfaceLAGModeChoices.MODE_ACTIVE_BACKUP}
+        response = self.client.patch(url, data, format='json', **self.header)
+        self.assertHttpStatus(response, status.HTTP_400_BAD_REQUEST)
+        self.assertIn('lag_hash_policy', response.json())
+
+        data['lag_hash_policy'] = None
+        response = self.client.patch(url, data, format='json', **self.header)
+        self.assertHttpStatus(response, status.HTTP_200_OK)
+        lag.refresh_from_db()
+        self.assertEqual(lag.lag_mode, InterfaceLAGModeChoices.MODE_ACTIVE_BACKUP)
+        self.assertFalse(lag.lag_hash_policy)
+
+    def test_graphql_filter_lag_attributes(self):
+        self.add_permissions('dcim.view_interface')
+        lag = Interface.objects.create(
+            device=Device.objects.get(name='Device 1'),
+            name='LAG 1',
+            type=InterfaceTypeChoices.TYPE_LAG,
+            lag_mode=InterfaceLAGModeChoices.MODE_LACP,
+            lag_hash_policy=InterfaceLAGHashPolicyChoices.POLICY_LAYER3_4,
+        )
+
+        for filters in ('lag_mode: {exact: MODE_LACP}', 'lag_hash_policy: {exact: POLICY_LAYER3_4}'):
+            with self.subTest(filters=filters):
+                query = f'{{ interface_list(filters: {{ {filters} }}) {{ id }} }}'
+                response = self.client.post(reverse('graphql'), data={'query': query}, format='json', **self.header)
+                self.assertHttpStatus(response, status.HTTP_200_OK)
+                data = response.json()
+                self.assertNotIn('errors', data)
+                self.assertEqual([row['id'] for row in data['data']['interface_list']], [str(lag.pk)])
+
     def test_list_objects_reuse_peer_serializers(self):
     def test_list_objects_reuse_peer_serializers(self):
         """Link peers and connected endpoints share one nested serializer each per request."""
         """Link peers and connected endpoints share one nested serializer each per request."""
         self.add_permissions('dcim.view_interface')
         self.add_permissions('dcim.view_interface')

+ 29 - 0
netbox/dcim/tests/test_filtersets.py

@@ -5920,6 +5920,35 @@ class InterfaceTestCase(TestCase, DeviceComponentFilterSetTestMixin, ChangeLogge
         params = {'poe_type': [InterfacePoETypeChoices.TYPE_1_8023AF, InterfacePoETypeChoices.TYPE_2_8023AT]}
         params = {'poe_type': [InterfacePoETypeChoices.TYPE_1_8023AF, InterfacePoETypeChoices.TYPE_2_8023AT]}
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
 
 
+    def _create_lag_interfaces(self):
+        device = Device.objects.first()
+        for name, lag_mode, lag_hash_policy in (
+            ('LAG 1', InterfaceLAGModeChoices.MODE_LACP, InterfaceLAGHashPolicyChoices.POLICY_LAYER2),
+            ('LAG 2', InterfaceLAGModeChoices.MODE_STATIC, InterfaceLAGHashPolicyChoices.POLICY_LAYER2_3),
+            ('LAG 3', InterfaceLAGModeChoices.MODE_ACTIVE_BACKUP, None),
+        ):
+            interface = Interface(
+                device=device,
+                name=name,
+                type=InterfaceTypeChoices.TYPE_LAG,
+                lag_mode=lag_mode,
+                lag_hash_policy=lag_hash_policy,
+            )
+            interface.full_clean()
+            interface.save()
+
+    def test_lag_mode(self):
+        self._create_lag_interfaces()
+        params = {'lag_mode': [InterfaceLAGModeChoices.MODE_LACP, InterfaceLAGModeChoices.MODE_ACTIVE_BACKUP]}
+        self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
+
+    def test_lag_hash_policy(self):
+        self._create_lag_interfaces()
+        params = {'lag_hash_policy': [
+            InterfaceLAGHashPolicyChoices.POLICY_LAYER2, InterfaceLAGHashPolicyChoices.POLICY_LAYER2_3,
+        ]}
+        self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
+
     def test_mode(self):
     def test_mode(self):
         params = {'mode': [InterfaceModeChoices.MODE_ACCESS]}
         params = {'mode': [InterfaceModeChoices.MODE_ACCESS]}
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
         self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)

+ 95 - 0
netbox/dcim/tests/test_forms.py

@@ -11,6 +11,8 @@ from dcim.choices import (
     CableProfileChoices,
     CableProfileChoices,
     DeviceFaceChoices,
     DeviceFaceChoices,
     DeviceStatusChoices,
     DeviceStatusChoices,
+    InterfaceLAGHashPolicyChoices,
+    InterfaceLAGModeChoices,
     InterfaceModeChoices,
     InterfaceModeChoices,
     InterfaceTypeChoices,
     InterfaceTypeChoices,
     LinkStatusChoices,
     LinkStatusChoices,
@@ -1346,6 +1348,99 @@ class InterfaceTestCase(TestCase):
         self.assertNotIn('tagged_vlans', form.cleaned_data.keys())
         self.assertNotIn('tagged_vlans', form.cleaned_data.keys())
         self.assertNotIn('qinq_svlan', form.cleaned_data.keys())
         self.assertNotIn('qinq_svlan', form.cleaned_data.keys())
 
 
+    def test_lag_hash_policy_hidden_for_non_hash_mode(self):
+        """A LAG hash policy is offered only for hashing LAG modes, and is cleared when switching away from one."""
+        lag = Interface.objects.create(
+            device=self.device,
+            name='bond0',
+            type=InterfaceTypeChoices.TYPE_LAG,
+            lag_mode=InterfaceLAGModeChoices.MODE_LACP,
+            lag_hash_policy=InterfaceLAGHashPolicyChoices.POLICY_LAYER3_4,
+        )
+        self.assertIn('lag_hash_policy', InterfaceForm(instance=lag).fields)
+
+        data = {
+            'device': self.device.pk,
+            'name': 'bond0',
+            'type': InterfaceTypeChoices.TYPE_LAG,
+            'lag_mode': InterfaceLAGModeChoices.MODE_ACTIVE_BACKUP,
+            'lag_hash_policy': InterfaceLAGHashPolicyChoices.POLICY_LAYER3_4,
+        }
+        form = InterfaceForm(data, instance=lag)
+        self.assertNotIn('lag_hash_policy', form.fields)
+        self.assertTrue(form.is_valid(), form.errors)
+        form.save()
+
+        lag.refresh_from_db()
+        self.assertEqual(lag.lag_mode, InterfaceLAGModeChoices.MODE_ACTIVE_BACKUP)
+        self.assertIsNone(lag.lag_hash_policy)
+
+    def test_lag_mode_cleared(self):
+        """Clearing the LAG mode of a LAG interface also clears its hash policy."""
+        lag = Interface.objects.create(
+            device=self.device,
+            name='bond0',
+            type=InterfaceTypeChoices.TYPE_LAG,
+            lag_mode=InterfaceLAGModeChoices.MODE_LACP,
+            lag_hash_policy=InterfaceLAGHashPolicyChoices.POLICY_LAYER3_4,
+        )
+        data = {
+            'device': self.device.pk,
+            'name': 'bond0',
+            'type': InterfaceTypeChoices.TYPE_LAG,
+            'lag_mode': '',
+            'lag_hash_policy': InterfaceLAGHashPolicyChoices.POLICY_LAYER3_4,
+        }
+        form = InterfaceForm(data, instance=lag)
+        self.assertNotIn('lag_hash_policy', form.fields)
+        self.assertTrue(form.is_valid(), form.errors)
+        form.save()
+
+        lag.refresh_from_db()
+        self.assertFalse(lag.lag_mode)
+        self.assertIsNone(lag.lag_hash_policy)
+
+    def test_lag_attributes_cleared_when_changing_from_lag_type(self):
+        """Changing a LAG interface to another type clears its LAG mode and hash policy."""
+        lag = Interface.objects.create(
+            device=self.device,
+            name='bond0',
+            type=InterfaceTypeChoices.TYPE_LAG,
+            lag_mode=InterfaceLAGModeChoices.MODE_LACP,
+            lag_hash_policy=InterfaceLAGHashPolicyChoices.POLICY_LAYER3_4,
+        )
+        data = {
+            'device': self.device.pk,
+            'name': 'bond0',
+            'type': InterfaceTypeChoices.TYPE_1GE_FIXED,
+            'lag_mode': InterfaceLAGModeChoices.MODE_LACP,
+            'lag_hash_policy': InterfaceLAGHashPolicyChoices.POLICY_LAYER3_4,
+        }
+        form = InterfaceForm(data, instance=lag)
+        self.assertTrue(form.is_valid(), form.errors)
+        form.save()
+
+        lag.refresh_from_db()
+        self.assertEqual(lag.type, InterfaceTypeChoices.TYPE_1GE_FIXED)
+        self.assertIsNone(lag.lag_mode)
+        self.assertIsNone(lag.lag_hash_policy)
+
+    def test_lag_attributes_only_for_lag_interfaces(self):
+        """LAG attributes are offered only for LAG interfaces, and are not saved for any other type."""
+        self.assertIn('lag_mode', InterfaceForm(initial={'type': InterfaceTypeChoices.TYPE_LAG}).fields)
+
+        data = {
+            'device': self.device.pk,
+            'name': 'eth9',
+            'type': InterfaceTypeChoices.TYPE_1GE_FIXED,
+            'lag_mode': InterfaceLAGModeChoices.MODE_LACP,
+        }
+        form = InterfaceForm(data)
+        self.assertNotIn('lag_mode', form.fields)
+        self.assertNotIn('lag_hash_policy', form.fields)
+        self.assertTrue(form.is_valid(), form.errors)
+        self.assertIsNone(form.save().lag_mode)
+
     def test_child_interface_preselects_every_parent_vdc(self):
     def test_child_interface_preselects_every_parent_vdc(self):
         """A child interface's form pre-selects every virtual device context of its parent."""
         """A child interface's form pre-selects every virtual device context of its parent."""
         vdcs = (
         vdcs = (

+ 69 - 0
netbox/dcim/tests/test_models.py

@@ -3934,6 +3934,75 @@ class CableDisconnectChangeLoggingTestCase(TestCase):
         self.assertFalse(self._updates(self.interface1).filter(request_id=request.id).exists())
         self.assertFalse(self._updates(self.interface1).filter(request_id=request.id).exists())
 
 
 
 
+class InterfaceLAGAttributesTestCase(TestCase):
+
+    @classmethod
+    def setUpTestData(cls):
+        site = Site.objects.create(name='Site 1', slug='site-1')
+        manufacturer = Manufacturer.objects.create(name='Manufacturer 1', slug='manufacturer-1')
+        devicetype = DeviceType.objects.create(manufacturer=manufacturer, model='Device Type 1', slug='device-type-1')
+        role = DeviceRole.objects.create(name='Device Role 1', slug='device-role-1', color='ff0000')
+        cls.device = Device.objects.create(device_type=devicetype, role=role, name='Device 1', site=site)
+
+    def test_lag_attributes_on_lag_interface(self):
+        interface = Interface(
+            device=self.device,
+            name='bond0',
+            type=InterfaceTypeChoices.TYPE_LAG,
+            lag_mode=InterfaceLAGModeChoices.MODE_LACP,
+            lag_hash_policy=InterfaceLAGHashPolicyChoices.POLICY_LAYER3_4,
+        )
+        interface.full_clean()
+
+    def test_lag_mode_on_non_lag_interface(self):
+        interface = Interface(
+            device=self.device,
+            name='eth0',
+            type=InterfaceTypeChoices.TYPE_1GE_FIXED,
+            lag_mode=InterfaceLAGModeChoices.MODE_LACP,
+        )
+        with self.assertRaises(ValidationError) as cm:
+            interface.full_clean()
+        self.assertIn('lag_mode', cm.exception.message_dict)
+
+    def test_lag_hash_policy_on_non_lag_interface(self):
+        interface = Interface(
+            device=self.device,
+            name='eth0',
+            type=InterfaceTypeChoices.TYPE_1GE_FIXED,
+            lag_hash_policy=InterfaceLAGHashPolicyChoices.POLICY_LAYER2,
+        )
+        with self.assertRaises(ValidationError) as cm:
+            interface.full_clean()
+        self.assertIn('lag_hash_policy', cm.exception.message_dict)
+
+    def test_lag_hash_policy_lag_mode(self):
+        for lag_mode, valid in (
+            (None, False),
+            (InterfaceLAGModeChoices.MODE_LACP, True),
+            (InterfaceLAGModeChoices.MODE_STATIC, True),
+            (InterfaceLAGModeChoices.MODE_BALANCE_TLB, False),
+            (InterfaceLAGModeChoices.MODE_ACTIVE_BACKUP, False),
+            (InterfaceLAGModeChoices.MODE_BALANCE_RR, False),
+            (InterfaceLAGModeChoices.MODE_BALANCE_ALB, False),
+            (InterfaceLAGModeChoices.MODE_BROADCAST, False),
+        ):
+            with self.subTest(lag_mode=lag_mode):
+                interface = Interface(
+                    device=self.device,
+                    name='bond0',
+                    type=InterfaceTypeChoices.TYPE_LAG,
+                    lag_mode=lag_mode,
+                    lag_hash_policy=InterfaceLAGHashPolicyChoices.POLICY_LAYER3_4,
+                )
+                if valid:
+                    interface.full_clean()
+                else:
+                    with self.assertRaises(ValidationError) as cm:
+                        interface.full_clean()
+                    self.assertIn('lag_hash_policy', cm.exception.message_dict)
+
+
 class VirtualDeviceContextTestCase(TestCase):
 class VirtualDeviceContextTestCase(TestCase):
 
 
     @classmethod
     @classmethod

+ 2 - 0
netbox/dcim/ui/panels.py

@@ -621,6 +621,8 @@ class InterfacePanel(panels.ObjectAttributesPanel):
     description = attrs.TextAttr('description')
     description = attrs.TextAttr('description')
     poe_mode = attrs.ChoiceAttr('poe_mode', label=_('PoE mode'))
     poe_mode = attrs.ChoiceAttr('poe_mode', label=_('PoE mode'))
     poe_type = attrs.ChoiceAttr('poe_type', label=_('PoE type'))
     poe_type = attrs.ChoiceAttr('poe_type', label=_('PoE type'))
+    lag_mode = attrs.ChoiceAttr('lag_mode', label=_('LAG mode'))
+    lag_hash_policy = attrs.ChoiceAttr('lag_hash_policy', label=_('LAG hash policy'))
     mode = attrs.ChoiceAttr('mode', label=_('802.1Q mode'))
     mode = attrs.ChoiceAttr('mode', label=_('802.1Q mode'))
     qinq_svlan = attrs.RelatedObjectAttr('qinq_svlan', linkify=True, label=_('Q-in-Q SVLAN'))
     qinq_svlan = attrs.RelatedObjectAttr('qinq_svlan', linkify=True, label=_('Q-in-Q SVLAN'))
     untagged_vlan = attrs.RelatedObjectAttr('untagged_vlan', linkify=True, label=_('Untagged VLAN'))
     untagged_vlan = attrs.RelatedObjectAttr('untagged_vlan', linkify=True, label=_('Untagged VLAN'))

+ 2 - 2
netbox/utilities/templates/form_helpers/render_fieldset.html

@@ -1,7 +1,7 @@
 {% load i18n %}
 {% load i18n %}
 {% load form_helpers %}
 {% load form_helpers %}
-<div class="field-group mb-5"{% if html_id %} id="{{ html_id }}"{% endif %}{% if heading %} role="group" aria-label="{{ heading }}"{% endif %}>
-  {% if heading %}
+<div class="field-group{% if rows %} mb-5{% endif %}"{% if html_id %} id="{{ html_id }}"{% endif %}{% if heading %} role="group" aria-label="{{ heading }}"{% endif %}>
+  {% if heading and rows %}
     <div class="row">
     <div class="row">
       <h2 class="col-9 offset-3">{{ heading }}</h2>
       <h2 class="col-9 offset-3">{{ heading }}</h2>
     </div>
     </div>