__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.217.30: ~ $
<!DOCTYPE html>

<html lang="en" data-content_root="../">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

    <title>Ethernet switch device driver model (switchdev) &#8212; The Linux Kernel  documentation</title>
    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=fa44fd50" />
    <link rel="stylesheet" type="text/css" href="../_static/alabaster.css?v=3918102e" />
    <script src="../_static/documentation_options.js?v=5929fcd5"></script>
    <script src="../_static/doctools.js?v=9bcbadda"></script>
    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Sysfs tagging" href="sysfs-tagging.html" />
    <link rel="prev" title="Stream Parser (strparser)" href="strparser.html" />
   
  <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
  

  
  

  </head><body>
  <div class="document">
    
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../index.html">
              <img class="logo" src="../_static/logo.svg" alt="Logo of The Linux Kernel"/>
            </a></p>
<h1 class="logo"><a href="../index.html">The Linux Kernel</a></h1>



<p class="blurb">6.18.50</p>







<search id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>


<p>
<h3 class="kernel-toc-contents">Contents</h3>
<input type="checkbox" class="kernel-toc-toggle" id = "kernel-toc-toggle" checked>
<label class="kernel-toc-title" for="kernel-toc-toggle"></label>

<div class="kerneltoc" id="kerneltoc">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../process/development-process.html">Development process</a></li>
<li class="toctree-l1"><a class="reference internal" href="../process/submitting-patches.html">Submitting patches</a></li>
<li class="toctree-l1"><a class="reference internal" href="../process/code-of-conduct.html">Code of conduct</a></li>
<li class="toctree-l1"><a class="reference internal" href="../maintainer/index.html">Maintainer handbook</a></li>
<li class="toctree-l1"><a class="reference internal" href="../process/index.html">All development-process docs</a></li>
</ul>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../core-api/index.html">Core API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../driver-api/index.html">Driver APIs</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../subsystem-apis.html">Subsystems</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../subsystem-apis.html#core-subsystems">Core subsystems</a></li>
<li class="toctree-l2"><a class="reference internal" href="../subsystem-apis.html#human-interfaces">Human interfaces</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../subsystem-apis.html#networking-interfaces">Networking interfaces</a><ul class="current">
<li class="toctree-l3 current"><a class="reference internal" href="index.html">Networking</a></li>
<li class="toctree-l3"><a class="reference internal" href="../netlabel/index.html">NetLabel</a></li>
<li class="toctree-l3"><a class="reference internal" href="../infiniband/index.html">InfiniBand</a></li>
<li class="toctree-l3"><a class="reference internal" href="../isdn/index.html">ISDN</a></li>
<li class="toctree-l3"><a class="reference internal" href="../mhi/index.html">MHI</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../subsystem-apis.html#storage-interfaces">Storage interfaces</a></li>
<li class="toctree-l2"><a class="reference internal" href="../subsystem-apis.html#other-subsystems">Other subsystems</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../locking/index.html">Locking</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../process/license-rules.html">Licensing rules</a></li>
<li class="toctree-l1"><a class="reference internal" href="../doc-guide/index.html">Writing documentation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../dev-tools/index.html">Development tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../dev-tools/testing-overview.html">Testing guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../kernel-hacking/index.html">Hacking guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../trace/index.html">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../fault-injection/index.html">Fault injection</a></li>
<li class="toctree-l1"><a class="reference internal" href="../livepatch/index.html">Livepatching</a></li>
<li class="toctree-l1"><a class="reference internal" href="../rust/index.html">Rust</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../admin-guide/index.html">Administration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../kbuild/index.html">Build system</a></li>
<li class="toctree-l1"><a class="reference internal" href="../admin-guide/reporting-issues.html">Reporting issues</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tools/index.html">Userspace tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../userspace-api/index.html">Userspace API</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../firmware-guide/index.html">Firmware</a></li>
<li class="toctree-l1"><a class="reference internal" href="../devicetree/index.html">Firmware and Devicetree</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../arch/index.html">CPU architectures</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../staging/index.html">Unsorted documentation</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../translations/index.html">Translations</a></li>
</ul>

</div>

<script type="text/javascript"> <!--
  var sbar = document.getElementsByClassName("sphinxsidebar")[0];
  let currents = document.getElementsByClassName("current")
  if (currents.length) {
    sbar.scrollTop = currents[currents.length - 1].offsetTop;
  }
  --> </script>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/networking/switchdev.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
        </div>
      </div>
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  



<section id="ethernet-switch-device-driver-model-switchdev">
<span id="switchdev"></span><h1>Ethernet switch device driver model (switchdev)<a class="headerlink" href="#ethernet-switch-device-driver-model-switchdev" title="Link to this heading">¶</a></h1>
<p>Copyright © 2014 Jiri Pirko &lt;<a class="reference external" href="mailto:jiri&#37;&#52;&#48;resnulli&#46;us">jiri<span>&#64;</span>resnulli<span>&#46;</span>us</a>&gt;</p>
<p>Copyright © 2014-2015 Scott Feldman &lt;<a class="reference external" href="mailto:sfeldma&#37;&#52;&#48;gmail&#46;com">sfeldma<span>&#64;</span>gmail<span>&#46;</span>com</a>&gt;</p>
<p>The Ethernet switch device driver model (switchdev) is an in-kernel driver
model for switch devices which offload the forwarding (data) plane from the
kernel.</p>
<p>Figure 1 is a block diagram showing the components of the switchdev model for
an example setup using a data-center-class switch ASIC chip.  Other setups
with SR-IOV or soft switches, such as OVS, are possible.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>                       User-space tools

 user space                   |
