|
44 | 44 | #define SERV6_V4MAPPED_IP "::ffff:192.168.0.4"
|
45 | 45 | #define SRC6_IP "::1"
|
46 | 46 | #define SRC6_REWRITE_IP "::6"
|
| 47 | +#define WILDCARD6_IP "::" |
47 | 48 | #define SERV6_PORT 6060
|
48 | 49 | #define SERV6_REWRITE_PORT 6666
|
49 | 50 |
|
@@ -85,12 +86,14 @@ static int bind4_prog_load(const struct sock_addr_test *test);
|
85 | 86 | static int bind6_prog_load(const struct sock_addr_test *test);
|
86 | 87 | static int connect4_prog_load(const struct sock_addr_test *test);
|
87 | 88 | static int connect6_prog_load(const struct sock_addr_test *test);
|
| 89 | +static int sendmsg_allow_prog_load(const struct sock_addr_test *test); |
88 | 90 | static int sendmsg_deny_prog_load(const struct sock_addr_test *test);
|
89 | 91 | static int sendmsg4_rw_asm_prog_load(const struct sock_addr_test *test);
|
90 | 92 | static int sendmsg4_rw_c_prog_load(const struct sock_addr_test *test);
|
91 | 93 | static int sendmsg6_rw_asm_prog_load(const struct sock_addr_test *test);
|
92 | 94 | static int sendmsg6_rw_c_prog_load(const struct sock_addr_test *test);
|
93 | 95 | static int sendmsg6_rw_v4mapped_prog_load(const struct sock_addr_test *test);
|
| 96 | +static int sendmsg6_rw_wildcard_prog_load(const struct sock_addr_test *test); |
94 | 97 |
|
95 | 98 | static struct sock_addr_test tests[] = {
|
96 | 99 | /* bind */
|
@@ -462,6 +465,34 @@ static struct sock_addr_test tests[] = {
|
462 | 465 | SRC6_REWRITE_IP,
|
463 | 466 | SYSCALL_ENOTSUPP,
|
464 | 467 | },
|
| 468 | + { |
| 469 | + "sendmsg6: set dst IP = [::] (BSD'ism)", |
| 470 | + sendmsg6_rw_wildcard_prog_load, |
| 471 | + BPF_CGROUP_UDP6_SENDMSG, |
| 472 | + BPF_CGROUP_UDP6_SENDMSG, |
| 473 | + AF_INET6, |
| 474 | + SOCK_DGRAM, |
| 475 | + SERV6_IP, |
| 476 | + SERV6_PORT, |
| 477 | + SERV6_REWRITE_IP, |
| 478 | + SERV6_REWRITE_PORT, |
| 479 | + SRC6_REWRITE_IP, |
| 480 | + SUCCESS, |
| 481 | + }, |
| 482 | + { |
| 483 | + "sendmsg6: preserve dst IP = [::] (BSD'ism)", |
| 484 | + sendmsg_allow_prog_load, |
| 485 | + BPF_CGROUP_UDP6_SENDMSG, |
| 486 | + BPF_CGROUP_UDP6_SENDMSG, |
| 487 | + AF_INET6, |
| 488 | + SOCK_DGRAM, |
| 489 | + WILDCARD6_IP, |
| 490 | + SERV6_PORT, |
| 491 | + SERV6_REWRITE_IP, |
| 492 | + SERV6_PORT, |
| 493 | + SRC6_IP, |
| 494 | + SUCCESS, |
| 495 | + }, |
465 | 496 | {
|
466 | 497 | "sendmsg6: deny call",
|
467 | 498 | sendmsg_deny_prog_load,
|
@@ -734,16 +765,27 @@ static int connect6_prog_load(const struct sock_addr_test *test)
|
734 | 765 | return load_path(test, CONNECT6_PROG_PATH);
|
735 | 766 | }
|
736 | 767 |
|
737 |
| -static int sendmsg_deny_prog_load(const struct sock_addr_test *test) |
| 768 | +static int sendmsg_ret_only_prog_load(const struct sock_addr_test *test, |
| 769 | + int32_t rc) |
738 | 770 | {
|
739 | 771 | struct bpf_insn insns[] = {
|
740 |
| - /* return 0 */ |
741 |
| - BPF_MOV64_IMM(BPF_REG_0, 0), |
| 772 | + /* return rc */ |
| 773 | + BPF_MOV64_IMM(BPF_REG_0, rc), |
742 | 774 | BPF_EXIT_INSN(),
|
743 | 775 | };
|
744 | 776 | return load_insns(test, insns, sizeof(insns) / sizeof(struct bpf_insn));
|
745 | 777 | }
|
746 | 778 |
|
| 779 | +static int sendmsg_allow_prog_load(const struct sock_addr_test *test) |
| 780 | +{ |
| 781 | + return sendmsg_ret_only_prog_load(test, /*rc*/ 1); |
| 782 | +} |
| 783 | + |
| 784 | +static int sendmsg_deny_prog_load(const struct sock_addr_test *test) |
| 785 | +{ |
| 786 | + return sendmsg_ret_only_prog_load(test, /*rc*/ 0); |
| 787 | +} |
| 788 | + |
747 | 789 | static int sendmsg4_rw_asm_prog_load(const struct sock_addr_test *test)
|
748 | 790 | {
|
749 | 791 | struct sockaddr_in dst4_rw_addr;
|
@@ -864,6 +906,11 @@ static int sendmsg6_rw_v4mapped_prog_load(const struct sock_addr_test *test)
|
864 | 906 | return sendmsg6_rw_dst_asm_prog_load(test, SERV6_V4MAPPED_IP);
|
865 | 907 | }
|
866 | 908 |
|
| 909 | +static int sendmsg6_rw_wildcard_prog_load(const struct sock_addr_test *test) |
| 910 | +{ |
| 911 | + return sendmsg6_rw_dst_asm_prog_load(test, WILDCARD6_IP); |
| 912 | +} |
| 913 | + |
867 | 914 | static int sendmsg6_rw_c_prog_load(const struct sock_addr_test *test)
|
868 | 915 | {
|
869 | 916 | return load_path(test, SENDMSG6_PROG_PATH);
|
|
0 commit comments