BPF List
 help / color / mirror / Atom feed
* sock_ops: calling bpf_sock_ops_cb_flags_set() for already established sockets
@ 2023-12-01 17:01 Alan Maguire
  2023-12-01 17:51 ` Martin KaFai Lau
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Maguire @ 2023-12-01 17:01 UTC (permalink / raw)
  To: bpf

hi folks

I've run into a few cases where users have wanted to enable additional
tcp-bpf sock_ops events for a socket _after_ connection establishment.
The problem is that to set the flags to enable additional events, we
have to be in the context of a sock_ops program, and as I understand it,
by default only events early in the socket lifetime are enabled by
default (such as connection established/accepted). As a consequence, if
we do not catch one of those early events, the sock_ops program will not
run and we miss the opportunity to enable more sock_ops events. This can
be a problem for boot-time connections like iSCSI where we are too late
to catch connection establishment.

I can see a few possibilities:

- support setting sock_ops event flags via a socket iterator. This would
mean that the user can always set per-socket flags on
already-established sockets by iterating over existing sockets,
selecting those of interest.
- supporting setting event flags via setsockopt(). In fact we wouldn't
need to fully support setting event flags via "real" setsockopt(); we
could simply use a cgroup/setsockopt program and allow
bpf_sock_ops_cb_flags_set() to run in the cgroup/setsockopt context
(with additional checks to ensure it is indeed a tcp socket).

Do either/both of these seem reasonable, or is there a better way to
tackle this? Thanks!

Alan

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: sock_ops: calling bpf_sock_ops_cb_flags_set() for already established sockets
  2023-12-01 17:01 sock_ops: calling bpf_sock_ops_cb_flags_set() for already established sockets Alan Maguire
@ 2023-12-01 17:51 ` Martin KaFai Lau
  0 siblings, 0 replies; 2+ messages in thread
From: Martin KaFai Lau @ 2023-12-01 17:51 UTC (permalink / raw)
  To: Alan Maguire; +Cc: bpf

On 12/1/23 9:01 AM, Alan Maguire wrote:
> hi folks
> 
> I've run into a few cases where users have wanted to enable additional
> tcp-bpf sock_ops events for a socket _after_ connection establishment.
> The problem is that to set the flags to enable additional events, we
> have to be in the context of a sock_ops program, and as I understand it,
> by default only events early in the socket lifetime are enabled by
> default (such as connection established/accepted). As a consequence, if
> we do not catch one of those early events, the sock_ops program will not
> run and we miss the opportunity to enable more sock_ops events. This can
> be a problem for boot-time connections like iSCSI where we are too late
> to catch connection establishment.
> 
> I can see a few possibilities:
> 
> - support setting sock_ops event flags via a socket iterator. This would
> mean that the user can always set per-socket flags on
> already-established sockets by iterating over existing sockets,
> selecting those of interest.
> - supporting setting event flags via setsockopt(). In fact we wouldn't
> need to fully support setting event flags via "real" setsockopt(); we
> could simply use a cgroup/setsockopt program and allow
> bpf_sock_ops_cb_flags_set() to run in the cgroup/setsockopt context
> (with additional checks to ensure it is indeed a tcp socket).
> 
> Do either/both of these seem reasonable, or is there a better way to
> tackle this? Thanks!

The lock_sock() is held in both cases (iterator / cgroup-setsockopt), so should 
be ok. I guess it depends on the usecase. If it does not have a hold on the 
socket fd, socket iterator may be the only way.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-12-01 17:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-01 17:01 sock_ops: calling bpf_sock_ops_cb_flags_set() for already established sockets Alan Maguire
2023-12-01 17:51 ` Martin KaFai Lau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox