]> git.ipfire.org Git - people/ms/rstp.git/blob - rstplib/base.h
d9637147549ca0d87e0ea0b9788b8f11a776f841
[people/ms/rstp.git] / rstplib / base.h
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 /* Mutual RSTP definitions */
24
25 #ifndef _STP_BASE_H__
26 #define _STP_BASE_H__
27
28 #include <stdlib.h>
29 #include <string.h>
30
31 #ifdef DEBUG
32 # define STP_DBG 1
33 #endif
34
35 #ifdef __LINUX__
36 # include <stddef.h>
37 # include <stdio.h>
38 # include <netinet/in.h>
39 # include "bitmap.h"
40 # include "uid_stp.h"
41 # define Print printf
42 #else
43 # include <psos.h>
44 # include "comdef.h"
45 # include "comdef.x"
46 # include "Bitmap/bitmap.h"
47 # include "Bitmap/bitmap.x"
48 # include "Ui/uid_stp.h"
49 #endif
50
51 #ifndef INOUT
52 # define IN /* consider as comments near 'input' parameters */
53 # define OUT /* consider as comments near 'output' parameters */
54 # define INOUT /* consider as comments near 'input/output' parameters */
55 #endif
56
57 #ifndef Zero
58 # define Zero 0
59 # define One 1
60 #endif
61
62 #ifndef Bool
63 # define Bool int
64 # define False 0
65 # define True 1
66 #endif
67
68 #include "stp_bpdu.h"
69 #include "vector.h"
70 #include "times.h"
71
72 #define RSTP_ERRORS { \
73 CHOOSE(STP_OK), \
74 CHOOSE(STP_Cannot_Find_Vlan), \
75 CHOOSE(STP_Imlicite_Instance_Create_Failed), \
76 CHOOSE(STP_Small_Bridge_Priority), \
77 CHOOSE(STP_Large_Bridge_Priority), \
78 CHOOSE(STP_Bridge_Priority_Not_A_Multiple_Of_4096), \
79 CHOOSE(STP_Small_Hello_Time), \
80 CHOOSE(STP_Large_Hello_Time), \
81 CHOOSE(STP_Small_Max_Age), \
82 CHOOSE(STP_Large_Max_Age), \
83 CHOOSE(STP_Small_Forward_Delay), \
84 CHOOSE(STP_Large_Forward_Delay), \
85 CHOOSE(STP_Forward_Delay_And_Max_Age_Are_Inconsistent),\
86 CHOOSE(STP_Hello_Time_And_Max_Age_Are_Inconsistent), \
87 CHOOSE(STP_Small_Port_Priority), \
88 CHOOSE(STP_Large_Port_Priority), \
89 CHOOSE(STP_Port_Priority_Not_A_Multiple_Of_16), \
90 CHOOSE(STP_Large_Port_PCost), \
91 CHOOSE(STP_Vlan_Had_Not_Yet_Been_Created), \
92 CHOOSE(STP_Port_Is_Absent_In_The_Vlan), \
93 CHOOSE(STP_Big_len8023_Format), \
94 CHOOSE(STP_Small_len8023_Format), \
95 CHOOSE(STP_len8023_Format_Gt_Len), \
96 CHOOSE(STP_Not_Proper_802_3_Packet), \
97 CHOOSE(STP_Invalid_Protocol), \
98 CHOOSE(STP_Invalid_Version), \
99 CHOOSE(STP_Had_Not_Yet_Been_Enabled_On_The_Vlan), \
100 CHOOSE(STP_Cannot_Create_Instance_For_Vlan), \
101 CHOOSE(STP_Cannot_Create_Instance_For_Port), \
102 CHOOSE(STP_Invalid_Bridge_Priority), \
103 CHOOSE(STP_There_Are_No_Ports), \
104 CHOOSE(STP_Cannot_Compute_Bridge_Prio), \
105 CHOOSE(STP_Another_Error), \
106 CHOOSE(STP_Nothing_To_Do), \
107 CHOOSE(STP_LAST_DUMMY), \
108 }
109
110 #define CHOOSE(a) a
111 typedef enum RSTP_ERRORS RSTP_ERRORS_T;
112 #undef CHOOSE
113
114 #ifndef __LINUX__
115 extern char* strdup (const char *s);
116
117 extern USHORT Ntohs (USHORT n);
118 extern ULONG Htonl (ULONG h);
119 extern USHORT Htons (USHORT h);
120 extern ULONG Ntohl (ULONG n);
121
122 #define htonl Htonl
123 #define htons Htons
124 #define ntohl Ntohl
125 #define ntohs Ntohs
126
127 #endif
128
129 #ifdef __LINUX__
130 #define STP_FATAL(TXT, MSG, EXCOD) \
131 {stp_trace ("FATAL:%s failed: %s:%d", TXT, MSG, EXCOD); \
132 exit (EXCOD);}
133 #else
134 #define STP_FATAL(TXT, MSG, EXCOD) \
135 Print ("FATAL: %s code %s:%d\n", TXT, MSG, EXCOD)
136 #endif
137
138 #define STP_MALLOC(PTR, TYPE, MSG) \
139 { \
140 PTR = (TYPE*) calloc (1, sizeof (TYPE)); \
141 if (! PTR) { \
142 STP_FATAL("malloc", MSG, -6); \
143 } \
144 }
145
146 #define STP_FREE(PTR, MSG) \
147 { \
148 if (! PTR) { \
149 STP_FATAL("free", MSG, -66); \
150 } \
151 free (PTR); \
152 PTR = NULL; \
153 }
154
155 #define STP_STRDUP(PTR, SRC, MSG) \
156 { \
157 PTR = strdup (SRC); \
158 if (! PTR) { \
159 STP_FATAL("strdup", MSG, -7); \
160 } \
161 }
162
163 #define STP_NEW_IN_LIST(WHAT, TYPE, LIST, MSG) \
164 { \
165 STP_MALLOC(WHAT, TYPE, MSG); \
166 WHAT->next = LIST; \
167 LIST = WHAT; \
168 }
169
170 typedef enum {
171 RSTP_PORT_EN_T,
172 RSTP_PORT_DIS_T,
173 RSTP_PORT_SPEED_T,
174 RSTP_PORT_DPLEX_T,
175 RSTP_PORT_RX_T,
176 RSTP_PORT_TIME_T,
177 RSTP_PORT_MNGR_T,
178 RSTP_EVENT_LAST_DUMMY
179
180 } RSTP_EVENT_T;
181
182 /* for debug trace messages */
183
184 #ifdef __LINUX__USE_PRINTF_FOR_STRACE
185 extern char* sprint_time_stump (void);
186 #define stp_trace(F, B...) printf("%s:" F "\n", sprint_time_stump(), ##B)
187 #else
188 extern void stp_trace (const char* fmt, ...);
189 #endif
190
191 #endif /* _STP_BASE_H__ */
192