Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix stale pointers in northbound nodes #8095

Merged
merged 4 commits into from
Feb 23, 2021

Conversation

idryzhov
Copy link
Contributor

Overall, this PR introduces the ability to register dependency between NB nodes to fix the stale pointers issue.
For more explanation, please, check individual commits.

Copy link

@polychaeta polychaeta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution to FRR!

Click for style suggestions

To apply these suggestions:

curl -s https://gist.githubusercontent.com/polychaeta/d802213a73edf58da38cea6360ed2509/raw/c9a1cb59763a172bc71762dab623869732707b05/cr_8095_1613473272.diff | git apply

diff --git a/lib/northbound.c b/lib/northbound.c
index f72f41936..d5f1ac40a 100644
--- a/lib/northbound.c
+++ b/lib/northbound.c
@@ -568,17 +568,19 @@ int nb_candidate_edit(struct nb_config *candidate,
 			/*
 			 * create dependency
 			 *
-			 * dnode returned by the lyd_new_path may be from different
-			 * schema, so we need to update the nb_node
+			 * dnode returned by the lyd_new_path may be from
+			 * different schema, so we need to update the nb_node
 			 */
 			nb_node = dnode->schema->priv;
 			if (nb_node->dep_cbs.get_dependency_xpath) {
-				nb_node->dep_cbs.get_dependency_xpath(dnode, dep_xpath);
+				nb_node->dep_cbs.get_dependency_xpath(
+					dnode, dep_xpath);
 
 				ly_errno = 0;
-				dep_dnode = lyd_new_path(candidate->dnode, ly_native_ctx,
-						     dep_xpath, NULL, 0,
-						     LYD_PATH_OPT_UPDATE);
+				dep_dnode = lyd_new_path(candidate->dnode,
+							 ly_native_ctx,
+							 dep_xpath, NULL, 0,
+							 LYD_PATH_OPT_UPDATE);
 				if (!dep_dnode && ly_errno) {
 					flog_warn(EC_LIB_LIBYANG,
 						  "%s: lyd_new_path() failed",
diff --git a/lib/vrf.c b/lib/vrf.c
index 63feb9421..0a91f4bc8 100644
--- a/lib/vrf.c
+++ b/lib/vrf.c
@@ -686,8 +686,8 @@ int vrf_handler_create(struct vty *vty, const char *vrfname,
 	}
 
 	if (vty) {
-		snprintf(xpath_list, sizeof(xpath_list),
-			 FRR_VRF_KEY_XPATH, vrfname);
+		snprintf(xpath_list, sizeof(xpath_list), FRR_VRF_KEY_XPATH,
+			 vrfname);
 
 		nb_cli_enqueue_change(vty, xpath_list, NB_OP_CREATE, NULL);
 		ret = nb_cli_apply_changes(vty, xpath_list);
@@ -821,8 +821,7 @@ DEFUN_YANG (no_vrf,
 		return CMD_WARNING_CONFIG_FAILED;
 	}
 
-	snprintf(xpath_list, sizeof(xpath_list), FRR_VRF_KEY_XPATH,
-		 vrfname);
+	snprintf(xpath_list, sizeof(xpath_list), FRR_VRF_KEY_XPATH, vrfname);
 
 	nb_cli_enqueue_change(vty, xpath_list, NB_OP_DESTROY, NULL);
 	return nb_cli_apply_changes(vty, xpath_list);
diff --git a/pimd/pim_nb_config.c b/pimd/pim_nb_config.c
index 39344c4b3..ceb20a69d 100644
--- a/pimd/pim_nb_config.c
+++ b/pimd/pim_nb_config.c
@@ -3051,17 +3051,19 @@ int lib_interface_igmp_address_family_static_group_destroy(
 	return NB_OK;
 }
 
-static void vrf_to_control_plane_protocol(const struct lyd_node *dnode, char *xpath)
+static void vrf_to_control_plane_protocol(const struct lyd_node *dnode,
+					  char *xpath)
 {
 	const char *vrf;
 
 	vrf = yang_dnode_get_string(dnode, "./name");
 
-	snprintf(xpath, XPATH_MAXLEN, FRR_ROUTING_KEY_XPATH,
-		 "frr-pim:pimd", "pim", vrf);
+	snprintf(xpath, XPATH_MAXLEN, FRR_ROUTING_KEY_XPATH, "frr-pim:pimd",
+		 "pim", vrf);
 }
 
-static void control_plane_protocol_to_vrf(const struct lyd_node *dnode, char *xpath)
+static void control_plane_protocol_to_vrf(const struct lyd_node *dnode,
+					  char *xpath)
 {
 	const char *vrf;
 
diff --git a/staticd/static_nb_config.c b/staticd/static_nb_config.c
index 04dea95ef..2cbde803d 100644
--- a/staticd/static_nb_config.c
+++ b/staticd/static_nb_config.c
@@ -1227,7 +1227,8 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_sr
 	return NB_OK;
 }
 
-static void vrf_to_control_plane_protocol(const struct lyd_node *dnode, char *xpath)
+static void vrf_to_control_plane_protocol(const struct lyd_node *dnode,
+					  char *xpath)
 {
 	const char *vrf;
 
@@ -1237,7 +1238,8 @@ static void vrf_to_control_plane_protocol(const struct lyd_node *dnode, char *xp
 		 "frr-staticd:staticd", "staticd", vrf);
 }
 
-static void control_plane_protocol_to_vrf(const struct lyd_node *dnode, char *xpath)
+static void control_plane_protocol_to_vrf(const struct lyd_node *dnode,
+					  char *xpath)
 {
 	const char *vrf;
 

If you are a new contributor to FRR, please see our contributing guidelines.

After making changes, you do not need to create a new PR. You should perform an amend or interactive rebase followed by a force push.

@LabN-CI
Copy link
Collaborator

LabN-CI commented Feb 16, 2021

Outdated results 💚

Basic BGPD CI results: SUCCESS, 0 tests failed

_ _
Result SUCCESS git merge/8095 c1ae678
Date 02/16/2021
Start 06:31:33
Finish 07:11:02
Run-Time 39:29
Total 1815
Pass 1815
Fail 0
Valgrind-Errors 0
Valgrind-Loss 0
Details vncregress-2021-02-16-06:31:33.txt
Log autoscript-2021-02-16-06:32:34.log.bz2
Memory 491 475 427

For details, please contact louberger

Copy link
Member

@riw777 riw777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look good to me ... though I did leave one question as a comment. It would be good to have another set of eyes on these changes.

@NetDEF-CI
Copy link
Collaborator

NetDEF-CI commented Feb 16, 2021

Continuous Integration Result: SUCCESSFUL

Continuous Integration Result: SUCCESSFUL

Congratulations, this patch passed basic tests

Tested-by: NetDEF / OpenSourceRouting.org CI System

CI System Testrun URL: https://ci1.netdef.org/browse/FRR-FRRPULLREQ-17172/

This is a comment from an automated CI system.
For questions and feedback in regards to this CI system, please feel free to email
Martin Winter - mwinter (at) opensourcerouting.org.

Warnings Generated during build:

Checkout code: Successful with additional warnings
Report for northbound.c | 6 issues
===============================================
< WARNING: line over 80 characters
< #571: FILE: /tmp/f1-31924/northbound.c:571:
< WARNING: line over 80 characters
< #576: FILE: /tmp/f1-31924/northbound.c:576:
< WARNING: line over 80 characters
< #579: FILE: /tmp/f1-31924/northbound.c:579:
Report for pim_nb_config.c | 4 issues
===============================================
< WARNING: line over 80 characters
< #3054: FILE: /tmp/f1-31924/pim_nb_config.c:3054:
< WARNING: line over 80 characters
< #3064: FILE: /tmp/f1-31924/pim_nb_config.c:3064:
Report for static_nb_config.c | 4 issues
===============================================
< WARNING: line over 80 characters
< #1230: FILE: /tmp/f1-31924/static_nb_config.c:1230:
< WARNING: line over 80 characters
< #1240: FILE: /tmp/f1-31924/static_nb_config.c:1240:

Warnings Generated during build:

Debian 10 amd64 build: Successful with additional warnings

Debian Package lintian failed for Debian 10 amd64 build:
(see full package build log at https://ci1.netdef.org/browse/FRR-FRRPULLREQ-17172/artifact/DEB10BUILD/ErrorLog/log_lintian.txt)

W: frr source: pkg-js-tools-test-is-missing
W: frr source: newer-standards-version 4.5.0.3 (current is 4.3.0)
W: frr source: pkg-js-tools-test-is-missing
W: frr source: newer-standards-version 4.5.0.3 (current is 4.3.0)
W: frr: changelog-file-missing-explicit-entry 7.5-0 -> 7.7-dev-20210216-05-gc1ae67864-0 (missing) -> 7.7-dev-20210216-05-gc1ae67864-0~deb10u1
W: frr-snmp: changelog-file-missing-explicit-entry 7.5-0 -> 7.7-dev-20210216-05-gc1ae67864-0 (missing) -> 7.7-dev-20210216-05-gc1ae67864-0~deb10u1
W: frr-doc: changelog-file-missing-explicit-entry 7.5-0 -> 7.7-dev-20210216-05-gc1ae67864-0 (missing) -> 7.7-dev-20210216-05-gc1ae67864-0~deb10u1
W: frr-rpki-rtrlib: changelog-file-missing-explicit-entry 7.5-0 -> 7.7-dev-20210216-05-gc1ae67864-0 (missing) -> 7.7-dev-20210216-05-gc1ae67864-0~deb10u1
W: frr-pythontools: changelog-file-missing-explicit-entry 7.5-0 -> 7.7-dev-20210216-05-gc1ae67864-0 (missing) -> 7.7-dev-20210216-05-gc1ae67864-0~deb10u1

CLANG Static Analyzer Summary

  • Github Pull Request 8095, comparing to Git base SHA 40c1b0e

Fixed warnings:

  • Memory error: Memory leak in clippy.c, function main, line 55
  • Memory error: Use of zero allocated in defun_lex.c, function yy_get_next_buffer, line 1697
  • Logic error: Dereference of null pointer in northbound_cli.c, function nb_cli_show_dnode_cmds, line 603
  • Logic error: Dereference of null pointer in northbound_cli.c, function nb_cli_show_dnode_cmds, line 603

New warnings:

Static Analysis warning summary compared to base:

  • Fixed warnings: 4
  • New warnings: 5

5 Static Analyzer issues remaining.

See details at
https://ci1.netdef.org/browse/FRR-FRRPULLREQ-17172/artifact/shared/static_analysis/index.html

@idryzhov idryzhov force-pushed the fix-nb-stale-pointers branch from c1ae678 to 7ab85ae Compare February 16, 2021 15:55
@qlyoung qlyoung self-requested a review February 16, 2021 16:20
Copy link
Member

@riw777 riw777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good now -- thanks! will wait for @qlyoung to review before pushing

@LabN-CI
Copy link
Collaborator

LabN-CI commented Feb 16, 2021

Outdated results 💚

Basic BGPD CI results: SUCCESS, 0 tests failed

_ _
Result SUCCESS git merge/8095 7ab85ae
Date 02/16/2021
Start 11:01:31
Finish 11:40:50
Run-Time 39:19
Total 1815
Pass 1815
Fail 0
Valgrind-Errors 0
Valgrind-Loss 0
Details vncregress-2021-02-16-11:01:31.txt
Log autoscript-2021-02-16-11:02:34.log.bz2
Memory 493 483 428

For details, please contact louberger

@NetDEF-CI
Copy link
Collaborator

NetDEF-CI commented Feb 16, 2021

Continuous Integration Result: SUCCESSFUL

Continuous Integration Result: SUCCESSFUL

Congratulations, this patch passed basic tests

Tested-by: NetDEF / OpenSourceRouting.org CI System

CI System Testrun URL: https://ci1.netdef.org/browse/FRR-FRRPULLREQ-17175/

This is a comment from an automated CI system.
For questions and feedback in regards to this CI system, please feel free to email
Martin Winter - mwinter (at) opensourcerouting.org.

Warnings Generated during build:

Checkout code: Successful with additional warnings
Report for routing_nb_config.c | 2 issues
===============================================
< WARNING: braces {} are not necessary for single statement blocks
< #79: FILE: /tmp/f1-6926/routing_nb_config.c:79:

Warnings Generated during build:

Debian 10 amd64 build: Successful with additional warnings

Debian Package lintian failed for Debian 10 amd64 build:
(see full package build log at https://ci1.netdef.org/browse/FRR-FRRPULLREQ-17175/artifact/DEB10BUILD/ErrorLog/log_lintian.txt)

W: frr source: pkg-js-tools-test-is-missing
W: frr source: newer-standards-version 4.5.0.3 (current is 4.3.0)
W: frr source: pkg-js-tools-test-is-missing
W: frr source: newer-standards-version 4.5.0.3 (current is 4.3.0)
W: frr: changelog-file-missing-explicit-entry 7.5-0 -> 7.7-dev-20210216-03-g7ab85ae8a-0 (missing) -> 7.7-dev-20210216-03-g7ab85ae8a-0~deb10u1
W: frr-doc: changelog-file-missing-explicit-entry 7.5-0 -> 7.7-dev-20210216-03-g7ab85ae8a-0 (missing) -> 7.7-dev-20210216-03-g7ab85ae8a-0~deb10u1
W: frr-rpki-rtrlib: changelog-file-missing-explicit-entry 7.5-0 -> 7.7-dev-20210216-03-g7ab85ae8a-0 (missing) -> 7.7-dev-20210216-03-g7ab85ae8a-0~deb10u1
W: frr-snmp: changelog-file-missing-explicit-entry 7.5-0 -> 7.7-dev-20210216-03-g7ab85ae8a-0 (missing) -> 7.7-dev-20210216-03-g7ab85ae8a-0~deb10u1
W: frr-pythontools: changelog-file-missing-explicit-entry 7.5-0 -> 7.7-dev-20210216-03-g7ab85ae8a-0 (missing) -> 7.7-dev-20210216-03-g7ab85ae8a-0~deb10u1

CLANG Static Analyzer Summary

  • Github Pull Request 8095, comparing to Git base SHA f37a846
  • Base image data for Git f37a846 does not exist - compare skipped

5 Static Analyzer issues remaining.

See details at
https://ci1.netdef.org/browse/FRR-FRRPULLREQ-17175/artifact/shared/static_analysis/index.html

@@ -87,12 +87,12 @@ int bgp_router_create(struct nb_cb_create_args *args)
case NB_EV_APPLY:
vrf_dnode = yang_dnode_get_parent(args->dnode,
"control-plane-protocol");
vrf = nb_running_get_entry(vrf_dnode, NULL, true);
vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont you have to register for bgp too ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. This one was the only place where it was using the vrf. Now it just gets the name from control-plane-protocol dnode, it doesn't need the actual vrf to be created.
More than that, we don't want to delete the "router bgp" configuration when the vrf is deleted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your answer is ok for me. thanks.
ok, I realise that rpki plugin has been magically ignored from the nb config porting.

Copy link
Member

@pguibert6WIND pguibert6WIND left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just need an answer for bgp. lgtm howeer

@donaldsharp
Copy link
Member

@idryzhov could you fix the 1 warning generated?

@idryzhov idryzhov force-pushed the fix-nb-stale-pointers branch from 7ab85ae to 91305bf Compare February 18, 2021 08:34
@idryzhov
Copy link
Contributor Author

@donaldsharp done

@LabN-CI
Copy link
Collaborator

LabN-CI commented Feb 18, 2021

Outdated results 💚

Basic BGPD CI results: SUCCESS, 0 tests failed

_ _
Result SUCCESS git merge/8095 91305bf
Date 02/18/2021
Start 03:45:48
Finish 04:25:19
Run-Time 39:31
Total 1815
Pass 1815
Fail 0
Valgrind-Errors 0
Valgrind-Loss 0
Details vncregress-2021-02-18-03:45:48.txt
Log autoscript-2021-02-18-03:46:51.log.bz2
Memory 471 495 427

For details, please contact louberger

@NetDEF-CI
Copy link
Collaborator

NetDEF-CI commented Feb 18, 2021

Continuous Integration Result: SUCCESSFUL

Continuous Integration Result: SUCCESSFUL

Congratulations, this patch passed basic tests

Tested-by: NetDEF / OpenSourceRouting.org CI System

CI System Testrun URL: https://ci1.netdef.org/browse/FRR-FRRPULLREQ-17204/

This is a comment from an automated CI system.
For questions and feedback in regards to this CI system, please feel free to email
Martin Winter - mwinter (at) opensourcerouting.org.

Warnings Generated during build:

Debian 10 amd64 build: Successful with additional warnings

Debian Package lintian failed for Debian 10 amd64 build:
(see full package build log at https://ci1.netdef.org/browse/FRR-FRRPULLREQ-17204/artifact/DEB10BUILD/ErrorLog/log_lintian.txt)

W: frr source: pkg-js-tools-test-is-missing
W: frr source: newer-standards-version 4.5.0.3 (current is 4.3.0)
W: frr source: pkg-js-tools-test-is-missing
W: frr source: newer-standards-version 4.5.0.3 (current is 4.3.0)
W: frr-snmp: changelog-file-missing-explicit-entry 7.5-0 -> 7.7-dev-20210218-00-g91305bfef-0 (missing) -> 7.7-dev-20210218-00-g91305bfef-0~deb10u1
W: frr-doc: changelog-file-missing-explicit-entry 7.5-0 -> 7.7-dev-20210218-00-g91305bfef-0 (missing) -> 7.7-dev-20210218-00-g91305bfef-0~deb10u1
W: frr-pythontools: changelog-file-missing-explicit-entry 7.5-0 -> 7.7-dev-20210218-00-g91305bfef-0 (missing) -> 7.7-dev-20210218-00-g91305bfef-0~deb10u1
W: frr-rpki-rtrlib: changelog-file-missing-explicit-entry 7.5-0 -> 7.7-dev-20210218-00-g91305bfef-0 (missing) -> 7.7-dev-20210218-00-g91305bfef-0~deb10u1
W: frr: changelog-file-missing-explicit-entry 7.5-0 -> 7.7-dev-20210218-00-g91305bfef-0 (missing) -> 7.7-dev-20210218-00-g91305bfef-0~deb10u1

CLANG Static Analyzer Summary

  • Github Pull Request 8095, comparing to Git base SHA 82451d0

Fixed warnings:

  • Memory error: Memory leak in clippy.c, function main, line 55
  • Memory error: Use of zero allocated in defun_lex.c, function yy_get_next_buffer, line 1697
  • Logic error: Dereference of null pointer in northbound_cli.c, function nb_cli_show_dnode_cmds, line 603
  • Logic error: Dereference of null pointer in northbound_cli.c, function nb_cli_show_dnode_cmds, line 603

New warnings:

Static Analysis warning summary compared to base:

  • Fixed warnings: 4
  • New warnings: 5

5 Static Analyzer issues remaining.

See details at
https://ci1.netdef.org/browse/FRR-FRRPULLREQ-17204/artifact/shared/static_analysis/index.html

dep_xpath, NULL, 0,
LYD_PATH_OPT_UPDATE);
if (!dep_dnode && ly_errno) {
flog_warn(EC_LIB_LIBYANG,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit : same error message for dnode and dep_dnode creation failure, It would be difficult to get the exact failure from logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

dnode, dep_xpath);

ly_errno = 0;
dep_dnode = lyd_new_path(candidate->dnode,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider one scenario

c t
ip route 1.1.1.1/32 ens33

In this configuration you will create a default dnode in frr-vrf yang table.

Now I have deleted the route

c t
no ip route 1.1.1.1/32 ens33

Now default dnode is not getting deleted from frr-vrf yang table.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue is not directly related to this PR. This already happens for any other configuration that needs default VRF dnode. For example, when you configure vni in zebra.
I'm not sure that this is an issue at all. Nothing wrong with always having a configuration node for the default VRF as this VRF always exists.
Anyway, this should not be a blocker for this fix and can be discussed and fixed separately.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, we can discuss and fixed separately.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
When the control plane protocol is created, the vrf structure is
allocated, and its address is stored in the northbound node.
The vrf structure may later be deleted by the user, which will lead to
a stale pointer stored in this node.

Instead of this, allow daemons that use the vrf pointer to register the
dependency between the control plane protocol and vrf nodes. This will
guarantee that the nodes will always be created and deleted together, and
there won't be any stale pointers.

Add such registration to staticd and pimd.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
@idryzhov idryzhov force-pushed the fix-nb-stale-pointers branch from 91305bf to 2ada626 Compare February 22, 2021 16:01
@LabN-CI
Copy link
Collaborator

LabN-CI commented Feb 22, 2021

💚 Basic BGPD CI results: SUCCESS, 0 tests failed

Results table
_ _
Result SUCCESS git merge/8095 2ada626
Date 02/22/2021
Start 12:56:27
Finish 13:35:41
Run-Time 39:14
Total 1815
Pass 1815
Fail 0
Valgrind-Errors 0
Valgrind-Loss 0
Details vncregress-2021-02-22-12:56:27.txt
Log autoscript-2021-02-22-12:57:27.log.bz2
Memory 501 491 427

For details, please contact louberger

@NetDEF-CI
Copy link
Collaborator

Continuous Integration Result: SUCCESSFUL

Congratulations, this patch passed basic tests

Tested-by: NetDEF / OpenSourceRouting.org CI System

CI System Testrun URL: https://ci1.netdef.org/browse/FRR-FRRPULLREQ-17250/

This is a comment from an automated CI system.
For questions and feedback in regards to this CI system, please feel free to email
Martin Winter - mwinter (at) opensourcerouting.org.


CLANG Static Analyzer Summary

  • Github Pull Request 8095, comparing to Git base SHA fa17cdc
  • Base image data for Git fa17cdc does not exist - compare skipped

4 Static Analyzer issues remaining.

See details at
https://ci1.netdef.org/browse/FRR-FRRPULLREQ-17250/artifact/shared/static_analysis/index.html

@vishaldhingra
Copy link
Contributor

PR looks good to me.

@riw777 riw777 merged commit 33d1282 into FRRouting:master Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants