From 40d599463bbca82e826a51db5ffae879fb1f4ec6 Mon Sep 17 00:00:00 2001 From: Nikhil Malik Date: Thu, 7 Mar 2024 12:51:37 +0900 Subject: [PATCH] Removed unwanted files and put a validation check before creating bfd session --- .../operations/delete_config_bfd_remote_ip.go | 58 --- .../delete_config_bfd_remote_ip_parameters.go | 101 ----- .../delete_config_bfd_remote_ip_responses.go | 354 ------------------ .../delete_config_bfd_remote_ip_urlbuilder.go | 113 ------ loxinet/cluster.go | 10 + 5 files changed, 10 insertions(+), 626 deletions(-) delete mode 100644 api/restapi/operations/delete_config_bfd_remote_ip.go delete mode 100644 api/restapi/operations/delete_config_bfd_remote_ip_parameters.go delete mode 100644 api/restapi/operations/delete_config_bfd_remote_ip_responses.go delete mode 100644 api/restapi/operations/delete_config_bfd_remote_ip_urlbuilder.go diff --git a/api/restapi/operations/delete_config_bfd_remote_ip.go b/api/restapi/operations/delete_config_bfd_remote_ip.go deleted file mode 100644 index 00154f4e2..000000000 --- a/api/restapi/operations/delete_config_bfd_remote_ip.go +++ /dev/null @@ -1,58 +0,0 @@ -// Code generated by go-swagger; DO NOT EDIT. - -package operations - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the generate command - -import ( - "net/http" - - "github.com/go-openapi/runtime/middleware" -) - -// DeleteConfigBfdRemoteIPHandlerFunc turns a function with the right signature into a delete config bfd remote IP handler -type DeleteConfigBfdRemoteIPHandlerFunc func(DeleteConfigBfdRemoteIPParams) middleware.Responder - -// Handle executing the request and returning a response -func (fn DeleteConfigBfdRemoteIPHandlerFunc) Handle(params DeleteConfigBfdRemoteIPParams) middleware.Responder { - return fn(params) -} - -// DeleteConfigBfdRemoteIPHandler interface for that can handle valid delete config bfd remote IP params -type DeleteConfigBfdRemoteIPHandler interface { - Handle(DeleteConfigBfdRemoteIPParams) middleware.Responder -} - -// NewDeleteConfigBfdRemoteIP creates a new http.Handler for the delete config bfd remote IP operation -func NewDeleteConfigBfdRemoteIP(ctx *middleware.Context, handler DeleteConfigBfdRemoteIPHandler) *DeleteConfigBfdRemoteIP { - return &DeleteConfigBfdRemoteIP{Context: ctx, Handler: handler} -} - -/* - DeleteConfigBfdRemoteIP swagger:route DELETE /config/bfd/{remote_ip} deleteConfigBfdRemoteIp - -# Delete a BFD session - -Delete a BFD session -*/ -type DeleteConfigBfdRemoteIP struct { - Context *middleware.Context - Handler DeleteConfigBfdRemoteIPHandler -} - -func (o *DeleteConfigBfdRemoteIP) ServeHTTP(rw http.ResponseWriter, r *http.Request) { - route, rCtx, _ := o.Context.RouteInfo(r) - if rCtx != nil { - *r = *rCtx - } - var Params = NewDeleteConfigBfdRemoteIPParams() - if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params - o.Context.Respond(rw, r, route.Produces, route, err) - return - } - - res := o.Handler.Handle(Params) // actually handle the request - o.Context.Respond(rw, r, route.Produces, route, res) - -} diff --git a/api/restapi/operations/delete_config_bfd_remote_ip_parameters.go b/api/restapi/operations/delete_config_bfd_remote_ip_parameters.go deleted file mode 100644 index 20d4bbe44..000000000 --- a/api/restapi/operations/delete_config_bfd_remote_ip_parameters.go +++ /dev/null @@ -1,101 +0,0 @@ -// Code generated by go-swagger; DO NOT EDIT. - -package operations - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -import ( - "net/http" - - "github.com/go-openapi/errors" - "github.com/go-openapi/runtime" - "github.com/go-openapi/runtime/middleware" - "github.com/go-openapi/strfmt" -) - -// NewDeleteConfigBfdRemoteIPParams creates a new DeleteConfigBfdRemoteIPParams object -// -// There are no default values defined in the spec. -func NewDeleteConfigBfdRemoteIPParams() DeleteConfigBfdRemoteIPParams { - - return DeleteConfigBfdRemoteIPParams{} -} - -// DeleteConfigBfdRemoteIPParams contains all the bound params for the delete config bfd remote IP operation -// typically these are obtained from a http.Request -// -// swagger:parameters DeleteConfigBfdRemoteIP -type DeleteConfigBfdRemoteIPParams struct { - - // HTTP Request Object - HTTPRequest *http.Request `json:"-"` - - /*Cluster instance name - In: query - */ - Instance *string - /*Remote IP address - Required: true - In: path - */ - RemoteIP string -} - -// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface -// for simple values it will use straight method calls. -// -// To ensure default values, the struct must have been initialized with NewDeleteConfigBfdRemoteIPParams() beforehand. -func (o *DeleteConfigBfdRemoteIPParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { - var res []error - - o.HTTPRequest = r - - qs := runtime.Values(r.URL.Query()) - - qInstance, qhkInstance, _ := qs.GetOK("instance") - if err := o.bindInstance(qInstance, qhkInstance, route.Formats); err != nil { - res = append(res, err) - } - - rRemoteIP, rhkRemoteIP, _ := route.Params.GetOK("remote_ip") - if err := o.bindRemoteIP(rRemoteIP, rhkRemoteIP, route.Formats); err != nil { - res = append(res, err) - } - if len(res) > 0 { - return errors.CompositeValidationError(res...) - } - return nil -} - -// bindInstance binds and validates parameter Instance from query. -func (o *DeleteConfigBfdRemoteIPParams) bindInstance(rawData []string, hasKey bool, formats strfmt.Registry) error { - var raw string - if len(rawData) > 0 { - raw = rawData[len(rawData)-1] - } - - // Required: false - // AllowEmptyValue: false - - if raw == "" { // empty values pass all other validations - return nil - } - o.Instance = &raw - - return nil -} - -// bindRemoteIP binds and validates parameter RemoteIP from path. -func (o *DeleteConfigBfdRemoteIPParams) bindRemoteIP(rawData []string, hasKey bool, formats strfmt.Registry) error { - var raw string - if len(rawData) > 0 { - raw = rawData[len(rawData)-1] - } - - // Required: true - // Parameter is provided by construction from the route - o.RemoteIP = raw - - return nil -} diff --git a/api/restapi/operations/delete_config_bfd_remote_ip_responses.go b/api/restapi/operations/delete_config_bfd_remote_ip_responses.go deleted file mode 100644 index d9ccb53f4..000000000 --- a/api/restapi/operations/delete_config_bfd_remote_ip_responses.go +++ /dev/null @@ -1,354 +0,0 @@ -// Code generated by go-swagger; DO NOT EDIT. - -package operations - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -import ( - "net/http" - - "github.com/go-openapi/runtime" - - "github.com/loxilb-io/loxilb/api/models" -) - -// DeleteConfigBfdRemoteIPNoContentCode is the HTTP code returned for type DeleteConfigBfdRemoteIPNoContent -const DeleteConfigBfdRemoteIPNoContentCode int = 204 - -/* -DeleteConfigBfdRemoteIPNoContent OK - -swagger:response deleteConfigBfdRemoteIpNoContent -*/ -type DeleteConfigBfdRemoteIPNoContent struct { -} - -// NewDeleteConfigBfdRemoteIPNoContent creates DeleteConfigBfdRemoteIPNoContent with default headers values -func NewDeleteConfigBfdRemoteIPNoContent() *DeleteConfigBfdRemoteIPNoContent { - - return &DeleteConfigBfdRemoteIPNoContent{} -} - -// WriteResponse to the client -func (o *DeleteConfigBfdRemoteIPNoContent) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses - - rw.WriteHeader(204) -} - -// DeleteConfigBfdRemoteIPBadRequestCode is the HTTP code returned for type DeleteConfigBfdRemoteIPBadRequest -const DeleteConfigBfdRemoteIPBadRequestCode int = 400 - -/* -DeleteConfigBfdRemoteIPBadRequest Malformed arguments for API call - -swagger:response deleteConfigBfdRemoteIpBadRequest -*/ -type DeleteConfigBfdRemoteIPBadRequest struct { - - /* - In: Body - */ - Payload *models.Error `json:"body,omitempty"` -} - -// NewDeleteConfigBfdRemoteIPBadRequest creates DeleteConfigBfdRemoteIPBadRequest with default headers values -func NewDeleteConfigBfdRemoteIPBadRequest() *DeleteConfigBfdRemoteIPBadRequest { - - return &DeleteConfigBfdRemoteIPBadRequest{} -} - -// WithPayload adds the payload to the delete config bfd remote Ip bad request response -func (o *DeleteConfigBfdRemoteIPBadRequest) WithPayload(payload *models.Error) *DeleteConfigBfdRemoteIPBadRequest { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the delete config bfd remote Ip bad request response -func (o *DeleteConfigBfdRemoteIPBadRequest) SetPayload(payload *models.Error) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *DeleteConfigBfdRemoteIPBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(400) - if o.Payload != nil { - payload := o.Payload - if err := producer.Produce(rw, payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} - -// DeleteConfigBfdRemoteIPUnauthorizedCode is the HTTP code returned for type DeleteConfigBfdRemoteIPUnauthorized -const DeleteConfigBfdRemoteIPUnauthorizedCode int = 401 - -/* -DeleteConfigBfdRemoteIPUnauthorized Invalid authentication credentials - -swagger:response deleteConfigBfdRemoteIpUnauthorized -*/ -type DeleteConfigBfdRemoteIPUnauthorized struct { - - /* - In: Body - */ - Payload *models.Error `json:"body,omitempty"` -} - -// NewDeleteConfigBfdRemoteIPUnauthorized creates DeleteConfigBfdRemoteIPUnauthorized with default headers values -func NewDeleteConfigBfdRemoteIPUnauthorized() *DeleteConfigBfdRemoteIPUnauthorized { - - return &DeleteConfigBfdRemoteIPUnauthorized{} -} - -// WithPayload adds the payload to the delete config bfd remote Ip unauthorized response -func (o *DeleteConfigBfdRemoteIPUnauthorized) WithPayload(payload *models.Error) *DeleteConfigBfdRemoteIPUnauthorized { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the delete config bfd remote Ip unauthorized response -func (o *DeleteConfigBfdRemoteIPUnauthorized) SetPayload(payload *models.Error) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *DeleteConfigBfdRemoteIPUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(401) - if o.Payload != nil { - payload := o.Payload - if err := producer.Produce(rw, payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} - -// DeleteConfigBfdRemoteIPForbiddenCode is the HTTP code returned for type DeleteConfigBfdRemoteIPForbidden -const DeleteConfigBfdRemoteIPForbiddenCode int = 403 - -/* -DeleteConfigBfdRemoteIPForbidden Capacity insufficient - -swagger:response deleteConfigBfdRemoteIpForbidden -*/ -type DeleteConfigBfdRemoteIPForbidden struct { - - /* - In: Body - */ - Payload *models.Error `json:"body,omitempty"` -} - -// NewDeleteConfigBfdRemoteIPForbidden creates DeleteConfigBfdRemoteIPForbidden with default headers values -func NewDeleteConfigBfdRemoteIPForbidden() *DeleteConfigBfdRemoteIPForbidden { - - return &DeleteConfigBfdRemoteIPForbidden{} -} - -// WithPayload adds the payload to the delete config bfd remote Ip forbidden response -func (o *DeleteConfigBfdRemoteIPForbidden) WithPayload(payload *models.Error) *DeleteConfigBfdRemoteIPForbidden { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the delete config bfd remote Ip forbidden response -func (o *DeleteConfigBfdRemoteIPForbidden) SetPayload(payload *models.Error) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *DeleteConfigBfdRemoteIPForbidden) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(403) - if o.Payload != nil { - payload := o.Payload - if err := producer.Produce(rw, payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} - -// DeleteConfigBfdRemoteIPNotFoundCode is the HTTP code returned for type DeleteConfigBfdRemoteIPNotFound -const DeleteConfigBfdRemoteIPNotFoundCode int = 404 - -/* -DeleteConfigBfdRemoteIPNotFound Resource not found - -swagger:response deleteConfigBfdRemoteIpNotFound -*/ -type DeleteConfigBfdRemoteIPNotFound struct { - - /* - In: Body - */ - Payload *models.Error `json:"body,omitempty"` -} - -// NewDeleteConfigBfdRemoteIPNotFound creates DeleteConfigBfdRemoteIPNotFound with default headers values -func NewDeleteConfigBfdRemoteIPNotFound() *DeleteConfigBfdRemoteIPNotFound { - - return &DeleteConfigBfdRemoteIPNotFound{} -} - -// WithPayload adds the payload to the delete config bfd remote Ip not found response -func (o *DeleteConfigBfdRemoteIPNotFound) WithPayload(payload *models.Error) *DeleteConfigBfdRemoteIPNotFound { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the delete config bfd remote Ip not found response -func (o *DeleteConfigBfdRemoteIPNotFound) SetPayload(payload *models.Error) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *DeleteConfigBfdRemoteIPNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(404) - if o.Payload != nil { - payload := o.Payload - if err := producer.Produce(rw, payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} - -// DeleteConfigBfdRemoteIPConflictCode is the HTTP code returned for type DeleteConfigBfdRemoteIPConflict -const DeleteConfigBfdRemoteIPConflictCode int = 409 - -/* -DeleteConfigBfdRemoteIPConflict Resource Conflict. BFD session already exists - -swagger:response deleteConfigBfdRemoteIpConflict -*/ -type DeleteConfigBfdRemoteIPConflict struct { - - /* - In: Body - */ - Payload *models.Error `json:"body,omitempty"` -} - -// NewDeleteConfigBfdRemoteIPConflict creates DeleteConfigBfdRemoteIPConflict with default headers values -func NewDeleteConfigBfdRemoteIPConflict() *DeleteConfigBfdRemoteIPConflict { - - return &DeleteConfigBfdRemoteIPConflict{} -} - -// WithPayload adds the payload to the delete config bfd remote Ip conflict response -func (o *DeleteConfigBfdRemoteIPConflict) WithPayload(payload *models.Error) *DeleteConfigBfdRemoteIPConflict { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the delete config bfd remote Ip conflict response -func (o *DeleteConfigBfdRemoteIPConflict) SetPayload(payload *models.Error) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *DeleteConfigBfdRemoteIPConflict) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(409) - if o.Payload != nil { - payload := o.Payload - if err := producer.Produce(rw, payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} - -// DeleteConfigBfdRemoteIPInternalServerErrorCode is the HTTP code returned for type DeleteConfigBfdRemoteIPInternalServerError -const DeleteConfigBfdRemoteIPInternalServerErrorCode int = 500 - -/* -DeleteConfigBfdRemoteIPInternalServerError Internal service error - -swagger:response deleteConfigBfdRemoteIpInternalServerError -*/ -type DeleteConfigBfdRemoteIPInternalServerError struct { - - /* - In: Body - */ - Payload *models.Error `json:"body,omitempty"` -} - -// NewDeleteConfigBfdRemoteIPInternalServerError creates DeleteConfigBfdRemoteIPInternalServerError with default headers values -func NewDeleteConfigBfdRemoteIPInternalServerError() *DeleteConfigBfdRemoteIPInternalServerError { - - return &DeleteConfigBfdRemoteIPInternalServerError{} -} - -// WithPayload adds the payload to the delete config bfd remote Ip internal server error response -func (o *DeleteConfigBfdRemoteIPInternalServerError) WithPayload(payload *models.Error) *DeleteConfigBfdRemoteIPInternalServerError { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the delete config bfd remote Ip internal server error response -func (o *DeleteConfigBfdRemoteIPInternalServerError) SetPayload(payload *models.Error) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *DeleteConfigBfdRemoteIPInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(500) - if o.Payload != nil { - payload := o.Payload - if err := producer.Produce(rw, payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} - -// DeleteConfigBfdRemoteIPServiceUnavailableCode is the HTTP code returned for type DeleteConfigBfdRemoteIPServiceUnavailable -const DeleteConfigBfdRemoteIPServiceUnavailableCode int = 503 - -/* -DeleteConfigBfdRemoteIPServiceUnavailable Maintanence mode - -swagger:response deleteConfigBfdRemoteIpServiceUnavailable -*/ -type DeleteConfigBfdRemoteIPServiceUnavailable struct { - - /* - In: Body - */ - Payload *models.Error `json:"body,omitempty"` -} - -// NewDeleteConfigBfdRemoteIPServiceUnavailable creates DeleteConfigBfdRemoteIPServiceUnavailable with default headers values -func NewDeleteConfigBfdRemoteIPServiceUnavailable() *DeleteConfigBfdRemoteIPServiceUnavailable { - - return &DeleteConfigBfdRemoteIPServiceUnavailable{} -} - -// WithPayload adds the payload to the delete config bfd remote Ip service unavailable response -func (o *DeleteConfigBfdRemoteIPServiceUnavailable) WithPayload(payload *models.Error) *DeleteConfigBfdRemoteIPServiceUnavailable { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the delete config bfd remote Ip service unavailable response -func (o *DeleteConfigBfdRemoteIPServiceUnavailable) SetPayload(payload *models.Error) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *DeleteConfigBfdRemoteIPServiceUnavailable) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(503) - if o.Payload != nil { - payload := o.Payload - if err := producer.Produce(rw, payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} diff --git a/api/restapi/operations/delete_config_bfd_remote_ip_urlbuilder.go b/api/restapi/operations/delete_config_bfd_remote_ip_urlbuilder.go deleted file mode 100644 index 68d5b4926..000000000 --- a/api/restapi/operations/delete_config_bfd_remote_ip_urlbuilder.go +++ /dev/null @@ -1,113 +0,0 @@ -// Code generated by go-swagger; DO NOT EDIT. - -package operations - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the generate command - -import ( - "errors" - "net/url" - golangswaggerpaths "path" - "strings" -) - -// DeleteConfigBfdRemoteIPURL generates an URL for the delete config bfd remote IP operation -type DeleteConfigBfdRemoteIPURL struct { - RemoteIP string - - Instance *string - - _basePath string - // avoid unkeyed usage - _ struct{} -} - -// WithBasePath sets the base path for this url builder, only required when it's different from the -// base path specified in the swagger spec. -// When the value of the base path is an empty string -func (o *DeleteConfigBfdRemoteIPURL) WithBasePath(bp string) *DeleteConfigBfdRemoteIPURL { - o.SetBasePath(bp) - return o -} - -// SetBasePath sets the base path for this url builder, only required when it's different from the -// base path specified in the swagger spec. -// When the value of the base path is an empty string -func (o *DeleteConfigBfdRemoteIPURL) SetBasePath(bp string) { - o._basePath = bp -} - -// Build a url path and query string -func (o *DeleteConfigBfdRemoteIPURL) Build() (*url.URL, error) { - var _result url.URL - - var _path = "/config/bfd/{remote_ip}" - - remoteIP := o.RemoteIP - if remoteIP != "" { - _path = strings.Replace(_path, "{remote_ip}", remoteIP, -1) - } else { - return nil, errors.New("remoteIp is required on DeleteConfigBfdRemoteIPURL") - } - - _basePath := o._basePath - if _basePath == "" { - _basePath = "/netlox/v1" - } - _result.Path = golangswaggerpaths.Join(_basePath, _path) - - qs := make(url.Values) - - var instanceQ string - if o.Instance != nil { - instanceQ = *o.Instance - } - if instanceQ != "" { - qs.Set("instance", instanceQ) - } - - _result.RawQuery = qs.Encode() - - return &_result, nil -} - -// Must is a helper function to panic when the url builder returns an error -func (o *DeleteConfigBfdRemoteIPURL) Must(u *url.URL, err error) *url.URL { - if err != nil { - panic(err) - } - if u == nil { - panic("url can't be nil") - } - return u -} - -// String returns the string representation of the path with query string -func (o *DeleteConfigBfdRemoteIPURL) String() string { - return o.Must(o.Build()).String() -} - -// BuildFull builds a full url with scheme, host, path and query string -func (o *DeleteConfigBfdRemoteIPURL) BuildFull(scheme, host string) (*url.URL, error) { - if scheme == "" { - return nil, errors.New("scheme is required for a full url on DeleteConfigBfdRemoteIPURL") - } - if host == "" { - return nil, errors.New("host is required for a full url on DeleteConfigBfdRemoteIPURL") - } - - base, err := o.Build() - if err != nil { - return nil, err - } - - base.Scheme = scheme - base.Host = host - return base, nil -} - -// StringFull returns the string representation of a complete url -func (o *DeleteConfigBfdRemoteIPURL) StringFull(scheme, host string) string { - return o.Must(o.BuildFull(scheme, host)).String() -} diff --git a/loxinet/cluster.go b/loxinet/cluster.go index f6de07b3f..a03598440 100644 --- a/loxinet/cluster.go +++ b/loxinet/cluster.go @@ -288,6 +288,16 @@ func (h *CIStateH) CIBFDSessionAdd(bm cmn.BFDMod) (int, error) { return -1, errors.New("cluster instance not found") } + ip := net.ParseIP(string(bm.RemoteIP)) + if ip == nil { + return -1, errors.New("remoteIP address malformed") + } + + myIP := net.ParseIP(string(bm.SourceIP)) + if myIP == nil { + return -1, errors.New("source address malformed") + } + if !h.SpawnKa { tk.LogIt(tk.LogInfo, "[CLUSTER] Cluster Instance %s starting BFD..\n", bm.Instance) h.SpawnKa = true