1/*-
2 * Copyright (c) 2006 Shteryana Shopova <syrinx@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 12 unchanged lines hidden (view full) ---
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * Bridge MIB implementation for SNMPd.
27 * Bridge ports.
28 *
29 * $FreeBSD: head/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_port.c 165253 2006-12-15 20:01:57Z syrinx $
30 */
31
32#include <sys/queue.h>
33#include <sys/socket.h>
34#include <sys/types.h>
35
36#include <net/ethernet.h>
37#include <net/if.h>
--- 317 unchanged lines hidden (view full) ---
355
356 switch (op) {
357 case SNMP_OP_GET:
358 if (val->var.len - sub != 1)
359 return (SNMP_ERR_NOSUCHNAME);
360 if ((bp = bridge_port_find(val->var.subs[sub],
361 bif)) == NULL)
362 return (SNMP_ERR_NOSUCHNAME);
363 goto get;
364
365 case SNMP_OP_GETNEXT:
366 if (val->var.len - sub == 0) {
367 if ((bp = bridge_port_bif_first(bif)) == NULL)
368 return (SNMP_ERR_NOSUCHNAME);
369 } else {
370 if ((bp = bridge_port_find(val->var.subs[sub],
371 bif)) == NULL ||
372 (bp = bridge_port_bif_next(bp)) == NULL)
373 return (SNMP_ERR_NOSUCHNAME);
374 }
375 val->var.len = sub + 1;
376 val->var.subs[sub] = bp->port_no;
377 goto get;
378
379 case SNMP_OP_SET:
380 return (SNMP_ERR_NOT_WRITEABLE);
381
382 case SNMP_OP_ROLLBACK:
383 case SNMP_OP_COMMIT:
384 break;
385 }
386 abort();
387
388get:
389 switch (val->var.subs[sub - 1]) {
390 case LEAF_dot1dBasePort:
391 val->v.integer = bp->port_no;
392 return (SNMP_ERR_NOERROR);
393
394 case LEAF_dot1dBasePortIfIndex:
395 val->v.integer = bp->if_idx;
396 return (SNMP_ERR_NOERROR);
397
398 case LEAF_dot1dBasePortCircuit:
399 val->v.oid = bp->circuit;
400 return (SNMP_ERR_NOERROR);
401
402 case LEAF_dot1dBasePortDelayExceededDiscards:
403 val->v.uint32 = bp->dly_ex_drops;
404 return (SNMP_ERR_NOERROR);
405
406 case LEAF_dot1dBasePortMtuExceededDiscards:
407 val->v.uint32 = bp->dly_mtu_drops;
408 return (SNMP_ERR_NOERROR);
409 }
410
411 abort();
412}
413
414int
415op_dot1d_stp_port(struct snmp_context *ctx, struct snmp_value *val,
416 uint sub, uint iidx __unused, enum snmp_op op)
417{
418 struct bridge_if *bif;
419 struct bridge_port *bp;
420
421 if ((bif = bridge_get_default()) == NULL)
422 return (SNMP_ERR_NOSUCHNAME);
423
424 if (time(NULL) - bif->ports_age > bridge_get_data_maxage() &&
425 bridge_update_memif(bif) <= 0)
426 return (SNMP_ERR_NOSUCHNAME);
427
428 switch (op) {
429 case SNMP_OP_GET:
430 if (val->var.len - sub != 1)
431 return (SNMP_ERR_NOSUCHNAME);
432 if ((bp = bridge_port_find(val->var.subs[sub],
433 bif)) == NULL)
434 return (SNMP_ERR_NOSUCHNAME);
435 goto get;
436
437 case SNMP_OP_GETNEXT:
438 if (val->var.len - sub == 0) {
439 if ((bp = bridge_port_bif_first(bif)) == NULL)
440 return (SNMP_ERR_NOSUCHNAME);
441 } else {
442 if ((bp = bridge_port_find(val->var.subs[sub],
443 bif)) == NULL ||
444 (bp = bridge_port_bif_next(bp)) == NULL)
445 return (SNMP_ERR_NOSUCHNAME);
446 }
447 val->var.len = sub + 1;
448 val->var.subs[sub] = bp->port_no;
449 goto get;
450
451 case SNMP_OP_SET:
452 if (val->var.len - sub != 1)
453 return (SNMP_ERR_NOSUCHNAME);
454 if ((bp = bridge_port_find(val->var.subs[sub],
455 bif)) == NULL)
456 return (SNMP_ERR_NOSUCHNAME);
457
458 switch (val->var.subs[sub - 1]) {
459 case LEAF_dot1dStpPortPriority:
460 if (val->v.integer < 0 || val->v.integer > 255)
461 return (SNMP_ERR_WRONG_VALUE);
462
463 ctx->scratch->int1 = bp->priority;
464 if (bridge_port_set_priority(bif->bif_name, bp,
465 val->v.integer) < 0)
466 return (SNMP_ERR_GENERR);
467 return (SNMP_ERR_NOERROR);
468
469 case LEAF_dot1dStpPortEnable:
470 if (val->v.integer != dot1dStpPortEnable_enabled &&
471 val->v.integer != dot1dStpPortEnable_disabled)
472 return (SNMP_ERR_WRONG_VALUE);
473
474 ctx->scratch->int1 = bp->enable;
475 if (bridge_port_set_stp_enable(bif->bif_name,
476 bp, val->v.integer) < 0)
477 return (SNMP_ERR_GENERR);
478 return (SNMP_ERR_NOERROR);
479
480 case LEAF_dot1dStpPortPathCost:
481 if (val->v.integer < SNMP_PORT_MIN_PATHCOST ||
482 val->v.integer > SNMP_PORT_MAX_PATHCOST)
483 return (SNMP_ERR_WRONG_VALUE);
484
485 ctx->scratch->int1 = bp->path_cost;
486 if (bridge_port_set_path_cost(bif->bif_name, bp,
487 val->v.integer) < 0)
488 return (SNMP_ERR_GENERR);
489 return (SNMP_ERR_NOERROR);
490
491 case LEAF_dot1dStpPort:
492 case LEAF_dot1dStpPortState:
493 case LEAF_dot1dStpPortDesignatedRoot:
494 case LEAF_dot1dStpPortDesignatedCost:
495 case LEAF_dot1dStpPortDesignatedBridge:
496 case LEAF_dot1dStpPortDesignatedPort:
497 case LEAF_dot1dStpPortForwardTransitions:
498 return (SNMP_ERR_NOT_WRITEABLE);
499 }
500 abort();
501
502 case SNMP_OP_ROLLBACK:
503 if ((bp = bridge_port_find(val->var.subs[sub],
504 bif)) == NULL)
505 return (SNMP_ERR_GENERR);
506 switch (val->var.subs[sub - 1]) {
507 case LEAF_dot1dStpPortPriority:
508 bridge_port_set_priority(bif->bif_name, bp,
--- 7 unchanged lines hidden (view full) ---
516 bridge_port_set_path_cost(bif->bif_name, bp,
517 ctx->scratch->int1);
518 break;
519 }
520 return (SNMP_ERR_NOERROR);
521
522 case SNMP_OP_COMMIT:
523 return (SNMP_ERR_NOERROR);
524 }
525 abort();
526
527get:
528 switch (val->var.subs[sub - 1]) {
529 case LEAF_dot1dStpPort:
530 val->v.integer = bp->port_no;
531 return (SNMP_ERR_NOERROR);
532
533 case LEAF_dot1dStpPortPriority:
534 val->v.integer = bp->priority;
535 return (SNMP_ERR_NOERROR);
536
537 case LEAF_dot1dStpPortState:
538 val->v.integer = bp->state;
539 return (SNMP_ERR_NOERROR);
540
541 case LEAF_dot1dStpPortEnable:
542 val->v.integer = bp->enable;
543 return (SNMP_ERR_NOERROR);
544
545 case LEAF_dot1dStpPortPathCost:
546 val->v.integer = bp->path_cost;
547 return (SNMP_ERR_NOERROR);
548
549 case LEAF_dot1dStpPortDesignatedRoot:
550 return (string_get(val, bp->design_root,
551 SNMP_BRIDGE_ID_LEN));
552
553 case LEAF_dot1dStpPortDesignatedCost:
554 val->v.integer = bp->design_cost;
555 return (SNMP_ERR_NOERROR);
556
557 case LEAF_dot1dStpPortDesignatedBridge:
558 return (string_get(val, bp->design_bridge,
559 SNMP_BRIDGE_ID_LEN));
560
561 case LEAF_dot1dStpPortDesignatedPort:
562 return (string_get(val, bp->design_port, 2));
563
564 case LEAF_dot1dStpPortForwardTransitions:
565 val->v.uint32 = bp->fwd_trans;
566 return (SNMP_ERR_NOERROR);
567 }
568
569 abort();
570}
571
572int
573op_dot1d_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val,
574 uint sub, uint iidx __unused, enum snmp_op op)
575{
576 struct bridge_if *bif;
577 struct bridge_port *bp;
578
579 if ((bif = bridge_get_default()) == NULL)
580 return (SNMP_ERR_NOSUCHNAME);
581
582 if (time(NULL) - bif->ports_age > bridge_get_data_maxage() &&
583 bridge_update_memif(bif) <= 0)
584 return (SNMP_ERR_NOSUCHNAME);
585
586 switch (op) {
587 case SNMP_OP_GET:
588 if (val->var.len - sub != 1)
589 return (SNMP_ERR_NOSUCHNAME);
590 if ((bp = bridge_port_find(val->var.subs[sub],
591 bif)) == NULL)
592 return (SNMP_ERR_NOSUCHNAME);
593 goto get;
594
595 case SNMP_OP_GETNEXT:
596 if (val->var.len - sub == 0) {
597 if ((bp = bridge_port_bif_first(bif)) == NULL)
598 return (SNMP_ERR_NOSUCHNAME);
599 } else {
600 if ((bp = bridge_port_find(val->var.subs[sub],
601 bif)) == NULL ||
602 (bp = bridge_port_bif_next(bp)) == NULL)
603 return (SNMP_ERR_NOSUCHNAME);
604 }
605 val->var.len = sub + 1;
606 val->var.subs[sub] = bp->port_no;
607 goto get;
608
609 case SNMP_OP_SET:
610 if (val->var.len - sub != 1)
611 return (SNMP_ERR_NOSUCHNAME);
612 if ((bp = bridge_port_find(val->var.subs[sub],
613 bif)) == NULL)
614 return (SNMP_ERR_NOSUCHNAME);
615
616 switch (val->var.subs[sub - 1]) {
617 case LEAF_dot1dStpPortAdminEdgePort:
618 if (val->v.integer != TruthValue_true &&
619 val->v.integer != TruthValue_false)
620 return (SNMP_ERR_WRONG_VALUE);
621
622 ctx->scratch->int1 = bp->admin_edge;
623 if (bridge_port_set_admin_edge(bif->bif_name, bp,
624 val->v.integer) < 0)
625 return (SNMP_ERR_GENERR);
626 return (SNMP_ERR_NOERROR);
627
628 case LEAF_dot1dStpPortAdminPointToPoint:
629 if (val->v.integer < 0 || val->v.integer >
630 StpPortAdminPointToPointType_auto)
631 return (SNMP_ERR_WRONG_VALUE);
632
633 ctx->scratch->int1 = bp->admin_p2p;
634 if (bridge_port_set_admin_p2p(bif->bif_name, bp,
635 val->v.integer) < 0)
636 return (SNMP_ERR_GENERR);
637 return (SNMP_ERR_NOERROR);
638
639 case LEAF_dot1dStpPortAdminPathCost:
640 if (val->v.integer < SNMP_PORT_MIN_PATHCOST ||
641 val->v.integer > SNMP_PORT_MAX_PATHCOST)
642 return (SNMP_ERR_WRONG_VALUE);
643
644 ctx->scratch->int1 = bp->admin_path_cost;
645 if (bridge_port_set_path_cost(bif->bif_name, bp,
646 val->v.integer) < 0)
647 return (SNMP_ERR_GENERR);
648 return (SNMP_ERR_NOERROR);
649
650 case LEAF_dot1dStpPortProtocolMigration:
651 case LEAF_dot1dStpPortOperEdgePort:
652 case LEAF_dot1dStpPortOperPointToPoint:
653 return (SNMP_ERR_NOT_WRITEABLE);
654 }
655 abort();
656
657 case SNMP_OP_ROLLBACK:
658 if ((bp = bridge_port_find(val->var.subs[sub],
659 bif)) == NULL)
660 return (SNMP_ERR_GENERR);
661
662 switch (val->var.subs[sub - 1]) {
663 case LEAF_dot1dStpPortAdminEdgePort:
664 bridge_port_set_admin_edge(bif->bif_name, bp,
--- 7 unchanged lines hidden (view full) ---
672 bridge_port_set_path_cost(bif->bif_name, bp,
673 ctx->scratch->int1);
674 break;
675 }
676 return (SNMP_ERR_NOERROR);
677
678 case SNMP_OP_COMMIT:
679 return (SNMP_ERR_NOERROR);
680 }
681 abort();
682
683get:
684 switch (val->var.subs[sub - 1]) {
685 case LEAF_dot1dStpPortProtocolMigration:
686 val->v.integer = bp->proto_migr;
687 return (SNMP_ERR_NOERROR);
688
689 case LEAF_dot1dStpPortAdminEdgePort:
690 val->v.integer = bp->admin_edge;
691 return (SNMP_ERR_NOERROR);
692
693 case LEAF_dot1dStpPortOperEdgePort:
694 val->v.integer = bp->oper_edge;
695 return (SNMP_ERR_NOERROR);
696
697 case LEAF_dot1dStpPortAdminPointToPoint:
698 val->v.integer = bp->admin_p2p;
699 return (SNMP_ERR_NOERROR);
700
701 case LEAF_dot1dStpPortOperPointToPoint:
702 val->v.integer = bp->oper_p2p;
703 return (SNMP_ERR_NOERROR);
704
705 case LEAF_dot1dStpPortAdminPathCost:
706 val->v.integer = bp->admin_path_cost;
707 return (SNMP_ERR_NOERROR);
708 }
709
710 abort();
711}
712
713int
714op_dot1d_tp_port(struct snmp_context *c __unused, struct snmp_value *val,
715 uint sub, uint iidx __unused, enum snmp_op op)
716{
717 struct bridge_if *bif;
718 struct bridge_port *bp;
--- 7 unchanged lines hidden (view full) ---
726
727 switch (op) {
728 case SNMP_OP_GET:
729 if (val->var.len - sub != 1)
730 return (SNMP_ERR_NOSUCHNAME);
731 if ((bp = bridge_port_find(val->var.subs[sub],
732 bif)) == NULL)
733 return (SNMP_ERR_NOSUCHNAME);
734 goto get;
735
736 case SNMP_OP_GETNEXT:
737 if (val->var.len - sub == 0) {
738 if ((bp = bridge_port_bif_first(bif)) == NULL)
739 return (SNMP_ERR_NOSUCHNAME);
740 } else {
741 if ((bp = bridge_port_find(val->var.subs[sub],
742 bif)) == NULL ||
743 (bp = bridge_port_bif_next(bp)) == NULL)
744 return (SNMP_ERR_NOSUCHNAME);
745 }
746 val->var.len = sub + 1;
747 val->var.subs[sub] = bp->port_no;
748 goto get;
749
750 case SNMP_OP_SET:
751 return (SNMP_ERR_NOT_WRITEABLE);
752
753 case SNMP_OP_ROLLBACK:
754 case SNMP_OP_COMMIT:
755 break;
756 }
757 abort();
758
759get:
760 switch (val->var.subs[sub - 1]) {
761 case LEAF_dot1dTpPort:
762 val->v.integer = bp->port_no;
763 return (SNMP_ERR_NOERROR);
764
765 case LEAF_dot1dTpPortMaxInfo:
766 val->v.integer = bp->max_info;
767 return (SNMP_ERR_NOERROR);
768
769 case LEAF_dot1dTpPortInFrames:
770 val->v.uint32 = bp->in_frames;
771 return (SNMP_ERR_NOERROR);
772
773 case LEAF_dot1dTpPortOutFrames:
774 val->v.uint32 = bp->out_frames;
775 return (SNMP_ERR_NOERROR);
776
777 case LEAF_dot1dTpPortInDiscards:
778 val->v.uint32 = bp->in_drops;
779 return (SNMP_ERR_NOERROR);
780 }
781
782 abort();
783}
784
785/*
786 * Private BEGEMOT-BRIDGE-MIB specifics.
787 */
788
789/*
790 * Construct a bridge port entry index.
--- 278 unchanged lines hidden (view full) ---
1069 return (SNMP_ERR_NOERROR);
1070}
1071
1072int
1073op_begemot_base_port(struct snmp_context *ctx, struct snmp_value *val,
1074 uint sub, uint iidx __unused, enum snmp_op op)
1075{
1076 int8_t status, which;
1077 struct bridge_port *bp;
1078
1079 if (time(NULL) - ports_list_age > bridge_get_data_maxage())
1080 bridge_update_all_ports();
1081
1082 which = val->var.subs[sub - 1];
1083 status = 0;
1084
1085 switch (op) {
1086 case SNMP_OP_GET:
1087 if (which == LEAF_begemotBridgeBaseSpanEnabled ||
1088 which == LEAF_begemotBridgeBasePortStatus)
1089 status = 1;
1090 if ((bp = bridge_port_index_get(&val->var, sub,
1091 status)) == NULL)
1092 return (SNMP_ERR_NOSUCHNAME);
1093 goto get;
1094
1095 case SNMP_OP_GETNEXT:
1096 if (which == LEAF_begemotBridgeBaseSpanEnabled ||
1097 which == LEAF_begemotBridgeBasePortStatus)
1098 status = 1;
1099 if ((bp = bridge_port_index_getnext(&val->var, sub,
1100 status)) == NULL ||
1101 bridge_port_index_append(&val->var, sub, bp) < 0)
1102 return (SNMP_ERR_NOSUCHNAME);
1103 goto get;
1104
1105 case SNMP_OP_SET:
1106 switch (which) {
1107 case LEAF_begemotBridgeBaseSpanEnabled:
1108 return (bridge_port_set_span_enable(ctx, val, sub));
1109
1110 case LEAF_begemotBridgeBasePortStatus:
1111 return (bridge_port_set_status(ctx, val, sub));
--- 16 unchanged lines hidden (view full) ---
1128 return (SNMP_ERR_NOERROR);
1129
1130 case SNMP_OP_COMMIT:
1131 if (which == LEAF_begemotBridgeBasePortStatus)
1132 return (bridge_port_commit_status(val, sub));
1133
1134 return (SNMP_ERR_NOERROR);
1135 }
1136 abort();
1137
1138get:
1139 switch (which) {
1140 case LEAF_begemotBridgeBasePort:
1141 val->v.integer = bp->port_no;
1142 return (SNMP_ERR_NOERROR);
1143
1144 case LEAF_begemotBridgeBasePortIfIndex:
1145 val->v.integer = bp->if_idx;
1146 return (SNMP_ERR_NOERROR);
1147
1148 case LEAF_begemotBridgeBaseSpanEnabled:
1149 val->v.integer = bp->span_enable;
1150 return (SNMP_ERR_NOERROR);
1151
1152 case LEAF_begemotBridgeBasePortDelayExceededDiscards:
1153 val->v.uint32 = bp->dly_ex_drops;
1154 return (SNMP_ERR_NOERROR);
1155
1156 case LEAF_begemotBridgeBasePortMtuExceededDiscards:
1157 val->v.uint32 = bp->dly_mtu_drops;
1158 return (SNMP_ERR_NOERROR);
1159
1160 case LEAF_begemotBridgeBasePortStatus:
1161 val->v.integer = bp->status;
1162 return (SNMP_ERR_NOERROR);
1163 }
1164
1165 abort();
1166}
1167
1168int
1169op_begemot_stp_port(struct snmp_context *ctx, struct snmp_value *val,
1170 uint sub, uint iidx __unused, enum snmp_op op)
1171{
1172 struct bridge_port *bp;
1173 const char *b_name;
1174
1175 if (time(NULL) - ports_list_age > bridge_get_data_maxage())
1176 bridge_update_all_ports();
1177
1178 switch (op) {
1179 case SNMP_OP_GET:
1180 if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL)
1181 return (SNMP_ERR_NOSUCHNAME);
1182 goto get;
1183
1184 case SNMP_OP_GETNEXT:
1185 if ((bp = bridge_port_index_getnext(&val->var, sub, 0)) ==
1186 NULL || bridge_port_index_append(&val->var, sub, bp) < 0)
1187 return (SNMP_ERR_NOSUCHNAME);
1188 goto get;
1189
1190 case SNMP_OP_SET:
1191 if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL)
1192 return (SNMP_ERR_NOSUCHNAME);
1193 if ((b_name = bridge_if_find_name(bp->sysindex)) == NULL)
1194 return (SNMP_ERR_GENERR);
1195
1196 switch (val->var.subs[sub - 1]) {
1197 case LEAF_begemotBridgeStpPortPriority:
1198 if (val->v.integer < 0 || val->v.integer > 255)
1199 return (SNMP_ERR_WRONG_VALUE);
1200
1201 ctx->scratch->int1 = bp->priority;
1202 if (bridge_port_set_priority(b_name, bp,
1203 val->v.integer) < 0)
1204 return (SNMP_ERR_GENERR);
1205 return (SNMP_ERR_NOERROR);
1206
1207 case LEAF_begemotBridgeStpPortEnable:
1208 if (val->v.integer !=
1209 begemotBridgeStpPortEnable_enabled ||
1210 val->v.integer !=
1211 begemotBridgeStpPortEnable_disabled)
1212 return (SNMP_ERR_WRONG_VALUE);
1213
1214 ctx->scratch->int1 = bp->enable;
1215 if (bridge_port_set_stp_enable(b_name, bp,
1216 val->v.integer) < 0)
1217 return (SNMP_ERR_GENERR);
1218 return (SNMP_ERR_NOERROR);
1219
1220 case LEAF_begemotBridgeStpPortPathCost:
1221 if (val->v.integer < SNMP_PORT_MIN_PATHCOST ||
1222 val->v.integer > SNMP_PORT_MAX_PATHCOST)
1223 return (SNMP_ERR_WRONG_VALUE);
1224
1225 ctx->scratch->int1 = bp->path_cost;
1226 if (bridge_port_set_path_cost(b_name, bp,
1227 val->v.integer) < 0)
1228 return (SNMP_ERR_GENERR);
1229 return (SNMP_ERR_NOERROR);
1230
1231 case LEAF_begemotBridgeStpPort:
1232 case LEAF_begemotBridgeStpPortState:
1233 case LEAF_begemotBridgeStpPortDesignatedRoot:
1234 case LEAF_begemotBridgeStpPortDesignatedCost:
1235 case LEAF_begemotBridgeStpPortDesignatedBridge:
1236 case LEAF_begemotBridgeStpPortDesignatedPort:
1237 case LEAF_begemotBridgeStpPortForwardTransitions:
1238 return (SNMP_ERR_NOT_WRITEABLE);
1239 }
1240 abort();
1241
1242 case SNMP_OP_ROLLBACK:
1243 if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL ||
1244 (b_name = bridge_if_find_name(bp->sysindex)) == NULL)
1245 return (SNMP_ERR_GENERR);
1246
1247 switch (val->var.subs[sub - 1]) {
1248 case LEAF_begemotBridgeStpPortPriority:
--- 8 unchanged lines hidden (view full) ---
1257 bridge_port_set_path_cost(b_name, bp,
1258 ctx->scratch->int1);
1259 break;
1260 }
1261 return (SNMP_ERR_NOERROR);
1262
1263 case SNMP_OP_COMMIT:
1264 return (SNMP_ERR_NOERROR);
1265 }
1266 abort();
1267
1268get:
1269 switch (val->var.subs[sub - 1]) {
1270 case LEAF_begemotBridgeStpPort:
1271 val->v.integer = bp->port_no;
1272 return (SNMP_ERR_NOERROR);
1273
1274 case LEAF_begemotBridgeStpPortPriority:
1275 val->v.integer = bp->priority;
1276 return (SNMP_ERR_NOERROR);
1277
1278 case LEAF_begemotBridgeStpPortState:
1279 val->v.integer = bp->state;
1280 return (SNMP_ERR_NOERROR);
1281
1282 case LEAF_begemotBridgeStpPortEnable:
1283 val->v.integer = bp->enable;
1284 return (SNMP_ERR_NOERROR);
1285
1286 case LEAF_begemotBridgeStpPortPathCost:
1287 val->v.integer = bp->path_cost;
1288 return (SNMP_ERR_NOERROR);
1289
1290 case LEAF_begemotBridgeStpPortDesignatedRoot:
1291 return (string_get(val, bp->design_root, SNMP_BRIDGE_ID_LEN));
1292
1293 case LEAF_begemotBridgeStpPortDesignatedCost:
1294 val->v.integer = bp->design_cost;
1295 return (SNMP_ERR_NOERROR);
1296
1297 case LEAF_begemotBridgeStpPortDesignatedBridge:
1298 return (string_get(val, bp->design_bridge, SNMP_BRIDGE_ID_LEN));
1299
1300 case LEAF_begemotBridgeStpPortDesignatedPort:
1301 return (string_get(val, bp->design_port, 2));
1302
1303 case LEAF_begemotBridgeStpPortForwardTransitions:
1304 val->v.uint32 = bp->fwd_trans;
1305 return (SNMP_ERR_NOERROR);
1306 }
1307
1308 abort();
1309}
1310
1311int
1312op_begemot_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val,
1313 uint sub, uint iidx __unused, enum snmp_op op)
1314{
1315 struct bridge_port *bp;
1316 const char *b_name;
1317
1318 if (time(NULL) - ports_list_age > bridge_get_data_maxage())
1319 bridge_update_all_ports();
1320
1321 switch (op) {
1322 case SNMP_OP_GET:
1323 if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL)
1324 return (SNMP_ERR_NOSUCHNAME);
1325 goto get;
1326
1327 case SNMP_OP_GETNEXT:
1328 if ((bp = bridge_port_index_getnext(&val->var, sub, 0)) ==
1329 NULL || bridge_port_index_append(&val->var, sub, bp) < 0)
1330 return (SNMP_ERR_NOSUCHNAME);
1331 goto get;
1332
1333 case SNMP_OP_SET:
1334 if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL)
1335 return (SNMP_ERR_NOSUCHNAME);
1336 if ((b_name = bridge_if_find_name(bp->sysindex)) == NULL)
1337 return (SNMP_ERR_GENERR);
1338
1339 switch (val->var.subs[sub - 1]) {
1340 case LEAF_begemotBridgeStpPortAdminEdgePort:
1341 if (val->v.integer != TruthValue_true &&
1342 val->v.integer != TruthValue_false)
1343 return (SNMP_ERR_WRONG_VALUE);
1344
1345 ctx->scratch->int1 = bp->admin_edge;
1346 if (bridge_port_set_admin_edge(b_name, bp,
1347 val->v.integer) < 0)
1348 return (SNMP_ERR_GENERR);
1349 return (SNMP_ERR_NOERROR);
1350
1351 case LEAF_begemotBridgeStpPortAdminPointToPoint:
1352 if (val->v.integer < 0 || val->v.integer >
1353 StpPortAdminPointToPointType_auto)
1354 return (SNMP_ERR_WRONG_VALUE);
1355
1356 ctx->scratch->int1 = bp->admin_p2p;
1357 if (bridge_port_set_admin_p2p(b_name, bp,
1358 val->v.integer) < 0)
1359 return (SNMP_ERR_GENERR);
1360 return (SNMP_ERR_NOERROR);
1361
1362 case LEAF_begemotBridgeStpPortAdminPathCost:
1363 if (val->v.integer < SNMP_PORT_MIN_PATHCOST ||
1364 val->v.integer > SNMP_PORT_MAX_PATHCOST)
1365 return (SNMP_ERR_WRONG_VALUE);
1366
1367 ctx->scratch->int1 = bp->admin_path_cost;
1368 if (bridge_port_set_path_cost(b_name, bp,
1369 val->v.integer) < 0)
1370 return (SNMP_ERR_GENERR);
1371 return (SNMP_ERR_NOERROR);
1372
1373 case LEAF_begemotBridgeStpPortProtocolMigration:
1374 case LEAF_begemotBridgeStpPortOperEdgePort:
1375 case LEAF_begemotBridgeStpPortOperPointToPoint:
1376 return (SNMP_ERR_NOT_WRITEABLE);
1377 }
1378 abort();
1379
1380 case SNMP_OP_ROLLBACK:
1381 if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL ||
1382 (b_name = bridge_if_find_name(bp->sysindex)) == NULL)
1383 return (SNMP_ERR_GENERR);
1384
1385 switch (val->var.subs[sub - 1]) {
1386 case LEAF_begemotBridgeStpPortAdminEdgePort:
1387 bridge_port_set_admin_edge(b_name, bp,
--- 7 unchanged lines hidden (view full) ---
1395 bridge_port_set_path_cost(b_name, bp,
1396 ctx->scratch->int1);
1397 break;
1398 }
1399 return (SNMP_ERR_NOERROR);
1400
1401 case SNMP_OP_COMMIT:
1402 return (SNMP_ERR_NOERROR);
1403 }
1404 abort();
1405
1406get:
1407 switch (val->var.subs[sub - 1]) {
1408 case LEAF_begemotBridgeStpPortProtocolMigration:
1409 val->v.integer = bp->proto_migr;
1410 return (SNMP_ERR_NOERROR);
1411
1412 case LEAF_begemotBridgeStpPortAdminEdgePort:
1413 val->v.integer = bp->admin_edge;
1414 return (SNMP_ERR_NOERROR);
1415
1416 case LEAF_begemotBridgeStpPortOperEdgePort:
1417 val->v.integer = bp->oper_edge;
1418 return (SNMP_ERR_NOERROR);
1419
1420 case LEAF_begemotBridgeStpPortAdminPointToPoint:
1421 val->v.integer = bp->admin_p2p;
1422 return (SNMP_ERR_NOERROR);
1423
1424 case LEAF_begemotBridgeStpPortOperPointToPoint:
1425 val->v.integer = bp->oper_p2p;
1426 return (SNMP_ERR_NOERROR);
1427
1428 case LEAF_begemotBridgeStpPortAdminPathCost:
1429 val->v.integer = bp->admin_path_cost;
1430 return (SNMP_ERR_NOERROR);
1431 }
1432
1433 abort();
1434}
1435
1436int
1437op_begemot_tp_port(struct snmp_context *c __unused, struct snmp_value *val,
1438 uint sub, uint iidx __unused, enum snmp_op op)
1439{
1440 struct bridge_port *bp;
1441
1442 if (time(NULL) - ports_list_age > bridge_get_data_maxage())
1443 bridge_update_all_ports();
1444
1445 switch (op) {
1446 case SNMP_OP_GET:
1447 if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL)
1448 return (SNMP_ERR_NOSUCHNAME);
1449 goto get;
1450
1451 case SNMP_OP_GETNEXT:
1452 if ((bp = bridge_port_index_getnext(&val->var, sub, 0)) ==
1453 NULL || bridge_port_index_append(&val->var, sub, bp) < 0)
1454 return (SNMP_ERR_NOSUCHNAME);
1455 goto get;
1456
1457 case SNMP_OP_SET:
1458 return (SNMP_ERR_NOT_WRITEABLE);
1459
1460 case SNMP_OP_ROLLBACK:
1461 case SNMP_OP_COMMIT:
1462 break;
1463 }
1464 abort();
1465
1466get:
1467 switch (val->var.subs[sub - 1]) {
1468 case LEAF_begemotBridgeTpPort:
1469 val->v.integer = bp->port_no;
1470 return (SNMP_ERR_NOERROR);
1471
1472 case LEAF_begemotBridgeTpPortMaxInfo:
1473 val->v.integer = bp->max_info;
1474 return (SNMP_ERR_NOERROR);
1475
1476 case LEAF_begemotBridgeTpPortInFrames:
1477 val->v.uint32 = bp->in_frames;
1478 return (SNMP_ERR_NOERROR);
1479
1480 case LEAF_begemotBridgeTpPortOutFrames:
1481 val->v.uint32 = bp->out_frames;
1482 return (SNMP_ERR_NOERROR);
1483
1484 case LEAF_begemotBridgeTpPortInDiscards:
1485 val->v.uint32 = bp->in_drops;
1486 return (SNMP_ERR_NOERROR);
1487 }
1488
1489 abort();
1490}
2 * Copyright (c) 2006 Shteryana Shopova <syrinx@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 12 unchanged lines hidden (view full) ---
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * Bridge MIB implementation for SNMPd.
27 * Bridge ports.
28 *
29 * $FreeBSD: head/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_port.c 165253 2006-12-15 20:01:57Z syrinx $
30 */
31
32#include <sys/queue.h>
33#include <sys/socket.h>
34#include <sys/types.h>
35
36#include <net/ethernet.h>
37#include <net/if.h>
--- 317 unchanged lines hidden (view full) ---
355
356 switch (op) {
357 case SNMP_OP_GET:
358 if (val->var.len - sub != 1)
359 return (SNMP_ERR_NOSUCHNAME);
360 if ((bp = bridge_port_find(val->var.subs[sub],
361 bif)) == NULL)
362 return (SNMP_ERR_NOSUCHNAME);
363 goto get;
364
365 case SNMP_OP_GETNEXT:
366 if (val->var.len - sub == 0) {
367 if ((bp = bridge_port_bif_first(bif)) == NULL)
368 return (SNMP_ERR_NOSUCHNAME);
369 } else {
370 if ((bp = bridge_port_find(val->var.subs[sub],
371 bif)) == NULL ||
372 (bp = bridge_port_bif_next(bp)) == NULL)
373 return (SNMP_ERR_NOSUCHNAME);
374 }
375 val->var.len = sub + 1;
376 val->var.subs[sub] = bp->port_no;
377 goto get;
378
379 case SNMP_OP_SET:
380 return (SNMP_ERR_NOT_WRITEABLE);
381
382 case SNMP_OP_ROLLBACK:
383 case SNMP_OP_COMMIT:
384 break;
385 }
386 abort();
387
388get:
389 switch (val->var.subs[sub - 1]) {
390 case LEAF_dot1dBasePort:
391 val->v.integer = bp->port_no;
392 return (SNMP_ERR_NOERROR);
393
394 case LEAF_dot1dBasePortIfIndex:
395 val->v.integer = bp->if_idx;
396 return (SNMP_ERR_NOERROR);
397
398 case LEAF_dot1dBasePortCircuit:
399 val->v.oid = bp->circuit;
400 return (SNMP_ERR_NOERROR);
401
402 case LEAF_dot1dBasePortDelayExceededDiscards:
403 val->v.uint32 = bp->dly_ex_drops;
404 return (SNMP_ERR_NOERROR);
405
406 case LEAF_dot1dBasePortMtuExceededDiscards:
407 val->v.uint32 = bp->dly_mtu_drops;
408 return (SNMP_ERR_NOERROR);
409 }
410
411 abort();
412}
413
414int
415op_dot1d_stp_port(struct snmp_context *ctx, struct snmp_value *val,
416 uint sub, uint iidx __unused, enum snmp_op op)
417{
418 struct bridge_if *bif;
419 struct bridge_port *bp;
420
421 if ((bif = bridge_get_default()) == NULL)
422 return (SNMP_ERR_NOSUCHNAME);
423
424 if (time(NULL) - bif->ports_age > bridge_get_data_maxage() &&
425 bridge_update_memif(bif) <= 0)
426 return (SNMP_ERR_NOSUCHNAME);
427
428 switch (op) {
429 case SNMP_OP_GET:
430 if (val->var.len - sub != 1)
431 return (SNMP_ERR_NOSUCHNAME);
432 if ((bp = bridge_port_find(val->var.subs[sub],
433 bif)) == NULL)
434 return (SNMP_ERR_NOSUCHNAME);
435 goto get;
436
437 case SNMP_OP_GETNEXT:
438 if (val->var.len - sub == 0) {
439 if ((bp = bridge_port_bif_first(bif)) == NULL)
440 return (SNMP_ERR_NOSUCHNAME);
441 } else {
442 if ((bp = bridge_port_find(val->var.subs[sub],
443 bif)) == NULL ||
444 (bp = bridge_port_bif_next(bp)) == NULL)
445 return (SNMP_ERR_NOSUCHNAME);
446 }
447 val->var.len = sub + 1;
448 val->var.subs[sub] = bp->port_no;
449 goto get;
450
451 case SNMP_OP_SET:
452 if (val->var.len - sub != 1)
453 return (SNMP_ERR_NOSUCHNAME);
454 if ((bp = bridge_port_find(val->var.subs[sub],
455 bif)) == NULL)
456 return (SNMP_ERR_NOSUCHNAME);
457
458 switch (val->var.subs[sub - 1]) {
459 case LEAF_dot1dStpPortPriority:
460 if (val->v.integer < 0 || val->v.integer > 255)
461 return (SNMP_ERR_WRONG_VALUE);
462
463 ctx->scratch->int1 = bp->priority;
464 if (bridge_port_set_priority(bif->bif_name, bp,
465 val->v.integer) < 0)
466 return (SNMP_ERR_GENERR);
467 return (SNMP_ERR_NOERROR);
468
469 case LEAF_dot1dStpPortEnable:
470 if (val->v.integer != dot1dStpPortEnable_enabled &&
471 val->v.integer != dot1dStpPortEnable_disabled)
472 return (SNMP_ERR_WRONG_VALUE);
473
474 ctx->scratch->int1 = bp->enable;
475 if (bridge_port_set_stp_enable(bif->bif_name,
476 bp, val->v.integer) < 0)
477 return (SNMP_ERR_GENERR);
478 return (SNMP_ERR_NOERROR);
479
480 case LEAF_dot1dStpPortPathCost:
481 if (val->v.integer < SNMP_PORT_MIN_PATHCOST ||
482 val->v.integer > SNMP_PORT_MAX_PATHCOST)
483 return (SNMP_ERR_WRONG_VALUE);
484
485 ctx->scratch->int1 = bp->path_cost;
486 if (bridge_port_set_path_cost(bif->bif_name, bp,
487 val->v.integer) < 0)
488 return (SNMP_ERR_GENERR);
489 return (SNMP_ERR_NOERROR);
490
491 case LEAF_dot1dStpPort:
492 case LEAF_dot1dStpPortState:
493 case LEAF_dot1dStpPortDesignatedRoot:
494 case LEAF_dot1dStpPortDesignatedCost:
495 case LEAF_dot1dStpPortDesignatedBridge:
496 case LEAF_dot1dStpPortDesignatedPort:
497 case LEAF_dot1dStpPortForwardTransitions:
498 return (SNMP_ERR_NOT_WRITEABLE);
499 }
500 abort();
501
502 case SNMP_OP_ROLLBACK:
503 if ((bp = bridge_port_find(val->var.subs[sub],
504 bif)) == NULL)
505 return (SNMP_ERR_GENERR);
506 switch (val->var.subs[sub - 1]) {
507 case LEAF_dot1dStpPortPriority:
508 bridge_port_set_priority(bif->bif_name, bp,
--- 7 unchanged lines hidden (view full) ---
516 bridge_port_set_path_cost(bif->bif_name, bp,
517 ctx->scratch->int1);
518 break;
519 }
520 return (SNMP_ERR_NOERROR);
521
522 case SNMP_OP_COMMIT:
523 return (SNMP_ERR_NOERROR);
524 }
525 abort();
526
527get:
528 switch (val->var.subs[sub - 1]) {
529 case LEAF_dot1dStpPort:
530 val->v.integer = bp->port_no;
531 return (SNMP_ERR_NOERROR);
532
533 case LEAF_dot1dStpPortPriority:
534 val->v.integer = bp->priority;
535 return (SNMP_ERR_NOERROR);
536
537 case LEAF_dot1dStpPortState:
538 val->v.integer = bp->state;
539 return (SNMP_ERR_NOERROR);
540
541 case LEAF_dot1dStpPortEnable:
542 val->v.integer = bp->enable;
543 return (SNMP_ERR_NOERROR);
544
545 case LEAF_dot1dStpPortPathCost:
546 val->v.integer = bp->path_cost;
547 return (SNMP_ERR_NOERROR);
548
549 case LEAF_dot1dStpPortDesignatedRoot:
550 return (string_get(val, bp->design_root,
551 SNMP_BRIDGE_ID_LEN));
552
553 case LEAF_dot1dStpPortDesignatedCost:
554 val->v.integer = bp->design_cost;
555 return (SNMP_ERR_NOERROR);
556
557 case LEAF_dot1dStpPortDesignatedBridge:
558 return (string_get(val, bp->design_bridge,
559 SNMP_BRIDGE_ID_LEN));
560
561 case LEAF_dot1dStpPortDesignatedPort:
562 return (string_get(val, bp->design_port, 2));
563
564 case LEAF_dot1dStpPortForwardTransitions:
565 val->v.uint32 = bp->fwd_trans;
566 return (SNMP_ERR_NOERROR);
567 }
568
569 abort();
570}
571
572int
573op_dot1d_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val,
574 uint sub, uint iidx __unused, enum snmp_op op)
575{
576 struct bridge_if *bif;
577 struct bridge_port *bp;
578
579 if ((bif = bridge_get_default()) == NULL)
580 return (SNMP_ERR_NOSUCHNAME);
581
582 if (time(NULL) - bif->ports_age > bridge_get_data_maxage() &&
583 bridge_update_memif(bif) <= 0)
584 return (SNMP_ERR_NOSUCHNAME);
585
586 switch (op) {
587 case SNMP_OP_GET:
588 if (val->var.len - sub != 1)
589 return (SNMP_ERR_NOSUCHNAME);
590 if ((bp = bridge_port_find(val->var.subs[sub],
591 bif)) == NULL)
592 return (SNMP_ERR_NOSUCHNAME);
593 goto get;
594
595 case SNMP_OP_GETNEXT:
596 if (val->var.len - sub == 0) {
597 if ((bp = bridge_port_bif_first(bif)) == NULL)
598 return (SNMP_ERR_NOSUCHNAME);
599 } else {
600 if ((bp = bridge_port_find(val->var.subs[sub],
601 bif)) == NULL ||
602 (bp = bridge_port_bif_next(bp)) == NULL)
603 return (SNMP_ERR_NOSUCHNAME);
604 }
605 val->var.len = sub + 1;
606 val->var.subs[sub] = bp->port_no;
607 goto get;
608
609 case SNMP_OP_SET:
610 if (val->var.len - sub != 1)
611 return (SNMP_ERR_NOSUCHNAME);
612 if ((bp = bridge_port_find(val->var.subs[sub],
613 bif)) == NULL)
614 return (SNMP_ERR_NOSUCHNAME);
615
616 switch (val->var.subs[sub - 1]) {
617 case LEAF_dot1dStpPortAdminEdgePort:
618 if (val->v.integer != TruthValue_true &&
619 val->v.integer != TruthValue_false)
620 return (SNMP_ERR_WRONG_VALUE);
621
622 ctx->scratch->int1 = bp->admin_edge;
623 if (bridge_port_set_admin_edge(bif->bif_name, bp,
624 val->v.integer) < 0)
625 return (SNMP_ERR_GENERR);
626 return (SNMP_ERR_NOERROR);
627
628 case LEAF_dot1dStpPortAdminPointToPoint:
629 if (val->v.integer < 0 || val->v.integer >
630 StpPortAdminPointToPointType_auto)
631 return (SNMP_ERR_WRONG_VALUE);
632
633 ctx->scratch->int1 = bp->admin_p2p;
634 if (bridge_port_set_admin_p2p(bif->bif_name, bp,
635 val->v.integer) < 0)
636 return (SNMP_ERR_GENERR);
637 return (SNMP_ERR_NOERROR);
638
639 case LEAF_dot1dStpPortAdminPathCost:
640 if (val->v.integer < SNMP_PORT_MIN_PATHCOST ||
641 val->v.integer > SNMP_PORT_MAX_PATHCOST)
642 return (SNMP_ERR_WRONG_VALUE);
643
644 ctx->scratch->int1 = bp->admin_path_cost;
645 if (bridge_port_set_path_cost(bif->bif_name, bp,
646 val->v.integer) < 0)
647 return (SNMP_ERR_GENERR);
648 return (SNMP_ERR_NOERROR);
649
650 case LEAF_dot1dStpPortProtocolMigration:
651 case LEAF_dot1dStpPortOperEdgePort:
652 case LEAF_dot1dStpPortOperPointToPoint:
653 return (SNMP_ERR_NOT_WRITEABLE);
654 }
655 abort();
656
657 case SNMP_OP_ROLLBACK:
658 if ((bp = bridge_port_find(val->var.subs[sub],
659 bif)) == NULL)
660 return (SNMP_ERR_GENERR);
661
662 switch (val->var.subs[sub - 1]) {
663 case LEAF_dot1dStpPortAdminEdgePort:
664 bridge_port_set_admin_edge(bif->bif_name, bp,
--- 7 unchanged lines hidden (view full) ---
672 bridge_port_set_path_cost(bif->bif_name, bp,
673 ctx->scratch->int1);
674 break;
675 }
676 return (SNMP_ERR_NOERROR);
677
678 case SNMP_OP_COMMIT:
679 return (SNMP_ERR_NOERROR);
680 }
681 abort();
682
683get:
684 switch (val->var.subs[sub - 1]) {
685 case LEAF_dot1dStpPortProtocolMigration:
686 val->v.integer = bp->proto_migr;
687 return (SNMP_ERR_NOERROR);
688
689 case LEAF_dot1dStpPortAdminEdgePort:
690 val->v.integer = bp->admin_edge;
691 return (SNMP_ERR_NOERROR);
692
693 case LEAF_dot1dStpPortOperEdgePort:
694 val->v.integer = bp->oper_edge;
695 return (SNMP_ERR_NOERROR);
696
697 case LEAF_dot1dStpPortAdminPointToPoint:
698 val->v.integer = bp->admin_p2p;
699 return (SNMP_ERR_NOERROR);
700
701 case LEAF_dot1dStpPortOperPointToPoint:
702 val->v.integer = bp->oper_p2p;
703 return (SNMP_ERR_NOERROR);
704
705 case LEAF_dot1dStpPortAdminPathCost:
706 val->v.integer = bp->admin_path_cost;
707 return (SNMP_ERR_NOERROR);
708 }
709
710 abort();
711}
712
713int
714op_dot1d_tp_port(struct snmp_context *c __unused, struct snmp_value *val,
715 uint sub, uint iidx __unused, enum snmp_op op)
716{
717 struct bridge_if *bif;
718 struct bridge_port *bp;
--- 7 unchanged lines hidden (view full) ---
726
727 switch (op) {
728 case SNMP_OP_GET:
729 if (val->var.len - sub != 1)
730 return (SNMP_ERR_NOSUCHNAME);
731 if ((bp = bridge_port_find(val->var.subs[sub],
732 bif)) == NULL)
733 return (SNMP_ERR_NOSUCHNAME);
734 goto get;
735
736 case SNMP_OP_GETNEXT:
737 if (val->var.len - sub == 0) {
738 if ((bp = bridge_port_bif_first(bif)) == NULL)
739 return (SNMP_ERR_NOSUCHNAME);
740 } else {
741 if ((bp = bridge_port_find(val->var.subs[sub],
742 bif)) == NULL ||
743 (bp = bridge_port_bif_next(bp)) == NULL)
744 return (SNMP_ERR_NOSUCHNAME);
745 }
746 val->var.len = sub + 1;
747 val->var.subs[sub] = bp->port_no;
748 goto get;
749
750 case SNMP_OP_SET:
751 return (SNMP_ERR_NOT_WRITEABLE);
752
753 case SNMP_OP_ROLLBACK:
754 case SNMP_OP_COMMIT:
755 break;
756 }
757 abort();
758
759get:
760 switch (val->var.subs[sub - 1]) {
761 case LEAF_dot1dTpPort:
762 val->v.integer = bp->port_no;
763 return (SNMP_ERR_NOERROR);
764
765 case LEAF_dot1dTpPortMaxInfo:
766 val->v.integer = bp->max_info;
767 return (SNMP_ERR_NOERROR);
768
769 case LEAF_dot1dTpPortInFrames:
770 val->v.uint32 = bp->in_frames;
771 return (SNMP_ERR_NOERROR);
772
773 case LEAF_dot1dTpPortOutFrames:
774 val->v.uint32 = bp->out_frames;
775 return (SNMP_ERR_NOERROR);
776
777 case LEAF_dot1dTpPortInDiscards:
778 val->v.uint32 = bp->in_drops;
779 return (SNMP_ERR_NOERROR);
780 }
781
782 abort();
783}
784
785/*
786 * Private BEGEMOT-BRIDGE-MIB specifics.
787 */
788
789/*
790 * Construct a bridge port entry index.
--- 278 unchanged lines hidden (view full) ---
1069 return (SNMP_ERR_NOERROR);
1070}
1071
1072int
1073op_begemot_base_port(struct snmp_context *ctx, struct snmp_value *val,
1074 uint sub, uint iidx __unused, enum snmp_op op)
1075{
1076 int8_t status, which;
1077 struct bridge_port *bp;
1078
1079 if (time(NULL) - ports_list_age > bridge_get_data_maxage())
1080 bridge_update_all_ports();
1081
1082 which = val->var.subs[sub - 1];
1083 status = 0;
1084
1085 switch (op) {
1086 case SNMP_OP_GET:
1087 if (which == LEAF_begemotBridgeBaseSpanEnabled ||
1088 which == LEAF_begemotBridgeBasePortStatus)
1089 status = 1;
1090 if ((bp = bridge_port_index_get(&val->var, sub,
1091 status)) == NULL)
1092 return (SNMP_ERR_NOSUCHNAME);
1093 goto get;
1094
1095 case SNMP_OP_GETNEXT:
1096 if (which == LEAF_begemotBridgeBaseSpanEnabled ||
1097 which == LEAF_begemotBridgeBasePortStatus)
1098 status = 1;
1099 if ((bp = bridge_port_index_getnext(&val->var, sub,
1100 status)) == NULL ||
1101 bridge_port_index_append(&val->var, sub, bp) < 0)
1102 return (SNMP_ERR_NOSUCHNAME);
1103 goto get;
1104
1105 case SNMP_OP_SET:
1106 switch (which) {
1107 case LEAF_begemotBridgeBaseSpanEnabled:
1108 return (bridge_port_set_span_enable(ctx, val, sub));
1109
1110 case LEAF_begemotBridgeBasePortStatus:
1111 return (bridge_port_set_status(ctx, val, sub));
--- 16 unchanged lines hidden (view full) ---
1128 return (SNMP_ERR_NOERROR);
1129
1130 case SNMP_OP_COMMIT:
1131 if (which == LEAF_begemotBridgeBasePortStatus)
1132 return (bridge_port_commit_status(val, sub));
1133
1134 return (SNMP_ERR_NOERROR);
1135 }
1136 abort();
1137
1138get:
1139 switch (which) {
1140 case LEAF_begemotBridgeBasePort:
1141 val->v.integer = bp->port_no;
1142 return (SNMP_ERR_NOERROR);
1143
1144 case LEAF_begemotBridgeBasePortIfIndex:
1145 val->v.integer = bp->if_idx;
1146 return (SNMP_ERR_NOERROR);
1147
1148 case LEAF_begemotBridgeBaseSpanEnabled:
1149 val->v.integer = bp->span_enable;
1150 return (SNMP_ERR_NOERROR);
1151
1152 case LEAF_begemotBridgeBasePortDelayExceededDiscards:
1153 val->v.uint32 = bp->dly_ex_drops;
1154 return (SNMP_ERR_NOERROR);
1155
1156 case LEAF_begemotBridgeBasePortMtuExceededDiscards:
1157 val->v.uint32 = bp->dly_mtu_drops;
1158 return (SNMP_ERR_NOERROR);
1159
1160 case LEAF_begemotBridgeBasePortStatus:
1161 val->v.integer = bp->status;
1162 return (SNMP_ERR_NOERROR);
1163 }
1164
1165 abort();
1166}
1167
1168int
1169op_begemot_stp_port(struct snmp_context *ctx, struct snmp_value *val,
1170 uint sub, uint iidx __unused, enum snmp_op op)
1171{
1172 struct bridge_port *bp;
1173 const char *b_name;
1174
1175 if (time(NULL) - ports_list_age > bridge_get_data_maxage())
1176 bridge_update_all_ports();
1177
1178 switch (op) {
1179 case SNMP_OP_GET:
1180 if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL)
1181 return (SNMP_ERR_NOSUCHNAME);
1182 goto get;
1183
1184 case SNMP_OP_GETNEXT:
1185 if ((bp = bridge_port_index_getnext(&val->var, sub, 0)) ==
1186 NULL || bridge_port_index_append(&val->var, sub, bp) < 0)
1187 return (SNMP_ERR_NOSUCHNAME);
1188 goto get;
1189
1190 case SNMP_OP_SET:
1191 if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL)
1192 return (SNMP_ERR_NOSUCHNAME);
1193 if ((b_name = bridge_if_find_name(bp->sysindex)) == NULL)
1194 return (SNMP_ERR_GENERR);
1195
1196 switch (val->var.subs[sub - 1]) {
1197 case LEAF_begemotBridgeStpPortPriority:
1198 if (val->v.integer < 0 || val->v.integer > 255)
1199 return (SNMP_ERR_WRONG_VALUE);
1200
1201 ctx->scratch->int1 = bp->priority;
1202 if (bridge_port_set_priority(b_name, bp,
1203 val->v.integer) < 0)
1204 return (SNMP_ERR_GENERR);
1205 return (SNMP_ERR_NOERROR);
1206
1207 case LEAF_begemotBridgeStpPortEnable:
1208 if (val->v.integer !=
1209 begemotBridgeStpPortEnable_enabled ||
1210 val->v.integer !=
1211 begemotBridgeStpPortEnable_disabled)
1212 return (SNMP_ERR_WRONG_VALUE);
1213
1214 ctx->scratch->int1 = bp->enable;
1215 if (bridge_port_set_stp_enable(b_name, bp,
1216 val->v.integer) < 0)
1217 return (SNMP_ERR_GENERR);
1218 return (SNMP_ERR_NOERROR);
1219
1220 case LEAF_begemotBridgeStpPortPathCost:
1221 if (val->v.integer < SNMP_PORT_MIN_PATHCOST ||
1222 val->v.integer > SNMP_PORT_MAX_PATHCOST)
1223 return (SNMP_ERR_WRONG_VALUE);
1224
1225 ctx->scratch->int1 = bp->path_cost;
1226 if (bridge_port_set_path_cost(b_name, bp,
1227 val->v.integer) < 0)
1228 return (SNMP_ERR_GENERR);
1229 return (SNMP_ERR_NOERROR);
1230
1231 case LEAF_begemotBridgeStpPort:
1232 case LEAF_begemotBridgeStpPortState:
1233 case LEAF_begemotBridgeStpPortDesignatedRoot:
1234 case LEAF_begemotBridgeStpPortDesignatedCost:
1235 case LEAF_begemotBridgeStpPortDesignatedBridge:
1236 case LEAF_begemotBridgeStpPortDesignatedPort:
1237 case LEAF_begemotBridgeStpPortForwardTransitions:
1238 return (SNMP_ERR_NOT_WRITEABLE);
1239 }
1240 abort();
1241
1242 case SNMP_OP_ROLLBACK:
1243 if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL ||
1244 (b_name = bridge_if_find_name(bp->sysindex)) == NULL)
1245 return (SNMP_ERR_GENERR);
1246
1247 switch (val->var.subs[sub - 1]) {
1248 case LEAF_begemotBridgeStpPortPriority:
--- 8 unchanged lines hidden (view full) ---
1257 bridge_port_set_path_cost(b_name, bp,
1258 ctx->scratch->int1);
1259 break;
1260 }
1261 return (SNMP_ERR_NOERROR);
1262
1263 case SNMP_OP_COMMIT:
1264 return (SNMP_ERR_NOERROR);
1265 }
1266 abort();
1267
1268get:
1269 switch (val->var.subs[sub - 1]) {
1270 case LEAF_begemotBridgeStpPort:
1271 val->v.integer = bp->port_no;
1272 return (SNMP_ERR_NOERROR);
1273
1274 case LEAF_begemotBridgeStpPortPriority:
1275 val->v.integer = bp->priority;
1276 return (SNMP_ERR_NOERROR);
1277
1278 case LEAF_begemotBridgeStpPortState:
1279 val->v.integer = bp->state;
1280 return (SNMP_ERR_NOERROR);
1281
1282 case LEAF_begemotBridgeStpPortEnable:
1283 val->v.integer = bp->enable;
1284 return (SNMP_ERR_NOERROR);
1285
1286 case LEAF_begemotBridgeStpPortPathCost:
1287 val->v.integer = bp->path_cost;
1288 return (SNMP_ERR_NOERROR);
1289
1290 case LEAF_begemotBridgeStpPortDesignatedRoot:
1291 return (string_get(val, bp->design_root, SNMP_BRIDGE_ID_LEN));
1292
1293 case LEAF_begemotBridgeStpPortDesignatedCost:
1294 val->v.integer = bp->design_cost;
1295 return (SNMP_ERR_NOERROR);
1296
1297 case LEAF_begemotBridgeStpPortDesignatedBridge:
1298 return (string_get(val, bp->design_bridge, SNMP_BRIDGE_ID_LEN));
1299
1300 case LEAF_begemotBridgeStpPortDesignatedPort:
1301 return (string_get(val, bp->design_port, 2));
1302
1303 case LEAF_begemotBridgeStpPortForwardTransitions:
1304 val->v.uint32 = bp->fwd_trans;
1305 return (SNMP_ERR_NOERROR);
1306 }
1307
1308 abort();
1309}
1310
1311int
1312op_begemot_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val,
1313 uint sub, uint iidx __unused, enum snmp_op op)
1314{
1315 struct bridge_port *bp;
1316 const char *b_name;
1317
1318 if (time(NULL) - ports_list_age > bridge_get_data_maxage())
1319 bridge_update_all_ports();
1320
1321 switch (op) {
1322 case SNMP_OP_GET:
1323 if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL)
1324 return (SNMP_ERR_NOSUCHNAME);
1325 goto get;
1326
1327 case SNMP_OP_GETNEXT:
1328 if ((bp = bridge_port_index_getnext(&val->var, sub, 0)) ==
1329 NULL || bridge_port_index_append(&val->var, sub, bp) < 0)
1330 return (SNMP_ERR_NOSUCHNAME);
1331 goto get;
1332
1333 case SNMP_OP_SET:
1334 if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL)
1335 return (SNMP_ERR_NOSUCHNAME);
1336 if ((b_name = bridge_if_find_name(bp->sysindex)) == NULL)
1337 return (SNMP_ERR_GENERR);
1338
1339 switch (val->var.subs[sub - 1]) {
1340 case LEAF_begemotBridgeStpPortAdminEdgePort:
1341 if (val->v.integer != TruthValue_true &&
1342 val->v.integer != TruthValue_false)
1343 return (SNMP_ERR_WRONG_VALUE);
1344
1345 ctx->scratch->int1 = bp->admin_edge;
1346 if (bridge_port_set_admin_edge(b_name, bp,
1347 val->v.integer) < 0)
1348 return (SNMP_ERR_GENERR);
1349 return (SNMP_ERR_NOERROR);
1350
1351 case LEAF_begemotBridgeStpPortAdminPointToPoint:
1352 if (val->v.integer < 0 || val->v.integer >
1353 StpPortAdminPointToPointType_auto)
1354 return (SNMP_ERR_WRONG_VALUE);
1355
1356 ctx->scratch->int1 = bp->admin_p2p;
1357 if (bridge_port_set_admin_p2p(b_name, bp,
1358 val->v.integer) < 0)
1359 return (SNMP_ERR_GENERR);
1360 return (SNMP_ERR_NOERROR);
1361
1362 case LEAF_begemotBridgeStpPortAdminPathCost:
1363 if (val->v.integer < SNMP_PORT_MIN_PATHCOST ||
1364 val->v.integer > SNMP_PORT_MAX_PATHCOST)
1365 return (SNMP_ERR_WRONG_VALUE);
1366
1367 ctx->scratch->int1 = bp->admin_path_cost;
1368 if (bridge_port_set_path_cost(b_name, bp,
1369 val->v.integer) < 0)
1370 return (SNMP_ERR_GENERR);
1371 return (SNMP_ERR_NOERROR);
1372
1373 case LEAF_begemotBridgeStpPortProtocolMigration:
1374 case LEAF_begemotBridgeStpPortOperEdgePort:
1375 case LEAF_begemotBridgeStpPortOperPointToPoint:
1376 return (SNMP_ERR_NOT_WRITEABLE);
1377 }
1378 abort();
1379
1380 case SNMP_OP_ROLLBACK:
1381 if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL ||
1382 (b_name = bridge_if_find_name(bp->sysindex)) == NULL)
1383 return (SNMP_ERR_GENERR);
1384
1385 switch (val->var.subs[sub - 1]) {
1386 case LEAF_begemotBridgeStpPortAdminEdgePort:
1387 bridge_port_set_admin_edge(b_name, bp,
--- 7 unchanged lines hidden (view full) ---
1395 bridge_port_set_path_cost(b_name, bp,
1396 ctx->scratch->int1);
1397 break;
1398 }
1399 return (SNMP_ERR_NOERROR);
1400
1401 case SNMP_OP_COMMIT:
1402 return (SNMP_ERR_NOERROR);
1403 }
1404 abort();
1405
1406get:
1407 switch (val->var.subs[sub - 1]) {
1408 case LEAF_begemotBridgeStpPortProtocolMigration:
1409 val->v.integer = bp->proto_migr;
1410 return (SNMP_ERR_NOERROR);
1411
1412 case LEAF_begemotBridgeStpPortAdminEdgePort:
1413 val->v.integer = bp->admin_edge;
1414 return (SNMP_ERR_NOERROR);
1415
1416 case LEAF_begemotBridgeStpPortOperEdgePort:
1417 val->v.integer = bp->oper_edge;
1418 return (SNMP_ERR_NOERROR);
1419
1420 case LEAF_begemotBridgeStpPortAdminPointToPoint:
1421 val->v.integer = bp->admin_p2p;
1422 return (SNMP_ERR_NOERROR);
1423
1424 case LEAF_begemotBridgeStpPortOperPointToPoint:
1425 val->v.integer = bp->oper_p2p;
1426 return (SNMP_ERR_NOERROR);
1427
1428 case LEAF_begemotBridgeStpPortAdminPathCost:
1429 val->v.integer = bp->admin_path_cost;
1430 return (SNMP_ERR_NOERROR);
1431 }
1432
1433 abort();
1434}
1435
1436int
1437op_begemot_tp_port(struct snmp_context *c __unused, struct snmp_value *val,
1438 uint sub, uint iidx __unused, enum snmp_op op)
1439{
1440 struct bridge_port *bp;
1441
1442 if (time(NULL) - ports_list_age > bridge_get_data_maxage())
1443 bridge_update_all_ports();
1444
1445 switch (op) {
1446 case SNMP_OP_GET:
1447 if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL)
1448 return (SNMP_ERR_NOSUCHNAME);
1449 goto get;
1450
1451 case SNMP_OP_GETNEXT:
1452 if ((bp = bridge_port_index_getnext(&val->var, sub, 0)) ==
1453 NULL || bridge_port_index_append(&val->var, sub, bp) < 0)
1454 return (SNMP_ERR_NOSUCHNAME);
1455 goto get;
1456
1457 case SNMP_OP_SET:
1458 return (SNMP_ERR_NOT_WRITEABLE);
1459
1460 case SNMP_OP_ROLLBACK:
1461 case SNMP_OP_COMMIT:
1462 break;
1463 }
1464 abort();
1465
1466get:
1467 switch (val->var.subs[sub - 1]) {
1468 case LEAF_begemotBridgeTpPort:
1469 val->v.integer = bp->port_no;
1470 return (SNMP_ERR_NOERROR);
1471
1472 case LEAF_begemotBridgeTpPortMaxInfo:
1473 val->v.integer = bp->max_info;
1474 return (SNMP_ERR_NOERROR);
1475
1476 case LEAF_begemotBridgeTpPortInFrames:
1477 val->v.uint32 = bp->in_frames;
1478 return (SNMP_ERR_NOERROR);
1479
1480 case LEAF_begemotBridgeTpPortOutFrames:
1481 val->v.uint32 = bp->out_frames;
1482 return (SNMP_ERR_NOERROR);
1483
1484 case LEAF_begemotBridgeTpPortInDiscards:
1485 val->v.uint32 = bp->in_drops;
1486 return (SNMP_ERR_NOERROR);
1487 }
1488
1489 abort();
1490}