Home | History | Annotate | Download | only in sys
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License (the "License").
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  * or http://www.opensolaris.org/os/licensing.
     10  * See the License for the specific language governing permissions
     11  * and limitations under the License.
     12  *
     13  * When distributing Covered Code, include this CDDL HEADER in each
     14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  * If applicable, add the following below this CDDL HEADER, with the
     16  * fields enclosed by brackets "[]" replaced with your own identifying
     17  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  *
     19  * CDDL HEADER END
     20  */
     21 /*
     22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
     23  * Use is subject to license terms.
     24  */
     25 
     26 #ifndef _SYS_ACCTCTL_H
     27 #define	_SYS_ACCTCTL_H
     28 
     29 #include <sys/types.h>
     30 #include <sys/bitmap.h>
     31 #include <sys/sysmacros.h>
     32 
     33 #ifdef	__cplusplus
     34 extern "C" {
     35 #endif
     36 
     37 /*
     38  * Definitions for acctctl() system call
     39  */
     40 
     41 /*
     42  * modes
     43  */
     44 #define	AC_PROC		(0x1 << 24)	/* change process accounting settings */
     45 #define	AC_TASK		(0x2 << 24)	/* change task accounting settings */
     46 #define	AC_FLOW		(0x4 << 24)	/* change flow accounting settings */
     47 #define	AC_NET		(0x8 << 24)	/* change network accounting settings */
     48 #define	AC_MODE(x)	((x) & 0xff000000)
     49 
     50 /*
     51  * options
     52  */
     53 #define	AC_FILE_SET	(0x01)	/* set accounting file name */
     54 #define	AC_FILE_GET	(0x02)	/* get accounting file name */
     55 #define	AC_RES_SET	(0x04)	/* set (enable/disable) resources */
     56 #define	AC_RES_GET	(0x08)	/* get a list of enabled resources */
     57 #define	AC_STATE_SET	(0x10)	/* set accounting mode state (on/off) */
     58 #define	AC_STATE_GET	(0x20)	/* get accounting mode state */
     59 #define	AC_OPTION(x)	((x) & 0x00ffffff)
     60 
     61 /*
     62  * Process accounting resource IDs
     63  */
     64 #define	AC_NONE			0	/* special end-of-list identifier */
     65 #define	AC_PROC_PID		1	/* process ID */
     66 #define	AC_PROC_UID		2	/* user ID */
     67 #define	AC_PROC_GID		3	/* group ID */
     68 #define	AC_PROC_PROJID		4	/* project ID */
     69 #define	AC_PROC_TASKID		5	/* task ID */
     70 #define	AC_PROC_CPU		6	/* user/system cpu time */
     71 #define	AC_PROC_TIME		7	/* start/finish time */
     72 #define	AC_PROC_COMMAND		8	/* command name */
     73 #define	AC_PROC_TTY		9	/* control tty */
     74 #define	AC_PROC_HOSTNAME	10	/* hostname */
     75 #define	AC_PROC_MICROSTATE	11	/* microstate accounting */
     76 #define	AC_PROC_FLAG		12	/* accounting flags */
     77 #define	AC_PROC_ANCPID		13	/* ancestor process's ID */
     78 #define	AC_PROC_WAIT_STATUS	14	/* process wait status */
     79 #define	AC_PROC_ZONENAME	15	/* zone name */
     80 #define	AC_PROC_MEM		16	/* memory usage */
     81 #define	AC_PROC_MAX_RES		16	/* must be equal to the number above */
     82 
     83 /*
     84  * Task accounting resource IDs
     85  */
     86 #define	AC_TASK_TASKID		1	/* task ID */
     87 #define	AC_TASK_PROJID		2	/* project ID */
     88 #define	AC_TASK_CPU		3	/* user/system cpu time */
     89 #define	AC_TASK_TIME		4	/* start/finish time */
     90 #define	AC_TASK_HOSTNAME	5	/* hostname */
     91 #define	AC_TASK_MICROSTATE	6	/* microstate accounting */
     92 #define	AC_TASK_ANCTASKID	7	/* ancestor task's taskid */
     93 #define	AC_TASK_ZONENAME	8	/* zone name */
     94 #define	AC_TASK_MAX_RES		8	/* must be equal to the number above */
     95 
     96 /*
     97  * Flow accounting resource IDs
     98  */
     99 #define	AC_FLOW_SADDR		1	/* source address */
    100 #define	AC_FLOW_DADDR		2	/* destination address */
    101 #define	AC_FLOW_SPORT		3	/* source port */
    102 #define	AC_FLOW_DPORT		4	/* destination port */
    103 #define	AC_FLOW_PROTOCOL	5	/* protocol */
    104 #define	AC_FLOW_DSFIELD		6	/* dsfield */
    105 #define	AC_FLOW_CTIME		7	/* creation time for this flow */
    106 #define	AC_FLOW_LSEEN		8	/* pkt last seen for this flow */
    107 #define	AC_FLOW_NBYTES		9	/* no. of bytes in this flow */
    108 #define	AC_FLOW_NPKTS		10	/* no. of packets for this flow */
    109 #define	AC_FLOW_PROJID		11	/* project id */
    110 #define	AC_FLOW_UID		12	/* user id */
    111 #define	AC_FLOW_ANAME		13	/* action instance name */
    112 #define	AC_FLOW_MAX_RES		13	/* must be equal to the number above */
    113 
    114 /*
    115  * Network accounting resource IDs
    116  */
    117 #define	AC_NET_NAME		1	/* flow name */
    118 #define	AC_NET_EHOST		2	/* ethernet source address */
    119 #define	AC_NET_EDEST		3	/* ethernet destination address */
    120 #define	AC_NET_VLAN_TPID	4	/* VLAN protocol ID */
    121 #define	AC_NET_VLAN_TCI		5	/* VLAN tag control info. */
    122 #define	AC_NET_SAP		6	/* SAP */
    123 #define	AC_NET_PRIORITY		7	/* Priority */
    124 #define	AC_NET_BWLIMIT		8	/* Bandwidth limit */
    125 #define	AC_NET_DEVNAME		9	/* Device name */
    126 #define	AC_NET_SADDR		10	/* Source IP address */
    127 #define	AC_NET_DADDR		11	/* Dest IP address */
    128 #define	AC_NET_SPORT		12	/* Source Port */
    129 #define	AC_NET_DPORT		13	/* Dest Port */
    130 #define	AC_NET_PROTOCOL		14	/* Protocol */
    131 #define	AC_NET_DSFIELD		15	/* DiffServ field */
    132 #define	AC_NET_CURTIME		16	/* Current Time */
    133 #define	AC_NET_IBYTES		17	/* Inbound Bytes */
    134 #define	AC_NET_OBYTES		18	/* Outbound Bytes */
    135 #define	AC_NET_IPKTS		19	/* Inbound Packets */
    136 #define	AC_NET_OPKTS		20	/* Outbound Packets */
    137 #define	AC_NET_IERRPKTS		21	/* Inbound Error Packets */
    138 #define	AC_NET_OERRPKTS		22	/* Outbound Error Packets */
    139 #define	AC_NET_MAX_RES		22	/* must be equal to the number above */
    140 
    141 #define	AC_MAX_RES		\
    142 	MAX(MAX(MAX(AC_PROC_MAX_RES, AC_TASK_MAX_RES), AC_FLOW_MAX_RES), \
    143 	AC_NET_MAX_RES)
    144 #define	AC_MASK_SZ		BT_BITOUL(AC_MAX_RES + 1)
    145 
    146 /*
    147  * resource states
    148  */
    149 #define	AC_ON		1	/* enabled resource */
    150 #define	AC_OFF		0	/* disabled resource */
    151 
    152 typedef struct ac_res {
    153 	int	ar_id;		/* resource ID */
    154 	int	ar_state;	/* resource state; see above */
    155 } ac_res_t;
    156 
    157 #ifdef	_KERNEL
    158 
    159 #include <sys/vnode.h>
    160 #include <sys/zone.h>
    161 #include <sys/list.h>
    162 
    163 typedef struct ac_info {
    164 	kmutex_t	ac_lock;		/* protects the structure */
    165 	vnode_t		*ac_vnode;		/* exacct file vnode pointer */
    166 	char		*ac_file;		/* exacct file name */
    167 	int		ac_state;		/* accounting state */
    168 	ulong_t		ac_mask[AC_MASK_SZ];	/* bitmask of resources */
    169 } ac_info_t;
    170 
    171 /*
    172  * Key used for retrieving per-zone exacct settings.  This remains
    173  * uninitialized (ZONE_KEY_UNINITIALIZED) until the acctctl module is loaded.
    174  */
    175 extern zone_key_t exacct_zone_key;
    176 
    177 /*
    178  * Per-zone exacct settings.  Each zone may have its own settings for
    179  * process, task, flow, and network accounting.
    180  *
    181  * Per-zone flow accounting has not yet been implemented, so this
    182  * provides zones with the view that flow accounting in the zone hasn't
    183  * been initialized (which is true).  The various system calls will fail
    184  * to set flow accounting parameters from within a zone.
    185  *
    186  * The global list of accounting settings is used when we check to see
    187  * if the accounting file is already in use by any zone.
    188  */
    189 struct exacct_globals {
    190 	ac_info_t	ac_task;
    191 	ac_info_t	ac_proc;
    192 	ac_info_t	ac_flow;
    193 	ac_info_t	ac_net;
    194 	list_node_t	ac_link;
    195 };
    196 
    197 #else
    198 
    199 extern int acctctl(int cmd, void *buf, size_t bufsz);
    200 
    201 #endif	/* ifdef _KERNEL */
    202 
    203 #ifdef	__cplusplus
    204 }
    205 #endif
    206 
    207 #endif	/* _SYS_ACCTCTL_H */
    208