// thttp
// bridge
// iptable-iproute
// net-tools busybox
// stunnel
// vconfig
//
//-------------------------------------
SSH (Secure SHell) is a network protocol that allows data to be exchanged over a secure channel between two host; encryption provides confidentiality and integrity of data. SSH uses public-key cryptography to authenticate the remote host and allow the remote host to authenticate the user, if necessary.
It is possible to distinguish between SSH “Client” and “Server” processes: client processes create the login request and provide the connection establishment with the remote unit, while server processes are hosted on the remote system and provide the login service to the request of the clients.
//-------------------------------------
12.1. NAT resource
Abilis implements NAT (Network Address Translation) with PAT (Port Address Translation) and IPACL (IP Access Control List) services that ensure sophisticated filters applying on IP traffic (“packet filtering”) by specifying for example:
Source IP address or network.
Destination IP address or network.
Source UDP/TCP port.
Destination UDP/TCP port.
Source/Destination IP resource.
TOS (Type of Service) for packets priority management by services.
By properly combining the services above it's possible obtain a high level of security.
Others elements that increase the security level are:
Proprietary operating system: it's not based on Microsoft or Linux, so it's unknown to hackers.
Proprietary VPN activating protocol.
Data encrypting based on 256 bit cypher key.
Abilis is not a Firewall! It implements basic firewall function, but evolved features must be commissioned to a “real” firewall. Abilis and firewall can coexist with no problems.
//-------------------------------------
13.1. IP Access Control List
The IP Access Control List is a security procedure through that the Abilis CPX executes control, basing on base addresses and the requested services, and check functionalities on the datagrams in transit from and to Abilis CPX.
Transit datagrams are filtered and then selected basing on the information carried by the header (source address and destination, internet protocol version and numbers of logical port) and not on their content. Two ways of filtering are allowed:
STD (Standard): in this case the such called "address filtering" procedure is executed; only IP source and destination addresses of the packet are checked.
EXT (Extended): in this case the "service filtering" procedure is executed; not only IP source and destination addresses of the packet are checked but also the internet protocol version and for TCP, UDP protocols the logical port numbers (indeed also the requested service).
By defining suitable filters in the IP access list it is so possible to set which data can transit and which no. This list provides two different kinds of filters:
PERMIT: permitted to transit.
DENY: denied to transit.
Filters also allow assigning each datagram data flow a different service class:
HIGH: service class "HIGH".
NORMAL: service class "NORMAL".
LOW: service class "LOW".
Usually the service classes are also called "priorities" so that it is possible to speak of "the traffic prioritisation"; further on the filter priorities will be introduced, the User should not confuse the two definition of priority, with the latter it is meant the evaluation order of filters.
Tip
This feature is very important when VoIp and Data applications coexist and use the same link. In these cases, voice packets must have the highest priority for not make the compressed voice quality worse.
Moreover it is possible to activate the cryptographic functionalities of data content in datagrams:
CRKEY: cryptography key to be used.
CRDIR: cryptography direction (encode decode).
Filters can be added, modified, deleted from the IP access list during Abilis CPX working mode, without needing to restart it. Changes are immediately active.
Caution
"Packet filtering" definitions must be added carefully cause the access to the Abilis by IP may be blocked!
13.1.1. TOS (Type Of Service)
It is possible to assign to each datagram data flow a different Type Of Service (TOS). TOS is just a hint to the routing algorithm that helps it choose among various paths to a destination. An internet does not guarantee the type of transport requested.
The Type of Service is used to indicate the quality of the service desired. The type of service is an abstract or generalized set of parameters which characterize the service choices provided in the networks that make up the internet. This type of service indication is to be used by gateways to select the actual transmission parameters for a particular network, the network to be used for the next hop, or the next gateway when routing an internet datagram. The five values allowed are:
N = None;
D = Minimize Delay;
T = Maximize Throughput;
R = Maximize Reliability;
C = Minimize Monetary Cost.
13.1.2. Activating IPACL
The IP Access Control List must be enabled into the IPRTR Resource.
[15:14:30] ABILIS_CPX:d p iprtr
RES:Iprtr ---------------------------------------------------------------------
DESCR:IP_Router_general_properties
- General --------------------------------------------------------------
R-ID:AUTO (192.168.001.001)
maxroute:500 DFTTTL:64 ps:2048
DEF-LOCAL-AD:0 DEF-STATIC-AD:1 DEF-OSPF-AD:110 DEF-RIP-AD:120
pvc:0 bsvc:0 LINKS:4 virtual:0
- IP Access List -------------------------------------------------------
ACL:NO ACLBYPASS:#
COS:DISABLED COSDFT:NORMAL
COSBALANCE:NO NORMRATE:50 LOWRATE:50
- IP Trace -------------------------------------------------------------
tracerec:100
- Ppp-Dns --------------------------------------------------------------
PPP-DNS-PRI:062.094.000.001 PPP-DNS-SEC:062.094.000.002
The highlight parameters manages the IPACL activation and functionality mode.
//-------------------------------------
15.1. VRRP resource
VRRP (Virtual Router Redundancy Protocol) specifies an election protocol that dynamically assigns responsibility for a virtual router to one of the VRRP routers on a LAN. The VRRP router controlling the IP address(es) associated with a virtual router is called the Master, and forwards packets sent to these IP addresses. The election process provides dynamic fail over in the forwarding responsibility should the Master become unavailable. This allows any of the virtual router IP addresses on the LAN to be used as the default first hop router by end-hosts. The advantage from using VRRP is a higher availability default path without requiring configuration of dynamic routing or router discovery protocols on every end-host.
The Virtual Router Redundancy Protocol (VRRP) is designed to eliminate the single point of failure inherent in the static default routed environment. It is available in every distribution of the Abilis firmware; however, in order to be used, it must be set active.
15.1.1. Activating the VRRP resource
Add the resource to the Abilis system with the command a res:vrrp; the VRRP resource may already exist in the system, but may not yet be active: set it active with the command s act res:vrrp.
[15:43:30] ABILIS_CPX:a res:vrrp
RES:VRRP ALREADY EXISTS
[16:02:48] ABILIS_CPX:s act res:vrrp
COMMAND EXECUTED
Caution
After adding or setting the VRRP active, you must restart the Abilis to make the resource running (use the command warm start to reboot the Abilis).
[16:51:53] ABILIS_CPX:s p vrrp act:yes
COMMAND EXECUTED
[16:52:04] ABILIS_CPX:d p vrrp
RES:Vrrp - Not Saved (SAVE CONF), Not Refreshed (INIT) ------------------------
------------------------------------------------------------------------
DESCR:Virtual_Router_Redundancy_Protocol
LOG:NO ACT:YES mxps:256 TOS:0-N
15.1.2. VRRP resource parameters
Use d p vrrp command to display the parameters of the resource; by typing d p vrrp ? command it is possible to display the meaning of all parameters.
[16:52:04] ABILIS_CPX:d p vrrp
RES:Vrrp ----------------------------------------------------------------------
Run DESCR:Virtual_Router_Redundancy_Protocol
LOG:NO ACT:NO mxps:256 TOS:0-N
Meaning of the parameters:
LOG
Logging functionalities activation/deactivation.
ACT
Runtime VRRP activation/deactivation.
mxps
Sets the maximum size of the packets handled (expressed in bytes).
TOS
Sets the TOS value for VRRP service.
The following command allows the administrator to change the configuration of the resource:
s p vrrp parameter:value...
Caution
To activate the changes made on the upper case parameters, execute the initialization command init res:vrrp; while to set act the changes made on the lowercase parameters a save conf and an Abilis restart are required (i.e. with warm start command).
//-------------------------------------
DHCP (Dynamic Host Configuration Protocol) is a protocol used by network devices (clients) to obtain various parameters (DNS, gateway, WINS, SNTP, SMTP, …) necessary for the clients to operate in an Internet Protocol (IP) network. By using this protocol, system administration workload greatly decreases, and devices can be added to the network with minimal or no manual configurations.
The Abilis DHCP module implements two working mode:
BOOTP relay agent (Relay mode): internet host or router that passes DHCP messages between DHCP clients and DHCP servers.
DHCP Server: internet host that returns configuration parameters to DHCP clients.
16.1.1. Activating DHCP resource
Add the resource to the Abilis system with the command a res:dhcp; the DHCP resource may already exist in the system, but may not yet be active: set it active with the command s act res:dhcp.
[17:14:59] ABILIS_CPX:a res:dhcp
RES:DHCP ALREADY EXISTS
[17:15:17] ABILIS_CPX:s act res:dhcp
COMMAND EXECUTED
Caution
After adding or setting the DHCP active, you must restart the Abilis to make the resource running (use the command warm start to reboot the Abilis).
[17:14:59] ABILIS_CPX:s p dhcp act:yes
COMMAND EXECUTED
[17:15:17] ABILIS_CPX:d p dhcp
RES:Dhcp - Not Saved (SAVE CONF), Not Refreshed (INIT) ------------------------
------------------------------------------------------------------------
Run DESCR:Dynamic_Host_Configuration_Protocol
LOG:DS ACT:YES srv-udp-locport:67 cli-udp-locport:68
msg-len:1472 mode:RELAY MAX-HOPS:4 SRV:#
LOCIPADD:R-ID (192.168.001.001)
WDIR:C:\APP\DHCP\
16.1.2. DHCP resource parameters
Use d p dhcp command to display the parameters of the resource; by typing d p dhcp ? command it is possible to display the meaning of all parameters.
[17:15:17] ABILIS_CPX:d p dhcp
RES:Dhcp ----------------------------------------------------------------------
Run DESCR:Dynamic_Host_Configuration_Protocol
LOG:DS ACT:YES srv-udp-locport:67 cli-udp-locport:68
msg-len:1472 mode:RELAY MAX-HOPS:4 SRV:#
LOCIPADD:R-ID (192.168.001.001)
WDIR:C:\APP\DHCP\
Meaning of the most important parametrs:
LOG
Logging functionalities activation/deactivation.
ACT
Runtime DHCP activation/deactivation.
mode
It specifies the mode of DHCP port working [SERVER, RELAY].
Parameters for mode:RELAY only:
MAX-HOPS
It specifies the maximum number of DHCP relay agent hops.
SRV
It specifies the DHCP Server to which requests must be forwarded; it can be set to an IP address, in Dotted Decimal Notation, or the name of an IP list;
LOCIPADD
It specifies the IP address that DHCP relay agent will use as "source address" in the requests relayed to the server.
Parameters for mode:SERVER only:
max-clients
Maximum number of supported DHCP clients; it actually determines the size of the binding database on disk and in memory.
ICMPCHK
Enables ICMP checking of IP address. When it is set to YES, ICMP checking is enabled. Before sending the DHCPOFFER message, the server sends two ICMP ping requests to check the IP address which was allocated. If both timeouts expire, the server will send the DHCP offer message, otherwise it will mark this IP address as abandoned and will not send response.
MAC-FILTER
Enables/disables the selection of serviceable clients based on their MAC address. When it is set to YES, MAC filtering is enabled. When DHCP receives an incoming request and before processing it, the DHCP verifies that the sender's MAC address is allowed by using MAC-LIST and MAC-RULE parameters current setting (MAC-LIST and MAC-RULE appear when MAC-FILTER is set to YES).
WDIR
Selects the directory where DHCP.BND (BND stays for binding) file is saved. A binding is a collection of configuration parameters, including at least an IP address, associated with or "bound to" a DHCP client. Bindings are managed by DHCP servers.
The following command allows the administrator to change the configuration of the resource:
s p dhcp parameter:value...
Caution
To activate the changes made on the upper case parameters, execute the initialization command init res:dhcp; while to set act the changes made on the lowercase parameters a save conf and an Abilis restart are required (i.e. with warm start command).
16.2. DHCP Relay Mode
A BOOTP relay agent or relay agent is an Internet host or router which allows DHCP messages being passed between DHCP clients and DHCP servers. DHCP is designed to use the same relay agent behaviour as specified in the BOOTP protocol specification.
For example, to allow the relay of DHCP packets to the server 192.168.0.250, type the command:
[18:08:56] ABILIS_CPX:s p dhcp act:yes mode:relay srv:192.168.0.250
COMMAND EXECUTED
[18:08:56] ABILIS_CPX:d p dhcp
RES:Dhcp - Not Saved (SAVE CONF), Not Refreshed (INIT) ------------------------
------------------------------------------------------------------------
DESCR:Dynamic_Host_Configuration_Protocol
LOG:DS ACT:YES srvport:67 cliport:68
msg-len:1472 mode:RELAY MAX-HOPS:4 SRV:192.168.000.250
LOCIPADD:R-ID (192.168.001.001)
WDIR:C:\APP\DHCP\
16.3. DHCP Server Mode
A DHCP server is an Internet host that returns configuration parameters to DHCP clients, as IP Address, subnet mask, DNS, gateway, WINS, SNTP, SMTP, etc.
To configure Abilis as a DHCP server it is needed to set the mode parameter to SERVER and to configure the DHCP Server tables.
[09:56:36] ABILIS_CPX:s p dhcp mode:server
COMMAND EXECUTED
[09:56:45] ABILIS_CPX:d p dhcp
RES:Dhcp - Not Saved (SAVE CONF), Not Refreshed (INIT) ------------------------
------------------------------------------------------------------------
DESCR:Dynamic_Host_Configuration_Protocol
LOG:DS ACT:YES srvport:67 cliport:68
msg-len:1472 mode:SERVER max-clients:300 ICMPCHK:NO
MAC-FILTER:NO
WDIR:C:\APP\DHCP\
Caution
To activate the changes made on the lowercase parameters a save conf and an Abilis restart are required (i.e. with warm start command).
16.3.1. DHCP Server tables
The configuration of DHCP server mode is based on three tables:
DHCP Profiles table: table conaining all the parameters to be distributed to clients (i.e. IP Address, Gateway, WINS, DSN, Domain, …);
DHCP Subnets: table containing the network IP address of the DHCP subnet, the subnet mask, the pools of addresses to distribute and the "lease" time of the IP addresses;
DHCP Hosts: t allows to define a static association between a specific MAC-ADDRESS of a client and an IP address (in this way, the PC will always obtain the same address).
16.3.1.1. DHCP Profiles table
The DHCP Profiles table can hold up to 129 definitions, indexed from 0 up to 128. The first definition, i.e. the profile identified by the index equal to zero, is a default profile that is always present within the table and that cannot be deleted by the user. Instead the user can arbitrarily add/delete the definitions from the index 1 to 128.
The table of DHCP Profiles can be modified while the Abilis CPX is working without needing to restart it. Changes made on the table can be activated by executing the initialization command init res:dhcp.
The commands for the DHCP Profiles table management are:
d dhcp prof:xxx[,yyy,...] : display DHCP profile;
a dhcp prof:xxx [par:val] : add DHCP profile;
c dhcp prof:xxx[,yyy,...] :clears DHCP profile;
s dhcp prof:xxx[,yyy,...] par:val [par:val]: set DHCP profile parameters.
A complete list of available configuration parameters is available by typing d dhcp prof: ?.
[10:50:20] ABILIS_CPX:d dhcp prof: ?
D DHCP PROF:xxx[,yyy,...] Display DHCP profile [0..128, A]
DHCP Profile parameters:
NAME: Profile name. From 0 up to 32 ASCII characters.
Spaces are not allowed. Case is preserved.
TTL: IP time-to-live [0, 1..255]
KEEPALIVE: TCP keepalive interval [0, 15..65535 sec.]
NB-SCOPE-ID: Netbios scope identifier. From 0 up to 32 ASCII characters.
Spaces are not allowed. Case is preserved.
NB-NODE-TYPE: Netbios node type [UNK, B, P, M, H]
DOMAIN: IP domain name. From 0 up to 32 ASCII characters.
Spaces are not allowed. Case is preserved.
GW1: First gateway [0.0.0.0, 1-126.x.x.x, 128-223.x.x.x]
GW2: Second (backup) gateway [0.0.0.0, 1-126.x.x.x, 128-223.x.x.x]
GW3: Third (backup) gateway [0.0.0.0, 1-126.x.x.x, 128-223.x.x.x]
DNS1: Primary Domain Name server [0.0.0.0, 1-126.x.x.x, 128-223.x.x.x]
DNS2: Secondary Domain Name server [0.0.0.0, 1-126.x.x.x, 128-223.x.x.x]
SMTP: Simple Mail Transport Protocol (SMTP) server [0.0.0.0,
1-126.x.x.x, 128-223.x.x.x]
POP3: Post Office Protocol (POP3) server [0.0.0.0, 1-126.x.x.x,
128-223.x.x.x]
NNTP: Network News Transport Protocol (NNTP) server [0.0.0.0,
1-126.x.x.x, 128-223.x.x.x]
WWW: World Wide Web (WWW) server [0.0.0.0, 1-126.x.x.x, 128-223.x.x.x]
FINGER: Finger server [0.0.0.0, 1-126.x.x.x, 128-223.x.x.x]
IRC: Internet Relay Chat server [0.0.0.0, 1-126.x.x.x, 128-223.x.x.x]
NTP: NTP/SNTP server [0.0.0.0, 1-126.x.x.x, 128-223.x.x.x]
TIME: TIME server [0.0.0.0, 1-126.x.x.x, 128-223.x.x.x]
WINS1: First WINS server [0.0.0.0, 1-126.x.x.x, 128-223.x.x.x]
WINS2: Second WINS server [0.0.0.0, 1-126.x.x.x, 128-223.x.x.x]
16.3.1.2. DHCP Subnets table
The DHCP Subnets table can hold up to 128 definitions.
The table of DHCP Subnets can be modified while the Abilis CPX is working without needing to restart it. Changes made on the table can be activated by executing the initialization command init res:dhcp.
The commands for the DHCP Subnets table management are:
d dhcp lan:xxx[,yyy,...] : display DHCP subnet;
a dhcp lan:xxx [par:val] : add DHCP subnet;
c dhcp lan:xxx[,yyy,...] :clears DHCP subnet;
s dhcp lan:xxx[,yyy,...] par:val [par:val]: set DHCP subnet parameters.
A complete list of available configuration parameters is available by typing d dhcp lan: ?.
[10:50:25] ABILIS_CPX:d dhcp lan: ?
D DHCP LAN:xxx[,yyy,...] Display DHCP subnet [1..128, A]
DHCP Subnet parameters:
NAME: Subnet name. From 0 up to 32 ASCII characters.
Spaces are not allowed. Case is preserved.
NET: Network address in DDN or network address and mask in Slash
Notation [0.0.0.0, 1-126.x.x.x, 128-223.x.x.x]/[0..32]
MASK: Network mask in DDN [0.0.0.0, 128.0.0.0-255.255.255.252]
POOL1: First IP pool. A single IP address [1.0.0.0-126.255.255.255,
128.0.0.0-223.255.255.255] or two IP addresses separated by ':'
(colon). (E.g.: 150.200.192.192 or 192.168.0.0:192.168.0.100)
POOL2: Second IP pool. A single IP address [1.0.0.0-126.255.255.255,
128.0.0.0-223.255.255.255] or two IP addresses separated by ':'
(colon). (E.g.: 150.200.192.192 or 192.168.0.0:192.168.0.100)
POOL3: Third IP pool. A single IP address [1.0.0.0-126.255.255.255,
128.0.0.0-223.255.255.255] or two IP addresses separated by ':'
(colon). (E.g.: 150.200.192.192 or 192.168.0.0:192.168.0.100)
POOL4: Fourth IP pool. A single IP address [1.0.0.0-126.255.255.255,
128.0.0.0-223.255.255.255] or two IP addresses separated by ':'
(colon). (E.g.: 150.200.192.192 or 192.168.0.0:192.168.0.100)
POOL5: Fifth IP pool. A single IP address [1.0.0.0-126.255.255.255,
128.0.0.0-223.255.255.255] or two IP addresses separated by ':'
(colon). (E.g.: 150.200.192.192 or 192.168.0.0:192.168.0.100)
PROF: Profile [NONE, 1..128]
DEF-LEASE: Default lease time of the IP address [60..1000000 sec.]
MAX-LEASE: Maximum lease time of the IP address [60..1000000 sec.]
16.3.1.3. DHCP Hosts table
The DHCP Hosts table can hold up to 500 definitions, indexed from 1 up to 500 hosts bindings.
The table of DHCP Hosts can be modified while the Abilis CPX is working without needing to restart it. Changes made on the table can be activated by executing the initialization command init res:dhcp.
The commands for the DHCP Hosts table management are:
d dhcp host:xxx[,yyy,...] : display DHCP host;
a dhcp host:xxx [par:val] : add DHCP host;
c dhcp host:xxx[,yyy,...] :clears DHCP host;
s dhcp host:xxx[,yyy,...] par:val [par:val]: set DHCP host parameters.
A complete list of available configuration parameters is available by typing d dhcp host: ?
[15:11:54] ABILIS_CPX:d dhcp host: ?
D DHCP HOST [MAC:] Display DHCP hosts table
DHCP Hosts parameters:
MAC: MAC address [00-00-00-00-00-01..FF-FF-FF-FF-FF-FF]
IP: IP address [0.0.0.0, 1-126.x.x.x, 128-223.x.x.x]
PROF: Profile [LAN, 1..128]
NAME: Host name. From 0 up to 32 ASCII characters.
Spaces are not allowed. Case is preserved.
16.3.2. Example of configuration of DHCP in Server mode
In this example the DHCP Server is configured to distribute the following parameters:
Network address: 192.168.0.0/24
IP pool of addresses: from 192.168.0.131 to 192.168.0.179
DNS server 1:192.168.0.232
DNS server 2:192.168.0.251
Default Gateway: 192.168.0.232
WINS server: 192.168.0.50
SMTP server: 192.168.0.250
POP3 server: 192.168.0.250
No static association between MAC-ADDRESS and any leased IP
ICMP checking of IP address
No MAC Filtering
First, set the dhcp resource active. To do so, issue the command:
[15:20:37] ABILIS_CPX:s p dhcp act:yes mode:server
COMMAND EXECUTED
[15:40:56] ABILIS_CPX:d p dhcp
RES:Dhcp - Not Saved (SAVE CONF), Not Refreshed (INIT) ------------------------
------------------------------------------------------------------------
DESCR:Dynamic_Host_Configuration_Protocol
LOG:DS ACT:YES srvport:67 cliport:68
msg-len:1472 mode:SERVER max-clients:300 ICMPCHK:NO
MAC-FILTER:NO
WDIR:C:\APP\DHCP\
Now let configure the DHCP Profiles table. This is done by typing:
[15:54:54] ABILIS_CPX:a dhcp prof:1 name:Private_LAN gw1:192.168.0.232 dns1:192.168.0.232 dns2:192.168.0.251 smtp:192.168.0.250 pop3:192.168.0.250 wins:192.168.0.50
COMMAND EXECUTED
[15:55:11] ABILIS_CPX:d dhcp prof
- Not Saved (SAVE CONF), Not Refreshed (INIT) ---------------------------------
PROF: |NAME:
-------------------------------------------------------------------------------
0 Default_profile
1 Private_LAN
[15:55:27] ABILIS_CPX:d dhcp prof:1
- Not Saved (SAVE CONF), Not Refreshed (INIT) ---------------------------------
Parameter: | Value:
-------------+-----------------------------------------------------------------
PROF: 1
NAME: Private_Lan
GW1: 192.168.000.232
DNS1: 192.168.000.232
DNS2: 192.168.000.251
SMTP: 192.168.000.250
POP3: 192.168.000.250
WINS1: 192.168.000.050
---------------------------------------------------
Now let's configure the DHCP Subnets table: we are going to insert the network address, the pool and the identifier of DHCP Profile to be used when assigning an IP from the pool. This is the command:
[16:02:17] ABILIS_CPX:a dhcp lan:1 name:Private_Lan net:192.168.0.0/24 pool1:192.168.0.131:192.168.0.179 prof:1
COMMAND EXECUTED
[16:03:22] ABILIS_CPX:d dhcp lan
- Not Saved (SAVE CONF), Not Refreshed (INIT) ---------------------------------
LAN: |NET: |MASK:
-------------------------------------------------------------------------------
1 192.168.000.000 255.255.255.000
[16:03:26] ABILIS_CPX:d dhcp lan:1
- Not Saved (SAVE CONF), Not Refreshed (INIT) ---------------------------------
Parameter: | Value:
-------------+-----------------------------------------------------------------
LAN: 1
NAME: Private_Lan
NET: 192.168.000.000/24
MASK: 255.255.255.000
POOL1: 192.168.000.131:192.168.000.179
PROF: 1
-------------------------------------------------------------------------------
Configuration of DHCP Hosts table is not required.
Now the configuration is complete.
Caution
To initialize the resource, use command init res:dhcp (to set act the changes made on uppercase parameters and in the tables) and save the configuration with save conf command to make the changes permanent.
Caution
To set act changes made on lowercase parameters a save conf and an Abilis restart are needed (i.e. with warm start command).
16.3.3. DHCP bindings table
The DHCP bindings table is the memory data base which stores bindings allocated for DHCP clients. A binding record includes the information about allocated IP address, start time and end time of lease, profile which is currently used by a DHCP client and some other information.
The Table of DHCP bindings is used in server mode only.
It is stored in the DHCP.BND file in the location defined by the WDIR parameter, that is by default the C:\APP\DHCP\ directory, and it allows storage of up to max-clients bindings, one per each record. Every one minute the DHCP server checks the bindings table in the memory and, if the table was changed since the last time it was updated, the DHCP server saves all bindings to the file.
During Abilis CPX DHCP resource start-up, the DHCP driver tries to read the bindings table from the CF. If the DHCP server finds the bindings file, it check wheter the file is can be updated, making a write operation try. If the writing attempt is successful the DHCP server goes to the ACTIVE state. If writing attempt fails the DHCP server goes to the STOP state; it writes a warning message into the System Log (i.e. "W: DHCP STOPPED") and it doesn't load the bindings DHCP.BND file content. If the DHCP server doesn't find the bindings file, it tries to create it. If it is not possible the server goes to the STOP state and it writes a warning message into the System Log (i.e. "W: DHCP STOPPED").
After loading the bindings from the DHCP.BND file, the DHCP server checks the bindings according to the current configuration of the DHCP driver and binding records that don't conform to the current configuration will be marked as "not valid" and they will not be used by the DHCP server.
The DHCP server makes the next checks of the loading bindings and marks the binding as "invalid" in all the following cases:
The subnet record which is coressponding to the IP address from the binding is not found in the subnets table.
The profile identifier from the binding is not found in the the profiles table.
If the binding is static (i.e. allocated from the hosts):
The host record with the IP and MAC addresses which are corresponding to the IP and MAC addresses from the loading binding is not found in the hosts table.
The IP address from the binding is found in one of the pools of the subnet record (i.e. if the corresponding subnet record was found).
if the binding is dynamic (i.e. allocated from the pools):
The host record with the IP and MAC addresses which are corresponding to the IP and MAC adresses from the loading binding is found in the hosts table;
The IP address from the binding is not found in one of the pools of the subnet record (i.e. if the corresponding subnet record was found).
Commands for handling DHCP bindings table are:
d dhcp bind: it displays DHCP bindings summary, in a synthetic format;
d dhcp binde: it display DHCP bindings details, in an extended format;
c dhcp bind: this command allows to remove a DHCP binding entry from the DHCP bindings table identified by the specified IP address.
Some examples follow.
[11:34:14] ABILIS_CPX:d dhcp bind
------------------+----------------+------+-----------------+------------------
MAC: |IP: |PROF: |Last request(GMT)|Expiry on(GMT)
------------------+----------------+------+-----------------+------------------
00-0C-6E-DE-2B-C1 192.168.000.002 1 27/12/2007 14:26 07/02/2036 06:28
00-0C-6E-E9-DE-29 192.168.000.003 1 27/12/2007 11:56 07/02/2036 06:28
00-0C-6E-DE-2C-15 192.168.000.005 1 28/12/2007 09:46 07/02/2036 06:28
00-08-54-01-D5-B7 192.168.000.006 1 05/10/2007 06:27 07/02/2036 06:28
00-40-CA-63-34-E5 192.168.000.008 1 28/12/2007 07:45 07/02/2036 06:28
00-48-54-13-23-E7 192.168.000.009 1 28/12/2007 10:22 07/02/2036 06:28
00-48-54-13-22-78 192.168.000.010 1 27/12/2007 12:45 07/02/2036 06:28
00-40-CA-63-34-6A 192.168.000.011 1 20/12/2007 09:46 07/02/2036 06:28
00-40-CA-63-34-CD 192.168.000.012 1 11/12/2007 15:49 07/02/2036 06:28
00-03-93-D9-71-94 192.168.000.014 1 28/12/2007 10:23 07/02/2036 06:28
00-08-54-02-00-78 192.168.000.024 1 12/12/2007 18:19 07/02/2036 06:28
00-40-CA-63-35-15 192.168.000.025 1 28/12/2007 07:16 07/02/2036 06:28
00-40-CA-63-34-E3 192.168.000.029 1 28/12/2007 08:57 07/02/2036 06:28
00-0C-6E-DE-2B-FD 192.168.000.030 1 28/12/2007 08:12 07/02/2036 06:28
00-40-CA-63-34-F2 192.168.000.032 1 28/12/2007 08:36 07/02/2036 06:28
00-40-CA-63-34-F8 192.168.000.033 1 28/12/2007 08:14 07/02/2036 06:28
00-0C-6E-DE-2B-C8 192.168.000.034 1 13/12/2006 11:33 07/02/2036 06:28
00-40-CA-63-34-82 192.168.000.035 1 28/12/2007 08:12 07/02/2036 06:28
00-40-CA-63-34-97 192.168.000.158 1 28/12/2007 07:45 28/12/2007 17:45
00-09-45-52-65-5B 192.168.000.161 1 28/12/2007 10:07 28/12/2007 20:07
00-09-45-52-10-44 192.168.000.166 1 28/12/2007 08:34 28/12/2007 18:34
00-07-85-51-F5-D6 192.168.000.171 1 28/12/2007 09:53 28/12/2007 19:53
00-40-CA-63-34-99 192.168.000.174 1 28/12/2007 09:45 28/12/2007 19:45
[11:34:21] ABILIS_CPX:d dhcp binde
----+-----+-------------------+-----------------+-------+----------------------
O: | ST: | MAC: | IP: | PROF: | Last request(GMT)
| Expiry on(GMT)
----+-----+-------------------+-----------------+-------+----------------------
H ACT 00-0C-6E-DE-2B-C1 192.168.000.002 1 27/12/2007 14:26:45
07/02/2036 06:28:15
-------------------------------------------------------------------------------
H ACT 00-0C-6E-E9-DE-29 192.168.000.003 1 27/12/2007 11:56:22
07/02/2036 06:28:15
-------------------------------------------------------------------------------
H ACT 00-0C-6E-DE-2C-15 192.168.000.005 1 28/12/2007 09:46:46
07/02/2036 06:28:15
-------------------------------------------------------------------------------
H ACT 00-08-54-01-D5-B7 192.168.000.006 1 05/10/2007 06:27:24
07/02/2036 06:28:15
-------------------------------------------------------------------------------
H ACT 00-40-CA-63-34-E5 192.168.000.008 1 28/12/2007 07:45:54
07/02/2036 06:28:15
-------------------------------------------------------------------------------
H ACT 00-48-54-13-23-E7 192.168.000.009 1 28/12/2007 10:22:51
07/02/2036 06:28:15
-------------------------------------------------------------------------------
H ACT 00-48-54-13-22-78 192.168.000.010 1 27/12/2007 12:45:53
07/02/2036 06:28:15
-------------------------------------------------------------------------------
H ACT 00-40-CA-63-34-6A 192.168.000.011 1 20/12/2007 09:46:24
07/02/2036 06:28:15
-------------------------------------------------------------------------------
H ACT 00-40-CA-63-34-CD 192.168.000.012 1 11/12/2007 15:49:57
07/02/2036 06:28:15
-------------------------------------------------------------------------------
H ACT 00-03-93-D9-71-94 192.168.000.014 1 28/12/2007 10:23:08
07/02/2036 06:28:15
-------------------------------------------------------------------------------
H ACT 00-08-54-02-00-78 192.168.000.024 1 12/12/2007 18:19:31
07/02/2036 06:28:15
-------------------------------------------------------------------------------
H ACT 00-40-CA-63-35-15 192.168.000.025 1 28/12/2007 07:16:40
07/02/2036 06:28:15
-------------------------------------------------------------------------------
H ACT 00-40-CA-63-34-E3 192.168.000.029 1 28/12/2007 08:57:33
07/02/2036 06:28:15
-------------------------------------------------------------------------------
H ACT 00-0C-6E-DE-2B-FD 192.168.000.030 1 28/12/2007 08:12:27
07/02/2036 06:28:15
-------------------------------------------------------------------------------
H ACT 00-40-CA-63-34-F2 192.168.000.032 1 28/12/2007 08:36:31
07/02/2036 06:28:15
-------------------------------------------------------------------------------
H ACT 00-40-CA-63-34-F8 192.168.000.033 1 28/12/2007 08:14:59
07/02/2036 06:28:15
-------------------------------------------------------------------------------
H ACT 00-0C-6E-DE-2B-C8 192.168.000.034 1 13/12/2006 11:33:52
07/02/2036 06:28:15
-------------------------------------------------------------------------------
H ACT 00-40-CA-63-34-82 192.168.000.035 1 28/12/2007 08:12:12
07/02/2036 06:28:15
-------------------------------------------------------------------------------
P EXP 00-0C-0C-01-5C-81 192.168.000.131 1 29/11/2007 10:59:42
29/11/2007 20:59:42
-------------------------------------------------------------------------------
P EXP 00-0C-0C-01-5B-BE 192.168.000.132 1 07/12/2007 10:17:12
07/12/2007 20:17:12
-------------------------------------------------------------------------------
P EXP 00-40-CA-63-34-B8 192.168.000.133 1 11/12/2007 21:58:05
12/12/2007 07:58:05
-------------------------------------------------------------------------------
P EXP 00-0C-29-52-67-31 192.168.000.134 1 17/12/2007 17:59:25
18/12/2007 03:59:25
-------------------------------------------------------------------------------
P EXP 00-16-36-EA-44-84 192.168.000.135 1 19/12/2007 10:10:38
19/12/2007 20:10:38
-------------------------------------------------------------------------------
P EXP 00-E0-4C-03-27-BC 192.168.000.136 1 18/12/2007 17:29:46
19/12/2007 03:29:46
-------------------------------------------------------------------------------
P EXP 00-0D-60-CE-7D-1D 192.168.000.150 1 07/11/2007 13:53:53
07/11/2007 23:53:53
-------------------------------------------------------------------------------
P EXP 00-E0-00-9B-D5-BB 192.168.000.151 1 08/08/2007 14:24:57
09/08/2007 00:24:57
-------------------------------------------------------------------------------
P EXP 00-07-95-BF-3A-7E 192.168.000.152 1 02/10/2007 10:36:55
02/10/2007 20:36:55
-------------------------------------------------------------------------------
P EXP 00-02-3F-0D-D5-A0 192.168.000.153 1 28/09/2007 07:22:33
28/09/2007 17:22:33
-------------------------------------------------------------------------------
P EXP 00-90-33-0F-02-EE 192.168.000.154 1 05/11/2007 18:18:39
06/11/2007 04:18:39
-------------------------------------------------------------------------------
P EXP 00-0F-20-CC-22-3C 192.168.000.155 1 17/10/2007 16:09:36
18/10/2007 02:09:36
-------------------------------------------------------------------------------
P EXP 00-16-6F-41-4B-EE 192.168.000.156 1 26/10/2007 13:42:41
26/10/2007 23:42:41
-------------------------------------------------------------------------------
P EXP 00-18-41-08-A0-74 192.168.000.157 1 25/10/2007 12:39:59
25/10/2007 22:39:59
-------------------------------------------------------------------------------
P ACT 00-40-CA-63-34-97 192.168.000.158 1 28/12/2007 07:45:26
28/12/2007 17:45:26
-------------------------------------------------------------------------------
P EXP 00-15-F2-03-06-4C 192.168.000.159 1 03/10/2007 08:01:28
03/10/2007 18:01:28
-------------------------------------------------------------------------------
P EXP 00-4F-4E-12-42-B9 192.168.000.160 1 19/11/2007 07:29:56
19/11/2007 17:29:56
-------------------------------------------------------------------------------
P ACT 00-09-45-52-65-5B 192.168.000.161 1 28/12/2007 10:07:13
28/12/2007 20:07:13
-------------------------------------------------------------------------------
P EXP 00-A0-D1-38-A4-14 192.168.000.163 1 07/09/2007 14:59:33
08/09/2007 00:59:33
-------------------------------------------------------------------------------
P EXP 00-16-D4-F2-06-A3 192.168.000.164 1 26/10/2007 15:32:37
27/10/2007 01:32:37
-------------------------------------------------------------------------------
P REL 00-40-8C-80-40-C2 192.168.000.165 1 23/11/2007 10:40:17
23/11/2007 10:42:40
-------------------------------------------------------------------------------
P ACT 00-09-45-52-10-44 192.168.000.166 1 28/12/2007 08:34:23
28/12/2007 18:34:23
-------------------------------------------------------------------------------
P EXP 00-03-93-D9-71-94 192.168.000.167 1 14/09/2007 06:40:59
14/09/2007 16:40:59
-------------------------------------------------------------------------------
P EXP 00-40-CA-63-34-C7 192.168.000.169 1 16/11/2007 10:00:05
16/11/2007 20:00:05
-------------------------------------------------------------------------------
P EXP 00-15-F2-59-09-7C 192.168.000.170 1 20/11/2007 15:31:45
21/11/2007 01:31:45
-------------------------------------------------------------------------------
P ACT 00-07-85-51-F5-D6 192.168.000.171 1 28/12/2007 09:53:45
28/12/2007 19:53:45
-------------------------------------------------------------------------------
P EXP 00-11-D8-70-A6-1D 192.168.000.172 1 30/08/2007 08:00:15
30/08/2007 18:00:15
-------------------------------------------------------------------------------
P EXP 00-0C-0C-01-48-AA 192.168.000.173 1 26/09/2007 12:34:27
26/09/2007 22:34:27
-------------------------------------------------------------------------------
P ACT 00-40-CA-63-34-99 192.168.000.174 1 28/12/2007 09:45:49
28/12/2007 19:45:49
-------------------------------------------------------------------------------
P EXP 00-0C-0C-01-48-BE 192.168.000.175 1 26/09/2007 12:33:29
26/09/2007 22:33:29
-------------------------------------------------------------------------------
P EXP 00-09-45-63-97-70 192.168.000.176 1 03/09/2007 11:54:48
03/09/2007 21:54:48
-------------------------------------------------------------------------------
P EXP 00-16-36-3E-1B-CB 192.168.000.177 1 16/11/2007 16:00:02
17/11/2007 02:00:02
-------------------------------------------------------------------------------
P EXP 00-1D-60-70-BE-1A 192.168.000.178 1 16/10/2007 08:24:22
16/10/2007 18:24:22
-------------------------------------------------------------------------------
P EXP 00-40-F4-BC-F5-3D 192.168.000.179 1 07/12/2007 13:54:03
07/12/2007 23:54:03
-------------------------------------------------------------------------------
Meaning of the most important parameters:
O
Origin of the binding [H: allocated from host tables; P: allocated from IP pools of one of subnets from subnets table; ?: origin unknown].
ST
State of the binding [REL: released; ACT:active, EXP: expired, ABD: abandoned, UNK: unknown (error state)].
MAC
The binded MAC address of the DHCP client.
IP
The IP address assigned to the DHCP client with the MAC address.
PROF
The identifier of DHCP profile from profiles table.
Last request(GMT)
The GMT date and time value when the lease was assigned/renewed the last time.
Expiry on(GMT)
The GMT date and time value when the lease will expire.
Binding records can also be cleared, however it should carefully evaluated by the user. The user interface allows to clear all the records currently present in the database in memory and/or to clear a specific record by specifying the IP address binded to the client. In both cases the user confirmation is requested before the command execution.
Here there are few samples of bindings clear commands:
[15:00:45] ABILIS_CPX:c dhcp bind ip:192.168.0.161
YOU ARE GOING TO DELETE THE SPECIFIED DHCP BINDING ENTRY FROM THE DATA BASE IN MEMORY.
DO YOU WANT TO PROCEES (Y/N)? Y
COMMAND EXECUTED
[15:00:45] ABILIS_CPX:c dhcp bind:a
YOU ARE GOING TO DELETE THE WHOLE CONTENT OF THE DHCP BINDINGS DATA BASE IN MEMORY.
DO YOU WANT TO PROCEES (Y/N)? Y
COMMAND EXECUTED
//-------------------------------------
The DNS Relay feature allows the system to appear as a DNS server to other IP stations while it simply forwards the requests to real DNS servers, and their responses are forwarded back to the original requesters.
The Abilis CPX DNS Resolver first requests the primary DNS Server. After 500 milliseconds, if it doesn't get any response, it forwards the same query to both primary and secondary server; if after 1 second, no response is received, another request is sent to both servers. In case of no answer, the same procedure is repeated after 1 second and after 2 seconds. If the DNS Resolver doesn't get any answer within 4 seconds, it terminates the procedure.
This procedure is repeated for a number of times equal to the value set in the RTY parameter. The delay (in seconds) between two subsequent queries can be set with the DELAY parameter.
The example below shows how to configure the DNS Resouce as Resolver.
[16:37:46] ABILIS_CPX:s p dns act:yes primary:62.94.0.1 secondary:62.94.0.2
COMMAND EXECUTED
[16:39:44] ABILIS_CPX:d p dns
RES:Dns - Not Saved (SAVE CONF), Not Refreshed (INIT) -------------------------
------------------------------------------------------------------------
Run DESCR:Domain_Name_System
LOG:NO ACT:YES
locport:53 SRCADD:R-ID (192.168.001.001) TOS:0-N
- Resolver -------------------------------------------------------------
PRIMARY:062.094.000.001 SECONDARY:062.094.000.002
DELAY:5 RTY:1
CACHE:NO cache-size:500
- Relay/Server ---------------------------------------------------------
RELAY:NO relay-size:500 RELAY-TOUT:10
SERVER:NO
IPSRC:* IPSRCLIST:#
Caution
To activate the changes made on the upper case parameters, execute the initialization command init res:dns.; while to set act the changes made on the lowercase parameters a save conf and an Abilis restart are required (i.e. with warm start command).
In the example above, CACHING is disabled (CACHE:NO). If CACHE:YES , when a DNS resolver (i.e. client) receives a DNS response, it caches the response for some time; this time depends on the size of the cache (cache-size parameter).
The DNS Relay feature allows the system to appear as a DNS server to other IP stations while it simply forwards the requests to real DNS servers, and their responses are forwarded back to the original requesters. So, when Abilis acts as DNS relay it actually acts as an “intermediate” between the requester and the real DNS servers.
The method is absolutely necessary when Abilis is used in a LAN as a router with NAT+PAT with a dial-up PPP connection. In this situation the address of DNS servers may not be known in advance because they are discovered at PPP connection establishment, and therefore they cannot be configured in the stations: the address of Abilis is configured instead, which in turn will forward the request to the DNS servers addresses obtained by PPP.
The method can also be used to simplify the configuration of the lan stations: lans are configured with the same address for both “default gateway” and “DNS server”, the CPX will forward the requests to the configured DNS which may be easily changed by the CPX administrator at any moment, and for all the stations.
The example below shows how to configure the DNS Resouce as Relay.
17.4.1. DNS Resource as Server
To configure the DNS Resouce as a Server type the following command:
[11:56:50] ABILIS_CPX:s p dns act:yes server:yes
COMMAND EXECUTED
[11:57:20] ABILIS_CPX:d p dns
RES:Dns - Not Saved (SAVE CONF), Not Refreshed (INIT) -------------------------
------------------------------------------------------------------------
DESCR:Domain_Name_System
LOG:NO ACT:YES
locport:53 SRCADD:R-ID (192.168.001.001) TOS:0-N
- Resolver -------------------------------------------------------------
PRIMARY:# SECONDARY:#
DELAY:5 RTY:1
CACHE:NO cache-size:500
- Relay/Server ---------------------------------------------------------
RELAY:NO relay-size:500 RELAY-TOUT:10
SERVER:YES
IPSRC:* IPSRCLIST:#
It is possible to filter the IP addresses allowed to the DNS service by combining the parameters IPSRC and IPSRCLIST.
In the following example, the “DNS_Allowed” list will be created and the range of IP from 192.168.1.10 to 192.168.1.50 will be added; otherwise, the address 192.168.1.100 will be set as the IP address Source.
DNS server can store up to 300 definitions (association between IP address and name): they are stored in the DNS table. The table can be displayed with the command d dns. By typing d dns ? command, it is possible to display the meaning of all the fields.
[10:44:46] ABILIS_CPX:d dns
Total records:0 Direct Lookup:0 Reverse Lookup:0 D&R Lookup:0
-------------------------------------------------------------------------------
ID: DIR: NAME: IP: TTL:
-------------------------------------------------------------------------------
*** NO DNS SERVER ENTRIES DEFINED ***
Meaning of the fields:
ID
DNS table entry identifier
DIR
Usage of the record [D (direct): domain names are translated into IP addresses; R (reverse): it is allowed the inverse lookup of the DNS record; DR (direct and reverse): the two features are allowed].
NAME
domain name.
IP
IP address.
TTL
The Time To Live sets the duration storage into a DNS cache system before it's considered expired.
The previous DNS records Table can be managed with these commands:
d dns : displays all Local DNS server table entries;
d dns filter:val [filter:val] : displays any Local DNS server table entry matching the specified filter(s);
a dns id:val name:
c dns id:val : clears a Local DNS server table entry;
s dns id:val [par:val] : sets parameters of a Local DNS server table entry.
Let's see an example of a DNS table configuration: let's assign to the IP addresses 192.168.1.20 and 192.168.1.30 the domain names john.lan and frank.lan; the first entry will be set as direct, while the second as "both" (direct+reverse).
//-------------------------------------
//-------------------------------------
//-------------------------------------
//-------------------------------------
//-------------------------------------
//
//-------------------------------------
// dns zone transfer: tcp--#53
// exchange database information between
// clients-servers
//
// dns relay:
// disabled: dsl router will handout the ip address of the isp iDNS
server address diretly to dhcp clients.
// enabled: gives the dhcp clients the router address for dns
// lookup and relay the request to isp dns servers.
// later the router will caching the response.
//
//
// |firewall, NAT, ACL...dns Proxy
// |
// clients----> dsl router -------> ISP dns server
// |
// router ip addr
|______>relay: sendto(isp_dns_ip)
<------recvfrom(isp_dns_ip)
//
// name ip time_t mac_addr AAA CNAME A
<--------reply to dns request.
//
//
// dproxy-nextgen dns proxy
// caching in a file (hasr disk)--cookie
// config.name_server_pnds[#]
// dns_req_t *head;
// timeout
// dns port; 53 (tcp, udp)
//------------------------------------
FILE *fp = fopen(config.cache_file, "r");
printf("%d, %s\n", __FUNCTION__, __LINE__);
int name_host_lookup(char *name) {
if (name == NULL || name[o] == '\0\)
return 0;
while (fgets(line, SIZE, fp)) {
host_ip = strtok(line, \t\r\n");
inet_aton(host_ip, &addr);
host_name = strtok(NULL, " \r\t\n");
if (host_name, strcasecmp(host_name, name)) {
strncpy(ip, host_ip, size);
fclose(fp);
return 1;
}
}
}
rewind(fp);
system("ping_connect");
// cache replace with same name
unlink(old_fp);
// configuration
const struct config_t conf[] = {
{},
{},
{0,0,0,0}
};
// dns_request_t *list
add_list(list **head, req_t)
new->next = (head)->next;
*head = new -malloc();
del_list()
find_list()
dns_read_packet(sock, req_t)
req->cnt = recvfrom(sock, m->buf, sz, 0, &sa, len);
memcpy(req->src_addr, &sa.sin_addr, sz);
req->port = ntohs(sa.sin_port);
req->cache = 0;
dns_decode_req(req_t);
dns_write_packet(sock, in_addr, port, req_t)
memset(&sa, 0, sz);
memcpy(&sa.sin_addr.s_addr, &in, sz);
sa.sin_port = htons(port);
sa.sin_family = AF_INET;
ret = sendto(sock, req->buf, sz, 0, &sa, sz);
int logg(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vsnprintf(tmp, len, fmt, ap);
va_end(ap);
}
is_dns_cache()
if(stat("/var/rmp/dns_cache", &stats) == 0)
return 1;
int if_fetch( *ife)
fd = socket(AF_IENT, SOCK_DGRAM, 0);
ioctl(ds, siocgifaddr, &ifr);
int dns_init()
socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
ip.s_addr = INADDR_ANY;
sa.sin_famuly = AF_INET;
memcpy(&sa.sin_addr, &ip, sz);
sa.sin_port = htons(PORT);
bind();
FD_ZERO(&rfds);
FD_SET();
cache_purge();
int islocalhost(char *name)
fp = fopen(file, "r");
rewind(fp);
while(!feof(fp)) {
fscanf(fp, "", ip_name);
}
fclose(fp);
int dns_main_loop()
while (not_quit)
ret= select(sz, &rfds, 0, 0, &tv);
if (ret)
dns_read_packet(dns_sock, &req_t);
dns_handle_req(&m);
else
//resolv.conf
stat(..);
syslog(LOG_INFO, ..);
else // timeout
// resend to another name server from List:
dns_construct_err_reply();
dns_write_oacket();
dns_req_list = dns_req_list_remove(this one);
1G
int main()
signal(SIGHUP, sig_hup); ==> signal(SIGHUP, ); conf_load(file_name);
get_options();
dns_init();
config.daemon_mode();
dns_main_loop();
// linux kernel model driver
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) && \
(LINUX_VERSION_CODE < KERNEL_VERSION(2, 7, 0))
#include
#endif
//wake_up_interrutible(q)
//wait_event_interruptible_timeout(q,c,t)
//set_page_reserved(virt_to_vage(vpa))
//clear_page_reserved(virt_to_page(vpa))
// pci_get_device()
// pci_resources_start()
// pci_resources_flags()
// pci_resources_len()
// pci_enable_device()
// pci_disable_device()
release_region();
request_region();
MODULE_AUTHOR("aaa, aaa");
MODULE_DESCRIPTION(DEV_MODEL, " driver " VErSION);
MODULE_LICENSE("GPL");
MODULE_SU{PORTED_DEVICE(DEV_MODEl);
int gsc_irq_isr(int irq, void *dev_id, ISR_ARGs) {
handled = gsc_irq_isr_common(irq, dev_id);
return = handled ? IRQ_HANDLED : IRQ_NONE;
return (irq);
}
int gsc_proc_get_info(
char *page,
char **start,
off_t offset,
int count) {
i = gsc_proc_read(,,,,); ==> read_proc();
}
// hardware.c
// read(intr_ctrl_stat(device),
// intr contr register
// intr mask register
// intr status register
// config register
int no_of_ones(int n)
{
iny cnt=0;
while(n>0)
{
if(n&1)
cnt++;
n=n>>1;
}
return cnt;
}
int bitcount (unsigned int n) {
int count = 0 ;
while (n) {
count++ ;
n &= (n - 1) ;
}
return count ;
}
trie:
prefix tree---suffix trie
Delve Networks » Data Structures Ideas Object Oriented Design
Tom on July 17, 2009 | Question #173669 (Report Dup) | Edit | History
You have more than 3 million entries of phone numbers. You have to create a phone book just like the one we have on the new phones these days. You type the name, and the numbers that match the letters you typed shows up on your phone.
For e.g: When you type 'K' all numbers under K appear,then you say "i"...all numbers under "Ki" appear..so on and so forth.
How will you design/architecture this type of search? Discuss data structures you would use whats the worst case for your design?
i think this question has already been asked in other threas...i guess the best solution from the context of efficiency is to use suffix trees and hence TRIE...they do exactly the same thing as what we are looking for...hope this helps. thankx
Introduction
Trie is an ordered tree data structure that uses strings as keys. Unlike Binary Trees, Tries do not store keys associated with the node. The key is actually determined based on the position of the node on the tree. Any descendants of a node shares a common prefix of the key string associated with that node. Hence, trie is also called as Prefix Tree. The word "trie" comes from Retrieval, and it is pronounced as "try". To read more about Trie click here.
Since this data structure is a prefix tree, trie is commonly used in Dictionaries, Phone Directories and matching algorithms. Trie is best-suited for phone directory (any matching application for that matter) because it is very efficient in matching strings.
So I have decided to implement Trie myself in C#. I have created three classes:
Node: Represents a single tree node;
NodeCollection: Represents the children of a node;
Trie: Trie implementation to insert and search nodes.
Implementation
Node: Node represents a basic tree node. Node implements both Depth First and Breadth First algorithms to search its children. It also contains its Parent node and Children node. Node has a key and a Value. Key contains the single character and the value has the actual value of the node. The actual key of the node will be determined by suffixing the single character to its parent's key. Node has a special property called IsTerminal. This property is set to true if the key or a value represents a complete string. See the picture below:
//Inserts Names into the Trie data structure
public static Node InsertNode(string name, Node root)
{
//Is name null?
if (string.IsNullOrEmpty(name))
throw new ArgumentNullException("Null Key");
//set the index, start inserting characters
int index = 1;
//key
string key;
//start with the root node
Node currentNode = root;
//loop for all charecters in the name
while (index <= name.Length)
{
//get the key character
key = name[index - 1].ToString();
//does the node with same key already exist?
Node resultNode = currentNode.Children.GetNodeByKey(key);
//No, this is a new key
if (resultNode == null)
{
//Add a node
Node newNode = new Node(key, name.Substring(0, index));
//If reached the last charaecter, this is a valid full name
if (index == name.Length)
newNode.IsTerminal = true;
//add the node to currentNode(i.e. Root node for the first time)
currentNode.Children.Add(newNode);
//set as the current node
currentNode = newNode;
}
else
{
//node already exist, set as tghe current node
//and move to the next character in the name
currentNode = resultNode;
}
//move to the next character in the name
index++;
}
//all done, return root node
return root;
}
The Insert method inserts the string as one character at a time. It starts with the first character; if the first character doesn't already exist in the root node it adds a new node with the new character and returns the new node. Otherwise it returns the node with the fist character for adding remaining characters. It loops until it adds the entire string. Once it reaches the last character, it marks that node as a terminal node because this node represents a complete string in the tree hierarchy.
The Find methods is implemented by Depth First search algorithm. The tree is searched until the complete string is found. Below is the code.
Collapse
//Find a node given the key("Jo")
public static bool Find(Node node, string key)
{
//Is key empty
if (string.IsNullOrEmpty(key))
return true;//terminal Node
//get the first character
string first = key.Substring(0, 1);
//get the tail: key - first character
string tail = key.Substring(1);
Node curNode = node.Children.GetNodeByKey(first);
//loop until you locate the key i.e. "Jo"
if (curNode != null)
{
return Find(curNode, tail);
}
else
{
//not found, return false
return false;
}
}
I've attached the entire source code above. The source code contains the Trie class library and a console application to test the Trie library. The console application loads a set of names (stored in names.txt in debug folder) in to the tree and provides options to run Depth First & Breadth First algorithm. The application also provides options for Directory Look-Up and Find option.
The class library can be further used to develop a web based phone directory. The data can also be stored on the client (it is too small) and the Trie can be implemented in JavaScript.
Happy Coding,
Madhu
//============
#include
#include
No comments:
Post a Comment