]> git.saurik.com Git - apple/xnu.git/blame - bsd/security/audit/audit_bsm_domain.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / security / audit / audit_bsm_domain.c
CommitLineData
b0d623f7 1/*-
cb323159 2 * Copyright (c) 2008-2019 Apple Inc. All rights reserved.
b0d623f7
A
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
15 *
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.
27 *
28 */
29
30#include <sys/param.h>
31#include <sys/socket.h>
32
33#include <security/audit/audit.h>
34
35#include <bsm/audit_domain.h>
36#include <bsm/audit_record.h>
37
38#if CONFIG_AUDIT
39struct bsm_domain {
0a7de745
A
40 u_short bd_bsm_domain;
41 int bd_local_domain;
b0d623f7
A
42};
43
0a7de745 44#define PF_NO_LOCAL_MAPPING -600
b0d623f7
A
45
46static const struct bsm_domain bsm_domains[] = {
cb323159
A
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,
b0d623f7 51#ifdef PF_IMPLINK
cb323159 52 .bd_local_domain = PF_IMPLINK
b0d623f7 53#else
cb323159 54 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
55#endif
56 },
cb323159 57 { .bd_bsm_domain = BSM_PF_PUP,
b0d623f7 58#ifdef PF_PUP
cb323159 59 .bd_local_domain = PF_PUP
b0d623f7 60#else
cb323159 61 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
62#endif
63 },
cb323159 64 { .bd_bsm_domain = BSM_PF_CHAOS,
b0d623f7 65#ifdef PF_CHAOS
cb323159 66 .bd_local_domain = PF_CHAOS
b0d623f7 67#else
cb323159 68 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
69#endif
70 },
cb323159 71 { .bd_bsm_domain = BSM_PF_NS,
b0d623f7 72#ifdef PF_NS
cb323159 73 .bd_local_domain = PF_NS
b0d623f7 74#else
cb323159 75 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
76#endif
77 },
cb323159 78 { .bd_bsm_domain = BSM_PF_NBS,
b0d623f7 79#ifdef PF_NBS
cb323159 80 .bd_local_domain = PF_NBS
b0d623f7 81#else
cb323159 82 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
83#endif
84 },
cb323159 85 { .bd_bsm_domain = BSM_PF_ECMA,
b0d623f7 86#ifdef PF_ECMA
cb323159 87 .bd_local_domain = PF_ECMA
b0d623f7 88#else
cb323159 89 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
90#endif
91 },
cb323159 92 { .bd_bsm_domain = BSM_PF_DATAKIT,
b0d623f7 93#ifdef PF_DATAKIT
cb323159 94 .bd_local_domain = PF_DATAKIT
b0d623f7 95#else
cb323159 96 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
97#endif
98 },
cb323159 99 { .bd_bsm_domain = BSM_PF_CCITT,
b0d623f7 100#ifdef PF_CCITT
cb323159 101 .bd_local_domain = PF_CCITT
b0d623f7 102#else
cb323159 103 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
104#endif
105 },
cb323159
A
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,
b0d623f7 109#ifdef PF_DLI
cb323159 110 .bd_local_domain = PF_DLI
b0d623f7 111#else
cb323159 112 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
113#endif
114 },
cb323159 115 { .bd_bsm_domain = BSM_PF_LAT,
b0d623f7 116#ifdef PF_LAT
cb323159 117 .bd_local_domain = PF_LAT
b0d623f7 118#else
cb323159 119 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
120#endif
121 },
cb323159 122 { .bd_bsm_domain = BSM_PF_HYLINK,
b0d623f7 123#ifdef PF_HYLINK
cb323159 124 .bd_local_domain = PF_HYLINK
b0d623f7 125#else
cb323159 126 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
127#endif
128 },
cb323159
A
129 { .bd_bsm_domain = BSM_PF_APPLETALK, .bd_local_domain = PF_APPLETALK },
130 { .bd_bsm_domain = BSM_PF_NIT,
b0d623f7 131#ifdef PF_NIT
cb323159 132 .bd_local_domain = PF_NIT
b0d623f7 133#else
cb323159 134 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
135#endif
136 },
cb323159 137 { .bd_bsm_domain = BSM_PF_802,
b0d623f7 138#ifdef PF_802
cb323159 139 .bd_local_domain = PF_802
b0d623f7 140#else
cb323159 141 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
142#endif
143 },
cb323159 144 { .bd_bsm_domain = BSM_PF_OSI,
b0d623f7 145#ifdef PF_OSI
cb323159 146 .bd_local_domain = PF_OSI
b0d623f7 147#else
cb323159 148 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
149#endif
150 },
cb323159 151 { .bd_bsm_domain = BSM_PF_X25,
b0d623f7 152#ifdef PF_X25
cb323159 153 .bd_local_domain = PF_X25
b0d623f7 154#else
cb323159 155 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
156#endif
157 },
cb323159 158 { .bd_bsm_domain = BSM_PF_OSINET,
b0d623f7 159#ifdef PF_OSINET
cb323159 160 .bd_local_domain = PF_OSINET
b0d623f7 161#else
cb323159 162 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
163#endif
164 },
cb323159 165 { .bd_bsm_domain = BSM_PF_GOSIP,
b0d623f7 166#ifdef PF_GOSIP
cb323159 167 .bd_local_domain = PF_GOSIP
b0d623f7 168#else
cb323159 169 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
170#endif
171 },
cb323159
A
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,
b0d623f7 175#ifdef PF_LINK
cb323159 176 .bd_local_domain = PF_LINK
b0d623f7 177#else
cb323159 178 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
179#endif
180 },
cb323159
A
181 { .bd_bsm_domain = BSM_PF_KEY, .bd_local_domain = PF_KEY },
182 { .bd_bsm_domain = BSM_PF_NCA,
b0d623f7 183#ifdef PF_NCA
cb323159 184 .bd_local_domain = PF_NCA
b0d623f7 185#else
cb323159 186 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
187#endif
188 },
cb323159 189 { .bd_bsm_domain = BSM_PF_POLICY,
b0d623f7 190#ifdef PF_POLICY
cb323159 191 .bd_local_domain = PF_POLICY
b0d623f7 192#else
cb323159 193 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
194#endif
195 },
cb323159 196 { .bd_bsm_domain = BSM_PF_INET_OFFLOAD,
b0d623f7 197#ifdef PF_INET_OFFLOAD
cb323159 198 .bd_local_domain = PF_INET_OFFLOAD
b0d623f7 199#else
cb323159 200 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
201#endif
202 },
cb323159 203 { .bd_bsm_domain = BSM_PF_NETBIOS,
b0d623f7 204#ifdef PF_NETBIOS
cb323159 205 .bd_local_domain = PF_NETBIOS
b0d623f7 206#else
cb323159 207 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
208#endif
209 },
cb323159 210 { .bd_bsm_domain = BSM_PF_ISO,
b0d623f7 211#ifdef PF_ISO
cb323159 212 .bd_local_domain = PF_ISO
b0d623f7 213#else
cb323159 214 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
215#endif
216 },
cb323159 217 { .bd_bsm_domain = BSM_PF_XTP,
b0d623f7 218#ifdef PF_XTP
cb323159 219 .bd_local_domain = PF_XTP
b0d623f7 220#else
cb323159 221 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
222#endif
223 },
cb323159 224 { .bd_bsm_domain = BSM_PF_COIP,
b0d623f7 225#ifdef PF_COIP
cb323159 226 .bd_local_domain = PF_COIP
b0d623f7 227#else
cb323159 228 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
229#endif
230 },
cb323159 231 { .bd_bsm_domain = BSM_PF_CNT,
b0d623f7 232#ifdef PF_CNT
cb323159 233 .bd_local_domain = PF_CNT
b0d623f7 234#else
cb323159 235 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
236#endif
237 },
cb323159 238 { .bd_bsm_domain = BSM_PF_RTIP,
b0d623f7 239#ifdef PF_RTIP
cb323159 240 .bd_local_domain = PF_RTIP
b0d623f7 241#else
cb323159 242 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
243#endif
244 },
cb323159 245 { .bd_bsm_domain = BSM_PF_SIP,
b0d623f7 246#ifdef PF_SIP
cb323159 247 .bd_local_domain = PF_SIP
b0d623f7 248#else
cb323159 249 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
250#endif
251 },
cb323159 252 { .bd_bsm_domain = BSM_PF_PIP,
b0d623f7 253#ifdef PF_PIP
cb323159 254 .bd_local_domain = PF_PIP
b0d623f7 255#else
cb323159 256 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
257#endif
258 },
cb323159 259 { .bd_bsm_domain = BSM_PF_ISDN,
b0d623f7 260#ifdef PF_ISDN
cb323159 261 .bd_local_domain = PF_ISDN
b0d623f7 262#else
cb323159 263 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
264#endif
265 },
cb323159 266 { .bd_bsm_domain = BSM_PF_E164,
b0d623f7 267#ifdef PF_E164
cb323159 268 .bd_local_domain = PF_E164
b0d623f7 269#else
cb323159 270 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
271#endif
272 },
cb323159 273 { .bd_bsm_domain = BSM_PF_NATM,
b0d623f7 274#ifdef PF_NATM
cb323159 275 .bd_local_domain = PF_NATM
b0d623f7 276#else
cb323159 277 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
278#endif
279 },
cb323159 280 { .bd_bsm_domain = BSM_PF_ATM,
b0d623f7 281#ifdef PF_ATM
cb323159 282 .bd_local_domain = PF_ATM
b0d623f7 283#else
cb323159 284 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
285#endif
286 },
cb323159 287 { .bd_bsm_domain = BSM_PF_NETGRAPH,
b0d623f7 288#ifdef PF_NETGRAPH
cb323159 289 .bd_local_domain = PF_NETGRAPH
b0d623f7 290#else
cb323159 291 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
292#endif
293 },
cb323159 294 { .bd_bsm_domain = BSM_PF_SLOW,
b0d623f7 295#ifdef PF_SLOW
cb323159 296 .bd_local_domain = PF_SLOW
b0d623f7 297#else
cb323159 298 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
299#endif
300 },
cb323159 301 { .bd_bsm_domain = BSM_PF_SCLUSTER,
b0d623f7 302#ifdef PF_SCLUSTER
cb323159 303 .bd_local_domain = PF_SCLUSTER
b0d623f7 304#else
cb323159 305 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
306#endif
307 },
cb323159 308 { .bd_bsm_domain = BSM_PF_ARP,
b0d623f7 309#ifdef PF_ARP
cb323159 310 .bd_local_domain = PF_ARP
b0d623f7 311#else
cb323159 312 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
313#endif
314 },
cb323159 315 { .bd_bsm_domain = BSM_PF_BLUETOOTH,
b0d623f7 316#ifdef PF_BLUETOOTH
cb323159 317 .bd_local_domain = PF_BLUETOOTH
b0d623f7 318#else
cb323159 319 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
320#endif
321 },
cb323159 322 { .bd_bsm_domain = BSM_PF_IEEE80211,
b0d623f7 323#ifdef PF_IEEE80211
cb323159 324 .bd_local_domain = PF_IEEE80211
b0d623f7 325#else
cb323159 326 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
327#endif
328 },
cb323159 329 { .bd_bsm_domain = BSM_PF_AX25,
b0d623f7 330#ifdef PF_AX25
cb323159 331 .bd_local_domain = PF_AX25
b0d623f7 332#else
cb323159 333 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
334#endif
335 },
cb323159 336 { .bd_bsm_domain = BSM_PF_ROSE,
b0d623f7 337#ifdef PF_ROSE
cb323159 338 .bd_local_domain = PF_ROSE
b0d623f7 339#else
cb323159 340 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
341#endif
342 },
cb323159 343 { .bd_bsm_domain = BSM_PF_NETBEUI,
b0d623f7 344#ifdef PF_NETBEUI
cb323159 345 .bd_local_domain = PF_NETBEUI
b0d623f7 346#else
cb323159 347 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
348#endif
349 },
cb323159 350 { .bd_bsm_domain = BSM_PF_SECURITY,
b0d623f7 351#ifdef PF_SECURITY
cb323159 352 .bd_local_domain = PF_SECURITY
b0d623f7 353#else
cb323159 354 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
355#endif
356 },
cb323159 357 { .bd_bsm_domain = BSM_PF_PACKET,
b0d623f7 358#ifdef PF_PACKET
cb323159 359 .bd_local_domain = PF_PACKET
b0d623f7 360#else
cb323159 361 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
362#endif
363 },
cb323159 364 { .bd_bsm_domain = BSM_PF_ASH,
b0d623f7 365#ifdef PF_ASH
cb323159 366 .bd_local_domain = PF_ASH
b0d623f7 367#else
cb323159 368 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
369#endif
370 },
cb323159 371 { .bd_bsm_domain = BSM_PF_ECONET,
b0d623f7 372#ifdef PF_ECONET
cb323159 373 .bd_local_domain = PF_ECONET
b0d623f7 374#else
cb323159 375 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
376#endif
377 },
cb323159 378 { .bd_bsm_domain = BSM_PF_ATMSVC,
b0d623f7 379#ifdef PF_ATMSVC
cb323159 380 .bd_local_domain = PF_ATMSVC
b0d623f7 381#else
cb323159 382 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
383#endif
384 },
cb323159 385 { .bd_bsm_domain = BSM_PF_IRDA,
b0d623f7 386#ifdef PF_IRDA
cb323159 387 .bd_local_domain = PF_IRDA
b0d623f7 388#else
cb323159 389 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
390#endif
391 },
cb323159 392 { .bd_bsm_domain = BSM_PF_PPPOX,
b0d623f7 393#ifdef PF_PPPOX
cb323159 394 .bd_local_domain = PF_PPPOX
b0d623f7 395#else
cb323159 396 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
397#endif
398 },
cb323159 399 { .bd_bsm_domain = BSM_PF_WANPIPE,
b0d623f7 400#ifdef PF_WANPIPE
cb323159 401 .bd_local_domain = PF_WANPIPE
b0d623f7 402#else
cb323159 403 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
404#endif
405 },
cb323159 406 { .bd_bsm_domain = BSM_PF_LLC,
b0d623f7 407#ifdef PF_LLC
cb323159 408 .bd_local_domain = PF_LLC
b0d623f7 409#else
cb323159 410 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
411#endif
412 },
cb323159 413 { .bd_bsm_domain = BSM_PF_CAN,
b0d623f7 414#ifdef PF_CAN
cb323159 415 .bd_local_domain = PF_CAN
b0d623f7 416#else
cb323159 417 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
418#endif
419 },
cb323159 420 { .bd_bsm_domain = BSM_PF_TIPC,
b0d623f7 421#ifdef PF_TIPC
cb323159 422 .bd_local_domain = PF_TIPC
b0d623f7 423#else
cb323159 424 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
425#endif
426 },
cb323159 427 { .bd_bsm_domain = BSM_PF_IUCV,
b0d623f7 428#ifdef PF_IUCV
cb323159 429 .bd_local_domain = PF_IUCV
b0d623f7 430#else
cb323159 431 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
432#endif
433 },
cb323159 434 { .bd_bsm_domain = BSM_PF_RXRPC,
b0d623f7 435#ifdef PF_RXRPC
cb323159 436 .bd_local_domain = PF_RXRPC
b0d623f7 437#else
cb323159 438 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
439#endif
440 },
cb323159 441 { .bd_bsm_domain = BSM_PF_PHONET,
b0d623f7 442#ifdef PF_PHONET
cb323159 443 .bd_local_domain = PF_PHONET
b0d623f7 444#else
cb323159 445 .bd_local_domain = PF_NO_LOCAL_MAPPING
b0d623f7
A
446#endif
447 },
448};
449static const int bsm_domains_count = sizeof(bsm_domains) /
0a7de745 450 sizeof(bsm_domains[0]);
b0d623f7
A
451
452static const struct bsm_domain *
453bsm_lookup_local_domain(int local_domain)
454{
455 int i;
456
457 for (i = 0; i < bsm_domains_count; i++) {
0a7de745
A
458 if (bsm_domains[i].bd_local_domain == local_domain) {
459 return &bsm_domains[i];
460 }
b0d623f7 461 }
0a7de745 462 return NULL;
b0d623f7
A
463}
464
465u_short
466au_domain_to_bsm(int local_domain)
467{
468 const struct bsm_domain *bstp;
469
470 bstp = bsm_lookup_local_domain(local_domain);
0a7de745
A
471 if (bstp == NULL) {
472 return BSM_PF_UNKNOWN;
473 }
474 return bstp->bd_bsm_domain;
b0d623f7
A
475}
476
477static const struct bsm_domain *
478bsm_lookup_bsm_domain(u_short bsm_domain)
479{
480 int i;
481
482 for (i = 0; i < bsm_domains_count; i++) {
0a7de745
A
483 if (bsm_domains[i].bd_bsm_domain == bsm_domain) {
484 return &bsm_domains[i];
485 }
b0d623f7 486 }
0a7de745 487 return NULL;
b0d623f7
A
488}
489
490int
491au_bsm_to_domain(u_short bsm_domain, int *local_domainp)
492{
493 const struct bsm_domain *bstp;
494
495 bstp = bsm_lookup_bsm_domain(bsm_domain);
0a7de745
A
496 if (bstp == NULL || bstp->bd_local_domain) {
497 return -1;
498 }
b0d623f7 499 *local_domainp = bstp->bd_local_domain;
0a7de745 500 return 0;
b0d623f7
A
501}
502#endif /* CONFIG_AUDIT */