2 * Copyright (c) 2008 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 #include <sys/types.h>
27 #include "ipsecPolicyTracer.h"
28 #include "ipsecMessageTracer.h"
30 const char *ipsecConfigTracerFailedString
= "Tracer Failed";
31 const char *ipsecPolicyInvalidEventString
= "Invalid Event";
32 const char *ipsecPolicyString
= "IPSEC";
34 const char * const ipsecPolicyEventStrings
[IPSECPOLICYEVENTCODE_MAX
] = { CONSTSTR("NONE") /* index place holder */,
35 CONSTSTR("setkey Error"),
39 ipsecPolicyEventCodeToString (ipsecPolicyEventCode_t eventCode
)
41 if (eventCode
<= IPSECPOLICYEVENTCODE_NONE
|| eventCode
>= IPSECPOLICYEVENTCODE_MAX
)
42 return ipsecPolicyInvalidEventString
;
43 return(ipsecPolicyEventStrings
[eventCode
]);
48 ipsecPolicyLogEvent (const char *event_msg
, const char *failure_signature
)
56 m
= asl_new(ASL_TYPE_MSG
);
57 asl_set(m
, ASL_KEY_FACILITY
, PLAINIPSECDOMAIN
);
58 asl_set(m
, ASL_KEY_MSG
, ipsecPolicyString
);
59 #if 0 /* we don't want to send filenames to MessageTracer server */
60 if (failure_signature
) {
61 asl_set(m
, "com.apple.message.domain", PLAINIPSECDOMAIN
);
62 asl_set(m
, "com.apple.message.result", "failure"); // failure
63 asl_set(m
, "com.apple.message.signature", failure_signature
);
65 asl_log(NULL
, m
, ASL_LEVEL_NOTICE
, "%s", event_msg
);
67 if (failure_signature
) {
68 asl_log(NULL
, m
, ASL_LEVEL_NOTICE
, "%s (failure: %s)", event_msg
, failure_signature
);
70 asl_log(NULL
, m
, ASL_LEVEL_NOTICE
, "%s", event_msg
);
77 ipsecPolicyTracerEvent (const char *filename
, ipsecPolicyEventCode_t eventCode
, const char *event
, const char *failure_reason
)
81 if (filename
== NULL
) {
82 ipsecPolicyLogEvent(CONSTSTR("tracer failed. (Invalid filename)."), ipsecConfigTracerFailedString
);
85 if (eventCode
<= IPSECPOLICYEVENTCODE_NONE
|| eventCode
>= IPSECPOLICYEVENTCODE_MAX
) {
86 ipsecPolicyLogEvent(CONSTSTR("tracer failed. (Invalid event code)."), ipsecConfigTracerFailedString
);
90 ipsecPolicyLogEvent(CONSTSTR("tracer failed. (Invalid event)."), ipsecConfigTracerFailedString
);
95 snprintf(buf
, sizeof(buf
), "%s. (%s, filename %s).", ipsecPolicyEventCodeToString(eventCode
), failure_reason
, filename
);
96 ipsecPolicyLogEvent(CONSTSTR(buf
), event
);