Skip to content

Commit ce5325c

Browse files
Vlad Yasevichdavem330
authored andcommitted
[SCTP]: Fix the SO_REUSEADDR handling to be similar to TCP.
Update the SO_REUSEADDR handling to also check for listen state. This was muliple listening server sockets can't be created and they will not steal packets from each other. Reported by Paolo Galtieri <pgaltieri@mvista.com> Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 16d00fb commit ce5325c

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

‎net/sctp/socket.c‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5020,7 +5020,8 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
50205020
struct hlist_node *node;
50215021

50225022
SCTP_DEBUG_PRINTK("sctp_get_port() found a possible match\n");
5023-
if (pp->fastreuse && sk->sk_reuse)
5023+
if (pp->fastreuse && sk->sk_reuse &&
5024+
sk->sk_state != SCTP_SS_LISTENING)
50245025
goto success;
50255026

50265027
/* Run through the list of sockets bound to the port
@@ -5037,7 +5038,8 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
50375038
struct sctp_endpoint *ep2;
50385039
ep2 = sctp_sk(sk2)->ep;
50395040

5040-
if (reuse && sk2->sk_reuse)
5041+
if (reuse && sk2->sk_reuse &&
5042+
sk2->sk_state != SCTP_SS_LISTENING)
50415043
continue;
50425044

50435045
if (sctp_bind_addr_match(&ep2->base.bind_addr, addr,
@@ -5058,18 +5060,22 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
50585060
* if sk->sk_reuse is too (that is, if the caller requested
50595061
* SO_REUSEADDR on this socket -sk-).
50605062
*/
5061-
if (hlist_empty(&pp->owner))
5062-
pp->fastreuse = sk->sk_reuse ? 1 : 0;
5063-
else if (pp->fastreuse && !sk->sk_reuse)
5063+
if (hlist_empty(&pp->owner)) {
5064+
if (sk->sk_reuse && sk->sk_state != SCTP_SS_LISTENING)
5065+
pp->fastreuse = 1;
5066+
else
5067+
pp->fastreuse = 0;
5068+
} else if (pp->fastreuse &&
5069+
(!sk->sk_reuse || sk->sk_state == SCTP_SS_LISTENING))
50645070
pp->fastreuse = 0;
50655071

50665072
/* We are set, so fill up all the data in the hash table
50675073
* entry, tie the socket list information with the rest of the
50685074
* sockets FIXME: Blurry, NPI (ipg).
50695075
*/
50705076
success:
5071-
inet_sk(sk)->num = snum;
50725077
if (!sctp_sk(sk)->bind_hash) {
5078+
inet_sk(sk)->num = snum;
50735079
sk_add_bind_node(sk, &pp->owner);
50745080
sctp_sk(sk)->bind_hash = pp;
50755081
}
@@ -5142,12 +5148,16 @@ SCTP_STATIC int sctp_seqpacket_listen(struct sock *sk, int backlog)
51425148
* This is not currently spelled out in the SCTP sockets
51435149
* extensions draft, but follows the practice as seen in TCP
51445150
* sockets.
5151+
*
5152+
* Additionally, turn off fastreuse flag since we are not listening
51455153
*/
5154+
sk->sk_state = SCTP_SS_LISTENING;
51465155
if (!ep->base.bind_addr.port) {
51475156
if (sctp_autobind(sk))
51485157
return -EAGAIN;
5149-
}
5150-
sk->sk_state = SCTP_SS_LISTENING;
5158+
} else
5159+
sctp_sk(sk)->bind_hash->fastreuse = 0;
5160+
51515161
sctp_hash_endpoint(ep);
51525162
return 0;
51535163
}
@@ -5185,11 +5195,13 @@ SCTP_STATIC int sctp_stream_listen(struct sock *sk, int backlog)
51855195
* extensions draft, but follows the practice as seen in TCP
51865196
* sockets.
51875197
*/
5198+
sk->sk_state = SCTP_SS_LISTENING;
51885199
if (!ep->base.bind_addr.port) {
51895200
if (sctp_autobind(sk))
51905201
return -EAGAIN;
5191-
}
5192-
sk->sk_state = SCTP_SS_LISTENING;
5202+
} else
5203+
sctp_sk(sk)->bind_hash->fastreuse = 0;
5204+
51935205
sk->sk_max_ack_backlog = backlog;
51945206
sctp_hash_endpoint(ep);
51955207
return 0;

0 commit comments

Comments
 (0)