xref: /titanic_44/usr/src/lib/librstp/common/stpmgmt.c (revision 4eaa471005973e11a6110b69fe990530b3b95a38)
1*4eaa4710SRishi Srivatsavai /************************************************************************
2*4eaa4710SRishi Srivatsavai  * RSTP library - Rapid Spanning Tree (802.1t, 802.1w)
3*4eaa4710SRishi Srivatsavai  * Copyright (C) 2001-2003 Optical Access
4*4eaa4710SRishi Srivatsavai  * Author: Alex Rozin
5*4eaa4710SRishi Srivatsavai  *
6*4eaa4710SRishi Srivatsavai  * This file is part of RSTP library.
7*4eaa4710SRishi Srivatsavai  *
8*4eaa4710SRishi Srivatsavai  * RSTP library is free software; you can redistribute it and/or modify it
9*4eaa4710SRishi Srivatsavai  * under the terms of the GNU Lesser General Public License as published by the
10*4eaa4710SRishi Srivatsavai  * Free Software Foundation; version 2.1
11*4eaa4710SRishi Srivatsavai  *
12*4eaa4710SRishi Srivatsavai  * RSTP library is distributed in the hope that it will be useful, but
13*4eaa4710SRishi Srivatsavai  * WITHOUT ANY WARRANTY; without even the implied warranty of
14*4eaa4710SRishi Srivatsavai  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
15*4eaa4710SRishi Srivatsavai  * General Public License for more details.
16*4eaa4710SRishi Srivatsavai  *
17*4eaa4710SRishi Srivatsavai  * You should have received a copy of the GNU Lesser General Public License
18*4eaa4710SRishi Srivatsavai  * along with RSTP library; see the file COPYING.  If not, write to the Free
19*4eaa4710SRishi Srivatsavai  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20*4eaa4710SRishi Srivatsavai  * 02111-1307, USA.
21*4eaa4710SRishi Srivatsavai  **********************************************************************/
22*4eaa4710SRishi Srivatsavai 
23*4eaa4710SRishi Srivatsavai /* This file contains API from an operation system to the RSTP library */
24*4eaa4710SRishi Srivatsavai 
25*4eaa4710SRishi Srivatsavai #include "base.h"
26*4eaa4710SRishi Srivatsavai #include "stpm.h"
27*4eaa4710SRishi Srivatsavai #include "stp_in.h" /* for bridge defaults */
28*4eaa4710SRishi Srivatsavai #include "stp_to.h"
29*4eaa4710SRishi Srivatsavai 
30*4eaa4710SRishi Srivatsavai 
31*4eaa4710SRishi Srivatsavai int
STP_IN_stpm_create(int vlan_id,char * name)32*4eaa4710SRishi Srivatsavai STP_IN_stpm_create (int vlan_id, char* name)
33*4eaa4710SRishi Srivatsavai {
34*4eaa4710SRishi Srivatsavai   register STPM_T*  this;
35*4eaa4710SRishi Srivatsavai   int               err_code;
36*4eaa4710SRishi Srivatsavai   UID_STP_CFG_T		init_cfg;
37*4eaa4710SRishi Srivatsavai 
38*4eaa4710SRishi Srivatsavai   stp_trace ("STP_IN_stpm_create(%s)", name);
39*4eaa4710SRishi Srivatsavai 
40*4eaa4710SRishi Srivatsavai   init_cfg.field_mask = BR_CFG_ALL;
41*4eaa4710SRishi Srivatsavai   STP_OUT_get_init_stpm_cfg (vlan_id, &init_cfg);
42*4eaa4710SRishi Srivatsavai   init_cfg.field_mask = 0;
43*4eaa4710SRishi Srivatsavai 
44*4eaa4710SRishi Srivatsavai   RSTP_CRITICAL_PATH_START;
45*4eaa4710SRishi Srivatsavai   this = stp_in_stpm_create (vlan_id, name, &err_code);
46*4eaa4710SRishi Srivatsavai   if (this) {
47*4eaa4710SRishi Srivatsavai     this->BrId.prio = init_cfg.bridge_priority;
48*4eaa4710SRishi Srivatsavai     this->BrTimes.MaxAge = init_cfg.max_age;
49*4eaa4710SRishi Srivatsavai     this->BrTimes.HelloTime = init_cfg.hello_time;
50*4eaa4710SRishi Srivatsavai     this->BrTimes.ForwardDelay = init_cfg.forward_delay;
51*4eaa4710SRishi Srivatsavai     this->ForceVersion = (PROTOCOL_VERSION_T) init_cfg.force_version;
52*4eaa4710SRishi Srivatsavai   }
53*4eaa4710SRishi Srivatsavai 
54*4eaa4710SRishi Srivatsavai   RSTP_CRITICAL_PATH_END;
55*4eaa4710SRishi Srivatsavai   return err_code;
56*4eaa4710SRishi Srivatsavai }
57*4eaa4710SRishi Srivatsavai 
58*4eaa4710SRishi Srivatsavai int
STP_IN_stpm_delete(int vlan_id)59*4eaa4710SRishi Srivatsavai STP_IN_stpm_delete (int vlan_id)
60*4eaa4710SRishi Srivatsavai {
61*4eaa4710SRishi Srivatsavai   register STPM_T* this;
62*4eaa4710SRishi Srivatsavai   int iret = 0;
63*4eaa4710SRishi Srivatsavai 
64*4eaa4710SRishi Srivatsavai   RSTP_CRITICAL_PATH_START;
65*4eaa4710SRishi Srivatsavai   this = stpapi_stpm_find (vlan_id);
66*4eaa4710SRishi Srivatsavai 
67*4eaa4710SRishi Srivatsavai   if (! this) { /* it had not yet been created :( */
68*4eaa4710SRishi Srivatsavai     iret = STP_Vlan_Had_Not_Yet_Been_Created;
69*4eaa4710SRishi Srivatsavai   } else {
70*4eaa4710SRishi Srivatsavai 
71*4eaa4710SRishi Srivatsavai     if (STP_ENABLED == this->admin_state) {
72*4eaa4710SRishi Srivatsavai       if (0 != STP_stpm_enable (this, STP_DISABLED)) {/* can't disable :( */
73*4eaa4710SRishi Srivatsavai         iret = STP_Another_Error;
74*4eaa4710SRishi Srivatsavai       } else
75*4eaa4710SRishi Srivatsavai         STP_OUT_set_hardware_mode (vlan_id, STP_DISABLED);
76*4eaa4710SRishi Srivatsavai     }
77*4eaa4710SRishi Srivatsavai 
78*4eaa4710SRishi Srivatsavai     if (0 == iret) {
79*4eaa4710SRishi Srivatsavai       STP_stpm_delete (this);
80*4eaa4710SRishi Srivatsavai     }
81*4eaa4710SRishi Srivatsavai   }
82*4eaa4710SRishi Srivatsavai   RSTP_CRITICAL_PATH_END;
83*4eaa4710SRishi Srivatsavai   return iret;
84*4eaa4710SRishi Srivatsavai }
85*4eaa4710SRishi Srivatsavai 
86*4eaa4710SRishi Srivatsavai int
STP_IN_stpm_get_vlan_id_by_name(char * name,int * vlan_id)87*4eaa4710SRishi Srivatsavai STP_IN_stpm_get_vlan_id_by_name (char* name, int* vlan_id)
88*4eaa4710SRishi Srivatsavai {
89*4eaa4710SRishi Srivatsavai   register STPM_T* stpm;
90*4eaa4710SRishi Srivatsavai   int iret = STP_Cannot_Find_Vlan;
91*4eaa4710SRishi Srivatsavai 
92*4eaa4710SRishi Srivatsavai   RSTP_CRITICAL_PATH_START;
93*4eaa4710SRishi Srivatsavai   for (stpm = STP_stpm_get_the_list (); stpm; stpm = stpm->next) {
94*4eaa4710SRishi Srivatsavai     if (stpm->name && ! strcmp (stpm->name, name)) {
95*4eaa4710SRishi Srivatsavai       *vlan_id = stpm->vlan_id;
96*4eaa4710SRishi Srivatsavai       iret = 0;
97*4eaa4710SRishi Srivatsavai       break;
98*4eaa4710SRishi Srivatsavai     }
99*4eaa4710SRishi Srivatsavai   }
100*4eaa4710SRishi Srivatsavai   RSTP_CRITICAL_PATH_END;
101*4eaa4710SRishi Srivatsavai 
102*4eaa4710SRishi Srivatsavai   return iret;
103*4eaa4710SRishi Srivatsavai }
104*4eaa4710SRishi Srivatsavai 
105*4eaa4710SRishi Srivatsavai 
106*4eaa4710SRishi Srivatsavai Bool
STP_IN_get_is_stpm_enabled(int vlan_id)107*4eaa4710SRishi Srivatsavai STP_IN_get_is_stpm_enabled (int vlan_id)
108*4eaa4710SRishi Srivatsavai {
109*4eaa4710SRishi Srivatsavai   STPM_T* this;
110*4eaa4710SRishi Srivatsavai   Bool iret = False;
111*4eaa4710SRishi Srivatsavai 
112*4eaa4710SRishi Srivatsavai   RSTP_CRITICAL_PATH_START;
113*4eaa4710SRishi Srivatsavai   this = stpapi_stpm_find (vlan_id);
114*4eaa4710SRishi Srivatsavai 
115*4eaa4710SRishi Srivatsavai   if (this) {
116*4eaa4710SRishi Srivatsavai     if (this->admin_state == STP_ENABLED) {
117*4eaa4710SRishi Srivatsavai       iret = True;
118*4eaa4710SRishi Srivatsavai     }
119*4eaa4710SRishi Srivatsavai #ifdef notdef
120*4eaa4710SRishi Srivatsavai   } else {
121*4eaa4710SRishi Srivatsavai     ;   /* it had not yet been created :( */
122*4eaa4710SRishi Srivatsavai #endif
123*4eaa4710SRishi Srivatsavai   }
124*4eaa4710SRishi Srivatsavai 
125*4eaa4710SRishi Srivatsavai   RSTP_CRITICAL_PATH_END;
126*4eaa4710SRishi Srivatsavai   return iret;
127*4eaa4710SRishi Srivatsavai }
128*4eaa4710SRishi Srivatsavai 
129*4eaa4710SRishi Srivatsavai int
STP_IN_stop_all(void)130*4eaa4710SRishi Srivatsavai STP_IN_stop_all (void)
131*4eaa4710SRishi Srivatsavai {
132*4eaa4710SRishi Srivatsavai   register STPM_T* stpm;
133*4eaa4710SRishi Srivatsavai 
134*4eaa4710SRishi Srivatsavai   RSTP_CRITICAL_PATH_START;
135*4eaa4710SRishi Srivatsavai 
136*4eaa4710SRishi Srivatsavai   for (stpm = STP_stpm_get_the_list (); stpm; stpm = stpm->next) {
137*4eaa4710SRishi Srivatsavai     if (STP_DISABLED != stpm->admin_state) {
138*4eaa4710SRishi Srivatsavai       STP_OUT_set_hardware_mode (stpm->vlan_id, STP_DISABLED);
139*4eaa4710SRishi Srivatsavai       (void) STP_stpm_enable (stpm, STP_DISABLED);
140*4eaa4710SRishi Srivatsavai     }
141*4eaa4710SRishi Srivatsavai   }
142*4eaa4710SRishi Srivatsavai 
143*4eaa4710SRishi Srivatsavai   RSTP_CRITICAL_PATH_END;
144*4eaa4710SRishi Srivatsavai   return 0;
145*4eaa4710SRishi Srivatsavai }
146*4eaa4710SRishi Srivatsavai 
147*4eaa4710SRishi Srivatsavai int
STP_IN_delete_all(void)148*4eaa4710SRishi Srivatsavai STP_IN_delete_all (void)
149*4eaa4710SRishi Srivatsavai {
150*4eaa4710SRishi Srivatsavai   register STPM_T* stpm;
151*4eaa4710SRishi Srivatsavai 
152*4eaa4710SRishi Srivatsavai   RSTP_CRITICAL_PATH_START;
153*4eaa4710SRishi Srivatsavai   for (stpm = STP_stpm_get_the_list (); stpm; stpm = stpm->next) {
154*4eaa4710SRishi Srivatsavai     (void) STP_stpm_enable (stpm, STP_DISABLED);
155*4eaa4710SRishi Srivatsavai     STP_stpm_delete (stpm);
156*4eaa4710SRishi Srivatsavai   }
157*4eaa4710SRishi Srivatsavai 
158*4eaa4710SRishi Srivatsavai   RSTP_CRITICAL_PATH_END;
159*4eaa4710SRishi Srivatsavai   return 0;
160*4eaa4710SRishi Srivatsavai }
161*4eaa4710SRishi Srivatsavai 
162