FD.io VPP  v19.01.3-6-g70449b9b9
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 
18 namespace VOM {
19 namespace ACL {
20 namespace list_cmds {
21 /*
22  * Jumping through hoops to not expose the VAPI types publically
23  */
24 static void
25 to_vpp(const l2_rule& rule, vapi_type_macip_acl_rule& payload)
26 {
27  payload.is_permit = rule.action().value();
28  rule.src_ip().to_vpp(&payload.is_ipv6, payload.src_ip_addr,
29  &payload.src_ip_prefix_len);
30  rule.mac().to_bytes(payload.src_mac, 6);
31  rule.mac_mask().to_bytes(payload.src_mac_mask, 6);
32 }
33 
34 static void
35 to_vpp(const l3_rule& rule, vapi_type_acl_rule& payload)
36 {
37  payload.is_permit = rule.action().value();
38  rule.src().to_vpp(&payload.is_ipv6, payload.src_ip_addr,
39  &payload.src_ip_prefix_len);
40  rule.dst().to_vpp(&payload.is_ipv6, payload.dst_ip_addr,
41  &payload.dst_ip_prefix_len);
42 
43  payload.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(payload.tag, m_key.c_str(),
65  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(payload.tag, m_key.c_str(),
132  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
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: ON
193  *
194  * Local Variables:
195  * eval: (c-set-style "mozilla")
196  * End:
197  */
const action_t & action() const
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
uint16_t srcport_or_icmptype_last() const
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
void to_bytes(uint8_t *array, uint8_t len) const
Convert to byte array.
Definition: types.cpp:140
int value() const
Return the value of the enum - same as integer conversion.
Definition: enum_base.hpp:67
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
T & data()
Return the data read/written.
Definition: hw.hpp:109
const action_t & action() const
Definition: acl_l2_rule.cpp:69
const mac_address_t & mac_mask() const
Definition: acl_l2_rule.cpp:87
rc_t issue(connection &con)
Issue the command to VPP/HW.
uint8_t proto() const
A representation of the connection to VPP.
Definition: connection.hpp:33
void to_vpp(uint8_t *is_ip6, uint8_t *addr, uint8_t *len) const
Convert the prefix into VPP API parameters.
Definition: prefix.cpp:251
static void to_vpp(const l2_rule &rule, vapi_type_macip_acl_rule &payload)
uint16_t dstport_or_icmpcode_last() const
An ACL rule is the building block of an ACL.
Definition: acl_l2_rule.hpp:31
uint16_t dstport_or_icmpcode_first() const
const route::prefix_t & dst() const
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
const route::prefix_t & src() const
Getters.
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:109
const route::prefix_t & src_ip() const
Definition: acl_l2_rule.cpp:75
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
An ACL rule is the building block of an ACL.
Definition: acl_l3_rule.hpp:31
rc_t issue(connection &con)
Issue the command to VPP/HW.
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
uint16_t srcport_or_icmptype_first() const
uint8_t tcp_flags_mask() const
rc_t issue(connection &con)
Issue the command to VPP/HW.
const mac_address_t & mac() const
Definition: acl_l2_rule.cpp:81
uint8_t tcp_flags_value() const
HW::item< handle_t > & m_hw_item
A reference to an object&#39;s HW::item that the command will update.
Definition: rpc_cmd.hpp:134