Browse Source

isisd: API: basic circuit config

Create isis_vty.c and start moving off CLI functions into that.  These
then call newly-added "nice" API wrappers.

Patch contains significant work authored by Christian Franke.

[v2: removed stuff that crept in from the next patch]

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
David Lamparter 3 years ago
parent
commit
3732cba030
6 changed files with 771 additions and 808 deletions
  1. 2 1
      isisd/Makefile.am
  2. 72 807
      isisd/isis_circuit.c
  3. 12 0
      isisd/isis_circuit.h
  4. 1 0
      isisd/isis_redist.h
  5. 678 0
      isisd/isis_vty.c
  6. 6 0
      isisd/isisd.h

+ 2 - 1
isisd/Makefile.am

@@ -16,7 +16,8 @@ libisis_a_SOURCES = \
 	isis_adjacency.c isis_lsp.c dict.c isis_circuit.c isis_pdu.c \
 	isis_tlv.c isisd.c isis_misc.c isis_zebra.c isis_dr.c \
 	isis_flags.c isis_dynhn.c iso_checksum.c isis_csm.c isis_events.c \
-	isis_spf.c isis_redist.c isis_route.c isis_routemap.c isis_te.c
+	isis_spf.c isis_redist.c isis_route.c isis_routemap.c isis_te.c \
+	isis_vty.c
 
 
 noinst_HEADERS = \

+ 72 - 807
isisd/isis_circuit.c

@@ -1248,364 +1248,88 @@ isis_interface_config_write (struct vty *vty)
   return write;
 }
 
-DEFUN (ip_router_isis,
-       ip_router_isis_cmd,
-       "ip router isis WORD",
-       "Interface Internet Protocol config commands\n"
-       "IP router interface commands\n"
-       "IS-IS Routing for IP\n"
-       "Routing process tag\n")
+struct isis_circuit *
+isis_circuit_create (struct isis_area *area, struct interface *ifp)
 {
   struct isis_circuit *circuit;
-  struct interface *ifp;
-  struct isis_area *area;
-  int rv;
-
-  ifp = (struct interface *) vty->index;
-  assert (ifp);
-
-  /* Prevent more than one area per circuit */
-  circuit = circuit_scan_by_ifp (ifp);
-  if (circuit)
-    {
-      if (circuit->ip_router == 1)
-        {
-          if (strcmp (circuit->area->area_tag, argv[0]))
-            {
-              vty_out (vty, "ISIS circuit is already defined on %s%s",
-                       circuit->area->area_tag, VTY_NEWLINE);
-              return CMD_ERR_NOTHING_TODO;
-            }
-          return CMD_SUCCESS;
-        }
-    }
-
-  if (isis_area_get (vty, argv[0]) != CMD_SUCCESS)
-    {
-      vty_out (vty, "Can't find ISIS instance %s", VTY_NEWLINE);
-      return CMD_ERR_NO_MATCH;
-    }
-  area = vty->index;
-
-  circuit = isis_csm_state_change (ISIS_ENABLE, circuit, area);
-  if (circuit->state != C_STATE_CONF && circuit->state != C_STATE_UP)
-    {
-      vty_out(vty, "Couldn't bring up interface, please check log.%s", VTY_NEWLINE);
-      rv = CMD_WARNING;
-    }
-  else
-    {
-      isis_circuit_if_bind (circuit, ifp);
-
-      circuit->ip_router = 1;
-      area->ip_circuits++;
-      circuit_update_nlpids (circuit);
-      rv = CMD_SUCCESS;
-    }
-
-  vty->node = INTERFACE_NODE;
-  vty->index = ifp;
-
-  if (circuit->ipv6_router)
-    lsp_regenerate_schedule(circuit->area, circuit->is_type, 0);
-  return rv;
+  circuit = isis_csm_state_change (ISIS_ENABLE, NULL, area);
+  assert (circuit->state == C_STATE_CONF || circuit->state == C_STATE_UP);
+  isis_circuit_if_bind (circuit, ifp);
+  return circuit;
 }
 
-DEFUN (no_ip_router_isis,
-       no_ip_router_isis_cmd,
-       "no ip router isis WORD",
-       NO_STR
-       "Interface Internet Protocol config commands\n"
-       "IP router interface commands\n"
-       "IS-IS Routing for IP\n"
-       "Routing process tag\n")
+void
+isis_circuit_af_set (struct isis_circuit *circuit, bool ip_router, bool ipv6_router)
 {
-  struct interface *ifp;
-  struct isis_area *area;
-  struct isis_circuit *circuit;
+  struct isis_area *area = circuit->area;
+  bool change = circuit->ip_router != ip_router || circuit->ipv6_router != ipv6_router;
+  bool was_enabled = circuit->ip_router || circuit->ipv6_router;
 
-  ifp = (struct interface *) vty->index;
-  if (!ifp)
-    {
-      vty_out (vty, "Invalid interface %s", VTY_NEWLINE);
-      return CMD_ERR_NO_MATCH;
-    }
+  area->ip_circuits   += ip_router   - circuit->ip_router;
+  area->ipv6_circuits += ipv6_router - circuit->ipv6_router;
+  circuit->ip_router   = ip_router;
+  circuit->ipv6_router = ipv6_router;
 
-  area = isis_area_lookup (argv[0]);
-  if (!area)
-    {
-      vty_out (vty, "Can't find ISIS instance %s%s",
-               argv[0], VTY_NEWLINE);
-      return CMD_ERR_NO_MATCH;
-    }
+  if (!change)
+    return;
 
-  circuit = circuit_lookup_by_ifp (ifp, area->circuit_list);
-  if (!circuit)
-    {
-      vty_out (vty, "ISIS is not enabled on circuit %s%s",
-               ifp->name, VTY_NEWLINE);
-      return CMD_ERR_NO_MATCH;
-    }
+  circuit_update_nlpids (circuit);
 
-  circuit->ip_router = 0;
-  area->ip_circuits--;
-  if (circuit->ipv6_router == 0)
+  if (!ip_router && !ipv6_router)
     isis_csm_state_change (ISIS_DISABLE, circuit, area);
+  else if (!was_enabled)
+    isis_csm_state_change (ISIS_ENABLE, circuit, area);
   else
-    lsp_regenerate_schedule(area, circuit->is_type, 0);
-
-  return CMD_SUCCESS;
-}
-
-#ifdef HAVE_IPV6
-DEFUN (ipv6_router_isis,
-       ipv6_router_isis_cmd,
-       "ipv6 router isis WORD",
-       "IPv6 interface subcommands\n"
-       "IPv6 Router interface commands\n"
-       "IS-IS Routing for IPv6\n"
-       "Routing process tag\n")
-{
-  struct isis_circuit *circuit;
-  struct interface *ifp;
-  struct isis_area *area;
-  int rv;
-
-  ifp = (struct interface *) vty->index;
-  assert (ifp);
-
-  /* Prevent more than one area per circuit */
-  circuit = circuit_scan_by_ifp (ifp);
-  if (circuit)
-    {
-      if (circuit->ipv6_router == 1)
-      {
-        if (strcmp (circuit->area->area_tag, argv[0]))
-          {
-            vty_out (vty, "ISIS circuit is already defined for IPv6 on %s%s",
-                     circuit->area->area_tag, VTY_NEWLINE);
-            return CMD_ERR_NOTHING_TODO;
-          }
-        return CMD_SUCCESS;
-      }
-    }
-
-  if (isis_area_get (vty, argv[0]) != CMD_SUCCESS)
-    {
-      vty_out (vty, "Can't find ISIS instance %s", VTY_NEWLINE);
-      return CMD_ERR_NO_MATCH;
-    }
-  area = vty->index;
-
-  circuit = isis_csm_state_change (ISIS_ENABLE, circuit, area);
-  if (circuit->state != C_STATE_CONF && circuit->state != C_STATE_UP)
-    {
-      vty_out(vty, "Couldn't bring up interface, please check log.%s", VTY_NEWLINE);
-      rv = CMD_WARNING;
-    }
-  else
-    {
-      isis_circuit_if_bind (circuit, ifp);
-
-      circuit->ipv6_router = 1;
-      area->ipv6_circuits++;
-      circuit_update_nlpids (circuit);
-      rv = CMD_SUCCESS;
-    }
-
-  vty->node = INTERFACE_NODE;
-  vty->index = ifp;
-
-  if (circuit->ip_router)
     lsp_regenerate_schedule(circuit->area, circuit->is_type, 0);
-  return rv;
 }
 
