Click
Loading...
Searching...
No Matches
tcp.h
1/* -*- c-basic-offset: 4 -*- */
2#ifndef CLICKNET_TCP_H
3#define CLICKNET_TCP_H
4
5/*
6 * <clicknet/tcp.h> -- TCP header definitions, based on one of the BSDs.
7 *
8 * Relevant RFCs include:
9 * RFC793 Transmission Control Protocol
10 * RFC1323 TCP Extensions for High Performance
11 * RFC2018 TCP Selective Acknowledgement Options
12 * RFC2581 TCP Congestion Control
13 * RFC2883 An Extension to the Selective Acknowledgement (SACK) Option
14 * for TCP
15 * RFC3168 The Addition of Explicit Congestion Notification (ECN) to IP
16 * RFC3540 Robust Explicit Congestion Notification (ECN) Signaling with
17 * Nonces
18 * among many others. See "A Roadmap for TCP Specification Documents",
19 * currently an Internet-Draft.
20 */
21
22typedef uint32_t tcp_seq_t;
23
24struct click_tcp {
25 uint16_t th_sport; /* 0-1 source port */
26 uint16_t th_dport; /* 2-3 destination port */
27 tcp_seq_t th_seq; /* 4-7 sequence number */
28 tcp_seq_t th_ack; /* 8-11 acknowledgement number */
29#if CLICK_BYTE_ORDER == CLICK_LITTLE_ENDIAN
30 unsigned th_flags2 : 4; /* 12 more flags */
31 unsigned th_off : 4; /* data offset in words */
32#elif CLICK_BYTE_ORDER == CLICK_BIG_ENDIAN
33 unsigned th_off : 4; /* 12 data offset in words */
34 unsigned th_flags2 : 4; /* more flags */
35#else
36# error "unknown byte order"
37#endif
38#define TH_NS 0x01 /* in 'th_flags2' */
39 uint8_t th_flags; /* 13 flags */
40#define TH_FIN 0x01
41#define TH_SYN 0x02
42#define TH_RST 0x04
43#define TH_PUSH 0x08
44#define TH_ACK 0x10
45#define TH_URG 0x20
46#define TH_ECE 0x40
47#define TH_CWR 0x80
48 uint16_t th_win; /* 14-15 window */
49 uint16_t th_sum; /* 16-17 checksum */
50 uint16_t th_urp; /* 18-19 urgent pointer */
51};
52
53/*
54 * TCP sequence number comparisons
55 */
56
57#define SEQ_LT(x,y) ((int)((x)-(y)) < 0)
58#define SEQ_LEQ(x,y) ((int)((x)-(y)) <= 0)
59#define SEQ_GT(x,y) ((int)((x)-(y)) > 0)
60#define SEQ_GEQ(x,y) ((int)((x)-(y)) >= 0)
61
62/*
63 * TCP options
64 */
65
66#define TCPOPT_EOL 0
67#define TCPOPT_NOP 1
68#define TCPOPT_MAXSEG 2
69#define TCPOLEN_MAXSEG 4
70#define TCPOPT_WSCALE 3
71#define TCPOLEN_WSCALE 3
72#define TCPOPT_SACK_PERMITTED 4
73#define TCPOLEN_SACK_PERMITTED 2
74#define TCPOPT_SACK 5
75#define TCPOPT_TIMESTAMP 8
76#define TCPOLEN_TIMESTAMP 10
77
78struct tcp_opt_timestamp {
79 uint32_t ts_val;
80 uint32_t ts_ecr;
81};
82
83
84#endif