fix routedDispatch

This commit is contained in:
yuzuki999
2023-09-25 16:20:12 +08:00
parent 94817e0f82
commit 2d44470f24

View File

@@ -414,48 +414,48 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
} }
sessionInbound := session.InboundFromContext(ctx) sessionInbound := session.InboundFromContext(ctx)
if l != nil { if sessionInbound.User != nil {
// del connect count if l != nil {
if sessionInbound.User != nil { // del connect count
if destination.Network == net.Network_TCP { if destination.Network == net.Network_TCP {
defer func() { defer func() {
l.ConnLimiter.DelConnCount(sessionInbound.User.Email, sessionInbound.Source.Address.IP().String()) l.ConnLimiter.DelConnCount(sessionInbound.User.Email, sessionInbound.Source.Address.IP().String())
}() }()
} }
} else {
var err error
l, err = limiter.GetLimiter(sessionInbound.Tag)
if err != nil {
newError("get limiter ", sessionInbound.Tag, " error: ", err).AtWarning().WriteToLog(session.ExportIDToError(ctx))
}
} }
} else { if l != nil {
var err error var destStr string
l, err = limiter.GetLimiter(sessionInbound.Tag) if destination.Address.Family().IsDomain() {
if err != nil { destStr = destination.Address.Domain()
newError("get limiter ", sessionInbound.Tag, " error: ", err).AtWarning().WriteToLog(session.ExportIDToError(ctx)) } else {
} destStr = destination.Address.IP().String()
} }
var destStr string if l.CheckDomainRule(destStr) {
if destination.Address.Family().IsDomain() {
destStr = destination.Address.Domain()
} else {
destStr = destination.Address.IP().String()
}
if l != nil {
if l.CheckDomainRule(destStr) {
newError(fmt.Sprintf(
"User %s access domain %s reject by rule",
sessionInbound.User.Email,
destStr)).AtWarning().WriteToLog(session.ExportIDToError(ctx))
common.Close(link.Writer)
common.Interrupt(link.Reader)
return
}
if len(protocol) != 0 {
if l.CheckProtocolRule(protocol) {
newError(fmt.Sprintf( newError(fmt.Sprintf(
"User %s access protocol %s reject by rule", "User %s access domain %s reject by rule",
sessionInbound.User.Email, sessionInbound.User.Email,
protocol)).AtWarning().WriteToLog(session.ExportIDToError(ctx)) destStr)).AtWarning().WriteToLog(session.ExportIDToError(ctx))
common.Close(link.Writer) common.Close(link.Writer)
common.Interrupt(link.Reader) common.Interrupt(link.Reader)
return return
} }
if len(protocol) != 0 {
if l.CheckProtocolRule(protocol) {
newError(fmt.Sprintf(
"User %s access protocol %s reject by rule",
sessionInbound.User.Email,
protocol)).AtWarning().WriteToLog(session.ExportIDToError(ctx))
common.Close(link.Writer)
common.Interrupt(link.Reader)
return
}
}
} }
} }