Skip to content

Raw socket support #11410

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

Closed
wants to merge 64 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
8d1fa48
Add low level support for polling arbitary file descriptors with libuv.
mrmonday Jan 8, 2014
99eb9fd
Add support for passing options to libc::fcntl().
mrmonday Jan 8, 2014
a7c72a5
Add some constants to libc required for raw socket support.
mrmonday Jan 8, 2014
8cfb7e5
Add raw socket support using libuv.
mrmonday Jan 8, 2014
0545404
Add libstd support for raw sockets.
mrmonday Jan 8, 2014
167d52b
Add missing constants for FreeBSD and OS X.
mrmonday Jan 8, 2014
a20ab41
Rust now supports varargs.
mrmonday Jan 8, 2014
ec20461
Slight stylistic fix.
mrmonday Jan 8, 2014
2e37656
Add uncommitted use statements.
mrmonday Jan 9, 2014
8f733b2
Add native backend support for raw sockets.
mrmonday Jan 9, 2014
8afa391
Another stylistic fix.
mrmonday Jan 9, 2014
9cb39a8
Merge branch 'master' of github.com:mozilla/rust into raw-socket-support
mrmonday Jan 30, 2014
20de502
Build fixes for latest Rust.
mrmonday Jan 31, 2014
64b6ba4
Some refactoring of native raw socket code.
mrmonday Jan 31, 2014
80ed5e6
API and bug fixes for raw socket support.
mrmonday Feb 1, 2014
d9a24dd
Stop leaking c_int and ssize_t in the API.
mrmonday Feb 4, 2014
a618b47
Fixes for lints.
mrmonday Feb 5, 2014
8b7d03f
Merge branch 'master' of github.com:mozilla/rust into raw-socket-support
mrmonday Feb 5, 2014
65aa0be
Fix return types for RawSocket methods.
mrmonday Feb 10, 2014
155773f
Merge branch 'master' of github.com:mozilla/rust into raw-socket-support
mrmonday Feb 10, 2014
70abec4
Add missing import.
mrmonday Feb 10, 2014
4c25273
Add tests for raw sockets.
mrmonday Feb 10, 2014
c83db12
Merge branch 'master' of github.com:mozilla/rust into raw-socket-support
mrmonday Feb 16, 2014
75b9a2b
Fix merge fallout.
mrmonday Feb 16, 2014
726aa82
Beginnings of a new RawSocket interface with tests.
mrmonday Feb 17, 2014
bd9d046
Clean up packet building interfaces.
mrmonday Feb 18, 2014
fdaf0ba
Add test case for Ipv4Header.
mrmonday Feb 18, 2014
9712b53
More comprehensive testing for Ipv4Header.
mrmonday Feb 18, 2014
96094fd
Implement Ipv6Header and test.
mrmonday Feb 19, 2014
bda6811
Refactor IpNextHeaderProtocol to be u8 rather than an enum.
mrmonday Feb 19, 2014
c6b531b
getifaddrs() stuff for raw sockets. WIP.
mrmonday Feb 26, 2014
836472d
Merge branch 'master' of github.com:mozilla/rust into raw-socket-support
mrmonday Mar 5, 2014
a372303
Get raw sockets compiling with latest rust again.
mrmonday Mar 6, 2014
a12898e
Make network interface bits compile.
mrmonday Mar 7, 2014
ee039da
Merge branch 'master' of github.com:mozilla/rust into raw-socket-support
mrmonday Mar 7, 2014
c1f2827
Fix some issues from the pull request.
mrmonday Mar 8, 2014
c49903a
Support immutable packet types.
mrmonday Mar 8, 2014
7a69541
Merge branch 'master' of github.com:mozilla/rust into raw-socket-support
mrmonday Mar 8, 2014
045f11e
Working cooked layer 2 support for Linux x86_64.
mrmonday Mar 9, 2014
c9322bd
Working layer 2 socket support for Linux x86-64.
mrmonday Mar 10, 2014
3a55917
Begin work on factoring out common networking code.
mrmonday Mar 12, 2014
9a11446
Got it working again, horrah!
mrmonday Mar 14, 2014
5a9fe28
Some code cleanups.
mrmonday Mar 14, 2014
325a93c
Move libc error handling to netsupport.
mrmonday Mar 14, 2014
a2190cb
Fix a last_error() for Windows.
mrmonday Mar 14, 2014
4ef4929
Merge branch 'master' of github.com:mozilla/rust into raw-socket-support
mrmonday Mar 14, 2014
6b4ae7e
Fix merge fallout.
mrmonday Mar 15, 2014
04f2358
Fix line length lints.
mrmonday Mar 15, 2014
2266880
Chan::new() -> channel().
mrmonday Mar 15, 2014
e530cb6
More channel changes.
mrmonday Mar 15, 2014
433379d
Fix mistake in channel changes.
mrmonday Mar 15, 2014
0cb2407
Get raw sockets compiling on FreeBSD.
mrmonday Mar 15, 2014
3c36def
Remove stray tabs from FreeBSD.
mrmonday Mar 15, 2014
591ce9a
Add remaining missing contants for FreeBSD. Ignore tests which are no…
mrmonday Mar 15, 2014
f695fb0
Added missing constants and types for OS X.
mrmonday Mar 15, 2014
3fa904e
Get raw sockets compiling on Windows.
mrmonday Mar 17, 2014
7f6a82e
Merge branch 'master' of github.com:mozilla/rust into raw-socket-support
mrmonday Mar 17, 2014
5a3d241
Fix merge conflicts.
mrmonday Mar 17, 2014
129691d
Correct formatting for MacAddr.
mrmonday Mar 19, 2014
60eba93
Add test cases for ethernet and IP header structs.
mrmonday Mar 19, 2014
e22eb9c
Merge branch 'master' of github.com:mozilla/rust into raw-socket-support
mrmonday Mar 19, 2014
33e6123
Add some bounds checking.
mrmonday Mar 23, 2014
8d4e750
The length returned from sendto() should be uint to be consistent wit…
mrmonday Mar 23, 2014
154b2f4
Add documentation for io::net::raw.
mrmonday Mar 26, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#
# DEPS_<crate>
# These lists are the dependencies of the <crate> that is to be built.
# Rust dependencies are listed bare (i.e. std, green) and native
# Rust dependencies are listed bare (i.e. std, extra, green) and native
# dependencies have a "native:" prefix (i.e. native:sundown). All deps
# will be built before the crate itself is built.
#
Expand All @@ -51,15 +51,15 @@

