Skip to content

Commit 8de4069

Browse files
authored
[macsecorch]: Update packet number of MACsec SA at runtime (sonic-net#2153)
What I did Improve macsec orchagent to make the packet number that can be updated at runtime. Why I did it The threshold of refreshing SAK is too larger to be triggered in testing environment, so this PR provides an opportunity to update the packet number at runtime so that we don't really need to send the larger count of packets for the testing purpose.
1 parent 3b9c6c1 commit 8de4069

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

orchagent/macsecorch.cpp

+51-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <stack>
1414
#include <memory>
1515
#include <typeinfo>
16+
#include <cstdint>
1617

1718
/* Global Variables*/
1819

@@ -821,7 +822,30 @@ task_process_status MACsecOrch::taskUpdateEgressSA(
821822
}
822823
if (ctx.get_macsec_sc()->m_encoding_an == an)
823824
{
824-
return createMACsecSA(port_sci_an, sa_attr, SAI_MACSEC_DIRECTION_EGRESS);
825+
if (ctx.get_macsec_sa() == nullptr)
826+
{
827+
// The MACsec SA hasn't been created
828+
return createMACsecSA(port_sci_an, sa_attr, SAI_MACSEC_DIRECTION_EGRESS);
829+
}
830+
else
831+
{
832+
// The MACsec SA has enabled, update SA's attributes
833+
sai_uint64_t pn;
834+
835+
if (get_value(sa_attr, "next_pn", pn))
836+
{
837+
sai_attribute_t attr;
838+
attr.id = SAI_MACSEC_SA_ATTR_CONFIGURED_EGRESS_XPN;
839+
attr.value.u64 = pn;
840+
if (!this->updateMACsecAttr(SAI_OBJECT_TYPE_MACSEC_SA, *(ctx.get_macsec_sa()), attr))
841+
{
842+
SWSS_LOG_WARN("Fail to update next pn (%" PRIu64 ") of egress MACsec SA %s", pn, port_sci_an.c_str());
843+
return task_failed;
844+
}
845+
}
846+
847+
return task_success;
848+
}
825849
}
826850
return task_need_retry;
827851
}
@@ -841,7 +865,7 @@ task_process_status MACsecOrch::taskUpdateIngressSA(
841865
SWSS_LOG_ENTER();
842866

843867
swss::AlphaBoolean alpha_boolean = false;
844-
get_value(sa_attr, "active", alpha_boolean);
868+
bool has_active_field = get_value(sa_attr, "active", alpha_boolean);
845869
bool active = alpha_boolean.operator bool();
846870
if (active)
847871
{
@@ -863,7 +887,29 @@ task_process_status MACsecOrch::taskUpdateIngressSA(
863887

864888
if (ctx.get_macsec_sa() != nullptr)
865889
{
866-
return deleteMACsecSA(port_sci_an, SAI_MACSEC_DIRECTION_INGRESS);
890+
if (has_active_field)
891+
{
892+
// Delete MACsec SA explicitly by set active to false
893+
return deleteMACsecSA(port_sci_an, SAI_MACSEC_DIRECTION_INGRESS);
894+
}
895+
else
896+
{
897+
sai_uint64_t pn;
898+
899+
if (get_value(sa_attr, "lowest_acceptable_pn", pn))
900+
{
901+
sai_attribute_t attr;
902+
attr.id = SAI_MACSEC_SA_ATTR_MINIMUM_INGRESS_XPN;
903+
attr.value.u64 = pn;
904+
if (!this->updateMACsecAttr(SAI_OBJECT_TYPE_MACSEC_SA, *(ctx.get_macsec_sa()), attr))
905+
{
906+
SWSS_LOG_WARN("Fail to update lowest acceptable PN (%" PRIu64 ") of ingress MACsec SA %s", pn, port_sci_an.c_str());
907+
return task_failed;
908+
}
909+
}
910+
911+
return task_success;
912+
}
867913
}
868914
else
869915
{
@@ -874,6 +920,8 @@ task_process_status MACsecOrch::taskUpdateIngressSA(
874920
return task_need_retry;
875921
}
876922
}
923+
924+
return task_success;
877925
}
878926

879927
task_process_status MACsecOrch::taskDeleteIngressSA(

tests/test_macsec.py

+13
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,13 @@ def delete_transmit_sa(self, sai: str):
321321
del self.app_transmit_sa_table[sai]
322322
self.state_transmit_sa_table.wait_delete(sai)
323323

324+
@macsec_sa()
325+
def set_macsec_pn(
326+
self,
327+
sai: str,
328+
pn: int):
329+
self.app_transmit_sa_table[sai] = {"next_pn": pn}
330+
324331
@macsec_sc()
325332
def set_enable_transmit_sa(self, sci: str, an: int, enable: bool):
326333
if enable:
@@ -475,6 +482,12 @@ def rekey_macsec(
475482
auth_key: str,
476483
ssci: int,
477484
salt: str):
485+
wpa.set_macsec_pn(
486+
port_name,
487+
local_mac_address,
488+
macsec_port_identifier,
489+
an,
490+
0x00000000C0000000)
478491
wpa.create_receive_sa(
479492
port_name,
480493
peer_mac_address,

0 commit comments

Comments
 (0)