Ifevent : Network interface event
This module provides network interface event listening service.
User can use the following code to import the Ifevent
module.
var Ifevent = require('router/ifevent');
Support
The following shows Ifevent
module APIs available for each permissions.
User Mode | Privilege Mode | |
---|---|---|
Ifevent | ● | |
Ifevent.open | ● | |
ifevent.close | ● | |
ifevent.clear | ● |
Ifevent Class
new Ifevent()
- Returns: {Object} Returns ifevent object.
Create a network interface event listener.
Example
var ifevent = new Ifevent();
Ifevent.open()
- Returns: {Object} Returns ifevent object.
Same as new Ifevent()
, but returns undefined
with no exception.
Ifevent Object
The ifevent
object inherits from EventEmitter
, and the on()
method can be used to add processing callbacks for different events.
ifevent.close()
Close this ifevent and reclaiming file descriptors. Due to the addition of asynchronous events, you must call this function manually when this object is no longer used.
ifevent.on(event, fn)
event
{Integer} Network interface event.fn
{Function} Network interface event callback.ifname
{String} Network interface.
Add response functions for different network interface events.
event
contains the following types of events:
- Common event:
event | Description |
---|---|
Ifevent.IF_ADD | Network interface was added |
Ifevent.IF_REMOVE | Network interface was removed |
Ifevent.IF_UP | Network interface is enabled |
Ifevent.IF_DOWN | Network interface is disabled |
Ifevent.IF_LINKUP | Network interface is connected |
Ifevent.IF_LINKDOWN | Network interface is disconnected |
Ifevent.IF_ADDRESS | Network interface address changed |
Ifevent.IF_CONFLICT | Network interface address conflict |
Ifevent.IF_AUTH_FAIL | Network interface authentication failed |
- Point-to-point network event:
event | Description |
---|---|
Ifevent.IF_PPP_DEAD | Connection dead |
Ifevent.IF_PPP_INIT | Initializing connection |
Ifevent.IF_PPP_AUTH | Start user authentication |
Ifevent.IF_PPP_RUN | Connection establishment |
Ifevent.IF_PPP_DISCONN | Disconnecting |
Ifevent.IF_PPP_TIMEOUT | Connection timeout |
Example
var ifevent = Ifevent.open();
ifevent.on(Ifevent.IF_AUTH_FAIL, function(ifname) {
console.log('Interface:', ifname, 'authentication failed!');
});
iosched.forever();
ifevent.on(ifname, fn)
ifname
{String} Network interface.fn
{Function} Network interface event callback.event
{Integer} Network interface event.
Add response functions for one network interface's all events.
Example
var ifevent = Ifevent.open();
ifevent.on('en1', function(event) {
// Network interface: en1 has a event.
});
ifevent.on('all', fn)
'all'
{String} All events.fn
{Function} Network interface event callback.ifname
{String} Network interface.event
{Integer} Network interface event.
Example
var ifevent = Ifevent.open();
ifevent.on('all', function(ifname, event) {
// Network interface: ifname has a event.
});
ifevent.on('error', fn)
'error'
{String} An error occured.fn
{Function} Network interface event callback.error
{Error} error information.
If an error occured an error
event is emitted with the error information. System will automatically call ifevent.close()
later.
Example
var ifevent = Ifevent.open();
ifevent.on('error', function(error)) {
// check error information
}
ifevent.clear()
Clear all unreceived event information.
Example
var ifevent = Ifevent.open();
ifevent.clear();