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