Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
tcp.h
1 /*
2  * Copyright (c) 2017-2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef HICN_PROTOCOL_TCP_H
17 #define HICN_PROTOCOL_TCP_H
18 
19 #include "../base.h"
20 #include "../common.h"
21 #include "../name.h"
22 
23 /*
24  * The length of the TCP header struct must be 20 bytes.
25  */
26 #define EXPECTED_TCP_HDRLEN 20
27 
28 /*
29  * NOTE: bitfields are problematic for portability reasons. There are provided
30  * here for reference and documentation purposes, we might just provide a macro
31  * to disable and use it instead of __BYTE_ORDER__.
32  */
33 typedef struct
34 {
35  u16 sport;
36  u16 dport;
37  union
38  {
39  u32 seq;
40  hicn_name_suffix_t name_suffix;
41  };
42  union
43  {
44  u32 seq_ack;
45  struct
46  {
47  hicn_pathlabel_t pathlabel;
48  u8 pad[3];
49  };
50  };
51 
52  union
53  {
54  struct
55  {
56  u8 data_offset_and_reserved;
57  u8 flags;
58  };
59 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
60  struct
61  {
62  u16 reserved:4;
63  u16 doff:4;
64  u16 fin:1;
65  u16 syn:1;
66  u16 rst:1;
67  u16 psh:1;
68  u16 ack:1;
69  u16 urg:1;
70  u16 ece:1;
71  u16 cwr:1;
72  };
73  struct
74  { /* __ denotes unchanged bitfields */
75  u16 timescale:4;
76  u16 __doff:4;
77  u16 __fin:1;
78  u16 __syn:1;
79  u16 __rst:1;
80  u16 sig:1;
81  u16 __ack:1;
82  u16 man:1;
83  u16 id:1;
84  u16 __cwr:1;
85  };
86 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
87  struct
88  {
89  u16 doff:4;
90  u16 reserved:4;
91  u16 cwr:1;
92  u16 ece:1;
93  u16 urg:1;
94  u16 ack:1;
95  u16 psh:1;
96  u16 rst:1;
97  u16 syn:1;
98  u16 fin:1;
99  };
100  struct
101  {
102  u16 __doff:4;
103  u16 timescale:4;
104  u16 __cwr:1;
105  u16 id:1 u16 man:1;
106  u16 __ack:1;
107  u16 sig:1;
108  u16 __rst:1;
109  u16 __syn:1;
110  u16 __fin:1;
111  };
112 #endif
113  };
114  union
115  {
116  u16 window;
117  u16 ldr;
118  };
119  u16 csum;
120  union
121  {
122  u16 urg_ptr;
123  u16 lifetime;
124  };
125 } _tcp_header_t;
126 
127 #define TCP_HDRLEN sizeof(_tcp_header_t)
128 static_assert (EXPECTED_TCP_HDRLEN == TCP_HDRLEN,
129  "Size of TCP struct does not match its expected size.");
130 
131 /* TCP flags bit 0 first. */
132 #define foreach_tcp_flag \
133  _ (FIN) \
134  _ (SYN) \
135  _ (RST) \
136  _ (PSH) \
137  _ (ACK) \
138  _ (URG) \
139  _ (ECE) \
140  _ (CWR)
142 enum
143 {
144 #define _(f) HICN_TCP_FLAG_BIT_##f,
145  foreach_tcp_flag
146 #undef _
147  HICN_TCP_N_FLAG_BITS,
148 };
149 
150 enum
151 {
152 #define _(f) HICN_TCP_FLAG_##f = 1 << HICN_TCP_FLAG_BIT_##f,
153  foreach_tcp_flag
154 #undef _
155 };
156 
157 #endif /* HICN_PROTOCOL_TCP_H */
158 
159 /*
160  * fd.io coding-style-patch-verification: ON
161  *
162  * Local Variables:
163  * eval: (c-set-style "gnu")
164  * End:
165  */
_tcp_header_t
Definition: tcp.h:33