Skip to content
Snippets Groups Projects
Select Git revision
  • a97f162c6c70e1466451f85bde5a16a15ec49f0a
  • collabora/main default protected
  • last-combined-container protected
  • wip/ritesh/move-hostname-ip.collabora/master protected
  • wip/docker-stuff protected
  • andrewsh/email-lookup protected
  • collabora/packaging protected
  • wip/collabora/main protected
  • wip/andrewsh/sso-base protected
  • wip/andrewsh/patch-queue/sso-test protected
  • collabora/master protected
  • fix-css protected
  • wip/andrewsh/upstream-backports protected
  • pristine-lfs protected
  • wip/ritesh/fix-changelog protected
  • wip-t13997 protected
  • revert-b2545e01 protected
  • debian/master protected
  • collabora/2.7.1-10 protected
  • pristine-tar protected
  • upstream/2.7.x protected
  • collabora/2.7.4-3co3 protected
  • collabora/2.7.4-3co2 protected
  • collabora/2.7.4-3co1 protected
  • collabora/2.7.1-10co6 protected
  • debian/2.7.4-1 protected
  • upstream/2.7.4 protected
  • collabora/2.7.1-10co4 protected
  • collabora/2.7.1-10co3 protected
  • collabora/2.7.1-10co2 protected
  • collabora/2.7.1-10co1 protected
  • debian/2.7.1-10 protected
  • debian/2.7.1-9 protected
  • debian/2.7.1-8 protected
  • debian/2.7.1-7 protected
  • debian/2.7.1-6 protected
  • debian/2.7.1-5 protected
  • debian/2.7.1-4 protected
  • debian/2.7.1-3 protected
  • debian/2.7.1-2 protected
  • debian/2.7.1-1 protected
41 results

user.rb

Blame
  • udp_limit.c 2.02 KiB
    // SPDX-License-Identifier: GPL-2.0
    #include <test_progs.h>
    #include "udp_limit.skel.h"
    
    #include <sys/types.h>
    #include <sys/socket.h>
    
    static int duration;
    
    void test_udp_limit(void)
    {
    	struct udp_limit *skel;
    	int fd1 = -1, fd2 = -1;
    	int cgroup_fd;
    
    	cgroup_fd = test__join_cgroup("/udp_limit");
    	if (CHECK(cgroup_fd < 0, "cg-join", "errno %d", errno))
    		return;
    
    	skel = udp_limit__open_and_load();
    	if (CHECK(!skel, "skel-load", "errno %d", errno))
    		goto close_cgroup_fd;
    
    	skel->links.sock = bpf_program__attach_cgroup(skel->progs.sock, cgroup_fd);
    	skel->links.sock_release = bpf_program__attach_cgroup(skel->progs.sock_release, cgroup_fd);
    	if (CHECK(IS_ERR(skel->links.sock) || IS_ERR(skel->links.sock_release),
    		  "cg-attach", "sock %ld sock_release %ld",
    		  PTR_ERR(skel->links.sock),
    		  PTR_ERR(skel->links.sock_release)))
    		goto close_skeleton;
    
    	/* BPF program enforces a single UDP socket per cgroup,
    	 * verify that.
    	 */
    	fd1 = socket(AF_INET, SOCK_DGRAM, 0);
    	if (CHECK(fd1 < 0, "fd1", "errno %d", errno))
    		goto close_skeleton;
    
    	fd2 = socket(AF_INET, SOCK_DGRAM, 0);
    	if (CHECK(fd2 >= 0, "fd2", "errno %d", errno))
    		goto close_skeleton;
    
    	/* We can reopen again after close. */
    	close(fd1);
    	fd1 = -1;
    
    	fd1 = socket(AF_INET, SOCK_DGRAM, 0);
    	if (CHECK(fd1 < 0, "fd1-again", "errno %d", errno))
    		goto close_skeleton;
    
    	/* Make sure the program was invoked the expected
    	 * number of times:
    	 * - open fd1           - BPF_CGROUP_INET_SOCK_CREATE
    	 * - attempt to openfd2 - BPF_CGROUP_INET_SOCK_CREATE
    	 * - close fd1          - BPF_CGROUP_INET_SOCK_RELEASE
    	 * - open fd1 again     - BPF_CGROUP_INET_SOCK_CREATE
    	 */
    	if (CHECK(skel->bss->invocations != 4, "bss-invocations",
    		  "invocations=%d", skel->bss->invocations))
    		goto close_skeleton;
    
    	/* We should still have a single socket in use */
    	if (CHECK(skel->bss->in_use != 1, "bss-in_use",
    		  "in_use=%d", skel->bss->in_use))
    		goto close_skeleton;
    
    close_skeleton:
    	if (fd1 >= 0)
    		close(fd1);
    	if (fd2 >= 0)
    		close(fd2);
    	udp_limit__destroy(skel);
    close_cgroup_fd:
    	close(cgroup_fd);
    }