TARGET_CRATES := std green rustuv native flate arena glob term semver \
uuid serialize sync getopts collections num test time rand \
workcache url log
workcache url log netsupport
HOST_CRATES := syntax rustc rustdoc fourcc hexfloat
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
TOOLS := compiletest rustdoc rustc

DEPS_std := native:rustrt native:compiler-rt native:backtrace
DEPS_green := std rand native:context_switch
DEPS_rustuv := std native:uv native:uv_support
DEPS_native := std
DEPS_rustuv := std native:uv native:uv_support netsupport
DEPS_native := std netsupport
DEPS_syntax := std term serialize collections log
DEPS_rustc := syntax native:rustllvm flate arena serialize sync getopts \
collections time log
Expand All @@ -84,6 +84,7 @@ DEPS_rand := std
DEPS_url := std collections
DEPS_workcache := std serialize collections log
DEPS_log := std sync
DEPS_netsupport := std

TOOL_DEPS_compiletest := test green rustuv getopts
TOOL_DEPS_rustdoc := rustdoc native
Expand Down
6 changes: 3 additions & 3 deletions src/libnative/io/addrinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate netsupport;

use ai = std::io::net::addrinfo;
use std::c_str::CString;
use std::cast;
Expand Down Expand Up @@ -96,10 +98,8 @@ extern "system" {

#[cfg(windows)]
fn get_error(_: c_int) -> IoError {
use super::translate_error;

unsafe {
translate_error(WSAGetLastError() as i32, true)
netsupport::translate_error(WSAGetLastError() as i32, true)
}
}

Expand Down
30 changes: 16 additions & 14 deletions src/libnative/io/file_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

//! Blocking posix-based file I/O

extern crate netsupport;

use std::sync::arc::UnsafeArc;
use std::c_str::CString;
use std::io::IoError;
Expand Down Expand Up @@ -62,7 +64,7 @@ impl FileDesc {
if ret == 0 {
Err(io::standard_error(io::EndOfFile))
} else if ret < 0 {
Err(super::last_error())
Err(netsupport::last_error())
} else {
Ok(ret as uint)
}
Expand All @@ -75,7 +77,7 @@ impl FileDesc {
}
});
if ret < 0 {
Err(super::last_error())
Err(netsupport::last_error())
} else {
Ok(())
}
Expand Down Expand Up @@ -113,7 +115,7 @@ impl rtio::RtioFileStream for FileDesc {
buf.len() as libc::size_t,
offset as libc::off_t) as libc::c_int
}) {
-1 => Err(super::last_error()),
-1 => Err(netsupport::last_error()),
n => Ok(n as int)
}
}
Expand All @@ -131,15 +133,15 @@ impl rtio::RtioFileStream for FileDesc {
};
let n = unsafe { libc::lseek(self.fd(), pos as libc::off_t, whence) };
if n < 0 {
Err(super::last_error())
Err(netsupport::last_error())
} else {
Ok(n as u64)
}
}
fn tell(&self) -> Result<u64, IoError> {
let n = unsafe { libc::lseek(self.fd(), 0, libc::SEEK_CUR) };
if n < 0 {
Err(super::last_error())
Err(netsupport::last_error())
} else {
Ok(n as u64)
}
Expand Down Expand Up @@ -249,7 +251,7 @@ impl rtio::RtioFileStream for CFile {
if ret == 0 {
Err(io::standard_error(io::EndOfFile))
} else if ret < 0 {
Err(super::last_error())
Err(netsupport::last_error())
} else {
Ok(ret as int)
}
Expand All @@ -263,7 +265,7 @@ impl rtio::RtioFileStream for CFile {
}
});
if ret < 0 {
Err(super::last_error())
Err(netsupport::last_error())
} else {
Ok(())
}
Expand All @@ -283,15 +285,15 @@ impl rtio::RtioFileStream for CFile {
};
let n = unsafe { libc::fseek(self.file, pos as libc::c_long, whence) };
if n < 0 {
Err(super::last_error())
Err(netsupport::last_error())
} else {
Ok(n as u64)
}
}
fn tell(&self) -> Result<u64, IoError> {
let ret = unsafe { libc::ftell(self.file) };
if ret < 0 {
Err(super::last_error())
Err(netsupport::last_error())
} else {
Ok(ret as u64)
}
Expand Down Expand Up @@ -330,7 +332,7 @@ pub fn open(path: &CString, fm: io::FileMode, fa: io::FileAccess)
};

