module infix-interfaces {
  yang-version 1.1;
  namespace "urn:infix:interfaces:ns:yang:1.0";
  prefix infix-if;

  import ietf-interfaces {
    prefix if;
  }
  import ietf-yang-types {
    prefix yang;
  }
  import ietf-inet-types {
    prefix inet;
  }
  import ietf-keystore {
    prefix ks;
  }
  import infix-if-type {
    prefix infix-ift;
  }

  include infix-if-base;
  include infix-if-bridge;
  include infix-if-lag;
  include infix-if-container;
  include infix-if-veth;
  include infix-if-vlan;
  include infix-if-gre;
  include infix-if-vxlan;
  include infix-if-wifi;

  organization "KernelKit";
  contact      "kernelkit@googlegroups.com";
  description  "Linux bridge and lag extensions for ietf-interfaces.";

  revision 2025-06-17 {
    description "Add support for Wi-Fi client.";
    reference "internal";
  }

 revision 2025-01-09 {
    description "Add support for link aggregation, static and LACP.";
    reference "internal";
  }

  revision 2025-01-08 {
    description "Add Spanning Tree Protocol (STP) support to bridges.";
    reference "internal";
  }

  revision 2024-11-27 {
    description "Allow IP addresses directly on VLAN filtering bridges.";
    reference "internal";
  }

  revision 2024-11-15 {
    description "Two changes:
                  - Limit name 1-15 chars, Linux limitation
                  - Relocate 'feature containers' to submodule";
    reference "internal";
  }

  revision 2024-10-28 {
    description "Limit description to 64 chars, matching IF-MIB max.";
    reference "internal";
  }

  revision 2024-10-14 {
    description "Deviate link-up-down-trap-enable not-supported.";
    reference "internal";
  }

  revision 2024-10-08 {
    description "Replace writable phy-address with custom-phys-address.";
    reference "internal";
  }

  revision 2024-09-23 {
    description "Drop interfaces-state deviation, already marked deprecated.";
    reference "internal";
  }

  revision 2024-01-15 {
    description "Add support for container ports (CNI networks).";
    reference "internal";
  }

  revision 2023-09-19 {
    description "Add deviation to allow setting phys-address on links.";
    reference "internal";
  }

  revision 2023-08-21 {
    description "Move port augment to submodule for infix-if-bridge and
                 infix-if-lag (later) which reference it.

                 Add deviation to if:type to limit the iana-if-types to
                 only those supported, also reduce list for CLI <TAB>.

                 Lint: move include and import to match canonical order.";
    reference "internal";
  }

  revision 2023-06-05 {
    description "Initial revision.";
    reference "internal";
  }

  grouping local-remote {
    description "Local address to use as source address";
    leaf local {
      type inet:ip-address;
      mandatory true;
    }
    leaf remote {
      description "Peer address";
      type inet:ip-address;
      must "(contains(../local, ':') and contains(., ':'))
            or (not(contains(../local, ':')) and not(contains(., ':')))" {
        error-message
          "Local and remote must be both IPv4 or both IPv6 addresses.";
      }
      mandatory true;
    }
  }

  /*
   * Data Nodes
   */

  deviation "/if:interfaces/if:interface/if:type" {
    deviate replace {
      type identityref {
        base infix-ift:infix-interface-type;
      }
    }
  }

  deviation "/if:interfaces/if:interface/if:name" {
    deviate replace {
      type string {
        length "1..15";
      }
    }
  }

  deviation "/if:interfaces/if:interface/if:description" {
    deviate replace {
      type string {
        length "0..64";
      }
    }
  }

  deviation "/if:interfaces/if:interface/if:link-up-down-trap-enable" {
    deviate not-supported;
  }

  augment "/if:interfaces/if:interface" {
    description "Custom phys-address management, static or derived from chassis MAC.";

    container custom-phys-address {
      description "Override the default physical address.";

      choice type {
        description "Choose between static MAC address or chassis-derived MAC.";

        case static {
          leaf static {
            description "Statically configured interface address on protocol sub-layer, e.g., MAC.";
            type yang:phys-address;
          }
        }

        case chassis {
          container chassis {
            description "Derive physical address from chassis MAC address.";
            presence "Enable chassis-derived address.";

            leaf offset {
              description "Static offset added to the chassis MAC address.";
              type yang:phys-address;
            }
          }
        }
      }
    }
  }
}
