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