iv_thread: Rewrite.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>