History

bpf: Bpf_{g,s}etsockopt for struct bpf_sock_addr

Currently, bpf_getsockopt and bpf_setsockopt helpers operate on the 'struct bpf_sock_ops' context in BPF_PROG_TYPE_SOCK_OPS program. Let's generalize them and make them available for 'struct bpf_sock_addr'. That way, in the future, we can allow those helpers in more places. As an example, let's expose those 'struct bpf_sock_addr' based helpers to BPF_CGROUP_INET{4,6}_CONNECT hooks. That way we can override CC before the connection is made. v3: * Expose custom helpers for bpf_sock_addr context instead of doing generic bpf_sock argument (as suggested by Daniel). Even with try_socket_lock that doesn't sleep we have a problem where context sk is already locked and socket lock is non-nestable. v2: * s/BPF_PROG_TYPE_CGROUP_SOCKOPT/BPF_PROG_TYPE_SOCK_OPS/

Stanislav Fomichev committed 6 years ago

Commit beecf111 parent 3dbb5b55 files · +166 −27Browse files

Showing the changes to include/uapi/linux (1 of 5 files). Show all

Unified · Split

include/uapi/linux/bpf.h+12−2
@@ -1587,7 +1587,7 @@ union bpf_attr { · 1586 unmodified lines
1587 * Return1587 * Return
1588 * 01588 * 0
1589 *1589 *
1590 * int bpf_setsockopt(struct bpf_sock_ops *bpf_socket, int level, int optname, void *optval, int optlen)1590 * int bpf_setsockopt(void *bpf_socket, int level, int optname, void *optval, int optlen)
1591 * Description1591 * Description
1592 * Emulate a call to **setsockopt()** on the socket associated to1592 * Emulate a call to **setsockopt()** on the socket associated to
1593 * *bpf_socket*, which must be a full socket. The *level* at1593 * *bpf_socket*, which must be a full socket. The *level* at
@@ -1595,6 +1595,11 @@ union bpf_attr { · 1 unmodified line
1595 * must be specified, see **setsockopt(2)** for more information.1595 * must be specified, see **setsockopt(2)** for more information.
1596 * The option value of length *optlen* is pointed by *optval*.1596 * The option value of length *optlen* is pointed by *optval*.
1597 *1597 *
1598 * *bpf_socket* should be one of the following:
1599 * * **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.
1600 * * **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**
1601 * and **BPF_CGROUP_INET6_CONNECT**.
1602 *
1598 * This helper actually implements a subset of **setsockopt()**.1603 * This helper actually implements a subset of **setsockopt()**.
1599 * It supports the following *level*\ s:1604 * It supports the following *level*\ s:
1600 *1605 *
@@ -1789,7 +1794,7 @@ union bpf_attr { · 188 unmodified lines
1789 * Return1794 * Return
1790 * 0 on success, or a negative error in case of failure.1795 * 0 on success, or a negative error in case of failure.
1791 *1796 *
1792 * int bpf_getsockopt(struct bpf_sock_ops *bpf_socket, int level, int optname, void *optval, int optlen)1797 * int bpf_getsockopt(void *bpf_socket, int level, int optname, void *optval, int optlen)
1793 * Description1798 * Description
1794 * Emulate a call to **getsockopt()** on the socket associated to1799 * Emulate a call to **getsockopt()** on the socket associated to
1795 * *bpf_socket*, which must be a full socket. The *level* at1800 * *bpf_socket*, which must be a full socket. The *level* at
@@ -1798,6 +1803,11 @@ union bpf_attr { · 2 unmodified lines
1798 * The retrieved value is stored in the structure pointed by1803 * The retrieved value is stored in the structure pointed by
1799 * *opval* and of length *optlen*.1804 * *opval* and of length *optlen*.
1800 *1805 *
1806 * *bpf_socket* should be one of the following:
1807 * * **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.
1808 * * **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**
1809 * and **BPF_CGROUP_INET6_CONNECT**.
1810 *
1801 * This helper actually implements a subset of **getsockopt()**.1811 * This helper actually implements a subset of **getsockopt()**.
1802 * It supports the following *level*\ s:1812 * It supports the following *level*\ s:
1803 *1813 *