-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for TCP_CONGESTION socketopt #371
Conversation
Co-authored-by: Campbell He <kp.campbell.he@duskmoon314.com>
Currently have no idea why FreeBSD throws an error on the code Woking on this now. Any suggestion? |
syscall may modify len to true string length
I have fixed the error thrown by FreeBSD. This is because that FreeBSD will modify the len field to the exact string length while Linux not. Now this pr is ready for review. |
Code has been polished again, ready for another review! |
src/sys/unix.rs
Outdated
&mut len, | ||
)) | ||
.map(|_| { | ||
let buf = unsafe { payload.assume_init() }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is UB. Only &buf[0..len]
bytes are initialised by the kernel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not resolved. You can't call payload.assume_init
, it's not fully initialised. I think you can simply remove this line and we're good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok so now I use directly [u8; TCP_CA_NAME_MAX]
(initialized as [0; TCP_CA_NAME_MAX]
) instead of MaybeUninit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not what I asked for, but fine for now.
Allow me to explain the UB in the old code one more time. You create an array of size TCP_CA_NAME_MAX
, accessing any of those by would be UB. Then you call the kernel to fill the bytes, but it doesn't fill all of them just n
bytes (return by the system call). With the old code you called payload.assume_init()
, which requires the entire array all (TCP_CA_NAME_MAX
bytes) to be initialised, but that's not always the case as it's only up to n
bytes.
So the only change needed to the old code was to remove the payload.assume_init()
line. Because the next line creating a slice of only the initialised bytes and the line after that cast it to a slice of bytes (MaybeUninit<u8>
-> u8
).
Some modification:
|
- FreeBSD in CI only support newreno
I have a suggestion that can we use OsString instead as the crate Also, So any ideas on the two points? Or is there anything else I should implement? |
That's fine, let's just set
No, we're already using |
Get your point. Then I've implemented all requested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still has UB.
src/sys/unix.rs
Outdated
&mut len, | ||
)) | ||
.map(|_| { | ||
let buf = unsafe { payload.assume_init() }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not resolved. You can't call payload.assume_init
, it's not fully initialised. I think you can simply remove this line and we're good.
src/sys/unix.rs
Outdated
&mut len, | ||
)) | ||
.map(|_| { | ||
let buf = unsafe { payload.assume_init() }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not what I asked for, but fine for now.
Allow me to explain the UB in the old code one more time. You create an array of size TCP_CA_NAME_MAX
, accessing any of those by would be UB. Then you call the kernel to fill the bytes, but it doesn't fill all of them just n
bytes (return by the system call). With the old code you called payload.assume_init()
, which requires the entire array all (TCP_CA_NAME_MAX
bytes) to be initialised, but that's not always the case as it's only up to n
bytes.
So the only change needed to the old code was to remove the payload.assume_init()
line. Because the next line creating a slice of only the initialised bytes and the line after that cast it to a slice of bytes (MaybeUninit<u8>
-> u8
).
Thanks @BobAnkh |
tcp_congestion
uses raw syscall since diff os have diff policy on modifying lenset_tcp_congestion
uses raw syscall since exact str len must be passed inCloses: #370
Co-authored-by: Campbell He kp.campbell.he@duskmoon314.com