OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
acl_entry_match.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef __AGENT_ACL_ENTRY_MATCH_H__
6 #define __AGENT_ACL_ENTRY_MATCH_H__
7 
8 #include <boost/ptr_container/ptr_list.hpp>
9 #include <boost/intrusive/list.hpp>
10 #include <boost/intrusive/slist.hpp>
11 #include <boost/uuid/uuid.hpp>
12 
13 #include <cmn/agent_cmn.h>
14 #include <cmn/agent.h>
15 #include <agent_types.h>
16 
17 struct PacketHeader;
18 struct FlowPolicyInfo;
19 
23  int ip_plen;
24 
26  }
27  bool operator==(const AclAddressInfo& rhs) const {
28  if (ip_addr == rhs.ip_addr && ip_mask == rhs.ip_mask) {
29  return true;
30  }
31  return false;
32  }
33 };
34 
36 public:
37  enum Type {
44  };
46  virtual ~AclEntryMatch() {}
47  virtual bool Match(const PacketHeader *packet_header,
48  FlowPolicyInfo *info) const = 0;
49  virtual void SetAclEntryMatchSandeshData(AclEntrySandeshData &data) = 0;
50  virtual bool Compare(const AclEntryMatch &rhs) const = 0;
51  bool operator ==(const AclEntryMatch &rhs) const {
52  if (type_ != rhs.type_) {
53  return false;
54  }
55  return Compare(rhs);
56  }
57 private:
59 };
60 
61 struct Range {
62  Range(const uint16_t minimum, const uint16_t maximum) :
63  min(minimum), max(maximum) {}
64  Range() : min(0), max(0) {}
65  boost::intrusive::slist_member_hook<> node;
66  uint16_t min;
67  uint16_t max;
68  bool operator==(const Range &rhs) const {
69  if (min == rhs.min && max == rhs.max) {
70  return true;
71  }
72  return false;
73  }
74 };
75 
76 typedef boost::intrusive::member_hook<Range,
77  boost::intrusive::slist_member_hook<>,
80 typedef boost::intrusive::slist<Range,
81  RangeNode,
82  boost::intrusive::cache_last<true>
84 
86  void operator() (Range *range) { delete range;}
87 };
88 
89 class PortMatch : public AclEntryMatch {
90 public:
92  ~PortMatch() {port_ranges_.clear_and_dispose(delete_disposer());}
93  void SetPortRange(const uint16_t min_port, const uint16_t max_port);
94  void SetAclEntryMatchSandeshData(AclEntrySandeshData &data) = 0;
95  virtual bool Match(const PacketHeader *packet_header,
96  FlowPolicyInfo *info) const = 0;
97  virtual bool Compare(const AclEntryMatch &rhs) const;
98  bool CheckPortRanges(const uint16_t min_port,
99  const uint16_t max_port) const;
100 protected:
102 };
103 
104 class SrcPortMatch : public PortMatch {
105 public:
107  bool Match(const PacketHeader *packet_header,
108  FlowPolicyInfo *info) const;
109  void SetAclEntryMatchSandeshData(AclEntrySandeshData &data);
110 };
111 class DstPortMatch : public PortMatch {
112 public:
114  bool Match(const PacketHeader *packet_header,
115  FlowPolicyInfo *info) const;
116  void SetAclEntryMatchSandeshData(AclEntrySandeshData &data);
117 };
118 
119 class ProtocolMatch : public AclEntryMatch {
120 public:
123  void SetProtocolRange(const uint16_t min, const uint16_t max);
124  bool Match(const PacketHeader *packet_header,
125  FlowPolicyInfo *info) const;
126  void SetAclEntryMatchSandeshData(AclEntrySandeshData &data);
127  virtual bool Compare(const AclEntryMatch &rhs) const;
128 
129 private:
131 };
132 
133 class ServicePort {
134 public:
138 
139  bool operator==(const ServicePort &rhs) const {
140  if (protocol == rhs.protocol &&
141  src_port == rhs.src_port&&
142  dst_port == rhs.dst_port) {
143  return true;
144  }
145  return false;
146  }
147 
148  bool PortMatch(uint32_t sport, uint32_t dport) const;
149 };
150 
152 public:
153  typedef std::vector<ServicePort> ServicePortList;
154 
155  ServiceGroupMatch(ServicePortList service_port_list):
157  service_port_list_(service_port_list) {}
159 
160  bool Match(const PacketHeader *packet_header,
161  FlowPolicyInfo *info) const;
162  void SetAclEntryMatchSandeshData(AclEntrySandeshData &data);
163  virtual bool Compare(const AclEntryMatch &rhs) const;
164 
165  size_t size() const {
166  return service_port_list_.size();
167  }
168 
169 private:
171 };
172 
173 
174 class TagsMatch : public AclEntryMatch {
175 public:
178  tag_list_(tag_list) {}
180 
181  bool Match(const PacketHeader *packet_header,
182  FlowPolicyInfo *info) const;
183  void SetAclEntryMatchSandeshData(AclEntrySandeshData &data);
184  virtual bool Compare(const AclEntryMatch &rhs) const;
185 
186  size_t size() const {
187  return tag_list_.size();
188  }
189 
190  const TagList& tag_list() const {
191  return tag_list_;
192  }
193 
194 private:
196 };
197 
198 class AddressMatch : public AclEntryMatch {
199 public:
201  static const int kAny = -1;
202  //typedef std::vector<uint32_t> sgl;
203  enum AddressType {
204  IP_ADDR = 1,
206  SG = 3,
207  TAGS = 4,
210  };
211 
214 
215  // Set source
216  void SetSource(bool src);
217 
218  // Network policy address could by SG uuid or VN policy uuid
219  void SetNetworkID(const uuid id);
220  void SetNetworkIDStr(const std::string id);
221  void SetSGId(const uint32_t id);
222  void SetTags(const TagList &tags) {
223  addr_type_ = TAGS;
224  tags_ = tags;
225  }
226 
227  void SetAddressGroup(const std::vector<AclAddressInfo> &list,
228  const TagList &tags);
229 
230  const TagList& tags() const {
231  return tags_;
232  }
233  // Set IP Address and mask
234  void SetIPAddress(const std::vector<AclAddressInfo> &list);
235  // Match packet header for address
236  bool Match(const PacketHeader *packet_header,
237  FlowPolicyInfo *info) const;
238  void SetAclEntryMatchSandeshData(AclEntrySandeshData &data);
239  virtual bool Compare(const AclEntryMatch &rhs) const;
240  static std::string BuildIpMaskList(const std::vector<AclAddressInfo> &list);
241  static std::string BuildTags(const TagList &list);
242  size_t ip_list_size() const {
243  return ip_list_.size();
244  }
245 private:
247  bool src_;
248 
249  // IP Address and mask
250  std::vector<AclAddressInfo> ip_list_;
251  // Network policy or Security Group identifier
253  std::string policy_id_s_;
254  int sg_id_;
256 
257  bool SGMatch(const SecurityGroupList &sg_l, int id) const;
258  bool SGMatch(const SecurityGroupList *sg_l, int id) const;
259  bool TagsMatch(const TagList &tags) const;
260  bool TagsMatchAG(const TagList &tags) const;
261  bool AddressGroupMatch(const IpAddress &ip, const TagList &tags) const;
262 };
263 #endif
bool Match(const PacketHeader *packet_header, FlowPolicyInfo *info) const
Definition: acl_entry.cc:522
bool operator==(const Range &rhs) const
bool TagsMatch(const TagList &tags) const
Definition: acl_entry.cc:410
static std::string BuildTags(const TagList &list)
Definition: acl_entry.cc:641
const TagList & tag_list() const
void SetAclEntryMatchSandeshData(AclEntrySandeshData &data)
Definition: acl_entry.cc:997
void SetSource(bool src)
Definition: acl_entry.cc:375
void SetAclEntryMatchSandeshData(AclEntrySandeshData &data)
Definition: acl_entry.cc:746
bool Match(const PacketHeader *packet_header, FlowPolicyInfo *info) const
Definition: acl_entry.cc:945
static const int kAny
virtual ~AclEntryMatch()
bool operator==(const AclEntryMatch &rhs) const
void SetIPAddress(const std::vector< AclAddressInfo > &list)
Definition: acl_entry.cc:344
virtual bool Compare(const AclEntryMatch &rhs) const
Definition: acl_entry.cc:887
void SetNetworkID(const uuid id)
Definition: acl_entry.cc:357
bool Match(const PacketHeader *packet_header, FlowPolicyInfo *info) const
Definition: acl_entry.cc:832
size_t size() const
Range(const uint16_t minimum, const uint16_t maximum)
boost::asio::ip::address IpAddress
Definition: address.h:13
void SetSGId(const uint32_t id)
Definition: acl_entry.cc:369
size_t size() const
std::vector< int > SecurityGroupList
Definition: agent.h:201
boost::uuids::uuid uuid
void SetAclEntryMatchSandeshData(AclEntrySandeshData &data)
Definition: acl_entry.cc:660
void SetTags(const TagList &tags)
bool AddressGroupMatch(const IpAddress &ip, const TagList &tags) const
Definition: acl_entry.cc:508
virtual bool Compare(const AclEntryMatch &rhs) const =0
virtual bool Match(const PacketHeader *packet_header, FlowPolicyInfo *info) const =0
std::vector< AclAddressInfo > ip_list_
virtual bool Compare(const AclEntryMatch &rhs) const
Definition: acl_entry.cc:925
boost::uuids::uuid uuid
virtual void SetAclEntryMatchSandeshData(AclEntrySandeshData &data)=0
const TagList & tags() const
boost::intrusive::member_hook< Range, boost::intrusive::slist_member_hook<>,&Range::node > RangeNode
ServiceGroupMatch(ServicePortList service_port_list)
virtual bool Compare(const AclEntryMatch &rhs) const
Definition: acl_entry.cc:578
void SetNetworkIDStr(const std::string id)
Definition: acl_entry.cc:363
uint8_t type
Definition: load_balance.h:109
void SetAclEntryMatchSandeshData(AclEntrySandeshData &data)
Definition: acl_entry.cc:897
AddressType addr_type_
virtual bool Match(const PacketHeader *packet_header, FlowPolicyInfo *info) const =0
RangeSList port_ranges_
static std::string BuildIpMaskList(const std::vector< AclAddressInfo > &list)
Definition: acl_entry.cc:624
void SetAclEntryMatchSandeshData(AclEntrySandeshData &data)=0
bool operator==(const ServicePort &rhs) const
IpAddress ip_addr
bool Match(const PacketHeader *packet_header, FlowPolicyInfo *info) const
Definition: acl_entry.cc:771
RangeSList protocol_ranges_
AclEntryMatch(Type type)
bool Match(const PacketHeader *packet_header, FlowPolicyInfo *info) const
Definition: acl_entry.cc:977
bool PortMatch(uint32_t sport, uint32_t dport) const
Definition: acl_entry.cc:757
bool operator==(const AclAddressInfo &rhs) const
std::string policy_id_s_
bool SGMatch(const SecurityGroupList &sg_l, int id) const
Definition: acl_entry.cc:397
void SetAclEntryMatchSandeshData(AclEntrySandeshData &data)
Definition: acl_entry.cc:965
void SetPortRange(const uint16_t min_port, const uint16_t max_port)
Definition: acl_entry.cc:907
virtual bool Compare(const AclEntryMatch &rhs) const
Definition: acl_entry.cc:709
void SetAddressGroup(const std::vector< AclAddressInfo > &list, const TagList &tags)
Definition: acl_entry.cc:350
IpAddress ip_mask
PortMatch(Type type)
std::vector< ServicePort > ServicePortList
bool TagsMatchAG(const TagList &tags) const
Definition: acl_entry.cc:440
bool Match(const PacketHeader *packet_header, FlowPolicyInfo *info) const
Definition: acl_entry.cc:731
boost::intrusive::slist_member_hook node
void SetProtocolRange(const uint16_t min, const uint16_t max)
Definition: acl_entry.cc:702
void SetAclEntryMatchSandeshData(AclEntrySandeshData &data)
Definition: acl_entry.cc:805
void operator()(Range *range)
uint16_t min
TagsMatch(TagList tag_list)
size_t ip_list_size() const
TagList tag_list_
boost::intrusive::slist< Range, RangeNode, boost::intrusive::cache_last< true > > RangeSList
ServicePortList service_port_list_
virtual bool Compare(const AclEntryMatch &rhs) const
Definition: acl_entry.cc:794
uint16_t max
bool CheckPortRanges(const uint16_t min_port, const uint16_t max_port) const
Definition: acl_entry.cc:913
std::vector< int > TagList
Definition: agent.h:202