/* save sk->sk_prot and set it to tls_prots */
err = setsockopt(s, IPPROTO_TCP, TCP_ULP, "tls", strlen("tls")); if (!ASSERT_OK(err, "setsockopt(TCP_ULP)")) goto close;
/* sockmap update should not affect saved sk_prot */
err = bpf_map_update_elem(map, &zero, &s, BPF_ANY); if (!ASSERT_ERR(err, "sockmap update elem")) goto close;
/* call sk->sk_prot->setsockopt to dispatch to saved sk_prot */
err = setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &zero, sizeof(zero));
ASSERT_OK(err, "setsockopt(TCP_NODELAY)");
staticvoid test_sockmap_ktls_tx_cork(int family, int sotype, bool push)
{ int err, off; int i, j; int start_push = 0, push_len = 0; int c = 0, p = 0, one = 1, sent, recvd; int prog_fd, map_fd; char msg[12] = "hello world\0"; char rcv[20] = {0}; struct test_sockmap_ktls *skel;
skel = test_sockmap_ktls__open_and_load(); if (!ASSERT_TRUE(skel, "open ktls skel")) return;
for (i = 0, j = 0; i < recvd;) { /* skip checking the data that has been pushed in */ if (i >= start_push && i <= start_push + push_len - 1) {
i++; continue;
} if (!ASSERT_EQ(rcv[i], msg[j], "data mismatch")) goto out;
i++;
j++;
}
out: if (c)
close(c); if (p)
close(p);
test_sockmap_ktls__destroy(skel);
}
staticvoid test_sockmap_ktls_tx_no_buf(int family, int sotype, bool push)
{ int c = -1, p = -1, one = 1, two = 2; struct test_sockmap_ktls *skel; unsignedchar *data = NULL; struct msghdr msg = {0}; struct iovec iov[2]; int prog_fd, map_fd; int txrx_buf = 1024; int iov_length = 8192; int err;
skel = test_sockmap_ktls__open_and_load(); if (!ASSERT_TRUE(skel, "open ktls skel")) return;
for (;;) {
err = sendmsg(c, &msg, MSG_DONTWAIT); if (err <= 0) break;
}
out: if (data)
free(data); if (c != -1)
close(c); if (p != -1)
close(p);
test_sockmap_ktls__destroy(skel);
}
staticvoid test_sockmap_ktls_tx_pop(int family, int sotype)
{ char msg[37] = "0123456789abcdefghijklmnopqrstuvwxyz\0"; int c = 0, p = 0, one = 1, sent, recvd; struct test_sockmap_ktls *skel; int prog_fd, map_fd; char rcv[50] = {0}; int err; int i, m, r;
skel = test_sockmap_ktls__open_and_load(); if (!ASSERT_TRUE(skel, "open ktls skel")) return;
err = init_ktls_pairs(c, p); if (!ASSERT_OK(err, "init_ktls_pairs(c, p)")) goto out;
struct { int pop_start; int pop_len;
} pop_policy[] = { /* trim the start */
{0, 2},
{0, 10},
{1, 2},
{1, 10}, /* trim the end */
{35, 2}, /* New entries should be added before this line */
{-1, -1},
};
i = 0; while (pop_policy[i].pop_start >= 0) {
skel->bss->pop_start = pop_policy[i].pop_start;
skel->bss->pop_end = pop_policy[i].pop_len;
sent = send(c, msg, sizeof(msg), 0); if (!ASSERT_EQ(sent, sizeof(msg), "send(msg)")) goto out;
recvd = recv_timeout(p, rcv, sizeof(rcv), MSG_DONTWAIT, 1); if (!ASSERT_EQ(recvd, sizeof(msg) - pop_policy[i].pop_len, "pop len mismatch")) goto out;
/* verify the data * msg: 0123456789a bcdefghij klmnopqrstuvwxyz * | | * popped data
*/ for (m = 0, r = 0; m < sizeof(msg);) { /* skip checking the data that has been popped */ if (m >= pop_policy[i].pop_start &&
m <= pop_policy[i].pop_start + pop_policy[i].pop_len - 1) {
m++; continue;
}
if (!ASSERT_EQ(msg[m], rcv[r], "data mismatch")) goto out;
m++;
r++;
}
i++;
}
out: if (c)
close(c); if (p)
close(p);
test_sockmap_ktls__destroy(skel);
}
staticvoid run_tests(int family, enum bpf_map_type map_type)
{ int map;
if (test__start_subtest(fmt_test_name("update_fails_when_sock_has_ulp", family, map_type)))
test_sockmap_ktls_update_fails_when_sock_has_ulp(family, map);
close(map);
}
staticvoid run_ktls_test(int family, int sotype)
{ if (test__start_subtest("tls simple offload"))
test_sockmap_ktls_offload(family, sotype); if (test__start_subtest("tls tx cork"))
test_sockmap_ktls_tx_cork(family, sotype, false); if (test__start_subtest("tls tx cork with push"))
test_sockmap_ktls_tx_cork(family, sotype, true); if (test__start_subtest("tls tx egress with no buf"))
test_sockmap_ktls_tx_no_buf(family, sotype, true); if (test__start_subtest("tls tx with pop"))
test_sockmap_ktls_tx_pop(family, sotype);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.