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

VxWorks

开发平台:

C/C++

  1. /* if_ether.h - network interface Ethernet header file */
  2. /* Copyright 1984 - 2002 Wind River Systems, Inc. */
  3. /*
  4.  * Copyright (c) 1982, 1986, 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.  * @(#)if_ether.h 8.1 (Berkeley) 6/10/93
  36.  */
  37. /*
  38. modification history
  39. --------------------
  40. 01h,24may02,vvv  replaced GNU_PACKED with _WRS_PACK_ALIGN
  41. 01g,23may02,vvv  added SH to GNU_PACKED list
  42. 01f,10oct01,rae  merge from truestack ver 01h base o1d
  43.                  SPRs 63006, 69112
  44. 01e,22jan01,scm  dealt with ARM alignment issue
  45. 01d,27may99,pul  added ether_tag_header and SIZEOF_TAG_ETHERHEADER
  46. 01c,29apr99,pul  Upgraded NPT phase3 code to tor2.0.0
  47. 01b,08Nov98,vin  changed the ordering of arguments to ipEtherResolveRtn 
  48. 01a,03mar96,vin  created from BSD4.4 stuff,integrated with 03l of if_ether.h
  49. */
  50. #ifndef __INCif_etherh
  51. #define __INCif_etherh
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. #include "netinet/in.h"
  56. #if ((CPU_FAMILY==I960) && (defined __GNUC__))
  57. #pragma align 1                 /* tell gcc960 not to optimize alignments */
  58. #endif /* CPU_FAMILY==I960 */
  59. #if ((defined __arm__) || (defined __sh__))
  60. #define ETHER_PACKED _WRS_PACK_ALIGN(1)
  61. #else
  62. #define ETHER_PACKED
  63. #endif
  64. /*
  65.  * Ethernet address - 6 octets
  66.  * this is only used by the ethers(3) functions.
  67.  */
  68. struct ether_addr {
  69. u_char ether_addr_octet[6];
  70. } ETHER_PACKED;
  71. /*
  72.  * Structure of a 10Mb/s Ethernet header.
  73.  */
  74. struct ether_header {
  75. u_char ether_dhost[6];
  76. u_char ether_shost[6];
  77. u_short ether_type;
  78. } ETHER_PACKED;
  79. /* Ether header for tagged frames */
  80. struct  ether_tag_header {
  81.         u_char  ether_dhost[6];
  82.         u_char  ether_shost[6];
  83.         u_char  etherTag[4];
  84.         u_short ether_type;
  85. };
  86. #define ETHERTYPE_PUP 0x0200 /* PUP protocol */
  87. #define ETHERTYPE_IP 0x0800 /* IP protocol */
  88. #define ETHERTYPE_ARP 0x0806 /* address resolution protocol */
  89. #define ETHERTYPE_REVARP 0x8035 /* reverse addr resolution protocol */
  90. /*
  91.  * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
  92.  * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
  93.  * by an ETHER type (as given above) and then the (variable-length) header.
  94.  */
  95. #define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */
  96. #define ETHERTYPE_NTRAILER 16
  97. #define ETHERMTU 1500
  98. #define ETHERMIN (60-14)
  99. /*
  100.  * for compilers that have 4-bytes structure alignment rule,
  101.  * it is understood that sizeof (ether_header) is 0x10
  102.  */
  103. #define SIZEOF_ETHERHEADER      0xe
  104. /* For tagged Ethernet headers */
  105. #define SIZEOF_TAG_ETHERHEADER      0x12
  106. /* minimal size of an ethernet frame including the headers supported
  107.  * by most ethernet chips.
  108.  */
  109. #define ETHERSMALL 60
  110. /*
  111.  * Macro to map an IP multicast address to an Ethernet multicast address.
  112.  * The high-order 25 bits of the Ethernet address are statically assigned,
  113.  * and the low-order 23 bits are taken from the low end of the IP address.
  114.  */
  115. #define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) 
  116. /* struct in_addr *ipaddr; */ 
  117. /* u_char enaddr[6];    */ 
  118. (enaddr)[0] = 0x01; 
  119. (enaddr)[1] = 0x00; 
  120. (enaddr)[2] = 0x5e; 
  121. (enaddr)[3] = ((u_char *)ipaddr)[1] & 0x7f; 
  122. (enaddr)[4] = ((u_char *)ipaddr)[2]; 
  123. (enaddr)[5] = ((u_char *)ipaddr)[3]; 
  124. }
  125. /*
  126.  * Macro to test whether the given ethernet address is multicast
  127.  */
  128.   #define ETHER_MULTICAST(enaddr) 
  129.       ((enaddr)[0] == 0x1) && ((enaddr)[1] == 0x0) && ((enaddr)[2] == 0x5e) 
  130. /*
  131.  * Ethernet Address Resolution Protocol.
  132.  *
  133.  * See RFC 826 for protocol description.  Structure below is adapted
  134.  * to resolving internet addresses.  Field names used correspond to 
  135.  * RFC 826.
  136.  */
  137. struct ether_arp {
  138. struct arphdr ea_hdr; /* fixed-size header */
  139. u_char arp_sha[6]; /* sender hardware address */
  140. u_char arp_spa[4]; /* sender protocol address */
  141. u_char arp_tha[6]; /* target hardware address */
  142. u_char arp_tpa[4]; /* target protocol address */
  143. } ETHER_PACKED;
  144. #define arp_hrd ea_hdr.ar_hrd
  145. #define arp_pro ea_hdr.ar_pro
  146. #define arp_hln ea_hdr.ar_hln
  147. #define arp_pln ea_hdr.ar_pln
  148. #define arp_op ea_hdr.ar_op
  149. /*
  150.  * Structure shared between the ethernet driver modules and
  151.  * the address resolution code.  For example, each ec_softc or il_softc
  152.  * begins with this structure.
  153.  */
  154. struct arpcom {
  155. struct  ifnet ac_if; /* network-visible interface */
  156. u_char ac_enaddr[6]; /* ethernet hardware address */
  157. struct in_addr ac_ipaddr; /* copy of ip address- XXX */
  158. struct ether_multi *ac_multiaddrs; /* list of ether multicast addrs */
  159. int ac_multicnt; /* length of ac_multiaddrs list */
  160. } ETHER_PACKED;
  161. /* XXX should be removed */
  162. /*
  163.  * Internet to ethernet address resolution table.
  164.  */
  165. struct arptab {
  166. struct in_addr at_iaddr; /* internet address */
  167. u_char at_enaddr[6]; /* ethernet address */
  168. u_char at_timer; /* minutes since last reference */
  169. u_char at_flags; /* flags */
  170. struct mbuf *at_hold; /* last packet until resolved/timeout */
  171. } ETHER_PACKED;
  172. struct llinfo_arp {
  173. struct llinfo_arp *la_next;
  174. struct llinfo_arp *la_prev;
  175. struct rtentry *la_rt;
  176. struct mbuf *la_hold; /* last packet until resolved/timeout */
  177. long la_asked; /* last time we QUERIED for this addr */
  178. #define la_timer la_rt->rt_rmx.rmx_expire /* deletion time in seconds */
  179. } ETHER_PACKED;
  180. struct sockaddr_inarp {
  181. u_char sin_len;
  182. u_char sin_family;
  183. u_short sin_port;
  184. struct in_addr sin_addr;
  185. struct in_addr sin_srcaddr;
  186. u_short sin_tos;
  187. u_short sin_other;
  188. #define SIN_PROXY 1
  189. } ETHER_PACKED;
  190. /*
  191.  * IP and ethernet specific routing flags
  192.  */
  193. #define RTF_USETRAILERS RTF_PROTO1 /* use trailers */
  194. #define RTF_ANNOUNCE RTF_PROTO2 /* announce new arp entry */
  195. /*
  196.  * Ethernet multicast address structure.  There is one of these for each
  197.  * multicast address or range of multicast addresses that we are supposed
  198.  * to listen to on a particular interface.  They are kept in a linked list,
  199.  * rooted in the interface's arpcom structure.  (This really has nothing to
  200.  * do with ARP, or with the Internet address family, but this appears to be
  201.  * the minimally-disrupting place to put it.)
  202.  */
  203. struct ether_multi {
  204. u_char enm_addrlo[6]; /* low  or only address of range */
  205. u_char enm_addrhi[6]; /* high or only address of range */
  206. struct arpcom *enm_ac; /* back pointer to arpcom */
  207. u_int enm_refcount; /* no. claims to this addr/range */
  208. struct ether_multi *enm_next; /* ptr to next ether_multi */
  209. } ETHER_PACKED;
  210. /*
  211.  * Structure used by macros below to remember position when stepping through
  212.  * all of the ether_multi records.
  213.  */
  214. struct ether_multistep {
  215. struct ether_multi  *e_enm;
  216. } ETHER_PACKED;
  217. #if ((CPU_FAMILY==I960) && (defined __GNUC__))
  218. #pragma align 0                 /* turn off alignment requirement */
  219. #endif /* CPU_FAMILY==I960 */
  220. /*
  221.  * Macro for looking up the ether_multi record for a given range of Ethernet
  222.  * multicast addresses connected to a given arpcom structure.  If no matching
  223.  * record is found, "enm" returns NULL.
  224.  */
  225. #define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) 
  226. /* u_char addrlo[6]; */ 
  227. /* u_char addrhi[6]; */ 
  228. /* struct arpcom *ac; */ 
  229. /* struct ether_multi *enm; */ 
  230. for ((enm) = (ac)->ac_multiaddrs; 
  231.     (enm) != NULL && 
  232.     (bcmp((char *)(enm)->enm_addrlo, (char *)(addrlo), 6) != 0 || 
  233.      bcmp((char *)(enm)->enm_addrhi, (char *)(addrhi), 6) != 0); 
  234. (enm) = (enm)->enm_next); 
  235. }
  236. /*
  237.  * Macro to step through all of the ether_multi records, one at a time.
  238.  * The current position is remembered in "step", which the caller must
  239.  * provide.  ETHER_FIRST_MULTI(), below, must be called to initialize "step"
  240.  * and get the first record.  Both macros return a NULL "enm" when there
  241.  * are no remaining records.
  242.  */
  243. #define ETHER_NEXT_MULTI(step, enm) 
  244. /* struct ether_multistep step; */  
  245. /* struct ether_multi *enm; */  
  246. if (((enm) = (step).e_enm) != NULL) 
  247. (step).e_enm = (enm)->enm_next; 
  248. }
  249. #define ETHER_FIRST_MULTI(step, ac, enm) 
  250. /* struct ether_multistep step; */ 
  251. /* struct arpcom *ac; */ 
  252. /* struct ether_multi *enm; */ 
  253. (step).e_enm = (ac)->ac_multiaddrs; 
  254. ETHER_NEXT_MULTI((step), (enm)); 
  255. }
  256. extern u_char  etherbroadcastaddr[6];
  257. extern u_char ether_ipmulticast_min[6];
  258. extern u_char ether_ipmulticast_max[6];
  259. extern struct ifqueue arpintrq;
  260. #ifndef VIRTUAL_STACK
  261. extern struct llinfo_arp llinfo_arp; /* head of the llinfo queue */
  262. #endif /* VIRTUAL_STACK */
  263. extern struct llinfo_arp *arptnew (struct in_addr *);
  264. extern void arpwhohas (struct arpcom *, struct in_addr *);
  265. #ifdef VIRTUAL_STACK
  266. extern void arpintr (int);
  267. #else
  268. extern void arpintr (void);
  269. #endif /* VIRTUAL_STACK */
  270. extern int arpresolve (struct arpcom *, struct rtentry *, struct mbuf *,
  271.      struct sockaddr *, u_char *);
  272. extern void arp_rtrequest (int, struct rtentry *, struct sockaddr *);
  273. extern void arpwhohas (struct arpcom *, struct in_addr *);
  274. extern void revarpinput(struct mbuf *m);
  275. extern void     ipToEtherMCastMap (struct in_addr *, u_char * );
  276. extern int      ipEtherResolvRtn (FUNCPTR, struct mbuf *, struct sockaddr *,  
  277.   struct ifnet *, struct rtentry *, char *);
  278. extern int ether_addmulti (struct ifreq *, struct arpcom *);
  279. extern int ether_delmulti (struct ifreq *, struct arpcom *);
  280. extern char *  ether_sprintf( u_char * ap);
  281. extern void db_print_sa(struct sockaddr* sa);
  282. #ifdef __cplusplus
  283. }
  284. #endif
  285. #endif /* __INCif_etherh */