[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.92

1.92    ! rmind       1: /*     $NetBSD: ip_var.h,v 1.91 2009/02/01 17:04:11 pooka 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.83      perry      49: } __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.64      jonathan   96:        u_int16_t ipq_nfrags;           /* frags in this queue entry */
1.81      matt       97:        u_int8_t  ipq_tos;              /* TOS of this fragment */
1.1       cgd        98: };
                     99:
                    100: /*
                    101:  * Structure stored in mbuf in inpcb.ip_options
                    102:  * and passed to ip_output when ip options are in use.
                    103:  * The actual length of the options (including ipopt_dst)
                    104:  * is in m_len.
                    105:  */
1.5       mycroft   106: #define        MAX_IPOPTLEN    40
1.1       cgd       107:
                    108: struct ipoption {
                    109:        struct  in_addr ipopt_dst;      /* first-hop dst if source routed */
1.12      cgd       110:        int8_t  ipopt_list[MAX_IPOPTLEN];       /* options proper */
1.1       cgd       111: };
                    112:
1.4       hpeyerl   113: /*
                    114:  * Structure attached to inpcb.ip_moptions and
                    115:  * passed to ip_output when IP multicast options are in use.
                    116:  */
                    117: struct ip_moptions {
1.12      cgd       118:        struct    ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
1.44      itojun    119:        struct in_addr imo_multicast_addr; /* ifindex/addr on MULTICAST_IF */
1.12      cgd       120:        u_int8_t  imo_multicast_ttl;    /* TTL for outgoing multicasts */
                    121:        u_int8_t  imo_multicast_loop;   /* 1 => hear sends if a member */
                    122:        u_int16_t imo_num_memberships;  /* no. memberships this socket */
                    123:        struct    in_multi *imo_membership[IP_MAX_MEMBERSHIPS];
1.4       hpeyerl   124: };
                    125:
1.85      thorpej   126: /*
                    127:  * IP statistics.
                    128:  * Each counter is an unsigned 64-bit value.
                    129:  */
                    130: #define        IP_STAT_TOTAL           0       /* total packets received */
                    131: #define        IP_STAT_BADSUM          1       /* checksum bad */
                    132: #define        IP_STAT_TOOSHORT        2       /* packet too short */
                    133: #define        IP_STAT_TOOSMALL        3       /* not enough data */
                    134: #define        IP_STAT_BADHLEN         4       /* ip header length < data size */
                    135: #define        IP_STAT_BADLEN          5       /* ip length < ip header length */
                    136: #define        IP_STAT_FRAGMENTS       6       /* fragments received */
                    137: #define        IP_STAT_FRAGDROPPED     7       /* frags dropped (dups, out of space) */
                    138: #define        IP_STAT_FRAGTIMEOUT     8       /* fragments timed out */
                    139: #define        IP_STAT_FORWARD         9       /* packets forwarded */
                    140: #define        IP_STAT_FASTFORWARD     10      /* packets fast forwarded */
                    141: #define        IP_STAT_CANTFORWARD     11      /* packets rcvd for unreachable dest */
                    142: #define        IP_STAT_REDIRECTSENT    12      /* packets forwareded on same net */
                    143: #define        IP_STAT_NOPROTO         13      /* unknown or unsupported protocol */
                    144: #define        IP_STAT_DELIVERED       14      /* datagrams delivered to upper level */
                    145: #define        IP_STAT_LOCALOUT        15      /* total ip packets generated here */
                    146: #define        IP_STAT_ODROPPED        16      /* lost packets due to nobufs, etc. */
                    147: #define        IP_STAT_REASSEMBLED     17      /* total packets reassembled ok */
                    148: #define        IP_STAT_FRAGMENTED      18      /* datagrams successfully fragmented */
                    149: #define        IP_STAT_OFRAGMENTS      19      /* output fragments created */
                    150: #define        IP_STAT_CANTFRAG        20      /* don't fragment flag was set, etc. */
                    151: #define        IP_STAT_BADOPTIONS      21      /* error in option processing */
                    152: #define        IP_STAT_NOROUTE         22      /* packets discarded due to no route */
                    153: #define        IP_STAT_BADVERS         23      /* ip version != 4 */
                    154: #define        IP_STAT_RAWOUT          24      /* total raw ip packets generated */
                    155: #define        IP_STAT_BADFRAGS        25      /* malformed fragments (bad length) */
                    156: #define        IP_STAT_RCVMEMDROP      26      /* frags dropped for lack of memory */
                    157: #define        IP_STAT_TOOLONG         27      /* ip length > max ip packet size */
                    158: #define        IP_STAT_NOGIF           28      /* no match gif found */
                    159: #define        IP_STAT_BADADDR         29      /* invalid address on header */
                    160:
                    161: #define        IP_NSTATS               30
1.1       cgd       162:
1.11      jtc       163: #ifdef _KERNEL
1.54      martin    164:
                    165: #ifdef _KERNEL_OPT
                    166: #include "opt_gateway.h"
                    167: #include "opt_mbuftrace.h"
                    168: #endif
                    169:
1.1       cgd       170: /* flags passed to ip_output as last parameter */
                    171: #define        IP_FORWARDING           0x1             /* most of ip header exists */
