suricata
util-device.h
Go to the documentation of this file.
1 /* Copyright (C) 2011-2016 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 #ifndef __UTIL_DEVICE_H__
19 #define __UTIL_DEVICE_H__
20 
21 #ifdef HAVE_DPDK
22 #include <rte_mempool.h>
23 #endif /* HAVE_DPDK */
24 
25 #include "queue.h"
26 
27 #define OFFLOAD_FLAG_SG (1<<0)
28 #define OFFLOAD_FLAG_TSO (1<<1)
29 #define OFFLOAD_FLAG_GSO (1<<2)
30 #define OFFLOAD_FLAG_GRO (1<<3)
31 #define OFFLOAD_FLAG_LRO (1<<4)
32 #define OFFLOAD_FLAG_RXCSUM (1<<5)
33 #define OFFLOAD_FLAG_TXCSUM (1<<6)
34 #define OFFLOAD_FLAG_TOE (1<<7)
35 
36 void LiveSetOffloadDisable(void);
37 void LiveSetOffloadWarn(void);
38 int LiveGetOffload(void);
39 
40 #define MAX_DEVNAME 10
41 
42 #ifdef HAVE_DPDK
43 typedef struct {
44  struct rte_mempool *pkt_mp;
45 } DPDKDeviceResources;
46 #endif /* HAVE_DPDK */
47 
48 /** storage for live device names */
49 typedef struct LiveDevice_ {
50  char *dev; /**< the device (e.g. "eth0") */
52  int mtu; /* MTU of the device */
54 
55  uint16_t id;
56 
57  SC_ATOMIC_DECLARE(uint64_t, pkts);
58  SC_ATOMIC_DECLARE(uint64_t, drop);
59  SC_ATOMIC_DECLARE(uint64_t, bypassed);
60  SC_ATOMIC_DECLARE(uint64_t, invalid_checksums);
62 
63  uint32_t tenant_id; /**< tenant id in multi-tenancy */
64  uint32_t offload_orig; /**< original offload settings to restore @exit */
65 #ifdef HAVE_DPDK
66  // DPDK resources that needs to be cleaned after workers are stopped and devices closed
67  DPDKDeviceResources dpdk_vars;
68 #endif
70 
71 typedef struct LiveDeviceName_ {
72  char *dev; /**< the device (e.g. "eth0") */
75 
76 void LiveDevRegisterExtension(void);
77 
78 int LiveRegisterDeviceName(const char *dev);
79 int LiveRegisterDevice(const char *dev);
81 void LiveDevSetBypassStats(LiveDevice *dev, uint64_t cnt, int family);
82 void LiveDevAddBypassStats(LiveDevice *dev, uint64_t cnt, int family);
83 void LiveDevSubBypassStats(LiveDevice *dev, uint64_t cnt, int family);
84 void LiveDevAddBypassFail(LiveDevice *dev, uint64_t cnt, int family);
85 void LiveDevAddBypassSuccess(LiveDevice *dev, uint64_t cnt, int family);
86 int LiveGetDeviceCount(void);
87 const char *LiveGetDeviceName(int number);
88 LiveDevice *LiveGetDevice(const char *dev);
89 const char *LiveGetShortName(const char *dev);
90 int LiveBuildDeviceList(const char *base);
91 void LiveDeviceHasNoStats(void);
92 int LiveDeviceListClean(void);
93 int LiveBuildDeviceListCustom(const char *base, const char *itemname);
94 
96 
97 void LiveDeviceFinalize(void);
98 
99 #ifdef BUILD_UNIX_SOCKET
100 TmEcode LiveDeviceIfaceStat(json_t *cmd, json_t *server_msg, void *data);
101 TmEcode LiveDeviceIfaceList(json_t *cmd, json_t *server_msg, void *data);
102 TmEcode LiveDeviceGetBypassedStats(json_t *cmd, json_t *answer, void *data);
103 #endif
104 
105 #endif /* __UTIL_DEVICE_H__ */
LiveDevAddBypassSuccess
void LiveDevAddBypassSuccess(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:572
LiveSetOffloadDisable
void LiveSetOffloadDisable(void)
Definition: util-device.c:71
LiveDevSubBypassStats
void LiveDevSubBypassStats(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:534
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
LiveDevice_
Definition: util-device.h:49
LiveDevice_::tenant_id_set
bool tenant_id_set
Definition: util-device.h:53
LiveDevice_::id
uint16_t id
Definition: util-device.h:55
LiveDevice
struct LiveDevice_ LiveDevice
LiveGetDeviceName
const char * LiveGetDeviceName(int number)
Get a pointer to the device name at idx.
Definition: util-device.c:184
LiveRegisterDevice
int LiveRegisterDevice(const char *dev)
Add a pcap device for monitoring and create structure.
Definition: util-device.c:126
LiveDeviceName_::TAILQ_ENTRY
TAILQ_ENTRY(LiveDeviceName_) next
LiveRegisterDeviceName
int LiveRegisterDeviceName(const char *dev)
Add a device for monitoring.
Definition: util-device.c:97
LiveDeviceFinalize
void LiveDeviceFinalize(void)
Definition: util-device.c:442
LiveDevAddBypassFail
void LiveDevAddBypassFail(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:553
LiveDevAddBypassStats
void LiveDevAddBypassStats(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:515
MAX_DEVNAME
#define MAX_DEVNAME
Definition: util-device.h:40
LiveBuildDeviceList
int LiveBuildDeviceList(const char *base)
Definition: util-device.c:274
LiveDevice_::SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(uint64_t, invalid_checksums)
LiveDeviceName
struct LiveDeviceName_ LiveDeviceName
LiveDeviceForEach
LiveDevice * LiveDeviceForEach(LiveDevice **ldev, LiveDevice **ndev)
Definition: util-device.c:420
LiveDeviceListClean
int LiveDeviceListClean(void)
Definition: util-device.c:314
LiveDevice_::tenant_id
uint32_t tenant_id
Definition: util-device.h:63
LiveGetDeviceCount
int LiveGetDeviceCount(void)
Get the number of registered devices.
Definition: util-device.c:164
LiveDevice_::dev
char * dev
Definition: util-device.h:50
LiveDevSetBypassStats
void LiveDevSetBypassStats(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:496
LiveDevRegisterExtension
void LiveDevRegisterExtension(void)
Definition: util-device.c:465
LiveDeviceName_::dev
char * dev
Definition: util-device.h:72
LiveGetOffload
int LiveGetOffload(void)
Definition: util-device.c:81
LiveDevice_::offload_orig
uint32_t offload_orig
Definition: util-device.h:64
LiveBuildDeviceListCustom
int LiveBuildDeviceListCustom(const char *base, const char *itemname)
Definition: util-device.c:279
TmEcode
TmEcode
Definition: tm-threads-common.h:83
queue.h
LiveDevice_::mtu
int mtu
Definition: util-device.h:52
LiveDevice_::TAILQ_ENTRY
TAILQ_ENTRY(LiveDevice_) next
LiveDevice_::SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(uint64_t, bypassed)
LiveDevice_::SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(uint64_t, pkts)
LiveDeviceName_
Definition: util-device.h:71
LiveDevice_::SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(uint64_t, drop)
LiveDeviceHasNoStats
void LiveDeviceHasNoStats(void)
Definition: util-device.c:309
LiveGetShortName
const char * LiveGetShortName(const char *dev)
Definition: util-device.c:266
LiveGetDevice
LiveDevice * LiveGetDevice(const char *dev)
Get a pointer to the device at idx.
Definition: util-device.c:248
LiveDevice_::dev_short
char dev_short[MAX_DEVNAME+1]
Definition: util-device.h:51
LiveSetOffloadWarn
void LiveSetOffloadWarn(void)
Definition: util-device.c:76
LiveDevUseBypass
int LiveDevUseBypass(LiveDevice *dev)
Definition: util-device.c:474