bpf: a bug fix and test cases for bpf_skb_change_tail()
Subsystems (6)
v3 cover bpf: a bug fix and test cases for bpf_skb_change_tail()
From: Cong Wang <[email protected]>
This patchset fixes a bug in bpf_skb_change_tail() helper and adds test cases for it, as requested by Daniel and John.
---
v3: switched to TCX prog attaching API
switched to UDP from TCP for TC test
cleaned up TC test code
v2: added a test case for TC where offsets are positive
fixed a typo in 1/4 patch description reduced buffer size in the sockmap test case
Cong Wang (4):
bpf: Check negative offsets in __bpf_skb_min_len() selftests/bpf: Add a BPF selftest for bpf_skb_change_tail() selftests/bpf: Introduce socket_helpers.h for TC tests selftests/bpf: Test bpf_skb_change_tail() in TC ingress
net/core/filter.c | 21 +- .../selftests/bpf/prog_tests/socket_helpers.h | 394 ++++++++++++++++++ .../selftests/bpf/prog_tests/sockmap_basic.c | 51 +++ .../bpf/prog_tests/sockmap_helpers.h | 385 +---------------- .../selftests/bpf/prog_tests/tc_change_tail.c | 62 +++ .../bpf/progs/test_sockmap_change_tail.c | 40 ++ .../selftests/bpf/progs/test_tc_change_tail.c | 106 +++++ 7 files changed, 669 insertions(+), 390 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/socket_helpers.h create mode 100644 tools/testing/selftests/bpf/prog_tests/tc_change_tail.c create mode 100644 tools/testing/selftests/bpf/progs/test_sockmap_change_tail.c create mode 100644 tools/testing/selftests/bpf/progs/test_tc_change_tail.c
Signature · 1 line
2.34.1
PATCH v3 1/4 bpf: Check negative offsets in __bpf_skb_min_len()
From: Cong Wang <[email protected]>
skb_network_offset() and skb_transport_offset() can be negative when they are called after we pull the transport header, for example, when we use eBPF sockmap at the point of ->sk_data_ready().
__bpf_skb_min_len() uses an unsigned int to get these offsets, this leads to a very large number which then causes bpf_skb_change_tail() failed unexpectedly.
Fix this by using a signed int to get these offsets and ensure the minimum is at least zero.
--- net/core/filter.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
net/core/filter.c +15 -6
@@ -3734,13 +3734,22 @@ static const struct bpf_func_proto bpf_skb_adjust_room_proto = {static u32 __bpf_skb_min_len (const struct sk_buff *skb) { -u32 min_len =skb_network_offset (skb); +int offset =skb_network_offset (skb); +u32 min_len =0 ; -if (skb_transport_header_was_set (skb)) - min_len =skb_transport_offset (skb); -if (skb->ip_summed ==CHECKSUM_PARTIAL ) - min_len =skb_checksum_start_offset (skb) + - skb->csum_offset +sizeof (__sum16); +if (offset >0 ) + min_len = offset; +if (skb_transport_header_was_set (skb)) { + offset =skb_transport_offset (skb); +if (offset >0 ) + min_len = offset; + } +if (skb->ip_summed ==CHECKSUM_PARTIAL ) { + offset =skb_checksum_start_offset (skb) + + skb->csum_offset +sizeof (__sum16); +if (offset >0 ) + min_len = offset; + }return min_len; }
Signature · 1 line
2.34.1
RE: [Patch bpf v3 1/4] bpf: Check negative offsets in __bpf_skb_min_len()
Quoted 10 lines · Cong Wang
From: Cong Wang <[email protected]>
skb_network_offset()andskb_transport_offset()can be negative when they are called after we pull the transport header, for example, when we use eBPF sockmap at the point of ->sk_data_ready().
__bpf_skb_min_len()uses an unsigned int to get these offsets, this leads to a very large number which then causesbpf_skb_change_tail()failed unexpectedly.
Quoted 8 lines
Fix this by using a signed int to get these offsets and ensure the minimum is at least zero.
Fixes 5293efe62df8 ("bpf: add bpf_skb_change_tail helper")Cc John Fastabend <[email protected]>Cc Daniel Borkmann <[email protected]>Signed-off-by Cong Wang <[email protected]>---
PATCH v3 2/4 selftests/bpf: Add a BPF selftest for bpf_skb_change_tail()
In reply to Cong WangFrom: Cong Wang <[email protected]>
As requested by Daniel, we need to add a selftest to cover bpf_skb_change_tail() cases in skb_verdict. Here we test trimming, growing and error cases, and validate its expected return values and the expected sizes of the payload.
--- .../selftests/bpf/prog_tests/sockmap_basic.c | 51 +++++++++++++++++++ .../bpf/progs/test_sockmap_change_tail.c | 40 +++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/test_sockmap_change_tail.c
tools/testing/selftests/bpf/prog_tests/sockmap_basic.c +51 -0
@@ -12,6 +12,7 @@#include "test_sockmap_progs_query.skel.h" #include "test_sockmap_pass_prog.skel.h" #include "test_sockmap_drop_prog.skel.h" +#include "test_sockmap_change_tail.skel.h" #include "bpf_iter_sockmap.skel.h" #include "sockmap_helpers.h"
@@ -643,6 +644,54 @@ static void test_sockmap_skb_verdict_fionread(bool pass_prog)test_sockmap_drop_prog__destroy (drop); } +static void test_sockmap_skb_verdict_change_tail (void ) +{ +struct test_sockmap_change_tail *skel; +int err, map, verdict; +int c1, p1, sent, recvd; +int zero =0 ; +char buf[2 ]; + + skel =test_sockmap_change_tail__open_and_load (); +if (!ASSERT_OK_PTR (skel,"open_and_load" )) +return ; + verdict =bpf_program__fd (skel->progs.prog_skb_verdict); + map =bpf_map__fd (skel->maps.sock_map_rx); + + err =bpf_prog_attach (verdict, map,BPF_SK_SKB_STREAM_VERDICT ,0 ); +if (!ASSERT_OK (err,"bpf_prog_attach" )) + goto out; + err =create_pair (AF_INET ,SOCK_STREAM , &c1, &p1); +if (!ASSERT_OK (err,"create_pair()" )) + goto out; + err =bpf_map_update_elem (map, &zero, &c1,BPF_NOEXIST ); +if (!ASSERT_OK (err,"bpf_map_update_elem(c1)" )) + goto out_close; + sent =xsend (p1,"Tr" ,2 ,0 ); +ASSERT_EQ (sent,2 ,"xsend(p1)" ); + recvd =recv (c1, buf,2 ,0 ); +ASSERT_EQ (recvd,1 ,"recv(c1)" ); +ASSERT_EQ (skel->data->change_tail_ret,0 ,"change_tail_ret" ); + + sent =xsend (p1,"G" ,1 ,0 ); +ASSERT_EQ (sent,1 ,"xsend(p1)" ); + recvd =recv (c1, buf,2 ,0 ); +ASSERT_EQ (recvd,2 ,"recv(c1)" ); +ASSERT_EQ (skel->data->change_tail_ret,0 ,"change_tail_ret" ); + + sent =xsend (p1,"E" ,1 ,0 ); +ASSERT_EQ (sent,1 ,"xsend(p1)" ); + recvd =recv (c1, buf,1 ,0 ); +ASSERT_EQ (recvd,1 ,"recv(c1)" ); +ASSERT_EQ (skel->data->change_tail_ret, -EINVAL ,"change_tail_ret" ); + +out_close: +close (c1); +close (p1); +out: +test_sockmap_change_tail__destroy (skel); +} +static void test_sockmap_skb_verdict_peek_helper (int map) {int err, c1, p1, zero =0 , sent, recvd, avail;
@@ -1058,6 +1107,8 @@ void test_sockmap_basic(void)test_sockmap_skb_verdict_fionread (true);if (test__start_subtest ("sockmap skb_verdict fionread on drop" ))test_sockmap_skb_verdict_fionread (false); +if (test__start_subtest ("sockmap skb_verdict change tail" )) +test_sockmap_skb_verdict_change_tail ();if (test__start_subtest ("sockmap skb_verdict msg_f_peek" ))test_sockmap_skb_verdict_peek ();if (test__start_subtest ("sockmap skb_verdict msg_f_peek with link" ))
tools/testing/selftests/bpf/progs/test_sockmap_change_tail.c new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2024 ByteDance */ +#include <linux/bpf.h> +#include <bpf/bpf_helpers.h> + +struct { + __uint(type, BPF_MAP_TYPE_SOCKMAP); + __uint(max_entries, 1); + __type(key, int); + __type(value, int); +} sock_map_rx SEC(".maps"); + +long change_tail_ret =1 ; + +SEC("sk_skb") +int prog_skb_verdict (struct __sk_buff *skb) +{ +char *data, *data_end; + +bpf_skb_pull_data (skb,1 ); + data = (char *)(unsigned long )skb->data; + data_end = (char *)(unsigned long )skb->data_end; + +if (data +1 > data_end) +return SK_PASS ; + +if (data[0 ] =='T' ) {/* Trim the packet */ + change_tail_ret =bpf_skb_change_tail (skb, skb->len -1 ,0 ); +return SK_PASS ; + }else if (data[0 ] =='G' ) {/* Grow the packet */ + change_tail_ret =bpf_skb_change_tail (skb, skb->len +1 ,0 ); +return SK_PASS ; + }else if (data[0 ] =='E' ) {/* Error */ + change_tail_ret =bpf_skb_change_tail (skb,65535 ,0 ); +return SK_PASS ; + } +return SK_PASS ; +} + +char _license[] SEC("license") = "GPL";
Signature · 1 line
2.34.1
RE: [Patch bpf v3 2/4] selftests/bpf: Add a BPF selftest for bpf_skb_change_tail()
Quoted 11 lines · Cong Wang
From: Cong Wang <[email protected]>
As requested by Daniel, we need to add a selftest to cover
bpf_skb_change_tail()cases inskb_verdict. Here we test trimming, growing and error cases, and validate its expected return values and the expected sizes of the payload.Cc John Fastabend <[email protected]>Cc Daniel Borkmann <[email protected]>Cc Zijian Zhang <[email protected]>Signed-off-by Cong Wang <[email protected]>
Quoted 5 lines
--- .../selftests/bpf/prog_tests/sockmap_basic.c | 51 +++++++++++++++++++ .../bpf/progs/test_sockmap_change_tail.c | 40 +++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/test_sockmap_change_tail.c
PATCH v3 3/4 selftests/bpf: Introduce socket_helpers.h for TC tests
In reply to Cong WangFrom: Cong Wang <[email protected]>
Pull socket helpers out of sockmap_helpers.h so that they can be reused for TC tests as well. This prepares for the next patch.
--- .../selftests/bpf/prog_tests/socket_helpers.h | 394 ++++++++++++++++++ .../bpf/prog_tests/sockmap_helpers.h | 385 +---------------- 2 files changed, 395 insertions(+), 384 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/socket_helpers.h
tools/testing/selftests/bpf/prog_tests/socket_helpers.h new file +394 -0
@@ -0,0 +1,394 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __SOCKET_HELPERS__ +#define __SOCKET_HELPERS__ + +#include <linux/vm_sockets.h> + +/* include/linux/net.h */ +#define SOCK_TYPE_MASK 0xf + +#define IO_TIMEOUT_SEC 30 +#define MAX_STRERR_LEN 256 + +/* workaround for older vm_sockets.h */ +#ifndef VMADDR_CID_LOCAL +#define VMADDR_CID_LOCAL 1 +#endif + +/* include/linux/cleanup.h */ +#define __get_and_null (p, nullvalue) \ + ({ \ + __auto_type __ptr = &(p); \ + __auto_type __val = *__ptr; \ + *__ptr = nullvalue; \ + __val; \ + }) + +#define take_fd (fd) __get_and_null(fd, -EBADF) + +/* Wrappers that fail the test on error and report it. */ + +#define _FAIL(errnum, fmt...) \ + ({ \ + error_at_line(0, (errnum), __func__, __LINE__, fmt); \ + CHECK_FAIL(true); \ + }) +#define FAIL(fmt...) _FAIL(0, fmt) +#define FAIL_ERRNO(fmt...) _FAIL(errno, fmt) +#define FAIL_LIBBPF (err, msg) \ + ({ \ + char __buf[MAX_STRERR_LEN]; \ + libbpf_strerror((err), __buf, sizeof(__buf)); \ + FAIL("%s: %s", (msg), __buf); \ + }) + + +#define xaccept_nonblock (fd, addr, len) \ + ({ \ + int __ret = \ + accept_timeout((fd), (addr), (len), IO_TIMEOUT_SEC); \ + if (__ret == -1) \ + FAIL_ERRNO("accept"); \ + __ret; \ + }) + +#define xbind (fd, addr, len) \ + ({ \ + int __ret = bind((fd), (addr), (len)); \ + if (__ret == -1) \ + FAIL_ERRNO("bind"); \ + __ret; \ + }) + +#define xclose (fd) \ + ({ \ + int __ret = close((fd)); \ + if (__ret == -1) \ + FAIL_ERRNO("close"); \ + __ret; \ + }) + +#define xconnect (fd, addr, len) \ + ({ \ + int __ret = connect((fd), (addr), (len)); \ + if (__ret == -1) \ + FAIL_ERRNO("connect"); \ + __ret; \ + }) + +#define xgetsockname (fd, addr, len) \ + ({ \ + int __ret = getsockname((fd), (addr), (len)); \ + if (__ret == -1) \ + FAIL_ERRNO("getsockname"); \ + __ret; \ + }) + +#define xgetsockopt (fd, level, name, val, len) \ + ({ \ + int __ret = getsockopt((fd), (level), (name), (val), (len)); \ + if (__ret == -1) \ + FAIL_ERRNO("getsockopt(" #name ")"); \ + __ret; \ + }) + +#define xlisten (fd, backlog) \ + ({ \ + int __ret = listen((fd), (backlog)); \ + if (__ret == -1) \ + FAIL_ERRNO("listen"); \ + __ret; \ + }) + +#define xsetsockopt (fd, level, name, val, len) \ + ({ \ + int __ret = setsockopt((fd), (level), (name), (val), (len)); \ + if (__ret == -1) \ + FAIL_ERRNO("setsockopt(" #name ")"); \ + __ret; \ + }) + +#define xsend (fd, buf, len, flags) \ + ({ \ + ssize_t __ret = send((fd), (buf), (len), (flags)); \ + if (__ret == -1) \ + FAIL_ERRNO("send"); \ + __ret; \ + }) + +#define xrecv_nonblock (fd, buf, len, flags) \ + ({ \ + ssize_t __ret = recv_timeout((fd), (buf), (len), (flags), \ + IO_TIMEOUT_SEC); \ + if (__ret == -1) \ + FAIL_ERRNO("recv"); \ + __ret; \ + }) + +#define xsocket (family, sotype, flags) \ + ({ \ + int __ret = socket(family, sotype, flags); \ + if (__ret == -1) \ + FAIL_ERRNO("socket"); \ + __ret; \ + }) + +static inline void close_fd (int *fd) +{ +if (*fd >=0 ) +xclose (*fd); +} + +#define __close_fd __attribute__((cleanup(close_fd))) + +static inline struct sockaddr *sockaddr (struct sockaddr_storage *ss) +{ +return (struct sockaddr *)ss; +} + +static inline void init_addr_loopback4 (struct sockaddr_storage *ss, +socklen_t *len) +{ +struct sockaddr_in *addr4 =memset (ss,0 ,sizeof (*ss)); + + addr4->sin_family =AF_INET ; + addr4->sin_port =0 ; + addr4->sin_addr.s_addr =htonl (INADDR_LOOPBACK ); + *len =sizeof (*addr4); +} + +static inline void init_addr_loopback6 (struct sockaddr_storage *ss, +socklen_t *len) +{ +struct sockaddr_in6 *addr6 =memset (ss,0 ,sizeof (*ss)); + + addr6->sin6_family =AF_INET6 ; + addr6->sin6_port =0 ; + addr6->sin6_addr = in6addr_loopback; + *len =sizeof (*addr6); +} + +static inline void init_addr_loopback_vsock (struct sockaddr_storage *ss, +socklen_t *len) +{ +struct sockaddr_vm *addr =memset (ss,0 ,sizeof (*ss)); + + addr->svm_family =AF_VSOCK ; + addr->svm_port =VMADDR_PORT_ANY ; + addr->svm_cid =VMADDR_CID_LOCAL ; + *len =sizeof (*addr); +} + +static inline void init_addr_loopback (int family,struct sockaddr_storage *ss, +socklen_t *len) +{ +switch (family) { +case AF_INET : +init_addr_loopback4 (ss, len); +return ; +case AF_INET6 : +init_addr_loopback6 (ss, len); +return ; +case AF_VSOCK : +init_addr_loopback_vsock (ss, len); +return ; +default : +FAIL ("unsupported address family %d" , family); + } +} + +static inline int enable_reuseport (int s,int progfd) +{ +int err, one =1 ; + + err =xsetsockopt (s,SOL_SOCKET ,SO_REUSEPORT , &one,sizeof (one)); +if (err) +return -1 ; + err =xsetsockopt (s,SOL_SOCKET ,SO_ATTACH_REUSEPORT_EBPF , &progfd, +sizeof (progfd)); +if (err) +return -1 ; + +return 0 ; +} + +static inline int socket_loopback_reuseport (int family,int sotype,int progfd) +{ +struct sockaddr_storage addr; +socklen_t len =0 ; +int err, s; + +init_addr_loopback (family, &addr, &len); + + s =xsocket (family, sotype,0 ); +if (s ==-1 ) +return -1 ; + +if (progfd >=0 ) +enable_reuseport (s, progfd); + + err =xbind (s,sockaddr (&addr), len); +if (err) + goto close; + +if (sotype &SOCK_DGRAM ) +return s; + + err =xlisten (s,SOMAXCONN ); +if (err) + goto close; + +return s; +close: +xclose (s); +return -1 ; +} + +static inline int socket_loopback (int family,int sotype) +{ +return socket_loopback_reuseport (family, sotype,-1 ); +} + +static inline int poll_connect (int fd,unsigned int timeout_sec) +{ +struct timeval timeout = { .tv_sec = timeout_sec }; +fd_set wfds; +int r, eval; +socklen_t esize =sizeof (eval); + +FD_ZERO (&wfds); +FD_SET (fd, &wfds); + + r =select (fd +1 ,NULL , &wfds,NULL , &timeout); +if (r ==0 ) + errno =ETIME ; +if (r !=1 ) +return -1 ; + +if (getsockopt (fd,SOL_SOCKET ,SO_ERROR , &eval, &esize) <0 ) +return -1 ; +if (eval !=0 ) { + errno = eval; +return -1 ; + } + +return 0 ; +} + +static inline int poll_read (int fd,unsigned int timeout_sec) +{ +struct timeval timeout = { .tv_sec = timeout_sec }; +fd_set rfds; +int r; + +FD_ZERO (&rfds); +FD_SET (fd, &rfds); + + r =select (fd +1 , &rfds,NULL ,NULL , &timeout); +if (r ==0 ) + errno =ETIME ; + +return r ==1 ?0 :-1 ; +} + +static inline int accept_timeout (int fd,struct sockaddr *addr,socklen_t *len, +unsigned int timeout_sec) +{ +if (poll_read (fd, timeout_sec)) +return -1 ; + +return accept (fd, addr, len); +} + +static inline int recv_timeout (int fd,void *buf,size_t len,int flags, +unsigned int timeout_sec) +{ +if (poll_read (fd, timeout_sec)) +return -1 ; + +return recv (fd, buf, len, flags); +} + + +static inline int create_pair (int family,int sotype,int *p0,int *p1) +{ + __close_fd int s, c = -1, p = -1; +struct sockaddr_storage addr; +socklen_t len =sizeof (addr); +int err; + + s =socket_loopback (family, sotype); +if (s <0 ) +return s; + + err =xgetsockname (s,sockaddr (&addr), &len); +if (err) +return err; + + c =xsocket (family, sotype,0 ); +if (c <0 ) +return c; + + err =connect (c,sockaddr (&addr), len); +if (err) { +if (errno !=EINPROGRESS ) { +FAIL_ERRNO ("connect" ); +return err; + } + + err =poll_connect (c,IO_TIMEOUT_SEC ); +if (err) { +FAIL_ERRNO ("poll_connect" ); +return err; + } + } + +switch (sotype &SOCK_TYPE_MASK ) { +case SOCK_DGRAM : + err =xgetsockname (c,sockaddr (&addr), &len); +if (err) +return err; + + err =xconnect (s,sockaddr (&addr), len); +if (err) +return err; + + *p0 =take_fd (s); +break ; +case SOCK_STREAM : +case SOCK_SEQPACKET : + p =xaccept_nonblock (s,NULL ,NULL ); +if (p <0 ) +return p; + + *p0 =take_fd (p); +break ; +default : +FAIL ("Unsupported socket type %#x" , sotype); +return -EOPNOTSUPP ; + } + + *p1 =take_fd (c); +return 0 ; +} + +static inline int create_socket_pairs (int family,int sotype,int *c0,int *c1, +int *p0,int *p1) +{ +int err; + + err =create_pair (family, sotype, c0, p0); +if (err) +return err; + + err =create_pair (family, sotype, c1, p1); +if (err) { +close (*c0); +close (*p0); + } + +return err; +} + +#endif // __SOCKET_HELPERS__
tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h +1 -384
406 lines not on this page · raw message
Signature · 1 line
2.34.1
RE: [Patch bpf v3 3/4] selftests/bpf: Introduce socket_helpers.h for TC tests
Quoted 10 lines · Cong Wang
From: Cong Wang <[email protected]>
Pull socket helpers out of
sockmap_helpers.hso that they can be reused for TC tests as well. This prepares for the next patch.Cc John Fastabend <[email protected]>Cc Daniel Borkmann <[email protected]>Cc Zijian Zhang <[email protected]>Signed-off-by Cong Wang <[email protected]>---
PATCH v3 4/4 selftests/bpf: Test bpf_skb_change_tail() in TC ingress
In reply to Cong WangFrom: Cong Wang <[email protected]>
Similarly to the previous test, we also need a test case to cover positive offsets as well, TC is an excellent hook for this.
--- .../selftests/bpf/prog_tests/tc_change_tail.c | 62 ++++++++++ .../selftests/bpf/progs/test_tc_change_tail.c | 106 ++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/tc_change_tail.c create mode 100644 tools/testing/selftests/bpf/progs/test_tc_change_tail.c
tools/testing/selftests/bpf/prog_tests/tc_change_tail.c new file +62 -0
@@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <error.h> +#include <test_progs.h> +#include <linux/pkt_cls.h> + +#include "test_tc_change_tail.skel.h" +#include "socket_helpers.h" + +#define LO_IFINDEX 1 + +void test_tc_change_tail (void ) +{ +LIBBPF_OPTS (bpf_tcx_opts, tcx_opts); +struct test_tc_change_tail *skel =NULL ; +struct bpf_link *link; +int c1, p1; +char buf[2 ]; +int ret; + + skel =test_tc_change_tail__open_and_load (); +if (!ASSERT_OK_PTR (skel,"test_tc_change_tail__open_and_load" )) +return ; + + link =bpf_program__attach_tcx (skel->progs.change_tail,LO_IFINDEX , + &tcx_opts); +if (!ASSERT_OK_PTR (link,"bpf_program__attach_tcx" )) + goto destroy; + + skel->links.change_tail = link; + ret =create_pair (AF_INET ,SOCK_DGRAM , &c1, &p1); +if (!ASSERT_OK (ret,"create_pair" )) + goto destroy; + + ret =xsend (p1,"Tr" ,2 ,0 ); +ASSERT_EQ (ret,2 ,"xsend(p1)" ); + ret =recv (c1, buf,2 ,0 ); +ASSERT_EQ (ret,2 ,"recv(c1)" ); +ASSERT_EQ (skel->data->change_tail_ret,0 ,"change_tail_ret" ); + + ret =xsend (p1,"G" ,1 ,0 ); +ASSERT_EQ (ret,1 ,"xsend(p1)" ); + ret =recv (c1, buf,2 ,0 ); +ASSERT_EQ (ret,1 ,"recv(c1)" ); +ASSERT_EQ (skel->data->change_tail_ret,0 ,"change_tail_ret" ); + + ret =xsend (p1,"E" ,1 ,0 ); +ASSERT_EQ (ret,1 ,"xsend(p1)" ); + ret =recv (c1, buf,1 ,0 ); +ASSERT_EQ (ret,1 ,"recv(c1)" ); +ASSERT_EQ (skel->data->change_tail_ret, -EINVAL ,"change_tail_ret" ); + + ret =xsend (p1,"Z" ,1 ,0 ); +ASSERT_EQ (ret,1 ,"xsend(p1)" ); + ret =recv (c1, buf,1 ,0 ); +ASSERT_EQ (ret,1 ,"recv(c1)" ); +ASSERT_EQ (skel->data->change_tail_ret, -EINVAL ,"change_tail_ret" ); + +close (c1); +close (p1); +destroy: +test_tc_change_tail__destroy (skel); +}
tools/testing/selftests/bpf/progs/test_tc_change_tail.c new file +106 -0
106 lines not on this page · raw message
Signature · 1 line
2.34.1
RE: [Patch bpf v3 4/4] selftests/bpf: Test bpf_skb_change_tail() in TC ingress
Quoted 10 lines · Cong Wang
From: Cong Wang <[email protected]>
Similarly to the previous test, we also need a test case to cover positive offsets as well, TC is an excellent hook for this.
Cc John Fastabend <[email protected]>Cc Daniel Borkmann <[email protected]>Tested-by Zijian Zhang <[email protected]>Signed-off-by Cong Wang <[email protected]>---
This series was applied to bpf/bpf.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This series was applied to bpf/bpf.git (master)
by Daniel Borkmann <[email protected]>:
Quoted 11 lines · On Thu, 12 Dec 2024 19:40:53 -0800 you wrote:
From: Cong Wang <[email protected]>
This patchset fixes a bug in
bpf_skb_change_tail()helper and adds test cases for it, as requested by Daniel and John.---
v3: switched to TCX prog attaching API
switched to UDP from TCP for TC test
cleaned up TC test code[...]
Here is the summary with links:
- [bpf,v3,1/4] bpf: Check negative offsets in __bpf_skb_min_len()
https://git.kernel.org/bpf/bpf/c/9ecc4d858b92 - [bpf,v3,2/4] selftests/bpf: Add a BPF selftest for bpf_skb_change_tail() https://git.kernel.org/bpf/bpf/c/9ee0c7b86543 - [bpf,v3,3/4] selftests/bpf: Introduce socket_helpers.h for TC tests https://git.kernel.org/bpf/bpf/c/472759c9f537 - [bpf,v3,4/4] selftests/bpf: Test bpf_skb_change_tail() in TC ingress https://git.kernel.org/bpf/bpf/c/4a58963d10fa
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html