-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Try to detect too many network issues and reset network
Instead of being stuck in the non-working setup. Ticket: MEN-7555 Changelog: none Signed-off-by: Vratislav Podzimek <[email protected]>
- Loading branch information
Showing
9 changed files
with
176 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @file mender-error-counters.c | ||
* @brief Mender Error counters implementation | ||
* | ||
* Copyright Northern.tech AS | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#if CONFIG_MENDER_ERRORS_THRESHOLD_NET > 0 | ||
|
||
#include <stdint.h> | ||
|
||
#include "mender-error-counters.h" | ||
#include "mender-log.h" | ||
#include "mender-utils.h" | ||
|
||
static uint8_t net_errors = 0; | ||
static_assert(CONFIG_MENDER_ERRORS_THRESHOLD_NET <= UINT8_MAX, "CONFIG_MENDER_ERRORS_THRESHOLD_NET must be <= UINT8_MAX"); | ||
|
||
mender_err_t | ||
mender_err_count_net_inc(void) { | ||
if (net_errors < UINT8_MAX) { | ||
net_errors++; | ||
} | ||
if (net_errors > CONFIG_MENDER_ERRORS_THRESHOLD_NET) { | ||
mender_log_warning("Network errors limit exceeded"); | ||
return MENDER_FAIL; | ||
} | ||
return MENDER_OK; | ||
} | ||
|
||
mender_err_t | ||
mender_err_count_net_check(void) { | ||
if (net_errors > CONFIG_MENDER_ERRORS_THRESHOLD_NET) { | ||
mender_log_warning("Network errors limit exceeded"); | ||
return MENDER_FAIL; | ||
} | ||
return MENDER_OK; | ||
} | ||
|
||
mender_err_t | ||
mender_err_count_net_reset(void) { | ||
net_errors = 0; | ||
return MENDER_OK; | ||
} | ||
#endif /* CONFIG_MENDER_ERRORS_THRESHOLD_NET > 0 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* @file mender-error-counters.h | ||
* @brief Mender Error Counters interface | ||
* | ||
* Copyright Northern.tech AS | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef __MENDER_ERROR_COUNTERS_H__ | ||
#define __MENDER_ERROR_COUNTERS_H__ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif /* __cplusplus */ | ||
|
||
#include <mender-utils.h> | ||
|
||
#ifndef CONFIG_MENDER_ERRORS_THRESHOLD_NET | ||
#define CONFIG_MENDER_ERRORS_THRESHOLD_NET 0 | ||
#endif | ||
|
||
#if CONFIG_MENDER_ERRORS_THRESHOLD_NET > 0 | ||
|
||
/** | ||
* @brief Increment the network errors counter | ||
* @return MENDER_OK if not too many errors, MENDER_FAIL if too many errors | ||
*/ | ||
mender_err_t mender_err_count_net_inc(void); | ||
|
||
/** | ||
* @brief Check the network errors counter | ||
* @return MENDER_OK if not too many errors, MENDER_FAIL if too many errors | ||
*/ | ||
mender_err_t mender_err_count_net_check(void); | ||
|
||
/** | ||
* @brief Reset the network errors counter | ||
* @return MENDER_OK if successful, error otherwise | ||
*/ | ||
mender_err_t mender_err_count_net_reset(void); | ||
|
||
#else | ||
|
||
/* Define the functions as inline noops so that the compiler can simply rule them out. */ | ||
inline mender_err_t | ||
mender_err_count_net_inc(void) { | ||
return MENDER_OK; | ||
} | ||
inline mender_err_t | ||
mender_err_count_net_check(void) { | ||
return MENDER_OK; | ||
} | ||
inline mender_err_t | ||
mender_err_count_net_reset(void) { | ||
return MENDER_OK; | ||
} | ||
|
||
#endif /* CONFIG_MENDER_ERRORS_THRESHOLD_NET > 0 */ | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif /* __cplusplus */ | ||
|
||
#endif /* __MENDER_ERROR_COUNTERS_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters