4 /* Declaration of the ipc filter structure. It provides a framework to
5 * selectively allow/disallow ipc messages a process agrees to receive. To this
6 * end, a single ipc filter can be specified at a given time for any recipient
7 * to blacklist/whitelist a set of ipc messages identified by sender or message
10 #include <minix/ipc_filter.h>
12 /* IPC filter types. */
13 #define IPCF_NONE 0 /* no ipc filter */
14 #define IPCF_BLACKLIST 1 /* blacklist filter type */
15 #define IPCF_WHITELIST 2 /* whitelist filter type */
17 /* IPC filter element macros. */
19 #define IPCF_EL_CHECK(E) \
20 ((((E)->flags & IPCF_MATCH_M_TYPE) || \
21 ((E)->flags & IPCF_MATCH_M_SOURCE)) && \
22 (!((E)->flags & IPCF_MATCH_M_SOURCE) || \
23 IPCF_IS_ANY_EP((E)->m_source) || isokendpt((E)->m_source, &_ipcf_nr)))
24 #define IPCF_IS_USR_EP(EP) \
25 (!(priv(proc_addr(_ENDPOINT_P((EP))))->s_flags & SYS_PROC))
26 #define IPCF_IS_TSK_EP(EP) (iskerneln(_ENDPOINT_P((EP))))
27 #define IPCF_IS_SYS_EP(EP) (!IPCF_IS_USR_EP(EP) && !IPCF_IS_TSK_EP(EP))
28 #define IPCF_IS_ANY_EP(EP) \
29 ((EP) == ANY_USR || (EP) == ANY_SYS || (EP) == ANY_TSK)
30 #define IPCF_EL_MATCH_M_TYPE(E,M) \
31 (!((E)->flags & IPCF_MATCH_M_TYPE) || (E)->m_type == (M)->m_type)
32 #define IPCF_EL_MATCH_M_SOURCE(E,M) \
33 (!((E)->flags & IPCF_MATCH_M_SOURCE) || \
34 (E)->m_source == (M)->m_source || \
35 IPCF_EL_MATCH_M_SOURCE_ANY_EP((E)->m_source,(M)->m_source))
36 #define IPCF_EL_MATCH_M_SOURCE_ANY_EP(ES,MS) \
37 (((ES) == ANY_USR && IPCF_IS_USR_EP(MS)) || \
38 ((ES) == ANY_SYS && IPCF_IS_SYS_EP(MS)) || \
39 ((ES) == ANY_TSK && IPCF_IS_TSK_EP(MS)))
40 #define IPCF_EL_MATCH(E,M) \
41 (IPCF_EL_MATCH_M_TYPE(E,M) && IPCF_EL_MATCH_M_SOURCE(E,M))
47 struct ipc_filter_s
*next
;
48 ipc_filter_el_t elements
[IPCF_MAX_ELEMENTS
];
50 typedef struct ipc_filter_s ipc_filter_t
;
52 /* IPC filter pool. */
53 #define IPCF_POOL_SIZE (2*NR_SYS_PROCS)
54 EXTERN ipc_filter_t ipc_filter_pool
[IPCF_POOL_SIZE
];
56 /* IPC filter pool macros. */
57 #define IPCF_POOL_FREE_SLOT(S) ((S)->type = IPCF_NONE)
58 #define IPCF_POOL_IS_FREE_SLOT(S) ((S)->type == IPCF_NONE)
59 #define IPCF_POOL_ALLOCATE_SLOT(T,S) \
63 for (i = 0; i < IPCF_POOL_SIZE; i++) { \
64 if (IPCF_POOL_IS_FREE_SLOT(&ipc_filter_pool[i])) { \
65 *(S) = &ipc_filter_pool[i]; \
71 #define IPCF_POOL_INIT(S) memset(&ipc_filter_pool,0,sizeof(ipc_filter_pool))
73 #endif /* !IPC_FILTER_H */