From: maxtors Date: Wed, 15 Apr 2015 13:21:24 +0000 (+0200) Subject: Added shortening of listening interface in util-runmodes X-Git-Tag: suricata-3.1RC1~226 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=10d1450e4995630834736bcb5ed192a463d87659;p=thirdparty%2Fsuricata.git Added shortening of listening interface in util-runmodes Added function LiveSafeDeviceName in util-device that shortens an NIC device name if the name is over a given length and turns it in to Ex: longi...eeth1 --- diff --git a/src/util-device.c b/src/util-device.c index 9332fcec4f..917e989537 100644 --- a/src/util-device.c +++ b/src/util-device.c @@ -19,6 +19,9 @@ #include "conf.h" #include "util-device.h" +#define MAX_DEVNAME 12 +#define DEVNAME_CHUNCK 5 + /** * \file * @@ -105,6 +108,28 @@ char *LiveGetDeviceName(int number) return NULL; } +/** + * \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 + */ +void LiveSafeDeviceName(const char *devname, char *newdevname) +{ + size_t devnamelen = strlen(devname); + + if (devnamelen > MAX_DEVNAME) { + strncpy(newdevname, devname, DEVNAME_CHUNCK); + strncpy(newdevname+DEVNAME_CHUNCK, "...", 3); + strncpy(newdevname+8, devname+(devnamelen-DEVNAME_CHUNCK), DEVNAME_CHUNCK); + strncpy(newdevname+13, "\0", 1); + SCLogInfo("Shortening device name to: %s", newdevname); + } else { + strcpy(newdevname, devname); + } +} + /** * \brief Get a pointer to the device at idx * diff --git a/src/util-device.h b/src/util-device.h index 1fabdbe596..5260db16f0 100644 --- a/src/util-device.h +++ b/src/util-device.h @@ -35,6 +35,7 @@ typedef struct LiveDevice_ { int LiveRegisterDevice(const char *dev); int LiveGetDeviceCount(void); char *LiveGetDeviceName(int number); +void LiveSafeDeviceName(const char *devname, char *newdevname); LiveDevice *LiveGetDevice(const char *dev); int LiveBuildDeviceList(const char *base); void LiveDeviceHasNoStats(void); diff --git a/src/util-runmodes.c b/src/util-runmodes.c index 3c5f39a775..cfeba9a845 100644 --- a/src/util-runmodes.c +++ b/src/util-runmodes.c @@ -186,6 +186,7 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser, for (lthread = 0; lthread < nlive; lthread++) { char *live_dev = LiveGetDeviceName(lthread); + char visual_devname[14] = ""; void *aconf; int threads_count; @@ -204,6 +205,7 @@ int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser, threads_count = ModThreadsCount(aconf); for (thread = 0; thread < threads_count; thread++) { + LiveSafeDeviceName(live_dev, visual_devname); snprintf(tname, sizeof(tname), "%s%s%d", thread_name, live_dev, thread+1); ThreadVars *tv_receive = @@ -314,12 +316,16 @@ static int RunModeSetLiveCaptureWorkersForDevice(ConfigIfaceThreadsCountFunc Mod /* create the threads */ for (thread = 0; thread < threads_count; thread++) { char tname[TM_THREAD_NAME_MAX]; + char *n_thread_name = NULL; + char visual_devname[13] = ""; ThreadVars *tv = NULL; TmModule *tm_module = NULL; if (single_mode) { snprintf(tname, sizeof(tname), "%s", thread_name); } else { + LiveSafeDeviceName(live_dev, visual_devname); + SCLogInfo("New dev name %s", visual_devname); snprintf(tname, sizeof(tname), "%s%s%d", thread_name, live_dev, thread+1); }