suricata
util-device.c File Reference

Utility functions to handle device list. More...

#include "suricata-common.h"
#include "conf.h"
#include "util-device.h"
#include "util-ioctl.h"
#include "device-storage.h"
Include dependency graph for util-device.c:

Go to the source code of this file.

Macros

#define MAX_DEVNAME   10
 

Functions

void LiveSetOffloadDisable (void)
 
void LiveSetOffloadWarn (void)
 
int LiveGetOffload (void)
 
int LiveRegisterDeviceName (const char *dev)
 Add a device for monitoring. More...
 
int LiveRegisterDevice (const char *dev)
 Add a pcap device for monitoring and create structure. More...
 
int LiveGetDeviceCount (void)
 Get the number of registered devices. More...
 
const char * LiveGetDeviceName (int number)
 Get a pointer to the device name at idx. More...
 
LiveDeviceLiveGetDevice (const char *name)
 Get a pointer to the device at idx. More...
 
const char * LiveGetShortName (const char *dev)
 
int LiveBuildDeviceList (const char *runmode)
 
int LiveBuildDeviceListCustom (const char *runmode, const char *itemname)
 
void LiveDeviceHasNoStats ()
 
int LiveDeviceListClean ()
 
LiveDeviceLiveDeviceForEach (LiveDevice **ldev, LiveDevice **ndev)
 
void LiveDeviceFinalize (void)
 
void LiveDevRegisterExtension (void)
 
int LiveDevUseBypass (LiveDevice *dev)
 
void LiveDevSetBypassStats (LiveDevice *dev, uint64_t cnt, int family)
 
void LiveDevAddBypassStats (LiveDevice *dev, uint64_t cnt, int family)
 
void LiveDevSubBypassStats (LiveDevice *dev, uint64_t cnt, int family)
 
void LiveDevAddBypassFail (LiveDevice *dev, uint64_t cnt, int family)
 
void LiveDevAddBypassSuccess (LiveDevice *dev, uint64_t cnt, int family)
 

Variables

 BypassInfo
 

Detailed Description

Utility functions to handle device list.

Author
Eric Leblond eric@.nosp@m.regi.nosp@m.t.org

Definition in file util-device.c.

Macro Definition Documentation

#define MAX_DEVNAME   10

Definition at line 25 of file util-device.c.

Referenced by LiveGetDeviceName(), and LiveRegisterDevice().

Function Documentation

int LiveBuildDeviceList ( const char *  runmode)

Definition at line 289 of file util-device.c.

References LiveBuildDeviceListCustom().

Referenced by RegisterAllModules().

Here is the call graph for this function:

Here is the caller graph for this function:

int LiveBuildDeviceListCustom ( const char *  runmode,
const char *  itemname 
)

Definition at line 294 of file util-device.c.

References ConfGetNode(), LiveRegisterDeviceName(), ConfNode_::name, next, TAILQ_FOREACH, and ConfNode_::val.

Referenced by LiveBuildDeviceList(), and RegisterAllModules().

Here is the call graph for this function:

Here is the caller graph for this function:

void LiveDevAddBypassFail ( LiveDevice dev,
uint64_t  cnt,
int  family 
)

Increase number of failed captured flows for a protocol family

Parameters
devpointer to LiveDevice to set stats for
cntnumber of flows to add
familyAF_INET to set IPv4 count or AF_INET6 to set IPv6 count

Definition at line 565 of file util-device.c.

References BypassInfo, LiveDevGetStorageById(), and SC_ATOMIC_ADD.

Referenced by AFPSetBPFFilter().

Here is the call graph for this function:

Here is the caller graph for this function:

void LiveDevAddBypassStats ( LiveDevice dev,
uint64_t  cnt,
int  family 
)

Increase number of currently bypassed flows for a protocol family

Parameters
devpointer to LiveDevice to set stats for
cntnumber of flows to add
familyAF_INET to set IPv4 count or AF_INET6 to set IPv6 count

Definition at line 527 of file util-device.c.

References BypassInfo, LiveDevGetStorageById(), and SC_ATOMIC_ADD.

Referenced by AFPSetBPFFilter().

Here is the call graph for this function:

Here is the caller graph for this function:

void LiveDevAddBypassSuccess ( LiveDevice dev,
uint64_t  cnt,
int  family 
)

Increase number of currently succesfully bypassed flows for a protocol family

