livedev: shorten devname at registration

pull/2143/head
Victor Julien 9 years ago
parent b673e14411
commit 5c974f92a8

@ -79,7 +79,7 @@ int RejectSendLibnet11L3IPv4TCP(ThreadVars *tv, Packet *p, void *data, int dir)
libnet_t *c; /* libnet context */
char ebuf[LIBNET_ERRBUF_SIZE];
int result;
char *devname = NULL;
const char *devname = NULL;
/* fill in struct defaults */
lpacket.ttl = 0;
@ -203,7 +203,7 @@ int RejectSendLibnet11L3IPv4ICMP(ThreadVars *tv, Packet *p, void *data, int dir)
libnet_t *c; /* libnet context */
char ebuf[LIBNET_ERRBUF_SIZE];
int result;
char *devname = NULL;
const char *devname = NULL;
/* fill in struct defaults */
lpacket.ttl = 0;
@ -291,7 +291,7 @@ int RejectSendLibnet11L3IPv6TCP(ThreadVars *tv, Packet *p, void *data, int dir)
libnet_t *c; /* libnet context */
char ebuf[LIBNET_ERRBUF_SIZE];
int result;
char *devname = NULL;
const char *devname = NULL;
/* fill in struct defaults */
lpacket.ttl = 0;
@ -414,7 +414,7 @@ int RejectSendLibnet11L3IPv6ICMP(ThreadVars *tv, Packet *p, void *data, int dir)
libnet_t *c; /* libnet context */
char ebuf[LIBNET_ERRBUF_SIZE];
int result;
char *devname = NULL;
const char *devname = NULL;
/* fill in struct defaults */
lpacket.ttl = 0;

