kernel - Reduce lwp_signotify() latency
[dragonfly.git] / usr.sbin / inetd / inetd.h
1 /*
2  * Copyright (c) 1983, 1991, 1993, 1994
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * $FreeBSD: src/usr.sbin/inetd/inetd.h,v 1.4.2.4 2002/08/21 10:00:24 ume Exp $
34  * $DragonFly: src/usr.sbin/inetd/inetd.h,v 1.3 2003/11/03 19:31:37 eirikn Exp $
35  */
36
37 #include <sys/time.h>
38 #include <sys/socket.h>
39 #include <sys/un.h>
40 #include <sys/queue.h>
41
42 #include <netinet/in.h>
43
44 #include <stdio.h>
45
46 #define BUFSIZE 8192
47 #define LINESIZ 72
48
49 #define NORM_TYPE       0
50 #define MUX_TYPE        1
51 #define MUXPLUS_TYPE    2
52 #define TTCP_TYPE       3
53 #define FAITH_TYPE      4
54 #define ISMUX(sep)      (((sep)->se_type == MUX_TYPE) || \
55                          ((sep)->se_type == MUXPLUS_TYPE))
56 #define ISMUXPLUS(sep)  ((sep)->se_type == MUXPLUS_TYPE)
57 #define ISTTCP(sep)     ((sep)->se_type == TTCP_TYPE)
58
59 struct procinfo {
60         LIST_ENTRY(procinfo) pr_link;
61         pid_t           pr_pid;         /* child pid */
62         struct conninfo *pr_conn;
63 };
64
65 struct conninfo {
66         LIST_ENTRY(conninfo) co_link;
67         struct sockaddr_storage co_addr;        /* source address */
68         int             co_numchild;    /* current number of children */
69         struct procinfo **co_proc;      /* array of child proc entry */
70 };
71
72 #define PERIPSIZE       256
73
74 struct  servtab {
75         char    *se_service;            /* name of service */
76         int     se_socktype;            /* type of socket to use */
77         int     se_family;              /* address family */
78         char    *se_proto;              /* protocol used */
79         int     se_maxchild;            /* max number of children */
80         int     se_maxcpm;              /* max connects per IP per minute */
81         int     se_numchild;            /* current number of children */
82         pid_t   *se_pids;               /* array of child pids */
83         char    *se_user;               /* user name to run as */
84         char    *se_group;              /* group name to run as */
85 #ifdef  LOGIN_CAP
86         char    *se_class;              /* login class name to run with */
87 #endif
88         struct  biltin *se_bi;          /* if built-in, description */
89         char    *se_server;             /* server program */
90         char    *se_server_name;        /* server program without path */
91 #define MAXARGV 20
92         char    *se_argv[MAXARGV+1];    /* program arguments */
93 #ifdef IPSEC
94         char    *se_policy;             /* IPsec policy string */
95 #endif
96         int     se_fd;                  /* open descriptor */
97         union {                         /* bound address */
98                 struct  sockaddr se_un_ctrladdr;
99                 struct  sockaddr_in se_un_ctrladdr4;
100                 struct  sockaddr_in6 se_un_ctrladdr6;
101                 struct  sockaddr_un se_un_ctrladdr_un;
102         } se_un;
103 #define se_ctrladdr     se_un.se_un_ctrladdr
104 #define se_ctrladdr4    se_un.se_un_ctrladdr4
105 #define se_ctrladdr6    se_un.se_un_ctrladdr6
106 #define se_ctrladdr_un   se_un.se_un_ctrladdr_un
107         socklen_t       se_ctrladdr_size;
108         uid_t   se_sockuid;             /* Owner for unix domain socket */
109         gid_t   se_sockgid;             /* Group for unix domain socket */
110         mode_t  se_sockmode;            /* Mode for unix domain socket */
111         u_char  se_type;                /* type: normal, mux, or mux+ */
112         u_char  se_checked;             /* looked at during merge */
113         u_char  se_accept;              /* i.e., wait/nowait mode */
114         u_char  se_rpc;                 /* ==1 if RPC service */
115         int     se_rpc_prog;            /* RPC program number */
116         u_int   se_rpc_lowvers;         /* RPC low version */
117         u_int   se_rpc_highvers;        /* RPC high version */
118         int     se_count;               /* number started since se_time */
119         struct  timeval se_time;        /* start of se_count */
120         struct  servtab *se_next;
121         struct se_flags {
122                 u_int se_nomapped : 1;
123                 u_int se_reset : 1;
124         } se_flags;
125         int     se_maxperip;            /* max number of children per src */
126         LIST_HEAD(, conninfo) se_conn[PERIPSIZE];
127 };
128
129 #define se_nomapped             se_flags.se_nomapped
130 #define se_reset                se_flags.se_reset
131
132 int             check_loop(const struct sockaddr *, const struct servtab *sep);
133 int             getvalue(const char *, int *, const char *);
134 char           *newstr(const char *);
135 void            inetd_setproctitle(const char *, int);
136 void            print_service(const char *, const struct servtab *);
137 char           *sskip(char **);
138 char           *skip(char **);
139 struct servtab *tcpmux(int);
140
141 extern int       debug;
142 extern struct servtab *servtab;
143
144 typedef void (bi_fn_t)(int, struct servtab *);
145
146 struct biltin {
147         const char *bi_service;         /* internally provided service name */
148         int     bi_socktype;            /* type of socket supported */
149         short   bi_fork;                /* 1 if should fork before call */
150         int     bi_maxchild;            /* max number of children, -1=default */
151         bi_fn_t *bi_fn;                 /* function which performs it */
152 };