📄 routelib.c
字号:
* constants as valid values: * * IPTOS_LOWDELAY* IPTOS_THROUGHPUT* IPTOS_RELIABILITY* IPTOS_MINCOST** Use <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.** EXAMPLE* To add a route to the 90.0.0.0 network through 91.0.0.3: * .CS* -> mRouteAdd ("90.0.0.0", "91.0.0.3", 0xffffff00, 0, 0);* .CE** 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:* .CS* -> mRouteAdd ("90.0.0.0", "91.0.0.3", 0xffffff00, 0, 0);* * -> mRouteAdd ("90.0.0.0", "91.0.0.254", 0xffff0000, 0, 0);* .CE* 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.** RETURNS: OK or ERROR.** SEE ALSO: mRouteEntryAdd(), mRouteDelete(), routeAdd()*/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 */ ) { long destIp; long gateIp; if (((destIp = (long) inet_addr (pDest)) == ERROR) || ((gateIp = (long) inet_addr (pGate)) == ERROR)) { return (ERROR); } mask = htonl (mask); return (mRouteEntryAdd (destIp, gateIp, mask, tos, flags, M2_ipRouteProto_other)); } /********************************************************************************* mPrivRouteEntryAdd - add a route to the routing table ** A route to the destination <pDest> with gateway <pGate>, destination mask* <mask>, and the type of service <tos> is added to the routing table. <flags>* specifies any flags associated with this entry. Valid values for <flags> * are 0, RTF_HOST and RTF_CLONING as defined in net/route.h. The <proto> * parameter identifies the protocol that generated this route. Values for * <proto> may be found in m2Lib.h and <tos> is one of following values defined * in netinet/ip.h:* * IPTOS_LOWDELAY* IPTOS_THROUGHPUT* IPTOS_RELIABILITY* IPTOS_MINCOST** This routine is the internal version of mRouteEntryAdd() and allows* you to get a ptr to the routing entry added, which is not available* with mRouteEntryAdd().** RETURNS: OK or ERROR.** NOMANUAL*/STATUS mPrivRouteEntryAdd ( 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 */ struct rtentry ** ppRtEntry /* for returning ptr to new entry added */ ) { struct sockaddr_in destSock; /* destination socket */ struct sockaddr_in gateSock; /* gateway socket */ struct sockaddr_in maskSock; /* destination mask socket */ if ((mask != 0) && (flags & RTF_HOST)) { return (ERROR); } bzero ((caddr_t) & destSock, sizeof (destSock)); bzero ((caddr_t) & gateSock, sizeof (gateSock)); bzero ((caddr_t) & maskSock, sizeof (maskSock)); destSock.sin_addr.s_addr = (mask != 0) ? (destIp & mask) : destIp; gateSock.sin_addr.s_addr = gateIp; destSock.sin_family = gateSock.sin_family = maskSock.sin_family = AF_INET; destSock.sin_len = gateSock.sin_len = maskSock.sin_len = sizeof (destSock); /* set gateway flag if not a direct route */ if (ifa_ifwithaddr ((struct sockaddr *) & gateSock) == NULL) flags |= RTF_GATEWAY; if (mask == 0xffffffff) flags |= RTF_GATEWAY; maskSock.sin_addr.s_addr = mask; TOS_SET (&maskSock, 0x1f); in_socktrim (&maskSock); TOS_SET (&destSock, tos); RT_PROTO_SET (&destSock, proto); /* * Add the static route using the default weight value. Report the * change using both routing socket messages and direct callbacks. */ return (rtrequestAddEqui ((struct sockaddr*) &destSock, (struct sockaddr*) &maskSock, (struct sockaddr*) &gateSock, flags, proto, 0, TRUE, TRUE, (ROUTE_ENTRY**)ppRtEntry)); }/********************************************************************************* mRouteEntryAdd - add a protocol-specific route to the routing table ** For a single destination <destIp>, this routine can add additional * routes <gateIp> to the routing table. The different routes are * distinguished by the gateway, 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** RETURNS: OK or ERROR.** SEE ALSO: m2Lib.h, mRouteAdd(), mRouteDelete()*/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 */ ) { return (mPrivRouteEntryAdd (destIp, gateIp, mask, tos, flags, proto, NULL)); }/********************************************************************************* mRouteEntryDelete - delete route from the routing table ** 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_MINCOST** An existing route is deleted only if it is owned by the protocol specified * by <proto>.** RETURNS: OK or ERROR.**/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 */ ) { struct sockaddr_in destSock; /* destination socket */ struct sockaddr_in gateSock; /* gateway socket */ struct sockaddr_in maskSock; /* destination mask socket */ if ((mask != 0) && (flags & RTF_HOST)) { return (ERROR); } bzero ((caddr_t) & destSock, sizeof (destSock)); bzero ((caddr_t) & gateSock, sizeof (gateSock)); bzero ((caddr_t) & maskSock, sizeof (maskSock)); destSock.sin_addr.s_addr = (mask != 0) ? (destIp & mask) : destIp; gateSock.sin_addr.s_addr = gateIp; destSock.sin_family = gateSock.sin_family = maskSock.sin_family = AF_INET; destSock.sin_len = gateSock.sin_len = maskSock.sin_len = sizeof (destSock); /* set gateway flag if not a direct route */ if (ifa_ifwithaddr ((struct sockaddr *) & gateSock) == NULL) flags |= RTF_GATEWAY; maskSock.sin_addr.s_addr = mask; TOS_SET (&maskSock, 0x1f); in_socktrim (&maskSock); if (mask == 0xffffffff) flags |= RTF_GATEWAY; TOS_SET (&destSock, tos); /* * Remove the matching route. Report the change using * both routing socket messages and direct callbacks. */ /* check required to support: mRouteDelete() with routing extensions */ if(gateIp==0) { return(rtrequestDelEqui((struct sockaddr*) &destSock, (struct sockaddr*) &maskSock, 0, flags, proto, TRUE, TRUE, NULL)); } else { return(rtrequestDelEqui((struct sockaddr*) &destSock, (struct sockaddr*) &maskSock, (struct sockaddr*) &gateSock, flags, proto, TRUE, TRUE, NULL)); } }/********************************************************************************* mPrivRouteEntryDelete - delete a held route from the routing table ** This routine deletes a protocol-specific route from the routing * table when mPrivRouteEntryAdd retained a copy of the new route* with the <pRoute> pointer. The routine calls rtfree to adjust the* reference count then passes the remaining arguments to the * mRouteEntryDelete routine to remove the route. ** RETURNS: OK or ERROR.** NOMANUAL*/STATUS mPrivRouteEntryDelete ( 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 */ struct rtentry * pRoute ) { int s; STATUS result; s = splnet (); if (pRoute) rtfree (pRoute); result = mRouteEntryDelete (destIp, gateIp, mask, tos, flags, proto); splx (s); return (result); }/********************************************************************************* mRouteDelete - delete a route from the routing table ** 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().** EXAMPLE* Consider the case of a route added in the following manner:* .CS* -> mRouteAdd ("90.0.0.0", "91.0.0.3", 0xffffff00, 0, 0);* .CE* To delete a route that was added in the above manner, call mRouteDelete()* as follows:* .CS* -> mRouteDelete("90.0.0.0", 0xffffff00, 0);* .CE** 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.** RETURNS: OK or ERROR. ** SEE ALSO: mRouteAdd()*/STATUS mRouteDelete ( char * pDest, /* destination address */ long mask, /* mask for destination */ int tos, /* type of service */ int flags /* either 0 or RTF_HOST */ ) { struct sockaddr_in destSock; /* destination socket */ struct sockaddr_in maskSock; /* destination mask socket */ if ((mask != 0) && (flags & RTF_HOST)) { return (ERROR); } bzero ((caddr_t) & destSock, sizeof (destSock)); bzero ((caddr_t) & maskSock, sizeof (maskSock)); if ((destSock.sin_addr.s_addr = (long) inet_addr (pDest)) == ERROR) { return (ERROR); } mask = htonl (mask); if (mask != 0) destSock.sin_addr.s_addr &= mask; destSock.sin_family = maskSock.sin_family = AF_INET; destSock.sin_len = maskSock.sin_len = sizeof (destSock); maskSock.sin_addr.s_addr = mask; TOS_SET (&maskSock, 0x1f); in_socktrim (&maskSock); TOS_SET (&destSock, tos); /* * Remove the matching route. Report the change using * both routing socket messages and direct callbacks. */ return(rtrequestDelEqui((struct sockaddr*) &destSock, (struct sockaddr*) &maskSock, NULL, flags, M2_ipRouteProto_other, TRUE, TRUE, NULL)); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -