瀏覽代碼

[SCTP]: Allow unspecified port in sctp_bindx()

Allow sctp_bindx() to accept multiple address with
unspecified port.  In this case, all addresses inherit
the first bound port.  We still catch full mis-matches.

Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
Acked-by: Sridhar Samudrala <sri@us.ibm.com>
Vlad Yasevich 18 年之前
父節點
當前提交
8b35805693
共有 1 個文件被更改,包括 11 次插入4 次删除
  1. 11 4
      net/sctp/socket.c

+ 11 - 4
net/sctp/socket.c

@@ -333,12 +333,19 @@ SCTP_STATIC int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
 	if (!sp->pf->bind_verify(sp, addr))
 	if (!sp->pf->bind_verify(sp, addr))
 		return -EADDRNOTAVAIL;
 		return -EADDRNOTAVAIL;
 
 
-	/* We must either be unbound, or bind to the same port.  */
-	if (bp->port && (snum != bp->port)) {
-		SCTP_DEBUG_PRINTK("sctp_do_bind:"
+	/* We must either be unbound, or bind to the same port.
+	 * It's OK to allow 0 ports if we are already bound.
+	 * We'll just inhert an already bound port in this case
+	 */
+	if (bp->port) {
+		if (!snum)
+			snum = bp->port;
+		else if (snum != bp->port) {
+			SCTP_DEBUG_PRINTK("sctp_do_bind:"
 				  " New port %d does not match existing port "
 				  " New port %d does not match existing port "
 				  "%d.\n", snum, bp->port);
 				  "%d.\n", snum, bp->port);
-		return -EINVAL;
+			return -EINVAL;
+		}
 	}
 	}
 
 
 	if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE))
 	if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE))