LuCI.network. Protocol

The Network.Protocol class serves as the base for protocol-specific subclasses which describe logical UCI networks defined by config interface sections in /etc/config/network.

Methods

addDevice(device) → {boolean}

Add the given network device to the logical interface.

Parameters:
NameTypeDescription
deviceLuCI.network.Protocol | LuCI.network.Device | LuCI.network.WifiDevice | LuCI.network.WifiNetwork | string

The object or device name to add to the logical interface. In case the given argument is not a string, it is resolved though the Network.getIfnameOf() function.

Returns:

Returns true if the device name has been added or false if any argument was invalid, if the device was already part of the logical interface or if the logical interface is virtual.

Type: 
boolean

containsDevice(device) → {boolean}

Checks whether this logical interface contains the given device object.

Parameters:
NameTypeDescription
deviceLuCI.network.Protocol | LuCI.network.Device | LuCI.network.WifiDevice | LuCI.network.WifiNetwork | string

The object or device name to check. In case the given argument is not a string, it is resolved though the Network.getIfnameOf() function.

Returns:

Returns true when this logical interface contains the given network device or false if not.

Type: 
boolean

(abstract) deleteConfiguration() → {*|Promise.<*>}

Cleanup related configuration entries.

This function will be invoked if an interface is about to be removed from the configuration and is responsible for performing any required cleanup tasks, such as unsetting uci entries in related configurations.

It should be overridden by protocol specific subclasses.

Returns:

This function may return a promise which is awaited before the rest of the configuration is removed. Any non-promise return value and any resolved promise value is ignored. If the returned promise is rejected, the interface removal will be aborted.

Type: 
* | Promise.<*>

deleteDevice(device) → {boolean}

Remove the given network device from the logical interface.

Parameters:
NameTypeDescription
deviceLuCI.network.Protocol | LuCI.network.Device | LuCI.network.WifiDevice | LuCI.network.WifiNetwork | string

The object or device name to remove from the logical interface. In case the given argument is not a string, it is resolved though the Network.getIfnameOf() function.

Returns:

Returns true if the device name has been added or false if any argument was invalid, if the device was already part of the logical interface or if the logical interface is virtual.

Type: 
boolean

get(opt) → {null|string|Array.<string>}

Read the given UCI option value of this network.

Parameters:
NameTypeDescription
optstring

The UCI option name to read.

Returns:

Returns the UCI option value or null if the requested option is not found.

Type: 
null | string | Array.<string>

getDNS6Addrs() → {Array.<string>}

Query the IPv6 DNS servers associated with the logical interface.

Returns:

Returns an array of IPv6 DNS servers registered by the remote protocol back-end.

Type: 
Array.<string>

getDNSAddrs() → {Array.<string>}

Query the IPv4 DNS servers associated with the logical interface.

Returns:

Returns an array of IPv4 DNS servers registered by the remote protocol back-end.

Type: 
Array.<string>

getDevice() → {LuCI.network.Device}

Returns the Linux network device associated with this logical interface.

Returns:

Returns a Network.Device class instance representing the expected Linux network device according to the configuration.

Type: 
LuCI.network.Device

getDevices() → {null|Array.<LuCI.network.Device>}

Returns a list of network sub-devices associated with this logical interface.

Returns:

Returns an array of Network.Device class instances representing the sub-devices attached to this logical interface or null if the logical interface does not support sub-devices, e.g. because it is virtual and not a bridge.

Type: 
null | Array.<LuCI.network.Device>

getErrors() → {Array.<string>}

Query interface error messages published in ubus runtime state.

Interface errors are emitted by remote protocol handlers if the setup of the underlying logical interface failed, e.g. due to bad configuration or network connectivity issues.

This function will translate the found error codes to human readable messages using the descriptions registered by Network.registerErrorCode() and fall back to "Unknown error (%s)" where %s is replaced by the error code in case no translation can be found.

Returns:

Returns an array of translated interface error messages.

Type: 
Array.<string>

getExpiry() → {number}

Get the logical interface expiry time in seconds.

