Module Name:    src
Committed By:   christos
Date:           Tue Dec  2 20:25:48 UTC 2014

Modified Files:
        src/sys/net: rtsock.c
        src/sys/netinet: in.h ip_icmp.c portalgo.c tcp_input.c
        src/sys/netinet6: in6.h

Log Message:
use the new printing code.


To generate a diff of this commit:
cvs rdiff -u -r1.164 -r1.165 src/sys/net/rtsock.c
cvs rdiff -u -r1.94 -r1.95 src/sys/netinet/in.h
cvs rdiff -u -r1.134 -r1.135 src/sys/netinet/ip_icmp.c
cvs rdiff -u -r1.6 -r1.7 src/sys/netinet/portalgo.c
cvs rdiff -u -r1.334 -r1.335 src/sys/netinet/tcp_input.c
cvs rdiff -u -r1.80 -r1.81 src/sys/netinet6/in6.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/rtsock.c
diff -u src/sys/net/rtsock.c:1.164 src/sys/net/rtsock.c:1.165
--- src/sys/net/rtsock.c:1.164	Fri Sep  5 02:00:05 2014
+++ src/sys/net/rtsock.c	Tue Dec  2 15:25:48 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtsock.c,v 1.164 2014/09/05 06:00:05 matt Exp $	*/
+/*	$NetBSD: rtsock.c,v 1.165 2014/12/02 20:25:48 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.164 2014/09/05 06:00:05 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.165 2014/12/02 20:25:48 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -131,6 +131,11 @@ DOMAIN_DEFINE(routedomain); /* forward d
 #define	COMPATCALL(name, args)	do { } while (/*CONSTCOND*/ 0)
 #endif
 
