2006-10-14 06:41:34 +08:00
|
|
|
\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}
|
2012-12-20 23:29:33 +08:00
|
|
|
. /lib/functions.sh # common functions
|
2006-10-14 06:41:34 +08:00
|
|
|
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}
|
2006-11-07 07:37:55 +08:00
|
|
|
\item{\texttt{find\_config \textit{interface}}} \\
|
|
|
|
looks for a network configuration that includes
|
|
|
|
the specified network interface.
|
2006-10-14 06:41:34 +08:00
|
|
|
|
2006-11-07 07:37:55 +08:00
|
|
|
\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.
|
2006-10-14 06:41:34 +08:00
|
|
|
\end{itemize}
|
|
|
|
|
|
|
|
\subsubsection{Writing protocol handlers}
|
|
|
|
|
2009-06-09 04:35:05 +08:00
|
|
|
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:
|
2006-10-14 06:41:34 +08:00
|
|
|
|
|
|
|
\begin{Verbatim}
|
|
|
|
scan_<protocolname>() {
|
2006-11-07 07:37:55 +08:00
|
|
|
local config="$1"
|
|
|
|
# change the interface names if necessary
|
2006-10-14 06:41:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
setup_interface_<protocolname>() {
|
2006-11-07 07:37:55 +08:00
|
|
|
local interface="$1"
|
|
|
|
local config="$2"
|
|
|
|
# set up the interface
|
2006-10-14 06:41:34 +08:00
|
|
|
}
|
|
|
|
\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.
|
|
|
|
|