From 5c8dd342182009cc1c2f55e2551daee99d7d44a8 Mon Sep 17 00:00:00 2001 From: Robert Watson Date: Wed, 30 Oct 2002 18:48:51 +0000 Subject: Move to C99 sparse structure initialization for the mac_policy_ops structure definition, rather than using an operation vector we translate into the structure. Originally, we used a vector for two reasons: (1) We wanted to define the structure sparsely, which wasn't supported by the C compiler for structures. For a policy with five entry points, you don't want to have to stick in a few hundred NULL function pointers. (2) We thought it would improve ABI compatibility allowing modules to work with kernels that had a superset of the entry points defined in the module, even if the kernel had changed its entry point set. Both of these no longer apply: (1) C99 gives us a way to sparsely define a static structure. (2) The ABI problems existed anyway, due to enumeration numbers, argument changes, and semantic mismatches. Since the going rule for FreeBSD is that you really need your modules to pretty closely match your kernel, it's not worth the complexity. This submit eliminates the operation vector, dynamic allocation of the operation structure, copying of the vector to the structure, and redoes the vectors in each policy to direct structure definitions. One enourmous benefit of this change is that we now get decent type checking on policy entry point implementation arguments. Obtained from: TrustedBSD Project Sponsored by: DARPA, Network Associates Laboratories --- sys/security/mac_ifoff/mac_ifoff.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'sys/security/mac_ifoff') diff --git a/sys/security/mac_ifoff/mac_ifoff.c b/sys/security/mac_ifoff/mac_ifoff.c index 8aea44a8f339..fb7e96612296 100644 --- a/sys/security/mac_ifoff/mac_ifoff.c +++ b/sys/security/mac_ifoff/mac_ifoff.c @@ -158,16 +158,12 @@ mac_ifoff_check_socket_deliver(struct socket *so, struct label *socketlabel, return (0); } -static struct mac_policy_op_entry mac_ifoff_ops[] = +static struct mac_policy_ops mac_ifoff_ops = { - { MAC_CHECK_BPFDESC_RECEIVE, - (macop_t)mac_ifoff_check_bpfdesc_receive }, - { MAC_CHECK_IFNET_TRANSMIT, - (macop_t)mac_ifoff_check_ifnet_transmit }, - { MAC_CHECK_SOCKET_DELIVER, - (macop_t)mac_ifoff_check_socket_deliver }, - { MAC_OP_LAST, NULL } + .mpo_check_bpfdesc_receive = mac_ifoff_check_bpfdesc_receive, + .mpo_check_ifnet_transmit = mac_ifoff_check_ifnet_transmit, + .mpo_check_socket_deliver = mac_ifoff_check_socket_deliver, }; -MAC_POLICY_SET(mac_ifoff_ops, trustedbsd_mac_ifoff, "TrustedBSD MAC/ifoff", +MAC_POLICY_SET(&mac_ifoff_ops, trustedbsd_mac_ifoff, "TrustedBSD MAC/ifoff", MPC_LOADTIME_FLAG_UNLOADOK, NULL); -- cgit v1.2.3