[BACK]Return to ip_var.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / netinet

Annotation of src/sys/netinet/ip_var.h, Revision 1.62

1.62    ! itojun      1: /*     $NetBSD: ip_var.h,v 1.61 2003/11/25 14:44:13 itojun Exp $       */
1.10      cgd         2:
1.1       cgd         3: /*
1.9       mycroft     4:  * Copyright (c) 1982, 1986, 1993
                      5:  *     The Regents of the University of California.  All rights reserved.
1.1       cgd         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.
1.57      agc        15:  * 3. Neither the name of the University nor the names of its contributors
1.1       cgd        16:  *    may be used to endorse or promote products derived from this software
                     17:  *    without specific prior written permission.
                     18:  *
                     19:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     20:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     21:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     22:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     23:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     24:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     25:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     26:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     27:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     28:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     29:  * SUCH DAMAGE.
                     30:  *
1.24      thorpej    31:  *     @(#)ip_var.h    8.2 (Berkeley) 1/9/95
1.1       cgd        32:  */
                     33:
1.25      perry      34: #ifndef _NETINET_IP_VAR_H_
                     35: #define _NETINET_IP_VAR_H_
1.53      martin     36:
1.15      cgd        37: #include <sys/queue.h>
1.30      thorpej    38: #include <net/route.h>
1.15      cgd        39:
1.1       cgd        40: /*
                     41:  * Overlay for ip header used by other protocols (tcp, udp).
                     42:  */
                     43: struct ipovly {
1.18      thorpej    44:        u_int8_t  ih_x1[9];             /* (unused) */
                     45:        u_int8_t  ih_pr;                /* protocol */
                     46:        u_int16_t ih_len;               /* protocol length */
                     47:        struct    in_addr ih_src;       /* source internet address */
                     48:        struct    in_addr ih_dst;       /* destination internet address */
1.40      thorpej    49: } __attribute__((__packed__));
1.1       cgd        50:
                     51: /*
1.15      cgd        52:  * Ip (reassembly or sequence) queue structures.
                     53:  *
                     54:  * XXX -- The following explains why the ipqe_m field is here, for TCP's use:
                     55:  * We want to avoid doing m_pullup on incoming packets but that
                     56:  * means avoiding dtom on the tcp reassembly code.  That in turn means
                     57:  * keeping an mbuf pointer in the reassembly queue (since we might
                     58:  * have a cluster).  As a quick hack, the source & destination
                     59:  * port numbers (which are no longer needed once we've located the
                     60:  * tcpcb) are overlayed with an mbuf pointer.
                     61:  */
1.47      matt       62: TAILQ_HEAD(ipqehead, ipqent);
1.15      cgd        63: struct ipqent {
1.47      matt       64:        TAILQ_ENTRY(ipqent) ipqe_q;
1.15      cgd        65:        union {
                     66:                struct ip       *_ip;
                     67:                struct tcpiphdr *_tcp;
                     68:        } _ipqe_u1;
1.47      matt       69:        struct mbuf     *ipqe_m;        /* point to first mbuf */
                     70:        struct mbuf     *ipre_mlast;    /* point to last mbuf */
1.20      thorpej    71:        u_int8_t        ipqe_mff;       /* for IP fragmentation */
1.28      matt       72:        /*
                     73:         * The following are used in TCP reassembly
                     74:         */
1.47      matt       75:        TAILQ_ENTRY(ipqent) ipqe_timeq;
1.28      matt       76:        u_int32_t ipqe_seq;
                     77:        u_int32_t ipqe_len;
                     78:        u_int32_t ipqe_flags;
1.15      cgd        79: };
                     80: #define        ipqe_ip         _ipqe_u1._ip
                     81: #define        ipqe_tcp        _ipqe_u1._tcp
                     82:
                     83: /*
1.1       cgd        84:  * Ip reassembly queue structure.  Each fragment
                     85:  * being reassembled is attached to one of these structures.
                     86:  * They are timed out after ipq_ttl drops to 0, and may also
                     87:  * be reclaimed if memory becomes tight.
                     88:  */
                     89: struct ipq {
1.15      cgd        90:        LIST_ENTRY(ipq) ipq_q;          /* to other reass headers */
1.12      cgd        91:        u_int8_t  ipq_ttl;              /* time for reass q to live */
                     92:        u_int8_t  ipq_p;                /* protocol of this fragment */
                     93:        u_int16_t ipq_id;               /* sequence id for reassembly */
1.15      cgd        94:        struct    ipqehead ipq_fragq;   /* to ip fragment queue */
1.14      mycroft    95:        struct    in_addr ipq_src, ipq_dst;
1.1       cgd        96: };
                     97:
                     98: /*
                     99:  * Structure stored in mbuf in inpcb.ip_options
                    100:  * and passed to ip_output when ip options are in use.
                    101:  * The actual length of the options (including ipopt_dst)
                    102:  * is in m_len.
                    103:  */
