Path: blob/main/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_snmp.h
107769 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*/2930#ifndef SNMP_BRIDGE_H31#define SNMP_BRIDGE_H3233#define SNMP_BRIDGE_ID_LEN 83435typedef uint8_t port_id[2];36typedef u_char bridge_id[SNMP_BRIDGE_ID_LEN];3738#define SNMP_BRIDGE_MAX_PRIORITY 655353940#define SNMP_BRIDGE_MIN_AGE_TIME 1041#define SNMP_BRIDGE_MAX_AGE_TIME 10000004243#define SNMP_BRIDGE_MIN_TXHC 144#define SNMP_BRIDGE_MAX_TXHC 104546#define SNMP_BRIDGE_MIN_MAGE 60047#define SNMP_BRIDGE_MAX_MAGE 40004849#define SNMP_BRIDGE_MIN_HTIME 10050#define SNMP_BRIDGE_MAX_HTIME 10005152#define SNMP_BRIDGE_MIN_FDELAY 40053#define SNMP_BRIDGE_MAX_FDELAY 30005455#define SNMP_PORT_PATHCOST_OBSOLETE 6553556#define SNMP_PORT_MIN_PATHCOST 057#define SNMP_PORT_MAX_PATHCOST 20000000058#define SNMP_PORT_PATHCOST_AUTO 05960#define SNMP_BRIDGE_DATA_MAXAGE 1061#define SNMP_BRIDGE_DATA_MAXAGE_MIN 162#define SNMP_BRIDGE_DATA_MAXAGE_MAX 3006364/* By default poll kernel data every 5 minutes. */65#define SNMP_BRIDGE_POLL_INTERVAL (5 * 60)66#define SNMP_BRIDGE_POLL_INTERVAL_MIN 167#define SNMP_BRIDGE_POLL_INTERVAL_MAX 36006869/* Poll for a topology change once every 30 seconds. */70#define SNMP_BRIDGE_TC_POLL_INTERVAL 307172struct bridge_if *bridge_get_default(void);7374void bridge_set_default(struct bridge_if *bif);7576const char *bridge_get_default_name(void);7778int bridge_get_data_maxage(void);7980/*81* Bridge Addresses Table.82*/83struct tp_entry {84uint32_t sysindex; /* The bridge if sysindex. */85int32_t port_no;86enum TpFdbStatus status;87uint8_t tp_addr[ETHER_ADDR_LEN];88uint8_t flags;89TAILQ_ENTRY(tp_entry) tp_e;90};9192/*93* Bridge ports.94* The bridge port system interface index is used for a95* port number. Transparent bridging statistics and STP96* information for a port are also contained here.97*/98struct bridge_port {99/* dot1dBase subtree objects. */100uint32_t sysindex; /* The bridge interface sysindex. */101int32_t port_no; /* The bridge member system index. */102int32_t if_idx; /* SNMP ifIndex from mibII. */103int8_t span_enable; /* Span flag set - private MIB. */104struct asn_oid circuit; /* Unused. */105uint32_t dly_ex_drops; /* Drops on output. */106uint32_t dly_mtu_drops; /* MTU exceeded drops. */107int32_t status; /* The entry status. */108enum TruthValue priv_set; /* The private flag. */109110/* dot1dStp subtree objects. */111int32_t path_cost;112int32_t priority;113int32_t design_cost;114uint32_t fwd_trans;115char p_name[IFNAMSIZ]; /* Not in BRIDGE-MIB. */116enum StpPortState state;117enum dot1dStpPortEnable enable;118port_id design_port;119bridge_id design_root;120bridge_id design_bridge;121122/* rstpMib extensions. */123int32_t admin_path_cost;124enum TruthValue proto_migr;125enum TruthValue admin_edge;126enum TruthValue oper_edge;127enum TruthValue oper_ptp;128enum StpPortAdminPointToPointType admin_ptp;129130/* dot1dTp subtree objects. */131int32_t max_info;132int32_t in_frames;133int32_t out_frames;134int32_t in_drops;135136uint8_t flags;137TAILQ_ENTRY(bridge_port) b_p;138};139140/*141* A bridge interface.142* The system interface index of the bridge is not required neither by the143* standard BRIDGE-MIB nor by the private BEGEMOT-BRIDGE-MIB, but is used144* as key for looking up the other info for this bridge.145*/146struct bridge_if {147/* dot1dBase subtree objects. */148uint32_t sysindex; /* The system interface index. */149int32_t num_ports; /* Number of ports. */150enum BaseType br_type; /* Bridge type. */151enum RowStatus if_status; /* Bridge status. */152char bif_name[IFNAMSIZ]; /* Bridge interface name. */153struct ether_addr br_addr; /* Bridge address. */154struct bridge_port *f_bp; /* This bridge's first entry155* in the base ports TAILQ. */156/* dot1dStp subtree objects. */157int32_t priority;158int32_t root_cost;159int32_t root_port;160int32_t max_age; /* Current max age. */161int32_t hello_time; /* Current hello time. */162int32_t fwd_delay; /* Current forward delay. */163int32_t hold_time;164int32_t bridge_max_age; /* Configured max age. */165int32_t bridge_hello_time; /* Configured hello time. */166int32_t bridge_fwd_delay; /* Configured forward delay. */167int32_t tx_hold_count;168uint32_t top_changes;169enum dot1dStpVersion stp_version;170enum dot1dStpProtocolSpecification prot_spec;171struct timeval last_tc_time;172bridge_id design_root;173174/* dot1dTp subtree objects. */175int32_t lrnt_drops; /* Dropped addresses. */176int32_t age_time; /* Address entry timeout. */177int32_t num_addrs; /* Current # of addresses in cache. */178int32_t max_addrs; /* Max # of addresses in cache. */179struct tp_entry *f_tpa; /* This bridge's first entry in180* the tp addresses TAILQ. */181182time_t entry_age;183time_t ports_age;184time_t addrs_age;185TAILQ_ENTRY(bridge_if) b_if;186};187188void bridge_ifs_fini(void);189190struct bridge_if *bridge_if_find_ifs(uint32_t sysindex);191192struct bridge_if *bridge_if_find_ifname(const char *b_name);193194const char *bridge_if_find_name(uint32_t sysindex);195196int bridge_compare_sysidx(uint32_t i1, uint32_t i2);197198int bridge_attach_newif(struct mibif *ifp);199200struct bridge_if *bridge_first_bif(void);201202struct bridge_if *bridge_next_bif(struct bridge_if *b_pr);203204void bridge_remove_bif(struct bridge_if *bif);205206void bridge_update_all_ports(void);207208void bridge_update_all_addrs(void);209210void bridge_update_all_ifs(void);211212void bridge_update_all(void *arg);213214void bridge_update_tc_time(void *arg);215216void bridge_ifs_dump(void);217218/* Bridge ports. */219void bridge_ports_update_listage(void);220221void bridge_ports_fini(void);222223void bridge_members_free(struct bridge_if *bif);224225struct bridge_port *bridge_new_port(struct mibif *mif, struct bridge_if *bif);226227void bridge_port_remove(struct bridge_port *bp, struct bridge_if *bif);228229struct bridge_port *bridge_port_bif_first(struct bridge_if *bif);230231struct bridge_port *bridge_port_bif_next(struct bridge_port *bp);232233struct bridge_port *bridge_port_find(int32_t if_idx, struct bridge_if *bif);234235void bridge_port_getinfo_mibif(struct mibif *m_if, struct bridge_port *bp);236237int bridge_getinfo_bif_ports(struct bridge_if *bif);238239int bridge_update_memif(struct bridge_if *bif);240241void bridge_ports_dump(struct bridge_if *bif);242243/* Bridge addresses. */244void bridge_addrs_update_listage(void);245246void bridge_addrs_fini(void);247248void bridge_addrs_free(struct bridge_if *bif);249250struct tp_entry *bridge_new_addrs(uint8_t *mac, struct bridge_if *bif);251252void bridge_addrs_remove(struct tp_entry *te, struct bridge_if *bif);253254struct tp_entry *bridge_addrs_find(uint8_t *mac, struct bridge_if *bif);255256struct tp_entry *bridge_addrs_bif_first(struct bridge_if *bif);257258struct tp_entry *bridge_addrs_bif_next(struct tp_entry *te);259260int bridge_getinfo_bif_addrs(struct bridge_if *bif);261262int bridge_update_addrs(struct bridge_if *bif);263264void bridge_addrs_dump(struct bridge_if *bif);265266/* Bridge PF. */267268void bridge_pf_dump(void);269270/* System specific. */271272/* Open the socket for the ioctls. */273int bridge_ioctl_init(void);274275/* Load bridge kernel module. */276int bridge_kmod_load(void);277278/* Get the bridge interface information. */279int bridge_getinfo_bif(struct bridge_if *bif);280281/* Get the bridge interface STP parameters. */282int bridge_get_op_param(struct bridge_if *bif);283284/* Set the bridge priority. */285int bridge_set_priority(struct bridge_if *bif, int32_t priority);286287/* Set the bridge max age. */288int bridge_set_maxage(struct bridge_if *bif, int32_t max_age);289290/* Set the bridge hello time.*/291int bridge_set_hello_time(struct bridge_if *bif, int32_t hello_time);292293/* Set the bridge forward delay.*/294int bridge_set_forward_delay(struct bridge_if *bif, int32_t fwd_delay);295296/* Set the bridge address cache max age. */297int bridge_set_aging_time(struct bridge_if *bif, int32_t age_time);298299/* Set the max number of entries in the bridge address cache. */300int bridge_set_max_cache(struct bridge_if *bif, int32_t max_cache);301302/* Set the bridge TX hold count. */303int bridge_set_tx_hold_count(struct bridge_if *bif, int32_t tx_hc);304305/* Set the bridge STP protocol version. */306int bridge_set_stp_version(struct bridge_if *bif, int32_t stp_proto);307308/* Set the bridge interface status to up/down. */309int bridge_set_if_up(const char* b_name, int8_t up);310311/* Create a bridge interface. */312int bridge_create(const char *b_name);313314/* Destroy a bridge interface. */315int bridge_destroy(const char *b_name);316317/* Fetch the bridge mac address. */318u_char *bridge_get_basemac(const char *bif_name, u_char *mac, size_t mlen);319320/* Set a bridge member priority. */321int bridge_port_set_priority(const char *bif_name, struct bridge_port *bp,322int32_t priority);323324/* Set a bridge member STP-enabled flag. */325int bridge_port_set_stp_enable(const char *bif_name, struct bridge_port *bp,326uint32_t enable);327328/* Set a bridge member STP path cost. */329int bridge_port_set_path_cost(const char *bif_name, struct bridge_port *bp,330int32_t path_cost);331332/* Set admin point-to-point link. */333int bridge_port_set_admin_ptp(const char *bif_name, struct bridge_port *bp,334uint32_t admin_ptp);335336/* Set admin edge. */337int bridge_port_set_admin_edge(const char *bif_name, struct bridge_port *bp,338uint32_t enable);339340/* Set 'private' flag. */341int bridge_port_set_private(const char *bif_name, struct bridge_port *bp,342uint32_t priv_set);343344/* Add a bridge member port. */345int bridge_port_addm(struct bridge_port *bp, const char *b_name);346347/* Delete a bridge member port. */348int bridge_port_delm(struct bridge_port *bp, const char *b_name);349350/* Get the current value from the module for bridge PF control. */351int32_t bridge_get_pfval(uint8_t which);352353/* Get/Set a bridge PF control. */354int32_t bridge_do_pfctl(int32_t bridge_ctl, enum snmp_op op, int32_t *val);355356#endif /* SNMP_BRIDGE_H */357358359