+-------------------------------------------------------------------+
 kernel                       | Netlink
                              |
               +--------------+-------------------------------+
               |         Network stack                        |
               |           (Linux)                            |
               |                                              |
               +----------------------------------------------+

                     sw1p2     sw1p4     sw1p6
                sw1p1  +  sw1p3  +  sw1p5  +          eth1
                  +    |    +    |    +    |            +
                  |    |    |    |    |    |            |
               +--+----+----+----+----+----+---+  +-----+-----+
               |         Switch driver         |  |    mgmt   |
               |        (this document)        |  |   driver  |
               |                               |  |           |
               +--------------+----------------+  +-----------+
                              |
 kernel                       | HW bus (eg PCI)
+-------------------------------------------------------------------+
 hardware                     |
               +--------------+----------------+
               |         Switch device (sw1)   |
               |  +----+                       +--------+
               |  |    v offloaded data path   | mgmt port
               |  |    |                       |
               +--|----|----+----+----+----+---+
                  |    |    |    |    |    |
                  +    +    +    +    +    +
                 p1   p2   p3   p4   p5   p6

                       front-panel ports


                              Fig 1.
</pre></div>
</div>
<section id="include-files">
<h2>Include Files<a class="headerlink" href="#include-files" title="Link to this heading">¶</a></h2>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>#include &lt;linux/netdevice.h&gt;
#include &lt;net/switchdev.h&gt;
</pre></div>
</div>
</section>
<section id="configuration">
<h2>Configuration<a class="headerlink" href="#configuration" title="Link to this heading">¶</a></h2>
<p>Use “depends NET_SWITCHDEV” in driver’s Kconfig to ensure switchdev model
support is built for driver.</p>
</section>
<section id="switch-ports">
<h2>Switch Ports<a class="headerlink" href="#switch-ports" title="Link to this heading">¶</a></h2>
<p>On switchdev driver initialization, the driver will allocate and register a
<a class="reference internal" href="kapi.html#c.net_device" title="net_device"><code class="xref c c-struct docutils literal notranslate"><span class="pre">struct</span> <span class="pre">net_device</span></code></a> (using <a class="reference internal" href="kapi.html#c.register_netdev" title="register_netdev"><code class="xref c c-func docutils literal notranslate"><span class="pre">register_netdev()</span></code></a>) for each enumerated physical switch
port, called the port netdev.  A port netdev is the software representation of
the physical port and provides a conduit for control traffic to/from the
controller (the kernel) and the network, as well as an anchor point for higher
level constructs such as bridges, bonds, VLANs, tunnels, and L3 routers.  Using
standard netdev tools (iproute2, ethtool, etc), the port netdev can also
provide to the user access to the physical properties of the switch port such
as PHY link state and I/O statistics.</p>
<p>There is (currently) no higher-level kernel object for the switch beyond the
port netdevs.  All of the switchdev driver ops are netdev ops or switchdev ops.</p>
<p>A switch management port is outside the scope of the switchdev driver model.
Typically, the management port is not participating in offloaded data plane and
is loaded with a different driver, such as a NIC driver, on the management port
device.</p>
<section id="switch-id">
<h3>Switch ID<a class="headerlink" href="#switch-id" title="Link to this heading">¶</a></h3>
<p>The switchdev driver must implement the net_device operation
ndo_get_port_parent_id for each port netdev, returning the same physical ID for
each port of a switch. The ID must be unique between switches on the same
system. The ID does not need to be unique between switches on different
systems.</p>
<p>The switch ID is used to locate ports on a switch and to know if aggregated
ports belong to the same switch.</p>
</section>
<section id="port-netdev-naming">
<h3>Port Netdev Naming<a class="headerlink" href="#port-netdev-naming" title="Link to this heading">¶</a></h3>
<p>Udev rules should be used for port netdev naming, using some unique attribute
of the port as a key, for example the port MAC address or the port PHYS name.
Hard-coding of kernel netdev names within the driver is discouraged; let the
kernel pick the default netdev name, and let udev set the final name based on a
port attribute.</p>
<p>Using port PHYS name (ndo_get_phys_port_name) for the key is particularly
useful for dynamically-named ports where the device names its ports based on
external configuration.  For example, if a physical 40G port is split logically
into 4 10G ports, resulting in 4 port netdevs, the device can give a unique
name for each port using port PHYS name.  The udev rule would be:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>SUBSYSTEM==&quot;net&quot;, ACTION==&quot;add&quot;, ATTR{phys_switch_id}==&quot;&lt;phys_switch_id&gt;&quot;, \
        ATTR{phys_port_name}!=&quot;&quot;, NAME=&quot;swX$attr{phys_port_name}&quot;