1.5       mycroft   104: #define        MAX_IPOPTLEN    40
1.1       cgd       105:
                    106: struct ipoption {
                    107:        struct  in_addr ipopt_dst;      /* first-hop dst if source routed */
1.12      cgd       108:        int8_t  ipopt_list[MAX_IPOPTLEN];       /* options proper */
1.1       cgd       109: };
                    110:
1.4       hpeyerl   111: /*
                    112:  * Structure attached to inpcb.ip_moptions and
                    113:  * passed to ip_output when IP multicast options are in use.
                    114:  */
                    115: struct ip_moptions {
1.12      cgd       116:        struct    ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
1.44      itojun    117:        struct in_addr imo_multicast_addr; /* ifindex/addr on MULTICAST_IF */
1.12      cgd       118:        u_int8_t  imo_multicast_ttl;    /* TTL for outgoing multicasts */
                    119:        u_int8_t  imo_multicast_loop;   /* 1 => hear sends if a member */
                    120:        u_int16_t imo_num_memberships;  /* no. memberships this socket */
                    121:        struct    in_multi *imo_membership[IP_MAX_MEMBERSHIPS];
1.4       hpeyerl   122: };
                    123:
1.1       cgd       124: struct ipstat {
1.39      bouyer    125:        u_quad_t ips_total;             /* total packets received */
                    126:        u_quad_t ips_badsum;            /* checksum bad */
                    127:        u_quad_t ips_tooshort;          /* packet too short */
                    128:        u_quad_t ips_toosmall;          /* not enough data */
                    129:        u_quad_t ips_badhlen;           /* ip header length < data size */
                    130:        u_quad_t ips_badlen;            /* ip length < ip header length */
                    131:        u_quad_t ips_fragments;         /* fragments received */
                    132:        u_quad_t ips_fragdropped;       /* frags dropped (dups, out of space) */
                    133:        u_quad_t ips_fragtimeout;       /* fragments timed out */
                    134:        u_quad_t ips_forward;           /* packets forwarded */
                    135:        u_quad_t ips_fastforward;       /* packets fast forwarded */
                    136:        u_quad_t ips_cantforward;       /* packets rcvd for unreachable dest */
                    137:        u_quad_t ips_redirectsent;      /* packets forwarded on same net */
                    138:        u_quad_t ips_noproto;           /* unknown or unsupported protocol */
                    139:        u_quad_t ips_delivered;         /* datagrams delivered to upper level*/
                    140:        u_quad_t ips_localout;          /* total ip packets generated here */
                    141:        u_quad_t ips_odropped;          /* lost packets due to nobufs, etc. */
                    142:        u_quad_t ips_reassembled;       /* total packets reassembled ok */
1.50      wiz       143:        u_quad_t ips_fragmented;        /* datagrams successfully fragmented */
1.39      bouyer    144:        u_quad_t ips_ofragments;        /* output fragments created */
                    145:        u_quad_t ips_cantfrag;          /* don't fragment flag was set, etc. */
                    146:        u_quad_t ips_badoptions;        /* error in option processing */
                    147:        u_quad_t ips_noroute;           /* packets discarded due to no route */
                    148:        u_quad_t ips_badvers;           /* ip version != 4 */
                    149:        u_quad_t ips_rawout;            /* total raw ip packets generated */
                    150:        u_quad_t ips_badfrags;          /* malformed fragments (bad length) */
                    151:        u_quad_t ips_rcvmemdrop;        /* frags dropped for lack of memory */
                    152:        u_quad_t ips_toolong;           /* ip length > max ip packet size */
                    153:        u_quad_t ips_nogif;             /* no match gif found */
1.45      itojun    154:        u_quad_t ips_badaddr;           /* invalid address on header */
1.1       cgd       155: };
                    156:
