4.2   IP, Internet Protocol

A network protocol handles network communications at the level just above the MUX interface to the drivers that provide raw Ethernet and backplane transmission mechanisms. In VxWorks, the most commonly used network protocol is the Internet Protocol (IP)--the network protocol of the Internet protocol suite often referred to as TCP/IP.

With IP, each host (computer) in the network has a unique 4-byte Internet address (described in 4.2.1 Internet Addresses). IP accepts packets addressed to a particular host and tries to deliver them. If multiple networks are connected by routers, IP forwards a packet from router to router until the packet reaches a network where it can be delivered directly. IP also breaks up and reassembles packets to fit the packet size of the physical network. However, IP makes no guarantees that packets are delivered to the destination correctly. Although it is possible to access IP directly, most applications use one of the higher-level protocols such as UDP or TCP.

The VxWorks network also fully supports the associated Internet Control Message Protocol (ICMP) and the Ethernet Address Resolution Protocol (ARP), as required by the relevant RFCs.

4.2.1   Internet Addresses

Each Internet host has a unique Internet address and an associated address mask. An Internet address is four bytes long and contains information that identifies a network as well as a specific host on that network. The number of bits used for network identification versus host identification can differ according to the class of the address.

Depending on the address class, the networking software uses different masks to separate the bits that carry the network address from those that carry the host address. The address mask is set to a default value according to class if subnets are not used. For more information, see 4.3.3 Subnet Configuration and 4.7.8 Proxy ARP and Its Consequences for Subnet Configuration.

The following list describes the Internet addresses used to accommodate different network configurations.

Class A:
These addresses support a small number of networks, each with a large number of hosts.
Class B:
These addresses support a moderate number of networks, each with a moderate number of hosts.
Class C:
These addresses support a large number of networks, each with a small number of hosts.
Class D:
These addresses support IP multicasting.

These classes are distinguished by the high-order bits of an Internet address as shown in Figure 4-1.

By convention, Internet addresses are usually represented in dotted-decimal notation, which lists the 32-bit number as a string of four 8-bit values separated by dots. Internally, the Internet address is often kept as a simple 32-bit value (of type struct in_addr1 ). For example, the Internet address 0x5A010203 is 90.1.2.3 in standard dotted-decimal notation. Each Internet address class has a unique address range determined by the high-order bits and the default address mask (used for separating the bits used for the network portion of the address) as shown in Table 4-1.

VxWorks includes utilities for manipulating Internet addresses. For example, there are routines for converting between dot notation and integer notation, routines for extracting network and host portions of an address, and routines for creating a new address from a network and host number.

See the reference entry for inetLib.

Table 4-1:  Internet Address Ranges


Class
 
High Order Bits
 
Default Address Mask
 
Address Range
 

A
 
0
 
0xff000000
 
0.0.0.0 - 126.255.255.255
 
Reserved
     
127.0.0.0 - 127.255.255.255
 
B
 
10
 
0xffff0000
 
128.0.0.0 - 191.255.255.255
 
C
 
110
 
0xffffff00
 
192.0.0.0 - 223.255.255.255
 
D
 
1110
 
None
 
224.0.0.0 to 239.255.255.255
 

4.2.2   Packet Routing

The IP protocol handles packet routing. Each route entry in the routing table is a mapping between a destination address and the network interface through which the packet is transmitted.

The route entries in a routing table are of two types: host-specific and network-specific. Host-specific route entries contain the host destination address and the address of the gateway to use for packets destined for this host. Network-specific route entries contain a network destination address and the Internet address of the gateway to use for packets destined for this network.

The VxWorks networking software establishes a route before transmitting each packet. Given a destination address, VxWorks searches the routing table to find a matching route entry and thus the network interface through which it transmits the packet. A route entry is considered a match if the logical AND of the network mask and the given search key (destination address) equals the destination address stored in the route entry. For example, if a route entry has 147.11.44.00 as a destination and 0xFFFFFF00 as a network mask, a search key of 147.11.44.155 matches. However, a search key of 147.11.43.155 does not match.

For a host route, a mask of 0xFFFFFFFF is assumed. If a default route is added with the destination address as "0.0.0.0", an implicit netmask of 0x00000000 is assumed. The destination address for a default route entry is always "0.0.0.0". An implicit network mask of 0x00000000 is assumed for this route entry.

When searching2 the routing table for a destination address, the search algorithm first tries to match the complete host address. If the host address match is not found, the search tries to match the network address of the provided destination address. If a network address match is not found, the search returns the route entry of the default address (if any).

If the search of the routing table finds a matching entry which has a clone flag set, a new route entry is created (cloned) from the found entry. For example:

If:
The routing table on a VxWorks target contains a route to an Ethernet network interface whose IP address is 147.11.44.155.

And:
The subnet mask is 0xFFFFFF00.

And:
The RTF_CLONING (0x100) flag is set.

Then:
A search for 147.11.44.156 matches the 147.11.44.155 entry and creates a new route entry, a copy (clone) of the route entry for 147.11.44.155.

This new route entry for 147.11.44.156 is used by the link level address resolution protocol (ARP) to supply the corresponding Ethernet hardware address to the gateway address field. The route flags RTF_HOST (0x004) and RTF_LLINFO (0x400) are set to specify that it is host route and the gateway address is a link level address rather than a regular Internet address.

For information on configuring and adding routes to the routing table, see Adding a Route on VxWorks.

4.2.3   Network Byte Order

A single network can contain CPUs using different internal architectures. The numeric representation schemes of these architectures can differ: some use big-endian numbers, and some use little-endian numbers. To permit exchanging numeric data over a network, some overall convention is necessary. Network byte order is the convention that governs exchange of numeric data related to the network itself, such as socket addresses or shared-semaphore IDs. Numbers in network byte order are big-endian.

The routines in Table 4-2 convert longs and shorts between host and network byte order. To minimize overhead, macro implementations (which have no effect on architectures where no conversion is needed) are also available, in h/netinet/in.h.

Table 4-2:  Network Address Conversion Macros


Macro
 
Description
 

htonl
 
Convert a long from host to network byte ordering.
 
htons
 
Convert a short from host to network byte ordering.
 
ntohl
 
Convert a long from network to host byte ordering.
 
ntohs
 
Convert a short from network to host byte ordering.
 

To avoid macro-expansion side effects, do not apply these macros directly to an expression. The following increments pBuf four times (on little-endian architectures):

pBufHostLong = ntohl (*pBuf++);     /* UNSAFE */

It is safer to increment separately from the macro call. The following increments pBuf only once, whether the architecture is big- or little-endian:

pBufHostLong = ntohl (*pBuf); 
pBuf++; 

1:  Other declarations are possible, but struct in_addr is more forward compatible and less subject to a change in the size of the address.

2:  For more information about the routing table structure and the algorithms used to search the routing table, see TCP/IP Illustrated, Volume 2, by Gary R. Wright and W. Richard Stevens.