\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}
. /etc/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.

-31e0f0ae/tree/target/linux/arc770/base-files.mk?h=do-work/Edimax-v2&amp;id=8f8b702f850a5f1c27fb2cfd74e5580a5f6cd7e8'>tree</a><a href='/cgit.cgi/openwrt/em-br6478acv2/lede/master-31e0f0ae/commit/target/linux/arc770/base-files.mk?h=do-work/Edimax-v2&amp;id=8f8b702f850a5f1c27fb2cfd74e5580a5f6cd7e8'>commit</a><a href='/cgit.cgi/openwrt/em-br6478acv2/lede/master-31e0f0ae/diff/target/linux/arc770/base-files.mk?h=do-work/Edimax-v2&amp;id=8f8b702f850a5f1c27fb2cfd74e5580a5f6cd7e8'>diff</a><a href='/cgit.cgi/openwrt/em-br6478acv2/lede/master-31e0f0ae/stats/target/linux/arc770/base-files.mk?h=do-work/Edimax-v2'>stats</a></td><td class='form'><form class='right' method='get' action='/cgit.cgi/openwrt/em-br6478acv2/lede/master-31e0f0ae/log/target/linux/arc770/base-files.mk'>
<input type='hidden' name='h' value='do-work/Edimax-v2'/><input type='hidden' name='id' value='8f8b702f850a5f1c27fb2cfd74e5580a5f6cd7e8'/><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.cgi/openwrt/em-br6478acv2/lede/master-31e0f0ae/tree/?h=do-work/Edimax-v2&amp;id=8f8b702f850a5f1c27fb2cfd74e5580a5f6cd7e8'>root</a>/<a href='/cgit.cgi/openwrt/em-br6478acv2/lede/master-31e0f0ae/tree/target?h=do-work/Edimax-v2&amp;id=8f8b702f850a5f1c27fb2cfd74e5580a5f6cd7e8'>target</a>/<a href='/cgit.cgi/openwrt/em-br6478acv2/lede/master-31e0f0ae/tree/target/linux?h=do-work/Edimax-v2&amp;id=8f8b702f850a5f1c27fb2cfd74e5580a5f6cd7e8'>linux</a>/<a href='/cgit.cgi/openwrt/em-br6478acv2/lede/master-31e0f0ae/tree/target/linux/arc770?h=do-work/Edimax-v2&amp;id=8f8b702f850a5f1c27fb2cfd74e5580a5f6cd7e8'>arc770</a>/<a href='/cgit.cgi/openwrt/em-br6478acv2/lede/master-31e0f0ae/tree/target/linux/arc770/base-files.mk?h=do-work/Edimax-v2&amp;id=8f8b702f850a5f1c27fb2cfd74e5580a5f6cd7e8'>base-files.mk</a></div><div class='content'>blob: fdd2c714b22892b9e72d9a8b89bd8288ccd4b797 (<a href='/cgit.cgi/openwrt/em-br6478acv2/lede/master-31e0f0ae/plain/target/linux/arc770/base-files.mk?h=do-work/Edimax-v2&amp;id=8f8b702f850a5f1c27fb2cfd74e5580a5f6cd7e8'>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>
</pre></td>
<td class='lines'><pre><code>