diff --git a/src/respond-reject-libnet11.c b/src/respond-reject-libnet11.c index b27b74e9d9..c52e340c5b 100644 --- a/src/respond-reject-libnet11.c +++ b/src/respond-reject-libnet11.c @@ -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; diff --git a/src/runmode-af-packet.c b/src/runmode-af-packet.c index 34b1a3872b..f485f5b23c 100644 --- a/src/runmode-af-packet.c +++ b/src/runmode-af-packet.c @@ -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; diff --git a/src/runmode-netmap.c b/src/runmode-netmap.c index 8403d0843e..e476dd0403 100644 --- a/src/runmode-netmap.c +++ b/src/runmode-netmap.c @@ -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; diff --git a/src/source-mpipe.c b/src/source-mpipe.c index d304b4a8b1..0310115a04 100644 --- a/src/source-mpipe.c +++ b/src/source-mpipe.c @@ -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; diff --git a/src/suricata.c b/src/suricata.c index 198420b3e6..a6e3e1f7b1 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -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)); diff --git a/src/util-device.c b/src/util-device.c index 409f8732cc..582746ac12 100644 --- a/src/util-device.c +++ b/src/util-device.c @@ -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) { diff --git a/src/util-device.h b/src/util-device.h index a6f78dd50b..ca3d91331a 100644 --- a/src/util-device.h +++ b/src/util-device.h @@ -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); diff --git a/src/util-runmodes.c b/src/util-runmodes.c index d2789f0f47..8f01983ab4 100644 --- a/src/util-runmodes.c +++ b/src/util-runmodes.c @@ -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();