34
34
#include "manpages.h"
35
35
36
36
#define PATTERN "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
37
- // "Nobody calls me Lebowski. You got the wrong guy. I'm the Dude, man."
38
37
39
- static int bflag ; /* run bpf tests */
40
- static int kflag ; /* run kprobe tests */
38
+ struct udphdr {
39
+ u16 source ;
40
+ u16 dest ;
41
+ u16 len ;
42
+ u16 check ;
43
+ };
41
44
42
45
#define msleep (_x ) usleep((uint64_t)_x * 1000ULL)
43
46
47
50
GREEN
48
51
};
49
52
53
+ static int bflag ; /* run bpf tests */
54
+ static int kflag ; /* run kprobe tests */
55
+
50
56
static int
51
57
fancy_tty (void )
52
58
{
@@ -731,8 +737,12 @@ t_stats(const struct test *t, struct quark_queue_attr *qa)
731
737
static int
732
738
t_dns (const struct test * t , struct quark_queue_attr * qa )
733
739
{
734
- struct quark_queue qq ;
735
- pid_t child ;
740
+ struct quark_queue qq ;
741
+ const struct quark_event * qev ;
742
+ struct quark_packet * packet ;
743
+ pid_t child ;
744
+ struct iphdr ip ;
745
+ struct udphdr udp ;
736
746
737
747
assert_localhost ();
738
748
@@ -742,7 +752,44 @@ t_dns(const struct test *t, struct quark_queue_attr *qa)
742
752
err (1 , "quark_queue_open" );
743
753
744
754
child = fork_sock_write (53 , SOCK_DGRAM );
745
- drain_for_pid (& qq , child );
755
+
756
+ /* first is the fork, no agg */
757
+ qev = drain_for_pid (& qq , child );
758
+ assert (qev -> packet == NULL );
759
+
760
+ /* egress */
761
+ qev = drain_for_pid (& qq , child );
762
+ packet = qev -> packet ;
763
+ assert (packet != NULL );
764
+ assert (packet -> cap_len == 90 );
765
+ assert (packet -> orig_len == 90 );
766
+ /* ip */
767
+ memcpy (& ip , packet -> data , sizeof (ip ));
768
+ assert (ip .protocol == IPPROTO_UDP );
769
+ assert (ip .saddr == htonl (INADDR_LOOPBACK ));
770
+ assert (ip .daddr == htonl (INADDR_LOOPBACK ));
771
+ /* udp */
772
+ memcpy (& udp , packet -> data + sizeof (ip ), sizeof (udp ));
773
+ assert (udp .dest == htons (53 ));
774
+ /* dns */
775
+ assert (!memcmp (packet -> data + 28 , PATTERN , packet -> cap_len - 28 ));
776
+
777
+ /* ingress */
778
+ qev = drain_for_pid (& qq , child );
779
+ packet = qev -> packet ;
780
+ assert (packet != NULL );
781
+ assert (packet -> cap_len == 90 );
782
+ assert (packet -> orig_len == 90 );
783
+ /* ip */
784
+ memcpy (& ip , packet -> data , sizeof (ip ));
785
+ assert (ip .protocol == IPPROTO_UDP );
786
+ assert (ip .saddr == htonl (INADDR_LOOPBACK ));
787
+ assert (ip .daddr == htonl (INADDR_LOOPBACK ));
788
+ /* udp */
789
+ memcpy (& udp , packet -> data + sizeof (ip ), sizeof (udp ));
790
+ assert (udp .dest == htons (53 ));
791
+ /* dns */
792
+ assert (!memcmp (packet -> data + 28 , PATTERN , packet -> cap_len - 28 ));
746
793
747
794
quark_queue_close (& qq );
748
795
0 commit comments