📄 ipv4.h
字号:
/*Copyright (c) 2003,2004 Jeremy Kerr & Rusty RussellThis file is part of nfsim.nfsim is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.nfsim is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with nfsim; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#ifndef __HAVE_IPV4_H#define __HAVE_IPV4_H 1#include <protocol.h>/* ipv4 definitions *//* ip.h */#define IP_CE 0x8000 /* Flag: "Congestion" */#define IP_DF 0x4000 /* Flag: "Don't Fragment" */#define IP_MF 0x2000 /* Flag: "More Fragments" */#define IP_OFFSET 0x1FFF /* "Fragment Offset" part */#define IPOPT_OPTVAL 0#define IPOPT_OLEN 1#define IPOPT_OFFSET 2#define IPOPT_MINOFF 4#define MAX_IPOPTLEN 40#define IPOPT_NOP IPOPT_NOOP#define IPOPT_EOL IPOPT_END#define IPOPT_TS IPOPT_TIMESTAMP#define IPTOS_TOS_MASK 0x1E#define IPTOS_TOS(tos) ((tos)&IPTOS_TOS_MASK)#define IPTOS_LOWDELAY 0x10#define IPTOS_THROUGHPUT 0x08#define IPTOS_RELIABILITY 0x04#define IPTOS_MINCOST 0x02#define IPTOS_PREC_MASK 0xE0#define IPTOS_PREC(tos) ((tos)&IPTOS_PREC_MASK)#define IPTOS_PREC_NETCONTROL 0xe0#define IPTOS_PREC_INTERNETCONTROL 0xc0#define IPTOS_PREC_CRITIC_ECP 0xa0#define IPTOS_PREC_FLASHOVERRIDE 0x80#define IPTOS_PREC_FLASH 0x60#define IPTOS_PREC_IMMEDIATE 0x40#define IPTOS_PREC_PRIORITY 0x20#define IPTOS_PREC_ROUTINE 0x00#define MAXTTL 255enum { IPPROTO_IP = 0, /* Dummy protocol for TCP */ IPPROTO_ICMP = 1, /* Internet Control Message Protocol */ IPPROTO_IGMP = 2, /* Internet Group Management Protocol */ IPPROTO_IPIP = 4, /* IPIP tunnels (older KA9Q tunnels use 94) */ IPPROTO_TCP = 6, /* Transmission Control Protocol */ IPPROTO_EGP = 8, /* Exterior Gateway Protocol */ IPPROTO_PUP = 12, /* PUP protocol */ IPPROTO_UDP = 17, /* User Datagram Protocol */ IPPROTO_IDP = 22, /* XNS IDP protocol */ IPPROTO_RSVP = 46, /* RSVP protocol */ IPPROTO_GRE = 47, /* Cisco GRE tunnels (rfc 1701,1702) */ IPPROTO_IPV6 = 41, /* IPv6-in-IPv4 tunnelling */ IPPROTO_ESP = 50, /* Encapsulation Security Payload protocol */ IPPROTO_AH = 51, /* Authentication Header protocol */ IPPROTO_PIM = 103, /* Protocol Independent Multicast */ IPPROTO_COMP = 108, /* Compression Header protocol */ IPPROTO_SCTP = 132, /* Stream Control Transport Protocol */ IPPROTO_RAW = 255, /* Raw IP packets */ IPPROTO_MAX};struct iphdr {#if defined(__LITTLE_ENDIAN_BITFIELD) __u8 ihl:4, version:4;#elif defined (__BIG_ENDIAN_BITFIELD) __u8 version:4, ihl:4;#else#error "Please fix <asm/byteorder.h>"#endif __u8 tos; __u16 tot_len; __u16 id; __u16 frag_off; __u8 ttl; __u8 protocol; __u16 check; __u32 saddr; __u32 daddr; /*The options start here. */};struct ip_auth_hdr { __u8 nexthdr; __u8 hdrlen; /* This one is measured in 32 bit units! */ __u16 reserved; __u32 spi; __u32 seq_no; /* Sequence number */ __u8 auth_data[0]; /* Variable len but >=4. Mind the 64 bit alignment! */};struct ip_esp_hdr { __u32 spi; __u32 seq_no; /* Sequence number */ __u8 enc_data[0]; /* Variable len but >=8. Mind the 64 bit alignment! */};struct ip_comp_hdr { __u8 nexthdr; __u8 flags; __u16 cpi;};#define LOOPBACK(x) (((x) & htonl(0xff000000)) == htonl(0x7f000000))#define MULTICAST(x) (((x) & htonl(0xf0000000)) == htonl(0xe0000000))#define BADCLASS(x) (((x) & htonl(0xf0000000)) == htonl(0xf0000000))#define ZERONET(x) (((x) & htonl(0xff000000)) == htonl(0x00000000))#define LOCAL_MCAST(x) (((x) & htonl(0xFFFFFF00)) == htonl(0xE0000000))/* tcp.h */#define TCPOPT_NOP 1 /* Padding */#define TCPOPT_EOL 0 /* End of options */#define TCPOPT_MSS 2 /* Segment size negotiating */#define TCPOPT_WINDOW 3 /* Window scaling */#define TCPOPT_SACK_PERM 4 /* SACK Permitted */#define TCPOPT_SACK 5 /* SACK Block */#define TCPOPT_TIMESTAMP 8 /* Better RTT estimations/PAWS */#define TCPOLEN_MSS 4#define TCPOLEN_WINDOW 3#define TCPOLEN_SACK_PERM 2#define TCPOLEN_TIMESTAMP 10/* But this is what stacks really send out. */#define TCPOLEN_TSTAMP_ALIGNED 12#define TCPOLEN_WSCALE_ALIGNED 4#define TCPOLEN_SACKPERM_ALIGNED 4#define TCPOLEN_SACK_BASE 2#define TCPOLEN_SACK_BASE_ALIGNED 4#define TCPOLEN_SACK_PERBLOCK 8struct tcphdr { __u16 source; __u16 dest; __u32 seq; __u32 ack_seq;#if defined(__LITTLE_ENDIAN_BITFIELD) __u16 res1:4, doff:4, fin:1, syn:1, rst:1, psh:1, ack:1, urg:1, ece:1, cwr:1;#elif defined(__BIG_ENDIAN_BITFIELD) __u16 doff:4, res1:4, cwr:1, ece:1, urg:1, ack:1, psh:1, rst:1, syn:1, fin:1;#else#error "Adjust your <asm/byteorder.h> defines"#endif __u16 window; __u16 check; __u16 urg_ptr;};union tcp_word_hdr { struct tcphdr hdr; __u32 words[5];}; #define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words [3]) enum { TCP_FLAG_CWR = __constant_htonl(0x00800000), TCP_FLAG_ECE = __constant_htonl(0x00400000), TCP_FLAG_URG = __constant_htonl(0x00200000), TCP_FLAG_ACK = __constant_htonl(0x00100000), TCP_FLAG_PSH = __constant_htonl(0x00080000), TCP_FLAG_RST = __constant_htonl(0x00040000), TCP_FLAG_SYN = __constant_htonl(0x00020000), TCP_FLAG_FIN = __constant_htonl(0x00010000), TCP_RESERVED_BITS = __constant_htonl(0x0F000000), TCP_DATA_OFFSET = __constant_htonl(0xF0000000)}; struct tcp_sack_block { __u32 start_seq; __u32 end_seq;};/* is s2<=s1<=s3 ? */static inline int between(__u32 seq1, __u32 seq2, __u32 seq3){ return seq3 - seq2 >= seq1 - seq2;}static inline int before(__u32 seq1, __u32 seq2){ return (__s32)(seq1-seq2) < 0;}static inline int after(__u32 seq1, __u32 seq2){ return (__s32)(seq2-seq1) < 0;}/* udp */struct udphdr { __u16 source; __u16 dest; __u16 len; __u16 check;};/* icmp */#define ICMP_ECHOREPLY 0 /* Echo Reply */#define ICMP_DEST_UNREACH 3 /* Destination Unreachable */#define ICMP_SOURCE_QUENCH 4 /* Source Quench */#define ICMP_REDIRECT 5 /* Redirect (change route) */#define ICMP_ECHO 8 /* Echo Request */#define ICMP_TIME_EXCEEDED 11 /* Time Exceeded */#define ICMP_PARAMETERPROB 12 /* Parameter Problem */#define ICMP_TIMESTAMP 13 /* Timestamp Request */#define ICMP_TIMESTAMPREPLY 14 /* Timestamp Reply */#define ICMP_INFO_REQUEST 15 /* Information Request */#define ICMP_INFO_REPLY 16 /* Information Reply */#define ICMP_ADDRESS 17 /* Address Mask Request */#define ICMP_ADDRESSREPLY 18 /* Address Mask Reply */#define NR_ICMP_TYPES 18/* Codes for UNREACH. */#define ICMP_NET_UNREACH 0 /* Network Unreachable */#define ICMP_HOST_UNREACH 1 /* Host Unreachable */#define ICMP_PROT_UNREACH 2 /* Protocol Unreachable */#define ICMP_PORT_UNREACH 3 /* Port Unreachable */#define ICMP_FRAG_NEEDED 4 /* Fragmentation Needed/DF set */#define ICMP_SR_FAILED 5 /* Source Route failed */#define ICMP_NET_UNKNOWN 6#define ICMP_HOST_UNKNOWN 7#define ICMP_HOST_ISOLATED 8#define ICMP_NET_ANO 9#define ICMP_HOST_ANO 10#define ICMP_NET_UNR_TOS 11#define ICMP_HOST_UNR_TOS 12#define ICMP_PKT_FILTERED 13 /* Packet filtered */#define ICMP_PREC_VIOLATION 14 /* Precedence violation */#define ICMP_PREC_CUTOFF 15 /* Precedence cut off */#define NR_ICMP_UNREACH 15 /* instead of hardcoding immediate value *//* Codes for REDIRECT. */#define ICMP_REDIR_NET 0 /* Redirect Net */#define ICMP_REDIR_HOST 1 /* Redirect Host */#define ICMP_REDIR_NETTOS 2 /* Redirect Net for TOS */#define ICMP_REDIR_HOSTTOS 3 /* Redirect Host for TOS *//* Codes for TIME_EXCEEDED. */#define ICMP_EXC_TTL 0 /* TTL count exceeded */#define ICMP_EXC_FRAGTIME 1 /* Fragment Reass time exceeded */struct icmphdr { __u8 type; __u8 code; __u16 checksum; union { struct { __u16 id; __u16 sequence; } echo; __u32 gateway; struct { __u16 __unused; __u16 mtu; } frag; } un;};/* in_route.h *//* IPv4 routing cache flags */#define RTCF_DEAD RTNH_F_DEAD#define RTCF_ONLINK RTNH_F_ONLINK/* Obsolete flag. About to be deleted */#define RTCF_NOPMTUDISC RTM_F_NOPMTUDISC#define RTCF_NOTIFY 0x00010000#define RTCF_DIRECTDST 0x00020000#define RTCF_REDIRECTED 0x00040000#define RTCF_TPROXY 0x00080000
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -