Skip to content
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

socket set_mark addition. #96334

Merged
merged 4 commits into from
Aug 29, 2022
Merged

socket set_mark addition. #96334

merged 4 commits into from
Aug 29, 2022

Conversation

devnexen
Copy link
Contributor

to be able to set a marker/id on the socket for network filtering
(iptables/ipfw here) purpose.

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Apr 23, 2022
@rust-highfive
Copy link
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs to request review from a libs-api team reviewer. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive
Copy link
Collaborator

r? @thomcc

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 23, 2022
@thomcc
Copy link
Member

thomcc commented Apr 23, 2022

r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs

@rust-highfive rust-highfive assigned dtolnay and unassigned thomcc Apr 23, 2022
@rustbot rustbot added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 23, 2022
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems okay to me. Needs documentation and a tracking issue; I assume that's why the PR is still marked Draft.

@dtolnay dtolnay added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 27, 2022
@devnexen
Copy link
Contributor Author

Not only that but waited to see if the idea itself would get traction. ok will do these.

@devnexen devnexen marked this pull request as ready for review April 27, 2022 05:03
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@devnexen devnexen force-pushed the socket_mark branch 2 times, most recently from d9b1a9e to 57024fb Compare May 14, 2022 13:39
@JohnCSimon
Copy link
Member

ping from triage:
@devnexen
Can you post the status of this PR?

FYI: when a PR is ready for review, send a message containing
@rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

@devnexen
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 18, 2022
Comment on lines 886 to 887
/// Set the id of the socket for network filtering purpose
/// and is only a setter.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me what useful information "and is only a setter" is meant to convey here. Can this sentence be just the following?—

Set the id of the socket for network filtering purposes.

Comment on lines 893 to 895
/// fn main() -> std::io::Result<()> {
/// let sock = UnixDatagram::unbound()?;
/// sock.set_mark(32 as u32).expect("set_mark function failed");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's odd to see expect here in a function that returns io::Result anyway. How about returning the error?

Suggested change
/// fn main() -> std::io::Result<()> {
/// let sock = UnixDatagram::unbound()?;
/// sock.set_mark(32 as u32).expect("set_mark function failed");
/// fn main() -> std::io::Result<()> {
/// let sock = UnixDatagram::unbound()?;
/// sock.set_mark(32 as u32)?;

/// }
/// ```
#[cfg(any(doc, target_os = "linux", target_os = "freebsd", target_os = "openbsd",))]
#[unstable(feature = "unix_set_mark", issue = "none")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening the tracking issue. You need to put the issue number here inside the issue attribute. Check out the other unstable attributes in this file.

Same applies to the other new unstable attribute below.

///
/// fn main() -> std::io::Result<()> {
/// let sock = UnixStream::connect("/tmp/sock")?;
/// sock.set_mark(32 as u32).expect("set_mark function failed");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

32 as u32 is redundant. This can just be sock.set_mark(32) and the integer will be of type u32 automatically.

Comment on lines 446 to 439
#[cfg(target_os = "linux")]
pub fn set_mark(&self, mark: u32) -> io::Result<()> {
setsockopt(self, libc::SOL_SOCKET, libc::SO_MARK, mark as libc::c_int)
}

#[cfg(target_os = "freebsd")]
pub fn set_mark(&self, mark: u32) -> io::Result<()> {
setsockopt(self, libc::SOL_SOCKET, libc::SO_USER_COOKIE, mark)
}

#[cfg(target_os = "openbsd")]
pub fn set_mark(&self, mark: u32) -> io::Result<()> {
setsockopt(self, libc::SOL_SOCKET, libc::SO_RTABLE, mark as libc::c_int)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signature is identical across all of these platforms, and the implementation is nearly identical. How about deduplicating it this way?—

pub fn set_mark(&self, mark: u32) -> io::Result<()> {
    #[cfg(target_os = "linux")]
    let option = libc::SO_MARK;
    #[cfg(target_os = "linux")]
    let option = libc::SO_USER_COOKIE;
    #[cfg(target_os = "linux")]
    let option = libc::SO_RTABLE;
    setsockopt(self, libc::SOL_SOCKET, option, mark as libc::c_int)
}

or maybe this:

pub fn set_mark(&self, mark: u32) -> io::Result<()> {
    setsockopt(
        self,
        libc::SOL_SOCKET,
        #[cfg(target_os = "linux")]
        libc::SO_MARK,
        #[cfg(target_os = "freebsd")]
        libc::SO_USER_COOKIE,
        #[cfg(target_os = "openbsd")]
        libc::SO_RTABLE,
        mark as libc::c_int,
    )
}

@dtolnay dtolnay removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 6, 2022
@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 7, 2022
@devnexen devnexen requested a review from dtolnay July 7, 2022 14:02
@JohnCSimon
Copy link
Member

@devnexen devnexen requested a review from dtolnay last month

Triage:
@devnexen I'm assuming you meant for this to be ready for review

FYI: when a PR is ready for review, send a message containing
@rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 13, 2022
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dtolnay
Copy link
Member

dtolnay commented Aug 26, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Aug 26, 2022

📌 Commit f6efb0b has been approved by dtolnay

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 26, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Aug 28, 2022
socket `set_mark` addition.

to be able to set a marker/id on the socket for network filtering
 (iptables/ipfw here) purpose.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Aug 28, 2022
socket `set_mark` addition.

to be able to set a marker/id on the socket for network filtering
 (iptables/ipfw here) purpose.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 28, 2022
socket `set_mark` addition.

to be able to set a marker/id on the socket for network filtering
 (iptables/ipfw here) purpose.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 28, 2022
socket `set_mark` addition.

to be able to set a marker/id on the socket for network filtering
 (iptables/ipfw here) purpose.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 28, 2022
socket `set_mark` addition.

to be able to set a marker/id on the socket for network filtering
 (iptables/ipfw here) purpose.
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 29, 2022
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#94890 (Support parsing IP addresses from a byte string)
 - rust-lang#96334 (socket `set_mark` addition.)
 - rust-lang#99027 (Replace `Body::basic_blocks()` with field access)
 - rust-lang#100437 (Improve const mismatch `FulfillmentError`)
 - rust-lang#100843 (Migrate part of rustc_infer to session diagnostic)
 - rust-lang#100897 (extra sanity check against consts pointing to mutable memory)
 - rust-lang#100959 (translations: rename warn_ to warning)
 - rust-lang#101111 (Use the declaration's SourceInfo for FnEntry retags, not the outermost)
 - rust-lang#101116 ([rustdoc] Remove Attrs type alias)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a96b44c into rust-lang:master Aug 29, 2022
@rustbot rustbot added this to the 1.65.0 milestone Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants