summaryrefslogtreecommitdiff
path: root/src/gateway/dlt_gateway.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gateway/dlt_gateway.c')
-rw-r--r--src/gateway/dlt_gateway.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/gateway/dlt_gateway.c b/src/gateway/dlt_gateway.c
index 9d0041d..3d832ce 100644
--- a/src/gateway/dlt_gateway.c
+++ b/src/gateway/dlt_gateway.c
@@ -669,6 +669,9 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose)
/* read configuration file */
file = dlt_config_file_init(config_file);
+ if(file == NULL) {
+ return DLT_RETURN_ERROR;
+ }
/* get number of entries and allocate memory to store information */
ret = dlt_config_file_get_num_sections(file, &num_sections);
@@ -791,6 +794,10 @@ int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose)
configuration_entries[j].key, value);
}
+ if (!tmp.ip_address) {
+ invalid = 1;
+ }
+
if (invalid) {
dlt_vlog(LOG_ERR,
"%s configuration is invalid.\n"
@@ -1285,6 +1292,7 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
DltGateway *gateway = NULL;
DltGatewayConnection *con = NULL;
DltMessage msg = { 0 };
+ bool b_reset_receiver = false;
if ((daemon == NULL) || (daemon_local == NULL) || (receiver == NULL)) {
dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__);
@@ -1301,13 +1309,11 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
}
for (i = 0; i < gateway->num_connections; i++)
- if (gateway->connections[i].client.sock == receiver->fd) {
+ if ((gateway->connections[i].status == DLT_GATEWAY_CONNECTED) && (gateway->connections[i].client.sock == receiver->fd)) {
con = &gateway->connections[i];
break;
}
-
-
if (con == NULL) {
dlt_log(LOG_ERR, "Cannot associate fd to passive Node connection\n");
return DLT_RETURN_ERROR;
@@ -1358,14 +1364,15 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
sizeof(DltStandardHeader));
/* only forward messages if the received ECUid is the expected one */
- if (strncmp(header->ecu, con->ecuid, strlen(con->ecuid)) == 0) {
+ if (strncmp(header->ecu, con->ecuid, DLT_ID_SIZE) == 0) {
uint32_t id;
uint32_t id_tmp;
DltPassiveControlMessage *control_msg = con->p_control_msgs;
dlt_vlog(LOG_DEBUG,
- "Received ECUid (%s) similar to configured ECUid(%s). "
+ "Received ECUid (%.*s) similar to configured ECUid(%s). "
"Forwarding message (%s).\n",
+ DLT_ID_SIZE,
header->ecu,
con->ecuid,
msg.databuffer);
@@ -1428,8 +1435,9 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
verbose);
} else { /* otherwise remove this connection and do not connect again */
dlt_vlog(LOG_WARNING,
- "Received ECUid (%s) differs to configured ECUid(%s). "
+ "Received ECUid (%.*s) differs to configured ECUid(%s). "
"Discard this message.\n",
+ DLT_ID_SIZE,
header->ecu,
con->ecuid);
@@ -1445,6 +1453,11 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
dlt_log(LOG_WARNING,
"Disconnect from passive node due to invalid ECUid\n");
+
+ /* it is possible that a partial log was received through the last recv call */
+ /* however, the rest will never be received since the socket will be closed by above method */
+ /* as such, we need to reset the receiver to prevent permanent corruption */
+ b_reset_receiver = true;
}
if (msg.found_serialheader) {
@@ -1468,6 +1481,9 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
}
}
+ if (b_reset_receiver)
+ dlt_receiver_remove(receiver, receiver->bytesRcvd);
+
if (dlt_receiver_move_to_begin(receiver) == -1) {
/* Return value ignored */
dlt_message_free(&msg, verbose);
@@ -1539,7 +1555,7 @@ int dlt_gateway_forward_control_message(DltGateway *gateway,
for (i = 0; i < gateway->num_connections; i++)
if (strncmp(gateway->connections[i].ecuid,
ecu,
- strlen(gateway->connections[i].ecuid)) == 0) {
+ DLT_ID_SIZE) == 0) {
con = &gateway->connections[i];
break;
}