Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
347 changes: 192 additions & 155 deletions src/vma/config_parser.c

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions src/vma/config_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */

#ifndef YY_LIBVMA_YY_CONFIG_PARSER_H_INCLUDED
# define YY_LIBVMA_YY_CONFIG_PARSER_H_INCLUDED
#ifndef YY_LIBVMA_YY_UTIL_CONFIG_PARSER_H_INCLUDED
# define YY_LIBVMA_YY_UTIL_CONFIG_PARSER_H_INCLUDED
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
Expand Down Expand Up @@ -69,7 +69,9 @@ extern int libvma_yydebug;
FILENAME = 278,
NAME = 279,
LEVEL = 280,
LINE = 281
LINE = 281,
DAEMON_KEY = 282,
DAEMON_VALUE = 283
};
#endif
/* Tokens. */
Expand Down Expand Up @@ -97,21 +99,23 @@ extern int libvma_yydebug;
#define NAME 279
#define LEVEL 280
#define LINE 281
#define DAEMON_KEY 282
#define DAEMON_VALUE 283



#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
/* Line 2058 of yacc.c */
/* Line 306 of config_parser.y */
#line 314 "../../../src/vma/util/config_parser.y"

int ival;
char *sval;


/* Line 2058 of yacc.c */
/* Line 115 of config_parser.h */
#line 119 "util/config_parser.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
Expand All @@ -134,4 +138,4 @@ int libvma_yyparse ();
#endif
#endif /* ! YYPARSE_PARAM */

#endif /* !YY_LIBVMA_YY_CONFIG_PARSER_H_INCLUDED */
#endif /* !YY_LIBVMA_YY_UTIL_CONFIG_PARSER_H_INCLUDED */
663 changes: 387 additions & 276 deletions src/vma/config_scanner.c

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions src/vma/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,16 @@ static void do_global_ctors_helper()
if (g_is_forked_child == true)
g_is_forked_child = false;

if (check_if_regular_file (safe_mce_sys().conf_filename))
{
vlog_printf(VLOG_WARNING,"FAILED to read VMA configuration file. %s is not a regular file.\n",
safe_mce_sys().conf_filename);
if (strcmp (MCE_DEFAULT_CONF_FILE, safe_mce_sys().conf_filename))
vlog_printf(VLOG_INFO,"Please see README.txt section regarding VMA_CONFIG_FILE\n");
}
else if (__vma_parse_config_file(safe_mce_sys().conf_filename))
vlog_printf(VLOG_DEBUG,"FAILED to read VMA configuration file: %s\n", safe_mce_sys().conf_filename);

/* Open communication with daemon */
NEW_CTOR(g_p_agent, agent());
vlog_printf(VLOG_DEBUG,"Agent setup state: g_p_agent=%p active=%d\n",
Expand Down Expand Up @@ -844,16 +854,6 @@ static void do_global_ctors_helper()

NEW_CTOR(g_p_fd_collection, fd_collection());

if (check_if_regular_file (safe_mce_sys().conf_filename))
{
vlog_printf(VLOG_WARNING,"FAILED to read VMA configuration file. %s is not a regular file.\n",
safe_mce_sys().conf_filename);
if (strcmp (MCE_DEFAULT_CONF_FILE, safe_mce_sys().conf_filename))
vlog_printf(VLOG_INFO,"Please see README.txt section regarding VMA_CONFIG_FILE\n");
}
else if (__vma_parse_config_file(safe_mce_sys().conf_filename))
vlog_printf(VLOG_DEBUG,"FAILED to read VMA configuration file: %s\n", safe_mce_sys().conf_filename);


// initialize LWIP tcp/ip stack
NEW_CTOR(g_p_lwip, vma_lwip());
Expand Down
12 changes: 8 additions & 4 deletions src/vma/util/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "vlogger/vlogger.h"
#include "utils/lock_wrapper.h"
#include "vma/sock/sock-redirect.h"
#include "vma/util/libvma.h"
#include "vma/util/list.h"
#include "vma/util/agent.h"

Expand Down Expand Up @@ -84,10 +85,13 @@ agent::agent() :
int rc = 0;
agent_msg_t *msg = NULL;
int i = 0;
const char *path = (__vma_get_daemon_path() ? __vma_get_daemon_path() : VMA_AGENT_PATH);

INIT_LIST_HEAD(&m_free_queue);
INIT_LIST_HEAD(&m_wait_queue);

__log_dbg("use location: %s\n", path);

/* Fill free queue with empty messages */
i = m_msg_num;
m_msg_num = 0;
Expand All @@ -104,22 +108,22 @@ agent::agent() :
m_msg_num++;
}