@ -479,7 +479,7 @@ int AFPRunModeIsIPS()
if_default = ConfNodeLookupKeyValue(af_packet_node, "interface", "default");
for (ldev = 0; ldev < nlive; ldev++) {
char *live_dev = LiveGetDeviceName(ldev);
const char *live_dev = LiveGetDeviceName(ldev);
if (live_dev == NULL) {
SCLogError(SC_ERR_INVALID_VALUE, "Problem with config file");
return 0;
@ -509,7 +509,7 @@ int AFPRunModeIsIPS()
if (has_ids && has_ips) {
SCLogInfo("AF_PACKET mode using IPS and IDS mode");
for (ldev = 0; ldev < nlive; ldev++) {
char *live_dev = LiveGetDeviceName(ldev);
const char *live_dev = LiveGetDeviceName(ldev);
if (live_dev == NULL) {
SCLogError(SC_ERR_INVALID_VALUE, "Problem with config file");
return 0;

@ -300,7 +300,7 @@ int NetmapRunModeIsIPS()
if_default = ConfNodeLookupKeyValue(netmap_node, "interface", "default");
for (ldev = 0; ldev < nlive; ldev++) {
char *live_dev = LiveGetDeviceName(ldev);
const char *live_dev = LiveGetDeviceName(ldev);
if (live_dev == NULL) {
SCLogError(SC_ERR_INVALID_VALUE, "Problem with config file");
return 0;
@ -330,7 +330,7 @@ int NetmapRunModeIsIPS()
if (has_ids && has_ips) {
SCLogInfo("Netmap mode using IPS and IDS mode");
for (ldev = 0; ldev < nlive; ldev++) {
char *live_dev = LiveGetDeviceName(ldev);
const char *live_dev = LiveGetDeviceName(ldev);
if (live_dev == NULL) {
SCLogError(SC_ERR_INVALID_VALUE, "Problem with config file");
return 0;

@ -895,8 +895,8 @@ TmEcode ReceiveMpipeThreadInit(ThreadVars *tv, void *initdata, void **data)
ptv->tv = tv;
int result;
char *link_name = (char *)initdata;
const char *link_name = (char *)initdata;
MpipeRegisterPerfCounters(ptv, tv);
*data = (void *)ptv;

@ -2233,7 +2233,7 @@ static int ConfigGetCaptureValue(SCInstance *suri)
case RUNMODE_PFRING:
nlive = LiveGetDeviceCount();
for (lthread = 0; lthread < nlive; lthread++) {
char *live_dev = LiveGetDeviceName(lthread);
const char *live_dev = LiveGetDeviceName(lthread);
char dev[32];
(void)strlcpy(dev, live_dev, sizeof(dev));

@ -1,4 +1,4 @@
/* Copyright (C) 2011-2012 Open Information Security Foundation
/* Copyright (C) 2011-2016 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
@ -36,6 +36,9 @@ static TAILQ_HEAD(, LiveDevice_) live_devices =
/** if set to 0 when we don't have real devices */
static int live_devices_stats = 1;
static int LiveSafeDeviceName(const char *devname,
char *newdevname, size_t destlen);
/**
* \brief Add a pcap device for monitoring
*
@ -56,6 +59,13 @@ int LiveRegisterDevice(const char *dev)
SCFree(pd);
return -1;
}
/* create a short version to be used in thread names */
if (strlen(pd->dev) > MAX_DEVNAME) {
LiveSafeDeviceName(pd->dev, pd->dev_short, sizeof(pd->dev_short));
} else {
(void)strlcpy(pd->dev_short, pd->dev, sizeof(pd->dev_short));
}
SC_ATOMIC_INIT(pd->pkts);
SC_ATOMIC_INIT(pd->drop);
SC_ATOMIC_INIT(pd->invalid_checksums);
@ -91,7 +101,7 @@ int LiveGetDeviceCount(void)
* \retval ptr pointer to the string containing the device
* \retval NULL on error
*/
char *LiveGetDeviceName(int number)
const char *LiveGetDeviceName(int number)
{
int i = 0;
LiveDevice *pd;
@ -107,14 +117,14 @@ char *LiveGetDeviceName(int number)
return NULL;
}
/**
/** \internal
* \brief Shorten a device name that is to long
*
* \param device name from config and destination for modified
*
* \retval None, is added to destination char *newdevname
*/
int LiveSafeDeviceName(const char *devname, char *newdevname, size_t destlen)
static int LiveSafeDeviceName(const char *devname, char *newdevname, size_t destlen)
{
size_t devnamelen = strlen(devname);
@ -192,7 +202,13 @@ LiveDevice *LiveGetDevice(const char *name)
return NULL;
}
const char *LiveGetShortName(const char *dev)
{
LiveDevice *live_dev = LiveGetDevice(dev);
if (live_dev == NULL)
return NULL;
return live_dev->dev_short;
}
int LiveBuildDeviceList(const char *runmode)
{

@ -1,4 +1,4 @@
/* Copyright (C) 2011-2012 Open Information Security Foundation
/* Copyright (C) 2011-2016 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
@ -21,9 +21,12 @@
#include "queue.h"
#include "unix-manager.h"
#define MAX_DEVNAME 10
/** storage for live device names */
typedef struct LiveDevice_ {
char *dev; /**< the device (e.g. "eth0") */
char dev_short[MAX_DEVNAME + 1];
int ignore_checksum;
SC_ATOMIC_DECLARE(uint64_t, pkts);
SC_ATOMIC_DECLARE(uint64_t, drop);
@ -34,9 +37,9 @@ typedef struct LiveDevice_ {
int LiveRegisterDevice(const char *dev);
int LiveGetDeviceCount(void);
char *LiveGetDeviceName(int number);
int LiveSafeDeviceName(const char *devname, char *newdevname, size_t destlen);
const char *LiveGetDeviceName(int number);
LiveDevice *LiveGetDevice(const char *dev);
const char *LiveGetShortName(const char *dev);
int LiveBuildDeviceList(const char *base);
void LiveDeviceHasNoStats(void);
int LiveDeviceListClean(void);

@ -169,9 +169,8 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser,
int lthread;
for (lthread = 0; lthread < nlive; lthread++) {
char *live_dev = LiveGetDeviceName(lthread);
char visual_devname[11] = "";
int shortening_result;
const char *live_dev = LiveGetDeviceName(lthread);
const char *visual_devname = LiveGetShortName(live_dev);
void *aconf;
int threads_count;
@ -190,12 +189,6 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser,
threads_count = ModThreadsCount(aconf);
for (thread = 0; thread < threads_count; thread++) {
shortening_result = LiveSafeDeviceName(live_dev, visual_devname, sizeof(visual_devname));
if (shortening_result != 0) {
SCLogError(SC_ERR_INVALID_VALUE, "Could not shorten long devicename: %s", live_dev);
exit(EXIT_FAILURE);
}
snprintf(tname, sizeof(tname), "%s#%02d-%s", thread_name,
thread+1, visual_devname);
@ -298,16 +291,9 @@ static int RunModeSetLiveCaptureWorkersForDevice(ConfigIfaceThreadsCountFunc Mod
/* create the threads */
for (thread = 0; thread < threads_count; thread++) {
char tname[TM_THREAD_NAME_MAX];
char visual_devname[11] = "";
int shortening_result;
ThreadVars *tv = NULL;
TmModule *tm_module = NULL;
shortening_result = LiveSafeDeviceName(live_dev, visual_devname, sizeof(visual_devname));
if (shortening_result != 0) {
SCLogError(SC_ERR_INVALID_VALUE, "Could not shorten long devicename: %s", live_dev);
exit(EXIT_FAILURE);
}
const char *visual_devname = LiveGetShortName(live_dev);
if (single_mode) {
snprintf(tname, sizeof(tname), "%s#01-%s", thread_name, visual_devname);
@ -447,7 +433,7 @@ int RunModeSetIPSAutoFp(ConfigIPSParserFunc ConfigParser,
char tname[TM_THREAD_NAME_MAX];
char qname[TM_QUEUE_NAME_MAX];
TmModule *tm_module ;
char *cur_queue = NULL;
const char *cur_queue = NULL;
char *queues = NULL;
int thread;
@ -593,7 +579,7 @@ int RunModeSetIPSWorker(ConfigIPSParserFunc ConfigParser,
char tname[TM_THREAD_NAME_MAX];
ThreadVars *tv = NULL;
TmModule *tm_module = NULL;
char *cur_queue = NULL;
const char *cur_queue = NULL;
int nqueue = LiveGetDeviceCount();

Loading…
Cancel
Save