iked: introduce and use print_addr()
authortb <tb@openbsd.org>
Tue, 13 Jun 2023 12:34:12 +0000 (12:34 +0000)
committertb <tb@openbsd.org>
Tue, 13 Jun 2023 12:34:12 +0000 (12:34 +0000)
The vast majority of print_host() callers cast the first argument
(usually a sockaddr_storage *) to (struct sockaddr *) and pass both
a NULL buffer and 0 length. Cast and useless arguments lead to
awkward line wrapping in many places. Clean this up by introducing a
helper. Make this helper take a void pointer, so all casts go away.

ok claudio kn tobhe

sbin/iked/iked.h
sbin/iked/ikev2.c
sbin/iked/ikev2_msg.c
sbin/iked/pfkey.c
sbin/iked/policy.c
sbin/iked/print.c
sbin/iked/util.c
sbin/iked/vroute.c

index 31734b5..f429d55 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: iked.h,v 1.215 2023/06/12 09:02:31 claudio Exp $      */
+/*     $OpenBSD: iked.h,v 1.216 2023/06/13 12:34:12 tb Exp $   */
 
 /*
  * Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de>
@@ -1252,6 +1252,8 @@ uint32_t
         prefixlen2mask(uint8_t);
 const char *
         print_host(struct sockaddr *, char *, size_t);
+const char *
+        print_addr(void *);
 char   *get_string(uint8_t *, size_t);
 const char *
         print_proto(uint8_t);
index dc641fa..ab3f747 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ikev2.c,v 1.369 2023/06/13 08:45:41 claudio Exp $     */
+/*     $OpenBSD: ikev2.c,v 1.370 2023/06/13 12:34:12 tb Exp $  */
 
 /*
  * Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de>
@@ -669,8 +669,8 @@ ikev2_recv(struct iked *env, struct iked_message *msg)
            print_map(hdr->ike_exchange, ikev2_exchange_map),
            msg->msg_response ? "res" : "req",
            msg->msg_msgid,
-           print_host((struct sockaddr *)&msg->msg_peer, NULL, 0),
-           print_host((struct sockaddr *)&msg->msg_local, NULL, 0),
+           print_addr(&msg->msg_peer),
+           print_addr(&msg->msg_local),
            ibuf_length(msg->msg_data),
            msg->msg_policy->pol_name);
        log_debug("%s: ispi %s rspi %s", __func__,
@@ -783,8 +783,7 @@ ikev2_recv(struct iked *env, struct iked_message *msg)
        sa->sa_fd = msg->msg_fd;
 
        log_debug("%s: updated SA to peer %s local %s", __func__,
-           print_host((struct sockaddr *)&sa->sa_peer.addr, NULL, 0),
-           print_host((struct sockaddr *)&sa->sa_local.addr, NULL, 0));
+           print_addr(&sa->sa_peer.addr), print_addr(&sa->sa_local.addr));
 
 done:
        if (initiator)
@@ -1101,16 +1100,13 @@ ikev2_ike_auth_recv(struct iked *env, struct iked_sa *sa,
        if (sa->sa_cp == IKEV2_CP_REPLY) {
                if (sa->sa_cp_addr)
                        log_info("%s: obtained lease: %s", SPI_SA(sa, __func__),
-                           print_host((struct sockaddr *)&sa->sa_cp_addr->addr,
-                           NULL, 0));
+                           print_addr(&sa->sa_cp_addr->addr));
                if (sa->sa_cp_addr6)
                        log_info("%s: obtained lease: %s", SPI_SA(sa, __func__),
-                           print_host((struct sockaddr *)&sa->sa_cp_addr6->addr,
-                           NULL, 0));
+                           print_addr(&sa->sa_cp_addr6->addr));
                if (sa->sa_cp_dns)
                        log_info("%s: obtained DNS: %s", SPI_SA(sa, __func__),
-                           print_host((struct sockaddr *)&sa->sa_cp_dns->addr,
-                           NULL, 0));
+                           print_addr(&sa->sa_cp_dns->addr));
        }
 
        return ikev2_ike_auth(env, sa);
@@ -1296,8 +1292,7 @@ ikev2_enable_natt(struct iked *env, struct iked_sa *sa,
 
        log_debug("%s: detected NAT, enabling UDP encapsulation,"
            " updated SA to peer %s local %s", __func__,
-           print_host((struct sockaddr *)&sa->sa_peer.addr, NULL, 0),
-           print_host((struct sockaddr *)&sa->sa_local.addr, NULL, 0));
+           print_addr(&sa->sa_peer.addr), print_addr(&sa->sa_local.addr));
 }
 
 void
@@ -1318,9 +1313,7 @@ ikev2_init_ike_sa(struct iked *env, void *arg)
 
                if (ikev2_init_ike_sa_peer(env, pol, &pol->pol_peer, NULL))
                        log_debug("%s: failed to initiate with peer %s",
-                           __func__,
-                           print_host((struct sockaddr *)&pol->pol_peer.addr,
-                           NULL, 0));
+                           __func__, print_addr(&pol->pol_peer.addr));
        }
 
        timer_set(env, &env->sc_inittmr, ikev2_init_ike_sa, NULL);
@@ -2326,7 +2319,7 @@ ikev2_nat_detection(struct iked *env, struct iked_message *msg,
                    frompeer ? "peer" : "local",
                    print_spi(betoh64(ispi), 8),
                    print_spi(betoh64(rspi), 8),
-                   print_host(src, NULL, 0));
+                   print_addr(src));
                ss = src;
                break;
        case IKEV2_N_NAT_DETECTION_DESTINATION_IP:
@@ -2334,7 +2327,7 @@ ikev2_nat_detection(struct iked *env, struct iked_message *msg,
                    frompeer ? "peer" : "local",
                    print_spi(betoh64(ispi), 8),
                    print_spi(betoh64(rspi), 8),
-                   print_host(dst, NULL, 0));
+                   print_addr(dst));
                ss = dst;
                break;
        default:
@@ -5225,12 +5218,12 @@ ikev2_ike_sa_keepalive(struct iked *env, void *arg)
            (struct sockaddr *)&sa->sa_local.addr, sa->sa_local.addr.ss_len)
            == -1)
                log_warn("%s: sendtofrom: peer %s local %s", __func__,
-                   print_host((struct sockaddr *)&sa->sa_peer.addr, NULL, 0),
-                   print_host((struct sockaddr *)&sa->sa_local.addr, NULL, 0));
+                   print_addr(&sa->sa_peer.addr),
+                   print_addr(&sa->sa_local.addr));
        else
                log_debug("%s: peer %s local %s", __func__,
-                   print_host((struct sockaddr *)&sa->sa_peer.addr, NULL, 0),
-                   print_host((struct sockaddr *)&sa->sa_local.addr, NULL, 0));
+                   print_addr(&sa->sa_peer.addr),
+                   print_addr(&sa->sa_local.addr));
        ikestat_inc(env, ikes_keepalive_sent);
        timer_add(env, &sa->sa_keepalive, IKED_IKE_SA_KEEPALIVE_TIMEOUT);
 }
@@ -6557,18 +6550,15 @@ ikev2_childsa_enable(struct iked *env, struct iked_sa *sa)
                                fputs(", ", flowf);
                        fprintf(flowf, "%s-%s/%d%s%s%s%s%s=%s/%d(%u)%s",
                            print_map(flow->flow_saproto, ikev2_saproto_map),
-                           print_host((struct sockaddr *)&flow->flow_src.addr,
-                           NULL, 0),
+                           print_addr(&flow->flow_src.addr),
                            flow->flow_src.addr_mask,
                            flow->flow_prenat.addr_af != 0 ? "[": "",
                            flow->flow_prenat.addr_af != 0 ?
-                           print_host((struct sockaddr *)
-                           &flow->flow_prenat.addr, NULL, 0) : "",
+                           print_addr(&flow->flow_prenat.addr) : "",
                            flow->flow_prenat.addr_af != 0 ? "/" : "",
                            flow->flow_prenat.addr_af != 0 ? prenat_mask : "",
                            flow->flow_prenat.addr_af != 0 ? "]": "",
-                           print_host((struct sockaddr *)&flow->flow_dst.addr,
-                           NULL, 0),
+                           print_addr(&flow->flow_dst.addr),
                            flow->flow_dst.addr_mask,
                            flow->flow_ipproto,
                            reload ? "-R" : "");
@@ -6580,8 +6570,7 @@ ikev2_childsa_enable(struct iked *env, struct iked_sa *sa)
                memcpy(&sa->sa_peer_loaded, &sa->sa_peer,
                    sizeof(sa->sa_peer_loaded));
                log_debug("%s: remember SA peer %s", __func__,
-                   print_host((struct sockaddr *)&sa->sa_peer_loaded.addr,
-                   NULL, 0));
+                   print_addr(&sa->sa_peer_loaded.addr));
        }
 
        fflush(spif);
@@ -7129,8 +7118,7 @@ ikev2_cp_setaddr_pool(struct iked *env, struct iked_sa *sa,
                        log_info(
                            "%s: giving up assigned address %s to IKESA %s",
                            SPI_SA(osa, __func__),
-                           print_host((struct sockaddr *)
-                           &sa->sa_addrpool->addr, NULL, 0),
+                           print_addr(&sa->sa_addrpool->addr),
                            print_spi(sa->sa_hdr.sh_ispi, 8));
                }
                if (sa->sa_addrpool6) {
@@ -7138,8 +7126,7 @@ ikev2_cp_setaddr_pool(struct iked *env, struct iked_sa *sa,
                        log_info(
                            "%s: giving up assigned v6 address %s to IKESA %s",
                            SPI_SA(osa, __func__),
-                           print_host((struct sockaddr *)
-                           &sa->sa_addrpool6->addr, NULL, 0),
+                           print_addr(&sa->sa_addrpool6->addr),
                            print_spi(sa->sa_hdr.sh_ispi, 8));
                }
                if (family == AF_INET && sa->sa_addrpool != NULL)
@@ -7268,7 +7255,7 @@ ikev2_cp_setaddr_pool(struct iked *env, struct iked_sa *sa,
        if (ikev2_print_id(IKESA_DSTID(sa), idstr, sizeof(idstr)) == -1)
                bzero(idstr, sizeof(idstr));
        log_info("%sassigned address %s to %s%s", SPI_SA(sa, NULL),
-           print_host((struct sockaddr *)&addr.addr, NULL, 0),
+           print_addr(&addr.addr),
            idstr, requested ? " (requested by peer)" : "");
        return (0);
 }
@@ -7374,8 +7361,8 @@ ikev2_update_sa_addresses(struct iked *env, struct iked_sa *sa)
                return -1;
 
        log_info("%s: old %s new %s", SPI_SA(sa, __func__),
-           print_host((struct sockaddr *)&sa->sa_peer_loaded.addr, NULL, 0),
-           print_host((struct sockaddr *)&sa->sa_peer.addr, NULL, 0));
+           print_addr(&sa->sa_peer_loaded.addr),
+           print_addr(&sa->sa_peer.addr));
 
        TAILQ_FOREACH(csa, &sa->sa_childsas, csa_entry) {
                if (!csa->csa_loaded)
@@ -7449,11 +7436,10 @@ ikev2_info_sa(struct iked *env, int dolog, const char *msg, struct iked_sa *sa)
            msg, sa,
            print_spi(sa->sa_hdr.sh_rspi, 8),
            print_spi(sa->sa_hdr.sh_ispi, 8),
-           print_host((struct sockaddr *)&sa->sa_local.addr, NULL, 0),
-           print_host((struct sockaddr *)&sa->sa_peer.addr, NULL, 0),
+           print_addr(&sa->sa_local.addr),
+           print_addr(&sa->sa_peer.addr),
            idstr,
-           sa->sa_addrpool ?
-           print_host((struct sockaddr *)&sa->sa_addrpool->addr, NULL, 0) : "",
+           sa->sa_addrpool ? print_addr(&sa->sa_addrpool->addr) : "",
            print_map(sa->sa_state, ikev2_state_map),
            sa->sa_hdr.sh_initiator ? 'i' : 'r',
            sa->sa_natt ? " natt" : "",
@@ -7484,8 +7470,8 @@ ikev2_info_csa(struct iked *env, int dolog, const char *msg, struct iked_childsa
            print_map(csa->csa_saproto, ikev2_saproto_map),
            print_spi(csa->csa_spi.spi, csa->csa_spi.spi_size),
            csa->csa_dir == IPSP_DIRECTION_IN ? "in" : "out",
-           print_host((struct sockaddr *)&csa->csa_local->addr, NULL, 0),
-           print_host((struct sockaddr *)&csa->csa_peer->addr, NULL, 0),
+           print_addr(&csa->csa_local->addr),
+           print_addr(&csa->csa_peer->addr),
            csa->csa_loaded ? "L" : "",
            csa->csa_rekey ? "R" : "",
            csa->csa_allocated ? "A" : "",
@@ -7524,13 +7510,13 @@ ikev2_info_flow(struct iked *env, int dolog, const char *msg, struct iked_flow *
            "%s: %p %s %s %s/%d -> %s/%d %s%s%s%s%s[%u]@%d (%s) @%p\n", msg, flow,
            print_map(flow->flow_saproto, ikev2_saproto_map),
            flow->flow_dir == IPSP_DIRECTION_IN ? "in" : "out",
-           print_host((struct sockaddr *)&flow->flow_src.addr, NULL, 0),
+           print_addr(&flow->flow_src.addr),
            flow->flow_src.addr_mask,
-           print_host((struct sockaddr *)&flow->flow_dst.addr, NULL, 0),
+           print_addr(&flow->flow_dst.addr),
            flow->flow_dst.addr_mask,
            flow->flow_prenat.addr_af != 0 ? "[": "",
-           flow->flow_prenat.addr_af != 0 ? print_host((struct sockaddr *)
-           &flow->flow_prenat.addr, NULL, 0) : "",
+           flow->flow_prenat.addr_af != 0 ?
+           print_addr(&flow->flow_prenat.addr) : "",
            flow->flow_prenat.addr_af != 0 ? "/" : "",
            flow->flow_prenat.addr_af != 0 ? prenat_mask : "",
            flow->flow_prenat.addr_af != 0 ? "] ": "",
@@ -7616,14 +7602,12 @@ ikev2_log_established(struct iked_sa *sa)
        log_info(
            "%sestablished peer %s[%s] local %s[%s]%s%s%s%s policy '%s'%s"
            " (enc %s%s%s group %s prf %s)", SPI_SA(sa, NULL),
-           print_host((struct sockaddr *)&sa->sa_peer.addr, NULL, 0), dstid,
-           print_host((struct sockaddr *)&sa->sa_local.addr, NULL, 0), srcid,
+           print_addr(&sa->sa_peer.addr), dstid,
+           print_addr(&sa->sa_local.addr), srcid,
            sa->sa_addrpool ? " assigned " : "",
-           sa->sa_addrpool ?
-           print_host((struct sockaddr *)&sa->sa_addrpool->addr, NULL, 0) : "",
+           sa->sa_addrpool ? print_addr(&sa->sa_addrpool->addr) : "",
            sa->sa_addrpool6 ? " assigned " : "",
-           sa->sa_addrpool6 ?
-           print_host((struct sockaddr *)&sa->sa_addrpool6->addr, NULL, 0) : "",
+           sa->sa_addrpool6 ? print_addr(&sa->sa_addrpool6->addr) : "",
            sa->sa_policy ? sa->sa_policy->pol_name : "",
            sa->sa_hdr.sh_initiator ? " as initiator" : " as responder",
            print_xf(sa->sa_encr->encr_id, cipher_keylength(sa->sa_encr) -
index 47803e9..338ef13 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ikev2_msg.c,v 1.94 2023/06/06 13:27:49 claudio Exp $  */
+/*     $OpenBSD: ikev2_msg.c,v 1.95 2023/06/13 12:34:12 tb Exp $       */
 
 /*
  * Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de>
@@ -285,8 +285,8 @@ ikev2_msg_send(struct iked *env, struct iked_message *msg)
            print_map(exchange, ikev2_exchange_map),
            (flags & IKEV2_FLAG_RESPONSE) ? "res" : "req",
            betoh32(hdr->ike_msgid),
-           print_host((struct sockaddr *)&msg->msg_peer, NULL, 0),
-           print_host((struct sockaddr *)&msg->msg_local, NULL, 0),
+           print_addr(&msg->msg_peer),
+           print_addr(&msg->msg_local),
            ibuf_length(buf), isnatt ? ", NAT-T" : "");
 
        if (isnatt) {
@@ -1290,8 +1290,8 @@ ikev2_msg_retransmit_response(struct iked *env, struct iked_sa *sa,
                    SPI_SA(sa, NULL),
                    print_map(exchange, ikev2_exchange_map),
                    m->msg_msgid,
-                   print_host((struct sockaddr *)&m->msg_local, NULL, 0),
-                   print_host((struct sockaddr *)&m->msg_peer, NULL, 0));
+                   print_addr(&m->msg_local),
+                   print_addr(&m->msg_peer));
        }
 
        timer_add(env, &mr->mrt_timer, IKED_RESPONSE_TIMEOUT);
@@ -1333,8 +1333,8 @@ ikev2_msg_retransmit_timeout(struct iked *env, void *arg)
                            "local %s", SPI_SA(sa, NULL), mr->mrt_tries + 1,
                            print_map(msg->msg_exchange, ikev2_exchange_map),
                            msg->msg_msgid,
-                           print_host((struct sockaddr *)&msg->msg_peer, NULL, 0),
-                           print_host((struct sockaddr *)&msg->msg_local, NULL, 0));
+                           print_addr(&msg->msg_peer),
+                           print_addr(&msg->msg_local));
                }
                /* Exponential timeout */
                timer_add(env, &mr->mrt_timer,
index 262dc76..eaebe53 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: pfkey.c,v 1.81 2022/07/22 15:33:53 tobhe Exp $        */
+/*     $OpenBSD: pfkey.c,v 1.82 2023/06/13 12:34:12 tb Exp $   */
 
 /*
  * Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -1853,7 +1853,7 @@ pfkey_process(struct iked *env, struct pfkey_message *pm)
                flow.flow_peer = &peer;
 
                log_debug("%s: acquire request (peer %s)", __func__,
-                   print_host(speer, NULL, 0));
+                   print_addr(speer));
 
                /* get the matching flow */
                bzero(&smsg, sizeof(smsg));
@@ -1992,9 +1992,9 @@ pfkey_process(struct iked *env, struct pfkey_message *pm)
 
                log_debug("%s: flow %s from %s/%s to %s/%s via %s", __func__,
                    flow.flow_dir == IPSP_DIRECTION_IN ? "in" : "out",
-                   print_host(ssrc, NULL, 0), print_host(smask, NULL, 0),
-                   print_host(sdst, NULL, 0), print_host(dmask, NULL, 0),
-                   print_host(speer, NULL, 0));
+                   print_addr(ssrc), print_addr(smask),
+                   print_addr(sdst), print_addr(dmask),
+                   print_addr(speer));
 
                ret = ikev2_child_sa_acquire(env, &flow);
 
