jpirko / libndp

Neighbor Discovery library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

There may be mistake programming when setting target address for NS and NA

guo1017138 opened this issue · comments

The current logic will be:
if this is NA, the ns message target will be set. If this NS, the na message target will be set. Even the result is correct, that's because they share the similar data structure. But I assume there are some mistake here. Can the owner confirm? Here is a change example.

$ git diff
diff --git a/libndp/libndp.c b/libndp/libndp.c
index bec55d4..84cb1d9 100644
--- a/libndp/libndp.c
+++ b/libndp/libndp.c
@@ -713,7 +713,7 @@ void ndp_msg_target_set(struct ndp_msg *msg, struct in6_addr *target)
        enum ndp_msg_type msg_type = ndp_msg_type(msg);
        switch (msg_type) {
                case NDP_MSG_NS:
-                       ((struct ndp_msgna*)&msg->nd_msg)->na->nd_na_target = *target;
+                       ((struct ndp_msgns*)&msg->nd_msg)->ns->nd_ns_target = *target;
                        /*
                         * Neighbor Solicitations are multicast when the node
                         * needs to resolve an address and unicast when the
@@ -727,7 +727,7 @@ void ndp_msg_target_set(struct ndp_msg *msg, struct in6_addr *target)
                        ndp_msg_addrto_adjust_solicit_multi(&msg->addrto, target);
                        break;
                case NDP_MSG_NA:
-                       ((struct ndp_msgns*)&msg->nd_msg)->ns->nd_ns_target = *target;
+                       ((struct ndp_msgna*)&msg->nd_msg)->na->nd_na_target = *target;
                        break;
                default:
                        break;

Fixed by:
commit 23490cb
Author: Hangbin Liu haliu@redhat.com
Date: Mon Sep 2 19:39:36 2019 +0800

libndp: fix nd_msg typo when setting target address