summaryrefslogtreecommitdiff
path: root/platform/include/sce.h
blob: 7d5bf9b56fb623b8da29ff9230833d5f494d8bc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef _SCE_H
#define _SCE_H

#ifdef __cpluscplus
extern "C"
{
#endif

#include <sched.h>

#include "policy.h"
#include "timestamp.h"
#include "packet_io.h"
#include "session_table.h"
#include "global_metrics.h"

#define MAX_THREAD_NUM 128

/******************************************************************************
 * Struct Thread Ctx
 ******************************************************************************/

struct thread_ctx
{
    pthread_t tid;
    int thread_index;

    struct sf_metrics *sf_metrics;
    struct session_table *session_table;

    struct packet_io *ref_io;
    struct sce_ctx *ref_sce_ctx;
    struct thread_metrics thread_metrics;
    struct global_metrics *ref_global_metrics;
    struct policy_enforcer *ref_enforcer;

    int session_table_need_reset;
    int thread_is_runing;
    uint64_t tx_packets_ipid;
};

/******************************************************************************
 * Struct Metadata
 ******************************************************************************/

struct metadata
{
    int write_ref;
    uint64_t session_id;
    uint32_t rehash_index;

    char *raw_data; // refer to current packet data
    int raw_len;
    uint16_t l7offset;

    int direction; // 1: E2I; 0: I2E
    int is_ctrl_pkt;
    int is_decrypted;

    struct sids sids;
    struct route_ctx route_ctx;
};

int metadata_isempty(struct metadata *meta);
void metadata_copy(struct metadata *dst, struct metadata *src);

char *memdup(const char *src, int len);

/******************************************************************************
 * Struct Session Ctx
 ******************************************************************************/

struct session_ctx
{
    uint64_t session_id;
    char *session_addr;

    // dup from received control packet, for sending control packet
    char *ctrl_packet_header_data;
    uint16_t ctrl_packet_header_len;

    uint16_t vxlan_src_port;

    struct four_tuple inner_tuple4;
    struct mutable_array rule_ids;

    struct metadata decrypted_meta_i2e;
    struct metadata decrypted_meta_e2i;
    struct metadata raw_meta_i2e;
    struct metadata raw_meta_e2i;
    struct metadata ctrl_meta;

    struct selected_chaining *chaining_raw;
    struct selected_chaining *chaining_decrypted;

    struct thread_ctx *ref_thread_ctx;
};

struct session_ctx *session_ctx_new();
void session_ctx_free(struct session_ctx *ctx);

/******************************************************************************
 * Struct SCE Ctx
 ******************************************************************************/

struct sce_ctx
{
    int enable_debug;
    int enable_send_log;
    int firewall_sids;
    int nr_worker_threads;
    int ts_update_interval_ms;
    int cpu_affinity_mask[MAX_THREAD_NUM];

    cpu_set_t coremask;
    struct timestamp *ts;
    struct packet_io *io;
    struct global_metrics *metrics;
    struct policy_enforcer *enforcer;
    struct thread_ctx work_threads[MAX_THREAD_NUM];
};

struct sce_ctx *sce_ctx_create(const char *profile);
void sce_ctx_destory(struct sce_ctx *ctx);

#ifdef __cpluscplus
}
#endif

#endif