network-scripts.txt 1.7 KB

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