Commit a13c7d84 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[4106] Cleanup in the DHCPv4o6 IPC class.

parent f80c5341
......@@ -38,23 +38,12 @@ Dhcp4o6IpcBase::~Dhcp4o6IpcBase() {
close();
}
int Dhcp4o6IpcBase::open(uint16_t port, int side) {
int Dhcp4o6IpcBase::open(const uint16_t port, const int side) {
if (port == port_) {
// No change: nothing to do
return (socket_fd_);
}
// Port 0: closing
if (port == 0) {
port_ = 0;
if (socket_fd_ != -1) {
IfaceMgr::instance().deleteExternalSocket(socket_fd_);
::close(socket_fd_);
socket_fd_ = -1;
}
return (socket_fd_);
}
// Open socket
int sock = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
if (sock < 0) {
......@@ -63,8 +52,8 @@ int Dhcp4o6IpcBase::open(uint16_t port, int side) {
// Set reuse address
int flag = 1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(char *)&flag, sizeof(flag)) < 0) {
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, static_cast<const void*>(&flag),
sizeof(flag)) < 0) {
::close(sock);
isc_throw(Unexpected, "Failed to set SO_REUSEADDR on DHCP4o6 socket.");
}
......@@ -104,7 +93,8 @@ int Dhcp4o6IpcBase::open(uint16_t port, int side) {
} else {
remote6.sin6_port = htons(port);
}
if (connect(sock, (struct sockaddr *)&remote6, sizeof(remote6)) < 0) {
if (connect(sock, reinterpret_cast<const struct sockaddr*>(&remote6),
sizeof(remote6)) < 0) {
::close(sock);
isc_throw(Unexpected, "Failed to connect DHCP4o6 socket.");
}
......@@ -127,7 +117,12 @@ int Dhcp4o6IpcBase::open(uint16_t port, int side) {
}
void Dhcp4o6IpcBase::close() {
static_cast<void>(open(0, 0));
port_ = 0;
if (socket_fd_ != -1) {
IfaceMgr::instance().deleteExternalSocket(socket_fd_);
::close(socket_fd_);
socket_fd_ = -1;
}
}
Pkt6Ptr Dhcp4o6IpcBase::receive() {
......@@ -170,7 +165,7 @@ Pkt6Ptr Dhcp4o6IpcBase::receive() {
return (pkt);
}
void Dhcp4o6IpcBase::send(Pkt6Ptr pkt) {
void Dhcp4o6IpcBase::send(const Pkt6Ptr& pkt) {
// No packet: nothing to send
if (!pkt) {
return;
......
......@@ -46,7 +46,7 @@ protected:
/// @param side side of the server (4 or 6)
///
/// @return new socket descriptor
int open(uint16_t port, int side);
int open(const uint16_t port, const int side);
public:
/// @brief Open communication socket (for derived classes)
......@@ -65,7 +65,7 @@ public:
///
/// @param a pointer to a DHCPv6 message with interface and remote
/// address set for the IPC message
void send(Pkt6Ptr pkt);
void send(const Pkt6Ptr& pkt);
protected:
/// @brief Port number
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment