mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-26 04:25:27 +08:00
62476cc1bf
Can be used to query/modify socket state for unconnected UDP sendmsg. Those hooks run as BPF_CGROUP_RUN_SA_PROG_LOCK and operate on a locked socket. Signed-off-by: Stanislav Fomichev <sdf@google.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20210127232853.3753823-2-sdf@google.com
22 lines
457 B
C
22 lines
457 B
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#include <sys/socket.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
|
|
int get_set_sk_priority(void *ctx)
|
|
{
|
|
int prio;
|
|
|
|
/* Verify that context allows calling bpf_getsockopt and
|
|
* bpf_setsockopt by reading and writing back socket
|
|
* priority.
|
|
*/
|
|
|
|
if (bpf_getsockopt(ctx, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio)))
|
|
return 0;
|
|
if (bpf_setsockopt(ctx, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio)))
|
|
return 0;
|
|
|
|
return 1;
|
|
}
|