OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cfg_filter.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include <iostream>
6 #include <list>
7 #include <map>
8 
9 #include <boost/function.hpp>
10 
11 #include <base/logging.h>
12 
13 #include <ifmap/ifmap_link.h>
14 #include <ifmap/ifmap_table.h>
16 #include <vnc_cfg_types.h>
17 
18 #include <base/parse_object.h>
19 
20 #include <cmn/agent_cmn.h>
21 #include <cmn/agent_db.h>
22 
23 #include <cfg/cfg_init.h>
24 #include <cfg/cfg_filter.h>
25 
26 using namespace std;
27 using namespace autogen;
28 
29 CfgFilter::CfgFilter(AgentConfig *cfg) : agent_cfg_(cfg) {
30 }
31 
33 }
34 
36  const IFMapIdentifier *req_id,
37  DBRequest *req,
38  int property_id) {
39  if (property_id < 0) {
40  return true;
41  }
42 
43  if (req_id->IsPropertySet(property_id)) {
44  return true;
45  }
46 
47  // When ID_PERMS is not present, ignore the request
49  static_cast<IFMapAgentTable::RequestKey *>(req->key.get());
50  LOG(ERROR, "ID-PERM not set for object <" << key->id_name << "> Table <" <<
51  table->name() << ">. Ignoring it");
52  return false;
53 }
54 
56  if (table == agent_cfg_->cfg_vm_table())
57  return VirtualMachine::ID_PERMS;
58  if (table == agent_cfg_->cfg_vn_table())
59  return VirtualNetwork::ID_PERMS;
60  if (table == agent_cfg_->cfg_vm_interface_table())
61  return VirtualMachineInterface::ID_PERMS;
62  if (table == agent_cfg_->cfg_acl_table())
63  return AccessControlList::ID_PERMS;
64  if (table == agent_cfg_->cfg_service_instance_table())
65  return ServiceInstance::ID_PERMS;
66  if (table == agent_cfg_->cfg_service_template_table())
67  return ServiceTemplate::ID_PERMS;
68  if (table == agent_cfg_->cfg_security_group_table())
69  return SecurityGroup::ID_PERMS;
70  if (table == agent_cfg_->cfg_logical_port_table())
71  return LogicalInterface::ID_PERMS;
72  if (table == agent_cfg_->cfg_physical_device_table())
73  return PhysicalRouter::ID_PERMS;
74  if (table == agent_cfg_->cfg_health_check_table())
75  return ServiceHealthCheck::ID_PERMS;
76  if (table == agent_cfg_->cfg_qos_table())
77  return autogen::QosConfig::ID_PERMS;
78  if (table == agent_cfg_->cfg_qos_queue_table())
79  return autogen::QosQueue::ID_PERMS;
80  if (table == agent_cfg_->cfg_forwarding_class_table())
81  return autogen::ForwardingClass::ID_PERMS;
82  if (table == agent_cfg_->cfg_bridge_domain_table())
83  return autogen::BridgeDomain::ID_PERMS;
84  if (table == agent_cfg_->cfg_slo_table())
85  return autogen::SecurityLoggingObject::ID_PERMS;
86  if (table == agent_cfg_->cfg_port_tuple_table())
87  return autogen::PortTuple::ID_PERMS;
88  if (table == agent_cfg_->cfg_policy_set_table())
89  return autogen::ApplicationPolicySet::ID_PERMS;
90  if (table == agent_cfg_->cfg_firewall_policy_table())
91  return autogen::FirewallPolicy::ID_PERMS;
92  if (table == agent_cfg_->cfg_firewall_rule_table())
93  return autogen::FirewallRule::ID_PERMS;
94  if (table == agent_cfg_->cfg_tag_table())
95  return autogen::Tag::ID_PERMS;
96  if (table == agent_cfg_->cfg_multicast_policy_table())
97  return autogen::MulticastPolicy::ID_PERMS;
98  return -1;
99 }
100 
102  if (req->oper == DBRequest::DB_ENTRY_DELETE) {
103  return true;
104  }
105 
106  if (req->oper == DBRequest::DB_ENTRY_NOTIFY) {
107  return true;
108  }
109 
110  assert(req->oper == DBRequest::DB_ENTRY_ADD_CHANGE);
111 
113  static_cast<IFMapAgentTable::IFMapAgentData *>(req->data.get());
114  IFMapObject *req_obj = static_cast<IFMapObject *>(data->content.get());
115  const IFMapIdentifier *req_id = static_cast<const IFMapIdentifier *>(req_obj);
116 
117  if (CheckIdPermsProperty(table, req_id, req,
118  GetIdPermsPropertyId(table)) == false)
119  return false;
120 
121  //Table specific property checks
122  if ((table == agent_cfg_->cfg_vm_interface_table()) &&
123  (CheckVmInterfaceProperty(table, req_id, req) == false)) {
124  return false;
125  }
126 
127  return true;
128 }
129 
131  const IFMapIdentifier *req_id,
132  DBRequest *req) {
133  if (req_id->IsPropertySet(VirtualMachineInterface::MAC_ADDRESSES) ==
134  false) {
135  return true;
136  }
137 
138  const VirtualMachineInterface *vmi =
139  dynamic_cast<const VirtualMachineInterface *>(req_id);
140  if ((vmi->mac_addresses().at(0) == MacAddress::ZeroMac().ToString()) ||
141  (vmi->mac_addresses().size() == 0)) {
142  return false;
143  }
144 
145  return true;
146 }
147 
150  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
151 
153  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
154 
156  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
157 
159  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
160 
162  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
163 
165  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
166 
168  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
169 
171  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
172 
174  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
175 
177  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
178 
180  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
181 
183  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
184 
186  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
187 
189  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
190 
192  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
193 
195  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
196 
198  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
199 
201  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
202 
204  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
205 
207  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
208 
210  (boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3));
211 }
212 
235 }
IFMapAgentTable * cfg_port_tuple_table() const
Definition: cfg_init.h:154
IFMapAgentTable * cfg_forwarding_class_table() const
Definition: cfg_init.h:94
static const MacAddress & ZeroMac()
Definition: mac_address.h:158
bool IsPropertySet(int id) const
Definition: ifmap_object.h:99
void Shutdown()
Definition: cfg_filter.cc:213
std::unique_ptr< DBRequestData > data
Definition: db_table.h:49
IFMapAgentTable * cfg_service_template_table() const
Definition: cfg_init.h:58
int GetIdPermsPropertyId(DBTable *table) const
Definition: cfg_filter.cc:55
std::string ToString() const
Definition: mac_address.cc:53
IFMapAgentTable * cfg_physical_device_table() const
Definition: cfg_init.h:78
IFMapAgentTable * cfg_vm_interface_table() const
Definition: cfg_init.h:22
void Init()
Definition: cfg_filter.cc:148
std::unique_ptr< DBRequestKey > key
Definition: db_table.h:48
IFMapAgentTable * cfg_tag_table() const
Definition: cfg_init.h:134
IFMapAgentTable * cfg_multicast_policy_table() const
Definition: cfg_init.h:158
DBOperation oper
Definition: db_table.h:42
virtual ~CfgFilter()
Definition: cfg_filter.cc:32
bool CheckVmInterfaceProperty(DBTable *table, const IFMapIdentifier *req_id, DBRequest *req)
Definition: cfg_filter.cc:130
const std::string & name() const
Definition: db_table.h:110
AgentConfig * agent_cfg_
Definition: cfg_filter.h:21
bool CheckProperty(DBTable *table, IFMapNode *node, DBRequest *req)
Definition: cfg_filter.cc:101
IFMapAgentTable * cfg_firewall_rule_table() const
Definition: cfg_init.h:118
IFMapAgentTable * cfg_qos_queue_table() const
Definition: cfg_init.h:90
IFMapAgentTable * cfg_policy_set_table() const
Definition: cfg_init.h:110
IFMapAgentTable * cfg_health_check_table() const
Definition: cfg_init.h:106
IFMapAgentTable * cfg_logical_port_table() const
Definition: cfg_init.h:66
IFMapAgentTable * cfg_firewall_policy_table() const
Definition: cfg_init.h:114
IFMapAgentTable * cfg_qos_table() const
Definition: cfg_init.h:82
bool CheckIdPermsProperty(DBTable *table, const IFMapIdentifier *req_id, DBRequest *req, int property_id)
Definition: cfg_filter.cc:35
IFMapAgentTable * cfg_acl_table() const
Definition: cfg_init.h:28
std::unique_ptr< IFMapObject > content
CfgFilter(AgentConfig *cfg)
Definition: cfg_filter.cc:29
IFMapAgentTable * cfg_bridge_domain_table() const
Definition: cfg_init.h:98
#define LOG(_Level, _Msg)
Definition: logging.h:33
IFMapAgentTable * cfg_vn_table() const
Definition: cfg_init.h:26
IFMapAgentTable * cfg_slo_table() const
Definition: cfg_init.h:150
void RegisterPreFilter(PreFilterFn fn)
IFMapAgentTable * cfg_vm_table() const
Definition: cfg_init.h:25
IFMapAgentTable * cfg_service_instance_table() const
Definition: cfg_init.h:70
IFMapAgentTable * cfg_security_group_table() const
Definition: cfg_init.h:74