diff --git a/ciscoasa/interfaces.go b/ciscoasa/interfaces.go index 33b3055..f803a0a 100644 --- a/ciscoasa/interfaces.go +++ b/ciscoasa/interfaces.go @@ -26,17 +26,41 @@ type interfaceService struct { *Client } -// IPAddress represents an IPv4 address. +// SlaTracking represents an SlaTracking Settings. +type SlaTracking struct { + SlaId int `json:"slaId"` + TrackedIP string `json:"trackedIP"` + FrequencyInSeconds int `json:"frequencyInSeconds"` + DataSizeInBytes int `json:"dataSizeInBytes"` + ThresholdInMilliseconds int `json:"thresholdInMilliseconds"` + ToS int `json:"ToS"` + TimeoutInMilliseconds int `json:"timeoutInMilliseconds"` + NumPackets int `json:"numPackets"` +} + +// DhcpClient represents an DHCP Settings. +type DhcpClient struct { + SetDefaultRoute bool `json:"setDefaultRoute"` + Metric int `json:"metric"` + PrimaryTrackId int `json:"primaryTrackId"` + TrackingEnabled bool `json:"trackingEnabled"` + SlaTrackingSettings *SlaTracking `json:"slaTrackingSettings"` +} + +// Address represents a static IPv4/IPv6 address settings. +type Address struct { + Kind string `json:"kind"` + Value string `json:"value"` +} + +// IPAddress represents an IP address settings. type IPAddress struct { - IP struct { - Kind string `json:"kind"` - Value string `json:"value"` - } `json:"ip"` - NetMask struct { - Kind string `json:"kind"` - Value string `json:"value"` - } `json:"netMask"` - Kind string `json:"kind"` + IP *Address `json:"ip,omitempty"` + NetMask *Address `json:"netMask,omitempty"` + Kind string `json:"kind"` + DhcpOptionUsingMac bool `json:"dhcpOptionUsingMac,omitempty"` + DhcpBroadcast bool `json:"dhcpBroadcast,omitempty"` + DhcpClient *DhcpClient `json:"dhcpClient,omitempty"` } // UnmarshalJSON implements json.Unmarshaler interface. @@ -56,23 +80,44 @@ func (ip *IPAddress) String() string { return ip.IP.Value + "/" + bitsize } +// nDiscoveryPrefix represents an nDiscoveryPrefix list. +type NDiscoveryPrefix struct { + OffLink bool `json:"offLink"` + NoAdvertise bool `json:"noAdvertise"` + PreferredLifetime int `json:"preferredLifetime"` + ValidLifetime int `json:"validLifetime"` + HasDuration bool `json:"hasDuration"` + DefaultPrefix bool `json:"defaultPrefix"` + Kind string `json:"kind"` +} + +// Ipv6Address represents an Ipv6Address. +type Ipv6Address struct { + PrefixLength int `json:"prefixLength,omitempty"` + Standby *Address `json:"standby,omitempty"` + Address *Address `json:"address,omitempty"` + // IsEUI64 bool `json:"isEUI64"` + Kind string `json:"kind"` +} + // IPv6Info represents an IPv6 address. type IPv6Info struct { - Enabled bool `json:"enabled"` - AutoConfig bool `json:"autoConfig"` - EnforceEUI64 bool `json:"enforceEUI64"` - ManagedAddressConfig bool `json:"managedAddressConfig"` - NsInterval int `json:"nsInterval"` - DadAttempts int `json:"dadAttempts"` - NDiscoveryPrefixList []string `json:"nDiscoveryPrefixList"` - OtherStatefulConfig bool `json:"otherStatefulConfig"` - RouterAdvertInterval int `json:"routerAdvertInterval"` - RouterAdvertIntervalUnit string `json:"routerAdvertIntervalUnit"` - RouterAdvertLifetime int `json:"routerAdvertLifetime"` - SuppressRouterAdvert bool `json:"suppressRouterAdvert"` - ReachableTime int `json:"reachableTime"` - Ipv6Addresses []string `json:"ipv6Addresses"` - Kind string `json:"kind"` + Enabled bool `json:"enabled"` + AutoConfig bool `json:"autoConfig"` + EnforceEUI64 bool `json:"enforceEUI64"` + ManagedAddressConfig bool `json:"managedAddressConfig"` + NsInterval int `json:"nsInterval"` + DadAttempts int `json:"dadAttempts"` + NDiscoveryPrefixList []*NDiscoveryPrefix `json:"nDiscoveryPrefixList,omitempty"` + OtherStatefulConfig bool `json:"otherStatefulConfig"` + RouterAdvertInterval int `json:"routerAdvertInterval"` + RouterAdvertIntervalUnit string `json:"routerAdvertIntervalUnit"` + RouterAdvertLifetime int `json:"routerAdvertLifetime"` + SuppressRouterAdvert bool `json:"suppressRouterAdvert"` + ReachableTime int `json:"reachableTime"` + LinkLocalAddress *Ipv6Address `json:"linkLocalAddress,omitempty"` + Ipv6Addresses []*Ipv6Address `json:"ipv6Addresses,omitempty"` + Kind string `json:"kind"` } // UnmarshalJSON implements json.Unmarshaler interface. diff --git a/ciscoasa/interfaces_physical.go b/ciscoasa/interfaces_physical.go index 2fd74bd..88ef3bf 100644 --- a/ciscoasa/interfaces_physical.go +++ b/ciscoasa/interfaces_physical.go @@ -32,7 +32,7 @@ type PhysicalInterface struct { InterfaceDesc string `json:"interfaceDesc"` ChannelGroupID string `json:"channelGroupID"` ChannelGroupMode string `json:"channelGroupMode"` - Duplex string `json:"duplex"` + Duplex string `json:"duplex,omitempty"` FlowcontrolOn bool `json:"flowcontrolOn"` FlowcontrolHigh int `json:"flowcontrolHigh"` FlowcontrolLow int `json:"flowcontrolLow"` @@ -47,12 +47,12 @@ type PhysicalInterface struct { Name string `json:"name"` SecurityLevel int `json:"securityLevel"` Shutdown bool `json:"shutdown"` - Speed string `json:"speed"` - IPAddress *IPAddress `json:"ipAddress"` - Ipv6Info *IPv6Info `json:"ipv6Info"` + Speed string `json:"speed,omitempty"` + IPAddress *IPAddress `json:"ipAddress,omitempty"` + Ipv6Info *IPv6Info `json:"ipv6Info,omitempty"` Kind string `json:"kind"` - ObjectID string `json:"objectId"` - SelfLink string `json:"selfLink"` + ObjectID string `json:"objectId,omitempty"` + SelfLink string `json:"selfLink,omitempty"` } // ListPhysicalInterfaces returns a collection of interfaces. @@ -88,3 +88,144 @@ func (s *interfaceService) ListPhysicalInterfaces() (*PhysicalInterfaceCollectio return result, nil } + +// UpdatePhysicalInterface updates a physical interface +// as there is no way of creating a physical interface. +func (s *interfaceService) UpdatePhysicalInterface( + activeMacAddress string, + forwardTrafficCX bool, + forwardTrafficSFR bool, + hardwareID string, + interfaceDesc string, + ipAddress *IPAddress, + ipv6Info *IPv6Info, + kind string, + managementOnly bool, + mtu int, + name string, + objectID string, + securityLevel int, + shutdown bool, + standByMacAddress string, +) (string, error) { + u := fmt.Sprintf("/api/interfaces/physical/%s", objectID) + + duplex := "auto" + speed := "auto" + if kind == "object#TenGigInterface" { + duplex = "" + speed = "" + } + + r := &PhysicalInterface{ + ActiveMacAddress: activeMacAddress, + ChannelGroupID: "", + ChannelGroupMode: "active", + Duplex: duplex, + FlowcontrolHigh: -1, + FlowcontrolLow: -1, + FlowcontrolOn: false, + FlowcontrolPeriod: -1, + ForwardTrafficCX: forwardTrafficCX, + ForwardTrafficSFR: forwardTrafficSFR, + HardwareID: hardwareID, + InterfaceDesc: interfaceDesc, + IPAddress: ipAddress, + Ipv6Info: ipv6Info, + Kind: kind, + LacpPriority: -1, + ManagementOnly: managementOnly, + Mtu: mtu, + Name: name, + ObjectID: objectID, + SecurityLevel: securityLevel, + Shutdown: shutdown, + Speed: speed, + StandByMacAddress: standByMacAddress, + } + + req, err := s.newRequest("PUT", u, r) + if err != nil { + return "", err + } + + resp, err := s.do(req, nil) + if err != nil { + return "", err + } + + return idFromResponse(resp) +} + +// GetPhysicalInterface retrieves a physical interface. +func (s *interfaceService) GetPhysicalInterface(objectID string) (*PhysicalInterface, error) { + u := fmt.Sprintf("/api/interfaces/physical/%s", objectID) + + req, err := s.newRequest("GET", u, nil) + if err != nil { + return nil, err + } + + r := &PhysicalInterface{} + _, err = s.do(req, r) + + return r, err +} + +// DeletePhysicalInterface sets values to defaults +// as there is no way of deletion a physical interface. +func (s *interfaceService) DeletePhysicalInterface( + hardwareID string, + kind string, + objectID string, +) error { + u := fmt.Sprintf("/api/interfaces/physical/%s", objectID) + + duplex := "auto" + speed := "auto" + if kind == "object#TenGigInterface" { + duplex = "" + speed = "" + } + + r := &PhysicalInterface{ + ActiveMacAddress: "", + ChannelGroupID: "", + ChannelGroupMode: "active", + Duplex: duplex, + FlowcontrolHigh: -1, + FlowcontrolLow: -1, + FlowcontrolOn: false, + FlowcontrolPeriod: -1, + ForwardTrafficCX: false, + ForwardTrafficSFR: false, + HardwareID: hardwareID, + InterfaceDesc: "", + IPAddress: nil, + Ipv6Info: nil, + Kind: kind, + LacpPriority: -1, + ManagementOnly: false, + Mtu: 1500, + Name: "", + SecurityLevel: -1, + Shutdown: false, + Speed: speed, + StandByMacAddress: "", + } + + req, err := s.newRequest("PUT", u, r) + if err != nil { + return err + } + + resp, err := s.do(req, nil) + if err != nil { + return err + } + + err = checkResponse(resp) + + return err + +} diff --git a/ciscoasa/interfaces_vlan.go b/ciscoasa/interfaces_vlan.go index 105e1df..1446f17 100644 --- a/ciscoasa/interfaces_vlan.go +++ b/ciscoasa/interfaces_vlan.go @@ -40,11 +40,11 @@ type VlanInterface struct { SecurityLevel int `json:"securityLevel"` Shutdown bool `json:"shutdown"` VlanID int `json:"vlanID"` - IPAddress *IPAddress `json:"ipAddress"` - Ipv6Info *IPv6Info `json:"ipv6Info"` + IPAddress *IPAddress `json:"ipAddress,omitempty"` + Ipv6Info *IPv6Info `json:"ipv6Info,omitempty"` Kind string `json:"kind"` - ObjectID string `json:"objectId"` - SelfLink string `json:"selfLink"` + ObjectID string `json:"objectId,omitempty"` + SelfLink string `json:"selfLink,omitempty"` } // ListVlanInterfaces returns a collection of interfaces. @@ -80,3 +80,138 @@ func (s *interfaceService) ListVlanInterfaces() (*VlanInterfaceCollection, error return result, nil } + +// CreateVlanInterface creates a vlan interface. +func (s *interfaceService) CreateVlanInterface( + activeMacAddress string, + forwardTrafficCX bool, + forwardTrafficSFR bool, + hardwareID string, + interfaceDesc string, + ipAddress *IPAddress, + ipv6Info *IPv6Info, + kind string, + managementOnly bool, + mtu int, + name string, + securityLevel int, + shutdown bool, + standByMacAddress string, + vlanId int, +) (string, error) { + u := "/api/interfaces/vlan/" + + r := &VlanInterface{ + ActiveMacAddress: activeMacAddress, + ForwardTrafficCX: forwardTrafficCX, + ForwardTrafficSFR: forwardTrafficSFR, + HardwareID: hardwareID, + InterfaceDesc: interfaceDesc, + IPAddress: ipAddress, + Ipv6Info: ipv6Info, + Kind: kind, + ManagementOnly: managementOnly, + Mtu: mtu, + Name: name, + SecurityLevel: securityLevel, + Shutdown: shutdown, + StandByMacAddress: standByMacAddress, + VlanID: vlanId, + } + + req, err := s.newRequest("POST", u, r) + if err != nil { + return "", err + } + + resp, err := s.do(req, nil) + if err != nil { + return "", err + } + + return idFromResponse(resp) +} + +// UpdateVlanInterface updates a vlan interface. +func (s *interfaceService) UpdateVlanInterface( + activeMacAddress string, + forwardTrafficCX bool, + forwardTrafficSFR bool, + hardwareID string, + interfaceDesc string, + ipAddress *IPAddress, + ipv6Info *IPv6Info, + kind string, + managementOnly bool, + mtu int, + name string, + objectID string, + securityLevel int, + shutdown bool, + standByMacAddress string, + vlanId int, +) error { + u := fmt.Sprintf("/api/interfaces/vlan/%s", objectID) + + r := &VlanInterface{ + ActiveMacAddress: activeMacAddress, + ForwardTrafficCX: forwardTrafficCX, + ForwardTrafficSFR: forwardTrafficSFR, + HardwareID: hardwareID, + InterfaceDesc: interfaceDesc, + IPAddress: ipAddress, + Ipv6Info: ipv6Info, + Kind: kind, + ManagementOnly: managementOnly, + Mtu: mtu, + Name: name, + ObjectID: objectID, + SecurityLevel: securityLevel, + Shutdown: shutdown, + StandByMacAddress: standByMacAddress, + VlanID: vlanId, + } + + req, err := s.newRequest("PUT", u, r) + if err != nil { + return err + } + + resp, err := s.do(req, nil) + if err != nil { + return err + } + + err = checkResponse(resp) + + return err +} + +// GetVlanInterface retrieves a vlan interface. +func (s *interfaceService) GetVlanInterface(objectID string) (*VlanInterface, error) { + u := fmt.Sprintf("/api/interfaces/vlan/%s", objectID) + + req, err := s.newRequest("GET", u, nil) + if err != nil { + return nil, err + } + + r := &VlanInterface{} + _, err = s.do(req, r) + + return r, err +} + +// DeleteVlanInterface deletes a vlan interface. +func (s *interfaceService) DeleteVlanInterface(objectID string) error { + u := fmt.Sprintf("/api/interfaces/vlan/%s", objectID) + + req, err := s.newRequest("DELETE", u, nil) + if err != nil { + return err + } + + _, err = s.do(req, nil) + + return err +} diff --git a/go.mod b/go.mod index 605c199..983ae59 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/xanzy/go-ciscoasa -go 1.12 +go 1.16