1/* Parts of this file are covered under the following copyright */
2/*
3 * Copyright (c) 1982, 1986, 1993
4 *      The Regents of the University of California.  All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 *    must display the following acknowledgement:
16 *      This product includes software developed by the University of
17 *      California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 *    may be used to endorse or promote products derived from this software
20 *    without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 *      @(#)ip_var.h    8.1 (Berkeley) 6/10/93
35 */
36
37#ifndef NETINET_IP_VAR_H
38#define NETINET_IP_VAR_H
39
40#include <netinet/in.h>
41#include <sys/socket.h>
42
43/*
44 * Overlay for ip header used by other protocols (tcp, udp).
45 */
46struct ipovly {
47	char *   ih_next;
48	char *   ih_prev;
49	uint8_t   ih_x1;        /* (unused) */
50	uint8_t   ih_pr;           /* protocol */
51	uint16_t  ih_len;          /* protocol length */
52	struct    in_addr ih_src;  /* source internet address */
53	struct    in_addr ih_dst;  /* destination internet address */
54};
55
56/*
57 * Structure stored in mbuf in inpcb.ip_options
58 * and passed to ip_output when ip options are in use.
59 * The actual length of the options (including ipopt_dst)
60 * is in m_len.
61 */
62#define MAX_IPOPTLEN    40
63
64struct ipoption {
65	struct  in_addr ipopt_dst;         /* first-hop dst if source routed */
66	int8_t  ipopt_list[MAX_IPOPTLEN];  /* options proper */
67};
68
69/*
70 * Structure attached to inpcb.ip_moptions and
71 * passed to ip_output when IP multicast options are in use.
72 */
73struct ip_moptions {
74	struct    ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
75	uint8_t  imo_multicast_ttl;           /* TTL for outgoing multicasts */
76	uint8_t  imo_multicast_loop;          /* 1 => here sends if a member */
77	uint16_t imo_num_memberships;         /* no. memberships this socket */
78	struct    in_multi *imo_membership[IP_MAX_MEMBERSHIPS];
79};
80
81struct ipasfrag {
82#if B_HOST_IS_BENDIAN
83	uint8_t  ip_v:4;
84	uint8_t  ip_hl:4;
85#else
86	uint8_t  ip_hl:4;
87	uint8_t  ip_v:4;
88#endif
89	uint8_t  ipf_mff;
90	int16_t  ip_len;
91	uint16_t ip_id;
92	int16_t  ip_off;
93	uint8_t  ip_ttl;
94	uint8_t  ip_p;
95	struct ipasfrag *ipf_next;
96	struct ipasfrag *ipf_prev;
97};
98
99struct ipq {
100	struct ipq *next, *prev;
101	uint8_t  ipq_ttl;
102	uint8_t  ipq_p;
103	uint16_t ipq_id;
104	struct ipasfrag *ipq_next, *ipq_prev;
105	struct in_addr ipq_src, ipq_dst;
106};
107
108struct  ipstat {
109        int32_t  ips_total;              /* total packets received */
110        int32_t  ips_badsum;             /* checksum bad */
111        int32_t  ips_tooshort;           /* packet too short */
112        int32_t  ips_toosmall;           /* not enough data */
113        int32_t  ips_badhlen;            /* ip header length < data size */
114        int32_t  ips_badlen;             /* ip length < ip header length */
115        int32_t  ips_fragments;          /* fragments received */
116        int32_t  ips_fragdropped;        /* frags dropped (dups, out of space) */
117        int32_t  ips_fragtimeout;        /* fragments timed out */
118        int32_t  ips_forward;            /* packets forwarded */
119        int32_t  ips_cantforward;        /* packets rcvd for unreachable dest */
120        int32_t  ips_redirectsent;       /* packets forwarded on same net */
121        int32_t  ips_noproto;            /* unknown or unsupported protocol */
122        int32_t  ips_delivered;          /* datagrams delivered to upper level*/
123        int32_t  ips_localout;           /* total ip packets generated here */
124        int32_t  ips_odropped;           /* lost packets due to nobufs, etc. */
125        int32_t  ips_reassembled;        /* total packets reassembled ok */
126        int32_t  ips_fragmented;         /* datagrams sucessfully fragmented */
127        int32_t  ips_ofragments;         /* output fragments created */
128        int32_t  ips_cantfrag;           /* don't fragment flag was set, etc. */
129        int32_t  ips_badoptions;         /* error in option processing */
130        int32_t  ips_noroute;            /* packets discarded due to no route */
131        int32_t  ips_badvers;            /* ip version != 4 */
132        int32_t  ips_rawout;             /* total raw ip packets generated */
133        int32_t  ips_badfrags;           /* malformed fragments (bad length) */
134        int32_t  ips_rcvmemdrop;         /* frags dropped for lack of memory */
135        int32_t  ips_toolong;            /* ip length > max ip packet size */
136        int32_t  ips_nogif;              /* no match gif found */
137        int32_t  ips_badaddr;            /* invalid address on header */
138        int32_t  ips_inhwcsum;           /* hardware checksummed on input */
139        int32_t  ips_outhwcsum;          /* hardware checksummed on output */
140};
141
142/* #ifdef _KERNEL_MODE */
143
144#define IP_FORWARDING			0x1				/* most of ip header exists */
145#define IP_ALLOWBROADCAST		SO_BROADCAST	/* can send broadcast packets */
146#define IP_RAWOUTPUT			0x4				/* raw ip header exists */
147#define IP_ROUTETOIF			SO_DONTROUTE	/* bypass routing tables */
148#define IP_MTUDISC				0x10			/* pmtu discovery, set DF */
149
150#if 0
151/* struct ipstat ipstat; */
152
153void  ipv4_input(struct mbuf *, int);
154int   ipv4_output(struct mbuf *, struct mbuf *, struct route *, int, void *);
155int   ipv4_ctloutput(int, struct socket *, int, int, struct mbuf **);
156
157int   ip_dooptions(struct mbuf *);
158void  ip_stripoptions (struct mbuf *, struct mbuf *);
159struct mbuf *ip_srcroute(void);
160
161
162#endif /* _KERNEL_MODE */
163
164#endif /* NETINET_IP_VAR_H */
165