Debian Codegraph @

src/bpf/socket-bind-api.bpf.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 /* The SPDX header above is actually correct in claiming this was
5 * LGPL-2.1-or-later, because it is. Since the kernel doesn't consider that
6 * compatible with GPL we will claim this to be GPL however, which should be
7 * fine given that LGPL-2.1-or-later downgrades to GPL if needed.
8 */
9
10 #include <linux/types.h>
11 #include <stdint.h>
12
13 /*
14 * Bind rule is matched with socket fields accessible to cgroup/bind{4,6} hook
15 * through bpf_sock_addr struct.
16 * 'address_family' is expected to be one of AF_UNSPEC, AF_INET, AF_INET6 or the
17 * magic SOCKET_BIND_RULE_AF_MATCH_NOTHING.
18 * Matching by family is bypassed for rules with AF_UNSPEC set, which makes the
19 * rest of a rule applicable for both IPv4 and IPv6 addresses.
20 * If SOCKET_BIND_RULE_AF_MATCH_NOTHING is set the rule fails unconditionally
21 * and other checks are skipped.
22 * If matching by family is either successful or bypassed, a rule and a socket
23 * are matched by ip protocol.
24 * If 'protocol' is 0, matching is bypassed.
25 * 'nr_ports' and 'port_min' fields specify a set of ports to match a user port
26 * with.
27 * If 'nr_ports' is 0, matching by port is bypassed, making that rule applicable
28 * for all possible ports, e.g. [1, 65535] range. Thus a rule with
29 * 'address_family', 'protocol' and 'nr_ports' equal to AF_UNSPEC, 0 and 0
30 * correspondingly forms 'allow any' or 'deny any' cases.
31 * For positive 'nr_ports', a user_port lying in a range from 'port_min' to'
32 * 'port_min' + 'nr_ports' exclusively is considered to be a match. 'nr_ports'
33 * equalling to 1 forms a rule for a single port.
34 * Ports are in host order.
35 *
36 * Examples:
37 * AF_UNSPEC, 1, 0, 7777: match IPv4 and IPv6 addresses with 7777 user port;
38 *
39 * AF_INET, 1023, 0, 1: match IPv4 addresses with user port in [1, 1023]
40 * range inclusively;
41 *
42 * AF_INET6, 0, 0, 0: match IPv6 addresses;
43 *
44 * AF_UNSPEC, 0, 0, 0: match IPv4 and IPv6 addresses;
45 *
46 * AF_INET6, IPPROTO_TCP, 0, 0: match IPv6/TCP addresses.
47 */
48
49 struct socket_bind_rule {
50 __u32 address_family;
51 __u32 protocol;
52 __u16 nr_ports;
53 __u16 port_min;
54 };
55
56 #define SOCKET_BIND_MAX_RULES 128
57 #define SOCKET_BIND_RULE_AF_MATCH_NOTHING UINT32_MAX