mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
server: do not allow a session to setup UDP tracks from different IPs
This commit is contained in:
@@ -257,3 +257,11 @@ type ErrServerPathHasChanged struct {
|
|||||||
func (e ErrServerPathHasChanged) Error() string {
|
func (e ErrServerPathHasChanged) Error() string {
|
||||||
return fmt.Sprintf("path has changed, was '%s', now is '%s'", e.Prev, e.Cur)
|
return fmt.Sprintf("path has changed, was '%s', now is '%s'", e.Prev, e.Cur)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrServerCannotSetupFromDifferentIPs is an error that can be returned by a server.
|
||||||
|
type ErrServerCannotSetupFromDifferentIPs struct{}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e ErrServerCannotSetupFromDifferentIPs) Error() string {
|
||||||
|
return "cannot setup tracks from different IPs"
|
||||||
|
}
|
||||||
|
@@ -587,6 +587,14 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
|||||||
StatusCode: base.StatusBadRequest,
|
StatusCode: base.StatusBadRequest,
|
||||||
}, liberrors.ErrServerTransportHeaderNoClientPorts{}
|
}, liberrors.ErrServerTransportHeaderNoClientPorts{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ss.setuppedTracks != nil &&
|
||||||
|
(!ss.udpIP.Equal(sc.ip()) || ss.udpZone != sc.zone()) {
|
||||||
|
return &base.Response{
|
||||||
|
StatusCode: base.StatusBadRequest,
|
||||||
|
}, liberrors.ErrServerCannotSetupFromDifferentIPs{}
|
||||||
|
}
|
||||||
|
|
||||||
} else if ss.s.MulticastIPRange == "" {
|
} else if ss.s.MulticastIPRange == "" {
|
||||||
return &base.Response{
|
return &base.Response{
|
||||||
StatusCode: base.StatusUnsupportedTransport,
|
StatusCode: base.StatusUnsupportedTransport,
|
||||||
@@ -672,6 +680,9 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
|||||||
|
|
||||||
switch {
|
switch {
|
||||||
case delivery == base.StreamDeliveryMulticast:
|
case delivery == base.StreamDeliveryMulticast:
|
||||||
|
ss.udpIP = sc.ip()
|
||||||
|
ss.udpZone = sc.zone()
|
||||||
|
|
||||||
th.Protocol = base.StreamProtocolUDP
|
th.Protocol = base.StreamProtocolUDP
|
||||||
de := base.StreamDeliveryMulticast
|
de := base.StreamDeliveryMulticast
|
||||||
th.Delivery = &de
|
th.Delivery = &de
|
||||||
@@ -685,6 +696,9 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
|||||||
}
|
}
|
||||||
|
|
||||||
case inTH.Protocol == base.StreamProtocolUDP:
|
case inTH.Protocol == base.StreamProtocolUDP:
|
||||||
|
ss.udpIP = sc.ip()
|
||||||
|
ss.udpZone = sc.zone()
|
||||||
|
|
||||||
sst.udpRTPPort = inTH.ClientPorts[0]
|
sst.udpRTPPort = inTH.ClientPorts[0]
|
||||||
sst.udpRTCPPort = inTH.ClientPorts[1]
|
sst.udpRTCPPort = inTH.ClientPorts[1]
|
||||||
|
|
||||||
@@ -781,10 +795,7 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
|||||||
if res.StatusCode == base.StatusOK {
|
if res.StatusCode == base.StatusOK {
|
||||||
ss.state = ServerSessionStateRead
|
ss.state = ServerSessionStateRead
|
||||||
|
|
||||||
if *ss.setuppedProtocol == base.StreamProtocolUDP {
|
if *ss.setuppedProtocol == base.StreamProtocolTCP {
|
||||||
ss.udpIP = sc.ip()
|
|
||||||
ss.udpZone = sc.zone()
|
|
||||||
} else {
|
|
||||||
ss.tcpConn = sc
|
ss.tcpConn = sc
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -877,10 +888,7 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
|||||||
path, query := base.PathSplitQuery(pathAndQuery)
|
path, query := base.PathSplitQuery(pathAndQuery)
|
||||||
|
|
||||||
// allow to use WriteFrame() before response
|
// allow to use WriteFrame() before response
|
||||||
if *ss.setuppedProtocol == base.StreamProtocolUDP {
|
if *ss.setuppedProtocol == base.StreamProtocolTCP {
|
||||||
ss.udpIP = sc.ip()
|
|
||||||
ss.udpZone = sc.zone()
|
|
||||||
} else {
|
|
||||||
ss.tcpConn = sc
|
ss.tcpConn = sc
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -919,8 +927,6 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
|||||||
return res, liberrors.ErrServerTCPFramesEnable{}
|
return res, liberrors.ErrServerTCPFramesEnable{}
|
||||||
}
|
}
|
||||||
|
|
||||||
ss.udpIP = nil
|
|
||||||
ss.udpZone = ""
|
|
||||||
ss.tcpConn = nil
|
ss.tcpConn = nil
|
||||||
|
|
||||||
return res, err
|
return res, err
|
||||||
@@ -964,8 +970,6 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
|||||||
ss.setuppedStream.readerSetInactive(ss)
|
ss.setuppedStream.readerSetInactive(ss)
|
||||||
|
|
||||||
ss.state = ServerSessionStatePreRead
|
ss.state = ServerSessionStatePreRead
|
||||||
ss.udpIP = nil
|
|
||||||
ss.udpZone = ""
|
|
||||||
ss.tcpConn = nil
|
ss.tcpConn = nil
|
||||||
|
|
||||||
if *ss.setuppedProtocol == base.StreamProtocolUDP {
|
if *ss.setuppedProtocol == base.StreamProtocolUDP {
|
||||||
@@ -976,8 +980,6 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
|||||||
|
|
||||||
case ServerSessionStatePublish:
|
case ServerSessionStatePublish:
|
||||||
ss.state = ServerSessionStatePrePublish
|
ss.state = ServerSessionStatePrePublish
|
||||||
ss.udpIP = nil
|
|
||||||
ss.udpZone = ""
|
|
||||||
ss.tcpConn = nil
|
ss.tcpConn = nil
|
||||||
|
|
||||||
if *ss.setuppedProtocol == base.StreamProtocolUDP {
|
if *ss.setuppedProtocol == base.StreamProtocolUDP {
|
||||||
|
Reference in New Issue
Block a user