4.3   VxWorks Manual Network Configuration Utilities

VxWorks includes a variety of utilities you can use to assign Internet addresses to network interfaces, hosts, and broadcasting. VxWorks also includes utilities you can use to explicitly add a gateway or configure a subnet. Not included in this section is information on the automatic network configuration protocols, DHCP and BOOTP. For more information on these utilities and their configuration needs, see Network Configuration Protocols.

4.3.1   Assigning Internet Addresses

On a VxWorks target, you can use the functions of the ifLib library to associate Internet addresses with network interfaces, host names, and broadcasting. For a listing of these configuration functions, see the reference entry for ifLib.

Associating Internet Addresses with Network Interfaces

A system's physical connection to a network is called a network interface. Each network interface must be assigned a unique Internet (inet) address. A system can be connected to several networks and thus have several network interfaces.

On a UNIX system, the Internet address of a network interface is specified using the ifconfig command. For example, to associate the Internet address 150.12.0.1 with the interface ln0, enter:

% ifconfig ln0 150.12.0.1

This is usually done in the UNIX startup file /etc/rc.boot. For more information, see the UNIX reference entry for ifconfig.

In VxWorks, the Internet address of a network interface is specified, and a new route to that interface is constructed, by calling ifAddrSet( ). For example, to associate the Internet address 150.12.0.1 with the interface ln0, enter:

ifAddrSet ("ln0", "150.12.0.1");


*

NOTE: The subnet mask used in determining the network portion of the address used in ifAddrSet( ) will be that set by ifMaskSet( ), or the default class mask if ifMaskSet( ) has not been called. It is standard to call ifMaskSet( ) prior to any calls to ifAddrSet( ).

For more information, see the Tornado reference entries for ifLib and ifAddrSet( ).

The VxWorks network startup routine, usrNetInit( ) in usrNetwork.c, automatically sets the address of the interface used to boot VxWorks to the Internet address specified in the VxWorks boot parameters.

Associating Internet Addresses with Host Names

The underlying Internet protocol uses the 32-bit Internet addresses of systems on the network. People, however, prefer to use system names that are more meaningful to them. Thus VxWorks and most host development systems maintain their own maps between system names and Internet addresses.

On UNIX systems, /etc/hosts contains the mapping between system names and Internet addresses. Each line consists of an Internet address and the assigned name(s) for that address:

150.12.0.1 vx1

There must be an entry in this file for each UNIX system and for each VxWorks system on the network. For more information on /etc/hosts, see your UNIX system reference entry hosts(5).

In VxWorks, call hostAdd( ) to associate system names with Internet addresses. Make one call to hostAdd( ) for each system the VxWorks target communicates with, as follows:

hostAdd ("vx1", "150.12.0.1");


*

NOTE: In addition to hostAdd( ), VxWorks also includes DNS. You can use DNS to create and automatically maintain host-name/address associations for your VxWorks target. For more information, see DNS: Domain Name System.

To associate more than one name with an Internet address, hostAdd( ) can be called several times with different host names and the same Internet address. The routine hostShow( ) displays the current system name and Internet address associations.In the following example, 150.12.0.1 can be accessed with the names host, myHost, and widget:

-> hostShow  
value = 0 = 0x0

The the standard output device displays the following output:

hostname         inet address     aliases 
--------          -----------     ------- 
localhost        127.0.0.1  
host             150.12.0.1  
 
-> hostAdd "myHost", "150.12.0.1" 
value = 0 = 0x0 
-> hostAdd "widget", "150.12.0.1" 
value = 0 = 0x0 
-> hostShow 
value = 0 = 0x0

Now standard output displays the following:1

hostname         inet address     aliases 
--------          -----------     ------- 
localhost        127.0.0.1  
vx1             150.12.0.1       myHost widget  
value = 0 = 0x0 

The VxWorks network startup routine, usrNetInit( ) in usrNetwork.c, automatically adds the name of the host VxWorks was booted from, using the host name specified in the VxWorks boot parameters.

Assigning Broadcast Addresses

Many physical networks support the notion of broadcasting a packet to all hosts on the network. A special Internet broadcast address is interpreted by the network subsystem to mean "all systems" when specified as the destination address of a datagram message (UDP). This is shown in the demo program target/src/demo/dg/dgTest.c.

Unfortunately, there is some ambiguity about which address is to be interpreted as the broadcast address. The Internet specification now states that the broadcast address is an Internet address with a host part of all ones (1). However, some older systems use an Internet address with a host part of all zeros as the broadcast address.

Most newer systems, including VxWorks, accept either address on incoming packets as being a broadcast packet. But when an application sends a broadcast packet, it must use the correct broadcast address for its system.

VxWorks normally uses a host part of all ones as the broadcast address. Thus a datagram sent to Internet address 150.255.255.255 (0x5AFFFFFF) is broadcast to all systems on network 150. However, to allow compatibility with other systems, VxWorks allows the broadcast address to be reassigned for each network interface by calling the routine ifBroadcastSet( ). For more information, see the reference entry for ifBroadcastSet( ).

In addition, VxWorks supports multicasting--transmission to a subset of hosts on the network. For more information on multicasting, see Using a Datagram (UDP) Socket to Access IP Multicasting.

4.3.2   Adding Gateways to a Network

One of the primary functions of IP is to transport packets from one host to another. Communication between two hosts on the same physical network requires little effort on the part of IP. In this case, IP can deliver the packet directly to the destination. However, if the destination of a packet is not local, IP cannot deliver the packet directly. In this case, IP hands the packet off to a gateway.

A gateway is a machine that is able to forward packets from one network to another. Thus, a gateway has a physical connection to two or more networks. If the destination of a packet is local to the network on the other side of the gateway, the gateway can deliver the packet directly. Otherwise, the gateway passes the packet to still another gateway. This process, called routing, continues until the packet is delivered or expires.

To support routing, most systems contain a table that identifies a default gateway as well as gateways associated with specific IP addresses. To maintain this table and determine network connectivity, a VxWorks system uses the Routing Information Protocol (RIP) either version 1 or 2. The RIP implementation provided with VxWorks is based on the BSD 4.4 routed program.

To setup the initial routing information available on a VxWorks target, use the functions of the routeLib library. Using the routeLib routines, you can establish the default gateway you want the target to use. These routines also let you associate a destination IP address with a specific gateway. For a listing of the routing configuration functions, see the reference entry for routeLib.


*

NOTE: An OSPF-based router is available for VxWorks as a separately purchasable option. You can use this router instead of RIP to set up and maintain routing information.

Adding a Route on Windows

The procedures vary according to your version of Windows and your networking software package. For the details, see the documentation for your system.

Adding a Route on UNIX

A UNIX system can be told explicitly about a gateway in one of two ways: by editing /etc/gateways or by using the route command. When the UNIX route daemon routed is started (usually at boot time), it reads a static routing configuration from /etc/gateways. Each line in /etc/gateways specifies a network gateway in the following format:

net destinationAddr gateway gatewayAddr metric n passive

where n is the hop count from the host system to the destination network (the number of gateways between the host and the destination network) and "passive" indicates the entry is to remain in the routing tables.

For example, consider a system on network 150. The following line in /etc/gateways describes a gateway between networks 150 and 161, with an Internet address 150.12.0.1 on network 150. A hop count (metric) of 1 specifies that the gateway is a direct connection between the two networks:

net 161.27.0.0 gateway 150.12.0.1 metric 1 passive

After editing /etc/gateways, you must kill the route daemon and restart it, because it only reads /etc/gateways when it starts. After the route daemon is running, it is not aware of subsequent changes to the file.

Alternatively, you can use the route command to add routing information explicitly:

# route add destination-network gatewayAddr [metric]

For example, the following command configures the gateway in the same way as the previous example, which used the /etc/gateways file:

# route add net 161.27.0.0 150.12.0.1 1

Note, however, that routes added with this manual method are lost the next time the system boots.

You can confirm that a route is in the routing table by using the UNIX command netstat -r.

Adding a Route on VxWorks

VxWorks provides a set of functions that you can use to edit the routing table. However, before you edit the table, it is generally a good idea to look at what is already there.

  • Inspecting the Routing Table
  • To inspect the contents of the routing table, use routeShow( ). If a VxWorks target boots through an Ethernet network interface, a typical routeShow( ) call would display the following:2

    -> routeShow() 
     
    ROUTE NET TABLE 
    destination      gateway           flags  Refcnt  Use       Interface  
    ---------------------------------------------------------------------- 
    147.11.44.0      147.11.44.165     101    0       0             ei0  
    ---------------------------------------------------------------------- 
    ROUTE HOST TABLE  
    destination      gateway           flags  Refcnt  Use       Interface  
    ---------------------------------------------------------------------- 
    127.0.0.1        127.0.0.1         5      1       0             lo0  
    ---------------------------------------------------------------------- 
    value = 77 = 0x4d = `M'

    In the output shown above, the route entry for 147.11.44.0 shows that the flags RTF_CLONING (0x100) and RTF_UP (0x001, signifying that the route is available for use) are set. This route entry is set when the Ethernet network device "ei0" is initialized. This is a network route and the network mask associated with this route is 0xFFFFFF00.

  • Editing the Routing Table
  • VxWorks includes a number of functions that you can use to edit the routing table. These functions are as follows:3

    routeAdd( )
    Adds a route to the routing table.

    routeNetAdd( )
    This function is the same as routeAdd( ) except that the destination address is assumed to be a network. This is useful for adding a route to a sub-network that is not on the same physical network as the local network.

    routeDelete( )
    Deletes a route from the routing table.

    mRouteAdd( )
    Adds routes differentiated by masks and service quality.

    mRouteDelete( )
    Deletes routes differentiated by masks and service quality.


    *

    NOTE: The functions routeAdd( )and routeDelete( ) implicitly derive the netmask from the given destination and gateway address. Please refer to the manual pages for the function calls mentioned above.

    To add gateways to the VxWorks network routing tables, use routeAdd( ) or mRouteAdd( ). For example, to use routeAdd( ):

    /* routeAdd ("destinationAddr", "gatewayAddr") */ 
    /* To send to network 161.27.0.0 use 150.12.0.2 */ 
    routeAdd ("161.27.0.0", "150.12.0.2"); 

    Both addresses can be specified either by dotted decimal notation or by the host names defined by the routine hostAdd( ). If the destination address is a subnet, you can use routeNetAdd( ) instead.

    For example, consider two VxWorks machines vx2 and vx3 (shown in Figure 4-3), both interfaced to network 161. Suppose that vx3 is a gateway between networks 150 and 161 and that its Internet address on network 161 is 161.27.0.3.

    The following calls can then be made on vx2 to establish vx3 as a gateway to network 150:

    -> routeAdd ("150.12.0.0", "vx3");

    or:

    -> routeAdd ("150.12.0.0", "161.27.0.3");

    To confirm that a route is in the routing table, use the routeShow( ) routine.4 Other routing routines are available in the library routeLib.

    The VxWorks network startup routine, usrNetInit( ) in usrNetwork.c, automatically adds the gateway specified in the boot parameters (if any) to the routing tables. In this case, the address specified in the gateway field (g = ) is added as the gateway to the network of the boot host.

    To add the default route entry to the routing table:

    routeAdd ("0.0.0.0", "gatewayAddrs");

    If a default route is added to the routing table, any packet for which a host route or a network route cannot be established, is forwarded to the address provided in the default route entry.

    To delete an entry from the routing table, use routeDelete( ).

    /* Delete route to node 161.27.0.51 using gateway 150.12.0.2 */ 
    routeDelete ("161.27.0.51", "150.12.0.2");
  • Using mRouteAdd( )
  • To use mRouteAdd( )you need to specify a little more information than for a simple routeAdd( ) call. However, this extra information does provide support for additional routing services that take into account the type of service or mask associated with a particular route. The general format of a mRouteAdd( ) call is as follows:

    mRouteAdd ( "destination", "gateway", netmask, type-of-service, flags)

    Thus, to specify that the route to the 90.0.0.0 network use the 91.0.0.3 router:

    mRouteAdd ("90.0.0.0", "91.0.0.3", 0xffffff00, 0, 0);

    To delete a route that was added using mRouteAdd( ), call mRouteDelete( ). The general format of a call to mRouteDelete( ) is as follows:

    mRouteDelete ("destination", netmask, tos)

    Thus, to delete the route just added above:

    mRouteDelete("90.0.0.0", 0xffffff00, 0);

    The netmask and type of service must match those of the route you want to delete. Otherwise the route is not deleted.

    Using mRouteAdd( ), you can specify multiple routes to a single destination. These routes differ only in factors such as the netmask or the type of service. For example:

    mRouteAdd ("90.0.0.0", "91.0.0.3",   0xFFFFFF00, 0, 0); 
    mRouteAdd ("90.0.0.0", "91.0.0.254", 0xFFFF0000, 0, 0);

    Now packets destined for "90.0.0.0" can get there using either of the two different gateways. The distinguishing factor is the netmask, although you could have used the type-of-service or flags values to distinguish the routes. For more information, see the mRouteAdd( ) reference entry.

  • Setting the Type Of Service
  • The type-of-service parameter to mRouteAdd( ) takes any of the following values:

    IPTOS_LOWDELAY5
    IPTOS_THROUGHPUT
    IPTOS_RELIABILITY
    IPTOS_MINCOST

    The routing engine uses these values to pick among multiple routes when a user application requests a certain type of service for their socket. Applications choose their type of service as input to a setsockopt( )call. See the setsockopt( ) reference entry for more information.

  • Setting the Routing Priority
  • Within VxWorks it is now possible to have routes chosen on a priority scheme. All routes that are installed in the system have a routing protocol type associated with them. These types are as follows:

    M2_ipRouteProto_other6
    M2_ipRouteProto_local
    M2_ipRouteProto_netmgmt
    M2_ipRouteProto_icmp
    M2_ipRouteProto_egp
    M2_ipRouteProto_ggp
    M2_ipRouteProto_hello
    M2_ipRouteProto_rip
    M2_ipRouteProto_is_is
    M2_ipRouteProto_es_is
    M2_ipRouteProto_ciscoIgrp
    M2_ipRouteProto_bbnSpfIgp
    M2_ipRouteProto_ospf
    M2_ipRouteProto_bgp

    All routes added by mRouteAdd( )take a protocol type of M2_ipRouteProto_other.

    To set the routing priority, use routeProtoPrioritySet( ):

    void routeProtoPrioritySet 
        ( 
        int    proto,             /* protocol no, from m2Lib.h */ 
        int    prio               /* priority, >= 0 , <= 200 */ 
        )

    Using this routine, you can give a certain class of routes precedence over routes of other classes. For example, you could use routeProtoPrioritySet( )to give OSPF-installed routes precedence over routes installed by RIP or mRouteAdd( ). See the routeProtoPrioritySet( ) reference entry for more information.

    4.3.3   Subnet Configuration

    An Internet address consists of a network address portion and a host address portion. There are different classes of Internet addresses in which different parts of the 32-bit address are assigned to each portion. This provides a great deal of flexibility in network addressing. Even so, in some environments network addresses are a scarce resource.

    A single network address can be subdivided into multiple sub-networks using a technique called subnet addressing. This technique involves extending the network portion of the addresses used on a particular set of physical networks. The interpretation of the Internet address is altered to include more bits in the network portion and fewer in host portion. For example, if a network uses a type B address (131.1.0.0), the third byte can be used for the subnet and the fourth byte for the host address, as shown in Figure 4-4. Internal to the subnet, the Internet address is interpreted as 131.1.7 for the network portion and 81 for the host portion.

    The specification of which bits are to be interpreted as the network address is called the net mask. A net mask is a 32-bit value with 1's in all bit positions to be interpreted as the network portion. In the example in Figure 4-4, the netmask is 0xFFFFFF00. In VxWorks, use ifMaskSet( ) to specify the subnet mask for a particular network interface ( see also the reference entry for ifMaskSet( )).

    To specify a net mask, you must correctly access the host from which you are booting. This can be done by appending :mask to the Internet address specifications for the Ethernet and/or backplane interfaces in the boot parameters, where mask is the desired net mask in hexadecimal. For example, when entering boot parameters interactively, it might look as follows:

    inet on ethernet (e)      : 131.1.7.81:ffffff00 
    inet on backplane (b)     : 131.1.81.1:ffffff00 
    

    When specifying the boot parameters in a boot string, the same Internet address specification looks as follows:

    e=131.1.7.81:ffffff00 b=131.1.81.1:ffffff00      

    1:  Internally, hostShow( ) uses the resolver library to access DNS to get the information it needs to respond to a query.

    2:  This assumes that the VxWorks image is configured with network show routines. The relevant configuration macro is INCLUDE_NET_SHOW.

    3:  These routines manage static routing entries. These entries are not updated, modified, or deleted by the dynamic routing protocols (RIP or OSPF). They remain active until you explicitly delete them.

    4:  This function is not built into the Tornado shell. The relevant configuration macro is INCLUDE_NET_SHOW.

    5:  The IPTOS constants are defined in netinet/ip.h.

    6:  The M2_ipRouteProto constants are defined in h/m2Lib.h.