2023-03-16 10:00:08 +01:00
|
|
|
package firewall
|
|
|
|
|
2023-06-20 20:33:41 +02:00
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2023-05-29 16:00:18 +02:00
|
|
|
// Protocol is the protocol of the port
|
|
|
|
type Protocol string
|
2023-03-16 10:00:08 +01:00
|
|
|
|
|
|
|
const (
|
2023-05-29 16:00:18 +02:00
|
|
|
// ProtocolTCP is the TCP protocol
|
|
|
|
ProtocolTCP Protocol = "tcp"
|
2023-03-16 10:00:08 +01:00
|
|
|
|
2023-05-29 16:00:18 +02:00
|
|
|
// ProtocolUDP is the UDP protocol
|
|
|
|
ProtocolUDP Protocol = "udp"
|
|
|
|
|
|
|
|
// ProtocolICMP is the ICMP protocol
|
|
|
|
ProtocolICMP Protocol = "icmp"
|
|
|
|
|
|
|
|
// ProtocolALL cover all supported protocols
|
|
|
|
ProtocolALL Protocol = "all"
|
|
|
|
|
|
|
|
// ProtocolUnknown unknown protocol
|
|
|
|
ProtocolUnknown Protocol = "unknown"
|
2023-03-16 10:00:08 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Port of the address for firewall rule
|
|
|
|
type Port struct {
|
|
|
|
// IsRange is true Values contains two values, the first is the start port, the second is the end port
|
|
|
|
IsRange bool
|
|
|
|
|
|
|
|
// Values contains one value for single port, multiple values for the list of ports, or two values for the range of ports
|
|
|
|
Values []int
|
|
|
|
}
|
2023-06-20 20:33:41 +02:00
|
|
|
|
|
|
|
// String interface implementation
|
|
|
|
func (p *Port) String() string {
|
|
|
|
var ports string
|
|
|
|
for _, port := range p.Values {
|
|
|
|
if ports != "" {
|
|
|
|
ports += ","
|
|
|
|
}
|
|
|
|
ports += strconv.Itoa(port)
|
|
|
|
}
|
|
|
|
return ports
|
|
|
|
}
|