From 25ec9c4db1345e0b338e333f661bd7ffafa36732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Thu, 29 Jun 2023 10:52:40 +0000 Subject: [PATCH] add 'nodad' support to ifc_add_address() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test: TreeHugger Bug: 242067762 Signed-off-by: Maciej Żenczykowski Change-Id: I2c022f6af45eac7631213801a89aa270709d4a57 --- libnetutils/ifc_utils.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c index 5999e39ba..7cca105c2 100644 --- a/libnetutils/ifc_utils.c +++ b/libnetutils/ifc_utils.c @@ -362,14 +362,19 @@ int ifc_act_on_address(int action, const char* name, const char* address, int pr return err->error; } +// Pass bitwise complement of prefix length to disable DAD, ie. use ~64 instead of 64. // Returns zero on success and negative errno on failure. int ifc_add_address(const char *name, const char *address, int prefixlen) { - return ifc_act_on_address(RTM_NEWADDR, name, address, prefixlen, /*nodad*/ false); + bool nodad = (prefixlen < 0); + if (nodad) prefixlen = ~prefixlen; + return ifc_act_on_address(RTM_NEWADDR, name, address, prefixlen, nodad); } // Returns zero on success and negative errno on failure. int ifc_del_address(const char *name, const char * address, int prefixlen) { - return ifc_act_on_address(RTM_DELADDR, name, address, prefixlen, /*nodad*/ false); + bool nodad = (prefixlen < 0); + if (nodad) prefixlen = ~prefixlen; + return ifc_act_on_address(RTM_DELADDR, name, address, prefixlen, nodad); } /*