Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

IP_VAR.H

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1982, 1986, 1993
00003  *      The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. All advertising materials mentioning features or use of this software
00014  *    must display the following acknowledgement:
00015  *      This product includes software developed by the University of
00016  *      California, Berkeley and its contributors.
00017  * 4. Neither the name of the University nor the names of its contributors
00018  *    may be used to endorse or promote products derived from this software
00019  *    without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  *      @(#)ip_var.h    8.2 (Berkeley) 1/9/95
00034  */
00035 
00036 #ifndef WIN32
00037 #include <endian.h>
00038 #else
00039 typedef char *  caddr_t;
00040 #include <winsock2.h>
00041 #ifndef LITTLE_ENDIAN
00042 #define LITTLE_ENDIAN 1234
00043 #define BIG_ENDIAN 4321
00044 #define BYTE_ORDER LITTLE_ENDIAN 
00045 #endif
00046 #endif
00047 
00048 /*
00049  * Overlay for ip header used by other protocols (tcp, udp).
00050  */
00051 struct ipovly {
00052         caddr_t ih_next, ih_prev;       /* for protocol sequence q's */
00053         u_char  ih_x1;                  /* (unused) */
00054         u_char  ih_pr;                  /* protocol */
00055         short   ih_len;                 /* protocol length */
00056         struct  in_addr ih_src;         /* source internet address */
00057         struct  in_addr ih_dst;         /* destination internet address */
00058 };
00059 
00060 /*
00061  * Ip reassembly queue structure.  Each fragment
00062  * being reassembled is attached to one of these structures.
00063  * They are timed out after ipq_ttl drops to 0, and may also
00064  * be reclaimed if memory becomes tight.
00065  */
00066 struct ipq {
00067         struct  ipq *next,*prev;        /* to other reass headers */
00068         u_char  ipq_ttl;                /* time for reass q to live */
00069         u_char  ipq_p;                  /* protocol of this fragment */
00070         u_short ipq_id;                 /* sequence id for reassembly */
00071         struct  ipasfrag *ipq_next,*ipq_prev;
00072                                         /* to ip headers of fragments */
00073         struct  in_addr ipq_src,ipq_dst;
00074 };
00075 
00076 /*
00077  * Ip header, when holding a fragment.
00078  *
00079  * Note: ipf_next must be at same offset as ipq_next above
00080  */
00081 struct  ipasfrag {
00082 #if BYTE_ORDER == LITTLE_ENDIAN 
00083         u_char  ip_hl:4,
00084                 ip_v:4;
00085 #endif
00086 #if BYTE_ORDER == BIG_ENDIAN 
00087         u_char  ip_v:4,
00088                 ip_hl:4;
00089 #endif
00090         u_char  ipf_mff;                /* XXX overlays ip_tos: use low bit
00091                                          * to avoid destroying tos;
00092                                          * copied from (ip_off&IP_MF) */
00093         short   ip_len;
00094         u_short ip_id;
00095         short   ip_off;
00096         u_char  ip_ttl;
00097         u_char  ip_p;
00098         u_short ip_sum;
00099         struct  ipasfrag *ipf_next;     /* next fragment */
00100         struct  ipasfrag *ipf_prev;     /* previous fragment */
00101 };
00102 
00103 /*
00104  * Structure stored in mbuf in inpcb.ip_options
00105  * and passed to ip_output when ip options are in use.
00106  * The actual length of the options (including ipopt_dst)
00107  * is in m_len.
00108  */
00109 #define MAX_IPOPTLEN    40
00110 
00111 struct ipoption {
00112         struct  in_addr ipopt_dst;      /* first-hop dst if source routed */
00113         char    ipopt_list[MAX_IPOPTLEN];       /* options proper */
00114 };
00115 
00116 struct  ipstat {
00117         n_long  ips_total;              /* total packets received */
00118         n_long  ips_badsum;             /* checksum bad */
00119         n_long  ips_tooshort;           /* packet too short */
00120         n_long  ips_toosmall;           /* not enough data */
00121         n_long  ips_badhlen;            /* ip header length < data size */
00122         n_long  ips_badlen;             /* ip length < ip header length */
00123         n_long  ips_fragments;          /* fragments received */
00124         n_long  ips_fragdropped;        /* frags dropped (dups, out of space) */
00125         n_long  ips_fragtimeout;        /* fragments timed out */
00126         n_long  ips_forward;            /* packets forwarded */
00127         n_long  ips_cantforward;        /* packets rcvd for unreachable dest */
00128         n_long  ips_redirectsent;       /* packets forwarded on same net */
00129         n_long  ips_noproto;            /* unknown or unsupported protocol */
00130         n_long  ips_delivered;          /* datagrams delivered to upper level*/
00131         n_long  ips_localout;           /* total ip packets generated here */
00132         n_long  ips_odropped;           /* lost packets due to nobufs, etc. */
00133         n_long  ips_reassembled;        /* total packets reassembled ok */
00134         n_long  ips_fragmented;         /* datagrams sucessfully fragmented */
00135         n_long  ips_ofragments;         /* output fragments created */
00136         n_long  ips_cantfrag;           /* don't fragment flag was set, etc. */
00137         n_long  ips_badoptions;         /* error in option processing */
00138         n_long  ips_noroute;            /* packets discarded due to no route */
00139         n_long  ips_badvers;            /* ip version != 4 */
00140         n_long  ips_rawout;             /* total raw ip packets generated */
00141 };
00142 
00143 #ifdef KERNEL
00144 /* flags passed to ip_output as last parameter */
00145 #define IP_FORWARDING           0x1             /* most of ip header exists */
00146 #define IP_RAWOUTPUT            0x2             /* raw ip header exists */
00147 #define IP_ROUTETOIF            SO_DONTROUTE    /* bypass routing tables */
00148 #define IP_ALLOWBROADCAST       SO_BROADCAST    /* can send broadcast packets */
00149 
00150 struct  ipstat  ipstat;
00151 struct  ipq     ipq;                    /* ip reass. queue */
00152 u_short ip_id;                          /* ip packet ctr, for ids */
00153 int     ip_defttl;                      /* default IP ttl */
00154 
00155 int      in_control __P((struct socket *, n_long, caddr_t, struct ifnet *));
00156 int      ip_ctloutput __P((int, struct socket *, int, int, struct mbuf **));
00157 void     ip_deq __P((struct ipasfrag *));
00158 int      ip_dooptions __P((struct mbuf *));
00159 void     ip_drain __P((void));
00160 void     ip_enq __P((struct ipasfrag *, struct ipasfrag *));
00161 void     ip_forward __P((struct mbuf *, int));
00162 void     ip_freef __P((struct ipq *));
00163 void     ip_freemoptions __P((struct ip_moptions *));
00164 int      ip_getmoptions __P((int, struct ip_moptions *, struct mbuf **));
00165 void     ip_init __P((void));
00166 int      ip_mforward __P((struct mbuf *, struct ifnet *));
00167 int      ip_optcopy __P((struct ip *, struct ip *));
00168 int      ip_output __P((struct mbuf *,
00169             struct mbuf *, struct route *, int, struct ip_moptions *));
00170 int      ip_pcbopts __P((struct mbuf **, struct mbuf *));
00171 struct ip *
00172          ip_reass __P((struct ipasfrag *, struct ipq *));
00173 struct in_ifaddr *
00174          ip_rtaddr __P((struct in_addr));
00175 int      ip_setmoptions __P((int, struct ip_moptions **, struct mbuf *));
00176 void     ip_slowtimo __P((void));
00177 struct mbuf *
00178          ip_srcroute __P((void));
00179 void     ip_stripoptions __P((struct mbuf *, struct mbuf *));
00180 int      ip_sysctl __P((int *, n_long, void *, size_t *, void *, size_t));
00181 void     ipintr __P((void));
00182 int      rip_ctloutput __P((int, struct socket *, int, int, struct mbuf **));
00183 void     rip_init __P((void));
00184 void     rip_input __P((struct mbuf *));
00185 int      rip_output __P((struct mbuf *, struct socket *, n_long));
00186 int      rip_usrreq __P((struct socket *,
00187             int, struct mbuf *, struct mbuf *, struct mbuf *));
00188 #endif

Generated on Sun May 14 14:51:20 2006 by  doxygen 1.4.2