Path: blob/main/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_pf.c
107468 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2006 Shteryana Shopova <[email protected]>4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*27* Bridge MIB implementation for SNMPd.28* Bridge pfil controls.29*/3031#include <sys/types.h>32#include <sys/sysctl.h>33#include <sys/socket.h>3435#include <net/ethernet.h>36#include <net/if.h>37#include <net/if_mib.h>38#include <net/if_types.h>3940#include <errno.h>41#include <string.h>42#include <stdlib.h>43#include <syslog.h>4445#include <bsnmp/snmpmod.h>46#include <bsnmp/snmp_mibII.h>4748#define SNMPTREE_TYPES49#include "bridge_tree.h"50#include "bridge_snmp.h"5152static int53val2snmp_truth(uint8_t val)54{55if (val == 0)56return (2);5758return (1);59}6061static int62snmp_truth2val(int32_t truth)63{64if (truth == 2)65return (0);66else if (truth == 1)67return (1);6869return (-1);70}7172int73op_begemot_bridge_pf(struct snmp_context *ctx, struct snmp_value *val,74uint sub, uint iidx __unused, enum snmp_op op)75{76int k_val;7778if (val->var.subs[sub - 1] > LEAF_begemotBridgeLayer2PfStatus)79return (SNMP_ERR_NOSUCHNAME);8081switch (op) {82case SNMP_OP_GETNEXT:83abort();84case SNMP_OP_ROLLBACK:85bridge_do_pfctl(val->var.subs[sub - 1] - 1,86op, &(ctx->scratch->int1));87return (SNMP_ERR_NOERROR);8889case SNMP_OP_COMMIT:90return (SNMP_ERR_NOERROR);9192case SNMP_OP_SET:93ctx->scratch->int1 =94bridge_get_pfval(val->var.subs[sub - 1]);9596if ((k_val = snmp_truth2val(val->v.integer)) < 0)97return (SNMP_ERR_BADVALUE);98return (SNMP_ERR_NOERROR);99100case SNMP_OP_GET:101switch (val->var.subs[sub - 1]) {102case LEAF_begemotBridgePfilStatus:103case LEAF_begemotBridgePfilMembers:104case LEAF_begemotBridgePfilIpOnly:105case LEAF_begemotBridgeLayer2PfStatus:106if (bridge_do_pfctl(val->var.subs[sub - 1] - 1,107op, &k_val) < 0)108return (SNMP_ERR_GENERR);109val->v.integer = val2snmp_truth(k_val);110return (SNMP_ERR_NOERROR);111}112abort();113}114115abort();116}117118119