1.29      matt      157: #define        IPFLOW_HASHBITS                 6 /* should not be a multiple of 8 */
                    158: struct ipflow {
1.34      thorpej   159:        LIST_ENTRY(ipflow) ipf_list;    /* next in active list */
                    160:        LIST_ENTRY(ipflow) ipf_hash;    /* next ipflow in bucket */
1.29      matt      161:        struct in_addr ipf_dst;         /* destination address */
                    162:        struct in_addr ipf_src;         /* source address */
                    163:        u_int8_t ipf_tos;               /* type-of-service */
                    164:        struct route ipf_ro;            /* associated route entry */
                    165:        u_long ipf_uses;                /* number of uses in this period */
                    166:        u_long ipf_last_uses;           /* number of uses in last period */
                    167:        u_long ipf_dropped;             /* ENOBUFS returned by if_output */
                    168:        u_long ipf_errors;              /* other errors returned by if_output */
1.34      thorpej   169:        u_int ipf_timer;                /* lifetime timer */
1.29      matt      170:        time_t ipf_start;               /* creation time */
                    171: };
                    172:
1.11      jtc       173: #ifdef _KERNEL
1.54      martin    174:
                    175: #ifdef _KERNEL_OPT
                    176: #include "opt_gateway.h"
                    177: #include "opt_mbuftrace.h"
                    178: #endif
                    179:
1.1       cgd       180: /* flags passed to ip_output as last parameter */
                    181: #define        IP_FORWARDING           0x1             /* most of ip header exists */
1.9       mycroft   182: #define        IP_RAWOUTPUT            0x2             /* raw ip header exists */
1.21      thorpej   183: #define        IP_RETURNMTU            0x4             /* pass back mtu on EMSGSIZE */
1.1       cgd       184: #define        IP_ROUTETOIF            SO_DONTROUTE    /* bypass routing tables */
                    185: #define        IP_ALLOWBROADCAST       SO_BROADCAST    /* can send broadcast packets */
1.43      thorpej   186: #define        IP_MTUDISC              0x0400          /* Path MTU Discovery; set DF */
1.48      thorpej   187:
                    188: #ifdef __NO_STRICT_ALIGNMENT
                    189: #define        IP_HDR_ALIGNED_P(ip)    1
                    190: #else
                    191: #define        IP_HDR_ALIGNED_P(ip)    ((((vaddr_t) (ip)) & 3) == 0)
                    192: #endif
1.1       cgd       193:
1.29      matt      194: extern struct ipstat ipstat;           /* ip statistics */
                    195: extern LIST_HEAD(ipqhead, ipq) ipq;    /* ip reass. queue */
                    196: extern int   ip_defttl;                        /* default IP ttl */
                    197: extern int   ipforwarding;             /* ip forwarding */
1.27      kml       198: extern int   ip_mtudisc;               /* mtu discovery */
1.49      itojun    199: extern int   ip_mtudisc_timeout;       /* seconds to timeout mtu discovery */
1.27      kml       200: extern int   anonportmin;              /* minimum ephemeral port */
                    201: extern int   anonportmax;              /* maximum ephemeral port */
1.42      tron      202: extern int   lowportmin;               /* minimum reserved port */
                    203: extern int   lowportmax;               /* maximum reserved port */
