Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
For bugs related to Red Hat Enterprise Linux 4 product line. The current stable release is 4.9. For Red Hat Enterprise Linux 6 and above, please visit Red Hat JIRA https://issues.redhat.com/secure/CreateIssue!default.jspa?pid=12332745 to report new issues.

Bug 145648

Summary: Socket option IP_FREEBIND has no effect on SCTP socket.
Product: Red Hat Enterprise Linux 4 Reporter: Jere Leppanen <jere.leppanen>
Component: kernelAssignee: Neil Horman <nhorman>
Status: CLOSED ERRATA QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 4.0CC: davej, davem, jbaron, jmorris, pcfe, tao
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: RHSA-2005-514 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-10-05 12:41:13 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 154907, 156323    
Attachments:
Description Flags
SCTP IP_FREEBIND patch
none
patch to enable IP_FREEBIND sockopt / ip_nonlocal_bind sysctl
none
updated version of FREEBIND patch none

Description Jere Leppanen 2005-01-20 13:53:32 UTC
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):
kernel-2.6.9-1.648_EL

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 172.21.94.188.
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("172.21.94.188")}, 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 127.0.0.1/8 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 172.21.94.189/22 brd 172.21.95.255 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 0.0.0.0 brd 0.0.0.0
$ /sbin/ip r
172.21.92.0/22 dev eth0  proto kernel  scope link  src 172.21.94.189
169.254.0.0/16 dev eth0  scope link
default via 172.21.92.1 dev eth0

Comment 2 Patrick C. F. Ernzer 2005-01-26 14:41:15 UTC
These have now been reproduced under RHEL 4 RC by jere.

Comment 5 Jere Leppanen 2005-05-02 14:45:57 UTC
Created attachment 113921 [details]
SCTP IP_FREEBIND patch

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 20:38:48 UTC
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 19:53:06 UTC
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 11:59:19 UTC
(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 12:40:32 UTC
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 12:41:13 UTC
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.

http://rhn.redhat.com/errata/RHSA-2005-514.html