VxWorks Reference Manual : Libraries
routeLib - network route manipulation library
routeAdd( ) - add a route
routeNetAdd( ) - add a route to a destination that is a network
routeDelete( ) - delete a route
mRouteAdd( ) - add multiple routes to the same destination
mRouteEntryAdd( ) - add a protocol-specific route to the routing table
mRouteEntryDelete( ) - delete route from the routing table
mRouteDelete( ) - delete a route from the routing table
routeProtoPrioritySet( ) - set the priority of routes added by the routing protocol
This library contains the routines for inspecting the routing table, as well as routines for adding and deleting routes from that table. If you do not configure VxWorks to include a routing protocol, such as RIP or OSPF, you can use these routines to maintain the routing tables manually.
routeLib.h
routeLib, hostLib, Network Programmer's Guide
routeAdd( ) - add a route
STATUS routeAdd ( char * destination, /* inet addr or name of route destination */ char * gateway /* inet addr or name of gateway to destination */ )
This routine adds gateways to the network routing tables. It is called from a VxWorks machine that needs to establish a gateway to a destination network (or machine).
You can specify both destination and gateway in standard Internet address format (for example, 90.0.0.2), or you can specify them using their host names, as specified with hostAdd( ).
Consider the following example:
-> routeAdd "90.0.0.0", "gate"This call tells VxWorks that the machine with the host name "gate" is the gateway to network 90.0.0.0. The host "gate" must already have been created by hostAdd( ).Consider the following example:
-> routeAdd "90.0.0.0", "91.0.0.3"This call tells VxWorks that the machine with the Internet address 91.0.0.3 is the gateway to network 90.0.0.0.Consider the following example:
-> routeAdd "destination", "gate"This call tells VxWorks that the machine with the host name "gate" is the gateway to the machine named "destination". The host names "gate" and "destination" must already have been created by hostAdd( ).Consider the following example:
-> routeAdd "0", "gate"This call tells VxWorks that the machine with the host name "gate" is the default gateway. The host "gate" must already have been created by hostAdd( ). A default gateway is where Internet Protocol (IP) datagrams are routed when there is no specific routing table entry available for the destination IP network or host.
OK or ERROR.
routeNetAdd( ) - add a route to a destination that is a network
STATUS routeNetAdd ( char * destination, /* inet addr or name of network destination */ char * gateway /* inet addr or name of gateway to destination */ )
This routine is equivalent to 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 overall network as the local network.
OK or ERROR.
routeDelete( ) - delete a route
STATUS routeDelete ( char * destination, /* inet addr or name of route destination */ char * gateway /* inet addr or name of gateway to destination */ )
This routine deletes a specified route from the network routing tables.
OK or ERROR.
mRouteAdd( ) - add multiple routes to the same destination
STATUS mRouteAdd ( char * pDest, /* destination addr in internet dot notation */ char * pGate, /* gateway address in internet dot notation */ long mask, /* mask for destination */ int tos, /* type of service */ int flags /* route flags */ )
This routine is similar to routeAdd( ), except that you can use multiple mRouteAdd( ) calls to add multiple routes to the same location. Use pDest to specify the destination, pGate to specify the gateway to that destination, mask to specify destination mask, and tos to specify the type of service. For tos, netinet/ip.h defines the following constants as valid values:
IPTOS_LOWDELAY
IPTOS_THROUGHPUT
IPTOS_RELIABILITY
IPTOS_MINCOSTUse flags to specify any flags you want to associate with this entry. The valid non-zero values are RTF_HOST and RTF_CLONING defined in net/route.h.
To add a route to the 90.0.0.0 network through 91.0.0.3:
-> mRouteAdd ("90.0.0.0", "91.0.0.3", 0xffffff00, 0, 0);Using mRouteAdd( ), you could create multiple routes to the same destination. VxWorks would distinguish among these routes based on factors such as the netmask or the type of service. Thus, it is perfectly legal to say:-> mRouteAdd ("90.0.0.0", "91.0.0.3", 0xffffff00, 0, 0); -> mRouteAdd ("90.0.0.0", "91.0.0.254", 0xffff0000, 0, 0);This adds two routes to the same network, "90.0.0.0", that go by two different gateways. The differentiating factor is the netmask.This routine adds a route of type M2_ipRouteProto_other, which is a static route. This route will not be modified or deleted until a call to mRouteDelete( ) removes it.
OK or ERROR.
routeLib, mRouteEntryAdd( ), mRouteDelete( ), routeAdd( )
mRouteEntryAdd( ) - add a protocol-specific route to the routing table
STATUS mRouteEntryAdd ( long destIp, /* destination address, network order */ long gateIp, /* gateway address, network order */ long mask, /* mask for destination, network order */ int tos, /* type of service */ int flags, /* route flags */ int proto /* routing protocol */ )
For a single destination destIp, this routine can add additional routes gateIp to the routing table. The different routes are distinguished by a destination mask mask, the type of service tos, and associated flag values flags. Valid values for flags are 0, RTF_HOST, RTF_CLONING (defined in net/route.h). The proto parameter identifies the protocol that generated this route. Values for proto may be found in m2Lib.h. The tos parameter takes one of following values (defined in netinet/ip.h):
IPTOS_LOWDELAY
IPTOS_THROUGHPUT
IPTOS_RELIABILITY
IPTOS_MINCOST
OK or ERROR.
routeLib, m2Lib.h, mRouteAdd( ), mRouteDelete( )
mRouteEntryDelete( ) - delete route from the routing table
STATUS mRouteEntryDelete ( long destIp, /* destination address, network order */ long gateIp, /* gateway address, network order */ long mask, /* mask for destination, network order */ int tos, /* type of service */ int flags, /* route flags */ int proto /* routing protocol */ )
This routine deletes a protocol-specific route from the routing table. Specify the route using a destination pDest, a gateway pGate, a destination mask mask, the type of service tos, a flags value, and a proto value that identifies the routing protocol that added the route. The valid values for flags are 0 and RTF_HOST (defined in net/route.h). Values for proto may be found in m2Lib.h and tos is one of the following values defined in netinet/ip.h:
IPTOS_LOWDELA
IPTOS_THROUGHPU
IPTOS_RELIABILIT
IPTOS_MINCOSTAn existing route is deleted only if it is owned by the protocol specified by proto.
OK or ERROR.
mRouteDelete( ) - delete a route from the routing table
STATUS mRouteDelete ( char * pDest, /* destination address */ long mask, /* mask for destination */ int tos, /* type of service */ int flags /* either 0 or RTF_HOST */ )
This routine deletes a routing table entry as specified by the destination, pDest, the destination mask, mask, and type of service, tos. The tos values are as defined in the reference entry for mRouteAdd( ).
Consider the case of a route added in the following manner:
-> mRouteAdd ("90.0.0.0", "91.0.0.3", 0xffffff00, 0, 0);To delete a route that was added in the above manner, call mRouteDelete( ) as follows:-> mRouteDelete("90.0.0.0", 0xffffff00, 0);If the netmask and or type of service do not match, the route is not deleted.The value of flags should be RTF_HOST for host routes, RTF_CLONING for routes which need to be cloned, and 0 in all other cases.
OK or ERROR.
routeProtoPrioritySet( ) - set the priority of routes added by the routing protocol
STATUS routeProtoPrioritySet ( int proto, /* protocol no, from m2Lib.h */ int prio /* priority, >= 0 , <= 200 */ )
This routine assigns a priority to a routing protocol. A route generated by the proto protocol is added to the routing table only if a protocol of higher priority does not already have that route installed in the table. Use proto to identify the protocol. See m2Lib.h for a listing of valid values for proto. Use prio to specify the priority level you want to assign to proto. The prio parameter may be any integer value greater or equal to 0 and less than or equal to 200. The higher values indicate higher priority. If you do not want VxWorks to prioritize protocols, do not call this routine.
Routes that are added with the routeAdd( ) or mRouteAdd( ) call are of type M2_ipRouteProto_other. These are static routes that are not affected by routing protocols such as RIP and OSPF. To change the priority of routes added in this way pass the value M2_ipRoute_Proto_other in the first argument of this routine.
OK if priority set successfully else ERROR.