1 /************************************************************************
2 * RSTP library - Rapid Spanning Tree (802.1t, 802.1w)
3 * Copyright (C) 2001-2003 Optical Access
6 * This file is part of RSTP library.
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
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.
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
21 **********************************************************************/
23 /* Mutual RSTP definitions */
33 #if defined(__LINUX__) || defined(__SUN__)
36 # include <netinet/in.h>
42 # include "Bitmap/bitmap.h"
43 # include "Bitmap/bitmap.x"
44 # include "Ui/uid_stp.h"
48 # define IN /* consider as comments near 'input' parameters */
49 # define OUT /* consider as comments near 'output' parameters */
50 # define INOUT /* consider as comments near 'input/output' parameters */
68 #define RSTP_ERRORS { \
70 CHOOSE(STP_Cannot_Find_Vlan), \
71 CHOOSE(STP_Implicit_Instance_Create_Failed), \
72 CHOOSE(STP_Small_Bridge_Priority), \
73 CHOOSE(STP_Large_Bridge_Priority), \
74 CHOOSE(STP_Small_Hello_Time), \
75 CHOOSE(STP_Large_Hello_Time), \
76 CHOOSE(STP_Small_Max_Age), \
77 CHOOSE(STP_Large_Max_Age), \
78 CHOOSE(STP_Small_Forward_Delay), \
79 CHOOSE(STP_Large_Forward_Delay), \
80 CHOOSE(STP_Forward_Delay_And_Max_Age_Are_Inconsistent),\
81 CHOOSE(STP_Hello_Time_And_Max_Age_Are_Inconsistent), \
82 CHOOSE(STP_Vlan_Had_Not_Yet_Been_Created), \
83 CHOOSE(STP_Port_Is_Absent_In_The_Vlan), \
84 CHOOSE(STP_Big_len8023_Format), \
85 CHOOSE(STP_Small_len8023_Format), \
86 CHOOSE(STP_len8023_Format_Gt_Len), \
87 CHOOSE(STP_Not_Proper_802_3_Packet), \
88 CHOOSE(STP_Invalid_Protocol), \
89 CHOOSE(STP_Invalid_Version), \
90 CHOOSE(STP_Had_Not_Yet_Been_Enabled_On_The_Vlan), \
91 CHOOSE(STP_Cannot_Create_Instance_For_Vlan), \
92 CHOOSE(STP_Cannot_Create_Instance_For_Port), \
93 CHOOSE(STP_Invalid_Bridge_Priority), \
94 CHOOSE(STP_There_Are_No_Ports), \
95 CHOOSE(STP_Cannot_Compute_Bridge_Prio), \
96 CHOOSE(STP_Another_Error), \
97 CHOOSE(STP_Nothing_To_Do), \
98 CHOOSE(STP_No_Such_State_Machine), \
99 CHOOSE(STP_LAST_DUMMY) \
103 typedef enum RSTP_ERRORS RSTP_ERRORS_T
;
106 #if !defined(__LINUX__) && !defined(__SUN__)
107 extern char* strdup (const char *s
);
109 extern USHORT
Ntohs (USHORT n
);
110 extern ULONG
Htonl (ULONG h
);
111 extern USHORT
Htons (USHORT h
);
112 extern ULONG
Ntohl (ULONG n
);
121 #if defined(__LINUX__) || defined(__SUN__)
123 #define STP_FATAL(TXT, MSG, EXCOD) \
124 {stp_trace ("FATAL:%s failed: %s:%d", TXT, MSG, EXCOD); \
127 #define STP_FATAL(TXT, MSG, EXCOD) \
131 #define STP_FATAL(TXT, MSG, EXCOD) \
132 printf("FATAL: %s code %s:%d\n", TXT, MSG, EXCOD)
135 #define STP_MALLOC(PTR, TYPE, MSG) \
137 PTR = (TYPE*) calloc (1, sizeof (TYPE)); \
139 STP_FATAL("malloc", MSG, -6); \
143 #define STP_FREE(PTR, MSG) \
146 STP_FATAL("free", MSG, -66); \
152 #define STP_STRDUP(PTR, SRC, MSG) \
154 PTR = strdup (SRC); \
156 STP_FATAL("strdup", MSG, -7); \
160 #define STP_NEW_IN_LIST(WHAT, TYPE, LIST, MSG) \
162 STP_MALLOC(WHAT, TYPE, MSG); \
167 /* for debug trace messages */
170 #if defined(__LINUX__)
171 extern char* sprint_time_stump (void);
172 #define stp_trace(F, B...) printf("%s:" F "\n", sprint_time_stump(), ##B)
173 #elif defined(__SUN__)
174 #define stp_trace (*stp_vectors->trace)
176 extern ULONG
stp_trace (const char* fmt
, ...);
179 #define stp_trace(F, B...) ((void)0)
183 /* Inner usage definitions & functions */
185 #if defined(__LINUX__) || defined(__SUN__)
186 # define RSTP_INIT_CRITICAL_PATH_PROTECTIO
187 # define RSTP_CRITICAL_PATH_START
188 # define RSTP_CRITICAL_PATH_END
190 # define RSTP_INIT_CRITICAL_PATH_PROTECTIO STP_OUT_psos_init_semaphore ()
191 # define RSTP_CRITICAL_PATH_START STP_OUT_psos_close_semaphore ()
192 # define RSTP_CRITICAL_PATH_END STP_OUT_psos_open_semaphore ()
193 extern void STP_OUT_psos_init_semaphore (void);
194 extern void STP_OUT_psos_close_semaphore (void);
195 extern void STP_OUT_psos_open_semaphore (void);
198 #endif /* _STP_BASE_H__ */