From owner-svn-src-head@FreeBSD.ORG Thu Feb 25 14:36:52 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 91E371065672; Thu, 25 Feb 2010 14:36:52 +0000 (UTC) (envelope-from ru@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7F7278FC0C; Thu, 25 Feb 2010 14:36:52 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o1PEaqmm039134; Thu, 25 Feb 2010 14:36:52 GMT (envelope-from ru@svn.freebsd.org) Received: (from ru@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o1PEap20039133; Thu, 25 Feb 2010 14:36:51 GMT (envelope-from ru@svn.freebsd.org) Message-Id: <201002251436.o1PEap20039133@svn.freebsd.org> From: Ruslan Ermilov Date: Thu, 25 Feb 2010 14:36:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r204310 - in head/tools/tools: mcgrab mctest X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Feb 2010 14:36:52 -0000 Author: ru Date: Thu Feb 25 14:36:50 2010 New Revision: 204310 URL: http://svn.freebsd.org/changeset/base/204310 Log: Moved mcgrab(1) into a separate directory -- our .mk infrastructure doesn't currently have support for building multiple programs in a single makefile. While here, fixed manpages and makefiles (missing dependencies). Added: head/tools/tools/mcgrab/ head/tools/tools/mcgrab/Makefile (contents, props changed) head/tools/tools/mcgrab/mcgrab.1 - copied, changed from r204302, head/tools/tools/mctest/mcgrab.1 head/tools/tools/mcgrab/mcgrab.cc - copied unchanged from r204302, head/tools/tools/mctest/mcgrab.cc Deleted: head/tools/tools/mctest/mcgrab.1 head/tools/tools/mctest/mcgrab.cc Modified: head/tools/tools/mctest/Makefile head/tools/tools/mctest/mctest.1 Added: head/tools/tools/mcgrab/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/tools/mcgrab/Makefile Thu Feb 25 14:36:50 2010 (r204310) @@ -0,0 +1,6 @@ +# $FreeBSD$ + +PROG_CXX= mcgrab +CFLAGS+= -I${.CURDIR}/../mctest + +.include Copied and modified: head/tools/tools/mcgrab/mcgrab.1 (from r204302, head/tools/tools/mctest/mcgrab.1) ============================================================================== --- head/tools/tools/mctest/mcgrab.1 Thu Feb 25 06:53:46 2010 (r204302, copy source) +++ head/tools/tools/mcgrab/mcgrab.1 Thu Feb 25 14:36:50 2010 (r204310) @@ -25,7 +25,7 @@ .\" $FreeBSD$ .\" .Dd July 9, 2008 -.Dt mcgrab 1 +.Dt MCGRAB 1 .Os .Sh NAME .Nm mcgrab @@ -36,23 +36,27 @@ .Op Fl g Ar group .Op Fl n Ar number .Sh DESCRIPTION -The +The .Nm command implements a multicast test which grabs and holds -N multicast addresses. The purpose of the test is to see what +N multicast addresses. +The purpose of the test is to see what happens when a network interface is no longer able to filter -multicasts in hardware and has to switch to promiscious or -multicast promiscious mode. A successful test does not have any +multicasts in hardware and has to switch to promiscuous or +multicast promiscuous mode. +A successful test does not have any result, but an unsuccessful test will have deleterious side effects. Packet size in bytes. The options are as follows: -.Bl -tag -width ".Fl d Ar argument" +.Bl -tag -width ".Fl i Ar interface" .It Fl i Ar interface -Network interface, which can be found with ifconfig(1). -.It Fl i Ar group -Multicast group +Network interface, which can be found with +.Xr ifconfig 8 . +.It Fl g Ar group +Multicast group. .It Fl n Ar number Number of groups to join. +.El .Sh EXAMPLES The following is an example of a typical usage of the @@ -62,9 +66,9 @@ command: .Dl "mcgrab -i em0 -g 239.255.255.1 -n 1024" .Sh SEE ALSO .Xr mctest 1 , -.Xr ifconfig 8 , .Xr netstat 1 , -.Xr nanosleep 2 . +.Xr nanosleep 2 , +.Xr ifconfig 8 .Sh HISTORY The .Nm @@ -75,4 +79,5 @@ This manual page was written by .An George V. Neville-Neil Aq gnn@FreeBSD.org . .Sh BUGS -Should be reported to the author or to net@freebsd.org. +Should be reported to the author or to +.Aq net@FreeBSD.org . Copied: head/tools/tools/mcgrab/mcgrab.cc (from r204302, head/tools/tools/mctest/mcgrab.cc) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/tools/mcgrab/mcgrab.cc Thu Feb 25 14:36:50 2010 (r204310, copy of r204302, head/tools/tools/mctest/mcgrab.cc) @@ -0,0 +1,189 @@ +// +// Copyright (c) 2008, Neville-Neil Consulting +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. +// +// This test simply grabs N multicast addresses starting +// from a base address. The purpose is to make sure that switching a device +// from using a multicast filtering table or function to promiscuous +// multicast listening mode does not cause deleterious side effects. +// + +#include +__FBSDID("$FreeBSD$"); + +// C++ STL and other related includes +#include +#include +#include +#include +#include + +// Operating System and other C based includes +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Private include files +#include "mctest.h" + +using namespace std; + +// +// usage - just the program's usage line +// +// +void usage() +{ + cout << "mcgrab -i interface -g multicast group -n number of groups\n"; + exit(-1); +} + +// +// usage - print out the usage with a possible message and exit +// +// \param message optional string +// +// +void usage(string message) +{ + + cerr << message << endl; + usage(); +} + + +// +// grab a set of addresses +// +// @param interface ///< text name of the interface (em0 etc.) +// @param group ///< multicast group +// @param number ///< number of addresses to grab +// +// @return 0 for 0K, -1 for error, sets errno +// +void grab(char *interface, struct in_addr *group, int number) { + + + int sock; + struct ip_mreq mreq; + struct ifreq ifreq; + struct in_addr lgroup; + + if (group == NULL) { + group = &lgroup; + if (inet_pton(AF_INET, DEFAULT_GROUP, group) < 1) + return; + } + + if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + perror("failed to open datagram socket"); + return; + } + + for (int i = 0; i < number; i++) { + bzero((struct ip_mreq *)&mreq, sizeof(mreq)); + bzero((struct ifreq *)&ifreq, sizeof(ifreq)); + + strncpy(ifreq.ifr_name, interface, IFNAMSIZ); + if (ioctl(sock, SIOCGIFADDR, &ifreq) < 0) { + perror("no such interface"); + return; + } + + memcpy(&mreq.imr_interface, + &((struct sockaddr_in*) &ifreq.ifr_addr)->sin_addr, + sizeof(struct in_addr)); + + mreq.imr_multiaddr.s_addr = group->s_addr; + if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, + sizeof(mreq)) < 0) { + + perror("failed to add membership"); + return; + } + + if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, + &((struct sockaddr_in *) &ifreq.ifr_addr)->sin_addr, + sizeof(struct in_addr)) < 0) { + perror("failed to bind interface"); + return; + } + + group->s_addr = htonl(ntohl(group->s_addr) + 1); + } + printf("Press Control-C to exit.\n"); + sleep(INT_MAX); + +} + + +// +// main - the main program +// +// \param -g multicast group address which we will hold +// \param -i interface on which we're holding the address +// +// +int main(int argc, char**argv) +{ + + char ch; ///< character from getopt() + extern char* optarg; ///< option argument + + char* interface = 0; ///< Name of the interface + struct in_addr *group = NULL; ///< the multicast group address + int number = 0; ///< Number of addresses to grab + + if (argc != 7) + usage(); + + while ((ch = getopt(argc, argv, "g:i:n:h")) != -1) { + switch (ch) { + case 'g': + group = new (struct in_addr ); + if (inet_pton(AF_INET, optarg, group) < 1) + usage(argv[0] + string(" Error: invalid multicast group") + + optarg); + break; + case 'i': + interface = optarg; + break; + case 'n': + number = atoi(optarg); + break; + case 'h': + usage(string("Help\n")); + break; + } + } + + grab(interface, group, number); + +} Modified: head/tools/tools/mctest/Makefile ============================================================================== --- head/tools/tools/mctest/Makefile Thu Feb 25 14:13:39 2010 (r204309) +++ head/tools/tools/mctest/Makefile Thu Feb 25 14:36:50 2010 (r204310) @@ -1,11 +1,7 @@ -# # $FreeBSD$ -# -# A Makefile that builds both the mctest program and its manual page. PROG_CXX= mctest -PROG_CXX= mcgrab - -LDADD+= -lpthread +DPADD= ${LIBPTHREAD} +LDADD= -lpthread .include Modified: head/tools/tools/mctest/mctest.1 ============================================================================== --- head/tools/tools/mctest/mctest.1 Thu Feb 25 14:13:39 2010 (r204309) +++ head/tools/tools/mctest/mctest.1 Thu Feb 25 14:36:50 2010 (r204310) @@ -25,7 +25,7 @@ .\" $FreeBSD$ .\" .Dd April 3, 2008 -.Dt mctest 1 +.Dt MCTEST 1 .Os .Sh NAME .Nm mctest @@ -40,29 +40,34 @@ .Op Fl t Ar inter-packet gap .Op Fl M Ar number of clients (source only) .Op Fl m Ar my client number (sink only) -.Op Fl r +.Op Fl r .Sh DESCRIPTION -The +The .Nm -command implements a multicast test which involved a source -and a sink. The source sends packets to a pre-configured -multicast address over the interface given as a command line -argument. The sink listens for multicast packets, records -the time at which they're received and then reflects them back -over unicast to the source. When the source has captured all +command implements a multicast test which involves a source +and a sink. +The source sends packets to a pre-configured +multicast address over the interface given as a command line +argument. +The sink listens for multicast packets, records +the time at which they are received and then reflects them back +over unicast to the source. +When the source has captured all the reflected packets it prints out the round trip time of each. .Pp The source prints out the round trip time of packets sent to the -sinks. The sink prints out the time between the packets received. +sinks. +The sink prints out the time between the packets received. .Pp The options are as follows: -.Bl -tag -width ".Fl d Ar argument" +.Bl -tag -width ".Fl i Ar interface" .It Fl i Ar interface -Network interface, which can be found with ifconfig(1). +Network interface, which can be found with +.Xr ifconfig 8 . .It Fl g Ar group -Multicast group +Multicast group. .It Fl b Ar base port -Port on which to listen +Port on which to listen. .It Fl s Ar size Packet size in bytes. .It Fl n Ar number @@ -70,14 +75,15 @@ Number of packets. .It Fl t Ar gap Inter-packet gap in nanoseconds. .It Fl M Ar clients -The number of clients that are listening +The number of clients that are listening. .It Fl m Ar my number The client's number 0, 1, etc. .It Fl r This version of .Nm -is the receiver aka the sink. This option MUST -only be used with one copy of the program at a time. +is the receiver aka the sink. +This option MUST +only be used with one copy of the program at a time. .El .Sh EXAMPLES The following is an example of a typical usage @@ -92,14 +98,15 @@ Sink .Pp Send 100 packets of 1024 bytes, with an inter-packet gap of 1 nanosecond. .Pp -Gaps are measured with +Gaps are measured with .Xr nanosleep 2 , and so are not accurate down to nanoseconds -but depend on the setting of kern.hz. +but depend on the setting of +.Va kern.hz . .Sh SEE ALSO -.Xr ifconfig 8 , .Xr netstat 1 , -.Xr nanosleep 2 . +.Xr nanosleep 2 , +.Xr ifconfig 8 .Sh HISTORY The .Nm @@ -110,4 +117,5 @@ This manual page was written by .An George V. Neville-Neil Aq gnn@FreeBSD.org . .Sh BUGS -Should be reported to the author or to net@freebsd.org. +Should be reported to the author or to +.Aq net@FreeBSD.org .