svn commit: r313821 - in head/sys: dev/cxgb/ulp/iw_cxgb fs/nfsserver kern netinet netinet/libalias netpfil/ipfw
Eric van Gyzen
vangyzen at FreeBSD.org
Thu Feb 16 20:47:44 UTC 2017
Author: vangyzen
Date: Thu Feb 16 20:47:41 2017
New Revision: 313821
URL: https://svnweb.freebsd.org/changeset/base/313821
Log:
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.
Suggested by: glebius, emaste
Reviewed by: gnn
MFC after: 2 weeks
Sponsored by: Dell EMC
Differential Revision: https://reviews.freebsd.org/D9625
Modified:
head/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c
head/sys/fs/nfsserver/nfs_nfsdkrpc.c
head/sys/kern/kern_jail.c
head/sys/netinet/if_ether.c
head/sys/netinet/igmp.c
head/sys/netinet/in.c
head/sys/netinet/in_mcast.c
head/sys/netinet/ip_icmp.c
head/sys/netinet/ip_mroute.c
head/sys/netinet/ip_options.c
head/sys/netinet/libalias/alias_local.h
head/sys/netinet/libalias/alias_nbt.c
head/sys/netinet/libalias/alias_proxy.c
head/sys/netinet/libalias/alias_sctp.c
head/sys/netinet/tcp_hostcache.c
head/sys/netpfil/ipfw/ip_fw_log.c
Modified: head/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c
==============================================================================
--- head/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c Thu Feb 16 20:44:44 2017 (r313820)
+++ head/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c Thu Feb 16 20:47:41 2017 (r313821)
@@ -1461,6 +1461,9 @@ static void
process_data(struct iwch_ep *ep)
{
struct sockaddr_in *local, *remote;
+#ifdef KTR
+ char local_str[INET_ADDRSTRLEN], remote_str[INET_ADDRSTRLEN];
+#endif
CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, ep, ep->com.so, states[ep->com.state]);
@@ -1479,8 +1482,8 @@ 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));
+ inet_ntoa_r(local->sin_addr, local_str),
+ inet_ntoa_r(remote->sin_addr, remote_str));
ep->com.local_addr = *local;
ep->com.remote_addr = *remote;
free(local, M_SONAME);
@@ -1519,6 +1522,9 @@ process_newconn(struct iw_cm_id *parent_
struct sockaddr_in *local;
struct sockaddr_in *remote;
struct iwch_ep *parent_ep = parent_cm_id->provider_data;
+#ifdef KTR
+ char buf[INET_ADDRSTRLEN];
+#endif
CTR3(KTR_IW_CXGB, "%s parent ep %p so %p", __FUNCTION__, parent_ep, parent_ep->com.so);
if (!child_so) {
@@ -1539,7 +1545,7 @@ process_newconn(struct iw_cm_id *parent_
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));
+ inet_ntoa_r(remote->sin_addr, buf), 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;
Modified: head/sys/fs/nfsserver/nfs_nfsdkrpc.c
==============================================================================
--- head/sys/fs/nfsserver/nfs_nfsdkrpc.c Thu Feb 16 20:44:44 2017 (r313820)
+++ head/sys/fs/nfsserver/nfs_nfsdkrpc.c Thu Feb 16 20:47:41 2017 (r313821)
@@ -174,7 +174,11 @@ nfssvc_program(struct svc_req *rqst, SVC
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, SVC
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);
Modified: head/sys/kern/kern_jail.c
==============================================================================
--- head/sys/kern/kern_jail.c Thu Feb 16 20:44:44 2017 (r313820)
+++ head/sys/kern/kern_jail.c Thu Feb 16 20:47:41 2017 (r313821)
@@ -3999,6 +3999,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
@@ -4050,7 +4053,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);
Modified: head/sys/netinet/if_ether.c
==============================================================================
--- head/sys/netinet/if_ether.c Thu Feb 16 20:44:44 2017 (r313820)
+++ head/sys/netinet/if_ether.c Thu Feb 16 20:47:41 2017 (r313821)
@@ -464,9 +464,12 @@ arpresolve_full(struct ifnet *ifp, int i
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);
}
@@ -803,6 +806,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;
@@ -927,7 +931,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;
}
@@ -949,7 +953,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;
@@ -1086,12 +1090,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
}
}
@@ -1101,7 +1107,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;
@@ -1162,6 +1168,7 @@ arp_check_update_lle(struct arphdr *ah,
uint8_t linkhdr[LLE_MAX_LINKHDR];
size_t linkhdrsize;
int lladdr_off;
+ char addrbuf[INET_ADDRSTRLEN];
LLE_WLOCK_ASSERT(la);
@@ -1170,7 +1177,7 @@ arp_check_update_lle(struct arphdr *ah,
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);
@@ -1187,13 +1194,14 @@ arp_check_update_lle(struct arphdr *ah,
"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), ":",
Modified: head/sys/netinet/igmp.c
==============================================================================
--- head/sys/netinet/igmp.c Thu Feb 16 20:44:44 2017 (r313820)
+++ head/sys/netinet/igmp.c Thu Feb 16 20:47:41 2017 (r313821)
@@ -314,12 +314,12 @@ igmp_scrub_context(struct mbuf *m)
#ifdef KTR
static __inline char *
-inet_ntoa_haddr(in_addr_t haddr)
+inet_ntoa_haddr(in_addr_t haddr, char *addrbuf)
{
struct in_addr ia;
ia.s_addr = htonl(haddr);
- return (inet_ntoa(ia));
+ return (inet_ntoa_r(ia, addrbuf));
}
#endif
@@ -804,6 +804,9 @@ igmp_input_v2_query(struct ifnet *ifp, c
struct in_multi *inm;
int is_general_query;
uint16_t timer;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
is_general_query = 0;
@@ -873,7 +876,8 @@ igmp_input_v2_query(struct ifnet *ifp, c
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);
+ inet_ntoa_r(igmp->igmp_group, addrbuf), ifp,
+ ifp->if_xname);
igmp_v2_update_group(inm, timer);
}
}
@@ -903,9 +907,12 @@ out_locked:
static void
igmp_v2_update_group(struct in_multi *inm, const int timer)
{
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
CTR4(KTR_IGMPV3, "%s: %s/%s timer=%d", __func__,
- inet_ntoa(inm->inm_addr), inm->inm_ifp->if_xname, timer);
+ inet_ntoa_r(inm->inm_addr, addrbuf), inm->inm_ifp->if_xname, timer);
IN_MULTI_LOCK_ASSERT();
@@ -956,6 +963,9 @@ igmp_input_v3_query(struct ifnet *ifp, c
uint32_t maxresp, nsrc, qqi;
uint16_t timer;
uint8_t qrv;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
is_general_query = 0;
@@ -1086,7 +1096,8 @@ igmp_input_v3_query(struct ifnet *ifp, c
}
}
CTR3(KTR_IGMPV3, "process v3 %s query on ifp %p(%s)",
- inet_ntoa(igmpv3->igmp_group), ifp, ifp->if_xname);
+ inet_ntoa_r(igmpv3->igmp_group, addrbuf), ifp,
+ ifp->if_xname);
/*
* If there is a pending General Query response
* scheduled sooner than the selected delay, no
@@ -1219,6 +1230,9 @@ igmp_input_v1_report(struct ifnet *ifp,
struct rm_priotracker in_ifa_tracker;
struct in_ifaddr *ia;
struct in_multi *inm;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
IGMPSTAT_INC(igps_rcv_reports);
@@ -1247,7 +1261,7 @@ igmp_input_v1_report(struct ifnet *ifp,
}
CTR3(KTR_IGMPV3, "process v1 report %s on ifp %p(%s)",
- inet_ntoa(igmp->igmp_group), ifp, ifp->if_xname);
+ inet_ntoa_r(igmp->igmp_group, addrbuf), ifp, ifp->if_xname);
/*
* IGMPv1 report suppression.
@@ -1290,14 +1304,16 @@ igmp_input_v1_report(struct ifnet *ifp,
case IGMP_AWAKENING_MEMBER:
CTR3(KTR_IGMPV3,
"report suppressed for %s on ifp %p(%s)",
- inet_ntoa(igmp->igmp_group), ifp, ifp->if_xname);
+ inet_ntoa_r(igmp->igmp_group, addrbuf), 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);
+ inet_ntoa_r(igmp->igmp_group, addrbuf), 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)
@@ -1328,6 +1344,9 @@ igmp_input_v2_report(struct ifnet *ifp,
struct rm_priotracker in_ifa_tracker;
struct in_ifaddr *ia;
struct in_multi *inm;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
/*
* Make sure we don't hear our own membership report. Fast
@@ -1371,7 +1390,7 @@ igmp_input_v2_report(struct ifnet *ifp,
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);
+ inet_ntoa_r(igmp->igmp_group, addrbuf), ifp, ifp->if_xname);
/*
* IGMPv2 report suppression.
@@ -1412,7 +1431,8 @@ igmp_input_v2_report(struct ifnet *ifp,
case IGMP_AWAKENING_MEMBER:
CTR3(KTR_IGMPV3,
"report suppressed for %s on ifp %p(%s)",
- inet_ntoa(igmp->igmp_group), ifp, ifp->if_xname);
+ inet_ntoa_r(igmp->igmp_group, addrbuf), ifp,
+ ifp->if_xname);
case IGMP_LAZY_MEMBER:
inm->inm_state = IGMP_LAZY_MEMBER;
break;
@@ -1814,6 +1834,9 @@ igmp_v3_process_group_timers(struct igmp
{
int query_response_timer_expired;
int state_change_retransmit_timer_expired;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
IN_MULTI_LOCK_ASSERT();
IGMP_LOCK_ASSERT();
@@ -1900,7 +1923,8 @@ igmp_v3_process_group_timers(struct igmp
inm_commit(inm);
CTR3(KTR_IGMPV3, "%s: T1 -> T0 for %s/%s", __func__,
- inet_ntoa(inm->inm_addr), inm->inm_ifp->if_xname);
+ inet_ntoa_r(inm->inm_addr, addrbuf),
+ inm->inm_ifp->if_xname);
/*
* If we are leaving the group for good, make sure
@@ -2346,9 +2370,12 @@ igmp_initial_join(struct in_multi *inm,
struct ifnet *ifp;
struct mbufq *mq;
int error, retval, syncstates;
-
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
+
CTR4(KTR_IGMPV3, "%s: initial join %s on ifp %p(%s)",
- __func__, inet_ntoa(inm->inm_addr), inm->inm_ifp,
+ __func__, inet_ntoa_r(inm->inm_addr, addrbuf), inm->inm_ifp,
inm->inm_ifp->if_xname);
error = 0;
@@ -2459,7 +2486,8 @@ igmp_initial_join(struct in_multi *inm,
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);
+ inet_ntoa_r(inm->inm_addr, addrbuf),
+ inm->inm_ifp->if_xname);
}
return (error);
@@ -2473,9 +2501,12 @@ igmp_handle_state_change(struct in_multi
{
struct ifnet *ifp;
int retval;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
CTR4(KTR_IGMPV3, "%s: state change for %s on ifp %p(%s)",
- __func__, inet_ntoa(inm->inm_addr), inm->inm_ifp,
+ __func__, inet_ntoa_r(inm->inm_addr, addrbuf), inm->inm_ifp,
inm->inm_ifp->if_xname);
ifp = inm->inm_ifp;
@@ -2496,7 +2527,8 @@ igmp_handle_state_change(struct in_multi
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);
+ inet_ntoa_r(inm->inm_addr, addrbuf),
+ inm->inm_ifp->if_xname);
return (0);
}
@@ -2531,11 +2563,14 @@ static void
igmp_final_leave(struct in_multi *inm, struct igmp_ifsoftc *igi)
{
int syncstates;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
syncstates = 1;
CTR4(KTR_IGMPV3, "%s: final leave %s on ifp %p(%s)",
- __func__, inet_ntoa(inm->inm_addr), inm->inm_ifp,
+ __func__, inet_ntoa_r(inm->inm_addr, addrbuf), inm->inm_ifp,
inm->inm_ifp->if_xname);
IN_MULTI_LOCK_ASSERT();
@@ -2578,7 +2613,7 @@ igmp_final_leave(struct in_multi *inm, s
}
CTR4(KTR_IGMPV3, "%s: Leaving %s/%s with %d "
"pending retransmissions.", __func__,
- inet_ntoa(inm->inm_addr),
+ inet_ntoa_r(inm->inm_addr, addrbuf),
inm->inm_ifp->if_xname, inm->inm_scrv);
if (inm->inm_scrv == 0) {
inm->inm_state = IGMP_NOT_MEMBER;
@@ -2612,10 +2647,12 @@ igmp_final_leave(struct in_multi *inm, s
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);
+ inet_ntoa_r(inm->inm_addr, addrbuf),
+ 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);
+ __func__, inet_ntoa_r(inm->inm_addr, addrbuf),
+ inm->inm_ifp->if_xname);
}
}
@@ -2663,6 +2700,9 @@ igmp_v3_enqueue_group_record(struct mbuf
int type;
in_addr_t naddr;
uint8_t mode;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
IN_MULTI_LOCK_ASSERT();
@@ -2741,7 +2781,7 @@ igmp_v3_enqueue_group_record(struct mbuf
if (type == IGMP_DO_NOTHING) {
CTR3(KTR_IGMPV3, "%s: nothing to do for %s/%s",
- __func__, inet_ntoa(inm->inm_addr),
+ __func__, inet_ntoa_r(inm->inm_addr, addrbuf),
inm->inm_ifp->if_xname);
return (0);
}
@@ -2756,7 +2796,7 @@ igmp_v3_enqueue_group_record(struct mbuf
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),
+ igmp_rec_type_to_str(type), inet_ntoa_r(inm->inm_addr, addrbuf),
inm->inm_ifp->if_xname);
/*
@@ -2845,7 +2885,7 @@ igmp_v3_enqueue_group_record(struct mbuf
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));
+ inet_ntoa_haddr(ims->ims_haddr, addrbuf));
now = ims_get_mode(inm, ims, 1);
CTR2(KTR_IGMPV3, "%s: node is %d", __func__, now);
if ((now != mode) ||
@@ -2941,7 +2981,7 @@ igmp_v3_enqueue_group_record(struct mbuf
msrcs = 0;
RB_FOREACH_FROM(ims, ip_msource_tree, nims) {
CTR2(KTR_IGMPV3, "%s: visit node %s", __func__,
- inet_ntoa_haddr(ims->ims_haddr));
+ inet_ntoa_haddr(ims->ims_haddr, addrbuf));
now = ims_get_mode(inm, ims, 1);
if ((now != mode) ||
(now == mode && mode == MCAST_UNDEFINED)) {
@@ -3024,6 +3064,9 @@ igmp_v3_enqueue_filter_change(struct mbu
int nallow, nblock;
uint8_t mode, now, then;
rectype_t crt, drt, nrt;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
IN_MULTI_LOCK_ASSERT();
@@ -3133,7 +3176,8 @@ igmp_v3_enqueue_filter_change(struct mbu
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));
+ __func__,
+ inet_ntoa_haddr(ims->ims_haddr, addrbuf));
now = ims_get_mode(inm, ims, 1);
then = ims_get_mode(inm, ims, 0);
CTR3(KTR_IGMPV3, "%s: mode: t0 %d, t1 %d",
Modified: head/sys/netinet/in.c
==============================================================================
--- head/sys/netinet/in.c Thu Feb 16 20:44:44 2017 (r313820)
+++ head/sys/netinet/in.c Thu Feb 16 20:47:41 2017 (r313821)
@@ -1218,7 +1218,7 @@ in_lltable_rtcheck(struct ifnet *ifp, u_
*/
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;
/*
@@ -1230,14 +1230,17 @@ in_lltable_rtcheck(struct ifnet *ifp, u_
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);
}
Modified: head/sys/netinet/in_mcast.c
==============================================================================
--- head/sys/netinet/in_mcast.c Thu Feb 16 20:44:44 2017 (r313820)
+++ head/sys/netinet/in_mcast.c Thu Feb 16 20:47:41 2017 (r313821)
@@ -495,9 +495,12 @@ in_getmulti(struct ifnet *ifp, const str
("%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;
@@ -875,7 +878,8 @@ inm_get_source(struct in_multi *inm, con
struct ip_msource find;
struct ip_msource *ims, *nims;
#ifdef KTR
- struct in_addr ia;
+ struct in_addr ia;
+ char addrbuf[INET_ADDRSTRLEN];
#endif
find.ims_haddr = haddr;
@@ -894,7 +898,7 @@ inm_get_source(struct in_multi *inm, con
#ifdef KTR
ia.s_addr = htonl(haddr);
CTR3(KTR_IGMPV3, "%s: allocated %s as %p", __func__,
- inet_ntoa(ia), ims);
+ inet_ntoa_r(ia, addrbuf), ims);
#endif
}
@@ -912,6 +916,7 @@ ims_merge(struct ip_msource *ims, const
{
int n = rollback ? -1 : 1;
#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
struct in_addr ia;
ia.s_addr = htonl(ims->ims_haddr);
@@ -919,21 +924,21 @@ ims_merge(struct ip_msource *ims, const
if (lims->imsl_st[0] == MCAST_EXCLUDE) {
CTR3(KTR_IGMPV3, "%s: t1 ex -= %d on %s",
- __func__, n, inet_ntoa(ia));
+ __func__, n, inet_ntoa_r(ia, addrbuf));
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));
+ __func__, n, inet_ntoa_r(ia, addrbuf));
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));
+ __func__, n, inet_ntoa_r(ia, addrbuf));
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));
+ __func__, n, inet_ntoa_r(ia, addrbuf));
ims->ims_st[1].in += n;
}
}
@@ -1166,11 +1171,14 @@ in_joingroup_locked(struct ifnet *ifp, c
struct in_mfilter timf;
struct in_multi *inm;
int error;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
IN_MULTI_LOCK_ASSERT();
CTR4(KTR_IGMPV3, "%s: join %s on %p(%s))", __func__,
- inet_ntoa(*gina), ifp, ifp->if_xname);
+ inet_ntoa_r(*gina, addrbuf), ifp, ifp->if_xname);
error = 0;
inm = NULL;
@@ -1248,13 +1256,16 @@ in_leavegroup_locked(struct in_multi *in
{
struct in_mfilter timf;
int error;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
error = 0;
IN_MULTI_LOCK_ASSERT();
CTR5(KTR_IGMPV3, "%s: leave inm %p, %s/%s, imf %p", __func__,
- inm, inet_ntoa(inm->inm_addr),
+ inm, inet_ntoa_r(inm->inm_addr, addrbuf),
(inm_is_ifp_detached(inm) ? "null" : inm->inm_ifp->if_xname),
imf);
@@ -1302,9 +1313,13 @@ in_addmulti(struct in_addr *ap, struct i
{
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)
@@ -1349,6 +1364,9 @@ inp_block_unblock_source(struct inpcb *i
size_t idx;
uint16_t fmode;
int error, doblock;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
ifp = NULL;
error = 0;
@@ -1384,7 +1402,7 @@ inp_block_unblock_source(struct inpcb *i
doblock = 1;
CTR3(KTR_IGMPV3, "%s: imr_interface = %s, ifp = %p",
- __func__, inet_ntoa(mreqs.imr_interface), ifp);
+ __func__, inet_ntoa_r(mreqs.imr_interface, addrbuf), ifp);
break;
}
@@ -1457,7 +1475,8 @@ inp_block_unblock_source(struct inpcb *i
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 ");
+ inet_ntoa_r(ssa->sin.sin_addr, addrbuf),
+ doblock ? "" : "not ");
error = EADDRNOTAVAIL;
goto out_inp_locked;
}
@@ -1934,6 +1953,9 @@ inp_join_group(struct inpcb *inp, struct
struct in_msource *lims;
size_t idx;
int error, is_new;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
ifp = NULL;
imf = NULL;
@@ -1986,7 +2008,7 @@ inp_join_group(struct inpcb *inp, struct
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);
+ __func__, inet_ntoa_r(mreqs.imr_interface, addrbuf), ifp);
break;
}
@@ -2233,6 +2255,9 @@ inp_leave_group(struct inpcb *inp, struc
struct in_multi *inm;
size_t idx;
int error, is_final;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
ifp = NULL;
error = 0;
@@ -2287,7 +2312,7 @@ inp_leave_group(struct inpcb *inp, struc
INADDR_TO_IFP(mreqs.imr_interface, ifp);
CTR3(KTR_IGMPV3, "%s: imr_interface = %s, ifp = %p",
- __func__, inet_ntoa(mreqs.imr_interface), ifp);
+ __func__, inet_ntoa_r(mreqs.imr_interface, addrbuf), ifp);
break;
@@ -2368,7 +2393,7 @@ inp_leave_group(struct inpcb *inp, struc
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 ");
+ inet_ntoa_r(ssa->sin.sin_addr, addrbuf), "not ");
error = EADDRNOTAVAIL;
goto out_inp_locked;
}
@@ -2450,6 +2475,9 @@ inp_set_multicast_if(struct inpcb *inp,
struct ifnet *ifp;
struct ip_moptions *imo;
int error;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
if (sopt->sopt_valsize == sizeof(struct ip_mreqn)) {
/*
@@ -2488,7 +2516,7 @@ inp_set_multicast_if(struct inpcb *inp,
return (EADDRNOTAVAIL);
}
CTR3(KTR_IGMPV3, "%s: ifp = %p, addr = %s", __func__, ifp,
- inet_ntoa(addr));
+ inet_ntoa_r(addr, addrbuf));
}
/* Reject interfaces which do not support multicast. */
@@ -2846,6 +2874,9 @@ sysctl_ip_mcast_filters(SYSCTL_HANDLER_A
int retval;
u_int namelen;
uint32_t fmode, ifindex;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
name = (int *)arg1;
namelen = arg2;
@@ -2866,7 +2897,7 @@ sysctl_ip_mcast_filters(SYSCTL_HANDLER_A
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));
+ __func__, inet_ntoa_r(group, addrbuf));
return (EINVAL);
}
@@ -2901,7 +2932,7 @@ sysctl_ip_mcast_filters(SYSCTL_HANDLER_A
struct in_addr ina;
ina.s_addr = htonl(ims->ims_haddr);
CTR2(KTR_IGMPV3, "%s: visit node %s", __func__,
- inet_ntoa(ina));
+ inet_ntoa_r(ina, addrbuf));
#endif
/*
* Only copy-out sources which are in-mode.
@@ -2965,13 +2996,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);
Modified: head/sys/netinet/ip_icmp.c
==============================================================================
--- head/sys/netinet/ip_icmp.c Thu Feb 16 20:44:44 2017 (r313820)
+++ head/sys/netinet/ip_icmp.c Thu Feb 16 20:47:41 2017 (r313821)
@@ -380,10 +380,12 @@ icmp_input(struct mbuf **mp, int *offp,
*/
#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) {
@@ -649,11 +651,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;
@@ -901,10 +904,12 @@ icmp_send(struct mbuf *m, struct mbuf *o
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);
Modified: head/sys/netinet/ip_mroute.c
==============================================================================
--- head/sys/netinet/ip_mroute.c Thu Feb 16 20:44:44 2017 (r313820)
+++ head/sys/netinet/ip_mroute.c Thu Feb 16 20:47:41 2017 (r313821)
@@ -845,6 +845,9 @@ add_vif(struct vifctl *vifcp)
struct ifaddr *ifa;
struct ifnet *ifp;
int error;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
VIF_LOCK();
if (vifcp->vifc_vifi >= MAXVIFS) {
@@ -929,7 +932,7 @@ 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),
+ (int)vifcp->vifc_vifi, inet_ntoa_r(vifcp->vifc_lcl_addr, addrbuf),
(int)vifcp->vifc_threshold);
return 0;
@@ -1052,6 +1055,9 @@ add_mfc(struct mfcctl2 *mfccp)
struct rtdetq *rte, *nrte;
u_long hash = 0;
u_short nstl;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
VIF_LOCK();
MFC_LOCK();
@@ -1061,7 +1067,7 @@ 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),
+ __func__, inet_ntoa_r(mfccp->mfcc_origin, addrbuf),
(u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
mfccp->mfcc_parent);
update_mfc_params(rt, mfccp);
@@ -1081,7 +1087,7 @@ add_mfc(struct mfcctl2 *mfccp)
!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),
+ __func__, inet_ntoa_r(mfccp->mfcc_origin, addrbuf),
(u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
mfccp->mfcc_parent,
TAILQ_FIRST(&rt->mfc_stall));
@@ -1155,12 +1161,15 @@ del_mfc(struct mfcctl2 *mfccp)
struct in_addr origin;
struct in_addr mcastgrp;
struct mfc *rt;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
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));
+ inet_ntoa_r(origin, addrbuf), (u_long)ntohl(mcastgrp.s_addr));
MFC_LOCK();
@@ -1223,9 +1232,13 @@ X_ip_mforward(struct ip *ip, struct ifne
struct mfc *rt;
int error;
vifi_t vifi;
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
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);
+ inet_ntoa_r(ip->ip_src, addrbuf), (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 ) {
@@ -1288,7 +1301,7 @@ X_ip_mforward(struct ip *ip, struct ifne
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));
+ inet_ntoa_r(ip->ip_src, addrbuf), (u_long)ntohl(ip->ip_dst.s_addr));
/*
* Allocate mbufs early so that we don't do extra work if we are
@@ -2570,7 +2583,10 @@ pim_input(struct mbuf **mp, int *offp, i
int minlen;
int datalen = ntohs(ip->ip_len) - iphlen;
int ip_tos;
-
+#ifdef KTR
+ char addrbuf[INET_ADDRSTRLEN];
+#endif
+
*mp = NULL;
/* Keep statistics */
@@ -2583,7 +2599,7 @@ pim_input(struct mbuf **mp, int *offp, i
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));
+ __func__, datalen, inet_ntoa_r(ip->ip_src, addrbuf));
m_freem(m);
return (IPPROTO_DONE);
}
@@ -2683,7 +2699,8 @@ pim_input(struct mbuf **mp, int *offp, i
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));
+ __func__, inet_ntoa_r(encap_ip->ip_src, addrbuf),
+ ntohs(encap_ip->ip_len));
/* verify the version number of the inner packet */
if (encap_ip->ip_v != IPVERSION) {
@@ -2697,7 +2714,7 @@ pim_input(struct mbuf **mp, int *offp, i
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));
+ inet_ntoa_r(encap_ip->ip_dst, addrbuf));
m_freem(m);
return (IPPROTO_DONE);
}
Modified: head/sys/netinet/ip_options.c
==============================================================================
--- head/sys/netinet/ip_options.c Thu Feb 16 20:44:44 2017 (r313820)
+++ head/sys/netinet/ip_options.c Thu Feb 16 20:47:41 2017 (r313821)
@@ -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",
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-src-all
mailing list