1220163Strasz/*- 2220163Strasz * Copyright (c) 2010 The FreeBSD Foundation 3220163Strasz * All rights reserved. 4220163Strasz * 5220163Strasz * This software was developed by Edward Tomasz Napierala under sponsorship 6220163Strasz * from the FreeBSD Foundation. 7220163Strasz * 8220163Strasz * Redistribution and use in source and binary forms, with or without 9220163Strasz * modification, are permitted provided that the following conditions 10220163Strasz * are met: 11220163Strasz * 1. Redistributions of source code must retain the above copyright 12220163Strasz * notice, this list of conditions and the following disclaimer. 13220163Strasz * 2. Redistributions in binary form must reproduce the above copyright 14220163Strasz * notice, this list of conditions and the following disclaimer in the 15220163Strasz * documentation and/or other materials provided with the distribution. 16220163Strasz * 17220163Strasz * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18220163Strasz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19220163Strasz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20220163Strasz * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21220163Strasz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22220163Strasz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23220163Strasz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24220163Strasz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25220163Strasz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26220163Strasz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27220163Strasz * SUCH DAMAGE. 28220163Strasz * 29220163Strasz * $FreeBSD$ 30220163Strasz */ 31220163Strasz 32220163Strasz/* 33220163Strasz * Resource Limits. 34220163Strasz */ 35220163Strasz 36220163Strasz#ifndef _RCTL_H_ 37220163Strasz#define _RCTL_H_ 38220163Strasz 39220163Strasz#include <sys/cdefs.h> 40220163Strasz#include <sys/queue.h> 41220163Strasz#include <sys/types.h> 42220163Strasz#include <sys/_task.h> 43220163Strasz 44220163Straszstruct proc; 45220163Straszstruct uidinfo; 46220163Straszstruct loginclass; 47221362Straszstruct prison_racct; 48220163Straszstruct ucred; 49220163Straszstruct rctl_rule_link; 50220163Strasz 51220163Strasz#ifdef _KERNEL 52220163Strasz 53220163Strasz/* 54220163Strasz * Rules describe an action to be taken when conditions defined 55220163Strasz * in the rule are met. There is no global list of rules; instead, 56220163Strasz * rules are linked to by the racct structures for all the subjects 57220163Strasz * they apply to - for example, a rule of type "user" is linked to the 58220163Strasz * appropriate struct uidinfo, and to all the processes of that user. 59220163Strasz * 60220163Strasz * 'rr_refcount' is equal to the number of rctl_rule_link structures 61220163Strasz * pointing to the rule. 62220163Strasz * 63220163Strasz * This structure must never change after being added, via rctl_rule_link 64220163Strasz * structures, to subjects. In order to change a rule, add a new rule 65220163Strasz * and remove the previous one. 66220163Strasz */ 67220163Straszstruct rctl_rule { 68220163Strasz int rr_subject_type; 69220163Strasz union { 70220527Strasz struct proc *rs_proc; 71220527Strasz struct uidinfo *rs_uip; 72220527Strasz struct loginclass *rs_loginclass; 73221362Strasz struct prison_racct *rs_prison_racct; 74220163Strasz } rr_subject; 75220163Strasz int rr_per; 76220163Strasz int rr_resource; 77220163Strasz int rr_action; 78220163Strasz int64_t rr_amount; 79220163Strasz u_int rr_refcount; 80220163Strasz struct task rr_task; 81220163Strasz}; 82220163Strasz 83220163Strasz/* 84220163Strasz * Allowed values for rr_subject_type and rr_per fields. 85220163Strasz */ 86220163Strasz#define RCTL_SUBJECT_TYPE_UNDEFINED -1 87220163Strasz#define RCTL_SUBJECT_TYPE_PROCESS 0x0000 88220163Strasz#define RCTL_SUBJECT_TYPE_USER 0x0001 89220163Strasz#define RCTL_SUBJECT_TYPE_LOGINCLASS 0x0003 90220163Strasz#define RCTL_SUBJECT_TYPE_JAIL 0x0004 91220163Strasz#define RCTL_SUBJECT_TYPE_MAX RCTL_SUBJECT_TYPE_JAIL 92220163Strasz 93220163Strasz/* 94220163Strasz * Allowed values for rr_action field. 95220163Strasz */ 96220163Strasz#define RCTL_ACTION_UNDEFINED -1 97220163Strasz#define RCTL_ACTION_SIGHUP SIGHUP 98220163Strasz#define RCTL_ACTION_SIGINT SIGINT 99220163Strasz#define RCTL_ACTION_SIGQUIT SIGQUIT 100220163Strasz#define RCTL_ACTION_SIGILL SIGILL 101220163Strasz#define RCTL_ACTION_SIGTRAP SIGTRAP 102220163Strasz#define RCTL_ACTION_SIGABRT SIGABRT 103220163Strasz#define RCTL_ACTION_SIGEMT SIGEMT 104220163Strasz#define RCTL_ACTION_SIGFPE SIGFPE 105220163Strasz#define RCTL_ACTION_SIGKILL SIGKILL 106220163Strasz#define RCTL_ACTION_SIGBUS SIGBUS 107220163Strasz#define RCTL_ACTION_SIGSEGV SIGSEGV 108220163Strasz#define RCTL_ACTION_SIGSYS SIGSYS 109220163Strasz#define RCTL_ACTION_SIGPIPE SIGPIPE 110220163Strasz#define RCTL_ACTION_SIGALRM SIGALRM 111220163Strasz#define RCTL_ACTION_SIGTERM SIGTERM 112220163Strasz#define RCTL_ACTION_SIGURG SIGURG 113220163Strasz#define RCTL_ACTION_SIGSTOP SIGSTOP 114220163Strasz#define RCTL_ACTION_SIGTSTP SIGTSTP 115220163Strasz#define RCTL_ACTION_SIGCHLD SIGCHLD 116220163Strasz#define RCTL_ACTION_SIGTTIN SIGTTIN 117220163Strasz#define RCTL_ACTION_SIGTTOU SIGTTOU 118220163Strasz#define RCTL_ACTION_SIGIO SIGIO 119220163Strasz#define RCTL_ACTION_SIGXCPU SIGXCPU 120220163Strasz#define RCTL_ACTION_SIGXFSZ SIGXFSZ 121220163Strasz#define RCTL_ACTION_SIGVTALRM SIGVTALRM 122220163Strasz#define RCTL_ACTION_SIGPROF SIGPROF 123220163Strasz#define RCTL_ACTION_SIGWINCH SIGWINCH 124220163Strasz#define RCTL_ACTION_SIGINFO SIGINFO 125220163Strasz#define RCTL_ACTION_SIGUSR1 SIGUSR1 126220163Strasz#define RCTL_ACTION_SIGUSR2 SIGUSR2 127220163Strasz#define RCTL_ACTION_SIGTHR SIGTHR 128220163Strasz#define RCTL_ACTION_SIGNAL_MAX RCTL_ACTION_SIGTHR 129220163Strasz#define RCTL_ACTION_DENY (RCTL_ACTION_SIGNAL_MAX + 1) 130220163Strasz#define RCTL_ACTION_LOG (RCTL_ACTION_SIGNAL_MAX + 2) 131220163Strasz#define RCTL_ACTION_DEVCTL (RCTL_ACTION_SIGNAL_MAX + 3) 132220163Strasz#define RCTL_ACTION_MAX RCTL_ACTION_DEVCTL 133220163Strasz 134220163Strasz#define RCTL_AMOUNT_UNDEFINED -1 135220163Strasz 136220163Straszstruct rctl_rule *rctl_rule_alloc(int flags); 137220163Straszstruct rctl_rule *rctl_rule_duplicate(const struct rctl_rule *rule, int flags); 138220163Straszvoid rctl_rule_acquire(struct rctl_rule *rule); 139220163Straszvoid rctl_rule_release(struct rctl_rule *rule); 140220163Straszint rctl_rule_add(struct rctl_rule *rule); 141220163Straszint rctl_rule_remove(struct rctl_rule *filter); 142220163Straszint rctl_enforce(struct proc *p, int resource, uint64_t amount); 143242139Straszint64_t rctl_pcpu_available(const struct proc *p); 144220163Straszuint64_t rctl_get_limit(struct proc *p, int resource); 145220163Straszuint64_t rctl_get_available(struct proc *p, int resource); 146220163Straszconst char *rctl_resource_name(int resource); 147220163Straszvoid rctl_proc_ucred_changed(struct proc *p, struct ucred *newcred); 148220163Straszint rctl_proc_fork(struct proc *parent, struct proc *child); 149220163Straszvoid rctl_racct_release(struct racct *racct); 150220163Strasz#else /* !_KERNEL */ 151220163Strasz 152220163Strasz/* 153220163Strasz * Syscall interface. 154220163Strasz */ 155220163Strasz__BEGIN_DECLS 156220163Straszint rctl_get_racct(const char *inbufp, size_t inbuflen, char *outbufp, 157220163Strasz size_t outbuflen); 158220163Straszint rctl_get_rules(const char *inbufp, size_t inbuflen, char *outbufp, 159220163Strasz size_t outbuflen); 160220163Straszint rctl_get_limits(const char *inbufp, size_t inbuflen, char *outbufp, 161220163Strasz size_t outbuflen); 162220163Straszint rctl_add_rule(const char *inbufp, size_t inbuflen, char *outbufp, 163220163Strasz size_t outbuflen); 164220163Straszint rctl_remove_rule(const char *inbufp, size_t inbuflen, char *outbufp, 165220163Strasz size_t outbuflen); 166220163Strasz__END_DECLS 167220163Strasz 168220163Strasz#endif /* !_KERNEL */ 169220163Strasz 170220163Strasz#endif /* !_RCTL_H_ */ 171