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