1*f1915787Swiz.\" $NetBSD: rfc6056.7,v 1.4 2012/07/01 17:00:32 wiz Exp $ 2369e1451Schristos.\" 3369e1451Schristos.\" Copyright (c) 2011 4369e1451Schristos.\" The NetBSD Foundation. All rights reserved. 5369e1451Schristos.\" 6369e1451Schristos.\" This code is derived from software contributed to The NetBSD Foundation 7369e1451Schristos.\" by Vlad Balan 8369e1451Schristos.\". 9369e1451Schristos.\" Redistribution and use in source and binary forms, with or without 10369e1451Schristos.\" modification, are permitted provided that the following conditions 11369e1451Schristos.\" are met: 12369e1451Schristos.\" 1. Redistributions of source code must retain the above copyright 13369e1451Schristos.\" notice, this list of conditions and the following disclaimer. 14369e1451Schristos.\" 2. Redistributions in binary form must reproduce the above copyright 15369e1451Schristos.\" notice, this list of conditions and the following disclaimer in the 16369e1451Schristos.\" documentation and/or other materials provided with the distribution. 17369e1451Schristos.\" 18369e1451Schristos.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19369e1451Schristos.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20369e1451Schristos.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21369e1451Schristos.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22369e1451Schristos.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23369e1451Schristos.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24369e1451Schristos.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25369e1451Schristos.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26369e1451Schristos.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27369e1451Schristos.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28369e1451Schristos.\" SUCH DAMAGE. 29369e1451Schristos.\" 30369e1451Schristos.\" 31369e1451Schristos.Dd August 25, 2011 32369e1451Schristos.Dt RFC6056 7 33369e1451Schristos.Os 34369e1451Schristos.Sh NAME 35369e1451Schristos.Nm rfc6056 36369e1451Schristos.Nd port randomization algorithms 37369e1451Schristos.Sh DESCRIPTION 38369e1451SchristosThe 3919284ed0Swiz.Nm 40369e1451Schristosalgorithms are used in order to randomize the port allocation of outgoing UDP 41369e1451Schristospackets, in order to provide protection from a series of 42369e1451Schristos.Dq blind 43369e1451Schristosattacks based on the 44369e1451Schristosattacker's ability to guess the sequence of ephemeral ports associated 4519284ed0Swizwith outgoing packets. 4619284ed0SwizFor more information consult RFC 6056. 47369e1451Schristos.Pp 48*f1915787SwizThe individual algorithms are described below. 49369e1451Schristos.Ss The RFC 6056 algorithms 50*f1915787SwizThe following algorithms are available: 51369e1451Schristos.Bl -tag -width "random_start" 52369e1451Schristos.It Sy bsd 53369e1451SchristosThis is the default 54369e1451Schristos.Nx 55369e1451Schristosport selection algorithm, which starts from 56369e1451Schristos.Dv anonportmax 57369e1451Schristosand proceeds decreasingly through the available ephemeral ports. 58369e1451Schristos.It Sy random_start 59369e1451SchristosSelect ports randomly from the available ephemeral ports. 6019284ed0SwizIn case a collision with a local port is detected, the 61369e1451Schristosalgorithm proceeds decreasingly through the sequence of ephemeral 62369e1451Schristosports until a free port is found. 63369e1451SchristosNote that the random port selection algorithms are not guaranteed to find 64369e1451Schristosa free port. 65369e1451Schristos.It Sy random_pick 66369e1451SchristosSelect ports randomly from the available ephemeral ports. 67369e1451SchristosIn case a collision with a local port is detected the algorithm tries 68369e1451Schristosselecting a new port randomly until a free port is found. 69369e1451Schristos.It Sy hash 70369e1451SchristosSelect ports using a 71369e1451Schristos.Xr md5 3 72369e1451Schristoshash of the local address, the foreign address, and the foreign port. 73369e1451SchristosNote that in the case of a 74369e1451Schristos.Xr bind 2 75369e1451Schristoscall some of this information might be unavailable and the 76369e1451Schristosport selection is delayed until the time of a 77369e1451Schristos.Xr connect 2 78369e1451Schristoscall, performed either explicitly or up calling 79369e1451Schristos.Xr sendto 2 . 80369e1451Schristos.It Sy doublehash 81369e1451SchristosSelect ports using a 82369e1451Schristos.Xr md5 3 8319284ed0Swizhash of the local address, foreign address, and foreign port coupled with a 84369e1451Schristos.Xr md5 3 85369e1451Schristoshash of the same components obtained using a separate table that is 86369e1451Schristosassociated with a subset of all outgoing connections. 87369e1451SchristosThe same considerations regarding late connection as in the case of hash apply. 88369e1451Schristos.It Sy randinc 89369e1451SchristosUse random increments in order to select the next port. 90369e1451Schristos.El 91369e1451Schristos.Sh SYSCTL CONTROLS 92369e1451SchristosThe following sysctl controls are available for selecting the default 93369e1451Schristosport randomization algorithm: 9440114b99Schristos.Bl -column "net.inet6.udp6.anonportalgo.available" "string" "Changeable" 95369e1451Schristos.It Sy sysctl name Ta Sy Type Ta Sy Changeable 9640114b99Schristos.It net.inet.ip.anonportalgo.available Ta string Ta no 9740114b99Schristos.It net.inet.ip.anonportalgo.selected Ta string Ta yes 9840114b99Schristos.It net.inet6.ip6.anonportalgo.available Ta string Ta no 9940114b99Schristos.It net.inet6.ip6.anonportalgo.selected Ta string Ta yes 100369e1451Schristos.El 101369e1451Schristos.Sh SOCKET OPTIONS 10240114b99SchristosThe 10340114b99Schristos.Dv IP_PORTSEL 10440114b99Schristossocket option at the 10540114b99Schristos.Dv IPPROTO_IP 10640114b99Schristoslevel and the 10740114b99Schristos.Dv IPV6_PORTSEL 10840114b99Schristossocket option at the 10940114b99Schristos.Dv IPPROTO_IPV6 110369e1451Schristoslevel can be used with a string argument specifying the algorithm's 111369e1451Schristosname in order to select the port randomization algorithm 112369e1451Schristosfor a specific socket. 113369e1451SchristosFor more info see 114369e1451Schristos.Xr setsockopt 2 . 115369e1451Schristos.Sh SEE ALSO 116369e1451Schristos.Xr setsockopt 2 , 117369e1451Schristos.Xr sysctl 3 , 118369e1451Schristos.Xr sysctl 7 119369e1451Schristos.Sh HISTORY 120369e1451SchristosThe 121369e1451Schristos.Nm 122369e1451Schristosalgorithms first appeared in 123369e1451Schristos.Nx 6.0 . 124