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  __u16 vlan2;
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  __u16 vlan2;
61 };
62 
63 struct pair {
64  uint64_t packets;
65  uint64_t bytes;
66 };
67 
68 typedef struct EBPFBypassData_ {
69  void *key[2];
70  int mapfd;
71  int cpus_count;
72 } EBPFBypassData;
73 
74 #define EBPF_SOCKET_FILTER (1<<0)
75 #define EBPF_XDP_CODE (1<<1)
76 #define EBPF_PINNED_MAPS (1<<2)
77 #define EBPF_XDP_HW_MODE (1<<3)
78 
79 int EBPFGetMapFDByName(const char *iface, const char *name);
80 int EBPFLoadFile(const char *iface, const char *path, const char * section,
81  int *val, struct ebpf_timeout_config *config);
82 int EBPFSetupXDP(const char *iface, int fd, uint8_t flags);
83 
84 int EBPFCheckBypassedFlowCreate(ThreadVars *th_v, struct timespec *curtime, void *data);
85 
86 void EBPFRegisterExtension(void);
87 
88 void EBPFBuildCPUSet(ConfNode *node, char *iface);
89 
90 int EBPFSetPeerIface(const char *iface, const char *out_iface);
91 
92 int EBPFUpdateFlow(Flow *f, Packet *p, void *data);
93 bool EBPFBypassUpdate(Flow *f, void *data, time_t tsec);
94 void EBPFBypassFree(void *data);
95 
96 void EBPFDeleteKey(int fd, void *key);
97 
98 #define __bpf_percpu_val_align __attribute__((__aligned__(8)))
99 
100 #define BPF_DECLARE_PERCPU(type, name, nr_cpus) \
101  struct { type v; /* padding */ } __bpf_percpu_val_align \
102  name[nr_cpus]
103 #define BPF_PERCPU(name, cpu) name[(cpu)].v
104 
105 
106 #endif
107 
108 #endif
flow-bypass.h
Flow_
Flow data structure.
Definition: flow.h:347
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
Packet_
Definition: decode.h:430
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