Skip to content

Commit 7176fa4

Browse files
pcn-k8switch: fix bad initialization logic
Before 09356c4c033 ("services: remove generate_code and generate_code_vector") the k8switch was created with a stub program and then reloaded with the initial configuration. That approach is far from optimal as the code is immediately reloaded, then 09356c4c033 changed that to created the cube without any eBPF program and then add it with the initial configuration. However, the call to reload_program was still there, it fails because the stub is not present anymore. This commits fix that by calling add_program when the cube is created. Fixes: e09356c ("services: remove generate_code and generate_code_vector") Signed-off-by: Mauricio Vasquez B <mauriciovasquezbernal@gmail.com>
1 parent e9b238b commit 7176fa4

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/services/pcn-k8switch/src/K8switch.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ K8switch::K8switch(const std::string name, const K8switchJsonObject &conf)
3434
doSetVirtualClientSubnet(conf.getVirtualClientSubnet());
3535

3636
// reload code a single time
37-
reloadConfig();
37+
add_program(getFlags() + k8switch_code, 0);
3838

3939
addServiceList(conf.getService());
4040
addPortsList(conf.getPorts());
@@ -170,7 +170,7 @@ void K8switch::doSetVirtualClientSubnet(const std::string &value) {
170170
virtual_client_cidr_ = value;
171171
}
172172

173-
void K8switch::reloadConfig() {
173+
std::string K8switch::getFlags() {
174174
std::string flags;
175175

176176
// ports
@@ -197,6 +197,13 @@ void K8switch::reloadConfig() {
197197
"#define CLIENT_SUBNET " + std::to_string(htonl(client_subnet_)) + "\n";
198198
flags += "#define VIRTUAL_CLIENT_SUBNET " +
199199
std::to_string(htonl(virtual_client_subnet_)) + "\n";
200+
logger()->debug("flags is {}", flags);
201+
202+
return flags;
203+
}
204+
205+
void K8switch::reloadConfig() {
206+
std::string flags(getFlags());
200207

201208
logger()->debug("Reloading code with flags port: {}", flags);
202209

src/services/pcn-k8switch/src/K8switch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class K8switch : public polycube::service::Cube<Ports>,
143143
void cleanupSessionTable();
144144
uint32_t timestampToAge(const uint64_t timestamp);
145145
void tick();
146+
std::string getFlags();
146147

147148
std::unique_ptr<std::thread> tick_thread;
148149
bool stop_;

0 commit comments

Comments
 (0)