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 SURICATA_UTIL_EBPF_H
25 #define SURICATA_UTIL_EBPF_H
26 
27 #include "flow-bypass.h"
28 #include "conf.h"
29 
30 #ifdef HAVE_PACKET_EBPF
31 
32 #define XDP_FLAGS_UPDATE_IF_NOEXIST (1U << 0)
33 #define XDP_FLAGS_SKB_MODE (1U << 1)
34 #define XDP_FLAGS_DRV_MODE (1U << 2)
35 #define XDP_FLAGS_HW_MODE (1U << 3)
36 
37 
38 struct flowv4_keys {
39  __be32 src;
40  __be32 dst;
41  union {
42  __be32 ports;
43  __be16 port16[2];
44  };
45  __u8 ip_proto:1;
46  __u16 vlan0:15;
47  __u16 vlan1;
48 };
49 
50 struct flowv6_keys {
51  __be32 src[4];
52  __be32 dst[4];
53  union {
54  __be32 ports;
55  __be16 port16[2];
56  };
57  __u8 ip_proto:1;
58  __u16 vlan0:15;
59  __u16 vlan1;
60 };
61 
62 struct pair {
63  uint64_t packets;
64  uint64_t bytes;
65 };
66 
67 typedef struct EBPFBypassData_ {
68  void *key[2];
69  int mapfd;
70  int cpus_count;
71 } EBPFBypassData;
72 
73 #define EBPF_SOCKET_FILTER (1<<0)
74 #define EBPF_XDP_CODE (1<<1)
75 #define EBPF_PINNED_MAPS (1<<2)
76 #define EBPF_XDP_HW_MODE (1<<3)
77 
78 int EBPFGetMapFDByName(const char *iface, const char *name);
79 int EBPFLoadFile(const char *iface, const char *path, const char * section,
80  int *val, struct ebpf_timeout_config *config);
81 int EBPFSetupXDP(const char *iface, int fd, uint8_t flags);
82 
83 int EBPFCheckBypassedFlowCreate(ThreadVars *th_v, struct timespec *curtime, void *data);
84 
85 void EBPFRegisterExtension(void);
86 
87 void EBPFBuildCPUSet(SCConfNode *node, char *iface);
88 
89 int EBPFSetPeerIface(const char *iface, const char *out_iface);
90 
91 int EBPFUpdateFlow(Flow *f, Packet *p, void *data);
92 bool EBPFBypassUpdate(Flow *f, void *data, time_t tsec);
93 void EBPFBypassFree(void *data);
94 
95 void EBPFDeleteKey(int fd, void *key);
96 
97 #define __bpf_percpu_val_align __attribute__((__aligned__(8)))
98 
99 #define BPF_DECLARE_PERCPU(type, name, nr_cpus) \
100  struct { type v; /* padding */ } __bpf_percpu_val_align \
101  name[nr_cpus]
102 #define BPF_PERCPU(name, cpu) name[(cpu)].v
103 
104 
105 #endif
106 
107 #endif
flow-bypass.h
name
const char * name
Definition: detect-engine-proto.c:48
Flow_
Flow data structure.
Definition: flow.h:347
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
Packet_
Definition: decode.h:501
conf.h
flags
uint8_t flags
Definition: decode-gre.h:0
src
uint16_t src
Definition: app-layer-dnp3.h:5
dst
uint16_t dst
Definition: app-layer-dnp3.h:4
SCConfNode_
Definition: conf.h:37