-
Notifications
You must be signed in to change notification settings - Fork 390
/
cfg_filter.cc
115 lines (88 loc) · 3.79 KB
/
cfg_filter.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include <iostream>
#include <list>
#include <map>
#include <boost/function.hpp>
#include <base/logging.h>
#include <ifmap/ifmap_link.h>
#include <ifmap/ifmap_table.h>
#include <ifmap/ifmap_agent_table.h>
#include <vnc_cfg_types.h>
#include <base/parse_object.h>
#include <cmn/agent_cmn.h>
#include <cmn/agent_db.h>
#include <cfg/cfg_listener.h>
#include <cfg/cfg_init.h>
#include <cfg/cfg_filter.h>
using namespace std;
using namespace autogen;
CfgFilter::CfgFilter(AgentConfig *cfg) : agent_cfg_(cfg) {
}
CfgFilter::~CfgFilter() {
}
bool CfgFilter::CheckProperty(DBTable *table, IFMapNode *node, DBRequest *req,
int property_id) {
if (property_id < 0) {
return true;
}
if (req->oper == DBRequest::DB_ENTRY_DELETE) {
return true;
}
assert(req->oper == DBRequest::DB_ENTRY_ADD_CHANGE);
IFMapAgentTable::IFMapAgentData *data =
static_cast<IFMapAgentTable::IFMapAgentData *>(req->data.get());
IFMapObject *req_obj = static_cast<IFMapObject *>(data->content.get());
const IFMapIdentifier *req_id = static_cast<const IFMapIdentifier *>(req_obj);
if (req_id->IsPropertySet(property_id)) {
return true;
}
IFMapAgentTable::RequestKey *key =
static_cast<IFMapAgentTable::RequestKey *>(req->key.get());
LOG(ERROR, "ID-PERM not set for object <" << key->id_name << "> Table <" <<
table->name() << ">. Converting to DELETE");
// Convert operation to DELETE if ID_PERMS is not present
req->oper = DBRequest::DB_ENTRY_DELETE;
return true;
}
void CfgFilter::Init() {
agent_cfg_->cfg_vm_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
VirtualMachine::ID_PERMS));
agent_cfg_->cfg_vn_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
VirtualNetwork::ID_PERMS));
agent_cfg_->cfg_vm_interface_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
VirtualMachineInterface::ID_PERMS));
agent_cfg_->cfg_acl_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
AccessControlList::ID_PERMS));
agent_cfg_->cfg_loadbalancer_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
LoadbalancerPool::ID_PERMS));
agent_cfg_->cfg_service_instance_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
ServiceInstance::ID_PERMS));
agent_cfg_->cfg_security_group_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
SecurityGroup::ID_PERMS));
agent_cfg_->cfg_logical_port_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
LogicalInterface::ID_PERMS));
agent_cfg_->cfg_physical_device_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
PhysicalRouter::ID_PERMS));
}
void CfgFilter::Shutdown() {
agent_cfg_->cfg_vm_table()->RegisterPreFilter(NULL);
agent_cfg_->cfg_vn_table()->RegisterPreFilter(NULL);
agent_cfg_->cfg_vm_interface_table()->RegisterPreFilter(NULL);
agent_cfg_->cfg_acl_table()->RegisterPreFilter(NULL);
agent_cfg_->cfg_loadbalancer_table()->RegisterPreFilter(NULL);
agent_cfg_->cfg_service_instance_table()->RegisterPreFilter(NULL);
agent_cfg_->cfg_security_group_table()->RegisterPreFilter(NULL);
agent_cfg_->cfg_logical_port_table()->RegisterPreFilter(NULL);
agent_cfg_->cfg_physical_device_table()->RegisterPreFilter(NULL);
}