sol_upcall in FreeBSD 12

Dheeraj Kandula dkandula at gmail.com
Thu Aug 1 20:06:48 UTC 2019


When going through the code of FreeBSD12, I see that the socket code has
undergone significant change.

The socket is now either a regular socket or a listen socket.
The listen socket has two new fields besides others:

sol_upcall and sol_upcallarg

My understanding is that this callback will be used to notify the accept
socket's consumers when the 3 way handshake is completed and the socket is
ready to be accepted.

However in soisconnected function, when the accept filter is set, the code
still sets the receive socket buffer's upcall. Shouldn't we set the
sol_upcall in line 3773 below instead. If not, when should the sol_upcall
be set. An example will help clarify the usage.

3762
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3762>
again:
3763
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3763>
if
((so->so_options & SO_ACCEPTFILTER) == 0) {
3764
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3764>
TAILQ_REMOVE(&head->sol_incomp, so, so_list);
3765
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3765>
head->sol_incqlen--;
3766
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3766>
TAILQ_INSERT_TAIL(&head->sol_comp, so, so_list);
3767
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3767>
head->sol_qlen++;
3768
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3768>
so->so_qstate = SQ_COMP;
3769
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3769>
SOCK_UNLOCK(so);
3770
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3770>
solisten_wakeup(head); /* unlocks */
3771
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3771>
}
else {
3772
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3772>
SOCKBUF_LOCK(&so->so_rcv);
3773
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3773>
soupcall_set(so, SO_RCV,
3774
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3774>
head->sol_accept_filter->accf_callback,
3775
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3775>
head->sol_accept_filter_arg);
3776
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3776>
so->so_options &= ~SO_ACCEPTFILTER;
3777
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3777>
ret = head->sol_accept_filter->accf_callback(so,
3778
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3778>
head->sol_accept_filter_arg, M_NOWAIT);
3779
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3779>
if (ret == SU_ISCONNECTED) {
3780
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3780>
soupcall_clear(so, SO_RCV);
3781
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3781>
SOCKBUF_UNLOCK(&so->so_rcv);
3782
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3782>
goto again;
3783
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3783>
}
3784
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3784>
SOCKBUF_UNLOCK(&so->so_rcv);
3785
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3785>
SOCK_UNLOCK(so);
3786
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3786>
SOLISTEN_UNLOCK(head);
3787
<https://svnweb.freebsd.org/base/head/sys/kern/uipc_socket.c?revision=349989&view=markup#l3787>
}

Dheeraj


More information about the freebsd-net mailing list