xref: /onnv-gate/usr/src/lib/librstp/common/stpmgmt.c (revision 10491:8893b747ecdf)
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" /* for bridge defaults */
28*10491SRishi.Srivatsavai@Sun.COM #include "stp_to.h"
29*10491SRishi.Srivatsavai@Sun.COM 
30*10491SRishi.Srivatsavai@Sun.COM 
31*10491SRishi.Srivatsavai@Sun.COM int
STP_IN_stpm_create(int vlan_id,char * name)32*10491SRishi.Srivatsavai@Sun.COM STP_IN_stpm_create (int vlan_id, char* name)
33*10491SRishi.Srivatsavai@Sun.COM {
34*10491SRishi.Srivatsavai@Sun.COM   register STPM_T*  this;
35*10491SRishi.Srivatsavai@Sun.COM   int               err_code;
36*10491SRishi.Srivatsavai@Sun.COM   UID_STP_CFG_T		init_cfg;
37*10491SRishi.Srivatsavai@Sun.COM 
38*10491SRishi.Srivatsavai@Sun.COM   stp_trace ("STP_IN_stpm_create(%s)", name);
39*10491SRishi.Srivatsavai@Sun.COM 
40*10491SRishi.Srivatsavai@Sun.COM   init_cfg.field_mask = BR_CFG_ALL;
41*10491SRishi.Srivatsavai@Sun.COM   STP_OUT_get_init_stpm_cfg (vlan_id, &init_cfg);
42*10491SRishi.Srivatsavai@Sun.COM   init_cfg.field_mask = 0;
43*10491SRishi.Srivatsavai@Sun.COM 
44*10491SRishi.Srivatsavai@Sun.COM   RSTP_CRITICAL_PATH_START;
45*10491SRishi.Srivatsavai@Sun.COM   this = stp_in_stpm_create (vlan_id, name, &err_code);
46*10491SRishi.Srivatsavai@Sun.COM   if (this) {
47*10491SRishi.Srivatsavai@Sun.COM     this->BrId.prio = init_cfg.bridge_priority;
48*10491SRishi.Srivatsavai@Sun.COM     this->BrTimes.MaxAge = init_cfg.max_age;
49*10491SRishi.Srivatsavai@Sun.COM     this->BrTimes.HelloTime = init_cfg.hello_time;
50*10491SRishi.Srivatsavai@Sun.COM     this->BrTimes.ForwardDelay = init_cfg.forward_delay;
51*10491SRishi.Srivatsavai@Sun.COM     this->ForceVersion = (PROTOCOL_VERSION_T) init_cfg.force_version;
52*10491SRishi.Srivatsavai@Sun.COM   }
53*10491SRishi.Srivatsavai@Sun.COM 
54*10491SRishi.Srivatsavai@Sun.COM   RSTP_CRITICAL_PATH_END;
55*10491SRishi.Srivatsavai@Sun.COM   return err_code;
56*10491SRishi.Srivatsavai@Sun.COM }
57*10491SRishi.Srivatsavai@Sun.COM 
58*10491SRishi.Srivatsavai@Sun.COM int
STP_IN_stpm_delete(int vlan_id)59*10491SRishi.Srivatsavai@Sun.COM STP_IN_stpm_delete (int vlan_id)
60*10491SRishi.Srivatsavai@Sun.COM {
61*10491SRishi.Srivatsavai@Sun.COM   register STPM_T* this;
62*10491SRishi.Srivatsavai@Sun.COM   int iret = 0;
63*10491SRishi.Srivatsavai@Sun.COM 
64*10491SRishi.Srivatsavai@Sun.COM   RSTP_CRITICAL_PATH_START;
65*10491SRishi.Srivatsavai@Sun.COM   this = stpapi_stpm_find (vlan_id);
66*10491SRishi.Srivatsavai@Sun.COM 
67*10491SRishi.Srivatsavai@Sun.COM   if (! this) { /* it had not yet been created :( */
68*10491SRishi.Srivatsavai@Sun.COM     iret = STP_Vlan_Had_Not_Yet_Been_Created;
69*10491SRishi.Srivatsavai@Sun.COM   } else {
70*10491SRishi.Srivatsavai@Sun.COM 
71*10491SRishi.Srivatsavai@Sun.COM     if (STP_ENABLED == this->admin_state) {
72*10491SRishi.Srivatsavai@Sun.COM       if (0 != STP_stpm_enable (this, STP_DISABLED)) {/* can't disable :( */
73*10491SRishi.Srivatsavai@Sun.COM         iret = STP_Another_Error;
74*10491SRishi.Srivatsavai@Sun.COM       } else
75*10491SRishi.Srivatsavai@Sun.COM         STP_OUT_set_hardware_mode (vlan_id, STP_DISABLED);
76*10491SRishi.Srivatsavai@Sun.COM     }
77*10491SRishi.Srivatsavai@Sun.COM 
78*10491SRishi.Srivatsavai@Sun.COM     if (0 == iret) {
79*10491SRishi.Srivatsavai@Sun.COM       STP_stpm_delete (this);
80*10491SRishi.Srivatsavai@Sun.COM     }
81*10491SRishi.Srivatsavai@Sun.COM   }
82*10491SRishi.Srivatsavai@Sun.COM   RSTP_CRITICAL_PATH_END;
83*10491SRishi.Srivatsavai@Sun.COM   return iret;
84*10491SRishi.Srivatsavai@Sun.COM }
85*10491SRishi.Srivatsavai@Sun.COM 
86*10491SRishi.Srivatsavai@Sun.COM int
STP_IN_stpm_get_vlan_id_by_name(char * name,int * vlan_id)87*10491SRishi.Srivatsavai@Sun.COM STP_IN_stpm_get_vlan_id_by_name (char* name, int* vlan_id)
88*10491SRishi.Srivatsavai@Sun.COM {
89*10491SRishi.Srivatsavai@Sun.COM   register STPM_T* stpm;
90*10491SRishi.Srivatsavai@Sun.COM   int iret = STP_Cannot_Find_Vlan;
91*10491SRishi.Srivatsavai@Sun.COM 
92*10491SRishi.Srivatsavai@Sun.COM   RSTP_CRITICAL_PATH_START;
93*10491SRishi.Srivatsavai@Sun.COM   for (stpm = STP_stpm_get_the_list (); stpm; stpm = stpm->next) {
94*10491SRishi.Srivatsavai@Sun.COM     if (stpm->name && ! strcmp (stpm->name, name)) {
95*10491SRishi.Srivatsavai@Sun.COM       *vlan_id = stpm->vlan_id;
96*10491SRishi.Srivatsavai@Sun.COM       iret = 0;
97*10491SRishi.Srivatsavai@Sun.COM       break;
98*10491SRishi.Srivatsavai@Sun.COM     }
99*10491SRishi.Srivatsavai@Sun.COM   }
100*10491SRishi.Srivatsavai@Sun.COM   RSTP_CRITICAL_PATH_END;
101*10491SRishi.Srivatsavai@Sun.COM 
102*10491SRishi.Srivatsavai@Sun.COM   return iret;
103*10491SRishi.Srivatsavai@Sun.COM }
104*10491SRishi.Srivatsavai@Sun.COM 
105*10491SRishi.Srivatsavai@Sun.COM 
106*10491SRishi.Srivatsavai@Sun.COM Bool
STP_IN_get_is_stpm_enabled(int vlan_id)107*10491SRishi.Srivatsavai@Sun.COM STP_IN_get_is_stpm_enabled (int vlan_id)
108*10491SRishi.Srivatsavai@Sun.COM {
109*10491SRishi.Srivatsavai@Sun.COM   STPM_T* this;
110*10491SRishi.Srivatsavai@Sun.COM   Bool iret = False;
111*10491SRishi.Srivatsavai@Sun.COM 
112*10491SRishi.Srivatsavai@Sun.COM   RSTP_CRITICAL_PATH_START;
113*10491SRishi.Srivatsavai@Sun.COM   this = stpapi_stpm_find (vlan_id);
114*10491SRishi.Srivatsavai@Sun.COM 
115*10491SRishi.Srivatsavai@Sun.COM   if (this) {
116*10491SRishi.Srivatsavai@Sun.COM     if (this->admin_state == STP_ENABLED) {
117*10491SRishi.Srivatsavai@Sun.COM       iret = True;
118*10491SRishi.Srivatsavai@Sun.COM     }
119*10491SRishi.Srivatsavai@Sun.COM #ifdef notdef
120*10491SRishi.Srivatsavai@Sun.COM   } else {
121*10491SRishi.Srivatsavai@Sun.COM     ;   /* it had not yet been created :( */
122*10491SRishi.Srivatsavai@Sun.COM #endif
123*10491SRishi.Srivatsavai@Sun.COM   }
124*10491SRishi.Srivatsavai@Sun.COM 
125*10491SRishi.Srivatsavai@Sun.COM   RSTP_CRITICAL_PATH_END;
126*10491SRishi.Srivatsavai@Sun.COM   return iret;
127*10491SRishi.Srivatsavai@Sun.COM }
128*10491SRishi.Srivatsavai@Sun.COM 
129*10491SRishi.Srivatsavai@Sun.COM int
STP_IN_stop_all(void)130*10491SRishi.Srivatsavai@Sun.COM STP_IN_stop_all (void)
131*10491SRishi.Srivatsavai@Sun.COM {
132*10491SRishi.Srivatsavai@Sun.COM   register STPM_T* stpm;
133*10491SRishi.Srivatsavai@Sun.COM 
134*10491SRishi.Srivatsavai@Sun.COM   RSTP_CRITICAL_PATH_START;
135*10491SRishi.Srivatsavai@Sun.COM 
136*10491SRishi.Srivatsavai@Sun.COM   for (stpm = STP_stpm_get_the_list (); stpm; stpm = stpm->next) {
137*10491SRishi.Srivatsavai@Sun.COM     if (STP_DISABLED != stpm->admin_state) {
138*10491SRishi.Srivatsavai@Sun.COM       STP_OUT_set_hardware_mode (stpm->vlan_id, STP_DISABLED);
139*10491SRishi.Srivatsavai@Sun.COM       (void) STP_stpm_enable (stpm, STP_DISABLED);
140*10491SRishi.Srivatsavai@Sun.COM     }
141*10491SRishi.Srivatsavai@Sun.COM   }
142*10491SRishi.Srivatsavai@Sun.COM 
143*10491SRishi.Srivatsavai@Sun.COM   RSTP_CRITICAL_PATH_END;
144*10491SRishi.Srivatsavai@Sun.COM   return 0;
145*10491SRishi.Srivatsavai@Sun.COM }
146*10491SRishi.Srivatsavai@Sun.COM 
147*10491SRishi.Srivatsavai@Sun.COM int
STP_IN_delete_all(void)148*10491SRishi.Srivatsavai@Sun.COM STP_IN_delete_all (void)
149*10491SRishi.Srivatsavai@Sun.COM {
150*10491SRishi.Srivatsavai@Sun.COM   register STPM_T* stpm;
151*10491SRishi.Srivatsavai@Sun.COM 
152*10491SRishi.Srivatsavai@Sun.COM   RSTP_CRITICAL_PATH_START;
153*10491SRishi.Srivatsavai@Sun.COM   for (stpm = STP_stpm_get_the_list (); stpm; stpm = stpm->next) {
154*10491SRishi.Srivatsavai@Sun.COM     (void) STP_stpm_enable (stpm, STP_DISABLED);
155*10491SRishi.Srivatsavai@Sun.COM     STP_stpm_delete (stpm);
156*10491SRishi.Srivatsavai@Sun.COM   }
157*10491SRishi.Srivatsavai@Sun.COM 
158*10491SRishi.Srivatsavai@Sun.COM   RSTP_CRITICAL_PATH_END;
159*10491SRishi.Srivatsavai@Sun.COM   return 0;
160*10491SRishi.Srivatsavai@Sun.COM }
161*10491SRishi.Srivatsavai@Sun.COM 
162