suricata
util-ebpf.h
Go to the documentation of this file.
1 /* Copyright (C) 2018 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Eric Leblond <eric@regit.org>
22  */
23 
24 #ifndef __UTIL_EBPF_H__
25 #define __UTIL_EBPF_H__
26 
27 #include "flow-bypass.h"
28 
29 #ifdef HAVE_PACKET_EBPF
30 
31 #define XDP_FLAGS_UPDATE_IF_NOEXIST (1U << 0)
32 #define XDP_FLAGS_SKB_MODE (1U << 1)
33 #define XDP_FLAGS_DRV_MODE (1U << 2)
34 #define XDP_FLAGS_HW_MODE (1U << 3)
35 
36 
37 struct flowv4_keys {
38  __be32 src;
39  __be32 dst;
40  union {
41  __be32 ports;
42  __be16 port16[2];
43  };
44  __u8 ip_proto:1;
45  __u16 vlan0:15;
46  __u16 vlan1;
47 };
48 
49 struct flowv6_keys {
50  __be32 src[4];
51  __be32 dst[4];
52  union {
53  __be32 ports;
54  __be16 port16[2];
55  };
56  __u8 ip_proto:1;
57  __u16 vlan0:15;
58  __u16 vlan1;
59 };
60 
61 struct pair {
62  uint64_t packets;
63  uint64_t bytes;
64 };
65 
66 typedef struct EBPFBypassData_ {
67  void *key[2];
68  int mapfd;
69  int cpus_count;
70 } EBPFBypassData;
71 
72 #define EBPF_SOCKET_FILTER (1<<0)
73 #define EBPF_XDP_CODE (1<<1)
74 #define EBPF_PINNED_MAPS (1<<2)
75 #define EBPF_XDP_HW_MODE (1<<3)
76 
77 int EBPFGetMapFDByName(const char *iface, const char *name);
78 int EBPFLoadFile(const char *iface, const char *path, const char * section,
79  int *val, struct ebpf_timeout_config *config);
80 int EBPFSetupXDP(const char *iface, int fd, uint8_t flags);
81 
82 int EBPFCheckBypassedFlowTimeout(ThreadVars *th_v, struct flows_stats *bypassstats,
83  struct timespec *curtime,
84  void *data);
85 int EBPFCheckBypassedFlowCreate(ThreadVars *th_v, struct timespec *curtime, void *data);
86 
87 void EBPFRegisterExtension(void);
88 
89 void EBPFBuildCPUSet(ConfNode *node, char *iface);
90 
91 int EBPFSetPeerIface(const char *iface, const char *out_iface);
92 
93 int EBPFUpdateFlow(Flow *f, Packet *p, void *data);
94 bool EBPFBypassUpdate(Flow *f, void *data, time_t tsec);
95 void EBPFBypassFree(void *data);
96 
97 void EBPFDeleteKey(int fd, void *key);
98 
99 #ifdef BUILD_UNIX_SOCKET
100 TmEcode EBPFGetBypassedStats(json_t *cmd, json_t *answer, void *data);
101 #endif
102 
103 #define __bpf_percpu_val_align __attribute__((__aligned__(8)))
104 
105 #define BPF_DECLARE_PERCPU(type, name, nr_cpus) \
106  struct { type v; /* padding */ } __bpf_percpu_val_align \
107  name[nr_cpus]
108 #define BPF_PERCPU(name, cpu) name[(cpu)].v
109 
110 
111 #endif
112 
113 #endif
flow-bypass.h
Flow_
Flow data structure.
Definition: flow.h:356
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
Packet_
Definition: decode.h:425
TmEcode
TmEcode
Definition: tm-threads-common.h:81
flags
uint8_t flags
Definition: decode-gre.h:0
ConfNode_
Definition: conf.h:32
src
uint16_t src
Definition: app-layer-dnp3.h:5
dst
uint16_t dst
Definition: app-layer-dnp3.h:4
flows_stats
Definition: flow-bypass.h:29