</pre></div>
</div>
<p>Suggested naming convention is “swXpYsZ”, where X is the switch name or ID, Y
is the port name or ID, and Z is the sub-port name or ID.  For example, sw1p1s0
would be sub-port 0 on port 1 on switch 1.</p>
</section>
<section id="port-features">
<h3>Port Features<a class="headerlink" href="#port-features" title="Link to this heading">¶</a></h3>
<p>dev-&gt;netns_immutable</p>
<p>If the switchdev driver (and device) only supports offloading of the default
network namespace (netns), the driver should set this private flag to prevent
the port netdev from being moved out of the default netns.  A netns-aware
driver/device would not set this flag and be responsible for partitioning
hardware to preserve netns containment.  This means hardware cannot forward
traffic from a port in one namespace to another port in another namespace.</p>
</section>
<section id="port-topology">
<h3>Port Topology<a class="headerlink" href="#port-topology" title="Link to this heading">¶</a></h3>
<p>The port netdevs representing the physical switch ports can be organized into
higher-level switching constructs.  The default construct is a standalone
router port, used to offload L3 forwarding.  Two or more ports can be bonded
together to form a LAG.  Two or more ports (or LAGs) can be bridged to bridge
L2 networks.  VLANs can be applied to sub-divide L2 networks.  L2-over-L3
tunnels can be built on ports.  These constructs are built using standard Linux
tools such as the bridge driver, the bonding/team drivers, and netlink-based
tools such as iproute2.</p>
<p>The switchdev driver can know a particular port’s position in the topology by
monitoring NETDEV_CHANGEUPPER notifications.  For example, a port moved into a
bond will see its upper master change.  If that bond is moved into a bridge,
the bond’s upper master will change.  And so on.  The driver will track such
movements to know what position a port is in in the overall topology by
registering for netdevice events and acting on NETDEV_CHANGEUPPER.</p>
</section>
</section>
<section id="l2-forwarding-offload">
<h2>L2 Forwarding Offload<a class="headerlink" href="#l2-forwarding-offload" title="Link to this heading">¶</a></h2>
<p>The idea is to offload the L2 data forwarding (switching) path from the kernel
to the switchdev device by mirroring bridge FDB entries down to the device.  An
FDB entry is the {port, MAC, VLAN} tuple forwarding destination.</p>
<p>To offloading L2 bridging, the switchdev driver/device should support:</p>
<blockquote>
<div><ul class="simple">
<li><p>Static FDB entries installed on a bridge port</p></li>
<li><p>Notification of learned/forgotten src mac/vlans from device</p></li>
<li><p>STP state changes on the port</p></li>
<li><p>VLAN flooding of multicast/broadcast and unknown unicast packets</p></li>
</ul>
</div></blockquote>
<section id="static-fdb-entries">
<h3>Static FDB Entries<a class="headerlink" href="#static-fdb-entries" title="Link to this heading">¶</a></h3>
<p>A driver which implements the <code class="docutils literal notranslate"><span class="pre">ndo_fdb_add</span></code>, <code class="docutils literal notranslate"><span class="pre">ndo_fdb_del</span></code> and
<code class="docutils literal notranslate"><span class="pre">ndo_fdb_dump</span></code> operations is able to support the command below, which adds a
static bridge FDB entry:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>bridge fdb add dev DEV ADDRESS [vlan VID] [self] static
</pre></div>
</div>
<p>(the “static” keyword is non-optional: if not specified, the entry defaults to
being “local”, which means that it should not be forwarded)</p>
<p>The “self” keyword (optional because it is implicit) has the role of
instructing the kernel to fulfill the operation through the <code class="docutils literal notranslate"><span class="pre">ndo_fdb_add</span></code>
implementation of the <code class="docutils literal notranslate"><span class="pre">DEV</span></code> device itself. If <code class="docutils literal notranslate"><span class="pre">DEV</span></code> is a bridge port, this
will bypass the bridge and therefore leave the software database out of sync
with the hardware one.</p>
<p>To avoid this, the “master” keyword can be used:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>bridge fdb add dev DEV ADDRESS [vlan VID] master static
</pre></div>
</div>
<p>The above command instructs the kernel to search for a master interface of
<code class="docutils literal notranslate"><span class="pre">DEV</span></code> and fulfill the operation through the <code class="docutils literal notranslate"><span class="pre">ndo_fdb_add</span></code> method of that.
This time, the bridge generates a <code class="docutils literal notranslate"><span class="pre">SWITCHDEV_FDB_ADD_TO_DEVICE</span></code> notification
which the port driver can handle and use it to program its hardware table. This
way, the software and the hardware database will both contain this static FDB
entry.</p>
<p>Note: for new switchdev drivers that offload the Linux bridge, implementing the
<code class="docutils literal notranslate"><span class="pre">ndo_fdb_add</span></code> and <code class="docutils literal notranslate"><span class="pre">ndo_fdb_del</span></code> bridge bypass methods is strongly
discouraged: all static FDB entries should be added on a bridge port using the
“master” flag. The <code class="docutils literal notranslate"><span class="pre">ndo_fdb_dump</span></code> is an exception and can be implemented to
visualize the hardware tables, if the device does not have an interrupt for
notifying the operating system of newly learned/forgotten dynamic FDB
addresses. In that case, the hardware FDB might end up having entries that the
software FDB does not, and implementing <code class="docutils literal notranslate"><span class="pre">ndo_fdb_dump</span></code> is the only way to see
them.</p>
<p>Note: by default, the bridge does not filter on VLAN and only bridges untagged
traffic.  To enable VLAN support, turn on VLAN filtering:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>echo 1 &gt;/sys/class/net/&lt;bridge&gt;/bridge/vlan_filtering
</pre></div>
</div>
</section>
<section id="notification-of-learned-forgotten-source-mac-vlans">
<h3>Notification of Learned/Forgotten Source MAC/VLANs<a class="headerlink" href="#notification-of-learned-forgotten-source-mac-vlans" title="Link to this heading">¶</a></h3>
<p>The switch device will learn/forget source MAC address/VLAN on ingress packets
and notify the switch driver of the mac/vlan/port tuples.  The switch driver,
in turn, will notify the bridge driver using the switchdev notifier call:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>err = call_switchdev_notifiers(val, dev, info, extack);
</pre></div>
</div>
<p>Where val is SWITCHDEV_FDB_ADD when learning and SWITCHDEV_FDB_DEL when
forgetting, and info points to a <code class="xref c c-struct broken_xref docutils literal notranslate"><span class="pre">struct</span> <span class="pre">switchdev_notifier_fdb_info</span></code>.  On
SWITCHDEV_FDB_ADD, the bridge driver will install the FDB entry into the
bridge’s FDB and mark the entry as NTF_EXT_LEARNED.  The iproute2 bridge
command will label these entries “offload”:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>$ bridge fdb
52:54:00:12:35:01 dev sw1p1 master br0 permanent
00:02:00:00:02:00 dev sw1p1 master br0 offload
00:02:00:00:02:00 dev sw1p1 self
52:54:00:12:35:02 dev sw1p2 master br0 permanent
00:02:00:00:03:00 dev sw1p2 master br0 offload
00:02:00:00:03:00 dev sw1p2 self
33:33:00:00:00:01 dev eth0 self permanent
01:00:5e:00:00:01 dev eth0 self permanent
33:33:ff:00:00:00 dev eth0 self permanent
01:80:c2:00:00:0e dev eth0 self permanent
33:33:00:00:00:01 dev br0 self permanent
01:00:5e:00:00:01 dev br0 self permanent
33:33:ff:12:35:01 dev br0 self permanent
</pre></div>
</div>
<p>Learning on the port should be disabled on the bridge using the bridge command:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>bridge link set dev DEV learning off
</pre></div>
</div>
<p>Learning on the device port should be enabled, as well as learning_sync:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>bridge link set dev DEV learning on self
bridge link set dev DEV learning_sync on self
</pre></div>
</div>
<p>Learning_sync attribute enables syncing of the learned/forgotten FDB entry to
the bridge’s FDB.  It’s possible, but not optimal, to enable learning on the
device port and on the bridge port, and disable learning_sync.</p>
<p>To support learning, the driver implements switchdev op
switchdev_port_attr_set for SWITCHDEV_ATTR_PORT_ID_{PRE}_BRIDGE_FLAGS.</p>
</section>
<section id="fdb-ageing">
<h3>FDB Ageing<a class="headerlink" href="#fdb-ageing" title="Link to this heading">¶</a></h3>
<p>The bridge will skip ageing FDB entries marked with NTF_EXT_LEARNED and it is
the responsibility of the port driver/device to age out these entries.  If the
port device supports ageing, when the FDB entry expires, it will notify the
driver which in turn will notify the bridge with SWITCHDEV_FDB_DEL.  If the
device does not support ageing, the driver can simulate ageing using a
garbage collection timer to monitor FDB entries.  Expired entries will be
notified to the bridge using SWITCHDEV_FDB_DEL.  See rocker driver for
example of driver running ageing timer.</p>
<p>To keep an NTF_EXT_LEARNED entry “alive”, the driver should refresh the FDB
entry by calling call_switchdev_notifiers(SWITCHDEV_FDB_ADD, ...).  The
notification will reset the FDB entry’s last-used time to now.  The driver
should rate limit refresh notifications, for example, no more than once a
second.  (The last-used time is visible using the bridge -s fdb option).</p>
</section>
<section id="stp-state-change-on-port">
<h3>STP State Change on Port<a class="headerlink" href="#stp-state-change-on-port" title="Link to this heading">¶</a></h3>
<p>Internally or with a third-party STP protocol implementation (e.g. mstpd), the
bridge driver maintains the STP state for ports, and will notify the switch
driver of STP state change on a port using the switchdev op
switchdev_attr_port_set for SWITCHDEV_ATTR_PORT_ID_STP_UPDATE.</p>
<p>State is one of BR_STATE_*.  The switch driver can use STP state updates to
update ingress packet filter list for the port.  For example, if port is
DISABLED, no packets should pass, but if port moves to BLOCKED, then STP BPDUs
and other IEEE 01:80:c2:xx:xx:xx link-local multicast packets can pass.</p>
<p>Note that STP BDPUs are untagged and STP state applies to all VLANs on the port
so packet filters should be applied consistently across untagged and tagged
VLANs on the port.</p>
</section>
<section id="flooding-l2-domain">
<h3>Flooding L2 domain<a class="headerlink" href="#flooding-l2-domain" title="Link to this heading">¶</a></h3>
<p>For a given L2 VLAN domain, the switch device should flood multicast/broadcast
and unknown unicast packets to all ports in domain, if allowed by port’s
current STP state.  The switch driver, knowing which ports are within which
vlan L2 domain, can program the switch device for flooding.  The packet may
be sent to the port netdev for processing by the bridge driver.  The
bridge should not reflood the packet to the same ports the device flooded,
otherwise there will be duplicate packets on the wire.</p>
<p>To avoid duplicate packets, the switch driver should mark a packet as already
forwarded by setting the skb-&gt;offload_fwd_mark bit. The bridge driver will mark
the skb using the ingress bridge port’s mark and prevent it from being forwarded
through any bridge port with the same mark.</p>
<p>It is possible for the switch device to not handle flooding and push the
packets up to the bridge driver for flooding.  This is not ideal as the number
of ports scale in the L2 domain as the device is much more efficient at
flooding packets that software.</p>
<p>If supported by the device, flood control can be offloaded to it, preventing
certain netdevs from flooding unicast traffic for which there is no FDB entry.</p>
</section>
<section id="igmp-snooping">
<h3>IGMP Snooping<a class="headerlink" href="#igmp-snooping" title="Link to this heading">¶</a></h3>
<p>In order to support IGMP snooping, the port netdevs should trap to the bridge
driver all IGMP join and leave messages.
The bridge multicast module will notify port netdevs on every multicast group
changed whether it is static configured or dynamically joined/leave.
The hardware implementation should be forwarding all registered multicast
traffic groups only to the configured ports.</p>
</section>
</section>
<section id="l3-routing-offload">
<h2>L3 Routing Offload<a class="headerlink" href="#l3-routing-offload" title="Link to this heading">¶</a></h2>
<p>Offloading L3 routing requires that device be programmed with FIB entries from
the kernel, with the device doing the FIB lookup and forwarding.  The device
does a longest prefix match (LPM) on FIB entries matching route prefix and
forwards the packet to the matching FIB entry’s nexthop(s) egress ports.</p>
<p>To program the device, the driver has to register a FIB notifier handler
using register_fib_notifier. The following events are available:</p>
<table class="docutils align-default">
<tbody>
<tr class="row-odd"><td><p>FIB_EVENT_ENTRY_ADD</p></td>
<td><p>used for both adding a new FIB entry to the device,
or modifying an existing entry on the device.</p></td>
</tr>
<tr class="row-even"><td><p>FIB_EVENT_ENTRY_DEL</p></td>
<td><p>used for removing a FIB entry</p></td>
</tr>
<tr class="row-odd"><td><p>FIB_EVENT_RULE_ADD,</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p>FIB_EVENT_RULE_DEL</p></td>
<td><p>used to propagate FIB rule changes</p></td>
</tr>
</tbody>
</table>
<p>FIB_EVENT_ENTRY_ADD and FIB_EVENT_ENTRY_DEL events pass:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>struct fib_entry_notifier_info {
        struct fib_notifier_info info; /* must be first */
        u32 dst;
        int dst_len;
        struct fib_info *fi;
        u8 tos;
        u8 type;
        u32 tb_id;
        u32 nlflags;
};
</pre></div>
</div>
<p>to add/modify/delete IPv4 dst/dest_len prefix on table tb_id.  The <code class="docutils literal notranslate"><span class="pre">*fi</span></code>
structure holds details on the route and route’s nexthops.  <code class="docutils literal notranslate"><span class="pre">*dev</span></code> is one
of the port netdevs mentioned in the route’s next hop list.</p>
<p>Routes offloaded to the device are labeled with “offload” in the ip route
listing:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>$ ip route show
default via 192.168.0.2 dev eth0
11.0.0.0/30 dev sw1p1  proto kernel  scope link  src 11.0.0.2 offload
11.0.0.4/30 via 11.0.0.1 dev sw1p1  proto zebra  metric 20 offload
11.0.0.8/30 dev sw1p2  proto kernel  scope link  src 11.0.0.10 offload
11.0.0.12/30 via 11.0.0.9 dev sw1p2  proto zebra  metric 20 offload
12.0.0.2  proto zebra  metric 30 offload
        nexthop via 11.0.0.1  dev sw1p1 weight 1
        nexthop via 11.0.0.9  dev sw1p2 weight 1
