2 * Copyright (c) 2018 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #import <Foundation/Foundation.h>
25 #import <EventFactory/EventFactory.h>
27 #import "KernelEventMonitorParser.h"
29 #define TokenStatus "status"
30 #define TokenLinkStatus "linkStatus"
31 #define TokenLinkQuality "linkQuality"
33 @implementation KernelEventMonitorParser
37 NSArray<EFLogEventMatch *> *matches = @[
38 [[EFLogEventMatch alloc] initWithPattern:@"Process interface (?<"TokenStatus">attach|detach): (?<"TokenInterfaceName">\\w+)"
40 ^EFEvent *(NSTextCheckingResult *matchResult, EFLogEvent *logEvent, BOOL *isComplete) {
42 EFNetworkControlPathEvent *newEvent = nil;
43 NSString *statusString = [logEvent substringForCaptureGroup:@TokenStatus inMatchResult:matchResult];
44 if (statusString != nil) {
45 newEvent = [self createInterfaceEventWithLogEvent:logEvent matchResult:matchResult];
46 if (newEvent != nil) {
47 newEvent.interfaceStatus = statusString;
52 [[EFLogEventMatch alloc] initWithPattern:@"Process interface link (?<"TokenLinkStatus">down|up): (?<"TokenInterfaceName">\\w+)"
54 ^EFEvent *(NSTextCheckingResult *matchResult, EFLogEvent *logEvent, BOOL *isComplete) {
56 EFNetworkControlPathEvent *newEvent = nil;
57 NSString *linkStatusString = [logEvent substringForCaptureGroup:@TokenLinkStatus inMatchResult:matchResult];
58 if (linkStatusString != nil) {
59 newEvent = [self createInterfaceEventWithLogEvent:logEvent matchResult:matchResult];
60 if (newEvent != nil) {
61 if ([linkStatusString isEqualToString:@"up"]) {
62 newEvent.link = @"link up";
63 } else if ([linkStatusString isEqualToString:@"down"]) {
64 newEvent.link = @"link down";
66 newEvent.link = linkStatusString;
72 [[EFLogEventMatch alloc] initWithPattern:@"Process interface quality: (?<"TokenInterfaceName">\\w+) \\(q=(?<"TokenLinkQuality">[-\\d]+)\\)"
74 ^EFEvent * _Nullable(NSTextCheckingResult * _Nonnull matchResult, EFLogEvent * _Nonnull logEvent, BOOL * _Nonnull isComplete) {
76 EFNetworkControlPathEvent *newEvent = nil;
77 NSString *qualityString = [logEvent substringForCaptureGroup:@TokenLinkQuality inMatchResult:matchResult];
78 if (qualityString != nil) {
79 newEvent = [self createInterfaceEventWithLogEvent:logEvent matchResult:matchResult];
80 if (newEvent != nil) {
81 newEvent.linkQuality = qualityString.integerValue;
87 EFLogEventParser *parser = [[EFLogEventParser alloc] initWithMatches:matches];
88 return [super initWithCategory:@"KernelEventMonitor" eventParser:parser];