|
5 | 5 | static void test_xdp_update_frags(void)
|
6 | 6 | {
|
7 | 7 | const char *file = "./test_xdp_update_frags.o";
|
| 8 | + int err, prog_fd, max_skb_frags, buf_size, num; |
8 | 9 | struct bpf_program *prog;
|
9 | 10 | struct bpf_object *obj;
|
10 |
| - int err, prog_fd; |
11 | 11 | __u32 *offset;
|
12 | 12 | __u8 *buf;
|
| 13 | + FILE *f; |
13 | 14 | LIBBPF_OPTS(bpf_test_run_opts, topts);
|
14 | 15 |
|
15 | 16 | obj = bpf_object__open(file);
|
@@ -99,6 +100,41 @@ static void test_xdp_update_frags(void)
|
99 | 100 | ASSERT_EQ(buf[7621], 0xbb, "xdp_update_frag buf[7621]");
|
100 | 101 |
|
101 | 102 | free(buf);
|
| 103 | + |
| 104 | + /* test_xdp_update_frags: unsupported buffer size */ |
| 105 | + f = fopen("/proc/sys/net/core/max_skb_frags", "r"); |
| 106 | + if (!ASSERT_OK_PTR(f, "max_skb_frag file pointer")) |
| 107 | + goto out; |
| 108 | + |
| 109 | + num = fscanf(f, "%d", &max_skb_frags); |
| 110 | + fclose(f); |
| 111 | + |
| 112 | + if (!ASSERT_EQ(num, 1, "max_skb_frags read failed")) |
| 113 | + goto out; |
| 114 | + |
| 115 | + /* xdp_buff linear area size is always set to 4096 in the |
| 116 | + * bpf_prog_test_run_xdp routine. |
| 117 | + */ |
| 118 | + buf_size = 4096 + (max_skb_frags + 1) * sysconf(_SC_PAGE_SIZE); |
| 119 | + buf = malloc(buf_size); |
| 120 | + if (!ASSERT_OK_PTR(buf, "alloc buf")) |
| 121 | + goto out; |
| 122 | + |
| 123 | + memset(buf, 0, buf_size); |
| 124 | + offset = (__u32 *)buf; |
| 125 | + *offset = 16; |
| 126 | + buf[*offset] = 0xaa; |
| 127 | + buf[*offset + 15] = 0xaa; |
| 128 | + |
| 129 | + topts.data_in = buf; |
| 130 | + topts.data_out = buf; |
| 131 | + topts.data_size_in = buf_size; |
| 132 | + topts.data_size_out = buf_size; |
| 133 | + |
| 134 | + err = bpf_prog_test_run_opts(prog_fd, &topts); |
| 135 | + ASSERT_EQ(err, -ENOMEM, |
| 136 | + "unsupported buf size, possible non-default /proc/sys/net/core/max_skb_flags?"); |
| 137 | + free(buf); |
102 | 138 | out:
|
103 | 139 | bpf_object__close(obj);
|
104 | 140 | }
|
|
0 commit comments