source: rtems-libbsd/rtemsbsd/src/rtems-bsd-jail.c @ d1528ff

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since d1528ff was d1528ff, checked in by Jennifer Averett <jennifer.averett@…>, on 03/28/12 at 16:40:08

Added log and prison methods to resolve linker errors for RealTek? Nic.

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_bsd_rtems
5 *
6 * @brief This object is an minimal rtems implementation of kern_jail.c.
7 */
8
9/*
10 * Copyright (c) 2009, 2010 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Obere Lagerstr. 30
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.com/license/LICENSE.
21 */
22
23#include <freebsd/machine/rtems-bsd-config.h>
24
25/*#include <freebsd/sys/types.h>
26#include <freebsd/sys/systm.h>
27#include <freebsd/sys/malloc.h>
28#include <freebsd/sys/jail.h>
29#include <freebsd/sys/lock.h>
30#include <freebsd/sys/mutex.h>*/
31
32#include <freebsd/sys/param.h>
33#include <freebsd/sys/types.h>
34#include <freebsd/sys/kernel.h>
35#include <freebsd/sys/systm.h>
36#include <freebsd/sys/errno.h>
37#include <freebsd/sys/sysproto.h>
38#include <freebsd/sys/malloc.h>
39#include <freebsd/sys/osd.h>
40#include <freebsd/sys/priv.h>
41#include <freebsd/sys/proc.h>
42#include <freebsd/sys/taskqueue.h>
43#include <freebsd/sys/fcntl.h>
44#include <freebsd/sys/jail.h>
45#include <freebsd/sys/lock.h>
46#include <freebsd/sys/mutex.h>
47#include <freebsd/sys/sx.h>
48#include <freebsd/sys/sysent.h>
49#include <freebsd/sys/namei.h>
50#include <freebsd/sys/mount.h>
51#include <freebsd/sys/queue.h>
52#include <freebsd/sys/socket.h>
53#include <freebsd/sys/syscallsubr.h>
54#include <freebsd/sys/sysctl.h>
55
56#define DEFAULT_HOSTUUID  "00000000-0000-0000-0000-000000000000"
57
58/* Keep struct prison prison0 and some code in kern_jail_set() readable. */
59#ifdef INET
60#ifdef INET6
61#define _PR_IP_SADDRSEL PR_IP4_SADDRSEL|PR_IP6_SADDRSEL
62#else
63#define _PR_IP_SADDRSEL PR_IP4_SADDRSEL
64#endif
65#else /* !INET */
66#ifdef INET6
67#define _PR_IP_SADDRSEL PR_IP6_SADDRSEL
68#else
69#define _PR_IP_SADDRSEL 0
70#endif
71#endif
72
73/* prison0 describes what is "real" about the system. */
74struct prison prison0 = {
75  .pr_id    = 0,
76  .pr_name  = "0",
77  .pr_ref   = 1,
78  .pr_uref  = 1,
79  .pr_path  = "/",
80  .pr_securelevel = -1,
81  .pr_childmax  = JAIL_MAX,
82  .pr_hostuuid  = DEFAULT_HOSTUUID,
83  .pr_children  = LIST_HEAD_INITIALIZER(prison0.pr_children),
84#ifdef VIMAGE
85  .pr_flags = PR_HOST|PR_VNET|_PR_IP_SADDRSEL,
86#else
87  .pr_flags = PR_HOST|_PR_IP_SADDRSEL,
88#endif
89  .pr_allow = PR_ALLOW_ALL,
90};
91MTX_SYSINIT(prison0, &prison0.pr_mtx, "jail mutex", MTX_DEF);
92
93/*
94 * See if a prison has the specific flag set.
95 */
96int
97prison_flag(struct ucred *cred, unsigned flag)
98{
99  /* This is an atomic read, so no locking is necessary. */
100  return (cred->cr_prison->pr_flags & flag);
101}
102
103void
104prison_free(struct prison *pr)
105{
106}
107
108void
109prison_hold(struct prison *pr)
110{
111}
112
113/*
114 * Check if given address belongs to the jail referenced by cred (wrapper to
115 * prison_check_ip[46]).
116 *
117 * Returns 0 if jail doesn't restrict the address family or if address belongs
118 * to jail, EADDRNOTAVAIL if the address doesn't belong, or EAFNOSUPPORT if
119 * the jail doesn't allow the address family.  IPv4 Address passed in in NBO.
120 */
121int
122prison_if(struct ucred *cred, struct sockaddr *sa)
123{
124  return 0;
125}
126
127/*
128 * Return 1 if we should do proper source address selection or are not jailed.
129 * We will return 0 if we should bypass source address selection in favour
130 * of the primary jail IPv6 address. Only in this case *ia will be updated and
131 * returned in NBO.
132 * Return EAFNOSUPPORT, in case this jail does not allow IPv6.
133 */
134int
135prison_saddrsel_ip6(struct ucred *cred, struct in6_addr *ia6)
136{
137  return EAFNOSUPPORT;
138}
139
140/*
141 * Return true if pr1 and pr2 have the same IPv4 address restrictions.
142 */
143int
144prison_equal_ip4(struct prison *pr1, struct prison *pr2)
145{
146  return 1;
147}
148
149/*
150 * Check if given address belongs to the jail referenced by cred/prison.
151 *
152 * Returns 0 if jail doesn't restrict IPv4 or if address belongs to jail,
153 * EADDRNOTAVAIL if the address doesn't belong, or EAFNOSUPPORT if the jail
154 * doesn't allow IPv4.  Address passed in in NBO.
155 */
156int
157prison_check_ip4(struct ucred *cred, struct in_addr *ia)
158{
159  return 0;
160}
161
162/*
163 * Assuming 0 means no restrictions.
164 *
165 * NOTE: RTEMS does not restrict via a jail so return 0.
166 */
167int
168prison_check_ip6(struct ucred *cred, struct in6_addr *ia6)
169{
170  return 0;
171}
172
173/*
174 * Make sure our (source) address is set to something meaningful to this
175 * jail.
176 *
177 * Returns 0 if jail doesn't restrict IPv4 or if address belongs to jail,
178 * EADDRNOTAVAIL if the address doesn't belong, or EAFNOSUPPORT if the jail
179 * doesn't allow IPv4.  Address passed in in NBO and returned in NBO.
180 */
181int
182prison_local_ip4(struct ucred *cred, struct in_addr *ia)
183{
184  return EAFNOSUPPORT;
185}
186
187/*
188 * Rewrite destination address in case we will connect to loopback address.
189 *
190 * Returns 0 on success, EAFNOSUPPORT if the jail doesn't allow IPv4.
191 * Address passed in in NBO and returned in NBO.
192 */
193int
194prison_remote_ip4(struct ucred *cred, struct in_addr *ia)
195{
196  return EAFNOSUPPORT;
197}
198
199/*
200 * Return true if pr1 and pr2 have the same IPv6 address restrictions.
201 */
202int
203prison_equal_ip6(struct prison *pr1, struct prison *pr2)
204{
205  return 1;
206}
207
208/*
209 * Make sure our (source) address is set to something meaningful to this jail.
210 *
211 * v6only should be set based on (inp->inp_flags & IN6P_IPV6_V6ONLY != 0)
212 * when needed while binding.
213 *
214 * Returns 0 if jail doesn't restrict IPv6 or if address belongs to jail,
215 * EADDRNOTAVAIL if the address doesn't belong, or EAFNOSUPPORT if the jail
216 * doesn't allow IPv6.
217 *
218 * NOTE: RTEMS does not restrict via a jail so return 0.
219 */
220int
221prison_local_ip6(struct ucred *cred, struct in6_addr *ia6, int v6only)
222{
223  return 0;
224}
225
226/*
227 * Rewrite destination address in case we will connect to loopback address.
228 *
229 * Returns 0 on success, EAFNOSUPPORT if the jail doesn't allow IPv6.
230 *
231 * NOTE: RTEMS does not restrict via a jail so return 0.
232 */
233int
234prison_remote_ip6(struct ucred *cred, struct in6_addr *ia6)
235{
236  return 0;
237}
Note: See TracBrowser for help on using the repository browser.