Skip to content

Commit

Permalink
min&max port
Browse files Browse the repository at this point in the history
  • Loading branch information
shireenf-ibm committed Dec 1, 2024
1 parent cdb8b84 commit 1a7939e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
9 changes: 3 additions & 6 deletions pkg/netpol/eval/internal/k8s/netpol.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,13 @@ func (np *NetworkPolicy) getPortsRange(rulePort netv1.NetworkPolicyPort, dst Pee
return start, end, portName, nil
}

const (
minimumPort = 1
maximumPort = 65535
)

func isEmptyPortRange(start, end int64) bool {
// an empty range when:
// - end is smaller than start
// - end or start is not in the legal range (a legal port is 1-65535)
return (start < minimumPort || end < minimumPort) || (end < start) || (start > maximumPort || end > maximumPort)
return (start < common.MinPort || end < common.MinPort) ||
(end < start) ||
(start > common.MaxPort || end > common.MaxPort)
}

// doesRulePortContain gets protocol and port numbers of a rule and other protocol and port;
Expand Down
6 changes: 3 additions & 3 deletions pkg/netpol/internal/common/portset.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (

const (
NoPort = -1
minPort int64 = 1
maxPort int64 = 65535
MinPort int64 = 1
MaxPort int64 = 65535
)

// PortSet: represents set of allowed ports in a connection
Expand All @@ -32,7 +32,7 @@ type PortSet struct {
// MakePortSet: return a new PortSet object, with all ports or no ports allowed
func MakePortSet(all bool) *PortSet {
if all {
return &PortSet{Ports: interval.New(minPort, maxPort).ToSet(),
return &PortSet{Ports: interval.New(MinPort, MaxPort).ToSet(),
NamedPorts: map[string]bool{},
ExcludedNamedPorts: map[string]bool{},
}
Expand Down

0 comments on commit 1a7939e

Please sign in to comment.