Skip to content

Commit 9c3f178

Browse files
jrifeAlexei Starovoitov
authored andcommitted
selftests/bpf: Remove redundant sendmsg test cases
Remove these test cases completely, as the same behavior is already covered by other sendmsg* test cases in prog_tests/sock_addr.c. This just rewrites the destination address similar to sendmsg_v4_prog and sendmsg_v6_prog. Signed-off-by: Jordan Rife <jrife@google.com> Link: https://lore.kernel.org/r/20240510190246.3247730-13-jrife@google.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent cded71f commit 9c3f178

1 file changed

Lines changed: 0 additions & 161 deletions

File tree

tools/testing/selftests/bpf/test_sock_addr.c

Lines changed: 0 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -88,170 +88,9 @@ struct sock_addr_test {
8888
} expected_result;
8989
};
9090

91-
static int sendmsg4_rw_asm_prog_load(const struct sock_addr_test *test);
92-
static int sendmsg6_rw_asm_prog_load(const struct sock_addr_test *test);
93-
9491
static struct sock_addr_test tests[] = {
95-
/* sendmsg */
96-
{
97-
"sendmsg4: rewrite IP & port (asm)",
98-
sendmsg4_rw_asm_prog_load,
99-
BPF_CGROUP_UDP4_SENDMSG,
100-
BPF_CGROUP_UDP4_SENDMSG,
101-
AF_INET,
102-
SOCK_DGRAM,
103-
SERV4_IP,
104-
SERV4_PORT,
105-
SERV4_REWRITE_IP,
106-
SERV4_REWRITE_PORT,
107-
SRC4_REWRITE_IP,
108-
SUCCESS,
109-
},
110-
{
111-
"sendmsg6: rewrite IP & port (asm)",
112-
sendmsg6_rw_asm_prog_load,
113-
BPF_CGROUP_UDP6_SENDMSG,
114-
BPF_CGROUP_UDP6_SENDMSG,
115-
AF_INET6,
116-
SOCK_DGRAM,
117-
SERV6_IP,
118-
SERV6_PORT,
119-
SERV6_REWRITE_IP,
120-
SERV6_REWRITE_PORT,
121-
SRC6_REWRITE_IP,
122-
SUCCESS,
123-
},
12492
};
12593

