📄 ospf_vty.c
字号:
/* OSPF VTY interface. * Copyright (C) 2000 Toshiaki Takada * * This file is part of GNU Zebra. * * GNU Zebra is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * * GNU Zebra 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 GNU Zebra; see the file COPYING. If not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */#include <zebra.h>#include "memory.h"#include "thread.h"#include "prefix.h"#include "table.h"#include "vty.h"#include "command.h"#include "plist.h"#include "log.h"#include "zclient.h"#include "ospfd/ospfd.h"#include "ospfd/ospf_asbr.h"#include "ospfd/ospf_lsa.h"#include "ospfd/ospf_lsdb.h"#include "ospfd/ospf_ism.h"#include "ospfd/ospf_interface.h"#include "ospfd/ospf_nsm.h"#include "ospfd/ospf_neighbor.h"#include "ospfd/ospf_flood.h"#include "ospfd/ospf_abr.h"#include "ospfd/ospf_spf.h"#include "ospfd/ospf_route.h"#include "ospfd/ospf_zebra.h"/*#include "ospfd/ospf_routemap.h" */#include "ospfd/ospf_vty.h"#include "ospfd/ospf_dump.h"static char *ospf_network_type_str[] = { "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT", "VIRTUALLINK", "LOOPBACK" };/* Utility functions. */intospf_str2area_id (char *str, struct in_addr *area_id, int *format){ char *endptr = NULL; unsigned long ret; /* match "A.B.C.D". */ if (strchr (str, '.') != NULL) { ret = inet_aton (str, area_id); if (!ret) return -1; *format = OSPF_AREA_ID_FORMAT_ADDRESS; } /* match "<0-4294967295>". */ else { ret = strtoul (str, &endptr, 10); if (*endptr != '\0' || (ret == ULONG_MAX && errno == ERANGE)) return -1; area_id->s_addr = htonl (ret); *format = OSPF_AREA_ID_FORMAT_DECIMAL; } return 0;}intstr2distribute_source (char *str, int *source){ /* Sanity check. */ if (str == NULL) return 0; if (strncmp (str, "k", 1) == 0) *source = ZEBRA_ROUTE_KERNEL; else if (strncmp (str, "c", 1) == 0) *source = ZEBRA_ROUTE_CONNECT; else if (strncmp (str, "s", 1) == 0) *source = ZEBRA_ROUTE_STATIC; else if (strncmp (str, "r", 1) == 0) *source = ZEBRA_ROUTE_RIP; else if (strncmp (str, "b", 1) == 0) *source = ZEBRA_ROUTE_BGP; else return 0; return 1;}intstr2metric (char *str, int *metric){ /* Sanity check. */ if (str == NULL) return 0; *metric = strtol (str, NULL, 10); if (*metric < 0 && *metric > 16777214) { /* vty_out (vty, "OSPF metric value is invalid%s", VTY_NEWLINE); */ return 0; } return 1;}intstr2metric_type (char *str, int *metric_type){ /* Sanity check. */ if (str == NULL) return 0; if (strncmp (str, "1", 1) == 0) *metric_type = EXTERNAL_METRIC_TYPE_1; else if (strncmp (str, "2", 1) == 0) *metric_type = EXTERNAL_METRIC_TYPE_2; else return 0; return 1;}intospf_oi_count (struct interface *ifp){ struct route_node *rn; int i = 0; for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn)) if (rn->info) i++; return i;}DEFUN (router_ospf, router_ospf_cmd, "router ospf", "Enable a routing process\n" "Start OSPF configuration\n"){ vty->node = OSPF_NODE; vty->index = ospf_get (); return CMD_SUCCESS;}DEFUN (no_router_ospf, no_router_ospf_cmd, "no router ospf", NO_STR "Enable a routing process\n" "Start OSPF configuration\n"){ struct ospf *ospf; ospf = ospf_lookup (); if (ospf == NULL) { vty_out (vty, "There isn't active ospf instance%s", VTY_NEWLINE); return CMD_WARNING; } ospf_finish (ospf); return CMD_SUCCESS;}DEFUN (ospf_router_id, ospf_router_id_cmd, "ospf router-id A.B.C.D", "OSPF specific commands\n" "router-id for the OSPF process\n" "OSPF router-id in IP address format\n"){ struct ospf *ospf = vty->index; struct in_addr router_id; int ret; ret = inet_aton (argv[0], &router_id); if (!ret) { vty_out (vty, "Please specify Router ID by A.B.C.D%s", VTY_NEWLINE); return CMD_WARNING; } ospf->router_id_static = router_id; if (ospf->t_router_id_update == NULL) OSPF_TIMER_ON (ospf->t_router_id_update, ospf_router_id_update_timer, OSPF_ROUTER_ID_UPDATE_DELAY); return CMD_SUCCESS;}ALIAS (ospf_router_id, router_ospf_id_cmd, "router-id A.B.C.D", "router-id for the OSPF process\n" "OSPF router-id in IP address format\n");DEFUN (no_ospf_router_id, no_ospf_router_id_cmd, "no ospf router-id", NO_STR "OSPF specific commands\n" "router-id for the OSPF process\n"){ struct ospf *ospf = vty->index; ospf->router_id_static.s_addr = 0; ospf_router_id_update (ospf); return CMD_SUCCESS;}ALIAS (no_ospf_router_id, no_router_ospf_id_cmd, "no router-id", NO_STR "router-id for the OSPF process\n");DEFUN (ospf_passive_interface, ospf_passive_interface_addr_cmd, "passive-interface IFNAME A.B.C.D", "Suppress routing updates on an interface\n" "Interface's name\n"){ struct interface *ifp; struct in_addr addr; int ret; struct ospf_if_params *params; ifp = if_lookup_by_name (argv[0]); if (ifp == NULL) { vty_out (vty, "Please specify an existing interface%s", VTY_NEWLINE); return CMD_WARNING; } params = IF_DEF_PARAMS (ifp); if (argc == 2) { ret = inet_aton(argv[1], &addr); if (!ret) { vty_out (vty, "Please specify interface address by A.B.C.D%s", VTY_NEWLINE); return CMD_WARNING; } params = ospf_get_if_params (ifp, addr); ospf_if_update_params (ifp, addr); } SET_IF_PARAM (params, passive_interface); params->passive_interface = OSPF_IF_PASSIVE; return CMD_SUCCESS;}ALIAS (ospf_passive_interface, ospf_passive_interface_cmd, "passive-interface IFNAME", "Suppress routing updates on an interface\n" "Interface's name\n");DEFUN (no_ospf_passive_interface, no_ospf_passive_interface_addr_cmd, "no passive-interface IFNAME A.B.C.D", NO_STR "Allow routing updates on an interface\n" "Interface's name\n"){ struct interface *ifp; struct in_addr addr; struct ospf_if_params *params; int ret; ifp = if_lookup_by_name (argv[0]); if (ifp == NULL) { vty_out (vty, "Please specify an existing interface%s", VTY_NEWLINE); return CMD_WARNING; } params = IF_DEF_PARAMS (ifp); if (argc == 2) { ret = inet_aton(argv[1], &addr); if (!ret) { vty_out (vty, "Please specify interface address by A.B.C.D%s", VTY_NEWLINE); return CMD_WARNING; } params = ospf_lookup_if_params (ifp, addr); if (params == NULL) return CMD_SUCCESS; } UNSET_IF_PARAM (params, passive_interface); params->passive_interface = OSPF_IF_ACTIVE; if (params != IF_DEF_PARAMS (ifp)) { ospf_free_if_params (ifp, addr); ospf_if_update_params (ifp, addr); } return CMD_SUCCESS;}ALIAS (no_ospf_passive_interface, no_ospf_passive_interface_cmd, "no passive-interface IFNAME", NO_STR "Allow routing updates on an interface\n" "Interface's name\n");DEFUN (ospf_network_area, ospf_network_area_cmd, "network A.B.C.D/M area (A.B.C.D|<0-4294967295>)", "Enable routing on an IP network\n" "OSPF network prefix\n" "Set the OSPF area ID\n" "OSPF area ID in IP address format\n" "OSPF area ID as a decimal value\n"){ struct ospf *ospf= vty->index; struct prefix_ipv4 p; struct in_addr area_id; int ret, format; /* Get network prefix and Area ID. */ VTY_GET_IPV4_PREFIX ("network prefix", p, argv[0]); VTY_GET_OSPF_AREA_ID (area_id, format, argv[1]); ret = ospf_network_set (ospf, &p, area_id); if (ret == 0) { vty_out (vty, "There is already same network statement.%s", VTY_NEWLINE); return CMD_WARNING; } return CMD_SUCCESS;}DEFUN (no_ospf_network_area, no_ospf_network_area_cmd, "no network A.B.C.D/M area (A.B.C.D|<0-4294967295>)", NO_STR "Enable routing on an IP network\n" "OSPF network prefix\n" "Set the OSPF area ID\n" "OSPF area ID in IP address format\n" "OSPF area ID as a decimal value\n"){ struct ospf *ospf = (struct ospf *) vty->index; struct prefix_ipv4 p; struct in_addr area_id; int ret, format; /* Get network prefix and Area ID. */ VTY_GET_IPV4_PREFIX ("network prefix", p, argv[0]); VTY_GET_OSPF_AREA_ID (area_id, format, argv[1]); ret = ospf_network_unset (ospf, &p, area_id); if (ret == 0) { vty_out (vty, "Can't find specified network area configuration.%s", VTY_NEWLINE); return CMD_WARNING; } return CMD_SUCCESS;}DEFUN (ospf_area_range, ospf_area_range_cmd, "area (A.B.C.D|<0-4294967295>) range A.B.C.D/M", "OSPF area parameters\n" "OSPF area ID in IP address format\n" "OSPF area ID as a decimal value\n" "Summarize routes matching address/mask (border routers only)\n" "Area range prefix\n"){ struct ospf *ospf = vty->index; struct prefix_ipv4 p; struct in_addr area_id; int format; u_int32_t cost; VTY_GET_OSPF_AREA_ID (area_id, format, argv[0]); VTY_GET_IPV4_PREFIX ("area range", p, argv[1]); ospf_area_range_set (ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); if (argc > 2) { VTY_GET_UINT32 ("range cost", cost, argv[2]); ospf_area_range_cost_set (ospf, area_id, &p, cost); } return CMD_SUCCESS;}ALIAS (ospf_area_range, ospf_area_range_advertise_cmd, "area (A.B.C.D|<0-4294967295>) range A.B.C.D/M advertise", "OSPF area parameters\n" "OSPF area ID in IP address format\n" "OSPF area ID as a decimal value\n" "OSPF area range for route advertise (default)\n" "Area range prefix\n" "Advertise this range (default)\n");ALIAS (ospf_area_range, ospf_area_range_cost_cmd, "area (A.B.C.D|<0-4294967295>) range A.B.C.D/M cost <0-16777215>", "OSPF area parameters\n" "OSPF area ID in IP address format\n" "OSPF area ID as a decimal value\n" "Summarize routes matching address/mask (border routers only)\n" "Area range prefix\n" "User specified metric for this range\n" "Advertised metric for this range\n");ALIAS (ospf_area_range, ospf_area_range_advertise_cost_cmd, "area (A.B.C.D|<0-4294967295>) range A.B.C.D/M advertise cost <0-16777215>", "OSPF area parameters\n" "OSPF area ID in IP address format\n" "OSPF area ID as a decimal value\n" "Summarize routes matching address/mask (border routers only)\n" "Area range prefix\n" "Advertise this range (default)\n" "User specified metric for this range\n" "Advertised metric for this range\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -