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
|
/*
* nortel.c -- scli nortel mode implementation
*
* Copyright (C) 2001 Juergen Schoenwaelder
*
* This program 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Id: nortel.c 713 2004-10-14 20:58:06Z schoenw $
*/
#include "scli.h"
#include "snmpv2-tc.h"
#include "rapid-city.h"
#include "rapid-city-proc.h"
static GNetSnmpEnum const vlan_priority[] = {
{ SNMPV2_TC_TRUTHVALUE_TRUE, "high" },
{ SNMPV2_TC_TRUTHVALUE_FALSE, "normal" },
{ 0, NULL }
};
static void
fmt_vlanStatus(GString *s, rapid_city_rcVlanEntry_t *vlanEntry)
{
static GNetSnmpEnum const rcVlanType[] = {
{ RAPID_CITY_RCVLANTYPE_BYPORT, "P" },
{ RAPID_CITY_RCVLANTYPE_BYIPSUBNET, "I" },
{ RAPID_CITY_RCVLANTYPE_BYPROTOCOLID, "O" },
{ RAPID_CITY_RCVLANTYPE_BYSRCMAC, "S" },
{ RAPID_CITY_RCVLANTYPE_BYDSTMCAST, "D" },
{ 0, NULL }
};
static GNetSnmpEnum const rcVlanHighPriority[] = {
{ SNMPV2_TC_TRUTHVALUE_TRUE, "H" },
{ SNMPV2_TC_TRUTHVALUE_FALSE, "N" },
{ 0, NULL }
};
static GNetSnmpEnum const rcVlanRoutingEnable[] = {
{ SNMPV2_TC_TRUTHVALUE_TRUE, "R" },
{ SNMPV2_TC_TRUTHVALUE_FALSE, "N" },
{ 0, NULL }
};
static GNetSnmpEnum const rcVlanRowStatus[] = {
{ SNMPV2_TC_ROWSTATUS_ACTIVE, "A" },
{ SNMPV2_TC_ROWSTATUS_NOTINSERVICE, "S" },
{ SNMPV2_TC_ROWSTATUS_NOTREADY, "R" },
{ SNMPV2_TC_ROWSTATUS_CREATEANDGO, "G" },
{ SNMPV2_TC_ROWSTATUS_CREATEANDWAIT, "W" },
{ SNMPV2_TC_ROWSTATUS_DESTROY, "D" },
{ 0, NULL }
};
const char *e;
e = fmt_enum(rcVlanRowStatus, vlanEntry->rcVlanRowStatus);
g_string_sprintfa(s, "%s", e ? e : "-");
e = fmt_enum(rcVlanType, vlanEntry->rcVlanType);
g_string_sprintfa(s, "%s", e ? e : "-");
e = fmt_enum(rcVlanHighPriority, vlanEntry->rcVlanHighPriority);
g_string_sprintfa(s, "%s", e ? e : "-");
e = fmt_enum(rcVlanRoutingEnable, vlanEntry->rcVlanRoutingEnable);
g_string_sprintfa(s, "%s", e ? e : "-");
}
static void
vlan_error(scli_interp_t *interp,
rapid_city_rcVlanEntry_t *vlanEntry)
{
if (vlanEntry) {
g_string_sprintfa(interp->result, "vlan %d: ", vlanEntry->rcVlanId);
if (vlanEntry->rcVlanName && vlanEntry->_rcVlanNameLength) {
g_string_sprintfa(interp->result, "%.*s: ",
(int) vlanEntry->_rcVlanNameLength,
vlanEntry->rcVlanName);
}
}
}
static void
vlan_snmp_error(scli_interp_t *interp,
rapid_city_rcVlanEntry_t *vlanEntry)
{
vlan_error(interp, vlanEntry);
scli_snmp_error(interp);
g_string_append(interp->result, "\n");
}
static int
match_vlan(regex_t *regex_vlan,
rapid_city_rcVlanEntry_t *vlanEntry)
{
int status;
if (! regex_vlan) {
return 1;
}
if (vlanEntry->rcVlanName) {
char *string = g_malloc0(vlanEntry->_rcVlanNameLength + 1);
memcpy(string, vlanEntry->rcVlanName, vlanEntry->_rcVlanNameLength);
status = regexec(regex_vlan, string, (size_t) 0, NULL, 0);
g_free(string);
if (status == 0) {
return 1;
}
}
return 0;
}
static void
get_default_port_set(guchar *bits, gsize bits_len,
rapid_city_rcVlanPortEntry_t **vlanPortTable,
guint32 vlanid)
{
int i;
for (i = 0; vlanPortTable[i]; i++) {
if (vlanPortTable[i]->rcVlanPortDefaultVlanId
&& *vlanPortTable[i]->rcVlanPortDefaultVlanId == vlanid) {
int p = vlanPortTable[i]->rcVlanPortIndex;
if (p/8 < bits_len) {
bits[p/8] |= 1 << (7-(p%8));
}
}
}
}
static void
xml_port_set(xmlNodePtr root, guchar *bits, gsize bits_len)
{
int bit, i;
xmlNodePtr node;
for (i = 0; i < bits_len * 8; i++) {
bit = bits[i/8] & 1 << (7-(i%8));
if (bit) {
node = xmlNewChild(root, NULL, "port", NULL);
xml_set_prop(node, "number", "%d", i);
}
}
}
static void
fmt_id_list(GString *s, guchar *ids, gint32 numids)
{
int i, cnt;
int first = -1;
int last = -1;
int port;
for (i = 0, cnt = 0; i < numids; i++) {
port = ids[i*2] * 256 + ids[i*2+1];
if (first < 0) {
first = port;
} else {
if (last+1 != port) {
if (first == last) {
g_string_sprintfa(s, "%s%d", cnt ? "," : "", first);
} else {
g_string_sprintfa(s, "%s%d-%d", cnt ? "," : "", first, last);
}
first = port;
cnt++;
}
}
last = port;
}
if (first == last) {
g_string_sprintfa(s, "%s%d", cnt ? "," : "", first);
} else {
g_string_sprintfa(s, "%s%d-%d", cnt ? "," : "", first, last);
}
}
static int
get_vlan_name_width(rapid_city_rcVlanEntry_t **vlanTable)
{
int i, name_width = 6;
if (vlanTable) {
for (i = 0; vlanTable[i]; i++) {
if (vlanTable[i]->_rcVlanNameLength > name_width) {
name_width = vlanTable[i]->_rcVlanNameLength;
}
}
}
return name_width;
}
static void
xml_nortel_bridge_vlan_details(xmlNodePtr root,
rapid_city_rcVlanEntry_t *vlanEntry,
rapid_city_rcVlanPortEntry_t **vlanPortTable)
{
xmlNodePtr tree, node;
const char *s;
tree = xmlNewChild(root, NULL, "vlan", NULL);
xml_set_prop(tree, "vlanid", "%d", vlanEntry->rcVlanId);
if (vlanEntry->rcVlanName) {
node = xmlNewChild(tree, NULL, "name", NULL);
xml_set_content(node, "%.*s",
(int) vlanEntry->_rcVlanNameLength,
vlanEntry->rcVlanName);
}
s = fmt_enum(rapid_city_enums_rcVlanType, vlanEntry->rcVlanType);
if (s) {
node = xmlNewChild(tree, NULL, "type", s);
}
s = fmt_enum(vlan_priority, vlanEntry->rcVlanHighPriority);
if (s) {
node = xmlNewChild(tree, NULL, "priority", s);
}
s = fmt_enum(snmpv2_tc_enums_TruthValue,
vlanEntry->rcVlanRoutingEnable);
if (s) {
node = xmlNewChild(tree, NULL, "routing", s);
}
s = fmt_enum(snmpv2_tc_enums_RowStatus,
vlanEntry->rcVlanRowStatus);
if (s) {
node = xmlNewChild(tree, NULL, "status", s);
}
if (vlanEntry->rcVlanType
&& *vlanEntry->rcVlanType == RAPID_CITY_RCVLANTYPE_BYPORT) {
if (vlanEntry->rcVlanPortMembers) {
node = xmlNewChild(tree, NULL, "member", NULL);
xml_port_set(node, vlanEntry->rcVlanPortMembers, 32);
}
if (vlanEntry->rcVlanActiveMembers) {
node = xmlNewChild(tree, NULL, "active", NULL);
xml_port_set(node, vlanEntry->rcVlanActiveMembers, 32);
}
if (vlanEntry->rcVlanStaticMembers) {
node = xmlNewChild(tree, NULL, "static", NULL);
xml_port_set(node, vlanEntry->rcVlanStaticMembers, 32);
}
if (vlanEntry->rcVlanNotAllowToJoin) {
node = xmlNewChild(tree, NULL, "disallowed", NULL);
xml_port_set(node, vlanEntry->rcVlanNotAllowToJoin, 32);
}
}
if (vlanPortTable) {
guchar bits[32];
memset(bits, 0, sizeof(bits));
get_default_port_set(bits, sizeof(bits),
vlanPortTable, (guint32) vlanEntry->rcVlanId);
node = xmlNewChild(tree, NULL, "default", NULL);
xml_port_set(node, bits, sizeof(bits));
}
}
static void
fmt_nortel_bridge_vlan_details(GString *s,
rapid_city_rcVlanEntry_t *vlanEntry,
rapid_city_rcVlanPortEntry_t **vlanPortTable)
{
const int width = 20;
const char *e;
g_string_sprintfa(s, "VLan: %-*d", width, vlanEntry->rcVlanId);
if (vlanEntry->rcVlanName && vlanEntry->_rcVlanNameLength) {
g_string_sprintfa(s, " Name: %.*s\n",
(int) vlanEntry->_rcVlanNameLength,
vlanEntry->rcVlanName);
} else {
g_string_append(s, " Name:\n");
}
e = fmt_enum(vlan_priority, vlanEntry->rcVlanHighPriority);
g_string_sprintfa(s, "Priority: %-*s", width, e ? e : "");
e = fmt_enum(snmpv2_tc_enums_RowStatus,
vlanEntry->rcVlanRowStatus);
g_string_sprintfa(s, " Status: %-*s\n", width, e ? e : "");
e = fmt_enum(snmpv2_tc_enums_TruthValue,
vlanEntry->rcVlanRoutingEnable);
g_string_sprintfa(s, "Routing: %-*s", width, e ? e : "");
e = fmt_enum(rapid_city_enums_rcVlanType,
vlanEntry->rcVlanType);
g_string_sprintfa(s, " Type: %-*s", width, e ? e : "");
if (vlanEntry->rcVlanType
&& *vlanEntry->rcVlanType == RAPID_CITY_RCVLANTYPE_BYPORT) {
if (vlanEntry->rcVlanPortMembers) {
g_string_append(s, "\nMember: ");
fmt_port_set(s, vlanEntry->rcVlanPortMembers, 32);
g_string_append(s, "\n");
} else {
g_string_append(s, "\n");
}
if (vlanEntry->rcVlanActiveMembers) {
g_string_append(s, "Allowed: ");
fmt_port_set(s, vlanEntry->rcVlanActiveMembers, 32);
g_string_append(s, "\n");
} else {
g_string_append(s, "\n");
}
if (vlanEntry->rcVlanStaticMembers) {
g_string_append(s, "Static: ");
fmt_port_set(s, vlanEntry->rcVlanStaticMembers, 32);
g_string_append(s, "\n");
} else {
g_string_append(s, "\n");
}
if (vlanEntry->rcVlanNotAllowToJoin) {
g_string_append(s, "Disallowed: ");
fmt_port_set(s, vlanEntry->rcVlanNotAllowToJoin, 32);
g_string_append(s, "\n");
} else {
g_string_append(s, "\n");
}
}
if (vlanPortTable) {
guchar bits[32];
memset(bits, 0, sizeof(bits));
get_default_port_set(bits, sizeof(bits),
vlanPortTable, (guint32) vlanEntry->rcVlanId);
g_string_append(s, "Default: ");
fmt_port_set(s, bits, sizeof(bits));
g_string_append(s, "\n");
}
if (vlanEntry->rcVlanType
&& (*vlanEntry->rcVlanType
== RAPID_CITY_RCVLANTYPE_BYPROTOCOLID)) {
if (vlanEntry->rcVlanProtocolId) {
e = fmt_enum(rapid_city_enums_rcVlanProtocolId,
vlanEntry->rcVlanProtocolId);
g_string_sprintfa(s, " Protocol: %s\n", e ? e : "");
} else {
g_string_append(s, "\n");
}
}
}
static int
show_nortel_bridge_vlan_details(scli_interp_t *interp, int argc, char **argv)
{
rapid_city_rcVlanEntry_t **vlanTable = NULL;
rapid_city_rcVlanPortEntry_t **vlanPortTable = NULL;
regex_t _regex_vlan, *regex_vlan = NULL;
int i, c;
const int mask = (RAPID_CITY_RCVLANNAME
| RAPID_CITY_RCVLANTYPE
| RAPID_CITY_RCVLANHIGHPRIORITY
| RAPID_CITY_RCVLANROUTINGENABLE
| RAPID_CITY_RCVLANROWSTATUS
| RAPID_CITY_RCVLANPORTMEMBERS
| RAPID_CITY_RCVLANACTIVEMEMBERS
| RAPID_CITY_RCVLANSTATICMEMBERS
| RAPID_CITY_RCVLANNOTALLOWTOJOIN
| RAPID_CITY_RCVLANPROTOCOLID);
g_return_val_if_fail(interp, SCLI_ERROR);
if (argc > 2) {
return SCLI_SYNTAX_NUMARGS;
}
if (argc == 2) {
regex_vlan = &_regex_vlan;
if (regcomp(regex_vlan, argv[1], interp->regex_flags) != 0) {
g_string_assign(interp->result, argv[1]);
return SCLI_SYNTAX_REGEXP;
}
}
if (scli_interp_dry(interp)) {
if (regex_vlan) regfree(regex_vlan);
return SCLI_OK;
}
rapid_city_get_rcVlanTable(interp->peer, &vlanTable, mask);
if (interp->peer->error_status) {
if (regex_vlan) regfree(regex_vlan);
return SCLI_SNMP;
}
if (vlanTable) {
rapid_city_get_rcVlanPortTable(interp->peer, &vlanPortTable,
RAPID_CITY_RCVLANPORTDEFAULTVLANID);
for (i = 0, c = 0; vlanTable[i]; i++) {
if (match_vlan(regex_vlan, vlanTable[i])) {
if (scli_interp_xml(interp)) {
xml_nortel_bridge_vlan_details(interp->xml_node,
vlanTable[i],
vlanPortTable);
} else {
if (c) {
g_string_append(interp->result, "\n");
}
fmt_nortel_bridge_vlan_details(interp->result,
vlanTable[i],
vlanPortTable);
c++;
}
}
}
}
if (vlanTable) rapid_city_free_rcVlanTable(vlanTable);
if (regex_vlan) regfree(regex_vlan);
return SCLI_OK;
}
static void
fmt_nortel_bridge_vlan_info(GString *s,
rapid_city_rcVlanEntry_t *vlanEntry,
int name_width)
{
g_string_sprintfa(s, "%4d ", vlanEntry->rcVlanId);
fmt_vlanStatus(s, vlanEntry);
if (vlanEntry->rcVlanName && vlanEntry->_rcVlanNameLength) {
g_string_sprintfa(s, " %-*.*s ", name_width,
(int) vlanEntry->_rcVlanNameLength,
vlanEntry->rcVlanName);
} else {
g_string_sprintfa(s, " %*s ", name_width, "");
}
if (vlanEntry->rcVlanPortMembers) {
fmt_port_set(s, vlanEntry->rcVlanPortMembers, 32);
}
g_string_append(s, "\n");
}
static int
show_nortel_bridge_vlan_info(scli_interp_t *interp, int argc, char **argv)
{
rapid_city_rcVlanEntry_t **vlanTable = NULL;
regex_t _regex_vlan, *regex_vlan = NULL;
int i, name_width;
const int mask = (RAPID_CITY_RCVLANNAME
| RAPID_CITY_RCVLANTYPE
| RAPID_CITY_RCVLANHIGHPRIORITY
| RAPID_CITY_RCVLANROUTINGENABLE
| RAPID_CITY_RCVLANROWSTATUS
| RAPID_CITY_RCVLANPORTMEMBERS);
g_return_val_if_fail(interp, SCLI_ERROR);
if (argc > 2) {
return SCLI_SYNTAX_NUMARGS;
}
if (argc == 2) {
regex_vlan = &_regex_vlan;
if (regcomp(regex_vlan, argv[1], interp->regex_flags) != 0) {
g_string_assign(interp->result, argv[1]);
return SCLI_SYNTAX_REGEXP;
}
}
if (scli_interp_dry(interp)) {
if (regex_vlan) regfree(regex_vlan);
return SCLI_OK;
}
rapid_city_get_rcVlanTable(interp->peer, &vlanTable, mask);
if (interp->peer->error_status) {
if (regex_vlan) regfree(regex_vlan);
return SCLI_SNMP;
}
name_width = get_vlan_name_width(vlanTable);
if (vlanTable) {
g_string_sprintfa(interp->header,
"VLAN STATUS %-*s PORTS", name_width, "NAME");
for (i = 0; vlanTable[i]; i++) {
if (match_vlan(regex_vlan, vlanTable[i])) {
fmt_nortel_bridge_vlan_info(interp->result, vlanTable[i],
name_width);
}
}
}
if (vlanTable) rapid_city_free_rcVlanTable(vlanTable);
if (regex_vlan) regfree(regex_vlan);
return SCLI_OK;
}
static void
fmt_nortel_bridge_vlan_port(GString *s,
rapid_city_rcVlanPortEntry_t *vlanPortEntry)
{
static GNetSnmpEnum const rapid_city_enums_rcVlanPortType[] = {
{ RAPID_CITY_RCVLANPORTTYPE_ACCESS, "A" },
{ RAPID_CITY_RCVLANPORTTYPE_TRUNK, "T" },
{ 0, NULL }
};
static GNetSnmpEnum const rcVlanPortPerformTagging[] = {
{ SNMPV2_TC_TRUTHVALUE_TRUE, "T" },
{ SNMPV2_TC_TRUTHVALUE_FALSE, "N" },
{ 0, NULL }
};
static GNetSnmpEnum const rcVlanPortDiscardTaggedFrames[] = {
{ SNMPV2_TC_TRUTHVALUE_TRUE, "D" },
{ SNMPV2_TC_TRUTHVALUE_FALSE, "N" },
{ 0, NULL }
};
static GNetSnmpEnum const rcVlanPortDiscardUntaggedFrames[] = {
{ SNMPV2_TC_TRUTHVALUE_TRUE, "D" },
{ SNMPV2_TC_TRUTHVALUE_FALSE, "N" },
{ 0, NULL }
};
const char *e;
g_string_sprintfa(s, "%5u ", vlanPortEntry->rcVlanPortIndex);
e = fmt_enum(rapid_city_enums_rcVlanPortType,
vlanPortEntry->rcVlanPortType);
g_string_sprintfa(s, "%s", e ? e : "-");
e = fmt_enum(rcVlanPortPerformTagging,
vlanPortEntry->rcVlanPortPerformTagging);
g_string_sprintfa(s, "%s", e ? e : "-");
e = fmt_enum(rcVlanPortDiscardTaggedFrames,
vlanPortEntry->rcVlanPortDiscardTaggedFrames);
g_string_sprintfa(s, "%s", e ? e : "-");
e = fmt_enum(rcVlanPortDiscardUntaggedFrames,
vlanPortEntry->rcVlanPortDiscardUntaggedFrames);
g_string_sprintfa(s, "%s", e ? e : "-");
if (vlanPortEntry->rcVlanPortDefaultVlanId) {
g_string_sprintfa(s, " %5u ",
*vlanPortEntry->rcVlanPortDefaultVlanId);
}
if (vlanPortEntry->rcVlanPortNumVlanIds
&& vlanPortEntry->rcVlanPortVlanIds) {
fmt_id_list(s, vlanPortEntry->rcVlanPortVlanIds,
*vlanPortEntry->rcVlanPortNumVlanIds);
}
g_string_sprintfa(s, "\n");
}
static int
show_nortel_bridge_vlan_ports(scli_interp_t *interp, int argc, char **argv)
{
rapid_city_rcVlanPortEntry_t **vlanPortTable = NULL;
int i;
g_return_val_if_fail(interp, SCLI_ERROR);
if (argc > 1) {
return SCLI_SYNTAX_NUMARGS;
}
if (scli_interp_dry(interp)) {
return SCLI_OK;
}
rapid_city_get_rcVlanPortTable(interp->peer, &vlanPortTable, 0);
if (interp->peer->error_status) {
return SCLI_SNMP;
}
if (vlanPortTable) {
g_string_sprintfa(interp->header, " PORT FLAGS DEFAULT VLANS");
for (i = 0; vlanPortTable[i]; i++) {
fmt_nortel_bridge_vlan_port(interp->result, vlanPortTable[i]);
}
}
if (vlanPortTable) rapid_city_free_rcVlanPortTable(vlanPortTable);
return SCLI_OK;
}
static int
create_nortel_bridge_vlan(scli_interp_t *interp, int argc, char **argv)
{
gint32 vlanId;
char *end, *name;
size_t name_len;
g_return_val_if_fail(interp, SCLI_ERROR);
if (argc != 3) {
return SCLI_SYNTAX_NUMARGS;
}
vlanId = strtol(argv[1], &end, 0);
if (*end || vlanId < 0) {
g_string_assign(interp->result, argv[1]);
return SCLI_SYNTAX_NUMBER;
}
name = argv[2];
name_len = strlen(name);
if (name_len < RAPID_CITY_RCVLANNAMEMINLENGTH
|| name_len > RAPID_CITY_RCVLANNAMEMAXLENGTH) {
g_string_assign(interp->result, name);
return SCLI_SYNTAX_VALUE;
}
if (scli_interp_dry(interp)) {
return SCLI_OK;
}
rapid_city_proc_create_vlan(interp->peer, vlanId, name, name_len,
RAPID_CITY_RCVLANTYPE_BYPORT);
if (interp->peer->error_status) {
return SCLI_SNMP;
}
return SCLI_OK;
}
static int
delete_nortel_bridge_vlan(scli_interp_t *interp, int argc, char **argv)
{
rapid_city_rcVlanEntry_t **vlanTable = NULL;
regex_t _regex_vlan, *regex_vlan = NULL;
int i;
g_return_val_if_fail(interp, SCLI_ERROR);
if (argc != 2) {
return SCLI_SYNTAX_NUMARGS;
}
regex_vlan = &_regex_vlan;
if (regcomp(regex_vlan, argv[1], interp->regex_flags) != 0) {
g_string_assign(interp->result, argv[1]);
return SCLI_SYNTAX_REGEXP;
}
if (scli_interp_dry(interp)) {
regfree(regex_vlan);
return SCLI_OK;
}
rapid_city_get_rcVlanTable(interp->peer, &vlanTable,
RAPID_CITY_RCVLANNAME);
if (interp->peer->error_status) {
regfree(regex_vlan);
return SCLI_SNMP;
}
if (vlanTable) {
for (i = 0; vlanTable[i]; i++) {
if (match_vlan(regex_vlan, vlanTable[i])) {
rapid_city_proc_delete_vlan(interp->peer,
vlanTable[i]->rcVlanId);
if (interp->peer->error_status) {
vlan_snmp_error(interp, vlanTable[i]);
}
}
}
}
if (vlanTable) rapid_city_free_rcVlanTable(vlanTable);
regfree(regex_vlan);
return SCLI_OK;
}
static int
set_nortel_bridge_vlan_name(scli_interp_t *interp, int argc, char **argv)
{
rapid_city_rcVlanEntry_t *vlanEntry = NULL;
gint32 vlanId;
char *end, *name;
size_t name_len;
g_return_val_if_fail(interp, SCLI_ERROR);
if (argc != 3) {
return SCLI_SYNTAX_NUMARGS;
}
vlanId = strtol(argv[1], &end, 0);
if (*end || vlanId < 0) {
g_string_assign(interp->result, argv[1]);
return SCLI_SYNTAX_NUMBER;
}
name = argv[2];
name_len = strlen(name);
if (name_len < RAPID_CITY_RCVLANNAMEMINLENGTH
|| name_len > RAPID_CITY_RCVLANNAMEMAXLENGTH) {
g_string_assign(interp->result, name);
return SCLI_SYNTAX_VALUE;
}
if (scli_interp_dry(interp)) {
return SCLI_OK;
}
rapid_city_get_rcVlanEntry(interp->peer, &vlanEntry, vlanId,
RAPID_CITY_RCVLANNAME);
if (interp->peer->error_status) {
return SCLI_SNMP;
}
if (vlanEntry) {
vlanEntry->rcVlanName = name;
vlanEntry->_rcVlanNameLength = name_len;
rapid_city_set_rcVlanEntry(interp->peer, vlanEntry,
RAPID_CITY_RCVLANNAME);
if (interp->peer->error_status) {
rapid_city_free_rcVlanEntry(vlanEntry);
return SCLI_SNMP;
}
}
if (vlanEntry) rapid_city_free_rcVlanEntry(vlanEntry);
return SCLI_OK;
}
static int
set_nortel_bridge_vlan_ports(scli_interp_t *interp, int argc, char **argv)
{
rapid_city_rcVlanEntry_t **vlanTable = NULL;
regex_t _regex_vlan, *regex_vlan = NULL;
guchar ports[32];
int i;
g_return_val_if_fail(interp, SCLI_ERROR);
if (argc != 3) {
return SCLI_SYNTAX_NUMARGS;
}
regex_vlan = &_regex_vlan;
if (regcomp(regex_vlan, argv[1], interp->regex_flags) != 0) {
g_string_assign(interp->result, argv[1]);
return SCLI_SYNTAX_REGEXP;
}
if (scan_port_set(ports, sizeof(ports), argv[2]) != SCLI_OK) {
if (regex_vlan) regfree(regex_vlan);
g_string_assign(interp->result, argv[2]);
return SCLI_SYNTAX_VALUE;
}
if (scli_interp_dry(interp)) {
if (regex_vlan) regfree(regex_vlan);
return SCLI_OK;
}
rapid_city_get_rcVlanTable(interp->peer, &vlanTable, RAPID_CITY_RCVLANNAME);
if (interp->peer->error_status) {
if (regex_vlan) regfree(regex_vlan);
return SCLI_SNMP;
}
if (vlanTable) {
for (i = 0; vlanTable[i]; i++) {
if (match_vlan(regex_vlan, vlanTable[i])) {
rapid_city_proc_set_vlan_port_member(interp->peer,
vlanTable[i]->rcVlanId,
ports);
if (interp->peer->error_status) {
vlan_snmp_error(interp, vlanTable[i]);
}
}
}
}
if (vlanTable) rapid_city_free_rcVlanTable(vlanTable);
if (regex_vlan) regfree(regex_vlan);
return SCLI_OK;
}
static int
set_nortel_bridge_vlan_default(scli_interp_t *interp, int argc, char **argv)
{
rapid_city_rcVlanEntry_t **vlanTable = NULL;
guchar ports[32];
int i, port, bit;
g_return_val_if_fail(interp, SCLI_ERROR);
if (argc != 3) {
return SCLI_SYNTAX_NUMARGS;
}
if (scan_port_set(ports, sizeof(ports), argv[2]) != SCLI_OK) {
g_string_assign(interp->result, argv[2]);
return SCLI_SYNTAX_VALUE;
}
if (scli_interp_dry(interp)) {
return SCLI_OK;
}
rapid_city_get_rcVlanTable(interp->peer, &vlanTable, RAPID_CITY_RCVLANNAME);
if (interp->peer->error_status) {
return SCLI_SNMP;
}
if (vlanTable) {
size_t len = strlen(argv[1]);
for (i = 0; vlanTable[i]; i++) {
if (vlanTable[i]->rcVlanName
&& vlanTable[i]->_rcVlanNameLength == len
&& memcmp(vlanTable[i]->rcVlanName, argv[1], len) == 0) {
break;
}
}
if (! vlanTable[i]) {
g_string_sprintfa(interp->result, "no vlan with this name");
rapid_city_free_rcVlanTable(vlanTable);
return SCLI_ERROR;
}
for (port = 0; port < 32 * 8; port++) {
bit = ports[port/8] & 1 << (7-(port%8));
if (bit) {
rapid_city_proc_set_vlan_port_default(interp->peer, port,
vlanTable[i]->rcVlanId);
if (interp->peer->error_status) {
vlan_snmp_error(interp, vlanTable[i]);
}
}
}
}
if (vlanTable) rapid_city_free_rcVlanTable(vlanTable);
return SCLI_OK;
}
static int
dump_nortel_bridge_vlan(scli_interp_t *interp, int argc, char **argv)
{
rapid_city_rcVlanEntry_t **vlanTable = NULL;
int i;
const int mask = (RAPID_CITY_RCVLANNAME
| RAPID_CITY_RCVLANTYPE
| RAPID_CITY_RCVLANPORTMEMBERS);
g_return_val_if_fail(interp, SCLI_ERROR);
if (argc > 1) {
return SCLI_SYNTAX_NUMARGS;
}
if (scli_interp_dry(interp)) {
return SCLI_OK;
}
rapid_city_get_rcVlanTable(interp->peer, &vlanTable, mask);
if (interp->peer->error_status) {
return SCLI_SNMP;
}
if (vlanTable) {
for (i = 0; vlanTable[i]; i++) {
if (! vlanTable[i]->rcVlanName) {
continue;
}
g_string_sprintfa(interp->result,
"create nortel bridge vlan \"%u\" \"%.*s\"\n",
vlanTable[i]->rcVlanId,
(int) vlanTable[i]->_rcVlanNameLength,
vlanTable[i]->rcVlanName);
}
g_string_append(interp->result, "\n");
for (i = 0; vlanTable[i]; i++) {
if (! vlanTable[i]->rcVlanName) {
continue;
}
if (vlanTable[i]->rcVlanPortMembers) {
g_string_sprintfa(interp->result,
"set nortel bridge vlan ports \"%.*s\" \"",
(int) vlanTable[i]->_rcVlanNameLength,
vlanTable[i]->rcVlanName);
fmt_port_set(interp->result, vlanTable[i]->rcVlanPortMembers, 32);
g_string_sprintfa(interp->result, "\"\n");
}
}
}
if (vlanTable) rapid_city_free_rcVlanTable(vlanTable);
return SCLI_OK;
}
void
scli_init_nortel_mode(scli_interp_t *interp)
{
static scli_cmd_t cmds[] = {
{ "create nortel bridge vlan", "<vlanid> <name>",
"The `create nortel bridge vlan' command is used to create a\n"
"new virtual LAN with the given <vlanid> and <name>.",
SCLI_CMD_FLAG_NEED_PEER | SCLI_CMD_FLAG_DRY | SCLI_CMD_FLAG_NORECURSE,
NULL, NULL,
create_nortel_bridge_vlan },
{ "delete nortel bridge vlan", "<regexp>",
"The `delete nortel bridge vlan' command deletes all selected\n"
"virtual LANs. The regular expression <regexp> is matched\n"
"against the virtual LAN names to select the vlans that should\n"
"be deleted.",
SCLI_CMD_FLAG_NEED_PEER | SCLI_CMD_FLAG_DRY | SCLI_CMD_FLAG_NORECURSE,
NULL, NULL,
delete_nortel_bridge_vlan },
{ "set nortel bridge vlan name", "<vlanid> <name>",
"The `set nortel bridge vlan name' command changes the name of\n"
"a virtual LAN.",
SCLI_CMD_FLAG_NEED_PEER | SCLI_CMD_FLAG_DRY | SCLI_CMD_FLAG_NORECURSE,
NULL, NULL,
set_nortel_bridge_vlan_name },
{ "set nortel bridge vlan ports", "<regexp> <ports>",
"The `set nortel bridge vlan ports' command allows to assign\n"
"ports to port-based vlans. The regular expression <regexp>\n"
"is matched against the vlan names to select the vlans that\n"
"should be modified. The <ports> argument contains a comma\n"
"separated list of port numbers or port number ranges, e.g.\n"
"1,5,7-8.",
SCLI_CMD_FLAG_NEED_PEER | SCLI_CMD_FLAG_DRY | SCLI_CMD_FLAG_NORECURSE,
NULL, NULL,
set_nortel_bridge_vlan_ports },
{ "set nortel bridge vlan default", "<string> <ports>",
"The `set nortel bridge vlan default' command allows to assign\n"
"ports to a default vlan. The <string> argument is matched\n"
"against the vlan names to select the vlan. The <ports> argument\n"
"contains a comma separated list of port numbers or port number\n"
"ranges, e.g. 1,5,7-8.",
SCLI_CMD_FLAG_NEED_PEER | SCLI_CMD_FLAG_DRY | SCLI_CMD_FLAG_NORECURSE,
NULL, NULL,
set_nortel_bridge_vlan_default },
{ "show nortel bridge vlan info", "[<regexp>]",
"The `show nortel bridge vlan info' command shows summary\n"
"information about all selected virtual LANs. The optional\n"
"regular expression <regexp> is matched against the virtual\n"
"LAN names to select the virtual LANs of interest. The\n"
"command generates a table with the following columns:\n"
"\n"
" VLAN number of the virtual LAN\n"
" STATUS status of the virtual LAN (see below)\n"
" NAME name of the virtual LAN\n"
" PORTS ports assigned to the virtual LAN\n"
"\n"
"The status is encoded in four characters. The first character\n"
"indicates the status of the row (A=active, S=not in service,\n"
"R=not ready). The second character indicates virtual LAN type\n"
"(P=port, I=IP-subnet, O=protocol, S=src address, D=dst address).\n"
"The third character indicates the priority of the virtual LAN\n"
"(H=high, N=normal) and the fourth character indicates whether\n"
"routing is enabled (R=routing, N=no routing).",
SCLI_CMD_FLAG_NEED_PEER | SCLI_CMD_FLAG_DRY,
NULL, NULL,
show_nortel_bridge_vlan_info },
{ "show nortel bridge vlan details", "[<regexp>]",
"The `show nortel bridge vlan details' command describes the\n"
"selected vlans in more detail. The optional regular expression\n"
"<regexp> is matched against the vlan names to select the vlans\n"
"of interest.",
SCLI_CMD_FLAG_NEED_PEER | SCLI_CMD_FLAG_XML | SCLI_CMD_FLAG_DRY,
"nortel bridge vlans", NULL,
show_nortel_bridge_vlan_details },
{ "show nortel bridge vlan ports", NULL,
"The `show nortel bridge vlan ports' command shows information\n"
"for each vlan port. The command generates a table with the\n"
"following columns:\n"
"\n"
" PORT port number\n"
" FLAGS port vlan flags (see below)\n"
" DEFAULT default vlan number\n"
" VLANS vlan numbers the port is member of\n"
"\n"
"The flags are encoded in four characters. The first character\n"
"indicates the port type (A=access, T=trunk). The second character\n"
"indicates whether the port tags frames (T=tagging, N=none). The\n"
"third character indicates whether the port discards tagged frames\n"
"(D=discard, N=none) and the fourth character indicates whether\n"
"the port discards untagged frames (D=discard, N=none).",
SCLI_CMD_FLAG_NEED_PEER | SCLI_CMD_FLAG_DRY,
NULL, NULL,
show_nortel_bridge_vlan_ports },
{ "dump nortel bridge vlan", NULL,
"The `dump nortel bridge vlan' command generates a sequence of scli\n"
"commands which can be used to restore the virtual LAN configuration.",
SCLI_CMD_FLAG_NEED_PEER | SCLI_CMD_FLAG_DRY,
NULL, NULL,
dump_nortel_bridge_vlan },
{ NULL, NULL, NULL, 0, NULL, NULL, NULL }
};
static scli_mode_t nortel_mode = {
"nortel",
"The nortel scli mode allows to manipulate virtual LANs (vlans)\n"
"on nortel bridges. It is based on the RAPID-CITY MIB which\n"
"is implemented at least on the baystack bridges.",
cmds
};
scli_register_mode(interp, &nortel_mode);
}
|