Skip to content

Commit 4a4e83a

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 d03806e commit 4a4e83a

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
@@ -813,10 +813,6 @@ pub unsafe extern "C" fn krun_add_net_unixstream(
813813
features: u32,
814814
flags: u32,
815815
) -> i32 {
816-
if cfg!(not(feature = "net")) {
817-
return -libc::ENOTSUP;
818-
}
819-
820816
let path = if !c_path.is_null() {
821817
match CStr::from_ptr(c_path).to_str() {
822818
Ok(path) => Some(PathBuf::from(path)),
@@ -873,10 +869,6 @@ pub unsafe extern "C" fn krun_add_net_unixgram(
873869
features: u32,
874870
flags: u32,
875871
) -> i32 {
876-
if cfg!(not(feature = "net")) {
877-
return -libc::ENOTSUP;
878-
}
879-
880872
let path = if !c_path.is_null() {
881873
match CStr::from_ptr(c_path).to_str() {
882874
Ok(path) => Some(PathBuf::from(path)),
@@ -933,10 +925,6 @@ pub unsafe extern "C" fn krun_add_net_tap(
933925
features: u32,
934926
flags: u32,
935927
) -> i32 {
936-
if cfg!(not(feature = "net")) {
937-
return -libc::ENOTSUP;
938-
}
939-
940928
let tap_name = match CStr::from_ptr(c_tap_name).to_str() {
941929
Ok(tap_name) => tap_name.to_string(),
942930
Err(e) => {
@@ -976,6 +964,19 @@ pub unsafe extern "C" fn krun_add_net_tap(
976964
KRUN_SUCCESS
977965
}
978966

967+
#[allow(clippy::missing_safety_doc)]
968+
#[no_mangle]
969+
#[cfg(all(not(target_os = "linux"), feature = "net"))]
970+
pub unsafe extern "C" fn krun_add_net_tap(
971+
_ctx_id: u32,
972+
_c_tap_name: *const c_char,
973+
_c_mac: *const u8,
974+
_features: u32,
975+
_flags: u32,
976+
) -> i32 {
977+
-libc::EINVAL
978+
}
979+
979980
#[allow(clippy::missing_safety_doc)]
980981
#[no_mangle]
981982
#[cfg(feature = "net")]
@@ -984,10 +985,6 @@ pub unsafe extern "C" fn krun_set_passt_fd(ctx_id: u32, fd: c_int) -> i32 {
984985
return -libc::EINVAL;
985986
}
986987

987-
if cfg!(not(feature = "net")) {
988-
return -libc::ENOTSUP;
989-
}
990-
991988
match CTX_MAP.lock().unwrap().entry(ctx_id) {
992989
Entry::Occupied(mut ctx_cfg) => {
993990
let cfg = ctx_cfg.get_mut();
@@ -1012,10 +1009,6 @@ pub unsafe extern "C" fn krun_set_passt_fd(ctx_id: u32, fd: c_int) -> i32 {
10121009
#[no_mangle]
10131010
#[cfg(feature = "net")]
10141011
pub unsafe extern "C" fn krun_set_gvproxy_path(ctx_id: u32, c_path: *const c_char) -> i32 {
1015-
if cfg!(not(feature = "net")) {
1016-
return -libc::ENOTSUP;
1017-
}
1018-
10191012
let path_str = match CStr::from_ptr(c_path).to_str() {
10201013
Ok(path) => path,
10211014
Err(e) => {

0 commit comments

Comments
 (0)