1*10491SRishi.Srivatsavai@Sun.COM /************************************************************************
2*10491SRishi.Srivatsavai@Sun.COM * RSTP library - Rapid Spanning Tree (802.1t, 802.1w)
3*10491SRishi.Srivatsavai@Sun.COM * Copyright (C) 2001-2003 Optical Access
4*10491SRishi.Srivatsavai@Sun.COM * Author: Alex Rozin
5*10491SRishi.Srivatsavai@Sun.COM *
6*10491SRishi.Srivatsavai@Sun.COM * This file is part of RSTP library.
7*10491SRishi.Srivatsavai@Sun.COM *
8*10491SRishi.Srivatsavai@Sun.COM * RSTP library is free software; you can redistribute it and/or modify it
9*10491SRishi.Srivatsavai@Sun.COM * under the terms of the GNU Lesser General Public License as published by the
10*10491SRishi.Srivatsavai@Sun.COM * Free Software Foundation; version 2.1
11*10491SRishi.Srivatsavai@Sun.COM *
12*10491SRishi.Srivatsavai@Sun.COM * RSTP library is distributed in the hope that it will be useful, but
13*10491SRishi.Srivatsavai@Sun.COM * WITHOUT ANY WARRANTY; without even the implied warranty of
14*10491SRishi.Srivatsavai@Sun.COM * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
15*10491SRishi.Srivatsavai@Sun.COM * General Public License for more details.
16*10491SRishi.Srivatsavai@Sun.COM *
17*10491SRishi.Srivatsavai@Sun.COM * You should have received a copy of the GNU Lesser General Public License
18*10491SRishi.Srivatsavai@Sun.COM * along with RSTP library; see the file COPYING. If not, write to the Free
19*10491SRishi.Srivatsavai@Sun.COM * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20*10491SRishi.Srivatsavai@Sun.COM * 02111-1307, USA.
21*10491SRishi.Srivatsavai@Sun.COM **********************************************************************/
22*10491SRishi.Srivatsavai@Sun.COM
23*10491SRishi.Srivatsavai@Sun.COM /* This file contains API from an operation system to the RSTP library */
24*10491SRishi.Srivatsavai@Sun.COM
25*10491SRishi.Srivatsavai@Sun.COM #include "base.h"
26*10491SRishi.Srivatsavai@Sun.COM #include "stpm.h"
27*10491SRishi.Srivatsavai@Sun.COM #include "stp_in.h"
28*10491SRishi.Srivatsavai@Sun.COM #include "stp_to.h"
29*10491SRishi.Srivatsavai@Sun.COM
30*10491SRishi.Srivatsavai@Sun.COM #define _stp_in_stpm_enable stp_in_stpm_enable
31*10491SRishi.Srivatsavai@Sun.COM
32*10491SRishi.Srivatsavai@Sun.COM STP_VECTORS_T *stp_vectors;
33*10491SRishi.Srivatsavai@Sun.COM
34*10491SRishi.Srivatsavai@Sun.COM void *
stp_in_stpm_create(int vlan_id,char * name,int * err_code)35*10491SRishi.Srivatsavai@Sun.COM stp_in_stpm_create (int vlan_id, char* name, int* err_code)
36*10491SRishi.Srivatsavai@Sun.COM {
37*10491SRishi.Srivatsavai@Sun.COM register STPM_T* this;
38*10491SRishi.Srivatsavai@Sun.COM
39*10491SRishi.Srivatsavai@Sun.COM /* stp_trace ("stp_in_stpm_create(%s)", name); */
40*10491SRishi.Srivatsavai@Sun.COM this = stpapi_stpm_find (vlan_id);
41*10491SRishi.Srivatsavai@Sun.COM if (this) { /* it had just been created :( */
42*10491SRishi.Srivatsavai@Sun.COM *err_code = STP_Nothing_To_Do;
43*10491SRishi.Srivatsavai@Sun.COM return this;
44*10491SRishi.Srivatsavai@Sun.COM }
45*10491SRishi.Srivatsavai@Sun.COM
46*10491SRishi.Srivatsavai@Sun.COM this = STP_stpm_create (vlan_id, name);
47*10491SRishi.Srivatsavai@Sun.COM if (! this) { /* can't create stpm :( */
48*10491SRishi.Srivatsavai@Sun.COM *err_code = STP_Cannot_Create_Instance_For_Vlan;
49*10491SRishi.Srivatsavai@Sun.COM return NULL;
50*10491SRishi.Srivatsavai@Sun.COM }
51*10491SRishi.Srivatsavai@Sun.COM
52*10491SRishi.Srivatsavai@Sun.COM *err_code = STP_OK;
53*10491SRishi.Srivatsavai@Sun.COM return this;
54*10491SRishi.Srivatsavai@Sun.COM }
55*10491SRishi.Srivatsavai@Sun.COM
56*10491SRishi.Srivatsavai@Sun.COM int
_stp_in_stpm_enable(int vlan_id,char * name,UID_STP_MODE_T admin_state)57*10491SRishi.Srivatsavai@Sun.COM _stp_in_stpm_enable (int vlan_id, char* name,
58*10491SRishi.Srivatsavai@Sun.COM UID_STP_MODE_T admin_state)
59*10491SRishi.Srivatsavai@Sun.COM {
60*10491SRishi.Srivatsavai@Sun.COM register STPM_T* this;
61*10491SRishi.Srivatsavai@Sun.COM Bool created_here = False;
62*10491SRishi.Srivatsavai@Sun.COM int rc, err_code;
63*10491SRishi.Srivatsavai@Sun.COM
64*10491SRishi.Srivatsavai@Sun.COM /* stp_trace ("_stp_in_stpm_enable(%s)", name); */
65*10491SRishi.Srivatsavai@Sun.COM this = stpapi_stpm_find (vlan_id);
66*10491SRishi.Srivatsavai@Sun.COM
67*10491SRishi.Srivatsavai@Sun.COM if (STP_DISABLED != admin_state) {
68*10491SRishi.Srivatsavai@Sun.COM if (! vlan_id) { /* STP_IN_stop_all (); */
69*10491SRishi.Srivatsavai@Sun.COM register STPM_T* stpm;
70*10491SRishi.Srivatsavai@Sun.COM
71*10491SRishi.Srivatsavai@Sun.COM for (stpm = STP_stpm_get_the_list (); stpm; stpm = stpm->next) {
72*10491SRishi.Srivatsavai@Sun.COM if (STP_DISABLED != stpm->admin_state) {
73*10491SRishi.Srivatsavai@Sun.COM STP_OUT_set_hardware_mode (stpm->vlan_id, STP_DISABLED);
74*10491SRishi.Srivatsavai@Sun.COM (void) STP_stpm_enable (stpm, STP_DISABLED);
75*10491SRishi.Srivatsavai@Sun.COM }
76*10491SRishi.Srivatsavai@Sun.COM }
77*10491SRishi.Srivatsavai@Sun.COM }
78*10491SRishi.Srivatsavai@Sun.COM }
79*10491SRishi.Srivatsavai@Sun.COM
80*10491SRishi.Srivatsavai@Sun.COM if (! this) { /* it had not yet been created */
81*10491SRishi.Srivatsavai@Sun.COM if (STP_ENABLED == admin_state) {/* try to create it */
82*10491SRishi.Srivatsavai@Sun.COM stp_trace ("implicit create to vlan '%s'", name);
83*10491SRishi.Srivatsavai@Sun.COM this = stp_in_stpm_create (vlan_id, name, &err_code);
84*10491SRishi.Srivatsavai@Sun.COM if (! this) {
85*10491SRishi.Srivatsavai@Sun.COM stp_trace ("implicit create to vlan '%s' failed", name);
86*10491SRishi.Srivatsavai@Sun.COM return STP_Implicit_Instance_Create_Failed;
87*10491SRishi.Srivatsavai@Sun.COM }
88*10491SRishi.Srivatsavai@Sun.COM created_here = True;
89*10491SRishi.Srivatsavai@Sun.COM } else {/* try to disable nothing ? */
90*10491SRishi.Srivatsavai@Sun.COM return 0;
91*10491SRishi.Srivatsavai@Sun.COM }
92*10491SRishi.Srivatsavai@Sun.COM }
93*10491SRishi.Srivatsavai@Sun.COM
94*10491SRishi.Srivatsavai@Sun.COM if (this->admin_state == admin_state) { /* nothing to do :) */
95*10491SRishi.Srivatsavai@Sun.COM return 0;
96*10491SRishi.Srivatsavai@Sun.COM }
97*10491SRishi.Srivatsavai@Sun.COM
98*10491SRishi.Srivatsavai@Sun.COM rc = STP_stpm_enable (this, admin_state);
99*10491SRishi.Srivatsavai@Sun.COM if (! rc) {
100*10491SRishi.Srivatsavai@Sun.COM STP_OUT_set_hardware_mode (vlan_id, admin_state);
101*10491SRishi.Srivatsavai@Sun.COM }
102*10491SRishi.Srivatsavai@Sun.COM
103*10491SRishi.Srivatsavai@Sun.COM if (rc && created_here) {
104*10491SRishi.Srivatsavai@Sun.COM STP_stpm_delete (this);
105*10491SRishi.Srivatsavai@Sun.COM }
106*10491SRishi.Srivatsavai@Sun.COM
107*10491SRishi.Srivatsavai@Sun.COM return rc;
108*10491SRishi.Srivatsavai@Sun.COM }
109*10491SRishi.Srivatsavai@Sun.COM
110*10491SRishi.Srivatsavai@Sun.COM
111*10491SRishi.Srivatsavai@Sun.COM STPM_T *
stpapi_stpm_find(int vlan_id)112*10491SRishi.Srivatsavai@Sun.COM stpapi_stpm_find (int vlan_id)
113*10491SRishi.Srivatsavai@Sun.COM {
114*10491SRishi.Srivatsavai@Sun.COM register STPM_T* this;
115*10491SRishi.Srivatsavai@Sun.COM
116*10491SRishi.Srivatsavai@Sun.COM for (this = STP_stpm_get_the_list (); this; this = this->next)
117*10491SRishi.Srivatsavai@Sun.COM if (vlan_id == this->vlan_id)
118*10491SRishi.Srivatsavai@Sun.COM return this;
119*10491SRishi.Srivatsavai@Sun.COM
120*10491SRishi.Srivatsavai@Sun.COM return NULL;
121*10491SRishi.Srivatsavai@Sun.COM }
122*10491SRishi.Srivatsavai@Sun.COM
123*10491SRishi.Srivatsavai@Sun.COM static PORT_T *
_stpapi_port_find(STPM_T * this,int port_index)124*10491SRishi.Srivatsavai@Sun.COM _stpapi_port_find (STPM_T* this, int port_index)
125*10491SRishi.Srivatsavai@Sun.COM {
126*10491SRishi.Srivatsavai@Sun.COM register PORT_T* port;
127*10491SRishi.Srivatsavai@Sun.COM
128*10491SRishi.Srivatsavai@Sun.COM for (port = this->ports; port; port = port->next)
129*10491SRishi.Srivatsavai@Sun.COM if (port_index == port->port_index) {
130*10491SRishi.Srivatsavai@Sun.COM return port;
131*10491SRishi.Srivatsavai@Sun.COM }
132*10491SRishi.Srivatsavai@Sun.COM
133*10491SRishi.Srivatsavai@Sun.COM return NULL;
134*10491SRishi.Srivatsavai@Sun.COM }
135*10491SRishi.Srivatsavai@Sun.COM
136*10491SRishi.Srivatsavai@Sun.COM
137*10491SRishi.Srivatsavai@Sun.COM static void
_conv_br_id_2_uid(IN BRIDGE_ID * f,OUT UID_BRIDGE_ID_T * t)138*10491SRishi.Srivatsavai@Sun.COM _conv_br_id_2_uid (IN BRIDGE_ID* f, OUT UID_BRIDGE_ID_T* t)
139*10491SRishi.Srivatsavai@Sun.COM {
140*10491SRishi.Srivatsavai@Sun.COM (void) memcpy (t, f, sizeof (UID_BRIDGE_ID_T));
141*10491SRishi.Srivatsavai@Sun.COM }
142*10491SRishi.Srivatsavai@Sun.COM
143*10491SRishi.Srivatsavai@Sun.COM static int
_check_stpm_config(IN UID_STP_CFG_T * uid_cfg)144*10491SRishi.Srivatsavai@Sun.COM _check_stpm_config (IN UID_STP_CFG_T* uid_cfg)
145*10491SRishi.Srivatsavai@Sun.COM {
146*10491SRishi.Srivatsavai@Sun.COM if (uid_cfg->bridge_priority < MIN_BR_PRIO) {
147*10491SRishi.Srivatsavai@Sun.COM stp_trace ("%d bridge_priority small", (int) uid_cfg->bridge_priority);
148*10491SRishi.Srivatsavai@Sun.COM return STP_Small_Bridge_Priority;
149*10491SRishi.Srivatsavai@Sun.COM }
150*10491SRishi.Srivatsavai@Sun.COM
151*10491SRishi.Srivatsavai@Sun.COM if (uid_cfg->bridge_priority > MAX_BR_PRIO) {
152*10491SRishi.Srivatsavai@Sun.COM stp_trace ("%d bridge_priority large", (int) uid_cfg->bridge_priority);
153*10491SRishi.Srivatsavai@Sun.COM return STP_Large_Bridge_Priority;
154*10491SRishi.Srivatsavai@Sun.COM }
155*10491SRishi.Srivatsavai@Sun.COM
156*10491SRishi.Srivatsavai@Sun.COM if (uid_cfg->hello_time < MIN_BR_HELLOT) {
157*10491SRishi.Srivatsavai@Sun.COM stp_trace ("%d hello_time small", (int) uid_cfg->hello_time);
158*10491SRishi.Srivatsavai@Sun.COM return STP_Small_Hello_Time;
159*10491SRishi.Srivatsavai@Sun.COM }
160*10491SRishi.Srivatsavai@Sun.COM
161*10491SRishi.Srivatsavai@Sun.COM if (uid_cfg->hello_time > MAX_BR_HELLOT) {
162*10491SRishi.Srivatsavai@Sun.COM stp_trace ("%d hello_time large", (int) uid_cfg->hello_time);
163*10491SRishi.Srivatsavai@Sun.COM return STP_Large_Hello_Time;
164*10491SRishi.Srivatsavai@Sun.COM }
165*10491SRishi.Srivatsavai@Sun.COM
166*10491SRishi.Srivatsavai@Sun.COM if (uid_cfg->max_age < MIN_BR_MAXAGE) {
167*10491SRishi.Srivatsavai@Sun.COM stp_trace ("%d max_age small", (int) uid_cfg->max_age);
168*10491SRishi.Srivatsavai@Sun.COM return STP_Small_Max_Age;
169*10491SRishi.Srivatsavai@Sun.COM }
170*10491SRishi.Srivatsavai@Sun.COM
171*10491SRishi.Srivatsavai@Sun.COM if (uid_cfg->max_age > MAX_BR_MAXAGE) {
172*10491SRishi.Srivatsavai@Sun.COM stp_trace ("%d max_age large", (int) uid_cfg->max_age);
173*10491SRishi.Srivatsavai@Sun.COM return STP_Large_Max_Age;
174*10491SRishi.Srivatsavai@Sun.COM }
175*10491SRishi.Srivatsavai@Sun.COM
176*10491SRishi.Srivatsavai@Sun.COM if (uid_cfg->forward_delay < MIN_BR_FWDELAY) {
177*10491SRishi.Srivatsavai@Sun.COM stp_trace ("%d forward_delay small", (int) uid_cfg->forward_delay);
178*10491SRishi.Srivatsavai@Sun.COM return STP_Small_Forward_Delay;
179*10491SRishi.Srivatsavai@Sun.COM }
180*10491SRishi.Srivatsavai@Sun.COM
181*10491SRishi.Srivatsavai@Sun.COM if (uid_cfg->forward_delay > MAX_BR_FWDELAY) {
182*10491SRishi.Srivatsavai@Sun.COM stp_trace ("%d forward_delay large", (int) uid_cfg->forward_delay);
183*10491SRishi.Srivatsavai@Sun.COM return STP_Large_Forward_Delay;
184*10491SRishi.Srivatsavai@Sun.COM }
185*10491SRishi.Srivatsavai@Sun.COM
186*10491SRishi.Srivatsavai@Sun.COM if (2 * (uid_cfg->forward_delay - 1) < uid_cfg->max_age) {
187*10491SRishi.Srivatsavai@Sun.COM return STP_Forward_Delay_And_Max_Age_Are_Inconsistent;
188*10491SRishi.Srivatsavai@Sun.COM }
189*10491SRishi.Srivatsavai@Sun.COM
190*10491SRishi.Srivatsavai@Sun.COM if (uid_cfg->max_age < 2 * (uid_cfg->hello_time + 1)) {
191*10491SRishi.Srivatsavai@Sun.COM return STP_Hello_Time_And_Max_Age_Are_Inconsistent;
192*10491SRishi.Srivatsavai@Sun.COM }
193*10491SRishi.Srivatsavai@Sun.COM
194*10491SRishi.Srivatsavai@Sun.COM return 0;
195*10491SRishi.Srivatsavai@Sun.COM }
196*10491SRishi.Srivatsavai@Sun.COM
197*10491SRishi.Srivatsavai@Sun.COM static void
_stp_in_enable_port_on_stpm(STPM_T * stpm,int port_index,Bool enable)198*10491SRishi.Srivatsavai@Sun.COM _stp_in_enable_port_on_stpm (STPM_T* stpm, int port_index, Bool enable)
199*10491SRishi.Srivatsavai@Sun.COM {
200*10491SRishi.Srivatsavai@Sun.COM register PORT_T* port;
201*10491SRishi.Srivatsavai@Sun.COM
202*10491SRishi.Srivatsavai@Sun.COM port = _stpapi_port_find (stpm, port_index);
203*10491SRishi.Srivatsavai@Sun.COM if (! port) return;
204*10491SRishi.Srivatsavai@Sun.COM if (port->portEnabled == enable) {/* nothing to do :) */
205*10491SRishi.Srivatsavai@Sun.COM return;
206*10491SRishi.Srivatsavai@Sun.COM }
207*10491SRishi.Srivatsavai@Sun.COM
208*10491SRishi.Srivatsavai@Sun.COM port->uptime = 0;
209*10491SRishi.Srivatsavai@Sun.COM if (enable) { /* clear port statistics */
210*10491SRishi.Srivatsavai@Sun.COM port->rx_cfg_bpdu_cnt =
211*10491SRishi.Srivatsavai@Sun.COM port->rx_rstp_bpdu_cnt =
212*10491SRishi.Srivatsavai@Sun.COM port->rx_tcn_bpdu_cnt = 0;
213*10491SRishi.Srivatsavai@Sun.COM }
214*10491SRishi.Srivatsavai@Sun.COM
215*10491SRishi.Srivatsavai@Sun.COM #ifdef STP_DBG
216*10491SRishi.Srivatsavai@Sun.COM if (port->edge->debug) {
217*10491SRishi.Srivatsavai@Sun.COM stp_trace ("Port %s became '%s' adminEdge=%c",
218*10491SRishi.Srivatsavai@Sun.COM port->port_name, enable ? "enable" : "disable",
219*10491SRishi.Srivatsavai@Sun.COM port->adminEdge ? 'Y' : 'N');
220*10491SRishi.Srivatsavai@Sun.COM }
221*10491SRishi.Srivatsavai@Sun.COM #endif
222*10491SRishi.Srivatsavai@Sun.COM
223*10491SRishi.Srivatsavai@Sun.COM port->adminEnable = enable;
224*10491SRishi.Srivatsavai@Sun.COM STP_port_init (port, stpm, False);
225*10491SRishi.Srivatsavai@Sun.COM
226*10491SRishi.Srivatsavai@Sun.COM port->reselect = True;
227*10491SRishi.Srivatsavai@Sun.COM port->selected = False;
228*10491SRishi.Srivatsavai@Sun.COM }
229*10491SRishi.Srivatsavai@Sun.COM
230*10491SRishi.Srivatsavai@Sun.COM void
STP_IN_init(STP_VECTORS_T * vectors)231*10491SRishi.Srivatsavai@Sun.COM STP_IN_init (STP_VECTORS_T *vectors)
232*10491SRishi.Srivatsavai@Sun.COM {
233*10491SRishi.Srivatsavai@Sun.COM RSTP_INIT_CRITICAL_PATH_PROTECTIO;
234*10491SRishi.Srivatsavai@Sun.COM stp_vectors = vectors;
235*10491SRishi.Srivatsavai@Sun.COM }
236*10491SRishi.Srivatsavai@Sun.COM
237*10491SRishi.Srivatsavai@Sun.COM int
STP_IN_stpm_get_cfg(IN int vlan_id,OUT UID_STP_CFG_T * uid_cfg)238*10491SRishi.Srivatsavai@Sun.COM STP_IN_stpm_get_cfg (IN int vlan_id, OUT UID_STP_CFG_T* uid_cfg)
239*10491SRishi.Srivatsavai@Sun.COM {
240*10491SRishi.Srivatsavai@Sun.COM register STPM_T* this;
241*10491SRishi.Srivatsavai@Sun.COM
242*10491SRishi.Srivatsavai@Sun.COM uid_cfg->field_mask = 0;
243*10491SRishi.Srivatsavai@Sun.COM
244*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_START;
245*10491SRishi.Srivatsavai@Sun.COM this = stpapi_stpm_find (vlan_id);
246*10491SRishi.Srivatsavai@Sun.COM
247*10491SRishi.Srivatsavai@Sun.COM if (!this) { /* it had not yet been created :( */
248*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
249*10491SRishi.Srivatsavai@Sun.COM return STP_Vlan_Had_Not_Yet_Been_Created;
250*10491SRishi.Srivatsavai@Sun.COM }
251*10491SRishi.Srivatsavai@Sun.COM
252*10491SRishi.Srivatsavai@Sun.COM if (this->admin_state != STP_DISABLED) {
253*10491SRishi.Srivatsavai@Sun.COM uid_cfg->field_mask |= BR_CFG_STATE;
254*10491SRishi.Srivatsavai@Sun.COM }
255*10491SRishi.Srivatsavai@Sun.COM uid_cfg->stp_enabled = this->admin_state;
256*10491SRishi.Srivatsavai@Sun.COM
257*10491SRishi.Srivatsavai@Sun.COM if (this->ForceVersion != 2) {
258*10491SRishi.Srivatsavai@Sun.COM uid_cfg->field_mask |= BR_CFG_FORCE_VER;
259*10491SRishi.Srivatsavai@Sun.COM }
260*10491SRishi.Srivatsavai@Sun.COM uid_cfg->force_version = this->ForceVersion;
261*10491SRishi.Srivatsavai@Sun.COM
262*10491SRishi.Srivatsavai@Sun.COM if (this->BrId.prio != DEF_BR_PRIO) {
263*10491SRishi.Srivatsavai@Sun.COM uid_cfg->field_mask |= BR_CFG_PRIO;
264*10491SRishi.Srivatsavai@Sun.COM }
265*10491SRishi.Srivatsavai@Sun.COM uid_cfg->bridge_priority = this->BrId.prio;
266*10491SRishi.Srivatsavai@Sun.COM
267*10491SRishi.Srivatsavai@Sun.COM if (this->BrTimes.MaxAge != DEF_BR_MAXAGE) {
268*10491SRishi.Srivatsavai@Sun.COM uid_cfg->field_mask |= BR_CFG_AGE;
269*10491SRishi.Srivatsavai@Sun.COM }
270*10491SRishi.Srivatsavai@Sun.COM uid_cfg->max_age = this->BrTimes.MaxAge;
271*10491SRishi.Srivatsavai@Sun.COM
272*10491SRishi.Srivatsavai@Sun.COM if (this->BrTimes.HelloTime != DEF_BR_HELLOT) {
273*10491SRishi.Srivatsavai@Sun.COM uid_cfg->field_mask |= BR_CFG_HELLO;
274*10491SRishi.Srivatsavai@Sun.COM }
275*10491SRishi.Srivatsavai@Sun.COM uid_cfg->hello_time = this->BrTimes.HelloTime;
276*10491SRishi.Srivatsavai@Sun.COM
277*10491SRishi.Srivatsavai@Sun.COM if (this->BrTimes.ForwardDelay != DEF_BR_FWDELAY) {
278*10491SRishi.Srivatsavai@Sun.COM uid_cfg->field_mask |= BR_CFG_DELAY;
279*10491SRishi.Srivatsavai@Sun.COM }
280*10491SRishi.Srivatsavai@Sun.COM uid_cfg->forward_delay = this->BrTimes.ForwardDelay;
281*10491SRishi.Srivatsavai@Sun.COM
282*10491SRishi.Srivatsavai@Sun.COM uid_cfg->hold_time = TxHoldCount;
283*10491SRishi.Srivatsavai@Sun.COM
284*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
285*10491SRishi.Srivatsavai@Sun.COM return 0;
286*10491SRishi.Srivatsavai@Sun.COM }
287*10491SRishi.Srivatsavai@Sun.COM
288*10491SRishi.Srivatsavai@Sun.COM int
STP_IN_port_get_cfg(int vlan_id,int port_index,UID_STP_PORT_CFG_T * uid_cfg)289*10491SRishi.Srivatsavai@Sun.COM STP_IN_port_get_cfg (int vlan_id, int port_index, UID_STP_PORT_CFG_T* uid_cfg)
290*10491SRishi.Srivatsavai@Sun.COM {
291*10491SRishi.Srivatsavai@Sun.COM register STPM_T* this;
292*10491SRishi.Srivatsavai@Sun.COM register PORT_T* port;
293*10491SRishi.Srivatsavai@Sun.COM
294*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_START;
295*10491SRishi.Srivatsavai@Sun.COM this = stpapi_stpm_find (vlan_id);
296*10491SRishi.Srivatsavai@Sun.COM
297*10491SRishi.Srivatsavai@Sun.COM if (!this) { /* it had not yet been created :( */
298*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
299*10491SRishi.Srivatsavai@Sun.COM return STP_Vlan_Had_Not_Yet_Been_Created;
300*10491SRishi.Srivatsavai@Sun.COM }
301*10491SRishi.Srivatsavai@Sun.COM
302*10491SRishi.Srivatsavai@Sun.COM port = _stpapi_port_find (this, port_index);
303*10491SRishi.Srivatsavai@Sun.COM if (! port) {/* port is absent in the stpm :( */
304*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
305*10491SRishi.Srivatsavai@Sun.COM return STP_Port_Is_Absent_In_The_Vlan;
306*10491SRishi.Srivatsavai@Sun.COM }
307*10491SRishi.Srivatsavai@Sun.COM
308*10491SRishi.Srivatsavai@Sun.COM uid_cfg->field_mask = 0;
309*10491SRishi.Srivatsavai@Sun.COM
310*10491SRishi.Srivatsavai@Sun.COM uid_cfg->port_priority = port->port_id >> 8;
311*10491SRishi.Srivatsavai@Sun.COM if (uid_cfg->port_priority != DEF_PORT_PRIO)
312*10491SRishi.Srivatsavai@Sun.COM uid_cfg->field_mask |= PT_CFG_PRIO;
313*10491SRishi.Srivatsavai@Sun.COM
314*10491SRishi.Srivatsavai@Sun.COM uid_cfg->admin_port_path_cost = port->adminPCost;
315*10491SRishi.Srivatsavai@Sun.COM if (uid_cfg->admin_port_path_cost != ADMIN_PORT_PATH_COST_AUTO)
316*10491SRishi.Srivatsavai@Sun.COM uid_cfg->field_mask |= PT_CFG_COST;
317*10491SRishi.Srivatsavai@Sun.COM
318*10491SRishi.Srivatsavai@Sun.COM uid_cfg->admin_point2point = port->adminPointToPointMac;
319*10491SRishi.Srivatsavai@Sun.COM if (uid_cfg->admin_point2point != DEF_P2P)
320*10491SRishi.Srivatsavai@Sun.COM uid_cfg->field_mask |= PT_CFG_P2P;
321*10491SRishi.Srivatsavai@Sun.COM
322*10491SRishi.Srivatsavai@Sun.COM uid_cfg->admin_edge = port->adminEdge;
323*10491SRishi.Srivatsavai@Sun.COM if (uid_cfg->admin_edge != DEF_ADMIN_EDGE)
324*10491SRishi.Srivatsavai@Sun.COM uid_cfg->field_mask |= PT_CFG_EDGE;
325*10491SRishi.Srivatsavai@Sun.COM
326*10491SRishi.Srivatsavai@Sun.COM uid_cfg->admin_non_stp = port->admin_non_stp;
327*10491SRishi.Srivatsavai@Sun.COM if (uid_cfg->admin_non_stp != DEF_ADMIN_NON_STP)
328*10491SRishi.Srivatsavai@Sun.COM uid_cfg->field_mask |= PT_CFG_NON_STP;
329*10491SRishi.Srivatsavai@Sun.COM
330*10491SRishi.Srivatsavai@Sun.COM if (port->mcheck)
331*10491SRishi.Srivatsavai@Sun.COM uid_cfg->field_mask |= PT_CFG_MCHECK;
332*10491SRishi.Srivatsavai@Sun.COM
333*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
334*10491SRishi.Srivatsavai@Sun.COM return 0;
335*10491SRishi.Srivatsavai@Sun.COM }
336*10491SRishi.Srivatsavai@Sun.COM
337*10491SRishi.Srivatsavai@Sun.COM int
STP_IN_port_get_state(IN int vlan_id,INOUT UID_STP_PORT_STATE_T * entry)338*10491SRishi.Srivatsavai@Sun.COM STP_IN_port_get_state (IN int vlan_id, INOUT UID_STP_PORT_STATE_T* entry)
339*10491SRishi.Srivatsavai@Sun.COM {
340*10491SRishi.Srivatsavai@Sun.COM register STPM_T* this;
341*10491SRishi.Srivatsavai@Sun.COM register PORT_T* port;
342*10491SRishi.Srivatsavai@Sun.COM
343*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_START;
344*10491SRishi.Srivatsavai@Sun.COM this = stpapi_stpm_find (vlan_id);
345*10491SRishi.Srivatsavai@Sun.COM
346*10491SRishi.Srivatsavai@Sun.COM if (!this) { /* it had not yet been created :( */
347*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
348*10491SRishi.Srivatsavai@Sun.COM return STP_Vlan_Had_Not_Yet_Been_Created;
349*10491SRishi.Srivatsavai@Sun.COM }
350*10491SRishi.Srivatsavai@Sun.COM
351*10491SRishi.Srivatsavai@Sun.COM port = _stpapi_port_find (this, entry->port_no);
352*10491SRishi.Srivatsavai@Sun.COM if (! port) {/* port is absent in the stpm :( */
353*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
354*10491SRishi.Srivatsavai@Sun.COM return STP_Port_Is_Absent_In_The_Vlan;
355*10491SRishi.Srivatsavai@Sun.COM }
356*10491SRishi.Srivatsavai@Sun.COM
357*10491SRishi.Srivatsavai@Sun.COM entry->port_id = port->port_id;
358*10491SRishi.Srivatsavai@Sun.COM if (DisabledPort == port->role) {
359*10491SRishi.Srivatsavai@Sun.COM entry->state = UID_PORT_DISABLED;
360*10491SRishi.Srivatsavai@Sun.COM } else if (! port->forward && ! port->learn) {
361*10491SRishi.Srivatsavai@Sun.COM entry->state = UID_PORT_DISCARDING;
362*10491SRishi.Srivatsavai@Sun.COM } else if (! port->forward && port->learn) {
363*10491SRishi.Srivatsavai@Sun.COM entry->state = UID_PORT_LEARNING;
364*10491SRishi.Srivatsavai@Sun.COM } else {
365*10491SRishi.Srivatsavai@Sun.COM entry->state = UID_PORT_FORWARDING;
366*10491SRishi.Srivatsavai@Sun.COM }
367*10491SRishi.Srivatsavai@Sun.COM
368*10491SRishi.Srivatsavai@Sun.COM entry->uptime = port->uptime;
369*10491SRishi.Srivatsavai@Sun.COM entry->path_cost = port->operPCost;
370*10491SRishi.Srivatsavai@Sun.COM _conv_br_id_2_uid (&port->portPrio.root_bridge, &entry->designated_root);
371*10491SRishi.Srivatsavai@Sun.COM entry->designated_cost = port->portPrio.root_path_cost;
372*10491SRishi.Srivatsavai@Sun.COM _conv_br_id_2_uid (&port->portPrio.design_bridge, &entry->designated_bridge);
373*10491SRishi.Srivatsavai@Sun.COM entry->designated_port = port->portPrio.design_port;
374*10491SRishi.Srivatsavai@Sun.COM
375*10491SRishi.Srivatsavai@Sun.COM switch (port->role) {
376*10491SRishi.Srivatsavai@Sun.COM case DisabledPort: entry->role = ' '; break;
377*10491SRishi.Srivatsavai@Sun.COM case AlternatePort: entry->role = 'A'; break;
378*10491SRishi.Srivatsavai@Sun.COM case BackupPort: entry->role = 'B'; break;
379*10491SRishi.Srivatsavai@Sun.COM case RootPort: entry->role = 'R'; break;
380*10491SRishi.Srivatsavai@Sun.COM case DesignatedPort: entry->role = 'D'; break;
381*10491SRishi.Srivatsavai@Sun.COM case NonStpPort: entry->role = '-'; break;
382*10491SRishi.Srivatsavai@Sun.COM default: entry->role = '?'; break;
383*10491SRishi.Srivatsavai@Sun.COM }
384*10491SRishi.Srivatsavai@Sun.COM
385*10491SRishi.Srivatsavai@Sun.COM if (DisabledPort == port->role || NonStpPort == port->role) {
386*10491SRishi.Srivatsavai@Sun.COM (void) memset (&entry->designated_root, 0, sizeof (UID_BRIDGE_ID_T));
387*10491SRishi.Srivatsavai@Sun.COM (void) memset (&entry->designated_bridge, 0, sizeof (UID_BRIDGE_ID_T));
388*10491SRishi.Srivatsavai@Sun.COM entry->designated_cost = 0;
389*10491SRishi.Srivatsavai@Sun.COM entry->designated_port = port->port_id;
390*10491SRishi.Srivatsavai@Sun.COM }
391*10491SRishi.Srivatsavai@Sun.COM
392*10491SRishi.Srivatsavai@Sun.COM if (DisabledPort == port->role) {
393*10491SRishi.Srivatsavai@Sun.COM entry->oper_point2point = (P2P_FORCE_FALSE == port->adminPointToPointMac) ? 0 : 1;
394*10491SRishi.Srivatsavai@Sun.COM entry->oper_edge = port->adminEdge;
395*10491SRishi.Srivatsavai@Sun.COM entry->oper_stp_neigb = 0;
396*10491SRishi.Srivatsavai@Sun.COM } else {
397*10491SRishi.Srivatsavai@Sun.COM entry->oper_point2point = port->operPointToPointMac ? 1 : 0;
398*10491SRishi.Srivatsavai@Sun.COM entry->oper_edge = port->operEdge ? 1 : 0;
399*10491SRishi.Srivatsavai@Sun.COM entry->oper_stp_neigb = port->sendRSTP ? 0 : 1;
400*10491SRishi.Srivatsavai@Sun.COM }
401*10491SRishi.Srivatsavai@Sun.COM entry->oper_port_path_cost = port->operPCost;
402*10491SRishi.Srivatsavai@Sun.COM
403*10491SRishi.Srivatsavai@Sun.COM entry->rx_cfg_bpdu_cnt = port->rx_cfg_bpdu_cnt;
404*10491SRishi.Srivatsavai@Sun.COM entry->rx_rstp_bpdu_cnt = port->rx_rstp_bpdu_cnt;
405*10491SRishi.Srivatsavai@Sun.COM entry->rx_tcn_bpdu_cnt = port->rx_tcn_bpdu_cnt;
406*10491SRishi.Srivatsavai@Sun.COM
407*10491SRishi.Srivatsavai@Sun.COM entry->fdWhile = port->fdWhile; /* 17.15.1 */
408*10491SRishi.Srivatsavai@Sun.COM entry->helloWhen = port->helloWhen; /* 17.15.2 */
409*10491SRishi.Srivatsavai@Sun.COM entry->mdelayWhile = port->mdelayWhile; /* 17.15.3 */
410*10491SRishi.Srivatsavai@Sun.COM entry->rbWhile = port->rbWhile; /* 17.15.4 */
411*10491SRishi.Srivatsavai@Sun.COM entry->rcvdInfoWhile = port->rcvdInfoWhile;/* 17.15.5 */
412*10491SRishi.Srivatsavai@Sun.COM entry->rrWhile = port->rrWhile; /* 17.15.6 */
413*10491SRishi.Srivatsavai@Sun.COM entry->tcWhile = port->tcWhile; /* 17.15.7 */
414*10491SRishi.Srivatsavai@Sun.COM entry->txCount = port->txCount; /* 17.18.40 */
415*10491SRishi.Srivatsavai@Sun.COM entry->lnkWhile = port->lnkWhile;
416*10491SRishi.Srivatsavai@Sun.COM
417*10491SRishi.Srivatsavai@Sun.COM entry->rcvdInfoWhile = port->rcvdInfoWhile;
418*10491SRishi.Srivatsavai@Sun.COM entry->top_change_ack = port->tcAck;
419*10491SRishi.Srivatsavai@Sun.COM entry->tc = port->tc;
420*10491SRishi.Srivatsavai@Sun.COM
421*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
422*10491SRishi.Srivatsavai@Sun.COM return 0;
423*10491SRishi.Srivatsavai@Sun.COM }
424*10491SRishi.Srivatsavai@Sun.COM
425*10491SRishi.Srivatsavai@Sun.COM int
STP_IN_stpm_get_state(IN int vlan_id,OUT UID_STP_STATE_T * entry)426*10491SRishi.Srivatsavai@Sun.COM STP_IN_stpm_get_state (IN int vlan_id, OUT UID_STP_STATE_T* entry)
427*10491SRishi.Srivatsavai@Sun.COM {
428*10491SRishi.Srivatsavai@Sun.COM register STPM_T* this;
429*10491SRishi.Srivatsavai@Sun.COM
430*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_START;
431*10491SRishi.Srivatsavai@Sun.COM this = stpapi_stpm_find (vlan_id);
432*10491SRishi.Srivatsavai@Sun.COM
433*10491SRishi.Srivatsavai@Sun.COM if (!this) { /* it had not yet been created :( */
434*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
435*10491SRishi.Srivatsavai@Sun.COM return STP_Vlan_Had_Not_Yet_Been_Created;
436*10491SRishi.Srivatsavai@Sun.COM }
437*10491SRishi.Srivatsavai@Sun.COM
438*10491SRishi.Srivatsavai@Sun.COM (void) strncpy (entry->vlan_name, this->name, NAME_LEN);
439*10491SRishi.Srivatsavai@Sun.COM entry->vlan_id = this->vlan_id;
440*10491SRishi.Srivatsavai@Sun.COM _conv_br_id_2_uid (&this->rootPrio.root_bridge, &entry->designated_root);
441*10491SRishi.Srivatsavai@Sun.COM entry->root_path_cost = this->rootPrio.root_path_cost;
442*10491SRishi.Srivatsavai@Sun.COM entry->root_port = this->rootPortId;
443*10491SRishi.Srivatsavai@Sun.COM entry->max_age = this->rootTimes.MaxAge;
444*10491SRishi.Srivatsavai@Sun.COM entry->forward_delay = this->rootTimes.ForwardDelay;
445*10491SRishi.Srivatsavai@Sun.COM entry->hello_time = this->rootTimes.HelloTime;
446*10491SRishi.Srivatsavai@Sun.COM
447*10491SRishi.Srivatsavai@Sun.COM _conv_br_id_2_uid (&this->BrId, &entry->bridge_id);
448*10491SRishi.Srivatsavai@Sun.COM
449*10491SRishi.Srivatsavai@Sun.COM entry->stp_enabled = this->admin_state;
450*10491SRishi.Srivatsavai@Sun.COM
451*10491SRishi.Srivatsavai@Sun.COM entry->timeSince_Topo_Change = this->timeSince_Topo_Change;
452*10491SRishi.Srivatsavai@Sun.COM entry->Topo_Change_Count = this->Topo_Change_Count;
453*10491SRishi.Srivatsavai@Sun.COM entry->Topo_Change = this->Topo_Change;
454*10491SRishi.Srivatsavai@Sun.COM
455*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
456*10491SRishi.Srivatsavai@Sun.COM return 0;
457*10491SRishi.Srivatsavai@Sun.COM }
458*10491SRishi.Srivatsavai@Sun.COM
459*10491SRishi.Srivatsavai@Sun.COM int
STP_IN_stpm_get_name_by_vlan_id(int vlan_id,char * name,size_t buffsize)460*10491SRishi.Srivatsavai@Sun.COM STP_IN_stpm_get_name_by_vlan_id (int vlan_id, char* name, size_t buffsize)
461*10491SRishi.Srivatsavai@Sun.COM {
462*10491SRishi.Srivatsavai@Sun.COM register STPM_T* stpm;
463*10491SRishi.Srivatsavai@Sun.COM int iret = -1;
464*10491SRishi.Srivatsavai@Sun.COM
465*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_START;
466*10491SRishi.Srivatsavai@Sun.COM for (stpm = STP_stpm_get_the_list (); stpm; stpm = stpm->next) {
467*10491SRishi.Srivatsavai@Sun.COM if (vlan_id == stpm->vlan_id) {
468*10491SRishi.Srivatsavai@Sun.COM if (stpm->name)
469*10491SRishi.Srivatsavai@Sun.COM (void) strncpy (name, stpm->name, buffsize);
470*10491SRishi.Srivatsavai@Sun.COM else
471*10491SRishi.Srivatsavai@Sun.COM (void) memset (name, 0, buffsize);
472*10491SRishi.Srivatsavai@Sun.COM iret = 0;
473*10491SRishi.Srivatsavai@Sun.COM break;
474*10491SRishi.Srivatsavai@Sun.COM }
475*10491SRishi.Srivatsavai@Sun.COM }
476*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
477*10491SRishi.Srivatsavai@Sun.COM return iret;
478*10491SRishi.Srivatsavai@Sun.COM }
479*10491SRishi.Srivatsavai@Sun.COM
480*10491SRishi.Srivatsavai@Sun.COM int /* call it, when link Up/Down */
STP_IN_enable_port(int port_index,Bool enable)481*10491SRishi.Srivatsavai@Sun.COM STP_IN_enable_port (int port_index, Bool enable)
482*10491SRishi.Srivatsavai@Sun.COM {
483*10491SRishi.Srivatsavai@Sun.COM register STPM_T* stpm;
484*10491SRishi.Srivatsavai@Sun.COM
485*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_START;
486*10491SRishi.Srivatsavai@Sun.COM if (! enable) {
487*10491SRishi.Srivatsavai@Sun.COM #ifdef STP_DBG
488*10491SRishi.Srivatsavai@Sun.COM stp_trace("%s (p%02d, all, %s, '%s')",
489*10491SRishi.Srivatsavai@Sun.COM "clearFDB", (int) port_index, "this port", "disable port");
490*10491SRishi.Srivatsavai@Sun.COM #endif
491*10491SRishi.Srivatsavai@Sun.COM STP_OUT_flush_lt (port_index, 0, LT_FLASH_ONLY_THE_PORT, "disable port");
492*10491SRishi.Srivatsavai@Sun.COM }
493*10491SRishi.Srivatsavai@Sun.COM
494*10491SRishi.Srivatsavai@Sun.COM for (stpm = STP_stpm_get_the_list (); stpm; stpm = stpm->next) {
495*10491SRishi.Srivatsavai@Sun.COM if (STP_ENABLED != stpm->admin_state) continue;
496*10491SRishi.Srivatsavai@Sun.COM
497*10491SRishi.Srivatsavai@Sun.COM _stp_in_enable_port_on_stpm (stpm, port_index, enable);
498*10491SRishi.Srivatsavai@Sun.COM /* STP_stpm_update (stpm);*/
499*10491SRishi.Srivatsavai@Sun.COM }
500*10491SRishi.Srivatsavai@Sun.COM
501*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
502*10491SRishi.Srivatsavai@Sun.COM return 0;
503*10491SRishi.Srivatsavai@Sun.COM }
504*10491SRishi.Srivatsavai@Sun.COM
505*10491SRishi.Srivatsavai@Sun.COM int /* call it, when port speed has been changed, speed in Kb/s */
STP_IN_changed_port_speed(int port_index,long speed)506*10491SRishi.Srivatsavai@Sun.COM STP_IN_changed_port_speed (int port_index, long speed)
507*10491SRishi.Srivatsavai@Sun.COM {
508*10491SRishi.Srivatsavai@Sun.COM register STPM_T* stpm;
509*10491SRishi.Srivatsavai@Sun.COM register PORT_T* port;
510*10491SRishi.Srivatsavai@Sun.COM
511*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_START;
512*10491SRishi.Srivatsavai@Sun.COM for (stpm = STP_stpm_get_the_list (); stpm; stpm = stpm->next) {
513*10491SRishi.Srivatsavai@Sun.COM if (STP_ENABLED != stpm->admin_state) continue;
514*10491SRishi.Srivatsavai@Sun.COM
515*10491SRishi.Srivatsavai@Sun.COM port = _stpapi_port_find (stpm, port_index);
516*10491SRishi.Srivatsavai@Sun.COM if (! port) continue;
517*10491SRishi.Srivatsavai@Sun.COM port->operSpeed = speed;
518*10491SRishi.Srivatsavai@Sun.COM #ifdef STP_DBG
519*10491SRishi.Srivatsavai@Sun.COM if (port->pcost->debug) {
520*10491SRishi.Srivatsavai@Sun.COM stp_trace ("changed operSpeed=%lu", port->operSpeed);
521*10491SRishi.Srivatsavai@Sun.COM }
522*10491SRishi.Srivatsavai@Sun.COM #endif
523*10491SRishi.Srivatsavai@Sun.COM
524*10491SRishi.Srivatsavai@Sun.COM port->reselect = True;
525*10491SRishi.Srivatsavai@Sun.COM port->selected = False;
526*10491SRishi.Srivatsavai@Sun.COM }
527*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
528*10491SRishi.Srivatsavai@Sun.COM return 0;
529*10491SRishi.Srivatsavai@Sun.COM }
530*10491SRishi.Srivatsavai@Sun.COM
531*10491SRishi.Srivatsavai@Sun.COM int /* call it, when port duplex mode has been changed */
STP_IN_changed_port_duplex(int port_index)532*10491SRishi.Srivatsavai@Sun.COM STP_IN_changed_port_duplex (int port_index)
533*10491SRishi.Srivatsavai@Sun.COM {
534*10491SRishi.Srivatsavai@Sun.COM register STPM_T* stpm;
535*10491SRishi.Srivatsavai@Sun.COM register PORT_T* port;
536*10491SRishi.Srivatsavai@Sun.COM
537*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_START;
538*10491SRishi.Srivatsavai@Sun.COM for (stpm = STP_stpm_get_the_list (); stpm; stpm = stpm->next) {
539*10491SRishi.Srivatsavai@Sun.COM if (STP_ENABLED != stpm->admin_state) continue;
540*10491SRishi.Srivatsavai@Sun.COM
541*10491SRishi.Srivatsavai@Sun.COM port = _stpapi_port_find (stpm, port_index);
542*10491SRishi.Srivatsavai@Sun.COM if (! port) continue;
543*10491SRishi.Srivatsavai@Sun.COM #ifdef STP_DBG
544*10491SRishi.Srivatsavai@Sun.COM if (port->p2p->debug) {
545*10491SRishi.Srivatsavai@Sun.COM stp_trace ("STP_IN_changed_port_duplex(%s)", port->port_name);
546*10491SRishi.Srivatsavai@Sun.COM }
547*10491SRishi.Srivatsavai@Sun.COM #endif
548*10491SRishi.Srivatsavai@Sun.COM port->p2p_recompute = True;
549*10491SRishi.Srivatsavai@Sun.COM port->reselect = True;
550*10491SRishi.Srivatsavai@Sun.COM port->selected = False;
551*10491SRishi.Srivatsavai@Sun.COM }
552*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
553*10491SRishi.Srivatsavai@Sun.COM return 0;
554*10491SRishi.Srivatsavai@Sun.COM }
555*10491SRishi.Srivatsavai@Sun.COM
556*10491SRishi.Srivatsavai@Sun.COM int
STP_IN_check_bpdu_header(BPDU_T * bpdu,size_t len)557*10491SRishi.Srivatsavai@Sun.COM STP_IN_check_bpdu_header (BPDU_T* bpdu, size_t len)
558*10491SRishi.Srivatsavai@Sun.COM {
559*10491SRishi.Srivatsavai@Sun.COM unsigned short len8023;
560*10491SRishi.Srivatsavai@Sun.COM
561*10491SRishi.Srivatsavai@Sun.COM /* LINTED: alignment */
562*10491SRishi.Srivatsavai@Sun.COM len8023 = ntohs (*(unsigned short*) bpdu->eth.len8023);
563*10491SRishi.Srivatsavai@Sun.COM if (len8023 > 1500) {/* big len8023 format :( */
564*10491SRishi.Srivatsavai@Sun.COM return STP_Big_len8023_Format;
565*10491SRishi.Srivatsavai@Sun.COM }
566*10491SRishi.Srivatsavai@Sun.COM
567*10491SRishi.Srivatsavai@Sun.COM if (len8023 < MIN_BPDU) { /* small len8023 format :( */
568*10491SRishi.Srivatsavai@Sun.COM return STP_Small_len8023_Format;
569*10491SRishi.Srivatsavai@Sun.COM }
570*10491SRishi.Srivatsavai@Sun.COM
571*10491SRishi.Srivatsavai@Sun.COM if (len8023 + 14 > len) { /* len8023 format gt len :( */
572*10491SRishi.Srivatsavai@Sun.COM return STP_len8023_Format_Gt_Len;
573*10491SRishi.Srivatsavai@Sun.COM }
574*10491SRishi.Srivatsavai@Sun.COM
575*10491SRishi.Srivatsavai@Sun.COM if (bpdu->eth.dsap != BPDU_L_SAP ||
576*10491SRishi.Srivatsavai@Sun.COM bpdu->eth.ssap != BPDU_L_SAP ||
577*10491SRishi.Srivatsavai@Sun.COM bpdu->eth.llc != LLC_UI) {
578*10491SRishi.Srivatsavai@Sun.COM /* this is not a proper 802.3 pkt! :( */
579*10491SRishi.Srivatsavai@Sun.COM return STP_Not_Proper_802_3_Packet;
580*10491SRishi.Srivatsavai@Sun.COM }
581*10491SRishi.Srivatsavai@Sun.COM
582*10491SRishi.Srivatsavai@Sun.COM if (bpdu->hdr.protocol[0] || bpdu->hdr.protocol[1]) {
583*10491SRishi.Srivatsavai@Sun.COM return STP_Invalid_Protocol;
584*10491SRishi.Srivatsavai@Sun.COM }
585*10491SRishi.Srivatsavai@Sun.COM
586*10491SRishi.Srivatsavai@Sun.COM #if 0
587*10491SRishi.Srivatsavai@Sun.COM if (bpdu->hdr.version != BPDU_VERSION_ID) {
588*10491SRishi.Srivatsavai@Sun.COM return STP_Invalid_Version;
589*10491SRishi.Srivatsavai@Sun.COM }
590*10491SRishi.Srivatsavai@Sun.COM #endif
591*10491SRishi.Srivatsavai@Sun.COM /* see also 9.3.4: think & TBD :( */
592*10491SRishi.Srivatsavai@Sun.COM return 0;
593*10491SRishi.Srivatsavai@Sun.COM }
594*10491SRishi.Srivatsavai@Sun.COM
595*10491SRishi.Srivatsavai@Sun.COM #ifdef STP_DBG
596*10491SRishi.Srivatsavai@Sun.COM int dbg_rstp_deny = 0;
597*10491SRishi.Srivatsavai@Sun.COM #endif
598*10491SRishi.Srivatsavai@Sun.COM
599*10491SRishi.Srivatsavai@Sun.COM
600*10491SRishi.Srivatsavai@Sun.COM int
STP_IN_rx_bpdu(int vlan_id,int port_index,BPDU_T * bpdu,size_t len)601*10491SRishi.Srivatsavai@Sun.COM STP_IN_rx_bpdu (int vlan_id, int port_index, BPDU_T* bpdu, size_t len)
602*10491SRishi.Srivatsavai@Sun.COM {
603*10491SRishi.Srivatsavai@Sun.COM register PORT_T* port;
604*10491SRishi.Srivatsavai@Sun.COM register STPM_T* this;
605*10491SRishi.Srivatsavai@Sun.COM int iret;
606*10491SRishi.Srivatsavai@Sun.COM
607*10491SRishi.Srivatsavai@Sun.COM #ifdef STP_DBG
608*10491SRishi.Srivatsavai@Sun.COM if (1 == dbg_rstp_deny) {
609*10491SRishi.Srivatsavai@Sun.COM return 0;
610*10491SRishi.Srivatsavai@Sun.COM }
611*10491SRishi.Srivatsavai@Sun.COM #endif
612*10491SRishi.Srivatsavai@Sun.COM
613*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_START;
614*10491SRishi.Srivatsavai@Sun.COM this = stpapi_stpm_find (vlan_id);
615*10491SRishi.Srivatsavai@Sun.COM if (! this) { /* the stpm had not yet been created :( */
616*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
617*10491SRishi.Srivatsavai@Sun.COM return STP_Vlan_Had_Not_Yet_Been_Created;
618*10491SRishi.Srivatsavai@Sun.COM }
619*10491SRishi.Srivatsavai@Sun.COM
620*10491SRishi.Srivatsavai@Sun.COM if (STP_DISABLED == this->admin_state) {/* the stpm had not yet been enabled :( */
621*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
622*10491SRishi.Srivatsavai@Sun.COM return STP_Had_Not_Yet_Been_Enabled_On_The_Vlan;
623*10491SRishi.Srivatsavai@Sun.COM }
624*10491SRishi.Srivatsavai@Sun.COM
625*10491SRishi.Srivatsavai@Sun.COM port = _stpapi_port_find (this, port_index);
626*10491SRishi.Srivatsavai@Sun.COM if (! port) {/* port is absent in the stpm :( */
627*10491SRishi.Srivatsavai@Sun.COM #ifdef STP_DBG
628*10491SRishi.Srivatsavai@Sun.COM stp_trace ("RX bpdu vlan_id=%d port=%d port is absent in the stpm :(", (int) vlan_id, (int) port_index);
629*10491SRishi.Srivatsavai@Sun.COM #endif
630*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
631*10491SRishi.Srivatsavai@Sun.COM return STP_Port_Is_Absent_In_The_Vlan;
632*10491SRishi.Srivatsavai@Sun.COM }
633*10491SRishi.Srivatsavai@Sun.COM
634*10491SRishi.Srivatsavai@Sun.COM #ifdef STP_DBG
635*10491SRishi.Srivatsavai@Sun.COM if (port->skip_rx > 0) {
636*10491SRishi.Srivatsavai@Sun.COM if (1 == port->skip_rx)
637*10491SRishi.Srivatsavai@Sun.COM stp_trace ("port %s stop rx skipping",
638*10491SRishi.Srivatsavai@Sun.COM port->port_name);
639*10491SRishi.Srivatsavai@Sun.COM else
640*10491SRishi.Srivatsavai@Sun.COM stp_trace ("port %s skip rx %d",
641*10491SRishi.Srivatsavai@Sun.COM port->port_name, port->skip_rx);
642*10491SRishi.Srivatsavai@Sun.COM port->skip_rx--;
643*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
644*10491SRishi.Srivatsavai@Sun.COM return STP_Nothing_To_Do;
645*10491SRishi.Srivatsavai@Sun.COM }
646*10491SRishi.Srivatsavai@Sun.COM #endif
647*10491SRishi.Srivatsavai@Sun.COM
648*10491SRishi.Srivatsavai@Sun.COM if (port->operEdge && ! port->lnkWhile && port->portEnabled) {
649*10491SRishi.Srivatsavai@Sun.COM #ifdef STP_DBG
650*10491SRishi.Srivatsavai@Sun.COM if (port->topoch->debug) {
651*10491SRishi.Srivatsavai@Sun.COM stp_trace ("port %s tc=TRUE by operEdge", port->port_name);
652*10491SRishi.Srivatsavai@Sun.COM }
653*10491SRishi.Srivatsavai@Sun.COM #endif
654*10491SRishi.Srivatsavai@Sun.COM port->tc = True; /* IEEE 802.1y, 17.30 */
655*10491SRishi.Srivatsavai@Sun.COM }
656*10491SRishi.Srivatsavai@Sun.COM
657*10491SRishi.Srivatsavai@Sun.COM /* port link change indication will come later :( */
658*10491SRishi.Srivatsavai@Sun.COM if (! port->portEnabled &&
659*10491SRishi.Srivatsavai@Sun.COM STP_OUT_get_port_link_status (port->port_index)) {
660*10491SRishi.Srivatsavai@Sun.COM _stp_in_enable_port_on_stpm (this, port->port_index, True);
661*10491SRishi.Srivatsavai@Sun.COM }
662*10491SRishi.Srivatsavai@Sun.COM
663*10491SRishi.Srivatsavai@Sun.COM #ifdef STP_DBG
664*10491SRishi.Srivatsavai@Sun.COM if (port->edge->debug && port->operEdge) {
665*10491SRishi.Srivatsavai@Sun.COM stp_trace ("port %s not operEdge !", port->port_name);
666*10491SRishi.Srivatsavai@Sun.COM }
667*10491SRishi.Srivatsavai@Sun.COM #endif
668*10491SRishi.Srivatsavai@Sun.COM
669*10491SRishi.Srivatsavai@Sun.COM port->operEdge = False;
670*10491SRishi.Srivatsavai@Sun.COM port->wasInitBpdu = True;
671*10491SRishi.Srivatsavai@Sun.COM
672*10491SRishi.Srivatsavai@Sun.COM iret = STP_port_rx_bpdu (port, bpdu, len);
673*10491SRishi.Srivatsavai@Sun.COM (void) STP_stpm_update (this);
674*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
675*10491SRishi.Srivatsavai@Sun.COM
676*10491SRishi.Srivatsavai@Sun.COM return iret;
677*10491SRishi.Srivatsavai@Sun.COM }
678*10491SRishi.Srivatsavai@Sun.COM
679*10491SRishi.Srivatsavai@Sun.COM int
STP_IN_one_second(void)680*10491SRishi.Srivatsavai@Sun.COM STP_IN_one_second (void)
681*10491SRishi.Srivatsavai@Sun.COM {
682*10491SRishi.Srivatsavai@Sun.COM register STPM_T* stpm;
683*10491SRishi.Srivatsavai@Sun.COM register int dbg_cnt = 0;
684*10491SRishi.Srivatsavai@Sun.COM
685*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_START;
686*10491SRishi.Srivatsavai@Sun.COM for (stpm = STP_stpm_get_the_list (); stpm; stpm = stpm->next) {
687*10491SRishi.Srivatsavai@Sun.COM if (STP_ENABLED == stpm->admin_state) {
688*10491SRishi.Srivatsavai@Sun.COM /* stp_trace ("STP_IN_one_second vlan_id=%d", (int) stpm->vlan_id); */
689*10491SRishi.Srivatsavai@Sun.COM STP_stpm_one_second (stpm);
690*10491SRishi.Srivatsavai@Sun.COM dbg_cnt++;
691*10491SRishi.Srivatsavai@Sun.COM }
692*10491SRishi.Srivatsavai@Sun.COM }
693*10491SRishi.Srivatsavai@Sun.COM
694*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
695*10491SRishi.Srivatsavai@Sun.COM
696*10491SRishi.Srivatsavai@Sun.COM return dbg_cnt;
697*10491SRishi.Srivatsavai@Sun.COM }
698*10491SRishi.Srivatsavai@Sun.COM
699*10491SRishi.Srivatsavai@Sun.COM int
STP_IN_stpm_set_cfg(IN int vlan_id,IN UID_STP_CFG_T * uid_cfg)700*10491SRishi.Srivatsavai@Sun.COM STP_IN_stpm_set_cfg (IN int vlan_id,
701*10491SRishi.Srivatsavai@Sun.COM IN UID_STP_CFG_T* uid_cfg)
702*10491SRishi.Srivatsavai@Sun.COM {
703*10491SRishi.Srivatsavai@Sun.COM int rc = 0, prev_prio, err_code;
704*10491SRishi.Srivatsavai@Sun.COM Bool created_here, enabled_here;
705*10491SRishi.Srivatsavai@Sun.COM register STPM_T* this;
706*10491SRishi.Srivatsavai@Sun.COM UID_STP_CFG_T old;
707*10491SRishi.Srivatsavai@Sun.COM
708*10491SRishi.Srivatsavai@Sun.COM /* stp_trace ("STP_IN_stpm_set_cfg"); */
709*10491SRishi.Srivatsavai@Sun.COM if (0 != STP_IN_stpm_get_cfg (vlan_id, &old)) {
710*10491SRishi.Srivatsavai@Sun.COM STP_OUT_get_init_stpm_cfg (vlan_id, &old);
711*10491SRishi.Srivatsavai@Sun.COM }
712*10491SRishi.Srivatsavai@Sun.COM
713*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_START;
714*10491SRishi.Srivatsavai@Sun.COM if (BR_CFG_PRIO & uid_cfg->field_mask) {
715*10491SRishi.Srivatsavai@Sun.COM old.bridge_priority = uid_cfg->bridge_priority;
716*10491SRishi.Srivatsavai@Sun.COM }
717*10491SRishi.Srivatsavai@Sun.COM
718*10491SRishi.Srivatsavai@Sun.COM if (BR_CFG_AGE & uid_cfg->field_mask) {
719*10491SRishi.Srivatsavai@Sun.COM old.max_age = uid_cfg->max_age;
720*10491SRishi.Srivatsavai@Sun.COM }
721*10491SRishi.Srivatsavai@Sun.COM
722*10491SRishi.Srivatsavai@Sun.COM if (BR_CFG_HELLO & uid_cfg->field_mask) {
723*10491SRishi.Srivatsavai@Sun.COM old.hello_time = uid_cfg->hello_time;
724*10491SRishi.Srivatsavai@Sun.COM }
725*10491SRishi.Srivatsavai@Sun.COM
726*10491SRishi.Srivatsavai@Sun.COM if (BR_CFG_DELAY & uid_cfg->field_mask) {
727*10491SRishi.Srivatsavai@Sun.COM old.forward_delay = uid_cfg->forward_delay;
728*10491SRishi.Srivatsavai@Sun.COM }
729*10491SRishi.Srivatsavai@Sun.COM
730*10491SRishi.Srivatsavai@Sun.COM if (BR_CFG_FORCE_VER & uid_cfg->field_mask) {
731*10491SRishi.Srivatsavai@Sun.COM old.force_version = uid_cfg->force_version;
732*10491SRishi.Srivatsavai@Sun.COM }
733*10491SRishi.Srivatsavai@Sun.COM
734*10491SRishi.Srivatsavai@Sun.COM rc = _check_stpm_config (&old);
735*10491SRishi.Srivatsavai@Sun.COM if (0 != rc) {
736*10491SRishi.Srivatsavai@Sun.COM stp_trace ("_check_stpm_config failed %d", (int) rc);
737*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
738*10491SRishi.Srivatsavai@Sun.COM return rc;
739*10491SRishi.Srivatsavai@Sun.COM }
740*10491SRishi.Srivatsavai@Sun.COM
741*10491SRishi.Srivatsavai@Sun.COM if ((BR_CFG_STATE & uid_cfg->field_mask) &&
742*10491SRishi.Srivatsavai@Sun.COM (STP_DISABLED == uid_cfg->stp_enabled)) {
743*10491SRishi.Srivatsavai@Sun.COM rc = _stp_in_stpm_enable (vlan_id, uid_cfg->vlan_name, STP_DISABLED);
744*10491SRishi.Srivatsavai@Sun.COM if (0 != rc) {
745*10491SRishi.Srivatsavai@Sun.COM stp_trace ("can't disable rc=%d", (int) rc);
746*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
747*10491SRishi.Srivatsavai@Sun.COM return rc;
748*10491SRishi.Srivatsavai@Sun.COM }
749*10491SRishi.Srivatsavai@Sun.COM uid_cfg->field_mask &= ~BR_CFG_STATE;
750*10491SRishi.Srivatsavai@Sun.COM if (! uid_cfg->field_mask) {
751*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
752*10491SRishi.Srivatsavai@Sun.COM return 0;
753*10491SRishi.Srivatsavai@Sun.COM }
754*10491SRishi.Srivatsavai@Sun.COM }
755*10491SRishi.Srivatsavai@Sun.COM
756*10491SRishi.Srivatsavai@Sun.COM /* get current state */
757*10491SRishi.Srivatsavai@Sun.COM this = stpapi_stpm_find (vlan_id);
758*10491SRishi.Srivatsavai@Sun.COM created_here = False;
759*10491SRishi.Srivatsavai@Sun.COM enabled_here = False;
760*10491SRishi.Srivatsavai@Sun.COM if (! this) { /* it had not yet been created */
761*10491SRishi.Srivatsavai@Sun.COM this = stp_in_stpm_create (vlan_id, uid_cfg->vlan_name, &err_code);
762*10491SRishi.Srivatsavai@Sun.COM if (! this) {
763*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
764*10491SRishi.Srivatsavai@Sun.COM return err_code;
765*10491SRishi.Srivatsavai@Sun.COM }
766*10491SRishi.Srivatsavai@Sun.COM }
767*10491SRishi.Srivatsavai@Sun.COM
768*10491SRishi.Srivatsavai@Sun.COM prev_prio = this->BrId.prio;
769*10491SRishi.Srivatsavai@Sun.COM this->BrId.prio = old.bridge_priority;
770*10491SRishi.Srivatsavai@Sun.COM if (STP_ENABLED == this->admin_state) {
771*10491SRishi.Srivatsavai@Sun.COM if (0 != STP_stpm_check_bridge_priority (this)) {
772*10491SRishi.Srivatsavai@Sun.COM this->BrId.prio = prev_prio;
773*10491SRishi.Srivatsavai@Sun.COM stp_trace ("%s", "STP_stpm_check_bridge_priority failed");
774*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
775*10491SRishi.Srivatsavai@Sun.COM return STP_Invalid_Bridge_Priority;
776*10491SRishi.Srivatsavai@Sun.COM }
777*10491SRishi.Srivatsavai@Sun.COM }
778*10491SRishi.Srivatsavai@Sun.COM
779*10491SRishi.Srivatsavai@Sun.COM this->BrTimes.MaxAge = old.max_age;
780*10491SRishi.Srivatsavai@Sun.COM this->BrTimes.HelloTime = old.hello_time;
781*10491SRishi.Srivatsavai@Sun.COM this->BrTimes.ForwardDelay = old.forward_delay;
782*10491SRishi.Srivatsavai@Sun.COM this->ForceVersion = (PROTOCOL_VERSION_T) old.force_version;
783*10491SRishi.Srivatsavai@Sun.COM
784*10491SRishi.Srivatsavai@Sun.COM if ((BR_CFG_STATE & uid_cfg->field_mask) &&
785*10491SRishi.Srivatsavai@Sun.COM STP_DISABLED != uid_cfg->stp_enabled &&
786*10491SRishi.Srivatsavai@Sun.COM STP_DISABLED == this->admin_state) {
787*10491SRishi.Srivatsavai@Sun.COM rc = _stp_in_stpm_enable (vlan_id, uid_cfg->vlan_name, uid_cfg->stp_enabled);
788*10491SRishi.Srivatsavai@Sun.COM if (0 != rc) {
789*10491SRishi.Srivatsavai@Sun.COM stp_trace ("%s", "cannot enable");
790*10491SRishi.Srivatsavai@Sun.COM if (created_here) {
791*10491SRishi.Srivatsavai@Sun.COM STP_stpm_delete (this);
792*10491SRishi.Srivatsavai@Sun.COM }
793*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
794*10491SRishi.Srivatsavai@Sun.COM return rc;
795*10491SRishi.Srivatsavai@Sun.COM }
796*10491SRishi.Srivatsavai@Sun.COM enabled_here = True;
797*10491SRishi.Srivatsavai@Sun.COM }
798*10491SRishi.Srivatsavai@Sun.COM
799*10491SRishi.Srivatsavai@Sun.COM if (! enabled_here && STP_DISABLED != this->admin_state) {
800*10491SRishi.Srivatsavai@Sun.COM STP_stpm_update_after_bridge_management (this);
801*10491SRishi.Srivatsavai@Sun.COM }
802*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
803*10491SRishi.Srivatsavai@Sun.COM return 0;
804*10491SRishi.Srivatsavai@Sun.COM }
805*10491SRishi.Srivatsavai@Sun.COM
806*10491SRishi.Srivatsavai@Sun.COM int
STP_IN_port_set_cfg(IN int vlan_id,IN int port_index,IN UID_STP_PORT_CFG_T * uid_cfg)807*10491SRishi.Srivatsavai@Sun.COM STP_IN_port_set_cfg (IN int vlan_id, IN int port_index,
808*10491SRishi.Srivatsavai@Sun.COM IN UID_STP_PORT_CFG_T* uid_cfg)
809*10491SRishi.Srivatsavai@Sun.COM {
810*10491SRishi.Srivatsavai@Sun.COM register STPM_T* this;
811*10491SRishi.Srivatsavai@Sun.COM register PORT_T* port;
812*10491SRishi.Srivatsavai@Sun.COM
813*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_START;
814*10491SRishi.Srivatsavai@Sun.COM this = stpapi_stpm_find (vlan_id);
815*10491SRishi.Srivatsavai@Sun.COM if (! this) { /* it had not yet been created :( */
816*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
817*10491SRishi.Srivatsavai@Sun.COM stp_trace ("RSTP instance with tag %d hasn't been created\n", vlan_id);
818*10491SRishi.Srivatsavai@Sun.COM return STP_Vlan_Had_Not_Yet_Been_Created;
819*10491SRishi.Srivatsavai@Sun.COM }
820*10491SRishi.Srivatsavai@Sun.COM
821*10491SRishi.Srivatsavai@Sun.COM port = _stpapi_port_find (this, port_index);
822*10491SRishi.Srivatsavai@Sun.COM if (! port) {/* port is absent in the stpm :( */
823*10491SRishi.Srivatsavai@Sun.COM return STP_Port_Is_Absent_In_The_Vlan;
824*10491SRishi.Srivatsavai@Sun.COM }
825*10491SRishi.Srivatsavai@Sun.COM
826*10491SRishi.Srivatsavai@Sun.COM if (PT_CFG_MCHECK & uid_cfg->field_mask) {
827*10491SRishi.Srivatsavai@Sun.COM if (this->ForceVersion >= NORMAL_RSTP)
828*10491SRishi.Srivatsavai@Sun.COM port->mcheck = True;
829*10491SRishi.Srivatsavai@Sun.COM }
830*10491SRishi.Srivatsavai@Sun.COM
831*10491SRishi.Srivatsavai@Sun.COM if (PT_CFG_COST & uid_cfg->field_mask) {
832*10491SRishi.Srivatsavai@Sun.COM port->adminPCost = uid_cfg->admin_port_path_cost;
833*10491SRishi.Srivatsavai@Sun.COM }
834*10491SRishi.Srivatsavai@Sun.COM
835*10491SRishi.Srivatsavai@Sun.COM if (PT_CFG_PRIO & uid_cfg->field_mask) {
836*10491SRishi.Srivatsavai@Sun.COM port->port_id = (uid_cfg->port_priority << 8) + port_index;
837*10491SRishi.Srivatsavai@Sun.COM }
838*10491SRishi.Srivatsavai@Sun.COM
839*10491SRishi.Srivatsavai@Sun.COM if (PT_CFG_P2P & uid_cfg->field_mask) {
840*10491SRishi.Srivatsavai@Sun.COM port->adminPointToPointMac = uid_cfg->admin_point2point;
841*10491SRishi.Srivatsavai@Sun.COM port->p2p_recompute = True;
842*10491SRishi.Srivatsavai@Sun.COM }
843*10491SRishi.Srivatsavai@Sun.COM
844*10491SRishi.Srivatsavai@Sun.COM if (PT_CFG_EDGE & uid_cfg->field_mask) {
845*10491SRishi.Srivatsavai@Sun.COM port->adminEdge = uid_cfg->admin_edge;
846*10491SRishi.Srivatsavai@Sun.COM port->operEdge = port->adminEdge;
847*10491SRishi.Srivatsavai@Sun.COM #ifdef STP_DBG
848*10491SRishi.Srivatsavai@Sun.COM if (port->edge->debug) {
849*10491SRishi.Srivatsavai@Sun.COM stp_trace ("port %s is operEdge=%c in STP_IN_port_set_cfg",
850*10491SRishi.Srivatsavai@Sun.COM port->port_name,
851*10491SRishi.Srivatsavai@Sun.COM port->operEdge ? 'Y' : 'n');
852*10491SRishi.Srivatsavai@Sun.COM }
853*10491SRishi.Srivatsavai@Sun.COM #endif
854*10491SRishi.Srivatsavai@Sun.COM }
855*10491SRishi.Srivatsavai@Sun.COM
856*10491SRishi.Srivatsavai@Sun.COM if (PT_CFG_NON_STP & uid_cfg->field_mask) {
857*10491SRishi.Srivatsavai@Sun.COM #ifdef STP_DBG
858*10491SRishi.Srivatsavai@Sun.COM if (port->roletrns->debug && port->admin_non_stp != uid_cfg->admin_non_stp) {
859*10491SRishi.Srivatsavai@Sun.COM stp_trace ("port %s is adminNonStp=%c in STP_IN_port_set_cfg",
860*10491SRishi.Srivatsavai@Sun.COM port->port_name,
861*10491SRishi.Srivatsavai@Sun.COM uid_cfg->admin_non_stp ? 'Y' : 'n');
862*10491SRishi.Srivatsavai@Sun.COM }
863*10491SRishi.Srivatsavai@Sun.COM #endif
864*10491SRishi.Srivatsavai@Sun.COM port->admin_non_stp = uid_cfg->admin_non_stp;
865*10491SRishi.Srivatsavai@Sun.COM }
866*10491SRishi.Srivatsavai@Sun.COM
867*10491SRishi.Srivatsavai@Sun.COM #ifdef STP_DBG
868*10491SRishi.Srivatsavai@Sun.COM if (PT_CFG_DBG_SKIP_RX & uid_cfg->field_mask) {
869*10491SRishi.Srivatsavai@Sun.COM port->skip_rx = uid_cfg->skip_rx;
870*10491SRishi.Srivatsavai@Sun.COM }
871*10491SRishi.Srivatsavai@Sun.COM
872*10491SRishi.Srivatsavai@Sun.COM if (PT_CFG_DBG_SKIP_TX & uid_cfg->field_mask) {
873*10491SRishi.Srivatsavai@Sun.COM port->skip_tx = uid_cfg->skip_tx;
874*10491SRishi.Srivatsavai@Sun.COM }
875*10491SRishi.Srivatsavai@Sun.COM
876*10491SRishi.Srivatsavai@Sun.COM #endif
877*10491SRishi.Srivatsavai@Sun.COM
878*10491SRishi.Srivatsavai@Sun.COM port->reselect = True;
879*10491SRishi.Srivatsavai@Sun.COM port->selected = False;
880*10491SRishi.Srivatsavai@Sun.COM
881*10491SRishi.Srivatsavai@Sun.COM (void) STP_stpm_update (this);
882*10491SRishi.Srivatsavai@Sun.COM
883*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
884*10491SRishi.Srivatsavai@Sun.COM
885*10491SRishi.Srivatsavai@Sun.COM return 0;
886*10491SRishi.Srivatsavai@Sun.COM }
887*10491SRishi.Srivatsavai@Sun.COM
888*10491SRishi.Srivatsavai@Sun.COM #ifdef STP_DBG
889*10491SRishi.Srivatsavai@Sun.COM int
890*10491SRishi.Srivatsavai@Sun.COM
STP_IN_dbg_set_port_trace(char * mach_name,int enadis,int vlan_id,int port_no)891*10491SRishi.Srivatsavai@Sun.COM STP_IN_dbg_set_port_trace (char* mach_name, int enadis,
892*10491SRishi.Srivatsavai@Sun.COM int vlan_id, int port_no)
893*10491SRishi.Srivatsavai@Sun.COM {
894*10491SRishi.Srivatsavai@Sun.COM register STPM_T* this;
895*10491SRishi.Srivatsavai@Sun.COM register PORT_T* port;
896*10491SRishi.Srivatsavai@Sun.COM int rc;
897*10491SRishi.Srivatsavai@Sun.COM
898*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_START;
899*10491SRishi.Srivatsavai@Sun.COM this = stpapi_stpm_find (vlan_id);
900*10491SRishi.Srivatsavai@Sun.COM if (! this) { /* it had not yet been created :( */
901*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
902*10491SRishi.Srivatsavai@Sun.COM stp_trace ("RSTP instance with tag %d hasn't been created\n", vlan_id);
903*10491SRishi.Srivatsavai@Sun.COM return STP_Vlan_Had_Not_Yet_Been_Created;
904*10491SRishi.Srivatsavai@Sun.COM }
905*10491SRishi.Srivatsavai@Sun.COM
906*10491SRishi.Srivatsavai@Sun.COM port = _stpapi_port_find (this, port_no);
907*10491SRishi.Srivatsavai@Sun.COM if (! port) {/* port is absent in the stpm :( */
908*10491SRishi.Srivatsavai@Sun.COM return STP_Port_Is_Absent_In_The_Vlan;
909*10491SRishi.Srivatsavai@Sun.COM }
910*10491SRishi.Srivatsavai@Sun.COM rc = STP_port_trace_state_machine (port, mach_name, enadis);
911*10491SRishi.Srivatsavai@Sun.COM
912*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
913*10491SRishi.Srivatsavai@Sun.COM
914*10491SRishi.Srivatsavai@Sun.COM return rc;
915*10491SRishi.Srivatsavai@Sun.COM }
916*10491SRishi.Srivatsavai@Sun.COM
917*10491SRishi.Srivatsavai@Sun.COM #endif
918*10491SRishi.Srivatsavai@Sun.COM
919*10491SRishi.Srivatsavai@Sun.COM const char*
STP_IN_get_error_explanation(int rstp_err_no)920*10491SRishi.Srivatsavai@Sun.COM STP_IN_get_error_explanation (int rstp_err_no)
921*10491SRishi.Srivatsavai@Sun.COM {
922*10491SRishi.Srivatsavai@Sun.COM #define CHOOSE(a) #a
923*10491SRishi.Srivatsavai@Sun.COM static char* rstp_error_names[] = RSTP_ERRORS;
924*10491SRishi.Srivatsavai@Sun.COM #undef CHOOSE
925*10491SRishi.Srivatsavai@Sun.COM if (rstp_err_no < STP_OK) {
926*10491SRishi.Srivatsavai@Sun.COM return "Too small error code :(";
927*10491SRishi.Srivatsavai@Sun.COM }
928*10491SRishi.Srivatsavai@Sun.COM if (rstp_err_no >= STP_LAST_DUMMY) {
929*10491SRishi.Srivatsavai@Sun.COM return "Too big error code :(";
930*10491SRishi.Srivatsavai@Sun.COM }
931*10491SRishi.Srivatsavai@Sun.COM
932*10491SRishi.Srivatsavai@Sun.COM return rstp_error_names[rstp_err_no];
933*10491SRishi.Srivatsavai@Sun.COM }
934*10491SRishi.Srivatsavai@Sun.COM
935*10491SRishi.Srivatsavai@Sun.COM int
STP_IN_port_add(int vlan_id,int port_index)936*10491SRishi.Srivatsavai@Sun.COM STP_IN_port_add(int vlan_id, int port_index)
937*10491SRishi.Srivatsavai@Sun.COM {
938*10491SRishi.Srivatsavai@Sun.COM STPM_T *this;
939*10491SRishi.Srivatsavai@Sun.COM PORT_T *port;
940*10491SRishi.Srivatsavai@Sun.COM int rc = STP_OK;
941*10491SRishi.Srivatsavai@Sun.COM
942*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_START;
943*10491SRishi.Srivatsavai@Sun.COM this = stpapi_stpm_find (vlan_id);
944*10491SRishi.Srivatsavai@Sun.COM
945*10491SRishi.Srivatsavai@Sun.COM if (!this) { /* it had not yet been created :( */
946*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
947*10491SRishi.Srivatsavai@Sun.COM return STP_Vlan_Had_Not_Yet_Been_Created;
948*10491SRishi.Srivatsavai@Sun.COM }
949*10491SRishi.Srivatsavai@Sun.COM
950*10491SRishi.Srivatsavai@Sun.COM port = this->ports;
951*10491SRishi.Srivatsavai@Sun.COM
952*10491SRishi.Srivatsavai@Sun.COM if (! STP_port_create (this, port_index)) {
953*10491SRishi.Srivatsavai@Sun.COM /* can't add port :( */
954*10491SRishi.Srivatsavai@Sun.COM stp_trace ("can't create port %d", port_index);
955*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
956*10491SRishi.Srivatsavai@Sun.COM return STP_Cannot_Create_Instance_For_Port;
957*10491SRishi.Srivatsavai@Sun.COM }
958*10491SRishi.Srivatsavai@Sun.COM
959*10491SRishi.Srivatsavai@Sun.COM if (!port)
960*10491SRishi.Srivatsavai@Sun.COM rc = STP_stpm_start (this);
961*10491SRishi.Srivatsavai@Sun.COM
962*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
963*10491SRishi.Srivatsavai@Sun.COM
964*10491SRishi.Srivatsavai@Sun.COM return rc;
965*10491SRishi.Srivatsavai@Sun.COM }
966*10491SRishi.Srivatsavai@Sun.COM
967*10491SRishi.Srivatsavai@Sun.COM int
STP_IN_port_remove(int vlan_id,int port_index)968*10491SRishi.Srivatsavai@Sun.COM STP_IN_port_remove(int vlan_id, int port_index)
969*10491SRishi.Srivatsavai@Sun.COM {
970*10491SRishi.Srivatsavai@Sun.COM STPM_T *this;
971*10491SRishi.Srivatsavai@Sun.COM PORT_T *port;
972*10491SRishi.Srivatsavai@Sun.COM
973*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_START;
974*10491SRishi.Srivatsavai@Sun.COM this = stpapi_stpm_find (vlan_id);
975*10491SRishi.Srivatsavai@Sun.COM
976*10491SRishi.Srivatsavai@Sun.COM if (!this) { /* it had not yet been created :( */
977*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
978*10491SRishi.Srivatsavai@Sun.COM return STP_Vlan_Had_Not_Yet_Been_Created;
979*10491SRishi.Srivatsavai@Sun.COM }
980*10491SRishi.Srivatsavai@Sun.COM
981*10491SRishi.Srivatsavai@Sun.COM port = _stpapi_port_find (this, port_index);
982*10491SRishi.Srivatsavai@Sun.COM if (! port) {/* port is absent in the stpm :( */
983*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
984*10491SRishi.Srivatsavai@Sun.COM return STP_Port_Is_Absent_In_The_Vlan;
985*10491SRishi.Srivatsavai@Sun.COM }
986*10491SRishi.Srivatsavai@Sun.COM
987*10491SRishi.Srivatsavai@Sun.COM STP_port_delete (port);
988*10491SRishi.Srivatsavai@Sun.COM
989*10491SRishi.Srivatsavai@Sun.COM if (!this->ports)
990*10491SRishi.Srivatsavai@Sun.COM STP_stpm_stop (this);
991*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
992*10491SRishi.Srivatsavai@Sun.COM
993*10491SRishi.Srivatsavai@Sun.COM return STP_OK;
994*10491SRishi.Srivatsavai@Sun.COM }
995*10491SRishi.Srivatsavai@Sun.COM
996*10491SRishi.Srivatsavai@Sun.COM void
STP_IN_get_bridge_id(int vlan_id,unsigned short * priority,unsigned char * mac)997*10491SRishi.Srivatsavai@Sun.COM STP_IN_get_bridge_id(int vlan_id, unsigned short *priority, unsigned char *mac)
998*10491SRishi.Srivatsavai@Sun.COM {
999*10491SRishi.Srivatsavai@Sun.COM STPM_T *this;
1000*10491SRishi.Srivatsavai@Sun.COM
1001*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_START;
1002*10491SRishi.Srivatsavai@Sun.COM this = stpapi_stpm_find (vlan_id);
1003*10491SRishi.Srivatsavai@Sun.COM *priority = this->BrId.prio;
1004*10491SRishi.Srivatsavai@Sun.COM (void) memcpy(mac, this->BrId.addr, 6);
1005*10491SRishi.Srivatsavai@Sun.COM RSTP_CRITICAL_PATH_END;
1006*10491SRishi.Srivatsavai@Sun.COM }
1007*10491SRishi.Srivatsavai@Sun.COM
1008*10491SRishi.Srivatsavai@Sun.COM const char *
STP_IN_state2str(RSTP_PORT_STATE state)1009*10491SRishi.Srivatsavai@Sun.COM STP_IN_state2str(RSTP_PORT_STATE state)
1010*10491SRishi.Srivatsavai@Sun.COM {
1011*10491SRishi.Srivatsavai@Sun.COM switch (state) {
1012*10491SRishi.Srivatsavai@Sun.COM case UID_PORT_DISABLED:
1013*10491SRishi.Srivatsavai@Sun.COM return ("disabled");
1014*10491SRishi.Srivatsavai@Sun.COM case UID_PORT_DISCARDING:
1015*10491SRishi.Srivatsavai@Sun.COM return ("discarding");
1016*10491SRishi.Srivatsavai@Sun.COM case UID_PORT_LEARNING:
1017*10491SRishi.Srivatsavai@Sun.COM return ("learning");
1018*10491SRishi.Srivatsavai@Sun.COM case UID_PORT_FORWARDING:
1019*10491SRishi.Srivatsavai@Sun.COM return ("forwarding");
1020*10491SRishi.Srivatsavai@Sun.COM case UID_PORT_NON_STP:
1021*10491SRishi.Srivatsavai@Sun.COM return ("non-stp");
1022*10491SRishi.Srivatsavai@Sun.COM case UID_PORT_BADSDU: /* synthetic state used by daemon */
1023*10491SRishi.Srivatsavai@Sun.COM return ("bad-mtu");
1024*10491SRishi.Srivatsavai@Sun.COM }
1025*10491SRishi.Srivatsavai@Sun.COM return ("unknown");
1026*10491SRishi.Srivatsavai@Sun.COM }
1027