Page MenuHomeFreeBSD

pcb: Move an assignment into in_pcbdisconnect()
ClosedPublic

Authored by markj on Feb 2 2023, 10:42 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Mar 21, 1:16 AM
Unknown Object (File)
Fri, Mar 20, 10:03 PM
Unknown Object (File)
Sun, Mar 8, 1:27 PM
Unknown Object (File)
Sun, Mar 8, 1:27 PM
Unknown Object (File)
Sat, Mar 7, 7:51 PM
Unknown Object (File)
Feb 8 2026, 3:02 AM
Unknown Object (File)
Feb 7 2026, 5:06 PM
Unknown Object (File)
Jan 31 2026, 4:19 AM
Subscribers

Details

Summary

All callers of in_pcbdisconnect() clear the local address, so let's just
do that in the function itself. No functional change intended.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj requested review of this revision.Feb 2 2023, 10:42 PM
This revision was not accepted when it landed; it landed in state Needs Review.Feb 3 2023, 4:52 PM
This revision was automatically updated to reflect the committed changes.

I'd like to revert this revision. I think the logic of clearing local address at the protocol level makes sense. It is feature of UDP, not of any protocol, that local address is cleared on disconnect. As you noted this code can be tracked down to pre-FreeBSD times.

For example, for TCP we want a disconnected socket to return previously used local address with getsockname(). The TCP has successfully evaded that by not calling in_pcbdisconnect() and calling in_pcbdetach() in the very old code and in_pcbdrop() in the newer code. In my current branch I have TCP started to use in_pcbdisconnect(), however it still evades clearing of local address for a different reason.

The other thing I'm about to do in branch is to make raw IP to make more use of the generic inpcb code. Yep, decided to give up with trees and follow your advice. So, raw IP starts to use in_pcbdisconnect(). For raw IP it is more than getsockname()! A raw socket may be bound with bind(2) and then connect(2)ed, and then disconnected, e.g. connect(INADDR_ANY). So, when we run raw IP socket through in_pcbdisconnect() we don't want to lose local address.

I'd like to revert this revision. I think the logic of clearing local address at the protocol level makes sense. It is feature of UDP, not of any protocol, that local address is cleared on disconnect. As you noted this code can be tracked down to pre-FreeBSD times.

For example, for TCP we want a disconnected socket to return previously used local address with getsockname(). The TCP has successfully evaded that by not calling in_pcbdisconnect() and calling in_pcbdetach() in the very old code and in_pcbdrop() in the newer code. In my current branch I have TCP started to use in_pcbdisconnect(), however it still evades clearing of local address for a different reason.

The other thing I'm about to do in branch is to make raw IP to make more use of the generic inpcb code. Yep, decided to give up with trees and follow your advice. So, raw IP starts to use in_pcbdisconnect(). For raw IP it is more than getsockname()! A raw socket may be bound with bind(2) and then connect(2)ed, and then disconnected, e.g. connect(INADDR_ANY). So, when we run raw IP socket through in_pcbdisconnect() we don't want to lose local address.

Makes sense to me!

Er, chaps, there is RFC 9622 to digest, the end of the BSD sockets API as we know it perhaps.

But that RFC needs a healthy dose of "Cui Bono?" to it. Some suggested it was just a Google land grab.

The thing that should be at the back of all our heads is: Cloudflare saw fit to bypass traditional inpcb semantics as well.

I'd like to revert this revision. I think the logic of clearing local address at the protocol level makes sense. It is feature of UDP, not of any protocol, that local address is cleared on disconnect. As you noted this code can be tracked down to pre-FreeBSD times.

For example, for TCP we want a disconnected socket to return previously used local address with getsockname(). The TCP has successfully evaded that by not calling in_pcbdisconnect() and calling in_pcbdetach() in the very old code and in_pcbdrop() in the newer code. In my current branch I have TCP started to use in_pcbdisconnect(), however it still evades clearing of local address for a different reason.

The other thing I'm about to do in branch is to make raw IP to make more use of the generic inpcb code. Yep, decided to give up with trees and follow your advice. So, raw IP starts to use in_pcbdisconnect(). For raw IP it is more than getsockname()! A raw socket may be bound with bind(2) and then connect(2)ed, and then disconnected, e.g. connect(INADDR_ANY). So, when we run raw IP socket through in_pcbdisconnect() we don't want to lose local address.

That sounds reasonable, no objection from me.