126-
static int load_insns(const struct sock_addr_test *test,
127-
const struct bpf_insn *insns, size_t insns_cnt)
128-
{
129-
LIBBPF_OPTS(bpf_prog_load_opts, opts);
130-
int ret;
131-
132-
opts.expected_attach_type = test->expected_attach_type;
133-
opts.log_buf = bpf_log_buf;
134-
opts.log_size = BPF_LOG_BUF_SIZE;
135-
136-
ret = bpf_prog_load(BPF_PROG_TYPE_CGROUP_SOCK_ADDR, NULL, "GPL", insns, insns_cnt, &opts);
137-
if (ret < 0 && test->expected_result != LOAD_REJECT) {
138-
log_err(">>> Loading program error.\n"
139-
">>> Verifier output:\n%s\n-------\n", bpf_log_buf);
140-
}
141-
142-
return ret;
143-
}
144-
145-
static int sendmsg4_rw_asm_prog_load(const struct sock_addr_test *test)
146-
{
147-
struct sockaddr_in dst4_rw_addr;
148-
struct in_addr src4_rw_ip;
149-
150-
if (inet_pton(AF_INET, SRC4_REWRITE_IP, (void *)&src4_rw_ip) != 1) {
151-
log_err("Invalid IPv4: %s", SRC4_REWRITE_IP);
152-
return -1;
153-
}
154-
155-
if (make_sockaddr(AF_INET, SERV4_REWRITE_IP, SERV4_REWRITE_PORT,
156-
(struct sockaddr_storage *)&dst4_rw_addr,
157-
NULL) == -1)
158-
return -1;
159-
160-
struct bpf_insn insns[] = {
161-
BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
162-
163-
/* if (sk.family == AF_INET && */
164-
BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6,
165-
offsetof(struct bpf_sock_addr, family)),
166-
BPF_JMP_IMM(BPF_JNE, BPF_REG_7, AF_INET, 8),
167-
168-
/* sk.type == SOCK_DGRAM) { */
169-
BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6,
170-
offsetof(struct bpf_sock_addr, type)),
171-
BPF_JMP_IMM(BPF_JNE, BPF_REG_7, SOCK_DGRAM, 6),
172-
173-
/* msg_src_ip4 = src4_rw_ip */
174-
BPF_MOV32_IMM(BPF_REG_7, src4_rw_ip.s_addr),
175-
BPF_STX_MEM(BPF_W, BPF_REG_6, BPF_REG_7,
176-
offsetof(struct bpf_sock_addr, msg_src_ip4)),
177-
178-
/* user_ip4 = dst4_rw_addr.sin_addr */
179-
BPF_MOV32_IMM(BPF_REG_7, dst4_rw_addr.sin_addr.s_addr),
180-
BPF_STX_MEM(BPF_W, BPF_REG_6, BPF_REG_7,
181-
offsetof(struct bpf_sock_addr, user_ip4)),
182-
183-
/* user_port = dst4_rw_addr.sin_port */
184-
BPF_MOV32_IMM(BPF_REG_7, dst4_rw_addr.sin_port),
185-
BPF_STX_MEM(BPF_W, BPF_REG_6, BPF_REG_7,
186-
offsetof(struct bpf_sock_addr, user_port)),
187-
/* } */
188-
189-
/* return 1 */
190-
BPF_MOV64_IMM(BPF_REG_0, 1),
191-
BPF_EXIT_INSN(),
192-
};
193-
194-
return load_insns(test, insns, ARRAY_SIZE(insns));
195-
}
196-
197-
static int sendmsg6_rw_dst_asm_prog_load(const struct sock_addr_test *test,
198-
const char *rw_dst_ip)
199-
{
200-
struct sockaddr_in6 dst6_rw_addr;
201-
struct in6_addr src6_rw_ip;
202-
203-
if (inet_pton(AF_INET6, SRC6_REWRITE_IP, (void *)&src6_rw_ip) != 1) {
204-
log_err("Invalid IPv6: %s", SRC6_REWRITE_IP);
205-
return -1;
206-
}
207-
208-
if (make_sockaddr(AF_INET6, rw_dst_ip, SERV6_REWRITE_PORT,
209-
(struct sockaddr_storage *)&dst6_rw_addr,
210-
NULL) == -1)
211-
return -1;
212-
213-
struct bpf_insn insns[] = {
214-
BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
215-
216-
/* if (sk.family == AF_INET6) { */
217-
BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6,
218-
offsetof(struct bpf_sock_addr, family)),
219-
BPF_JMP_IMM(BPF_JNE, BPF_REG_7, AF_INET6, 18),
220-
221-
#define STORE_IPV6_WORD_N(DST, SRC, N) \
222-
BPF_MOV32_IMM(BPF_REG_7, SRC[N]), \
223-
BPF_STX_MEM(BPF_W, BPF_REG_6, BPF_REG_7, \
224-
offsetof(struct bpf_sock_addr, DST[N]))
225-
226-
#define STORE_IPV6(DST, SRC) \
227-
STORE_IPV6_WORD_N(DST, SRC, 0), \
228-
STORE_IPV6_WORD_N(DST, SRC, 1), \
229-
STORE_IPV6_WORD_N(DST, SRC, 2), \
230-
STORE_IPV6_WORD_N(DST, SRC, 3)
231-
232-
STORE_IPV6(msg_src_ip6, src6_rw_ip.s6_addr32),
233-
STORE_IPV6(user_ip6, dst6_rw_addr.sin6_addr.s6_addr32),
234-
235-
/* user_port = dst6_rw_addr.sin6_port */
236-
BPF_MOV32_IMM(BPF_REG_7, dst6_rw_addr.sin6_port),
237-
BPF_STX_MEM(BPF_W, BPF_REG_6, BPF_REG_7,
238-
offsetof(struct bpf_sock_addr, user_port)),
239-
240-
/* } */
241-
242-
/* return 1 */
243-
BPF_MOV64_IMM(BPF_REG_0, 1),
244-
BPF_EXIT_INSN(),
245-
};
246-
247-
return load_insns(test, insns, ARRAY_SIZE(insns));
248-
}
249-
250-
static int sendmsg6_rw_asm_prog_load(const struct sock_addr_test *test)
251-
{
252-
return sendmsg6_rw_dst_asm_prog_load(test, SERV6_REWRITE_IP);
253-
}
254-
25594
static int cmp_addr(const struct sockaddr_storage *addr1,
25695
const struct sockaddr_storage *addr2, int cmp_port)
25796
{

0 commit comments

Comments
 (0)