For protocols that have a concept of a lease, such as DHCP or DHCPv6, this function returns the remaining time in seconds until the lease expires.

Returns:

Returns the number of seconds until the lease expires or -1 if it isn't applicable to the associated protocol.

Type: 
number

getGateway6Addr() → {string}

Query the gateway (nexthop) of the IPv6 default route associated with this logical interface.

Returns:

Returns a string containing the IPv6 nexthop address of the associated default route or null if no default route was found.

Type: 
string

getGatewayAddr() → {string}

Query the gateway (nexthop) of the default route associated with this logical interface.

Returns:

Returns a string containing the IPv4 nexthop address of the associated default route or null if no default route was found.

Type: 
string

(abstract) getI18n() → {string}

Return a human readable description for the protocol, such as Static address or DHCP client.

This function should be overridden by subclasses.

Returns:

Returns the description string.

Type: 
string

getIP6Addr() → {null|string}

Query the first (primary) IPv6 address of the logical interface.

Returns:

Returns the primary IPv6 address registered by the protocol handler in CIDR notation or null if no IPv6 addresses were set.

Type: 
null | string

getIP6Addrs() → {Array.<string>}

Query all IPv6 addresses of the logical interface.

Returns:

Returns an array of IPv6 addresses in CIDR notation which have been registered by the protocol handler. The order of the resulting array follows the order of the addresses in ubus runtime information.

Type: 
Array.<string>

getIP6Prefix() → {null|string}

Query the routed IPv6 prefix associated with the logical interface.

Returns:

Returns the routed IPv6 prefix registered by the remote protocol handler or null if no prefix is present.

Type: 
null | string

getIP6Prefixes() → {null|Array.<string>}

Query the routed IPv6 prefixes associated with the logical interface.

Returns:

Returns an array of the routed IPv6 prefixes registered by the remote protocol handler or null if no prefixes are present.

Type: 
null | Array.<string>

getIPAddr() → {null|string}

Query the first (primary) IPv4 address of the logical interface.

Returns:

Returns the primary IPv4 address registered by the protocol handler or null if no IPv4 addresses were set.

Type: 
null | string

getIPAddrs() → {Array.<string>}

Query all IPv4 addresses of the logical interface.

Returns:

Returns an array of IPv4 addresses in CIDR notation which have been registered by the protocol handler. The order of the resulting array follows the order of the addresses in ubus runtime information.

Type: 
Array.<string>

getIfname() → {null|string}

Get the associated Linux network device of this network.

Returns:

Returns the name of the associated network device or null if it could not be determined.

Type: 
null | string

getL2Device() → {LuCI.network.Device}

Returns the layer 2 Linux network device currently associated with this logical interface.

Returns:

Returns a Network.Device class instance representing the Linux network device currently associated with the logical interface.

Type: 
LuCI.network.Device

getL3Device() → {LuCI.network.Device}

Returns the layer 3 Linux network device currently associated with this logical interface.

Returns:

Returns a Network.Device class instance representing the Linux network device currently associated with the logical interface.

Type: 
LuCI.network.Device

getMetric() → {number}

Get the metric value of the logical interface.

Returns:

Returns the current metric value used for device and network routes spawned by the associated logical interface.

Type: 
number

getName() → {string}

Get the name of the associated logical interface.

Returns:

Returns the logical interface name, such as lan or wan.

Type: 
string

getNetmask() → {null|string}

Query the first (primary) IPv4 netmask of the logical interface.

Returns:

Returns the netmask of the primary IPv4 address registered by the protocol handler or null if no IPv4 addresses were set.

Type: 
null | string

(abstract) getPackageName() → {string}

Gets the name of the package providing the protocol functionality. The package is available via the system default package manager. This is used when a config refers to a protocol handler which is not yet installed.

This function should be overridden by protocol specific subclasses.

Returns:

Returns the name of the package to download, required for the protocol to function, e.g. odhcp6c for the dhcpv6 protocol.

Type: 
string

(abstract) getProtocol() → {string}

Get the name of this network protocol class.

This function will be overridden by subclasses created by Network.registerProtocol().

Returns:

