Skip to content

Commit 59f067d

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 1e2c7dc commit 59f067d

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) => {
@@ -931,6 +919,19 @@ pub unsafe extern "C" fn krun_add_net_tap(
931919
KRUN_SUCCESS
932920
}
933921

922+
#[allow(clippy::missing_safety_doc)]
923+
#[no_mangle]
924+
#[cfg(all(not(target_os = "linux"), feature = "net"))]
925+
pub unsafe extern "C" fn krun_add_net_tap(
926+
_ctx_id: u32,
927+
_c_tap_name: *const c_char,
928+
_c_mac: *const u8,
929+
_features: u32,
930+
_flags: u32,
931+
) -> i32 {
932+
-libc::EINVAL
933+
}
934+
934935
#[allow(clippy::missing_safety_doc)]
935936
#[no_mangle]
936937
#[cfg(feature = "net")]
@@ -939,10 +940,6 @@ pub unsafe extern "C" fn krun_set_passt_fd(ctx_id: u32, fd: c_int) -> i32 {
939940
return -libc::EINVAL;
940941
}
941942

942-
if cfg!(not(feature = "net")) {
943-
return -libc::ENOTSUP;
944-
}
945-
946943
match CTX_MAP.lock().unwrap().entry(ctx_id) {
947944
Entry::Occupied(mut ctx_cfg) => {
948945
let cfg = ctx_cfg.get_mut();
@@ -967,10 +964,6 @@ pub unsafe extern "C" fn krun_set_passt_fd(ctx_id: u32, fd: c_int) -> i32 {
967964
#[no_mangle]
968965
#[cfg(feature = "net")]
969966
pub unsafe extern "C" fn krun_set_gvproxy_path(ctx_id: u32, c_path: *const c_char) -> i32 {
970-
if cfg!(not(feature = "net")) {
971-
return -libc::ENOTSUP;
972-
}
973-
974967
let path_str = match CStr::from_ptr(c_path).to_str() {
975968
Ok(path) => path,
976969
Err(e) => {

0 commit comments

Comments
 (0)