index be34ed9..0048b4a 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: policy.c,v 1.94 2023/05/23 13:12:19 claudio Exp $     */
+/*     $OpenBSD: policy.c,v 1.95 2023/06/13 12:34:12 tb Exp $  */
 
 /*
  * Copyright (c) 2020-2021 Tobias Heider <tobhe@openbsd.org>
@@ -398,10 +398,8 @@ sa_state(struct iked *env, struct iked_sa *sa, int state)
                case IKEV2_STATE_CLOSED:
                        log_debug("%s: %s -> %s from %s to %s policy '%s'",
                            SPI_SA(sa, __func__), a, b,
-                           print_host((struct sockaddr *)&sa->sa_peer.addr,
-                           NULL, 0),
-                           print_host((struct sockaddr *)&sa->sa_local.addr,
-                           NULL, 0),
+                           print_addr(&sa->sa_peer.addr),
+                           print_addr(&sa->sa_local.addr),
                            sa->sa_policy ? sa->sa_policy->pol_name :
                            "<unknown>");
                        break;
index 607e933..5444f95 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: print.c,v 1.3 2021/10/26 17:31:22 tobhe Exp $ */
+/*     $OpenBSD: print.c,v 1.4 2023/06/13 12:34:12 tb Exp $    */
 
 /*
  * Copyright (c) 2019-2021 Tobias Heider <tobias.heider@stusta.de>
@@ -112,9 +112,7 @@ print_policy(struct iked_policy *pol)
                print_verbose(" rdomain %d", pol->pol_rdomain);
 
        RB_FOREACH(flow, iked_flows, &pol->pol_flows) {
-               print_verbose(" from %s",
-                   print_host((struct sockaddr *)&flow->flow_src.addr, NULL,
-                   0));
+               print_verbose(" from %s", print_addr(&flow->flow_src.addr));
                if (flow->flow_src.addr_af != AF_UNSPEC &&
                    flow->flow_src.addr_net)
                        print_verbose("/%d", flow->flow_src.addr_mask);
@@ -122,9 +120,7 @@ print_policy(struct iked_policy *pol)
                        print_verbose(" port %d",
                            ntohs(flow->flow_src.addr_port));
 
-               print_verbose(" to %s",
-                   print_host((struct sockaddr *)&flow->flow_dst.addr, NULL,
-                   0));
+               print_verbose(" to %s", print_addr(&flow->flow_dst.addr));
                if (flow->flow_dst.addr_af != AF_UNSPEC &&
                    flow->flow_dst.addr_net)
                        print_verbose("/%d", flow->flow_dst.addr_mask);
@@ -134,16 +130,12 @@ print_policy(struct iked_policy *pol)
        }
 
        if ((pol->pol_flags & IKED_POLICY_DEFAULT) == 0) {
-               print_verbose(" local %s",
-                   print_host((struct sockaddr *)&pol->pol_local.addr, NULL,
-                   0));
+               print_verbose(" local %s", print_addr(&pol->pol_local.addr));
                if (pol->pol_local.addr.ss_family != AF_UNSPEC &&
                    pol->pol_local.addr_net)
                        print_verbose("/%d", pol->pol_local.addr_mask);
 
-               print_verbose(" peer %s",
-                   print_host((struct sockaddr *)&pol->pol_peer.addr, NULL,
-                   0));
+               print_verbose(" peer %s", print_addr(&pol->pol_peer.addr));
                if (pol->pol_peer.addr.ss_family != AF_UNSPEC &&
                    pol->pol_peer.addr_net)
                        print_verbose("/%d", pol->pol_peer.addr_mask);
@@ -235,8 +227,7 @@ print_policy(struct iked_policy *pol)
                cfg = &pol->pol_cfg[i];
                print_verbose(" config %s %s", print_xf(cfg->cfg_type,
                    cfg->cfg.address.addr_af, cpxfs),
-                   print_host((struct sockaddr *)&cfg->cfg.address.addr, NULL,
-                   0));
+                   print_addr(&cfg->cfg.address.addr));
        }
 
        if (pol->pol_iface != 0 && if_indextoname(pol->pol_iface, iface) != NULL)
index 304f590..9f827b1 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: util.c,v 1.40 2020/08/15 11:31:17 tobhe Exp $ */
+/*     $OpenBSD: util.c,v 1.41 2023/06/13 12:34:12 tb Exp $    */
 
 /*
  * Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -669,6 +669,12 @@ print_host(struct sockaddr *sa, char *buf, size_t len)
        return (buf);
 }
 
+const char *
+print_addr(void *addr)
+{
+       return print_host(addr, NULL, 0);
+}
+
 char *
 get_string(uint8_t *ptr, size_t len)
 {
index 7f900e7..5ef892d 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: vroute.c,v 1.18 2023/02/10 19:51:08 tobhe Exp $       */
+/*     $OpenBSD: vroute.c,v 1.19 2023/06/13 12:34:12 tb Exp $  */
 
 /*
  * Copyright (c) 2021 Tobias Heider <tobhe@openbsd.org>
@@ -840,9 +840,9 @@ vroute_doroute(struct iked *env, int flags, int addrs, int rdomain, uint8_t type
            flags & RTF_HOST ? "H" : "",
            flags & RTF_GATEWAY ? "G" : "",
            addrs,
-           addrs & RTA_DST ? print_host(dest, NULL, 0) : "<>",
-           addrs & RTA_NETMASK ? print_host(mask, NULL, 0) : "<>",
-           addrs & RTA_GATEWAY ? print_host(addr, NULL, 0) : "<>");
+           addrs & RTA_DST ? print_addr(dest) : "<>",
+           addrs & RTA_NETMASK ? print_addr(mask) : "<>",
+           addrs & RTA_GATEWAY ? print_addr(addr) : "<>");
 
        if (writev(ivr->ivr_rtsock, iov, iovcnt) == -1) {
                if ((type == RTM_ADD && errno != EEXIST) ||
@@ -933,9 +933,7 @@ vroute_doaddr(struct iked *env, char *ifname, struct sockaddr *addr,
                        memcpy(&req.ifra_mask, mask, sizeof(req.ifra_addr));
 
                log_debug("%s: %s inet %s netmask %s", __func__,
-                   add ? "add" : "del",
-                   print_host((struct sockaddr *)addr, NULL, 0),
-                   print_host((struct sockaddr *)mask, NULL, 0));
+                   add ? "add" : "del", print_addr(addr), print_addr(mask));
 
                ioreq = add ? SIOCAIFADDR : SIOCDIFADDR;
                if (ioctl(ivr->ivr_iosock, ioreq, &req) == -1) {
@@ -955,9 +953,7 @@ vroute_doaddr(struct iked *env, char *ifname, struct sockaddr *addr,
                            sizeof(req6.ifra_prefixmask));
 
                log_debug("%s: %s inet6 %s netmask %s", __func__,
-                   add ? "add" : "del",
-                   print_host((struct sockaddr *)addr, NULL, 0),
-                   print_host((struct sockaddr *)mask, NULL, 0));
+                   add ? "add" : "del", print_addr(addr), print_addr(mask));
 
                ioreq = add ? SIOCAIFADDR_IN6 : SIOCDIFADDR_IN6;
                if (ioctl(ivr->ivr_iosock6, ioreq, &req6) == -1) {