@@ -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,73 @@ 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
+ // MarshalText implements Match.
966
+ func (m * udpPortMatch ) MarshalText () ([]byte , error ) {
967
+ return matchUdpPort (m .srcdst , m .port , m .mask )
968
+ }
969
+
970
+ // GoString implements Match.
971
+ func (m * udpPortMatch ) GoString () string {
972
+ if m .mask > 0 {
973
+ if m .srcdst == source {
974
+ return fmt .Sprintf ("ovs.UdpSourceMaskedPort(%#x, %#x)" , m .port , m .mask )
975
+ }
976
+
977
+ return fmt .Sprintf ("ovs.UdpDestinationMaskedPort(%#x, %#x)" , m .port , m .mask )
978
+ }
979
+
980
+ if m .srcdst == source {
981
+ return fmt .Sprintf ("ovs.UdpSourcePort(%d)" , m .port )
982
+ }
983
+
984
+ return fmt .Sprintf ("ovs.UdpDestinationPort(%d)" , m .port )
985
+ }
986
+
922
987
// A transportPortMatch is a Match returned by Transport{Source,Destination}Port.
923
988
type transportPortMatch struct {
924
989
srcdst string
@@ -1491,6 +1556,17 @@ func matchTransportPort(srcdst string, port uint16, mask uint16) ([]byte, error)
1491
1556
return bprintf ("tp_%s=0x%04x/0x%04x" , srcdst , port , mask ), nil
1492
1557
}
1493
1558
1559
+ // matchUdpPort is the common implementation for
1560
+ // Udp{Source,Destination}Port.
1561
+ func matchUdpPort (srcdst string , port uint16 , mask uint16 ) ([]byte , error ) {
1562
+ // No mask specified
1563
+ if mask == 0 {
1564
+ return bprintf ("udp_%s=%d" , srcdst , port ), nil
1565
+ }
1566
+
1567
+ return bprintf ("udp_%s=0x%04x/0x%04x" , srcdst , port , mask ), nil
1568
+ }
1569
+
1494
1570
// IPFragFlag is a string type which can be used with the IPFragMatch.
1495
1571
type IPFragFlag string
1496
1572
0 commit comments