network-scripts.tex 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. \subsubsection{Using the network scripts}
  2. To be able to access the network functions, you need to include
  3. the necessary shell scripts by running:
  4. \begin{Verbatim}
  5. . /lib/functions.sh # common functions
  6. include /lib/network # include /lib/network/*.sh
  7. scan_interfaces # read and parse the network config
  8. \end{Verbatim}
  9. Some protocols, such as PPP might change the configured interface names
  10. at run time (e.g. \texttt{eth0} => \texttt{ppp0} for PPPoE). That's why you have to run
  11. \texttt{scan\_interfaces} instead of reading the values from the config directly.
  12. After running \texttt{scan\_interfaces}, the \texttt{'ifname'} option will always contain
  13. the effective interface name (which is used for IP traffic) and if the
  14. physical device name differs from it, it will be stored in the \texttt{'device'}
  15. option.
  16. That means that running \texttt{config\_get lan ifname}
  17. after \texttt{scan\_interfaces} might not return the same result as running it before.
  18. After running \texttt{scan\_interfaces}, the following functions are available:
  19. \begin{itemize}
  20. \item{\texttt{find\_config \textit{interface}}} \\
  21. looks for a network configuration that includes
  22. the specified network interface.
  23. \item{\texttt{setup\_interface \textit{interface [config] [protocol]}}} \\
  24. will set up the specified interface, optionally overriding the network configuration
  25. name or the protocol that it uses.
  26. \end{itemize}
  27. \subsubsection{Writing protocol handlers}
  28. You can add custom protocol handlers (e.g: PPPoE, PPPoA, ATM, PPTP ...)
  29. by adding shell scripts to \texttt{/lib/network}. They provide the following
  30. two shell functions:
  31. \begin{Verbatim}
  32. scan_<protocolname>() {
  33. local config="$1"
  34. # change the interface names if necessary
  35. }
  36. setup_interface_<protocolname>() {
  37. local interface="$1"
  38. local config="$2"
  39. # set up the interface
  40. }
  41. \end{Verbatim}
  42. \texttt{scan\_\textit{protocolname}} is optional and only necessary if your protocol
  43. uses a custom device, e.g. a tunnel or a PPP device.