sd-ndisc: make callback takes arbitrary type of message

No functional change. Preparation for supporting Neighbor Advertisement
message.
This commit is contained in:
Yu Watanabe
2024-02-25 11:38:58 +00:00
committed by Luca Boccassi
parent c75d119658
commit 28eef15898
4 changed files with 10 additions and 7 deletions
+2 -2
View File
@@ -31,7 +31,7 @@ static const char * const ndisc_event_table[_SD_NDISC_EVENT_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(ndisc_event, sd_ndisc_event_t);
static void ndisc_callback(sd_ndisc *ndisc, sd_ndisc_event_t event, sd_ndisc_router *rt) {
static void ndisc_callback(sd_ndisc *ndisc, sd_ndisc_event_t event, void *message) {
assert(ndisc);
assert(event >= 0 && event < _SD_NDISC_EVENT_MAX);
@@ -39,7 +39,7 @@ static void ndisc_callback(sd_ndisc *ndisc, sd_ndisc_event_t event, sd_ndisc_rou
return (void) log_ndisc(ndisc, "Received '%s' event.", ndisc_event_to_string(event));
log_ndisc(ndisc, "Invoking callback for '%s' event.", ndisc_event_to_string(event));
ndisc->callback(ndisc, event, rt, ndisc->userdata);
ndisc->callback(ndisc, event, message, ndisc->userdata);
}
int sd_ndisc_is_running(sd_ndisc *nd) {
+3 -1
View File
@@ -202,7 +202,7 @@ static int send_ra(uint8_t flags) {
return 0;
}
static void test_callback(sd_ndisc *nd, sd_ndisc_event_t event, sd_ndisc_router *rt, void *userdata) {
static void test_callback(sd_ndisc *nd, sd_ndisc_event_t event, void *message, void *userdata) {
sd_event *e = userdata;
static unsigned idx = 0;
uint64_t flags_array[] = {
@@ -219,6 +219,8 @@ static void test_callback(sd_ndisc *nd, sd_ndisc_event_t event, sd_ndisc_router
if (event != SD_NDISC_EVENT_ROUTER)
return;
sd_ndisc_router *rt = ASSERT_PTR(message);
router_dump(rt);
assert_se(sd_ndisc_router_get_flags(rt, &flags) >= 0);
+4 -3
View File
@@ -1735,7 +1735,7 @@ static int ndisc_router_handler(Link *link, sd_ndisc_router *rt) {
return 0;
}
static void ndisc_handler(sd_ndisc *nd, sd_ndisc_event_t event, sd_ndisc_router *rt, void *userdata) {
static void ndisc_handler(sd_ndisc *nd, sd_ndisc_event_t event, void *message, void *userdata) {
Link *link = ASSERT_PTR(userdata);
int r;
@@ -1745,7 +1745,7 @@ static void ndisc_handler(sd_ndisc *nd, sd_ndisc_event_t event, sd_ndisc_router
switch (event) {
case SD_NDISC_EVENT_ROUTER:
r = ndisc_router_handler(link, rt);
r = ndisc_router_handler(link, ASSERT_PTR(message));
if (r < 0 && r != -EBADMSG) {
link_enter_failed(link);
return;
@@ -1759,8 +1759,9 @@ static void ndisc_handler(sd_ndisc *nd, sd_ndisc_event_t event, sd_ndisc_router
link_check_ready(link);
}
break;
default:
assert_not_reached();
log_link_debug(link, "Received unsupported NDisc event, ignoring.");
}
}
+1 -1
View File
@@ -43,7 +43,7 @@ __extension__ typedef enum sd_ndisc_event_t {
_SD_ENUM_FORCE_S64(NDISC_EVENT)
} sd_ndisc_event_t;
typedef void (*sd_ndisc_callback_t)(sd_ndisc *nd, sd_ndisc_event_t event, sd_ndisc_router *rt, void *userdata);
typedef void (*sd_ndisc_callback_t)(sd_ndisc *nd, sd_ndisc_event_t event, void *message, void *userdata);
int sd_ndisc_new(sd_ndisc **ret);
sd_ndisc *sd_ndisc_ref(sd_ndisc *nd);