2015-11-15 22:07:25 -08:00
|
|
|
|
/*
|
2019-02-13 15:34:21 -08:00
|
|
|
|
* Copyright (c) 2015, 2016, 2017, 2019 Nicira, Inc.
|
2015-11-15 22:07:25 -08:00
|
|
|
|
*
|
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
|
|
*
|
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
*
|
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CONNTRACK_H
|
|
|
|
|
|
#define CONNTRACK_H 1
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
2019-05-09 08:15:07 -07:00
|
|
|
|
#include "cmap.h"
|
2016-05-16 12:59:23 -07:00
|
|
|
|
#include "latch.h"
|
2015-11-15 22:07:25 -08:00
|
|
|
|
#include "odp-netlink.h"
|
|
|
|
|
|
#include "openvswitch/hmap.h"
|
2016-05-16 12:59:23 -07:00
|
|
|
|
#include "openvswitch/list.h"
|
2015-11-15 22:07:25 -08:00
|
|
|
|
#include "openvswitch/thread.h"
|
|
|
|
|
|
#include "openvswitch/types.h"
|
|
|
|
|
|
#include "ovs-atomic.h"
|
2017-05-30 10:49:25 -07:00
|
|
|
|
#include "ovs-thread.h"
|
|
|
|
|
|
#include "packets.h"
|
2018-01-09 15:44:54 -08:00
|
|
|
|
#include "hindex.h"
|
2015-11-15 22:07:25 -08:00
|
|
|
|
|
|
|
|
|
|
/* Userspace connection tracker
|
|
|
|
|
|
* ============================
|
|
|
|
|
|
*
|
|
|
|
|
|
* This is a connection tracking module that keeps all the state in userspace.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Usage
|
|
|
|
|
|
* =====
|
|
|
|
|
|
*
|
2019-05-09 08:15:07 -07:00
|
|
|
|
* struct conntrack *ct;
|
2015-11-15 22:07:25 -08:00
|
|
|
|
*
|
|
|
|
|
|
* Initialization:
|
|
|
|
|
|
*
|
2019-05-09 08:15:07 -07:00
|
|
|
|
* ct = conntrack_init();
|
2015-11-15 22:07:25 -08:00
|
|
|
|
*
|
|
|
|
|
|
* To send a group of packets through the connection tracker:
|
|
|
|
|
|
*
|
2019-05-09 08:15:07 -07:00
|
|
|
|
* conntrack_execute(ct, pkt_batch, ...);
|
2015-11-15 22:07:25 -08:00
|
|
|
|
*
|
2019-05-09 08:15:07 -07:00
|
|
|
|
* Thread-safety:
|
2015-11-15 22:07:25 -08:00
|
|
|
|
*
|
|
|
|
|
|
* conntrack_execute() can be called by multiple threads simultaneoulsy.
|
2019-05-09 08:15:07 -07:00
|
|
|
|
*
|
|
|
|
|
|
* Shutdown:
|
|
|
|
|
|
*
|
|
|
|
|
|
* 1/ Shutdown packet input to the datapath
|
|
|
|
|
|
* 2/ Destroy PMD threads after quiescence.
|
|
|
|
|
|
* 3/ conntrack_destroy(ct);
|
2015-11-15 22:07:25 -08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
struct dp_packet_batch;
|
|
|
|
|
|
|
|
|
|
|
|
struct conntrack;
|
|
|
|
|
|
|
2019-02-14 13:15:08 -08:00
|
|
|
|
union ct_addr {
|
|
|
|
|
|
ovs_be32 ipv4;
|
|
|
|
|
|
struct in6_addr ipv6;
|
2017-05-30 10:49:25 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum nat_action_e {
|
|
|
|
|
|
NAT_ACTION_SRC = 1 << 0,
|
|
|
|
|
|
NAT_ACTION_SRC_PORT = 1 << 1,
|
|
|
|
|
|
NAT_ACTION_DST = 1 << 2,
|
|
|
|
|
|
NAT_ACTION_DST_PORT = 1 << 3,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct nat_action_info_t {
|
2019-02-14 13:15:08 -08:00
|
|
|
|
union ct_addr min_addr;
|
|
|
|
|
|
union ct_addr max_addr;
|
2017-05-30 10:49:25 -07:00
|
|
|
|
uint16_t min_port;
|
|
|
|
|
|
uint16_t max_port;
|
|
|
|
|
|
uint16_t nat_action;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-05-02 21:34:04 -07:00
|
|
|
|
struct conntrack *conntrack_init(void);
|
2015-11-15 22:07:25 -08:00
|
|
|
|
void conntrack_destroy(struct conntrack *);
|
|
|
|
|
|
|
2017-12-04 08:13:06 -08:00
|
|
|
|
int conntrack_execute(struct conntrack *ct, struct dp_packet_batch *pkt_batch,
|
|
|
|
|
|
ovs_be16 dl_type, bool force, bool commit, uint16_t zone,
|
|
|
|
|
|
const uint32_t *setmark,
|
2017-05-30 10:49:27 -07:00
|
|
|
|
const struct ovs_key_ct_labels *setlabel,
|
2017-12-04 08:13:06 -08:00
|
|
|
|
ovs_be16 tp_src, ovs_be16 tp_dst, const char *helper,
|
2017-08-24 22:16:53 -07:00
|
|
|
|
const struct nat_action_info_t *nat_action_info,
|
|
|
|
|
|
long long now);
|
2018-01-19 14:21:51 -05:00
|
|
|
|
void conntrack_clear(struct dp_packet *packet);
|
2015-11-15 22:07:25 -08:00
|
|
|
|
|
|
|
|
|
|
struct conntrack_dump {
|
|
|
|
|
|
struct conntrack *ct;
|
|
|
|
|
|
unsigned bucket;
|
2019-05-09 08:15:07 -07:00
|
|
|
|
struct cmap_position cm_pos;
|
2015-11-15 22:07:25 -08:00
|
|
|
|
bool filter_zone;
|
|
|
|
|
|
uint16_t zone;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct ct_dpif_entry;
|
2018-02-12 14:02:37 -08:00
|
|
|
|
struct ct_dpif_tuple;
|
2015-11-15 22:07:25 -08:00
|
|
|
|
|
|
|
|
|
|
int conntrack_dump_start(struct conntrack *, struct conntrack_dump *,
|
2017-08-01 20:12:03 -07:00
|
|
|
|
const uint16_t *pzone, int *);
|
2015-11-15 22:07:25 -08:00
|
|
|
|
int conntrack_dump_next(struct conntrack_dump *, struct ct_dpif_entry *);
|
|
|
|
|
|
int conntrack_dump_done(struct conntrack_dump *);
|
2015-11-15 22:07:25 -08:00
|
|
|
|
|
|
|
|
|
|
int conntrack_flush(struct conntrack *, const uint16_t *zone);
|
2018-02-12 14:02:37 -08:00
|
|
|
|
int conntrack_flush_tuple(struct conntrack *, const struct ct_dpif_tuple *,
|
|
|
|
|
|
uint16_t zone);
|
2018-01-08 15:18:42 -08:00
|
|
|
|
int conntrack_set_maxconns(struct conntrack *ct, uint32_t maxconns);
|
|
|
|
|
|
int conntrack_get_maxconns(struct conntrack *ct, uint32_t *maxconns);
|
2018-01-08 15:18:43 -08:00
|
|
|
|
int conntrack_get_nconns(struct conntrack *ct, uint32_t *nconns);
|
2019-09-25 14:09:41 -07:00
|
|
|
|
int conntrack_set_tcp_seq_chk(struct conntrack *ct, bool enabled);
|
|
|
|
|
|
bool conntrack_get_tcp_seq_chk(struct conntrack *ct);
|
2019-02-13 15:34:21 -08:00
|
|
|
|
struct ipf *conntrack_ipf_ctx(struct conntrack *ct);
|
2015-11-15 22:07:25 -08:00
|
|
|
|
|
|
|
|
|
|
#endif /* conntrack.h */
|