diff options
author | vangyzen <vangyzen@FreeBSD.org> | 2017-03-17 14:54:10 +0000 |
---|---|---|
committer | Luiz Souza <luiz@netgate.com> | 2017-07-15 11:13:31 -0500 |
commit | 8f9d443add7b88b37079e841ed5ae9ffde397622 (patch) | |
tree | 6eb4781c842fdd1de9fde5aab75873d6f7c00576 | |
parent | 77840faf83cb76da257b9725df642fa331673a5f (diff) | |
download | FreeBSD-src-8f9d443add7b88b37079e841ed5ae9ffde397622.zip FreeBSD-src-8f9d443add7b88b37079e841ed5ae9ffde397622.tar.gz |
MFC r313821 r315277 r315286
Use inet_ntoa_r() instead of inet_ntoa() throughout the kernel.
inet_ntoa() cannot be used safely in a multithreaded environment
because it uses a static local buffer. Instead, use inet_ntoa_r()
with a buffer on the caller's stack, except for KTR messages.
KTR can correctly log the immediate integral values passed to it,
as well as constant strings, but not non-constant strings,
since they might change by the time ktrdump retrieves them.
Therefore, use hex notation in KTR messages.
Sponsored by: Dell EMC
(cherry picked from commit 5ebfb876ead3dd5491730d0a543aba065d39d55d)
-rw-r--r-- | sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c | 10 | ||||
-rw-r--r-- | sys/fs/nfsserver/nfs_nfsdkrpc.c | 10 | ||||
-rw-r--r-- | sys/kern/kern_jail.c | 5 | ||||
-rw-r--r-- | sys/netinet/if_ether.c | 26 | ||||
-rw-r--r-- | sys/netinet/igmp.c | 109 | ||||
-rw-r--r-- | sys/netinet/in.c | 13 | ||||
-rw-r--r-- | sys/netinet/in_mcast.c | 89 | ||||
-rw-r--r-- | sys/netinet/ip_icmp.c | 23 | ||||
-rw-r--r-- | sys/netinet/ip_mroute.c | 39 | ||||
-rw-r--r-- | sys/netinet/ip_options.c | 11 | ||||
-rw-r--r-- | sys/netinet/libalias/alias_local.h | 6 | ||||
-rw-r--r-- | sys/netinet/libalias/alias_nbt.c | 32 | ||||
-rw-r--r-- | sys/netinet/libalias/alias_proxy.c | 4 | ||||
-rw-r--r-- | sys/netinet/libalias/alias_sctp.c | 14 | ||||
-rw-r--r-- | sys/netinet/tcp_hostcache.c | 4 | ||||
-rw-r--r-- | sys/netpfil/ipfw/ip_fw_log.c | 3 |
16 files changed, 222 insertions, 176 deletions
diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c index 9bcc1b0..09c5a6f 100644 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c +++ b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c @@ -1478,9 +1478,9 @@ process_data(struct iwch_ep *ep) */ in_getsockaddr(ep->com.so, (struct sockaddr **)&local); in_getpeeraddr(ep->com.so, (struct sockaddr **)&remote); - CTR3(KTR_IW_CXGB, "%s local %s remote %s", __FUNCTION__, - inet_ntoa(local->sin_addr), - inet_ntoa(remote->sin_addr)); + CTR3(KTR_IW_CXGB, "%s local 0x%08x remote 0x%08x", __FUNCTION__, + ntohl(local->sin_addr.s_addr), + ntohl(remote->sin_addr.s_addr)); ep->com.local_addr = *local; ep->com.remote_addr = *remote; free(local, M_SONAME); @@ -1538,8 +1538,8 @@ process_newconn(struct iw_cm_id *parent_cm_id, struct socket *child_so) in_getsockaddr(child_so, (struct sockaddr **)&local); in_getpeeraddr(child_so, (struct sockaddr **)&remote); - CTR3(KTR_IW_CXGB, "%s remote addr %s port %d", __FUNCTION__, - inet_ntoa(remote->sin_addr), ntohs(remote->sin_port)); + CTR3(KTR_IW_CXGB, "%s remote addr 0x%08x port %d", __FUNCTION__, + ntohl(remote->sin_addr.s_addr), ntohs(remote->sin_port)); child_ep->com.tdev = parent_ep->com.tdev; child_ep->com.local_addr.sin_family = parent_ep->com.local_addr.sin_family; child_ep->com.local_addr.sin_port = parent_ep->com.local_addr.sin_port; diff --git a/sys/fs/nfsserver/nfs_nfsdkrpc.c b/sys/fs/nfsserver/nfs_nfsdkrpc.c index e5ad4ab..75f6a41 100644 --- a/sys/fs/nfsserver/nfs_nfsdkrpc.c +++ b/sys/fs/nfsserver/nfs_nfsdkrpc.c @@ -174,7 +174,11 @@ nfssvc_program(struct svc_req *rqst, SVCXPRT *xprt) if (port >= IPPORT_RESERVED && nd.nd_procnum != NFSPROC_NULL) { #ifdef INET6 - char b6[INET6_ADDRSTRLEN]; + char buf[INET6_ADDRSTRLEN]; +#else + char buf[INET_ADDRSTRLEN]; +#endif +#ifdef INET6 #if defined(KLD_MODULE) /* Do not use ip6_sprintf: the nfs module should work without INET6. */ #define ip6_sprintf(buf, a) \ @@ -189,12 +193,12 @@ nfssvc_program(struct svc_req *rqst, SVCXPRT *xprt) printf("NFS request from unprivileged port (%s:%d)\n", #ifdef INET6 sin->sin_family == AF_INET6 ? - ip6_sprintf(b6, &satosin6(sin)->sin6_addr) : + ip6_sprintf(buf, &satosin6(sin)->sin6_addr) : #if defined(KLD_MODULE) #undef ip6_sprintf #endif #endif - inet_ntoa(sin->sin_addr), port); + inet_ntoa_r(sin->sin_addr, buf), port); svcerr_weakauth(rqst); svc_freereq(rqst); m_freem(nd.nd_mrep); diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c index ebd714f..87824a7 100644 --- a/sys/kern/kern_jail.c +++ b/sys/kern/kern_jail.c @@ -4729,6 +4729,9 @@ db_show_prison(struct prison *pr) int ii; #endif unsigned jsf; +#ifdef INET + char ip4buf[INET_ADDRSTRLEN]; +#endif #ifdef INET6 char ip6buf[INET6_ADDRSTRLEN]; #endif @@ -4780,7 +4783,7 @@ db_show_prison(struct prison *pr) for (ii = 0; ii < pr->pr_ip4s; ii++) db_printf(" %s %s\n", ii == 0 ? "ip4.addr =" : " ", - inet_ntoa(pr->pr_ip4[ii])); + inet_ntoa_r(pr->pr_ip4[ii], ip4buf)); #endif #ifdef INET6 db_printf(" ip6s = %d\n", pr->pr_ip6s); diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c index 9f36c32..d87fd00 100644 --- a/sys/netinet/if_ether.c +++ b/sys/netinet/if_ether.c @@ -442,9 +442,12 @@ arpresolve_full(struct ifnet *ifp, int is_gw, int flags, struct mbuf *m, if (la == NULL && (ifp->if_flags & (IFF_NOARP | IFF_STATICARP)) == 0) { la = lltable_alloc_entry(LLTABLE(ifp), 0, dst); if (la == NULL) { + char addrbuf[INET_ADDRSTRLEN]; + log(LOG_DEBUG, "arpresolve: can't allocate llinfo for %s on %s\n", - inet_ntoa(SIN(dst)->sin_addr), if_name(ifp)); + inet_ntoa_r(SIN(dst)->sin_addr, addrbuf), + if_name(ifp)); m_freem(m); return (EINVAL); } @@ -781,6 +784,7 @@ in_arpinput(struct mbuf *m) size_t linkhdrsize; int lladdr_off; int error; + char addrbuf[INET_ADDRSTRLEN]; sin.sin_len = sizeof(struct sockaddr_in); sin.sin_family = AF_INET; @@ -905,7 +909,7 @@ match: goto drop; /* it's from me, ignore it. */ if (!bcmp(ar_sha(ah), ifp->if_broadcastaddr, ifp->if_addrlen)) { ARP_LOG(LOG_NOTICE, "link address is broadcast for IP address " - "%s!\n", inet_ntoa(isaddr)); + "%s!\n", inet_ntoa_r(isaddr, addrbuf)); goto drop; } @@ -927,7 +931,7 @@ match: myaddr.s_addr != 0) { ARP_LOG(LOG_ERR, "%*D is using my IP address %s on %s!\n", ifp->if_addrlen, (u_char *)ar_sha(ah), ":", - inet_ntoa(isaddr), ifp->if_xname); + inet_ntoa_r(isaddr, addrbuf), ifp->if_xname); itaddr = myaddr; ARPSTAT_INC(dupips); goto reply; @@ -1064,12 +1068,14 @@ reply: if (nh4.nh_ifp != ifp) { ARP_LOG(LOG_INFO, "proxy: ignoring request" " from %s via %s\n", - inet_ntoa(isaddr), ifp->if_xname); + inet_ntoa_r(isaddr, addrbuf), + ifp->if_xname); goto drop; } #ifdef DEBUG_PROXY - printf("arp: proxying for %s\n", inet_ntoa(itaddr)); + printf("arp: proxying for %s\n", + inet_ntoa_r(itaddr, addrbuf)); #endif } } @@ -1079,7 +1085,7 @@ reply: /* RFC 3927 link-local IPv4; always reply by broadcast. */ #ifdef DEBUG_LINKLOCAL printf("arp: sending reply for link-local addr %s\n", - inet_ntoa(itaddr)); + inet_ntoa_r(itaddr, addrbuf)); #endif m->m_flags |= M_BCAST; m->m_flags &= ~M_MCAST; @@ -1140,6 +1146,7 @@ arp_check_update_lle(struct arphdr *ah, struct in_addr isaddr, struct ifnet *ifp uint8_t linkhdr[LLE_MAX_LINKHDR]; size_t linkhdrsize; int lladdr_off; + char addrbuf[INET_ADDRSTRLEN]; LLE_WLOCK_ASSERT(la); @@ -1148,7 +1155,7 @@ arp_check_update_lle(struct arphdr *ah, struct in_addr isaddr, struct ifnet *ifp if (log_arp_wrong_iface) ARP_LOG(LOG_WARNING, "%s is on %s " "but got reply from %*D on %s\n", - inet_ntoa(isaddr), + inet_ntoa_r(isaddr, addrbuf), la->lle_tbl->llt_ifp->if_xname, ifp->if_addrlen, (u_char *)ar_sha(ah), ":", ifp->if_xname); @@ -1165,13 +1172,14 @@ arp_check_update_lle(struct arphdr *ah, struct in_addr isaddr, struct ifnet *ifp "permanent entry for %s on %s\n", ifp->if_addrlen, (u_char *)ar_sha(ah), ":", - inet_ntoa(isaddr), ifp->if_xname); + inet_ntoa_r(isaddr, addrbuf), + ifp->if_xname); return; } if (log_arp_movements) { ARP_LOG(LOG_INFO, "%s moved from %*D " "to %*D on %s\n", - inet_ntoa(isaddr), + inet_ntoa_r(isaddr, addrbuf), ifp->if_addrlen, (u_char *)&la->ll_addr, ":", ifp->if_addrlen, (u_char *)ar_sha(ah), ":", diff --git a/sys/netinet/igmp.c b/sys/netinet/igmp.c index 5dba31d..e12cab9 100644 --- a/sys/netinet/igmp.c +++ b/sys/netinet/igmp.c @@ -312,17 +312,6 @@ igmp_scrub_context(struct mbuf *m) m->m_pkthdr.flowid = 0; } -#ifdef KTR -static __inline char * -inet_ntoa_haddr(in_addr_t haddr) -{ - struct in_addr ia; - - ia.s_addr = htonl(haddr); - return (inet_ntoa(ia)); -} -#endif - /* * Restore context from a queued IGMP output chain. * Return saved ifindex. @@ -872,8 +861,9 @@ igmp_input_v2_query(struct ifnet *ifp, const struct ip *ip, */ inm = inm_lookup(ifp, igmp->igmp_group); if (inm != NULL) { - CTR3(KTR_IGMPV3, "process v2 query %s on ifp %p(%s)", - inet_ntoa(igmp->igmp_group), ifp, ifp->if_xname); + CTR3(KTR_IGMPV3, + "process v2 query 0x%08x on ifp %p(%s)", + ntohl(igmp->igmp_group.s_addr), ifp, ifp->if_xname); igmp_v2_update_group(inm, timer); } } @@ -904,8 +894,8 @@ static void igmp_v2_update_group(struct in_multi *inm, const int timer) { - CTR4(KTR_IGMPV3, "%s: %s/%s timer=%d", __func__, - inet_ntoa(inm->inm_addr), inm->inm_ifp->if_xname, timer); + CTR4(KTR_IGMPV3, "0x%08x: %s/%s timer=%d", __func__, + ntohl(inm->inm_addr.s_addr), inm->inm_ifp->if_xname, timer); IN_MULTI_LOCK_ASSERT(); @@ -1085,8 +1075,8 @@ igmp_input_v3_query(struct ifnet *ifp, const struct ip *ip, goto out_locked; } } - CTR3(KTR_IGMPV3, "process v3 %s query on ifp %p(%s)", - inet_ntoa(igmpv3->igmp_group), ifp, ifp->if_xname); + CTR3(KTR_IGMPV3, "process v3 0x%08x query on ifp %p(%s)", + ntohl(igmpv3->igmp_group.s_addr), ifp, ifp->if_xname); /* * If there is a pending General Query response * scheduled sooner than the selected delay, no @@ -1246,8 +1236,8 @@ igmp_input_v1_report(struct ifnet *ifp, /*const*/ struct ip *ip, } } - CTR3(KTR_IGMPV3, "process v1 report %s on ifp %p(%s)", - inet_ntoa(igmp->igmp_group), ifp, ifp->if_xname); + CTR3(KTR_IGMPV3, "process v1 report 0x%08x on ifp %p(%s)", + ntohl(igmp->igmp_group.s_addr), ifp, ifp->if_xname); /* * IGMPv1 report suppression. @@ -1289,15 +1279,17 @@ igmp_input_v1_report(struct ifnet *ifp, /*const*/ struct ip *ip, case IGMP_LAZY_MEMBER: case IGMP_AWAKENING_MEMBER: CTR3(KTR_IGMPV3, - "report suppressed for %s on ifp %p(%s)", - inet_ntoa(igmp->igmp_group), ifp, ifp->if_xname); + "report suppressed for 0x%08x on ifp %p(%s)", + ntohl(igmp->igmp_group.s_addr), ifp, + ifp->if_xname); case IGMP_SLEEPING_MEMBER: inm->inm_state = IGMP_SLEEPING_MEMBER; break; case IGMP_REPORTING_MEMBER: CTR3(KTR_IGMPV3, - "report suppressed for %s on ifp %p(%s)", - inet_ntoa(igmp->igmp_group), ifp, ifp->if_xname); + "report suppressed for 0x%08x on ifp %p(%s)", + ntohl(igmp->igmp_group.s_addr), ifp, + ifp->if_xname); if (igi->igi_version == IGMP_VERSION_1) inm->inm_state = IGMP_LAZY_MEMBER; else if (igi->igi_version == IGMP_VERSION_2) @@ -1370,8 +1362,8 @@ igmp_input_v2_report(struct ifnet *ifp, /*const*/ struct ip *ip, if (ia != NULL) ifa_free(&ia->ia_ifa); - CTR3(KTR_IGMPV3, "process v2 report %s on ifp %p(%s)", - inet_ntoa(igmp->igmp_group), ifp, ifp->if_xname); + CTR3(KTR_IGMPV3, "process v2 report 0x%08x on ifp %p(%s)", + ntohl(igmp->igmp_group.s_addr), ifp, ifp->if_xname); /* * IGMPv2 report suppression. @@ -1411,8 +1403,8 @@ igmp_input_v2_report(struct ifnet *ifp, /*const*/ struct ip *ip, case IGMP_IDLE_MEMBER: case IGMP_AWAKENING_MEMBER: CTR3(KTR_IGMPV3, - "report suppressed for %s on ifp %p(%s)", - inet_ntoa(igmp->igmp_group), ifp, ifp->if_xname); + "report suppressed for 0x%08x on ifp %p(%s)", + ntohl(igmp->igmp_group.s_addr), ifp, ifp->if_xname); case IGMP_LAZY_MEMBER: inm->inm_state = IGMP_LAZY_MEMBER; break; @@ -1899,8 +1891,9 @@ igmp_v3_process_group_timers(struct igmp_ifsoftc *igi, (void)igmp_v3_merge_state_changes(inm, scq); inm_commit(inm); - CTR3(KTR_IGMPV3, "%s: T1 -> T0 for %s/%s", __func__, - inet_ntoa(inm->inm_addr), inm->inm_ifp->if_xname); + CTR3(KTR_IGMPV3, "%s: T1 -> T0 for 0x%08x/%s", __func__, + ntohl(inm->inm_addr.s_addr), + inm->inm_ifp->if_xname); /* * If we are leaving the group for good, make sure @@ -2346,10 +2339,9 @@ igmp_initial_join(struct in_multi *inm, struct igmp_ifsoftc *igi) struct ifnet *ifp; struct mbufq *mq; int error, retval, syncstates; - - CTR4(KTR_IGMPV3, "%s: initial join %s on ifp %p(%s)", - __func__, inet_ntoa(inm->inm_addr), inm->inm_ifp, - inm->inm_ifp->if_xname); + + CTR4(KTR_IGMPV3, "%s: initial join 0x%08x on ifp %p(%s)", __func__, + ntohl(inm->inm_addr.s_addr), inm->inm_ifp, inm->inm_ifp->if_xname); error = 0; syncstates = 1; @@ -2458,8 +2450,8 @@ igmp_initial_join(struct in_multi *inm, struct igmp_ifsoftc *igi) */ if (syncstates) { inm_commit(inm); - CTR3(KTR_IGMPV3, "%s: T1 -> T0 for %s/%s", __func__, - inet_ntoa(inm->inm_addr), inm->inm_ifp->if_xname); + CTR3(KTR_IGMPV3, "%s: T1 -> T0 for 0x%08x/%s", __func__, + ntohl(inm->inm_addr.s_addr), inm->inm_ifp->if_xname); } return (error); @@ -2474,9 +2466,8 @@ igmp_handle_state_change(struct in_multi *inm, struct igmp_ifsoftc *igi) struct ifnet *ifp; int retval; - CTR4(KTR_IGMPV3, "%s: state change for %s on ifp %p(%s)", - __func__, inet_ntoa(inm->inm_addr), inm->inm_ifp, - inm->inm_ifp->if_xname); + CTR4(KTR_IGMPV3, "%s: state change for 0x%08x on ifp %p(%s)", __func__, + ntohl(inm->inm_addr.s_addr), inm->inm_ifp, inm->inm_ifp->if_xname); ifp = inm->inm_ifp; @@ -2495,8 +2486,8 @@ igmp_handle_state_change(struct in_multi *inm, struct igmp_ifsoftc *igi) } CTR1(KTR_IGMPV3, "%s: nothing to do", __func__); inm_commit(inm); - CTR3(KTR_IGMPV3, "%s: T1 -> T0 for %s/%s", __func__, - inet_ntoa(inm->inm_addr), inm->inm_ifp->if_xname); + CTR3(KTR_IGMPV3, "%s: T1 -> T0 for 0x%08x/%s", __func__, + ntohl(inm->inm_addr.s_addr), inm->inm_ifp->if_xname); return (0); } @@ -2534,8 +2525,8 @@ igmp_final_leave(struct in_multi *inm, struct igmp_ifsoftc *igi) syncstates = 1; - CTR4(KTR_IGMPV3, "%s: final leave %s on ifp %p(%s)", - __func__, inet_ntoa(inm->inm_addr), inm->inm_ifp, + CTR4(KTR_IGMPV3, "%s: final leave 0x%08x on ifp %p(%s)", + __func__, ntohl(inm->inm_addr.s_addr), inm->inm_ifp, inm->inm_ifp->if_xname); IN_MULTI_LOCK_ASSERT(); @@ -2576,9 +2567,9 @@ igmp_final_leave(struct in_multi *inm, struct igmp_ifsoftc *igi) } else { inm->inm_scrv = igi->igi_rv; } - CTR4(KTR_IGMPV3, "%s: Leaving %s/%s with %d " + CTR4(KTR_IGMPV3, "%s: Leaving 0x%08x/%s with %d " "pending retransmissions.", __func__, - inet_ntoa(inm->inm_addr), + ntohl(inm->inm_addr.s_addr), inm->inm_ifp->if_xname, inm->inm_scrv); if (inm->inm_scrv == 0) { inm->inm_state = IGMP_NOT_MEMBER; @@ -2611,11 +2602,12 @@ igmp_final_leave(struct in_multi *inm, struct igmp_ifsoftc *igi) if (syncstates) { inm_commit(inm); - CTR3(KTR_IGMPV3, "%s: T1 -> T0 for %s/%s", __func__, - inet_ntoa(inm->inm_addr), inm->inm_ifp->if_xname); + CTR3(KTR_IGMPV3, "%s: T1 -> T0 for 0x%08x/%s", __func__, + ntohl(inm->inm_addr.s_addr), inm->inm_ifp->if_xname); inm->inm_st[1].iss_fmode = MCAST_UNDEFINED; - CTR3(KTR_IGMPV3, "%s: T1 now MCAST_UNDEFINED for %s/%s", - __func__, inet_ntoa(inm->inm_addr), inm->inm_ifp->if_xname); + CTR3(KTR_IGMPV3, "%s: T1 now MCAST_UNDEFINED for 0x%08x/%s", + __func__, ntohl(inm->inm_addr.s_addr), + inm->inm_ifp->if_xname); } } @@ -2740,9 +2732,8 @@ igmp_v3_enqueue_group_record(struct mbufq *mq, struct in_multi *inm, return (igmp_v3_enqueue_filter_change(mq, inm)); if (type == IGMP_DO_NOTHING) { - CTR3(KTR_IGMPV3, "%s: nothing to do for %s/%s", - __func__, inet_ntoa(inm->inm_addr), - inm->inm_ifp->if_xname); + CTR3(KTR_IGMPV3, "%s: nothing to do for 0x%08x/%s", __func__, + ntohl(inm->inm_addr.s_addr), inm->inm_ifp->if_xname); return (0); } @@ -2755,8 +2746,8 @@ igmp_v3_enqueue_group_record(struct mbufq *mq, struct in_multi *inm, if (record_has_sources) minrec0len += sizeof(in_addr_t); - CTR4(KTR_IGMPV3, "%s: queueing %s for %s/%s", __func__, - igmp_rec_type_to_str(type), inet_ntoa(inm->inm_addr), + CTR4(KTR_IGMPV3, "%s: queueing %s for 0x%08x/%s", __func__, + igmp_rec_type_to_str(type), ntohl(inm->inm_addr.s_addr), inm->inm_ifp->if_xname); /* @@ -2844,8 +2835,8 @@ igmp_v3_enqueue_group_record(struct mbufq *mq, struct in_multi *inm, } msrcs = 0; RB_FOREACH_SAFE(ims, ip_msource_tree, &inm->inm_srcs, nims) { - CTR2(KTR_IGMPV3, "%s: visit node %s", __func__, - inet_ntoa_haddr(ims->ims_haddr)); + CTR2(KTR_IGMPV3, "%s: visit node 0x%08x", __func__, + ims->ims_haddr); now = ims_get_mode(inm, ims, 1); CTR2(KTR_IGMPV3, "%s: node is %d", __func__, now); if ((now != mode) || @@ -2940,8 +2931,8 @@ igmp_v3_enqueue_group_record(struct mbufq *mq, struct in_multi *inm, msrcs = 0; RB_FOREACH_FROM(ims, ip_msource_tree, nims) { - CTR2(KTR_IGMPV3, "%s: visit node %s", __func__, - inet_ntoa_haddr(ims->ims_haddr)); + CTR2(KTR_IGMPV3, "%s: visit node 0x%08x", __func__, + ims->ims_haddr); now = ims_get_mode(inm, ims, 1); if ((now != mode) || (now == mode && mode == MCAST_UNDEFINED)) { @@ -3132,8 +3123,8 @@ igmp_v3_enqueue_filter_change(struct mbufq *mq, struct in_multi *inm) if (nims == NULL) nims = RB_MIN(ip_msource_tree, &inm->inm_srcs); RB_FOREACH_FROM(ims, ip_msource_tree, nims) { - CTR2(KTR_IGMPV3, "%s: visit node %s", - __func__, inet_ntoa_haddr(ims->ims_haddr)); + CTR2(KTR_IGMPV3, "%s: visit node 0x%08x", + __func__, ims->ims_haddr); now = ims_get_mode(inm, ims, 1); then = ims_get_mode(inm, ims, 0); CTR3(KTR_IGMPV3, "%s: mode: t0 %d, t1 %d", diff --git a/sys/netinet/in.c b/sys/netinet/in.c index 6f73df0..80d5509 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -1201,7 +1201,7 @@ in_lltable_rtcheck(struct ifnet *ifp, u_int flags, const struct sockaddr *l3addr */ if (!(rt_flags & RTF_HOST) && info.rti_ifp != ifp) { const char *sa, *mask, *addr, *lim; - int len; + const struct sockaddr_in *l3sin; mask = (const char *)&rt_mask; /* @@ -1213,14 +1213,17 @@ in_lltable_rtcheck(struct ifnet *ifp, u_int flags, const struct sockaddr *l3addr sa = (const char *)&rt_key; addr = (const char *)l3addr; - len = ((const struct sockaddr_in *)l3addr)->sin_len; - lim = addr + len; + l3sin = (const struct sockaddr_in *)l3addr; + lim = addr + l3sin->sin_len; for ( ; addr < lim; sa++, mask++, addr++) { if ((*sa ^ *addr) & *mask) { #ifdef DIAGNOSTIC - log(LOG_INFO, "IPv4 address: \"%s\" is not on the network\n", - inet_ntoa(((const struct sockaddr_in *)l3addr)->sin_addr)); + char addrbuf[INET_ADDRSTRLEN]; + + log(LOG_INFO, "IPv4 address: \"%s\" " + "is not on the network\n", + inet_ntoa_r(l3sin->sin_addr, addrbuf)); #endif return (EINVAL); } diff --git a/sys/netinet/in_mcast.c b/sys/netinet/in_mcast.c index 07b5bba..c7fff94 100644 --- a/sys/netinet/in_mcast.c +++ b/sys/netinet/in_mcast.c @@ -495,9 +495,12 @@ in_getmulti(struct ifnet *ifp, const struct in_addr *group, ("%s: ifma not AF_INET", __func__)); KASSERT(inm != NULL, ("%s: no ifma_protospec", __func__)); if (inm->inm_ifma != ifma || inm->inm_ifp != ifp || - !in_hosteq(inm->inm_addr, *group)) + !in_hosteq(inm->inm_addr, *group)) { + char addrbuf[INET_ADDRSTRLEN]; + panic("%s: ifma %p is inconsistent with %p (%s)", - __func__, ifma, inm, inet_ntoa(*group)); + __func__, ifma, inm, inet_ntoa_r(*group, addrbuf)); + } #endif ++inm->inm_refcount; *pinm = inm; @@ -874,9 +877,6 @@ inm_get_source(struct in_multi *inm, const in_addr_t haddr, { struct ip_msource find; struct ip_msource *ims, *nims; -#ifdef KTR - struct in_addr ia; -#endif find.ims_haddr = haddr; ims = RB_FIND(ip_msource_tree, &inm->inm_srcs, &find); @@ -892,9 +892,8 @@ inm_get_source(struct in_multi *inm, const in_addr_t haddr, ++inm->inm_nsrc; ims = nims; #ifdef KTR - ia.s_addr = htonl(haddr); - CTR3(KTR_IGMPV3, "%s: allocated %s as %p", __func__, - inet_ntoa(ia), ims); + CTR3(KTR_IGMPV3, "%s: allocated 0x%08x as %p", __func__, + haddr, ims); #endif } @@ -911,29 +910,24 @@ ims_merge(struct ip_msource *ims, const struct in_msource *lims, const int rollback) { int n = rollback ? -1 : 1; -#ifdef KTR - struct in_addr ia; - - ia.s_addr = htonl(ims->ims_haddr); -#endif if (lims->imsl_st[0] == MCAST_EXCLUDE) { - CTR3(KTR_IGMPV3, "%s: t1 ex -= %d on %s", - __func__, n, inet_ntoa(ia)); + CTR3(KTR_IGMPV3, "%s: t1 ex -= %d on 0x%08x", + __func__, n, ims->ims_haddr); ims->ims_st[1].ex -= n; } else if (lims->imsl_st[0] == MCAST_INCLUDE) { - CTR3(KTR_IGMPV3, "%s: t1 in -= %d on %s", - __func__, n, inet_ntoa(ia)); + CTR3(KTR_IGMPV3, "%s: t1 in -= %d on 0x%08x", + __func__, n, ims->ims_haddr); ims->ims_st[1].in -= n; } if (lims->imsl_st[1] == MCAST_EXCLUDE) { - CTR3(KTR_IGMPV3, "%s: t1 ex += %d on %s", - __func__, n, inet_ntoa(ia)); + CTR3(KTR_IGMPV3, "%s: t1 ex += %d on 0x%08x", + __func__, n, ims->ims_haddr); ims->ims_st[1].ex += n; } else if (lims->imsl_st[1] == MCAST_INCLUDE) { - CTR3(KTR_IGMPV3, "%s: t1 in += %d on %s", - __func__, n, inet_ntoa(ia)); + CTR3(KTR_IGMPV3, "%s: t1 in += %d on 0x%08x", + __func__, n, ims->ims_haddr); ims->ims_st[1].in += n; } } @@ -1169,8 +1163,8 @@ in_joingroup_locked(struct ifnet *ifp, const struct in_addr *gina, IN_MULTI_LOCK_ASSERT(); - CTR4(KTR_IGMPV3, "%s: join %s on %p(%s))", __func__, - inet_ntoa(*gina), ifp, ifp->if_xname); + CTR4(KTR_IGMPV3, "%s: join 0x%08x on %p(%s))", __func__, + ntohl(gina->s_addr), ifp, ifp->if_xname); error = 0; inm = NULL; @@ -1253,8 +1247,8 @@ in_leavegroup_locked(struct in_multi *inm, /*const*/ struct in_mfilter *imf) IN_MULTI_LOCK_ASSERT(); - CTR5(KTR_IGMPV3, "%s: leave inm %p, %s/%s, imf %p", __func__, - inm, inet_ntoa(inm->inm_addr), + CTR5(KTR_IGMPV3, "%s: leave inm %p, 0x%08x/%s, imf %p", __func__, + inm, ntohl(inm->inm_addr.s_addr), (inm_is_ifp_detached(inm) ? "null" : inm->inm_ifp->if_xname), imf); @@ -1302,9 +1296,13 @@ in_addmulti(struct in_addr *ap, struct ifnet *ifp) { struct in_multi *pinm; int error; +#ifdef INVARIANTS + char addrbuf[INET_ADDRSTRLEN]; +#endif KASSERT(IN_LOCAL_GROUP(ntohl(ap->s_addr)), - ("%s: %s not in 224.0.0.0/24", __func__, inet_ntoa(*ap))); + ("%s: %s not in 224.0.0.0/24", __func__, + inet_ntoa_r(*ap, addrbuf))); error = in_joingroup(ifp, ap, NULL, &pinm); if (error != 0) @@ -1383,8 +1381,8 @@ inp_block_unblock_source(struct inpcb *inp, struct sockopt *sopt) if (sopt->sopt_name == IP_BLOCK_SOURCE) doblock = 1; - CTR3(KTR_IGMPV3, "%s: imr_interface = %s, ifp = %p", - __func__, inet_ntoa(mreqs.imr_interface), ifp); + CTR3(KTR_IGMPV3, "%s: imr_interface = 0x%08x, ifp = %p", + __func__, ntohl(mreqs.imr_interface.s_addr), ifp); break; } @@ -1456,8 +1454,8 @@ inp_block_unblock_source(struct inpcb *inp, struct sockopt *sopt) */ ims = imo_match_source(imo, idx, &ssa->sa); if ((ims != NULL && doblock) || (ims == NULL && !doblock)) { - CTR3(KTR_IGMPV3, "%s: source %s %spresent", __func__, - inet_ntoa(ssa->sin.sin_addr), doblock ? "" : "not "); + CTR3(KTR_IGMPV3, "%s: source 0x%08x %spresent", __func__, + ntohl(ssa->sin.sin_addr.s_addr), doblock ? "" : "not "); error = EADDRNOTAVAIL; goto out_inp_locked; } @@ -1985,8 +1983,8 @@ inp_join_group(struct inpcb *inp, struct sockopt *sopt) ifp = inp_lookup_mcast_ifp(inp, &gsa->sin, mreqs.imr_interface); - CTR3(KTR_IGMPV3, "%s: imr_interface = %s, ifp = %p", - __func__, inet_ntoa(mreqs.imr_interface), ifp); + CTR3(KTR_IGMPV3, "%s: imr_interface = 0x%08x, ifp = %p", + __func__, ntohl(mreqs.imr_interface.s_addr), ifp); break; } @@ -2286,8 +2284,8 @@ inp_leave_group(struct inpcb *inp, struct sockopt *sopt) if (!in_nullhost(mreqs.imr_interface)) INADDR_TO_IFP(mreqs.imr_interface, ifp); - CTR3(KTR_IGMPV3, "%s: imr_interface = %s, ifp = %p", - __func__, inet_ntoa(mreqs.imr_interface), ifp); + CTR3(KTR_IGMPV3, "%s: imr_interface = 0x%08x, ifp = %p", + __func__, ntohl(mreqs.imr_interface.s_addr), ifp); break; @@ -2367,8 +2365,8 @@ inp_leave_group(struct inpcb *inp, struct sockopt *sopt) } ims = imo_match_source(imo, idx, &ssa->sa); if (ims == NULL) { - CTR3(KTR_IGMPV3, "%s: source %s %spresent", __func__, - inet_ntoa(ssa->sin.sin_addr), "not "); + CTR3(KTR_IGMPV3, "%s: source 0x%08x %spresent", + __func__, ntohl(ssa->sin.sin_addr.s_addr), "not "); error = EADDRNOTAVAIL; goto out_inp_locked; } @@ -2487,8 +2485,8 @@ inp_set_multicast_if(struct inpcb *inp, struct sockopt *sopt) if (ifp == NULL) return (EADDRNOTAVAIL); } - CTR3(KTR_IGMPV3, "%s: ifp = %p, addr = %s", __func__, ifp, - inet_ntoa(addr)); + CTR3(KTR_IGMPV3, "%s: ifp = %p, addr = 0x%08x", __func__, ifp, + ntohl(addr.s_addr)); } /* Reject interfaces which do not support multicast. */ @@ -2865,8 +2863,8 @@ sysctl_ip_mcast_filters(SYSCTL_HANDLER_ARGS) group.s_addr = name[1]; if (!IN_MULTICAST(ntohl(group.s_addr))) { - CTR2(KTR_IGMPV3, "%s: group %s is not multicast", - __func__, inet_ntoa(group)); + CTR2(KTR_IGMPV3, "%s: group 0x%08x is not multicast", + __func__, ntohl(group.s_addr)); return (EINVAL); } @@ -2897,12 +2895,8 @@ sysctl_ip_mcast_filters(SYSCTL_HANDLER_ARGS) if (retval != 0) break; RB_FOREACH(ims, ip_msource_tree, &inm->inm_srcs) { -#ifdef KTR - struct in_addr ina; - ina.s_addr = htonl(ims->ims_haddr); - CTR2(KTR_IGMPV3, "%s: visit node %s", __func__, - inet_ntoa(ina)); -#endif + CTR2(KTR_IGMPV3, "%s: visit node 0x%08x", __func__, + ims->ims_haddr); /* * Only copy-out sources which are in-mode. */ @@ -2965,13 +2959,14 @@ void inm_print(const struct in_multi *inm) { int t; + char addrbuf[INET_ADDRSTRLEN]; if ((ktr_mask & KTR_IGMPV3) == 0) return; printf("%s: --- begin inm %p ---\n", __func__, inm); printf("addr %s ifp %p(%s) ifma %p\n", - inet_ntoa(inm->inm_addr), + inet_ntoa_r(inm->inm_addr, addrbuf), inm->inm_ifp, inm->inm_ifp->if_xname, inm->inm_ifma); diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index 867c5e8..c655b01 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -380,10 +380,12 @@ icmp_input(struct mbuf **mp, int *offp, int proto) */ #ifdef ICMPPRINTFS if (icmpprintfs) { - char buf[4 * sizeof "123"]; - strcpy(buf, inet_ntoa(ip->ip_src)); + char srcbuf[INET_ADDRSTRLEN]; + char dstbuf[INET_ADDRSTRLEN]; + printf("icmp_input from %s to %s, len %d\n", - buf, inet_ntoa(ip->ip_dst), icmplen); + inet_ntoa_r(ip->ip_src, srcbuf), + inet_ntoa_r(ip->ip_dst, dstbuf), icmplen); } #endif if (icmplen < ICMP_MINLEN) { @@ -647,11 +649,12 @@ reflect: icmpdst.sin_addr = icp->icmp_gwaddr; #ifdef ICMPPRINTFS if (icmpprintfs) { - char buf[4 * sizeof "123"]; - strcpy(buf, inet_ntoa(icp->icmp_ip.ip_dst)); + char dstbuf[INET_ADDRSTRLEN]; + char gwbuf[INET_ADDRSTRLEN]; printf("redirect dst %s to %s\n", - buf, inet_ntoa(icp->icmp_gwaddr)); + inet_ntoa_r(icp->icmp_ip.ip_dst, dstbuf), + inet_ntoa_r(icp->icmp_gwaddr, gwbuf)); } #endif icmpsrc.sin_addr = icp->icmp_ip.ip_dst; @@ -899,10 +902,12 @@ icmp_send(struct mbuf *m, struct mbuf *opts) m->m_pkthdr.rcvif = (struct ifnet *)0; #ifdef ICMPPRINTFS if (icmpprintfs) { - char buf[4 * sizeof "123"]; - strcpy(buf, inet_ntoa(ip->ip_dst)); + char dstbuf[INET_ADDRSTRLEN]; + char srcbuf[INET_ADDRSTRLEN]; + printf("icmp_send dst %s src %s\n", - buf, inet_ntoa(ip->ip_src)); + inet_ntoa_r(ip->ip_dst, dstbuf), + inet_ntoa_r(ip->ip_src, srcbuf)); } #endif (void) ip_output(m, opts, NULL, 0, NULL, NULL); diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c index d6164ef..1051016 100644 --- a/sys/netinet/ip_mroute.c +++ b/sys/netinet/ip_mroute.c @@ -928,8 +928,8 @@ add_vif(struct vifctl *vifcp) VIF_UNLOCK(); - CTR4(KTR_IPMF, "%s: add vif %d laddr %s thresh %x", __func__, - (int)vifcp->vifc_vifi, inet_ntoa(vifcp->vifc_lcl_addr), + CTR4(KTR_IPMF, "%s: add vif %d laddr 0x%08x thresh %x", __func__, + (int)vifcp->vifc_vifi, ntohl(vifcp->vifc_lcl_addr.s_addr), (int)vifcp->vifc_threshold); return 0; @@ -1060,8 +1060,8 @@ add_mfc(struct mfcctl2 *mfccp) /* If an entry already exists, just update the fields */ if (rt) { - CTR4(KTR_IPMF, "%s: update mfc orig %s group %lx parent %x", - __func__, inet_ntoa(mfccp->mfcc_origin), + CTR4(KTR_IPMF, "%s: update mfc orig 0x%08x group %lx parent %x", + __func__, ntohl(mfccp->mfcc_origin.s_addr), (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr), mfccp->mfcc_parent); update_mfc_params(rt, mfccp); @@ -1080,8 +1080,8 @@ add_mfc(struct mfcctl2 *mfccp) in_hosteq(rt->mfc_mcastgrp, mfccp->mfcc_mcastgrp) && !TAILQ_EMPTY(&rt->mfc_stall)) { CTR5(KTR_IPMF, - "%s: add mfc orig %s group %lx parent %x qh %p", - __func__, inet_ntoa(mfccp->mfcc_origin), + "%s: add mfc orig 0x%08x group %lx parent %x qh %p", + __func__, ntohl(mfccp->mfcc_origin.s_addr), (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr), mfccp->mfcc_parent, TAILQ_FIRST(&rt->mfc_stall)); @@ -1159,8 +1159,8 @@ del_mfc(struct mfcctl2 *mfccp) origin = mfccp->mfcc_origin; mcastgrp = mfccp->mfcc_mcastgrp; - CTR3(KTR_IPMF, "%s: delete mfc orig %s group %lx", __func__, - inet_ntoa(origin), (u_long)ntohl(mcastgrp.s_addr)); + CTR3(KTR_IPMF, "%s: delete mfc orig 0x%08x group %lx", __func__, + ntohl(origin.s_addr), (u_long)ntohl(mcastgrp.s_addr)); MFC_LOCK(); @@ -1224,8 +1224,8 @@ X_ip_mforward(struct ip *ip, struct ifnet *ifp, struct mbuf *m, int error; vifi_t vifi; - CTR3(KTR_IPMF, "ip_mforward: delete mfc orig %s group %lx ifp %p", - inet_ntoa(ip->ip_src), (u_long)ntohl(ip->ip_dst.s_addr), ifp); + CTR3(KTR_IPMF, "ip_mforward: delete mfc orig 0x%08x group %lx ifp %p", + ntohl(ip->ip_src.s_addr), (u_long)ntohl(ip->ip_dst.s_addr), ifp); if (ip->ip_hl < (sizeof(struct ip) + TUNNEL_LEN) >> 2 || ((u_char *)(ip + 1))[1] != IPOPT_LSRR ) { @@ -1287,8 +1287,8 @@ X_ip_mforward(struct ip *ip, struct ifnet *ifp, struct mbuf *m, MRTSTAT_INC(mrts_mfc_misses); MRTSTAT_INC(mrts_no_route); - CTR2(KTR_IPMF, "ip_mforward: no mfc for (%s,%lx)", - inet_ntoa(ip->ip_src), (u_long)ntohl(ip->ip_dst.s_addr)); + CTR2(KTR_IPMF, "ip_mforward: no mfc for (0x%08x,%lx)", + ntohl(ip->ip_src.s_addr), (u_long)ntohl(ip->ip_dst.s_addr)); /* * Allocate mbufs early so that we don't do extra work if we are @@ -2570,7 +2570,7 @@ pim_input(struct mbuf **mp, int *offp, int proto) int minlen; int datalen = ntohs(ip->ip_len) - iphlen; int ip_tos; - + *mp = NULL; /* Keep statistics */ @@ -2582,8 +2582,8 @@ pim_input(struct mbuf **mp, int *offp, int proto) */ if (datalen < PIM_MINLEN) { PIMSTAT_INC(pims_rcv_tooshort); - CTR3(KTR_IPMF, "%s: short packet (%d) from %s", - __func__, datalen, inet_ntoa(ip->ip_src)); + CTR3(KTR_IPMF, "%s: short packet (%d) from 0x%08x", + __func__, datalen, ntohl(ip->ip_src.s_addr)); m_freem(m); return (IPPROTO_DONE); } @@ -2682,8 +2682,9 @@ pim_input(struct mbuf **mp, int *offp, int proto) reghdr = (u_int32_t *)(pim + 1); encap_ip = (struct ip *)(reghdr + 1); - CTR3(KTR_IPMF, "%s: register: encap ip src %s len %d", - __func__, inet_ntoa(encap_ip->ip_src), ntohs(encap_ip->ip_len)); + CTR3(KTR_IPMF, "%s: register: encap ip src 0x%08x len %d", + __func__, ntohl(encap_ip->ip_src.s_addr), + ntohs(encap_ip->ip_len)); /* verify the version number of the inner packet */ if (encap_ip->ip_v != IPVERSION) { @@ -2696,8 +2697,8 @@ pim_input(struct mbuf **mp, int *offp, int proto) /* verify the inner packet is destined to a mcast group */ if (!IN_MULTICAST(ntohl(encap_ip->ip_dst.s_addr))) { PIMSTAT_INC(pims_rcv_badregisters); - CTR2(KTR_IPMF, "%s: bad encap ip dest %s", __func__, - inet_ntoa(encap_ip->ip_dst)); + CTR2(KTR_IPMF, "%s: bad encap ip dest 0x%08x", __func__, + ntohl(encap_ip->ip_dst.s_addr)); m_freem(m); return (IPPROTO_DONE); } diff --git a/sys/netinet/ip_options.c b/sys/netinet/ip_options.c index 3e44ffb..399c88b 100644 --- a/sys/netinet/ip_options.c +++ b/sys/netinet/ip_options.c @@ -196,16 +196,19 @@ ip_dooptions(struct mbuf *m, int pass) #endif if (!V_ip_dosourceroute) { if (V_ipforwarding) { - char buf[16]; /* aaa.bbb.ccc.ddd\0 */ + char srcbuf[INET_ADDRSTRLEN]; + char dstbuf[INET_ADDRSTRLEN]; + /* * Acting as a router, so generate * ICMP */ nosourcerouting: - strcpy(buf, inet_ntoa(ip->ip_dst)); log(LOG_WARNING, - "attempted source route from %s to %s\n", - inet_ntoa(ip->ip_src), buf); + "attempted source route from %s " + "to %s\n", + inet_ntoa_r(ip->ip_src, srcbuf), + inet_ntoa_r(ip->ip_dst, dstbuf)); type = ICMP_UNREACH; code = ICMP_UNREACH_SRCFAIL; goto bad; diff --git a/sys/netinet/libalias/alias_local.h b/sys/netinet/libalias/alias_local.h index 506193c..e9e843c 100644 --- a/sys/netinet/libalias/alias_local.h +++ b/sys/netinet/libalias/alias_local.h @@ -70,6 +70,12 @@ #define GET_ALIAS_PORT -1 #define GET_ALIAS_ID GET_ALIAS_PORT +#ifdef _KERNEL +#define INET_NTOA_BUF(buf) (buf) +#else +#define INET_NTOA_BUF(buf) (buf), sizeof(buf) +#endif + struct proxy_entry; struct libalias { diff --git a/sys/netinet/libalias/alias_nbt.c b/sys/netinet/libalias/alias_nbt.c index a7598f8..b041699 100644 --- a/sys/netinet/libalias/alias_nbt.c +++ b/sys/netinet/libalias/alias_nbt.c @@ -344,6 +344,9 @@ AliasHandleUdpNbt( NbtDataHeader *ndh; u_char *p = NULL; char *pmax; +#ifdef LIBALIAS_DEBUG + char addrbuf[INET_ADDRSTRLEN]; +#endif (void)la; (void)lnk; @@ -379,7 +382,8 @@ AliasHandleUdpNbt( if (p == NULL || (char *)p > pmax) p = NULL; #ifdef LIBALIAS_DEBUG - printf("%s:%d-->", inet_ntoa(ndh->source_ip), ntohs(ndh->source_port)); + printf("%s:%d-->", inet_ntoa_r(ndh->source_ip, INET_NTOA_BUF(addrbuf)), + ntohs(ndh->source_port)); #endif /* Doing an IP address and Port number Translation */ if (uh->uh_sum != 0) { @@ -399,7 +403,8 @@ AliasHandleUdpNbt( ndh->source_ip = *alias_address; ndh->source_port = alias_port; #ifdef LIBALIAS_DEBUG - printf("%s:%d\n", inet_ntoa(ndh->source_ip), ntohs(ndh->source_port)); + printf("%s:%d\n", inet_ntoa_r(ndh->source_ip, INET_NTOA_BUF(addrbuf)), + ntohs(ndh->source_port)); fflush(stdout); #endif return ((p == NULL) ? -1 : 0); @@ -480,6 +485,10 @@ AliasHandleResourceNB( { NBTNsRNB *nb; u_short bcount; +#ifdef LIBALIAS_DEBUG + char oldbuf[INET_ADDRSTRLEN]; + char newbuf[INET_ADDRSTRLEN]; +#endif if (q == NULL || (char *)(q + 1) > pmax) return (NULL); @@ -491,8 +500,10 @@ AliasHandleResourceNB( /* Processing all in_addr array */ #ifdef LIBALIAS_DEBUG - printf("NB rec[%s", inet_ntoa(nbtarg->oldaddr)); - printf("->%s, %dbytes] ", inet_ntoa(nbtarg->newaddr), bcount); + printf("NB rec[%s->%s, %dbytes] ", + inet_ntoa_r(nbtarg->oldaddr, INET_NTOA_BUF(oldbuf)), + inet_ntoa_r(nbtarg->newaddr, INET_NTOA_BUF(newbuf)), + bcount); #endif while (nb != NULL && bcount != 0) { if ((char *)(nb + 1) > pmax) { @@ -500,7 +511,7 @@ AliasHandleResourceNB( break; } #ifdef LIBALIAS_DEBUG - printf("<%s>", inet_ntoa(nb->addr)); + printf("<%s>", inet_ntoa_r(nb->addr, INET_NTOA_BUF(newbuf))); #endif if (!bcmp(&nbtarg->oldaddr, &nb->addr, sizeof(struct in_addr))) { if (*nbtarg->uh_sum != 0) { @@ -547,6 +558,10 @@ AliasHandleResourceA( { NBTNsResourceA *a; u_short bcount; +#ifdef LIBALIAS_DEBUG + char oldbuf[INET_ADDRSTRLEN]; + char newbuf[INET_ADDRSTRLEN]; +#endif if (q == NULL || (char *)(q + 1) > pmax) return (NULL); @@ -559,14 +574,15 @@ AliasHandleResourceA( /* Processing all in_addr array */ #ifdef LIBALIAS_DEBUG - printf("Arec [%s", inet_ntoa(nbtarg->oldaddr)); - printf("->%s]", inet_ntoa(nbtarg->newaddr)); + printf("Arec [%s->%s]", + inet_ntoa_r(nbtarg->oldaddr, INET_NTOA_BUF(oldbuf)), + inet_ntoa_r(nbtarg->newaddr, INET_NTOA_BUF(newbuf))); #endif while (bcount != 0) { if (a == NULL || (char *)(a + 1) > pmax) return (NULL); #ifdef LIBALIAS_DEBUG - printf("..%s", inet_ntoa(a->addr)); + printf("..%s", inet_ntoa_r(a->addr, INET_NTOA_BUF(newbuf))); #endif if (!bcmp(&nbtarg->oldaddr, &a->addr, sizeof(struct in_addr))) { if (*nbtarg->uh_sum != 0) { diff --git a/sys/netinet/libalias/alias_proxy.c b/sys/netinet/libalias/alias_proxy.c index 0d49381..132e562 100644 --- a/sys/netinet/libalias/alias_proxy.c +++ b/sys/netinet/libalias/alias_proxy.c @@ -294,6 +294,7 @@ ProxyEncodeTcpStream(struct alias_link *lnk, int slen; char buffer[40]; struct tcphdr *tc; + char addrbuf[INET_ADDRSTRLEN]; /* Compute pointer to tcp header */ tc = (struct tcphdr *)ip_next(pip); @@ -305,7 +306,8 @@ ProxyEncodeTcpStream(struct alias_link *lnk, /* Translate destination address and port to string form */ snprintf(buffer, sizeof(buffer) - 2, "[DEST %s %d]", - inet_ntoa(GetProxyAddress(lnk)), (u_int) ntohs(GetProxyPort(lnk))); + inet_ntoa_r(GetProxyAddress(lnk), INET_NTOA_BUF(addrbuf)), + (u_int) ntohs(GetProxyPort(lnk))); /* Pad string out to a multiple of two in length */ slen = strlen(buffer); diff --git a/sys/netinet/libalias/alias_sctp.c b/sys/netinet/libalias/alias_sctp.c index 67e4754..fbc8e41 100644 --- a/sys/netinet/libalias/alias_sctp.c +++ b/sys/netinet/libalias/alias_sctp.c @@ -904,6 +904,7 @@ TxAbortErrorM(struct libalias *la, struct sctp_nat_msg *sm, struct sctp_nat_asso int ip_size = sizeof(struct ip) + sctp_size; int include_error_cause = 1; char tmp_ip[ip_size]; + char addrbuf[INET_ADDRSTRLEN]; if (ntohs(sm->ip_hdr->ip_len) < ip_size) { /* short packet, cannot send error cause */ include_error_cause = 0; @@ -984,7 +985,8 @@ TxAbortErrorM(struct libalias *la, struct sctp_nat_msg *sm, struct sctp_nat_asso ((sndrply == SN_SEND_ABORT) ? "Sending" : "Replying"), ((sndrply & SN_TX_ERROR) ? "ErrorM" : "AbortM"), (include_error_cause ? ntohs(error_cause->code) : 0), - inet_ntoa(ip->ip_dst),ntohs(sctp_hdr->dest_port), + inet_ntoa_r(ip->ip_dst, INET_NTOA_BUF(addrbuf)), + ntohs(sctp_hdr->dest_port), ntohl(sctp_hdr->v_tag), ntohl(sctp_hdr->checksum))); } @@ -2574,6 +2576,8 @@ static void logsctpassoc(struct sctp_nat_assoc *assoc, char* s) { struct sctp_GlobalAddress *G_Addr = NULL; char *sp; + char addrbuf[INET_ADDRSTRLEN]; + switch(assoc->state) { case SN_ID: sp = "ID "; @@ -2598,12 +2602,14 @@ static void logsctpassoc(struct sctp_nat_assoc *assoc, char* s) break; } SctpAliasLog("%sAssoc: %s exp=%u la=%s lv=%u lp=%u gv=%u gp=%u tbl=%d\n", - s, sp, assoc->exp, inet_ntoa(assoc->l_addr), ntohl(assoc->l_vtag), - ntohs(assoc->l_port), ntohl(assoc->g_vtag), ntohs(assoc->g_port), + s, sp, assoc->exp, inet_ntoa_r(assoc->l_addr, addrbuf), + ntohl(assoc->l_vtag), ntohs(assoc->l_port), + ntohl(assoc->g_vtag), ntohs(assoc->g_port), assoc->TableRegister); /* list global addresses */ LIST_FOREACH(G_Addr, &(assoc->Gaddr), list_Gaddr) { - SctpAliasLog("\t\tga=%s\n",inet_ntoa(G_Addr->g_addr)); + SctpAliasLog("\t\tga=%s\n", + inet_ntoa_r(G_Addr->g_addr, addrbuf)); } } diff --git a/sys/netinet/tcp_hostcache.c b/sys/netinet/tcp_hostcache.c index 5e8342f..16062e6 100644 --- a/sys/netinet/tcp_hostcache.c +++ b/sys/netinet/tcp_hostcache.c @@ -595,6 +595,7 @@ sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS) struct sbuf sb; int i, error; struct hc_metrics *hc_entry; + char ip4buf[INET_ADDRSTRLEN]; #ifdef INET6 char ip6buf[INET6_ADDRSTRLEN]; #endif @@ -614,7 +615,8 @@ sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS) sbuf_printf(&sb, "%-15s %5lu %8lu %6lums %6lums %8lu %8lu %8lu %4lu " "%4lu %4i\n", - hc_entry->ip4.s_addr ? inet_ntoa(hc_entry->ip4) : + hc_entry->ip4.s_addr ? + inet_ntoa_r(hc_entry->ip4, ip4buf) : #ifdef INET6 ip6_sprintf(ip6buf, &hc_entry->ip6), #else diff --git a/sys/netpfil/ipfw/ip_fw_log.c b/sys/netpfil/ipfw/ip_fw_log.c index b56604d..7ef92cd 100644 --- a/sys/netpfil/ipfw/ip_fw_log.c +++ b/sys/netpfil/ipfw/ip_fw_log.c @@ -372,6 +372,7 @@ ipfw_log(struct ip_fw_chain *chain, struct ip_fw *f, u_int hlen, TARG(cmd->arg1, pipe)); break; case O_FORWARD_IP: { + char buf[INET_ADDRSTRLEN]; ipfw_insn_sa *sa = (ipfw_insn_sa *)cmd; int len; struct in_addr dummyaddr; @@ -381,7 +382,7 @@ ipfw_log(struct ip_fw_chain *chain, struct ip_fw *f, u_int hlen, dummyaddr.s_addr = sa->sa.sin_addr.s_addr; len = snprintf(SNPARGS(action2, 0), "Forward to %s", - inet_ntoa(dummyaddr)); + inet_ntoa_r(dummyaddr, buf)); if (sa->sa.sin_port) snprintf(SNPARGS(action2, len), ":%d", |