FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
acl_list_cmds.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "vom/acl_list_cmds.hpp"
17 #include "vom/api_types.hpp"
18 
19 namespace VOM {
20 namespace ACL {
21 namespace list_cmds {
22 /*
23  * Jumping through hoops to not expose the VAPI types publically
24  */
25 static void
26 to_vpp(const l2_rule& rule, vapi_type_macip_acl_rule& payload)
27 {
28  payload.is_permit = (vapi_enum_acl_action)rule.action().value();
29  rule.src_ip().to_vpp((uint8_t*)&payload.src_prefix.address.af,
30  (uint8_t*)&payload.src_prefix.address.un,
31  &payload.src_prefix.len);
32  rule.mac().to_bytes(payload.src_mac, 6);
33  rule.mac_mask().to_bytes(payload.src_mac_mask, 6);
34 }
35 
36 static void
37 to_vpp(const l3_rule& rule, vapi_type_acl_rule& payload)
38 {
39  payload.is_permit = (vapi_enum_acl_action)rule.action().value();
40  payload.src_prefix = to_api(rule.src());
41  payload.dst_prefix = to_api(rule.dst());
42 
43  payload.proto = (vapi_enum_ip_proto)rule.proto();
44  payload.srcport_or_icmptype_first = rule.srcport_or_icmptype_first();
45  payload.srcport_or_icmptype_last = rule.srcport_or_icmptype_last();
46  payload.dstport_or_icmpcode_first = rule.dstport_or_icmpcode_first();
47  payload.dstport_or_icmpcode_last = rule.dstport_or_icmpcode_last();
48 
49  payload.tcp_flags_mask = rule.tcp_flags_mask();
50  payload.tcp_flags_value = rule.tcp_flags_value();
51 }
52 
53 template<>
54 rc_t
56 {
57  msg_t req(con.ctx(), m_rules.size(), std::ref(*this));
58  uint32_t ii = 0;
59 
60  auto& payload = req.get_request().get_payload();
61  payload.acl_index = m_hw_item.data().value();
62  payload.count = m_rules.size();
63  memset(payload.tag, 0, sizeof(payload.tag));
64  memcpy(
65  payload.tag, m_key.c_str(), std::min(m_key.length(), sizeof(payload.tag)));
66 
67  auto it = m_rules.cbegin();
68 
69  while (it != m_rules.cend()) {
70  to_vpp(*it, payload.r[ii]);
71  ++it;
72  ++ii;
73  }
74 
75  VAPI_CALL(req.execute());
76 
77  wait();
78 
79  if (m_hw_item.rc() == rc_t::OK)
80  insert_acl();
81 
82  return rc_t::OK;
83 }
84 
85 template<>
86 rc_t
88 {
89  msg_t req(con.ctx(), std::ref(*this));
90 
91  auto& payload = req.get_request().get_payload();
92  payload.acl_index = m_hw_item.data().value();
93 
94  VAPI_CALL(req.execute());
95 
96  wait();
98 
99  remove_acl();
100 
101  return rc_t::OK;
102 }
103 
104 template<>
105 rc_t
107 {
108  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
109 
110  auto& payload = m_dump->get_request().get_payload();
111  payload.acl_index = ~0;
112 
113  VAPI_CALL(m_dump->execute());
114 
115  wait();
116 
117  return rc_t::OK;
118 }
119 
120 template<>
121 rc_t
123 {
124  msg_t req(con.ctx(), m_rules.size(), std::ref(*this));
125  uint32_t ii = 0;
126 
127  auto& payload = req.get_request().get_payload();
128  // payload.acl_index = m_hw_item.data().value();
129  payload.count = m_rules.size();
130  memset(payload.tag, 0, sizeof(payload.tag));
131  memcpy(
132  payload.tag, m_key.c_str(), std::min(m_key.length(), sizeof(payload.tag)));
133 
134  auto it = m_rules.cbegin();
135 
136  while (it != m_rules.cend()) {
137  to_vpp(*it, payload.r[ii]);
138  ++it;
139  ++ii;
140  }
141 
142  VAPI_CALL(req.execute());
143 
144  wait();
145 
146  if (m_hw_item.rc() == rc_t::OK)
147  insert_acl();
148 
149  return rc_t::OK;
150 }
151 
152 template<>
153 rc_t
155 {
156  msg_t req(con.ctx(), std::ref(*this));
157 
158  auto& payload = req.get_request().get_payload();
159  payload.acl_index = m_hw_item.data().value();
160 
161  VAPI_CALL(req.execute());
162 
163  wait();
165 
166  remove_acl();
167 
168  return rc_t::OK;
169 }
170 
171 template<>
172 rc_t
173 l2_dump_cmd::issue(connection& con)
174 {
175  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
176 
177  auto& payload = m_dump->get_request().get_payload();
178  payload.acl_index = ~0;
179 
180  VAPI_CALL(m_dump->execute());
181 
182  wait();
183 
184  return rc_t::OK;
185 }
186 
187 }; // namespace list_cmds
188 }; // namespace ACL
189 }; // namespace VOM
190 
191 /*
192  * fd.io coding-style-patch-verification: OFF
193  *
194  * Local Variables:
195  * eval: (c-set-style "mozilla")
196  * End:
197  */
VOM::ACL::l3_rule::srcport_or_icmptype_first
uint16_t srcport_or_icmptype_first() const
Definition: acl_l3_rule.cpp:169
VOM::dump_cmd< DUMP >::msg_t
DUMP msg_t
Definition: dump_cmd.hpp:46
VOM::rpc_cmd< HW::item< handle_t >, UPDATE >::wait
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
VOM::HW::item::set
void set(const rc_t &rc)
Set the HW return code - should only be called from the family of Command objects.
Definition: hw.hpp:125
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::ACL::l3_rule::dst
const route::prefix_t & dst() const
Definition: acl_l3_rule.cpp:157
VOM::rc_t::OK
const static rc_t OK
The HW write was successfull.
Definition: types.hpp:109
VOM::ACL::l2_rule
An ACL rule is the building block of an ACL.
Definition: acl_l2_rule.hpp:31
VOM::ACL::l3_rule::proto
uint8_t proto() const
Definition: acl_l3_rule.cpp:163
VOM::ACL::l3_rule::src
const route::prefix_t & src() const
Getters.
Definition: acl_l3_rule.cpp:139
VOM::ACL::list_cmds::update_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: acl_list_cmds.cpp:55
VOM::handle_t::value
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
VOM::ACL::l3_rule::action
const action_t & action() const
Definition: acl_l3_rule.cpp:151
VOM::ACL::l3_rule::dstport_or_icmpcode_first
uint16_t dstport_or_icmpcode_first() const
Definition: acl_l3_rule.cpp:181
con
Connection con
Definition: vapi_cpp_test.cpp:56
VOM::ACL::list_cmds::delete_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: acl_list_cmds.hpp:141
VOM::rpc_cmd< HW::item< handle_t >, UPDATE >::m_hw_item
HW::item< handle_t > & m_hw_item
A reference to an object's HW::item that the command will update.
Definition: rpc_cmd.hpp:134
VOM::dump_cmd< DUMP >::m_dump
std::unique_ptr< DUMP > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
VOM::enum_base::value
int value() const
Return the value of the enum - same as integer conversion.
Definition: enum_base.hpp:88
VOM::ACL::l2_rule::action
const action_t & action() const
Definition: acl_l2_rule.cpp:69
VAPI_CALL
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
VOM::ACL::list_cmds::dump_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: acl_list_cmds.cpp:106
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
VOM::mac_address_t::to_bytes
void to_bytes(uint8_t *array, uint8_t len) const
Convert to byte array.
Definition: types.cpp:140
VOM::ACL::list_cmds::to_vpp
static void to_vpp(const l2_rule &rule, vapi_type_macip_acl_rule &payload)
Definition: acl_list_cmds.cpp:26
VOM::dump_cmd< DUMP >::wait
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
VOM::ACL::l3_rule
An ACL rule is the building block of an ACL.
Definition: acl_l3_rule.hpp:31
VOM::rc_t::NOOP
const static rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
it
save_rewrite_length must be aligned so that reass doesn t overwrite it
Definition: buffer.h:425
VOM::ACL::l3_rule::tcp_flags_value
uint8_t tcp_flags_value() const
Definition: acl_l3_rule.cpp:199
VOM::ACL::l2_rule::mac_mask
const mac_address_t & mac_mask() const
Definition: acl_l2_rule.cpp:87
VOM::ACL::l2_rule::mac
const mac_address_t & mac() const
Definition: acl_l2_rule.cpp:81
VOM::to_api
vapi_enum_ip_neighbor_flags to_api(const neighbour::flags_t &f)
Definition: api_types.cpp:21
VOM::rpc_cmd< HW::item< handle_t >, UPDATE >::msg_t
UPDATE msg_t
convenient typedef
Definition: rpc_cmd.hpp:46
VOM::HW::item::rc
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
VOM::HW::item::data
T & data()
Return the data read/written.
Definition: hw.hpp:109
acl_list_cmds.hpp
VOM::route::prefix_t::to_vpp
void to_vpp(uint8_t *is_ip6, uint8_t *addr, uint8_t *len) const
Convert the prefix into VPP API parameters.
Definition: prefix.cpp:282
VOM::ACL::l3_rule::srcport_or_icmptype_last
uint16_t srcport_or_icmptype_last() const
Definition: acl_l3_rule.cpp:175
VOM::ACL::l2_rule::src_ip
const route::prefix_t & src_ip() const
Definition: acl_l2_rule.cpp:75
VOM::ACL::l3_rule::dstport_or_icmpcode_last
uint16_t dstport_or_icmpcode_last() const
Definition: acl_l3_rule.cpp:187
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
api_types.hpp
VOM::dependency_t::ACL
@ ACL
ACLs.
VOM::ACL::l3_rule::tcp_flags_mask
uint8_t tcp_flags_mask() const
Definition: acl_l3_rule.cpp:193