diff options
-rw-r--r-- | VNFs/DPPD-PROX/cfgfile.c | 7 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/clock.c | 3 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/cmd_parser.c | 9 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/file_utils.c | 3 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/handle_acl.c | 1 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/handle_dump.c | 5 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/log.c | 7 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/parse_utils.c | 21 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/prox_args.c | 14 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/prox_compat.h | 11 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/prox_lua.c | 9 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/prox_lua_types.c | 3 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/prox_port_cfg.c | 8 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/prox_shared.c | 5 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/quit.h | 1 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/stats_parser.c | 3 |
16 files changed, 68 insertions, 42 deletions
diff --git a/VNFs/DPPD-PROX/cfgfile.c b/VNFs/DPPD-PROX/cfgfile.c index b15fc0ad..dc225075 100644 --- a/VNFs/DPPD-PROX/cfgfile.c +++ b/VNFs/DPPD-PROX/cfgfile.c @@ -26,6 +26,7 @@ #include "parse_utils.h" #include "log.h" #include "quit.h" +#include "prox_compat.h" #define UINT32_MAX_STR "4294967295" @@ -195,7 +196,7 @@ static struct cfg_section *cfg_check_section(char *buffer, struct cfg_section *p 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) { @@ -275,7 +276,7 @@ int cfg_parse(struct cfg_file *pcfg, struct cfg_section *psec) 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; } @@ -299,7 +300,7 @@ int cfg_parse(struct cfg_file *pcfg, struct cfg_section *psec) } 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 diff --git a/VNFs/DPPD-PROX/clock.c b/VNFs/DPPD-PROX/clock.c index 6e057101..43caccad 100644 --- a/VNFs/DPPD-PROX/clock.c +++ b/VNFs/DPPD-PROX/clock.c @@ -20,6 +20,7 @@ #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 @@ -92,7 +93,7 @@ uint64_t str_to_tsc(const char *from) uint64_t ret; char str[16]; - strncpy(str, from, sizeof(str)); + prox_strncpy(str, from, sizeof(str)); char *frac = strchr(str, '.'); diff --git a/VNFs/DPPD-PROX/cmd_parser.c b/VNFs/DPPD-PROX/cmd_parser.c index ced6d288..79c939b9 100644 --- a/VNFs/DPPD-PROX/cmd_parser.c +++ b/VNFs/DPPD-PROX/cmd_parser.c @@ -52,6 +52,7 @@ #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) { @@ -823,7 +824,7 @@ static int parse_cmd_rule_add(const char *str, struct input *input) 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) { @@ -1491,7 +1492,7 @@ static int parse_cmd_stats(const char *str, struct input *input) 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; @@ -2157,7 +2158,7 @@ static int parse_cmd_help(const char *str, struct input *input) 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)) { @@ -2189,7 +2190,7 @@ static int parse_cmd_help(const char *str, struct input *input) len3 = max_len; } - strncpy(tmp, h, len3); + prox_strncpy(tmp, h, len3); h += len3; while (h[0] == ' ' && strlen(h)) h++; diff --git a/VNFs/DPPD-PROX/file_utils.c b/VNFs/DPPD-PROX/file_utils.c index b3cf0846..cf1d3444 100644 --- a/VNFs/DPPD-PROX/file_utils.c +++ b/VNFs/DPPD-PROX/file_utils.c @@ -22,6 +22,7 @@ #include "prox_args.h" #include "file_utils.h" +#include "prox_compat.h" static char file_error_string[128] = {0}; @@ -44,7 +45,7 @@ static void resolve_path_cfg_dir(char *file_name, size_t len, const char *path) 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) diff --git a/VNFs/DPPD-PROX/handle_acl.c b/VNFs/DPPD-PROX/handle_acl.c index 03949360..c0a1b86b 100644 --- a/VNFs/DPPD-PROX/handle_acl.c +++ b/VNFs/DPPD-PROX/handle_acl.c @@ -108,6 +108,7 @@ static int handle_acl_bulk(struct task_base *tbase, struct rte_mbuf **mbufs, uin break; case ACL_ALLOW: out[i] = 0; + __attribute__ ((fallthrough)); case ACL_RATE_LIMIT: set_tc(mbufs[i], 3); break; diff --git a/VNFs/DPPD-PROX/handle_dump.c b/VNFs/DPPD-PROX/handle_dump.c index c35a6e9e..71874620 100644 --- a/VNFs/DPPD-PROX/handle_dump.c +++ b/VNFs/DPPD-PROX/handle_dump.c @@ -24,13 +24,14 @@ #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) @@ -69,7 +70,7 @@ static void init_task_dump(struct task_base *tbase, __attribute__((unused)) stru 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) diff --git a/VNFs/DPPD-PROX/log.c b/VNFs/DPPD-PROX/log.c index 7049a5e3..56338f89 100644 --- a/VNFs/DPPD-PROX/log.c +++ b/VNFs/DPPD-PROX/log.c @@ -29,6 +29,7 @@ #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; @@ -56,7 +57,7 @@ const char *get_warning(int i) 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++; } @@ -69,10 +70,10 @@ void plog_init(const char *log_name, int log_name_pid) 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"); diff --git a/VNFs/DPPD-PROX/parse_utils.c b/VNFs/DPPD-PROX/parse_utils.c index 6653ca6f..84ff8cc9 100644 --- a/VNFs/DPPD-PROX/parse_utils.c +++ b/VNFs/DPPD-PROX/parse_utils.c @@ -34,6 +34,7 @@ #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 @@ -117,7 +118,7 @@ int parse_single_var(char *val, size_t len, const char *name) match->name, match->val); return -1; } - strncpy(val, match->val, len); + prox_strncpy(val, match->val, len); return 0; } else { @@ -174,7 +175,7 @@ int parse_vars(char *val, size_t len, const char *name) 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; @@ -195,7 +196,7 @@ int parse_vars(char *val, size_t len, const char *name) break; } } - strncpy(val, result, len); + prox_strncpy(val, result, len); return 0; } @@ -922,10 +923,12 @@ int parse_kmg(uint32_t* val, const char *str2) 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; @@ -1048,7 +1051,7 @@ int parse_str(char* dst, const char *str2, size_t max_len) return -2; } - strncpy(dst, str, max_len); + prox_strncpy(dst, str, max_len); return 0; } @@ -1122,7 +1125,7 @@ int parse_remap(uint8_t *mapping, const char *str) 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) { @@ -1179,7 +1182,7 @@ int add_port_name(uint32_t val, const char *str2) } 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; @@ -1197,7 +1200,7 @@ int set_self_var(const char *str) 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++; @@ -1245,8 +1248,8 @@ int add_var(const char* name, const char *str2, uint8_t cli) 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; diff --git a/VNFs/DPPD-PROX/prox_args.c b/VNFs/DPPD-PROX/prox_args.c index e1ed10ee..b99796b7 100644 --- a/VNFs/DPPD-PROX/prox_args.c +++ b/VNFs/DPPD-PROX/prox_args.c @@ -242,7 +242,7 @@ const char *get_cfg_dir(void) while (end > 0 && cfg_file[end] != '/') end--; - strncpy(dir, cfg_file, end); + prox_strncpy(dir, cfg_file, end); return dir; } @@ -263,7 +263,7 @@ static int get_lua_cfg(__attribute__((unused)) unsigned sindex, __attribute__((u 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; @@ -517,7 +517,7 @@ static int get_port_cfg(unsigned sindex, char *str, void *data) } 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); } @@ -1635,14 +1635,14 @@ int prox_parse_args(int argc, char **argv) } } - 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; @@ -1664,7 +1664,7 @@ int prox_parse_args(int argc, char **argv) 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) @@ -1729,7 +1729,7 @@ int prox_parse_args(int argc, char **argv) (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) { diff --git a/VNFs/DPPD-PROX/prox_compat.h b/VNFs/DPPD-PROX/prox_compat.h index 3ad04140..7564f294 100644 --- a/VNFs/DPPD-PROX/prox_compat.h +++ b/VNFs/DPPD-PROX/prox_compat.h @@ -17,6 +17,7 @@ #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 * @@ -128,3 +129,13 @@ static void *prox_rte_table_create(struct prox_rte_table_params *params, int soc #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; +} diff --git a/VNFs/DPPD-PROX/prox_lua.c b/VNFs/DPPD-PROX/prox_lua.c index b5c2fec9..4e2f18a6 100644 --- a/VNFs/DPPD-PROX/prox_lua.c +++ b/VNFs/DPPD-PROX/prox_lua.c @@ -20,6 +20,7 @@ #include "prox_lua.h" #include "lua_compat.h" #include "parse_utils.h" +#include "prox_compat.h" static struct lua_State *lua_instance; @@ -137,7 +138,7 @@ static int l_mac(lua_State *L) 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; @@ -223,7 +224,7 @@ static int l_ip6(lua_State *L) 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) { @@ -270,7 +271,7 @@ static int l_cidr(lua_State *L) 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; @@ -296,7 +297,7 @@ static int l_cidr6(lua_State *L) 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; diff --git a/VNFs/DPPD-PROX/prox_lua_types.c b/VNFs/DPPD-PROX/prox_lua_types.c index 7a0b6e08..f901b931 100644 --- a/VNFs/DPPD-PROX/prox_lua_types.c +++ b/VNFs/DPPD-PROX/prox_lua_types.c @@ -39,6 +39,7 @@ #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 @@ -345,7 +346,7 @@ int lua_to_string(struct lua_State *L, enum lua_place from, const char *name, ch } str = lua_tostring(L, -1); - strncpy(dst, str, size); + prox_strncpy(dst, str, size); lua_pop(L, pop); return 0; diff --git a/VNFs/DPPD-PROX/prox_port_cfg.c b/VNFs/DPPD-PROX/prox_port_cfg.c index 043e755b..481fa368 100644 --- a/VNFs/DPPD-PROX/prox_port_cfg.c +++ b/VNFs/DPPD-PROX/prox_port_cfg.c @@ -224,15 +224,15 @@ void init_rte_dev(int use_dummy_devices) 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) { diff --git a/VNFs/DPPD-PROX/prox_shared.c b/VNFs/DPPD-PROX/prox_shared.c index 890d564b..db381ff5 100644 --- a/VNFs/DPPD-PROX/prox_shared.c +++ b/VNFs/DPPD-PROX/prox_shared.c @@ -23,6 +23,7 @@ #include "log.h" #include "prox_shared.h" #include "prox_globals.h" +#include "prox_compat.h" #define INIT_HASH_TABLE_SIZE 8192 @@ -84,7 +85,7 @@ static int prox_sh_add(struct prox_shared *ps, const char *name, void *data) 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); } @@ -121,7 +122,7 @@ static void *prox_sh_find(struct prox_shared *sh, const char *name) 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; diff --git a/VNFs/DPPD-PROX/quit.h b/VNFs/DPPD-PROX/quit.h index a01c0a02..d0bf8b95 100644 --- a/VNFs/DPPD-PROX/quit.h +++ b/VNFs/DPPD-PROX/quit.h @@ -25,6 +25,7 @@ #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. */ diff --git a/VNFs/DPPD-PROX/stats_parser.c b/VNFs/DPPD-PROX/stats_parser.c index 73db5010..c9428072 100644 --- a/VNFs/DPPD-PROX/stats_parser.c +++ b/VNFs/DPPD-PROX/stats_parser.c @@ -31,6 +31,7 @@ #include "stats_global.h" #include "stats_prio_task.h" #include "stats_irq.h" +#include "prox_compat.h" struct stats_path_str { const char *str; @@ -910,7 +911,7 @@ uint64_t stats_parser_get(const char *stats_path) 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; |