Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 May 2010 17:29:41 GMT
From:      Gabor Pali <pgj@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 177839 for review
Message-ID:  <201005061729.o46HTf01046366@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@177839?ac=10

Change 177839 by pgj@csupor on 2010/05/06 17:28:48

	Use <net/stat.h> and move timestamp_type there to remove the temporary
	hack that I introduced to fix strict-aliasing issues.

Affected files ...

.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#65 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_stat.c#29 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#74 edit
.. //depot/projects/soc2009/pgj_libstat/src/sys/net/stat.h#2 edit
.. //depot/projects/soc2009/pgj_libstat/src/sys/netinet/sctp_constants.h#4 edit
.. //depot/projects/soc2009/pgj_libstat/src/sys/netinet/sctp_pcb.c#5 edit
.. //depot/projects/soc2009/pgj_libstat/src/sys/netinet/sctp_sysctl.c#6 edit
.. //depot/projects/soc2009/pgj_libstat/src/sys/netinet/sctp_uio.h#6 edit

Differences ...

==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#65 (text+ko) ====

@@ -38,6 +38,7 @@
 #include <kvm.h>
 #include <net/if.h>
 #include <net/route.h>
+#include <net/stat.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
 #include <netinet/ip_var.h>
@@ -319,12 +320,6 @@
 	struct bpf_type		*bpti_next;
 };
 
-/* Timestamp type. */
-struct timestamp_type {
-	u_int32_t   ts_sec;
-	u_int32_t   ts_usec;
-};
-
 /* General statistics type. */
 struct stat_type {
 	enum stat   stt_type;
@@ -366,8 +361,7 @@
 
 #ifdef SCTP
 struct sctp_stat {
-	struct timestamp_type discontinuitytime;
-	struct sctpstat *s;
+	struct sctpstat s;
 };
 #endif
 

==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_stat.c#29 (text+ko) ====

@@ -29,7 +29,6 @@
 #include <sys/types.h>
 #include <sys/sysctl.h>
 
-#include <net/stat.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
 #include <netinet/ip_var.h>
@@ -205,24 +204,6 @@
 		break;
 #endif /* !IPSEC */
 
-	/*
-	 * XXX : Try to avoid breaking strict aliasing rules, but it might not be
-	 * the best solution.
-	 */ 
-
-#ifdef SCTP
-	case stat_SCTP:
-		sttp->stt_data = malloc(sizeof(struct sctp_stat));
-		if (sttp->stt_data == NULL) {
-			sttp->stt_error = NETSTAT_ERROR_NOMEMORY;
-			free(buffer);
-			return(-1);
-		}
-		((struct sctp_stat *)sttp->stt_data)->discontinuitytime.ts_sec  = ((struct sctpstat *)buffer)->sctps_discontinuitytime.tv_sec;
-		((struct sctp_stat *)sttp->stt_data)->discontinuitytime.ts_usec = ((struct sctpstat *)buffer)->sctps_discontinuitytime.tv_usec;
-		((struct sctp_stat *)sttp->stt_data)->s = (struct sctpstat *)buffer;
-		break;
-#endif /* !SCTP */
 	default:
 		sttp->stt_data = buffer;
 	}

==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#74 (text+ko) ====

@@ -1656,12 +1656,12 @@
 
 #ifdef SCTP
 #define SCTP_ACC(field) \
-    STATS_ACCP(u_int32_t,sctp,field)
+    STATS_ACC(u_int32_t,sctp,field)
 
 const struct timestamp_type *
-netstat_sctps_get_discontinuitytime(const struct sctp_stat *ssp)
+netstat_sctps_get_discontinuitytime(const struct sctp_stat *a)
 {
-	return &ssp->discontinuitytime;
+	return &a->s.sctps_discontinuitytime;
 }
 
 STATS_GET(sctp,SCTP);

==== //depot/projects/soc2009/pgj_libstat/src/sys/net/stat.h#2 (text+ko) ====

@@ -34,4 +34,10 @@
 	const u_int32_t	sth_len;
 };
 
+/* Timestamp type. */
+struct timestamp_type {
+	u_int32_t   ts_sec;
+	u_int32_t   ts_usec;
+};
+
 #endif /* !_NET_STAT_H_ */

==== //depot/projects/soc2009/pgj_libstat/src/sys/netinet/sctp_constants.h#4 (text+ko) ====

@@ -1009,8 +1009,8 @@
 #endif
 /*#if defined(__FreeBSD__) || defined(__APPLE__)*/
 /*#define SCTP_GETTIME_TIMEVAL(x) { \*/
