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  __u16 vlan2;
49 };
50 
51 struct flowv6_keys {
52  __be32 src[4];
53  __be32 dst[4];
54  union {
55  __be32 ports;
56  __be16 port16[2];
57  };
58  __u8 ip_proto:1;
59  __u16 vlan0:15;
60  __u16 vlan1;
61  __u16 vlan2;
62 };
63 
64 struct pair {
65  uint64_t packets;
66  uint64_t bytes;
67 };
68 
69 typedef struct EBPFBypassData_ {
70  void *key[2];
71  int mapfd;
72  int cpus_count;
73 } EBPFBypassData;
74 
75 #define EBPF_SOCKET_FILTER (1<<0)
76 #define EBPF_XDP_CODE (1<<1)
77 #define EBPF_PINNED_MAPS (1<<2)
78 #define EBPF_XDP_HW_MODE (1<<3)
79 
80 int EBPFGetMapFDByName(const char *iface, const char *name);
81 int EBPFLoadFile(const char *iface, const char *path, const char * section,
82  int *val, struct ebpf_timeout_config *config);
83 int EBPFSetupXDP(const char *iface, int fd, uint8_t flags);
84 
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 #define __bpf_percpu_val_align __attribute__((__aligned__(8)))
100 
101 #define BPF_DECLARE_PERCPU(type, name, nr_cpus) \
102  struct { type v; /* padding */ } __bpf_percpu_val_align \
103  name[nr_cpus]
104 #define BPF_PERCPU(name, cpu) name[(cpu)].v
105 
106 
107 #endif
108 
109 #endif
flow-bypass.h
Flow_
Flow data structure.
Definition: flow.h:351
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
Packet_
Definition: decode.h:437
conf.h
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