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 "util-misc.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...
 
int LiveGetDeviceNameCount (void)
 Get the number of pre registered devices. More...
 
const char * LiveGetDeviceNameName (int number)
 Get a pointer to the pre 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

◆ MAX_DEVNAME

#define MAX_DEVNAME   10

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

Function Documentation

◆ LiveBuildDeviceList()

int LiveBuildDeviceList ( const char *  runmode)

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

References LiveBuildDeviceListCustom().

Here is the call graph for this function:

◆ LiveBuildDeviceListCustom()

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

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

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

Referenced by LiveBuildDeviceList().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LiveDevAddBypassFail()

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 580 of file util-device.c.

◆ LiveDevAddBypassStats()

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 542 of file util-device.c.

◆ LiveDevAddBypassSuccess()

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 599 of file util-device.c.

◆ LiveDeviceFinalize()

void LiveDeviceFinalize ( void  )

Create registered devices

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

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

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

Here is the call graph for this function:

◆ LiveDeviceForEach()

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

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

References next, TAILQ_FIRST, and TAILQ_NEXT.

◆ LiveDeviceHasNoStats()

void LiveDeviceHasNoStats ( )

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 342 of file util-device.c.

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

Here is the caller graph for this function:

◆ LiveDeviceListClean()

int LiveDeviceListClean ( )

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

References next, SCEnter, and TAILQ_FOREACH_SAFE.

◆ LiveDevRegisterExtension()

void LiveDevRegisterExtension ( void  )

Register bypass stats storage

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

Referenced by PostConfLoadedSetup().

Here is the caller graph for this function:

◆ LiveDevSetBypassStats()

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 523 of file util-device.c.

◆ LiveDevSubBypassStats()

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 561 of file util-device.c.

◆ LiveDevUseBypass()

int LiveDevUseBypass ( LiveDevice dev)

Prepare a LiveDevice so we can set bypass stats

Definition at line 501 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:

◆ LiveGetDevice()

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 278 of file util-device.c.

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

Referenced by LiveGetShortName(), and ReceiveErfDagThreadInit().

Here is the caller graph for this function:

◆ LiveGetDeviceCount()

int LiveGetDeviceCount ( void  )

Get the number of registered devices.

Return values
cntthe number of registered devices

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

References next, and TAILQ_FOREACH.

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

Here is the caller graph for this function:

◆ LiveGetDeviceName()

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 176 of file util-device.c.

References LiveDevice_::dev, next, and TAILQ_FOREACH.

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

Here is the caller graph for this function:

◆ LiveGetDeviceNameCount()

int LiveGetDeviceNameCount ( void  )

Get the number of pre registered devices.

Return values
cntthe number of pre registered devices

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

References next, and TAILQ_FOREACH.

◆ LiveGetDeviceNameName()

const char* LiveGetDeviceNameName ( int  number)

Get a pointer to the pre device name at idx.

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

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

References LiveDeviceName_::dev, next, and TAILQ_FOREACH.

◆ LiveGetOffload()

int LiveGetOffload ( void  )

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

◆ LiveGetShortName()

const char* LiveGetShortName ( const char *  dev)

Definition at line 299 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:

◆ LiveRegisterDevice()

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 124 of file util-device.c.

References LiveDevice_::dev, LiveDevStorageSize(), SCCalloc, SCFree, SCStrdup, and unlikely.

Referenced by LiveDeviceFinalize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LiveRegisterDeviceName()

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 95 of file util-device.c.

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

Referenced by LiveBuildDeviceListCustom().

Here is the caller graph for this function:

◆ LiveSetOffloadDisable()

void LiveSetOffloadDisable ( void  )

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

Referenced by PostConfLoadedSetup().

Here is the caller graph for this function:

◆ LiveSetOffloadWarn()

void LiveSetOffloadWarn ( void  )

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

Referenced by PostConfLoadedSetup().

Here is the caller graph for this function:

Variable Documentation

◆ BypassInfo

BypassInfo

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

Referenced by LiveDevUseBypass().