add an initial (experimental) version of netifd, disabled by default
[openwrt/openwrt.git] / package / netifd / files / lib / network / config.sh
1 #!/bin/sh
2 # Copyright (C) 2011 OpenWrt.org
3
4 . /usr/share/libubox/jshn.sh
5
6 find_config() {
7 return
8 }
9
10 unbridge() {
11 return
12 }
13
14 ubus_call() {
15 json_init
16 local _data="$(ubus call "$1" "$2")"
17 [ $? -ne 0 ] && return "$?"
18 json_load "$_data"
19 return 0
20 }
21
22
23 fixup_interface() {
24 local config="$1"
25 local ifname
26
27 config_get type "$config" type
28 config_get ifname "$config" ifname
29 [ "bridge" = "$type" ] && ifname="br-$config"
30 config_set "$config" device "$ifname"
31 ubus_call "network.interface.$config" status
32 json_get_var l3dev l3_device
33 [ -n "$l3dev" ] && ifname="$l3dev"
34 json_init
35 config_set "$config" ifname "$ifname"
36 }
37
38 scan_interfaces() {
39 config_load network
40 config_foreach fixup_interface interface
41 }
42
43 setup_interface() {
44 local iface="$1"
45 local config="$2"
46
47 [ -n "$config" ] || return 0
48 ubus call network.interface."$config" add_device "{ \"name\": \"$iface\" }"
49 }
50