1.9       mycroft   172: #define        IP_RAWOUTPUT            0x2             /* raw ip header exists */
1.21      thorpej   173: #define        IP_RETURNMTU            0x4             /* pass back mtu on EMSGSIZE */
1.84      matt      174: #define        IP_NOIPNEWID            0x8             /* don't fill in ip_id */
1.1       cgd       175: #define        IP_ROUTETOIF            SO_DONTROUTE    /* bypass routing tables */
                    176: #define        IP_ALLOWBROADCAST       SO_BROADCAST    /* can send broadcast packets */
1.43      thorpej   177: #define        IP_MTUDISC              0x0400          /* Path MTU Discovery; set DF */
1.48      thorpej   178:
1.68      matt      179: extern struct domain inetdomain;
                    180:
1.63      jonathan  181: extern LIST_HEAD(ipqhead, ipq) ipq[];  /* ip reass. queue */
1.29      matt      182: extern int   ip_defttl;                        /* default IP ttl */
                    183: extern int   ipforwarding;             /* ip forwarding */
1.27      kml       184: extern int   ip_mtudisc;               /* mtu discovery */
1.49      itojun    185: extern int   ip_mtudisc_timeout;       /* seconds to timeout mtu discovery */
1.27      kml       186: extern int   anonportmin;              /* minimum ephemeral port */
                    187: extern int   anonportmax;              /* maximum ephemeral port */
1.42      tron      188: extern int   lowportmin;               /* minimum reserved port */
                    189: extern int   lowportmax;               /* maximum reserved port */
1.69      thorpej   190: extern int   ip_do_loopback_cksum;     /* do IP checksum on loopback? */
1.27      kml       191: extern struct rttimer_queue *ip_mtudisc_timeout_q;
1.51      matt      192: #ifdef MBUFTRACE
                    193: extern struct mowner ip_rx_mowner;
                    194: extern struct mowner ip_tx_mowner;
                    195: #endif
1.31      matt      196: #ifdef GATEWAY
                    197: extern int ip_maxflows;
1.79      liamjfoy  198: extern int ip_hashsize;
1.31      matt      199: #endif
1.52      matt      200: extern struct pool inmulti_pool;
1.19      thorpej   201: struct  inpcb;
1.88      plunky    202: struct   sockopt;
1.19      thorpej   203:
1.88      plunky    204: int     ip_ctloutput(int, struct socket *, struct sockopt *);
1.67      itojun    205: int     ip_dooptions(struct mbuf *);
                    206: void    ip_drain(void);
                    207: void    ip_forward(struct mbuf *, int);
                    208: void    ip_freemoptions(struct ip_moptions *);
1.88      plunky    209: int     ip_getmoptions(struct ip_moptions *, struct sockopt *);
1.67      itojun    210: void    ip_init(void);
                    211: int     ip_optcopy(struct ip *, struct ip *);
                    212: u_int   ip_optlen(struct inpcb *);
                    213: int     ip_output(struct mbuf *, ...);
                    214: int     ip_fragment(struct mbuf *, struct ifnet *, u_long);
1.90      plunky    215: int     ip_pcbopts(struct mbuf **, const struct sockopt *);
1.92    ! rmind     216:
        !           217: struct ipq *
        !           218:         ip_reass_lookup(struct ip *, u_int *);
        !           219: void    ip_reass_unlock(void);
        !           220: struct ipqent *
        !           221:        ip_reass_getent(void);
1.20      thorpej   222: struct mbuf *
1.92    ! rmind     223:         ip_reass(struct ipqent *, struct ipq *, u_int);
        !           224: void    ip_reass_slowtimo(void);
        !           225: void    ip_reass_drain(void);
        !           226: void    ip_freef(struct ipq *);
        !           227:
1.6       mycroft   228: struct in_ifaddr *
1.67      itojun    229:         ip_rtaddr(struct in_addr);
                    230: void    ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *,
1.66      matt      231:           struct mbuf *);
1.89      plunky    232: int     ip_setmoptions(struct ip_moptions **, const struct sockopt *);
1.67      itojun    233: void    ip_slowtimo(void);
1.6       mycroft   234: struct mbuf *
1.67      itojun    235:         ip_srcroute(void);
                    236: int     ip_sysctl(int *, u_int, void *, size_t *, void *, size_t);
1.87      thorpej   237: void    ip_statinc(u_int);
1.67      itojun    238: void    ipintr(void);
1.78      dyoung    239: void *  rip_ctlinput(int, const struct sockaddr *, void *);
1.88      plunky    240: int     rip_ctloutput(int, struct socket *, struct sockopt *);
1.67      itojun    241: void    rip_init(void);
                    242: void    rip_input(struct mbuf *, ...);
                    243: int     rip_output(struct mbuf *, ...);
                    244: int     rip_usrreq(struct socket *,
1.75      christos  245:            int, struct mbuf *, struct mbuf *, struct mbuf *, struct lwp *);
1.79      liamjfoy  246: int    ipflow_init(int);
1.91      pooka     247: void   ipflow_poolinit(void);
1.86      thorpej   248: void   ipflow_prune(void);
1.67      itojun    249: void   ipflow_create(const struct route *, struct mbuf *);
                    250: void   ipflow_slowtimo(void);
1.79      liamjfoy  251: int    ipflow_invalidate_all(int);
1.59      itojun    252:
1.60      jonathan  253: #endif  /* _KERNEL */
1.25      perry     254:
1.74      elad      255: #endif /* !_NETINET_IP_VAR_H_ */

CVSweb <webmaster@jp.NetBSD.org>