From f093d547c2e4c68d0b7060f9accfc67784b7c06a Mon Sep 17 00:00:00 2001 From: sebastienr Date: Wed, 25 Nov 2020 01:11:43 +0100 Subject: dlt-daemon: Adds an option to disable injection mode (#266) A new option named "InjectionMode" allows to select if we want to enable / disable the feature Signed-off-by: Sebastien RAILLET --- doc/dlt.conf.5.md | 6 ++++++ src/daemon/dlt-daemon.c | 4 ++++ src/daemon/dlt-daemon.h | 3 ++- src/daemon/dlt.conf | 3 +++ src/daemon/dlt_daemon_client.c | 8 +++++++- 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/doc/dlt.conf.5.md b/doc/dlt.conf.5.md index 4b30150..8109c27 100644 --- a/doc/dlt.conf.5.md +++ b/doc/dlt.conf.5.md @@ -120,6 +120,12 @@ Initial trace-status that is sent when an application registers. DLT_TRACE_STATU Force log level and trace status of contexts to not exceed "ContextLogLevel" and "ContextTraceStatus". If set to 1 (ON) whenever a context registers or changes the log-level it has to be lower or equal to ContextLogLevel. Default: 0 + +## InjectionMode + +If set to 0, the injection mode (see [here](./dlt_for_developers.md#DLT-Injection-Messages)) is disabled. + + Default: 1 # GATEWAY CONFIGURATION diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index a14de88..cd6e5d9 100644 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -322,6 +322,7 @@ int option_file_parser(DltDaemonLocal *daemon_local) daemon_local->UDPMulticastIPPort = MULTICASTIPPORT; #endif daemon_local->flags.ipNodes = NULL; + daemon_local->flags.injectionMode = 1; /* open configuration file */ if (daemon_local->flags.cvalue[0]) @@ -705,6 +706,9 @@ int option_file_parser(DltDaemonLocal *daemon_local) dlt_vlog(LOG_WARNING, "BindAddress option is empty\n"); } } + else if (strcmp(token, "InjectionMode") == 0) { + daemon_local->flags.injectionMode = atoi(value); + } else { fprintf(stderr, "Unknown option: %s=%s\n", token, value); } diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h index 6637f1d..31598bb 100644 --- a/src/daemon/dlt-daemon.h +++ b/src/daemon/dlt-daemon.h @@ -135,7 +135,8 @@ typedef struct int contextLogLevel; /**< (int) log level sent to context if registered with default log-level or if enforced*/ int contextTraceStatus; /**< (int) trace status sent to context if registered with default trace status or if enforced*/ int enforceContextLLAndTS; /**< (Boolean) Enforce log-level, trace-status not to exceed contextLogLevel, contextTraceStatus */ - DltBindAddress_t *ipNodes; /**< (String: BindAddress) The daemon accepts connections only on this list of IP addresses */ + DltBindAddress_t* ipNodes; /**< (String: BindAddress) The daemon accepts connections only on this list of IP addresses */ + int injectionMode; /**< (Boolean) Injection mode */ } DltDaemonFlags; /** * The global parameters of a dlt daemon. diff --git a/src/daemon/dlt.conf b/src/daemon/dlt.conf index 60d3315..ab2a9bd 100644 --- a/src/daemon/dlt.conf +++ b/src/daemon/dlt.conf @@ -75,6 +75,9 @@ RingbufferStepSize = 500000 # If set to 1 (ON) whenever a context registers or changes the log-level it has to be lower or equal to ContextLogLevel # ForceContextLogLevelAndTraceStatus = 1 +# Allows injection mode usage (Default: 1) +# InjectionMode = 1 + ######################################################################## # Gateway Configuration # ######################################################################## diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c index 9450e77..941aa8c 100644 --- a/src/daemon/dlt_daemon_client.c +++ b/src/daemon/dlt_daemon_client.c @@ -1544,7 +1544,7 @@ void dlt_daemon_control_callsw_cinjection(int sock, PRINT_FUNCTION_VERBOSE(verbose); - if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) + if ((daemon == NULL) || (daemon_local == NULL) || (msg == NULL) || (msg->databuffer == NULL)) return; datalength = msg->datasize; @@ -1553,6 +1553,12 @@ void dlt_daemon_control_callsw_cinjection(int sock, DLT_MSG_READ_VALUE(id_tmp, ptr, datalength, uint32_t); /* Get service id */ id = DLT_ENDIAN_GET_32(msg->standardheader->htyp, id_tmp); + /* injectionMode is disabled */ + if (daemon_local->flags.injectionMode == 0) { + dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_PERM_DENIED, verbose); + return; + } + /* id is always less than DLT_DAEMON_INJECTION_MAX since its type is uinit32_t */ if (id >= DLT_DAEMON_INJECTION_MIN) { /* This a a real SW-C injection call */ -- cgit v1.2.1