110491SRishi.Srivatsavai@Sun.COM /* 210491SRishi.Srivatsavai@Sun.COM * CDDL HEADER START 310491SRishi.Srivatsavai@Sun.COM * 410491SRishi.Srivatsavai@Sun.COM * The contents of this file are subject to the terms of the 510491SRishi.Srivatsavai@Sun.COM * Common Development and Distribution License (the "License"). 610491SRishi.Srivatsavai@Sun.COM * You may not use this file except in compliance with the License. 710491SRishi.Srivatsavai@Sun.COM * 810491SRishi.Srivatsavai@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 910491SRishi.Srivatsavai@Sun.COM * or http://www.opensolaris.org/os/licensing. 1010491SRishi.Srivatsavai@Sun.COM * See the License for the specific language governing permissions 1110491SRishi.Srivatsavai@Sun.COM * and limitations under the License. 1210491SRishi.Srivatsavai@Sun.COM * 1310491SRishi.Srivatsavai@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 1410491SRishi.Srivatsavai@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1510491SRishi.Srivatsavai@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 1610491SRishi.Srivatsavai@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 1710491SRishi.Srivatsavai@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 1810491SRishi.Srivatsavai@Sun.COM * 1910491SRishi.Srivatsavai@Sun.COM * CDDL HEADER END 2010491SRishi.Srivatsavai@Sun.COM */ 2110491SRishi.Srivatsavai@Sun.COM 2210491SRishi.Srivatsavai@Sun.COM /* 23*11483SRishi.Srivatsavai@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 2410491SRishi.Srivatsavai@Sun.COM * Use is subject to license terms. 2510491SRishi.Srivatsavai@Sun.COM */ 2610491SRishi.Srivatsavai@Sun.COM 2710491SRishi.Srivatsavai@Sun.COM #ifndef _BRIDGE_IMPL_H 2810491SRishi.Srivatsavai@Sun.COM #define _BRIDGE_IMPL_H 2910491SRishi.Srivatsavai@Sun.COM 3010491SRishi.Srivatsavai@Sun.COM /* 3110491SRishi.Srivatsavai@Sun.COM * These are the internal data structures used by the layer-two (Ethernet) 3210491SRishi.Srivatsavai@Sun.COM * bridging module. 3310491SRishi.Srivatsavai@Sun.COM */ 3410491SRishi.Srivatsavai@Sun.COM 3510491SRishi.Srivatsavai@Sun.COM #ifdef __cplusplus 3610491SRishi.Srivatsavai@Sun.COM extern "C" { 3710491SRishi.Srivatsavai@Sun.COM #endif 3810491SRishi.Srivatsavai@Sun.COM 3910491SRishi.Srivatsavai@Sun.COM #include <sys/list.h> 4010491SRishi.Srivatsavai@Sun.COM #include <sys/sysmacros.h> 4110491SRishi.Srivatsavai@Sun.COM #include <sys/avl.h> 4210491SRishi.Srivatsavai@Sun.COM #include <sys/queue.h> 4310491SRishi.Srivatsavai@Sun.COM #include <sys/kstat.h> 4410491SRishi.Srivatsavai@Sun.COM #include <sys/ksynch.h> 4510491SRishi.Srivatsavai@Sun.COM #include <sys/ethernet.h> 4610491SRishi.Srivatsavai@Sun.COM #include <sys/dld.h> 4710491SRishi.Srivatsavai@Sun.COM #include <sys/mac.h> 4810491SRishi.Srivatsavai@Sun.COM #include <sys/mac_client.h> 4910491SRishi.Srivatsavai@Sun.COM #include <sys/vlan.h> 5010491SRishi.Srivatsavai@Sun.COM #include <net/bridge.h> 5110491SRishi.Srivatsavai@Sun.COM 5211109SRishi.Srivatsavai@Sun.COM #define BRIDGE_DEV_NAME "bridge" 5311109SRishi.Srivatsavai@Sun.COM 5410491SRishi.Srivatsavai@Sun.COM #define KSINST_NAMES "recv", "sent", "drops", \ 5510491SRishi.Srivatsavai@Sun.COM "forward_direct", "forward_unknown", "forward_mbcast", \ 5610491SRishi.Srivatsavai@Sun.COM "learn_source", "learn_moved", "learn_expire", "learn_size" 5710491SRishi.Srivatsavai@Sun.COM typedef struct bridge_ksinst_s { 5810491SRishi.Srivatsavai@Sun.COM kstat_named_t bki_recv; /* packets received */ 5910491SRishi.Srivatsavai@Sun.COM kstat_named_t bki_sent; /* packets sent through */ 6010491SRishi.Srivatsavai@Sun.COM kstat_named_t bki_drops; /* packets dropped (untowardly) */ 6110491SRishi.Srivatsavai@Sun.COM kstat_named_t bki_forwards; /* packets forwarded */ 6210491SRishi.Srivatsavai@Sun.COM kstat_named_t bki_unknown; /* packets forwarded (unknown dest) */ 6310491SRishi.Srivatsavai@Sun.COM kstat_named_t bki_mbcast; /* packets forwarded (multi/bcast) */ 6410491SRishi.Srivatsavai@Sun.COM kstat_named_t bki_source; /* source addresses learned */ 6510491SRishi.Srivatsavai@Sun.COM kstat_named_t bki_moved; /* source addresses moved */ 6610491SRishi.Srivatsavai@Sun.COM kstat_named_t bki_expire; /* source addresses expired */ 6710491SRishi.Srivatsavai@Sun.COM kstat_named_t bki_count; /* source addresses known */ 6810491SRishi.Srivatsavai@Sun.COM } bridge_ksinst_t; 6910491SRishi.Srivatsavai@Sun.COM 7010491SRishi.Srivatsavai@Sun.COM #define KSLINK_NAMES "recv", "xmit", "drops" 7110491SRishi.Srivatsavai@Sun.COM typedef struct bridge_kslink_s { 7210491SRishi.Srivatsavai@Sun.COM kstat_named_t bkl_recv; /* packets received */ 7310491SRishi.Srivatsavai@Sun.COM kstat_named_t bkl_xmit; /* packets transmitted */ 7410491SRishi.Srivatsavai@Sun.COM kstat_named_t bkl_drops; /* packets dropped */ 7510491SRishi.Srivatsavai@Sun.COM } bridge_kslink_t; 7610491SRishi.Srivatsavai@Sun.COM 7710491SRishi.Srivatsavai@Sun.COM /* 7810491SRishi.Srivatsavai@Sun.COM * There's one instance structure and one observability mac node for each 7910491SRishi.Srivatsavai@Sun.COM * bridge. Each open non-DLPI stream gets a 'stream' structure; these are used 8010491SRishi.Srivatsavai@Sun.COM * for bridge instance allocation and control. Each link on the bridge has a 8110491SRishi.Srivatsavai@Sun.COM * link structure. Finally, the bridge has a table of learned forwarding 8210491SRishi.Srivatsavai@Sun.COM * entries, each with a list of outputs, which are either links or TRILL 8310491SRishi.Srivatsavai@Sun.COM * nicknames. 8410491SRishi.Srivatsavai@Sun.COM * 8510491SRishi.Srivatsavai@Sun.COM * The mac structure lives as long as the dls and mac layers are busy. It can 8610491SRishi.Srivatsavai@Sun.COM * outlive the bridge instance and be picked up again (by name) if the instance 8710491SRishi.Srivatsavai@Sun.COM * is restarted. 8810491SRishi.Srivatsavai@Sun.COM */ 8910491SRishi.Srivatsavai@Sun.COM 9010491SRishi.Srivatsavai@Sun.COM struct bridge_mac_s; 9110491SRishi.Srivatsavai@Sun.COM struct bridge_stream_s; 9210491SRishi.Srivatsavai@Sun.COM 9310491SRishi.Srivatsavai@Sun.COM typedef struct bridge_inst_s { 9410491SRishi.Srivatsavai@Sun.COM list_node_t bi_node; 9510491SRishi.Srivatsavai@Sun.COM dev_t bi_dev; 9610491SRishi.Srivatsavai@Sun.COM uint_t bi_flags; 9710491SRishi.Srivatsavai@Sun.COM uint_t bi_refs; 9810491SRishi.Srivatsavai@Sun.COM uint32_t bi_tablemax; 9910491SRishi.Srivatsavai@Sun.COM uint_t bi_tshift; 10010491SRishi.Srivatsavai@Sun.COM krwlock_t bi_rwlock; 10110491SRishi.Srivatsavai@Sun.COM list_t bi_links; 10210491SRishi.Srivatsavai@Sun.COM kcondvar_t bi_linkwait; 10310491SRishi.Srivatsavai@Sun.COM avl_tree_t bi_fwd; 10410491SRishi.Srivatsavai@Sun.COM kstat_t *bi_ksp; 10510491SRishi.Srivatsavai@Sun.COM struct bridge_stream_s *bi_control; 10610491SRishi.Srivatsavai@Sun.COM struct bridge_mac_s *bi_mac; 10710491SRishi.Srivatsavai@Sun.COM void *bi_trilldata; 10810491SRishi.Srivatsavai@Sun.COM char bi_name[MAXLINKNAMELEN]; 10910491SRishi.Srivatsavai@Sun.COM bridge_ksinst_t bi_kstats; 11010491SRishi.Srivatsavai@Sun.COM } bridge_inst_t; 11110491SRishi.Srivatsavai@Sun.COM 11210491SRishi.Srivatsavai@Sun.COM #define BIF_SHUTDOWN 0x0001 /* control stream has closed */ 11310491SRishi.Srivatsavai@Sun.COM 11410491SRishi.Srivatsavai@Sun.COM /* 11510491SRishi.Srivatsavai@Sun.COM * The bridge MAC structure has the same lifetime as an observability node. 11610491SRishi.Srivatsavai@Sun.COM * It's created when a bridge instance is allocated, but is not freed when the 11710491SRishi.Srivatsavai@Sun.COM * instance is removed because there's no way for a MAC client to guarantee 11810491SRishi.Srivatsavai@Sun.COM * that all users have disappeared. 11910491SRishi.Srivatsavai@Sun.COM */ 12010491SRishi.Srivatsavai@Sun.COM typedef struct bridge_mac_s { 12110491SRishi.Srivatsavai@Sun.COM list_node_t bm_node; 12210491SRishi.Srivatsavai@Sun.COM mac_handle_t bm_mh; 12310491SRishi.Srivatsavai@Sun.COM bridge_inst_t *bm_inst; 12410491SRishi.Srivatsavai@Sun.COM uint_t bm_flags; /* BMF_* below */ 12510491SRishi.Srivatsavai@Sun.COM uint_t bm_maxsdu; 12610491SRishi.Srivatsavai@Sun.COM link_state_t bm_linkstate; 12710491SRishi.Srivatsavai@Sun.COM char bm_name[MAXLINKNAMELEN]; 12810491SRishi.Srivatsavai@Sun.COM } bridge_mac_t; 12910491SRishi.Srivatsavai@Sun.COM 13010491SRishi.Srivatsavai@Sun.COM #define BMF_DLS 0x0001 /* dls monitor node created */ 13110491SRishi.Srivatsavai@Sun.COM #define BMF_STARTED 0x0002 /* snoop-like client is present */ 13210491SRishi.Srivatsavai@Sun.COM 13310491SRishi.Srivatsavai@Sun.COM /* 13410491SRishi.Srivatsavai@Sun.COM * Bridge streams are used only for instance allocation and control. 13510491SRishi.Srivatsavai@Sun.COM */ 13610491SRishi.Srivatsavai@Sun.COM typedef struct bridge_stream_s { 13710491SRishi.Srivatsavai@Sun.COM bridge_inst_t *bs_inst; 13810491SRishi.Srivatsavai@Sun.COM queue_t *bs_wq; /* write-side queue for stream */ 13910491SRishi.Srivatsavai@Sun.COM minor_t bs_minor; 14010491SRishi.Srivatsavai@Sun.COM uint_t bs_taskq_cnt; /* taskq references */ 14110491SRishi.Srivatsavai@Sun.COM } bridge_stream_t; 14210491SRishi.Srivatsavai@Sun.COM 14310491SRishi.Srivatsavai@Sun.COM /* 14410491SRishi.Srivatsavai@Sun.COM * These macros are used to set and test link membership in particular VLANs. 14510491SRishi.Srivatsavai@Sun.COM * This membership is used to determine how to forward packets between 14610491SRishi.Srivatsavai@Sun.COM * interfaces. 14710491SRishi.Srivatsavai@Sun.COM */ 14810491SRishi.Srivatsavai@Sun.COM 14910491SRishi.Srivatsavai@Sun.COM #define BRIDGE_VLAN_ARR_SIZE \ 15010491SRishi.Srivatsavai@Sun.COM (P2ROUNDUP(VLAN_ID_MAX, NBBY) / NBBY) 15110491SRishi.Srivatsavai@Sun.COM 15210491SRishi.Srivatsavai@Sun.COM #define BRIDGE_VLAN_ISSET(l, v) ((l)->bl_vlans[(v) / NBBY] & \ 15310491SRishi.Srivatsavai@Sun.COM (1 << ((v) % NBBY))) 15410491SRishi.Srivatsavai@Sun.COM 15510491SRishi.Srivatsavai@Sun.COM #define BRIDGE_VLAN_SET(l, v) ((l)->bl_vlans[(v) / NBBY] |= \ 15610491SRishi.Srivatsavai@Sun.COM (1 << ((v) % NBBY))) 15710491SRishi.Srivatsavai@Sun.COM 15810491SRishi.Srivatsavai@Sun.COM #define BRIDGE_VLAN_CLR(l, v) ((l)->bl_vlans[(v) / NBBY] &= \ 15910491SRishi.Srivatsavai@Sun.COM ~(1 << ((v) % NBBY))) 16010491SRishi.Srivatsavai@Sun.COM 16110491SRishi.Srivatsavai@Sun.COM #define BRIDGE_AF_ISSET(l, v) ((l)->bl_afs[(v) / NBBY] & \ 16210491SRishi.Srivatsavai@Sun.COM (1 << ((v) % NBBY))) 16310491SRishi.Srivatsavai@Sun.COM 16410491SRishi.Srivatsavai@Sun.COM /* 16510491SRishi.Srivatsavai@Sun.COM * This structure represents a link attached to a bridge. VLAN membership 16610491SRishi.Srivatsavai@Sun.COM * information is kept here; when forwarding, we must look at the membership of 16710491SRishi.Srivatsavai@Sun.COM * the input link and the output to determine when to update the packet 16810491SRishi.Srivatsavai@Sun.COM * contents and when to discard. 16910491SRishi.Srivatsavai@Sun.COM */ 17010491SRishi.Srivatsavai@Sun.COM typedef struct bridge_link_s { 17110491SRishi.Srivatsavai@Sun.COM list_node_t bl_node; 17210491SRishi.Srivatsavai@Sun.COM uint_t bl_refs; 17310491SRishi.Srivatsavai@Sun.COM datalink_id_t bl_linkid; /* allocated link ID for bridge */ 17410491SRishi.Srivatsavai@Sun.COM bridge_state_t bl_state; /* blocking/learning/forwarding */ 17510491SRishi.Srivatsavai@Sun.COM uint_t bl_pvid; /* VLAN ID for untagged traffic */ 17610491SRishi.Srivatsavai@Sun.COM uint_t bl_flags; /* BLF_* below */ 17710491SRishi.Srivatsavai@Sun.COM uint_t bl_learns; /* learning limit */ 17810491SRishi.Srivatsavai@Sun.COM mac_handle_t bl_mh; 17910491SRishi.Srivatsavai@Sun.COM mac_client_handle_t bl_mch; 18010491SRishi.Srivatsavai@Sun.COM uint32_t bl_margin; 18110491SRishi.Srivatsavai@Sun.COM uint_t bl_maxsdu; 18210491SRishi.Srivatsavai@Sun.COM mac_unicast_handle_t bl_mah; 18310491SRishi.Srivatsavai@Sun.COM mac_notify_handle_t bl_mnh; 18410491SRishi.Srivatsavai@Sun.COM mac_promisc_handle_t bl_mphp; 18510491SRishi.Srivatsavai@Sun.COM bridge_inst_t *bl_inst; /* backpointer to bridge instance */ 18610491SRishi.Srivatsavai@Sun.COM kstat_t *bl_ksp; 18710491SRishi.Srivatsavai@Sun.COM void *bl_trilldata; 18810491SRishi.Srivatsavai@Sun.COM mblk_t *bl_lfailmp; /* preallocated */ 18910491SRishi.Srivatsavai@Sun.COM link_state_t bl_linkstate; 19010491SRishi.Srivatsavai@Sun.COM uint_t bl_trillthreads; 19110491SRishi.Srivatsavai@Sun.COM kcondvar_t bl_trillwait; 19210491SRishi.Srivatsavai@Sun.COM kmutex_t bl_trilllock; 19310491SRishi.Srivatsavai@Sun.COM uint8_t bl_local_mac[ETHERADDRL]; 19410491SRishi.Srivatsavai@Sun.COM uint8_t bl_vlans[BRIDGE_VLAN_ARR_SIZE]; 19510491SRishi.Srivatsavai@Sun.COM uint8_t bl_afs[BRIDGE_VLAN_ARR_SIZE]; 19610491SRishi.Srivatsavai@Sun.COM bridge_kslink_t bl_kstats; 19710491SRishi.Srivatsavai@Sun.COM } bridge_link_t; 19810491SRishi.Srivatsavai@Sun.COM 19910491SRishi.Srivatsavai@Sun.COM #define BLF_DELETED 0x0001 /* waiting for last reference to go */ 20010491SRishi.Srivatsavai@Sun.COM #define BLF_CLIENT_OPEN 0x0002 /* MAC client opened */ 20110491SRishi.Srivatsavai@Sun.COM #define BLF_MARGIN_ADDED 0x0004 /* MAC margin added */ 20210491SRishi.Srivatsavai@Sun.COM #define BLF_SET_BRIDGE 0x0008 /* MAC in bridging mode */ 20310491SRishi.Srivatsavai@Sun.COM #define BLF_PROM_ADDED 0x0010 /* MAC promiscuous added */ 20410491SRishi.Srivatsavai@Sun.COM #define BLF_FREED 0x0020 /* free has begun; debug assertion */ 20510491SRishi.Srivatsavai@Sun.COM #define BLF_TRILLACTIVE 0x0040 /* in active forwarding use */ 20610491SRishi.Srivatsavai@Sun.COM #define BLF_SDUFAIL 0x0080 /* has mismatched SDU */ 207*11483SRishi.Srivatsavai@Sun.COM #define BLF_LINK_ADDED 0x0100 /* link added in bridge instance */ 20810491SRishi.Srivatsavai@Sun.COM 20910491SRishi.Srivatsavai@Sun.COM /* 21010491SRishi.Srivatsavai@Sun.COM * This represents a learned forwarding entry. These are generally created and 21110491SRishi.Srivatsavai@Sun.COM * refreshed on demand as we learn about nodes through source MAC addresses we 21210491SRishi.Srivatsavai@Sun.COM * see. They're destroyed when they age away. For forwarding, we look up the 21310491SRishi.Srivatsavai@Sun.COM * destination address in an AVL tree, and the entry found tells us where the 21410491SRishi.Srivatsavai@Sun.COM * that source must live. 21510491SRishi.Srivatsavai@Sun.COM */ 21610491SRishi.Srivatsavai@Sun.COM typedef struct bridge_fwd_s { 21710491SRishi.Srivatsavai@Sun.COM avl_node_t bf_node; 21810491SRishi.Srivatsavai@Sun.COM uchar_t bf_dest[ETHERADDRL]; 21910491SRishi.Srivatsavai@Sun.COM uint16_t bf_trill_nick; /* destination nickname */ 22010491SRishi.Srivatsavai@Sun.COM clock_t bf_lastheard; /* time we last heard from this node */ 22110491SRishi.Srivatsavai@Sun.COM uint_t bf_flags; /* BFF_* below */ 22210491SRishi.Srivatsavai@Sun.COM uint_t bf_refs; 22310491SRishi.Srivatsavai@Sun.COM uint16_t bf_vlanid; /* VLAN ID for IVL */ 22410491SRishi.Srivatsavai@Sun.COM uint16_t bf_vcnt; /* number of duplicates */ 22510491SRishi.Srivatsavai@Sun.COM uint_t bf_nlinks; /* number of links in bf_links */ 22610491SRishi.Srivatsavai@Sun.COM uint_t bf_maxlinks; /* allocated size of link array */ 22710491SRishi.Srivatsavai@Sun.COM bridge_link_t **bf_links; 22810491SRishi.Srivatsavai@Sun.COM } bridge_fwd_t; 22910491SRishi.Srivatsavai@Sun.COM 23010491SRishi.Srivatsavai@Sun.COM #define BFF_INTREE 0x0001 23110491SRishi.Srivatsavai@Sun.COM #define BFF_LOCALADDR 0x0002 /* address is known to mac layer */ 23210491SRishi.Srivatsavai@Sun.COM #define BFF_VLANLOCAL 0x0004 /* set if duplicate for IVL */ 23310491SRishi.Srivatsavai@Sun.COM 23410491SRishi.Srivatsavai@Sun.COM /* TRILL linkage */ 23510491SRishi.Srivatsavai@Sun.COM typedef void (*trill_recv_pkt_t)(void *, bridge_link_t *, mac_resource_handle_t, 23610491SRishi.Srivatsavai@Sun.COM mblk_t *, mac_header_info_t *); 23710491SRishi.Srivatsavai@Sun.COM typedef void (*trill_encap_pkt_t)(void *, bridge_link_t *, mac_header_info_t *, 23810491SRishi.Srivatsavai@Sun.COM mblk_t *, uint16_t); 23910491SRishi.Srivatsavai@Sun.COM typedef void (*trill_br_dstr_t)(void *, bridge_inst_t *); 24010491SRishi.Srivatsavai@Sun.COM typedef void (*trill_ln_dstr_t)(void *, bridge_link_t *); 24110491SRishi.Srivatsavai@Sun.COM 24210491SRishi.Srivatsavai@Sun.COM extern void bridge_trill_register_cb(trill_recv_pkt_t, trill_encap_pkt_t, 24310491SRishi.Srivatsavai@Sun.COM trill_br_dstr_t, trill_ln_dstr_t); 24410491SRishi.Srivatsavai@Sun.COM extern bridge_inst_t *bridge_trill_brref(const char *, void *); 24510491SRishi.Srivatsavai@Sun.COM extern void bridge_trill_brunref(bridge_inst_t *); 24610491SRishi.Srivatsavai@Sun.COM extern bridge_link_t *bridge_trill_lnref(bridge_inst_t *, datalink_id_t, 24710491SRishi.Srivatsavai@Sun.COM void *); 24810491SRishi.Srivatsavai@Sun.COM extern void bridge_trill_lnunref(bridge_link_t *); 24910491SRishi.Srivatsavai@Sun.COM extern void bridge_trill_decaps(bridge_link_t *, mblk_t *, uint16_t); 25010491SRishi.Srivatsavai@Sun.COM extern mblk_t *bridge_trill_output(bridge_link_t *, mblk_t *); 25110491SRishi.Srivatsavai@Sun.COM extern void bridge_trill_setvlans(bridge_link_t *, const uint8_t *); 25210491SRishi.Srivatsavai@Sun.COM extern void bridge_trill_flush(bridge_link_t *, uint16_t, boolean_t); 25310491SRishi.Srivatsavai@Sun.COM 25410491SRishi.Srivatsavai@Sun.COM /* Ethernet multicast address; constant stored in bridge module */ 25510491SRishi.Srivatsavai@Sun.COM extern const uint8_t all_isis_rbridges[]; 25610491SRishi.Srivatsavai@Sun.COM extern const uint8_t bridge_group_address[]; 25710491SRishi.Srivatsavai@Sun.COM 25810491SRishi.Srivatsavai@Sun.COM #ifdef __cplusplus 25910491SRishi.Srivatsavai@Sun.COM } 26010491SRishi.Srivatsavai@Sun.COM #endif 26110491SRishi.Srivatsavai@Sun.COM 26210491SRishi.Srivatsavai@Sun.COM #endif /* _BRIDGE_IMPL_H */ 263