-
Notifications
You must be signed in to change notification settings - Fork 104
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Segmentation fault when trying to add a secondaryip address in the format "ip-address/N" to a port on a router that has no ip address.
To Reproduce
In one terminal:
~ polycubectl router add r1
~ polycubectl router r1 ports p1
~ r1 ports p1 secondaryip add 10.0.2.254/24
Post "http://localhost:9000/polycube/v1/router/r1/ports/p1/secondaryip/10.0.2.254%2F24/": EOF
In another terminal:
~ sudo polycubed
...
[2020-10-23 17:03:00.524] [Router] [r1] [info] Creating Router instance
[2020-10-23 17:03:08.609] [Router] [r1] [info] Added new port: p1 (index: 0) [mac: b2:60:a2:c6:2b:b1 - ip: ]
[2020-10-23 17:03:19.571] [Router] [r1] [info] Adding secondary address [port: p1 - ip: 10.1.1.1/24]
[2020-10-23 17:03:19.571] [Router] [r1] [info] Added route [network: 10.1.1.1/32 - nexthop: 0.0.0.0 - interface: p1]
[2020-10-23 17:03:19.571] [Router] [r1] [info] Added route [network: 10.1.1.0/24 - nexthop: 0.0.0.0 - interface: p1]
[1] 29861 segmentation fault sudo polycubed
Expected behavior
Maybe a "warning" to the user instead of "segmentation fault".
Please tell us about your environment:
- OS details: cat /etc/-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"
- Kernel details: uname -a
5.4.0-48-generic #52~18.04.1-Ubuntu SMP Thu Sep 10 12:50:22 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
- Polycube Version: polycubectl version
polycubectl:
version: v0.9.0+ [git: (branch/commit): master/79889309]
polycubed:
version: v0.9.0+ [git: (branch/commit): master/79889309]
Possible solution
A possible solution I have found is to modify the addSecondaryIp method in Ports.cpp
void Ports::addSecondaryip(const std::string &ip,
const PortsSecondaryipJsonObject &conf) {
/*
* First create the port in the control plane
*/
if (!this->getIp().empty()) {
logger()->info("Adding secondary address [port: {0} - ip: {1}]", getName(),
ip);
auto ret = secondary_ips_.emplace(PortsSecondaryip(*this, conf));
/*
* Then update the port in the data path (this also adds the proper routes
* in the routing table)
*/
updatePortInDataPath();
} else
throw std::runtime_error(
"You can not add a secondary ip address to a port with no ip address");
}
It simply checks if the port has an IP address using the getIp() method. Let me know if you like this solution.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working