1 /* SPDX-License-Identifier: BSD-3-Clause */
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. Neither the name of the University nor the names of its contributors
15  *    may be used to endorse or promote products derived from this software
16  *    without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  *	@(#)tcpip.h	8.1 (Berkeley) 6/10/93
31  * tcpip.h,v 1.3 1994/08/21 05:27:40 paul Exp
32  */
33 
34 #ifndef TCPIP_H
35 #define TCPIP_H
36 
37 /*
38  * Tcp+ip header, after ip options removed.
39  */
40 struct tcpiphdr {
41     struct mbuf_ptr ih_mbuf; /* backpointer to mbuf */
42     union {
43         struct {
44             struct in_addr ih_src; /* source internet address */
45             struct in_addr ih_dst; /* destination internet address */
46             uint8_t ih_x1; /* (unused) */
47             uint8_t ih_pr; /* protocol */
48         } ti_i4;
49         struct {
50             struct in6_addr ih_src;
51             struct in6_addr ih_dst;
52             uint8_t ih_x1;
53             uint8_t ih_nh;
54         } ti_i6;
55     } ti;
56     uint16_t ti_x0;
57     uint16_t ti_len; /* protocol length */
58     struct tcphdr ti_t; /* tcp header */
59 };
60 #define ti_mbuf ih_mbuf.mptr
61 #define ti_pr ti.ti_i4.ih_pr
62 #define ti_src ti.ti_i4.ih_src
63 #define ti_dst ti.ti_i4.ih_dst
64 #define ti_src6 ti.ti_i6.ih_src
65 #define ti_dst6 ti.ti_i6.ih_dst
66 #define ti_nh6 ti.ti_i6.ih_nh
67 #define ti_sport ti_t.th_sport
68 #define ti_dport ti_t.th_dport
69 #define ti_seq ti_t.th_seq
70 #define ti_ack ti_t.th_ack
71 #define ti_x2 ti_t.th_x2
72 #define ti_off ti_t.th_off
73 #define ti_flags ti_t.th_flags
74 #define ti_win ti_t.th_win
75 #define ti_sum ti_t.th_sum
76 #define ti_urp ti_t.th_urp
77 
78 #define tcpiphdr2qlink(T) \
79     ((struct qlink *)(((char *)(T)) - sizeof(struct qlink)))
80 #define qlink2tcpiphdr(Q) \
81     ((struct tcpiphdr *)(((char *)(Q)) + sizeof(struct qlink)))
82 #define tcpiphdr_next(T) qlink2tcpiphdr(tcpiphdr2qlink(T)->next)
83 #define tcpiphdr_prev(T) qlink2tcpiphdr(tcpiphdr2qlink(T)->prev)
84 #define tcpfrag_list_first(T) qlink2tcpiphdr((T)->seg_next)
85 #define tcpfrag_list_end(F, T) (tcpiphdr2qlink(F) == (struct qlink *)(T))
86 #define tcpfrag_list_empty(T) ((T)->seg_next == (struct tcpiphdr *)(T))
87 
88 /* This is the difference between the size of a tcpiphdr structure, and the
89  * size of actual ip+tcp headers, rounded up since we need to align data.  */
90 #define TCPIPHDR_DELTA                                     \
91     (MAX(0, (sizeof(struct tcpiphdr) - sizeof(struct ip) - \
92              sizeof(struct tcphdr) + 3) &                  \
93                 ~3))
94 
95 /*
96  * Just a clean way to get to the first byte
97  * of the packet
98  */
99 struct tcpiphdr_2 {
100     struct tcpiphdr dummy;
101     char first_char;
102 };
103 
104 #endif
105