-/*	(x)->tv_sec = ticks / 1000; \*/
-/*	(x)->tv_usec = (ticks % 1000) * 1000; \*/
+/*	(x)->ts_sec = ticks / 1000; \*/
+/*	(x)->ts_usec = (ticks % 1000) * 1000; \*/
 /*}*/
 
 /*#else*/

==== //depot/projects/soc2009/pgj_libstat/src/sys/netinet/sctp_pcb.c#5 (text+ko) ====

@@ -5426,11 +5426,11 @@
 #endif
 	(void)SCTP_GETTIME_TIMEVAL(&tv);
 #if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
-	SCTP_BASE_STATS[PCPU_GET(cpuid)].sctps_discontinuitytime.tv_sec = (uint32_t) tv.tv_sec;
-	SCTP_BASE_STATS[PCPU_GET(cpuid)].sctps_discontinuitytime.tv_usec = (uint32_t) tv.tv_usec;
+	SCTP_BASE_STATS[PCPU_GET(cpuid)].sctps_discontinuitytime.ts_sec = (u_int32_t) tv.tv_sec;
+	SCTP_BASE_STATS[PCPU_GET(cpuid)].sctps_discontinuitytime.ts_usec = (u_int32_t) tv.tv_usec;
 #else
-	SCTP_BASE_STAT(sctps_discontinuitytime).tv_sec = (uint32_t) tv.tv_sec;
-	SCTP_BASE_STAT(sctps_discontinuitytime).tv_usec = (uint32_t) tv.tv_usec;
+	SCTP_BASE_STAT(sctps_discontinuitytime).ts_sec = (u_int32_t) tv.tv_sec;
+	SCTP_BASE_STAT(sctps_discontinuitytime).ts_usec = (u_int32_t) tv.tv_usec;
 #endif
 	/* init the empty list of (All) Endpoints */
 	LIST_INIT(&SCTP_BASE_INFO(listhead));

==== //depot/projects/soc2009/pgj_libstat/src/sys/netinet/sctp_sysctl.c#6 (text+ko) ====

@@ -286,8 +286,8 @@
 				continue;
 			memset((void *)&xladdr, 0, sizeof(struct xsctp_laddr));
 			memcpy((void *)&xladdr.address, (const void *)&laddr->ifa->address, sizeof(union sctp_sockstore));
-			xladdr.start_time.tv_sec = (uint32_t) laddr->start_time.tv_sec;
-			xladdr.start_time.tv_usec = (uint32_t) laddr->start_time.tv_usec;
+			xladdr.start_time.ts_sec = (u_int32_t) laddr->start_time.tv_sec;
+			xladdr.start_time.ts_usec = (u_int32_t) laddr->start_time.tv_usec;
 			SCTP_INP_RUNLOCK(inp);
 			SCTP_INP_INFO_RUNLOCK();
 			error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
@@ -423,10 +423,10 @@
 			xstcb.T1_expireries = stcb->asoc.timoinit + stcb->asoc.timocookie;
 			xstcb.T2_expireries = stcb->asoc.timoshutdown + stcb->asoc.timoshutdownack;
 			xstcb.retransmitted_tsns = stcb->asoc.marked_retrans;
-			xstcb.start_time.tv_sec = (uint32_t) stcb->asoc.start_time.tv_sec;
-			xstcb.start_time.tv_usec = (uint32_t) stcb->asoc.start_time.tv_usec;
-			xstcb.discontinuity_time.tv_sec = (uint32_t) stcb->asoc.discontinuity_time.tv_sec;
-			xstcb.discontinuity_time.tv_usec = (uint32_t) stcb->asoc.discontinuity_time.tv_usec;
+			xstcb.start_time.ts_sec = (u_int32_t) stcb->asoc.start_time.tv_sec;
+			xstcb.start_time.ts_usec = (u_int32_t) stcb->asoc.start_time.tv_usec;
+			xstcb.discontinuity_time.ts_sec = (u_int32_t) stcb->asoc.discontinuity_time.tv_sec;
+			xstcb.discontinuity_time.ts_usec = (u_int32_t) stcb->asoc.discontinuity_time.tv_usec;
 			xstcb.total_sends = stcb->total_sends;
 			xstcb.total_recvs = stcb->total_recvs;
 			xstcb.local_tag = stcb->asoc.my_vtag;
