1 #ifndef IPC_FILTER_H 2 #define IPC_FILTER_H 3 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 8 * type. 9 */ 10 #include <minix/ipc_filter.h> 11 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 */ 16 17 /* IPC filter element macros. */ 18 EXTERN int _ipcf_nr; 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)) 42 43 struct ipc_filter_s { 44 int type; 45 int num_elements; 46 int flags; 47 struct ipc_filter_s *next; 48 ipc_filter_el_t elements[IPCF_MAX_ELEMENTS]; 49 }; 50 typedef struct ipc_filter_s ipc_filter_t; 51 52 /* IPC filter pool. */ 53 #define IPCF_POOL_SIZE (2*NR_SYS_PROCS) 54 EXTERN ipc_filter_t ipc_filter_pool[IPCF_POOL_SIZE]; 55 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) \ 60 do { \ 61 int i; \ 62 *(S) = NULL; \ 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]; \ 66 (*(S))->type = T; \ 67 break; \ 68 } \ 69 } \ 70 } while(0) 71 #define IPCF_POOL_INIT(S) memset(&ipc_filter_pool,0,sizeof(ipc_filter_pool)) 72 73 #endif /* !IPC_FILTER_H */ 74