if ((mkdir(VMA_AGENT_PATH, 0777) != 0) && (errno != EEXIST)) {
if ((mkdir(path, 0777) != 0) && (errno != EEXIST)) {
rc = -errno;
__log_dbg("failed create folder %s (rc = %d)\n", VMA_AGENT_PATH, rc);
__log_dbg("failed create folder %s (rc = %d)\n", path, rc);
goto err;
}

rc = snprintf(m_sock_file, sizeof(m_sock_file) - 1,
"%s/%s.%d.sock", VMA_AGENT_PATH, VMA_AGENT_BASE_NAME, getpid());
"%s/%s.%d.sock", path, VMA_AGENT_BASE_NAME, getpid());
if ((rc < 0 ) || (rc == (sizeof(m_sock_file) - 1) )) {
rc = -ENOMEM;
__log_dbg("failed allocate sock file (rc = %d)\n", rc);
goto err;
}

rc = snprintf(m_pid_file, sizeof(m_pid_file) - 1,
"%s/%s.%d.pid", VMA_AGENT_PATH, VMA_AGENT_BASE_NAME, getpid());
"%s/%s.%d.pid", path, VMA_AGENT_BASE_NAME, getpid());
if ((rc < 0 ) || (rc == (sizeof(m_pid_file) - 1) )) {
rc = -ENOMEM;
__log_dbg("failed allocate pid file (rc = %d)\n", rc);
Expand Down
16 changes: 14 additions & 2 deletions src/vma/util/config_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ static void __vma_set_inet_addr_prefix_len(unsigned char prefixlen)
// SM: log part is not used...
int __vma_min_level = 9;

char *__vma_daemon_path = "/tmp/vma";

void __vma_dump_address_port_rule_config_state(char *buf) {
if (__vma_address_port_rule->match_by_addr) {
char str_addr[INET_ADDRSTRLEN];
Expand Down Expand Up @@ -338,8 +340,10 @@ static void __vma_add_rule() {
%token NAME "a name"
%token LEVEL "min-level"
%token LINE "new line"
%type <sval> NAME PROGRAM USER_DEFINED_ID_STR
%type <ival> INT LOG DEST STDERR SYSLOG FILENAME APP_ID USE OS VMA SDP TCP UDP TCP_CLIENT TCP_SERVER UDP_SENDER UDP_RECEIVER UDP_CONNECT LEVEL LINE
%token DAEMON_KEY "daemon"
%token DAEMON_VALUE "daemon path"
%type <sval> NAME PROGRAM USER_DEFINED_ID_STR DAEMON_VALUE
%type <ival> INT LOG DEST STDERR SYSLOG FILENAME APP_ID USE OS VMA SDP TCP UDP TCP_CLIENT TCP_SERVER UDP_SENDER UDP_RECEIVER UDP_CONNECT LEVEL LINE DAEMON_KEY
%start config

%{
Expand Down Expand Up @@ -367,6 +371,7 @@ statement:
log_statement
| app_id_statement
| socket_statement
| daemon_statement
;

log_statement:
Expand Down Expand Up @@ -397,6 +402,13 @@ app_id:
| APP_ID PROGRAM INT {__vma_add_inst_with_int_uid($2, $3); if ($2) free($2); }
;

daemon_statement:
daemon NL
;

daemon:
DAEMON_KEY DAEMON_VALUE { __vma_set_daemon_path($2); if ($2) free($2); }
;

socket_statement:
use transport role tuple NL { __vma_add_rule(); }
Expand Down
21 changes: 20 additions & 1 deletion src/vma/util/config_scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extern long __vma_config_line_num;
%}
%option nounput
%option noinput
%s CANNAME APP_ID_S1 APP_ID_S2
%s CANNAME APP_ID_S1 APP_ID_S2 DAEMON_VALUE_S
%%

^[ \t]*#.* {}
Expand Down Expand Up @@ -252,6 +252,25 @@ udp_connect {
return (NAME);
}

daemon {
yylval.ival = DAEMON_KEY;
#ifdef DEBUG
printf("DAEMON_KEY\n");
#endif
BEGIN(DAEMON_VALUE_S);
return DAEMON_KEY;
}

<DAEMON_VALUE_S>[^ \t\n]+ {
yylval.sval = (char *)malloc(strlen(yytext) + 1);
strcpy(yylval.sval, yytext);
#ifdef DEBUG
printf("DAEMON_VALUE:%s\n",yylval.sval);
#endif
BEGIN(0);
return (DAEMON_VALUE);
}

\n {
__vma_config_line_num++;
#ifdef DEBUG
Expand Down
7 changes: 6 additions & 1 deletion src/vma/util/libvma.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
# takes immidiate effect we define these straight after the "application-id".
#
##############################################################################
# DEAFUALT SETTINGS:
# DEFAULT SETTINGS:
# Please do not forget to comment if you want to change these.
# (the rest of this file explains the syntax and give examples)
#

#
# Location for auxiliary files (this parameter should be
# identical for daemon and process)
daemon /tmp/vma

#
# By default apply the statments to any application with any ID
application-id * *
Expand Down
4 changes: 4 additions & 0 deletions src/vma/util/libvma.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ static inline int __vma_log_set_log_file(char *filename )
return 0;
};

char* __vma_get_daemon_path(void);

int __vma_set_daemon_path(char *pathname);

int __vma_sockaddr_to_vma(const struct sockaddr *addr_in, socklen_t addrlen, struct sockaddr_in *addr_out, int *was_ipv6 );

#ifdef __cplusplus
Expand Down