Skip to content

Commit 0a09706

Browse files
committed
libkrun: remove redundant "net" checks
We had cfg! checks for net on methods that are only present if net is enabled, so let's remove them. Suggested-by: Matej Hrica <[email protected]> Signed-off-by: Sergio Lopez <[email protected]>
1 parent c5e8897 commit 0a09706

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

src/libkrun/src/lib.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -768,10 +768,6 @@ pub unsafe extern "C" fn krun_add_net_unixstream(
768768
features: u32,
769769
flags: u32,
770770
) -> i32 {
771-
if cfg!(not(feature = "net")) {
772-
return -libc::ENOTSUP;
773-
}
774-
775771
let path = if !c_path.is_null() {
776772
match CStr::from_ptr(c_path).to_str() {
777773
Ok(path) => Some(PathBuf::from(path)),
@@ -828,10 +824,6 @@ pub unsafe extern "C" fn krun_add_net_unixgram(
828824
features: u32,
829825
flags: u32,
830826
) -> i32 {
831-
if cfg!(not(feature = "net")) {
832-
return -libc::ENOTSUP;
833-
}
834-
835827
let path = if !c_path.is_null() {
836828
match CStr::from_ptr(c_path).to_str() {
837829
Ok(path) => Some(PathBuf::from(path)),
@@ -888,10 +880,6 @@ pub unsafe extern "C" fn krun_add_net_tap(
888880
features: u32,
889881
flags: u32,
890882
) -> i32 {
891-
if cfg!(not(feature = "net")) {
892-
return -libc::ENOTSUP;
893-
}
894-
895883
let tap_name = match CStr::from_ptr(c_tap_name).to_str() {
896884
Ok(tap_name) => tap_name.to_string(),
897885
Err(e) => {
@@ -935,6 +923,19 @@ pub unsafe extern "C" fn krun_add_net_tap(
935923
KRUN_SUCCESS
936924
}
937925

926+
#[allow(clippy::missing_safety_doc)]
927+
#[no_mangle]
928+
#[cfg(all(not(target_os = "linux"), feature = "net"))]
929+
pub unsafe extern "C" fn krun_add_net_tap(
930+
_ctx_id: u32,
931+
_c_tap_name: *const c_char,
932+
_c_mac: *const u8,
933+
_features: u32,
934+
_flags: u32,
935+
) -> i32 {
936+
-libc::EINVAL
937+
}
938+
938939
#[allow(clippy::missing_safety_doc)]
939940
#[no_mangle]
940941
#[cfg(feature = "net")]
@@ -943,10 +944,6 @@ pub unsafe extern "C" fn krun_set_passt_fd(ctx_id: u32, fd: c_int) -> i32 {
943944
return -libc::EINVAL;
944945
}
945946

946-
if cfg!(not(feature = "net")) {
947-
return -libc::ENOTSUP;
948-
}
949-
950947
match CTX_MAP.lock().unwrap().entry(ctx_id) {
951948
Entry::Occupied(mut ctx_cfg) => {
952949
let cfg = ctx_cfg.get_mut();
@@ -971,10 +968,6 @@ pub unsafe extern "C" fn krun_set_passt_fd(ctx_id: u32, fd: c_int) -> i32 {
971968
#[no_mangle]
972969
#[cfg(feature = "net")]
973970
pub unsafe extern "C" fn krun_set_gvproxy_path(ctx_id: u32, c_path: *const c_char) -> i32 {
974-
if cfg!(not(feature = "net")) {
975-
return -libc::ENOTSUP;
976-
}
977-
978971
let path_str = match CStr::from_ptr(c_path).to_str() {
979972
Ok(path) => path,
980973
Err(e) => {

0 commit comments

Comments
 (0)