summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluwenpeng <[email protected]>2024-04-22 14:23:45 +0800
committerluwenpeng <[email protected]>2024-04-22 14:23:50 +0800
commitdd32f0f231ae1e003c21c611731ff78b7b041c1a (patch)
tree0efa4fa73762d35a7aa8db58bfceff7ba812985a
parentbb7d7410c99704e2613d5902911b33676f14334b (diff)
Enhancement: Improve error handling in stellar's packet API by checking return values of metadata functions and adding descriptive error logging
-rw-r--r--deps/timeout/timeout.h9
-rw-r--r--src/ip_reassembly/test/gtest_utils.h4
-rw-r--r--src/packet/packet_utils.cpp62
3 files changed, 61 insertions, 14 deletions
diff --git a/deps/timeout/timeout.h b/deps/timeout/timeout.h
index 2c7fccb..40eaafb 100644
--- a/deps/timeout/timeout.h
+++ b/deps/timeout/timeout.h
@@ -26,6 +26,11 @@
#ifndef TIMEOUT_H
#define TIMEOUT_H
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
#include <stdbool.h> /* bool */
#include <stdio.h> /* FILE */
@@ -259,4 +264,8 @@ TIMEOUT_PUBLIC struct timeout *timeouts_next(struct timeouts *, struct timeouts_
#define timeouts_addf(T, to, timeout) \
timeouts_add((T), (to), timeouts_f2i((T), (timeout)))
+#ifdef __cplusplus
+}
+#endif
+
#endif /* TIMEOUT_H */
diff --git a/src/ip_reassembly/test/gtest_utils.h b/src/ip_reassembly/test/gtest_utils.h
index e037a29..0e652f2 100644
--- a/src/ip_reassembly/test/gtest_utils.h
+++ b/src/ip_reassembly/test/gtest_utils.h
@@ -1,13 +1,13 @@
#ifndef _GTEST_UTILS_H
#define _GTEST_UTILS_H
+#include <gtest/gtest.h>
+
#ifdef __cplusplus
extern "C"
{
#endif
-#include <gtest/gtest.h>
-
#include "udp_utils.h"
#include "tcp_utils.h"
#include "ipv4_utils.h"
diff --git a/src/packet/packet_utils.cpp b/src/packet/packet_utils.cpp
index ad905e1..2653437 100644
--- a/src/packet/packet_utils.cpp
+++ b/src/packet/packet_utils.cpp
@@ -176,7 +176,10 @@ void packet_set_direction(struct packet *pkt, int dir)
{
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
assert(mbuff != NULL);
- marsio_buff_set_metadata(mbuff, MR_BUFF_DIR, &dir, sizeof(dir));
+ if (marsio_buff_set_metadata(mbuff, MR_BUFF_DIR, &dir, sizeof(dir)) != 0)
+ {
+ PACKET_LOG_ERROR("failed to set direction");
+ }
}
}
@@ -188,7 +191,10 @@ int packet_get_direction(const struct packet *pkt)
{
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
assert(mbuff != NULL);
- marsio_buff_get_metadata(mbuff, MR_BUFF_DIR, &direction, sizeof(direction));
+ if (marsio_buff_get_metadata(mbuff, MR_BUFF_DIR, &direction, sizeof(direction)) <= 0)
+ {
+ PACKET_LOG_ERROR("failed to get direction");
+ }
}
return direction;
@@ -200,7 +206,10 @@ void packet_set_session_id(struct packet *pkt, uint64_t sess_id)
{
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
assert(mbuff != NULL);
- marsio_buff_set_metadata(mbuff, MR_BUFF_SESSION_ID, &sess_id, sizeof(sess_id));
+ if (marsio_buff_set_metadata(mbuff, MR_BUFF_SESSION_ID, &sess_id, sizeof(sess_id)) != 0)
+ {
+ PACKET_LOG_ERROR("failed to set session id");
+ }
}
}
@@ -211,7 +220,10 @@ uint64_t packet_get_session_id(const struct packet *pkt)
{
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
assert(mbuff != NULL);
- marsio_buff_get_metadata(mbuff, MR_BUFF_SESSION_ID, &sess_id, sizeof(sess_id));
+ if (marsio_buff_get_metadata(mbuff, MR_BUFF_SESSION_ID, &sess_id, sizeof(sess_id)) <= 0)
+ {
+ PACKET_LOG_ERROR("failed to get session id");
+ }
}
return sess_id;
@@ -223,8 +235,13 @@ void packet_set_domain(struct packet *pkt, uint64_t domain)
{
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
assert(mbuff != NULL);
- // TODO
- // marsio_buff_set_metadata(mbuff, MR_BUFF_DOMAIN, &domain, sizeof(domain));
+// TODO
+#if 0
+ if (marsio_buff_set_metadata(mbuff, MR_BUFF_DOMAIN, &domain, sizeof(domain)) != 0)
+ {
+ PACKET_LOG_ERROR("failed to set domain");
+ }
+#endif
}
}
@@ -235,8 +252,13 @@ uint64_t packet_get_domain(const struct packet *pkt)
{
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
assert(mbuff != NULL);
- // TODO
- // marsio_buff_get_metadata(mbuff, MR_BUFF_DOMAIN, &domain, sizeof(domain));
+// TODO
+#if 0
+ if (marsio_buff_get_metadata(mbuff, MR_BUFF_DOMAIN, &domain, sizeof(domain)) <= 0)
+ {
+ PACKET_LOG_ERROR("failed to get domain");
+ }
+#endif
}
return domain;
@@ -248,7 +270,10 @@ void packet_set_route_ctx(struct packet *pkt, const char *route, int len)
{
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
assert(mbuff != NULL);
- marsio_buff_set_metadata(mbuff, MR_BUFF_ROUTE_CTX, (void *)route, len);
+ if (marsio_buff_set_metadata(mbuff, MR_BUFF_ROUTE_CTX, (void *)route, len) != 0)
+ {
+ PACKET_LOG_ERROR("failed to set route ctx");
+ }
}
}
@@ -261,6 +286,10 @@ int packet_get_route_ctx(const struct packet *pkt, char *buff, int size)
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
assert(mbuff != NULL);
len = marsio_buff_get_metadata(mbuff, MR_BUFF_ROUTE_CTX, buff, size);
+ if (len <= 0)
+ {
+ PACKET_LOG_ERROR("failed to get route ctx");
+ }
}
return len;
@@ -272,7 +301,10 @@ void packet_set_sid_list(struct packet *pkt, uint16_t *sid, int num)
{
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
assert(mbuff != NULL);
- marsio_buff_set_sid_list(mbuff, sid, num);
+ if (marsio_buff_set_sid_list(mbuff, sid, num) != 0)
+ {
+ PACKET_LOG_ERROR("failed to set sid list");
+ }
}
}
@@ -295,7 +327,10 @@ void packet_prepend_sid_list(struct packet *pkt, uint16_t *sid, int num)
{
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
assert(mbuff != NULL);
- marsio_buff_prepend_sid_list(mbuff, sid, num);
+ if (marsio_buff_prepend_sid_list(mbuff, sid, num) != 0)
+ {
+ PACKET_LOG_ERROR("failed to prepend sid list");
+ }
}
}
@@ -305,6 +340,9 @@ void packet_append_sid_list(struct packet *pkt, uint16_t *sid, int num)
{
marsio_buff_t *mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
assert(mbuff != NULL);
- marsio_buff_append_sid_list(mbuff, sid, num);
+ if (marsio_buff_append_sid_list(mbuff, sid, num) != 0)
+ {
+ PACKET_LOG_ERROR("failed to append sid list");
+ }
}
}