]> git.saurik.com Git - apple/configd.git/blob - EventFactory/IPConfigurationParser.m
configd-1061.40.2.tar.gz
[apple/configd.git] / EventFactory / IPConfigurationParser.m
1 /*
2 * Copyright (c) 2018 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #import <Foundation/Foundation.h>
25 #import <EventFactory/EventFactory.h>
26 #import "IPConfigurationParser.h"
27
28 #define TokenLinkStatus "linkStatus"
29 #define TokenSSID "ssid"
30 #define TokenMessage "message"
31 #define TokenAddress "address"
32 #define TokenComponentName "component"
33
34 @implementation IPConfigurationParser
35
36 - (instancetype)init
37 {
38 NSArray<EFLogEventMatch *> *matches = @[
39 [[EFLogEventMatch alloc] initWithPattern:@"(?<"TokenInterfaceName">\\w+) link (?<"TokenLinkStatus">ACTIVE|INACTIVE)"
40 newEventHandler:
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";
46 } else {
47 newEvent.link = @"link down";
48 }
49 *isComplete = YES;
50 return newEvent;
51 }],
52 [[EFLogEventMatch alloc] initWithPattern:@"(?<"TokenInterfaceName">\\w+): SSID (?<"TokenSSID">\\S+) BSSID"
53 newEventHandler:
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];
59 *isComplete = YES;
60 return newEvent;
61 }],
62 [[EFLogEventMatch alloc] initWithPattern:@"\\[(?<"TokenComponentName">\\w+ )?(?<"TokenInterfaceName">\\w+)\\] (?<"TokenMessage">(?:Transmit|Receive) \\d+ byte packet xid \\w+ (?:to|from) .*)"
63 newEventHandler:
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];
71 *isComplete = YES;
72 return newEvent;
73 }],
74 [[EFLogEventMatch alloc] initWithPattern:@"\\w+ (?<"TokenInterfaceName">\\w+): setting (?<"TokenAddress">\\S+) netmask \\S+ broadcast \\S+"
75 newEventHandler:
76 ^EFEvent *(NSTextCheckingResult *matchResult, EFLogEvent *logEvent, BOOL *isComplete) {
77 *isComplete = YES;
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];
82 return newEvent;
83 }
84 return nil;
85 }],
86 [[EFLogEventMatch alloc] initWithPattern:@"\\w+ (?<"TokenInterfaceName">\\w+): removing (?<"TokenAddress">.+)"
87 newEventHandler:
88 ^EFEvent *(NSTextCheckingResult *matchResult, EFLogEvent *logEvent, BOOL *isComplete) {
89 *isComplete = YES;
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]) {
94 return newEvent;
95 }
96 }
97 return nil;
98 }]
99 ];
100
101 EFLogEventParser *parser = [[EFLogEventParser alloc] initWithMatches:matches];
102 return [super initWithCategory:@"IPConfiguration" eventParser:parser];
103 }
104
105 @end