@@ -467,8 +467,8 @@
 				xraddr.flight_size = net->flight_size;
 				xraddr.mtu = net->mtu;
 				xraddr.rtt = net->rtt;
-				xraddr.start_time.tv_sec = (uint32_t) net->start_time.tv_sec;
-				xraddr.start_time.tv_usec = (uint32_t) net->start_time.tv_usec;
+				xraddr.start_time.ts_sec = (u_int32_t) net->start_time.tv_sec;
+				xraddr.start_time.ts_usec = (u_int32_t) net->start_time.tv_usec;
 				SCTP_INP_RUNLOCK(inp);
 				SCTP_INP_INFO_RUNLOCK();
 				error = SYSCTL_OUT(req, &xraddr, sizeof(struct xsctp_raddr));
@@ -639,9 +639,9 @@
 	memset(&sb, 0, sizeof(sb));
 	for (cpu = 0; cpu < mp_ncpus; cpu++) {
 		sarry = &SCTP_BASE_STATS[cpu];
-		if (sarry->sctps_discontinuitytime.tv_sec > sb.sctps_discontinuitytime.tv_sec) {
-			sb.sctps_discontinuitytime.tv_sec = sarry->sctps_discontinuitytime.tv_sec;
-			sb.sctps_discontinuitytime.tv_usec = sarry->sctps_discontinuitytime.tv_usec;
+		if (sarry->sctps_discontinuitytime.ts_sec > sb.sctps_discontinuitytime.ts_sec) {
+			sb.sctps_discontinuitytime.ts_sec = sarry->sctps_discontinuitytime.ts_sec;
+			sb.sctps_discontinuitytime.ts_usec = sarry->sctps_discontinuitytime.ts_usec;
 		}
 		sb.sctps_currestab += sarry->sctps_currestab;
 		sb.sctps_activeestab += sarry->sctps_activeestab;

==== //depot/projects/soc2009/pgj_libstat/src/sys/netinet/sctp_uio.h#6 (text+ko) ====

@@ -41,6 +41,7 @@
 #endif
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <net/stat.h>
 #include <netinet/in.h>
 
 typedef uint32_t sctp_assoc_t;
@@ -759,15 +760,10 @@
 	struct sctp_cwnd_log log[];
 };
 
-struct sctp_timeval {
-	uint32_t tv_sec;
-	uint32_t tv_usec;
-};
-
 #define	SCTPSTAT_VERSION    0x00000001
 
 struct sctpstat {
-	struct sctp_timeval sctps_discontinuitytime;	/* sctpStats 18
+	struct timestamp_type sctps_discontinuitytime;	/* sctpStats 18
 							 * (TimeStamp) */
 	/* MIB according to RFC 3873 */
 	uint32_t sctps_currestab;	/* sctpStats  1   (Gauge32) */
@@ -1022,8 +1018,8 @@
 	uint32_t refcnt;
 	uint16_t local_port;	/* sctpAssocEntry 3   */
 	uint16_t remote_port;	/* sctpAssocEntry 4   */
-	struct sctp_timeval start_time;	/* sctpAssocEntry 16  */
-	struct sctp_timeval discontinuity_time;	/* sctpAssocEntry 17  */
+	struct timestamp_type start_time;	/* sctpAssocEntry 16  */
+	struct timestamp_type discontinuity_time;	/* sctpAssocEntry 17  */
 	uint32_t peers_rwnd;
 	sctp_assoc_t assoc_id;	/* sctpAssocEntry 1   */
 	uint32_t extra_padding[32];	/* future */
@@ -1032,7 +1028,7 @@
 struct xsctp_laddr {
 	union sctp_sockstore address;	/* sctpAssocLocalAddrEntry 1/2 */
 	uint32_t last;
-	struct sctp_timeval start_time;	/* sctpAssocLocalAddrEntry 3   */
+	struct timestamp_type start_time;	/* sctpAssocLocalAddrEntry 3   */
 	uint32_t extra_padding[32];	/* future */
 };
 
@@ -1049,7 +1045,7 @@
 	uint8_t active;		/* sctpAssocLocalRemEntry 3   */
 	uint8_t confirmed;	/* */
 	uint8_t heartbeat_enabled;	/* sctpAssocLocalRemEntry 4   */
-	struct sctp_timeval start_time;	/* sctpAssocLocalRemEntry 8   */
+	struct timestamp_type start_time;	/* sctpAssocLocalRemEntry 8   */
 	uint32_t rtt;
 	uint32_t extra_padding[32];	/* future */
 };



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201005061729.o46HTf01046366>