]> git.proxmox.com Git - mirror_ovs.git/blob - lib/ct-dpif.h
Userspace datapath: Add fragmentation handling.
[mirror_ovs.git] / lib / ct-dpif.h
1 /*
2 * Copyright (c) 2015, 2018 Nicira, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef CT_DPIF_H
18 #define CT_DPIF_H
19
20 #include "openvswitch/types.h"
21 #include "packets.h"
22
23 union ct_dpif_inet_addr {
24 ovs_be32 ip;
25 ovs_be32 ip6[4];
26 struct in_addr in;
27 struct in6_addr in6;
28 };
29
30 struct ct_dpif_tuple {
31 uint16_t l3_type; /* Address family. */
32 uint8_t ip_proto;
33 union ct_dpif_inet_addr src;
34 union ct_dpif_inet_addr dst;
35 union {
36 ovs_be16 src_port;
37 ovs_be16 icmp_id;
38 };
39 union {
40 ovs_be16 dst_port;
41 struct {
42 uint8_t icmp_type;
43 uint8_t icmp_code;
44 };
45 };
46 };
47 BUILD_ASSERT_DECL(sizeof(struct ct_dpif_tuple) % 8 == 0);
48
49 struct ct_dpif_counters {
50 uint64_t packets;
51 uint64_t bytes;
52 };
53
54 /* Nanoseconds from January 1, 1970 */
55 struct ct_dpif_timestamp {
56 /* When the entry was created */
57 uint64_t start;
58 /* When the entry was deleted */
59 uint64_t stop;
60 };
61
62 #define CT_DPIF_TCP_STATES \
63 CT_DPIF_TCP_STATE(CLOSED) \
64 CT_DPIF_TCP_STATE(LISTEN) \
65 CT_DPIF_TCP_STATE(SYN_SENT) \
66 CT_DPIF_TCP_STATE(SYN_RECV) \
67 CT_DPIF_TCP_STATE(ESTABLISHED) \
68 CT_DPIF_TCP_STATE(CLOSE_WAIT) \
69 CT_DPIF_TCP_STATE(FIN_WAIT_1) \
70 CT_DPIF_TCP_STATE(CLOSING) \
71 CT_DPIF_TCP_STATE(LAST_ACK) \
72 CT_DPIF_TCP_STATE(FIN_WAIT_2) \
73 CT_DPIF_TCP_STATE(TIME_WAIT) \
74 CT_DPIF_TCP_STATE(MAX_NUM)
75
76 enum ct_dpif_tcp_state {
77 #define CT_DPIF_TCP_STATE(STATE) CT_DPIF_TCPS_##STATE,
78 CT_DPIF_TCP_STATES
79 #undef CT_DPIF_TCP_STATE
80 };
81
82 extern const char *ct_dpif_tcp_state_string[];
83
84 #define CT_DPIF_TCP_FLAGS \
85 CT_DPIF_TCP_FLAG(WINDOW_SCALE) \
86 CT_DPIF_TCP_FLAG(SACK_PERM) \
87 CT_DPIF_TCP_FLAG(CLOSE_INIT) \
88 CT_DPIF_TCP_FLAG(BE_LIBERAL) \
89 CT_DPIF_TCP_FLAG(DATA_UNACKNOWLEDGED) \
90 CT_DPIF_TCP_FLAG(MAXACK_SET) \
91
92 enum ct_dpif_tcp_flags_count_ {
93 #define CT_DPIF_TCP_FLAG(FLAG) FLAG##_COUNT_,
94 CT_DPIF_TCP_FLAGS
95 #undef CT_DPIF_TCP_FLAG
96 };
97
98 enum ct_dpif_tcp_flags {
99 #define CT_DPIF_TCP_FLAG(FLAG) CT_DPIF_TCPF_##FLAG = (1 << FLAG##_COUNT_),
100 CT_DPIF_TCP_FLAGS
101 #undef CT_DPIF_TCP_FLAG
102 };
103
104 struct ct_dpif_protoinfo {
105 uint16_t proto; /* IPPROTO_* */
106 union {
107 struct {
108 uint8_t state_orig;
109 uint8_t state_reply;
110 uint8_t wscale_orig;
111 uint8_t wscale_reply;
112 uint8_t flags_orig;
113 uint8_t flags_reply;
114 } tcp;
115 };
116 };
117
118 struct ct_dpif_helper {
119 char *name;
120 };
121
122 #define CT_DPIF_STATUS_FLAGS \
123 CT_DPIF_STATUS_FLAG(EXPECTED) \
124 CT_DPIF_STATUS_FLAG(SEEN_REPLY) \
125 CT_DPIF_STATUS_FLAG(ASSURED) \
126 CT_DPIF_STATUS_FLAG(CONFIRMED) \
127 CT_DPIF_STATUS_FLAG(SRC_NAT) \
128 CT_DPIF_STATUS_FLAG(DST_NAT) \
129 CT_DPIF_STATUS_FLAG(SEQ_ADJUST) \
130 CT_DPIF_STATUS_FLAG(SRC_NAT_DONE) \
131 CT_DPIF_STATUS_FLAG(DST_NAT_DONE) \
132 CT_DPIF_STATUS_FLAG(DYING) \
133 CT_DPIF_STATUS_FLAG(FIXED_TIMEOUT) \
134 CT_DPIF_STATUS_FLAG(TEMPLATE) \
135 CT_DPIF_STATUS_FLAG(UNTRACKED) \
136
137 enum ct_dpif_status_flags_count_ {
138 #define CT_DPIF_STATUS_FLAG(FLAG) FLAG##_COUNT_,
139 CT_DPIF_STATUS_FLAGS
140 #undef CT_DPIF_STATUS_FLAG
141 };
142
143 enum ct_dpif_status_flags {
144 #define CT_DPIF_STATUS_FLAG(FLAG) CT_DPIF_STATUS_##FLAG = (1 << FLAG##_COUNT_),
145 CT_DPIF_STATUS_FLAGS
146 #undef CT_DPIF_STATUS_FLAG
147 };
148
149 struct ct_dpif_entry {
150 /* Const members. */
151 struct ct_dpif_tuple tuple_orig;
152 struct ct_dpif_tuple tuple_reply;
153 struct ct_dpif_tuple tuple_master;
154 struct ct_dpif_helper helper;
155 uint32_t id;
156 uint16_t zone;
157
158 /* Modifiable members. */
159
160 struct ct_dpif_counters counters_orig;
161 struct ct_dpif_counters counters_reply;
162
163 struct ct_dpif_timestamp timestamp;
164 struct ct_dpif_protoinfo protoinfo;
165
166 ovs_u128 labels;
167 bool have_labels;
168 uint32_t status;
169 /* Timeout for this entry in seconds */
170 uint32_t timeout;
171 uint32_t mark;
172 uint32_t bkt; /* CT bucket number. */
173 };
174
175 enum {
176 CT_STATS_UDP,
177 CT_STATS_TCP,
178 CT_STATS_SCTP,
179 CT_STATS_ICMP,
180 CT_STATS_ICMPV6,
181 CT_STATS_UDPLITE,
182 CT_STATS_DCCP,
183 CT_STATS_IGMP,
184 CT_STATS_OTHER,
185 CT_STATS_MAX,
186 };
187
188 struct dpif;
189 struct dpif_ipf_status;
190 struct ipf_dump_ctx;
191
192 struct ct_dpif_dump_state {
193 struct dpif *dpif;
194 };
195
196 struct ct_dpif_zone_limit {
197 uint16_t zone;
198 uint32_t limit; /* Limit on number of entries. */
199 uint32_t count; /* Current number of entries. */
200 struct ovs_list node;
201 };
202
203 int ct_dpif_dump_start(struct dpif *, struct ct_dpif_dump_state **,
204 const uint16_t *zone, int *);
205 int ct_dpif_dump_next(struct ct_dpif_dump_state *, struct ct_dpif_entry *);
206 int ct_dpif_dump_done(struct ct_dpif_dump_state *);
207 int ct_dpif_flush(struct dpif *, const uint16_t *zone,
208 const struct ct_dpif_tuple *);
209 int ct_dpif_set_maxconns(struct dpif *dpif, uint32_t maxconns);
210 int ct_dpif_get_maxconns(struct dpif *dpif, uint32_t *maxconns);
211 int ct_dpif_get_nconns(struct dpif *dpif, uint32_t *nconns);
212 int ct_dpif_set_limits(struct dpif *dpif, const uint32_t *default_limit,
213 const struct ovs_list *);
214 int ct_dpif_get_limits(struct dpif *dpif, uint32_t *default_limit,
215 const struct ovs_list *, struct ovs_list *);
216 int ct_dpif_del_limits(struct dpif *dpif, const struct ovs_list *);
217 int ct_dpif_ipf_set_enabled(struct dpif *, bool v6, bool enable);
218 int ct_dpif_ipf_set_min_frag(struct dpif *, bool v6, uint32_t min_frag);
219 int ct_dpif_ipf_set_max_nfrags(struct dpif *, uint32_t max_frags);
220 int ct_dpif_ipf_get_status(struct dpif *dpif,
221 struct dpif_ipf_status *dpif_ipf_status);
222 int ct_dpif_ipf_dump_start(struct dpif *dpif, struct ipf_dump_ctx **);
223 int ct_dpif_ipf_dump_next(struct dpif *dpif, void *, char **);
224 int ct_dpif_ipf_dump_done(struct dpif *dpif, void *);
225 void ct_dpif_entry_uninit(struct ct_dpif_entry *);
226 void ct_dpif_format_entry(const struct ct_dpif_entry *, struct ds *,
227 bool verbose, bool print_stats);
228 void ct_dpif_format_tuple(struct ds *, const struct ct_dpif_tuple *);
229 uint8_t ct_dpif_coalesce_tcp_state(uint8_t state);
230 void ct_dpif_format_tcp_stat(struct ds *, int, int);
231 bool ct_dpif_parse_tuple(struct ct_dpif_tuple *, const char *s, struct ds *);
232 void ct_dpif_push_zone_limit(struct ovs_list *, uint16_t zone, uint32_t limit,
233 uint32_t count);
234 void ct_dpif_free_zone_limits(struct ovs_list *);
235 bool ct_dpif_parse_zone_limit_tuple(const char *s, uint16_t *pzone,
236 uint32_t *plimit, struct ds *);
237 void ct_dpif_format_zone_limits(uint32_t default_limit,
238 const struct ovs_list *, struct ds *);
239
240 #endif /* CT_DPIF_H */