Rttable : Routing table management

更新时间:
2024-05-15
下载文档

Rttable : Routing table management

This module provides a routing table operation interface.

User can use the following code to import the rttable module.

var rttable = require('router/rttable');

Support

The following shows rttable module APIs available for each permissions.

 User ModePrivilege Mode
rttable.list
rttable.add 
rttable.delete 
rttable.change 
rttable.default 

Rttable Object

rttable.list(domain)

  • domain {Integer} Network protocol domain, must be: socket.AF_INET or socket.AF_INET6.
  • Returns: {Array} Array of all routing entries in the specified network protocol domain.

List all routing entries of the specified network protocol domain. Each routing entry contains the following members:

  • dest {String} Destination address.
  • genmask {String} Netmask.
  • gateway {String} Gateway address.
  • lock {Boolean} Is this entry locked.
  • flags {Integer} Route entry flags.
  • metric {Integer} Route metric.
  • refcnt {Integer} Route reference count.
  • ifname {String} Route network interface.

flags consists of the following bits:

  • rttable.RTF_UP This route is valid.
  • rttable.RTF_GATEWAY This route is a gateway route.
  • rttable.RTF_HOST This route is a host route.
  • rttable.RTF_DYNAMIC This route is a dynamic route.

Example

var array = rttable.list(socket.AF_INET);
array.forEach(function(item) {
  console.log(item);
});

rttable.add(domain, flags, dest, genmask[, gateway[, ifname[, metric]]])

  • domain {Integer} Network protocol domain, must be: socket.AF_INET or socket.AF_INET6.
  • flags {Integer} Route entry flags.
  • dest {String} Destination address.
  • genmask {String} Netmask.
  • gateway {String} Gateway address. default: 0.0.0.0 or ::
  • ifname {String} Route network interface. default: undefined means choose the most suitable network interface according to the gateway settings.
  • metric {Integer} Route metric. default: 0
  • Returns: {Boolean} Whether the operation was successful.

Add a route entry. This route entry can be a host route or a network route.

Example

  • Add host route
rttable.add(socket.AF_INET, rttable.RTF_UP | rttable.RTF_HOST, '12.0.0.1', '255.255.255.255', '10.0.0.1');
  • Add net route
rttable.add(socket.AF_INET, rttable.RTF_UP | rttable.RTF_GATEWAY, '12.0.0.0', '255.0.0.0', '10.0.0.1');
  • Add default route
native.add(socket.AF_INET, native.RTF_UP | native.RTF_GATEWAY, '0.0.0.0', '0.0.0.0', gateway, ifname, metric);

rttable.delete(domain, flags, dest[, genmask[, [gateway[, [ifname]]]]])

  • domain {Integer} Network protocol domain, must be: socket.AF_INET or socket.AF_INET6.
  • flags {Integer} Route entry flags.
  • dest {String} Destination address.
  • genmask {String} Netmask.
  • gateway {String} Gateway address.
  • ifname {String} Route network interface.
  • Returns: {Boolean} Whether the operation was successful.

Delete a route item according to the input parameters, return true if successful, otherwise return false.

rttable.change(domain, flags, dest, genmask[, gateway, [ifname[, metric]]])

  • domain {Integer} Network protocol domain, must be: socket.AF_INET or socket.AF_INET6.
  • flags {Integer} Route entry flags.
  • dest {String} Destination address.
  • genmask {String} Netmask.
  • gateway {String} Gateway address. default: 0.0.0.0 or ::
  • ifname {String} Route network interface. default: undefined means choose the most suitable network interface according to the gateway settings.
  • metric {Integer} Route metric. default: 0
  • Returns: {Boolean} Whether the operation was successful.

First match a routing information that has been added by the destination address, and modify this routing information according to the input parameters.

rttable.default(domain[, gateway[, ifname[, metric]]])

  • domain {Integer} Network protocol domain, must be: socket.AF_INET or socket.AF_INET6.
  • gateway {String} Gateway address. default: 0.0.0.0 or ::
  • ifname {String} Route network interface. default: undefined means choose the most suitable network interface according to the gateway settings.
  • metric {Integer} Route metric. default: 0
  • Returns: {Boolean} Whether the operation was successful.

Add or set a default route.

Example

rttable.default(socket.AF_INET, '0.0.0.0', 'en1');
rttable.default(socket.AF_INET, '10.0.0.1');
文档内容是否对您有所帮助?
有帮助
没帮助