Bug 145648 - Socket option IP_FREEBIND has no effect on SCTP socket.
Socket option IP_FREEBIND has no effect on SCTP socket.
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: kernel (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Neil Horman
Brian Brock
Depends On:
Blocks: 154907 156323
  Show dependency treegraph
Reported: 2005-01-20 08:53 EST by Jere Leppanen
Modified: 2007-11-30 17:07 EST (History)
6 users (show)

See Also:
Fixed In Version: RHSA-2005-514
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2005-10-05 08:41:13 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
SCTP IP_FREEBIND patch (420 bytes, patch)
2005-05-02 10:45 EDT, Jere Leppanen
no flags Details | Diff
patch to enable IP_FREEBIND sockopt / ip_nonlocal_bind sysctl (1.20 KB, patch)
2005-06-03 16:38 EDT, Neil Horman
no flags Details | Diff
updated version of FREEBIND patch (1.34 KB, patch)
2005-06-06 15:53 EDT, Neil Horman
no flags Details | Diff

  None (edit)
Description Jere Leppanen 2005-01-20 08:53:32 EST
Description of problem:
Setting socket option IP_FREEBIND with setsockopt() returns 0 
(success). After this, one should be able to bind the socket to any 
IP address. This works with TCP sockets. With SCTP sockets, however, 
after setting IP_FREEBIND the set of IP addresses that the socket can 
be bound to is unchanged.

Version-Release number of selected component (if applicable):

How reproducible:
Every time.

Steps to Reproduce:
1. Pick an IP address that does _not_ exist in any of the host's 
interfaces. In this case I picked
3. socket(PF_INET, SOCK_STREAM, 0x84 /* IPPROTO_??? */) = 3
4. setsockopt(3, SOL_IP, 0xf /* IP_??? */, [1], 4) = 0
5. bind(3, {sa_family=AF_INET, sin_port=htons(10000), 
sin_addr=inet_addr("")}, 16) = -1 EADDRNOTAVAIL (Cannot 
assign requested address)
Actual results:
In step 4, bind() returns -1 with EADDRNOTAVAIL.

Expected results:
Since IP_FREEBIND is set, bind() in step 4 should return 0 (success).

Additional info:

My net config (just in case):

$ /sbin/ip a
1: lo: <LOOPBACK,UP> mtu 16436 qdisc noqueue
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0b:db:81:c4:db brd ff:ff:ff:ff:ff:ff
    inet brd scope global eth0
    inet6 fe80::20b:dbff:fe81:c4db/64 scope link
       valid_lft forever preferred_lft forever
3: sit0: <NOARP> mtu 1480 qdisc noop
    link/sit brd
$ /sbin/ip r dev eth0  proto kernel  scope link  src dev eth0  scope link
default via dev eth0
Comment 2 Patrick C. F. Ernzer 2005-01-26 09:41:15 EST
These have now been reproduced under RHEL 4 RC by jere.
Comment 5 Jere Leppanen 2005-05-02 10:45:57 EDT
Created attachment 113921 [details]

The fix to this bug might be as trivial as

- if (!sp->pf->bind_verify(sp, addr))
+ if (!inet_sk(sk)->freebind && !sp->pf->bind_verify(sp, addr))

in sctp_do_bind(). It does get rid of the EADDRNOTAVAIL, but I'm not sure
whether this is enough.
Comment 9 Neil Horman 2005-06-03 16:38:48 EDT
Created attachment 115140 [details]
patch to enable IP_FREEBIND sockopt / ip_nonlocal_bind sysctl

I've made this version of the patch which seems to be more in line with what
the SCTP developers intended to do to support this.  It also pulls in the
ability to use the ip_nonlocal_bind sysctl.  I've posted it upstream, and it
passes all my tests here.  Please give it a try and let me know if you concur.
Comment 10 Neil Horman 2005-06-06 15:53:06 EDT
Created attachment 115175 [details]
updated version of FREEBIND patch

This is an updated version of the previous patch, which more properly
externalizes the ip_nonlocal_bind sysctl variable.  It just got upstream
acceptance, and its pretty straightforward to test (it passes my tests here
just fine), so I'm going to post it internally here.
Comment 11 Jere Leppanen 2005-06-08 07:59:19 EDT
(struct sctp_opt *)sp->inet.freebind doesn't compile, since struct sctp_opt has 
no member named "inet". What am I doing wrong?

By the way, if you do this in sctp_v4_available(), it'll work for IPv4 only, 
right? What about IPv6?
Comment 12 Neil Horman 2005-06-08 08:40:32 EDT
Upstream kernels pass a sctp_sock structure down to sctp_v4_available, as
opposed to the RHEL kernel that still uses the sock_opt structure.  The attached
is the upstream patch.  I'm working on a backport right now, but if you want you
should just be able to modify the call path from sctp_bind down to
sctp_v4_available to change the sctp_opt parameter to a sctp_sock parameter. 
You will also need to cast the sk ponter in sctp_bind appropriately and modify
the bind_avail method in sctp/structs.h.

As for IPv6, I ignored it as the IPv6 protocol itself appears to no support the
nonlocal bind option. I suppose it could, but I'd prefer to implement that in a
separate issue if you don't mind.
Comment 24 Red Hat Bugzilla 2005-10-05 08:41:13 EDT
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.


Note You need to log in before you can comment on or make changes to this bug.