From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Dumazet Subject: Re: [RFC Patch] net: reserve ports for applications using fixed port numbers Date: Wed, 03 Feb 2010 05:39:53 +0100 Message-ID: <1265171993.3274.3.camel@edumazet-laptop> References: <20100203043332.3817.27932.sendpatchset@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Neil Horman , linux-sctp-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, David Miller To: Amerigo Wang Return-path: In-Reply-To: <20100203043332.3817.27932.sendpatchset-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org> Sender: linux-rdma-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-Id: netdev.vger.kernel.org Le mardi 02 f=C3=A9vrier 2010 =C3=A0 23:30 -0500, Amerigo Wang a =C3=A9= crit : > This patch introduces /proc/sys/net/ipv4/ip_local_reserved_ports, > it can be used like ip_local_port_range, but this is used to > reserve ports for third-party applications which use fixed > port numbers within ip_local_port_range. >=20 > This only affects the applications which call socket functions > like bind(2) with port number 0, to prevent the kernel getting the po= rts > within the specified range for them. For applications which use fixed > port number, it will have no effects. >=20 > Any comments are welcome. >=20 > Signed-off-by: WANG Cong > Cc: David Miller > Cc: Neil Horman > Cc: Eric Dumazet > .procname =3D "igmp_max_memberships", > diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c > index f0126fd..83045ca 100644 > --- a/net/ipv4/udp.c > +++ b/net/ipv4/udp.c > @@ -210,8 +210,11 @@ int udp_lib_get_port(struct sock *sk, unsigned s= hort snum, > inet_get_local_port_range(&low, &high); > remaining =3D (high - low) + 1; > =20 > +again: > rand =3D net_random(); > first =3D (((u64)rand * remaining) >> 32) + low; > + if (inet_is_reserved_local_port(first)) > + goto again; > /* > * force rand to be an odd multiple of UDP_HTABLE_SIZE > */ Unless I misread the patch, you are checking only the 'first' port that udp_lib_get_port() chose. I would use inet_get_local_reserved_ports(&min_res, &max_res); and check every port that we chose in the loop to avoid it if necessary= =2E -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" i= n the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html