The basic issue that made me notice the race condition is that if_index was 0 when setup_linklocal_addr had failed. As setup_linklocal_addr sets both the address and the if_index, it made sense to me to use if_index as an indicator.