Returns the name of the network protocol implementation, e.g. static or dhcp.

Type: 
string

getType() → {null|string}

Get the type of the underlying interface.

This function actually is a convenience wrapper around proto.get("type") and is mainly used by other LuCI.network code to check whether the interface is declared as bridge in UCI.

Returns:

Returns the value of the type option of the associated logical interface or null if no type option is set.

Type: 
null | string

getUptime() → {number}

Get the uptime of the logical interface.

Returns:

Returns the uptime of the associated interface in seconds.

Type: 
number

getZoneName() → {null|string}

Get the requested firewall zone name of the logical interface.

Some protocol implementations request a specific firewall zone to trigger inclusion of their resulting network devices into the firewall rule set.

Returns:

Returns the requested firewall zone name as published in the ubus runtime information or null if the remote protocol handler didn't request a zone.

Type: 
null | string

isAlias() → {null|string}

Checks whether this interface is an alias interface.

Alias interfaces are interfaces layering on top of another interface and are denoted by a special @interfacename notation in the underlying device option.

Returns:

Returns the name of the parent interface if this logical interface is an alias or null if it is not an alias interface.

Type: 
null | string

isBridge() → {boolean}

Checks whether the underlying logical interface is declared as bridge.

Returns:

Returns true when the interface is declared with option type bridge and when the associated protocol implementation is not marked virtual or false when the logical interface is no bridge.

Type: 
boolean

(abstract) isCreateable(ifname) → {Promise.<void>}

Check function for the protocol handler if a new interface is creatable.

This function should be overridden by protocol specific subclasses.

Parameters:
NameTypeDescription
ifnamestring

The name of the interface to be created.

Returns:

Returns a promise resolving if a new interface is creatable, else rejects with an error message string.

Type: 
Promise.<void>

isDynamic() → {boolean}

Checks whether this logical interface is dynamic.

A dynamic interface is an interface that has been created at runtime. E.g. as a sub-interface of another interface, but which is not backed by any user configuration. Such dynamic interfaces cannot be edited but only brought down or restarted.

Returns:

Returns a boolean indicating whether this interface is dynamic (true) or not (false).

Type: 
boolean

isEmpty() → {boolean}

Checks whether this logical interface is "empty", where empty means that it has no network devices attached.

Returns:

Returns true if this logical interface is empty, else false.

Type: 
boolean

isFloating() → {boolean}

Checks whether this protocol is "floating".

A "floating" protocol is a protocol which spawns its own interfaces on demand, like a virtual one but which relies on an existing lower level interface to initiate the connection.

An example for such a protocol is "pppoe".

This function exists for backwards compatibility with older code but should not be used anymore.

Deprecated
  • Yes
Returns:

Returns a boolean indicating whether this protocol is floating (true) or not (false).

Type: 
boolean

(abstract) isInstalled() → {boolean}

Checks whether the protocol functionality is installed.

This function exists for compatibility with old code, it always returns true.

Deprecated
  • Yes
Returns:

Returns true if the protocol support is installed, else false.

Type: 
boolean

isPending() → {boolean}

Checks whether this logical interface is pending.

Returns:

returns true when the interface is pending or false when it is not.

Type: 
boolean

isUp() → {boolean}

Checks whether this logical interface is configured and running.

Returns:

Returns true when the interface is active or false when it is not.

Type: 
boolean

isVirtual() → {boolean}

Checks whether this protocol is "virtual".

A "virtual" protocol is a protocol which spawns its own interfaces on demand instead of using existing physical interfaces.

Examples for virtual protocols are 6in4 which gre spawn a tunnel network device on startup, examples for non-virtual protocols are dhcp or static which apply IP configuration to existing interfaces.

This function should be overridden by subclasses.

Returns:

Returns a boolean indicating whether the underlying protocol spawns dynamic interfaces (true) or not (false).

Type: 
boolean

set(opt, val) → {null}

Set the given UCI option of this network to the given value.

Parameters:
NameTypeDescription
optstring

The name of the UCI option to set.

valnull | string | Array.<string>

The value to set or null to remove the given option from the configuration.

Returns:
Type: 
null