add 'nodad' support to ifc_add_address()

Test: TreeHugger
Bug: 242067762
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2c022f6af45eac7631213801a89aa270709d4a57
This commit is contained in:
Maciej Żenczykowski 2023-06-29 10:52:40 +00:00
parent de4ad68fa7
commit 25ec9c4db1

View file

@ -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);
}
/*