\subsubsection{Using the network scripts}

To be able to access the network functions, you need to include
the necessary shell scripts by running:

\begin{Verbatim}
. /lib/functions.sh      # common functions
include /lib/network     # include /lib/network/*.sh
scan_interfaces          # read and parse the network config
\end{Verbatim}

Some protocols, such as PPP might change the configured interface names
at run time (e.g. \texttt{eth0} => \texttt{ppp0} for PPPoE). That's why you have to run
\texttt{scan\_interfaces} instead of reading the values from the config directly.
After running \texttt{scan\_interfaces}, the \texttt{'ifname'} option will always contain
the effective interface name (which is used for IP traffic) and if the
physical device name differs from it, it will be stored in the \texttt{'device'}
option.
That means that running \texttt{config\_get lan ifname}
after \texttt{scan\_interfaces} might not return the same result as running it before.

After running \texttt{scan\_interfaces}, the following functions are available:

\begin{itemize}
    \item{\texttt{find\_config \textit{interface}}} \\
        looks for a network configuration that includes
        the specified network interface.

    \item{\texttt{setup\_interface \textit{interface [config] [protocol]}}} \\
      will set up the specified interface, optionally overriding the network configuration
      name or the protocol that it uses.
\end{itemize}

\subsubsection{Writing protocol handlers}

You can add custom protocol handlers (e.g: PPPoE, PPPoA, ATM, PPTP ...)
by adding shell scripts to \texttt{/lib/network}. They provide the following
two shell functions:

\begin{Verbatim}
scan_<protocolname>() {
    local config="$1"
    # change the interface names if necessary
}

setup_interface_<protocolname>() {
    local interface="$1"
    local config="$2"
    # set up the interface
}
\end{Verbatim}

\texttt{scan\_\textit{protocolname}} is optional and only necessary if your protocol
uses a custom device, e.g. a tunnel or a PPP device.

ibxc/rpm.spec?h=4.0.3-rc1&amp;id=2a2afad75f736039c0e561609331d0d0f1ed963c'>diff</a><a href='/cgit/xen/xen/stats/tools/libxc/rpm.spec?h=4.0.3-rc1'>stats</a></td><td class='form'><form class='right' method='get' action='/cgit/xen/xen/log/tools/libxc/rpm.spec'>
<input type='hidden' name='h' value='4.0.3-rc1'/><input type='hidden' name='id' value='2a2afad75f736039c0e561609331d0d0f1ed963c'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/cgit/xen/xen/tree/?h=4.0.3-rc1&amp;id=2a2afad75f736039c0e561609331d0d0f1ed963c'>root</a>/<a href='/cgit/xen/xen/tree/tools?h=4.0.3-rc1&amp;id=2a2afad75f736039c0e561609331d0d0f1ed963c'>tools</a>/<a href='/cgit/xen/xen/tree/tools/libxc?h=4.0.3-rc1&amp;id=2a2afad75f736039c0e561609331d0d0f1ed963c'>libxc</a>/<a href='/cgit/xen/xen/tree/tools/libxc/rpm.spec?h=4.0.3-rc1&amp;id=2a2afad75f736039c0e561609331d0d0f1ed963c'>rpm.spec</a></div><div class='content'>blob: 1b4c5fc85af0bc8a90c40fed0ec3c981ca5ed3f4 (<a href='/cgit/xen/xen/plain/tools/libxc/rpm.spec?h=4.0.3-rc1&amp;id=2a2afad75f736039c0e561609331d0d0f1ed963c'>plain</a>)
<table summary='blob content' class='blob'>
<tr><td class='linenumbers'><pre><a id='n1' href='#n1'>1</a>
<a id='n2' href='#n2'>2</a>
<a id='n3' href='#n3'>3</a>
<a id='n4' href='#n4'>4</a>
<a id='n5' href='#n5'>5</a>
<a id='n6' href='#n6'>6</a>
<a id='n7' href='#n7'>7</a>
<a id='n8' href='#n8'>8</a>
<a id='n9' href='#n9'>9</a>
<a id='n10' href='#n10'>10</a>
<a id='n11' href='#n11'>11</a>
<a id='n12' href='#n12'>12</a>
<a id='n13' href='#n13'>13</a>
<a id='n14' href='#n14'>14</a>
<a id='n15' href='#n15'>15</a>
<a id='n16' href='#n16'>16</a>
<a id='n17' href='#n17'>17</a>
<a id='n18' href='#n18'>18</a>
<a id='n19' href='#n19'>19</a>
<a id='n20' href='#n20'>20</a>
<a id='n21' href='#n21'>21</a>
<a id='n22' href='#n22'>22</a>
<a id='n23' href='#n23'>23</a>
<a id='n24' href='#n24'>24</a>
<a id='n25' href='#n25'>25</a>
<a id='n26' href='#n26'>26</a>
<a id='n27' href='#n27'>27</a>
<a id='n28' href='#n28'>28</a>
</pre></td>
<td class='lines'><pre><code>