On 25/06/20(Thu) 19:56, Vitaliy Makkoveev wrote:
> Updated diff.
>
> OpenBSD uses 16 bit counter for allocate interface indexes. So we can't
> store index in session and be sure if_get(9) returned `ifnet' is our
> original `ifnet'.
Why not? The point of if_get(9) is to be sure. If that doesn't work
for whatever reason then the if_get(9) interface has to be fixed. Which
case doesn't work for you? Do you have a reproducer?
How does sessions stay around if their corresponding interface is
destroyed?
> Now each pipex(4) session has it's own reference to `ifnet'. Also pppoe
> related sessions has the reference to it's ethernet interface.
>
> All `ifnet's are obtained by if_get(9) and we use `if_index' from stored
> reference to `ifnet'.
That's not how the API is meant to be used. All if_get(9) must have a
corresponding if_put(9) in the same context. We don't store pointers
put interface indexes, meaning:
> Index: net/pipex.c
> ===================================================================
> RCS file: /cvs/src/sys/net/pipex.c,v
> retrieving revision 1.116
> diff -u -p -r1.116 pipex.c
> --- net/pipex.c 22 Jun 2020 09:38:15 -0000 1.116
> +++ net/pipex.c 25 Jun 2020 16:41:25 -0000
> @@ -148,7 +148,7 @@ pipex_iface_init(struct pipex_iface_cont
> struct pipex_session *session;
>
> pipex_iface->pipexmode = 0;
> - pipex_iface->ifnet_this = ifp;
> + pipex_iface->ifnet_this = if_get(ifp->if_index);
`ifnet_this' should be replaced by `ifidx' so this becomes:
pipex_iface->ifidx = ifp->if_index.