Re: SO_REUSEADDR setsockopt() and SCTP

From: Brian F. G. Bidulock <bidulock@openss7.org>
Date: Mon Feb 14 2005 - 08:54:14 EST
('binary' encoding is not supported, stored as-is) ('binary' encoding is not supported, stored as-is) Anatoly,

The socket option is protocol independent, but reuse of local
addresses is not supported by all protocols. (e.g. under SCCP
or X.25, a local address describes a complete connection unlike
TCP or SCTP where it merely names a socket.)

On Linux:

  ADDR = Some valid address to bind
  fd1 = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  bind(fd1, ADDR)
  fd2 = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  bind(fd2, ADDR) <=== Fails EADDRINUSE

  ADDR = Some valid address to bind
  fd1 = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  setsockopt(fd1, SOL_SOCKET, SO_REUSEADDR)
  bind(fd1, ADDR)
  fd2 = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  setsockopt(fd2, SOL_SOCKET, SO_REUSEADDR)
  bind(fd2, ADDR) <=== Succeeds

For OpenSS7 SCTP (and LKSCTP I suppose):

  ADDR = Some valid address to bind
  fd1 = socket(PF_INET, SOCK_STREAM, IPPROTO_SCTP);
  bind(fd1, ADDR)
  fd2 = socket(PF_INET, SOCK_STREAM, IPPROTO_SCTP);
  bind(fd2, ADDR) <=== Fails EADDRINUSE

  ADDR = Some valid address to bind
  fd1 = socket(PF_INET, SOCK_STREAM, IPPROTO_SCTP);
  setsockopt(fd1, SOL_SOCKET, SO_REUSEADDR)
  bind(fd1, ADDR)
  fd2 = socket(PF_INET, SOCK_STREAM, IPPROTO_SCTP);
  setsockopt(fd2, SOL_SOCKET, SO_REUSEADDR)
  bind(fd2, ADDR) <=== Succeeds

Which makes perfect sense and is consistent with POSIX.

You will find the following true for Linux as well:

  ADDR = Some valid address to bind
  fd1 = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  setsockopt(fd1, SOL_SOCKET, SO_REUSEADDR);
  bind(fd1, ADDR);
  listen(fd1);
  fd2 = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  setsockopt(fd2, SOL_SOCKET, SO_REUSEADDR);
  bind(fd2, ADDR); <=== Fails EADDRINUSE

Which makes less sense... I think this should actually succeed.

Not having such a mechanism will make peer-to-peer protocols
like M2PA quite difficult to implement in user space, and will
go quite against the POSIX sockets model.

--brian

On Mon, 14 Feb 2005, Anatoly Khusid wrote:

> Brian,
>
> First you say that:
> >SO_REUSEADDR is described by POSIX and is protocol independent.
>
> But then you quote POSIX, which says:
>
> "if this is supported by the protocol."
>
> So how can it be protocol independent? I agree with Randall that
> SO_REUSEADDR does not make sense for SCTP.
>
> Anatoly
>
> Sent: Friday, February 11, 2005 6:48 PM
> To: Anatoly Khusid
> Cc: sctp-impl@external.cisco.com
> Subject: Re: SO_REUSEADDR setsockopt() and SCTP
>
>
> Anatoly,
>
> POSIX:
>
> SO_REUSEADDR
> Specifies that the rules used in validating addresses supplied to
> bind()
> should allow reuse of local addresses, if this is supported by the
> protocol.
> This option takes an int value. This is a boolean option.
>
> SO_REUSEADDR is necessary to bind to a protocol address that is already
> listening or connected (or in the case of TCP in timed wait as well).
>
> The former two are perfectly applicable to SCTP.
>
> --brian
>
> On Fri, 11 Feb 2005, Anatoly Khusid wrote:
>
> >
> > >SO_REUSEADDR is described by POSIX and is protocol independent.
> >
> > It works different on Linux SLES9 vs. Solaris when using SCTP sockets.
> > I provided an example which illustrates the differences.
> > This web site only explains how SO_REUSEADDR work with TCP.
> > Is TCP TIME_WAIT equivalent to SCTP_SHUTDOWN_PENDING ?
> >
> >
> > >You can use setsockopt() to set the SO_REUSEADDR socket option, which
> > explicitly
> > >allows a process to bind to a port which remains in TIME_WAIT (it still
> > only
> > >allows a single process to be bound to that port). This is the both the
> > simplest
> > >and the most effective option for reducing the "address already in use"
> > error.
> >
> > http://hea-www.harvard.edu/~fine/Tech/addrinuse.html
> >
> > -----Original Message-----
> > From: Brian F. G. Bidulock [mailto:bidulock@openss7.org]
> > Sent: Friday, February 11, 2005 5:04 PM
> > To: Anatoly Khusid
> > Cc: sctp-impl@external.cisco.com
> > Subject: Re: SO_REUSEADDR setsockopt() and SCTP
> >
> >
> > Anatoly,
> >
> > SO_REUSEADDR is described by POSIX and is protocol independent.
> >
> > --brian
> >
> > On Fri, 11 Feb 2005, Anatoly Khusid wrote:
> >
> > > This question deals more with "SCTP Sockets API" draft. I have not seen
> > any
> > > explanation in this document regarding the usage of SO_REUSEADDR on SCTP
> > > sockets.
> > > The following code fails on Solaris 10:
> > >
> > >
> > > ADDR = Some valid address to bind
> > > fd1 = socket(PF_INET, SOCK_STREAM, IPPROTO_SCTP);
> > > setsockopt(fd1, SOL_SOCKET, SO_REUSEADDR)
> > > bind(fd1, ADDR)
> > > fd2 = socket(PF_INET, SOCK_STREAM, IPPROTO_SCTP);
> > > setsockopt(fd2, SOL_SOCKET, SO_REUSEADDR)
> > > bind(fd2, ADDR) <=== Fails with errno="Address in use"
> > >
> > >
> > > However, the above code works fine on Linux SLES9. Does it mean that
> > Linux
> > > has a bug, or this is something implementation dependent?
> > > What is the right behavior for SO_REUSEADDR on SCTP sockets?
> > > Do you think this should be explained/documented in "SCTP Sockets API"?
> > >
> > > Thanks,
> > >
> > > Anatoly Khusid
> >
> > --
> > Brian F. G. Bidulock ¦ The reasonable man adapts himself to the ¦
> > bidulock@openss7.org ¦ world; the unreasonable one persists in ¦
> > http://www.openss7.org/ ¦ trying to adapt the world to himself. ¦
> > ¦ Therefore all progress depends on the ¦
> > ¦ unreasonable man. -- George Bernard Shaw ¦
>
> --
> Brian F. G. Bidulock ¦ The reasonable man adapts himself to the ¦
> bidulock@openss7.org ¦ world; the unreasonable one persists in ¦
> http://www.openss7.org/ ¦ trying to adapt the world to himself. ¦
> ¦ Therefore all progress depends on the ¦
> ¦ unreasonable man. -- George Bernard Shaw ¦

-- 
Brian F. G. Bidulock    ¦ The reasonable man adapts himself to the ¦
bidulock@openss7.org    ¦ world; the unreasonable one persists in  ¦
http://www.openss7.org/ ¦ trying  to adapt the  world  to himself. ¦
                        ¦ Therefore  all  progress  depends on the ¦
                        ¦ unreasonable man. -- George Bernard Shaw ¦
Received on Mon Feb 14 09:01:27 2005

This archive was generated by hypermail 2.1.8 : Mon Mar 13 2006 - 15:22:24 EST