-DEFUN (no_ipv6_router_isis,
-       no_ipv6_router_isis_cmd,
-       "no ipv6 router isis WORD",
-       NO_STR
-       "IPv6 interface subcommands\n"
-       "IPv6 Router interface commands\n"
-       "IS-IS Routing for IPv6\n"
-       "Routing process tag\n")
-{
-  struct interface *ifp;
-  struct isis_area *area;
-  struct isis_circuit *circuit;
-
-  ifp = (struct interface *) vty->index;
-  if (!ifp)
-    {
-      vty_out (vty, "Invalid interface %s", VTY_NEWLINE);
-      return CMD_ERR_NO_MATCH;
-    }
-
-  area = isis_area_lookup (argv[0]);
-  if (!area)
-    {
-      vty_out (vty, "Can't find ISIS instance %s%s",
-               argv[0], VTY_NEWLINE);
-      return CMD_ERR_NO_MATCH;
-    }
-
-  circuit = circuit_lookup_by_ifp (ifp, area->circuit_list);
-  if (!circuit)
-    {
-      vty_out (vty, "ISIS is not enabled on circuit %s%s",
-               ifp->name, VTY_NEWLINE);
-      return CMD_ERR_NO_MATCH;
-    }
-
-  circuit->ipv6_router = 0;
-  area->ipv6_circuits--;
-  if (circuit->ip_router == 0)
-    isis_csm_state_change (ISIS_DISABLE, circuit, area);
-  else
-    lsp_regenerate_schedule(area, circuit->is_type, 0);
-
-  return CMD_SUCCESS;
-}
-#endif /* HAVE_IPV6 */
-
-DEFUN (isis_passive,
-       isis_passive_cmd,
-       "isis passive",
-       "IS-IS commands\n"
-       "Configure the passive mode for interface\n")
+int
+isis_circuit_passive_set (struct isis_circuit *circuit, bool passive)
 {
-  struct isis_circuit *circuit = isis_circuit_lookup (vty);
-  if (!circuit)
-    return CMD_ERR_NO_MATCH;
+  if (circuit->is_passive == passive)
+    return 0;
 
-  if (circuit->is_passive == 1)
-    return CMD_SUCCESS;
+  if (if_is_loopback (circuit->interface) && !passive)
+    return -1;
 
   if (circuit->state != C_STATE_UP)
     {
-      circuit->is_passive = 1;
+      circuit->is_passive = passive;
     }
   else
     {
       struct isis_area *area = circuit->area;
       isis_csm_state_change (ISIS_DISABLE, circuit, area);
-      circuit->is_passive = 1;
+      circuit->is_passive = passive;
       isis_csm_state_change (ISIS_ENABLE, circuit, area);
     }
 
-  return CMD_SUCCESS;
+  return 0;
 }
 
-DEFUN (no_isis_passive,
-       no_isis_passive_cmd,
-       "no isis passive",
-       NO_STR
-       "IS-IS commands\n"
-       "Configure the passive mode for interface\n")
+void
+isis_circuit_is_type_set (struct isis_circuit *circuit, int circ_type)
 {
-  struct interface *ifp;
-  struct isis_circuit *circuit;
-
-  ifp = (struct interface *) vty->index;
-  if (!ifp)
-    {
-      vty_out (vty, "Invalid interface %s", VTY_NEWLINE);
-      return CMD_ERR_NO_MATCH;
-    }
-
-  /* FIXME: what is wrong with circuit = ifp->info ? */
-  circuit = circuit_scan_by_ifp (ifp);
-  if (!circuit)
-    {
-      vty_out (vty, "ISIS is not enabled on circuit %s%s",
-               ifp->name, VTY_NEWLINE);
-      return CMD_ERR_NO_MATCH;
-    }
-
-  if (if_is_loopback(ifp))
-    {
-      vty_out (vty, "Can't set no passive for loopback interface%s",
-               VTY_NEWLINE);
-      return CMD_ERR_AMBIGUOUS;
-    }
-
-  if (circuit->is_passive == 0)
-    return CMD_SUCCESS;
-
-  if (circuit->state != C_STATE_UP)
-    {
-      circuit->is_passive = 0;
-    }
-  else
-    {
-      struct isis_area *area = circuit->area;
-      isis_csm_state_change (ISIS_DISABLE, circuit, area);
-      circuit->is_passive = 0;
-      isis_csm_state_change (ISIS_ENABLE, circuit, area);
-    }
-
-  return CMD_SUCCESS;
+  if (circuit->circ_type != circ_type)
+    isis_event_circuit_type_change (circuit, circ_type);
 }
 
