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 #include "queue.h"
22 #include "unix-manager.h"
23 
24 #define OFFLOAD_FLAG_SG (1<<0)
25 #define OFFLOAD_FLAG_TSO (1<<1)
26 #define OFFLOAD_FLAG_GSO (1<<2)
27 #define OFFLOAD_FLAG_GRO (1<<3)
28 #define OFFLOAD_FLAG_LRO (1<<4)
29 #define OFFLOAD_FLAG_RXCSUM (1<<5)
30 #define OFFLOAD_FLAG_TXCSUM (1<<6)
31 #define OFFLOAD_FLAG_TOE (1<<7)
32 
33 void LiveSetOffloadDisable(void);
34 void LiveSetOffloadWarn(void);
35 int LiveGetOffload(void);
36 
37 #define MAX_DEVNAME 10
38 
39 /** storage for live device names */
40 typedef struct LiveDevice_ {
41  char *dev; /**< the device (e.g. "eth0") */
44 
46  int id;
47 
48  SC_ATOMIC_DECLARE(uint64_t, pkts);
49  SC_ATOMIC_DECLARE(uint64_t, drop);
50  SC_ATOMIC_DECLARE(uint64_t, bypassed);
51  SC_ATOMIC_DECLARE(uint64_t, invalid_checksums);
53 
54  uint32_t tenant_id; /**< tenant id in multi-tenancy */
55  uint32_t offload_orig; /**< original offload settings to restore @exit */
56 } LiveDevice;
57 
58 typedef struct LiveDeviceName_ {
59  char *dev; /**< the device (e.g. "eth0") */
60  TAILQ_ENTRY(LiveDeviceName_) next;
62 
63 void LiveDevRegisterExtension(void);
64 
65 int LiveRegisterDeviceName(const char *dev);
66 int LiveGetDeviceNameCount(void);
67 const char *LiveGetDeviceNameName(int number);
68 int LiveRegisterDevice(const char *dev);
70 void LiveDevSetBypassStats(LiveDevice *dev, uint64_t cnt, int family);
71 void LiveDevAddBypassStats(LiveDevice *dev, uint64_t cnt, int family);
72 void LiveDevSubBypassStats(LiveDevice *dev, uint64_t cnt, int family);
73 void LiveDevAddBypassFail(LiveDevice *dev, uint64_t cnt, int family);
74 void LiveDevAddBypassSuccess(LiveDevice *dev, uint64_t cnt, int family);
75 int LiveGetDeviceCount(void);
76 const char *LiveGetDeviceName(int number);
77 LiveDevice *LiveGetDevice(const char *dev);
78 const char *LiveGetShortName(const char *dev);
79 int LiveBuildDeviceList(const char *base);
80 void LiveDeviceHasNoStats(void);
81 int LiveDeviceListClean(void);
82 int LiveBuildDeviceListCustom(const char *base, const char *itemname);
83 
85 
86 void LiveDeviceFinalize(void);
87 
88 #ifdef BUILD_UNIX_SOCKET
89 TmEcode LiveDeviceIfaceStat(json_t *cmd, json_t *server_msg, void *data);
90 TmEcode LiveDeviceIfaceList(json_t *cmd, json_t *server_msg, void *data);
91 TmEcode LiveDeviceGetBypassedStats(json_t *cmd, json_t *answer, void *data);
92 #endif
93 
94 #endif /* __UTIL_DEVICE_H__ */
void LiveSetOffloadWarn(void)
Definition: util-device.c:74
SC_ATOMIC_DECLARE(uint64_t, pkts)
uint32_t offload_orig
Definition: util-device.h:55
struct HtpBodyChunk_ * next
void LiveDevAddBypassSuccess(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:603
char dev_short[MAX_DEVNAME+1]
Definition: util-device.h:42
int LiveRegisterDevice(const char *dev)
Add a pcap device for monitoring and create structure.
Definition: util-device.c:124
LiveDevice * LiveDeviceForEach(LiveDevice **ldev, LiveDevice **ndev)
Definition: util-device.c:451
char * dev
Definition: util-device.h:41
int LiveGetOffload(void)
Definition: util-device.c:79
int LiveGetDeviceNameCount(void)
Get the number of pre registered devices.
Definition: util-device.c:198
int LiveBuildDeviceList(const char *base)
Definition: util-device.c:308
const char * LiveGetDeviceNameName(int number)
Get a pointer to the pre device name at idx.
Definition: util-device.c:218
#define MAX_DEVNAME
Definition: util-device.h:37
void LiveDevAddBypassStats(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:546
int LiveRegisterDeviceName(const char *dev)
Add a device for monitoring.
Definition: util-device.c:95
void LiveSetOffloadDisable(void)
Definition: util-device.c:69
const char * LiveGetShortName(const char *dev)
Definition: util-device.c:300
const char * LiveGetDeviceName(int number)
Get a pointer to the device name at idx.
Definition: util-device.c:177
LiveDevice * LiveGetDevice(const char *dev)
Get a pointer to the device at idx.
Definition: util-device.c:279
int LiveBuildDeviceListCustom(const char *base, const char *itemname)
Definition: util-device.c:313
int ignore_checksum
Definition: util-device.h:45
int LiveDeviceListClean(void)
Definition: util-device.c:348
void LiveDevRegisterExtension(void)
Definition: util-device.c:496
uint32_t tenant_id
Definition: util-device.h:54
void LiveDeviceFinalize(void)
Definition: util-device.c:473
int LiveGetDeviceCount(void)
Get the number of registered devices.
Definition: util-device.c:157
void LiveDeviceHasNoStats(void)
Definition: util-device.c:343
void LiveDevSubBypassStats(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:565
void LiveDevSetBypassStats(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:527
int LiveDevUseBypass(LiveDevice *dev)
Definition: util-device.c:505
void LiveDevAddBypassFail(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:584
TAILQ_ENTRY(LiveDevice_) next
bool tenant_id_set
Definition: util-device.h:43