12.0.0.3 via 11.0.0.1 dev sw1p1  proto zebra  metric 20 offload
12.0.0.4 via 11.0.0.9 dev sw1p2  proto zebra  metric 20 offload
192.168.0.0/24 dev eth0  proto kernel  scope link  src 192.168.0.15
</pre></div>
</div>
<p>The “offload” flag is set in case at least one device offloads the FIB entry.</p>
<p>XXX: add/mod/del IPv6 FIB API</p>
<section id="nexthop-resolution">
<h3>Nexthop Resolution<a class="headerlink" href="#nexthop-resolution" title="Link to this heading">¶</a></h3>
<p>The FIB entry’s nexthop list contains the nexthop tuple (gateway, dev), but for
the switch device to forward the packet with the correct dst mac address, the
nexthop gateways must be resolved to the neighbor’s mac address.  Neighbor mac
address discovery comes via the ARP (or ND) process and is available via the
arp_tbl neighbor table.  To resolve the routes nexthop gateways, the driver
should trigger the kernel’s neighbor resolution process.  See the rocker
driver’s <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">rocker_port_ipv4_resolve()</span></code> for an example.</p>
<p>The driver can monitor for updates to arp_tbl using the netevent notifier
NETEVENT_NEIGH_UPDATE.  The device can be programmed with resolved nexthops
for the routes as arp_tbl updates.  The driver implements ndo_neigh_destroy
to know when arp_tbl neighbor entries are purged from the port.</p>
</section>
</section>
<section id="device-driver-expected-behavior">
<h2>Device driver expected behavior<a class="headerlink" href="#device-driver-expected-behavior" title="Link to this heading">¶</a></h2>
<p>Below is a set of defined behavior that switchdev enabled network devices must
adhere to.</p>
<section id="configuration-less-state">
<h3>Configuration-less state<a class="headerlink" href="#configuration-less-state" title="Link to this heading">¶</a></h3>
<p>Upon driver bring up, the network devices must be fully operational, and the
backing driver must configure the network device such that it is possible to
send and receive traffic to this network device and it is properly separated
from other network devices/ports (e.g.: as is frequent with a switch ASIC). How
this is achieved is heavily hardware dependent, but a simple solution can be to
use per-port VLAN identifiers unless a better mechanism is available
(proprietary metadata for each network port for instance).</p>
<p>The network device must be capable of running a full IP protocol stack
including multicast, DHCP, IPv4/6, etc. If necessary, it should program the
appropriate filters for VLAN, multicast, unicast etc. The underlying device
driver must effectively be configured in a similar fashion to what it would do
when IGMP snooping is enabled for IP multicast over these switchdev network
devices and unsolicited multicast must be filtered as early as possible in
the hardware.</p>
<p>When configuring VLANs on top of the network device, all VLANs must be working,
irrespective of the state of other network devices (e.g.: other ports being part
of a VLAN-aware bridge doing ingress VID checking). See below for details.</p>
<p>If the device implements e.g.: VLAN filtering, putting the interface in
promiscuous mode should allow the reception of all VLAN tags (including those
not present in the filter(s)).</p>
</section>
<section id="bridged-switch-ports">
<h3>Bridged switch ports<a class="headerlink" href="#bridged-switch-ports" title="Link to this heading">¶</a></h3>
<p>When a switchdev enabled network device is added as a bridge member, it should
not disrupt any functionality of non-bridged network devices and they
should continue to behave as normal network devices. Depending on the bridge
configuration knobs below, the expected behavior is documented.</p>
</section>
<section id="bridge-vlan-filtering">
<h3>Bridge VLAN filtering<a class="headerlink" href="#bridge-vlan-filtering" title="Link to this heading">¶</a></h3>
<p>The Linux bridge allows the configuration of a VLAN filtering mode (statically,
at device creation time, and dynamically, during run time) which must be
observed by the underlying switchdev network device/hardware:</p>
<ul class="simple">
<li><p>with VLAN filtering turned off: the bridge is strictly VLAN unaware and its
data path will process all Ethernet frames as if they are VLAN-untagged.
The bridge VLAN database can still be modified, but the modifications should
have no effect while VLAN filtering is turned off. Frames ingressing the
device with a VID that is not programmed into the bridge/switch’s VLAN table
must be forwarded and may be processed using a VLAN device (see below).</p></li>
<li><p>with VLAN filtering turned on: the bridge is VLAN-aware and frames ingressing
the device with a VID that is not programmed into the bridges/switch’s VLAN
table must be dropped (strict VID checking).</p></li>
</ul>
<p>When there is a VLAN device (e.g: sw0p1.100) configured on top of a switchdev
network device which is a bridge port member, the behavior of the software
network stack must be preserved, or the configuration must be refused if that
is not possible.</p>
<ul>
<li><p>with VLAN filtering turned off, the bridge will process all ingress traffic
for the port, except for the traffic tagged with a VLAN ID destined for a
VLAN upper. The VLAN upper interface (which consumes the VLAN tag) can even
be added to a second bridge, which includes other switch ports or software
interfaces. Some approaches to ensure that the forwarding domain for traffic
belonging to the VLAN upper interfaces are managed properly:</p>
<blockquote>
<div><ul class="simple">
<li><p>If forwarding destinations can be managed per VLAN, the hardware could be
configured to map all traffic, except the packets tagged with a VID
belonging to a VLAN upper interface, to an internal VID corresponding to
untagged packets. This internal VID spans all ports of the VLAN-unaware
bridge. The VID corresponding to the VLAN upper interface spans the
physical port of that VLAN interface, as well as the other ports that
might be bridged with it.</p></li>
<li><p>Treat bridge ports with VLAN upper interfaces as standalone, and let
forwarding be handled in the software data path.</p></li>
</ul>
</div></blockquote>
</li>
<li><p>with VLAN filtering turned on, these VLAN devices can be created as long as
the bridge does not have an existing VLAN entry with the same VID on any
bridge port. These VLAN devices cannot be enslaved into the bridge since they
duplicate functionality/use case with the bridge’s VLAN data path processing.</p></li>
</ul>
<p>Non-bridged network ports of the same switch fabric must not be disturbed in any
way by the enabling of VLAN filtering on the bridge device(s). If the VLAN
filtering setting is global to the entire chip, then the standalone ports
should indicate to the network stack that VLAN filtering is required by setting
‘rx-vlan-filter: on [fixed]’ in the ethtool features.</p>
<p>Because VLAN filtering can be turned on/off at runtime, the switchdev driver
must be able to reconfigure the underlying hardware on the fly to honor the
toggling of that option and behave appropriately. If that is not possible, the
switchdev driver can also refuse to support dynamic toggling of the VLAN
filtering knob at runtime and require a destruction of the bridge device(s) and
creation of new bridge device(s) with a different VLAN filtering value to
ensure VLAN awareness is pushed down to the hardware.</p>
<p>Even when VLAN filtering in the bridge is turned off, the underlying switch
hardware and driver may still configure itself in a VLAN-aware mode provided
that the behavior described above is observed.</p>
<p>The VLAN protocol of the bridge plays a role in deciding whether a packet is
treated as tagged or not: a bridge using the 802.1ad protocol must treat both
VLAN-untagged packets, as well as packets tagged with 802.1Q headers, as
untagged.</p>
<p>The 802.1p (VID 0) tagged packets must be treated in the same way by the device
as untagged packets, since the bridge device does not allow the manipulation of
VID 0 in its database.</p>
<p>When the bridge has VLAN filtering enabled and a PVID is not configured on the
ingress port, untagged and 802.1p tagged packets must be dropped. When the bridge
has VLAN filtering enabled and a PVID exists on the ingress port, untagged and
priority-tagged packets must be accepted and forwarded according to the
bridge’s port membership of the PVID VLAN. When the bridge has VLAN filtering
disabled, the presence/lack of a PVID should not influence the packet
forwarding decision.</p>
</section>
<section id="bridge-igmp-snooping">
<h3>Bridge IGMP snooping<a class="headerlink" href="#bridge-igmp-snooping" title="Link to this heading">¶</a></h3>
<p>The Linux bridge allows the configuration of IGMP snooping (statically, at
interface creation time, or dynamically, during runtime) which must be observed
by the underlying switchdev network device/hardware in the following way:</p>
<ul class="simple">
<li><p>when IGMP snooping is turned off, multicast traffic must be flooded to all
ports within the same bridge that have mcast_flood=true. The CPU/management
port should ideally not be flooded (unless the ingress interface has
IFF_ALLMULTI or IFF_PROMISC) and continue to learn multicast traffic through
the network stack notifications. If the hardware is not capable of doing that
then the CPU/management port must also be flooded and multicast filtering
happens in software.</p></li>
<li><p>when IGMP snooping is turned on, multicast traffic must selectively flow
to the appropriate network ports (including CPU/management port). Flooding of
unknown multicast should be only towards the ports connected to a multicast
router (the local device may also act as a multicast router).</p></li>
</ul>
<p>The switch must adhere to RFC 4541 and flood multicast traffic accordingly
since that is what the Linux bridge implementation does.</p>
<p>Because IGMP snooping can be turned on/off at runtime, the switchdev driver
must be able to reconfigure the underlying hardware on the fly to honor the
toggling of that option and behave appropriately.</p>
<p>A switchdev driver can also refuse to support dynamic toggling of the multicast
snooping knob at runtime and require the destruction of the bridge device(s)
and creation of a new bridge device(s) with a different multicast snooping
value.</p>
</section>
</section>
</section>


          </div>
          
        </div>
      </div>
    <div class="clearer"></div>
  </div>
    <div class="footer">
      &#169;The kernel development community.
      
      |
      Powered by <a href="https://www.sphinx-doc.org/">Sphinx 8.1.3</a>
      &amp; <a href="https://alabaster.readthedocs.io">Alabaster 0.7.16</a>
      
      |
      <a href="../_sources/networking/switchdev.rst.txt"
          rel="nofollow">Page source</a>
    </div>

    

    
  </body>
