Skip to content

Helper function bpf_setsockopt

v4.13

Definition

Copyright (c) 2015 The Libbpf Authors. All rights reserved.

Emulate a call to setsockopt() on the socket associated to bpf_socket, which must be a full socket. The level at which the option resides and the name optname of the option must be specified, see setsockopt(2) for more information. The option value of length optlen is pointed by optval.

bpf_socket should be one of the following:

  • struct bpf_sock_ops for BPF_PROG_TYPE_SOCK_OPS.
  • struct bpf_sock_addr for BPF_CGROUP_INET4_CONNECT, BPF_CGROUP_INET6_CONNECT and BPF_CGROUP_UNIX_CONNECT.

This helper actually implements a subset of setsockopt(). It supports the following _level_s:

  • SOL_SOCKET, which supports the following optname_s: SO_RCVBUF, SO_SNDBUF, SO_MAX_PACING_RATE, SO_PRIORITY, SO_RCVLOWAT, SO_MARK, SO_BINDTODEVICE, SO_KEEPALIVE, SO_REUSEADDR, SO_REUSEPORT, SO_BINDTOIFINDEX, SO_TXREHASH. * IPPROTO_TCP, which supports the following _optname_s: TCP_CONGESTION, TCP_BPF_IW, TCP_BPF_SNDCWND_CLAMP, TCP_SAVE_SYN, TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT, TCP_SYNCNT, TCP_USER_TIMEOUT, TCP_NOTSENT_LOWAT, TCP_NODELAY, TCP_MAXSEG, TCP_WINDOW_CLAMP, TCP_THIN_LINEAR_TIMEOUTS, TCP_BPF_DELACK_MAX, TCP_BPF_RTO_MIN. * IPPROTO_IP, which supports _optname IP_TOS.
  • IPPROTO_IPV6, which supports the following _optname_s: IPV6_TCLASS, IPV6_AUTOFLOWLABEL.

Returns

0 on success, or a negative error in case of failure.

static long (* const bpf_setsockopt)(void *bpf_socket, int level, int optname, void *optval, int optlen) = (void *) 49;

Usage

Docs could be improved

This part of the docs is incomplete, contributions are very welcome

Program types

This helper call can be used in the following program types:

Example

Docs could be improved

This part of the docs is incomplete, contributions are very welcome