Parameters
devpointer to LiveDevice to set stats for
cntnumber of flows to add
familyAF_INET to set IPv4 count or AF_INET6 to set IPv6 count

Definition at line 584 of file util-device.c.

References BypassInfo, MimeDecParseState::data, LiveDevice_::dev, LiveDevGetStorageById(), LiveDeviceForEach(), SC_ATOMIC_ADD, SC_ATOMIC_GET, SCReturnInt, TM_ECODE_FAILED, and TM_ECODE_OK.

Referenced by AFPSetBPFFilter().

Here is the call graph for this function:

Here is the caller graph for this function:

void LiveDeviceFinalize ( void  )

Create registered devices

This function creates all needed LiveDevice from the LiveDeviceName list created via LiveRegisterDevice()

Definition at line 454 of file util-device.c.

References LiveDeviceName_::dev, LiveRegisterDevice(), next, SCFree, SCLogDebug, and TAILQ_FOREACH_SAFE.

Referenced by PostRunDeinit().

Here is the call graph for this function:

Here is the caller graph for this function:

LiveDevice* LiveDeviceForEach ( LiveDevice **  ldev,
LiveDevice **  ndev 
)

Definition at line 432 of file util-device.c.

References next, TAILQ_FIRST, and TAILQ_NEXT.

Referenced by LiveDevAddBypassSuccess().

Here is the caller graph for this function:

void LiveDeviceHasNoStats ( void  )

Call this function to disable stat on live devices

This can be useful in the case, this is not a real interface.

Definition at line 324 of file util-device.c.

Referenced by RunModeIpsIPFWAutoFp(), RunModeIpsIPFWWorker(), RunModeIpsNFQAutoFp(), RunModeIpsNFQWorker(), RunModeIpsWinDivertAutoFp(), and RunModeNapatechRegister().

Here is the caller graph for this function:

int LiveDeviceListClean ( void  )

Definition at line 329 of file util-device.c.

References MimeDecParseState::data, LiveDevice_::dev, LiveDevFreeStorage(), next, RestoreIfaceOffloading(), SC_ATOMIC_DESTROY, SC_ATOMIC_GET, SCEnter, SCFree, SCLogNotice, SCReturnInt, TAILQ_FOREACH, TAILQ_FOREACH_SAFE, TM_ECODE_FAILED, and TM_ECODE_OK.

Referenced by GlobalsInitPreConfig().

Here is the call graph for this function:

Here is the caller graph for this function:

void LiveDevRegisterExtension ( void  )

Register bypass stats storage

Definition at line 477 of file util-device.c.

References LiveDevStorageRegister().

Referenced by PostRunDeinit().

Here is the call graph for this function:

Here is the caller graph for this function:

void LiveDevSetBypassStats ( LiveDevice dev,
uint64_t  cnt,
int  family 
)

Set number of currently bypassed flows for a protocol family

Parameters
devpointer to LiveDevice to set stats for
cntnumber of currently bypassed flows
familyAF_INET to set IPv4 count or AF_INET6 to set IPv6 count

Definition at line 508 of file util-device.c.

References BypassInfo, LiveDevGetStorageById(), and SC_ATOMIC_SET.

Here is the call graph for this function:

void LiveDevSubBypassStats ( LiveDevice dev,
uint64_t  cnt,
int  family 
)

Decrease number of currently bypassed flows for a protocol family

Parameters
devpointer to LiveDevice to set stats for
cntnumber of flows to remove
familyAF_INET to set IPv4 count or AF_INET6 to set IPv6 count

Definition at line 546 of file util-device.c.

References BypassInfo, LiveDevGetStorageById(), and SC_ATOMIC_SUB.

Referenced by FlowDisableFlowManagerThread().

Here is the call graph for this function:

Here is the caller graph for this function:

int LiveDevUseBypass ( LiveDevice dev)

Prepare a LiveDevice so we can set bypass stats

Definition at line 486 of file util-device.c.

References BypassInfo, LiveDevSetStorageById(), SC_ATOMIC_INIT, SC_ERR_MEM_ALLOC, SCCalloc, and SCLogError.

Here is the call graph for this function:

LiveDevice* LiveGetDevice ( const char *  name)

Get a pointer to the device at idx.

Parameters
numberidx of the device in our list
Return values
ptrpointer to the string containing the device
NULLon error

Definition at line 260 of file util-device.c.

