xfrm.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * SELinux support for the XFRM LSM hooks
  3. *
  4. * Author : Trent Jaeger, <jaegert@us.ibm.com>
  5. * Updated : Venkat Yekkirala, <vyekkirala@TrustedCS.com>
  6. */
  7. #ifndef _SELINUX_XFRM_H_
  8. #define _SELINUX_XFRM_H_
  9. int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
  10. struct xfrm_user_sec_ctx *sec_ctx);
  11. int selinux_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
  12. struct xfrm_sec_ctx **new_ctxp);
  13. void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx);
  14. int selinux_xfrm_policy_delete(struct xfrm_sec_ctx *ctx);
  15. int selinux_xfrm_state_alloc(struct xfrm_state *x,
  16. struct xfrm_user_sec_ctx *sec_ctx, u32 secid);
  17. void selinux_xfrm_state_free(struct xfrm_state *x);
  18. int selinux_xfrm_state_delete(struct xfrm_state *x);
  19. int selinux_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir);
  20. int selinux_xfrm_state_pol_flow_match(struct xfrm_state *x,
  21. struct xfrm_policy *xp, struct flowi *fl);
  22. /*
  23. * Extract the security blob from the sock (it's actually on the socket)
  24. */
  25. static inline struct inode_security_struct *get_sock_isec(struct sock *sk)
  26. {
  27. if (!sk->sk_socket)
  28. return NULL;
  29. return SOCK_INODE(sk->sk_socket)->i_security;
  30. }
  31. #ifdef CONFIG_SECURITY_NETWORK_XFRM
  32. extern atomic_t selinux_xfrm_refcount;
  33. static inline int selinux_xfrm_enabled(void)
  34. {
  35. return (atomic_read(&selinux_xfrm_refcount) > 0);
  36. }
  37. int selinux_xfrm_sock_rcv_skb(u32 sid, struct sk_buff *skb,
  38. struct avc_audit_data *ad);
  39. int selinux_xfrm_postroute_last(u32 isec_sid, struct sk_buff *skb,
  40. struct avc_audit_data *ad, u8 proto);
  41. int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
  42. static inline void selinux_xfrm_notify_policyload(void)
  43. {
  44. atomic_inc(&flow_cache_genid);
  45. }
  46. #else
  47. static inline int selinux_xfrm_enabled(void)
  48. {
  49. return 0;
  50. }
  51. static inline int selinux_xfrm_sock_rcv_skb(u32 isec_sid, struct sk_buff *skb,
  52. struct avc_audit_data *ad)
  53. {
  54. return 0;
  55. }
  56. static inline int selinux_xfrm_postroute_last(u32 isec_sid, struct sk_buff *skb,
  57. struct avc_audit_data *ad, u8 proto)
  58. {
  59. return 0;
  60. }
  61. static inline int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall)
  62. {
  63. *sid = SECSID_NULL;
  64. return 0;
  65. }
  66. static inline void selinux_xfrm_notify_policyload(void)
  67. {
  68. }
  69. #endif
  70. static inline void selinux_skb_xfrm_sid(struct sk_buff *skb, u32 *sid)
  71. {
  72. int err = selinux_xfrm_decode_session(skb, sid, 0);
  73. BUG_ON(err);
  74. }
  75. #endif /* _SELINUX_XFRM_H_ */