]>
git.saurik.com Git - apple/xnu.git/blob - bsd/security/audit/audit_bsm_domain.c
2 * Copyright (c) 2008-2019 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
13 * its contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/param.h>
31 #include <sys/socket.h>
33 #include <security/audit/audit.h>
35 #include <bsm/audit_domain.h>
36 #include <bsm/audit_record.h>
40 u_short bd_bsm_domain
;
44 #define PF_NO_LOCAL_MAPPING -600
46 static const struct bsm_domain bsm_domains
[] = {
47 { .bd_bsm_domain
= BSM_PF_UNSPEC
, .bd_local_domain
= PF_UNSPEC
},
48 { .bd_bsm_domain
= BSM_PF_LOCAL
, .bd_local_domain
= PF_LOCAL
},
49 { .bd_bsm_domain
= BSM_PF_INET
, .bd_local_domain
= PF_INET
},
50 { .bd_bsm_domain
= BSM_PF_IMPLINK
,
52 .bd_local_domain
= PF_IMPLINK
54 .bd_local_domain
= PF_NO_LOCAL_MAPPING
57 { .bd_bsm_domain
= BSM_PF_PUP
,
59 .bd_local_domain
= PF_PUP
61 .bd_local_domain
= PF_NO_LOCAL_MAPPING
64 { .bd_bsm_domain
= BSM_PF_CHAOS
,
66 .bd_local_domain
= PF_CHAOS
68 .bd_local_domain
= PF_NO_LOCAL_MAPPING
71 { .bd_bsm_domain
= BSM_PF_NS
,
73 .bd_local_domain
= PF_NS
75 .bd_local_domain
= PF_NO_LOCAL_MAPPING
78 { .bd_bsm_domain
= BSM_PF_NBS
,
80 .bd_local_domain
= PF_NBS
82 .bd_local_domain
= PF_NO_LOCAL_MAPPING
85 { .bd_bsm_domain
= BSM_PF_ECMA
,
87 .bd_local_domain
= PF_ECMA
89 .bd_local_domain
= PF_NO_LOCAL_MAPPING
92 { .bd_bsm_domain
= BSM_PF_DATAKIT
,
94 .bd_local_domain
= PF_DATAKIT
96 .bd_local_domain
= PF_NO_LOCAL_MAPPING
99 { .bd_bsm_domain
= BSM_PF_CCITT
,
101 .bd_local_domain
= PF_CCITT
103 .bd_local_domain
= PF_NO_LOCAL_MAPPING
106 { .bd_bsm_domain
= BSM_PF_SNA
, .bd_local_domain
= PF_SNA
},
107 { .bd_bsm_domain
= BSM_PF_DECnet
, .bd_local_domain
= PF_DECnet
},
108 { .bd_bsm_domain
= BSM_PF_DLI
,
110 .bd_local_domain
= PF_DLI
112 .bd_local_domain
= PF_NO_LOCAL_MAPPING
115 { .bd_bsm_domain
= BSM_PF_LAT
,
117 .bd_local_domain
= PF_LAT
119 .bd_local_domain
= PF_NO_LOCAL_MAPPING
122 { .bd_bsm_domain
= BSM_PF_HYLINK
,
124 .bd_local_domain
= PF_HYLINK
126 .bd_local_domain
= PF_NO_LOCAL_MAPPING
129 { .bd_bsm_domain
= BSM_PF_APPLETALK
, .bd_local_domain
= PF_APPLETALK
},
130 { .bd_bsm_domain
= BSM_PF_NIT
,
132 .bd_local_domain
= PF_NIT
134 .bd_local_domain
= PF_NO_LOCAL_MAPPING
137 { .bd_bsm_domain
= BSM_PF_802
,
139 .bd_local_domain
= PF_802
141 .bd_local_domain
= PF_NO_LOCAL_MAPPING
144 { .bd_bsm_domain
= BSM_PF_OSI
,
146 .bd_local_domain
= PF_OSI
148 .bd_local_domain
= PF_NO_LOCAL_MAPPING
151 { .bd_bsm_domain
= BSM_PF_X25
,
153 .bd_local_domain
= PF_X25
155 .bd_local_domain
= PF_NO_LOCAL_MAPPING
158 { .bd_bsm_domain
= BSM_PF_OSINET
,
160 .bd_local_domain
= PF_OSINET
162 .bd_local_domain
= PF_NO_LOCAL_MAPPING
165 { .bd_bsm_domain
= BSM_PF_GOSIP
,
167 .bd_local_domain
= PF_GOSIP
169 .bd_local_domain
= PF_NO_LOCAL_MAPPING
172 { .bd_bsm_domain
= BSM_PF_IPX
, .bd_local_domain
= PF_IPX
},
173 { .bd_bsm_domain
= BSM_PF_ROUTE
, .bd_local_domain
= PF_ROUTE
},
174 { .bd_bsm_domain
= BSM_PF_LINK
,
176 .bd_local_domain
= PF_LINK
178 .bd_local_domain
= PF_NO_LOCAL_MAPPING
181 { .bd_bsm_domain
= BSM_PF_KEY
, .bd_local_domain
= PF_KEY
},
182 { .bd_bsm_domain
= BSM_PF_NCA
,
184 .bd_local_domain
= PF_NCA
186 .bd_local_domain
= PF_NO_LOCAL_MAPPING
189 { .bd_bsm_domain
= BSM_PF_POLICY
,
191 .bd_local_domain
= PF_POLICY
193 .bd_local_domain
= PF_NO_LOCAL_MAPPING
196 { .bd_bsm_domain
= BSM_PF_INET_OFFLOAD
,
197 #ifdef PF_INET_OFFLOAD
198 .bd_local_domain
= PF_INET_OFFLOAD
200 .bd_local_domain
= PF_NO_LOCAL_MAPPING
203 { .bd_bsm_domain
= BSM_PF_NETBIOS
,
205 .bd_local_domain
= PF_NETBIOS
207 .bd_local_domain
= PF_NO_LOCAL_MAPPING
210 { .bd_bsm_domain
= BSM_PF_ISO
,
212 .bd_local_domain
= PF_ISO
214 .bd_local_domain
= PF_NO_LOCAL_MAPPING
217 { .bd_bsm_domain
= BSM_PF_XTP
,
219 .bd_local_domain
= PF_XTP
221 .bd_local_domain
= PF_NO_LOCAL_MAPPING
224 { .bd_bsm_domain
= BSM_PF_COIP
,
226 .bd_local_domain
= PF_COIP
228 .bd_local_domain
= PF_NO_LOCAL_MAPPING
231 { .bd_bsm_domain
= BSM_PF_CNT
,
233 .bd_local_domain
= PF_CNT
235 .bd_local_domain
= PF_NO_LOCAL_MAPPING
238 { .bd_bsm_domain
= BSM_PF_RTIP
,
240 .bd_local_domain
= PF_RTIP
242 .bd_local_domain
= PF_NO_LOCAL_MAPPING
245 { .bd_bsm_domain
= BSM_PF_SIP
,
247 .bd_local_domain
= PF_SIP
249 .bd_local_domain
= PF_NO_LOCAL_MAPPING
252 { .bd_bsm_domain
= BSM_PF_PIP
,
254 .bd_local_domain
= PF_PIP
256 .bd_local_domain
= PF_NO_LOCAL_MAPPING
259 { .bd_bsm_domain
= BSM_PF_ISDN
,
261 .bd_local_domain
= PF_ISDN
263 .bd_local_domain
= PF_NO_LOCAL_MAPPING
266 { .bd_bsm_domain
= BSM_PF_E164
,
268 .bd_local_domain
= PF_E164
270 .bd_local_domain
= PF_NO_LOCAL_MAPPING
273 { .bd_bsm_domain
= BSM_PF_NATM
,
275 .bd_local_domain
= PF_NATM
277 .bd_local_domain
= PF_NO_LOCAL_MAPPING
280 { .bd_bsm_domain
= BSM_PF_ATM
,
282 .bd_local_domain
= PF_ATM
284 .bd_local_domain
= PF_NO_LOCAL_MAPPING
287 { .bd_bsm_domain
= BSM_PF_NETGRAPH
,
289 .bd_local_domain
= PF_NETGRAPH
291 .bd_local_domain
= PF_NO_LOCAL_MAPPING
294 { .bd_bsm_domain
= BSM_PF_SLOW
,
296 .bd_local_domain
= PF_SLOW
298 .bd_local_domain
= PF_NO_LOCAL_MAPPING
301 { .bd_bsm_domain
= BSM_PF_SCLUSTER
,
303 .bd_local_domain
= PF_SCLUSTER
305 .bd_local_domain
= PF_NO_LOCAL_MAPPING
308 { .bd_bsm_domain
= BSM_PF_ARP
,
310 .bd_local_domain
= PF_ARP
312 .bd_local_domain
= PF_NO_LOCAL_MAPPING
315 { .bd_bsm_domain
= BSM_PF_BLUETOOTH
,
317 .bd_local_domain
= PF_BLUETOOTH
319 .bd_local_domain
= PF_NO_LOCAL_MAPPING
322 { .bd_bsm_domain
= BSM_PF_IEEE80211
,
324 .bd_local_domain
= PF_IEEE80211
326 .bd_local_domain
= PF_NO_LOCAL_MAPPING
329 { .bd_bsm_domain
= BSM_PF_AX25
,
331 .bd_local_domain
= PF_AX25
333 .bd_local_domain
= PF_NO_LOCAL_MAPPING
336 { .bd_bsm_domain
= BSM_PF_ROSE
,
338 .bd_local_domain
= PF_ROSE
340 .bd_local_domain
= PF_NO_LOCAL_MAPPING
343 { .bd_bsm_domain
= BSM_PF_NETBEUI
,
345 .bd_local_domain
= PF_NETBEUI
347 .bd_local_domain
= PF_NO_LOCAL_MAPPING
350 { .bd_bsm_domain
= BSM_PF_SECURITY
,
352 .bd_local_domain
= PF_SECURITY
354 .bd_local_domain
= PF_NO_LOCAL_MAPPING
357 { .bd_bsm_domain
= BSM_PF_PACKET
,
359 .bd_local_domain
= PF_PACKET
361 .bd_local_domain
= PF_NO_LOCAL_MAPPING
364 { .bd_bsm_domain
= BSM_PF_ASH
,
366 .bd_local_domain
= PF_ASH
368 .bd_local_domain
= PF_NO_LOCAL_MAPPING
371 { .bd_bsm_domain
= BSM_PF_ECONET
,
373 .bd_local_domain
= PF_ECONET
375 .bd_local_domain
= PF_NO_LOCAL_MAPPING
378 { .bd_bsm_domain
= BSM_PF_ATMSVC
,
380 .bd_local_domain
= PF_ATMSVC
382 .bd_local_domain
= PF_NO_LOCAL_MAPPING
385 { .bd_bsm_domain
= BSM_PF_IRDA
,
387 .bd_local_domain
= PF_IRDA
389 .bd_local_domain
= PF_NO_LOCAL_MAPPING
392 { .bd_bsm_domain
= BSM_PF_PPPOX
,
394 .bd_local_domain
= PF_PPPOX
396 .bd_local_domain
= PF_NO_LOCAL_MAPPING
399 { .bd_bsm_domain
= BSM_PF_WANPIPE
,
401 .bd_local_domain
= PF_WANPIPE
403 .bd_local_domain
= PF_NO_LOCAL_MAPPING
406 { .bd_bsm_domain
= BSM_PF_LLC
,
408 .bd_local_domain
= PF_LLC
410 .bd_local_domain
= PF_NO_LOCAL_MAPPING
413 { .bd_bsm_domain
= BSM_PF_CAN
,
415 .bd_local_domain
= PF_CAN
417 .bd_local_domain
= PF_NO_LOCAL_MAPPING
420 { .bd_bsm_domain
= BSM_PF_TIPC
,
422 .bd_local_domain
= PF_TIPC
424 .bd_local_domain
= PF_NO_LOCAL_MAPPING
427 { .bd_bsm_domain
= BSM_PF_IUCV
,
429 .bd_local_domain
= PF_IUCV
431 .bd_local_domain
= PF_NO_LOCAL_MAPPING
434 { .bd_bsm_domain
= BSM_PF_RXRPC
,
436 .bd_local_domain
= PF_RXRPC
438 .bd_local_domain
= PF_NO_LOCAL_MAPPING
441 { .bd_bsm_domain
= BSM_PF_PHONET
,
443 .bd_local_domain
= PF_PHONET
445 .bd_local_domain
= PF_NO_LOCAL_MAPPING
449 static const int bsm_domains_count
= sizeof(bsm_domains
) /
450 sizeof(bsm_domains
[0]);
452 static const struct bsm_domain
*
453 bsm_lookup_local_domain(int local_domain
)
457 for (i
= 0; i
< bsm_domains_count
; i
++) {
458 if (bsm_domains
[i
].bd_local_domain
== local_domain
) {
459 return &bsm_domains
[i
];
466 au_domain_to_bsm(int local_domain
)
468 const struct bsm_domain
*bstp
;
470 bstp
= bsm_lookup_local_domain(local_domain
);
472 return BSM_PF_UNKNOWN
;
474 return bstp
->bd_bsm_domain
;
477 static const struct bsm_domain
*
478 bsm_lookup_bsm_domain(u_short bsm_domain
)
482 for (i
= 0; i
< bsm_domains_count
; i
++) {
483 if (bsm_domains
[i
].bd_bsm_domain
== bsm_domain
) {
484 return &bsm_domains
[i
];
491 au_bsm_to_domain(u_short bsm_domain
, int *local_domainp
)
493 const struct bsm_domain
*bstp
;
495 bstp
= bsm_lookup_bsm_domain(bsm_domain
);
496 if (bstp
== NULL
|| bstp
->bd_local_domain
) {
499 *local_domainp
= bstp
->bd_local_domain
;
502 #endif /* CONFIG_AUDIT */