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