From db44b7e6766351cf9352b7ba27c424e260234220 Mon Sep 17 00:00:00 2001 From: stormliang Date: Wed, 21 Jun 2023 08:19:36 +0000 Subject: [PATCH 1/3] error handling --- .../0030-bgpd-error-handling-improve.patch | 42 +++++++++++++++++++ src/sonic-frr/patch/series | 1 + 2 files changed, 43 insertions(+) create mode 100644 src/sonic-frr/patch/0030-bgpd-error-handling-improve.patch diff --git a/src/sonic-frr/patch/0030-bgpd-error-handling-improve.patch b/src/sonic-frr/patch/0030-bgpd-error-handling-improve.patch new file mode 100644 index 000000000000..ba5c9e6e0157 --- /dev/null +++ b/src/sonic-frr/patch/0030-bgpd-error-handling-improve.patch @@ -0,0 +1,42 @@ +From 33a231ac26a46bfb728975d1695b7a71a7bc95ab Mon Sep 17 00:00:00 2001 +From: stormliang +Date: Wed, 21 Jun 2023 08:10:10 +0000 +Subject: [PATCH] error handling improve + +--- + vtysh/vtysh.c | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c +index 8e95aaa47..9df2011ce 100644 +--- a/vtysh/vtysh.c ++++ b/vtysh/vtysh.c +@@ -25,6 +25,8 @@ + #include + #include + #include ++#include ++#include + + /* readline carries some ancient definitions around */ + #pragma GCC diagnostic push +@@ -895,6 +897,16 @@ int vtysh_config_from_file(struct vty *vty, FILE *fp) + } + } + } ++ if (feof(fp)) { ++ // Handle end-of-file (EOF) error ++ vty_out(vty, "fgets error: End of file reached.\n"); ++ } else if (ferror(file)) { ++ // Handle general I/O error ++ vty_out(vty, "fgets error: Error occurred while reading input: %s\n", strerror(errno)); ++ } else { ++ // Handle other errors ++ vty_out(vty, "fgets error: Unknown error occurred.\n"); ++ } + + return (retcode); + } +-- +2.25.1 + diff --git a/src/sonic-frr/patch/series b/src/sonic-frr/patch/series index db97b2ea823f..81d9e48aa7a1 100644 --- a/src/sonic-frr/patch/series +++ b/src/sonic-frr/patch/series @@ -28,4 +28,5 @@ cross-compile-changes.patch 0027-bgpd-Ensure-FRR-has-enough-data-to-read-in-peek_for_as4_capability-and-bgp_open_option_parse.patch 0028-bgpd-Ensure-that-bgp-open-message-stream-has-enough-data-to-read.patch 0029-bgpd-Change-log-level-for-graceful-restart-events.patch +0030-bgpd-error-handling-improve.patch From d3658b131df01b7da13ccd122c45f66559f08c5b Mon Sep 17 00:00:00 2001 From: stormliang Date: Sun, 25 Jun 2023 03:18:41 +0000 Subject: [PATCH 2/3] enhance error handling --- .../0030-bgpd-error-handling-improve.patch | 92 ++++++++++++++----- 1 file changed, 70 insertions(+), 22 deletions(-) diff --git a/src/sonic-frr/patch/0030-bgpd-error-handling-improve.patch b/src/sonic-frr/patch/0030-bgpd-error-handling-improve.patch index ba5c9e6e0157..b97ec0e4a6fd 100644 --- a/src/sonic-frr/patch/0030-bgpd-error-handling-improve.patch +++ b/src/sonic-frr/patch/0030-bgpd-error-handling-improve.patch @@ -1,14 +1,61 @@ -From 33a231ac26a46bfb728975d1695b7a71a7bc95ab Mon Sep 17 00:00:00 2001 +From 4f50e545db4593121a2da0cab710cac4ad018d04 Mon Sep 17 00:00:00 2001 From: stormliang -Date: Wed, 21 Jun 2023 08:10:10 +0000 +Date: Sun, 25 Jun 2023 03:15:39 +0000 Subject: [PATCH] error handling improve --- - vtysh/vtysh.c | 12 ++++++++++++ - 1 file changed, 12 insertions(+) + lib/command.c | 15 +++++++++++++++ + lib/command.h | 1 + + vtysh/vtysh.c | 14 ++++++++++++++ + 3 files changed, 30 insertions(+) +diff --git a/lib/command.c b/lib/command.c +index 3718c1459..5f15f5469 100644 +--- a/lib/command.c ++++ b/lib/command.c +@@ -51,6 +51,9 @@ + + #include "frrscript.h" + ++#include ++#include ++ + DEFINE_MTYPE_STATIC(LIB, HOST, "Host config"); + DEFINE_MTYPE(LIB, COMPLETION, "Completion item"); + +@@ -1290,6 +1293,18 @@ int config_from_file(struct vty *vty, FILE *fp, unsigned int *line_num) + && ret != CMD_ERR_NOTHING_TODO) + error_ret = ret; + } ++ if (feof(fp)) { ++ // Handle end-of-file (EOF) error ++ vty_out(vty, "End of file reached.\n"); ++ } else if (ferror(fp)) { ++ error_ret = CMD_ERR_READ_CONF_FILE; ++ // Handle general I/O error ++ vty_out(vty, "fgets error: Error occurred while reading input: %s\n", strerror(errno)); ++ } else { ++ error_ret = CMD_ERR_READ_CONF_FILE; ++ // Handle other errors ++ vty_out(vty, "fgets error: Unknown error occurred.\n"); ++ } + + if (error_ret) { + return error_ret; +diff --git a/lib/command.h b/lib/command.h +index c888356d6..e38617737 100644 +--- a/lib/command.h ++++ b/lib/command.h +@@ -236,6 +236,7 @@ struct cmd_node { + #define CMD_NOT_MY_INSTANCE 14 + #define CMD_NO_LEVEL_UP 15 + #define CMD_ERR_NO_DAEMON 16 ++#define CMD_ERR_READ_CONF_FILE 17 + + /* Argc max counts. */ + #define CMD_ARGC_MAX 256 diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c -index 8e95aaa47..9df2011ce 100644 +index 8e95aaa47..bbcdb90dc 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -25,6 +25,8 @@ @@ -20,23 +67,24 @@ index 8e95aaa47..9df2011ce 100644 /* readline carries some ancient definitions around */ #pragma GCC diagnostic push -@@ -895,6 +897,16 @@ int vtysh_config_from_file(struct vty *vty, FILE *fp) - } - } - } -+ if (feof(fp)) { -+ // Handle end-of-file (EOF) error -+ vty_out(vty, "fgets error: End of file reached.\n"); -+ } else if (ferror(file)) { -+ // Handle general I/O error -+ vty_out(vty, "fgets error: Error occurred while reading input: %s\n", strerror(errno)); -+ } else { -+ // Handle other errors -+ vty_out(vty, "fgets error: Unknown error occurred.\n"); -+ } +@@ -895,6 +897,18 @@ int vtysh_config_from_file(struct vty *vty, FILE *fp) + } + } + } ++ if (feof(fp)) { ++ // Handle end-of-file (EOF) error ++ vty_out(vty, "End of file reached.\n"); ++ } else if (ferror(fp)) { ++ retcode = CMD_ERR_READ_CONF_FILE; ++ // Handle general I/O error ++ vty_out(vty, "fgets error: Error occurred while reading input: %s\n", strerror(errno)); ++ } else { ++ retcode = CMD_ERR_READ_CONF_FILE; ++ // Handle other errors ++ vty_out(vty, "fgets error: Unknown error occurred.\n"); ++ } - return (retcode); + return (retcode); } -- -2.25.1 - +2.25.1 \ No newline at end of file From f7a73db6c4f6c26b14a2c84589da73d0f356733f Mon Sep 17 00:00:00 2001 From: stormliang Date: Sun, 25 Jun 2023 07:44:14 +0000 Subject: [PATCH 3/3] fix format issue --- .../0030-bgpd-error-handling-improve.patch | 71 ++++++++++--------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/src/sonic-frr/patch/0030-bgpd-error-handling-improve.patch b/src/sonic-frr/patch/0030-bgpd-error-handling-improve.patch index b97ec0e4a6fd..3503362814e2 100644 --- a/src/sonic-frr/patch/0030-bgpd-error-handling-improve.patch +++ b/src/sonic-frr/patch/0030-bgpd-error-handling-improve.patch @@ -24,30 +24,30 @@ index 3718c1459..5f15f5469 100644 DEFINE_MTYPE(LIB, COMPLETION, "Completion item"); @@ -1290,6 +1293,18 @@ int config_from_file(struct vty *vty, FILE *fp, unsigned int *line_num) - && ret != CMD_ERR_NOTHING_TODO) - error_ret = ret; - } -+ if (feof(fp)) { -+ // Handle end-of-file (EOF) error -+ vty_out(vty, "End of file reached.\n"); -+ } else if (ferror(fp)) { -+ error_ret = CMD_ERR_READ_CONF_FILE; -+ // Handle general I/O error -+ vty_out(vty, "fgets error: Error occurred while reading input: %s\n", strerror(errno)); -+ } else { -+ error_ret = CMD_ERR_READ_CONF_FILE; -+ // Handle other errors -+ vty_out(vty, "fgets error: Unknown error occurred.\n"); -+ } + && ret != CMD_ERR_NOTHING_TODO) + error_ret = ret; + } ++ if (feof(fp)) { ++ // Handle end-of-file (EOF) error ++ vty_out(vty, "End of file reached.\n"); ++ } else if (ferror(fp)) { ++ error_ret = CMD_ERR_READ_CONF_FILE; ++ // Handle general I/O error ++ vty_out(vty, "fgets error: Error occurred while reading input: %s\n", strerror(errno)); ++ } else { ++ error_ret = CMD_ERR_READ_CONF_FILE; ++ // Handle other errors ++ vty_out(vty, "fgets error: Unknown error occurred.\n"); ++ } - if (error_ret) { - return error_ret; + if (error_ret) { + return error_ret; diff --git a/lib/command.h b/lib/command.h index c888356d6..e38617737 100644 --- a/lib/command.h +++ b/lib/command.h @@ -236,6 +236,7 @@ struct cmd_node { - #define CMD_NOT_MY_INSTANCE 14 + #define CMD_NOT_MY_INSTANCE 14 #define CMD_NO_LEVEL_UP 15 #define CMD_ERR_NO_DAEMON 16 +#define CMD_ERR_READ_CONF_FILE 17 @@ -68,23 +68,24 @@ index 8e95aaa47..bbcdb90dc 100644 /* readline carries some ancient definitions around */ #pragma GCC diagnostic push @@ -895,6 +897,18 @@ int vtysh_config_from_file(struct vty *vty, FILE *fp) - } - } - } -+ if (feof(fp)) { -+ // Handle end-of-file (EOF) error -+ vty_out(vty, "End of file reached.\n"); -+ } else if (ferror(fp)) { -+ retcode = CMD_ERR_READ_CONF_FILE; -+ // Handle general I/O error -+ vty_out(vty, "fgets error: Error occurred while reading input: %s\n", strerror(errno)); -+ } else { -+ retcode = CMD_ERR_READ_CONF_FILE; -+ // Handle other errors -+ vty_out(vty, "fgets error: Unknown error occurred.\n"); -+ } + } + } + } ++ if (feof(fp)) { ++ // Handle end-of-file (EOF) error ++ vty_out(vty, "End of file reached.\n"); ++ } else if (ferror(fp)) { ++ retcode = CMD_ERR_READ_CONF_FILE; ++ // Handle general I/O error ++ vty_out(vty, "fgets error: Error occurred while reading input: %s\n", strerror(errno)); ++ } else { ++ retcode = CMD_ERR_READ_CONF_FILE; ++ // Handle other errors ++ vty_out(vty, "fgets error: Unknown error occurred.\n"); ++ } - return (retcode); + return (retcode); } -- -2.25.1 \ No newline at end of file +2.25.1 +