DSA Interfaces

Linux has a DSA1 subsystem to support ethernet switches. The command ifstatecli identify can be used to write a custom ifstate.yaml configuration file. The following example was used on a Banana Pi BPI-R4.

interfaces:
  end0:
    link:
      state: up
      kind: physical
    identify:
      of_node: base/soc/ethernet@15100000/mac@0
  end1:
    link:
      state: up
      kind: physical
    identify:
      of_node: base/soc/ethernet@15100000/mac@1
  end2:
    link:
      state: up
      kind: physical
    identify:
      of_node: base/soc/ethernet@15100000/mac@2
  wan:
    addresses:
    - 192.0.2.2/31
    - 2001:0db8::2/64
    link:
      state: up
      kind: dsa
      link: end0
    identify:
      of_node: base/soc/switch@15020000/ports/port@0
  lan1:
    link:
      state: up
      kind: dsa
      link: end0
      master: br-lan
    identify:
      of_node: base/soc/switch@15020000/ports/port@1
  lan2:
    link:
      state: up
      kind: dsa
      link: end0
      master: br-lan
    identify:
      of_node: base/soc/switch@15020000/ports/port@2
  lan3:
    link:
      state: up
      kind: dsa
      link: end0
      master: br-lan
    identify:
      of_node: base/soc/switch@15020000/ports/port@3
  br-lan:
    addresses:
    - 192.0.2.128/25
    link:
      state: up
      kind: bridge

routing:
  routes:
  - to: 0.0.0.0/0
    dev: wan
    via: 192.0.2.1
  - to: ::/0
    dev: wan
    via: 2001:0db8::1
{
  networking.ifstate = {
    enable = true;
    settings = {
      interfaces = {
        end0 = {
          link = {
            state = "up";
            kind = "physical";
          };
          identify.of_node = "base/soc/ethernet@15100000/mac@0";
        };
        end1 = {
          link = {
            state = "up";
            kind = "physical";
          };
          identify.of_node = "base/soc/ethernet@15100000/mac@1";
        };
        end2 = {
          link = {
            state = "up";
            kind = "physical";
          };
          identify.of_node = "base/soc/ethernet@15100000/mac@2";
        };
        wan = {
          addresses = [ "192.0.2.2/31" "2001:0db8::2/64" ];
          link = {
            state = "up";
            kind = "dsa";
            link = "end0";
          };
          identify.of_node = "base/soc/switch@15020000/ports/port@0";
        };
        lan1 = {
          link = {
            state = "up";
            kind = "dsa";
            link = "end0";
            master = "br-lan";
          };
          identify.of_node = "base/soc/switch@15020000/ports/port@1";
        };
        lan2 = {
          link = {
            state = "up";
            kind = "dsa";
            link = "end0";
            master = "br-lan";
          };
          identify.of_node = "base/soc/switch@15020000/ports/port@2";
        };
        lan3 = {
          link = {
            state = "up";
            kind = "dsa";
            link = "end0";
            master = "br-lan";
          };
          identify.of_node = "base/soc/switch@15020000/ports/port@3";
        };
        br-lan = {
          addresses = [ "192.0.2.128/25" ];
          link = {
            state = "up";
            kind = "bridge";
          };
        };
      };
      routing.routes = [
        {
          to = "0.0.0.0/0";
          dev = "wan";
          via = "192.0.2.1";
        }
        {
          to = "::/0";
          dev = "wan";
          via = "2001:0db8::1";
        }
      ];
    };
  };
}

  1. Distributed Switch Architecture