1*2cc1ae48SMichael Weiß /* SPDX-License-Identifier: GPL-2.0 */
2*2cc1ae48SMichael Weiß /*
3*2cc1ae48SMichael Weiß * Creating audit records for mapped devices.
4*2cc1ae48SMichael Weiß *
5*2cc1ae48SMichael Weiß * Copyright (C) 2021 Fraunhofer AISEC. All rights reserved.
6*2cc1ae48SMichael Weiß *
7*2cc1ae48SMichael Weiß * Authors: Michael Weiß <michael.weiss@aisec.fraunhofer.de>
8*2cc1ae48SMichael Weiß */
9*2cc1ae48SMichael Weiß
10*2cc1ae48SMichael Weiß #ifndef DM_AUDIT_H
11*2cc1ae48SMichael Weiß #define DM_AUDIT_H
12*2cc1ae48SMichael Weiß
13*2cc1ae48SMichael Weiß #include <linux/device-mapper.h>
14*2cc1ae48SMichael Weiß #include <linux/audit.h>
15*2cc1ae48SMichael Weiß
16*2cc1ae48SMichael Weiß #ifdef CONFIG_DM_AUDIT
17*2cc1ae48SMichael Weiß void dm_audit_log_bio(const char *dm_msg_prefix, const char *op,
18*2cc1ae48SMichael Weiß struct bio *bio, sector_t sector, int result);
19*2cc1ae48SMichael Weiß
20*2cc1ae48SMichael Weiß /*
21*2cc1ae48SMichael Weiß * dm_audit_log_ti() is not intended to be used directly in dm modules,
22*2cc1ae48SMichael Weiß * the wrapper functions below should be called by dm modules instead.
23*2cc1ae48SMichael Weiß */
24*2cc1ae48SMichael Weiß void dm_audit_log_ti(int audit_type, const char *dm_msg_prefix, const char *op,
25*2cc1ae48SMichael Weiß struct dm_target *ti, int result);
26*2cc1ae48SMichael Weiß
dm_audit_log_ctr(const char * dm_msg_prefix,struct dm_target * ti,int result)27*2cc1ae48SMichael Weiß static inline void dm_audit_log_ctr(const char *dm_msg_prefix,
28*2cc1ae48SMichael Weiß struct dm_target *ti, int result)
29*2cc1ae48SMichael Weiß {
30*2cc1ae48SMichael Weiß dm_audit_log_ti(AUDIT_DM_CTRL, dm_msg_prefix, "ctr", ti, result);
31*2cc1ae48SMichael Weiß }
32*2cc1ae48SMichael Weiß
dm_audit_log_dtr(const char * dm_msg_prefix,struct dm_target * ti,int result)33*2cc1ae48SMichael Weiß static inline void dm_audit_log_dtr(const char *dm_msg_prefix,
34*2cc1ae48SMichael Weiß struct dm_target *ti, int result)
35*2cc1ae48SMichael Weiß {
36*2cc1ae48SMichael Weiß dm_audit_log_ti(AUDIT_DM_CTRL, dm_msg_prefix, "dtr", ti, result);
37*2cc1ae48SMichael Weiß }
38*2cc1ae48SMichael Weiß
dm_audit_log_target(const char * dm_msg_prefix,const char * op,struct dm_target * ti,int result)39*2cc1ae48SMichael Weiß static inline void dm_audit_log_target(const char *dm_msg_prefix, const char *op,
40*2cc1ae48SMichael Weiß struct dm_target *ti, int result)
41*2cc1ae48SMichael Weiß {
42*2cc1ae48SMichael Weiß dm_audit_log_ti(AUDIT_DM_EVENT, dm_msg_prefix, op, ti, result);
43*2cc1ae48SMichael Weiß }
44*2cc1ae48SMichael Weiß #else
dm_audit_log_bio(const char * dm_msg_prefix,const char * op,struct bio * bio,sector_t sector,int result)45*2cc1ae48SMichael Weiß static inline void dm_audit_log_bio(const char *dm_msg_prefix, const char *op,
46*2cc1ae48SMichael Weiß struct bio *bio, sector_t sector,
47*2cc1ae48SMichael Weiß int result)
48*2cc1ae48SMichael Weiß {
49*2cc1ae48SMichael Weiß }
dm_audit_log_target(const char * dm_msg_prefix,const char * op,struct dm_target * ti,int result)50*2cc1ae48SMichael Weiß static inline void dm_audit_log_target(const char *dm_msg_prefix,
51*2cc1ae48SMichael Weiß const char *op, struct dm_target *ti,
52*2cc1ae48SMichael Weiß int result)
53*2cc1ae48SMichael Weiß {
54*2cc1ae48SMichael Weiß }
dm_audit_log_ctr(const char * dm_msg_prefix,struct dm_target * ti,int result)55*2cc1ae48SMichael Weiß static inline void dm_audit_log_ctr(const char *dm_msg_prefix,
56*2cc1ae48SMichael Weiß struct dm_target *ti, int result)
57*2cc1ae48SMichael Weiß {
58*2cc1ae48SMichael Weiß }
59*2cc1ae48SMichael Weiß
dm_audit_log_dtr(const char * dm_msg_prefix,struct dm_target * ti,int result)60*2cc1ae48SMichael Weiß static inline void dm_audit_log_dtr(const char *dm_msg_prefix,
61*2cc1ae48SMichael Weiß struct dm_target *ti, int result)
62*2cc1ae48SMichael Weiß {
63*2cc1ae48SMichael Weiß }
64*2cc1ae48SMichael Weiß #endif
65*2cc1ae48SMichael Weiß
66*2cc1ae48SMichael Weiß #endif
67