Minor linting stuff

This commit is contained in:
Juan Font Alonso 2022-03-29 16:28:08 +02:00
parent 38418e940f
commit fc181333e5

View File

@ -61,21 +61,25 @@ func (h *Headscale) getNoiseConnection(ctx *gin.Context) (*controlbase.Conn, err
next := ctx.GetHeader("Upgrade") next := ctx.GetHeader("Upgrade")
if next == "" { if next == "" {
ctx.String(http.StatusBadRequest, "missing next protocol") ctx.String(http.StatusBadRequest, "missing next protocol")
return nil, errWrongConnectionUpgrade return nil, errWrongConnectionUpgrade
} }
if next != upgradeHeaderValue { if next != upgradeHeaderValue {
ctx.String(http.StatusBadRequest, "unknown next protocol") ctx.String(http.StatusBadRequest, "unknown next protocol")
return nil, errWrongConnectionUpgrade return nil, errWrongConnectionUpgrade
} }
initB64 := ctx.GetHeader(handshakeHeaderName) initB64 := ctx.GetHeader(handshakeHeaderName)
if initB64 == "" { if initB64 == "" {
ctx.String(http.StatusBadRequest, "missing Tailscale handshake header") ctx.String(http.StatusBadRequest, "missing Tailscale handshake header")
return nil, errWrongConnectionUpgrade return nil, errWrongConnectionUpgrade
} }
init, err := base64.StdEncoding.DecodeString(initB64) init, err := base64.StdEncoding.DecodeString(initB64)
if err != nil { if err != nil {
ctx.String(http.StatusBadRequest, "invalid tailscale handshake header") ctx.String(http.StatusBadRequest, "invalid tailscale handshake header")
return nil, errWrongConnectionUpgrade return nil, errWrongConnectionUpgrade
} }
@ -83,6 +87,7 @@ func (h *Headscale) getNoiseConnection(ctx *gin.Context) (*controlbase.Conn, err
if !ok { if !ok {
log.Error().Caller().Err(err).Msgf("Hijack failed") log.Error().Caller().Err(err).Msgf("Hijack failed")
ctx.String(http.StatusInternalServerError, "HTTP does not support general TCP support") ctx.String(http.StatusInternalServerError, "HTTP does not support general TCP support")
return nil, errCannotHijack return nil, errCannotHijack
} }
@ -102,6 +107,7 @@ func (h *Headscale) getNoiseConnection(ctx *gin.Context) (*controlbase.Conn, err
} }
if err := conn.Flush(); err != nil { if err := conn.Flush(); err != nil {
netConn.Close() netConn.Close()
return nil, errCannotHijack return nil, errCannotHijack
} }
netConn = netutil.NewDrainBufConn(netConn, conn.Reader) netConn = netutil.NewDrainBufConn(netConn, conn.Reader)
@ -109,6 +115,7 @@ func (h *Headscale) getNoiseConnection(ctx *gin.Context) (*controlbase.Conn, err
nc, err := controlbase.Server(ctx.Request.Context(), netConn, *h.noisePrivateKey, init) nc, err := controlbase.Server(ctx.Request.Context(), netConn, *h.noisePrivateKey, init)
if err != nil { if err != nil {
netConn.Close() netConn.Close()
return nil, errNoiseHandshakeFailed return nil, errNoiseHandshakeFailed
} }