Skip to content

Commit

Permalink
ipvsadm: add version info
Browse files Browse the repository at this point in the history
Signed-off-by: ywc689 <[email protected]>
  • Loading branch information
ywc689 committed Sep 9, 2022
1 parent 4b4a5b7 commit d4d6285
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/global_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ extern char *dpvs_conf_file;
extern char *dpvs_pid_file;
extern char *dpvs_ipc_file;

extern unsigned int g_version;
extern bool g_kni_enabled;

#ifdef CONFIG_DPVS_PDUMP
extern bool g_dpvs_pdump;
#endif

int version_parse(const char *strver);

int global_data_init(void);
int global_data_term(void);

Expand Down
37 changes: 37 additions & 0 deletions src/global_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
*
*/

#include <string.h>
#include <rte_cycles.h>
#include "global_data.h"

RTE_DEFINE_PER_LCORE(uint32_t, g_dpvs_poll_tick);

unsigned int g_version;
uint64_t g_cycles_per_sec;

dpvs_lcore_role_t g_lcore_role[DPVS_MAX_LCORE];
Expand Down Expand Up @@ -51,6 +53,41 @@ int global_data_init(void)
return EDPVS_OK;
}

int version_parse(const char *strver)
{
int i, j = 0;
size_t len;
unsigned int version = 0, mask = 0xFF;
char *sver;

if (strver[0] == 'v' || strver[0] == 'V') {
sver = strdup(&strver[1]);
len = strlen(&strver[1]);
} else {
sver = strdup(strver);
len = strlen(strver);
}

if (unlikely(sver == NULL))
return 0;

for (i = 0; i < len && mask < 0xFFFFFF; i++) {
if ('.' == sver[i] || '-' == sver[i]) {
sver[i] = '\0';
version = ((version << 8) | atoi(&sver[j])) & mask;
mask |= mask << 8;
j = i + 1;
continue;
}
if (!isdigit(sver[i]))
break;
}
version = ((version << 8) | atoi(&sver[j])) & mask;

free(sver);
return version;
}

int global_data_term(void)
{
return EDPVS_OK;
Expand Down
2 changes: 1 addition & 1 deletion src/ipvs/ip_vs_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ static int dp_vs_service_get(sockoptid_t opt, const void *user, size_t len, void
info = rte_zmalloc("info", sizeof(struct dp_vs_getinfo), 0);
if (unlikely(NULL == info))
return EDPVS_NOMEM;
info->version = 0;
info->version = g_version;
info->size = 0;
info->num_services = rte_atomic16_read(&dp_vs_num_services[cid]);
info->num_lcores = g_slave_lcore_num;
Expand Down
2 changes: 2 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ static int parse_app_args(int argc, char **argv)
if (!dpvs_ipc_file)
dpvs_ipc_file="/var/run/dpvs.ipc";

g_version = version_parse(DPVS_VERSION);

return ret;
}

Expand Down

0 comments on commit d4d6285

Please sign in to comment.