Skip to content

Commit

Permalink
Handle return val from send_response() and ioctl()
Browse files Browse the repository at this point in the history
Signed-off-by: Kasiewicz, Marek <[email protected]>
  • Loading branch information
Sakoram committed Dec 9, 2024
1 parent 2fa5be5 commit d80834c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 17 deletions.
6 changes: 5 additions & 1 deletion app/v4l2_to_ip/v4l2_to_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,11 @@ static void video_close(struct device* dev) {
}

static void video_log_status(struct device* dev) {
ioctl(dev->fd, VIDIOC_LOG_STATUS);
int ret;
ret = ioctl(dev->fd, VIDIOC_LOG_STATUS);
if (ret < 0) {
printf("Failed to log status: %s (%d).\n", strerror(errno), errno);
}
}

static int video_get_format(struct device* dev) {
Expand Down
64 changes: 48 additions & 16 deletions manager/mtl_instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,16 @@ void mtl_instance::handle_message_get_lcore(mtl_lcore_message_t* lcore_msg) {
uint16_t lcore_id = ntohs(lcore_msg->lcore);
int ret = mtl_lcore::get_instance().get_lcore(lcore_id);
if (ret < 0) {
send_response(ret);
if (send_response(ret) < 0) {
log(log_level::ERROR, "Failed to send response for get_lcore");
}
return;
}
lcore_ids.insert(lcore_id);
log(log_level::INFO, "Added lcore " + std::to_string(lcore_id));
send_response(0);
if (send_response(0) < 0) {
log(log_level::ERROR, "Failed to send response for get_lcore");
}
}

void mtl_instance::handle_message_put_lcore(mtl_lcore_message_t* lcore_msg) {
Expand All @@ -172,12 +176,16 @@ void mtl_instance::handle_message_put_lcore(mtl_lcore_message_t* lcore_msg) {
uint16_t lcore_id = ntohs(lcore_msg->lcore);
int ret = mtl_lcore::get_instance().put_lcore(lcore_id);
if (ret < 0) {
send_response(ret);
if (send_response(ret) < 0) {
log(log_level::ERROR, "Failed to send response for put_lcore");
}
return;
}
lcore_ids.erase(lcore_id);
log(log_level::INFO, "Removed lcore " + std::to_string(lcore_id));
send_response(0);
if (send_response(0) < 0) {
log(log_level::ERROR, "Failed to send response for put_lcore");
}
}

void mtl_instance::handle_message_register(mtl_register_message_t* register_msg) {
Expand All @@ -190,15 +198,19 @@ void mtl_instance::handle_message_register(mtl_register_message_t* register_msg)
auto interface = get_interface(ifindex);
if (interface == nullptr) {
log(log_level::ERROR, "Could not get interface " + std::to_string(ifindex));
send_response(-1);
if (send_response(-1) < 0) {
log(log_level::ERROR, "Failed to send response for register");
}
return;
}
}

log(log_level::INFO, "Registered.");

is_registered = true;
send_response(0);
if (send_response(0) < 0) {
log(log_level::ERROR, "Failed to send response for register");
}
}

std::shared_ptr<mtl_interface> mtl_instance::get_interface(const unsigned int ifindex) {
Expand Down Expand Up @@ -265,67 +277,87 @@ void mtl_instance::handle_message_udp_dp_filter(
auto interface = get_interface(ifindex);
if (interface == nullptr) {
log(log_level::ERROR, "Failed to get interface " + std::to_string(ifindex));
send_response(-1);
if (send_response(-1) < 0) {
log(log_level::ERROR, "Failed to send response for udp_dp_filter");
}
return;
}
int ret = interface->update_udp_dp_filter(port, add);
send_response(ret);
if (send_response(ret) < 0) {
log(log_level::ERROR, "Failed to send response for udp_dp_filter");
}
}

void mtl_instance::handle_message_if_get_queue(mtl_if_message_t* if_msg) {
unsigned int ifindex = ntohl(if_msg->ifindex);
auto interface = get_interface(ifindex);
if (interface == nullptr) {
log(log_level::ERROR, "Failed to get interface " + std::to_string(ifindex));
send_response(-1, MTL_MSG_TYPE_IF_QUEUE_ID);
if (send_response(-1, MTL_MSG_TYPE_IF_QUEUE_ID) < 0) {
log(log_level::ERROR, "Failed to send response for if_get_queue");
}
return;
}
int ret = interface->get_queue();
if (ret > 0) if_queue_ids[ifindex].insert(ret);
send_response(ret, MTL_MSG_TYPE_IF_QUEUE_ID);
if (send_response(ret, MTL_MSG_TYPE_IF_QUEUE_ID) < 0) {
log(log_level::ERROR, "Failed to send response for if_get_queue");
}
}

void mtl_instance::handle_message_if_put_queue(mtl_if_message_t* if_msg) {
unsigned int ifindex = ntohl(if_msg->ifindex);
auto interface = get_interface(ifindex);
if (interface == nullptr) {
log(log_level::ERROR, "Failed to get interface " + std::to_string(ifindex));
send_response(-1);
if (send_response(-1) < 0) {
log(log_level::ERROR, "Failed to send response for if_put_queue");
}
return;
}
uint16_t queue_id = ntohs(if_msg->queue_id);
int ret = interface->put_queue(queue_id);
if (ret == 0) if_queue_ids[ifindex].erase(queue_id);
send_response(ret);
if (send_response(ret) < 0) {
log(log_level::ERROR, "Failed to send response for if_put_queue");
}
}

void mtl_instance::handle_message_if_add_flow(mtl_if_message_t* if_msg) {
unsigned int ifindex = ntohl(if_msg->ifindex);
auto interface = get_interface(ifindex);
if (interface == nullptr) {
log(log_level::ERROR, "Failed to get interface " + std::to_string(ifindex));
send_response(-1);
if (send_response(-1) < 0) {
log(log_level::ERROR, "Failed to send response for if_add_flow");
}
return;
}
int ret = interface->add_flow(ntohs(if_msg->queue_id), ntohl(if_msg->flow_type),
ntohl(if_msg->src_ip), ntohl(if_msg->dst_ip),
ntohs(if_msg->src_port), ntohs(if_msg->dst_port));
if (ret > 0) if_flow_ids[ifindex].insert(ret);
send_response(ret, MTL_MSG_TYPE_IF_FLOW_ID);
if (send_response(ret, MTL_MSG_TYPE_IF_FLOW_ID) < 0) {
log(log_level::ERROR, "Failed to send response for if_add_flow");
}
}

void mtl_instance::handle_message_if_del_flow(mtl_if_message_t* if_msg) {
unsigned int ifindex = ntohl(if_msg->ifindex);
auto interface = get_interface(ifindex);
if (interface == nullptr) {
log(log_level::ERROR, "Failed to get interface " + std::to_string(ifindex));
send_response(-1);
if (send_response(-1) < 0) {
log(log_level::ERROR, "Failed to send response for if_del_flow");
}
return;
}
unsigned int flow_id = ntohl(if_msg->flow_id);
int ret = interface->del_flow(flow_id);
if (ret == 0) if_flow_ids[ifindex].erase(flow_id);
send_response(ret);
if (send_response(ret) < 0) {
log(log_level::ERROR, "Failed to send response for if_del_flow");
}
}

#endif

0 comments on commit d80834c

Please sign in to comment.