1.27      kml       204: extern struct rttimer_queue *ip_mtudisc_timeout_q;
1.51      matt      205: #ifdef MBUFTRACE
                    206: extern struct mowner ip_rx_mowner;
                    207: extern struct mowner ip_tx_mowner;
                    208: #endif
1.31      matt      209: #ifdef GATEWAY
                    210: extern int ip_maxflows;
                    211: #endif
1.52      matt      212: extern struct pool inmulti_pool;
1.35      thorpej   213: extern struct pool ipqent_pool;
1.19      thorpej   214: struct  inpcb;
                    215:
1.9       mycroft   216: int     ip_ctloutput __P((int, struct socket *, int, int, struct mbuf **));
                    217: int     ip_dooptions __P((struct mbuf *));
                    218: void    ip_drain __P((void));
                    219: void    ip_forward __P((struct mbuf *, int));
                    220: void    ip_freef __P((struct ipq *));
                    221: void    ip_freemoptions __P((struct ip_moptions *));
                    222: int     ip_getmoptions __P((int, struct ip_moptions *, struct mbuf **));
                    223: void    ip_init __P((void));
                    224: int     ip_optcopy __P((struct ip *, struct ip *));
1.26      kml       225: u_int   ip_optlen __P((struct inpcb *));
1.16      christos  226: int     ip_output __P((struct mbuf *, ...));
1.58      itojun    227: int     ip_fragment(struct mbuf *, struct ifnet *, u_long);
1.9       mycroft   228: int     ip_pcbopts __P((struct mbuf **, struct mbuf *));
1.20      thorpej   229: struct mbuf *
1.15      cgd       230:         ip_reass __P((struct ipqent *, struct ipq *));
1.6       mycroft   231: struct in_ifaddr *
1.9       mycroft   232:         ip_rtaddr __P((struct in_addr));
1.19      thorpej   233: void    ip_savecontrol __P((struct inpcb *, struct mbuf **, struct ip *,
                    234:           struct mbuf *));
1.9       mycroft   235: int     ip_setmoptions __P((int, struct ip_moptions **, struct mbuf *));
                    236: void    ip_slowtimo __P((void));
1.6       mycroft   237: struct mbuf *
1.9       mycroft   238:         ip_srcroute __P((void));
                    239: void    ip_stripoptions __P((struct mbuf *, struct mbuf *));
                    240: int     ip_sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
                    241: void    ipintr __P((void));
1.46      itojun    242: void *  rip_ctlinput __P((int, struct sockaddr *, void *));
1.9       mycroft   243: int     rip_ctloutput __P((int, struct socket *, int, int, struct mbuf **));
                    244: void    rip_init __P((void));
1.16      christos  245: void    rip_input __P((struct mbuf *, ...));
                    246: int     rip_output __P((struct mbuf *, ...));
1.9       mycroft   247: int     rip_usrreq __P((struct socket *,
1.56      fvdl      248:            int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *));
1.36      thorpej   249: void   ipflow_init __P((void));
1.31      matt      250: struct ipflow *ipflow_reap __P((int));
                    251: void   ipflow_create __P((const struct route *, struct mbuf *));
                    252: void   ipflow_slowtimo __P((void));
1.59      itojun    253:
1.60      jonathan  254: extern uint16_t        ip_id;
                    255: static __inline uint16_t ip_newid __P((void));
                    256:
1.59      itojun    257: u_int16_t ip_randomid __P((void));
1.60      jonathan  258: extern int ip_do_randomid;
                    259:
                    260: static __inline uint16_t
                    261: ip_newid(void)
                    262: {
                    263:        if (ip_do_randomid)
1.61      itojun    264:                return ip_randomid();
1.60      jonathan  265:
                    266:        return htons(ip_id++);
                    267: }
                    268:
                    269: #endif  /* _KERNEL */
1.25      perry     270:
                    271: #endif /* _NETINET_IP_VAR_H_ */

CVSweb <webmaster@jp.NetBSD.org>