@@ -1183,6 +1183,18 @@ bool MACsecOrch::updateMACsecPort(MACsecPort &macsec_port, const TaskArgs &port_
1183
1183
if (get_value (port_attr, " enable_encrypt" , alpha_boolean))
1184
1184
{
1185
1185
macsec_port.m_enable_encrypt = alpha_boolean.operator bool ();
1186
+ if (!updateMACsecSCs (
1187
+ macsec_port,
1188
+ [&macsec_port, this ](MACsecOrch::MACsecSC &macsec_sc)
1189
+ {
1190
+ sai_attribute_t attr;
1191
+ attr.id = SAI_MACSEC_SC_ATTR_ENCRYPTION_ENABLE;
1192
+ attr.value .booldata = macsec_port.m_enable_encrypt ;
1193
+ return this ->updateMACsecAttr (SAI_OBJECT_TYPE_MACSEC_SC, macsec_sc.m_sc_id , attr);
1194
+ }))
1195
+ {
1196
+ return false ;
1197
+ }
1186
1198
}
1187
1199
if (get_value (port_attr, " send_sci" , alpha_boolean))
1188
1200
{
@@ -1212,42 +1224,74 @@ bool MACsecOrch::updateMACsecPort(MACsecPort &macsec_port, const TaskArgs &port_
1212
1224
SWSS_LOG_WARN (" Unknown Cipher Suite %s" , cipher_suite.c_str ());
1213
1225
return false ;
1214
1226
}
1227
+ if (!updateMACsecSCs (
1228
+ macsec_port,
1229
+ [&macsec_port, this ](MACsecOrch::MACsecSC &macsec_sc)
1230
+ {
1231
+ sai_attribute_t attr;
1232
+ attr.id = SAI_MACSEC_SC_ATTR_MACSEC_CIPHER_SUITE;
1233
+ attr.value .s32 = macsec_port.m_cipher_suite ;
1234
+ return this ->updateMACsecAttr (SAI_OBJECT_TYPE_MACSEC_SC, macsec_sc.m_sc_id , attr);
1235
+ }))
1236
+ {
1237
+ return false ;
1238
+ }
1215
1239
}
1216
1240
swss::AlphaBoolean enable = false ;
1217
1241
if (get_value (port_attr, " enable" , enable) && enable.operator bool () != macsec_port.m_enable )
1218
1242
{
1219
- std::vector<MACsecOrch::MACsecSC *> macsec_scs;
1220
1243
macsec_port.m_enable = enable.operator bool ();
1221
- for (auto &sc : macsec_port.m_egress_scs )
1244
+ if (!updateMACsecSCs (
1245
+ macsec_port,
1246
+ [&macsec_port, &recover, this ](MACsecOrch::MACsecSC &macsec_sc)
1247
+ {
1248
+ // Change the ACL entry action from packet action to MACsec flow
1249
+ if (macsec_port.m_enable )
1250
+ {
1251
+ if (!this ->setMACsecFlowActive (macsec_sc.m_entry_id , macsec_sc.m_flow_id , true ))
1252
+ {
1253
+ SWSS_LOG_WARN (" Cannot change the ACL entry action from packet action to MACsec flow" );
1254
+ return false ;
1255
+ }
1256
+ auto entry_id = macsec_sc.m_entry_id ;
1257
+ auto flow_id = macsec_sc.m_flow_id ;
1258
+ recover.add_action ([this , entry_id, flow_id]()
1259
+ { this ->setMACsecFlowActive (entry_id, flow_id, false ); });
1260
+ }
1261
+ else
1262
+ {
1263
+ this ->setMACsecFlowActive (macsec_sc.m_entry_id , macsec_sc.m_flow_id , false );
1264
+ }
1265
+ return true ;
1266
+ }))
1222
1267
{
1223
- macsec_scs. push_back (&sc. second ) ;
1268
+ return false ;
1224
1269
}
1225
- for (auto &sc : macsec_port.m_ingress_scs )
1270
+ }
1271
+
1272
+ recover.clear ();
1273
+ return true ;
1274
+ }
1275
+
1276
+ bool MACsecOrch::updateMACsecSCs (MACsecPort &macsec_port, std::function<bool (MACsecOrch::MACsecSC &)> action)
1277
+ {
1278
+ SWSS_LOG_ENTER ();
1279
+
1280
+ for (auto &sc : macsec_port.m_egress_scs )
1281
+ {
1282
+ if (!action (sc.second ))
1226
1283
{
1227
- macsec_scs. push_back (&sc. second ) ;
1284
+ return false ;
1228
1285
}
1229
- for (auto &macsec_sc : macsec_scs)
1286
+ }
1287
+ for (auto &sc : macsec_port.m_ingress_scs )
1288
+ {
1289
+ if (!action (sc.second ))
1230
1290
{
1231
- // Change the ACL entry action from packet action to MACsec flow
1232
- if (macsec_port.m_enable )
1233
- {
1234
- if (!setMACsecFlowActive (macsec_sc->m_entry_id , macsec_sc->m_flow_id , true ))
1235
- {
1236
- SWSS_LOG_WARN (" Cannot change the ACL entry action from packet action to MACsec flow" );
1237
- return false ;
1238
- }
1239
- auto entry_id = macsec_sc->m_entry_id ;
1240
- auto flow_id = macsec_sc->m_flow_id ;
1241
- recover.add_action ([this , entry_id, flow_id]() { this ->setMACsecFlowActive (entry_id, flow_id, false ); });
1242
- }
1243
- else
1244
- {
1245
- setMACsecFlowActive (macsec_sc->m_entry_id , macsec_sc->m_flow_id , false );
1246
- }
1291
+ return false ;
1247
1292
}
1248
1293
}
1249
1294
1250
- recover.clear ();
1251
1295
return true ;
1252
1296
}
1253
1297
@@ -1721,6 +1765,42 @@ bool MACsecOrch::deleteMACsecSC(sai_object_id_t sc_id)
1721
1765
return true ;
1722
1766
}
1723
1767
1768
+ bool MACsecOrch::updateMACsecAttr (sai_object_type_t object_type, sai_object_id_t object_id, const sai_attribute_t &attr)
1769
+ {
1770
+ SWSS_LOG_ENTER ();
1771
+
1772
+ sai_status_t status = SAI_STATUS_SUCCESS;
1773
+
1774
+ if (object_type == SAI_OBJECT_TYPE_MACSEC_PORT)
1775
+ {
1776
+ status = sai_macsec_api->set_macsec_port_attribute (object_id, &attr);
1777
+ }
1778
+ else if (object_type == SAI_OBJECT_TYPE_MACSEC_SC)
1779
+ {
1780
+ status = sai_macsec_api->set_macsec_sc_attribute (object_id, &attr);
1781
+ }
1782
+ else if (object_type == SAI_OBJECT_TYPE_MACSEC_SA)
1783
+ {
1784
+ status = sai_macsec_api->set_macsec_sa_attribute (object_id, &attr);
1785
+ }
1786
+ else
1787
+ {
1788
+ SWSS_LOG_ERROR (" Wrong type %s" , sai_serialize_object_type (object_type).c_str ());
1789
+ return false ;
1790
+ }
1791
+
1792
+ if (status != SAI_STATUS_SUCCESS)
1793
+ {
1794
+ task_process_status handle_status = handleSaiSetStatus (SAI_API_MACSEC, status);
1795
+ if (handle_status != task_success)
1796
+ {
1797
+ return parseHandleSaiStatusFailure (handle_status);
1798
+ }
1799
+ }
1800
+
1801
+ return true ;
1802
+ }
1803
+
1724
1804
task_process_status MACsecOrch::createMACsecSA (
1725
1805
const std::string &port_sci_an,
1726
1806
const TaskArgs &sa_attr,
0 commit comments