]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCNetworkConfigurationInternal.h
configd-1061.120.2.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCNetworkConfigurationInternal.h
1 /*
2 * Copyright (c) 2004-2020 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 #ifndef _SCNETWORKCONFIGURATIONINTERNAL_H
25 #define _SCNETWORKCONFIGURATIONINTERNAL_H
26
27 #include <TargetConditionals.h>
28 #include <CoreFoundation/CoreFoundation.h>
29 #include <CoreFoundation/CFRuntime.h>
30
31 #ifndef SC_LOG_HANDLE
32 #define SC_LOG_HANDLE __log_SCNetworkConfiguration
33 #endif // SC_LOG_HANDLE
34 #include <SystemConfiguration/SystemConfiguration.h>
35 #include <SystemConfiguration/SCPrivate.h>
36 #include <SystemConfiguration/SCValidation.h>
37 #include "SCPreferencesPathKey.h"
38 #include "IPMonitorControl.h"
39 #include <IOKit/IOKitLib.h>
40
41
42 #define NETWORK_CONFIGURATION_VERSION 20191120
43
44
45 typedef struct {
46
47 // base CFType information
48 CFRuntimeBase cfBase;
49
50 // set id
51 CFStringRef setID;
52
53 // prefs
54 SCPreferencesRef prefs;
55
56 // name
57 CFStringRef name;
58
59 // misc
60 Boolean established;
61
62 } SCNetworkSetPrivate, *SCNetworkSetPrivateRef;
63
64
65 typedef struct {
66
67 // base CFType information
68 CFRuntimeBase cfBase;
69
70 // service id
71 CFStringRef serviceID;
72
73 // interface
74 SCNetworkInterfaceRef interface;
75
76 // prefs
77 SCPreferencesRef prefs;
78
79 // store (for live SCNetworkService)
80 SCDynamicStoreRef store;
81
82 // name
83 CFStringRef name;
84
85 // external identifiers
86 CFMutableDictionaryRef externalIDs;
87
88 } SCNetworkServicePrivate, *SCNetworkServicePrivateRef;
89
90
91 typedef struct {
92
93 // base CFType information
94 CFRuntimeBase cfBase;
95
96 // entity id
97 CFStringRef entityID;
98
99 // service
100 SCNetworkServiceRef service;
101
102 } SCNetworkProtocolPrivate, *SCNetworkProtocolPrivateRef;
103
104
105 typedef struct {
106
107 // base CFType information
108 CFRuntimeBase cfBase;
109
110 // interface information
111 CFStringRef interface_type; // interface type
112
113 Boolean active;
114
115 // [non-localized] name
116 CFStringRef name; // non-localized [display] name
117
118 // localized name
119 CFStringRef localized_name; // localized [display] name
120 CFStringRef localized_key;
121 CFStringRef localized_arg1;
122 CFStringRef localized_arg2;
123
124 // [layered] interface
125 SCNetworkInterfaceRef interface;
126
127 // prefs (for associated service, BOND interfaces, and VLAN interfaces)
128 SCPreferencesRef prefs;
129
130 // SCDynamicStore
131 SCDynamicStoreRef store;
132
133 // serviceID (NULL if not associated with a service)
134 CFStringRef serviceID;
135
136 // unsaved configuration (when prefs not [yet] available)
137 CFMutableDictionaryRef unsaved;
138
139 // [SCPreferences] interface entity information
140 CFStringRef entity_device; // interface device
141 CFStringRef entity_device_unique; // ... UniqueIdentifier
142 CFStringRef entity_type; // interface type
143 CFStringRef entity_subtype; // interface subtype
144
145 // configuration information
146 CFMutableArrayRef supported_interface_types;
147 CFMutableArrayRef supported_protocol_types;
148
149 // IORegistry (service plane) information
150 CFDataRef address;
151 CFStringRef addressString;
152 Boolean builtin;
153 CFStringRef configurationAction;
154 Boolean hidden;
155 CFStringRef location;
156 CFStringRef path;
157 uint64_t entryID;
158 CFMutableDictionaryRef overrides;
159 CFStringRef prefix;
160 Boolean trustRequired;
161 CFNumberRef type;
162 CFNumberRef unit;
163 CFNumberRef family;
164 CFNumberRef subfamily;
165 struct {
166 CFStringRef name;
167 CFNumberRef vid;
168 CFNumberRef pid;
169 } usb;
170
171 // misc
172 CFArrayRef matchingMACs;
173 unsigned int sort_order; // sort order for this interface
174
175 // for BOND interfaces
176 Boolean supportsBond;
177 struct {
178 CFArrayRef interfaces;
179 CFNumberRef mode;
180 CFDictionaryRef options;
181 } bond;
182
183 // for Bridge interfaces
184 Boolean supportsBridge;
185 struct {
186 CFArrayRef interfaces;
187 CFDictionaryRef options;
188 } bridge;
189
190 // for VLAN interfaces
191 Boolean supportsVLAN;
192 struct {
193 SCNetworkInterfaceRef interface;
194 CFNumberRef tag; // e.g. 1 <= tag <= 4094
195 CFDictionaryRef options;
196 } vlan;
197
198 // for interface rank assertions
199 IPMonitorControlRef IPMonitorControl;
200
201 } SCNetworkInterfacePrivate, *SCNetworkInterfacePrivateRef;
202
203
204 __BEGIN_DECLS
205
206 #pragma mark -
207 #pragma mark SCNetworkConfiguration (internal)
208
209
210 Boolean
211 __SCNetworkConfigurationBackup (SCPreferencesRef prefs) SPI_AVAILABLE(macos(10.15.4), ios(13.4), tvos(13.4), watchos(6.2), bridgeos(4.0));
212
213
214 #pragma mark -
215 #pragma mark SCNetworkInterface configuration (internal)
216
217
218 Boolean
219 __SCNetworkInterfaceMatchesName (CFStringRef name,
220 CFStringRef key);
221
222 CFArrayRef
223 __SCNetworkInterfaceCopyAll_IONetworkInterface (Boolean keep_pre_configured);
224
225 /*!
226 @function __SCNetworkInterfaceCopyStoredWithPreferences
227 @discussion Create an array of network interfaces, which is present in the preferences
228 in NetworkInteraces.plist
229 @param ni_prefs Preference for network interfaces
230 @result Array which contains SCNetworkInterfaceRef.
231 You must release the returned value.
232 */
233
234 CFArrayRef // SCNetworkInterfaceRef
235 __SCNetworkInterfaceCopyStoredWithPreferences (SCPreferencesRef ni_prefs);
236
237 SCNetworkInterfacePrivateRef
238 __SCNetworkInterfaceCreateCopy (CFAllocatorRef allocator,
239 SCNetworkInterfaceRef interface,
240 SCPreferencesRef prefs,
241 CFStringRef serviceID);
242
243 /*!
244 @function __SCNetworkInterfaceCreateMappingUsingBSDName
245 @discussion This function creates mapping of BSD name and network interface using
246 preferences which point to the NetworkInterfaces.plist file.
247 @param interfaces An array of network interfaces to use for the mapping.
248 @result BSD Mapping in a dictionary.
249 You must release the returned value.
250 */
251 CFDictionaryRef
252 __SCNetworkInterfaceCreateMappingUsingBSDName (CFArrayRef interfaces);
253
254 SCNetworkInterfaceRef
255 __SCNetworkInterfaceCreateWithNIPreferencesUsingBSDName(CFAllocatorRef allocator,
256 SCPreferencesRef ni_prefs,
257 CFStringRef bsdName);
258
259 SCNetworkInterfacePrivateRef
260 __SCNetworkInterfaceCreatePrivate (CFAllocatorRef allocator,
261 SCNetworkInterfaceRef interface,
262 SCPreferencesRef prefs,
263 CFStringRef serviceID);
264
265 SCNetworkInterfacePrivateRef
266 _SCBondInterfaceCreatePrivate (CFAllocatorRef allocator,
267 CFStringRef bond_if);
268
269 SCNetworkInterfacePrivateRef
270 _SCBridgeInterfaceCreatePrivate (CFAllocatorRef allocator,
271 CFStringRef bridge_if);
272
273 SCNetworkInterfacePrivateRef
274 _SCVLANInterfaceCreatePrivate (CFAllocatorRef allocator,
275 CFStringRef vlan_if);
276
277 CFDictionaryRef
278 __SCNetworkInterfaceCopyInterfaceEntity (SCNetworkInterfaceRef interface);
279
280 CFArrayRef
281 __SCNetworkInterfaceCopyDeepConfiguration (SCNetworkSetRef set,
282 SCNetworkInterfaceRef interface);
283
284 #if !TARGET_OS_IPHONE
285 CFStringRef
286 __SCNetworkInterfaceCopyXLocalizedDisplayName (SCNetworkInterfaceRef interface);
287
288 CFStringRef
289 __SCNetworkInterfaceCopyXNonLocalizedDisplayName(SCNetworkInterfaceRef interface);
290 #endif // !TARGET_OS_IPHONE
291
292 CFStringRef
293 __SCNetworkInterfaceGetDefaultConfigurationType (SCNetworkInterfaceRef interface);
294
295 CFStringRef
296 __SCNetworkInterfaceGetEntitySubType (SCNetworkInterfaceRef interface);
297
298 CFStringRef
299 __SCNetworkInterfaceGetEntityType (SCNetworkInterfaceRef interface);
300
301 CFStringRef
302 __SCNetworkInterfaceGetNonLocalizedDisplayName (SCNetworkInterfaceRef interface);
303
304 void
305 __SCNetworkInterfaceSetUserDefinedName(SCNetworkInterfaceRef interface, CFStringRef name);
306
307 /*!
308 @function __SCNetworkInterfaceGetUserDefinedName
309 @discussion This function returns the user defined name of the interface if available
310 @param interface The network interface.
311 @result String containing the user defined name.
312 */
313 CFStringRef
314 __SCNetworkInterfaceGetUserDefinedName(SCNetworkInterfaceRef interface);
315
316 /*!
317 @function __SCNetworkInterfaceIsActive
318 @discussion Identifies if the configuration of network interface is active or not
319 @param interface The network interface
320 @result TRUE if the interface configuration is active.
321 */
322 Boolean
323 __SCNetworkInterfaceIsActive (SCNetworkInterfaceRef interface);
324
325 Boolean
326 __SCNetworkInterfaceIsMember (SCPreferencesRef prefs,
327 SCNetworkInterfaceRef interface);
328
329 Boolean
330 __SCNetworkInterfaceEntityIsPPTP (CFDictionaryRef entity);
331
332 Boolean
333 __SCNetworkInterfaceIsValidExtendedConfigurationType
334 (SCNetworkInterfaceRef interface,
335 CFStringRef extendedType,
336 Boolean requirePerInterface);
337
338 CFPropertyListRef
339 __SCNetworkInterfaceGetTemplateOverrides (SCNetworkInterfaceRef interface,
340 CFStringRef overrideType);
341
342 int
343 __SCNetworkInterfaceOrder (SCNetworkInterfaceRef interface);
344
345 /*!
346 @function __SCNetworkInterfaceSaveStoredWithPreferences
347 @discussion Saves the array of interfaces in the preferences passed in the function. The interfaces
348 which are already present in the prefs file are replaced.
349 @param prefs Preferences which contain the interfaces to be replaced. If NULL, then preferences on
350 the system are used.
351 @param interfacesToSave The new interfaces array which is to be stored in preferences.
352 @result TRUE if saving of the new interfaces was successful.
353 */
354
355 Boolean
356 __SCNetworkInterfaceSaveStoredWithPreferences (SCPreferencesRef prefs,
357 CFArrayRef interfacesToSave);
358
359 Boolean
360 __SCNetworkInterfaceSetConfiguration (SCNetworkInterfaceRef interface,
361 CFStringRef extendedType,
362 CFDictionaryRef config,
363 Boolean okToHold);
364
365 void
366 __SCNetworkInterfaceSetDeepConfiguration (SCNetworkSetRef set,
367 SCNetworkInterfaceRef interface,
368 CFArrayRef configs);
369
370 /*!
371 @function __SCNetworkInterfaceSetIOInterfaceUnity
372 @discussion Will allow the caller to set IO Interface Unit
373 @param interface The network interface
374 @param unit The new interface unit to set
375 */
376 void
377 __SCNetworkInterfaceSetIOInterfaceUnit (SCNetworkInterfaceRef interface,
378 CFNumberRef unit);
379
380 Boolean
381 __SCNetworkInterfaceSupportsVLAN (CFStringRef bsd_if);
382
383 void
384 __SCBondInterfaceListCollectMembers (CFArrayRef interfaces,
385 CFMutableSetRef set);
386
387 Boolean
388 __SCBondInterfaceSetMemberInterfaces (SCBondInterfaceRef bond,
389 CFArrayRef members);
390
391 void
392 __SCBridgeInterfaceListCollectMembers (CFArrayRef interfaces,
393 CFMutableSetRef set);
394
395 Boolean
396 __SCBridgeInterfaceSetMemberInterfaces (SCBridgeInterfaceRef bridge,
397 CFArrayRef members);
398
399 void
400 _SCNetworkInterfaceCacheOpen(void);
401
402 void
403 _SCNetworkInterfaceCacheClose(void);
404
405
406 #pragma mark -
407 #pragma mark SCNetworkInterface (NetworkInterfaces.plist) configuration (internal)
408
409
410 #define kSCNetworkInterfaceActive "Active"
411 #define kSCNetworkInterfaceInfo "SCNetworkInterfaceInfo"
412 #define kSCNetworkInterfaceType "SCNetworkInterfaceType"
413 #define kSCNetworkInterfaceBSDName kIOBSDNameKey
414 #define kSCNetworkInterfaceIOBuiltin kIOBuiltin
415 #define kSCNetworkInterfaceIOInterfaceNamePrefix kIOInterfaceNamePrefix
416 #define kSCNetworkInterfaceIOInterfaceType kIOInterfaceType
417 #define kSCNetworkInterfaceIOInterfaceUnit kIOInterfaceUnit
418 #define kSCNetworkInterfaceIOMACAddress kIOMACAddress
419 #define kSCNetworkInterfaceIOPathMatch kIOPathMatchKey
420 #define kSCNetworkInterfaceMatchingMACs "MatchingMACs"
421
422
423 /*!
424 @function __SCNetworkInterfaceCopyStorageEntity
425 @discussion Create interface entity of network interface as seen in
426 NetworkInterfaces.plist
427 @param interface The network interface from which interface entity is create
428 @result Dictionary which contains information about interface entity.
429 You must release the returned value.
430 */
431 CFDictionaryRef
432 __SCNetworkInterfaceCopyStorageEntity (SCNetworkInterfaceRef interface);
433
434
435 #pragma mark -
436 #pragma mark SCNetworkProtocol configuration (internal)
437
438
439 SCNetworkProtocolPrivateRef
440 __SCNetworkProtocolCreatePrivate (CFAllocatorRef allocator,
441 CFStringRef entityID,
442 SCNetworkServiceRef service);
443
444 Boolean
445 __SCNetworkProtocolIsValidType (CFStringRef protocolType);
446
447
448 #pragma mark -
449 #pragma mark SCNetworkService configuration (internal)
450
451
452 CFArrayRef /* of SCNetworkServiceRef's */
453 __SCNetworkServiceCopyAllEnabled (SCPreferencesRef prefs);
454
455 CFArrayRef /* of SCNetworkInterfaceRef's */
456 __SCNetworkServiceCopyAllInterfaces (SCPreferencesRef prefs);
457
458 SCNetworkServicePrivateRef
459 __SCNetworkServiceCreatePrivate (CFAllocatorRef allocator,
460 SCPreferencesRef prefs,
461 CFStringRef serviceID,
462 SCNetworkInterfaceRef interface);
463
464 Boolean
465 __SCNetworkServiceExists (SCNetworkServiceRef service);
466
467 Boolean
468 __SCNetworkServiceExistsForInterface (CFArrayRef services,
469 SCNetworkInterfaceRef interface);
470
471 Boolean
472 __SCNetworkServiceCreate (SCPreferencesRef prefs,
473 SCNetworkInterfaceRef interface,
474 CFStringRef userDefinedName);
475
476 Boolean
477 __SCNetworkServiceIsPPTP (SCNetworkServiceRef service);
478
479
480 void
481 __SCNetworkPopulateDefaultNIPrefs (SCPreferencesRef ni_prefs);
482
483 /*!
484 @function __SCNetworkServiceMigrateNew
485 @discussion Adds network service to SCPreferencesRef if it doesn't exists
486 @param prefs SCPreferencesRef
487 @param service The network service
488 @param bsdMapping Mapping of interface names between configurations
489 @result TRUE if add service to prefs is successful
490 */
491 Boolean
492 __SCNetworkServiceMigrateNew (SCPreferencesRef prefs,
493 SCNetworkServiceRef service,
494 CFDictionaryRef bsdMapping,
495 CFDictionaryRef setMapping,
496 CFDictionaryRef serviceSetMapping);
497
498 void
499 __SCNetworkServiceAddProtocolToService (SCNetworkServiceRef service,
500 CFStringRef protocolType,
501 CFDictionaryRef configuration,
502 Boolean enabled);
503
504
505 #pragma mark -
506 #pragma mark SCNetworkSet configuration (internal)
507
508
509 Boolean
510 __SCNetworkSetExists (SCNetworkSetRef set);
511
512
513 #pragma mark -
514 #pragma mark Logging
515
516
517 os_log_t
518 __log_SCNetworkConfiguration (void);
519
520
521 #pragma mark -
522 #pragma mark Miscellaneous (internal)
523
524
525 CFDictionaryRef
526 __copyInterfaceTemplate (CFStringRef interfaceType,
527 CFStringRef childInterfaceType);
528
529 CFDictionaryRef
530 __copyProtocolTemplate (CFStringRef interfaceType,
531 CFStringRef childInterfaceType,
532 CFStringRef protocolType);
533
534 CFDictionaryRef
535 __SCNetworkConfigurationGetValue (SCPreferencesRef prefs,
536 CFStringRef path);
537
538 Boolean
539 __SCNetworkConfigurationSetValue (SCPreferencesRef prefs,
540 CFStringRef path,
541 CFDictionaryRef config,
542 Boolean keepInactive);
543
544 Boolean
545 __getPrefsEnabled (SCPreferencesRef prefs,
546 CFStringRef path);
547
548 Boolean
549 __setPrefsEnabled (SCPreferencesRef prefs,
550 CFStringRef path,
551 Boolean enabled);
552
553 Boolean
554 __createInterface (int s,
555 CFStringRef interface);
556
557 Boolean
558 __destroyInterface (int s,
559 CFStringRef interface);
560
561 CFStringRef
562 __SCPreferencesPathCreateUniqueChild_WithMoreSCFCompatibility
563 (SCPreferencesRef prefs,
564 CFStringRef prefix);
565
566 Boolean
567 __extract_password (SCPreferencesRef prefs,
568 CFDictionaryRef config,
569 CFStringRef passwordKey,
570 CFStringRef encryptionKey,
571 CFStringRef encryptionKeyChainValue,
572 CFStringRef unique_id,
573 CFDataRef *password);
574
575 Boolean
576 __remove_password (SCPreferencesRef prefs,
577 CFDictionaryRef config,
578 CFStringRef passwordKey,
579 CFStringRef encryptionKey,
580 CFStringRef encryptionKeyChainValue,
581 CFStringRef unique_id,
582 CFDictionaryRef *newConfig);
583
584 Boolean
585 __rank_to_str (SCNetworkServicePrimaryRank rank,
586 CFStringRef *rankStr);
587
588 Boolean
589 __str_to_rank (CFStringRef rankStr,
590 SCNetworkServicePrimaryRank *rank);
591
592 __END_DECLS
593
594 #endif /* _SCNETWORKCONFIGURATIONINTERNAL_H */