FD.io VPP  v18.07-rc0-415-g6c78436
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  m_hw_item = wait();
78  if (m_hw_item.rc() == rc_t::OK)
79  insert_acl();
80 
81  return rc_t::OK;
82 }
83 
84 template <>
85 rc_t
87 {
88  msg_t req(con.ctx(), std::ref(*this));
89 
90  auto& payload = req.get_request().get_payload();
91  payload.acl_index = m_hw_item.data().value();
92 
93  VAPI_CALL(req.execute());
94 
95  wait();
97 
98  remove_acl();
99 
100  return rc_t::OK;
101 }
102 
103 template <>
104 rc_t
106 {
107  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
108 
109  auto& payload = m_dump->get_request().get_payload();
110  payload.acl_index = ~0;
111 
112  VAPI_CALL(m_dump->execute());
113 
114  wait();
115 
116  return rc_t::OK;
117 }
118 
119 template <>
120 rc_t
122 {
123  msg_t req(con.ctx(), m_rules.size(), std::ref(*this));
124  uint32_t ii = 0;
125 
126  auto& payload = req.get_request().get_payload();
127  // payload.acl_index = m_hw_item.data().value();
128  payload.count = m_rules.size();
129  memset(payload.tag, 0, sizeof(payload.tag));
130  memcpy(payload.tag, m_key.c_str(),
131  std::min(m_key.length(), sizeof(payload.tag)));
132 
133  auto it = m_rules.cbegin();
134 
135  while (it != m_rules.cend()) {
136  to_vpp(*it, payload.r[ii]);
137  ++it;
138  ++ii;
139  }
140 
141  VAPI_CALL(req.execute());
142 
143  m_hw_item = wait();
144  if (m_hw_item.rc() == rc_t::OK)
145  insert_acl();
146 
147  return rc_t::OK;
148 }
149 
150 template <>
151 rc_t
153 {
154  msg_t req(con.ctx(), std::ref(*this));
155 
156  auto& payload = req.get_request().get_payload();
157  payload.acl_index = m_hw_item.data().value();
158 
159  VAPI_CALL(req.execute());
160 
161  wait();
163 
164  remove_acl();
165 
166  return rc_t::OK;
167 }
168 
169 template <>
170 rc_t
172 {
173  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
174 
175  auto& payload = m_dump->get_request().get_payload();
176  payload.acl_index = ~0;
177 
178  VAPI_CALL(m_dump->execute());
179 
180  wait();
181 
182  return rc_t::OK;
183 }
184 
185 }; // namespace list_cmds
186 }; // namespace ACL
187 }; // namespace VOM
188 
189 /*
190  * fd.io coding-style-patch-verification: ON
191  *
192  * Local Variables:
193  * eval: (c-set-style "mozilla")
194  * End:
195  */
const route::prefix_t & src() const
Getters.
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:107
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:135
int value() const
Return the value of the enum - same as integer conversion.
Definition: enum_base.hpp:67
const mac_address_t & mac() const
Definition: acl_l2_rule.cpp:81
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
uint8_t tcp_flags_mask() const
const route::prefix_t & src_ip() const
Definition: acl_l2_rule.cpp:75
uint8_t tcp_flags_value() const
Error codes that VPP will return during a HW write.
Definition: types.hpp:90
T & data()
Return the data read/written.
Definition: hw.hpp:108
uint16_t dstport_or_icmpcode_first() const
rc_t issue(connection &con)
Issue the command to VPP/HW.
A representation of the connection to VPP.
Definition: connection.hpp:33
const action_t & action() const
static void to_vpp(const l2_rule &rule, vapi_type_macip_acl_rule &payload)
An ACL rule is the building block of an ACL.
Definition: acl_l2_rule.hpp:31
uint8_t proto() const
uint16_t srcport_or_icmptype_last() const
const mac_address_t & mac_mask() const
Definition: acl_l2_rule.cpp:87
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
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
const action_t & action() const
Definition: acl_l2_rule.cpp:69
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:112
const route::prefix_t & dst() const
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
void to_bytes(uint8_t *array, uint8_t len) const
Convert to byte array.
Definition: types.cpp:140
uint16_t srcport_or_icmptype_first() const
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:124
uint16_t dstport_or_icmpcode_last() const
rc_t issue(connection &con)
Issue the command to VPP/HW.
HW::item< handle_t > wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:89