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

Add Loopback Socket #326

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Add Loopback Socket #326

wants to merge 2 commits into from

Conversation

qianxichen233
Copy link
Contributor

Description

This PR adds loopback socket (127.0.0.7) for rustposix

  • When server calls bind_syscall to a loopback address, its socket will be implicitly replaced to a domain socket
  • When client calls connect_syscall to a loopback address, its socket will be implicitly replaced to a domain socket

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Test A - ipc_tests.rs/ut_lind_ipc_loopback_socket

Checklist:

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been added to a pull request and/or merged in other modules (native-client, lind-glibc, lind-project)

@@ -445,7 +447,32 @@ impl Cage {
let res = match sockhandle.domain {
AF_UNIX => self.bind_inner_socket_unix(sockhandle, &mut newsockaddr),
AF_INET | AF_INET6 => {
self.bind_inner_socket_inet(sockhandle, &mut newsockaddr, prereserved)
let loopback_addr = u32::from_ne_bytes([127, 0, 0, 7]);
Copy link
Member

Choose a reason for hiding this comment

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

Why this address only?

self.bind_inner_socket_inet(sockhandle, &mut newsockaddr, prereserved)
let loopback_addr = u32::from_ne_bytes([127, 0, 0, 7]);
match newsockaddr.addr() {
interface::GenIpaddr::V4(addr) => {
Copy link
Member

Choose a reason for hiding this comment

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

V6 has loopback also

@@ -890,6 +917,7 @@ impl Cage {
//by other threads accessing other fields
let sock_tmp = sockfdobj.handle.clone();
let mut sockhandle = sock_tmp.write();

Copy link
Member

Choose a reason for hiding this comment

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

Extra space

let mut remoteaddr_final = remoteaddr.clone();

if remoteaddr.get_family() == AF_INET as u16 {
let loopback_addr = u32::from_ne_bytes([127, 0, 0, 7]);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't define this twice. Use a constant or similar in once place

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants