Skip to content

Commit 7c6cbc4

Browse files
committed
Added UDP Source/Destination Port Range functions
1 parent 5d48a06 commit 7c6cbc4

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

ovs/match.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,57 @@ type udpPortMatch struct {
962962

963963
var _ Match = &udpPortMatch{}
964964

965+
// A udpPortRange reprsents the start and end values of a udp protocol port range.
966+
type udpPortRange struct {
967+
srcdst string
968+
startPort uint16
969+
endPort uint16
970+
}
971+
972+
// UdpDestinationPortRange represent a port range intended for a UDP protocol destination port.
973+
func UdpDestinationPortRange(startPort uint16, endPort uint16) TransportPortRanger {
974+
return &udpPortRange{
975+
srcdst: destination,
976+
startPort: startPort,
977+
endPort: endPort,
978+
}
979+
}
980+
981+
// UdpSourcePortRange represent a port range intended for a UDP protocol source port.
982+
func UdpSourcePortRange(startPort uint16, endPort uint16) TransportPortRanger {
983+
return &udpPortRange{
984+
srcdst: source,
985+
startPort: startPort,
986+
endPort: endPort,
987+
}
988+
}
989+
990+
// MaskedPorts returns the represented port ranges as an array of bitwise matches.
991+
func (pr *udpPortRange) MaskedPorts() ([]Match, error) {
992+
portRange := PortRange{
993+
Start: pr.startPort,
994+
End: pr.endPort,
995+
}
996+
997+
bitRanges, err := portRange.BitwiseMatch()
998+
if err != nil {
999+
return nil, err
1000+
}
1001+
1002+
var ports []Match
1003+
1004+
for _, br := range bitRanges {
1005+
maskedPortRange := &udpPortMatch{
1006+
srcdst: pr.srcdst,
1007+
port: br.Value,
1008+
mask: br.Mask,
1009+
}
1010+
ports = append(ports, maskedPortRange)
1011+
}
1012+
1013+
return ports, nil
1014+
}
1015+
9651016
// MarshalText implements Match.
9661017
func (m *udpPortMatch) MarshalText() ([]byte, error) {
9671018
return matchUdpPort(m.srcdst, m.port, m.mask)

0 commit comments

Comments
 (0)