]> git.proxmox.com Git - mirror_frr.git/blobdiff - ripd/ripd.c
Merge pull request #5186 from opensourcerouting/nb-cbs-reorg
[mirror_frr.git] / ripd / ripd.c
index 561fbcb52d1b33b3bdc8cd4950b4a18d54fee0b5..ec0770ef3d7d835441ff5da0b81c4edc621b0f9c 100644 (file)
@@ -46,6 +46,7 @@
 #include "northbound_cli.h"
 
 #include "ripd/ripd.h"
+#include "ripd/rip_nb.h"
 #include "ripd/rip_debug.h"
 #include "ripd/rip_errors.h"
 #include "ripd/rip_interface.h"
@@ -1395,7 +1396,7 @@ int rip_create_socket(struct vrf *vrf)
        /* Make datagram socket. */
        if (vrf->vrf_id != VRF_DEFAULT)
                vrf_dev = vrf->name;
-       frr_elevate_privs(&ripd_privs) {
+       frr_with_privs(&ripd_privs) {
                sock = vrf_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, vrf->vrf_id,
                                  vrf_dev);
                if (sock < 0) {
@@ -1415,7 +1416,7 @@ int rip_create_socket(struct vrf *vrf)
 #endif
        setsockopt_so_recvbuf(sock, RIP_UDP_RCV_BUF);
 
-       frr_elevate_privs(&ripd_privs) {
+       frr_with_privs(&ripd_privs) {
                if ((ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr)))
                    < 0) {
                        zlog_err("%s: Can't bind socket %d to %s port %d: %s",
@@ -3641,6 +3642,37 @@ static int rip_vrf_enable(struct vrf *vrf)
        int socket;
 
        rip = rip_lookup_by_vrf_name(vrf->name);
+       if (!rip) {
+               char *old_vrf_name = NULL;
+
+               rip = (struct rip *)vrf->info;
+               if (!rip)
+                       return 0;
+               /* update vrf name */
+               if (rip->vrf_name)
+                       old_vrf_name = rip->vrf_name;
+               rip->vrf_name = XSTRDUP(MTYPE_RIP_VRF_NAME, vrf->name);
+               /*
+                * HACK: Change the RIP VRF in the running configuration directly,
+                * bypassing the northbound layer. This is necessary to avoid deleting
+                * the RIP and readding it in the new VRF, which would have
+                * several implications.
+                */
+               if (yang_module_find("frr-ripd") && old_vrf_name) {
+                       struct lyd_node *rip_dnode;
+
+                       rip_dnode = yang_dnode_get(
+                               running_config->dnode,
+                               "/frr-ripd:ripd/instance[vrf='%s']/vrf",
+                               old_vrf_name);
+                       if (rip_dnode) {
+                               yang_dnode_change_leaf(rip_dnode, vrf->name);
+                               running_config->version++;
+                       }
+               }
+               if (old_vrf_name)
+                       XFREE(MTYPE_RIP_VRF_NAME, old_vrf_name);
+       }
        if (!rip || rip->enabled)
                return 0;
 
@@ -3682,7 +3714,7 @@ static int rip_vrf_disable(struct vrf *vrf)
 void rip_vrf_init(void)
 {
        vrf_init(rip_vrf_new, rip_vrf_enable, rip_vrf_disable, rip_vrf_delete,
-                NULL);
+                rip_vrf_enable);
 }
 
 void rip_vrf_terminate(void)