/** * \brief Add a single Netfilter queue * * \param string with the queue number * * \retval 0 on success. * \retval -1 on failure. */ int NFQRegisterQueue(const uint16_t number) { NFQThreadVars *ntv = NULL; NFQQueueVars *nq = NULL; char queue[10] = { 0 }; static bool many_queues_warned = false; uint16_t num_cpus = UtilCpuGetNumProcessorsOnline(); if (g_nfq_t == NULL || g_nfq_q == NULL) { SCLogError(SC_ERR_INVALID_ARGUMENT, "NFQ context is not initialized"); return -1; } SCMutexLock(&nfq_init_lock); if (!many_queues_warned && (receive_queue_num >= num_cpus)) { SCLogWarning(SC_WARN_UNCOMMON, "using more Netfilter queues than %hu available CPU core(s) " "may degrade performance", num_cpus); many_queues_warned = true; } if (receive_queue_num >= NFQ_MAX_QUEUE) { SCLogError(SC_ERR_INVALID_ARGUMENT, "can not register more than %d Netfilter queues", NFQ_MAX_QUEUE); SCMutexUnlock(&nfq_init_lock); return -1; } ntv = &g_nfq_t[receive_queue_num]; ntv->nfq_index = receive_queue_num; nq = &g_nfq_q[receive_queue_num]; nq->queue_num = number; receive_queue_num++; SCMutexUnlock(&nfq_init_lock); snprintf(queue, sizeof(queue) - 1, "NFQ#%hu", number); LiveRegisterDevice(queue); ntv->livedev = LiveGetDevice(queue); if (ntv->livedev == NULL) { SCLogError(SC_ERR_INVALID_VALUE, "Unable to find Live device"); return -1; } SCLogDebug("Queue %d registered.", number); return 0; }
/** * \brief Add a Netfilter queue * * \param string with the queue name * * \retval 0 on success. * \retval -1 on failure. */ int NFQRegisterQueue(char *queue) { NFQThreadVars *ntv = NULL; NFQQueueVars *nq = NULL; /* Extract the queue number from the specified command line argument */ uint16_t queue_num = 0; if ((ByteExtractStringUint16(&queue_num, 10, strlen(queue), queue)) < 0) { SCLogError(SC_ERR_INVALID_ARGUMENT, "specified queue number %s is not " "valid", queue); return -1; } SCMutexLock(&nfq_init_lock); if (receive_queue_num >= NFQ_MAX_QUEUE) { SCLogError(SC_ERR_INVALID_ARGUMENT, "too much Netfilter queue registered (%d)", receive_queue_num); SCMutexUnlock(&nfq_init_lock); return -1; } if (receive_queue_num == 0) { memset(&nfq_t, 0, sizeof(nfq_t)); memset(&nfq_q, 0, sizeof(nfq_q)); } ntv = &nfq_t[receive_queue_num]; ntv->nfq_index = receive_queue_num; nq = &nfq_q[receive_queue_num]; nq->queue_num = queue_num; receive_queue_num++; SCMutexUnlock(&nfq_init_lock); LiveRegisterDevice(queue); SCLogDebug("Queue \"%s\" registered.", queue); return 0; }
/** * \brief Add an IPFW divert * * \param string with the queue name * * \retval 0 on success. * \retval -1 on failure. */ int IPFWRegisterQueue(char *queue) { IPFWThreadVars *ntv = NULL; IPFWQueueVars *nq = NULL; /* Extract the queue number from the specified command line argument */ uint16_t port_num = 0; if ((ByteExtractStringUint16(&port_num, 10, strlen(queue), queue)) < 0) { SCLogError(SC_ERR_INVALID_ARGUMENT, "specified queue number %s is not " "valid", queue); return -1; } SCMutexLock(&ipfw_init_lock); if (receive_port_num >= IPFW_MAX_QUEUE) { SCLogError(SC_ERR_INVALID_ARGUMENT, "too much IPFW divert port registered (%d)", receive_port_num); SCMutexUnlock(&ipfw_init_lock); return -1; } if (receive_port_num == 0) { memset(&ipfw_t, 0, sizeof(ipfw_t)); memset(&ipfw_q, 0, sizeof(ipfw_q)); } ntv = &ipfw_t[receive_port_num]; ntv->ipfw_index = receive_port_num; nq = &ipfw_q[receive_port_num]; nq->port_num = port_num; receive_port_num++; SCMutexUnlock(&ipfw_init_lock); LiveRegisterDevice(queue); SCLogDebug("Queue \"%s\" registered.", queue); return 0; }
static int GetDevAndParser(char **live_dev, ConfigIfaceParserFunc *parser) { ConfGet("pfring.live-interface", live_dev); /* determine which config type we have */ if (PfringConfLevel() > PFRING_CONF_V1) { *parser = ParsePfringConfig; } else { SCLogInfo("Using 1.0 style configuration for pfring"); *parser = OldParsePfringConfig; /* In v1: try to get interface name from config */ if (*live_dev == NULL) { if (ConfGet("pfring.interface", live_dev) == 1) { SCLogInfo("Using interface %s", *live_dev); LiveRegisterDevice(*live_dev); } else { SCLogInfo("No interface found, problem incoming"); *live_dev = NULL; } } } return 0; }