18 #include <linux/types.h>
19 #include <linux/slab.h>
20 #include <linux/stddef.h>
21 #include <linux/kernel.h>
22 #include <linux/list.h>
24 #include <linux/netdevice.h>
32 #define SEL_NETIF_HASH_SIZE 64
33 #define SEL_NETIF_HASH_MAX 1024
41 static u32 sel_netif_total;
55 static inline u32 sel_netif_hashfn(
int ifindex)
69 static inline struct sel_netif *sel_netif_find(
int ifindex)
71 int idx = sel_netif_hashfn(ifindex);
74 list_for_each_entry_rcu(netif, &sel_netif_hash[idx],
list)
99 idx = sel_netif_hashfn(netif->nsec.ifindex);
100 list_add_rcu(&netif->list, &sel_netif_hash[idx]);
114 static void sel_netif_destroy(
struct sel_netif *netif)
116 list_del_rcu(&netif->
list);
133 static int sel_netif_sid_slow(
int ifindex,
u32 *
sid)
146 "SELinux: failure in sel_netif_sid_slow(),"
147 " invalid network interface (%d)\n", ifindex);
151 spin_lock_bh(&sel_netif_lock);
152 netif = sel_netif_find(ifindex);
154 *sid = netif->
nsec.sid;
167 ret = sel_netif_insert(
new);
170 *sid =
new->nsec.sid;
173 spin_unlock_bh(&sel_netif_lock);
177 "SELinux: failure in sel_netif_sid_slow(),"
178 " unable to determine network interface label (%d)\n",
203 netif = sel_netif_find(ifindex);
204 if (
likely(netif != NULL)) {
205 *sid = netif->
nsec.sid;
211 return sel_netif_sid_slow(ifindex, sid);
223 static void sel_netif_kill(
int ifindex)
228 spin_lock_bh(&sel_netif_lock);
229 netif = sel_netif_find(ifindex);
231 sel_netif_destroy(netif);
232 spin_unlock_bh(&sel_netif_lock);
243 static void sel_netif_flush(
void)
248 spin_lock_bh(&sel_netif_lock);
251 sel_netif_destroy(netif);
252 spin_unlock_bh(&sel_netif_lock);
255 static int sel_netif_avc_callback(
u32 event)
264 static int sel_netif_netdev_notifier_handler(
struct notifier_block *
this,
265 unsigned long event,
void *
ptr)
279 .notifier_call = sel_netif_netdev_notifier_handler,
282 static __init int sel_netif_init(
void)
290 INIT_LIST_HEAD(&sel_netif_hash[i]);
296 panic(
"avc_add_callback() failed, error %d\n", err);