/* Utility functions. */
int
-ospf_str2area_id (const char *str, struct in_addr *area_id, int *format)
+str2area_id (const char *str, struct in_addr *area_id, int *area_id_fmt)
{
- char *endptr = NULL;
- unsigned long ret;
+ char *ep;
- /* 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
- {
- if (*str == '-')
- return -1;
- errno = 0;
- ret = strtoul (str, &endptr, 10);
- if (*endptr != '\0' || errno || ret > UINT32_MAX)
- return -1;
+ area_id->s_addr = htonl (strtoul (str, &ep, 10));
+ if (*ep && !inet_aton (str, area_id))
+ return -1;
- area_id->s_addr = htonl (ret);
- *format = OSPF_AREA_ID_FORMAT_DECIMAL;
- }
+ *area_id_fmt = *ep ? OSPF_AREA_ID_FMT_DOTTEDQUAD : OSPF_AREA_ID_FMT_DECIMAL;
return 0;
}
+void
+area_id2str (char *buf, int length, struct in_addr *area_id, int area_id_fmt)
+{
+ memset (buf, 0, length);
+
+ if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
+ strncpy (buf, inet_ntoa (*area_id), length);
+ else
+ sprintf (buf, "%lu", (unsigned long) ntohl (area_id->s_addr));
+}
static int
str2metric (const char *str, int *metric)
VTY_GET_IPV4_PREFIX ("network prefix", p, argv[idx_ipv4_prefixlen]->arg);
VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
- ret = ospf_network_set (ospf, &p, area_id);
+ ret = ospf_network_set (ospf, &p, area_id, format);
if (ret == 0)
{
vty_out (vty, "There is already same network statement.%s", VTY_NEWLINE);
VTY_GET_IPV4_PREFIX ("area range", p, argv[idx_ipv4_prefixlen]->arg);
ospf_area_range_set (ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE);
+ ospf_area_display_format_set (ospf, ospf_area_get (ospf, area_id), format);
VTY_GET_INTEGER ("range cost", cost, argv[idx_cost]->arg);
ospf_area_range_cost_set (ospf, area_id, &p, cost);
VTY_GET_IPV4_PREFIX ("area range", p, argv[idx_ipv4_prefixlen]->arg);
ospf_area_range_set (ospf, area_id, &p, 0);
+ ospf_area_display_format_set (ospf, ospf_area_get (ospf, area_id), format);
return CMD_SUCCESS;
}
VTY_GET_IPV4_PREFIX ("substituted network prefix", s, argv[idx_ipv4_prefixlen_2]->arg);
ospf_area_range_substitute_set (ospf, area_id, &p, &s);
+ ospf_area_display_format_set (ospf, ospf_area_get (ospf, area_id), format);
return CMD_SUCCESS;
}
struct ospf_vl_config_data {
struct vty *vty; /* vty stuff */
struct in_addr area_id; /* area ID from command line */
- int format; /* command line area ID format */
+ int area_id_fmt; /* command line area ID format */
struct in_addr vl_peer; /* command line vl_peer */
int auth_type; /* Authehntication type, if given */
char *auth_key; /* simple password if present */
VTY_NEWLINE);
return NULL;
}
- area = ospf_area_get (ospf, area_id, vl_config->format);
+ area = ospf_area_get (ospf, area_id);
+ ospf_area_display_format_set (ospf, area, vl_config->area_id_fmt);
if (area->external_routing != OSPF_AREA_DEFAULT)
{
- if (vl_config->format == OSPF_AREA_ID_FORMAT_ADDRESS)
+ if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
vty_out (vty, "Area %s is %s%s",
inet_ntoa (area_id),
area->external_routing == OSPF_AREA_NSSA?"nssa":"stub",
ospf_vl_config_data_init(&vl_config, vty);
/* Read off first 2 parameters and check them */
- ret = ospf_str2area_id (argv[idx_ipv4_number]->arg, &vl_config.area_id, &vl_config.format);
+ ret = str2area_id (argv[idx_ipv4_number]->arg, &vl_config.area_id,
+ &vl_config.area_id_fmt);
if (ret < 0)
{
vty_out (vty, "OSPF area ID is invalid%s", VTY_NEWLINE);
char *area_id = argv[1]->arg;
char *router_id = argv[3]->arg;
- ret = ospf_str2area_id (area_id, &vl_config.area_id, &vl_config.format);
+ ret = str2area_id (area_id, &vl_config.area_id, &vl_config.area_id_fmt);
if (ret < 0)
{
vty_out (vty, "OSPF area ID is invalid%s", VTY_NEWLINE);
ospf_vl_config_data_init(&vl_config, vty);
- ret = ospf_str2area_id (argv[idx_ipv4_number]->arg, &vl_config.area_id, &format);
+ ret = str2area_id (argv[idx_ipv4_number]->arg, &vl_config.area_id, &format);
if (ret < 0)
{
vty_out (vty, "OSPF area ID is invalid%s", VTY_NEWLINE);
char *area_id = argv[2]->arg;
char *router_id = argv[4]->arg;
- ret = ospf_str2area_id (area_id, &vl_config.area_id, &vl_config.format);
+ ret = str2area_id (area_id, &vl_config.area_id, &vl_config.area_id_fmt);
if (ret < 0)
{
vty_out (vty, "OSPF area ID is invalid%s", VTY_NEWLINE);
VTY_GET_OSPF_AREA_ID_NO_BB ("shortcut", area_id, format, argv[idx_ipv4_number]->arg);
- area = ospf_area_get (ospf, area_id, format);
+ area = ospf_area_get (ospf, area_id);
+ ospf_area_display_format_set (ospf, area, format);
if (strncmp (argv[idx_enable_disable]->arg, "de", 2) == 0)
mode = OSPF_SHORTCUT_DEFAULT;
VTY_GET_OSPF_AREA_ID_NO_BB ("stub", area_id, format, argv[idx_ipv4_number]->arg);
ret = ospf_area_stub_set (ospf, area_id);
+ ospf_area_display_format_set (ospf, ospf_area_get (ospf, area_id), format);
if (ret == 0)
{
vty_out (vty, "First deconfigure all virtual link through this area%s",
VTY_GET_OSPF_AREA_ID_NO_BB ("stub", area_id, format, argv[idx_ipv4_number]->arg);
ret = ospf_area_stub_set (ospf, area_id);
+ ospf_area_display_format_set (ospf, ospf_area_get (ospf, area_id), format);
if (ret == 0)
{
vty_out (vty, "%% Area cannot be stub as it contains a virtual link%s",
VTY_GET_OSPF_AREA_ID_NO_BB ("NSSA", area_id, format, argv[1]->arg);
ret = ospf_area_nssa_set (ospf, area_id);
+ ospf_area_display_format_set (ospf, ospf_area_get (ospf, area_id), format);
if (ret == 0)
{
vty_out (vty, "%% Area cannot be nssa as it contains a virtual link%s",
VTY_GET_OSPF_AREA_ID_NO_BB ("default-cost", area_id, format, argv[idx_ipv4_number]->arg);
VTY_GET_INTEGER_RANGE ("stub default cost", cost, argv[idx_number]->arg, 0, 16777215);
- area = ospf_area_get (ospf, area_id, format);
+ area = ospf_area_get (ospf, area_id);
+ ospf_area_display_format_set (ospf, area, format);
if (area->external_routing == OSPF_AREA_DEFAULT)
{
VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
- area = ospf_area_get (ospf, area_id, format);
+ area = ospf_area_get (ospf, area_id);
+ ospf_area_display_format_set (ospf, area, format);
ospf_area_export_list_set (ospf, area, argv[3]->arg);
return CMD_SUCCESS;
VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
- area = ospf_area_get (ospf, area_id, format);
+ area = ospf_area_get (ospf, area_id);
+ ospf_area_display_format_set (ospf, area, format);
ospf_area_import_list_set (ospf, area, argv[3]->arg);
return CMD_SUCCESS;
VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
- area = ospf_area_get (ospf, area_id, format);
+ area = ospf_area_get (ospf, area_id);
+ ospf_area_display_format_set (ospf, area, format);
plist = prefix_list_lookup (AFI_IP, argv[idx_word]->arg);
if (strncmp (argv[idx_in_out]->arg, "in", 2) == 0)
{
VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
- area = ospf_area_get (ospf, area_id, format);
+ area = ospf_area_get (ospf, area_id);
+ ospf_area_display_format_set (ospf, area, format);
area->auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
return CMD_SUCCESS;
VTY_GET_OSPF_AREA_ID (area_id, format, argv[idx_ipv4_number]->arg);
- area = ospf_area_get (ospf, area_id, format);
+ area = ospf_area_get (ospf, area_id);
+ ospf_area_display_format_set (ospf, area, format);
area->auth_type = OSPF_AUTH_SIMPLE;
return CMD_SUCCESS;
return CMD_SUCCESS;
}
- ret = ospf_str2area_id (areaid, &area_id, &format);
+ ret = str2area_id (areaid, &area_id, &format);
if (ret < 0)
{
vty_out (vty, "Please specify area by A.B.C.D|<0-4294967295>%s",
"disable"
};
-
-static void
-area_id2str (char *buf, int length, struct ospf_area *area)
-{
- memset (buf, 0, length);
-
- if (area->format == OSPF_AREA_ID_FORMAT_ADDRESS)
- strncpy (buf, inet_ntoa (area->area_id), length);
- else
- sprintf (buf, "%lu", (unsigned long) ntohl (area->area_id.s_addr));
-}
-
-
const char *ospf_int_type_str[] =
{
"unknown", /* should never be used. */
memset (buf, 0, INET_ADDRSTRLEN);
/* Create Area ID string by specified Area ID format. */
- if (n->format == OSPF_AREA_ID_FORMAT_ADDRESS)
+ if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
strncpy ((char *) buf, inet_ntoa (n->area_id), INET_ADDRSTRLEN);
else
sprintf ((char *) buf, "%lu",
{
struct route_node *rn1;
- area_id2str ((char *) buf, INET_ADDRSTRLEN, area);
+ area_id2str ((char *) buf, INET_ADDRSTRLEN, &area->area_id,
+ area->area_id_fmt);
if (area->auth_type != OSPF_AUTH_NULL)
{
{
struct listnode *node;
struct ospf_vl_data *vl_data;
- u_char buf[INET_ADDRSTRLEN];
+ char buf[INET_ADDRSTRLEN];
/* Virtual-Link print */
for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
if (vl_data != NULL)
{
memset (buf, 0, INET_ADDRSTRLEN);
-
- if (vl_data->format == OSPF_AREA_ID_FORMAT_ADDRESS)
- strncpy ((char *) buf, inet_ntoa (vl_data->vl_area_id), INET_ADDRSTRLEN);
- else
- sprintf ((char *) buf, "%lu",
- (unsigned long int) ntohl (vl_data->vl_area_id.s_addr));
+
+ area_id2str (buf, sizeof(buf), &vl_data->vl_area_id, vl_data->vl_area_id_fmt);
oi = vl_data->vl_oi;
/* timers */
new->ospf = ospf;
new->area_id = area_id;
+ new->area_id_fmt = OSPF_AREA_ID_FMT_DOTTEDQUAD;
new->external_routing = OSPF_AREA_DEFAULT;
new->default_cost = 1;
}
struct ospf_area *
-ospf_area_get (struct ospf *ospf, struct in_addr area_id, int format)
+ospf_area_get (struct ospf *ospf, struct in_addr area_id)
{
struct ospf_area *area;
if (!area)
{
area = ospf_area_new (ospf, area_id);
- area->format = format;
listnode_add_sort (ospf->areas, area);
ospf_check_abr_status (ospf);
if (ospf->stub_router_admin_set == OSPF_STUB_ROUTER_ADMINISTRATIVE_SET)
/* Config network statement related functions. */
static struct ospf_network *
-ospf_network_new (struct in_addr area_id, int format)
+ospf_network_new (struct in_addr area_id)
{
struct ospf_network *new;
new = XCALLOC (MTYPE_OSPF_NETWORK, sizeof (struct ospf_network));
new->area_id = area_id;
- new->format = format;
+ new->area_id_fmt = OSPF_AREA_ID_FMT_DOTTEDQUAD;
return new;
}
int
ospf_network_set (struct ospf *ospf, struct prefix_ipv4 *p,
- struct in_addr area_id)
+ struct in_addr area_id, int df)
{
struct ospf_network *network;
struct ospf_area *area;
struct route_node *rn;
- int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
rn = route_node_get (ospf->networks, (struct prefix *)p);
if (rn->info)
return 0;
}
- rn->info = network = ospf_network_new (area_id, ret);
- area = ospf_area_get (ospf, area_id, ret);
+ rn->info = network = ospf_network_new (area_id);
+ network->area_id_fmt = df;
+ area = ospf_area_get (ospf, area_id);
+ ospf_area_display_format_set (ospf, area, df);
/* Run network config now. */
ospf_network_run ((struct prefix *)p, area);
struct ospf *ospf;
struct ospf_if_params *params;
struct ospf_interface *oi;
- int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
if ((ospf = ospf_lookup ()) == NULL)
return 1; /* Ospf not ready yet */
SET_IF_PARAM (params, if_area);
params->if_area = area_id;
- area = ospf_area_get (ospf, area_id, ret);
+ area = ospf_area_get (ospf, area_id);
for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, co))
{
if (rn->info != NULL)
{
network = (struct ospf_network *) rn->info;
- area = ospf_area_get (ospf, network->area_id, network->format);
+ area = ospf_area_get (ospf, network->area_id);
ospf_network_run_interface (&rn->p, area, ifp);
}
return count;
}
+int
+ospf_area_display_format_set (struct ospf *ospf, struct ospf_area *area, int df)
+{
+ area->area_id_fmt = df;
+
+ return 1;
+}
+
int
ospf_area_stub_set (struct ospf *ospf, struct in_addr area_id)
{
struct ospf_area *area;
- int format = OSPF_AREA_ID_FORMAT_ADDRESS;
- area = ospf_area_get (ospf, area_id, format);
+ area = ospf_area_get (ospf, area_id);
if (ospf_area_vlink_count (ospf, area))
return 0;
ospf_area_no_summary_set (struct ospf *ospf, struct in_addr area_id)
{
struct ospf_area *area;
- int format = OSPF_AREA_ID_FORMAT_ADDRESS;
- area = ospf_area_get (ospf, area_id, format);
+ area = ospf_area_get (ospf, area_id);
area->no_summary = 1;
return 1;
ospf_area_nssa_set (struct ospf *ospf, struct in_addr area_id)
{
struct ospf_area *area;
- int format = OSPF_AREA_ID_FORMAT_ADDRESS;
- area = ospf_area_get (ospf, area_id, format);
+ area = ospf_area_get (ospf, area_id);
if (ospf_area_vlink_count (ospf, area))
return 0;