@@ -1768,6 +1768,14 @@ func TestFilterFlowerAddDel(t *testing.T) {
17681768 }
17691769
17701770 testMask := net .CIDRMask (24 , 32 )
1771+ srcMac , err := net .ParseMAC ("2C:54:91:88:C9:E3" )
1772+ if err != nil {
1773+ t .Fatal (err )
1774+ }
1775+ destMac , err := net .ParseMAC ("2C:54:91:88:C9:E5" )
1776+ if err != nil {
1777+ t .Fatal (err )
1778+ }
17711779
17721780 ipproto := new (nl.IPProto )
17731781 * ipproto = nl .IPPROTO_TCP
@@ -1790,10 +1798,19 @@ func TestFilterFlowerAddDel(t *testing.T) {
17901798 EncSrcIPMask : testMask ,
17911799 EncDestPort : 8472 ,
17921800 EncKeyId : 1234 ,
1801+ SrcMac : srcMac ,
1802+ DestMac : destMac ,
17931803 IPProto : ipproto ,
17941804 DestPort : 1111 ,
17951805 SrcPort : 1111 ,
17961806 Actions : []Action {
1807+ & VlanAction {
1808+ ActionAttrs : ActionAttrs {
1809+ Action : TC_ACT_PIPE ,
1810+ },
1811+ Action : TCA_VLAN_ACT_PUSH ,
1812+ VlanID : 1234 ,
1813+ },
17971814 & MirredAction {
17981815 ActionAttrs : ActionAttrs {
17991816 Action : TC_ACT_STOLEN ,
@@ -1871,8 +1888,31 @@ func TestFilterFlowerAddDel(t *testing.T) {
18711888 if filter .SrcPort != flower .SrcPort {
18721889 t .Fatalf ("Flower SrcPort doesn't match" )
18731890 }
1891+ if ! (filter .SrcMac .String () == flower .SrcMac .String ()) {
1892+ t .Fatalf ("Flower SrcMac doesn't match" )
1893+ }
1894+ if ! (filter .DestMac .String () == flower .DestMac .String ()) {
1895+ t .Fatalf ("Flower DestMac doesn't match" )
1896+ }
18741897
1875- mia , ok := flower .Actions [0 ].(* MirredAction )
1898+ vla , ok := flower .Actions [0 ].(* VlanAction )
1899+ if ! ok {
1900+ t .Fatal ("Unable to find vlan action" )
1901+ }
1902+
1903+ if vla .Attrs ().Action != TC_ACT_PIPE {
1904+ t .Fatal ("Vlan action isn't TC_ACT_PIPE" )
1905+ }
1906+
1907+ if vla .Action != TCA_VLAN_ACT_PUSH {
1908+ t .Fatal ("Second Vlan action isn't push" )
1909+ }
1910+
1911+ if vla .VlanID != 1234 {
1912+ t .Fatal ("Second Vlan action vlanId isn't correct" )
1913+ }
1914+
1915+ mia , ok := flower .Actions [1 ].(* MirredAction )
18761916 if ! ok {
18771917 t .Fatal ("Unable to find mirred action" )
18781918 }
@@ -1889,7 +1929,7 @@ func TestFilterFlowerAddDel(t *testing.T) {
18891929 t .Fatal ("Incorrect mirred action stats" )
18901930 }
18911931
1892- ga , ok := flower .Actions [1 ].(* GenericAction )
1932+ ga , ok := flower .Actions [2 ].(* GenericAction )
18931933 if ! ok {
18941934 t .Fatal ("Unable to find generic action" )
18951935 }
@@ -1917,6 +1957,94 @@ func TestFilterFlowerAddDel(t *testing.T) {
19171957 t .Fatal ("Failed to remove filter" )
19181958 }
19191959
1960+ filter = & Flower {
1961+ FilterAttrs : FilterAttrs {
1962+ LinkIndex : link .Attrs ().Index ,
1963+ Parent : MakeHandle (0xffff , 0 ),
1964+ Priority : 1 ,
1965+ Protocol : unix .ETH_P_8021Q ,
1966+ },
1967+ EthType : unix .ETH_P_8021Q ,
1968+ VlanId : 2046 ,
1969+ Actions : []Action {
1970+ & VlanAction {
1971+ ActionAttrs : ActionAttrs {
1972+ Action : TC_ACT_PIPE ,
1973+ },
1974+ Action : TCA_VLAN_ACT_POP ,
1975+ },
1976+ & MirredAction {
1977+ ActionAttrs : ActionAttrs {
1978+ Action : TC_ACT_STOLEN ,
1979+ },
1980+ MirredAction : TCA_EGRESS_REDIR ,
1981+ Ifindex : redir .Attrs ().Index ,
1982+ },
1983+ },
1984+ }
1985+
1986+ if err := FilterAdd (filter ); err != nil {
1987+ t .Fatal (err )
1988+ }
1989+
1990+ time .Sleep (time .Second )
1991+ filters , err = FilterList (link , MakeHandle (0xffff , 0 ))
1992+ if err != nil {
1993+ t .Fatal (err )
1994+ }
1995+ if len (filters ) != 1 {
1996+ t .Fatal ("Failed to add filter" )
1997+ }
1998+ flower , ok = filters [0 ].(* Flower )
1999+ if ! ok {
2000+ t .Fatal ("Filter is the wrong type" )
2001+ }
2002+
2003+ if filter .VlanId != flower .VlanId {
2004+ t .Fatalf ("Flower VlanId doesn't match" )
2005+ }
2006+
2007+ vla , ok = flower .Actions [0 ].(* VlanAction )
2008+ if ! ok {
2009+ t .Fatal ("Unable to find vlan action" )
2010+ }
2011+
2012+ if vla .Attrs ().Action != TC_ACT_PIPE {
2013+ t .Fatal ("Vlan action isn't TC_ACT_PIPE" )
2014+ }
2015+
2016+ if vla .Action != TCA_VLAN_ACT_POP {
2017+ t .Fatal ("First Vlan action isn't pop" )
2018+ }
2019+
2020+ mia , ok = flower .Actions [1 ].(* MirredAction )
2021+ if ! ok {
2022+ t .Fatal ("Unable to find mirred action" )
2023+ }
2024+
2025+ if mia .Attrs ().Action != TC_ACT_STOLEN {
2026+ t .Fatal ("Mirred action isn't TC_ACT_STOLEN" )
2027+ }
2028+
2029+ if mia .Timestamp == nil || mia .Timestamp .Installed == 0 {
2030+ t .Fatal ("Incorrect mirred action timestamp" )
2031+ }
2032+
2033+ if mia .Statistics == nil {
2034+ t .Fatal ("Incorrect mirred action stats" )
2035+ }
2036+
2037+ if err := FilterDel (filter ); err != nil {
2038+ t .Fatal (err )
2039+ }
2040+ filters , err = FilterList (link , MakeHandle (0xffff , 0 ))
2041+ if err != nil {
2042+ t .Fatal (err )
2043+ }
2044+ if len (filters ) != 0 {
2045+ t .Fatal ("Failed to remove filter" )
2046+ }
2047+
19202048 if err := QdiscDel (qdisc ); err != nil {
19212049 t .Fatal (err )
19222050 }
0 commit comments