package pkg import ( "errors" "strconv" "strings" ) // SCTPProfile : Virtual server SCTP traffic profile configuration type SCTPProfile struct { ProfileCommon AlternateAddresses []string `json:"alternate_addresses"` // none ClientSideMultihoming string `json:"client_side_multihoming"` // disabled CookieExpiration int `json:"cookie_expiration"` // 60 HeartbeatInterval int `json:"heartbeat_interval"` // 30 HeartbeatMaxBurst int `json:"heartbeat_max_burst"` // 1 IdleTimeout int `json:"idle_timeout"` // 300 InStreams int `json:"in_streams"` // 2 InitMaxRetries int `json:"init_max_retries"` // 8 IPTOS int `json:"ip_tos"` // 0 LinkQOS int `json:"link_qos"` // 0 MaxBurst int `json:"max_burst"` // 4 MaxCommunicationPaths int `json:"max_communication_paths"` // 16 MaxPathRetransmitLimit int `json:"max_path_retransmit_limit"` // 5 OutStreams int `json:"out_streams"` // 2 ProxyBufferHigh int `json:"proxy_buffer_high"` // 16384 ProxyBufferLow int `json:"proxy_buffer_low"` // 4096 ReceiveChunks int `json:"receive_chunks"` // 256 ReceiveOrdered string `json:"receive_ordered"` // enabled ReceiveWindowSize int `json:"receive_window_size"` // 65535 ResetOnTimeout string `json:"reset_on_timeout"` // enabled Secret string `json:"secret"` // $M$It$QXsLJBRK3sykB6NwsP1IOw== SendBufferSize int `json:"send_buffer_size"` // 65536 SendMaxRetries int `json:"send_max_retries"` // 10 SendPartial string `json:"send_partial"` // disabled ServerSideMultihoming string `json:"server_side_multihoming"` // disabled TCPShutdown string `json:"tcp_shutdown"` // disabled TransmitChunks int `json:"transmit_chunks"` // 256 } func ParseSCTP(raw string) (*SCTPProfile, error) { p := new(SCTPProfile) split := strings.Split(raw, "\n") if !strings.Contains(split[0], "ltm profile sctp") { return nil, errors.New("not an sctp profile") } p.ProfileCommon = parseCommon(raw) p.AlternateAddresses = []string{} for _, line := range split { f := strings.Fields(line) switch strings.ToLower(f[0]) { case "alternate-addresses": if f[1] != "none" { p.AlternateAddresses = f[2 : len(f)-1] } case "client-side-multihoming": p.ClientSideMultihoming = strings.Join(f[1:], " ") case "cookie-expiration": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.CookieExpiration = i case "heartbeat-interval": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.HeartbeatInterval = i case "heartbeat-max-burst": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.HeartbeatMaxBurst = i case "idle-timeout": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.IdleTimeout = i case "in-streams": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.InStreams = i case "init-max-retries": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.InitMaxRetries = i case "ip-tos": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.IPTOS = i case "link-qos": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.LinkQOS = i case "max-burst": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.MaxBurst = i case "max-communication-paths": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.MaxCommunicationPaths = i case "max-path-retransmit-limit": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.MaxPathRetransmitLimit = i case "out-streams": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.OutStreams = i case "proxy-buffer-high": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.ProxyBufferHigh = i case "proxy-buffer-low": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.ProxyBufferLow = i case "receive-chunks": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.ReceiveChunks = i case "receive-ordered": p.ReceiveOrdered = strings.Join(f[1:], " ") case "receive-window-size": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.ReceiveWindowSize = i case "reset-on-timeout": p.ResetOnTimeout = strings.Join(f[1:], " ") case "secret": p.Secret = strings.Join(f[1:], " ") case "send-buffer-size": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.SendBufferSize = i case "send-max-retries": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.SendMaxRetries = i case "send-partial": p.SendPartial = strings.Join(f[1:], " ") case "server-side-multihoming": p.ServerSideMultihoming = strings.Join(f[1:], " ") case "tcp-shutdown": p.TCPShutdown = strings.Join(f[1:], " ") case "transmit-chunks": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.TransmitChunks = i } } return p, nil }