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>
26 #import "IPConfigurationParser.h"
28 #define TokenLinkStatus "linkStatus"
29 #define TokenSSID "ssid"
30 #define TokenMessage "message"
31 #define TokenAddress "address"
32 #define TokenComponentName "component"
34 @implementation IPConfigurationParser
38 NSArray<EFLogEventMatch *> *matches = @[
39 [[EFLogEventMatch alloc] initWithPattern:@"(?<"TokenInterfaceName">\\w+) link (?<"TokenLinkStatus">ACTIVE|INACTIVE)"
41 ^EFEvent *(NSTextCheckingResult *matchResult, EFLogEvent *logEvent, BOOL *isComplete) {
42 NSString *statusString = [logEvent substringForCaptureGroup:@TokenLinkStatus inMatchResult:matchResult];
43 EFNetworkControlPathEvent *newEvent = [self createInterfaceEventWithLogEvent:logEvent matchResult:matchResult];
44 if ([statusString isEqualToString:@"ACTIVE"]) {
45 newEvent.link = @"link up";
47 newEvent.link = @"link down";
52 [[EFLogEventMatch alloc] initWithPattern:@"(?<"TokenInterfaceName">\\w+): SSID (?<"TokenSSID">\\S+) BSSID"
54 ^EFEvent *(NSTextCheckingResult *matchResult, EFLogEvent *logEvent, BOOL *isComplete) {
55 NSString *ssid = [logEvent substringForCaptureGroup:@TokenSSID inMatchResult:matchResult];
56 EFNetworkControlPathEvent *newEvent = [self createInterfaceEventWithLogEvent:logEvent matchResult:matchResult];
57 EFSubEvent *subEvent = [[EFSubEvent alloc] initWithTimestamp:logEvent.date textDescription:ssid];
58 [newEvent addSubEvent:subEvent];
62 [[EFLogEventMatch alloc] initWithPattern:@"\\[(?<"TokenComponentName">\\w+ )?(?<"TokenInterfaceName">\\w+)\\] (?<"TokenMessage">(?:Transmit|Receive) \\d+ byte packet xid \\w+ (?:to|from) .*)"
64 ^EFEvent *(NSTextCheckingResult *matchResult, EFLogEvent *logEvent, BOOL *isComplete) {
65 NSString *message = [logEvent substringForCaptureGroup:@TokenMessage inMatchResult:matchResult];
66 NSString *component = [logEvent substringForCaptureGroup:@TokenComponentName inMatchResult:matchResult];
67 EFNetworkControlPathEvent *newEvent = [self createInterfaceEventWithLogEvent:logEvent matchResult:matchResult];
68 NSString *description = [[NSString alloc] initWithFormat:@"%@ %@", component, message];
69 EFSubEvent *subEvent = [[EFSubEvent alloc] initWithTimestamp:logEvent.date textDescription:description];
70 [newEvent addSubEvent:subEvent];
74 [[EFLogEventMatch alloc] initWithPattern:@"\\w+ (?<"TokenInterfaceName">\\w+): setting (?<"TokenAddress">\\S+) netmask \\S+ broadcast \\S+"
76 ^EFEvent *(NSTextCheckingResult *matchResult, EFLogEvent *logEvent, BOOL *isComplete) {
78 NSString *addressString = [logEvent substringForCaptureGroup:@TokenAddress inMatchResult:matchResult];
79 if (addressString.length > 0) {
80 EFNetworkControlPathEvent *newEvent = [self createInterfaceEventWithLogEvent:logEvent matchResult:matchResult];
81 [self addAddress:addressString toInterfaceEvent:newEvent];
86 [[EFLogEventMatch alloc] initWithPattern:@"\\w+ (?<"TokenInterfaceName">\\w+): removing (?<"TokenAddress">.+)"
88 ^EFEvent *(NSTextCheckingResult *matchResult, EFLogEvent *logEvent, BOOL *isComplete) {
90 NSString *addressString = [logEvent substringForCaptureGroup:@TokenAddress inMatchResult:matchResult];
91 if (addressString.length > 0) {
92 EFNetworkControlPathEvent *newEvent = [self createInterfaceEventWithLogEvent:logEvent matchResult:matchResult];
93 if ([self removeAddress:addressString fromInterfaceEvent:newEvent]) {
101 EFLogEventParser *parser = [[EFLogEventParser alloc] initWithMatches:matches];
102 return [super initWithCategory:@"IPConfiguration" eventParser:parser];