File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -962,6 +962,57 @@ type udpPortMatch struct {
962962
963963var _ 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.
9661017func (m * udpPortMatch ) MarshalText () ([]byte , error ) {
9671018 return matchUdpPort (m .srcdst , m .port , m .mask )
You can’t perform that action at this time.
0 commit comments