Path: blob/a-new-beginning/SharedDependencies/Sources/libslirp/include/tcp.h
2 views
/* SPDX-License-Identifier: BSD-3-Clause */1/*2* Copyright (c) 1982, 1986, 19933* The Regents of the University of California. All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13* 3. Neither the name of the University nor the names of its contributors14* may be used to endorse or promote products derived from this software15* without specific prior written permission.16*17* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND18* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE20* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE21* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT25* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY26* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF27* SUCH DAMAGE.28*29* @(#)tcp.h 8.1 (Berkeley) 6/10/9330* tcp.h,v 1.3 1994/08/21 05:27:34 paul Exp31*/3233#ifndef TCP_H34#define TCP_H3536#include <glib.h>3738typedef uint32_t tcp_seq;3940#define PR_SLOWHZ 2 /* 2 slow timeouts per second (approx) */41#define PR_FASTHZ 5 /* 5 fast timeouts per second (not important) */4243#define TCP_SNDSPACE 1024 * 12844#define TCP_RCVSPACE 1024 * 12845#define TCP_MAXSEG_MAX 327684647/*48* TCP header.49* Per RFC 793, September, 1981.50*/51#define tcphdr slirp_tcphdr52struct tcphdr {53uint16_t th_sport; /* source port */54uint16_t th_dport; /* destination port */55tcp_seq th_seq; /* sequence number */56tcp_seq th_ack; /* acknowledgement number */57#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)58uint8_t th_off : 4, /* data offset */59th_x2 : 4; /* (unused) */60#else61uint8_t th_x2 : 4, /* (unused) */62th_off : 4; /* data offset */63#endif64uint8_t th_flags;65uint16_t th_win; /* window */66uint16_t th_sum; /* checksum */67uint16_t th_urp; /* urgent pointer */68};6970#include "tcp_var.h"7172#ifndef TH_FIN73#define TH_FIN 0x0174#define TH_SYN 0x0275#define TH_RST 0x0476#define TH_PUSH 0x0877#define TH_ACK 0x1078#define TH_URG 0x2079#endif8081#ifndef TCPOPT_EOL82#define TCPOPT_EOL 083#define TCPOPT_NOP 184#define TCPOPT_MAXSEG 285#define TCPOPT_WINDOW 386#define TCPOPT_SACK_PERMITTED 4 /* Experimental */87#define TCPOPT_SACK 5 /* Experimental */88#define TCPOPT_TIMESTAMP 88990#define TCPOPT_TSTAMP_HDR \91(TCPOPT_NOP << 24 | TCPOPT_NOP << 16 | TCPOPT_TIMESTAMP << 8 | \92TCPOLEN_TIMESTAMP)93#endif9495#ifndef TCPOLEN_MAXSEG96#define TCPOLEN_MAXSEG 497#define TCPOLEN_WINDOW 398#define TCPOLEN_SACK_PERMITTED 299#define TCPOLEN_TIMESTAMP 10100#define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP + 2) /* appendix A */101#endif102103#undef TCP_MAXWIN104#define TCP_MAXWIN 65535 /* largest value for (unscaled) window */105106#undef TCP_MAX_WINSHIFT107#define TCP_MAX_WINSHIFT 14 /* maximum window shift */108109/*110* User-settable options (used with setsockopt).111*112* We don't use the system headers on unix because we have conflicting113* local structures. We can't avoid the system definitions on Windows,114* so we undefine them.115*/116#undef TCP_NODELAY117#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */118#undef TCP_MAXSEG119120/*121* TCP FSM state definitions.122* Per RFC793, September, 1981.123*/124125#define TCP_NSTATES 11126127#define TCPS_CLOSED 0 /* closed */128#define TCPS_LISTEN 1 /* listening for connection */129#define TCPS_SYN_SENT 2 /* active, have sent syn */130#define TCPS_SYN_RECEIVED 3 /* have send and received syn */131/* states < TCPS_ESTABLISHED are those where connections not established */132#define TCPS_ESTABLISHED 4 /* established */133#define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */134/* states > TCPS_CLOSE_WAIT are those where user has closed */135#define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */136#define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */137#define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */138/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */139#define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */140#define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */141142#define TCPS_HAVERCVDSYN(s) ((s) >= TCPS_SYN_RECEIVED)143#define TCPS_HAVEESTABLISHED(s) ((s) >= TCPS_ESTABLISHED)144#define TCPS_HAVERCVDFIN(s) ((s) >= TCPS_TIME_WAIT)145146/*147* TCP sequence numbers are 32 bit integers operated148* on with modular arithmetic. These macros can be149* used to compare such integers.150*/151#define SEQ_LT(a, b) ((int)((a) - (b)) < 0)152#define SEQ_LEQ(a, b) ((int)((a) - (b)) <= 0)153#define SEQ_GT(a, b) ((int)((a) - (b)) > 0)154#define SEQ_GEQ(a, b) ((int)((a) - (b)) >= 0)155156/*157* Macros to initialize tcp sequence numbers for158* send and receive from initial send and receive159* sequence numbers.160*/161#define tcp_rcvseqinit(tp) (tp)->rcv_adv = (tp)->rcv_nxt = (tp)->irs + 1162163#define tcp_sendseqinit(tp) \164(tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = (tp)->iss165166#define TCP_ISSINCR (125 * 1024) /* increment for tcp_iss each second */167168#endif169170171