+#ifdef RTSOCK_DEBUG
+#define RT_IN_PRINT(b, a) (in_print((b), sizeof(b), \
+    &((const struct sockaddr_in *)info.rti_info(a))->sin_addr), (b))
+#endif /* RTSOCK_DEBUG */
+
 struct route_info COMPATNAME(route_info) = {
 	.ri_dst = { .sa_len = 2, .sa_family = PF_XROUTE, },
 	.ri_src = { .sa_len = 2, .sa_family = PF_XROUTE, },
@@ -493,9 +498,9 @@ COMPATNAME(route_output)(struct mbuf *m,
 	info.rti_flags = rtm->rtm_flags;
 #ifdef RTSOCK_DEBUG
 	if (info.rti_info[RTAX_DST]->sa_family == AF_INET) {
+		char abuf[INET_ADDRSTRLEN];
 		printf("%s: extracted info.rti_info[RTAX_DST] %s\n", __func__,
-		    inet_ntoa(((const struct sockaddr_in *)
-		    info.rti_info[RTAX_DST])->sin_addr));
+		    RT_IN_PRINT(abuf, RTAX_DST));
 	}
 #endif /* RTSOCK_DEBUG */
 	if (info.rti_info[RTAX_DST] == NULL ||
@@ -577,16 +582,14 @@ COMPATNAME(route_output)(struct mbuf *m,
 #ifdef RTSOCK_DEBUG
 				if (info.rti_info[RTAX_IFA]->sa_family ==
 				    AF_INET) {
+					char ibuf[INET_ADDRSTRLEN];
+					char abuf[INET_ADDRSTRLEN];
 					printf("%s: copying out RTAX_IFA %s ",
-					    __func__, inet_ntoa(
-					    ((const struct sockaddr_in *)
-					    info.rti_info[RTAX_IFA])->sin_addr)
-					    );
-					printf("for info.rti_info[RTAX_DST] %s "
+					    "for info.rti_info[RTAX_DST] %s "
 					    "ifa_getifa %p ifa_seqno %p\n",
-					    inet_ntoa(
-					    ((const struct sockaddr_in *)
-					    info.rti_info[RTAX_DST])->sin_addr),
+					    __func__,
+					    RT_IN_PRINT(ibuf, RTAX_IFA),
+					    RT_IN_PRINT(abuf, RTAX_DST),
 					    (void *)rtifa->ifa_getifa,
 					    rtifa->ifa_seqno);
 				}

Index: src/sys/netinet/in.h
diff -u src/sys/netinet/in.h:1.94 src/sys/netinet/in.h:1.95
--- src/sys/netinet/in.h:1.94	Tue Dec  2 14:35:27 2014
+++ src/sys/netinet/in.h	Tue Dec  2 15:25:47 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.h,v 1.94 2014/12/02 19:35:27 christos Exp $	*/
+/*	$NetBSD: in.h,v 1.95 2014/12/02 20:25:47 christos Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -618,6 +618,7 @@ sockaddr_in_alloc(const struct in_addr *
 
 #if defined(_KERNEL) || defined(_TEST)
 int	in_print(char *, size_t, const struct in_addr *);
+#define IN_PRINT(b, a)	(in_print((b), sizeof(b), a), (b))
 int	sin_print(char *, size_t, const void *);
 #endif
 

Index: src/sys/netinet/ip_icmp.c
diff -u src/sys/netinet/ip_icmp.c:1.134 src/sys/netinet/ip_icmp.c:1.135
--- src/sys/netinet/ip_icmp.c:1.134	Thu May 29 21:39:03 2014
+++ src/sys/netinet/ip_icmp.c	Tue Dec  2 15:25:47 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_icmp.c,v 1.134 2014/05/30 01:39:03 christos Exp $	*/
+/*	$NetBSD: ip_icmp.c,v 1.135 2014/12/02 20:25:47 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -94,7 +94,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_icmp.c,v 1.134 2014/05/30 01:39:03 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_icmp.c,v 1.135 2014/12/02 20:25:47 christos Exp $");
 
 #include "opt_ipsec.h"
 
@@ -408,8 +408,10 @@ icmp_input(struct mbuf *m, ...)
 	icmplen = ntohs(ip->ip_len) - hlen;
 #ifdef ICMPPRINTFS
 	if (icmpprintfs) {
-		printf("icmp_input from `%s' to ", inet_ntoa(ip->ip_src));
-		printf("`%s', len %d\n", inet_ntoa(ip->ip_dst), icmplen);
+		char sbuf[INET_ADDRSTRLEN], dbuf[INET_ADDRSTRLEN];
+		printf("icmp_input from `%s' to `%s', len %d\n",
+		    IN_PRINT(sbuf, &ip->ip_src), IN_PRINT(dbuf, &ip->ip_dst),
+		    icmplen);
 	}
 #endif
 	if (icmplen < ICMP_MINLEN) {
@@ -615,9 +617,10 @@ reflect:
 		icmpdst.sin_addr = icp->icmp_gwaddr;
 #ifdef	ICMPPRINTFS
 		if (icmpprintfs) {
+			char gbuf[INET_ADDRSTRLEN], dbuf[INET_ADDRSTRLEN];
 			printf("redirect dst `%s' to `%s'\n",
-			    inet_ntoa(icp->icmp_ip.ip_dst),
-			    inet_ntoa(icp->icmp_gwaddr));
+			    IN_PRINT(dbuf, &icp->icmp_ip.ip_dst),
+			    IN_PRINT(gbuf, &icp->icmp_gwaddr));
 		}
 #endif
 		icmpsrc.sin_addr = icp->icmp_ip.ip_dst;
@@ -627,11 +630,13 @@ reflect:
 		if (rt != NULL && icmp_redirtimeout != 0) {
 			i = rt_timer_add(rt, icmp_redirect_timeout,
 					 icmp_redirect_timeout_q);
-			if (i)
+			if (i) {
+				char buf[INET_ADDRSTRLEN];
 				log(LOG_ERR, "ICMP:  redirect failed to "
-				    "register timeout for route to %x, "
+				    "register timeout for route to %s, "
 				    "code %d\n",
-				    icp->icmp_ip.ip_dst.s_addr, i);
+				    IN_PRINT(buf, &icp->icmp_ip.ip_dst), i);
+			}
 		}
 		if (rt != NULL)
 			rtfree(rt);
@@ -898,8 +903,9 @@ icmp_send(struct mbuf *m, struct mbuf *o
 	m->m_len += hlen;
 #ifdef ICMPPRINTFS
 	if (icmpprintfs) {
+		char sbuf[INET_ADDRSTRLEN], dbuf[INET_ADDRSTRLEN];
 		printf("icmp_send to destination `%s' from `%s'\n",
-		    inet_ntoa(ip->ip_dst), inet_ntoa(ip->ip_src));
+		    IN_PRINT(dbuf, &ip->ip_dst), IN_PRINT(sbuf, &ip->ip_src));
 	}
 #endif
 	(void)ip_output(m, opts, NULL, 0, NULL, NULL);

Index: src/sys/netinet/portalgo.c
diff -u src/sys/netinet/portalgo.c:1.6 src/sys/netinet/portalgo.c:1.7
--- src/sys/netinet/portalgo.c:1.6	Mon Sep  8 13:40:02 2014
+++ src/sys/netinet/portalgo.c	Tue Dec  2 15:25:47 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: portalgo.c,v 1.6 2014/09/08 17:40:02 joerg Exp $	*/
+/*	$NetBSD: portalgo.c,v 1.7 2014/12/02 20:25:47 christos Exp $	*/
 
 /*
  * Copyright 2011 Vlad Balan
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: portalgo.c,v 1.6 2014/09/08 17:40:02 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: portalgo.c,v 1.7 2014/12/02 20:25:47 christos Exp $");
 
 #include "opt_inet.h"
 
@@ -796,21 +796,24 @@ portalgo_randport(uint16_t *port, struct
 	switch (inp_hdr->inph_af) {
 #ifdef INET
 	case AF_INET: {
+		char buf[INET_ADDRSTRLEN];
 		struct inpcb *inp = (struct inpcb *)(void *)inp_hdr;
-		DPRINTF("local addr: %s\n", inet_ntoa(inp->inp_laddr));
+		DPRINTF("local addr: %s\n", IN_PRINT(buf, &inp->inp_laddr));
 		DPRINTF("local port: %d\n", inp->inp_lport);
-		DPRINTF("foreign addr: %s\n", inet_ntoa(inp->inp_faddr));
+		DPRINTF("foreign addr: %s\n", IN_PRINT(buf, &inp->inp_faddr));
 		DPRINTF("foreign port: %d\n", inp->inp_fport);
 		break;
 	}
 #endif
 #ifdef INET6
 	case AF_INET6: {
+		char buf[INET6_ADDRSTRLEN];
 		struct in6pcb *in6p = (struct in6pcb *)(void *)inp_hdr;
 
-		DPRINTF("local addr: %s\n", ip6_sprintf(&in6p->in6p_laddr));
+		DPRINTF("local addr: %s\n", IN6_PRINT(buf, &in6p->in6p_laddr));
 		DPRINTF("local port: %d\n", in6p->in6p_lport);
-		DPRINTF("foreign addr: %s\n", ip6_sprintf(&in6p->in6p_faddr));
+		DPRINTF("foreign addr: %s\n", IN6_PRINT(buf,
+		    &in6p->in6p_laddr));
 		DPRINTF("foreign port: %d\n", in6p->in6p_fport);
 		break;
 	}

Index: src/sys/netinet/tcp_input.c
diff -u src/sys/netinet/tcp_input.c:1.334 src/sys/netinet/tcp_input.c:1.335
--- src/sys/netinet/tcp_input.c:1.334	Thu Aug  7 23:05:45 2014
+++ src/sys/netinet/tcp_input.c	Tue Dec  2 15:25:47 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_input.c,v 1.334 2014/08/08 03:05:45 rtr Exp $	*/
+/*	$NetBSD: tcp_input.c,v 1.335 2014/12/02 20:25:47 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.334 2014/08/08 03:05:45 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.335 2014/12/02 20:25:47 christos Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -845,12 +845,12 @@ tcp6_input(struct mbuf **mp, int *offp, 
 static void
 tcp4_log_refused(const struct ip *ip, const struct tcphdr *th)
 {
-	char src[4*sizeof "123"];
-	char dst[4*sizeof "123"];
+	char src[INET_ADDRSTRLEN];
+	char dst[INET_ADDRSTRLEN];
 
 	if (ip) {
-		strlcpy(src, inet_ntoa(ip->ip_src), sizeof(src));
-		strlcpy(dst, inet_ntoa(ip->ip_dst), sizeof(dst));
+		in_print(src, sizeof(src), &ip->ip_src);
+		in_print(dst, sizeof(dst), &ip->ip_dst);
 	}
 	else {
 		strlcpy(src, "(unknown)", sizeof(src));
@@ -871,8 +871,8 @@ tcp6_log_refused(const struct ip6_hdr *i
 	char dst[INET6_ADDRSTRLEN];
 
 	if (ip6) {
-		strlcpy(src, ip6_sprintf(&ip6->ip6_src), sizeof(src));
-		strlcpy(dst, ip6_sprintf(&ip6->ip6_dst), sizeof(dst));
+		in6_print(src, sizeof(src), &ip6->ip6_src);
+		in6_print(dst, sizeof(dst), &ip6->ip6_dst);
 	}
 	else {
 		strlcpy(src, "(unknown v6)", sizeof(src));
@@ -3312,27 +3312,25 @@ tcp_dooptions(struct tcpcb *tp, const u_
 			tp->t_flags |= TF_RCVD_SCALE;
 			tp->requested_s_scale = cp[2];
 			if (tp->requested_s_scale > TCP_MAX_WINSHIFT) {
-#if 0	/*XXX*/
-				char *p;
-
+				char buf[INET6_ADDRSTRLEN];
+				struct ip *ip = mtod(m, struct ip *);
+#ifdef INET6
+				struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
+#endif
 				if (ip)
-					p = ntohl(ip->ip_src);
+					in_print(buf, sizeof(buf),
+					    &ip->ip_src);
 #ifdef INET6
 				else if (ip6)
-					p = ip6_sprintf(&ip6->ip6_src);
+					in6_print(buf, sizeof(buf),
+					    &ip6->ip6_src);
 #endif
 				else
-					p = "(unknown)";
+					strlcpy(buf, "(unknown)", sizeof(buf));
 				log(LOG_ERR, "TCP: invalid wscale %d from %s, "
 				    "assuming %d\n",
-				    tp->requested_s_scale, p,
+				    tp->requested_s_scale, buf,
 				    TCP_MAX_WINSHIFT);
-#else
-				log(LOG_ERR, "TCP: invalid wscale %d, "
-				    "assuming %d\n",
-				    tp->requested_s_scale,
-				    TCP_MAX_WINSHIFT);
-#endif
 				tp->requested_s_scale = TCP_MAX_WINSHIFT;
 			}
 			break;

Index: src/sys/netinet6/in6.h
diff -u src/sys/netinet6/in6.h:1.80 src/sys/netinet6/in6.h:1.81
--- src/sys/netinet6/in6.h:1.80	Tue Dec  2 14:36:58 2014
+++ src/sys/netinet6/in6.h	Tue Dec  2 15:25:48 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.h,v 1.80 2014/12/02 19:36:58 christos Exp $	*/
+/*	$NetBSD: in6.h,v 1.81 2014/12/02 20:25:48 christos Exp $	*/
 /*	$KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $	*/
 
 /*
@@ -820,6 +820,7 @@ __END_DECLS
 
 #if defined(_KERNEL) || defined(_TEST)
 int	in6_print(char *, size_t, const struct in6_addr *);
+#define IN6_PRINT(b, a) (in6_print((b), sizeof(b), (a)), (b))
 int	sin6_print(char *, size_t, const void *);
 #endif
 

Reply via email to