@@ -1793,22 +1793,28 @@ func TestDecode_DropNotify(t *testing.T) {
17931793 parser , err := New (hivetest .Logger (t ), defaultEndpointGetter , nil , nil , nil , nil , nil )
17941794 require .NoError (t , err )
17951795
1796- template := & flowpb.Flow {
1797- EventType : & flowpb.CiliumEventType {Type : 1 },
1798- Summary : flowpb .IPVersion_IPv4 .String (),
1799- Type : flowpb .FlowType_L3_L4 ,
1800- Verdict : flowpb .Verdict_DROPPED ,
1801- Source : & flowpb.Endpoint {},
1802- Destination : & flowpb.Endpoint {},
1803- Ethernet : & flowpb.Ethernet {
1804- Source : srcMAC .String (),
1805- Destination : dstMAC .String (),
1806- },
1807- IP : & flowpb.IP {
1808- IpVersion : flowpb .IPVersion_IPv4 ,
1809- Source : localIP .String (),
1810- Destination : remoteIP .String (),
1811- },
1796+ getTemplate := func (isL3Device bool ) * flowpb.Flow {
1797+ template := & flowpb.Flow {
1798+ EventType : & flowpb.CiliumEventType {Type : 1 },
1799+ Summary : flowpb .IPVersion_IPv4 .String (),
1800+ Type : flowpb .FlowType_L3_L4 ,
1801+ Verdict : flowpb .Verdict_DROPPED ,
1802+ Source : & flowpb.Endpoint {},
1803+ Destination : & flowpb.Endpoint {},
1804+ Ethernet : & flowpb.Ethernet {
1805+ Source : srcMAC .String (),
1806+ Destination : dstMAC .String (),
1807+ },
1808+ IP : & flowpb.IP {
1809+ IpVersion : flowpb .IPVersion_IPv4 ,
1810+ Source : localIP .String (),
1811+ Destination : remoteIP .String (),
1812+ },
1813+ }
1814+ if isL3Device {
1815+ template .Ethernet = nil
1816+ }
1817+ return template
18121818 }
18131819
18141820 testCases := []struct {
@@ -1878,20 +1884,51 @@ func TestDecode_DropNotify(t *testing.T) {
18781884 },
18791885 },
18801886 },
1887+ {
1888+ name : "drop_ingress_l3_device" ,
1889+ event : monitor.DropNotify {
1890+ Type : byte (monitorAPI .MessageTypeDrop ),
1891+ Source : localEP ,
1892+ File : 7 ,
1893+ Line : 44 ,
1894+ Version : monitor .DropNotifyVersion2 ,
1895+ Flags : monitor .DropNotifyFlagIsL3Device ,
1896+ },
1897+ ipTuple : ingressTuple ,
1898+ want : & flowpb.Flow {
1899+ IP : & flowpb.IP {
1900+ Source : remoteIP .String (),
1901+ Destination : localIP .String (),
1902+ },
1903+ Destination : & flowpb.Endpoint {
1904+ ID : uint32 (localEP ),
1905+ },
1906+ TrafficDirection : flowpb .TrafficDirection_INGRESS ,
1907+ File : & flowpb.FileInfo {
1908+ Name : "bpf_wireguard.c" ,
1909+ Line : 44 ,
1910+ },
1911+ },
1912+ },
18811913 }
18821914 for _ , tc := range testCases {
18831915 t .Run (tc .name , func (t * testing.T ) {
1884- want := proto .Clone (template )
1885- proto .Merge (want , tc .want )
1916+ isL3Device := tc .event .IsL3Device ()
18861917
1887- data , err := testutils .CreateL3L4Payload (tc .event ,
1888- & layers.Ethernet {
1918+ var l []gopacket.SerializableLayer
1919+ if ! isL3Device {
1920+ l = append (l , & layers.Ethernet {
18891921 SrcMAC : srcMAC ,
18901922 DstMAC : dstMAC ,
18911923 EthernetType : layers .EthernetTypeIPv4 ,
1892- },
1893- & layers.IPv4 {SrcIP : tc .ipTuple .src .AsSlice (), DstIP : tc .ipTuple .dst .AsSlice ()},
1894- )
1924+ })
1925+ }
1926+ l = append (l , & layers.IPv4 {SrcIP : tc .ipTuple .src .AsSlice (), DstIP : tc .ipTuple .dst .AsSlice ()})
1927+
1928+ want := proto .Clone (getTemplate (isL3Device ))
1929+ proto .Merge (want , tc .want )
1930+
1931+ data , err := testutils .CreateL3L4Payload (tc .event , l ... )
18951932 if err != nil {
18961933 t .Fatalf ("Unexpected error from CreateL3L4Payload(%T, ...): %v" , tc .event , err )
18971934 }
0 commit comments