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 #ifdef HAVE_PACKET_EBPF
28 
29 #define XDP_FLAGS_UPDATE_IF_NOEXIST (1U << 0)
30 #define XDP_FLAGS_SKB_MODE (1U << 1)
31 #define XDP_FLAGS_DRV_MODE (1U << 2)
32 #define XDP_FLAGS_HW_MODE (1U << 3)
33 
34 #include "flow-bypass.h"
35 
36 struct flowv4_keys {
37  __be32 src;
38  __be32 dst;
39  union {
40  __be32 ports;
41  __be16 port16[2];
42  };
43  __u8 ip_proto:1;
44  __u16 vlan0:15;
45  __u16 vlan1;
46 };
47 
48 struct flowv6_keys {
49  __be32 src[4];
50  __be32 dst[4];
51  union {
52  __be32 ports;
53  __be16 port16[2];
54  };
55  __u8 ip_proto:1;
56  __u16 vlan0:15;
57  __u16 vlan1;
58 };
59 
60 struct pair {
61  uint64_t packets;
62  uint64_t bytes;
63 };
64 
65 typedef struct EBPFBypassData_ {
66  void *key[2];
67  int mapfd;
68  int cpus_count;
69 } EBPFBypassData;
70 
71 #define EBPF_SOCKET_FILTER (1<<0)
72 #define EBPF_XDP_CODE (1<<1)
73 #define EBPF_PINNED_MAPS (1<<2)
74 #define EBPF_XDP_HW_MODE (1<<3)
75 
76 int EBPFGetMapFDByName(const char *iface, const char *name);
77 int EBPFLoadFile(const char *iface, const char *path, const char * section,
78  int *val, struct ebpf_timeout_config *config);
79 int EBPFSetupXDP(const char *iface, int fd, uint8_t flags);
80 
81 int EBPFCheckBypassedFlowTimeout(ThreadVars *th_v, struct flows_stats *bypassstats,
82  struct timespec *curtime,
83  void *data);
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 #ifdef BUILD_UNIX_SOCKET
99 TmEcode EBPFGetBypassedStats(json_t *cmd, json_t *answer, void *data);
100 #endif
101 
102 #define __bpf_percpu_val_align __attribute__((__aligned__(8)))
103 
104 #define BPF_DECLARE_PERCPU(type, name, nr_cpus) \
105  struct { type v; /* padding */ } __bpf_percpu_val_align \
106  name[nr_cpus]
107 #define BPF_PERCPU(name, cpu) name[(cpu)].v
108 
109 
110 #endif
111 
112 #endif
uint16_t flags
uint16_t src
uint16_t dst
Definition: conf.h:32
Per thread variable structure.
Definition: threadvars.h:57
Flow data structure.
Definition: flow.h:325