summaryrefslogtreecommitdiff
path: root/usr/src/lib/librstp/common/topoch.c
blob: 1926bcfe44264f7879f56c5074923e1979a78392 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/************************************************************************ 
 * RSTP library - Rapid Spanning Tree (802.1t, 802.1w) 
 * Copyright (C) 2001-2003 Optical Access 
 * Author: Alex Rozin 
 * 
 * This file is part of RSTP library. 
 * 
 * RSTP library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by the 
 * Free Software Foundation; version 2.1 
 * 
 * RSTP library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser 
 * General Public License for more details. 
 * 
 * You should have received a copy of the GNU Lesser General Public License 
 * along with RSTP library; see the file COPYING.  If not, write to the Free 
 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 
 * 02111-1307, USA. 
 **********************************************************************/

/* Topolgy Change state machine : 17.25 */
  
#include "base.h"
#include "stpm.h"
#include "stp_to.h" /* for STP_OUT_flush_lt */
  
#define STATES { \
  CHOOSE(INIT),             \
  CHOOSE(INACTIVE),         \
  CHOOSE(TCACTIVE),         \
  CHOOSE(DETECTED),         \
  CHOOSE(NOTIFIED_TC),          \
  CHOOSE(PROPAGATING),          \
  CHOOSE(ACKNOWLEDGED),         \
  CHOOSE(NOTIFIED_TCN)         \
}

#define GET_STATE_NAME STP_topoch_get_state_name
#include "choose.h"

#ifndef STRONGLY_SPEC_802_1W
/* 
 * In many kinds of hardware the function
 * STP_OUT_flush_lt is a) is very hard and b) cannot
 * delete learning emtries per port. The alternate
 * method may be used: we don't care operEdge flag here,
 * but clean learning table once for TopologyChange
 * for all ports, except the received port. I am ready to discuss :(
 * See below word STRONGLY_SPEC_802_1W
 */
#else
static Bool
flush (STATE_MACH_T *this, char* reason) /* 17.19.9 */
{
  register PORT_T* port = this->owner.port;
  Bool bret;

  if (port->operEdge) return True;
  if (this->debug) {
    stp_trace("%s (%s, %s, %s, '%s')",
        "flush", port->port_name, port->owner->name,
        LT_FLASH_ONLY_THE_PORT == type ? "this port" : "other ports",
        reason);
  }

  bret = STP_OUT_flush_lt (port->port_index, port->owner->vlan_id,
                           LT_FLASH_ONLY_THE_PORT, reason);
}
#endif

static void
setTcPropBridge (STATE_MACH_T* this, char* reason) /* 17.19.14 */
{
  register PORT_T* port = this->owner.port;
  register PORT_T* tmp;

  for (tmp = port->owner->ports; tmp; tmp = tmp->next) {
    if (tmp->port_index != port->port_index)
      tmp->tcProp = True;
  }

#ifndef STRONGLY_SPEC_802_1W
#ifdef STP_DBG
  if (this->debug) {
    stp_trace("%s (%s, %s, %s, '%s')",
        "clearFDB", port->port_name, port->owner->name,
        "other ports", reason);
  }
#endif

  STP_OUT_flush_lt (port->port_index, port->owner->vlan_id,
                    LT_FLASH_ALL_PORTS_EXCLUDE_THIS, reason);
#endif
}

static unsigned int
newTcWhile (STATE_MACH_T* this) /* 17.19.7 */
{
  register PORT_T* port = this->owner.port;

  if (port->sendRSTP && port->operPointToPointMac) {
    return 2 * port->owner->rootTimes.HelloTime;
  }
  return port->owner->rootTimes.MaxAge;
}

void
STP_topoch_enter_state (STATE_MACH_T* this)
{
  register PORT_T*      port = this->owner.port;

  switch (this->State) {
    case BEGIN:
    case INIT:
#ifdef STRONGLY_SPEC_802_1W
      flush (this, "topoch INIT");
#endif
      port->tcWhile = 0;
      port->tc =
      port->tcProp =
      port->tcAck = False;
      break;
    case INACTIVE:
      port->rcvdTc =
      port->rcvdTcn =
      port->rcvdTcAck = port->tc = port->tcProp = False;
      break;
    case TCACTIVE:
      break;
    case DETECTED:
      port->tcWhile = newTcWhile (this);
#ifdef STP_DBG
  if (this->debug) 
    stp_trace("DETECTED: tcWhile=%d on port %s", 
        port->tcWhile, port->port_name);
#endif
      setTcPropBridge (this, "DETECTED");
      port->tc = False;  
      break;
    case NOTIFIED_TC:
      port->rcvdTcn = port->rcvdTc = False;
      if (port->role == DesignatedPort) {
        port->tcAck = True;
      }
      setTcPropBridge (this, "NOTIFIED_TC");
      break;
    case PROPAGATING:
      port->tcWhile = newTcWhile (this);
#ifdef STP_DBG
  if (this->debug) 
    stp_trace("PROPAGATING: tcWhile=%d on port %s", 
        port->tcWhile, port->port_name);
#endif
#ifdef STRONGLY_SPEC_802_1W
      flush (this, "topoch PROPAGATING");
#endif
      port->tcProp = False;
      break;
    case ACKNOWLEDGED:
      port->tcWhile = 0;
#ifdef STP_DBG
  if (this->debug) 
    stp_trace("ACKNOWLEDGED: tcWhile=%d on port %s", 
        port->tcWhile, port->port_name);
#endif
      port->rcvdTcAck = False;
      break;
    case NOTIFIED_TCN:
      port->tcWhile = newTcWhile (this);
#ifdef STP_DBG
  if (this->debug) 
    stp_trace("NOTIFIED_TCN: tcWhile=%d on port %s", 
        port->tcWhile, port->port_name);
#endif
      break;
  };
}

Bool
STP_topoch_check_conditions (STATE_MACH_T* this)
{
  register PORT_T*      port = this->owner.port;

  if (BEGIN == this->State) {
    return STP_hop_2_state (this, INIT);
  }

  switch (this->State) {
    case INIT:
      return STP_hop_2_state (this, INACTIVE);
    case INACTIVE:
      if (port->role == RootPort || port->role == DesignatedPort)
        return STP_hop_2_state (this, TCACTIVE);
      if (port->rcvdTc || port->rcvdTcn || port->rcvdTcAck ||
          port->tc || port->tcProp)
        return STP_hop_2_state (this, INACTIVE);
      break;
    case TCACTIVE:
      if (port->role != RootPort && (port->role != DesignatedPort))
        return STP_hop_2_state (this, INIT);
      if (port->tc)
        return STP_hop_2_state (this, DETECTED);
      if (port->rcvdTcn)
        return STP_hop_2_state (this, NOTIFIED_TCN);
      if (port->rcvdTc)
        return STP_hop_2_state (this, NOTIFIED_TC);
      if (port->tcProp && !port->operEdge)
        return STP_hop_2_state (this, PROPAGATING);
      if (port->rcvdTcAck)
        return STP_hop_2_state (this, ACKNOWLEDGED);
      break;
    case DETECTED:
      return STP_hop_2_state (this, TCACTIVE);
    case NOTIFIED_TC:
      return STP_hop_2_state (this, TCACTIVE);
    case PROPAGATING:
      return STP_hop_2_state (this, TCACTIVE);
    case ACKNOWLEDGED:
      return STP_hop_2_state (this, TCACTIVE);
    case NOTIFIED_TCN:
      return STP_hop_2_state (this, NOTIFIED_TC);
  };
  return False;
}