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

VxWorks

开发平台:

C/C++

  1. /* common.h - DHCP server include file for shared data structures */
  2. /* Copyright 1984 - 2001 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01b,12dec01,wap  Interface name field of if_info structure is too small for
  7.                  some interface names (SPR #29087)
  8. 01a,09oct01,rae  merge from truestack ver 01h, base 01e, minor fixes
  9. 01e,14jul00,spm  upgraded to RFC 2131 and removed direct link-level access
  10. 01d,06oct97,spm  added support for dynamic driver type detection
  11. 01c,06aug97,spm  added definitions for C++ compilation
  12. 01b,06may97,spm  changed memory access to align IP header on four byte boundary
  13. 01a,07apr97,spm  created by modifying WIDE project DHCP implementation
  14. */
  15. /*
  16.  * WIDE Project DHCP Implementation
  17.  * Copyright (c) 1995 Akihiro Tominaga
  18.  * Copyright (c) 1995 WIDE Project
  19.  * All rights reserved.
  20.  *
  21.  * Permission to use, copy, modify and distribute this software and its
  22.  * documentation is hereby granted, provided only with the following
  23.  * conditions are satisfied:
  24.  *
  25.  * 1. Both the copyright notice and this permission notice appear in
  26.  *    all copies of the software, derivative works or modified versions,
  27.  *    and any portions thereof, and that both notices appear in
  28.  *    supporting documentation.
  29.  * 2. All advertising materials mentioning features or use of this software
  30.  *    must display the following acknowledgement:
  31.  *      This product includes software developed by WIDE Project and
  32.  *      its contributors.
  33.  * 3. Neither the name of WIDE Project nor the names of its contributors
  34.  *    may be used to endorse or promote products derived from this software
  35.  *    without specific prior written permission.
  36.  *
  37.  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND WIDE
  38.  * PROJECT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  39.  * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. ALSO, THERE
  40.  * IS NO WARRANTY IMPLIED OR OTHERWISE, NOR IS SUPPORT PROVIDED.
  41.  *
  42.  * Feedback of the results generated from any improvements or
  43.  * extensions made to this software would be much appreciated.
  44.  * Any such feedback should be sent to:
  45.  * 
  46.  *  Akihiro Tominaga
  47.  *  WIDE Project
  48.  *  Keio University, Endo 5322, Kanagawa, Japan
  49.  *  (E-mail: dhcp-dist@wide.ad.jp)
  50.  *
  51.  * WIDE project has the rights to redistribute these changes.
  52.  */
  53. #ifndef __INCcommonh
  54. #define __INCcommonh
  55. #ifdef __cplusplus
  56. extern "C" {
  57. #endif
  58. /* Resources sent to client outside of options field, if at all. */
  59. #define S_TABLE_CONT          0
  60. #define S_SNAME               1
  61. #define S_FILE                2
  62. #define S_SIADDR              3
  63. #define S_ALLOW_BOOTP         4
  64. #define S_IP_ADDR             5
  65. #define S_MAX_LEASE           6
  66. #define S_DEFAULT_LEASE       7
  67. #define S_CLIENT_ID           8
  68. #define S_PARAM_ID            9
  69. #define S_CLASS_ID           10
  70. /* Resources sent to client as RFC 1533 options. */
  71. #define S_SUBNET_MASK        11
  72. #define S_TIME_OFFSET        12
  73. #define S_ROUTER             13
  74. #define S_TIME_SERVER        14
  75. #define S_NAME_SERVER        15
  76. #define S_DNS_SERVER         16
  77. #define S_LOG_SERVER         17
  78. #define S_COOKIE_SERVER      18
  79. #define S_LPR_SERVER         19
  80. #define S_IMPRESS_SERVER     20
  81. #define S_RLS_SERVER         21
  82. #define S_HOSTNAME           22
  83. #define S_BOOTSIZE           23
  84. #define S_MERIT_DUMP         24
  85. #define S_DNS_DOMAIN         25
  86. #define S_SWAP_SERVER        26
  87. #define S_ROOT_PATH          27
  88. #define S_EXTENSIONS_PATH    28
  89. #define S_IP_FORWARD         29
  90. #define S_NONLOCAL_SRCROUTE  30
  91. #define S_POLICY_FILTER      31
  92. #define S_MAX_DGRAM_SIZE     32
  93. #define S_DEFAULT_IP_TTL     33
  94. #define S_MTU_AGING_TIMEOUT  34
  95. #define S_MTU_PLATEAU_TABLE  35
  96. #define S_IF_MTU             36
  97. #define S_ALL_SUBNET_LOCAL   37
  98. #define S_BRDCAST_ADDR       38
  99. #define S_MASK_DISCOVER      39
  100. #define S_MASK_SUPPLIER      40
  101. #define S_ROUTER_DISCOVER    41
  102. #define S_ROUTER_SOLICIT     42
  103. #define S_STATIC_ROUTE       43
  104. #define S_TRAILER            44
  105. #define S_ARP_CACHE_TIMEOUT  45
  106. #define S_ETHER_ENCAP        46
  107. #define S_DEFAULT_TCP_TTL    47
  108. #define S_KEEPALIVE_INTER    48
  109. #define S_KEEPALIVE_GARBA    49
  110. #define S_NIS_DOMAIN         50
  111. #define S_NIS_SERVER         51
  112. #define S_NTP_SERVER         52
  113. #define S_NBN_SERVER         53
  114. #define S_NBDD_SERVER        54
  115. #define S_NB_NODETYPE        55
  116. #define S_NB_SCOPE           56
  117. #define S_XFONT_SERVER       57
  118. #define S_XDISPLAY_MANAGER   58
  119. #define S_DHCP_T1            59
  120. #define S_DHCP_T2            60
  121. #define S_NISP_DOMAIN        61
  122. #define S_NISP_SERVER        62
  123. #define S_MOBILEIP_HA        63
  124. #define S_SMTP_SERVER        64
  125. #define S_POP3_SERVER        65
  126. #define S_NNTP_SERVER        66
  127. #define S_DFLT_WWW_SERVER    67
  128. #define S_DFLT_FINGER_SERVER 68
  129. #define S_DFLT_IRC_SERVER    69
  130. #define S_STREETTALK_SERVER  70
  131. #define S_STDA_SERVER        71
  132. #define S_LAST_OPTION        S_STDA_SERVER
  133. #define VALIDSIZE   ((S_LAST_OPTION / 8) + 1)
  134. /* Set length for entry names. Leave space to append unique value. */
  135. #define BASE_NAME  8   /* length for user-provided name, excluding '' */
  136. #define MAX_NAME  BASE_NAME + 2 * sizeof (u_long)
  137. #include <netinet/udp.h>
  138. #include <netinet/ip.h>
  139. #include <netinet/if_ether.h>
  140. #define DHCPS_OFF 2      /* 4-byte alignment offset needed by Sun BSP's */
  141. #define ETHERHL  sizeof(struct ether_header)  /* ethernet header length */
  142. #define IPHL     sizeof(struct ip)            /* IP header length */
  143. #define UDPHL    sizeof(struct udphdr)        /* UDP header length */
  144. #define WORD     4                            /* word alignment in bits */
  145. #if CPU_FAMILY==I960
  146. #pragma align 1                 /* tell gcc960 not to optimize alignments */
  147. #endif  /* CPU_FAMILY==I960 */
  148. struct msg
  149. {
  150.   struct ether_header *ether;
  151.   struct ip *ip;
  152.   struct udphdr *udp;
  153.   struct dhcp *dhcp;
  154. };
  155. struct if_info {
  156.   int fd;
  157.   char name[IFNAMSIZ];
  158.   short unit;
  159.   int bpfDev;   /* File descriptor for Berkeley Packet Filter */
  160.   int mtuSize;
  161.   unsigned int htype;
  162.   unsigned char hlen;
  163.   char haddr[6];
  164.   struct in_addr ipaddr;
  165.   struct in_addr subnetmask;
  166.   int buf_size;
  167.   char *buf;
  168.   struct if_info *next;              /* Next entry in null terminated list. */
  169. };
  170. struct relay_acl {
  171.   struct in_addr relay,
  172.                  subnet_mask;
  173. };
  174. struct client_id {
  175.   unsigned char   idtype,
  176.                   idlen;
  177.   char            id [MAXOPT];
  178.   struct in_addr  subnet;
  179. };
  180. struct u_shorts {
  181.   int num;
  182.   unsigned short *shorts;
  183. };
  184. struct in_addrs {
  185.   int num;
  186.   struct in_addr *addr;
  187. };
  188. struct ip_pairs {
  189.   int num;
  190.   struct in_addr *addr1,
  191.                  *addr2;
  192. };
  193. struct chaddr {
  194.   unsigned char  htype,
  195.                  hlen;
  196.   char           haddr [MAX_HLEN];
  197. };
  198. struct dhcp_binding {
  199.   /* external info */
  200.   struct client_id           cid;           /* hashing key. client identifier */
  201.   struct chaddr              haddr;
  202.   time_t                     expire_epoch;  /* lease expiration epoch */
  203.   char                       res_name [MAX_NAME + 1]; /* name of resource */
  204.   /* internal info */
  205.   char                       flag;
  206. #define COMPLETE_ENTRY       0x1         /* complete entry */
  207. #define STATIC_ENTRY         0x2         /* static entry */
  208. #define BOOTP_ENTRY          0x4         /* bootp entry */
  209.   time_t                     temp_epoch;        /* memo expiration epoch */
  210.   struct dhcp_resource       *res;              /* pointer to resource */
  211. };
  212. struct dhcp_resource {
  213.   /* external info */
  214.   char                      allow_bootp,         /* boolean */
  215.                             ip_forward,          /* boolean */
  216.                             nonlocal_srcroute,   /* boolean */
  217.                             all_subnet_local,    /* boolean */
  218.                             mask_discover,       /* boolean */
  219.                             mask_supplier,       /* boolean */
  220.                             router_discover,     /* boolean */
  221.                             trailer,             /* boolean */
  222.                             ether_encap,         /* boolean */
  223.                             keepalive_garba,     /* boolean */
  224.                             entryname [MAX_NAME + 1],  /* tag name of entry */
  225.                             sname [MAX_SNAME + 1], /* server host name */
  226.                             file [MAX_FILE + 1], /* boot file name */
  227.                             hostname [MAXOPT + 1],
  228.                             merit_dump [MAXOPT + 1],
  229.                             dns_domain [MAXOPT + 1],
  230.                             root_path [MAXOPT + 1],
  231.                             extensions_path [MAXOPT + 1],
  232.                             nis_domain [MAXOPT + 1],
  233.                             nb_scope [MAXOPT + 1], /* NetBIOS scope */
  234.                             nisp_domain [MAXOPT + 1]; /* NIS+ domain name */
  235.   unsigned char             default_ip_ttl,       /* time to live (1 - 255) */
  236.                             default_tcp_ttl,
  237.                             nb_nodetype;         /* NetBIOS node type */
  238. #define BNODE   0x1
  239. #define PNODE   0x2
  240. #define MNODE   0x4
  241. #define HNODE   0x8
  242.   unsigned short            bootsize,            /* bootfile size in 16 bits */
  243.                             max_dgram_size,      /* max dgram reassembly */
  244.                             intf_mtu,            /* interface mtu */
  245.                             dhcp_t1,             /* host byte order */
  246.                             dhcp_t2;             /* host byte order */
  247.   long                      time_offset;         /* offset from UTC */
  248.   unsigned long             max_lease,           /* maximum lease duration
  249.     (host byte order) */
  250.                             default_lease,       /* default lease duration
  251.     (host byte order) */
  252.                             mtu_aging_timeout,   /* unsigned 32 bits integer */
  253.                             arp_cache_timeout,
  254.                             keepalive_inter;
  255.   struct u_shorts           mtu_plateau_table;   /* array of 16 bit ints */
  256.   struct in_addr            siaddr,              /* (tftp) server */
  257.                             ip_addr,             /* IP address */
  258.                             subnet_mask,
  259.                             swap_server,
  260.                             brdcast_addr,
  261.                             router_solicit;
  262.   struct in_addrs           router,
  263.                             time_server,
  264.                             name_server,
  265.                             dns_server,       /* DNS server */
  266.                             log_server,
  267.                             cookie_server,
  268.                             lpr_server,
  269.                             impress_server,
  270.                             rls_server,       /* Resource Location Server */
  271.                             nis_server,
  272.                             ntp_server,
  273.                             nbn_server,         /* NetBIOS name server */
  274.                             nbdd_server,     /* NetBIOS dgram distrib server */
  275.                             xfont_server,       /* X font erver */
  276.                             xdisplay_manager,   /* X display manager */
  277.                             nisp_server,        /* NIS+ server */
  278.                             mobileip_ha,        /* Mobile IP Home Agent */
  279.                             smtp_server,        /* SMTP server */
  280.                             pop3_server,        /* POP3 server */
  281.                             nntp_server,        /* NNTP server */
  282.                             dflt_www_server,    /* Default WWW server */
  283.                             dflt_finger_server, /* Default Finger server */
  284.                             dflt_irc_server,    /* Default IRC server */
  285.                             streettalk_server,  /* StreetTalk server */
  286.                             stda_server;        /* STDA server */
  287.   struct ip_pairs           policy_filter,   
  288.                             static_route;
  289.   /* internal info */
  290.   char                      valid[VALIDSIZE],  /* indicate which are available */
  291.                             active[VALIDSIZE]; /* indicate which differ from
  292.   Host Requirements RFC */
  293.   struct dhcp_binding       *binding;            /* pointer to identifier
  294.                                                   * associated with resource. 
  295.                                                   */
  296. };
  297. #if CPU_FAMILY==I960
  298. #pragma align 0                 /* turn off alignment requirement */
  299. #endif  /* CPU_FAMILY==I960 */
  300. #ifndef TRUE
  301. #define TRUE   1
  302. #endif
  303. #ifndef FALSE
  304. #define FALSE  0
  305. #endif
  306. #ifndef GOOD
  307. #define GOOD   1
  308. #endif
  309. #ifndef BAD
  310. #define BAD    0
  311. #endif
  312. #ifndef ADDRPOOL_DUMP
  313. #define ADDRPOOL_DUMP           "/tmp/addrpool_dump"
  314. #endif
  315. #define MAX_NBIND       500   /* maximum number of dhcp_binding
  316.  ( this is used in garbage_collect(); ) */
  317. #define MAXPATHLEN 64       /* Maximum length of database names. */
  318. #ifndef VIRTUAL_STACK
  319. extern int nbind;
  320. #endif /* VIRTUAL_STACK */
  321. #ifndef sun
  322. extern struct bpf_hdr *rbpf;        /* pointer to bpf header */
  323. #endif
  324. /* extern struct msg rcv; */
  325. int     add_bind();
  326. STATUS  read_bind_db (void);
  327. STATUS  read_addrpool_db (int);
  328. void    read_relay_db (int);
  329. void    dump_bind_db();
  330. void    finish();
  331. char    *haddrtos();
  332. char    *cidtos();
  333. char    *_ctime();
  334. #ifdef __cplusplus
  335. }
  336. #endif
  337. #endif