Skip to content

bgp: Add composable wrappers for {get,set}sockopt - #900

Open
taspelund wants to merge 1 commit into
mainfrom
jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr
Open

taspelund wants to merge 1 commit into
mainfrom
jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr

Conversation

@taspelund

Copy link
Copy Markdown
Contributor

Instead of jamming unsafe calls to libc::{get,set}sockopt, centralize it to just one wrapper for each method and use option-specific wrappers.

Also fix incorrect sockopt name for IPv6 TTL: IP_MINTTL -> IPV6_MINHOPCOUNT

Fixes: #647

Signed-off-by: Trey Aspelund trey@oxidecomputer.com

@taspelund

taspelund commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor Author

@taspelund
taspelund force-pushed the jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr branch from 543da50 to 9d83e29 Compare September 2, 2026 19:20
@taspelund
taspelund force-pushed the jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr branch 2 times, most recently from 0bf3422 to 109cc76 Compare September 2, 2026 20:40
@taspelund taspelund self-assigned this Sep 2, 2026
@taspelund taspelund added bgp Border Gateway Protocol mgd Maghemite daemon rust Pull requests that update rust code labels Sep 2, 2026
@taspelund
taspelund force-pushed the jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr branch 2 times, most recently from d1ff6f0 to 1abfb30 Compare September 4, 2026 21:27
@taspelund
taspelund force-pushed the jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr branch from 1abfb30 to b431f3f Compare September 22, 2026 22:57
@taspelund
taspelund force-pushed the jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr branch from b431f3f to 519832a Compare September 23, 2026 17:07
Comment thread bgp/src/connection_tcp.rs Outdated
}

#[cfg(any(target_os = "linux", target_os = "illumos"))]
fn get_sockopt(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this be

get_sockopt<T>(...) -> Result<T, Error> { ... }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Initially I had thought so too, but getsockopt(2) always returns int so there's no need for generics. I made set_sockopt generic so that plain Rust refs can be passed in without forcing the caller to cast it to a c_void pointer ahead of time

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think thats right for illumos getsockopt(3socket), perhaps on linux. For example, IPV6_NEXTHOP and IPV6_PATHMTU return structs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, yeah ok. I was looking at the C return type and overlooked the void pointer passed in for the kernel to write to

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've pushed a change (it's force-pushed, sorry... the diff is here) that addresses this, adds some safety comments, and adds in the round-trip socket option tests that I'd started playing with for a different branch a while back.

Assuming the ipv4-mapped sockopts work in whatever helios version CI runs, the tests should all pass and we'll have actual regression coverage.

@taspelund
taspelund force-pushed the jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr branch from 519832a to 030c409 Compare September 30, 2026 23:08
@taspelund
taspelund force-pushed the jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr branch from 030c409 to 3735cc0 Compare October 13, 2026 21:59
@taspelund
taspelund force-pushed the jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr branch from 3735cc0 to 60264fc Compare October 20, 2026 16:53
@taspelund
taspelund removed this pull request from stack #902 October 20, 2026 19:37
@taspelund
taspelund force-pushed the jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr branch from 60264fc to 9678231 Compare October 20, 2026 19:37
@taspelund
taspelund changed the base branch from jj-stack/falcon-lab-add-focused-bgp-md5-regression-lvopsxpz to jj-stack/bgp-fix-length-truncation-for-enhe-capability-and-capabilities-parameter-qoplztqq October 20, 2026 19:37
@taspelund
taspelund added this pull request to stack #951 October 20, 2026 19:37
@taspelund
taspelund removed this pull request from stack #951 October 20, 2026 19:43
@taspelund
taspelund added this pull request to stack #952 October 20, 2026 19:43
@taspelund
taspelund force-pushed the jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr branch from 9678231 to fd1f122 Compare October 20, 2026 19:43
@taspelund
taspelund removed this pull request from stack #952 October 20, 2026 23:09
@taspelund
taspelund changed the base branch from jj-stack/bgp-fix-length-truncation-for-enhe-capability-and-capabilities-parameter-qoplztqq to jj-stack/bgp-split-message-history-into-all-major-buffers-urwxzymv October 20, 2026 23:09
@taspelund
taspelund force-pushed the jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr branch from fd1f122 to 04b1453 Compare October 20, 2026 23:09
@taspelund
taspelund added this pull request to stack #954 October 20, 2026 23:09
@taspelund
taspelund removed this pull request from stack #954 October 21, 2026 06:45
@taspelund
taspelund changed the base branch from jj-stack/bgp-split-message-history-into-all-major-buffers-urwxzymv to jj-stack/workspace-remove-unused-dependencies-rsvyqtum October 21, 2026 06:46
@taspelund
taspelund force-pushed the jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr branch from 04b1453 to bbea8da Compare October 21, 2026 06:46
@taspelund
taspelund added this pull request to stack #956 October 21, 2026 06:46
@taspelund
taspelund force-pushed the jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr branch from bbea8da to b621dc0 Compare October 21, 2026 17:04
@taspelund
taspelund force-pushed the jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr branch from b621dc0 to aabfeed Compare October 21, 2026 23:22
Base automatically changed from jj-stack/workspace-remove-unused-dependencies-rsvyqtum to main October 22, 2026 17:46
@taspelund
taspelund force-pushed the jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr branch from aabfeed to db96ca8 Compare October 22, 2026 17:46
@taspelund
taspelund force-pushed the jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr branch 3 times, most recently from cabb066 to 21947ea Compare November 6, 2026 20:59
Instead of jamming unsafe calls to libc::{get,set}sockopt, centralize it
to just one wrapper for each method and use option-specific wrappers.

Also fix incorrect sockopt name for IPv6 TTL:
IP_MINTTL -> IPV6_MINHOPCOUNT

Fixes: #647

Signed-off-by: Trey Aspelund <trey@oxidecomputer.com>
@taspelund
taspelund force-pushed the jj-stack/bgp-add-composable-wrappers-for-get-set-sockopt-xqyysnkr branch from 21947ea to 99e826f Compare November 9, 2026 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bgp Border Gateway Protocol mgd Maghemite daemon rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TTL settings are broken for IPv6 peers

2 participants