blob: 1450f85b946da462e5ef3576a50d979d15574b8f [file] [log] [blame]
Trent Jaegerd28d1e02005-12-13 23:12:40 -08001/*
2 * SELinux support for the XFRM LSM hooks
3 *
4 * Author : Trent Jaeger, <jaegert@us.ibm.com>
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07005 * Updated : Venkat Yekkirala, <vyekkirala@TrustedCS.com>
Trent Jaegerd28d1e02005-12-13 23:12:40 -08006 */
7#ifndef _SELINUX_XFRM_H_
8#define _SELINUX_XFRM_H_
9
David Howells778aae82012-03-26 16:38:47 +010010#include <net/flow.h>
11
Paul Moore03e1ad72008-04-12 19:07:52 -070012int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
Nikolay Aleksandrov52a4c642014-03-07 12:44:19 +010013 struct xfrm_user_sec_ctx *uctx,
14 gfp_t gfp);
Paul Moore03e1ad72008-04-12 19:07:52 -070015int selinux_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
16 struct xfrm_sec_ctx **new_ctxp);
17void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx);
18int selinux_xfrm_policy_delete(struct xfrm_sec_ctx *ctx);
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070019int selinux_xfrm_state_alloc(struct xfrm_state *x,
Paul Moore2e5aa862013-07-23 17:38:38 -040020 struct xfrm_user_sec_ctx *uctx);
21int selinux_xfrm_state_alloc_acquire(struct xfrm_state *x,
22 struct xfrm_sec_ctx *polsec, u32 secid);
Trent Jaegerd28d1e02005-12-13 23:12:40 -080023void selinux_xfrm_state_free(struct xfrm_state *x);
Catherine Zhangc8c05a82006-06-08 23:39:49 -070024int selinux_xfrm_state_delete(struct xfrm_state *x);
Paul Moore03e1ad72008-04-12 19:07:52 -070025int selinux_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir);
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070026int selinux_xfrm_state_pol_flow_match(struct xfrm_state *x,
Paul Moored1b17b02013-07-23 17:38:40 -040027 struct xfrm_policy *xp,
28 const struct flowi *fl);
Trent Jaegerd28d1e02005-12-13 23:12:40 -080029
Trent Jaegerd28d1e02005-12-13 23:12:40 -080030#ifdef CONFIG_SECURITY_NETWORK_XFRM
Paul Moored621d352008-01-29 08:43:36 -050031extern atomic_t selinux_xfrm_refcount;
32
33static inline int selinux_xfrm_enabled(void)
34{
35 return (atomic_read(&selinux_xfrm_refcount) > 0);
36}
37
Paul Mooreeef9b412013-07-23 17:38:39 -040038int selinux_xfrm_sock_rcv_skb(u32 sk_sid, struct sk_buff *skb,
39 struct common_audit_data *ad);
40int selinux_xfrm_postroute_last(u32 sk_sid, struct sk_buff *skb,
41 struct common_audit_data *ad, u8 proto);
Venkat Yekkiralaa51c64f2006-07-27 22:01:34 -070042int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
Paul Moore817eff72013-12-10 14:57:54 -050043int selinux_xfrm_skb_sid(struct sk_buff *skb, u32 *sid);
Venkat Yekkirala342a0cf2007-01-26 19:03:48 -080044
45static inline void selinux_xfrm_notify_policyload(void)
46{
fan.duca4c3fc2013-07-30 08:33:53 +080047 struct net *net;
48
fan.duca4c3fc2013-07-30 08:33:53 +080049 rtnl_lock();
Fan Duca925cf2014-01-18 09:55:27 +080050 for_each_net(net) {
51 atomic_inc(&net->xfrm.flow_cache_genid);
fan.duca4c3fc2013-07-30 08:33:53 +080052 rt_genid_bump_all(net);
Fan Duca925cf2014-01-18 09:55:27 +080053 }
fan.duca4c3fc2013-07-30 08:33:53 +080054 rtnl_unlock();
Venkat Yekkirala342a0cf2007-01-26 19:03:48 -080055}
Trent Jaegerd28d1e02005-12-13 23:12:40 -080056#else
Paul Moored621d352008-01-29 08:43:36 -050057static inline int selinux_xfrm_enabled(void)
58{
59 return 0;
60}
61
Paul Mooreeef9b412013-07-23 17:38:39 -040062static inline int selinux_xfrm_sock_rcv_skb(u32 sk_sid, struct sk_buff *skb,
63 struct common_audit_data *ad)
Trent Jaegerd28d1e02005-12-13 23:12:40 -080064{
65 return 0;
66}
67
Paul Mooreeef9b412013-07-23 17:38:39 -040068static inline int selinux_xfrm_postroute_last(u32 sk_sid, struct sk_buff *skb,
69 struct common_audit_data *ad,
70 u8 proto)
Trent Jaegerd28d1e02005-12-13 23:12:40 -080071{
James Morris4e5ab4c2006-06-09 00:33:33 -070072 return 0;
Trent Jaegerd28d1e02005-12-13 23:12:40 -080073}
Catherine Zhange6f50712006-03-20 22:49:00 -080074
Paul Moored1b17b02013-07-23 17:38:40 -040075static inline int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid,
76 int ckall)
Venkat Yekkiralaa51c64f2006-07-27 22:01:34 -070077{
78 *sid = SECSID_NULL;
79 return 0;
80}
Venkat Yekkirala342a0cf2007-01-26 19:03:48 -080081
82static inline void selinux_xfrm_notify_policyload(void)
83{
84}
Trent Jaegerd28d1e02005-12-13 23:12:40 -080085
Paul Moore817eff72013-12-10 14:57:54 -050086static inline int selinux_xfrm_skb_sid(struct sk_buff *skb, u32 *sid)
Venkat Yekkirala6b877692006-11-08 17:04:09 -060087{
Paul Moore817eff72013-12-10 14:57:54 -050088 *sid = SECSID_NULL;
89 return 0;
Venkat Yekkirala6b877692006-11-08 17:04:09 -060090}
Paul Moore817eff72013-12-10 14:57:54 -050091#endif
Venkat Yekkirala6b877692006-11-08 17:04:09 -060092
Trent Jaegerd28d1e02005-12-13 23:12:40 -080093#endif /* _SELINUX_XFRM_H_ */