netifd: add missing do_sysctl function
[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         config_get device "$config" device "$ifname"
30         [ "bridge" = "$type" ] && ifname="br-$config"
31         config_set "$config" device "$ifname"
32         ubus_call "network.interface.$config" status
33         json_get_var l3dev l3_device
34         [ -n "$l3dev" ] && ifname="$l3dev"
35         json_init
36         config_set "$config" ifname "$ifname"
37         config_set "$config" device "$device"
38 }
39
40 scan_interfaces() {
41         config_load network
42         config_foreach fixup_interface interface
43 }
44
45 prepare_interface_bridge() {
46         local config="$1"
47
48         [ -n "$config" ] || return 0
49         ubus call network.interface."$config" prepare
50 }
51
52 setup_interface() {
53         local iface="$1"
54         local config="$2"
55
56         [ -n "$config" ] || return 0
57         ubus call network.interface."$config" add_device "{ \"name\": \"$iface\" }"
58 }
59
60 do_sysctl() {
61         [ -n "$2" ] && \
62                 sysctl -n -e -w "$1=$2" >/dev/null || \
63                 sysctl -n -e "$1"
64 }