@@ -93,6 +93,10 @@ sai_status_t SwitchStateBase::setAclEntryMACsecFlowActive(
93
93
static_cast <std::uint32_t >(macsecAttr.m_an ),
94
94
macsecAttr.m_macsecName .c_str ());
95
95
}
96
+ else
97
+ {
98
+ m_uncreatedIngressMACsecSAs.insert (macsecAttr);
99
+ }
96
100
}
97
101
}
98
102
}
@@ -199,6 +203,21 @@ sai_status_t SwitchStateBase::createMACsecSA(
199
203
macsecAttr.m_sci .c_str (),
200
204
static_cast <std::uint32_t >(macsecAttr.m_an ),
201
205
macsecAttr.m_macsecName .c_str ());
206
+
207
+ // Maybe there are some uncreated ingress SAs that were added into m_uncreatedIngressMACsecSAs
208
+ // because the corresponding egress SA has not been created.
209
+ // So retry to create them.
210
+ if (macsecAttr.m_direction == SAI_MACSEC_DIRECTION_EGRESS)
211
+ {
212
+ retryCreateIngressMaCsecSAs ();
213
+ }
214
+ }
215
+ else
216
+ {
217
+ // In Linux MACsec model, Egress SA need to be created before ingress SA.
218
+ // So, if try to create the ingress SA firstly, it will failed.
219
+ // But to create the egress SA should be always successful.
220
+ m_uncreatedIngressMACsecSAs.insert (macsecAttr);
202
221
}
203
222
}
204
223
@@ -221,17 +240,31 @@ sai_status_t SwitchStateBase::removeMACsecPort(
221
240
}
222
241
}
223
242
224
- auto itr = m_macsecFlowPortMap.begin ();
243
+ auto flowItr = m_macsecFlowPortMap.begin ();
225
244
226
- while (itr != m_macsecFlowPortMap.end ())
245
+ while (flowItr != m_macsecFlowPortMap.end ())
227
246
{
228
- if (itr ->second == macsecPortId)
247
+ if (flowItr ->second == macsecPortId)
229
248
{
230
- itr = m_macsecFlowPortMap.erase (itr );
249
+ flowItr = m_macsecFlowPortMap.erase (flowItr );
231
250
}
232
251
else
233
252
{
234
- itr ++;
253
+ flowItr ++;
254
+ }
255
+ }
256
+
257
+ auto saItr = m_uncreatedIngressMACsecSAs.begin ();
258
+
259
+ while (saItr != m_uncreatedIngressMACsecSAs.end ())
260
+ {
261
+ if (saItr->m_macsecName == macsecAttr.m_macsecName )
262
+ {
263
+ saItr = m_uncreatedIngressMACsecSAs.erase (saItr);
264
+ }
265
+ else
266
+ {
267
+ saItr ++;
235
268
}
236
269
}
237
270
@@ -257,6 +290,20 @@ sai_status_t SwitchStateBase::removeMACsecSC(
257
290
}
258
291
}
259
292
293
+ auto saItr = m_uncreatedIngressMACsecSAs.begin ();
294
+
295
+ while (saItr != m_uncreatedIngressMACsecSAs.end ())
296
+ {
297
+ if (saItr->m_macsecName == macsecAttr.m_macsecName && saItr->m_sci == macsecAttr.m_sci )
298
+ {
299
+ saItr = m_uncreatedIngressMACsecSAs.erase (saItr);
300
+ }
301
+ else
302
+ {
303
+ saItr ++;
304
+ }
305
+ }
306
+
260
307
auto sid = sai_serialize_object_id (macsecScId);
261
308
return remove_internal (SAI_OBJECT_TYPE_MACSEC_SC, sid);
262
309
}
@@ -550,7 +597,7 @@ sai_status_t SwitchStateBase::loadMACsecAttrFromMACsecSA(
550
597
551
598
CHECK_STATUS (get (SAI_OBJECT_TYPE_MACSEC_SC, attr->value .oid , static_cast <uint32_t >(attrs.size ()), attrs.data ()));
552
599
553
- macsecAttr.m_cipher = MACsecAttr::get_cipher_name (attr-> value .s32 );
600
+ macsecAttr.m_cipher = MACsecAttr::get_cipher_name (attrs[ 3 ]. value .s32 );
554
601
555
602
if (macsecAttr.m_cipher == MACsecAttr::CIPHER_NAME_INVALID)
556
603
{
@@ -841,3 +888,28 @@ sai_status_t SwitchStateBase::getMACsecSAPacketNumber(
841
888
842
889
return SAI_STATUS_FAILURE;
843
890
}
891
+
892
+ void SwitchStateBase::retryCreateIngressMaCsecSAs ()
893
+ {
894
+ SWSS_LOG_ENTER ();
895
+
896
+ auto itr = m_uncreatedIngressMACsecSAs.begin ();
897
+
898
+ while (itr != m_uncreatedIngressMACsecSAs.end ())
899
+ {
900
+ if (m_macsecManager.create_macsec_sa (*itr))
901
+ {
902
+ SWSS_LOG_NOTICE (
903
+ " Enable MACsec SA %s:%u at the device %s" ,
904
+ itr->m_sci .c_str (),
905
+ static_cast <std::uint32_t >(itr->m_an ),
906
+ itr->m_macsecName .c_str ());
907
+
908
+ itr = m_uncreatedIngressMACsecSAs.erase (itr);
909
+ }
910
+ else
911
+ {
912
+ itr ++;
913
+ }
914
+ }
915
+ }
0 commit comments