</html>

Filemanager

Name Type Size Permission Actions
caif Folder 0755
device_drivers Folder 0755
devlink Folder 0755
diagnostic Folder 0755
dsa Folder 0755
mac80211_hwsim Folder 0755
net_cachelines Folder 0755
pse-pd Folder 0755
6lowpan.html File 9.97 KB 0644
6pack.html File 18.06 KB 0644
af_xdp.html File 71.08 KB 0644
alias.html File 9.71 KB 0644
arcnet-hardware.html File 153.3 KB 0644
arcnet.html File 37.48 KB 0644
atm.html File 8.24 KB 0644
ax25.html File 8.75 KB 0644
bareudp.html File 10.56 KB 0644
batman-adv.html File 16.81 KB 0644
bonding.html File 140.89 KB 0644
bridge.html File 53.36 KB 0644
can.html File 120.11 KB 0644
can_ucan_protocol.html File 25.27 KB 0644
cdc_mbim.html File 25.28 KB 0644
checksum-offloads.html File 16.15 KB 0644
dctcp.html File 10.32 KB 0644
devmem.html File 24.33 KB 0644
dns_resolver.html File 15.11 KB 0644
driver.html File 20.41 KB 0644
eql.html File 31.48 KB 0644
ethtool-netlink.html File 274 KB 0644
failover.html File 8.43 KB 0644
fib_trie.html File 16.04 KB 0644
filter.html File 42.43 KB 0644
gen_stats.html File 14.2 KB 0644
generic-hdlc.html File 14.67 KB 0644
generic_netlink.html File 8.11 KB 0644
gtp.html File 20.55 KB 0644
ieee802154.html File 25.03 KB 0644
ila.html File 21.79 KB 0644
index.html File 108.18 KB 0644
ioam6-sysctl.html File 8.48 KB 0644
iou-zcrx.html File 16.63 KB 0644
ip-sysctl.html File 154.81 KB 0644
ip_dynaddr.html File 9.97 KB 0644
ipsec.html File 9.71 KB 0644
ipv6.html File 9.87 KB 0644
ipvlan.html File 16.87 KB 0644
ipvs-sysctl.html File 20.73 KB 0644
iso15765-2.html File 39.91 KB 0644
j1939.html File 99.33 KB 0644
kapi.html File 1.78 MB 0644
kcm.html File 21.67 KB 0644
l2tp.html File 47.74 KB 0644
lapb-module.html File 22.56 KB 0644
mac80211-injection.html File 12.37 KB 0644
mctp.html File 35.16 KB 0644
mpls-sysctl.html File 9.64 KB 0644
mptcp-sysctl.html File 13.33 KB 0644
mptcp.html File 19.74 KB 0644
msg_zerocopy.html File 19.72 KB 0644
multi-pf-netdev.html File 17.48 KB 0644
multiqueue.html File 13.21 KB 0644
napi.html File 43.36 KB 0644
net_dim.html File 76.45 KB 0644
net_failover.html File 16.3 KB 0644
netconsole.html File 31.44 KB 0644
netdev-features.html File 17.75 KB 0644
netdevices.html File 43.33 KB 0644
netfilter-sysctl.html File 8.43 KB 0644
netif-msg.html File 12.93 KB 0644
netmem.html File 14.84 KB 0644
nexthop-group-resilient.html File 24.56 KB 0644
nf_conntrack-sysctl.html File 15.77 KB 0644
nf_flowtable.html File 21.24 KB 0644
nfc.html File 13.73 KB 0644
oa-tc6-framework.html File 39.07 KB 0644
openvswitch.html File 21.15 KB 0644
operstates.html File 18.28 KB 0644
packet_mmap.html File 55.34 KB 0644
page_pool.html File 59.25 KB 0644
phonet.html File 16.92 KB 0644
phy-link-topology.html File 15.77 KB 0644
phy.html File 40.5 KB 0644
pktgen.html File 24.97 KB 0644
plip.html File 18.56 KB 0644
ppp_generic.html File 37.23 KB 0644
proc_net_tcp.html File 11.13 KB 0644
psp.html File 18.66 KB 0644
radiotap-headers.html File 14.73 KB 0644
rds.html File 29.39 KB 0644
regulatory.html File 18.44 KB 0644
representors.html File 25.79 KB 0644
rxrpc.html File 130.88 KB 0644
scaling.html File 40.25 KB 0644
sctp.html File 9.73 KB 0644
secid.html File 8.42 KB 0644
seg6-sysctl.html File 9.53 KB 0644
segmentation-offloads.html File 17.81 KB 0644
sfp-phylink.html File 41.09 KB 0644
skbuff.html File 29.22 KB 0644
smc-sysctl.html File 10.42 KB 0644
snmp_counter.html File 91.51 KB 0644
sriov.html File 9.46 KB 0644
statistics.html File 31.78 KB 0644
strparser.html File 19.15 KB 0644
switchdev.html File 39.55 KB 0644
sysfs-tagging.html File 10.95 KB 0644
tc-actions-env-rules.html File 8.87 KB 0644
tc-queue-filters.html File 9.33 KB 0644
tcp-thin.html File 10.33 KB 0644
tcp_ao.html File 35.85 KB 0644
team.html File 7.93 KB 0644
timestamping.html File 59.83 KB 0644
tipc.html File 384.61 KB 0644
tls-handshake.html File 21.18 KB 0644
tls-offload.html File 42.72 KB 0644
tls.html File 39.38 KB 0644
tproxy.html File 13.18 KB 0644
tuntap.html File 19 KB 0644
udplite.html File 23.04 KB 0644
vrf.html File 28.46 KB 0644
vxlan.html File 11.95 KB 0644
x25-iface.html File 10.9 KB 0644
x25.html File 10.07 KB 0644
xdp-rx-metadata.html File 27.46 KB 0644
xfrm_device.html File 19.14 KB 0644
xfrm_proc.html File 11.37 KB 0644
xfrm_sync.html File 15.85 KB 0644
xfrm_sysctl.html File 8.07 KB 0644
xsk-tx-metadata.html File 18.64 KB 0644
Filemanager