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 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* SHARP - vty code
* Copyright (C) Cumulus Networks, Inc.
* Donald Sharp
*/
#include <zebra.h>
#include "vty.h"
#include "command.h"
#include "prefix.h"
#include "nexthop.h"
#include "log.h"
#include "vrf.h"
#include "zclient.h"
#include "nexthop_group.h"
#include "linklist.h"
#include "link_state.h"
#include "cspf.h"
#include "tc.h"
#include "sharpd/sharp_globals.h"
#include "sharpd/sharp_zebra.h"
#include "sharpd/sharp_nht.h"
#include "sharpd/sharp_vty.h"
#include "sharpd/sharp_vty_clippy.c"
DEFINE_MTYPE_STATIC(SHARPD, SRV6_LOCATOR, "SRv6 Locator");
DEFPY(watch_neighbor, watch_neighbor_cmd,
"sharp watch [vrf NAME$vrf_name] neighbor",
"Sharp routing Protocol\n"
"Watch for changes\n"
"The vrf we would like to watch if non-default\n"
"The NAME of the vrf\n"
"Neighbor events\n")
{
struct vrf *vrf;
if (!vrf_name)
vrf_name = VRF_DEFAULT_NAME;
vrf = vrf_lookup_by_name(vrf_name);
if (!vrf) {
vty_out(vty, "The vrf NAME specified: %s does not exist\n",
vrf_name);
return CMD_WARNING;
}
sharp_zebra_register_neigh(vrf->vrf_id, AFI_IP, true);
return CMD_SUCCESS;
}
DEFPY(watch_redistribute, watch_redistribute_cmd,
"[no] sharp watch [vrf NAME$vrf_name] redistribute " FRR_REDIST_STR_SHARPD,
NO_STR
"Sharp routing Protocol\n"
"Watch for changes\n"
"The vrf we would like to watch if non-default\n"
"The NAME of the vrf\n"
"Redistribute into Sharp\n"
FRR_REDIST_HELP_STR_SHARPD)
{
struct vrf *vrf;
uint8_t source;
if (!vrf_name)
vrf_name = VRF_DEFAULT_NAME;
vrf = vrf_lookup_by_name(vrf_name);
if (!vrf) {
vty_out(vty, "The vrf NAME specified: %s does not exist\n",
vrf_name);
return CMD_WARNING;
}
source = proto_redistnum(AFI_IP, argv[argc-1]->text);
sharp_redistribute_vrf(vrf, source, !no);
return CMD_SUCCESS;
}
DEFPY(watch_nexthop_v6, watch_nexthop_v6_cmd,
"sharp watch [vrf NAME$vrf_name] <nexthop$n X:X::X:X$nhop|import$import X:X::X:X/M$inhop> [connected$connected] [mrib$mrib]",
"Sharp routing Protocol\n"
"Watch for changes\n"
"The vrf we would like to watch if non-default\n"
"The NAME of the vrf\n"
"Watch for nexthop changes\n"
"The v6 nexthop to signal for watching\n"
"Watch for import check changes\n"
"The v6 prefix to signal for watching\n"
"Should the route be connected\n"
"In the Multicast rib\n")
{
struct vrf *vrf;
struct prefix p;
bool type_import;
if (!vrf_name)
vrf_name = VRF_DEFAULT_NAME;
vrf = vrf_lookup_by_name(vrf_name);
if (!vrf) {
vty_out(vty, "The vrf NAME specified: %s does not exist\n",
vrf_name);
return CMD_WARNING;
}
memset(&p, 0, sizeof(p));
if (n) {
type_import = false;
p.prefixlen = IPV6_MAX_BITLEN;
memcpy(&p.u.prefix6, &nhop, IPV6_MAX_BYTELEN);
p.family = AF_INET6;
} else {
type_import = true;
prefix_copy(&p, inhop);
}
sharp_nh_tracker_get(&p);
sharp_zebra_nexthop_watch(&p, vrf->vrf_id, type_import, true, !!connected, !!mrib);
return CMD_SUCCESS;
}
DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd,
"sharp watch [vrf NAME$vrf_name] <nexthop$n A.B.C.D$nhop|import$import A.B.C.D/M$inhop> [connected$connected] [mrib$mrib]",
"Sharp routing Protocol\n"
"Watch for changes\n"
"The vrf we would like to watch if non-default\n"
"The NAME of the vrf\n"
"Watch for nexthop changes\n"
"The v4 address to signal for watching\n"
"Watch for import check changes\n"
"The v4 prefix for import check to watch\n"
"Should the route be connected\n"
"In the Multicast rib\n")
{
struct vrf *vrf;
struct prefix p;
bool type_import;
if (!vrf_name)
vrf_name = VRF_DEFAULT_NAME;
vrf = vrf_lookup_by_name(vrf_name);
if (!vrf) {
vty_out(vty, "The vrf NAME specified: %s does not exist\n",
vrf_name);
return CMD_WARNING;
}
memset(&p, 0, sizeof(p));
if (n) {
type_import = false;
p.prefixlen = IPV4_MAX_BITLEN;
p.u.prefix4 = nhop;
p.family = AF_INET;
}
else {
type_import = true;
prefix_copy(&p, inhop);
}
sharp_nh_tracker_get(&p);
sharp_zebra_nexthop_watch(&p, vrf->vrf_id, type_import, true, !!connected, !!mrib);
return CMD_SUCCESS;
}
DEFPY(sharp_nht_data_dump,
sharp_nht_data_dump_cmd,
"sharp data nexthop",
"Sharp routing Protocol\n"
"Data about what is going on\n"
"Nexthop information\n")
{
sharp_nh_tracker_dump(vty);
return CMD_SUCCESS;
}
DEFPY (install_routes_data_dump,
install_routes_data_dump_cmd,
"sharp data route",
"Sharp routing Protocol\n"
"Data about what is going on\n"
"Route Install/Removal Information\n")
{
struct timeval r;
timersub(&sg.r.t_end, &sg.r.t_start, &r);
vty_out(vty, "Prefix: %pFX Total: %u %u %u Time: %jd.%ld\n",
&sg.r.orig_prefix, sg.r.total_routes, sg.r.installed_routes,
sg.r.removed_routes, (intmax_t)r.tv_sec, (long)r.tv_usec);
return CMD_SUCCESS;
}
DEFPY (install_routes,
install_routes_cmd,
"sharp install routes [vrf NAME$vrf_name]\
<A.B.C.D$start4|X:X::X:X$start6>\
<nexthop <A.B.C.D$nexthop4|X:X::X:X$nexthop6>|\
nexthop-group NHGNAME$nexthop_group>\
[backup$backup <A.B.C.D$backup_nexthop4|X:X::X:X$backup_nexthop6>] \
(1-1000000)$routes [instance (0-255)$instance] [repeat (2-1000)$rpt] [opaque WORD] [no-recurse$norecurse]",
"Sharp routing Protocol\n"
"install some routes\n"
"Routes to install\n"
"The vrf we would like to install into if non-default\n"
"The NAME of the vrf\n"
"v4 Address to start /32 generation at\n"
"v6 Address to start /128 generation at\n"
"Nexthop to use(Can be an IPv4 or IPv6 address)\n"
"V4 Nexthop address to use\n"
"V6 Nexthop address to use\n"
"Nexthop-Group to use\n"
"The Name of the nexthop-group\n"
"Backup nexthop to use(Can be an IPv4 or IPv6 address)\n"
"Backup V4 Nexthop address to use\n"
"Backup V6 Nexthop address to use\n"
"How many to create\n"
"Instance to use\n"
"Instance\n"
"Should we repeat this command\n"
"How many times to repeat this command\n"
"What opaque data to send down\n"
"The opaque data\n"
"No recursive nexthops\n")
{
struct vrf *vrf;
struct prefix prefix;
uint32_t rts;
uint32_t nhgid = 0;
sg.r.total_routes = routes;
sg.r.installed_routes = 0;
sg.r.flags = 0;
if (rpt >= 2)
sg.r.repeat = rpt * 2;
else
sg.r.repeat = 0;
memset(&prefix, 0, sizeof(prefix));
memset(&sg.r.orig_prefix, 0, sizeof(sg.r.orig_prefix));
nexthop_del_srv6_seg6local(&sg.r.nhop);
nexthop_del_srv6_seg6(&sg.r.nhop);
memset(&sg.r.nhop, 0, sizeof(sg.r.nhop));
memset(&sg.r.nhop_group, 0, sizeof(sg.r.nhop_group));
memset(&sg.r.backup_nhop, 0, sizeof(sg.r.nhop));
memset(&sg.r.backup_nhop_group, 0, sizeof(sg.r.nhop_group));
if (start4.s_addr != INADDR_ANY) {
prefix.family = AF_INET;
prefix.prefixlen = IPV4_MAX_BITLEN;
prefix.u.prefix4 = start4;
} else {
prefix.family = AF_INET6;
prefix.prefixlen = IPV6_MAX_BITLEN;
prefix.u.prefix6 = start6;
}
sg.r.orig_prefix = prefix;
if (!vrf_name)
vrf_name = VRF_DEFAULT_NAME;
vrf = vrf_lookup_by_name(vrf_name);
if (!vrf) {
vty_out(vty, "The vrf NAME specified: %s does not exist\n",
vrf_name);
return CMD_WARNING;
}
/* Explicit backup not available with named nexthop-group */
if (backup && nexthop_group) {
vty_out(vty, "%% Invalid: cannot specify both nexthop-group and backup\n");
return CMD_WARNING;
}
if (nexthop_group) {
struct nexthop_group_cmd *nhgc = nhgc_find(nexthop_group);
if (!nhgc) {
vty_out(vty,
"Specified Nexthop Group: %s does not exist\n",
nexthop_group);
return CMD_WARNING;
}
nhgid = sharp_nhgroup_get_id(nexthop_group);
sg.r.nhgid = nhgid;
sg.r.nhop_group.nexthop = nhgc->nhg.nexthop;
/* Use group's backup nexthop info if present */
if (nhgc->backup_list_name[0]) {
struct nexthop_group_cmd *bnhgc =
nhgc_find(nhgc->backup_list_name);
if (!bnhgc) {
vty_out(vty, "%% Backup group %s not found for group %s\n",
nhgc->backup_list_name,
nhgc->name);
return CMD_WARNING;
}
sg.r.backup_nhop.vrf_id = vrf->vrf_id;
sg.r.backup_nhop_group.nexthop = bnhgc->nhg.nexthop;
}
} else {
if (nexthop4.s_addr != INADDR_ANY) {
sg.r.nhop.gate.ipv4 = nexthop4;
sg.r.nhop.type = NEXTHOP_TYPE_IPV4;
} else {
sg.r.nhop.gate.ipv6 = nexthop6;
sg.r.nhop.type = NEXTHOP_TYPE_IPV6;
}
sg.r.nhop.vrf_id = vrf->vrf_id;
sg.r.nhop_group.nexthop = &sg.r.nhop;
}
/* Use single backup nexthop if specified */
if (backup) {
/* Set flag and index in primary nexthop */
SET_FLAG(sg.r.nhop.flags, NEXTHOP_FLAG_HAS_BACKUP);
sg.r.nhop.backup_num = 1;
sg.r.nhop.backup_idx[0] = 0;
if (backup_nexthop4.s_addr != INADDR_ANY) {
sg.r.backup_nhop.gate.ipv4 = backup_nexthop4;
sg.r.backup_nhop.type = NEXTHOP_TYPE_IPV4;
} else {
sg.r.backup_nhop.gate.ipv6 = backup_nexthop6;
sg.r.backup_nhop.type = NEXTHOP_TYPE_IPV6;
}
sg.r.backup_nhop.vrf_id = vrf->vrf_id;
sg.r.backup_nhop_group.nexthop = &sg.r.backup_nhop;
}
if (opaque)
strlcpy(sg.r.opaque, opaque, ZAPI_MESSAGE_OPAQUE_LENGTH);
else
sg.r.opaque[0] = '\0';
/* Default is to ask for recursive nexthop resolution */
if (norecurse == NULL)
SET_FLAG(sg.r.flags, ZEBRA_FLAG_ALLOW_RECURSION);
sg.r.inst = instance;
sg.r.vrf_id = vrf->vrf_id;
rts = routes;
sharp_install_routes_helper(&prefix, sg.r.vrf_id, sg.r.inst, nhgid,
&sg.r.nhop_group, &sg.r.backup_nhop_group,
rts, sg.r.flags, sg.r.opaque);
return CMD_SUCCESS;
}
DEFPY (install_seg6_routes,
install_seg6_routes_cmd,
"sharp install seg6-routes [vrf NAME$vrf_name]\
<A.B.C.D$start4|X:X::X:X$start6>\
nexthop-seg6 X:X::X:X$seg6_nh6 encap X:X::X:X$seg6_seg\
(1-1000000)$routes [repeat (2-1000)$rpt]",
"Sharp routing Protocol\n"
"install some routes\n"
"Routes to install\n"
"The vrf we would like to install into if non-default\n"
"The NAME of the vrf\n"
"v4 Address to start /32 generation at\n"
"v6 Address to start /128 generation at\n"
"Nexthop-seg6 to use\n"
"V6 Nexthop address to use\n"
"Encap mode\n"
"Segment List to use\n"
"How many to create\n"
"Should we repeat this command\n"
"How many times to repeat this command\n")
{
struct vrf *vrf;
struct prefix prefix;
uint32_t route_flags = 0;
sg.r.total_routes = routes;
sg.r.installed_routes = 0;
if (rpt >= 2)
sg.r.repeat = rpt * 2;
else
sg.r.repeat = 0;
memset(&prefix, 0, sizeof(prefix));
memset(&sg.r.orig_prefix, 0, sizeof(sg.r.orig_prefix));
nexthop_del_srv6_seg6local(&sg.r.nhop);
nexthop_del_srv6_seg6(&sg.r.nhop);
memset(&sg.r.nhop, 0, sizeof(sg.r.nhop));
memset(&sg.r.nhop_group, 0, sizeof(sg.r.nhop_group));
memset(&sg.r.backup_nhop, 0, sizeof(sg.r.nhop));
memset(&sg.r.backup_nhop_group, 0, sizeof(sg.r.nhop_group));
sg.r.opaque[0] = '\0';
sg.r.inst = 0;
if (start4.s_addr != INADDR_ANY) {
prefix.family = AF_INET;
prefix.prefixlen = IPV4_MAX_BITLEN;
prefix.u.prefix4 = start4;
} else {
prefix.family = AF_INET6;
prefix.prefixlen = IPV6_MAX_BITLEN;
prefix.u.prefix6 = start6;
}
sg.r.orig_prefix = prefix;
if (!vrf_name)
vrf_name = VRF_DEFAULT_NAME;
vrf = vrf_lookup_by_name(vrf_name);
if (!vrf) {
vty_out(vty, "The vrf NAME specified: %s does not exist\n",
vrf_name);
return CMD_WARNING;
}
sg.r.nhop.type = NEXTHOP_TYPE_IPV6;
sg.r.nhop.gate.ipv6 = seg6_nh6;
sg.r.nhop.vrf_id = vrf->vrf_id;
sg.r.nhop_group.nexthop = &sg.r.nhop;
nexthop_add_srv6_seg6(&sg.r.nhop, &seg6_seg, 1, SRV6_HEADEND_BEHAVIOR_H_ENCAPS);
sg.r.vrf_id = vrf->vrf_id;
sharp_install_routes_helper(&prefix, sg.r.vrf_id, sg.r.inst, 0,
&sg.r.nhop_group, &sg.r.backup_nhop_group,
routes, route_flags, sg.r.opaque);
return CMD_SUCCESS;
}
DEFPY(install_seg6local_segs_routes, install_seg6local_segs_routes_cmd,
"sharp install seg6local-routes [vrf NAME$vrf_name]\
X:X::X:X$start6\
nexthop-seg6local NAME$seg6l_oif\
<End_B6_Encap$end_b6_encap|uB6_Encap$ub6_encap>\
nexthop-seg6 X:X::X:X$seg6_nh6\
encap X:X::X:X$seg6_seg1 X:X::X:X$seg6_seg2\
[usid-block-length (1-128)$lcblen] [usid-function-length (1-128)$lcfunclen] \
(1-1000000)$routes [repeat (2-1000)$rpt]",
"Sharp routing Protocol\n"
"install some routes\n"
"Routes to install\n"
"The vrf we would like to install into if non-default\n"
"The NAME of the vrf\n"
"v6 Address to start /32 generation at\n"
"Nexthop-seg6local to use\n"
"Output device to use\n"
"SRv6 End.B6.Encap function to use\n"
"SRv6 uB6.Encap function to use\n"
"Nexthop-seg6 to use\n"
"V6 Nexthop address to use\n"
"Encap mode\n"
"Segment List, 1st SID to use\n"
"Segment List, 2nd SID to use\n"
"uSID locator block length\n"
"Value in bits\n"
"uSID node Function length\n"
"Value in bits\n"
"How many to create\n"
"Should we repeat this command\n"
"How many times to repeat this command\n")
{
struct vrf *vrf;
uint32_t route_flags = 0;
struct seg6local_context ctx = {};
enum seg6local_action_t action;
struct in6_addr seg_list[2];
struct in6_addr *p_seg_list = &seg_list[0];
sg.r.total_routes = routes;
sg.r.installed_routes = 0;
if (rpt >= 2)
sg.r.repeat = rpt * 2;
else
sg.r.repeat = 0;
memset(&sg.r.orig_prefix, 0, sizeof(sg.r.orig_prefix));
nexthop_del_srv6_seg6local(&sg.r.nhop);
nexthop_del_srv6_seg6(&sg.r.nhop);
memset(&sg.r.nhop, 0, sizeof(sg.r.nhop));
memset(&sg.r.nhop_group, 0, sizeof(sg.r.nhop_group));
memset(&sg.r.backup_nhop, 0, sizeof(sg.r.nhop));
memset(&sg.r.backup_nhop_group, 0, sizeof(sg.r.nhop_group));
sg.r.opaque[0] = '\0';
sg.r.inst = 0;
sg.r.orig_prefix.family = AF_INET6;
sg.r.orig_prefix.prefixlen = 128;
sg.r.orig_prefix.u.prefix6 = start6;
if (!vrf_name)
vrf_name = VRF_DEFAULT_NAME;
vrf = vrf_lookup_by_name(vrf_name);
if (!vrf) {
vty_out(vty, "The vrf NAME specified: %s does not exist\n", vrf_name);
return CMD_WARNING;
}
ctx.nh6 = seg6_nh6;
action = ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP;
if (ub6_encap) {
SET_SRV6_FLV_OP(ctx.flv.flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID);
if (lcblen)
ctx.flv.lcblock_len = lcblen;
if (lcfunclen)
ctx.flv.lcnode_func_len = lcfunclen;
}
sg.r.nhop.type = NEXTHOP_TYPE_IPV6_IFINDEX;
sg.r.nhop.gate.ipv6 = seg6_nh6;
sg.r.nhop.ifindex = ifname2ifindex(seg6l_oif, vrf->vrf_id);
sg.r.nhop.vrf_id = vrf->vrf_id;
sg.r.nhop_group.nexthop = &sg.r.nhop;
nexthop_add_srv6_seg6local(&sg.r.nhop, action, &ctx);
sg.r.nhop_group.nexthop = &sg.r.nhop;
seg_list[0] = seg6_seg1;
seg_list[1] = seg6_seg2;
nexthop_add_srv6_seg6(&sg.r.nhop, p_seg_list, 2, SRV6_HEADEND_BEHAVIOR_H_ENCAPS);
sg.r.vrf_id = vrf->vrf_id;
sharp_install_routes_helper(&sg.r.orig_prefix, sg.r.vrf_id, sg.r.inst, 0, &sg.r.nhop_group,
&sg.r.backup_nhop_group, routes, route_flags, sg.r.opaque);
return CMD_SUCCESS;
}
DEFPY (install_seg6local_routes,
install_seg6local_routes_cmd,
"sharp install seg6local-routes [vrf NAME$vrf_name]\
X:X::X:X$start6\
nexthop-seg6local NAME$seg6l_oif\
<End$seg6l_end|\
uN$seg6l_micro_end|\
End_X$seg6l_endx X:X::X:X$seg6l_endx_nh6|\
uA$seg6l_micro_endx X:X::X:X$seg6l_micro_endx_nh6|\
End_T$seg6l_endt (1-4294967295)$seg6l_endt_table|\
uDT$seg6l_micro_endt (1-4294967295)$seg6l_micro_endt_table|\
End_DX4$seg6l_enddx4 A.B.C.D$seg6l_enddx4_nh4|\
uDX4$seg6l_micro_enddx4 A.B.C.D$seg6l_micro_enddx4_nh4|\
End_DX6$seg6l_enddx6 X:X::X:X$seg6l_enddx6_nh6|\
uDX6$seg6l_micro_enddx6 X:X::X:X$seg6l_micro_enddx6_nh6|\
End_DT6$seg6l_enddt6 (1-4294967295)$seg6l_enddt6_table|\
uDT6$seg6l_micro_enddt6 (1-4294967295)$seg6l_micro_enddt6_table|\
End_DT4$seg6l_enddt4 (1-4294967295)$seg6l_enddt4_table|\
uDT4$seg6l_micro_enddt4 (1-4294967295)$seg6l_micro_enddt4_table|\
End_DT46$seg6l_enddt46 (1-4294967295)$seg6l_enddt46_table|\
uDT46$seg6l_micro_enddt46 (1-4294967295)$seg6l_micro_enddt46_table>\
[usid-block-length (1-128)$lcblen] [usid-function-length (1-128)$lcfunclen] \
[psp-flavor$psp_flavor] \
(1-1000000)$routes [repeat (2-1000)$rpt]",
"Sharp routing Protocol\n"
"install some routes\n"
"Routes to install\n"
"The vrf we would like to install into if non-default\n"
"The NAME of the vrf\n"
"v6 Address to start /128 generation at\n"
"Nexthop-seg6local to use\n"
"Output device to use\n"
"SRv6 End function to use\n"
"SRv6 uN function to use\n"
"SRv6 End.X function to use\n"
"V6 Nexthop address to use\n"
"SRv6 uA function to use\n"
"V6 Nexthop address to use\n"
"SRv6 End.T function to use\n"
"Redirect table id to use\n"
"SRv6 uDT function to use\n"
"Redirect table id to use\n"
"SRv6 End.DX4 function to use\n"
"V4 Nexthop address to use\n"
"SRv6 uDX4 function to use\n"
"V4 Nexthop address to use\n"
"SRv6 End.DX6 function to use\n"
"V6 Nexthop address to use\n"
"SRv6 uDX6 function to use\n"
"V6 Nexthop address to use\n"
"SRv6 End.DT6 function to use\n"
"Redirect table id to use\n"
"SRv6 uDT6 function to use\n"
"Redirect table id to use\n"
"SRv6 End.DT4 function to use\n"
"Redirect table id to use\n"
"SRv6 uDT4 function to use\n"
"Redirect table id to use\n"
"SRv6 End.DT46 function to use\n"
"Redirect table id to use\n"
"SRv6 uDT46 function to use\n"
"Redirect table id to use\n"
"uSID locator block length\n"
"Value in bits\n"
"uSID node Function length\n"
"Value in bits\n"
"Add the PSP flavor\n"
"How many to create\n"
"Should we repeat this command\n"
"How many times to repeat this command\n")
{
struct vrf *vrf;
uint32_t route_flags = 0;
struct seg6local_context ctx = {};
enum seg6local_action_t action;
sg.r.total_routes = routes;
sg.r.installed_routes = 0;
if (rpt >= 2)
sg.r.repeat = rpt * 2;
else
sg.r.repeat = 0;
memset(&sg.r.orig_prefix, 0, sizeof(sg.r.orig_prefix));
nexthop_del_srv6_seg6local(&sg.r.nhop);
nexthop_del_srv6_seg6(&sg.r.nhop);
memset(&sg.r.nhop, 0, sizeof(sg.r.nhop));
memset(&sg.r.nhop_group, 0, sizeof(sg.r.nhop_group));
memset(&sg.r.backup_nhop, 0, sizeof(sg.r.nhop));
memset(&sg.r.backup_nhop_group, 0, sizeof(sg.r.nhop_group));
sg.r.opaque[0] = '\0';
sg.r.inst = 0;
sg.r.orig_prefix.family = AF_INET6;
sg.r.orig_prefix.prefixlen = IPV6_MAX_BITLEN;
sg.r.orig_prefix.u.prefix6 = start6;
if (!vrf_name)
vrf_name = VRF_DEFAULT_NAME;
vrf = vrf_lookup_by_name(vrf_name);
if (!vrf) {
vty_out(vty, "The vrf NAME specified: %s does not exist\n",
vrf_name);
return CMD_WARNING;
}
if (seg6l_enddx4) {
action = ZEBRA_SEG6_LOCAL_ACTION_END_DX4;
ctx.nh4 = seg6l_enddx4_nh4;
} else if (seg6l_micro_enddx4) {
action = ZEBRA_SEG6_LOCAL_ACTION_END_DX4;
ctx.nh4 = seg6l_micro_enddx4_nh4;
SET_SRV6_FLV_OP(ctx.flv.flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID);
} else if (seg6l_enddx6) {
action = ZEBRA_SEG6_LOCAL_ACTION_END_DX6;
ctx.nh6 = seg6l_enddx6_nh6;
} else if (seg6l_micro_enddx6) {
action = ZEBRA_SEG6_LOCAL_ACTION_END_DX6;
ctx.nh6 = seg6l_enddx6_nh6;
SET_SRV6_FLV_OP(ctx.flv.flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID);
} else if (seg6l_endx) {
action = ZEBRA_SEG6_LOCAL_ACTION_END_X;
ctx.nh6 = seg6l_endx_nh6;
} else if (seg6l_micro_endx) {
action = ZEBRA_SEG6_LOCAL_ACTION_END_X;
ctx.nh6 = seg6l_micro_endx_nh6;
SET_SRV6_FLV_OP(ctx.flv.flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID);
} else if (seg6l_endt) {
action = ZEBRA_SEG6_LOCAL_ACTION_END_T;
ctx.table = seg6l_endt_table;
} else if (seg6l_micro_endt) {
action = ZEBRA_SEG6_LOCAL_ACTION_END_T;
ctx.table = seg6l_micro_endt_table;
SET_SRV6_FLV_OP(ctx.flv.flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID);
} else if (seg6l_enddt6) {
action = ZEBRA_SEG6_LOCAL_ACTION_END_DT6;
ctx.table = seg6l_enddt6_table;
} else if (seg6l_micro_enddt6) {
action = ZEBRA_SEG6_LOCAL_ACTION_END_DT6;
ctx.table = seg6l_micro_enddt6_table;
SET_SRV6_FLV_OP(ctx.flv.flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID);
} else if (seg6l_enddt4) {
action = ZEBRA_SEG6_LOCAL_ACTION_END_DT4;
ctx.table = seg6l_enddt4_table;
} else if (seg6l_micro_enddt4) {
action = ZEBRA_SEG6_LOCAL_ACTION_END_DT4;
ctx.table = seg6l_micro_enddt4_table;
SET_SRV6_FLV_OP(ctx.flv.flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID);
} else if (seg6l_enddt46) {
action = ZEBRA_SEG6_LOCAL_ACTION_END_DT46;
ctx.table = seg6l_enddt46_table;
} else if (seg6l_micro_enddt46) {
action = ZEBRA_SEG6_LOCAL_ACTION_END_DT46;
ctx.table = seg6l_micro_enddt46_table;
SET_SRV6_FLV_OP(ctx.flv.flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID);
} else if (seg6l_micro_end) {
action = ZEBRA_SEG6_LOCAL_ACTION_END;
SET_SRV6_FLV_OP(ctx.flv.flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID);
if (psp_flavor)
SET_SRV6_FLV_OP(ctx.flv.flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_PSP);
} else {
action = ZEBRA_SEG6_LOCAL_ACTION_END;
if (psp_flavor)
SET_SRV6_FLV_OP(ctx.flv.flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_PSP);
}
if (CHECK_SRV6_FLV_OP(ctx.flv.flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID)) {
if (lcblen)
ctx.flv.lcblock_len = lcblen;
if (lcfunclen)
ctx.flv.lcnode_func_len = lcfunclen;
}
sg.r.nhop.type = NEXTHOP_TYPE_IFINDEX;
sg.r.nhop.ifindex = ifname2ifindex(seg6l_oif, vrf->vrf_id);
sg.r.nhop.vrf_id = vrf->vrf_id;
sg.r.nhop_group.nexthop = &sg.r.nhop;
nexthop_add_srv6_seg6local(&sg.r.nhop, action, &ctx);
sg.r.vrf_id = vrf->vrf_id;
sharp_install_routes_helper(&sg.r.orig_prefix, sg.r.vrf_id, sg.r.inst,
0, &sg.r.nhop_group,
&sg.r.backup_nhop_group, routes,
route_flags, sg.r.opaque);
return CMD_SUCCESS;
}
DEFPY(vrf_label, vrf_label_cmd,
"sharp label <ip$ipv4|ipv6$ipv6> vrf NAME$vrf_name label (0-100000)$label",
"Sharp Routing Protocol\n"
"Give a vrf a label\n"
"Pop and forward for IPv4\n"
"Pop and forward for IPv6\n"
VRF_CMD_HELP_STR
"The label to use, 0 specifies remove the label installed from previous\n"
"Specified range to use\n")
{
struct vrf *vrf;
afi_t afi = (ipv4) ? AFI_IP : AFI_IP6;
if (strcmp(vrf_name, "default") == 0)
vrf = vrf_lookup_by_id(VRF_DEFAULT);
else
vrf = vrf_lookup_by_name(vrf_name);
if (!vrf) {
vty_out(vty, "Unable to find vrf you silly head\n");
return CMD_WARNING_CONFIG_FAILED;
}
if (label == 0)
label = MPLS_LABEL_NONE;
vrf_label_add(vrf->vrf_id, afi, label);
return CMD_SUCCESS;
}
DEFPY (remove_routes,
remove_routes_cmd,
"sharp remove routes [vrf NAME$vrf_name] <A.B.C.D$start4|X:X::X:X$start6> (1-1000000)$routes [instance (0-255)$instance]",
"Sharp Routing Protocol\n"
"Remove some routes\n"
"Routes to remove\n"
"The vrf we would like to remove from if non-default\n"
"The NAME of the vrf\n"
"v4 Starting spot\n"
"v6 Starting spot\n"
"Routes to uninstall\n"
"instance to use\n"
"Value of instance\n")
{
struct vrf *vrf;
struct prefix prefix;
sg.r.total_routes = routes;
sg.r.removed_routes = 0;
uint32_t rts;
memset(&prefix, 0, sizeof(prefix));
if (start4.s_addr != INADDR_ANY) {
prefix.family = AF_INET;
prefix.prefixlen = IPV4_MAX_BITLEN;
prefix.u.prefix4 = start4;
} else {
prefix.family = AF_INET6;
prefix.prefixlen = IPV6_MAX_BITLEN;
prefix.u.prefix6 = start6;
}
vrf = vrf_lookup_by_name(vrf_name ? vrf_name : VRF_DEFAULT_NAME);
if (!vrf) {
vty_out(vty, "The vrf NAME specified: %s does not exist\n",
vrf_name ? vrf_name : VRF_DEFAULT_NAME);
return CMD_WARNING;
}
sg.r.inst = instance;
sg.r.vrf_id = vrf->vrf_id;
rts = routes;
sharp_remove_routes_helper(&prefix, sg.r.vrf_id,
sg.r.inst, rts);
return CMD_SUCCESS;
}
DEFUN_NOSH (show_debugging_sharpd,
show_debugging_sharpd_cmd,
"show debugging [sharp]",
SHOW_STR
DEBUG_STR
"Sharp Information\n")
{
vty_out(vty, "Sharp debugging status:\n");
cmd_show_lib_debugs(vty);
return CMD_SUCCESS;
}
DEFPY (sharp_lsp_prefix_v4, sharp_lsp_prefix_v4_cmd,
"sharp lsp [update]$update (0-100000)$inlabel\
nexthop-group NHGNAME$nhgname\
[prefix A.B.C.D/M$pfx\
" FRR_IP_REDIST_STR_ZEBRA "$type_str [instance (0-255)$instance]]",
"Sharp Routing Protocol\n"
"Add an LSP\n"
"Update an LSP\n"
"The ingress label to use\n"
"Use nexthops from a nexthop-group\n"
"The nexthop-group name\n"
"Label a prefix\n"
"The v4 prefix to label\n"
FRR_IP_REDIST_HELP_STR_ZEBRA
"Instance to use\n"
"Instance\n")
{
struct nexthop_group_cmd *nhgc = NULL;
struct nexthop_group_cmd *backup_nhgc = NULL;
struct nexthop_group *backup_nhg = NULL;
struct prefix p = {};
uint8_t type = 0;
bool update_p;
update_p = (update != NULL);
/* We're offered a v4 prefix */
if (pfx->family > 0 && type_str) {
p.family = pfx->family;
p.prefixlen = pfx->prefixlen;
p.u.prefix4 = pfx->prefix;
type = proto_redistnum(AFI_IP, type_str);
if (type == ZEBRA_ROUTE_ERROR) {
vty_out(vty, "%% Unknown route type '%s'\n", type_str);
return CMD_WARNING;
}
} else if (pfx->family > 0 || type_str) {
vty_out(vty, "%% Must supply both prefix and type\n");
return CMD_WARNING;
}
nhgc = nhgc_find(nhgname);
if (!nhgc) {
vty_out(vty, "%% Nexthop-group '%s' does not exist\n",
nhgname);
return CMD_WARNING;
}
if (nhgc->nhg.nexthop == NULL) {
vty_out(vty, "%% Nexthop-group '%s' is empty\n", nhgname);
return CMD_WARNING;
}
/* Use group's backup nexthop info if present */
if (nhgc->backup_list_name[0]) {
backup_nhgc = nhgc_find(nhgc->backup_list_name);
if (!backup_nhgc) {
vty_out(vty,
"%% Backup group %s not found for group %s\n",
nhgc->backup_list_name,
nhgname);
return CMD_WARNING;
}
backup_nhg = &(backup_nhgc->nhg);
}
if (sharp_install_lsps_helper(true /*install*/, update_p,
pfx->family > 0 ? &p : NULL,
type, instance, inlabel,
&(nhgc->nhg), backup_nhg) == 0)
return CMD_SUCCESS;
else {
vty_out(vty, "%% LSP install failed!\n");
return CMD_WARNING;
}
}
DEFPY(sharp_remove_lsp_prefix_v4, sharp_remove_lsp_prefix_v4_cmd,
"sharp remove lsp \
(0-100000)$inlabel\
[nexthop-group NHGNAME$nhgname] \
[prefix A.B.C.D/M$pfx\
" FRR_IP_REDIST_STR_ZEBRA "$type_str [instance (0-255)$instance]]",
"Sharp Routing Protocol\n"
"Remove data\n"
"Remove an LSP\n"
"The ingress label\n"
"Use nexthops from a nexthop-group\n"
"The nexthop-group name\n"
"Specify a v4 prefix\n"
"The v4 prefix to label\n"
FRR_IP_REDIST_HELP_STR_ZEBRA
"Routing instance\n"
"Instance to use\n")
{
struct nexthop_group_cmd *nhgc = NULL;
struct prefix p = {};
uint8_t type = 0;
struct nexthop_group *nhg = NULL;
/* We're offered a v4 prefix */
if (pfx->family > 0 && type_str) {
p.family = pfx->family;
p.prefixlen = pfx->prefixlen;
p.u.prefix4 = pfx->prefix;
type = proto_redistnum(AFI_IP, type_str);
if (type == ZEBRA_ROUTE_ERROR) {
vty_out(vty, "%% Unknown route type '%s'\n", type_str);
return CMD_WARNING;
}
} else if (pfx->family > 0 || type_str) {
vty_out(vty, "%% Must supply both prefix and type\n");
return CMD_WARNING;
}
if (nhgname) {
nhgc = nhgc_find(nhgname);
if (!nhgc) {
vty_out(vty, "%% Nexthop-group '%s' does not exist\n",
nhgname);
return CMD_WARNING;
}
if (nhgc->nhg.nexthop == NULL) {
vty_out(vty, "%% Nexthop-group '%s' is empty\n",
nhgname);
return CMD_WARNING;
}
nhg = &(nhgc->nhg);
}
if (sharp_install_lsps_helper(false /*!install*/, false,
pfx->family > 0 ? &p : NULL,
type, instance, inlabel, nhg, NULL) == 0)
return CMD_SUCCESS;
else {
vty_out(vty, "%% LSP remove failed!\n");
return CMD_WARNING;
}
}
DEFPY (logpump,
logpump_cmd,
"sharp logpump duration (1-60) frequency (1-1000000) burst (1-1000)",
"Sharp Routing Protocol\n"
"Generate bulk log messages for testing\n"
"Duration of run (s)\n"
"Duration of run (s)\n"
"Frequency of bursts (s^-1)\n"
"Frequency of bursts (s^-1)\n"
"Number of log messages per each burst\n"
"Number of log messages per each burst\n")
{
sharp_logpump_run(vty, duration, frequency, burst);
return CMD_SUCCESS;
}
DEFPY (create_session,
create_session_cmd,
"sharp create session (1-1024)",
"Sharp Routing Protocol\n"
"Create data\n"
"Create a test session\n"
"Session ID\n")
{
if (sharp_zclient_create(session) != 0) {
vty_out(vty, "%% Client session error\n");
return CMD_WARNING;
}
return CMD_SUCCESS;
}
DEFPY (remove_session,
remove_session_cmd,
"sharp remove session (1-1024)",
"Sharp Routing Protocol\n"
"Remove data\n"
"Remove a test session\n"
"Session ID\n")
{
sharp_zclient_delete(session);
return CMD_SUCCESS;
}
DEFPY (send_opaque,
send_opaque_cmd,
"sharp send opaque type (1-255) (1-1000)$count",
SHARP_STR
"Send messages for testing\n"
"Send opaque messages\n"
"Type code to send\n"
"Type code to send\n"
"Number of messages to send\n")
{
sharp_opaque_send(type, 0, 0, 0, count);
return CMD_SUCCESS;
}
DEFPY (send_opaque_unicast,
send_opaque_unicast_cmd,
"sharp send opaque unicast type (1-255) \
" FRR_IP_REDIST_STR_ZEBRA "$proto_str \
[{instance (0-1000) | session (1-1000)}] (1-1000)$count",
SHARP_STR
"Send messages for testing\n"
"Send opaque messages\n"
"Send unicast messages\n"
"Type code to send\n"
"Type code to send\n"
FRR_IP_REDIST_HELP_STR_ZEBRA
"Daemon instance\n"
"Daemon instance\n"
"Session ID\n"
"Session ID\n"
"Number of messages to send\n")
{
uint8_t proto;
proto = proto_redistnum(AFI_IP, proto_str);
sharp_opaque_send(type, proto, instance, session, count);
return CMD_SUCCESS;
}
DEFPY (send_opaque_reg,
send_opaque_reg_cmd,
"sharp send opaque <reg$reg | unreg> \
" FRR_IP_REDIST_STR_ZEBRA "$proto_str \
[{instance (0-1000) | session (1-1000)}] type (1-1000)",
SHARP_STR
"Send messages for testing\n"
"Send opaque messages\n"
"Send opaque registration\n"
"Send opaque unregistration\n"
FRR_IP_REDIST_HELP_STR_ZEBRA
"Daemon instance\n"
"Daemon instance\n"
"Session ID\n"
"Session ID\n"
"Opaque sub-type code\n"
"Opaque sub-type code\n")
{
uint8_t proto;
proto = proto_redistnum(AFI_IP, proto_str);
sharp_opaque_reg_send((reg != NULL), proto, instance, session, type);
return CMD_SUCCESS;
}
/* Opaque notifications - register or unregister */
DEFPY (send_opaque_notif_reg,
send_opaque_notif_reg_cmd,
"sharp send opaque notify <reg$reg | unreg> type (1-1000)",
SHARP_STR
"Send messages for testing\n"
"Send opaque messages\n"
"Opaque notification messages\n"
"Send notify registration\n"
"Send notify unregistration\n"
"Opaque sub-type code\n"
"Opaque sub-type code\n")
{
sharp_zebra_opaque_notif_reg((reg != NULL), type);
return CMD_SUCCESS;
}
DEFPY (neigh_discover,
neigh_discover_cmd,
"sharp neigh discover [vrf NAME$vrf_name] <A.B.C.D$dst4|X:X::X:X$dst6> IFNAME$ifname",
SHARP_STR
"Discover neighbours\n"
"Send an ARP/NDP request\n"
VRF_CMD_HELP_STR
"v4 Destination address\n"
"v6 Destination address\n"
"Interface name\n")
{
struct vrf *vrf;
struct interface *ifp;
struct prefix prefix;
memset(&prefix, 0, sizeof(prefix));
if (dst4.s_addr != INADDR_ANY) {
prefix.family = AF_INET;
prefix.prefixlen = IPV4_MAX_BITLEN;
prefix.u.prefix4 = dst4;
} else {
prefix.family = AF_INET6;
prefix.prefixlen = IPV6_MAX_BITLEN;
prefix.u.prefix6 = dst6;
}
vrf = vrf_lookup_by_name(vrf_name ? vrf_name : VRF_DEFAULT_NAME);
if (!vrf) {
vty_out(vty, "The vrf NAME specified: %s does not exist\n",
vrf_name ? vrf_name : VRF_DEFAULT_NAME);
return CMD_WARNING;
}
ifp = if_lookup_by_name_vrf(ifname, vrf);
if (ifp == NULL) {
vty_out(vty, "%% Can't find interface %s\n", ifname);
return CMD_WARNING;
}
sharp_zebra_send_arp(ifp, &prefix);
return CMD_SUCCESS;
}
DEFPY (import_te,
import_te_cmd,
"sharp import-te",
SHARP_STR
"Import Traffic Engineering\n")
{
sg.ted = ls_ted_new(1, "Sharp", 0);
sharp_zebra_register_te();
return CMD_SUCCESS;
}
static void sharp_srv6_locator_chunk_free(struct prefix_ipv6 *chunk)
{
prefix_ipv6_free(&chunk);
}
DEFPY (sharp_srv6_manager_get_locator_chunk,
sharp_srv6_manager_get_locator_chunk_cmd,
"sharp srv6-manager get-locator-chunk NAME$locator_name",
SHARP_STR
"Segment-Routing IPv6\n"
"Get SRv6 locator-chunk\n"
"SRv6 Locator name\n")
{
int ret;
struct listnode *node;
struct sharp_srv6_locator *loc;
struct sharp_srv6_locator *loc_found = NULL;
for (ALL_LIST_ELEMENTS_RO(sg.srv6_locators, node, loc)) {
if (strcmp(loc->name, locator_name))
continue;
loc_found = loc;
break;
}
if (!loc_found) {
loc = XCALLOC(MTYPE_SRV6_LOCATOR,
sizeof(struct sharp_srv6_locator));
loc->chunks = list_new();
loc->chunks->del =
(void (*)(void *))sharp_srv6_locator_chunk_free;
snprintf(loc->name, SRV6_LOCNAME_SIZE, "%s", locator_name);
listnode_add(sg.srv6_locators, loc);
}
ret = sharp_zebra_srv6_manager_get_locator_chunk(locator_name);
if (ret < 0)
return CMD_WARNING_CONFIG_FAILED;
return CMD_SUCCESS;
}
DEFUN (show_sharp_ted,
show_sharp_ted_cmd,
"show sharp ted [<vertex [A.B.C.D]|edge [A.B.C.D]|subnet [A.B.C.D/M]>] [verbose|json]",
SHOW_STR
SHARP_STR
"Traffic Engineering Database\n"
"MPLS-TE Vertex\n"
"MPLS-TE router ID (as an IP address)\n"
"MPLS-TE Edge\n"
"MPLS-TE Edge ID (as an IP address)\n"
"MPLS-TE Subnet\n"
"MPLS-TE Subnet ID (as an IP prefix)\n"
"Verbose output\n"
JSON_STR)
{
int idx = 0;
struct in_addr ip_addr;
struct prefix pref;
struct ls_vertex *vertex;
struct ls_edge *edge;
struct ls_subnet *subnet;
uint64_t key;
struct ls_edge_key ekey;
bool verbose = false;
bool uj = use_json(argc, argv);
json_object *json = NULL;
if (sg.ted == NULL) {
vty_out(vty, "MPLS-TE import is not enabled\n");
return CMD_WARNING;
}
if (uj)
json = json_object_new_object();
if (argv[argc - 1]->arg && strmatch(argv[argc - 1]->text, "verbose"))
verbose = true;
if (argv_find(argv, argc, "vertex", &idx)) {
/* Show Vertex */
if (argv_find(argv, argc, "A.B.C.D", &idx)) {
if (!inet_aton(argv[idx + 1]->arg, &ip_addr)) {
vty_out(vty,
"Specified Router ID %s is invalid\n",
argv[idx + 1]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
/* Get the Vertex from the Link State Database */
key = ((uint64_t)ip_addr.s_addr) & 0xffffffff;
vertex = ls_find_vertex_by_key(sg.ted, key);
if (!vertex) {
vty_out(vty, "No vertex found for ID %pI4\n",
&ip_addr);
return CMD_WARNING;
}
} else
vertex = NULL;
if (vertex)
ls_show_vertex(vertex, vty, json, verbose);
else
ls_show_vertices(sg.ted, vty, json, verbose);
} else if (argv_find(argv, argc, "edge", &idx)) {
/* Show Edge */
if (argv_find(argv, argc, "A.B.C.D", &idx)) {
if (!inet_aton(argv[idx]->arg, &ip_addr)) {
vty_out(vty,
"Specified Edge ID %s is invalid\n",
argv[idx]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
/* Get the Edge from the Link State Database */
ekey.family = AF_INET;
IPV4_ADDR_COPY(&ekey.k.addr, &ip_addr);
edge = ls_find_edge_by_key(sg.ted, ekey);
if (!edge) {
vty_out(vty, "No edge found for ID %pI4\n",
&ip_addr);
return CMD_WARNING;
}
} else
edge = NULL;
if (edge)
ls_show_edge(edge, vty, json, verbose);
else
ls_show_edges(sg.ted, vty, json, verbose);
} else if (argv_find(argv, argc, "subnet", &idx)) {
/* Show Subnet */
if (argv_find(argv, argc, "A.B.C.D/M", &idx)) {
if (!str2prefix(argv[idx]->arg, &pref)) {
vty_out(vty, "Invalid prefix format %s\n",
argv[idx]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
/* Get the Subnet from the Link State Database */
subnet = ls_find_subnet(sg.ted, &pref);
if (!subnet) {
vty_out(vty, "No subnet found for ID %pFX\n",
&pref);
return CMD_WARNING;
}
} else
subnet = NULL;
if (subnet)
ls_show_subnet(subnet, vty, json, verbose);
else
ls_show_subnets(sg.ted, vty, json, verbose);
} else {
/* Show the complete TED */
ls_show_ted(sg.ted, vty, json, verbose);
}
if (uj)
vty_json(vty, json);
return CMD_SUCCESS;
}
DEFPY (sharp_srv6_manager_release_locator_chunk,
sharp_srv6_manager_release_locator_chunk_cmd,
"sharp srv6-manager release-locator-chunk NAME$locator_name",
SHARP_STR
"Segment-Routing IPv6\n"
"Release SRv6 locator-chunk\n"
"SRv6 Locator name\n")
{
int ret;
struct listnode *loc_node;
struct sharp_srv6_locator *loc;
for (ALL_LIST_ELEMENTS_RO(sg.srv6_locators, loc_node, loc)) {
if (!strcmp(loc->name, locator_name)) {
list_delete_all_node(loc->chunks);
list_delete(&loc->chunks);
listnode_delete(sg.srv6_locators, loc);
XFREE(MTYPE_SRV6_LOCATOR, loc);
break;
}
}
ret = sharp_zebra_srv6_manager_release_locator_chunk(locator_name);
if (ret < 0)
return CMD_WARNING_CONFIG_FAILED;
return CMD_SUCCESS;
}
DEFPY (show_sharp_segment_routing_srv6,
show_sharp_segment_routing_srv6_cmd,
"show sharp segment-routing srv6 [json]",
SHOW_STR
SHARP_STR
"Segment-Routing\n"
"Segment-Routing IPv6\n"
JSON_STR)
{
char str[256];
struct listnode *loc_node;
struct listnode *chunk_node;
struct sharp_srv6_locator *loc;
struct prefix_ipv6 *chunk;
bool uj = use_json(argc, argv);
json_object *jo_locs = NULL;
json_object *jo_loc = NULL;
json_object *jo_chunks = NULL;
if (uj) {
jo_locs = json_object_new_array();
for (ALL_LIST_ELEMENTS_RO(sg.srv6_locators, loc_node, loc)) {
jo_loc = json_object_new_object();
json_object_array_add(jo_locs, jo_loc);
json_object_string_add(jo_loc, "name", loc->name);
jo_chunks = json_object_new_array();
json_object_object_add(jo_loc, "chunks", jo_chunks);
for (ALL_LIST_ELEMENTS_RO(loc->chunks, chunk_node,
chunk)) {
prefix2str(chunk, str, sizeof(str));
json_array_string_add(jo_chunks, str);
}
}
vty_json(vty, jo_locs);
} else {
for (ALL_LIST_ELEMENTS_RO(sg.srv6_locators, loc_node, loc)) {
vty_out(vty, "Locator %s has %d prefix chunks\n",
loc->name, listcount(loc->chunks));
for (ALL_LIST_ELEMENTS_RO(loc->chunks, chunk_node,
chunk)) {
prefix2str(chunk, str, sizeof(str));
vty_out(vty, " %s\n", str);
}
vty_out(vty, "\n");
}
}
return CMD_SUCCESS;
}
DEFPY (show_sharp_cspf,
show_sharp_cspf_cmd,
"show sharp cspf source <A.B.C.D$src4|X:X::X:X$src6> \
destination <A.B.C.D$dst4|X:X::X:X$dst6> \
<metric|te-metric|delay> (0-16777215)$cost \
[rsv-bw (0-7)$cos BANDWIDTH$bw]",
SHOW_STR
SHARP_STR
"Constraint Shortest Path First path computation\n"
"Source of the path\n"
"IPv4 Source address in dot decimal A.B.C.D\n"
"IPv6 Source address as X:X:X:X\n"
"Destination of the path\n"
"IPv4 Destination address in dot decimal A.B.C.D\n"
"IPv6 Destination address as X:X:X:X\n"
"Maximum Metric\n"
"Maximum TE Metric\n"
"Maxim Delay\n"
"Value of Maximum cost\n"
"Reserved Bandwidth of this path\n"
"Class of Service or Priority level\n"
"Bytes/second (IEEE floating point format)\n")
{
struct cspf *algo;
struct constraints csts;
struct c_path *path;
struct listnode *node;
struct ls_edge *edge;
int idx;
if (sg.ted == NULL) {
vty_out(vty, "MPLS-TE import is not enabled\n");
return CMD_WARNING;
}
if ((src4.s_addr != INADDR_ANY && dst4.s_addr == INADDR_ANY) ||
(src4.s_addr == INADDR_ANY && dst4.s_addr != INADDR_ANY)) {
vty_out(vty, "Don't mix IPv4 and IPv6 addresses\n");
return CMD_WARNING;
}
idx = 6;
memset(&csts, 0, sizeof(struct constraints));
if (argv_find(argv, argc, "metric", &idx)) {
csts.ctype = CSPF_METRIC;
csts.cost = cost;
}
idx = 6;
if (argv_find(argv, argc, "te-metric", &idx)) {
csts.ctype = CSPF_TE_METRIC;
csts.cost = cost;
}
idx = 6;
if (argv_find(argv, argc, "delay", &idx)) {
csts.ctype = CSPF_DELAY;
csts.cost = cost;
}
if (argc > 9) {
if (sscanf(bw, "%g", &csts.bw) != 1) {
vty_out(vty, "Bandwidth constraints: fscanf: %s\n",
safe_strerror(errno));
return CMD_WARNING_CONFIG_FAILED;
}
csts.cos = cos;
}
/* Initialize and call point-to-point Path computation */
if (src4.s_addr != INADDR_ANY)
algo = cspf_init_v4(NULL, sg.ted, src4, dst4, &csts);
else
algo = cspf_init_v6(NULL, sg.ted, src6, dst6, &csts);
path = compute_p2p_path(algo, sg.ted);
cspf_del(algo);
if (!path) {
vty_out(vty, "Path computation failed without error\n");
return CMD_SUCCESS;
}
if (path->status != SUCCESS) {
vty_out(vty, "Path computation failed: %d\n", path->status);
cpath_del(path);
return CMD_SUCCESS;
}
vty_out(vty, "Path computation success\n");
vty_out(vty, "\tCost: %d\n", path->weight);
vty_out(vty, "\tEdges:");
for (ALL_LIST_ELEMENTS_RO(path->edges, node, edge)) {
if (src4.s_addr != INADDR_ANY)
vty_out(vty, " %pI4",
&edge->attributes->standard.remote);
else
vty_out(vty, " %pI6",
&edge->attributes->standard.remote6);
}
vty_out(vty, "\n");
cpath_del(path);
return CMD_SUCCESS;
}
static struct interface *if_lookup_vrf_all(const char *ifname)
{
struct interface *ifp;
struct vrf *vrf;
RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name) {
ifp = if_lookup_by_name(ifname, vrf->vrf_id);
if (ifp)
return ifp;
}
return NULL;
}
DEFPY (sharp_interface_protodown,
sharp_interface_protodown_cmd,
"sharp interface IFNAME$ifname protodown",
SHARP_STR
INTERFACE_STR
IFNAME_STR
"Set interface protodown\n")
{
struct interface *ifp;
ifp = if_lookup_vrf_all(ifname);
if (!ifp) {
vty_out(vty, "%% Can't find interface %s\n", ifname);
return CMD_WARNING;
}
if (sharp_zebra_send_interface_protodown(ifp, true) != 0)
return CMD_WARNING;
return CMD_SUCCESS;
}
DEFPY (no_sharp_interface_protodown,
no_sharp_interface_protodown_cmd,
"no sharp interface IFNAME$ifname protodown",
NO_STR
SHARP_STR
INTERFACE_STR
IFNAME_STR
"Set interface protodown\n")
{
struct interface *ifp;
ifp = if_lookup_vrf_all(ifname);
if (!ifp) {
vty_out(vty, "%% Can't find interface %s\n", ifname);
return CMD_WARNING;
}
if (sharp_zebra_send_interface_protodown(ifp, false) != 0)
return CMD_WARNING;
return CMD_SUCCESS;
}
DEFPY (tc_filter_rate,
tc_filter_rate_cmd,
"sharp tc dev IFNAME$ifname \
source <A.B.C.D/M|X:X::X:X/M>$src \
destination <A.B.C.D/M|X:X::X:X/M>$dst \
ip-protocol <tcp|udp>$ip_proto \
src-port (1-65535)$src_port \
dst-port (1-65535)$dst_port \
rate RATE$ratestr",
SHARP_STR
"Traffic control\n"
"TC interface (for qdisc, class, filter)\n"
"TC interface name\n"
"TC filter source\n"
"TC filter source IPv4 prefix\n"
"TC filter source IPv6 prefix\n"
"TC filter destination\n"
"TC filter destination IPv4 prefix\n"
"TC filter destination IPv6 prefix\n"
"TC filter IP protocol\n"
"TC filter IP protocol TCP\n"
"TC filter IP protocol UDP\n"
"TC filter source port\n"
"TC filter source port\n"
"TC filter destination port\n"
"TC filter destination port\n"
"TC rate\n"
"TC rate number (bits/s) or rate string (suffixed with Bps or bit)\n")
{
struct interface *ifp;
struct protoent *p;
uint64_t rate;
ifp = if_lookup_vrf_all(ifname);
if (!ifp) {
vty_out(vty, "%% Can't find interface %s\n", ifname);
return CMD_WARNING;
}
p = getprotobyname(ip_proto);
if (!p) {
vty_out(vty, "Unable to convert %s to proto id\n", ip_proto);
return CMD_WARNING;
}
if (tc_getrate(ratestr, &rate) != 0) {
vty_out(vty, "Unable to convert %s to rate\n", ratestr);
return CMD_WARNING;
}
if (sharp_zebra_send_tc_filter_rate(ifp, src, dst, p->p_proto, src_port,
dst_port, rate) != 0)
return CMD_WARNING;
return CMD_SUCCESS;
}
/* for testing builtin crash handler & backtrace */
DEFPY(crashme_segv,
crashme_segv_cmd,
"sharp crashtest segv",
SHARP_STR
"crashtest functions\n"
"*(int *)1 = 1\n")
{
#if defined(__COVERITY__) || defined(__clang_analyzer__)
vty_out(vty, "static analysis build, this should not happen?!\n");
#else
/* GCC is too clever, complains if it knows the pointer is just "1" */
intptr_t one = atoi("1");
*(int *)one = 1;
#endif
return CMD_SUCCESS;
}
/* for testing ASAN & Valgrind warnings */
DEFPY(crashme_uaf,
crashme_uaf_cmd,
"sharp crashtest use-after-free",
SHARP_STR
"crashtest functions\n"
"free(p); vty_out(p)\n")
{
#if defined(__COVERITY__) || defined(__clang_analyzer__)
vty_out(vty, "static analysis build, this should not happen?!\n");
#else
int *p, *f;
p = f = XCALLOC(MTYPE_TMP, sizeof(*p));
*p = 12345;
XFREE(MTYPE_TMP, p);
vty_out(vty, "use-after-free: %d\n", *f);
#endif
return CMD_SUCCESS;
}
void sharp_vty_init(void)
{
install_element(ENABLE_NODE, &install_routes_data_dump_cmd);
install_element(ENABLE_NODE, &install_routes_cmd);
install_element(ENABLE_NODE, &install_seg6_routes_cmd);
install_element(ENABLE_NODE, &install_seg6local_routes_cmd);
install_element(ENABLE_NODE, &install_seg6local_segs_routes_cmd);
install_element(ENABLE_NODE, &remove_routes_cmd);
install_element(ENABLE_NODE, &vrf_label_cmd);
install_element(ENABLE_NODE, &sharp_nht_data_dump_cmd);
install_element(ENABLE_NODE, &watch_neighbor_cmd);
install_element(ENABLE_NODE, &watch_redistribute_cmd);
install_element(ENABLE_NODE, &watch_nexthop_v6_cmd);
install_element(ENABLE_NODE, &watch_nexthop_v4_cmd);
install_element(ENABLE_NODE, &sharp_lsp_prefix_v4_cmd);
install_element(ENABLE_NODE, &sharp_remove_lsp_prefix_v4_cmd);
install_element(ENABLE_NODE, &logpump_cmd);
install_element(ENABLE_NODE, &create_session_cmd);
install_element(ENABLE_NODE, &remove_session_cmd);
install_element(ENABLE_NODE, &send_opaque_cmd);
install_element(ENABLE_NODE, &send_opaque_unicast_cmd);
install_element(ENABLE_NODE, &send_opaque_reg_cmd);
install_element(ENABLE_NODE, &send_opaque_notif_reg_cmd);
install_element(ENABLE_NODE, &neigh_discover_cmd);
install_element(ENABLE_NODE, &import_te_cmd);
install_element(ENABLE_NODE, &show_debugging_sharpd_cmd);
install_element(ENABLE_NODE, &show_sharp_ted_cmd);
install_element(ENABLE_NODE, &show_sharp_cspf_cmd);
install_element(ENABLE_NODE, &sharp_srv6_manager_get_locator_chunk_cmd);
install_element(ENABLE_NODE,
&sharp_srv6_manager_release_locator_chunk_cmd);
install_element(ENABLE_NODE, &show_sharp_segment_routing_srv6_cmd);
install_element(ENABLE_NODE, &sharp_interface_protodown_cmd);
install_element(ENABLE_NODE, &no_sharp_interface_protodown_cmd);
install_element(ENABLE_NODE, &tc_filter_rate_cmd);
install_element(ENABLE_NODE, &crashme_segv_cmd);
install_element(ENABLE_NODE, &crashme_uaf_cmd);
return;
}
|