FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
acl_l3_rule.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 <sstream>
17 
18 #include "vom/acl_l3_rule.hpp"
19 
20 namespace VOM {
21 namespace ACL {
23  const action_t& action,
24  const route::prefix_t& src,
25  const route::prefix_t& dst,
26  uint8_t proto,
28  uint16_t srcport_or_icmptype_last,
30  uint16_t dstport_or_icmpcode_last,
31  uint8_t tcp_flags_mask,
32  uint8_t tcp_flags_value)
33  : m_priority(priority)
34  , m_action(action)
35  , m_src(src)
36  , m_dst(dst)
37  , m_proto(proto)
38  , m_srcport_or_icmptype_first(srcport_or_icmptype_first)
39  , m_srcport_or_icmptype_last(srcport_or_icmptype_last)
40  , m_dstport_or_icmpcode_first(dstport_or_icmpcode_first)
41  , m_dstport_or_icmpcode_last(dstport_or_icmpcode_last)
42  , m_tcp_flags_mask(tcp_flags_mask)
43  , m_tcp_flags_value(tcp_flags_value)
44 {
45 }
46 
47 bool
48 l3_rule::operator<(const l3_rule& other) const
49 {
50  return (other.m_priority < m_priority);
51 }
52 
53 bool
54 l3_rule::operator==(const l3_rule& rule) const
55 {
56  return ((m_action == rule.m_action) && (m_src == rule.m_src) &&
57  (m_dst == rule.m_dst) && (m_proto == rule.m_proto) &&
58  (m_srcport_or_icmptype_first == rule.m_srcport_or_icmptype_first) &&
59  (m_srcport_or_icmptype_last == rule.m_srcport_or_icmptype_last) &&
60  (m_dstport_or_icmpcode_first == rule.m_dstport_or_icmpcode_first) &&
61  (m_dstport_or_icmpcode_last == rule.m_dstport_or_icmpcode_last) &&
62  (m_tcp_flags_mask == rule.m_tcp_flags_mask) &&
63  (m_tcp_flags_value == rule.m_tcp_flags_value));
64 }
65 
68 {
69  std::ostringstream s;
70 
71  s << "L3-rule:["
72  << "priority:" << m_priority << " action:" << m_action.to_string()
73  << " src:" << m_src.to_string() << " dst:" << m_dst.to_string()
74  << " proto:" << std::to_string(m_proto)
75  << " srcportfrom:" << m_srcport_or_icmptype_first
76  << " srcportto: " << m_srcport_or_icmptype_last
77  << " dstportfrom:" << m_dstport_or_icmpcode_first
78  << " dstportto:" << m_dstport_or_icmpcode_last
79  << " tcpflagmask:" << std::to_string(m_tcp_flags_mask)
80  << " tcpflagvalue:" << std::to_string(m_tcp_flags_value) << "]";
81 
82  return (s.str());
83 }
84 
85 void
87 {
88  m_src = src;
89 }
90 
91 void
93 {
94  m_dst = dst;
95 }
96 
97 void
99 {
100  m_proto = proto;
101 }
102 void
104 {
105  m_srcport_or_icmptype_first = srcport_or_icmptype_first;
106 }
107 
108 void
110 {
111  m_srcport_or_icmptype_last = srcport_or_icmptype_last;
112 }
113 
114 void
116 {
117  m_dstport_or_icmpcode_first = dstport_or_icmpcode_first;
118 }
119 
120 void
122 {
123  m_dstport_or_icmpcode_last = dstport_or_icmpcode_last;
124 }
125 
126 void
128 {
129  m_tcp_flags_mask = tcp_flags_mask;
130 }
131 
132 void
134 {
135  m_tcp_flags_value = tcp_flags_value;
136 }
137 
138 const route::prefix_t&
140 {
141  return m_src;
142 }
143 
144 uint32_t
146 {
147  return m_priority;
148 }
149 
150 const action_t&
152 {
153  return m_action;
154 }
155 
156 const route::prefix_t&
158 {
159  return m_dst;
160 }
161 
162 uint8_t
164 {
165  return m_proto;
166 }
167 
168 uint16_t
170 {
171  return m_srcport_or_icmptype_first;
172 }
173 
174 uint16_t
176 {
177  return m_srcport_or_icmptype_last;
178 }
179 
180 uint16_t
182 {
183  return m_dstport_or_icmpcode_first;
184 }
185 
186 uint16_t
188 {
189  return m_dstport_or_icmpcode_last;
190 }
191 
192 uint8_t
194 {
195  return m_tcp_flags_mask;
196 }
197 
198 uint8_t
200 {
201  return m_tcp_flags_value;
202 }
203 
204 }; // namespace ACL
205 }; // namespace VOM
206 
207 /*
208  * fd.io coding-style-patch-verification: OFF
209  *
210  * Local Variables:
211  * eval: (c-set-style "mozilla")
212  * End:
213  */
VOM::ACL::l3_rule::set_dst_ip
void set_dst_ip(route::prefix_t dst)
Set Dst Ip Address.
Definition: acl_l3_rule.cpp:92
VOM::ACL::l3_rule::set_tcp_flags_value
void set_tcp_flags_value(uint8_t tcp_flags_value)
Set TCP flags value.
Definition: acl_l3_rule.cpp:133
VOM::route::prefix_t
A prefix defintion.
Definition: prefix.hpp:131
VOM::ACL::l3_rule::srcport_or_icmptype_first
uint16_t srcport_or_icmptype_first() const
Definition: acl_l3_rule.cpp:169
VOM::ACL::l3_rule::set_src_ip
void set_src_ip(route::prefix_t src)
Set Src Ip Address.
Definition: acl_l3_rule.cpp:86
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::ACL::l3_rule::operator==
bool operator==(const l3_rule &rule) const
comparison operator (for testing)
Definition: acl_l3_rule.cpp:54
tcp_flags_mask
u8 tcp_flags_mask
Definition: acl_types.api:70
VOM::ACL::l3_rule::proto
uint8_t proto() const
Definition: acl_l3_rule.cpp:163
VOM::ACL::action_t
ACL Actions.
Definition: acl_types.hpp:26
VOM::ACL::l3_rule::operator<
bool operator<(const l3_rule &rule) const
less-than operator
Definition: acl_l3_rule.cpp:48
VOM::ACL::l3_rule::src
const route::prefix_t & src() const
Getters.
Definition: acl_l3_rule.cpp:139
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
dstport_or_icmpcode_first
u16 dstport_or_icmpcode_first
Definition: acl_types.api:63
VOM::ACL::l3_rule::priority
uint32_t priority() const
Definition: acl_l3_rule.cpp:145
VOM::route::prefix_t::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: prefix.cpp:214
dstport_or_icmpcode_last
u16 dstport_or_icmpcode_last
Definition: acl_types.api:64
VOM::ACL::l3_rule::set_src_to_port
void set_src_to_port(uint16_t srcport_or_icmptype_last)
Set Src port or ICMP Type last.
Definition: acl_l3_rule.cpp:109
priority
i32 priority
Definition: ipsec.api:95
VOM::ACL::l3_rule::set_src_from_port
void set_src_from_port(uint16_t srcport_or_icmptype_first)
Set Src port or ICMP Type first.
Definition: acl_l3_rule.cpp:103
tcp_flags_value
u8 tcp_flags_value
Definition: acl_types.api:71
VOM::ACL::l3_rule::set_proto
void set_proto(uint8_t proto)
Set proto.
Definition: acl_l3_rule.cpp:98
VOM::ACL::l3_rule
An ACL rule is the building block of an ACL.
Definition: acl_l3_rule.hpp:31
src
vl_api_address_t src
Definition: gre.api:54
VOM::ACL::l3_rule::tcp_flags_value
uint8_t tcp_flags_value() const
Definition: acl_l3_rule.cpp:199
VOM::enum_base::to_string
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
srcport_or_icmptype_first
u16 srcport_or_icmptype_first
Definition: acl_types.api:61
srcport_or_icmptype_last
u16 srcport_or_icmptype_last
Definition: acl_types.api:62
VOM::ACL::l3_rule::set_dst_from_port
void set_dst_from_port(uint16_t dstport_or_icmpcode_first)
Set Dst port or ICMP code first.
Definition: acl_l3_rule.cpp:115
VOM::ACL::l3_rule::set_tcp_flags_mask
void set_tcp_flags_mask(uint8_t tcp_flags_mask)
Set TCP flags mask.
Definition: acl_l3_rule.cpp:127
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
VOM::ACL::l3_rule::srcport_or_icmptype_last
uint16_t srcport_or_icmptype_last() const
Definition: acl_l3_rule.cpp:175
VOM::ACL::l3_rule::set_dst_to_port
void set_dst_to_port(uint16_t dstport_or_icmpcode_last)
Set Dst port or ICMP code last.
Definition: acl_l3_rule.cpp:121
VOM::ACL::l3_rule::dstport_or_icmpcode_last
uint16_t dstport_or_icmpcode_last() const
Definition: acl_l3_rule.cpp:187
VOM::ACL::l3_rule::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: acl_l3_rule.cpp:67
VOM::ACL::l3_rule::l3_rule
l3_rule(uint32_t priority, const action_t &action, const route::prefix_t &src, const route::prefix_t &dst, uint8_t proto=0, uint16_t srcport_or_icmptype_first=0, uint16_t srcport_or_icmptype_last=0, uint16_t dstport_or_icmpcode_first=0, uint16_t dstport_or_icmpcode_last=0, uint8_t tcp_flags_mask=0, uint8_t tcp_flags_value=0)
Construct a new object matching the desried state.
Definition: acl_l3_rule.cpp:22
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
action
vl_api_mac_event_action_t action
Definition: l2.api:211
acl_l3_rule.hpp
VOM::dependency_t::ACL
@ ACL
ACLs.
string
const char *const string
Definition: cJSON.h:172
VOM::ACL::l3_rule::tcp_flags_mask
uint8_t tcp_flags_mask() const
Definition: acl_l3_rule.cpp:193