#include "parse_utils.h"
#include "log.h"
#include "quit.h"
+#include "prox_compat.h"
#define UINT32_MAX_STR "4294967295"
if (parse_vars(val, sizeof(val), pend))
return NULL;
} else
- strncpy(val, pend, sizeof(val));
+ prox_strncpy(val, pend, sizeof(val));
for (len = 0; val[len] != '\0'; ++len) {
if (strchr(valid, val[len]) == NULL) {
ret = fgets(buffer, sizeof(buffer), pcfg->pfile);
if (ret && *ret != '[') {
size_t l = strlen(buffer);
- strncpy(lines, buffer, max_len);
+ prox_strncpy(lines, buffer, max_len);
max_len -= l;
lines += l;
}
}
while (cfg_get_line(pcfg, buffer, MAX_CFG_STRING_LEN, psec->raw_lines) > 0) {
- strncpy(pcfg->cur_line, buffer, sizeof(pcfg->cur_line));
+ prox_strncpy(pcfg->cur_line, buffer, sizeof(pcfg->cur_line));
if (*buffer == '[') {
if (index_count + 1 < psec->nbindex) {
// Need to loop - go back to recorded postion in file
#include <string.h>
#include <rte_cycles.h>
+#include "prox_compat.h"
/* Calibrate TSC overhead by reading NB_READ times and take the smallest value.
Bigger values are caused by external influence and can be discarded. The best
uint64_t ret;
char str[16];
- strncpy(str, from, sizeof(str));
+ prox_strncpy(str, from, sizeof(str));
char *frac = strchr(str, '.');
#include "handle_cgnat.h"
#include "handle_impair.h"
#include "rx_pkt.h"
+#include "prox_compat.h"
static int core_task_is_valid(int lcore_id, int task_id)
{
return -1;
char *fields[9];
char str_cpy[255];
- strncpy(str_cpy, str, 255);
+ prox_strncpy(str_cpy, str, 255);
// example add rule command: rule add 15 0 1&0x0fff 1&0x0fff 0&0 128.0.0.0/1 128.0.0.0/1 5000-5000 5000-5000 allow
int ret = rte_strsplit(str_cpy, 255, fields, 9, ' ');
if (ret != 8) {
char *ret = ret2;
int list = 0;
- strncpy(buf, str, sizeof(buf) - 1);
+ prox_strncpy(buf, str, sizeof(buf) - 1);
char *tok;
uint64_t stat_val;
if (strlen(cmd_strings[i].args)) {
char tmp[256] = {0};
- strncpy(tmp, cmd_strings[i].args, 128);
+ prox_strncpy(tmp, cmd_strings[i].args, 128);
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "Arguments: %s\n", tmp);
len2 = len;
if (strlen(cmd_strings[i].help)) {
len3 = max_len;
}
- strncpy(tmp, h, len3);
+ prox_strncpy(tmp, h, len3);
h += len3;
while (h[0] == ' ' && strlen(h))
h++;
#include "prox_args.h"
#include "file_utils.h"
+#include "prox_compat.h"
static char file_error_string[128] = {0};
if (path[0] != '/')
snprintf(file_name, len, "%s/%s", get_cfg_dir(), path);
else
- strncpy(file_name, path, len);
+ prox_strncpy(file_name, path, len);
}
long file_get_size(const char *path)
break;
case ACL_ALLOW:
out[i] = 0;
+ __attribute__ ((fallthrough));
case ACL_RATE_LIMIT:
set_tc(mbufs[i], 3);
break;
#include "task_init.h"
#include "task_base.h"
#include "stats.h"
+#include "prox_compat.h"
struct task_dump {
struct task_base base;
uint32_t n_mbufs;
struct rte_mbuf **mbufs;
uint32_t n_pkts;
- char pcap_file[128];
+ char pcap_file[256];
};
static uint16_t buffer_packets(struct task_dump *task, struct rte_mbuf **mbufs, uint16_t n_pkts)
if (!strcmp(targ->pcap_file, "")) {
strcpy(targ->pcap_file, "out.pcap");
}
- strncpy(task->pcap_file, targ->pcap_file, sizeof(task->pcap_file));
+ prox_strncpy(task->pcap_file, targ->pcap_file, sizeof(task->pcap_file));
}
static void stop(struct task_base *tbase)
#include "defaults.h"
#include "etypes.h"
#include "prox_cfg.h"
+#include "prox_compat.h"
static pthread_mutex_t file_mtx = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
int log_lvl = PROX_MAX_LOG_LVL;
static void store_warning(const char *warning)
{
- strncpy(last_warn[n_warnings % 5], warning, sizeof(last_warn[0]));
+ prox_strncpy(last_warn[n_warnings % 5], warning, sizeof(last_warn[0]));
n_warnings++;
}
if (log_name_pid)
snprintf(buf, sizeof(buf), "%s-%u.log", "prox", getpid());
else
- strncpy(buf, "prox.log", sizeof(buf));
+ prox_strncpy(buf, "prox.log", sizeof(buf));
}
else {
- strncpy(buf, log_name, sizeof(buf));
+ prox_strncpy(buf, log_name, sizeof(buf));
}
fp = fopen(buf, "w");
#include "log.h"
#include "prox_lua.h"
#include "prox_lua_types.h"
+#include "prox_compat.h"
#define MAX_NB_PORT_NAMES PROX_MAX_PORTS
#define MAX_LEN_PORT_NAME 24
match->name, match->val);
return -1;
}
- strncpy(val, match->val, len);
+ prox_strncpy(val, match->val, len);
return 0;
}
else {
return -1;
}
- strncpy(&cur_var[1], &name[start_var], var_len);
+ prox_strncpy(&cur_var[1], &name[start_var], var_len);
cur_var[1 + var_len] = 0;
if (parse_single_var(parsed, sizeof(parsed), cur_var)) {
return -1;
break;
}
}
- strncpy(val, result, len);
+ prox_strncpy(val, result, len);
return 0;
}
if (*val >> 22)
return -2;
*val <<= 10;
+ __attribute__ ((fallthrough));
case 'M':
if (*val >> 22)
return -2;
*val <<= 10;
+ __attribute__ ((fallthrough));
case 'K':
if (*val >> 22)
return -2;
return -2;
}
- strncpy(dst, str, max_len);
+ prox_strncpy(dst, str, max_len);
return 0;
}
set_errf("String too long (max supported: %d)", MAX_STR_LEN_PROC);
return -2;
}
- strncpy(str_cpy, str, MAX_STR_LEN_PROC);
+ prox_strncpy(str_cpy, str, MAX_STR_LEN_PROC);
ret = rte_strsplit(str_cpy, strlen(str_cpy), elements, PROX_MAX_PORTS + 1, ',');
if (ret <= 0) {
}
pn = &port_names[nb_port_names];
- strncpy(pn->name, str, sizeof(pn->name));
+ prox_strncpy(pn->name, str, sizeof(pn->name));
pn->id = val;
++nb_port_names;
struct var *v = &vars[nb_vars];
- strncpy(v->name, "$self", strlen("$self"));
+ prox_strncpy(v->name, "$self", strlen("$self") + 1);
sprintf(v->val, "%s", str);
nb_vars++;
v = &vars[nb_vars];
PROX_PANIC(strlen(name) > sizeof(v->name), "\tUnable to parse var %s: too long\n", name);
PROX_PANIC(strlen(str) > sizeof(v->val), "\tUnable to parse var %s=%s: too long\n", name,str);
- strncpy(v->name, name, sizeof(v->name));
- strncpy(v->val, str, sizeof(v->val));
+ prox_strncpy(v->name, name, sizeof(v->name));
+ prox_strncpy(v->val, str, sizeof(v->val));
v->cli = cli;
++nb_vars;
while (end > 0 && cfg_file[end] != '/')
end--;
- strncpy(dir, cfg_file, end);
+ prox_strncpy(dir, cfg_file, end);
return dir;
}
struct lua_State *l = prox_lua();
char str_cpy[1024];
- strncpy(str_cpy, str, sizeof(str_cpy));
+ prox_strncpy(str_cpy, str, sizeof(str_cpy));
uint32_t len = strlen(str_cpy);
str_cpy[len++] = '\n';
str_cpy[len++] = 0;
}
else if (STR_EQ(str, "name")) {
uint32_t val;
- strncpy(cfg->name, pkey, MAX_NAME_SIZE);
+ prox_strncpy(cfg->name, pkey, MAX_NAME_SIZE);
PROX_ASSERT(cur_if < PROX_MAX_PORTS);
return add_port_name(cur_if, pkey);
}
}
}
- strncpy(prox_cfg.name, cfg_file + offset, MAX_NAME_SIZE);
+ prox_strncpy(prox_cfg.name, cfg_file + offset, MAX_NAME_SIZE);
break;
case 'v':
plog_set_lvl(atoi(optarg));
break;
case 'l':
prox_cfg.log_name_pid = 0;
- strncpy(prox_cfg.log_name, optarg, MAX_NAME_SIZE);
+ prox_strncpy(prox_cfg.log_name, optarg, MAX_NAME_SIZE);
break;
case 'p':
prox_cfg.log_name_pid = 1;
case 'r':
if (!str_is_number(optarg) || strlen(optarg) > 11)
return -1;
- strncpy(prox_cfg.update_interval_str, optarg, sizeof(prox_cfg.update_interval_str));
+ prox_strncpy(prox_cfg.update_interval_str, optarg, sizeof(prox_cfg.update_interval_str));
break;
case 'o':
if (prox_cfg.flags & DSF_DAEMON)
(tmp2 = strchr(tmp, '='))) {
*tmp2 = 0;
tmp3[0] = '$';
- strncpy(tmp3 + 1, tmp, 63);
+ prox_strncpy(tmp3 + 1, tmp, 63);
plog_info("\tAdding variable: %s = %s\n", tmp3, tmp2 + 1);
ret = add_var(tmp3, tmp2 + 1, 1);
if (ret == -2) {
#include <rte_table_hash.h>
#include <rte_hash_crc.h>
#include "hash_utils.h"
+#include "quit.h"
/* This is a copy of the rte_table_hash_params from DPDK 17.11 *
* So if DPDK decides to change the structure the modifications *
#ifndef DEV_RX_OFFLOAD_JUMBO_FRAME
#define DEV_RX_OFFLOAD_JUMBO_FRAME 0x00000800
#endif
+
+static inline char *prox_strncpy(char * dest, const char * src, size_t count)
+{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
+ strncpy(dest, src, count);
+#pragma GCC diagnostic pop
+ PROX_PANIC(dest[count - 1] != 0, "\t\tError in strncpy: buffer overrun (%lu bytes)", count);
+ return dest;
+}
#include "prox_lua.h"
#include "lua_compat.h"
#include "parse_utils.h"
+#include "prox_compat.h"
static struct lua_State *lua_instance;
if (lua_isstring(L, -1)) {
const char *arg = lua_tostring(L, -1);
char arg2[128];
- strncpy(arg2, arg, sizeof(arg2));
+ prox_strncpy(arg2, arg, sizeof(arg2));
char *p = arg2;
int count = 0;
int next_str = 1;
int ret;
- strncpy(arg2, arg, sizeof(arg2));
+ prox_strncpy(arg2, arg, sizeof(arg2));
for (size_t i = 0; i < str_len; ++i) {
if (next_str) {
const char *arg = lua_tostring(L, -1);
char tmp[128];
- strncpy(tmp, arg, sizeof(tmp));
+ prox_strncpy(tmp, arg, sizeof(tmp));
char *slash = strchr(tmp, '/');
*slash = 0;
const char *arg = lua_tostring(L, -1);
char tmp[128];
- strncpy(tmp, arg, sizeof(tmp));
+ prox_strncpy(tmp, arg, sizeof(tmp));
char *slash = strchr(tmp, '/');
*slash = 0;
#include "handle_qinq_encap4.h"
#include "toeplitz.h"
#include "handle_lb_5tuple.h"
+#include "prox_compat.h"
#if RTE_VERSION < RTE_VERSION_NUM(1,8,0,0)
#define RTE_CACHE_LINE_SIZE CACHE_LINE_SIZE
}
str = lua_tostring(L, -1);
- strncpy(dst, str, size);
+ prox_strncpy(dst, str, size);
lua_pop(L, pop);
return 0;
port_cfg->max_rx_pkt_len = dev_info.max_rx_pktlen;
port_cfg->min_rx_bufsize = dev_info.min_rx_bufsize;
- strncpy(port_cfg->driver_name, dev_info.driver_name, sizeof(port_cfg->driver_name));
+ prox_strncpy(port_cfg->driver_name, dev_info.driver_name, sizeof(port_cfg->driver_name));
plog_info("\tPort %u : driver='%s' tx_queues=%d rx_queues=%d\n", port_id, !strcmp(port_cfg->driver_name, "")? "null" : port_cfg->driver_name, port_cfg->max_txq, port_cfg->max_rxq);
if (strncmp(port_cfg->driver_name, "rte_", 4) == 0) {
- strncpy(port_cfg->short_name, prox_port_cfg[port_id].driver_name + 4, sizeof(port_cfg->short_name));
+ prox_strncpy(port_cfg->short_name, prox_port_cfg[port_id].driver_name + 4, sizeof(port_cfg->short_name));
} else if (strncmp(port_cfg->driver_name, "net_", 4) == 0) {
- strncpy(port_cfg->short_name, prox_port_cfg[port_id].driver_name + 4, sizeof(port_cfg->short_name));
+ prox_strncpy(port_cfg->short_name, prox_port_cfg[port_id].driver_name + 4, sizeof(port_cfg->short_name));
} else {
- strncpy(port_cfg->short_name, prox_port_cfg[port_id].driver_name, sizeof(port_cfg->short_name));
+ prox_strncpy(port_cfg->short_name, prox_port_cfg[port_id].driver_name, sizeof(port_cfg->short_name));
}
char *ptr;
if ((ptr = strstr(port_cfg->short_name, "_pmd")) != NULL) {
#include "log.h"
#include "prox_shared.h"
#include "prox_globals.h"
+#include "prox_compat.h"
#define INIT_HASH_TABLE_SIZE 8192
char key[256] = {0};
int ret;
- strncpy(key, name, sizeof(key));
+ prox_strncpy(key, name, sizeof(key));
if (ps->size == 0) {
prox_sh_create_hash(ps, INIT_HASH_TABLE_SIZE);
}
if (!sh->hash)
return NULL;
- strncpy(key, name, sizeof(key));
+ prox_strncpy(key, name, sizeof(key));
ret = rte_hash_lookup_data(sh->hash, key, &data);
if (ret >= 0)
return data;
#include "display.h"
#include "prox_cfg.h"
+#include "log.h"
/* PROX_PANIC for checks that are possibly hit due to configuration or
when feature is not implemented. */
#include "stats_global.h"
#include "stats_prio_task.h"
#include "stats_irq.h"
+#include "prox_compat.h"
struct stats_path_str {
const char *str;
char stats_path_cpy[128];
- strncpy(stats_path_cpy, stats_path, sizeof(stats_path_cpy));
+ prox_strncpy(stats_path_cpy, stats_path, sizeof(stats_path_cpy));
stats_path_len = strlen(stats_path);
size_t max_argc = 16;