@@ -75,6 +75,8 @@ const (
75
75
tunTTL = "tun_ttl"
76
76
tunv6DST = "tun_ipv6_dst"
77
77
tunv6SRC = "tun_ipv6_src"
78
+ udpDST = "udp_dst"
79
+ udpSRC = "udp_src"
78
80
vlanTCI1 = "vlan_tci1"
79
81
vlanTCI = "vlan_tci"
80
82
)
@@ -879,8 +881,7 @@ func (m *arpProtocolAddressMatch) GoString() string {
879
881
return fmt .Sprintf ("ovs.ARPTargetProtocolAddress(%q)" , m .ip )
880
882
}
881
883
882
- // TransportSourcePort matches packets with a transport layer (TCP/UDP) source
883
- // port matching port.
884
+ // TransportSourcePort matches packets with a TCP source port matching port.
884
885
func TransportSourcePort (port uint16 ) Match {
885
886
return & transportPortMatch {
886
887
srcdst : source ,
@@ -889,8 +890,7 @@ func TransportSourcePort(port uint16) Match {
889
890
}
890
891
}
891
892
892
- // TransportDestinationPort matches packets with a transport layer (TCP/UDP)
893
- // destination port matching port.
893
+ // TransportDestinationPort matches packets with a TCP destination port matching port.
894
894
func TransportDestinationPort (port uint16 ) Match {
895
895
return & transportPortMatch {
896
896
srcdst : destination ,
@@ -899,8 +899,7 @@ func TransportDestinationPort(port uint16) Match {
899
899
}
900
900
}
901
901
902
- // TransportSourceMaskedPort matches packets with a transport layer (TCP/UDP)
903
- // source port matching a masked port range.
902
+ // TransportSourceMaskedPort matches packets with TCP source port matching a masked port range.
904
903
func TransportSourceMaskedPort (port uint16 , mask uint16 ) Match {
905
904
return & transportPortMatch {
906
905
srcdst : source ,
@@ -909,8 +908,7 @@ func TransportSourceMaskedPort(port uint16, mask uint16) Match {
909
908
}
910
909
}
911
910
912
- // TransportDestinationMaskedPort matches packets with a transport layer (TCP/UDP)
913
- // destination port matching a masked port range.
911
+ // TransportDestinationMaskedPort matches packets with a TCP destination port matching a masked port range.
914
912
func TransportDestinationMaskedPort (port uint16 , mask uint16 ) Match {
915
913
return & transportPortMatch {
916
914
srcdst : destination ,
@@ -919,6 +917,124 @@ func TransportDestinationMaskedPort(port uint16, mask uint16) Match {
919
917
}
920
918
}
921
919
920
+ // UDPSourcePort matches packets with a UDP source port matching port.
921
+ func UDPSourcePort (port uint16 ) Match {
922
+ return & udpPortMatch {
923
+ srcdst : source ,
924
+ port : port ,
925
+ mask : 0 ,
926
+ }
927
+ }
928
+
929
+ // UDPDestinationPort matches packets with a UDP destination port matching port.
930
+ func UDPDestinationPort (port uint16 ) Match {
931
+ return & udpPortMatch {
932
+ srcdst : destination ,
933
+ port : port ,
934
+ mask : 0 ,
935
+ }
936
+ }
937
+
938
+ // UDPSourceMaskedPort matches packets with UDP source port matching a masked port range.
939
+ func UDPSourceMaskedPort (port uint16 , mask uint16 ) Match {
940
+ return & udpPortMatch {
941
+ srcdst : source ,
942
+ port : port ,
943
+ mask : mask ,
944
+ }
945
+ }
946
+
947
+ // UDPDestinationMaskedPort matches packets with a UDP destination port matching a masked port range.
948
+ func UDPDestinationMaskedPort (port uint16 , mask uint16 ) Match {
949
+ return & udpPortMatch {
950
+ srcdst : destination ,
951
+ port : port ,
952
+ mask : mask ,
953
+ }
954
+ }
955
+
956
+ // A udpPortMatch is a Match returned by Udp{Source,Destination}Port.
957
+ type udpPortMatch struct {
958
+ srcdst string
959
+ port uint16
960
+ mask uint16
961
+ }
962
+
963
+ var _ Match = & udpPortMatch {}
964
+
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
+
1016
+ // MarshalText implements Match.
1017
+ func (m * udpPortMatch ) MarshalText () ([]byte , error ) {
1018
+ return matchUDPPort (m .srcdst , m .port , m .mask )
1019
+ }
1020
+
1021
+ // GoString implements Match.
1022
+ func (m * udpPortMatch ) GoString () string {
1023
+ if m .mask > 0 {
1024
+ if m .srcdst == source {
1025
+ return fmt .Sprintf ("ovs.UdpSourceMaskedPort(%#x, %#x)" , m .port , m .mask )
1026
+ }
1027
+
1028
+ return fmt .Sprintf ("ovs.UdpDestinationMaskedPort(%#x, %#x)" , m .port , m .mask )
1029
+ }
1030
+
1031
+ if m .srcdst == source {
1032
+ return fmt .Sprintf ("ovs.UdpSourcePort(%d)" , m .port )
1033
+ }
1034
+
1035
+ return fmt .Sprintf ("ovs.UdpDestinationPort(%d)" , m .port )
1036
+ }
1037
+
922
1038
// A transportPortMatch is a Match returned by Transport{Source,Destination}Port.
923
1039
type transportPortMatch struct {
924
1040
srcdst string
@@ -1491,6 +1607,17 @@ func matchTransportPort(srcdst string, port uint16, mask uint16) ([]byte, error)
1491
1607
return bprintf ("tp_%s=0x%04x/0x%04x" , srcdst , port , mask ), nil
1492
1608
}
1493
1609
1610
+ // matchUDPPort is the common implementation for
1611
+ // Udp{Source,Destination}Port.
1612
+ func matchUDPPort (srcdst string , port uint16 , mask uint16 ) ([]byte , error ) {
1613
+ // No mask specified
1614
+ if mask == 0 {
1615
+ return bprintf ("udp_%s=%d" , srcdst , port ), nil
1616
+ }
1617
+
1618
+ return bprintf ("udp_%s=0x%04x/0x%04x" , srcdst , port , mask ), nil
1619
+ }
1620
+
1494
1621
// IPFragFlag is a string type which can be used with the IPFragMatch.
1495
1622
type IPFragFlag string
1496
1623
0 commit comments