1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607
|
/*
* Copyright (C) 2003 Yasuhiro Ohara
*
* 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 "if.h"
#include "log.h"
#include "command.h"
#include "thread.h"
#include "prefix.h"
#include "plist.h"
#include "ospf6_lsa.h"
#include "ospf6_lsdb.h"
#include "ospf6_network.h"
#include "ospf6_message.h"
#include "ospf6_route.h"
#include "ospf6_top.h"
#include "ospf6_area.h"
#include "ospf6_interface.h"
#include "ospf6_neighbor.h"
#include "ospf6_intra.h"
#include "ospf6_spf.h"
#include "ospf6d.h"
unsigned char conf_debug_ospf6_interface = 0;
const char *ospf6_interface_state_str[] =
{
"None",
"Down",
"Loopback",
"Waiting",
"PointToPoint",
"DROther",
"BDR",
"DR",
NULL
};
struct ospf6_interface *
ospf6_interface_lookup_by_ifindex (int ifindex)
{
struct ospf6_interface *oi;
struct interface *ifp;
ifp = if_lookup_by_index (ifindex);
if (ifp == NULL)
return (struct ospf6_interface *) NULL;
oi = (struct ospf6_interface *) ifp->info;
return oi;
}
/* schedule routing table recalculation */
void
ospf6_interface_lsdb_hook (struct ospf6_lsa *lsa)
{
switch (ntohs (lsa->header->type))
{
case OSPF6_LSTYPE_LINK:
if (OSPF6_INTERFACE (lsa->lsdb->data)->state == OSPF6_INTERFACE_DR)
OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (OSPF6_INTERFACE (lsa->lsdb->data));
ospf6_spf_schedule (OSPF6_INTERFACE (lsa->lsdb->data)->area);
break;
default:
break;
}
}
/* Create new ospf6 interface structure */
struct ospf6_interface *
ospf6_interface_create (struct interface *ifp)
{
struct ospf6_interface *oi;
unsigned int iobuflen;
oi = (struct ospf6_interface *)
XMALLOC (MTYPE_OSPF6_IF, sizeof (struct ospf6_interface));
if (oi)
memset (oi, 0, sizeof (struct ospf6_interface));
else
{
zlog_err ("Can't malloc ospf6_interface for ifindex %d", ifp->ifindex);
return (struct ospf6_interface *) NULL;
}
oi->area = (struct ospf6_area *) NULL;
oi->neighbor_list = list_new ();
oi->neighbor_list->cmp = ospf6_neighbor_cmp;
oi->linklocal_addr = (struct in6_addr *) NULL;
oi->instance_id = 0;
oi->transdelay = 1;
oi->priority = 1;
oi->hello_interval = 10;
oi->dead_interval = 40;
oi->rxmt_interval = 5;
oi->cost = 1;
oi->state = OSPF6_INTERFACE_DOWN;
oi->flag = 0;
/* Try to adjust I/O buffer size with IfMtu */
oi->ifmtu = ifp->mtu6;
iobuflen = ospf6_iobuf_size (ifp->mtu6);
if (oi->ifmtu > iobuflen)
{
if (IS_OSPF6_DEBUG_INTERFACE)
zlog_debug ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
ifp->name, iobuflen);
oi->ifmtu = iobuflen;
}
oi->lsupdate_list = ospf6_lsdb_create (oi);
oi->lsack_list = ospf6_lsdb_create (oi);
oi->lsdb = ospf6_lsdb_create (oi);
oi->lsdb->hook_add = ospf6_interface_lsdb_hook;
oi->lsdb->hook_remove = ospf6_interface_lsdb_hook;
oi->lsdb_self = ospf6_lsdb_create (oi);
oi->route_connected = OSPF6_ROUTE_TABLE_CREATE (INTERFACE, CONNECTED_ROUTES);
oi->route_connected->scope = oi;
/* link both */
oi->interface = ifp;
ifp->info = oi;
return oi;
}
void
ospf6_interface_delete (struct ospf6_interface *oi)
{
struct listnode *node, *nnode;
struct ospf6_neighbor *on;
for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
ospf6_neighbor_delete (on);
list_delete (oi->neighbor_list);
THREAD_OFF (oi->thread_send_hello);
THREAD_OFF (oi->thread_send_lsupdate);
THREAD_OFF (oi->thread_send_lsack);
ospf6_lsdb_remove_all (oi->lsdb);
ospf6_lsdb_remove_all (oi->lsupdate_list);
ospf6_lsdb_remove_all (oi->lsack_list);
ospf6_lsdb_delete (oi->lsdb);
ospf6_lsdb_delete (oi->lsdb_self);
ospf6_lsdb_delete (oi->lsupdate_list);
ospf6_lsdb_delete (oi->lsack_list);
ospf6_route_table_delete (oi->route_connected);
/* cut link */
oi->interface->info = NULL;
/* plist_name */
if (oi->plist_name)
XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
XFREE (MTYPE_OSPF6_IF, oi);
}
void
ospf6_interface_enable (struct ospf6_interface *oi)
{
UNSET_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE);
oi->thread_send_hello =
thread_add_event (master, ospf6_hello_send, oi, 0);
}
void
ospf6_interface_disable (struct ospf6_interface *oi)
{
struct listnode *node, *nnode;
struct ospf6_neighbor *on;
SET_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE);
for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
ospf6_neighbor_delete (on);
list_delete_all_node (oi->neighbor_list);
ospf6_lsdb_remove_all (oi->lsdb);
ospf6_lsdb_remove_all (oi->lsupdate_list);
ospf6_lsdb_remove_all (oi->lsack_list);
THREAD_OFF (oi->thread_send_hello);
THREAD_OFF (oi->thread_send_lsupdate);
THREAD_OFF (oi->thread_send_lsack);
}
static struct in6_addr *
ospf6_interface_get_linklocal_address (struct interface *ifp)
{
struct listnode *n;
struct connected *c;
struct in6_addr *l = (struct in6_addr *) NULL;
/* for each connected address */
for (ALL_LIST_ELEMENTS_RO (ifp->connected, n, c))
{
/* if family not AF_INET6, ignore */
if (c->address->family != AF_INET6)
continue;
/* linklocal scope check */
if (IN6_IS_ADDR_LINKLOCAL (&c->address->u.prefix6))
l = &c->address->u.prefix6;
}
return l;
}
void
ospf6_interface_if_add (struct interface *ifp)
{
struct ospf6_interface *oi;
unsigned int iobuflen;
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
return;
/* Try to adjust I/O buffer size with IfMtu */
if (oi->ifmtu == 0)
oi->ifmtu = ifp->mtu6;
iobuflen = ospf6_iobuf_size (ifp->mtu6);
if (oi->ifmtu > iobuflen)
{
if (IS_OSPF6_DEBUG_INTERFACE)
zlog_debug ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
ifp->name, iobuflen);
oi->ifmtu = iobuflen;
}
/* interface start */
if (oi->area)
thread_add_event (master, interface_up, oi, 0);
}
void
ospf6_interface_if_del (struct interface *ifp)
{
struct ospf6_interface *oi;
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
return;
/* interface stop */
if (oi->area)
thread_execute (master, interface_down, oi, 0);
listnode_delete (oi->area->if_list, oi);
oi->area = (struct ospf6_area *) NULL;
/* cut link */
oi->interface = NULL;
ifp->info = NULL;
ospf6_interface_delete (oi);
}
void
ospf6_interface_state_update (struct interface *ifp)
{
struct ospf6_interface *oi;
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
return;
if (oi->area == NULL)
return;
if (if_is_up (ifp))
thread_add_event (master, interface_up, oi, 0);
else
thread_add_event (master, interface_down, oi, 0);
return;
}
void
ospf6_interface_connected_route_update (struct interface *ifp)
{
struct ospf6_interface *oi;
struct ospf6_route *route;
struct connected *c;
struct listnode *node, *nnode;
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
return;
/* reset linklocal pointer */
oi->linklocal_addr = ospf6_interface_get_linklocal_address (ifp);
/* if area is null, do not make connected-route list */
if (oi->area == NULL)
return;
/* update "route to advertise" interface route table */
ospf6_route_remove_all (oi->route_connected);
for (ALL_LIST_ELEMENTS (oi->interface->connected, node, nnode, c))
{
if (c->address->family != AF_INET6)
continue;
CONTINUE_IF_ADDRESS_LINKLOCAL (IS_OSPF6_DEBUG_INTERFACE, c->address);
CONTINUE_IF_ADDRESS_UNSPECIFIED (IS_OSPF6_DEBUG_INTERFACE, c->address);
CONTINUE_IF_ADDRESS_LOOPBACK (IS_OSPF6_DEBUG_INTERFACE, c->address);
CONTINUE_IF_ADDRESS_V4COMPAT (IS_OSPF6_DEBUG_INTERFACE, c->address);
CONTINUE_IF_ADDRESS_V4MAPPED (IS_OSPF6_DEBUG_INTERFACE, c->address);
/* apply filter */
if (oi->plist_name)
{
struct prefix_list *plist;
enum prefix_list_type ret;
char buf[128];
prefix2str (c->address, buf, sizeof (buf));
plist = prefix_list_lookup (AFI_IP6, oi->plist_name);
ret = prefix_list_apply (plist, (void *) c->address);
if (ret == PREFIX_DENY)
{
if (IS_OSPF6_DEBUG_INTERFACE)
zlog_debug ("%s on %s filtered by prefix-list %s ",
buf, oi->interface->name, oi->plist_name);
continue;
}
}
route = ospf6_route_create ();
memcpy (&route->prefix, c->address, sizeof (struct prefix));
apply_mask (&route->prefix);
route->type = OSPF6_DEST_TYPE_NETWORK;
route->path.area_id = oi->area->area_id;
route->path.type = OSPF6_PATH_TYPE_INTRA;
route->path.cost = oi->cost;
route->nexthop[0].ifindex = oi->interface->ifindex;
inet_pton (AF_INET6, "::1", &route->nexthop[0].address);
ospf6_route_add (route, oi->route_connected);
}
/* create new Link-LSA */
OSPF6_LINK_LSA_SCHEDULE (oi);
OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
}
static void
ospf6_interface_state_change (u_char next_state, struct ospf6_interface *oi)
{
u_char prev_state;
prev_state = oi->state;
oi->state = next_state;
if (prev_state == next_state)
return;
/* log */
if (IS_OSPF6_DEBUG_INTERFACE)
{
zlog_debug ("Interface state change %s: %s -> %s", oi->interface->name,
ospf6_interface_state_str[prev_state],
ospf6_interface_state_str[next_state]);
}
if ((prev_state == OSPF6_INTERFACE_DR ||
prev_state == OSPF6_INTERFACE_BDR) &&
(next_state != OSPF6_INTERFACE_DR &&
next_state != OSPF6_INTERFACE_BDR))
ospf6_leave_alldrouters (oi->interface->ifindex);
if ((prev_state != OSPF6_INTERFACE_DR &&
prev_state != OSPF6_INTERFACE_BDR) &&
(next_state == OSPF6_INTERFACE_DR ||
next_state == OSPF6_INTERFACE_BDR))
ospf6_join_alldrouters (oi->interface->ifindex);
OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
if (next_state == OSPF6_INTERFACE_DOWN)
{
OSPF6_NETWORK_LSA_EXECUTE (oi);
OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT (oi);
OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
}
else if (prev_state == OSPF6_INTERFACE_DR ||
next_state == OSPF6_INTERFACE_DR)
{
OSPF6_NETWORK_LSA_SCHEDULE (oi);
OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
}
}
/* DR Election, RFC2328 section 9.4 */
#define IS_ELIGIBLE(n) \
((n)->state >= OSPF6_NEIGHBOR_TWOWAY && (n)->priority != 0)
static struct ospf6_neighbor *
better_bdrouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
{
if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id) &&
(b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id))
return NULL;
else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id)
return b;
else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id)
return a;
if (a->bdrouter == a->router_id && b->bdrouter != b->router_id)
return a;
if (a->bdrouter != a->router_id && b->bdrouter == b->router_id)
return b;
if (a->priority > b->priority)
return a;
if (a->priority < b->priority)
return b;
if (ntohl (a->router_id) > ntohl (b->router_id))
return a;
if (ntohl (a->router_id) < ntohl (b->router_id))
return b;
zlog_warn ("Router-ID duplicate ?");
return a;
}
static struct ospf6_neighbor *
better_drouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
{
if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id) &&
(b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id))
return NULL;
else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id)
return b;
else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id)
return a;
if (a->drouter == a->router_id && b->drouter != b->router_id)
return a;
if (a->drouter != a->router_id && b->drouter == b->router_id)
return b;
if (a->priority > b->priority)
return a;
if (a->priority < b->priority)
return b;
if (ntohl (a->router_id) > ntohl (b->router_id))
return a;
if (ntohl (a->router_id) < ntohl (b->router_id))
return b;
zlog_warn ("Router-ID duplicate ?");
return a;
}
static u_char
dr_election (struct ospf6_interface *oi)
{
struct listnode *node, *nnode;
struct ospf6_neighbor *on, *drouter, *bdrouter, myself;
struct ospf6_neighbor *best_drouter, *best_bdrouter;
u_char next_state = 0;
drouter = bdrouter = NULL;
best_drouter = best_bdrouter = NULL;
/* pseudo neighbor myself, including noting current DR/BDR (1) */
memset (&myself, 0, sizeof (myself));
inet_ntop (AF_INET, &oi->area->ospf6->router_id, myself.name,
sizeof (myself.name));
myself.state = OSPF6_NEIGHBOR_TWOWAY;
myself.drouter = oi->drouter;
myself.bdrouter = oi->bdrouter;
myself.priority = oi->priority;
myself.router_id = oi->area->ospf6->router_id;
/* Electing BDR (2) */
for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
bdrouter = better_bdrouter (bdrouter, on);
best_bdrouter = bdrouter;
bdrouter = better_bdrouter (best_bdrouter, &myself);
/* Electing DR (3) */
for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
drouter = better_drouter (drouter, on);
best_drouter = drouter;
drouter = better_drouter (best_drouter, &myself);
if (drouter == NULL)
drouter = bdrouter;
/* the router itself is newly/no longer DR/BDR (4) */
if ((drouter == &myself && myself.drouter != myself.router_id) ||
(drouter != &myself && myself.drouter == myself.router_id) ||
(bdrouter == &myself && myself.bdrouter != myself.router_id) ||
(bdrouter != &myself && myself.bdrouter == myself.router_id))
{
myself.drouter = (drouter ? drouter->router_id : htonl (0));
myself.bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
/* compatible to Electing BDR (2) */
bdrouter = better_bdrouter (best_bdrouter, &myself);
/* compatible to Electing DR (3) */
drouter = better_drouter (best_drouter, &myself);
if (drouter == NULL)
drouter = bdrouter;
}
/* Set interface state accordingly (5) */
if (drouter && drouter == &myself)
next_state = OSPF6_INTERFACE_DR;
else if (bdrouter && bdrouter == &myself)
next_state = OSPF6_INTERFACE_BDR;
else
next_state = OSPF6_INTERFACE_DROTHER;
/* If NBMA, schedule Start for each neighbor having priority of 0 (6) */
/* XXX */
/* If DR or BDR change, invoke AdjOK? for each neighbor (7) */
/* RFC 2328 section 12.4. Originating LSAs (3) will be handled
accordingly after AdjOK */
if (oi->drouter != (drouter ? drouter->router_id : htonl (0)) ||
oi->bdrouter != (bdrouter ? bdrouter->router_id : htonl (0)))
{
if (IS_OSPF6_DEBUG_INTERFACE)
zlog_debug ("DR Election on %s: DR: %s BDR: %s", oi->interface->name,
(drouter ? drouter->name : "0.0.0.0"),
(bdrouter ? bdrouter->name : "0.0.0.0"));
for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, node, on))
{
if (on->state < OSPF6_NEIGHBOR_TWOWAY)
continue;
/* Schedule AdjOK. */
thread_add_event (master, adj_ok, on, 0);
}
}
oi->drouter = (drouter ? drouter->router_id : htonl (0));
oi->bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
return next_state;
}
/* Interface State Machine */
int
interface_up (struct thread *thread)
{
struct ospf6_interface *oi;
oi = (struct ospf6_interface *) THREAD_ARG (thread);
assert (oi && oi->interface);
if (IS_OSPF6_DEBUG_INTERFACE)
zlog_debug ("Interface Event %s: [InterfaceUp]",
oi->interface->name);
/* check physical interface is up */
if (! if_is_up (oi->interface))
{
if (IS_OSPF6_DEBUG_INTERFACE)
zlog_debug ("Interface %s is down, can't execute [InterfaceUp]",
oi->interface->name);
return 0;
}
/* if already enabled, do nothing */
if (oi->state > OSPF6_INTERFACE_DOWN)
{
if (IS_OSPF6_DEBUG_INTERFACE)
zlog_debug ("Interface %s already enabled",
oi->interface->name);
return 0;
}
/* Join AllSPFRouters */
ospf6_join_allspfrouters (oi->interface->ifindex);
/* Update interface route */
ospf6_interface_connected_route_update (oi->interface);
/* Schedule Hello */
if (! CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
thread_add_event (master, ospf6_hello_send, oi, 0);
/* decide next interface state */
if (if_is_pointopoint (oi->interface))
ospf6_interface_state_change (OSPF6_INTERFACE_POINTTOPOINT, oi);
else if (oi->priority == 0)
ospf6_interface_state_change (OSPF6_INTERFACE_DROTHER, oi);
else
{
ospf6_interface_state_change (OSPF6_INTERFACE_WAITING, oi);
thread_add_timer (master, wait_timer, oi, oi->dead_interval);
}
return 0;
}
int
wait_timer (struct thread *thread)
{
struct ospf6_interface *oi;
oi = (struct ospf6_interface *) THREAD_ARG (thread);
assert (oi && oi->interface);
if (IS_OSPF6_DEBUG_INTERFACE)
zlog_debug ("Interface Event %s: [WaitTimer]",
oi->interface->name);
if (oi->state == OSPF6_INTERFACE_WAITING)
ospf6_interface_state_change (dr_election (oi), oi);
return 0;
}
int
backup_seen (struct thread *thread)
{
struct ospf6_interface *oi;
oi = (struct ospf6_interface *) THREAD_ARG (thread);
assert (oi && oi->interface);
if (IS_OSPF6_DEBUG_INTERFACE)
zlog_debug ("Interface Event %s: [BackupSeen]",
oi->interface->name);
if (oi->state == OSPF6_INTERFACE_WAITING)
ospf6_interface_state_change (dr_election (oi), oi);
return 0;
}
int
neighbor_change (struct thread *thread)
{
struct ospf6_interface *oi;
oi = (struct ospf6_interface *) THREAD_ARG (thread);
assert (oi && oi->interface);
if (IS_OSPF6_DEBUG_INTERFACE)
zlog_debug ("Interface Event %s: [NeighborChange]",
oi->interface->name);
if (oi->state == OSPF6_INTERFACE_DROTHER ||
oi->state == OSPF6_INTERFACE_BDR ||
oi->state == OSPF6_INTERFACE_DR)
ospf6_interface_state_change (dr_election (oi), oi);
return 0;
}
int
loopind (struct thread *thread)
{
struct ospf6_interface *oi;
oi = (struct ospf6_interface *) THREAD_ARG (thread);
assert (oi && oi->interface);
if (IS_OSPF6_DEBUG_INTERFACE)
zlog_debug ("Interface Event %s: [LoopInd]",
oi->interface->name);
/* XXX not yet */
return 0;
}
int
interface_down (struct thread *thread)
{
struct ospf6_interface *oi;
struct listnode *node, *nnode;
struct ospf6_neighbor *on;
oi = (struct ospf6_interface *) THREAD_ARG (thread);
assert (oi && oi->interface);
if (IS_OSPF6_DEBUG_INTERFACE)
zlog_debug ("Interface Event %s: [InterfaceDown]",
oi->interface->name);
/* Leave AllSPFRouters */
if (oi->state > OSPF6_INTERFACE_DOWN)
ospf6_leave_allspfrouters (oi->interface->ifindex);
ospf6_interface_state_change (OSPF6_INTERFACE_DOWN, oi);
for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
ospf6_neighbor_delete (on);
list_delete_all_node (oi->neighbor_list);
return 0;
}
/* show specified interface structure */
int
ospf6_interface_show (struct vty *vty, struct interface *ifp)
{
struct ospf6_interface *oi;
struct connected *c;
struct prefix *p;
struct listnode *i;
char strbuf[64], drouter[32], bdrouter[32];
const char *updown[3] = {"down", "up", NULL};
const char *type;
struct timeval res, now;
char duration[32];
struct ospf6_lsa *lsa;
/* check physical interface type */
if (if_is_loopback (ifp))
type = "LOOPBACK";
else if (if_is_broadcast (ifp))
type = "BROADCAST";
else if (if_is_pointopoint (ifp))
type = "POINTOPOINT";
else
type = "UNKNOWN";
vty_out (vty, "%s is %s, type %s%s",
ifp->name, updown[if_is_up (ifp)], type,
VNL);
vty_out (vty, " Interface ID: %d%s", ifp->ifindex, VNL);
if (ifp->info == NULL)
{
vty_out (vty, " OSPF not enabled on this interface%s", VNL);
return 0;
}
else
oi = (struct ospf6_interface *) ifp->info;
vty_out (vty, " Internet Address:%s", VNL);
for (ALL_LIST_ELEMENTS_RO (ifp->connected, i, c))
{
p = c->address;
prefix2str (p, strbuf, sizeof (strbuf));
switch (p->family)
{
case AF_INET:
vty_out (vty, " inet : %s%s", strbuf,
VNL);
break;
case AF_INET6:
vty_out (vty, " inet6: %s%s", strbuf,
VNL);
break;
default:
vty_out (vty, " ??? : %s%s", strbuf,
VNL);
break;
}
}
if (oi->area)
{
vty_out (vty, " Instance ID %d, Interface MTU %d (autodetect: %d)%s",
oi->instance_id, oi->ifmtu, ifp->mtu6, VNL);
inet_ntop (AF_INET, &oi->area->area_id,
strbuf, sizeof (strbuf));
vty_out (vty, " Area ID %s, Cost %hu%s", strbuf, oi->cost,
VNL);
}
else
vty_out (vty, " Not Attached to Area%s", VNL);
vty_out (vty, " State %s, Transmit Delay %d sec, Priority %d%s",
ospf6_interface_state_str[oi->state],
oi->transdelay, oi->priority,
VNL);
vty_out (vty, " Timer intervals configured:%s", VNL);
vty_out (vty, " Hello %d, Dead %d, Retransmit %d%s",
oi->hello_interval, oi->dead_interval, oi->rxmt_interval,
VNL);
inet_ntop (AF_INET, &oi->drouter, drouter, sizeof (drouter));
inet_ntop (AF_INET, &oi->bdrouter, bdrouter, sizeof (bdrouter));
vty_out (vty, " DR: %s BDR: %s%s", drouter, bdrouter, VNL);
vty_out (vty, " Number of I/F scoped LSAs is %u%s",
oi->lsdb->count, VNL);
gettimeofday (&now, (struct timezone *) NULL);
timerclear (&res);
if (oi->thread_send_lsupdate)
timersub (&oi->thread_send_lsupdate->u.sands, &now, &res);
timerstring (&res, duration, sizeof (duration));
vty_out (vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]%s",
oi->lsupdate_list->count, duration,
(oi->thread_send_lsupdate ? "on" : "off"),
VNL);
for (lsa = ospf6_lsdb_head (oi->lsupdate_list); lsa;
lsa = ospf6_lsdb_next (lsa))
vty_out (vty, " %s%s", lsa->name, VNL);
timerclear (&res);
if (oi->thread_send_lsack)
timersub (&oi->thread_send_lsack->u.sands, &now, &res);
timerstring (&res, duration, sizeof (duration));
vty_out (vty, " %d Pending LSAs for LSAck in Time %s [thread %s]%s",
oi->lsack_list->count, duration,
(oi->thread_send_lsack ? "on" : "off"),
VNL);
for (lsa = ospf6_lsdb_head (oi->lsack_list); lsa;
lsa = ospf6_lsdb_next (lsa))
vty_out (vty, " %s%s", lsa->name, VNL);
return 0;
}
/* show interface */
DEFUN (show_ipv6_ospf6_interface,
show_ipv6_ospf6_interface_ifname_cmd,
"show ipv6 ospf6 interface IFNAME",
SHOW_STR
IP6_STR
OSPF6_STR
INTERFACE_STR
IFNAME_STR
)
{
struct interface *ifp;
struct listnode *i;
if (argc)
{
ifp = if_lookup_by_name (argv[0]);
if (ifp == NULL)
{
vty_out (vty, "No such Interface: %s%s", argv[0],
VNL);
return CMD_WARNING;
}
ospf6_interface_show (vty, ifp);
}
else
{
for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
ospf6_interface_show (vty, ifp);
}
return CMD_SUCCESS;
}
ALIAS (show_ipv6_ospf6_interface,
show_ipv6_ospf6_interface_cmd,
"show ipv6 ospf6 interface",
SHOW_STR
IP6_STR
OSPF6_STR
INTERFACE_STR
);
DEFUN (show_ipv6_ospf6_interface_ifname_prefix,
show_ipv6_ospf6_interface_ifname_prefix_cmd,
"show ipv6 ospf6 interface IFNAME prefix",
SHOW_STR
IP6_STR
OSPF6_STR
INTERFACE_STR
IFNAME_STR
"Display connected prefixes to advertise\n"
)
{
struct interface *ifp;
struct ospf6_interface *oi;
ifp = if_lookup_by_name (argv[0]);
if (ifp == NULL)
{
vty_out (vty, "No such Interface: %s%s", argv[0], VNL);
return CMD_WARNING;
}
oi = ifp->info;
if (oi == NULL)
{
vty_out (vty, "OSPFv3 is not enabled on %s%s", argv[0], VNL);
return CMD_WARNING;
}
argc--;
argv++;
ospf6_route_table_show (vty, argc, argv, oi->route_connected);
return CMD_SUCCESS;
}
ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
show_ipv6_ospf6_interface_ifname_prefix_detail_cmd,
"show ipv6 ospf6 interface IFNAME prefix (X:X::X:X|X:X::X:X/M|detail)",
SHOW_STR
IP6_STR
OSPF6_STR
INTERFACE_STR
IFNAME_STR
"Display connected prefixes to advertise\n"
OSPF6_ROUTE_ADDRESS_STR
OSPF6_ROUTE_PREFIX_STR
"Dispaly details of the prefixes\n"
);
ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
show_ipv6_ospf6_interface_ifname_prefix_match_cmd,
"show ipv6 ospf6 interface IFNAME prefix X:X::X:X/M (match|detail)",
SHOW_STR
IP6_STR
OSPF6_STR
INTERFACE_STR
IFNAME_STR
"Display connected prefixes to advertise\n"
OSPF6_ROUTE_PREFIX_STR
OSPF6_ROUTE_MATCH_STR
"Dispaly details of the prefixes\n"
);
DEFUN (show_ipv6_ospf6_interface_prefix,
show_ipv6_ospf6_interface_prefix_cmd,
"show ipv6 ospf6 interface prefix",
SHOW_STR
IP6_STR
OSPF6_STR
INTERFACE_STR
"Display connected prefixes to advertise\n"
)
{
struct listnode *i;
struct ospf6_interface *oi;
struct interface *ifp;
for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
{
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
continue;
ospf6_route_table_show (vty, argc, argv, oi->route_connected);
}
return CMD_SUCCESS;
}
ALIAS (show_ipv6_ospf6_interface_prefix,
show_ipv6_ospf6_interface_prefix_detail_cmd,
"show ipv6 ospf6 interface prefix (X:X::X:X|X:X::X:X/M|detail)",
SHOW_STR
IP6_STR
OSPF6_STR
INTERFACE_STR
"Display connected prefixes to advertise\n"
OSPF6_ROUTE_ADDRESS_STR
OSPF6_ROUTE_PREFIX_STR
"Dispaly details of the prefixes\n"
);
ALIAS (show_ipv6_ospf6_interface_prefix,
show_ipv6_ospf6_interface_prefix_match_cmd,
"show ipv6 ospf6 interface prefix X:X::X:X/M (match|detail)",
SHOW_STR
IP6_STR
OSPF6_STR
INTERFACE_STR
"Display connected prefixes to advertise\n"
OSPF6_ROUTE_PREFIX_STR
OSPF6_ROUTE_MATCH_STR
"Dispaly details of the prefixes\n"
);
/* interface variable set command */
DEFUN (ipv6_ospf6_ifmtu,
ipv6_ospf6_ifmtu_cmd,
"ipv6 ospf6 ifmtu <1-65535>",
IP6_STR
OSPF6_STR
"Interface MTU\n"
"OSPFv3 Interface MTU\n"
)
{
struct ospf6_interface *oi;
struct interface *ifp;
unsigned int ifmtu, iobuflen;
struct listnode *node, *nnode;
struct ospf6_neighbor *on;
ifp = (struct interface *) vty->index;
assert (ifp);
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
oi = ospf6_interface_create (ifp);
assert (oi);
ifmtu = strtol (argv[0], NULL, 10);
if (oi->ifmtu == ifmtu)
return CMD_SUCCESS;
if (ifp->mtu6 != 0 && ifp->mtu6 < ifmtu)
{
vty_out (vty, "%s's ospf6 ifmtu cannot go beyond physical mtu (%d)%s",
ifp->name, ifp->mtu6, VNL);
return CMD_WARNING;
}
if (oi->ifmtu < ifmtu)
{
iobuflen = ospf6_iobuf_size (ifmtu);
if (iobuflen < ifmtu)
{
vty_out (vty, "%s's ifmtu is adjusted to I/O buffer size (%d).%s",
ifp->name, iobuflen, VNL);
oi->ifmtu = iobuflen;
}
else
oi->ifmtu = ifmtu;
}
else
oi->ifmtu = ifmtu;
/* re-establish adjacencies */
for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
{
THREAD_OFF (on->inactivity_timer);
thread_add_event (master, inactivity_timer, on, 0);
}
return CMD_SUCCESS;
}
DEFUN (no_ipv6_ospf6_ifmtu,
no_ipv6_ospf6_ifmtu_cmd,
"no ipv6 ospf6 ifmtu",
NO_STR
IP6_STR
OSPF6_STR
"Interface MTU\n"
)
{
struct ospf6_interface *oi;
struct interface *ifp;
unsigned int iobuflen;
struct listnode *node, *nnode;
struct ospf6_neighbor *on;
ifp = (struct interface *) vty->index;
assert (ifp);
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
oi = ospf6_interface_create (ifp);
assert (oi);
if (oi->ifmtu < ifp->mtu)
{
iobuflen = ospf6_iobuf_size (ifp->mtu);
if (iobuflen < ifp->mtu)
{
vty_out (vty, "%s's ifmtu is adjusted to I/O buffer size (%d).%s",
ifp->name, iobuflen, VNL);
oi->ifmtu = iobuflen;
}
else
oi->ifmtu = ifp->mtu;
}
else
oi->ifmtu = ifp->mtu;
/* re-establish adjacencies */
for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
{
THREAD_OFF (on->inactivity_timer);
thread_add_event (master, inactivity_timer, on, 0);
}
return CMD_SUCCESS;
}
DEFUN (ipv6_ospf6_cost,
ipv6_ospf6_cost_cmd,
"ipv6 ospf6 cost <1-65535>",
IP6_STR
OSPF6_STR
"Interface cost\n"
"Outgoing metric of this interface\n"
)
{
struct ospf6_interface *oi;
struct interface *ifp;
unsigned long int lcost;
ifp = (struct interface *) vty->index;
assert (ifp);
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
oi = ospf6_interface_create (ifp);
assert (oi);
lcost = strtol (argv[0], NULL, 10);
if (lcost > UINT32_MAX)
{
vty_out (vty, "Cost %ld is out of range%s", lcost, VNL);
return CMD_WARNING;
}
if (oi->cost == lcost)
return CMD_SUCCESS;
oi->cost = lcost;
/* update cost held in route_connected list in ospf6_interface */
ospf6_interface_connected_route_update (oi->interface);
/* execute LSA hooks */
if (oi->area)
{
OSPF6_LINK_LSA_SCHEDULE (oi);
OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
OSPF6_NETWORK_LSA_SCHEDULE (oi);
OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
}
return CMD_SUCCESS;
}
DEFUN (ipv6_ospf6_hellointerval,
ipv6_ospf6_hellointerval_cmd,
"ipv6 ospf6 hello-interval <1-65535>",
IP6_STR
OSPF6_STR
"Interval time of Hello packets\n"
SECONDS_STR
)
{
struct ospf6_interface *oi;
struct interface *ifp;
ifp = (struct interface *) vty->index;
assert (ifp);
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
oi = ospf6_interface_create (ifp);
assert (oi);
oi->hello_interval = strtol (argv[0], NULL, 10);
return CMD_SUCCESS;
}
/* interface variable set command */
DEFUN (ipv6_ospf6_deadinterval,
ipv6_ospf6_deadinterval_cmd,
"ipv6 ospf6 dead-interval <1-65535>",
IP6_STR
OSPF6_STR
"Interval time after which a neighbor is declared down\n"
SECONDS_STR
)
{
struct ospf6_interface *oi;
struct interface *ifp;
ifp = (struct interface *) vty->index;
assert (ifp);
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
oi = ospf6_interface_create (ifp);
assert (oi);
oi->dead_interval = strtol (argv[0], NULL, 10);
return CMD_SUCCESS;
}
/* interface variable set command */
DEFUN (ipv6_ospf6_transmitdelay,
ipv6_ospf6_transmitdelay_cmd,
"ipv6 ospf6 transmit-delay <1-3600>",
IP6_STR
OSPF6_STR
"Transmit delay of this interface\n"
SECONDS_STR
)
{
struct ospf6_interface *oi;
struct interface *ifp;
ifp = (struct interface *) vty->index;
assert (ifp);
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
oi = ospf6_interface_create (ifp);
assert (oi);
oi->transdelay = strtol (argv[0], NULL, 10);
return CMD_SUCCESS;
}
/* interface variable set command */
DEFUN (ipv6_ospf6_retransmitinterval,
ipv6_ospf6_retransmitinterval_cmd,
"ipv6 ospf6 retransmit-interval <1-65535>",
IP6_STR
OSPF6_STR
"Time between retransmitting lost link state advertisements\n"
SECONDS_STR
)
{
struct ospf6_interface *oi;
struct interface *ifp;
ifp = (struct interface *) vty->index;
assert (ifp);
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
oi = ospf6_interface_create (ifp);
assert (oi);
oi->rxmt_interval = strtol (argv[0], NULL, 10);
return CMD_SUCCESS;
}
/* interface variable set command */
DEFUN (ipv6_ospf6_priority,
ipv6_ospf6_priority_cmd,
"ipv6 ospf6 priority <0-255>",
IP6_STR
OSPF6_STR
"Router priority\n"
"Priority value\n"
)
{
struct ospf6_interface *oi;
struct interface *ifp;
ifp = (struct interface *) vty->index;
assert (ifp);
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
oi = ospf6_interface_create (ifp);
assert (oi);
oi->priority = strtol (argv[0], NULL, 10);
if (oi->area)
ospf6_interface_state_change (dr_election (oi), oi);
return CMD_SUCCESS;
}
DEFUN (ipv6_ospf6_instance,
ipv6_ospf6_instance_cmd,
"ipv6 ospf6 instance-id <0-255>",
IP6_STR
OSPF6_STR
"Instance ID for this interface\n"
"Instance ID value\n"
)
{
struct ospf6_interface *oi;
struct interface *ifp;
ifp = (struct interface *)vty->index;
assert (ifp);
oi = (struct ospf6_interface *)ifp->info;
if (oi == NULL)
oi = ospf6_interface_create (ifp);
assert (oi);
oi->instance_id = strtol (argv[0], NULL, 10);
return CMD_SUCCESS;
}
DEFUN (ipv6_ospf6_passive,
ipv6_ospf6_passive_cmd,
"ipv6 ospf6 passive",
IP6_STR
OSPF6_STR
"passive interface, No adjacency will be formed on this interface\n"
)
{
struct ospf6_interface *oi;
struct interface *ifp;
struct listnode *node, *nnode;
struct ospf6_neighbor *on;
ifp = (struct interface *) vty->index;
assert (ifp);
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
oi = ospf6_interface_create (ifp);
assert (oi);
SET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
THREAD_OFF (oi->thread_send_hello);
for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
{
THREAD_OFF (on->inactivity_timer);
thread_add_event (master, inactivity_timer, on, 0);
}
return CMD_SUCCESS;
}
DEFUN (no_ipv6_ospf6_passive,
no_ipv6_ospf6_passive_cmd,
"no ipv6 ospf6 passive",
NO_STR
IP6_STR
OSPF6_STR
"passive interface: No Adjacency will be formed on this I/F\n"
)
{
struct ospf6_interface *oi;
struct interface *ifp;
ifp = (struct interface *) vty->index;
assert (ifp);
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
oi = ospf6_interface_create (ifp);
assert (oi);
UNSET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
THREAD_OFF (oi->thread_send_hello);
oi->thread_send_hello =
thread_add_event (master, ospf6_hello_send, oi, 0);
return CMD_SUCCESS;
}
DEFUN (ipv6_ospf6_advertise_prefix_list,
ipv6_ospf6_advertise_prefix_list_cmd,
"ipv6 ospf6 advertise prefix-list WORD",
IP6_STR
OSPF6_STR
"Advertising options\n"
"Filter prefix using prefix-list\n"
"Prefix list name\n"
)
{
struct ospf6_interface *oi;
struct interface *ifp;
ifp = (struct interface *) vty->index;
assert (ifp);
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
oi = ospf6_interface_create (ifp);
assert (oi);
if (oi->plist_name)
XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
oi->plist_name = XSTRDUP (MTYPE_PREFIX_LIST_STR, argv[0]);
ospf6_interface_connected_route_update (oi->interface);
OSPF6_LINK_LSA_SCHEDULE (oi);
if (oi->state == OSPF6_INTERFACE_DR)
{
OSPF6_NETWORK_LSA_SCHEDULE (oi);
OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
}
OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
return CMD_SUCCESS;
}
DEFUN (no_ipv6_ospf6_advertise_prefix_list,
no_ipv6_ospf6_advertise_prefix_list_cmd,
"no ipv6 ospf6 advertise prefix-list",
NO_STR
IP6_STR
OSPF6_STR
"Advertising options\n"
"Filter prefix using prefix-list\n"
)
{
struct ospf6_interface *oi;
struct interface *ifp;
ifp = (struct interface *) vty->index;
assert (ifp);
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
oi = ospf6_interface_create (ifp);
assert (oi);
if (oi->plist_name)
{
XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
oi->plist_name = NULL;
}
ospf6_interface_connected_route_update (oi->interface);
OSPF6_LINK_LSA_SCHEDULE (oi);
if (oi->state == OSPF6_INTERFACE_DR)
{
OSPF6_NETWORK_LSA_SCHEDULE (oi);
OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
}
OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
return CMD_SUCCESS;
}
int
config_write_ospf6_interface (struct vty *vty)
{
struct listnode *i;
struct ospf6_interface *oi;
struct interface *ifp;
for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
{
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
continue;
vty_out (vty, "interface %s%s",
oi->interface->name, VNL);
if (ifp->desc)
vty_out (vty, " description %s%s", ifp->desc, VNL);
if (ifp->mtu6 != oi->ifmtu)
vty_out (vty, " ipv6 ospf6 ifmtu %d%s", oi->ifmtu, VNL);
vty_out (vty, " ipv6 ospf6 cost %d%s",
oi->cost, VNL);
vty_out (vty, " ipv6 ospf6 hello-interval %d%s",
oi->hello_interval, VNL);
vty_out (vty, " ipv6 ospf6 dead-interval %d%s",
oi->dead_interval, VNL);
vty_out (vty, " ipv6 ospf6 retransmit-interval %d%s",
oi->rxmt_interval, VNL);
vty_out (vty, " ipv6 ospf6 priority %d%s",
oi->priority, VNL);
vty_out (vty, " ipv6 ospf6 transmit-delay %d%s",
oi->transdelay, VNL);
vty_out (vty, " ipv6 ospf6 instance-id %d%s",
oi->instance_id, VNL);
if (oi->plist_name)
vty_out (vty, " ipv6 ospf6 advertise prefix-list %s%s",
oi->plist_name, VNL);
if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
vty_out (vty, " ipv6 ospf6 passive%s", VNL);
vty_out (vty, "!%s", VNL);
}
return 0;
}
struct cmd_node interface_node =
{
INTERFACE_NODE,
"%s(config-if)# ",
1 /* VTYSH */
};
void
ospf6_interface_init ()
{
/* Install interface node. */
install_node (&interface_node, config_write_ospf6_interface);
install_element (VIEW_NODE, &show_ipv6_ospf6_interface_cmd);
install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_cmd);
install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
install_element (CONFIG_NODE, &interface_cmd);
install_default (INTERFACE_NODE);
install_element (INTERFACE_NODE, &interface_desc_cmd);
install_element (INTERFACE_NODE, &no_interface_desc_cmd);
install_element (INTERFACE_NODE, &ipv6_ospf6_cost_cmd);
install_element (INTERFACE_NODE, &ipv6_ospf6_ifmtu_cmd);
install_element (INTERFACE_NODE, &no_ipv6_ospf6_ifmtu_cmd);
install_element (INTERFACE_NODE, &ipv6_ospf6_deadinterval_cmd);
install_element (INTERFACE_NODE, &ipv6_ospf6_hellointerval_cmd);
install_element (INTERFACE_NODE, &ipv6_ospf6_priority_cmd);
install_element (INTERFACE_NODE, &ipv6_ospf6_retransmitinterval_cmd);
install_element (INTERFACE_NODE, &ipv6_ospf6_transmitdelay_cmd);
install_element (INTERFACE_NODE, &ipv6_ospf6_instance_cmd);
install_element (INTERFACE_NODE, &ipv6_ospf6_passive_cmd);
install_element (INTERFACE_NODE, &no_ipv6_ospf6_passive_cmd);
install_element (INTERFACE_NODE, &ipv6_ospf6_advertise_prefix_list_cmd);
install_element (INTERFACE_NODE, &no_ipv6_ospf6_advertise_prefix_list_cmd);
}
DEFUN (debug_ospf6_interface,
debug_ospf6_interface_cmd,
"debug ospf6 interface",
DEBUG_STR
OSPF6_STR
"Debug OSPFv3 Interface\n"
)
{
OSPF6_DEBUG_INTERFACE_ON ();
return CMD_SUCCESS;
}
DEFUN (no_debug_ospf6_interface,
no_debug_ospf6_interface_cmd,
"no debug ospf6 interface",
NO_STR
DEBUG_STR
OSPF6_STR
"Debug OSPFv3 Interface\n"
)
{
OSPF6_DEBUG_INTERFACE_OFF ();
return CMD_SUCCESS;
}
int
config_write_ospf6_debug_interface (struct vty *vty)
{
if (IS_OSPF6_DEBUG_INTERFACE)
vty_out (vty, "debug ospf6 interface%s", VNL);
return 0;
}
void
install_element_ospf6_debug_interface ()
{
install_element (ENABLE_NODE, &debug_ospf6_interface_cmd);
install_element (ENABLE_NODE, &no_debug_ospf6_interface_cmd);
install_element (CONFIG_NODE, &debug_ospf6_interface_cmd);
install_element (CONFIG_NODE, &no_debug_ospf6_interface_cmd);
}
|