Re: [PATCH bpf-next 2/2] selftests/bpf: Verify that the cgroup_skb filters receive expected packets.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jun 12, 2023 at 12:16 PM Kui-Feng Lee <thinker.li@xxxxxxxxx> wrote:
> +static int close_connection(int *closing_fd, int *peer_fd, int *listen_fd)
> +{
> +       int err;
> +
> +       /* Half shutdown to make sure the closing socket having a chance to
> +        * receive a FIN from the client.
> +        */
> +       err = shutdown(*closing_fd, SHUT_WR);
> +       if (CHECK(err, "shutdown closing_fd", "failed: %d\n", err))
> +               return -1;
> +       usleep(100000);
> +       err = close(*peer_fd);
> +       if (CHECK(err, "close peer_fd", "failed: %d\n", err))
> +               return -1;
> +       *peer_fd = -1;
> +       usleep(100000);
> +       err = close(*closing_fd);

usleep() won't guarantee it. The test will be flaky.
Can you make it reliable?

> +
> +/* Run accept() on a socket in the cgroup to receive a new connection. */
> +#define EGRESS_ACCEPT                                                  \
> +       case SYN_RECV_SENDING_SYN_ACK:                                  \
> +               if (tcph.fin || !tcph.syn || tcph.rst || !tcph.ack)     \
> +                       g_unexpected++;                                 \
> +               else                                                    \
> +                       g_sock_state = SYN_RECV;                        \
> +               break
> +
> +#define INGRESS_ACCEPT                                                 \
> +       case INIT:                                                      \
> +               if (!tcph.syn || tcph.fin || tcph.rst || tcph.ack)      \
> +                       g_unexpected++;                                 \
> +               else                                                    \
> +                       g_sock_state = SYN_RECV_SENDING_SYN_ACK;        \
> +               break;                                                  \
> +       case SYN_RECV:                                                  \
> +               if (tcph.fin || tcph.syn || tcph.rst || !tcph.ack)      \
> +                       g_unexpected++;                                 \
> +               else                                                    \
> +                       g_sock_state = ESTABLISHED;                     \
> +               break
> +

The macros make the code difficult to follow.
Could you do it with normal functions?





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux