Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| docs:guide-developer:network-scripting [2021/02/16 09:07] – [Examples] vgaetera | docs:guide-developer:network-scripting [2023/07/19 09:34] (current) – [Get WAN gateway for unmanaged default route] add vgaetera | ||
|---|---|---|---|
| Line 33: | Line 33: | ||
| <code bash> | <code bash> | ||
| proto_protocolname_init_config() { | proto_protocolname_init_config() { | ||
| - | | + | proto_config_add_string " |
| - | proto_config_add_int " | + | proto_config_add_int " |
| - | proto_config_add_boolean " | + | proto_config_add_boolean " |
| - | ... | + | ... |
| } | } | ||
| </ | </ | ||
| Line 50: | Line 50: | ||
| <code bash> | <code bash> | ||
| proto_protocolname_setup() { | proto_protocolname_setup() { | ||
| - | | + | local config=" |
| - | # set up the interface | + | # set up the interface |
| } | } | ||
| </ | </ | ||
| Line 87: | Line 87: | ||
| <code bash> | <code bash> | ||
| proto_protocolname_teardown() { | proto_protocolname_teardown() { | ||
| - | | + | local config=" |
| - | local iface=" | + | local iface=" |
| - | # tear down the interface | + | # tear down the interface |
| } | } | ||
| </ | </ | ||
| Line 101: | Line 101: | ||
| <code bash> | <code bash> | ||
| proto_protocolname_init_config() { | proto_protocolname_init_config() { | ||
| - | | + | no_device=1 |
| - | available=1 | + | available=1 |
| - | ... | + | ... |
| } | } | ||
| </ | </ | ||
| Line 112: | Line 112: | ||
| * There is a pending patch: https:// | * There is a pending patch: https:// | ||
| - | ==== Available | + | ==== Available |
| - | Flags can be added to a proto handler in '' | + | Flags can be added to a proto handler in '' |
| + | The information about all loaded protocols can be obtained by calling //ubus call network get_proto_handlers// | ||
| ^ Name ^ Name in //ubus call network get_proto_handlers// | ^ Name ^ Name in //ubus call network get_proto_handlers// | ||
| | no_device | no_device | The interface does not have a lower device. <color # | | no_device | no_device | The interface does not have a lower device. <color # | ||
| - | | | immediate | <color # | + | | | immediate | <color # |
| | available | init_available | Initialize the device directly as available, without the device specified by ifname being present <color # | | available | init_available | Initialize the device directly as available, without the device specified by ifname being present <color # | ||
| | renew_handler | renew_available | Has a renew handler, which can be called. <color # | | renew_handler | renew_available | Has a renew handler, which can be called. <color # | ||
| Line 124: | Line 125: | ||
| | no_proto_task | no_task | <color # | | no_proto_task | no_task | <color # | ||
| - | ==== Error Codes ==== | + | ==== Error codes ==== |
| - | If errors for interfaces occur, the json object in //ifstatus interfacename// | + | If errors for interfaces occur, the json object in //ifstatus interfacename// |
| + | If there are no errors, this attribute is not existing. | ||
| ^ CODE ^ Meaning ^ | ^ CODE ^ Meaning ^ | ||
| Line 182: | Line 184: | ||
| * '' | * '' | ||
| - | It seems to avoid race conditions in protos. We can register the following type of dependencies by calling: | + | It seems to avoid race conditions in protos. |
| + | We can register the following type of dependencies by calling: | ||
| * '' | * '' | ||
| * '' | * '' | ||
| Line 204: | Line 207: | ||
| ===== Examples ===== | ===== Examples ===== | ||
| - | :!: Network functions rely on runtime configuration and can return unexpected result if you are using MWAN or VPN. | + | [[https:// |
| - | Replace automatic WAN detection with explicit interface definition if required. | + | Replace automatic WAN detection with explicit interface definition if necessary. |
| + | |||
| + | ==== Get LAN address ==== | ||
| + | <code bash> | ||
| + | # Runtime configuration | ||
| + | NET_IF=" | ||
| + | . / | ||
| + | network_flush_cache | ||
| + | network_get_ipaddr NET_ADDR " | ||
| + | network_get_ipaddr6 NET_ADDR6 " | ||
| + | echo " | ||
| + | echo " | ||
| + | </ | ||
| ==== Get WAN interface ==== | ==== Get WAN interface ==== | ||
| Line 214: | Line 229: | ||
| network_find_wan NET_IF | network_find_wan NET_IF | ||
| network_find_wan6 NET_IF6 | network_find_wan6 NET_IF6 | ||
| - | network_get_device | + | echo " |
| - | network_get_device | + | echo " |
| - | echo "${NET_DEV}" | + | </ |
| - | echo "${NET_DEV6}" | + | |
| + | ==== Get WAN L2 device ==== | ||
| + | <code bash> | ||
| + | # Runtime configuration | ||
| + | . / | ||
| + | network_flush_cache | ||
| + | network_find_wan NET_IF | ||
| + | network_find_wan6 NET_IF6 | ||
| + | network_get_physdev NET_L2D " | ||
| + | network_get_physdev NET_L2D6 " | ||
| + | echo " | ||
| + | echo " | ||
| + | </ | ||
| + | |||
| + | ==== Get WAN L3 device ==== | ||
| + | <code bash> | ||
| + | # Runtime configuration | ||
| + | . / | ||
| + | network_flush_cache | ||
| + | network_find_wan NET_IF | ||
| + | network_find_wan6 NET_IF6 | ||
| + | network_get_device | ||
| + | network_get_device | ||
| + | echo "${NET_L3D}" | ||
| + | echo "${NET_L3D6}" | ||
| # Persistent configuration | # Persistent configuration | ||
| - | uci get network.wan.ifname | + | uci get network.wan.device |
| - | uci get network.wan6.ifname | + | uci get network.wan6.device |
| </ | </ | ||
| - | ==== Get WAN IP address ==== | + | ==== Get WAN address ==== |
| <code bash> | <code bash> | ||
| # Runtime configuration | # Runtime configuration | ||
| Line 256: | Line 295: | ||
| uci get network.wan.gateway | uci get network.wan.gateway | ||
| uci get network.wan6.ip6gw | uci get network.wan6.ip6gw | ||
| + | </ | ||
| + | |||
| + | ==== Get WAN prefix ==== | ||
| + | <code bash> | ||
| + | # Runtime configuration | ||
| + | . / | ||
| + | network_flush_cache | ||
| + | network_find_wan6 NET_IF6 | ||
| + | network_get_prefix6 NET_PFX6 " | ||
| + | echo " | ||
| + | |||
| + | # Persistent static configuration | ||
| + | uci get network.wan6.ip6prefix | ||
| + | </ | ||
| + | |||
| + | ==== Get WAN gateway for unmanaged default route ==== | ||
| + | <code bash> | ||
| + | # Runtime configuration | ||
| + | ubus call network.interface dump \ | ||
| + | | jsonfilter -e " | ||
| + | [' | ||
| </ | </ | ||