From owner-svn-src-all@freebsd.org Tue Jul 21 15:03:37 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1075835EEF1; Tue, 21 Jul 2020 15:03:37 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BB20m6V5vz3W9w; Tue, 21 Jul 2020 15:03:36 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C221E20295; Tue, 21 Jul 2020 15:03:36 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 06LF3aoT036947; Tue, 21 Jul 2020 15:03:36 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 06LF3aYK036946; Tue, 21 Jul 2020 15:03:36 GMT (envelope-from markj@FreeBSD.org) Message-Id: <202007211503.06LF3aYK036946@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Tue, 21 Jul 2020 15:03:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363395 - head/usr.sbin/traceroute6 X-SVN-Group: head X-SVN-Commit-Author: markj X-SVN-Commit-Paths: head/usr.sbin/traceroute6 X-SVN-Commit-Revision: 363395 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jul 2020 15:03:37 -0000 Author: markj Date: Tue Jul 21 15:03:36 2020 New Revision: 363395 URL: https://svnweb.freebsd.org/changeset/base/363395 Log: traceroute6: Fix most warnings at the default WARNS level. Fix some style issues as well. Leave -Wno-cast-aligned set for now, as most of the warnings come casts of CMSG_DATA(), which does provide sufficient alignment in practice. Submitted by: Shubh Gupta Sponsored by: Google (GSOC 2020) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D25603 Modified: head/usr.sbin/traceroute6/Makefile head/usr.sbin/traceroute6/traceroute6.c Modified: head/usr.sbin/traceroute6/Makefile ============================================================================== --- head/usr.sbin/traceroute6/Makefile Tue Jul 21 14:42:22 2020 (r363394) +++ head/usr.sbin/traceroute6/Makefile Tue Jul 21 15:03:36 2020 (r363395) @@ -26,8 +26,8 @@ BINMODE= 4555 CFLAGS+= -DIPSEC -DHAVE_POLL CFLAGS+= -I${.CURDIR} -I${TRACEROUTE_DISTDIR} -I. -WARNS?= 3 - LIBADD= ipsec .include + +CWARNFLAGS+= -Wno-cast-align Modified: head/usr.sbin/traceroute6/traceroute6.c ============================================================================== --- head/usr.sbin/traceroute6/traceroute6.c Tue Jul 21 14:42:22 2020 (r363394) +++ head/usr.sbin/traceroute6/traceroute6.c Tue Jul 21 15:03:36 2020 (r363395) @@ -294,16 +294,14 @@ static const char rcsid[] = #define freehostent(x) #endif -u_char packet[512]; /* last inbound (icmp) packet */ -char *outpacket; /* last output packet */ +static u_char packet[512]; /* last inbound (icmp) packet */ +static char *outpacket; /* last output packet */ int main(int, char *[]); int wait_for_reply(int, struct msghdr *); -#ifdef IPSEC -#ifdef IPSEC_POLICY_IPSEC +#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) int setpolicy(int so, char *policy); #endif -#endif void send_probe(int, u_long); void *get_uphdr(struct ip6_hdr *, u_char *); int get_hoplim(struct msghdr *); @@ -318,40 +316,40 @@ u_int16_t tcp_chksum(struct sockaddr_in6 *, struct soc void *, u_int32_t); void usage(void); -int rcvsock; /* receive (icmp) socket file descriptor */ -int sndsock; /* send (raw/udp) socket file descriptor */ +static int rcvsock; /* receive (icmp) socket file descriptor */ +static int sndsock; /* send (raw/udp) socket file descriptor */ -struct msghdr rcvmhdr; -struct iovec rcviov[2]; -int rcvhlim; -struct in6_pktinfo *rcvpktinfo; +static struct msghdr rcvmhdr; +static struct iovec rcviov[2]; +static int rcvhlim; +static struct in6_pktinfo *rcvpktinfo; -struct sockaddr_in6 Src, Dst, Rcv; -u_long datalen = 20; /* How much data */ +static struct sockaddr_in6 Src, Dst, Rcv; +static u_long datalen = 20; /* How much data */ #define ICMP6ECHOLEN 8 /* XXX: 2064 = 127(max hops in type 0 rthdr) * sizeof(ip6_hdr) + 16(margin) */ -char rtbuf[2064]; -struct ip6_rthdr *rth; -struct cmsghdr *cmsg; +static char rtbuf[2064]; +static struct ip6_rthdr *rth; +static struct cmsghdr *cmsg; -char *source = NULL; -char *hostname; +static char *source = NULL; +static char *hostname; -u_long nprobes = 3; -u_long first_hop = 1; -u_long max_hops = 30; -u_int16_t srcport; -u_int16_t port = 32768+666; /* start udp dest port # for probe packets */ -u_int16_t ident; -int options; /* socket options */ -int verbose; -int waittime = 5; /* time to wait for response (in seconds) */ -int nflag; /* print addresses numerically */ -int useproto = IPPROTO_UDP; /* protocol to use to send packet */ -int lflag; /* print both numerical address & hostname */ -int as_path; /* print as numbers for each hop */ -char *as_server = NULL; -void *asn; +static u_long nprobes = 3; +static u_long first_hop = 1; +static u_long max_hops = 30; +static u_int16_t srcport; +static u_int16_t port = 32768+666; /* start udp dest port # for probe packets */ +static u_int16_t ident; +static int options; /* socket options */ +static int verbose; +static int waittime = 5; /* time to wait for response (in seconds) */ +static int nflag; /* print addresses numerically */ +static int useproto = IPPROTO_UDP; /* protocol to use to send packet */ +static int lflag; /* print both numerical address & hostname */ +static int as_path; /* print as numbers for each hop */ +static char *as_server = NULL; +static void *asn; int main(int argc, char *argv[]) @@ -366,6 +364,10 @@ main(int argc, char *argv[]) size_t size, minlen; uid_t uid; u_char type, code; +#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) + char ipsec_inpolicy[] = "in bypass"; + char ipsec_outpolicy[] = "out bypass"; +#endif /* * Receive ICMP @@ -628,7 +630,7 @@ main(int argc, char *argv[]) fprintf(stderr, "traceroute6: Warning: %s has multiple " "addresses; using %s\n", hostname, hbuf); } - + freeaddrinfo(res); if (*++argv) { ep = NULL; errno = 0; @@ -705,15 +707,14 @@ main(int argc, char *argv[]) if (options & SO_DONTROUTE) (void) setsockopt(rcvsock, SOL_SOCKET, SO_DONTROUTE, (char *)&on, sizeof(on)); -#ifdef IPSEC -#ifdef IPSEC_POLICY_IPSEC +#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) /* * do not raise error even if setsockopt fails, kernel may have ipsec * turned off. */ - if (setpolicy(rcvsock, "in bypass") < 0) + if (setpolicy(rcvsock, ipsec_inpolicy) < 0) errx(1, "%s", ipsec_strerror()); - if (setpolicy(rcvsock, "out bypass") < 0) + if (setpolicy(rcvsock, ipsec_outpolicy) < 0) errx(1, "%s", ipsec_strerror()); #else { @@ -735,8 +736,7 @@ main(int argc, char *argv[]) sizeof(level)); #endif } -#endif /*IPSEC_POLICY_IPSEC*/ -#endif /*IPSEC*/ +#endif /* !(IPSEC && IPSEC_POLICY_IPSEC) */ #ifdef SO_SNDBUF i = datalen; @@ -763,15 +763,14 @@ main(int argc, char *argv[]) exit(1); } } -#ifdef IPSEC -#ifdef IPSEC_POLICY_IPSEC +#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) /* * do not raise error even if setsockopt fails, kernel may have ipsec * turned off. */ - if (setpolicy(sndsock, "in bypass") < 0) + if (setpolicy(sndsock, ipsec_inpolicy) < 0) errx(1, "%s", ipsec_strerror()); - if (setpolicy(sndsock, "out bypass") < 0) + if (setpolicy(sndsock, ipsec_outpolicy) < 0) errx(1, "%s", ipsec_strerror()); #else { @@ -793,17 +792,13 @@ main(int argc, char *argv[]) sizeof(level)); #endif } -#endif /*IPSEC_POLICY_IPSEC*/ -#endif /*IPSEC*/ +#endif /* !(IPSEC && IPSEC_POLICY_IPSEC) */ /* * Source selection */ bzero(&Src, sizeof(Src)); if (source) { - struct addrinfo hints, *res; - int error; - memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET6; hints.ai_socktype = SOCK_DGRAM; /*dummy*/ @@ -1018,12 +1013,9 @@ wait_for_reply(int sock, struct msghdr *mhdr) #endif } -#ifdef IPSEC -#ifdef IPSEC_POLICY_IPSEC +#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) int -setpolicy(so, policy) - int so; - char *policy; +setpolicy(int so, char *policy) { char *buf; @@ -1040,7 +1032,6 @@ setpolicy(so, policy) return 0; } #endif -#endif void send_probe(int seq, u_long hops) @@ -1627,11 +1618,11 @@ static u_int32_t crc_c[256] = { }; u_int32_t -sctp_crc32c(void *packet, u_int32_t len) +sctp_crc32c(void *pack, u_int32_t len) { u_int32_t i, crc32c; u_int8_t byte0, byte1, byte2, byte3; - u_int8_t *buf = (u_int8_t *)packet; + u_int8_t *buf = (u_int8_t *)pack; crc32c = ~0; for (i = 0; i < len; i++)