summaryrefslogtreecommitdiffstats
path: root/VNFs/DPPD-PROX/dpi/dpi.h
blob: 5ce1015d4cc19c3e4d168a92454e7d24c5557f59 (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
/*
// Copyright (c) 2010-2017 Intel Corporation
//
// 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 _DPI_H_
#define _DPI_H_

#include <sys/time.h>
#include <inttypes.h>
#include <stddef.h>

struct flow_info {
	uint32_t ip_src;
	uint32_t ip_dst;
	uint8_t ip_proto;
	uint16_t port_src;
	uint16_t port_dst;
	uint8_t reservered[3];
} __attribute__((packed));

struct dpi_payload {
	uint8_t  *payload;
	uint16_t len;
	uint16_t client_to_server;
	struct timeval tv;
};

struct dpi_engine {
	/* Returns 0 on success, This function is called from an
	   arbitrary thread before any other function in this struct
	   is called. */
	int (*dpi_init)(uint32_t thread_count, int argc, const char *argv[]);
	/* Return the size that should be allocated in the flow
	   table. It is the sizeof(*flow_data) passed to
	   dpi_process(). */
	size_t (*dpi_get_flow_entry_size)(void);
	/* Called before the flow entry is expired. */
	void (*dpi_flow_expire)(void *flow_data);
	/* start function called from a DPI thread itself. The opaque
	   pointer returned here will be passed to dpi_thread_stop and
	   dpi_process. */
	void *(*dpi_thread_start)(void);
	/* Stop function called from a DPI thread itself. */
	void (*dpi_thread_stop)(void *opaque);
	/* Processing function to perform actual DPI work. struct
	   flow_info contains the 5 tuple, flow_data is the entry in
	   the flow table which has a size specified by
	   dpi_get_flow_entry_size(). The payload (together with the
	   time and the direction) is passed through the payload
	   parameter. DPI results are returned by the results
	   array. The function returns 0 on success. */
	int (*dpi_process)(void *opaque, struct flow_info *fi, void *flow_data,
			   struct dpi_payload *payload, uint32_t results[],
			   size_t *result_len);
	/* Called once at cleanup. */
	void (*dpi_finish)(void);
	/* Function used for printing. */
	int (*dpi_print)(const char *fmt, ...);
};

/* Returns the implementation of a dpi_engine. */
struct dpi_engine *get_dpi_engine(void);

#endif /* _DPI_H_ */