Skip to content

Commit 5f8fff0

Browse files
authored
[vslib]Add MACsec Manager (sonic-net#715)
Signed-off-by: Ze Gan <[email protected]>
1 parent 65de898 commit 5f8fff0

File tree

4 files changed

+1111
-0
lines changed

4 files changed

+1111
-0
lines changed

vslib/inc/MACsecAttr.h

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#pragma once
2+
3+
#include "HostInterfaceInfo.h"
4+
5+
#include <string>
6+
#include <memory>
7+
8+
namespace saivs
9+
{
10+
using macsec_sci_t = std::string;
11+
using macsec_an_t = std::uint16_t;
12+
using macsec_pn_t = std::uint64_t;
13+
14+
struct MACsecAttr
15+
{
16+
// Explicitely declare constructor and destructor as non-inline functions
17+
// to avoid 'call is unlikely and code size would grow [-Werror=inline]'
18+
MACsecAttr();
19+
20+
~MACsecAttr();
21+
22+
std::string m_vethName;
23+
std::string m_macsecName;
24+
std::string m_authKey;
25+
std::string m_sak;
26+
std::string m_sci;
27+
28+
macsec_an_t m_an;
29+
macsec_pn_t m_pn;
30+
31+
bool m_sendSci;
32+
bool m_encryptionEnable;
33+
34+
sai_int32_t m_direction;
35+
36+
std::shared_ptr<HostInterfaceInfo> m_info;
37+
};
38+
}

vslib/inc/MACsecManager.h

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#pragma once
2+
3+
#include "MACsecAttr.h"
4+
#include "MACsecFilter.h"
5+
#include "MACsecForwarder.h"
6+
7+
namespace saivs
8+
{
9+
class MACsecManager
10+
{
11+
public:
12+
MACsecManager();
13+
14+
virtual ~MACsecManager();
15+
16+
bool create_macsec_port(
17+
_In_ const MACsecAttr &attr);
18+
19+
bool create_macsec_sc(
20+
_In_ const MACsecAttr &attr);
21+
22+
bool create_macsec_sa(
23+
_In_ const MACsecAttr &attr);
24+
25+
bool delete_macsec_port(
26+
_In_ const MACsecAttr &attr);
27+
28+
bool delete_macsec_sc(
29+
_In_ const MACsecAttr &attr);
30+
31+
bool delete_macsec_sa(
32+
_In_ const MACsecAttr &attr);
33+
34+
bool enable_macsec_filter(
35+
_In_ const std::string &macsecInterface,
36+
_In_ bool enable);
37+
38+
bool get_macsec_sa_pn(
39+
_In_ const MACsecAttr &attr,
40+
_Out_ sai_uint64_t &pn) const;
41+
42+
private:
43+
44+
bool create_macsec_egress_sc(
45+
_In_ const MACsecAttr &attr);
46+
47+
bool create_macsec_ingress_sc(
48+
_In_ const MACsecAttr &attr);
49+
50+
bool create_macsec_egress_sa(
51+
_In_ const MACsecAttr &attr);
52+
53+
bool create_macsec_ingress_sa(
54+
_In_ const MACsecAttr &attr);
55+
56+
bool delete_macsec_egress_sc(
57+
_In_ const MACsecAttr &attr);
58+
59+
bool delete_macsec_ingress_sc(
60+
_In_ const MACsecAttr &attr);
61+
62+
bool delete_macsec_egress_sa(
63+
_In_ const MACsecAttr &attr);
64+
65+
bool delete_macsec_ingress_sa(
66+
_In_ const MACsecAttr &attr);
67+
68+
bool add_macsec_filter(
69+
_In_ const std::string &macsecInterface);
70+
71+
bool add_macsec_forwarder(
72+
_In_ const std::string &macsecInterface);
73+
74+
bool delete_macsec_forwarder(
75+
_In_ const std::string &macsecInterface);
76+
77+
bool add_macsec_manager(
78+
_In_ const std::string &macsecInterface,
79+
_In_ std::shared_ptr<HostInterfaceInfo> info);
80+
81+
bool delete_macsec_manager(
82+
_In_ const std::string &macsecInterface);
83+
84+
bool get_macsec_device_info(
85+
_In_ const std::string &macsecDevice,
86+
_Out_ std::string &info) const;
87+
88+
bool is_macsec_device_existing(
89+
_In_ const std::string &macsecDevice) const;
90+
91+
bool get_macsec_sc_info(
92+
_In_ const std::string &macsecDevice,
93+
_In_ sai_int32_t direction,
94+
_In_ const std::string &sci,
95+
_Out_ std::string &info) const;
96+
97+
bool is_macsec_sc_existing(
98+
_In_ const std::string &macsecDevice,
99+
_In_ sai_int32_t direction,
100+
_In_ const std::string &sci) const;
101+
102+
bool get_macsec_sa_info(
103+
_In_ const std::string &macsecDevice,
104+
_In_ sai_int32_t direction,
105+
_In_ const std::string &sci,
106+
_In_ macsec_an_t an,
107+
_Out_ std::string &info) const;
108+
109+
bool is_macsec_sa_existing(
110+
_In_ const std::string &macsecDevice,
111+
_In_ sai_int32_t direction,
112+
_In_ const std::string &sci,
113+
_In_ macsec_an_t an) const;
114+
115+
size_t get_macsec_sa_count(
116+
_In_ const std::string &macsecDevice,
117+
_In_ sai_int32_t direction,
118+
_In_ const std::string &sci) const;
119+
120+
void cleanup_macsec_device() const;
121+
122+
std::string shellquote(
123+
_In_ const std::string &str) const;
124+
125+
bool exec(
126+
_In_ const std::string &command,
127+
_Out_ std::string &output) const;
128+
129+
bool exec(
130+
_In_ const std::string &command) const;
131+
132+
struct MACsecTrafficManager
133+
{
134+
MACsecTrafficManager() = default;
135+
136+
~MACsecTrafficManager() = default;
137+
138+
std::shared_ptr<HostInterfaceInfo> m_info;
139+
std::shared_ptr<MACsecFilter> m_ingressFilter;
140+
std::shared_ptr<MACsecFilter> m_egressFilter;
141+
std::shared_ptr<MACsecForwarder> m_forwarder;
142+
};
143+
144+
std::map<std::string, MACsecTrafficManager> m_macsecTrafficManagers;
145+
};
146+
}

vslib/src/MACsecAttr.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "MACsecAttr.h"
2+
3+
#include "swss/logger.h"
4+
5+
using namespace saivs;
6+
7+
MACsecAttr::MACsecAttr()
8+
{
9+
SWSS_LOG_ENTER();
10+
11+
// empty intentionally
12+
}
13+
14+
MACsecAttr::~MACsecAttr()
15+
{
16+
SWSS_LOG_ENTER();
17+
18+
// empty intentionally
19+
}

0 commit comments

Comments
 (0)