]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Allow vrf under the cli
authorDonald Sharp <sharpd@cumulusnetworks.com>
Mon, 1 Feb 2016 17:38:33 +0000 (09:38 -0800)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Mon, 1 Feb 2016 17:38:33 +0000 (09:38 -0800)
Add the infrastructure to allow the vrf keyword.

Signed-off-by: Vipin Kumar <vipin@cumulusnetworks.com>
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
lib/command.c
lib/command.h
lib/if.c
lib/if.h

index 5e8259dd39118a3f4ce216c4b9b149a66788efca..ed337cbccf4f0511778cafbceb784c696e645969 100644 (file)
@@ -2929,6 +2929,7 @@ DEFUN (config_exit,
       vty_config_unlock (vty);
       break;
     case INTERFACE_NODE:
+    case VRF_NODE:
     case ZEBRA_NODE:
     case BGP_NODE:
     case RIP_NODE:
@@ -2980,6 +2981,7 @@ DEFUN (config_end,
       break;
     case CONFIG_NODE:
     case INTERFACE_NODE:
+    case VRF_NODE:
     case ZEBRA_NODE:
     case RIP_NODE:
     case RIPNG_NODE:
index f9f4c7e397b1b23a2b1118d82579ea7bd7a24573..c964b8a8074ff46bacf28691092447cf9bf8d213 100644 (file)
@@ -74,6 +74,7 @@ enum node_type
   KEYCHAIN_NODE,               /* Key-chain node. */
   KEYCHAIN_KEY_NODE,           /* Key-chain key node. */
   INTERFACE_NODE,              /* Interface mode node. */
+  VRF_NODE,                    /* VRF mode node. */
   ZEBRA_NODE,                  /* zebra connection node. */
   TABLE_NODE,                  /* rtm_table selection node. */
   RIP_NODE,                    /* RIP protocol mode node. */ 
index d4bd918e955753e4eab7a1889cbe0c31c1e8597c..6a54d242a09e0a9e238d2331c33b7ac780627296 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -154,6 +154,31 @@ if_create (const char *name, int namelen)
   return if_create_vrf (name, namelen, VRF_DEFAULT);
 }
 
+/* Create new interface structure. */
+void
+if_update_vrf (struct interface *ifp, const char *name, int namelen, vrf_id_t vrf_id)
+{
+  struct list *intf_list = vrf_iflist_get (vrf_id);
+
+  /* remove interface from old master vrf list */
+  if (vrf_iflist (ifp->vrf_id))
+    listnode_delete (vrf_iflist (ifp->vrf_id), ifp);
+
+  assert (name);
+  assert (namelen <= INTERFACE_NAMSIZ);        /* Need space for '\0' at end. */
+  strncpy (ifp->name, name, namelen);
+  ifp->name[namelen] = '\0';
+  ifp->vrf_id = vrf_id;
+  if (if_lookup_by_name_vrf (ifp->name, vrf_id) == NULL)
+    listnode_add_sort (intf_list, ifp);
+  else
+    zlog_err("if_create(%s): corruption detected -- interface with this "
+             "name exists already in VRF %u!", ifp->name, vrf_id);
+
+  return;
+}
+
+
 /* Delete interface structure. */
 void
 if_delete_retain (struct interface *ifp)
@@ -682,8 +707,10 @@ DEFUN (interface,
       return CMD_WARNING;
     }
 
+/*Pending: need proper vrf name based lookup/(possible creation of VRF)
+ Imagine forward reference of a vrf by name in this interface config */
   if (argc > 1)
-    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
+    VRF_GET_ID (vrf_id, argv[1]);
 
 #ifdef SUNOS_5
   ifp = if_sunwzebra_get (argv[0], sl, vrf_id);
@@ -716,7 +743,7 @@ DEFUN_NOSH (no_interface,
   vrf_id_t vrf_id = VRF_DEFAULT;
 
   if (argc > 1)
-    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
+    VRF_GET_ID (vrf_id, argv[1]);
 
   ifp = if_lookup_by_name_vrf (argv[0], vrf_id);
 
@@ -746,6 +773,61 @@ ALIAS (no_interface,
        "Interface's name\n"
        VRF_CMD_HELP_STR)
 
+DEFUN (vrf,
+       vrf_cmd,
+       "vrf NAME",
+       "Select a VRF to configure\n"
+       "VRF's name\n")
+{
+  struct vrf *vrfp;
+  size_t sl;
+
+  if ((sl = strlen(argv[0])) > VRF_NAMSIZ)
+    {
+      vty_out (vty, "%% VRF name %s is invalid: length exceeds "
+                   "%d characters%s",
+              argv[0], VRF_NAMSIZ, VTY_NEWLINE);
+      return CMD_WARNING;
+    }
+
+  vrfp = vrf_get_by_name_len (argv[0], sl);
+
+  vty->index = vrfp;
+  vty->node = VRF_NODE;
+
+  return CMD_SUCCESS;
+}
+
+DEFUN_NOSH (no_vrf,
+           no_vrf_cmd,
+           "no vrf NAME",
+           NO_STR
+           "Delete a pseudo VRF's configuration\n"
+           "VRF's name\n")
+{
+  struct vrf *vrfp;
+
+  vrfp = vrf_list_lookup_by_name (argv[0]);
+
+  if (vrfp == NULL)
+    {
+      vty_out (vty, "%% VRF %s does not exist%s", argv[0], VTY_NEWLINE);
+      return CMD_WARNING;
+    }
+
+  if (CHECK_FLAG (vrfp->status, ZEBRA_VRF_ACTIVE))
+    {
+      vty_out (vty, "%% Only inactive VRFs can be deleted%s",
+             VTY_NEWLINE);
+      return CMD_WARNING;
+    }
+
+  vrf_delete(vrfp);
+
+  return CMD_SUCCESS;
+}
+
+
 /* For debug purpose. */
 DEFUN (show_address,
        show_address_cmd,
@@ -761,7 +843,7 @@ DEFUN (show_address,
   vrf_id_t vrf_id = VRF_DEFAULT;
 
   if (argc > 0)
-    VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
+    VRF_GET_ID (vrf_id, argv[0]);
 
   for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
     {
index f7a5a5ceefc63bb1345ae5af2a35f512b5a259e9..b0f620352b60f1546598e2a07bc5749ba32260fd 100644 (file)
--- a/lib/if.h
+++ b/lib/if.h
@@ -146,6 +146,7 @@ struct interface
   struct if_data stats;
 #endif /* HAVE_NET_RT_IFLIST */
 
+  struct route_node *node;
   vrf_id_t vrf_id;
 };
 
@@ -266,6 +267,8 @@ extern struct interface *if_lookup_exact_address (void *matchaddr, int family);
 extern struct interface *if_lookup_address (void *matchaddr, int family);
 extern struct interface *if_lookup_prefix (struct prefix *prefix);
 
+extern void if_update_vrf (struct interface *, const char *name, int namelen,
+                                vrf_id_t vrf_id);
 extern struct interface *if_create_vrf (const char *name, int namelen,
                                 vrf_id_t vrf_id);
 extern struct interface *if_lookup_by_index_vrf (unsigned int,
@@ -370,5 +373,7 @@ extern struct cmd_element no_interface_pseudo_cmd;
 extern struct cmd_element show_address_cmd;
 extern struct cmd_element show_address_vrf_cmd;
 extern struct cmd_element show_address_vrf_all_cmd;
+extern struct cmd_element vrf_cmd;
+extern struct cmd_element no_vrf_cmd;
 
 #endif /* _ZEBRA_IF_H */