FD.io VPP  v18.01.2-1-g9b554f3
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  complete();
79 
80  return rc_t::OK;
81 }
82 
83 template <>
84 rc_t
86 {
87  msg_t req(con.ctx(), std::ref(*this));
88 
89  auto& payload = req.get_request().get_payload();
90  payload.acl_index = m_hw_item.data().value();
91 
92  VAPI_CALL(req.execute());
93 
94  wait();
96 
97  return rc_t::OK;
98 }
99 
100 template <>
101 rc_t
103 {
104  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
105 
106  auto& payload = m_dump->get_request().get_payload();
107  payload.acl_index = ~0;
108 
109  VAPI_CALL(m_dump->execute());
110 
111  wait();
112 
113  return rc_t::OK;
114 }
115 
116 template <>
117 rc_t
119 {
120  msg_t req(con.ctx(), m_rules.size(), std::ref(*this));
121  uint32_t ii = 0;
122 
123  auto& payload = req.get_request().get_payload();
124  // payload.acl_index = m_hw_item.data().value();
125  payload.count = m_rules.size();
126  memset(payload.tag, 0, sizeof(payload.tag));
127  memcpy(payload.tag, m_key.c_str(),
128  std::min(m_key.length(), sizeof(payload.tag)));
129 
130  auto it = m_rules.cbegin();
131 
132  while (it != m_rules.cend()) {
133  to_vpp(*it, payload.r[ii]);
134  ++it;
135  ++ii;
136  }
137 
138  VAPI_CALL(req.execute());
139 
140  m_hw_item = wait();
141 
142  return rc_t::OK;
143 }
144 
145 template <>
146 rc_t
148 {
149  msg_t req(con.ctx(), std::ref(*this));
150 
151  auto& payload = req.get_request().get_payload();
152  payload.acl_index = m_hw_item.data().value();
153 
154  VAPI_CALL(req.execute());
155 
156  wait();
158 
159  return rc_t::OK;
160 }
161 
162 template <>
163 rc_t
165 {
166  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
167 
168  auto& payload = m_dump->get_request().get_payload();
169  payload.acl_index = ~0;
170 
171  VAPI_CALL(m_dump->execute());
172 
173  wait();
174 
175  return rc_t::OK;
176 }
177 
178 }; // namespace list_cmds
179 }; // namespace ACL
180 }; // namespace VOM
181 
182 /*
183  * fd.io coding-style-patch-verification: ON
184  *
185  * Local Variables:
186  * eval: (c-set-style "mozilla")
187  * End:
188  */
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:101
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:131
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:92
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:84
T & data()
Return the data read/written.
Definition: hw.hpp:108
action_t action() const
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
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
action_t action() const
Definition: acl_l2_rule.cpp:69
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:238
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:106
const route::prefix_t & dst() const
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:51
void to_bytes(uint8_t *array, uint8_t len) const
Convert to byte array.
Definition: types.cpp:133
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