References LiveDevice_::dev, next, SC_ERR_INVALID_VALUE, SCLogWarning, and TAILQ_FOREACH.

Referenced by DetectEngineReloadTenantBlocking(), LiveGetShortName(), NFQRegisterQueue(), NoNFLOGSupportExit(), ReceiveAFPThreadInit(), ReceiveErfDagThreadInit(), ReceivePcapThreadInit(), ReceivePfringThreadInit(), RunModeIdsAFPRegister(), RunModeIdsNetmapRegister(), RunModeIdsPfringRegister(), and TmModuleDecodeNetmapRegister().

Here is the caller graph for this function:

int LiveGetDeviceCount ( void  )

Get the number of registered devices.

Return values
cntthe number of registered devices

Definition at line 160 of file util-device.c.

References next, and TAILQ_FOREACH.

Referenced by AFPRunModeIsIPS(), LiveRegisterDevice(), PostRunDeinit(), RunModeIdsNetmapRegister(), RunModeSetIPSAutoFp(), RunModeSetIPSWorker(), RunModeSetLiveCaptureAutoFp(), RunModeSetLiveCaptureSingle(), and RunModeSetLiveCaptureWorkers().

Here is the caller graph for this function:

const char* LiveGetDeviceName ( int  number)

Get a pointer to the device name at idx.

Parameters
numberidx of the device in our list
Return values
ptrpointer to the string containing the device
NULLon error

Definition at line 180 of file util-device.c.

References LiveDevice_::dev, length, MAX_DEVNAME, next, SCLogInfo, strlcat(), strlcpy(), and TAILQ_FOREACH.

Referenced by AFPRunModeIsIPS(), PostRunDeinit(), RunModeIdsNetmapRegister(), RunModeSetIPSAutoFp(), RunModeSetIPSWorker(), RunModeSetLiveCaptureAutoFp(), RunModeSetLiveCaptureSingle(), and RunModeSetLiveCaptureWorkers().

Here is the call graph for this function:

Here is the caller graph for this function:

int LiveGetOffload ( void  )

Definition at line 78 of file util-device.c.

Referenced by NoWinDivertSupportExit(), ReceivePcapThreadInit(), RunModeIdsAFPRegister(), RunModeIdsNetmapRegister(), and RunModeIdsPfringRegister().

Here is the caller graph for this function:

const char* LiveGetShortName ( const char *  dev)

Definition at line 281 of file util-device.c.

References LiveDevice_::dev_short, and LiveGetDevice().

Referenced by RunModeSetLiveCaptureAutoFp().

Here is the call graph for this function:

Here is the caller graph for this function:

int LiveRegisterDevice ( const char *  dev)

Add a pcap device for monitoring and create structure.

Parameters
devstring with the device name
Return values
0on success.
-1on failure.

Definition at line 123 of file util-device.c.

References LiveDevice_::dev, LiveDevice_::dev_short, LiveDevice_::id, LiveDevice_::ignore_checksum, LiveDevStorageSize(), LiveGetDeviceCount(), MAX_DEVNAME, next, SC_ATOMIC_INIT, SCCalloc, SCFree, SCLogDebug, SCStrdup, strlcpy(), TAILQ_INSERT_TAIL, and unlikely.

Referenced by LiveDeviceFinalize(), NFQRegisterQueue(), NoWinDivertSupportExit(), RunModeIdsPfringRegister(), and RunModeNapatechRegister().

Here is the call graph for this function:

Here is the caller graph for this function:

int LiveRegisterDeviceName ( const char *  dev)

Add a device for monitoring.

To be used during option parsing. When a device has to be created during runmode init, use LiveRegisterDevice()

Parameters
devstring with the device name
Return values
0on success.
-1on failure.

Definition at line 94 of file util-device.c.

References LiveDeviceName_::dev, next, SCCalloc, SCFree, SCLogDebug, SCStrdup, TAILQ_INSERT_TAIL, and unlikely.

Referenced by IPFWRegisterQueue(), LiveBuildDeviceListCustom(), and RegisterAllModules().

Here is the caller graph for this function:

void LiveSetOffloadDisable ( void  )

Definition at line 68 of file util-device.c.

Referenced by PostRunDeinit().

Here is the caller graph for this function:

void LiveSetOffloadWarn ( void  )

Definition at line 73 of file util-device.c.

Referenced by PostRunDeinit().

Here is the caller graph for this function:

Variable Documentation