@@ -158,11 +158,24 @@ pub enum LandlockStatus {
158158 NotEnabled ,
159159 /// Landlock is not implemented (i.e. not built into the running kernel: `ENOSYS`).
160160 NotImplemented ,
161- /// Landlock is available and supported up to the given ABI .
161+ /// Landlock is available and working on the running system .
162162 ///
163- /// `Option<i32>` contains the raw ABI value if it's greater than the greatest known ABI,
164- /// which would mean that the running kernel is newer than the Landlock crate.
165- Available ( ABI , Option < i32 > ) ,
163+ /// This indicates that the kernel supports Landlock and it's properly enabled.
164+ /// The crate uses the `effective_abi` for all operations, which represents
165+ /// the highest ABI version that both the kernel and this crate understand.
166+ Available {
167+ /// The effective ABI version that this crate will use for Landlock operations.
168+ /// This is the intersection of what the kernel supports and what this crate knows about.
169+ effective_abi : ABI ,
170+ /// The actual kernel ABI version when it's newer than any ABI supported by this crate.
171+ ///
172+ /// If `Some(version)`, it means the running kernel supports Landlock ABI `version`
173+ /// which is higher than the latest ABI known by this crate.
174+ ///
175+ /// This field is purely informational and is never used for Landlock operations.
176+ /// The crate always and only uses `effective_abi` for all functionality.
177+ kernel_abi : Option < i32 > ,
178+ } ,
166179}
167180
168181impl LandlockStatus {
@@ -188,7 +201,10 @@ impl LandlockStatus {
188201 }
189202 } else {
190203 let abi = ABI :: from ( v) ;
191- Self :: Available ( abi, ( v != abi as i32 ) . then_some ( v) )
204+ Self :: Available {
205+ effective_abi : abi,
206+ kernel_abi : ( v != abi as i32 ) . then_some ( v) ,
207+ }
192208 }
193209 }
194210}
@@ -200,10 +216,18 @@ fn test_current_landlock_status() {
200216 if * TEST_ABI == ABI :: Unsupported {
201217 assert_eq ! ( status, LandlockStatus :: NotImplemented ) ;
202218 } else {
203- assert ! ( matches!( status, LandlockStatus :: Available ( abi, _) if abi == * TEST_ABI ) ) ;
219+ assert ! (
220+ matches!( status, LandlockStatus :: Available { effective_abi, .. } if effective_abi == * TEST_ABI )
221+ ) ;
204222 if std:: env:: var ( TEST_ABI_ENV_NAME ) . is_ok ( ) {
205223 // We cannot reliably check for unknown kernel.
206- assert ! ( matches!( status, LandlockStatus :: Available ( _, None ) ) ) ;
224+ assert ! ( matches!(
225+ status,
226+ LandlockStatus :: Available {
227+ kernel_abi: None ,
228+ ..
229+ }
230+ ) ) ;
207231 }
208232 }
209233}
@@ -214,7 +238,7 @@ impl From<LandlockStatus> for ABI {
214238 // The only possible error values should be EOPNOTSUPP and ENOSYS,
215239 // but let's convert all kind of errors as unsupported.
216240 LandlockStatus :: NotEnabled | LandlockStatus :: NotImplemented => ABI :: Unsupported ,
217- LandlockStatus :: Available ( abi , _ ) => abi ,
241+ LandlockStatus :: Available { effective_abi , .. } => effective_abi ,
218242 }
219243 }
220244}
@@ -227,7 +251,10 @@ impl From<ABI> for LandlockStatus {
227251 match abi {
228252 // Convert to ENOSYS because of check_ruleset_support() and ruleset_unsupported() tests.
229253 ABI :: Unsupported => Self :: NotImplemented ,
230- _ => Self :: Available ( abi, None ) ,
254+ _ => Self :: Available {
255+ effective_abi : abi,
256+ kernel_abi : None ,
257+ } ,
231258 }
232259 }
233260}
@@ -278,7 +305,7 @@ pub(crate) fn get_errno_from_landlock_status() -> Option<i32> {
278305 }
279306 }
280307 }
281- LandlockStatus :: Available ( _ , _ ) => None ,
308+ LandlockStatus :: Available { .. } => None ,
282309 }
283310}
284311
0 commit comments