From owner-svn-src-all@freebsd.org Tue Nov 15 22:18:53 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E54D3C43F7E; Tue, 15 Nov 2016 22:18:53 +0000 (UTC) (envelope-from hiren@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 mx1.freebsd.org (Postfix) with ESMTPS id C1EF617C8; Tue, 15 Nov 2016 22:18:53 +0000 (UTC) (envelope-from hiren@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAFMIr0b086484; Tue, 15 Nov 2016 22:18:53 GMT (envelope-from hiren@FreeBSD.org) Received: (from hiren@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAFMIqQT086481; Tue, 15 Nov 2016 22:18:52 GMT (envelope-from hiren@FreeBSD.org) Message-Id: <201611152218.uAFMIqQT086481@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hiren set sender to hiren@FreeBSD.org using -f From: Hiren Panchasara Date: Tue, 15 Nov 2016 22:18:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r308701 - in stable/11: cddl/lib/libdtrace tests/sys/netinet X-SVN-Group: stable-11 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.23 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, 15 Nov 2016 22:18:54 -0000 Author: hiren Date: Tue Nov 15 22:18:52 2016 New Revision: 308701 URL: https://svnweb.freebsd.org/changeset/base/308701 Log: MFC r302474 (By gnn) On FreeBSD there is a setsockopt option SO_USER_COOKIE which allows setting a 32 bit value on each socket. This can be used by applications and DTrace as a rendezvous point so that an applicaton's data can more easily be captured at run time. Expose the user cookie via DTrace by updating the translator in tcp.d and add a quick test program, a TCP server, that sets the cookie on each connection accepted. Sponsored by: Limelight Networks Added: stable/11/tests/sys/netinet/tcp_user_cookie.c - copied unchanged from r302474, head/tests/sys/netinet/tcp_user_cookie.c Modified: stable/11/cddl/lib/libdtrace/tcp.d stable/11/tests/sys/netinet/Makefile Directory Properties: stable/11/ (props changed) Modified: stable/11/cddl/lib/libdtrace/tcp.d ============================================================================== --- stable/11/cddl/lib/libdtrace/tcp.d Tue Nov 15 21:58:04 2016 (r308700) +++ stable/11/cddl/lib/libdtrace/tcp.d Tue Nov 15 22:18:52 2016 (r308701) @@ -126,6 +126,7 @@ typedef struct tcpsinfo { int tcps_retransmit; /* retransmit send event, boolean */ int tcps_srtt; /* smoothed RTT in units of (TCP_RTT_SCALE*hz) */ int tcps_debug; /* socket has SO_DEBUG set */ + int tcps_cookie; /* expose the socket's SO_USER_COOKIE */ int32_t tcps_dupacks; /* consecutive dup acks received */ uint32_t tcps_rtttime; /* RTT measurement start time */ uint32_t tcps_rtseq; /* sequence # being timed */ @@ -224,6 +225,8 @@ translator tcpsinfo_t < struct tcpcb *p tcps_srtt = p == NULL ? -1 : p->t_srtt; /* smoothed RTT in units of (TCP_RTT_SCALE*hz) */ tcps_debug = p == NULL ? 0 : p->t_inpcb->inp_socket->so_options & 1; + tcps_cookie = p == NULL ? -1 : + p->t_inpcb->inp_socket->so_user_cookie; tcps_dupacks = p == NULL ? -1 : p->t_dupacks; tcps_rtttime = p == NULL ? -1 : p->t_rtttime; tcps_rtseq = p == NULL ? -1 : p->t_rtseq; Modified: stable/11/tests/sys/netinet/Makefile ============================================================================== --- stable/11/tests/sys/netinet/Makefile Tue Nov 15 21:58:04 2016 (r308700) +++ stable/11/tests/sys/netinet/Makefile Tue Nov 15 22:18:52 2016 (r308701) @@ -5,7 +5,7 @@ BINDIR= ${TESTSDIR} ATF_TESTS_SH= fibs_test -PROGS= udp_dontroute +PROGS= udp_dontroute tcp_user_cookie MAN= Copied: stable/11/tests/sys/netinet/tcp_user_cookie.c (from r302474, head/tests/sys/netinet/tcp_user_cookie.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/tests/sys/netinet/tcp_user_cookie.c Tue Nov 15 22:18:52 2016 (r308701, copy of r302474, head/tests/sys/netinet/tcp_user_cookie.c) @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2016 Limelight Networks + * 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, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR 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 DAMAGES. + * + * Authors: George Neville-Neil + * + * $FreeBSD$ + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define buflen 80 + +/* + * Setup a TCP server listening on a port for connections, all of + * which subseuqently have their user cookie set. + */ +int +main(int argc, char **argv) +{ + struct sockaddr_in srv; + int sock, accepted, port, cookie; + int ret; + char recvbuf[buflen]; + + if (argc != 3) { + fprintf(stderr, "Usage: %s port cookie\n", argv[0]); + exit(2); + } + + port = atoi(argv[1]); + cookie = atoi(argv[2]); + + sock = socket(PF_INET, SOCK_STREAM, 0); + if (sock < 0) + err(EXIT_FAILURE, "socket"); + + srv.sin_len = sizeof(srv); + srv.sin_family = AF_INET; + srv.sin_port = htons(port); + srv.sin_addr.s_addr = INADDR_ANY; + + if (bind(sock, (struct sockaddr *)&srv, srv.sin_len) < 0) + err(EX_OSERR, "failed to bind to port %d", port); + + if (listen(sock, 5) < 0) + err(EX_OSERR, "failed to listen on socket"); + + ret = setsockopt(sock, SOL_SOCKET, SO_USER_COOKIE, &cookie, sizeof(cookie)); + if (ret < 0) + err(EX_OSERR, "setsockopt(SO_USER_COOKIE)"); + + while (1) { + + accepted = accept(sock, NULL, 0); + + if (accepted < 0) + err(EX_OSERR, "accept failed"); + + ret = setsockopt(accepted, SOL_SOCKET, SO_USER_COOKIE, + &cookie, sizeof(cookie)); + if (ret < 0) + err(EX_OSERR, "setsockopt(SO_USER_COOKIE)"); + + ret = read(accepted, &recvbuf, buflen); + + if (ret < 0) + warn("failed read"); + + close(accepted); + } + + return (0); +}