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 SURICATA_UTIL_DEVICE_H
19 #define SURICATA_UTIL_DEVICE_H
20 
21 #ifdef HAVE_DPDK
22 #include <rte_mempool.h>
23 #endif /* HAVE_DPDK */
24 
25 #include "queue.h"
26 #include "util-storage.h"
27 
28 #define OFFLOAD_FLAG_SG (1<<0)
29 #define OFFLOAD_FLAG_TSO (1<<1)
30 #define OFFLOAD_FLAG_GSO (1<<2)
31 #define OFFLOAD_FLAG_GRO (1<<3)
32 #define OFFLOAD_FLAG_LRO (1<<4)
33 #define OFFLOAD_FLAG_RXCSUM (1<<5)
34 #define OFFLOAD_FLAG_TXCSUM (1<<6)
35 #define OFFLOAD_FLAG_TOE (1<<7)
36 
37 void LiveSetOffloadDisable(void);
38 void LiveSetOffloadWarn(void);
39 int LiveGetOffload(void);
40 
41 #define MAX_DEVNAME 10
42 
43 #ifdef HAVE_DPDK
44 typedef struct {
45  struct rte_mempool *pkt_mp;
46 } DPDKDeviceResources;
47 #endif /* HAVE_DPDK */
48 
49 /** storage for live device names */
50 typedef struct LiveDevice_ {
51  char *dev; /**< the device (e.g. "eth0") */
53  int mtu; /* MTU of the device */
55 
56  uint16_t id;
57 
58  SC_ATOMIC_DECLARE(uint64_t, pkts);
59  SC_ATOMIC_DECLARE(uint64_t, drop);
60  SC_ATOMIC_DECLARE(uint64_t, bypassed);
61  SC_ATOMIC_DECLARE(uint64_t, invalid_checksums);
63 
64  uint32_t tenant_id; /**< tenant id in multi-tenancy */
65  uint32_t offload_orig; /**< original offload settings to restore @exit */
66 #ifdef HAVE_DPDK
67  // DPDK resources that needs to be cleaned after workers are stopped and devices closed
68  DPDKDeviceResources dpdk_vars;
69 #endif
70  /** storage handle as a flex array member */
73 
74 typedef struct LiveDeviceName_ {
75  char *dev; /**< the device (e.g. "eth0") */
78 
79 void LiveDevRegisterExtension(void);
80 
81 int LiveRegisterDeviceName(const char *dev);
82 int LiveRegisterDevice(const char *dev);
84 void LiveDevAddBypassStats(LiveDevice *dev, uint64_t cnt, int family);
85 void LiveDevSubBypassStats(LiveDevice *dev, uint64_t cnt, int family);
86 void LiveDevAddBypassFail(LiveDevice *dev, uint64_t cnt, int family);
87 void LiveDevAddBypassSuccess(LiveDevice *dev, uint64_t cnt, int family);
88 int LiveGetDeviceCount(void);
89 const char *LiveGetDeviceName(int number);
90 LiveDevice *LiveGetDevice(const char *dev);
91 const char *LiveGetShortName(const char *dev);
92 int LiveBuildDeviceList(const char *base);
93 void LiveDeviceHasNoStats(void);
94 int LiveDeviceListClean(void);
95 int LiveBuildDeviceListCustom(const char *base, const char *itemname);
96 
98 
99 void LiveDeviceFinalize(void);
100 
101 #ifdef BUILD_UNIX_SOCKET
102 TmEcode LiveDeviceIfaceStat(json_t *cmd, json_t *server_msg, void *data);
103 TmEcode LiveDeviceIfaceList(json_t *cmd, json_t *server_msg, void *data);
104 TmEcode LiveDeviceGetBypassedStats(json_t *cmd, json_t *answer, void *data);
105 #endif
106 
107 #endif /* SURICATA_UTIL_DEVICE_H */
LiveDevAddBypassSuccess
void LiveDevAddBypassSuccess(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:553
LiveSetOffloadDisable
void LiveSetOffloadDisable(void)
Definition: util-device.c:71
LiveDevSubBypassStats
void LiveDevSubBypassStats(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:515
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
LiveDevice_
Definition: util-device.h:50
LiveDevice_::tenant_id_set
bool tenant_id_set
Definition: util-device.h:54
LiveDevice_::id
uint16_t id
Definition: util-device.h:56
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
LiveDevice_::storage
Storage storage[]
Definition: util-device.h:71
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:534
Storage
Definition: util-storage.h:39
LiveDevAddBypassStats
void LiveDevAddBypassStats(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:496
MAX_DEVNAME
#define MAX_DEVNAME
Definition: util-device.h:41
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:64
LiveGetDeviceCount
int LiveGetDeviceCount(void)
Get the number of registered devices.
Definition: util-device.c:164
LiveDevice_::dev
char * dev
Definition: util-device.h:51
LiveDevRegisterExtension
void LiveDevRegisterExtension(void)
Definition: util-device.c:465
LiveDeviceName_::dev
char * dev
Definition: util-device.h:75
LiveGetOffload
int LiveGetOffload(void)
Definition: util-device.c:81
LiveDevice_::offload_orig
uint32_t offload_orig
Definition: util-device.h:65
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:53
LiveDevice_::TAILQ_ENTRY
TAILQ_ENTRY(LiveDevice_) next
LiveDevice_::SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(uint64_t, bypassed)
cnt
uint32_t cnt
Definition: tmqh-packetpool.h:7
LiveDevice_::SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(uint64_t, pkts)
LiveDeviceName_
Definition: util-device.h:74
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:52
LiveSetOffloadWarn
void LiveSetOffloadWarn(void)
Definition: util-device.c:76
LiveDevUseBypass
int LiveDevUseBypass(LiveDevice *dev)
Definition: util-device.c:474
util-storage.h