Skip to content

Commit 941ff6f

Browse files
borkmanndavem330
authored andcommitted
bpf: fix rlimit in reuseport net selftest
Fix two issues in the reuseport_bpf selftests that were reported by Linaro CI: [...] + ./reuseport_bpf ---- IPv4 UDP ---- Testing EBPF mod 10... Reprograming, testing mod 5... ./reuseport_bpf: ebpf error. log: 0: (bf) r6 = r1 1: (20) r0 = *(u32 *)skb[0] 2: (97) r0 %= 10 3: (95) exit processed 4 insns : Operation not permitted + echo FAIL [...] ---- IPv4 TCP ---- Testing EBPF mod 10... ./reuseport_bpf: failed to bind send socket: Address already in use + echo FAIL [...] For the former adjust rlimit since this was the cause of failure for loading the BPF prog, and for the latter add SO_REUSEADDR. Reported-by: Naresh Kamboju <[email protected]> Link: https://bugs.linaro.org/show_bug.cgi?id=3502 Signed-off-by: Daniel Borkmann <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 07f2c7a commit 941ff6f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

tools/testing/selftests/net/reuseport_bpf.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <sys/epoll.h>
2222
#include <sys/types.h>
2323
#include <sys/socket.h>
24+
#include <sys/resource.h>
2425
#include <unistd.h>
2526

2627
#ifndef ARRAY_SIZE
@@ -190,11 +191,14 @@ static void send_from(struct test_params p, uint16_t sport, char *buf,
190191
struct sockaddr * const saddr = new_any_sockaddr(p.send_family, sport);
191192
struct sockaddr * const daddr =
192193
new_loopback_sockaddr(p.send_family, p.recv_port);
193-
const int fd = socket(p.send_family, p.protocol, 0);
194+
const int fd = socket(p.send_family, p.protocol, 0), one = 1;
194195

195196
if (fd < 0)
196197
error(1, errno, "failed to create send socket");
197198

199+
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)))
200+
error(1, errno, "failed to set reuseaddr");
201+
198202
if (bind(fd, saddr, sockaddr_size()))
199203
error(1, errno, "failed to bind send socket");
200204

@@ -433,6 +437,21 @@ void enable_fastopen(void)
433437
}
434438
}
435439

440+
static struct rlimit rlim_old, rlim_new;
441+
442+
static __attribute__((constructor)) void main_ctor(void)
443+
{
444+
getrlimit(RLIMIT_MEMLOCK, &rlim_old);
445+
rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20);
446+
rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20);
447+
setrlimit(RLIMIT_MEMLOCK, &rlim_new);
448+
}
449+
450+
static __attribute__((destructor)) void main_dtor(void)
451+
{
452+
setrlimit(RLIMIT_MEMLOCK, &rlim_old);
453+
}
454+
436455
int main(void)
437456
{
438457
fprintf(stderr, "---- IPv4 UDP ----\n");

0 commit comments

Comments
 (0)