livedev: shorten devname at registration

pull/2143/head
Victor Julien 10 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 */ libnet_t *c; /* libnet context */
char ebuf[LIBNET_ERRBUF_SIZE]; char ebuf[LIBNET_ERRBUF_SIZE];
int result; int result;
char *devname = NULL; const char *devname = NULL;
/* fill in struct defaults */ /* fill in struct defaults */
lpacket.ttl = 0; lpacket.ttl = 0;
@ -203,7 +203,7 @@ int RejectSendLibnet11L3IPv4ICMP(ThreadVars *tv, Packet *p, void *data, int dir)
libnet_t *c; /* libnet context */ libnet_t *c; /* libnet context */
char ebuf[LIBNET_ERRBUF_SIZE]; char ebuf[LIBNET_ERRBUF_SIZE];
int result; int result;
char *devname = NULL; const char *devname = NULL;
/* fill in struct defaults */ /* fill in struct defaults */
lpacket.ttl = 0; lpacket.ttl = 0;
@ -291,7 +291,7 @@ int RejectSendLibnet11L3IPv6TCP(ThreadVars *tv, Packet *p, void *data, int dir)
libnet_t *c; /* libnet context */ libnet_t *c; /* libnet context */
char ebuf[LIBNET_ERRBUF_SIZE]; char ebuf[LIBNET_ERRBUF_SIZE];
int result; int result;
char *devname = NULL; const char *devname = NULL;
/* fill in struct defaults */ /* fill in struct defaults */
lpacket.ttl = 0; lpacket.ttl = 0;
@ -414,7 +414,7 @@ int RejectSendLibnet11L3IPv6ICMP(ThreadVars *tv, Packet *p, void *data, int dir)
libnet_t *c; /* libnet context */ libnet_t *c; /* libnet context */
char ebuf[LIBNET_ERRBUF_SIZE]; char ebuf[LIBNET_ERRBUF_SIZE];
int result; int result;
char *devname = NULL; const char *devname = NULL;
/* fill in struct defaults */ /* fill in struct defaults */
lpacket.ttl = 0; lpacket.ttl = 0;

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

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

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

@ -2233,7 +2233,7 @@ static int ConfigGetCaptureValue(SCInstance *suri)
case RUNMODE_PFRING: case RUNMODE_PFRING:
nlive = LiveGetDeviceCount(); nlive = LiveGetDeviceCount();
for (lthread = 0; lthread < nlive; lthread++) { for (lthread = 0; lthread < nlive; lthread++) {
char *live_dev = LiveGetDeviceName(lthread); const char *live_dev = LiveGetDeviceName(lthread);
char dev[32]; char dev[32];
(void)strlcpy(dev, live_dev, sizeof(dev)); (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 * You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free * 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 */ /** if set to 0 when we don't have real devices */
static int live_devices_stats = 1; static int live_devices_stats = 1;
static int LiveSafeDeviceName(const char *devname,
char *newdevname, size_t destlen);
/** /**
* \brief Add a pcap device for monitoring * \brief Add a pcap device for monitoring
* *
@ -56,6 +59,13 @@ int LiveRegisterDevice(const char *dev)
SCFree(pd); SCFree(pd);
return -1; 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->pkts);
SC_ATOMIC_INIT(pd->drop); SC_ATOMIC_INIT(pd->drop);
SC_ATOMIC_INIT(pd->invalid_checksums); SC_ATOMIC_INIT(pd->invalid_checksums);
@ -91,7 +101,7 @@ int LiveGetDeviceCount(void)
* \retval ptr pointer to the string containing the device * \retval ptr pointer to the string containing the device
* \retval NULL on error * \retval NULL on error
*/ */
char *LiveGetDeviceName(int number) const char *LiveGetDeviceName(int number)
{ {
int i = 0; int i = 0;
LiveDevice *pd; LiveDevice *pd;
@ -107,14 +117,14 @@ char *LiveGetDeviceName(int number)
return NULL; return NULL;
} }
/** /** \internal
* \brief Shorten a device name that is to long * \brief Shorten a device name that is to long
* *
* \param device name from config and destination for modified * \param device name from config and destination for modified
* *
* \retval None, is added to destination char *newdevname * \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); size_t devnamelen = strlen(devname);
@ -192,7 +202,13 @@ LiveDevice *LiveGetDevice(const char *name)
return NULL; 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) 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 * You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free * the GNU General Public License version 2 as published by the Free
@ -21,9 +21,12 @@
#include "queue.h" #include "queue.h"
#include "unix-manager.h" #include "unix-manager.h"
#define MAX_DEVNAME 10
/** storage for live device names */ /** storage for live device names */
typedef struct LiveDevice_ { typedef struct LiveDevice_ {
char *dev; /**< the device (e.g. "eth0") */ char *dev; /**< the device (e.g. "eth0") */
char dev_short[MAX_DEVNAME + 1];
int ignore_checksum; int ignore_checksum;
SC_ATOMIC_DECLARE(uint64_t, pkts); SC_ATOMIC_DECLARE(uint64_t, pkts);
SC_ATOMIC_DECLARE(uint64_t, drop); SC_ATOMIC_DECLARE(uint64_t, drop);
@ -34,9 +37,9 @@ typedef struct LiveDevice_ {
int LiveRegisterDevice(const char *dev); int LiveRegisterDevice(const char *dev);
int LiveGetDeviceCount(void); int LiveGetDeviceCount(void);
char *LiveGetDeviceName(int number); const char *LiveGetDeviceName(int number);
int LiveSafeDeviceName(const char *devname, char *newdevname, size_t destlen);
LiveDevice *LiveGetDevice(const char *dev); LiveDevice *LiveGetDevice(const char *dev);
const char *LiveGetShortName(const char *dev);
int LiveBuildDeviceList(const char *base); int LiveBuildDeviceList(const char *base);
void LiveDeviceHasNoStats(void); void LiveDeviceHasNoStats(void);
int LiveDeviceListClean(void); int LiveDeviceListClean(void);

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

Loading…
Cancel
Save