Path: blob/a-new-beginning/SharedDependencies/Sources/libslirp/include/ip.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* @(#)ip.h 8.1 (Berkeley) 6/10/9330* ip.h,v 1.3 1994/08/21 05:27:30 paul Exp31*/3233#ifndef IP_H34#define IP_H3536#include <glib.h>3738#if G_BYTE_ORDER == G_BIG_ENDIAN39#undef NTOHL40#undef NTOHS41#undef HTONL42#undef HTONS43#define NTOHL(d)44#define NTOHS(d)45#define HTONL(d)46#define HTONS(d)47#else48#ifndef NTOHL49#define NTOHL(d) ((d) = ntohl((d)))50#endif51#ifndef NTOHS52#define NTOHS(d) ((d) = ntohs((uint16_t)(d)))53#endif54#ifndef HTONL55#define HTONL(d) ((d) = htonl((d)))56#endif57#ifndef HTONS58#define HTONS(d) ((d) = htons((uint16_t)(d)))59#endif60#endif6162typedef uint32_t n_long; /* long as received from the net */6364/*65* Definitions for internet protocol version 4.66* Per RFC 791, September 1981.67*/68#define IPVERSION 46970#ifdef RSTSLIRP7172/*73* Structure of an internet header, naked of options.74*/75SLIRP_PACKED_BEGIN76struct ip {77#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)78uint8_t ip_v : 4, /* version */79ip_hl : 4; /* header length */80#else81uint8_t ip_hl : 4, /* header length */82ip_v : 4; /* version */83#endif84uint8_t ip_tos; /* type of service */85uint16_t ip_len; /* total length */86uint16_t ip_id; /* identification */87uint16_t ip_off; /* fragment offset field */88#define IP_DF 0x4000 /* don't fragment flag */89#define IP_MF 0x2000 /* more fragments flag */90#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */91uint8_t ip_ttl; /* time to live */92uint8_t ip_p; /* protocol */93uint16_t ip_sum; /* checksum */94struct in_addr ip_src, ip_dst; /* source and dest address */95} SLIRP_PACKED_END;9697#endif9899#define IP_MAXPACKET 65535 /* maximum packet size */100101/*102* Definitions for IP type of service (ip_tos)103*/104#define IPTOS_LOWDELAY 0x10105#define IPTOS_THROUGHPUT 0x08106#define IPTOS_RELIABILITY 0x04107108/*109* Definitions for options.110*/111#define IPOPT_COPIED(o) ((o)&0x80)112#define IPOPT_CLASS(o) ((o)&0x60)113#define IPOPT_NUMBER(o) ((o)&0x1f)114115#define IPOPT_CONTROL 0x00116#define IPOPT_RESERVED1 0x20117#define IPOPT_DEBMEAS 0x40118#define IPOPT_RESERVED2 0x60119120#define IPOPT_EOL 0 /* end of option list */121#define IPOPT_NOP 1 /* no operation */122123#define IPOPT_RR 7 /* record packet route */124#define IPOPT_TS 68 /* timestamp */125#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */126#define IPOPT_LSRR 131 /* loose source route */127#define IPOPT_SATID 136 /* satnet id */128#define IPOPT_SSRR 137 /* strict source route */129130/*131* Offsets to fields in options other than EOL and NOP.132*/133#define IPOPT_OPTVAL 0 /* option ID */134#define IPOPT_OLEN 1 /* option length */135#define IPOPT_OFFSET 2 /* offset within option */136#define IPOPT_MINOFF 4 /* min value of above */137138#ifdef RSTSLIRP139140/*141* Time stamp option structure.142*/143SLIRP_PACKED_BEGIN144struct ip_timestamp {145uint8_t ipt_code; /* IPOPT_TS */146uint8_t ipt_len; /* size of structure (variable) */147uint8_t ipt_ptr; /* index of current entry */148#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)149uint8_t ipt_oflw : 4, /* overflow counter */150ipt_flg : 4; /* flags, see below */151#else152uint8_t ipt_flg : 4, /* flags, see below */153ipt_oflw : 4; /* overflow counter */154#endif155union ipt_timestamp {156n_long ipt_time[1];157struct ipt_ta {158struct in_addr ipt_addr;159n_long ipt_time;160} ipt_ta[1];161} ipt_timestamp;162} SLIRP_PACKED_END;163164#endif165166/* flag bits for ipt_flg */167#define IPOPT_TS_TSONLY 0 /* timestamps only */168#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */169#define IPOPT_TS_PRESPEC 3 /* specified modules only */170171/* bits for security (not byte swapped) */172#define IPOPT_SECUR_UNCLASS 0x0000173#define IPOPT_SECUR_CONFID 0xf135174#define IPOPT_SECUR_EFTO 0x789a175#define IPOPT_SECUR_MMMM 0xbc4d176#define IPOPT_SECUR_RESTR 0xaf13177#define IPOPT_SECUR_SECRET 0xd788178#define IPOPT_SECUR_TOPSECRET 0x6bc5179180/*181* Internet implementation parameters.182*/183#define MAXTTL 255 /* maximum time to live (seconds) */184#define IPDEFTTL 64 /* default ttl, from RFC 1340 */185#define IPFRAGTTL 60 /* time to live for frags, slowhz */186#define IPTTLDEC 1 /* subtracted when forwarding */187188#define IP_MSS 576 /* default maximum segment size */189190#if GLIB_SIZEOF_VOID_P == 4191SLIRP_PACKED_BEGIN192struct mbuf_ptr {193struct mbuf *mptr;194uint32_t dummy;195} SLIRP_PACKED_END;196#else197SLIRP_PACKED_BEGIN198struct mbuf_ptr {199struct mbuf *mptr;200} SLIRP_PACKED_END;201#endif202struct qlink {203void *next, *prev;204};205206/*207* Overlay for ip header used by other protocols (tcp, udp).208*/209SLIRP_PACKED_BEGIN210struct ipovly {211struct mbuf_ptr ih_mbuf; /* backpointer to mbuf */212uint8_t ih_x1; /* (unused) */213uint8_t ih_pr; /* protocol */214uint16_t ih_len; /* protocol length */215struct in_addr ih_src; /* source internet address */216struct in_addr ih_dst; /* destination internet address */217} SLIRP_PACKED_END;218219/*220* Ip reassembly queue structure. Each fragment221* being reassembled is attached to one of these structures.222* They are timed out after ipq_ttl drops to 0, and may also223* be reclaimed if memory becomes tight.224*/225struct ipq {226struct qlink ip_link; /* to other reass headers */227uint8_t ipq_ttl; /* time for reass q to live */228uint8_t ipq_p; /* protocol of this fragment */229uint16_t ipq_id; /* sequence id for reassembly */230struct in_addr ipq_src, ipq_dst;231};232233struct ipas {234struct qlink link;235union {236struct ipq ipq;237struct ip ipf_ip;238};239};240241#define ipf_off ipf_ip.ip_off242#define ipf_tos ipf_ip.ip_tos243#define ipf_len ipf_ip.ip_len244245#endif246247248