defs.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:9k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* defs.h - common definitions for routed/rip */
  2. /* Copyright 1984 - 2002 Wind River Systems, Inc. */
  3. /*
  4.  * Copyright (c) 1983, 1988, 1993
  5.  * The Regents of the University of California.  All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in the
  14.  *    documentation and/or other materials provided with the distribution.
  15.  * 3. All advertising materials mentioning features or use of this software
  16.  *    must display the following acknowledgement:
  17.  * This product includes software developed by the University of
  18.  * California, Berkeley and its contributors.
  19.  * 4. Neither the name of the University nor the names of its contributors
  20.  *    may be used to endorse or promote products derived from this software
  21.  *    without specific prior written permission.
  22.  *
  23.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  24.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33.  * SUCH DAMAGE.
  34.  *
  35.  * @(#)defs.h 8.2 (Berkeley) 4/28/95
  36.  */
  37. /*
  38. modification history
  39. --------------------
  40. 01n,28apr02,rae  added extern C jazz (SPR #76303)
  41. 01m,22mar02,niq  Merged from Synth view, tor3_x.synth branch, ver 01o
  42. 01l,24jan02,niq  SPR 72415 - Added support for Route tags
  43. 01k,12oct01,rae  merge from truestack ver 01l, base 01j
  44. 01j,16mar99,spm  recovered orphaned code from tor1_0_1.sens1_1 (SPR #25770)
  45. 01i,05oct98,spm  made task parameters adjustable (SPR #22422)
  46. 01h,11sep98,spm  added support for expanded ripShutdown routine and provided 
  47.                  broader access to mutual exclusion semaphore to prevent 
  48.                  collisions between RIP tasks (SPR #22352); removed references
  49.                  to bloated trace commands (SPR #22350); corrected value
  50.                  of MIN_WAITTIME (SPR #22360)
  51. 01g,26jun98,spm  changed prototypes to remove compiler warnings; added 
  52.                  prototype for ripClearInterfaces; changed RIP_MCAST_ADDR
  53.                  constant from string to value
  54. 01f,06oct97,gnn  added function prototypes and removed ripState
  55. 01e,17apr97,gnn  changed the MIB-II variables to follow coding conventions.
  56. 01d,07apr97,gnn  cleared up some of the more egregious warnings.
  57.                  added MIB-II interfaces and options.
  58. 01c,12mar97,gnn  added multicast support
  59.                  added timer variables
  60. 01b,24feb97,gnn  changed some variable names, added some fields to global
  61.                  structure
  62.                  changed location of netdb.h
  63. 01a,26nov96,gnn  created from BSD4.4 routed
  64. */
  65. #ifndef __INCdefsh
  66. #define __INCdefsh
  67. #ifdef __cplusplus
  68. extern "C" {
  69. #endif
  70. /*
  71.  * Internal data structure definitions for
  72.  * user routing process.  Based on Xerox NS
  73.  * protocol specs with mods relevant to more
  74.  * general addressing scheme.
  75.  */
  76. #include "sys/socket.h"
  77. #include "time.h"
  78. #include "net/route.h"
  79. #include "net/af.h"
  80. #include "netinet/in.h"
  81. #include "rip/ripLib.h"
  82. #include "stdio.h"
  83. #include "rip/interface.h"
  84. #include "rip/table.h"
  85. #include "rip/rip2.h"
  86. #include "rip/m2RipLib.h"
  87. #include "wdLib.h"
  88. #include "semLib.h"
  89. #include "netdb.h"
  90. #define equal(a1, a2) 
  91. (memcmp((a1), (a2), sizeof (struct sockaddr)) == 0)
  92. #if ((CPU_FAMILY==I960) && (defined __GNUC__))
  93. #pragma align 1                 /* tell gcc960 not to optimize alignments */
  94. #endif  /* CPU_FAMILY==I960 */
  95. #define S_ADDR(x)       (((struct sockaddr_in *)(x))->sin_addr.s_addr)
  96. #define INFO_DST(I)     ((I)->rti_info[RTAX_DST])
  97. #define INFO_GATE(I)    ((I)->rti_info[RTAX_GATEWAY])
  98. #define INFO_MASK(I)    ((I)->rti_info[RTAX_NETMASK])
  99. #define INFO_IFA(I)     ((I)->rti_info[RTAX_IFA])
  100. #define INFO_IFP(I)     ((I)->rti_info[RTAX_IFP])
  101. #define INFO_AUTHOR(I)  ((I)->rti_info[RTAX_AUTHOR])
  102. #define INFO_BRD(I)     ((I)->rti_info[RTAX_BRD])
  103.   
  104. /* Needed for compatability */
  105. /* XXX */
  106. struct osockaddr {
  107.         u_short sa_family;              /* address family */
  108.         char    sa_data[14];            /* up to 14 bytes of direct address */
  109. }; 
  110. /*
  111.  * This global structure holds what used to be all the global 
  112.  * variables in the rip program.
  113.  */
  114. typedef struct rip_globals
  115.     {
  116.     int version;                /* What RIP version are we running? */
  117.     struct sockaddr_in addr; /* address of daemon's socket */
  118.     
  119.     int s; /* source and sink of all data */
  120.     int routeSocket; /* source for routing messages */
  121.     int ripTaskId;  /* Identifier for primary RIP task. */
  122.     int ripTimerTaskId;  /* Identifier for RIP timer task. */
  123.     int supplier; /* process should supply updates */
  124.     BOOL lookforinterfaces; /* if 1 probe kernel for new up interfaces */
  125.     int externalinterfaces; /* # of remote and local interfaces */
  126.     int gateway;                /* Are we a gateway? */
  127.     BOOL multicast;             /* Are we using multicast? */
  128.     struct timeval now; /* current idea of time */
  129.     struct      timeval then;           /* previous idea of time */
  130.     struct timeval lastbcast; /* last time all/changes broadcast */
  131.     struct timeval lastfullupdate;/* last time full table broadcast */
  132.     struct timeval nextbcast;     /* time to wait before changes */
  133.                                         /* broadcast */
  134.     int needupdate; /* true if we need update at nextbcast */
  135.     
  136.     int timerRate;          /* How often does the timer go off */
  137.     int supplyInterval;     /* How often do we supply routes? */
  138.     int expire;             /* HOw long until we expire a route? */
  139.     int garbage;            /* When is a route really thrown out? */
  140.     char packet[MAXPACKETSIZE+1];
  141.     struct rip_pkt *msg;
  142.     
  143.     int         port;
  144.     int         faketime;       /* Used by the timer routine to keep track. */
  145.     WDOG_ID     timerDog;       /* Watch dog for firing off the timer. */
  146.     SEM_ID      timerSem;       /* Semaphore that our user level routine */
  147.                                 /* waits on to do timer processing. */
  148.     FUNCPTR  pRouteHook;    /* Route propagation hook */
  149.     /*
  150.      * Variables to store MIB-II data.
  151.      */
  152.     M2_RIP2_GLOBAL_GROUP ripGlobal;
  153.     /*
  154.      * The ripConf element contains configuration settings
  155.      * copied for all available interfaces during initialization.
  156.      * Because the configuration may be changed on an interface-specific 
  157.      * basis, this structure should not be consulted for the
  158.      * actual values after routedIfInit() has been called.
  159.      */
  160.     
  161.     M2_RIP2_IFCONF_ENTRY ripConf;
  162.     } RIP;
  163. #if ((CPU_FAMILY==I960) && (defined __GNUC__))
  164. #pragma align 0                 /* turn off alignment requirement */
  165. #endif  /* CPU_FAMILY==I960 */
  166. IMPORT SEM_ID ripLockSem;
  167. /* This is the global structure used by the routing daemon. */
  168. struct in_addr inet_makeaddr();
  169. int inet_maskof();
  170. int  sndmsg();
  171. STATUS supply();
  172. int cleanup();
  173. int rtioctl();
  174. struct rt_entry * rtadd(struct sockaddr *dst, struct sockaddr *gate, int metric, 
  175. int state, struct sockaddr *netmask, int proto, int tag,
  176. int from, struct interface *ifp);
  177. STATUS rtchange(struct rt_entry *rt, struct sockaddr *gate, short metric,
  178.                 struct sockaddr *netmask, int tag, int from, 
  179. struct interface *ifp);
  180. STATUS rtdelete(struct rt_entry *rt);
  181. void toall (int (*)(), int, struct interface *);
  182. void ripRouteToAddrs (struct rt_entry* pRoute,
  183.                       struct sockaddr_in** ppDsin,
  184.                       struct sockaddr_in** ppGsin,
  185.                       struct sockaddr_in** ppNsin);
  186. void ifRouteAdd (struct sockaddr * pAddr, int refCnt, int subnetsCnt, 
  187.  BOOL internalFlag, u_long subnetMask);
  188. void ripBuildPacket (RIP2PKT *, struct rt_entry*, struct interface *, int);
  189. void ripSetInterfaces(INT32 sock, UINT32 mcastAddr);
  190. void ripClearInterfaces(INT32 sock, UINT32 mcastAddr);
  191. /* Defines created in the port to VxWorks. */
  192. #define RIP_PORT 520
  193. #define NSEC_MAX 1000000000
  194. #define RIP_TASK "tRipTask"
  195. #define RIP_TIMER "tRipTimerTask"
  196. #define RIP_MAX_PACKET 512                   /* The maximum packet size. */
  197. #define RIP_MIN_PACKET 24                    /* A packet with 1 entry. */
  198. #define RIP_MCAST_ADDR 0xe0000009  /* RIP group address is 224.0.0.9 */
  199. #ifdef __cplusplus
  200. }
  201. #endif
  202. #endif /* __INCdefsh */