2 * Copyright (c) 2015, 2016, 2017, 2019 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 #include "odp-netlink.h"
26 #include "openvswitch/hmap.h"
27 #include "openvswitch/list.h"
28 #include "openvswitch/thread.h"
29 #include "openvswitch/types.h"
30 #include "ovs-atomic.h"
31 #include "ovs-thread.h"
35 /* Userspace connection tracker
36 * ============================
38 * This is a connection tracking module that keeps all the state in userspace.
43 * struct conntrack *ct;
47 * ct = conntrack_init();
49 * To send a group of packets through the connection tracker:
51 * conntrack_execute(ct, pkt_batch, ...);
55 * conntrack_execute() can be called by multiple threads simultaneoulsy.
59 * 1/ Shutdown packet input to the datapath
60 * 2/ Destroy PMD threads after quiescence.
61 * 3/ conntrack_destroy(ct);
64 struct dp_packet_batch
;
74 NAT_ACTION_SRC
= 1 << 0,
75 NAT_ACTION_SRC_PORT
= 1 << 1,
76 NAT_ACTION_DST
= 1 << 2,
77 NAT_ACTION_DST_PORT
= 1 << 3,
80 struct nat_action_info_t
{
81 union ct_addr min_addr
;
82 union ct_addr max_addr
;
88 struct conntrack
*conntrack_init(void);
89 void conntrack_destroy(struct conntrack
*);
91 int conntrack_execute(struct conntrack
*ct
, struct dp_packet_batch
*pkt_batch
,
92 ovs_be16 dl_type
, bool force
, bool commit
, uint16_t zone
,
93 const uint32_t *setmark
,
94 const struct ovs_key_ct_labels
*setlabel
,
95 ovs_be16 tp_src
, ovs_be16 tp_dst
, const char *helper
,
96 const struct nat_action_info_t
*nat_action_info
,
97 long long now
, uint32_t tp_id
);
98 void conntrack_clear(struct dp_packet
*packet
);
100 struct conntrack_dump
{
101 struct conntrack
*ct
;
103 struct cmap_position cm_pos
;
108 struct conntrack_zone_limit
{
112 uint32_t zone_limit_seq
; /* Used to disambiguate zone limit counts. */
115 struct timeout_policy
{
116 struct hmap_node node
;
117 struct ct_dpif_timeout_policy policy
;
122 DEFAULT_ZONE
= -1, /* Default zone for zone limit management. */
127 struct ct_dpif_entry
;
128 struct ct_dpif_tuple
;
130 int conntrack_dump_start(struct conntrack
*, struct conntrack_dump
*,
131 const uint16_t *pzone
, int *);
132 int conntrack_dump_next(struct conntrack_dump
*, struct ct_dpif_entry
*);
133 int conntrack_dump_done(struct conntrack_dump
*);
135 int conntrack_flush(struct conntrack
*, const uint16_t *zone
);
136 int conntrack_flush_tuple(struct conntrack
*, const struct ct_dpif_tuple
*,
138 int conntrack_set_maxconns(struct conntrack
*ct
, uint32_t maxconns
);
139 int conntrack_get_maxconns(struct conntrack
*ct
, uint32_t *maxconns
);
140 int conntrack_get_nconns(struct conntrack
*ct
, uint32_t *nconns
);
141 int conntrack_set_tcp_seq_chk(struct conntrack
*ct
, bool enabled
);
142 bool conntrack_get_tcp_seq_chk(struct conntrack
*ct
);
143 struct ipf
*conntrack_ipf_ctx(struct conntrack
*ct
);
144 struct conntrack_zone_limit
zone_limit_get(struct conntrack
*ct
,
146 int zone_limit_update(struct conntrack
*ct
, int32_t zone
, uint32_t limit
);
147 int zone_limit_delete(struct conntrack
*ct
, uint16_t zone
);
149 #endif /* conntrack.h */