match retry(|| unsafe { libc::open(path.with_ref(|p| p), flags, mode) }) {
-1 => Err(super::last_error()),
-1 => Err(netsupport::last_error()),
fd => Ok(FileDesc::new(fd, true)),
}
}
Expand Down Expand Up @@ -378,7 +380,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> {
assert_eq!(unsafe { closedir(dir_ptr) }, 0);
Ok(prune(p, paths))
} else {
Err(super::last_error())
Err(netsupport::last_error())
}
}

Expand Down Expand Up @@ -422,7 +424,7 @@ pub fn readlink(p: &CString) -> IoResult<Path> {
libc::readlink(p, buf.as_ptr() as *mut libc::c_char,
len as libc::size_t) as libc::c_int
}) {
-1 => Err(super::last_error()),
-1 => Err(netsupport::last_error()),
n => {
assert!(n > 0);
unsafe { buf.set_len(n as uint); }
Expand Down Expand Up @@ -495,15 +497,15 @@ pub fn stat(p: &CString) -> IoResult<io::FileStat> {
let mut stat: libc::stat = unsafe { mem::uninit() };
match retry(|| unsafe { libc::stat(p.with_ref(|p| p), &mut stat) }) {
0 => Ok(mkstat(&stat, p)),
_ => Err(super::last_error()),
_ => Err(netsupport::last_error()),
}
}

pub fn lstat(p: &CString) -> IoResult<io::FileStat> {
let mut stat: libc::stat = unsafe { mem::uninit() };
match retry(|| unsafe { libc::lstat(p.with_ref(|p| p), &mut stat) }) {
0 => Ok(mkstat(&stat, p)),
_ => Err(super::last_error()),
_ => Err(netsupport::last_error()),
}
}

Expand Down
26 changes: 14 additions & 12 deletions src/libnative/io/file_win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

//! Blocking win32-based file I/O

extern crate netsupport;

use std::c_str::CString;
use std::cast;
use std::io::IoError;
Expand Down Expand Up @@ -63,7 +65,7 @@ impl FileDesc {
if ret != 0 {
Ok(read as uint)
} else {
Err(super::last_error())
Err(netsupport::last_error())
}
}
pub fn inner_write(&mut self, buf: &[u8]) -> Result<(), IoError> {
Expand All @@ -80,7 +82,7 @@ impl FileDesc {
remaining -= amt as uint;
cur = unsafe { cur.offset(amt as int) };
} else {
return Err(super::last_error())
return Err(netsupport::last_error())
}
}
Ok(())
Expand Down Expand Up @@ -130,7 +132,7 @@ impl rtio::RtioFileStream for FileDesc {
if ret != 0 {
Ok(read as int)
} else {
Err(super::last_error())
Err(netsupport::last_error())
}
}
fn pwrite(&mut self, buf: &[u8], mut offset: u64) -> Result<(), IoError> {
Expand All @@ -151,7 +153,7 @@ impl rtio::RtioFileStream for FileDesc {
cur = unsafe { cur.offset(amt as int) };
offset += amt as u64;
} else {
return Err(super::last_error())
return Err(netsupport::last_error())
}
}
Ok(())
Expand All @@ -166,7 +168,7 @@ impl rtio::RtioFileStream for FileDesc {
let mut newpos = 0;
match libc::SetFilePointerEx(self.handle(), pos, &mut newpos,
whence) {
0 => Err(super::last_error()),
0 => Err(netsupport::last_error()),
_ => Ok(newpos as u64),
}
}
Expand All @@ -190,7 +192,7 @@ impl rtio::RtioFileStream for FileDesc {
let _ = try!(self.seek(offset, io::SeekSet));
let ret = unsafe {
match libc::SetEndOfFile(self.handle()) {
0 => Err(super::last_error()),
0 => Err(netsupport::last_error()),
_ => Ok(())
}
};
Expand Down Expand Up @@ -300,14 +302,14 @@ pub fn open(path: &CString, fm: io::FileMode, fa: io::FileAccess)
ptr::mut_null())
});
if handle == libc::INVALID_HANDLE_VALUE as libc::HANDLE {
Err(super::last_error())
Err(netsupport::last_error())
} else {
let fd = unsafe {
libc::open_osfhandle(handle as libc::intptr_t, flags)
};
if fd < 0 {
let _ = unsafe { libc::CloseHandle(handle) };
Err(super::last_error())
Err(netsupport::last_error())
} else {
Ok(FileDesc::new(fd, true))
}
Expand Down Expand Up @@ -367,7 +369,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> {
libc::free(wfd_ptr as *mut c_void);
Ok(prune(p, paths))
} else {
Err(super::last_error())
Err(netsupport::last_error())
}
})
}
Expand Down Expand Up @@ -421,7 +423,7 @@ pub fn readlink(p: &CString) -> IoResult<Path> {
})
};
if handle as int == libc::INVALID_HANDLE_VALUE as int {
return Err(super::last_error())
return Err(netsupport::last_error())
}
// Specify (sz - 1) because the documentation states that it's the size
// without the null pointer
Expand All @@ -434,7 +436,7 @@ pub fn readlink(p: &CString) -> IoResult<Path> {
let ret = match ret {
Some(ref s) if s.starts_with(r"\\?\") => Ok(Path::new(s.slice_from(4))),
Some(s) => Ok(Path::new(s)),
None => Err(super::last_error()),
None => Err(netsupport::last_error()),
};
assert!(unsafe { libc::CloseHandle(handle) } != 0);
return ret;
Expand Down Expand Up @@ -495,7 +497,7 @@ pub fn stat(p: &CString) -> IoResult<io::FileStat> {
as_utf16_p(p.as_str().unwrap(), |up| {
match unsafe { libc::wstat(up, &mut stat) } {
0 => Ok(mkstat(&stat, p)),
_ => Err(super::last_error()),
_ => Err(netsupport::last_error()),
}
})
}
Expand Down
Loading