2 * Netlink event notifications for SELinux.
4 * Author: James Morris <jmorris@redhat.com>
6 * Copyright (C) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2,
10 * as published by the Free Software Foundation.
12 #include <linux/init.h>
13 #include <linux/types.h>
14 #include <linux/stddef.h>
15 #include <linux/kernel.h>
16 #include <linux/list.h>
17 #include <linux/skbuff.h>
18 #include <linux/netlink.h>
19 #include <linux/selinux_netlink.h>
21 static struct sock
*selnl
;
23 static int selnl_msglen(int msgtype
)
28 case SELNL_MSG_SETENFORCE
:
29 ret
= sizeof(struct selnl_msg_setenforce
);
32 case SELNL_MSG_POLICYLOAD
:
33 ret
= sizeof(struct selnl_msg_policyload
);
42 static void selnl_add_payload(struct nlmsghdr
*nlh
, int len
, int msgtype
, void *data
)
45 case SELNL_MSG_SETENFORCE
: {
46 struct selnl_msg_setenforce
*msg
= NLMSG_DATA(nlh
);
49 msg
->val
= *((int *)data
);
53 case SELNL_MSG_POLICYLOAD
: {
54 struct selnl_msg_policyload
*msg
= NLMSG_DATA(nlh
);
57 msg
->seqno
= *((u32
*)data
);
66 static void selnl_notify(int msgtype
, void *data
)
73 len
= selnl_msglen(msgtype
);
75 skb
= alloc_skb(NLMSG_SPACE(len
), GFP_USER
);
80 nlh
= NLMSG_PUT(skb
, 0, 0, msgtype
, len
);
81 selnl_add_payload(nlh
, len
, msgtype
, data
);
82 nlh
->nlmsg_len
= skb
->tail
- tmp
;
83 netlink_broadcast(selnl
, skb
, 0, SELNL_GRP_AVC
, GFP_USER
);
90 printk(KERN_ERR
"SELinux: OOM in %s\n", __FUNCTION__
);
94 void selnl_notify_setenforce(int val
)
96 selnl_notify(SELNL_MSG_SETENFORCE
, &val
);
99 void selnl_notify_policyload(u32 seqno
)
101 selnl_notify(SELNL_MSG_POLICYLOAD
, &seqno
);
104 static int __init
selnl_init(void)
106 selnl
= netlink_kernel_create(NETLINK_SELINUX
, NULL
);
108 panic("SELinux: Cannot create netlink socket.");
109 netlink_set_nonroot(NETLINK_SELINUX
, NL_NONROOT_RECV
);
113 __initcall(selnl_init
);