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

VxWorks

开发平台:

C/C++

  1. /* if.h - network interface header file */
  2. /* Copyright 1984 - 2001 Wind River Systems, Inc. */
  3. /*
  4.  * Copyright (c) 1982, 1986, 1989, 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.h 8.1 (Berkeley) 6/10/93
  36.  */
  37. /*
  38. modification history
  39. --------------------
  40. 01m,10oct01,rae  merge from truestack ver 01o, base 01j (SPR #69683)
  41. 01l,17oct00,spm  merged from version 01k of tor2_0_x branch (base version 01j):
  42.                  updated if_attach to report memory allocation failures
  43. 01k,29apr99,pul  Upgraded NPT phase3 code to tor2.0.0
  44. 01j,17mar99,spm  added support for identical unit numbers (SPR #20913)
  45. 01i,12dec97,gnn  removed a lingering reference to IFF_SCAT.
  46. 01h,11dec97,gnn  removed IFF_SCAT and IFF_LOAN.
  47. 01g,05oct97,vin  added field in ifnet for holding multicast addrs
  48. 01f,01jul97,vin  removed some double declarations.
  49. 01e,24feb97,bjl  moved struct ifqueue declaration outside of struct ifnet
  50.  to make struct ifqueue globally visible for c++ 
  51. 01d,31jan97,vin  added prototypes for functions in ifnet ().
  52. 01c,21jan97,gnn  added IFF_SCAT for scatter/gather capable drivers.
  53. 01b,27aug96,gnn  added IFF_LOAN for buffer loaning drivers, added ifmreq
  54.  structure to we can retrieve multicast tables
  55. 01a,03mar96,vin  created from BSD4.4 stuff,integrated with 02q of if.h.
  56. */
  57. #ifndef __INCifh
  58. #define __INCifh
  59. #ifdef __cplusplus
  60. extern "C" {
  61. #endif
  62. #include "vxWorks.h"
  63. #include "sys/socket.h"
  64. #include "net/if_arp.h"
  65. #include "net/route.h"
  66. #include "ifLib.h"
  67. #if ((CPU_FAMILY==I960) && (defined __GNUC__))
  68. #pragma align 1                 /* tell gcc960 not to optimize alignments */
  69. #endif /* CPU_FAMILY==I960 */
  70. /*
  71.  * Structures defining a network interface, providing a packet
  72.  * transport mechanism (ala level 0 of the PUP protocols).
  73.  *
  74.  * Each interface accepts output datagrams of a specified maximum
  75.  * length, and provides higher level routines with input datagrams
  76.  * received from its medium.
  77.  *
  78.  * Output occurs when the routine if_output is called, with three parameters:
  79.  * (*ifp->if_output)(ifp, m, dst)
  80.  * Here m is the mbuf chain to be sent and dst is the destination address.
  81.  * The output routine encapsulates the supplied datagram if necessary,
  82.  * and then transmits it on its medium.
  83.  *
  84.  * On input, each interface unwraps the data received by it, and either
  85.  * places it on the input queue of a internetwork datagram routine
  86.  * and posts the associated software interrupt, or passes the datagram to a raw
  87.  * packet input routine.
  88.  *
  89.  * Routines exist for locating interfaces by their addresses
  90.  * or for locating a interface on a certain network, as well as more general
  91.  * routing and gateway routines maintaining information used to locate
  92.  * interfaces.  These routines live in the files if.c and route.c
  93.  */
  94. struct ifqueue {
  95. struct mbuf *ifq_head;
  96. struct mbuf *ifq_tail;
  97. int ifq_len;
  98. int ifq_maxlen;
  99. int ifq_drops;
  100. };
  101. struct mbuf;
  102. struct proc;
  103. struct rtentry;
  104. struct socket;
  105. struct ether_header;
  106. /*
  107.  * Structure defining statistics and other data kept regarding a network
  108.  * interface.
  109.  */
  110. struct if_data {
  111. /* generic interface information */
  112. u_char ifi_type; /* ethernet, tokenring, etc. */
  113. u_char ifi_addrlen; /* media address length */
  114. u_char ifi_hdrlen; /* media header length */
  115. u_long ifi_mtu; /* maximum transmission unit */
  116. u_long ifi_metric; /* routing metric (external only) */
  117. u_long ifi_baudrate; /* linespeed */
  118. /* volatile statistics */
  119. u_long ifi_ipackets; /* packets received on interface */
  120. u_long ifi_ierrors; /* input errors on interface */
  121. u_long ifi_opackets; /* packets sent on interface */
  122. u_long ifi_oerrors; /* output errors on interface */
  123. u_long ifi_collisions; /* collisions on csma interfaces */
  124. u_long ifi_ibytes; /* total number of octets received */
  125. u_long ifi_obytes; /* total number of octets sent */
  126. u_long ifi_imcasts; /* packets received via multicast */
  127. u_long ifi_omcasts; /* packets sent via multicast */
  128. u_long ifi_iqdrops; /* dropped on input, this interface */
  129. u_long ifi_noproto; /* destined for unsupported protocol */
  130. u_long  ifi_lastchange; /* last updated */
  131. };
  132. /*
  133.  * Structure defining a queue for a network interface.
  134.  *
  135.  * (Would like to call this struct ``if'', but C isn't PL/1.)
  136.  */
  137. struct ifnet {
  138. char *if_name; /* name, e.g. ``en'' or ``lo'' */
  139. struct ifnet *if_next; /* all struct ifnets are chained */
  140. struct ifaddr *if_addrlist; /* linked list of addresses per if */
  141. int if_pcount; /* number of promiscuous listeners */
  142. caddr_t if_bpf; /* packet filter structure */
  143. u_short if_index; /* numeric abbreviation for this if */
  144. short if_unit; /* sub-unit for lower level driver */
  145. short if_timer; /* time 'til if_watchdog called */
  146. short if_flags; /* up/down, broadcast, etc. */
  147. struct if_data if_data; /* statistics and other data about if */
  148. struct mBlk * pInmMblk;  /* chain of multicast addresses */
  149. int (*if_init) 
  150. (int unit); /* init routine */
  151. int (*if_output) /* output routine */
  152. (struct ifnet *, struct mbuf *, struct sockaddr *, 
  153.  struct rtentry *);
  154. int (*if_start)  /* initiate output routine */
  155.      (struct ifnet *);
  156. int (*if_ioctl) /* ioctl routine */
  157. (struct ifnet *, int cmd, caddr_t data);
  158. int (*if_reset) /* bus reset routine */
  159. (int unit);
  160. int (*if_resolve)(); /* arp resolve at driver level */
  161. void (*if_watchdog) /* timer routine */
  162. (int unit);
  163. struct ifqueue if_snd; /* output queue */
  164.         void *  pCookie;  /* data for IP over MUX attachment */
  165. #ifdef VIRTUAL_STACK
  166.         int     vsNum;                  /* virtual stack number */
  167. #endif
  168. };
  169. #define if_mtu if_data.ifi_mtu
  170. #define if_type if_data.ifi_type
  171. #define if_addrlen if_data.ifi_addrlen
  172. #define if_hdrlen if_data.ifi_hdrlen
  173. #define if_metric if_data.ifi_metric
  174. #define if_baudrate if_data.ifi_baudrate
  175. #define if_ipackets if_data.ifi_ipackets
  176. #define if_ierrors if_data.ifi_ierrors
  177. #define if_opackets if_data.ifi_opackets
  178. #define if_oerrors if_data.ifi_oerrors
  179. #define if_collisions if_data.ifi_collisions
  180. #define if_ibytes if_data.ifi_ibytes
  181. #define if_obytes if_data.ifi_obytes
  182. #define if_imcasts if_data.ifi_imcasts
  183. #define if_omcasts if_data.ifi_omcasts
  184. #define if_iqdrops if_data.ifi_iqdrops
  185. #define if_noproto if_data.ifi_noproto
  186. #define if_lastchange if_data.ifi_lastchange
  187. #define IFF_UP 0x1 /* interface is up */
  188. #define IFF_BROADCAST 0x2 /* broadcast address valid */
  189. #define IFF_DEBUG 0x4 /* turn on debugging */
  190. #define IFF_LOOPBACK 0x8 /* is a loopback net */
  191. #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
  192. #define IFF_NOTRAILERS 0x20 /* avoid use of trailers */
  193. #define IFF_RUNNING 0x40 /* resources allocated */
  194. #define IFF_NOARP 0x80 /* no address resolution protocol */
  195. #define IFF_PROMISC 0x100 /* receive all packets */
  196. #define IFF_ALLMULTI 0x200 /* receive all multicast packets */
  197. #define IFF_OACTIVE 0x400 /* transmission in progress */
  198. #define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
  199. #define IFF_LINK0 0x1000 /* fastPath enabled */
  200. #define IFF_LINK1 0x2000 /* per link layer defined bit */
  201. #define IFF_LINK2 0x4000 /* per link layer defined bit */
  202. #define IFF_MULTICAST 0x8000 /* supports multicast */
  203. #define IFF_RFC2233     0x10000         /* supports RFC 2223 MIB */
  204. #define IFF_UNNUMBERED  IFF_POINTOPOINT /* supports unnumbered interafaces */
  205. /* flags set internally only: */
  206. #define IFF_CANTCHANGE 
  207. (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|
  208.     IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
  209. #define IFF_FP_ENABLE IFF_LINK0         /* fastpath enabled */
  210. /*
  211.  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
  212.  * input routines have queues of messages stored on ifqueue structures
  213.  * (defined above).  Entries are added to and deleted from these structures
  214.  * by these macros, which should be called with ipl raised to splimp().
  215.  */
  216. #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
  217. #define IF_DROP(ifq) ((ifq)->ifq_drops++)
  218. #define IF_ENQUEUE(ifq, m) { 
  219. (m)->m_nextpkt = 0; 
  220. if ((ifq)->ifq_tail == 0) 
  221. (ifq)->ifq_head = m; 
  222. else 
  223. (ifq)->ifq_tail->m_nextpkt = m; 
  224. (ifq)->ifq_tail = m; 
  225. (ifq)->ifq_len++; 
  226. }
  227. #define IF_PREPEND(ifq, m) { 
  228. (m)->m_nextpkt = (ifq)->ifq_head; 
  229. if ((ifq)->ifq_tail == 0) 
  230. (ifq)->ifq_tail = (m); 
  231. (ifq)->ifq_head = (m); 
  232. (ifq)->ifq_len++; 
  233. }
  234. /*
  235.  * Packets destined for level-1 protocol input routines
  236.  * have a pointer to the receiving interface prepended to the data.
  237.  * IF_DEQUEUEIF extracts and returns this pointer when dequeueing the packet.
  238.  * IF_ADJ should be used otherwise to adjust for its presence.
  239.  */
  240. #define IF_ADJ(m) { 
  241. (m)->m_off += sizeof(struct ifnet *); 
  242. (m)->m_len -= sizeof(struct ifnet *); 
  243. if ((m)->m_len == 0) { 
  244. struct mbuf *n; 
  245. MFREE((m), n); 
  246. (m) = n; 
  247. }
  248. #if CPU_FAMILY==SH /* Changed at OCt-20-94 byS.Awai */
  249. #define IF_DEQUEUEIF(ifq, m, ifp) { 
  250. (m) = (ifq)->ifq_head; 
  251. if (m) { 
  252. if (((ifq)->ifq_head = (m)->m_act) == 0) 
  253. (ifq)->ifq_tail = 0; 
  254. (m)->m_act = 0; 
  255. (ifq)->ifq_len--; 
  256. (ifp) = (struct ifnet *)( 
  257. (*((u_short *)((int)(m)+(m)->m_off+0)) << 16) | 
  258. (*((u_short *)((int)(m)+(m)->m_off+2)) ) ); 
  259. IF_ADJ(m); 
  260. }
  261. #else /* orig */
  262. #define IF_DEQUEUEIF(ifq, m, ifp) { 
  263. (m) = (ifq)->ifq_head; 
  264. if (m) { 
  265. if (((ifq)->ifq_head = (m)->m_act) == 0) 
  266. (ifq)->ifq_tail = 0; 
  267. (m)->m_act = 0; 
  268. (ifq)->ifq_len--; 
  269. (ifp) = *(mtod((m), struct ifnet **)); 
  270. IF_ADJ(m); 
  271. }
  272. #endif
  273. #define IF_DEQUEUE(ifq, m) { 
  274. (m) = (ifq)->ifq_head; 
  275. if (m) { 
  276. if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) 
  277. (ifq)->ifq_tail = 0; 
  278. (m)->m_nextpkt = 0; 
  279. (ifq)->ifq_len--; 
  280. }
  281. #define IFQ_MAXLEN 50
  282. #define IFNET_SLOWHZ 1 /* granularity is 1 second */
  283. /*
  284.  * The ifaddr structure contains information about one address
  285.  * of an interface.  They are maintained by the different address families,
  286.  * are allocated and attached when an address is set, and are linked
  287.  * together so all addresses for an interface can be located.
  288.  */
  289. struct ifaddr {
  290. struct sockaddr *ifa_addr; /* address of interface */
  291. struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
  292. #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
  293. struct sockaddr *ifa_netmask; /* used to determine subnet */
  294. struct ifnet *ifa_ifp; /* back-pointer to interface */
  295. struct ifaddr *ifa_next; /* next address for interface */
  296. void (*ifa_rtrequest)(); /* check or clean routes (+ or -)'d */
  297. u_short ifa_flags; /* mostly rt_flags for cloning */
  298. short ifa_refcnt; /* count of references */
  299. int ifa_metric; /* cost of going out this interface */
  300. };
  301. #define IFA_ROUTE RTF_UP /* route installed */
  302. /*
  303.  * Message format for use in obtaining information about interfaces
  304.  * from sysctl and the routing socket.
  305.  */
  306. struct if_msghdr {
  307. u_short ifm_msglen; /* to skip over non-understood messages */
  308. u_char ifm_version; /* future binary compatability */
  309. u_char ifm_type; /* message type */
  310. int ifm_addrs; /* like rtm_addrs */
  311. int ifm_flags; /* value of if_flags */
  312. u_short ifm_index; /* index for associated ifp */
  313. struct if_data ifm_data;/* statistics and other data about if */
  314. };
  315. /*
  316.  * Message format for use in obtaining information about interface addresses
  317.  * from sysctl and the routing socket.
  318.  */
  319. struct ifa_msghdr {
  320. u_short ifam_msglen; /* to skip over non-understood messages */
  321. u_char ifam_version; /* future binary compatability */
  322. u_char ifam_type; /* message type */
  323. int ifam_addrs; /* like rtm_addrs */
  324. int ifam_flags; /* value of ifa_flags */
  325. u_short ifam_index; /* index for associated ifp */
  326. int ifam_metric; /* value of ifa_metric */
  327. };
  328. /*
  329.  * Interface request structure used for socket
  330.  * ioctl's.  All interface ioctl's must have parameter
  331.  * definitions which begin with ifr_name.  The
  332.  * remainder may be interface specific.
  333.  */
  334. struct ifreq {
  335. #define IFNAMSIZ 16
  336. char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
  337. union {
  338. struct sockaddr ifru_addr;
  339. struct sockaddr ifru_dstaddr;
  340. struct sockaddr ifru_broadaddr;
  341. short ifru_flags;
  342. int ifru_metric;
  343. caddr_t ifru_data;
  344. } ifr_ifru;
  345. #define ifr_addr ifr_ifru.ifru_addr /* address */
  346. #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
  347. #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
  348. #define ifr_flags ifr_ifru.ifru_flags /* flags */
  349. #define ifr_metric ifr_ifru.ifru_metric /* metric */
  350. #define ifr_data ifr_ifru.ifru_data /* for use by interface */
  351. };
  352. struct ifaliasreq {
  353. char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
  354. struct sockaddr ifra_addr;
  355. struct sockaddr ifra_broadaddr;
  356. struct sockaddr ifra_mask;
  357. };
  358. /*
  359.  * Interface request structure used for getting
  360.  * the multicast table from a driver.
  361.  */
  362. struct ifmreq {
  363. #define IFNAMSIZ 16
  364. char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
  365. int ifr_tableLen;
  366. char  *ifr_table;
  367. };
  368. /*
  369.  * Structure used in SIOCGIFCONF request.
  370.  * Used to retrieve interface configuration
  371.  * for machine (useful for programs which
  372.  * must know all networks accessible).
  373.  */
  374. struct ifconf {
  375. int ifc_len; /* size of associated buffer */
  376. union {
  377. caddr_t ifcu_buf;
  378. struct ifreq *ifcu_req;
  379. } ifc_ifcu;
  380. #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
  381. #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
  382. };
  383. /* 
  384.  * Structure used in SIOCGMTU request.
  385.  * Used to retrieve the MTU for point-to-multipoint devices.
  386.  */
  387. typedef struct mtuQuery_t 
  388. {
  389. UCHAR family;
  390. UINT32 dstIpAddr;
  391. UINT32 mtu;
  392. } MTU_QUERY;
  393. #define IFAFREE(ifa) 
  394. if ((ifa)->ifa_refcnt <= 0) 
  395. ifafree(ifa); 
  396. else 
  397. (ifa)->ifa_refcnt--;
  398. #if ((CPU_FAMILY==I960) && (defined __GNUC__))
  399. #pragma align 0                 /* turn off alignment requirement */
  400. #endif /* CPU_FAMILY==I960 */
  401. extern struct ifnet *  ifnet; /* declared in if.c */
  402. extern struct ifqueue  rawintrq; /* raw packet input queue */
  403. extern STATUS if_attach (struct ifnet *);
  404. extern void if_down (struct ifnet *);
  405. extern void if_qflush (struct ifqueue *);
  406. #ifndef VIRTUAL_STACK
  407. extern void if_slowtimo (void);
  408. #else
  409. extern void if_slowtimo (int stackNum);
  410. #endif /* VIRTUAL_STACK */
  411. extern void if_up (struct ifnet *);
  412. extern int ifconf (int, caddr_t);
  413. extern void ifinit (void);
  414. extern int ifioctl (struct socket *, u_long, caddr_t);
  415. extern int ifpromisc (struct ifnet *, int);
  416. extern struct ifaddr * ifa_ifwithaddr (struct sockaddr *);
  417. extern struct ifaddr * ifa_ifwithaf (int);
  418. extern struct ifaddr * ifa_ifwithdstaddr (struct sockaddr *);
  419. extern struct ifaddr * ifa_ifwithnet (struct sockaddr *);
  420. extern struct ifaddr * ifaof_ifpforaddr (struct sockaddr *, struct ifnet *);
  421. extern struct ifaddr * ifa_ifwithroute(int, struct sockaddr *, 
  422. struct sockaddr*);
  423. extern void ifafree (struct ifaddr *);
  424. extern void link_rtrequest (int, struct rtentry *,
  425.                                         struct sockaddr *);
  426. #ifdef __cplusplus
  427. }
  428. #endif
  429. #endif /* __INCifh */