All of lore.kernel.org
 help / color / mirror / Atom feed
* scope id field in bpf_sock_addr
@ 2022-06-20 16:11 Matteo Croce
  2022-06-21  1:20 ` Martin KaFai Lau
  0 siblings, 1 reply; 5+ messages in thread
From: Matteo Croce @ 2022-06-20 16:11 UTC (permalink / raw)
  To: Andrey Ignatov, bpf

Hi,

I wonder why struct bpf_sock_addr doesn't contain the sin6_scope_id as
in struct sockaddr_in6.
A program with type like BPF_PROG_TYPE_CGROUP_SOCK_ADDR might want to
access that field.

Regards,
-- 
per aspera ad upstream

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

* Re: scope id field in bpf_sock_addr
  2022-06-20 16:11 scope id field in bpf_sock_addr Matteo Croce
@ 2022-06-21  1:20 ` Martin KaFai Lau
  2022-06-21  2:05   ` Dave Thaler
  0 siblings, 1 reply; 5+ messages in thread
From: Martin KaFai Lau @ 2022-06-21  1:20 UTC (permalink / raw)
  To: Matteo Croce; +Cc: Andrey Ignatov, bpf

On Mon, Jun 20, 2022 at 06:11:11PM +0200, Matteo Croce wrote:
> Hi,
> 
> I wonder why struct bpf_sock_addr doesn't contain the sin6_scope_id as
> in struct sockaddr_in6.
> A program with type like BPF_PROG_TYPE_CGROUP_SOCK_ADDR might want to
> access that field.
I think usually there was no use case?
Do you need to read from it or write to it?
You can try to extend it.  Take a look at sock_addr_is_valid_access()
and sock_addr_convert_ctx_access().

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

* RE: scope id field in bpf_sock_addr
  2022-06-21  1:20 ` Martin KaFai Lau
@ 2022-06-21  2:05   ` Dave Thaler
  2022-06-22 20:07     ` Martin KaFai Lau
  0 siblings, 1 reply; 5+ messages in thread
From: Dave Thaler @ 2022-06-21  2:05 UTC (permalink / raw)
  To: Martin KaFai Lau, Matteo Croce; +Cc: Andrey Ignatov, bpf

Martin KaFai Lau <kafai@fb.com> writes: 
>> I wonder why struct bpf_sock_addr doesn't contain the sin6_scope_id as 
>> in struct sockaddr_in6.
>> A program with type like BPF_PROG_TYPE_CGROUP_SOCK_ADDR might want to 
>> access that field.
>
>
> I think usually there was no use case?
> Do you need to read from it or write to it?
> You can try to extend it.  Take a look at sock_addr_is_valid_access() and sock_addr_convert_ctx_access().

For me: read it.  If you're trying to, say, track the set of all connections, you can't do it simply from
the IP+port pairs, since IPv6 scoped addresses are ambiguous so you can have 2 or more connections
with the same IP+port pair, so I need either the scope id, or an interface (device) identifier, to disambiguate
and know which connection is which.

If Linux has an API to get to it, we'd ty to do the same in the ebpf-for-windows project as well,
but right now I don't know the answer.

Dave


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

* Re: scope id field in bpf_sock_addr
  2022-06-21  2:05   ` Dave Thaler
@ 2022-06-22 20:07     ` Martin KaFai Lau
  2022-06-22 21:28       ` Dave Thaler
  0 siblings, 1 reply; 5+ messages in thread
From: Martin KaFai Lau @ 2022-06-22 20:07 UTC (permalink / raw)
  To: Dave Thaler; +Cc: Matteo Croce, bpf

On Tue, Jun 21, 2022 at 02:05:47AM +0000, Dave Thaler wrote:
> Martin KaFai Lau <kafai@fb.com> writes: 
> >> I wonder why struct bpf_sock_addr doesn't contain the sin6_scope_id as 
> >> in struct sockaddr_in6.
> >> A program with type like BPF_PROG_TYPE_CGROUP_SOCK_ADDR might want to 
> >> access that field.
> >
> >
> > I think usually there was no use case?
> > Do you need to read from it or write to it?
> > You can try to extend it.  Take a look at sock_addr_is_valid_access() and sock_addr_convert_ctx_access().
> 
> For me: read it.  If you're trying to, say, track the set of all connections, you can't do it simply from
> the IP+port pairs, since IPv6 scoped addresses are ambiguous so you can have 2 or more connections
> with the same IP+port pair, so I need either the scope id, or an interface (device) identifier, to disambiguate
> and know which connection is which.
> 
> If Linux has an API to get to it, we'd ty to do the same in the ebpf-for-windows project as well,
> but right now I don't know the answer.
For read only into any syscall like functions, it is usually done with
bpf-tracing in Linux which can read the scope id and other args.

afaik, the cgroup sock_addr hook is more for changing the sockaddr
rather than only reading it.  If the sock_addr prog is to be extended
for sin6_scope_id, it should be changeable also.

[ Remove outdated email from cc list ]

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

* RE: scope id field in bpf_sock_addr
  2022-06-22 20:07     ` Martin KaFai Lau
@ 2022-06-22 21:28       ` Dave Thaler
  0 siblings, 0 replies; 5+ messages in thread
From: Dave Thaler @ 2022-06-22 21:28 UTC (permalink / raw)
  To: Martin KaFai Lau; +Cc: Matteo Croce, bpf

Martin KaFai Lau <kafai@fb.com> writes:
[...]
> > > Do you need to read from it or write to it?
> > > You can try to extend it.  Take a look at sock_addr_is_valid_access() and
> sock_addr_convert_ctx_access().
> >
> > For me: read it.  If you're trying to, say, track the set of all
> > connections, you can't do it simply from the IP+port pairs, since IPv6
> > scoped addresses are ambiguous so you can have 2 or more connections
> > with the same IP+port pair, so I need either the scope id, or an interface
> (device) identifier, to disambiguate and know which connection is which.
> >
> > If Linux has an API to get to it, we'd ty to do the same in the
> > ebpf-for-windows project as well, but right now I don't know the answer.
> For read only into any syscall like functions, it is usually done with bpf-tracing
> in Linux which can read the scope id and other args.
> 
> afaik, the cgroup sock_addr hook is more for changing the sockaddr rather
> than only reading it.  If the sock_addr prog is to be extended for
> sin6_scope_id, it should be changeable also.

Sure.   But I'm getting the impression that it's a current bug/limitation
since I haven't heard a way to get (or change) it...

Dave

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

end of thread, other threads:[~2022-06-22 21:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-20 16:11 scope id field in bpf_sock_addr Matteo Croce
2022-06-21  1:20 ` Martin KaFai Lau
2022-06-21  2:05   ` Dave Thaler
2022-06-22 20:07     ` Martin KaFai Lau
2022-06-22 21:28       ` Dave Thaler

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.