X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_eal%2Fcommon%2Feal_common_options.c;h=a5426e12346a7591180dd6313f4a46c4eb087875;hb=819a716858264d6c90f554e4fe53740b42c4c893;hp=0546beb3a075ab0c64e00eedcedab9a86e78b459;hpb=d87f964ce6decd07f64091a36a55642b8960fd4e;p=dpdk.git diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 0546beb3a0..a5426e1234 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -15,6 +15,7 @@ #include #ifndef RTE_EXEC_ENV_WINDOWS #include +#include #endif #include #include @@ -94,6 +95,7 @@ eal_long_options[] = { {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM }, {OPT_VDEV, 1, NULL, OPT_VDEV_NUM }, {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM }, + {OPT_VFIO_VF_TOKEN, 1, NULL, OPT_VFIO_VF_TOKEN_NUM }, {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM }, {OPT_LEGACY_MEM, 0, NULL, OPT_LEGACY_MEM_NUM }, {OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM}, @@ -146,6 +148,29 @@ static int master_lcore_parsed; static int mem_parsed; static int core_parsed; +/* Allow the application to print its usage message too if set */ +static rte_usage_hook_t rte_application_usage_hook; + +/* Returns rte_usage_hook_t */ +rte_usage_hook_t +eal_get_application_usage_hook(void) +{ + return rte_application_usage_hook; +} + +/* Set a per-application usage message */ +rte_usage_hook_t +rte_set_application_usage_hook(rte_usage_hook_t usage_func) +{ + rte_usage_hook_t old_func; + + /* Will be NULL on the first call to denote the last usage routine. */ + old_func = rte_application_usage_hook; + rte_application_usage_hook = usage_func; + + return old_func; +} + #ifndef RTE_EXEC_ENV_WINDOWS static char **eal_args; static char **eal_app_args; @@ -264,8 +289,11 @@ eal_option_device_parse(void) const char * eal_get_hugefile_prefix(void) { - if (internal_config.hugefile_prefix != NULL) - return internal_config.hugefile_prefix; + const struct internal_config *internal_conf = + eal_get_internal_configuration(); + + if (internal_conf->hugefile_prefix != NULL) + return internal_conf->hugefile_prefix; return HUGEFILE_PREFIX_DEFAULT; } @@ -301,6 +329,8 @@ eal_reset_internal_config(struct internal_config *internal_cfg) /* if set to NONE, interrupt mode is determined automatically */ internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE; + memset(internal_cfg->vfio_vf_token, 0, + sizeof(internal_cfg->vfio_vf_token)); #ifdef RTE_LIBEAL_USE_HPET internal_cfg->no_hpet = 0; @@ -326,14 +356,20 @@ eal_plugin_add(const char *path) return -1; } memset(solib, 0, sizeof(*solib)); - strlcpy(solib->name, path, PATH_MAX-1); - solib->name[PATH_MAX-1] = 0; + strlcpy(solib->name, path, PATH_MAX); TAILQ_INSERT_TAIL(&solib_list, solib, next); return 0; } -#ifndef RTE_EXEC_ENV_WINDOWS +#ifdef RTE_EXEC_ENV_WINDOWS +int +eal_plugins_init(void) +{ + return 0; +} +#else + static int eal_plugindir_init(const char *path) { @@ -353,9 +389,15 @@ eal_plugindir_init(const char *path) while ((dent = readdir(d)) != NULL) { struct stat sb; + int nlen = strnlen(dent->d_name, sizeof(dent->d_name)); + + /* check if name ends in .so */ + if (strcmp(&dent->d_name[nlen - 3], ".so") != 0) + continue; snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name); + /* if a regular file, add to list to load */ if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode))) continue; @@ -367,17 +409,93 @@ eal_plugindir_init(const char *path) /* XXX this ignores failures from readdir() itself */ return (dent == NULL) ? 0 : -1; } -#endif + +static int +verify_perms(const char *dirpath) +{ + struct stat st; + + /* if not root, check down one level first */ + if (strcmp(dirpath, "/") != 0) { + static __thread char last_dir_checked[PATH_MAX]; + char copy[PATH_MAX]; + const char *dir; + + strlcpy(copy, dirpath, PATH_MAX); + dir = dirname(copy); + if (strncmp(dir, last_dir_checked, PATH_MAX) != 0) { + if (verify_perms(dir) != 0) + return -1; + strlcpy(last_dir_checked, dir, PATH_MAX); + } + } + + /* call stat to check for permissions and ensure not world writable */ + if (stat(dirpath, &st) != 0) { + RTE_LOG(ERR, EAL, "Error with stat on %s, %s\n", + dirpath, strerror(errno)); + return -1; + } + if (st.st_mode & S_IWOTH) { + RTE_LOG(ERR, EAL, + "Error, directory path %s is world-writable and insecure\n", + dirpath); + return -1; + } + + return 0; +} + +static void * +eal_dlopen(const char *pathname) +{ + void *retval = NULL; + char *realp = realpath(pathname, NULL); + + if (realp == NULL && errno == ENOENT) { + /* not a full or relative path, try a load from system dirs */ + retval = dlopen(pathname, RTLD_NOW); + if (retval == NULL) + RTE_LOG(ERR, EAL, "%s\n", dlerror()); + return retval; + } + if (realp == NULL) { + RTE_LOG(ERR, EAL, "Error with realpath for %s, %s\n", + pathname, strerror(errno)); + goto out; + } + if (strnlen(realp, PATH_MAX) == PATH_MAX) { + RTE_LOG(ERR, EAL, "Error, driver path greater than PATH_MAX\n"); + goto out; + } + + /* do permissions checks */ + if (verify_perms(realp) != 0) + goto out; + + retval = dlopen(realp, RTLD_NOW); + if (retval == NULL) + RTE_LOG(ERR, EAL, "%s\n", dlerror()); +out: + free(realp); + return retval; +} int eal_plugins_init(void) { -#ifndef RTE_EXEC_ENV_WINDOWS struct shared_driver *solib = NULL; struct stat sb; - if (*default_solib_dir != '\0' && stat(default_solib_dir, &sb) == 0 && - S_ISDIR(sb.st_mode)) + /* If we are not statically linked, add default driver loading + * path if it exists as a directory. + * (Using dlopen with NOLOAD flag on EAL, will return NULL if the EAL + * shared library is not already loaded i.e. it's statically linked.) + */ + if (dlopen("librte_eal.so", RTLD_LAZY | RTLD_NOLOAD) != NULL && + *default_solib_dir != '\0' && + stat(default_solib_dir, &sb) == 0 && + S_ISDIR(sb.st_mode)) eal_plugin_add(default_solib_dir); TAILQ_FOREACH(solib, &solib_list, next) { @@ -392,17 +510,15 @@ eal_plugins_init(void) } else { RTE_LOG(DEBUG, EAL, "open shared lib %s\n", solib->name); - solib->lib_handle = dlopen(solib->name, RTLD_NOW); - if (solib->lib_handle == NULL) { - RTE_LOG(ERR, EAL, "%s\n", dlerror()); + solib->lib_handle = eal_dlopen(solib->name); + if (solib->lib_handle == NULL) return -1; - } } } -#endif return 0; } +#endif /* * Parse the coremask given as argument (hexadecimal string) and fill @@ -1176,6 +1292,8 @@ static int eal_parse_iova_mode(const char *name) { int mode; + struct internal_config *internal_conf = + eal_get_internal_configuration(); if (name == NULL) return -1; @@ -1187,7 +1305,7 @@ eal_parse_iova_mode(const char *name) else return -1; - internal_config.iova_mode = mode; + internal_conf->iova_mode = mode; return 0; } @@ -1196,6 +1314,8 @@ eal_parse_base_virtaddr(const char *arg) { char *end; uint64_t addr; + struct internal_config *internal_conf = + eal_get_internal_configuration(); errno = 0; addr = strtoull(arg, &end, 16); @@ -1215,7 +1335,7 @@ eal_parse_base_virtaddr(const char *arg) * it can align to 2MB for x86. So this alignment can also be used * on x86 and other architectures. */ - internal_config.base_virtaddr = + internal_conf->base_virtaddr = RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M); return 0; @@ -1668,12 +1788,14 @@ eal_adjust_config(struct internal_config *internal_cfg) { int i; struct rte_config *cfg = rte_eal_get_configuration(); + struct internal_config *internal_conf = + eal_get_internal_configuration(); if (!core_parsed) eal_auto_detect_cores(cfg); - if (internal_config.process_type == RTE_PROC_AUTO) - internal_config.process_type = eal_proc_type_detect(); + if (internal_conf->process_type == RTE_PROC_AUTO) + internal_conf->process_type = eal_proc_type_detect(); /* default master lcore is the first one */ if (!master_lcore_parsed) { @@ -1697,6 +1819,8 @@ int eal_check_common_options(struct internal_config *internal_cfg) { struct rte_config *cfg = rte_eal_get_configuration(); + const struct internal_config *internal_conf = + eal_get_internal_configuration(); if (cfg->lcore_role[cfg->master_lcore] != ROLE_RTE) { RTE_LOG(ERR, EAL, "Master lcore is not enabled for DPDK\n"); @@ -1743,7 +1867,7 @@ eal_check_common_options(struct internal_config *internal_cfg) "be specified together with --"OPT_NO_HUGE"\n"); return -1; } - if (internal_config.force_socket_limits && internal_config.legacy_mem) { + if (internal_conf->force_socket_limits && internal_conf->legacy_mem) { RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT " is only supported in non-legacy memory mode\n"); }