-DEFUN (isis_circuit_type,
-       isis_circuit_type_cmd,
-       "isis circuit-type (level-1|level-1-2|level-2-only)",
-       "IS-IS commands\n"
-       "Configure circuit type for interface\n"
-       "Level-1 only adjacencies are formed\n"
-       "Level-1-2 adjacencies are formed\n"
-       "Level-2 only adjacencies are formed\n")
-{
-  int circuit_type;
-  struct isis_circuit *circuit = isis_circuit_lookup (vty);
-  if (!circuit)
-    return CMD_ERR_NO_MATCH;
-
-  circuit_type = string2circuit_t (argv[0]);
-  if (!circuit_type)
-    {
-      vty_out (vty, "Unknown circuit-type %s", VTY_NEWLINE);
-      return CMD_ERR_AMBIGUOUS;
-    }
-
-  if (circuit->state == C_STATE_UP &&
-      circuit->area->is_type != IS_LEVEL_1_AND_2 &&
-      circuit->area->is_type != circuit_type)
-    {
-      vty_out (vty, "Invalid circuit level for area %s.%s",
-               circuit->area->area_tag, VTY_NEWLINE);
-      return CMD_ERR_AMBIGUOUS;
-    }
-  isis_event_circuit_type_change (circuit, circuit_type);
-
-  return CMD_SUCCESS;
-}
-
-DEFUN (no_isis_circuit_type,
-       no_isis_circuit_type_cmd,
-       "no isis circuit-type (level-1|level-1-2|level-2-only)",
-       NO_STR
-       "IS-IS commands\n"
-       "Configure circuit type for interface\n"
-       "Level-1 only adjacencies are formed\n"
-       "Level-1-2 adjacencies are formed\n"
-       "Level-2 only adjacencies are formed\n")
+int
+isis_circuit_metric_set (struct isis_circuit *circuit, int level, int metric)
 {
-  int circuit_type;
-  struct isis_circuit *circuit = isis_circuit_lookup (vty);
-  if (!circuit)
-    return CMD_ERR_NO_MATCH;
+  assert (level == IS_LEVEL_1 || level == IS_LEVEL_2);
+  if (metric > MAX_WIDE_LINK_METRIC)
+    return -1;
+  if (circuit->area && circuit->area->oldmetric
+      && metric > MAX_NARROW_LINK_METRIC)
+    return -1;
 
-  /*
-   * Set the circuits level to its default value
-   */
-  if (circuit->state == C_STATE_UP)
-    circuit_type = circuit->area->is_type;
-  else
-    circuit_type = IS_LEVEL_1_AND_2;
-  isis_event_circuit_type_change (circuit, circuit_type);
+  circuit->te_metric[level - 1] = metric;
+  circuit->metrics[level - 1].metric_default = metric;
 
-  return CMD_SUCCESS;
+  if (circuit->area)
+    lsp_regenerate_schedule (circuit->area, level, 0);
+  return 0;
 }
 
 DEFUN (isis_passwd_md5,
@@ -1676,387 +1400,6 @@ DEFUN (no_isis_passwd,
   return CMD_SUCCESS;
 }
 
-DEFUN (isis_priority,
-       isis_priority_cmd,
-       "isis priority <0-127>",
-       "IS-IS commands\n"
-       "Set priority for Designated Router election\n"
-       "Priority value\n")
-{
-  int prio;
-  struct isis_circuit *circuit = isis_circuit_lookup (vty);
-  if (!circuit)
-    return CMD_ERR_NO_MATCH;
-
-  prio = atoi (argv[0]);
-  if (prio < MIN_PRIORITY || prio > MAX_PRIORITY)
-    {
-      vty_out (vty, "Invalid priority %d - should be <0-127>%s",
-               prio, VTY_NEWLINE);
-      return CMD_ERR_AMBIGUOUS;
-    }
-
-  circuit->priority[0] = prio;
-  circuit->priority[1] = prio;
-
-  return CMD_SUCCESS;
-}
-
-DEFUN (no_isis_priority,
-       no_isis_priority_cmd,
-       "no isis priority",
-       NO_STR
-       "IS-IS commands\n"
-       "Set priority for Designated Router election\n")
-{
-  struct isis_circuit *circuit = isis_circuit_lookup (vty);
-  if (!circuit)
-    return CMD_ERR_NO_MATCH;
-
-  circuit->priority[0] = DEFAULT_PRIORITY;
-  circuit->priority[1] = DEFAULT_PRIORITY;
-
-  return CMD_SUCCESS;
-}
-
-ALIAS (no_isis_priority,
-       no_isis_priority_arg_cmd,
-       "no isis priority <0-127>",
-       NO_STR
-       "IS-IS commands\n"
-       "Set priority for Designated Router election\n"
-       "Priority value\n")
-
-DEFUN (isis_priority_l1,
-       isis_priority_l1_cmd,
-       "isis priority <0-127> level-1",
-       "IS-IS commands\n"
-       "Set priority for Designated Router election\n"
-       "Priority value\n"
-       "Specify priority for level-1 routing\n")
-{
-  int prio;
-  struct isis_circuit *circuit = isis_circuit_lookup (vty);
-  if (!circuit)
-    return CMD_ERR_NO_MATCH;
-
-  prio = atoi (argv[0]);
-  if (prio < MIN_PRIORITY || prio > MAX_PRIORITY)
-    {
-      vty_out (vty, "Invalid priority %d - should be <0-127>%s",
-               prio, VTY_NEWLINE);
-      return CMD_ERR_AMBIGUOUS;
-    }
-
-  circuit->priority[0] = prio;
-
-  return CMD_SUCCESS;
-}
-
-DEFUN (no_isis_priority_l1,
-       no_isis_priority_l1_cmd,
-       "no isis priority level-1",
-       NO_STR
-       "IS-IS commands\n"
-       "Set priority for Designated Router election\n"
-       "Specify priority for level-1 routing\n")
-{
-  struct isis_circuit *circuit = isis_circuit_lookup (vty);
-  if (!circuit)
-    return CMD_ERR_NO_MATCH;
-
-  circuit->priority[0] = DEFAULT_PRIORITY;
-
-  return CMD_SUCCESS;
-}
-
-ALIAS (no_isis_priority_l1,
-       no_isis_priority_l1_arg_cmd,
-       "no isis priority <0-127> level-1",
-       NO_STR
-       "IS-IS commands\n"
-       "Set priority for Designated Router election\n"
-       "Priority value\n"
-       "Specify priority for level-1 routing\n")
-
-DEFUN (isis_priority_l2,
-       isis_priority_l2_cmd,
-       "isis priority <0-127> level-2",
-       "IS-IS commands\n"
-       "Set priority for Designated Router election\n"
-       "Priority value\n"
-       "Specify priority for level-2 routing\n")
-{
-  int prio;
-  struct isis_circuit *circuit = isis_circuit_lookup (vty);
-  if (!circuit)
-    return CMD_ERR_NO_MATCH;
-
-  prio = atoi (argv[0]);
-  if (prio < MIN_PRIORITY || prio > MAX_PRIORITY)
-    {
-      vty_out (vty, "Invalid priority %d - should be <0-127>%s",
-               prio, VTY_NEWLINE);
-      return CMD_ERR_AMBIGUOUS;
-    }
-
-  circuit->priority[1] = prio;
-
-  return CMD_SUCCESS;
-}
-
-DEFUN (no_isis_priority_l2,
-       no_isis_priority_l2_cmd,
-       "no isis priority level-2",
-       NO_STR
-       "IS-IS commands\n"
-       "Set priority for Designated Router election\n"
-       "Specify priority for level-2 routing\n")
-{
-  struct isis_circuit *circuit = isis_circuit_lookup (vty);
-  if (!circuit)
-    return CMD_ERR_NO_MATCH;
-
-  circuit->priority[1] = DEFAULT_PRIORITY;
-
-  return CMD_SUCCESS;
-}
-
-ALIAS (no_isis_priority_l2,
-       no_isis_priority_l2_arg_cmd,
-       "no isis priority <0-127> level-2",
-       NO_STR
-       "IS-IS commands\n"
-       "Set priority for Designated Router election\n"
-       "Priority value\n"
-       "Specify priority for level-2 routing\n")
-
-/* Metric command */
-DEFUN (isis_metric,
-       isis_metric_cmd,
-       "isis metric <0-16777215>",
-       "IS-IS commands\n"
-       "Set default metric for circuit\n"
-       "Default metric value\n")
-{
-  int met;
-  struct isis_circuit *circuit = isis_circuit_lookup (vty);
-  if (!circuit)
-    return CMD_ERR_NO_MATCH;
-
-  met = atoi (argv[0]);
-
-  /* RFC3787 section 5.1 */
-  if (circuit->area && circuit->area->oldmetric == 1 &&
-      met > MAX_NARROW_LINK_METRIC)
-    {
-      vty_out (vty, "Invalid metric %d - should be <0-63> "
-               "when narrow metric type enabled%s",
-               met, VTY_NEWLINE);
-      return CMD_ERR_AMBIGUOUS;
-    }
-
-  /* RFC4444 */
-  if (circuit->area && circuit->area->newmetric == 1 &&
-      met > MAX_WIDE_LINK_METRIC)
-    {
-      vty_out (vty, "Invalid metric %d - should be <0-16777215> "
-               "when wide metric type enabled%s",
-               met, VTY_NEWLINE);
-      return CMD_ERR_AMBIGUOUS;
-    }
-
-  circuit->te_metric[0] = met;
-  circuit->te_metric[1] = met;
-
-  circuit->metrics[0].metric_default = met;
-  circuit->metrics[1].metric_default = met;
-
-  if (circuit->area)
-    lsp_regenerate_schedule (circuit->area, circuit->is_type, 0);
-
-  return CMD_SUCCESS;
-}
-
-DEFUN (no_isis_metric,
-       no_isis_metric_cmd,
-       "no isis metric",
-       NO_STR
-       "IS-IS commands\n"
-       "Set default metric for circuit\n")
-{
-  struct isis_circuit *circuit = isis_circuit_lookup (vty);
-  if (!circuit)
-    return CMD_ERR_NO_MATCH;
-
-  circuit->te_metric[0] = DEFAULT_CIRCUIT_METRIC;
-  circuit->te_metric[1] = DEFAULT_CIRCUIT_METRIC;
-  circuit->metrics[0].metric_default = DEFAULT_CIRCUIT_METRIC;
-  circuit->metrics[1].metric_default = DEFAULT_CIRCUIT_METRIC;
-
-  if (circuit->area)
-    lsp_regenerate_schedule (circuit->area, circuit->is_type, 0);
-
-  return CMD_SUCCESS;
-}
-
-ALIAS (no_isis_metric,
-       no_isis_metric_arg_cmd,
-       "no isis metric <0-16777215>",
-       NO_STR
-       "IS-IS commands\n"
-       "Set default metric for circuit\n"
-       "Default metric value\n")
-
-DEFUN (isis_metric_l1,
-       isis_metric_l1_cmd,
-       "isis metric <0-16777215> level-1",
-       "IS-IS commands\n"
-       "Set default metric for circuit\n"
-       "Default metric value\n"
-       "Specify metric for level-1 routing\n")
-{
-  int met;
-  struct isis_circuit *circuit = isis_circuit_lookup (vty);
-  if (!circuit)
-    return CMD_ERR_NO_MATCH;
-
-  met = atoi (argv[0]);
-
-  /* RFC3787 section 5.1 */
-  if (circuit->area && circuit->area->oldmetric == 1 &&
-      met > MAX_NARROW_LINK_METRIC)
-    {
-      vty_out (vty, "Invalid metric %d - should be <0-63> "
-               "when narrow metric type enabled%s",
-               met, VTY_NEWLINE);
-      return CMD_ERR_AMBIGUOUS;
-    }
-
-  /* RFC4444 */
-  if (circuit->area && circuit->area->newmetric == 1 &&
-      met > MAX_WIDE_LINK_METRIC)
-    {
-      vty_out (vty, "Invalid metric %d - should be <0-16777215> "
-               "when wide metric type enabled%s",
-               met, VTY_NEWLINE);
-      return CMD_ERR_AMBIGUOUS;
-    }
-
-  circuit->te_metric[0] = met;
-  circuit->metrics[0].metric_default = met;
-
-  if (circuit->area)
-    lsp_regenerate_schedule (circuit->area, IS_LEVEL_1, 0);
-
-  return CMD_SUCCESS;
-}
-
-DEFUN (no_isis_metric_l1,
-       no_isis_metric_l1_cmd,
-       "no isis metric level-1",
-       NO_STR
-       "IS-IS commands\n"
-       "Set default metric for circuit\n"
-       "Specify metric for level-1 routing\n")
-{
-  struct isis_circuit *circuit = isis_circuit_lookup (vty);
-  if (!circuit)
-    return CMD_ERR_NO_MATCH;
-
-  circuit->te_metric[0] = DEFAULT_CIRCUIT_METRIC;
-  circuit->metrics[0].metric_default = DEFAULT_CIRCUIT_METRIC;
-
-  if (circuit->area)
-    lsp_regenerate_schedule (circuit->area, IS_LEVEL_1, 0);
-
-  return CMD_SUCCESS;
-}
-
-ALIAS (no_isis_metric_l1,
-       no_isis_metric_l1_arg_cmd,
-       "no isis metric <0-16777215> level-1",
-       NO_STR
-       "IS-IS commands\n"
-       "Set default metric for circuit\n"
-       "Default metric value\n"
-       "Specify metric for level-1 routing\n")
-
-DEFUN (isis_metric_l2,
-       isis_metric_l2_cmd,
-       "isis metric <0-16777215> level-2",
-       "IS-IS commands\n"
-       "Set default metric for circuit\n"
-       "Default metric value\n"
-       "Specify metric for level-2 routing\n")
-{
-  int met;
-  struct isis_circuit *circuit = isis_circuit_lookup (vty);
-  if (!circuit)
-    return CMD_ERR_NO_MATCH;
-
-  met = atoi (argv[0]);
-
-  /* RFC3787 section 5.1 */
-  if (circuit->area && circuit->area->oldmetric == 1 &&
-      met > MAX_NARROW_LINK_METRIC)
-    {
-      vty_out (vty, "Invalid metric %d - should be <0-63> "
-               "when narrow metric type enabled%s",
-               met, VTY_NEWLINE);
-      return CMD_ERR_AMBIGUOUS;
-    }
-
-  /* RFC4444 */
-  if (circuit->area && circuit->area->newmetric == 1 &&
-      met > MAX_WIDE_LINK_METRIC)
-    {
-      vty_out (vty, "Invalid metric %d - should be <0-16777215> "
-               "when wide metric type enabled%s",
-               met, VTY_NEWLINE);
-      return CMD_ERR_AMBIGUOUS;
-    }
-
-  circuit->te_metric[1] = met;
-  circuit->metrics[1].metric_default = met;
-
-  if (circuit->area)
-    lsp_regenerate_schedule (circuit->area, IS_LEVEL_2, 0);
-
-  return CMD_SUCCESS;
-}
-
-DEFUN (no_isis_metric_l2,
-       no_isis_metric_l2_cmd,
-       "no isis metric level-2",
-       NO_STR
-       "IS-IS commands\n"
-       "Set default metric for circuit\n"
-       "Specify metric for level-2 routing\n")
-{
-  struct isis_circuit *circuit = isis_circuit_lookup (vty);
-  if (!circuit)
-    return CMD_ERR_NO_MATCH;
-
-  circuit->te_metric[1] = DEFAULT_CIRCUIT_METRIC;
-  circuit->metrics[1].metric_default = DEFAULT_CIRCUIT_METRIC;
-
-  if (circuit->area)
-    lsp_regenerate_schedule (circuit->area, IS_LEVEL_2, 0);
-
-  return CMD_SUCCESS;
-}
-
-ALIAS (no_isis_metric_l2,
-       no_isis_metric_l2_arg_cmd,
-       "no isis metric <0-16777215> level-2",
-       NO_STR
-       "IS-IS commands\n"
-       "Set default metric for circuit\n"
-       "Default metric value\n"
-       "Specify metric for level-2 routing\n")
-/* end of metrics */
-
 DEFUN (isis_hello_interval,
        isis_hello_interval_cmd,
        "isis hello-interval <1-600>",
@@ -2724,86 +2067,43 @@ struct cmd_node interface_node = {
   1,
 };
 
-DEFUN (isis_network,
-       isis_network_cmd,
-       "isis network point-to-point",
-       "IS-IS commands\n"
-       "Set network type\n"
-       "point-to-point network type\n")
+int
+isis_circuit_circ_type_set(struct isis_circuit *circuit, int circ_type)
 {
-  struct isis_circuit *circuit = isis_circuit_lookup (vty);
-  if (!circuit)
-    return CMD_ERR_NO_MATCH;
-
-  /* RFC5309 section 4 */
-  if (circuit->circ_type == CIRCUIT_T_P2P)
-    return CMD_SUCCESS;
-
-  if (circuit->state != C_STATE_UP)
+  /* Changing the network type to/of loopback or unknown interfaces
+   * is not supported. */
+  if (circ_type == CIRCUIT_T_UNKNOWN
+      || circ_type == CIRCUIT_T_LOOPBACK
+      || circuit->circ_type == CIRCUIT_T_UNKNOWN
+      || circuit->circ_type == CIRCUIT_T_LOOPBACK)
     {
-      circuit->circ_type = CIRCUIT_T_P2P;
-      circuit->circ_type_config = CIRCUIT_T_P2P;
-    }
-  else
-    {
-      struct isis_area *area = circuit->area;
-      if (!if_is_broadcast (circuit->interface))
-        {
-          vty_out (vty, "isis network point-to-point "
-                   "is valid only on broadcast interfaces%s",
-                   VTY_NEWLINE);
-          return CMD_ERR_AMBIGUOUS;
-        }
-
-      isis_csm_state_change (ISIS_DISABLE, circuit, area);
-      circuit->circ_type = CIRCUIT_T_P2P;
-      circuit->circ_type_config = CIRCUIT_T_P2P;
-      isis_csm_state_change (ISIS_ENABLE, circuit, area);
+      if (circuit->circ_type != circ_type)
+        return -1;
+      else
+        return 0;
     }
 
-  return CMD_SUCCESS;
-}
-
-DEFUN (no_isis_network,
-       no_isis_network_cmd,
-       "no isis network point-to-point",
-       NO_STR
-       "IS-IS commands\n"
-       "Set network type for circuit\n"
-       "point-to-point network type\n")
-{
-  struct isis_circuit *circuit = isis_circuit_lookup (vty);
-  if (!circuit)
-    return CMD_ERR_NO_MATCH;
-
-  /* RFC5309 section 4 */
-  if (circuit->circ_type == CIRCUIT_T_BROADCAST)
-    return CMD_SUCCESS;
+  if (circuit->circ_type == circ_type)
+    return 0;
 
   if (circuit->state != C_STATE_UP)
     {
-      circuit->circ_type = CIRCUIT_T_BROADCAST;
-      circuit->circ_type_config = CIRCUIT_T_BROADCAST;
+      circuit->circ_type = circ_type;
+      circuit->circ_type_config = circ_type;
     }
   else
     {
       struct isis_area *area = circuit->area;
-      if (circuit->interface &&
-          !if_is_broadcast (circuit->interface))
-      {
-        vty_out (vty, "no isis network point-to-point "
-                 "is valid only on broadcast interfaces%s",
-                 VTY_NEWLINE);
-        return CMD_ERR_AMBIGUOUS;
-      }
+      if (circ_type == CIRCUIT_T_BROADCAST
+          && !if_is_broadcast(circuit->interface))
+        return -1;
 
-      isis_csm_state_change (ISIS_DISABLE, circuit, area);
-      circuit->circ_type = CIRCUIT_T_BROADCAST;
-      circuit->circ_type_config = CIRCUIT_T_BROADCAST;
-      isis_csm_state_change (ISIS_ENABLE, circuit, area);
+      isis_csm_state_change(ISIS_DISABLE, circuit, area);
+      circuit->circ_type = circ_type;
+      circuit->circ_type_config = circ_type;
+      isis_csm_state_change(ISIS_ENABLE, circuit, area);
     }
-
-  return CMD_SUCCESS;
+  return 0;
 }
 
 int
@@ -2843,39 +2143,10 @@ isis_circuit_init ()
   install_element (INTERFACE_NODE, &interface_desc_cmd);
   install_element (INTERFACE_NODE, &no_interface_desc_cmd);
 
-  install_element (INTERFACE_NODE, &ip_router_isis_cmd);
-  install_element (INTERFACE_NODE, &no_ip_router_isis_cmd);
-
-  install_element (INTERFACE_NODE, &isis_passive_cmd);
-  install_element (INTERFACE_NODE, &no_isis_passive_cmd);
-
-  install_element (INTERFACE_NODE, &isis_circuit_type_cmd);
-  install_element (INTERFACE_NODE, &no_isis_circuit_type_cmd);
-
   install_element (INTERFACE_NODE, &isis_passwd_clear_cmd);
   install_element (INTERFACE_NODE, &isis_passwd_md5_cmd);
   install_element (INTERFACE_NODE, &no_isis_passwd_cmd);
 
-  install_element (INTERFACE_NODE, &isis_priority_cmd);
-  install_element (INTERFACE_NODE, &no_isis_priority_cmd);
-  install_element (INTERFACE_NODE, &no_isis_priority_arg_cmd);
-  install_element (INTERFACE_NODE, &isis_priority_l1_cmd);
-  install_element (INTERFACE_NODE, &no_isis_priority_l1_cmd);
-  install_element (INTERFACE_NODE, &no_isis_priority_l1_arg_cmd);
-  install_element (INTERFACE_NODE, &isis_priority_l2_cmd);
-  install_element (INTERFACE_NODE, &no_isis_priority_l2_cmd);
-  install_element (INTERFACE_NODE, &no_isis_priority_l2_arg_cmd);
-
-  install_element (INTERFACE_NODE, &isis_metric_cmd);
-  install_element (INTERFACE_NODE, &no_isis_metric_cmd);
-  install_element (INTERFACE_NODE, &no_isis_metric_arg_cmd);
-  install_element (INTERFACE_NODE, &isis_metric_l1_cmd);
-  install_element (INTERFACE_NODE, &no_isis_metric_l1_cmd);
-  install_element (INTERFACE_NODE, &no_isis_metric_l1_arg_cmd);
-  install_element (INTERFACE_NODE, &isis_metric_l2_cmd);
-  install_element (INTERFACE_NODE, &no_isis_metric_l2_cmd);
-  install_element (INTERFACE_NODE, &no_isis_metric_l2_arg_cmd);
-
   install_element (INTERFACE_NODE, &isis_hello_interval_cmd);
   install_element (INTERFACE_NODE, &no_isis_hello_interval_cmd);
   install_element (INTERFACE_NODE, &no_isis_hello_interval_arg_cmd);
@@ -2919,11 +2190,5 @@ isis_circuit_init ()
   install_element (INTERFACE_NODE, &no_psnp_interval_l2_cmd);
   install_element (INTERFACE_NODE, &no_psnp_interval_l2_arg_cmd);
 
-  install_element (INTERFACE_NODE, &isis_network_cmd);
-  install_element (INTERFACE_NODE, &no_isis_network_cmd);
-
-#ifdef HAVE_IPV6
-  install_element (INTERFACE_NODE, &ipv6_router_isis_cmd);
-  install_element (INTERFACE_NODE, &no_ipv6_router_isis_cmd);
-#endif
+  isis_vty_init ();
 }

+ 12 - 0
isisd/isis_circuit.h

@@ -24,6 +24,10 @@
 #define ISIS_CIRCUIT_H
 
 #include "vty.h"
+#include "if.h"
+
+#include "isis_constants.h"
+#include "isis_common.h"
 
 #define CIRCUIT_MAX 255
 
@@ -168,4 +172,12 @@ void isis_circuit_print_vty (struct isis_circuit *circuit, struct vty *vty,
 size_t isis_circuit_pdu_size(struct isis_circuit *circuit);
 void isis_circuit_stream(struct isis_circuit *circuit, struct stream **stream);
 
+struct isis_circuit *isis_circuit_create (struct isis_area *area, struct interface *ifp);
+void isis_circuit_af_set (struct isis_circuit *circuit, bool ip_router, bool ipv6_router);
+int  isis_circuit_passive_set (struct isis_circuit *circuit, bool passive);
+void isis_circuit_is_type_set (struct isis_circuit *circuit, int is_type);
+int  isis_circuit_circ_type_set (struct isis_circuit *circuit, int circ_type);
+
+int  isis_circuit_metric_set (struct isis_circuit *circuit, int level, int metric);
+
 #endif /* _ZEBRA_ISIS_CIRCUIT_H */

+ 1 - 0
isisd/isis_redist.h

@@ -44,6 +44,7 @@ struct isis_redist
 
 struct isis_area;
 struct prefix;
+struct vty;
 
 struct route_table *get_ext_reach(struct isis_area *area,
                                   int family, int level);

+ 678 - 0
isisd/isis_vty.c

@@ -0,0 +1,678 @@
+/*
+ * IS-IS Rout(e)ing protocol - isis_circuit.h
+ *
+ * Copyright (C) 2001,2002   Sampo Saaristo
+ *                           Tampere University of Technology      
+ *                           Institute of Communications Engineering
+ * Copyright (C) 2016        David Lamparter, for NetDEF, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it 
+ * under the terms of the GNU General Public Licenseas published by the Free 
+ * Software Foundation; either version 2 of the License, or (at your option) 
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,but WITHOUT 
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
+ * more details.
+
+ * You should have received a copy of the GNU General Public License along 
+ * with this program; if not, write to the Free Software Foundation, Inc., 
+ * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#include <zebra.h>
+#include <command.h>
+
+#include "isis_circuit.h"
+#include "isis_csm.h"
+#include "isis_misc.h"
+#include "isisd.h"
+
+static struct isis_circuit *
+isis_circuit_lookup (struct vty *vty)
+{
+  struct interface *ifp;
+  struct isis_circuit *circuit;
+
+  ifp = (struct interface *) vty->index;
+  if (!ifp)
+    {
+      vty_out (vty, "Invalid interface %s", VTY_NEWLINE);
+      return NULL;
+    }
+
+  circuit = circuit_scan_by_ifp (ifp);
+  if (!circuit)
+    {
+      vty_out (vty, "ISIS is not enabled on circuit %s%s",
+               ifp->name, VTY_NEWLINE);
+      return NULL;
+    }
+
+  return circuit;
+}
+
+DEFUN (ip_router_isis,
+       ip_router_isis_cmd,
+       "(ip|ipv6) router isis WORD",
+       "Interface Internet Protocol config commands\n"
+       "IP router interface commands\n"
+       "IS-IS Routing for IP\n"
+       "Routing process tag\n")
+{
+  struct interface *ifp;
+  struct isis_circuit *circuit;
+  struct isis_area *area;
+  const char *af = argv[0];
+  const char *area_tag = argv[1];
+
+  ifp = (struct interface *) vty->index;
+  assert (ifp);
+
+  /* Prevent more than one area per circuit */
+  circuit = circuit_scan_by_ifp (ifp);
+  if (circuit)
+    {
+      if (circuit->ip_router == 1)
+        {
+          if (strcmp (circuit->area->area_tag, area_tag))
+            {
+              vty_out (vty, "ISIS circuit is already defined on %s%s",
+                       circuit->area->area_tag, VTY_NEWLINE);
+              return CMD_ERR_NOTHING_TODO;
+            }
+          return CMD_SUCCESS;
+        }
+    }
+
+  area = isis_area_lookup (area_tag);
+  if (!area)
+    area = isis_area_create (area_tag);
+
+  if (!circuit)
+    circuit = isis_circuit_create (area, ifp);
+
+  bool ip = circuit->ip_router, ipv6 = circuit->ipv6_router;
+  if (af[2] != '\0')
+    ipv6 = true;
+  else
+    ip = true;
+
+  isis_circuit_af_set (circuit, ip, ipv6);
+  return CMD_SUCCESS;
+}
+
+DEFUN (no_ip_router_isis,
+       no_ip_router_isis_cmd,
+       "no (ip|ipv6) router isis WORD",
+       NO_STR
+       "Interface Internet Protocol config commands\n"
+       "IP router interface commands\n"
+       "IS-IS Routing for IP\n"
+       "Routing process tag\n")
+{
+  struct interface *ifp;
+  struct isis_area *area;
+  struct isis_circuit *circuit;
+  const char *af = argv[0];
+  const char *area_tag = argv[1];
+
+  ifp = (struct interface *) vty->index;
+  if (!ifp)
+    {
+      vty_out (vty, "Invalid interface %s", VTY_NEWLINE);
+      return CMD_ERR_NO_MATCH;
+    }
+
+  area = isis_area_lookup (area_tag);
+  if (!area)
+    {
+      vty_out (vty, "Can't find ISIS instance %s%s",
+               argv[0], VTY_NEWLINE);
+      return CMD_ERR_NO_MATCH;
+    }
+
+  circuit = circuit_lookup_by_ifp (ifp, area->circuit_list);
+  if (!circuit)
+    {
+      vty_out (vty, "ISIS is not enabled on circuit %s%s",
+               ifp->name, VTY_NEWLINE);
+      return CMD_ERR_NO_MATCH;
+    }
+
+  bool ip = circuit->ip_router, ipv6 = circuit->ipv6_router;
+  if (af[2] != '\0')
+    ipv6 = false;
+  else
+    ip = false;
+
+  isis_circuit_af_set (circuit, ip, ipv6);
+  return CMD_SUCCESS;
+}
+
+DEFUN (isis_passive,
+       isis_passive_cmd,
+       "isis passive",
+       "IS-IS commands\n"
+       "Configure the passive mode for interface\n")
+{
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  isis_circuit_passive_set (circuit, 1);
+  return CMD_SUCCESS;
+}
+
+DEFUN (no_isis_passive,
+       no_isis_passive_cmd,
+       "no isis passive",
+       NO_STR
+       "IS-IS commands\n"
+       "Configure the passive mode for interface\n")
+{
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  if (if_is_loopback (circuit->interface))
+    {
+      vty_out (vty, "Can't set no passive for loopback interface%s",
+               VTY_NEWLINE);
+      return CMD_ERR_AMBIGUOUS;
+    }
+
+  isis_circuit_passive_set (circuit, 0);
+  return CMD_SUCCESS;
+}
+
+DEFUN (isis_circuit_type,
+       isis_circuit_type_cmd,
+       "isis circuit-type (level-1|level-1-2|level-2-only)",
+       "IS-IS commands\n"
+       "Configure circuit type for interface\n"
+       "Level-1 only adjacencies are formed\n"
+       "Level-1-2 adjacencies are formed\n"
+       "Level-2 only adjacencies are formed\n")
+{
+  int is_type;
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  is_type = string2circuit_t (argv[0]);
+  if (!is_type)
+    {
+      vty_out (vty, "Unknown circuit-type %s", VTY_NEWLINE);
+      return CMD_ERR_AMBIGUOUS;
+    }
+
+  if (circuit->state == C_STATE_UP &&
+      circuit->area->is_type != IS_LEVEL_1_AND_2 &&
+      circuit->area->is_type != is_type)
+    {
+      vty_out (vty, "Invalid circuit level for area %s.%s",
+               circuit->area->area_tag, VTY_NEWLINE);
+      return CMD_ERR_AMBIGUOUS;
+    }
+  isis_circuit_is_type_set (circuit, is_type);
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (no_isis_circuit_type,
+       no_isis_circuit_type_cmd,
+       "no isis circuit-type (level-1|level-1-2|level-2-only)",
+       NO_STR
+       "IS-IS commands\n"
+       "Configure circuit type for interface\n"
+       "Level-1 only adjacencies are formed\n"
+       "Level-1-2 adjacencies are formed\n"
+       "Level-2 only adjacencies are formed\n")
+{
+  int is_type;
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  /*
+   * Set the circuits level to its default value
+   */
+  if (circuit->state == C_STATE_UP)
+    is_type = circuit->area->is_type;
+  else
+    is_type = IS_LEVEL_1_AND_2;
+  isis_circuit_is_type_set (circuit, is_type);
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (isis_network,
+       isis_network_cmd,
+       "isis network point-to-point",
+       "IS-IS commands\n"
+       "Set network type\n"
+       "point-to-point network type\n")
+{
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  if (!isis_circuit_circ_type_set(circuit, CIRCUIT_T_P2P))
+    {
+      vty_out (vty, "isis network point-to-point "
+               "is valid only on broadcast interfaces%s",
+               VTY_NEWLINE);
+      return CMD_ERR_AMBIGUOUS;
+    }
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (no_isis_network,
+       no_isis_network_cmd,
+       "no isis network point-to-point",
+       NO_STR
+       "IS-IS commands\n"
+       "Set network type for circuit\n"
+       "point-to-point network type\n")
+{
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  if (!isis_circuit_circ_type_set(circuit, CIRCUIT_T_BROADCAST))
+    {
+      vty_out (vty, "isis network point-to-point "
+               "is valid only on broadcast interfaces%s",
+               VTY_NEWLINE);
+      return CMD_ERR_AMBIGUOUS;
+    }
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (isis_priority,
+       isis_priority_cmd,
+       "isis priority <0-127>",
+       "IS-IS commands\n"
+       "Set priority for Designated Router election\n"
+       "Priority value\n")
+{
+  int prio;
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  prio = atoi (argv[0]);
+  if (prio < MIN_PRIORITY || prio > MAX_PRIORITY)
+    {
+      vty_out (vty, "Invalid priority %d - should be <0-127>%s",
+               prio, VTY_NEWLINE);
+      return CMD_ERR_AMBIGUOUS;
+    }
+
+  circuit->priority[0] = prio;
+  circuit->priority[1] = prio;
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (no_isis_priority,
+       no_isis_priority_cmd,
+       "no isis priority",
+       NO_STR
+       "IS-IS commands\n"
+       "Set priority for Designated Router election\n")
+{
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  circuit->priority[0] = DEFAULT_PRIORITY;
+  circuit->priority[1] = DEFAULT_PRIORITY;
+
+  return CMD_SUCCESS;
+}
+
+ALIAS (no_isis_priority,
+       no_isis_priority_arg_cmd,
+       "no isis priority <0-127>",
+       NO_STR
+       "IS-IS commands\n"
+       "Set priority for Designated Router election\n"
+       "Priority value\n")
+
+DEFUN (isis_priority_l1,
+       isis_priority_l1_cmd,
+       "isis priority <0-127> level-1",
+       "IS-IS commands\n"
+       "Set priority for Designated Router election\n"
+       "Priority value\n"
+       "Specify priority for level-1 routing\n")
+{
+  int prio;
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  prio = atoi (argv[0]);
+  if (prio < MIN_PRIORITY || prio > MAX_PRIORITY)
+    {
+      vty_out (vty, "Invalid priority %d - should be <0-127>%s",
+               prio, VTY_NEWLINE);
+      return CMD_ERR_AMBIGUOUS;
+    }
+
+  circuit->priority[0] = prio;
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (no_isis_priority_l1,
+       no_isis_priority_l1_cmd,
+       "no isis priority level-1",
+       NO_STR
+       "IS-IS commands\n"
+       "Set priority for Designated Router election\n"
+       "Specify priority for level-1 routing\n")
+{
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  circuit->priority[0] = DEFAULT_PRIORITY;
+
+  return CMD_SUCCESS;
+}
+
+ALIAS (no_isis_priority_l1,
+       no_isis_priority_l1_arg_cmd,
+       "no isis priority <0-127> level-1",
+       NO_STR
+       "IS-IS commands\n"
+       "Set priority for Designated Router election\n"
+       "Priority value\n"
+       "Specify priority for level-1 routing\n")
+
+DEFUN (isis_priority_l2,
+       isis_priority_l2_cmd,
+       "isis priority <0-127> level-2",
+       "IS-IS commands\n"
+       "Set priority for Designated Router election\n"
+       "Priority value\n"
+       "Specify priority for level-2 routing\n")
+{
+  int prio;
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  prio = atoi (argv[0]);
+  if (prio < MIN_PRIORITY || prio > MAX_PRIORITY)
+    {
+      vty_out (vty, "Invalid priority %d - should be <0-127>%s",
+               prio, VTY_NEWLINE);
+      return CMD_ERR_AMBIGUOUS;
+    }
+
+  circuit->priority[1] = prio;
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (no_isis_priority_l2,
+       no_isis_priority_l2_cmd,
+       "no isis priority level-2",
+       NO_STR
+       "IS-IS commands\n"
+       "Set priority for Designated Router election\n"
+       "Specify priority for level-2 routing\n")
+{
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  circuit->priority[1] = DEFAULT_PRIORITY;
+
+  return CMD_SUCCESS;
+}
+
+ALIAS (no_isis_priority_l2,
+       no_isis_priority_l2_arg_cmd,
+       "no isis priority <0-127> level-2",
+       NO_STR
+       "IS-IS commands\n"
+       "Set priority for Designated Router election\n"
+       "Priority value\n"
+       "Specify priority for level-2 routing\n")
+
+/* Metric command */
+DEFUN (isis_metric,
+       isis_metric_cmd,
+       "isis metric <0-16777215>",
+       "IS-IS commands\n"
+       "Set default metric for circuit\n"
+       "Default metric value\n")
+{
+  int met;
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  met = atoi (argv[0]);
+
+  /* RFC3787 section 5.1 */
+  if (circuit->area && circuit->area->oldmetric == 1 &&
+      met > MAX_NARROW_LINK_METRIC)
+    {
+      vty_out (vty, "Invalid metric %d - should be <0-63> "
+               "when narrow metric type enabled%s",
+               met, VTY_NEWLINE);
+      return CMD_ERR_AMBIGUOUS;
+    }
+
+  /* RFC4444 */
+  if (circuit->area && circuit->area->newmetric == 1 &&
+      met > MAX_WIDE_LINK_METRIC)
+    {
+      vty_out (vty, "Invalid metric %d - should be <0-16777215> "
+               "when wide metric type enabled%s",
+               met, VTY_NEWLINE);
+      return CMD_ERR_AMBIGUOUS;
+    }
+
+  isis_circuit_metric_set (circuit, IS_LEVEL_1, met);
+  isis_circuit_metric_set (circuit, IS_LEVEL_2, met);
+  return CMD_SUCCESS;
+}
+
+DEFUN (no_isis_metric,
+       no_isis_metric_cmd,
+       "no isis metric",
+       NO_STR
+       "IS-IS commands\n"
+       "Set default metric for circuit\n")
+{
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  isis_circuit_metric_set (circuit, IS_LEVEL_1, DEFAULT_CIRCUIT_METRIC);
+  isis_circuit_metric_set (circuit, IS_LEVEL_2, DEFAULT_CIRCUIT_METRIC);
+  return CMD_SUCCESS;
+}
+
+ALIAS (no_isis_metric,
+       no_isis_metric_arg_cmd,
+       "no isis metric <0-16777215>",
+       NO_STR
+       "IS-IS commands\n"
+       "Set default metric for circuit\n"
+       "Default metric value\n")
+
+DEFUN (isis_metric_l1,
+       isis_metric_l1_cmd,
+       "isis metric <0-16777215> level-1",
+       "IS-IS commands\n"
+       "Set default metric for circuit\n"
+       "Default metric value\n"
+       "Specify metric for level-1 routing\n")
+{
+  int met;
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  met = atoi (argv[0]);
+
+  /* RFC3787 section 5.1 */
+  if (circuit->area && circuit->area->oldmetric == 1 &&
+      met > MAX_NARROW_LINK_METRIC)
+    {
+      vty_out (vty, "Invalid metric %d - should be <0-63> "
+               "when narrow metric type enabled%s",
+               met, VTY_NEWLINE);
+      return CMD_ERR_AMBIGUOUS;
+    }
+
+  /* RFC4444 */
+  if (circuit->area && circuit->area->newmetric == 1 &&
+      met > MAX_WIDE_LINK_METRIC)
+    {
+      vty_out (vty, "Invalid metric %d - should be <0-16777215> "
+               "when wide metric type enabled%s",
+               met, VTY_NEWLINE);
+      return CMD_ERR_AMBIGUOUS;
+    }
+
+  isis_circuit_metric_set (circuit, IS_LEVEL_1, met);
+  return CMD_SUCCESS;
+}
+
+DEFUN (no_isis_metric_l1,
+       no_isis_metric_l1_cmd,
+       "no isis metric level-1",
+       NO_STR
+       "IS-IS commands\n"
+       "Set default metric for circuit\n"
+       "Specify metric for level-1 routing\n")
+{
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  isis_circuit_metric_set (circuit, IS_LEVEL_1, DEFAULT_CIRCUIT_METRIC);
+  return CMD_SUCCESS;
+}
+
+ALIAS (no_isis_metric_l1,
+       no_isis_metric_l1_arg_cmd,
+       "no isis metric <0-16777215> level-1",
+       NO_STR
+       "IS-IS commands\n"
+       "Set default metric for circuit\n"
+       "Default metric value\n"
+       "Specify metric for level-1 routing\n")
+
+DEFUN (isis_metric_l2,
+       isis_metric_l2_cmd,
+       "isis metric <0-16777215> level-2",
+       "IS-IS commands\n"
+       "Set default metric for circuit\n"
+       "Default metric value\n"
+       "Specify metric for level-2 routing\n")
+{
+  int met;
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  met = atoi (argv[0]);
+
+  /* RFC3787 section 5.1 */
+  if (circuit->area && circuit->area->oldmetric == 1 &&
+      met > MAX_NARROW_LINK_METRIC)
+    {
+      vty_out (vty, "Invalid metric %d - should be <0-63> "
+               "when narrow metric type enabled%s",
+               met, VTY_NEWLINE);
+      return CMD_ERR_AMBIGUOUS;
+    }
+
+  /* RFC4444 */
+  if (circuit->area && circuit->area->newmetric == 1 &&
+      met > MAX_WIDE_LINK_METRIC)
+    {
+      vty_out (vty, "Invalid metric %d - should be <0-16777215> "
+               "when wide metric type enabled%s",
+               met, VTY_NEWLINE);
+      return CMD_ERR_AMBIGUOUS;
+    }
+
+  isis_circuit_metric_set (circuit, IS_LEVEL_2, met);
+  return CMD_SUCCESS;
+}
+
+DEFUN (no_isis_metric_l2,
+       no_isis_metric_l2_cmd,
+       "no isis metric level-2",
+       NO_STR
+       "IS-IS commands\n"
+       "Set default metric for circuit\n"
+       "Specify metric for level-2 routing\n")
+{
+  struct isis_circuit *circuit = isis_circuit_lookup (vty);
+  if (!circuit)
+    return CMD_ERR_NO_MATCH;
+
+  isis_circuit_metric_set (circuit, IS_LEVEL_2, DEFAULT_CIRCUIT_METRIC);
+  return CMD_SUCCESS;
+}
+
+ALIAS (no_isis_metric_l2,
+       no_isis_metric_l2_arg_cmd,
+       "no isis metric <0-16777215> level-2",
+       NO_STR
+       "IS-IS commands\n"
+       "Set default metric for circuit\n"
+       "Default metric value\n"
+       "Specify metric for level-2 routing\n")
+/* end of metrics */
+
+void
+isis_vty_init (void)
+{
+  install_element (INTERFACE_NODE, &ip_router_isis_cmd);
+  install_element (INTERFACE_NODE, &no_ip_router_isis_cmd);
+
+  install_element (INTERFACE_NODE, &isis_passive_cmd);
+  install_element (INTERFACE_NODE, &no_isis_passive_cmd);
+
+  install_element (INTERFACE_NODE, &isis_circuit_type_cmd);
+  install_element (INTERFACE_NODE, &no_isis_circuit_type_cmd);
+
+  install_element (INTERFACE_NODE, &isis_network_cmd);
+  install_element (INTERFACE_NODE, &no_isis_network_cmd);
+
+  install_element (INTERFACE_NODE, &isis_priority_cmd);
+  install_element (INTERFACE_NODE, &no_isis_priority_cmd);
+  install_element (INTERFACE_NODE, &no_isis_priority_arg_cmd);
+  install_element (INTERFACE_NODE, &isis_priority_l1_cmd);
+  install_element (INTERFACE_NODE, &no_isis_priority_l1_cmd);
+  install_element (INTERFACE_NODE, &no_isis_priority_l1_arg_cmd);
+  install_element (INTERFACE_NODE, &isis_priority_l2_cmd);
+  install_element (INTERFACE_NODE, &no_isis_priority_l2_cmd);
+  install_element (INTERFACE_NODE, &no_isis_priority_l2_arg_cmd);
+
+  install_element (INTERFACE_NODE, &isis_metric_cmd);
+  install_element (INTERFACE_NODE, &no_isis_metric_cmd);
+  install_element (INTERFACE_NODE, &no_isis_metric_arg_cmd);
+  install_element (INTERFACE_NODE, &isis_metric_l1_cmd);
+  install_element (INTERFACE_NODE, &no_isis_metric_l1_cmd);
+  install_element (INTERFACE_NODE, &no_isis_metric_l1_arg_cmd);
+  install_element (INTERFACE_NODE, &isis_metric_l2_cmd);
+  install_element (INTERFACE_NODE, &no_isis_metric_l2_cmd);
+  install_element (INTERFACE_NODE, &no_isis_metric_l2_arg_cmd);
+}

+ 6 - 0
isisd/isisd.h

@@ -25,7 +25,11 @@
 
 #define ISISD_VERSION "0.0.7"
 
+#include "isisd/isis_constants.h"
+#include "isisd/isis_common.h"
 #include "isisd/isis_redist.h"
+#include "isis_flags.h"
+#include "dict.h"
 
 /* uncomment if you are a developer in bug hunt */
 /* #define EXTREME_DEBUG  */
@@ -137,6 +141,8 @@ struct isis_area *isis_area_lookup (const char *);
 int isis_area_get (struct vty *vty, const char *area_tag);
 void print_debug(struct vty *, int, int);
 
+void isis_vty_init (void);
+
 /* Master of threads. */
 extern struct thread_master *master;