1187214Srwatson/*- 2187214Srwatson * Copyright (c) 2008 Apple Inc. 3187214Srwatson * All rights reserved. 4187214Srwatson * 5187214Srwatson * Redistribution and use in source and binary forms, with or without 6187214Srwatson * modification, are permitted provided that the following conditions 7187214Srwatson * are met: 8187214Srwatson * 1. Redistributions of source code must retain the above copyright 9187214Srwatson * notice, this list of conditions and the following disclaimer. 10187214Srwatson * 2. Redistributions in binary form must reproduce the above copyright 11187214Srwatson * notice, this list of conditions and the following disclaimer in the 12187214Srwatson * documentation and/or other materials provided with the distribution. 13187214Srwatson * 3. Neither the name of Apple Inc. ("Apple") nor the names of 14187214Srwatson * its contributors may be used to endorse or promote products derived 15187214Srwatson * from this software without specific prior written permission. 16187214Srwatson * 17187214Srwatson * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND 18187214Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19187214Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20187214Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR 21187214Srwatson * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22187214Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23187214Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24187214Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25187214Srwatson * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26187214Srwatson * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27187214Srwatson * POSSIBILITY OF SUCH DAMAGE. 28187214Srwatson * 29191270Srwatson * P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_domain.c#3 30187214Srwatson */ 31187214Srwatson 32187214Srwatson#include <sys/cdefs.h> 33187214Srwatson__FBSDID("$FreeBSD$"); 34187214Srwatson 35187214Srwatson#include <sys/param.h> 36187214Srwatson#include <sys/socket.h> 37187214Srwatson 38187214Srwatson#include <security/audit/audit.h> 39187214Srwatson 40187214Srwatson#include <bsm/audit_domain.h> 41187214Srwatson#include <bsm/audit_record.h> 42187214Srwatson 43187214Srwatsonstruct bsm_domain { 44187214Srwatson u_short bd_bsm_domain; 45187214Srwatson int bd_local_domain; 46187214Srwatson}; 47187214Srwatson 48187214Srwatson#define PF_NO_LOCAL_MAPPING -600 49187214Srwatson 50187214Srwatsonstatic const struct bsm_domain bsm_domains[] = { 51187214Srwatson { BSM_PF_UNSPEC, PF_UNSPEC }, 52187214Srwatson { BSM_PF_LOCAL, PF_LOCAL }, 53187214Srwatson { BSM_PF_INET, PF_INET }, 54187214Srwatson { BSM_PF_IMPLINK, 55187214Srwatson#ifdef PF_IMPLINK 56187214Srwatson PF_IMPLINK 57187214Srwatson#else 58187214Srwatson PF_NO_LOCAL_MAPPING 59187214Srwatson#endif 60187214Srwatson }, 61187214Srwatson { BSM_PF_PUP, 62187214Srwatson#ifdef PF_PUP 63187214Srwatson PF_PUP 64187214Srwatson#else 65187214Srwatson PF_NO_LOCAL_MAPPING 66187214Srwatson#endif 67187214Srwatson }, 68187214Srwatson { BSM_PF_CHAOS, 69187214Srwatson#ifdef PF_CHAOS 70187214Srwatson PF_CHAOS 71187214Srwatson#else 72187214Srwatson PF_NO_LOCAL_MAPPING 73187214Srwatson#endif 74187214Srwatson }, 75187214Srwatson { BSM_PF_NS, 76187214Srwatson#ifdef PF_NS 77187214Srwatson PF_NS 78187214Srwatson#else 79187214Srwatson PF_NO_LOCAL_MAPPING 80187214Srwatson#endif 81187214Srwatson }, 82187214Srwatson { BSM_PF_NBS, 83187214Srwatson#ifdef PF_NBS 84187214Srwatson PF_NBS 85187214Srwatson#else 86187214Srwatson PF_NO_LOCAL_MAPPING 87187214Srwatson#endif 88187214Srwatson }, 89187214Srwatson { BSM_PF_ECMA, 90187214Srwatson#ifdef PF_ECMA 91187214Srwatson PF_ECMA 92187214Srwatson#else 93187214Srwatson PF_NO_LOCAL_MAPPING 94187214Srwatson#endif 95187214Srwatson }, 96187214Srwatson { BSM_PF_DATAKIT, 97187214Srwatson#ifdef PF_DATAKIT 98187214Srwatson PF_DATAKIT 99187214Srwatson#else 100187214Srwatson PF_NO_LOCAL_MAPPING 101187214Srwatson#endif 102187214Srwatson }, 103187214Srwatson { BSM_PF_CCITT, 104187214Srwatson#ifdef PF_CCITT 105187214Srwatson PF_CCITT 106187214Srwatson#else 107187214Srwatson PF_NO_LOCAL_MAPPING 108187214Srwatson#endif 109187214Srwatson }, 110187214Srwatson { BSM_PF_SNA, PF_SNA }, 111187214Srwatson { BSM_PF_DECnet, PF_DECnet }, 112187214Srwatson { BSM_PF_DLI, 113187214Srwatson#ifdef PF_DLI 114187214Srwatson PF_DLI 115187214Srwatson#else 116187214Srwatson PF_NO_LOCAL_MAPPING 117187214Srwatson#endif 118187214Srwatson }, 119187214Srwatson { BSM_PF_LAT, 120187214Srwatson#ifdef PF_LAT 121187214Srwatson PF_LAT 122187214Srwatson#else 123187214Srwatson PF_NO_LOCAL_MAPPING 124187214Srwatson#endif 125187214Srwatson }, 126187214Srwatson { BSM_PF_HYLINK, 127187214Srwatson#ifdef PF_HYLINK 128187214Srwatson PF_HYLINK 129187214Srwatson#else 130187214Srwatson PF_NO_LOCAL_MAPPING 131187214Srwatson#endif 132187214Srwatson }, 133187214Srwatson { BSM_PF_APPLETALK, PF_APPLETALK }, 134187214Srwatson { BSM_PF_NIT, 135187214Srwatson#ifdef PF_NIT 136187214Srwatson PF_NIT 137187214Srwatson#else 138187214Srwatson PF_NO_LOCAL_MAPPING 139187214Srwatson#endif 140187214Srwatson }, 141187214Srwatson { BSM_PF_802, 142187214Srwatson#ifdef PF_802 143187214Srwatson PF_802 144187214Srwatson#else 145187214Srwatson PF_NO_LOCAL_MAPPING 146187214Srwatson#endif 147187214Srwatson }, 148187214Srwatson { BSM_PF_OSI, 149187214Srwatson#ifdef PF_OSI 150187214Srwatson PF_OSI 151187214Srwatson#else 152187214Srwatson PF_NO_LOCAL_MAPPING 153187214Srwatson#endif 154187214Srwatson }, 155187214Srwatson { BSM_PF_X25, 156187214Srwatson#ifdef PF_X25 157187214Srwatson PF_X25 158187214Srwatson#else 159187214Srwatson PF_NO_LOCAL_MAPPING 160187214Srwatson#endif 161187214Srwatson }, 162187214Srwatson { BSM_PF_OSINET, 163187214Srwatson#ifdef PF_OSINET 164187214Srwatson PF_OSINET 165187214Srwatson#else 166187214Srwatson PF_NO_LOCAL_MAPPING 167187214Srwatson#endif 168187214Srwatson }, 169187214Srwatson { BSM_PF_GOSIP, 170187214Srwatson#ifdef PF_GOSIP 171187214Srwatson PF_GOSIP 172187214Srwatson#else 173187214Srwatson PF_NO_LOCAL_MAPPING 174187214Srwatson#endif 175187214Srwatson }, 176187214Srwatson { BSM_PF_IPX, PF_IPX }, 177187214Srwatson { BSM_PF_ROUTE, PF_ROUTE }, 178187214Srwatson { BSM_PF_LINK, 179187214Srwatson#ifdef PF_LINK 180187214Srwatson PF_LINK 181187214Srwatson#else 182187214Srwatson PF_NO_LOCAL_MAPPING 183187214Srwatson#endif 184187214Srwatson }, 185187214Srwatson { BSM_PF_INET6, PF_INET6 }, 186187214Srwatson { BSM_PF_KEY, PF_KEY }, 187187214Srwatson { BSM_PF_NCA, 188187214Srwatson#ifdef PF_NCA 189187214Srwatson PF_NCA 190187214Srwatson#else 191187214Srwatson PF_NO_LOCAL_MAPPING 192187214Srwatson#endif 193187214Srwatson }, 194187214Srwatson { BSM_PF_POLICY, 195187214Srwatson#ifdef PF_POLICY 196187214Srwatson PF_POLICY 197187214Srwatson#else 198187214Srwatson PF_NO_LOCAL_MAPPING 199187214Srwatson#endif 200187214Srwatson }, 201187214Srwatson { BSM_PF_INET_OFFLOAD, 202187214Srwatson#ifdef PF_INET_OFFLOAD 203187214Srwatson PF_INET_OFFLOAD 204187214Srwatson#else 205187214Srwatson PF_NO_LOCAL_MAPPING 206187214Srwatson#endif 207187214Srwatson }, 208187214Srwatson { BSM_PF_NETBIOS, 209187214Srwatson#ifdef PF_NETBIOS 210187214Srwatson PF_NETBIOS 211187214Srwatson#else 212187214Srwatson PF_NO_LOCAL_MAPPING 213187214Srwatson#endif 214187214Srwatson }, 215187214Srwatson { BSM_PF_ISO, 216187214Srwatson#ifdef PF_ISO 217187214Srwatson PF_ISO 218187214Srwatson#else 219187214Srwatson PF_NO_LOCAL_MAPPING 220187214Srwatson#endif 221187214Srwatson }, 222187214Srwatson { BSM_PF_XTP, 223187214Srwatson#ifdef PF_XTP 224187214Srwatson PF_XTP 225187214Srwatson#else 226187214Srwatson PF_NO_LOCAL_MAPPING 227187214Srwatson#endif 228187214Srwatson }, 229187214Srwatson { BSM_PF_COIP, 230187214Srwatson#ifdef PF_COIP 231187214Srwatson PF_COIP 232187214Srwatson#else 233187214Srwatson PF_NO_LOCAL_MAPPING 234187214Srwatson#endif 235187214Srwatson }, 236187214Srwatson { BSM_PF_CNT, 237187214Srwatson#ifdef PF_CNT 238187214Srwatson PF_CNT 239187214Srwatson#else 240187214Srwatson PF_NO_LOCAL_MAPPING 241187214Srwatson#endif 242187214Srwatson }, 243187214Srwatson { BSM_PF_RTIP, 244187214Srwatson#ifdef PF_RTIP 245187214Srwatson PF_RTIP 246187214Srwatson#else 247187214Srwatson PF_NO_LOCAL_MAPPING 248187214Srwatson#endif 249187214Srwatson }, 250187214Srwatson { BSM_PF_SIP, 251187214Srwatson#ifdef PF_SIP 252187214Srwatson PF_SIP 253187214Srwatson#else 254187214Srwatson PF_NO_LOCAL_MAPPING 255187214Srwatson#endif 256187214Srwatson }, 257187214Srwatson { BSM_PF_PIP, 258187214Srwatson#ifdef PF_PIP 259187214Srwatson PF_PIP 260187214Srwatson#else 261187214Srwatson PF_NO_LOCAL_MAPPING 262187214Srwatson#endif 263187214Srwatson }, 264187214Srwatson { BSM_PF_ISDN, 265187214Srwatson#ifdef PF_ISDN 266187214Srwatson PF_ISDN 267187214Srwatson#else 268187214Srwatson PF_NO_LOCAL_MAPPING 269187214Srwatson#endif 270187214Srwatson }, 271187214Srwatson { BSM_PF_E164, 272187214Srwatson#ifdef PF_E164 273187214Srwatson PF_E164 274187214Srwatson#else 275187214Srwatson PF_NO_LOCAL_MAPPING 276187214Srwatson#endif 277187214Srwatson }, 278187214Srwatson { BSM_PF_NATM, 279187214Srwatson#ifdef PF_NATM 280187214Srwatson PF_NATM 281187214Srwatson#else 282187214Srwatson PF_NO_LOCAL_MAPPING 283187214Srwatson#endif 284187214Srwatson }, 285187214Srwatson { BSM_PF_ATM, 286187214Srwatson#ifdef PF_ATM 287187214Srwatson PF_ATM 288187214Srwatson#else 289187214Srwatson PF_NO_LOCAL_MAPPING 290187214Srwatson#endif 291187214Srwatson }, 292187214Srwatson { BSM_PF_NETGRAPH, 293187214Srwatson#ifdef PF_NETGRAPH 294187214Srwatson PF_NETGRAPH 295187214Srwatson#else 296187214Srwatson PF_NO_LOCAL_MAPPING 297187214Srwatson#endif 298187214Srwatson }, 299187214Srwatson { BSM_PF_SLOW, 300187214Srwatson#ifdef PF_SLOW 301187214Srwatson PF_SLOW 302187214Srwatson#else 303187214Srwatson PF_NO_LOCAL_MAPPING 304187214Srwatson#endif 305187214Srwatson }, 306187214Srwatson { BSM_PF_SCLUSTER, 307187214Srwatson#ifdef PF_SCLUSTER 308187214Srwatson PF_SCLUSTER 309187214Srwatson#else 310187214Srwatson PF_NO_LOCAL_MAPPING 311187214Srwatson#endif 312187214Srwatson }, 313187214Srwatson { BSM_PF_ARP, 314187214Srwatson#ifdef PF_ARP 315187214Srwatson PF_ARP 316187214Srwatson#else 317187214Srwatson PF_NO_LOCAL_MAPPING 318187214Srwatson#endif 319187214Srwatson }, 320187214Srwatson { BSM_PF_BLUETOOTH, 321187214Srwatson#ifdef PF_BLUETOOTH 322187214Srwatson PF_BLUETOOTH 323187214Srwatson#else 324187214Srwatson PF_NO_LOCAL_MAPPING 325187214Srwatson#endif 326187214Srwatson }, 327187214Srwatson { BSM_PF_AX25, 328187214Srwatson#ifdef PF_AX25 329187214Srwatson PF_AX25 330187214Srwatson#else 331187214Srwatson PF_NO_LOCAL_MAPPING 332187214Srwatson#endif 333187214Srwatson }, 334187214Srwatson { BSM_PF_ROSE, 335187214Srwatson#ifdef PF_ROSE 336187214Srwatson PF_ROSE 337187214Srwatson#else 338187214Srwatson PF_NO_LOCAL_MAPPING 339187214Srwatson#endif 340187214Srwatson }, 341187214Srwatson { BSM_PF_NETBEUI, 342187214Srwatson#ifdef PF_NETBEUI 343187214Srwatson PF_NETBEUI 344187214Srwatson#else 345187214Srwatson PF_NO_LOCAL_MAPPING 346187214Srwatson#endif 347187214Srwatson }, 348187214Srwatson { BSM_PF_SECURITY, 349187214Srwatson#ifdef PF_SECURITY 350187214Srwatson PF_SECURITY 351187214Srwatson#else 352187214Srwatson PF_NO_LOCAL_MAPPING 353187214Srwatson#endif 354187214Srwatson }, 355187214Srwatson { BSM_PF_PACKET, 356187214Srwatson#ifdef PF_PACKET 357187214Srwatson PF_PACKET 358187214Srwatson#else 359187214Srwatson PF_NO_LOCAL_MAPPING 360187214Srwatson#endif 361187214Srwatson }, 362187214Srwatson { BSM_PF_ASH, 363187214Srwatson#ifdef PF_ASH 364187214Srwatson PF_ASH 365187214Srwatson#else 366187214Srwatson PF_NO_LOCAL_MAPPING 367187214Srwatson#endif 368187214Srwatson }, 369187214Srwatson { BSM_PF_ECONET, 370187214Srwatson#ifdef PF_ECONET 371187214Srwatson PF_ECONET 372187214Srwatson#else 373187214Srwatson PF_NO_LOCAL_MAPPING 374187214Srwatson#endif 375187214Srwatson }, 376187214Srwatson { BSM_PF_ATMSVC, 377187214Srwatson#ifdef PF_ATMSVC 378187214Srwatson PF_ATMSVC 379187214Srwatson#else 380187214Srwatson PF_NO_LOCAL_MAPPING 381187214Srwatson#endif 382187214Srwatson }, 383187214Srwatson { BSM_PF_IRDA, 384187214Srwatson#ifdef PF_IRDA 385187214Srwatson PF_IRDA 386187214Srwatson#else 387187214Srwatson PF_NO_LOCAL_MAPPING 388187214Srwatson#endif 389187214Srwatson }, 390187214Srwatson { BSM_PF_PPPOX, 391187214Srwatson#ifdef PF_PPPOX 392187214Srwatson PF_PPPOX 393187214Srwatson#else 394187214Srwatson PF_NO_LOCAL_MAPPING 395187214Srwatson#endif 396187214Srwatson }, 397187214Srwatson { BSM_PF_WANPIPE, 398187214Srwatson#ifdef PF_WANPIPE 399187214Srwatson PF_WANPIPE 400187214Srwatson#else 401187214Srwatson PF_NO_LOCAL_MAPPING 402187214Srwatson#endif 403187214Srwatson }, 404187214Srwatson { BSM_PF_LLC, 405187214Srwatson#ifdef PF_LLC 406187214Srwatson PF_LLC 407187214Srwatson#else 408187214Srwatson PF_NO_LOCAL_MAPPING 409187214Srwatson#endif 410187214Srwatson }, 411187214Srwatson { BSM_PF_CAN, 412187214Srwatson#ifdef PF_CAN 413187214Srwatson PF_CAN 414187214Srwatson#else 415187214Srwatson PF_NO_LOCAL_MAPPING 416187214Srwatson#endif 417187214Srwatson }, 418187214Srwatson { BSM_PF_TIPC, 419187214Srwatson#ifdef PF_TIPC 420187214Srwatson PF_TIPC 421187214Srwatson#else 422187214Srwatson PF_NO_LOCAL_MAPPING 423187214Srwatson#endif 424187214Srwatson }, 425187214Srwatson { BSM_PF_IUCV, 426187214Srwatson#ifdef PF_IUCV 427187214Srwatson PF_IUCV 428187214Srwatson#else 429187214Srwatson PF_NO_LOCAL_MAPPING 430187214Srwatson#endif 431187214Srwatson }, 432187214Srwatson { BSM_PF_RXRPC, 433187214Srwatson#ifdef PF_RXRPC 434187214Srwatson PF_RXRPC 435187214Srwatson#else 436187214Srwatson PF_NO_LOCAL_MAPPING 437187214Srwatson#endif 438187214Srwatson }, 439187214Srwatson { BSM_PF_PHONET, 440187214Srwatson#ifdef PF_PHONET 441187214Srwatson PF_PHONET 442187214Srwatson#else 443187214Srwatson PF_NO_LOCAL_MAPPING 444187214Srwatson#endif 445187214Srwatson }, 446187214Srwatson}; 447187214Srwatsonstatic const int bsm_domains_count = sizeof(bsm_domains) / 448187214Srwatson sizeof(bsm_domains[0]); 449187214Srwatson 450187214Srwatsonstatic const struct bsm_domain * 451187214Srwatsonbsm_lookup_local_domain(int local_domain) 452187214Srwatson{ 453187214Srwatson int i; 454187214Srwatson 455187214Srwatson for (i = 0; i < bsm_domains_count; i++) { 456187214Srwatson if (bsm_domains[i].bd_local_domain == local_domain) 457187214Srwatson return (&bsm_domains[i]); 458187214Srwatson } 459187214Srwatson return (NULL); 460187214Srwatson} 461187214Srwatson 462187214Srwatsonu_short 463187214Srwatsonau_domain_to_bsm(int local_domain) 464187214Srwatson{ 465187214Srwatson const struct bsm_domain *bstp; 466187214Srwatson 467187214Srwatson bstp = bsm_lookup_local_domain(local_domain); 468187214Srwatson if (bstp == NULL) 469187214Srwatson return (BSM_PF_UNKNOWN); 470187214Srwatson return (bstp->bd_bsm_domain); 471187214Srwatson} 472187214Srwatson 473187214Srwatsonstatic const struct bsm_domain * 474187214Srwatsonbsm_lookup_bsm_domain(u_short bsm_domain) 475187214Srwatson{ 476187214Srwatson int i; 477187214Srwatson 478187214Srwatson for (i = 0; i < bsm_domains_count; i++) { 479187214Srwatson if (bsm_domains[i].bd_bsm_domain == bsm_domain) 480187214Srwatson return (&bsm_domains[i]); 481187214Srwatson } 482187214Srwatson return (NULL); 483187214Srwatson} 484187214Srwatson 485187214Srwatsonint 486187214Srwatsonau_bsm_to_domain(u_short bsm_domain, int *local_domainp) 487187214Srwatson{ 488187214Srwatson const struct bsm_domain *bstp; 489187214Srwatson 490187214Srwatson bstp = bsm_lookup_bsm_domain(bsm_domain); 491187214Srwatson if (bstp == NULL || bstp->bd_local_domain) 492187214Srwatson return (-1); 493187214Srwatson *local_domainp = bstp->bd_local_domain; 494187214Srwatson return (0); 495187214Srwatson} 496