11#include " MACsecFilter.h"
2+ #include " MACsecFilterStateGuard.h"
23
34#include " swss/logger.h"
45#include " swss/select.h"
@@ -17,7 +18,8 @@ MACsecFilter::MACsecFilter(
1718 _In_ const std::string &macsecInterfaceName):
1819 m_macsecDeviceEnable(false ),
1920 m_macsecfd(0 ),
20- m_macsecInterfaceName(macsecInterfaceName)
21+ m_macsecInterfaceName(macsecInterfaceName),
22+ m_state(MACsecFilter::MACsecFilterState::MACSEC_FILTER_STATE_IDLE)
2123{
2224 SWSS_LOG_ENTER ();
2325
@@ -30,6 +32,17 @@ void MACsecFilter::enable_macsec_device(
3032 SWSS_LOG_ENTER ();
3133
3234 m_macsecDeviceEnable = enable;
35+
36+ // The function, execute(), may be running in another thread,
37+ // the macsec device enable state cannot be changed in the busy state.
38+ // Because if the macsec device was deleted in the busy state,
39+ // the error value of function, forward, will be returned
40+ // to the caller of execute()
41+ // and the caller thread will exit due to the error return value.
42+ while (get_state () == MACsecFilter::MACsecFilterState::MACSEC_FILTER_STATE_BUSY)
43+ {
44+ // Waiting the MACsec filter exit from the BUSY state
45+ }
3346}
3447
3548void MACsecFilter::set_macsec_fd (
@@ -40,12 +53,20 @@ void MACsecFilter::set_macsec_fd(
4053 m_macsecfd = macsecfd;
4154}
4255
56+ MACsecFilter::MACsecFilterState MACsecFilter::get_state () const
57+ {
58+ SWSS_LOG_ENTER ();
59+
60+ return m_state;
61+ }
62+
4363TrafficFilter::FilterStatus MACsecFilter::execute (
4464 _Inout_ void *buffer,
4565 _Inout_ size_t &length)
4666{
4767 SWSS_LOG_ENTER ();
4868
69+ MACsecFilterStateGuard state_guard (m_state, MACsecFilter::MACsecFilterState::MACSEC_FILTER_STATE_BUSY);
4970 auto mac_hdr = static_cast <const ethhdr *>(buffer);
5071
5172 if (ntohs (mac_hdr->h_proto ) == EAPOL_ETHER_TYPE)
0 commit comments