2 * Copyright (c) 2004-2011, 2013-2017, 2019, 2020 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@
25 * Modification History
27 * August 5, 2004 Allan Nathanson <ajn@apple.com>
32 #include <TargetConditionals.h>
39 #define INLINE_PASSWORDS_USE_CFSTRING
40 #endif // TARGET_OS_IPHONE
44 #pragma mark Interface management
50 CFMutableArrayRef interfaces
;
51 CFArrayRef real_interfaces
;
53 real_interfaces
= _SCNetworkInterfaceCopyAllWithPreferences(prefs
);
54 if (real_interfaces
== NULL
) {
55 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
59 interfaces
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
61 // include real interfaces
62 CFArrayAppendArray(interfaces
,
64 CFRangeMake(0, CFArrayGetCount(real_interfaces
)));
65 CFRelease(real_interfaces
);
67 // include pseudo interfaces
68 CFArrayAppendValue(interfaces
, kSCNetworkInterfaceLoopback
);
69 CFArrayAppendValue(interfaces
, kSCNetworkInterfaceIPv4
);
71 // include interfaces that we have created
72 if (new_interfaces
!= NULL
) {
73 CFArrayAppendArray(interfaces
,
75 CFRangeMake(0, CFArrayGetCount(new_interfaces
)));
78 return (CFArrayRef
)interfaces
;
84 _find_interface(int argc
, char **argv
, int *nArgs
)
86 Boolean allowIndex
= TRUE
;
88 CFArrayRef myInterfaces
= interfaces
;
90 CFStringRef select_name
= NULL
;
91 SCNetworkInterfaceRef selected
= NULL
;
94 SCPrint(TRUE
, stdout
, CFSTR("no interface specified\n"));
98 if (nArgs
!= NULL
) *nArgs
= 1;
100 if (strcasecmp(argv
[0], "$child") == 0) {
101 if (net_interface
== NULL
) {
102 SCPrint(TRUE
, stdout
, CFSTR("interface not selected\n"));
106 selected
= SCNetworkInterfaceGetInterface(net_interface
);
107 if(selected
== NULL
) {
108 SCPrint(TRUE
, stdout
, CFSTR("no child interface\n"));
112 } else if (strcasecmp(argv
[0], "$service") == 0) {
113 if (net_service
== NULL
) {
114 SCPrint(TRUE
, stdout
, CFSTR("service not selected\n"));
118 selected
= SCNetworkServiceGetInterface(net_service
);
119 if(selected
== NULL
) {
120 SCPrint(TRUE
, stdout
, CFSTR("no interface for service\n"));
126 #if !TARGET_OS_IPHONE
127 else if (strcasecmp(argv
[0], "$bond") == 0) {
128 CFStringRef interfaceType
;
130 if (net_interface
== NULL
) {
131 SCPrint(TRUE
, stdout
, CFSTR("interface not selected\n"));
135 interfaceType
= SCNetworkInterfaceGetInterfaceType(net_interface
);
136 if (!CFEqual(interfaceType
, kSCNetworkInterfaceTypeBond
)) {
137 SCPrint(TRUE
, stdout
, CFSTR("interface not Bond\n"));
142 SCPrint(TRUE
, stdout
, CFSTR("no member interface specified\n"));
147 if (nArgs
!= NULL
) *nArgs
+= 1;
149 myInterfaces
= SCBondInterfaceGetMemberInterfaces(net_interface
);
150 if (myInterfaces
== NULL
) {
151 SCPrint(TRUE
, stdout
, CFSTR("no member interfaces\n"));
156 #endif // !TARGET_OS_IPHONE
158 else if (strcasecmp(argv
[0], "$bridge") == 0) {
159 CFStringRef interfaceType
;
161 if (net_interface
== NULL
) {
162 SCPrint(TRUE
, stdout
, CFSTR("interface not selected\n"));
166 interfaceType
= SCNetworkInterfaceGetInterfaceType(net_interface
);
167 if (!CFEqual(interfaceType
, kSCNetworkInterfaceTypeBridge
)) {
168 SCPrint(TRUE
, stdout
, CFSTR("interface not Bridge\n"));
173 SCPrint(TRUE
, stdout
, CFSTR("no member interface specified\n"));
178 if (nArgs
!= NULL
) *nArgs
+= 1;
180 myInterfaces
= SCBridgeInterfaceGetMemberInterfaces(net_interface
);
181 if (myInterfaces
== NULL
) {
182 SCPrint(TRUE
, stdout
, CFSTR("no member interfaces\n"));
188 else if (strcasecmp(argv
[0], "$vlan") == 0) {
189 CFStringRef interfaceType
;
191 if (net_interface
== NULL
) {
192 SCPrint(TRUE
, stdout
, CFSTR("interface not selected\n"));
196 interfaceType
= SCNetworkInterfaceGetInterfaceType(net_interface
);
197 if (!CFEqual(interfaceType
, kSCNetworkInterfaceTypeVLAN
)) {
198 SCPrint(TRUE
, stdout
, CFSTR("interface not VLAN\n"));
202 selected
= SCVLANInterfaceGetPhysicalInterface(net_interface
);
203 if(selected
== NULL
) {
204 SCPrint(TRUE
, stdout
, CFSTR("no physical interface\n"));
210 if ((myInterfaces
== NULL
) && (interfaces
== NULL
)) {
211 interfaces
= _copy_interfaces();
212 if (interfaces
== NULL
) {
215 myInterfaces
= interfaces
;
219 // try to select the interface by its display name
221 select_name
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
223 n
= (myInterfaces
!= NULL
) ? CFArrayGetCount(myInterfaces
) : 0;
224 for (i
= 0; i
< n
; i
++) {
225 SCNetworkInterfaceRef interface
;
226 CFStringRef interfaceName
;
228 interface
= CFArrayGetValueAtIndex(myInterfaces
, i
);
229 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
230 if ((interfaceName
!= NULL
) && CFEqual(select_name
, interfaceName
)) {
231 if (selected
== NULL
) {
232 selected
= interface
;
234 // if multiple interfaces match
236 SCPrint(TRUE
, stdout
, CFSTR("multiple interfaces match\n"));
242 if (selected
!= NULL
) {
246 // try to select the interface by its BSD name
248 for (i
= 0; i
< n
; i
++) {
249 SCNetworkInterfaceRef interface
;
250 CFStringRef bsd_name
= NULL
;
252 interface
= CFArrayGetValueAtIndex(myInterfaces
, i
);
253 while ((interface
!= NULL
) && (bsd_name
== NULL
)) {
254 bsd_name
= SCNetworkInterfaceGetBSDName(interface
);
255 if (bsd_name
== NULL
) {
256 interface
= SCNetworkInterfaceGetInterface(interface
);
260 if ((bsd_name
!= NULL
) && CFEqual(select_name
, bsd_name
)) {
261 if (selected
== NULL
) {
262 selected
= interface
;
264 // if multiple interfaces match
266 SCPrint(TRUE
, stdout
, CFSTR("multiple interfaces match\n"));
272 if (selected
!= NULL
) {
276 // try to select an [Apple] pre-configured / hidden interface by its BSD name
278 selected
= _SCNetworkInterfaceCreateWithBSDName(NULL
, select_name
, kIncludeNoVirtualInterfaces
);
279 if (selected
!= NULL
) {
280 if (_SCNetworkInterfaceGetIOPath(selected
) != NULL
) {
281 // if [real] interface exists
289 // try to select the interface by its interface type
291 for (i
= 0; i
< n
; i
++) {
292 SCNetworkInterfaceRef interface
;
293 CFStringRef interfaceType
;
295 interface
= CFArrayGetValueAtIndex(myInterfaces
, i
);
296 interfaceType
= SCNetworkInterfaceGetInterfaceType(interface
);
297 if (CFEqual(select_name
, interfaceType
)) {
298 if (selected
== NULL
) {
299 selected
= interface
;
301 // if multiple interfaces match
303 SCPrint(TRUE
, stdout
, CFSTR("multiple interfaces match\n"));
309 if (selected
!= NULL
) {
318 // try to select the interface by its index
321 val
= strtol(str
, &end
, 10);
322 if ((*str
!= '\0') &&
323 ((*end
== '\0') || (*end
== '.')) &&
325 if ((val
> 0) && (val
<= n
)) {
326 selected
= CFArrayGetValueAtIndex(myInterfaces
, val
- 1);
330 val
= strtol(str
, &end
, 10);
331 if ((*str
!= '\0') && (*end
== '\0') && (errno
== 0)) {
333 selected
= SCNetworkInterfaceGetInterface(selected
);
334 if (selected
== NULL
) {
344 if (selected
!= NULL
) {
348 SCPrint(TRUE
, stdout
, CFSTR("no match\n"));
352 if (select_name
!= NULL
) CFRelease(select_name
);
357 /* -------------------- */
362 create_interface(int argc
, char **argv
)
364 SCNetworkInterfaceRef interface
;
365 CFStringRef interfaceName
;
366 CFStringRef interfaceType
;
367 SCNetworkInterfaceRef new_interface
;
370 SCPrint(TRUE
, stdout
, CFSTR("what interface type?\n"));
374 interfaceType
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
378 if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeBond
)) {
379 SCPrint(TRUE
, stdout
, CFSTR("bond creation not yet supported\n"));
382 if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeBridge
)) {
383 SCPrint(TRUE
, stdout
, CFSTR("bridge creation not yet supported\n"));
386 if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeVLAN
)) {
387 SCPrint(TRUE
, stdout
, CFSTR("vlan creation not yet supported\n"));
392 if (net_interface
== NULL
) {
393 SCPrint(TRUE
, stdout
, CFSTR("no network interface selected\n"));
397 interface
= net_interface
;
399 interface
= _find_interface(argc
, argv
, NULL
);
402 if (interface
== NULL
) {
406 new_interface
= SCNetworkInterfaceCreateWithInterface(interface
, interfaceType
);
407 if (new_interface
== NULL
) {
408 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
412 if (new_interfaces
== NULL
) {
413 new_interfaces
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
415 CFArrayAppendValue(new_interfaces
, new_interface
);
417 if (net_interface
!= NULL
) CFRelease(net_interface
);
418 net_interface
= new_interface
;
420 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(net_interface
);
421 if (interfaceName
== NULL
) {
422 interfaceName
= SCNetworkInterfaceGetBSDName(net_interface
);
424 if (interfaceName
== NULL
) {
425 interfaceName
= SCNetworkInterfaceGetInterfaceType(net_interface
);
427 SCPrint(TRUE
, stdout
, CFSTR("interface \"%@\" created and selected\n"), interfaceName
);
431 CFRelease(interfaceType
);
436 /* -------------------- */
441 select_interface(int argc
, char **argv
)
443 SCNetworkInterfaceRef interface
;
445 interface
= _find_interface(argc
, argv
, NULL
);
446 if (interface
!= NULL
) {
447 CFStringRef interfaceName
;
449 if (net_interface
!= NULL
) CFRelease(net_interface
);
450 net_interface
= CFRetain(interface
);
452 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
453 if (interfaceName
== NULL
) {
454 interfaceName
= SCNetworkInterfaceGetBSDName(interface
);
456 if (interfaceName
== NULL
) {
457 interfaceName
= SCNetworkInterfaceGetInterfaceType(interface
);
460 SCPrint(TRUE
, stdout
, CFSTR("interface \"%@\" selected\n"), interfaceName
);
467 /* -------------------- */
472 _show_interface(SCNetworkInterfaceRef interface
, CFStringRef prefix
, Boolean showChild
)
474 CFDictionaryRef configuration
;
475 CFStringRef if_bsd_name
;
476 CFStringRef if_localized_name
;
477 CFStringRef if_mac_address
;
479 Boolean isPhysicalEthernet
;
480 CFArrayRef supported
;
482 if_localized_name
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
483 if (if_localized_name
!= NULL
) {
484 SCPrint(TRUE
, stdout
, CFSTR("%@ name = %@\n"), prefix
, if_localized_name
);
487 if_bsd_name
= SCNetworkInterfaceGetBSDName(interface
);
488 if (if_bsd_name
!= NULL
) {
489 SCPrint(TRUE
, stdout
, CFSTR("%@ interface name = %@"), prefix
, if_bsd_name
);
491 #if !TARGET_OS_IPHONE
492 if (isA_SCBondInterface(interface
)) {
495 members
= SCBondInterfaceGetMemberInterfaces(interface
);
496 if (members
!= NULL
) {
497 CFIndex n
= CFArrayGetCount(members
);
499 SCPrint(TRUE
, stdout
, CFSTR(", members = ("));
500 for (CFIndex i
= 0; i
< n
; i
++) {
501 SCNetworkInterfaceRef member
;
504 member
= CFArrayGetValueAtIndex(members
, i
);
505 bsdName
= SCNetworkInterfaceGetBSDName(member
);
506 SCPrint(TRUE
, stdout
, CFSTR("%s%@"),
508 bsdName
!= NULL
? bsdName
: CFSTR("?"));
510 SCPrint(TRUE
, stdout
, CFSTR(")"));
513 #endif // !TARGET_OS_IPHONE
515 if (isA_SCBridgeInterface(interface
)) {
518 members
= SCBridgeInterfaceGetMemberInterfaces(interface
);
519 if (members
!= NULL
) {
520 CFIndex n
= CFArrayGetCount(members
);
522 SCPrint(TRUE
, stdout
, CFSTR(", members = ("));
523 for (CFIndex i
= 0; i
< n
; i
++) {
524 SCNetworkInterfaceRef member
;
527 member
= CFArrayGetValueAtIndex(members
, i
);
528 bsdName
= SCNetworkInterfaceGetBSDName(member
);
529 SCPrint(TRUE
, stdout
, CFSTR("%s%@"),
531 bsdName
!= NULL
? bsdName
: CFSTR("?"));
533 SCPrint(TRUE
, stdout
, CFSTR(")"));
537 if (isA_SCVLANInterface(interface
)) {
538 SCNetworkInterfaceRef physical
;
541 physical
= SCVLANInterfaceGetPhysicalInterface(interface
);
542 tag
= SCVLANInterfaceGetTag(interface
);
543 if ((physical
!= NULL
) && (tag
!= NULL
)) {
544 SCPrint(TRUE
, stdout
, CFSTR(", physical interface = %@, tag = %@"),
550 SCPrint(TRUE
, stdout
, CFSTR("\n"));
553 if_type
= SCNetworkInterfaceGetInterfaceType(interface
);
554 SCPrint(TRUE
, stdout
, CFSTR("%@ type = %@\n"), prefix
, if_type
);
556 if_mac_address
= SCNetworkInterfaceGetHardwareAddressString(interface
);
557 if (if_mac_address
!= NULL
) {
558 SCPrint(TRUE
, stdout
, CFSTR("%@ address = %@\n"), prefix
, if_mac_address
);
561 configuration
= SCNetworkInterfaceGetConfiguration(interface
);
562 if ((configuration
!= NULL
) &&
563 CFDictionaryContainsKey(configuration
, kSCResvInactive
)) {
564 configuration
= NULL
;
567 if (if_bsd_name
!= NULL
) {
568 CFArrayRef available
;
569 CFDictionaryRef active
;
570 CFDictionaryRef cap_current
;
574 CFDictionaryRef qosPolicy
;
576 cap_current
= SCNetworkInterfaceCopyCapability(interface
, NULL
);
577 if (cap_current
!= NULL
) {
579 CFArrayRef cap_names
;
580 CFMutableArrayRef cap_sorted
;
584 n
= CFDictionaryGetCount(cap_current
);
585 keys
= CFAllocatorAllocate(NULL
, n
* sizeof(CFStringRef
), 0);
586 CFDictionaryGetKeysAndValues(cap_current
, keys
, NULL
);
587 cap_names
= CFArrayCreate(NULL
, keys
, n
, &kCFTypeArrayCallBacks
);
588 CFAllocatorDeallocate(NULL
, keys
);
590 cap_sorted
= CFArrayCreateMutableCopy(NULL
, 0, cap_names
);
591 CFRelease(cap_names
);
593 CFArraySortValues(cap_sorted
, CFRangeMake(0, n
), (CFComparatorFunction
)CFStringCompare
, NULL
);
595 SCPrint(TRUE
, stdout
, CFSTR("%@ capabilities = "), prefix
);
596 for (i
= 0; i
< n
; i
++) {
597 CFStringRef cap_name
;
599 CFNumberRef val
= NULL
;
601 cap_name
= CFArrayGetValueAtIndex(cap_sorted
, i
);
602 if (configuration
!= NULL
) {
603 val
= CFDictionaryGetValue(configuration
, cap_name
);
605 if (!isA_CFNumber(val
)) {
606 val
= CFDictionaryGetValue(cap_current
, cap_name
);
609 SCPrint(TRUE
, stdout
, CFSTR("%s%@%c"),
612 (CFNumberGetValue(val
, kCFNumberIntType
, &cap_val
) &&
613 (cap_val
!= 0)) ? '+' : '-');
615 SCPrint(TRUE
, stdout
, CFSTR("\n"));
617 CFRelease(cap_sorted
);
618 CFRelease(cap_current
);
621 if (SCNetworkInterfaceCopyMTU(interface
, &mtu_cur
, &mtu_min
, &mtu_max
)) {
622 char isCurrent
= '*';
624 if (configuration
!= NULL
) {
628 num
= CFDictionaryGetValue(configuration
, kSCPropNetEthernetMTU
);
629 if (isA_CFNumber(num
) &&
630 CFNumberGetValue(num
, kCFNumberIntType
, &mtu_req
)) {
631 if (mtu_cur
!= mtu_req
) {
638 SCPrint(TRUE
, stdout
, CFSTR("%@ mtu %c = %d (%d < n < %d)\n"),
646 if (SCNetworkInterfaceCopyMediaOptions(interface
, NULL
, &active
, &available
, TRUE
)) {
647 char isCurrent
= ' ';
648 CFArrayRef options
= NULL
;
649 CFArrayRef options_req
= NULL
;
650 CFStringRef subtype
= NULL
;
651 CFStringRef subtype_req
= NULL
;
653 if (configuration
!= NULL
) {
654 subtype_req
= CFDictionaryGetValue(configuration
, kSCPropNetEthernetMediaSubType
);
655 options_req
= CFDictionaryGetValue(configuration
, kSCPropNetEthernetMediaOptions
);
658 if (subtype_req
== NULL
) {
659 subtype_req
= CFSTR("autoselect");
662 if (active
!= NULL
) {
663 subtype
= CFDictionaryGetValue(active
, kSCPropNetEthernetMediaSubType
);
664 options
= CFDictionaryGetValue(active
, kSCPropNetEthernetMediaOptions
);
667 if (subtype
!= NULL
) {
668 if (((subtype_req
!= NULL
) &&
669 CFEqual(subtype
, subtype_req
)) &&
670 ((options
== options_req
) ||
671 ((options
!= NULL
) &&
672 (options_req
!= NULL
) &&
673 CFEqual(options
, options_req
)))
676 } else if ((subtype_req
== NULL
) ||
677 ((subtype_req
!= NULL
) &&
678 CFEqual(subtype_req
, CFSTR("autoselect")))) {
679 // if requested subtype not specified or "autoselect"
684 if (subtype_req
!= NULL
) {
685 SCPrint(TRUE
, stdout
, CFSTR("%@ media %c = %@"),
690 if ((options_req
!= NULL
) &&
691 (CFArrayGetCount(options_req
) > 0)) {
692 CFStringRef options_str
;
694 options_str
= CFStringCreateByCombiningStrings(NULL
, options_req
, CFSTR(","));
695 SCPrint(TRUE
, stdout
, CFSTR(" <%@>"), options_str
);
696 CFRelease(options_str
);
699 SCPrint(TRUE
, stdout
, CFSTR("\n"));
702 SCPrint(TRUE
, stdout
, CFSTR("\n"));
704 if (available
!= NULL
) {
709 subtypes
= SCNetworkInterfaceCopyMediaSubTypes(available
);
710 n_subtypes
= (subtypes
!= NULL
) ? CFArrayGetCount(subtypes
) : 0;
711 for (i
= 0; i
< n_subtypes
; i
++) {
713 CFIndex n_subtype_options
;
715 CFArrayRef subtype_options
;
717 subtype
= CFArrayGetValueAtIndex(subtypes
, i
);
718 subtype_options
= SCNetworkInterfaceCopyMediaSubTypeOptions(available
, subtype
);
719 n_subtype_options
= (subtype_options
!= NULL
) ? CFArrayGetCount(subtype_options
) : 0;
720 for (j
= 0; j
< n_subtype_options
; j
++) {
721 char isCurrent
= ' ';
724 options
= CFArrayGetValueAtIndex(subtype_options
, j
);
726 if (((subtype_req
!= NULL
) &&
727 CFEqual(subtype
, subtype_req
)) &&
728 ((options
== options_req
) ||
729 ((options
!= NULL
) &&
730 (options_req
!= NULL
) &&
731 CFEqual(options
, options_req
)))
736 SCPrint(TRUE
, stdout
, CFSTR("%@ %s %c = %@"),
738 ((i
== 0) && (j
== 0)) ? "supported media" : " ",
742 if ((options
!= NULL
) &&
743 (CFArrayGetCount(options
) > 0)) {
744 CFStringRef options_str
;
746 options_str
= CFStringCreateByCombiningStrings(NULL
, options
, CFSTR(","));
747 SCPrint(TRUE
, stdout
, CFSTR(" <%@>"), options_str
);
748 CFRelease(options_str
);
751 SCPrint(TRUE
, stdout
, CFSTR("\n"));
753 if (subtype_options
!= NULL
) CFRelease(subtype_options
);
755 if (subtypes
!= NULL
) CFRelease(subtypes
);
758 SCPrint(TRUE
, stdout
, CFSTR("\n"));
761 qosPolicy
= SCNetworkInterfaceGetQoSMarkingPolicy(interface
);
762 if (qosPolicy
!= NULL
) {
764 CFArrayRef bundleIDs
;
765 Boolean needComma
= FALSE
;
767 SCPrint(TRUE
, stdout
, CFSTR("%@ qos marking ="), prefix
);
769 bVal
= CFDictionaryGetValue(qosPolicy
, kSCPropNetQoSMarkingEnabled
);
770 if ((bVal
!= NULL
) && isA_CFBoolean(bVal
)) {
771 SCPrint(TRUE
, stdout
, CFSTR(" %senabled"),
772 CFBooleanGetValue(bVal
) ? "" : "!");
776 bVal
= CFDictionaryGetValue(qosPolicy
, kSCPropNetQoSMarkingAppleAudioVideoCalls
);
777 if ((bVal
!= NULL
) && isA_CFBoolean(bVal
)) {
778 SCPrint(TRUE
, stdout
, CFSTR("%s %sapple-av"),
779 needComma
? "," : "",
780 CFBooleanGetValue(bVal
) ? "" : "!");
784 bundleIDs
= CFDictionaryGetValue(qosPolicy
, kSCPropNetQoSMarkingWhitelistedAppIdentifiers
);
785 if ((bundleIDs
!= NULL
) && CFArrayGetCount(bundleIDs
)) {
786 CFIndex n
= CFArrayGetCount(bundleIDs
);
788 SCPrint(TRUE
, stdout
, CFSTR("%s applications = ("),
789 needComma
? "," : "");
790 for (CFIndex i
= 0; i
< n
; i
++) {
791 CFStringRef bundleID
;
793 bundleID
= CFArrayGetValueAtIndex(bundleIDs
, i
);
794 if (!isA_CFString(bundleID
)) {
795 bundleID
= CFSTR("--invalid-bundle-id--");
797 SCPrint(TRUE
, stdout
, CFSTR("%s%@"),
801 SCPrint(TRUE
, stdout
, CFSTR(")"));
804 SCPrint(TRUE
, stdout
, CFSTR("\n"));
808 supported
= SCNetworkInterfaceGetSupportedInterfaceTypes(interface
);
809 SCPrint(TRUE
, stdout
, CFSTR("%@ supported interfaces = "), prefix
);
810 if (supported
!= NULL
) {
812 CFIndex n
= CFArrayGetCount(supported
);
814 for (i
= 0; i
< n
; i
++) {
815 SCPrint(TRUE
, stdout
, CFSTR("%s%@"),
816 (i
== 0) ? "" : ", ",
817 CFArrayGetValueAtIndex(supported
, i
));
820 SCPrint(TRUE
, stdout
, CFSTR("\n"));
822 supported
= SCNetworkInterfaceGetSupportedProtocolTypes(interface
);
823 SCPrint(TRUE
, stdout
, CFSTR("%@ supported protocols = "), prefix
);
824 if (supported
!= NULL
) {
826 CFIndex n
= CFArrayGetCount(supported
);
828 for (i
= 0; i
< n
; i
++) {
829 SCPrint(TRUE
, stdout
, CFSTR("%s%@"),
830 (i
== 0) ? "" : ", ",
831 CFArrayGetValueAtIndex(supported
, i
));
834 SCPrint(TRUE
, stdout
, CFSTR("\n"));
836 isPhysicalEthernet
= _SCNetworkInterfaceIsPhysicalEthernet(interface
);
837 SCPrint(TRUE
, stdout
, CFSTR("%@ is%s physical ethernet\n"),
839 isPhysicalEthernet
? "" : " not");
841 if (_SCNetworkInterfaceIsApplePreconfigured(interface
)) {
842 SCPrint(TRUE
, stdout
, CFSTR("%@ is pre-configured\n"), prefix
);
845 if (configuration
!= NULL
) {
846 CFMutableDictionaryRef effective
;
848 effective
= CFDictionaryCreateMutableCopy(NULL
, 0, configuration
);
850 // remove known (and already reported) interface configuration keys
851 if (CFDictionaryContainsKey(effective
, kSCResvInactive
)) {
852 CFDictionaryRemoveAllValues(effective
);
854 CFDictionaryRemoveValue(effective
, kSCPropNetEthernetMTU
);
855 CFDictionaryRemoveValue(effective
, kSCPropNetEthernetMediaSubType
);
856 CFDictionaryRemoveValue(effective
, kSCPropNetEthernetMediaOptions
);
858 if (CFDictionaryGetCount(effective
) > 0) {
859 SCPrint(TRUE
, stdout
, CFSTR("\n%@ per-interface configuration\n"), prefix
);
860 _show_entity(effective
, prefix
);
863 CFRelease(effective
);
866 if (CFEqual(if_type
, kSCNetworkInterfaceTypePPP
)) {
867 SCNetworkInterfaceRef childInterface
;
869 childInterface
= SCNetworkInterfaceGetInterface(interface
);
870 if (childInterface
!= NULL
) {
871 CFStringRef childInterfaceType
;
873 childInterfaceType
= SCNetworkInterfaceGetInterfaceType(childInterface
);
874 if (CFEqual(childInterfaceType
, kSCNetworkInterfaceTypeL2TP
)) {
875 CFDictionaryRef ipsec_configuration
;
877 ipsec_configuration
= SCNetworkInterfaceGetExtendedConfiguration(interface
, kSCEntNetIPSec
);
878 if (isA_CFDictionary(ipsec_configuration
) &&
879 (CFDictionaryGetCount(ipsec_configuration
) > 0)) {
880 SCPrint(TRUE
, stdout
, CFSTR("\n%@ per-interface IPSec configuration\n"), prefix
);
881 _show_entity(ipsec_configuration
, prefix
);
888 SCPrint(TRUE
, stdout
, CFSTR("\n%@\n"), interface
);
891 interface
= SCNetworkInterfaceGetInterface(interface
);
892 if (interface
!= NULL
) {
893 CFStringRef newPrefix
;
895 newPrefix
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%@ "), prefix
);
896 SCPrint(TRUE
, stdout
, CFSTR("\n%@child interface\n"), newPrefix
);
897 _show_interface(interface
, newPrefix
, showChild
);
898 CFRelease(newPrefix
);
905 /* -------------------- */
909 validateMediaOptions(SCNetworkInterfaceRef interface
, CFMutableDictionaryRef newConfiguration
)
916 mtu
= CFDictionaryGetValue(newConfiguration
, kSCPropNetEthernetMTU
);
917 if (isA_CFNumber(mtu
)) {
922 if (!SCNetworkInterfaceCopyMTU(interface
, NULL
, &mtu_min
, &mtu_max
)) {
923 SCPrint(TRUE
, stdout
, CFSTR("cannot set MTU\n"));
927 if (!CFNumberGetValue(mtu
, kCFNumberIntType
, &mtu_val
) ||
928 (mtu_val
< mtu_min
) ||
929 (mtu_val
> mtu_max
)) {
930 SCPrint(TRUE
, stdout
, CFSTR("mtu out of range\n"));
935 subtype
= CFDictionaryGetValue(newConfiguration
, kSCPropNetEthernetMediaSubType
);
936 options
= CFDictionaryGetValue(newConfiguration
, kSCPropNetEthernetMediaOptions
);
938 if (subtype
!= NULL
) {
939 CFArrayRef available
= NULL
;
940 CFArrayRef config_options
= options
;
941 CFArrayRef subtypes
= NULL
;
942 CFArrayRef subtype_options
= NULL
;
946 if (options
== NULL
) {
947 config_options
= CFArrayCreate(NULL
, NULL
, 0, &kCFTypeArrayCallBacks
);
950 if (!SCNetworkInterfaceCopyMediaOptions(interface
, NULL
, NULL
, &available
, FALSE
)) {
951 SCPrint(TRUE
, stdout
, CFSTR("media type / options not available\n"));
955 if (available
== NULL
) {
959 subtypes
= SCNetworkInterfaceCopyMediaSubTypes(available
);
960 if ((subtypes
== NULL
) ||
961 !CFArrayContainsValue(subtypes
,
962 CFRangeMake(0, CFArrayGetCount(subtypes
)),
964 SCPrint(TRUE
, stdout
, CFSTR("media type not valid\n"));
968 subtype_options
= SCNetworkInterfaceCopyMediaSubTypeOptions(available
, subtype
);
969 if ((subtype_options
== NULL
) ||
970 !CFArrayContainsValue(subtype_options
,
971 CFRangeMake(0, CFArrayGetCount(subtype_options
)),
973 SCPrint(TRUE
, stdout
, CFSTR("media options not valid for \"%@\"\n"), subtype
);
977 if (options
== NULL
) {
978 CFDictionarySetValue(newConfiguration
, kSCPropNetEthernetMediaOptions
, config_options
);
985 if (available
!= NULL
) CFRelease(available
);
986 if (subtypes
!= NULL
) CFRelease(subtypes
);
987 if (subtype_options
!= NULL
) CFRelease(subtype_options
);
988 if (options
== NULL
) CFRelease(config_options
);
990 if (options
!= NULL
) {
991 SCPrint(TRUE
, stdout
, CFSTR("media type and options must both be specified\n"));
1000 /* -------------------- */
1005 show_interfaces(int argc
, char **argv
)
1007 #pragma unused(argc)
1008 #pragma unused(argv)
1012 if (interfaces
!= NULL
) CFRelease(interfaces
);
1013 interfaces
= _copy_interfaces();
1014 if (interfaces
== NULL
) {
1018 n
= CFArrayGetCount(interfaces
);
1019 for (i
= 0; i
< n
; i
++) {
1020 CFIndex childIndex
= 0;
1021 SCNetworkInterfaceRef interface
;
1023 interface
= CFArrayGetValueAtIndex(interfaces
, i
);
1025 CFStringRef interfaceName
;
1028 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
1029 if (interfaceName
== NULL
) {
1030 interfaceName
= SCNetworkInterfaceGetBSDName(interface
);
1032 if (interfaceName
== NULL
) {
1033 interfaceName
= SCNetworkInterfaceGetInterfaceType(interface
);
1037 if ((net_interface
!= NULL
) && CFEqual(interface
, net_interface
)) {
1041 if (childIndex
== 0) {
1042 SCPrint(TRUE
, stdout
, CFSTR("%c%2ld: %@\n"),
1047 SCPrint(TRUE
, stdout
, CFSTR("%c%2ld.%ld: %@\n"),
1055 CFMutableStringRef desc
;
1056 CFMutableDictionaryRef formatOptions
;
1058 desc
= CFStringCreateMutable(NULL
, 0);
1060 formatOptions
= CFDictionaryCreateMutable(NULL
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
1061 CFDictionarySetValue(formatOptions
, CFSTR("PREFIX1"), CFSTR(""));
1062 CFDictionarySetValue(formatOptions
, CFSTR("PREFIX2"), CFSTR("$$"));
1063 CFStringAppendFormat(desc
, formatOptions
, CFSTR("%@"), interface
);
1064 CFRelease(formatOptions
);
1066 // cleanup SCNetworkInterface details
1067 CFStringFindAndReplace(desc
,
1070 CFRangeMake(0, CFStringGetLength(desc
)),
1072 CFStringFindAndReplace(desc
,
1075 CFRangeMake(0, CFStringGetLength(desc
)),
1077 CFStringFindAndReplace(desc
,
1080 CFRangeMake(CFStringGetLength(desc
) - 1, 1),
1081 kCFCompareBackwards
|kCFCompareAnchored
);
1083 // additional cleanup for Bond, Bridge, VLAN options
1084 CFStringFindAndReplace(desc
,
1087 CFRangeMake(0, CFStringGetLength(desc
)),
1089 CFStringFindAndReplace(desc
,
1092 CFRangeMake(0, CFStringGetLength(desc
)),
1094 CFStringFindAndReplace(desc
,
1097 CFRangeMake(0, CFStringGetLength(desc
)),
1100 SCPrint(TRUE
, stdout
, CFSTR("\n %@\n\n"), desc
);
1104 interface
= SCNetworkInterfaceGetInterface(interface
);
1106 } while (interface
!= NULL
);
1113 /* -------------------- */
1117 __doRank(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1120 #pragma unused(info)
1121 #pragma unused(newConfiguration)
1122 SCNetworkInterfaceRef interface
;
1123 CFStringRef interfaceName
;
1125 SCNetworkServicePrimaryRank rank
= kSCNetworkServicePrimaryRankDefault
;
1126 SCDynamicStoreRef store
;
1129 SCPrint(TRUE
, stdout
,
1130 CFSTR("%s not specified\n"),
1131 description
!= NULL
? description
: "rank");
1135 if (strlen(argv
[0]) == 0) {
1136 rank
= kSCNetworkServicePrimaryRankDefault
;
1137 } else if ((strcasecmp(argv
[0], "First") == 0)) {
1138 rank
= kSCNetworkServicePrimaryRankFirst
;
1139 } else if ((strcasecmp(argv
[0], "Last") == 0)) {
1140 rank
= kSCNetworkServicePrimaryRankLast
;
1141 } else if ((strcasecmp(argv
[0], "Never") == 0)) {
1142 rank
= kSCNetworkServicePrimaryRankNever
;
1143 } else if ((strcasecmp(argv
[0], "Scoped") == 0)) {
1144 rank
= kSCNetworkServicePrimaryRankScoped
;
1146 SCPrint(TRUE
, stdout
, CFSTR("invalid rank\n"));
1150 interfaceName
= SCNetworkInterfaceGetBSDName(net_interface
);
1151 if (interfaceName
== NULL
) {
1152 SCPrint(TRUE
, stdout
, CFSTR("no BSD interface\n"));
1156 store
= SCDynamicStoreCreate(NULL
, CFSTR("scutil --net"), NULL
, NULL
);
1157 interface
= _SCNetworkInterfaceCopyActive(store
, interfaceName
);
1159 if (interface
== NULL
) {
1160 SCPrint(TRUE
, stdout
, CFSTR("No active interface\n"));
1164 ok
= SCNetworkInterfaceSetPrimaryRank(interface
, rank
);
1165 CFRelease(interface
);
1167 SCPrint(TRUE
, stdout
, CFSTR("could not update per-interface rank\n"));
1175 /* -------------------- */
1179 _replaceOne(const void *key
, const void *value
, void *context
)
1181 CFMutableDictionaryRef newConfiguration
= (CFMutableDictionaryRef
)context
;
1183 CFDictionarySetValue(newConfiguration
, key
, value
);
1189 updateInterfaceConfiguration(CFMutableDictionaryRef newConfiguration
)
1191 CFDictionaryRef configuration
;
1193 CFDictionaryRemoveAllValues(newConfiguration
);
1195 configuration
= SCNetworkInterfaceGetConfiguration(net_interface
);
1196 if (configuration
!= NULL
) {
1197 CFDictionaryApplyFunction(configuration
, _replaceOne
, (void *)newConfiguration
);
1205 #pragma mark QoS Marking Policy options
1208 static options qosOptions
[] = {
1209 { "enabled" , NULL
, isBool
, &kSCPropNetQoSMarkingEnabled
, NULL
, NULL
},
1210 { "apple-av" , NULL
, isBool
, &kSCPropNetQoSMarkingAppleAudioVideoCalls
, NULL
, NULL
},
1211 { "bundle-ids", NULL
, isStringArray
, &kSCPropNetQoSMarkingWhitelistedAppIdentifiers
, NULL
, NULL
},
1213 { "?" , NULL
, isHelp
, NULL
, NULL
,
1214 "\nQoS marking policy commands\n\n"
1215 " set interface qos [enabled {yes|no}]\n"
1216 " set interface qos [apple-av {yes|no}]\n"
1217 " set interface qos [bundle-ids bundle-id[,bundle-id]]\n"
1220 #define N_QOS_OPTIONS (sizeof(qosOptions) / sizeof(qosOptions[0]))
1224 __doQoSMarking(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1227 #pragma unused(description)
1228 #pragma unused(info)
1229 #pragma unused(newConfiguration)
1230 CFStringRef interfaceName
;
1231 CFMutableDictionaryRef newPolicy
;
1233 CFDictionaryRef policy
;
1236 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
1240 interfaceName
= SCNetworkInterfaceGetBSDName(net_interface
);
1241 if (interfaceName
== NULL
) {
1242 SCPrint(TRUE
, stdout
, CFSTR("no BSD interface\n"));
1246 policy
= SCNetworkInterfaceGetQoSMarkingPolicy(net_interface
);
1247 if (policy
!= NULL
) {
1248 newPolicy
= CFDictionaryCreateMutableCopy(NULL
, 0, policy
);
1249 CFDictionaryRemoveValue(newPolicy
, kSCResvInactive
);
1251 newPolicy
= CFDictionaryCreateMutable(NULL
,
1253 &kCFTypeDictionaryKeyCallBacks
,
1254 &kCFTypeDictionaryValueCallBacks
);
1257 ok
= _process_options(qosOptions
, N_QOS_OPTIONS
, argc
, argv
, newPolicy
);
1262 if (((policy
== NULL
) && (CFDictionaryGetCount(newPolicy
) > 0)) ||
1263 ((policy
!= NULL
) && !CFEqual(policy
, newPolicy
))) {
1264 if (!SCNetworkInterfaceSetQoSMarkingPolicy(net_interface
, newPolicy
)) {
1265 if (SCError() == kSCStatusNoKey
) {
1266 SCPrint(TRUE
, stdout
, CFSTR("could not update per-interface QoS marking policy\n"));
1268 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
1273 _prefs_changed
= TRUE
;
1278 if (newPolicy
!= NULL
) CFRelease(newPolicy
);
1284 #pragma mark Bond options
1287 static options bondOptions
[] = {
1288 { "mtu" , NULL
, isNumber
, &kSCPropNetEthernetMTU
, NULL
, NULL
},
1289 // xxx { "+device" , ... },
1290 // xxx { "-device" , ... },
1292 { "?" , NULL
, isHelp
, NULL
, NULL
,
1293 "\nBond configuration commands\n\n"
1294 " set interface [mtu n] [media type] [mediaopts opts]\n"
1297 #define N_BOND_OPTIONS (sizeof(bondOptions) / sizeof(bondOptions[0]))
1301 set_interface_bond(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1303 CFStringRef interfaceName
;
1306 interfaceName
= SCNetworkInterfaceGetBSDName(net_interface
);
1307 if (interfaceName
== NULL
) {
1308 SCPrint(TRUE
, stdout
, CFSTR("no BSD interface\n"));
1312 ok
= _process_options(bondOptions
, N_BOND_OPTIONS
, argc
, argv
, newConfiguration
);
1314 // validate configuration
1315 if (!validateMediaOptions(net_interface
, newConfiguration
)) {
1325 #pragma mark Bridge options
1328 static options bridgeOptions
[] = {
1329 { "mtu" , NULL
, isNumber
, &kSCPropNetEthernetMTU
, NULL
, NULL
},
1330 // xxx { "+device" , ... },
1331 // xxx { "-device" , ... },
1333 { "?" , NULL
, isHelp
, NULL
, NULL
,
1334 "\nBridge configuration commands\n\n"
1335 " set interface [mtu n] [media type] [mediaopts opts]\n"
1338 #define N_BRIDGE_OPTIONS (sizeof(bridgeOptions) / sizeof(bridgeOptions[0]))
1342 set_interface_bridge(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1344 CFStringRef interfaceName
;
1347 interfaceName
= SCNetworkInterfaceGetBSDName(net_interface
);
1348 if (interfaceName
== NULL
) {
1349 SCPrint(TRUE
, stdout
, CFSTR("no BSD interface\n"));
1353 ok
= _process_options(bridgeOptions
, N_BRIDGE_OPTIONS
, argc
, argv
, newConfiguration
);
1355 // validate configuration
1356 if (!validateMediaOptions(net_interface
, newConfiguration
)) {
1366 #pragma mark AirPort options
1369 static options airportOptions
[] = {
1370 { "mtu" , NULL
, isNumber
, &kSCPropNetEthernetMTU
, NULL
, NULL
},
1371 { "media" , NULL
, isString
, &kSCPropNetEthernetMediaSubType
, NULL
, NULL
},
1372 { "mediaopt" , NULL
, isStringArray
, &kSCPropNetEthernetMediaOptions
, NULL
, NULL
},
1374 { "rank" , NULL
, isOther
, NULL
, __doRank
, NULL
},
1376 { "qos" , NULL
, isOther
, NULL
, __doQoSMarking
, NULL
},
1378 { "?" , NULL
, isHelp
, NULL
, NULL
,
1379 "\nAirPort configuration commands\n\n"
1380 " set interface [mtu n] [media type] [mediaopts opts]\n"
1381 " set interface [rank [{First|Last|Never|Scoped}]]\n"
1382 " set interface [qos <qos-options>]]\n"
1385 #define N_AIRPORT_OPTIONS (sizeof(airportOptions) / sizeof(airportOptions[0]))
1389 set_interface_airport(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1391 CFStringRef interfaceName
;
1394 interfaceName
= SCNetworkInterfaceGetBSDName(net_interface
);
1395 if (interfaceName
== NULL
) {
1396 SCPrint(TRUE
, stdout
, CFSTR("no BSD interface\n"));
1400 ok
= _process_options(airportOptions
, N_AIRPORT_OPTIONS
, argc
, argv
, newConfiguration
);
1402 // validate configuration
1403 if (!validateMediaOptions(net_interface
, newConfiguration
)) {
1413 #pragma mark Ethernet options
1417 __doCapability(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1419 #pragma unused(info)
1423 SCPrint(TRUE
, stdout
,
1424 CFSTR("%s not specified\n"),
1425 description
!= NULL
? description
: "enable/disable");
1429 if (strlen(argv
[0]) == 0) {
1430 ok
= SCNetworkInterfaceSetCapability(net_interface
, key
, NULL
);
1431 } else if ((strcasecmp(argv
[0], "disable") == 0) ||
1432 (strcasecmp(argv
[0], "no" ) == 0) ||
1433 (strcasecmp(argv
[0], "off" ) == 0) ||
1434 (strcasecmp(argv
[0], "0" ) == 0)) {
1435 ok
= SCNetworkInterfaceSetCapability(net_interface
, key
, CFNumberRef_0
);
1436 } else if ((strcasecmp(argv
[0], "enable") == 0) ||
1437 (strcasecmp(argv
[0], "yes" ) == 0) ||
1438 (strcasecmp(argv
[0], "on" ) == 0) ||
1439 (strcasecmp(argv
[0], "1" ) == 0)) {
1440 ok
= SCNetworkInterfaceSetCapability(net_interface
, key
, CFNumberRef_1
);
1442 SCPrint(TRUE
, stdout
, CFSTR("invalid value\n"));
1447 updateInterfaceConfiguration(newConfiguration
);
1449 SCPrint(TRUE
, stdout
,
1450 CFSTR("%@ not updated: %s\n"),
1452 SCErrorString(SCError()));
1460 static options ethernetOptions
[] = {
1461 { "mtu" , NULL
, isNumber
, &kSCPropNetEthernetMTU
, NULL
, NULL
},
1462 { "media" , NULL
, isString
, &kSCPropNetEthernetMediaSubType
, NULL
, NULL
},
1463 { "mediaopt" , NULL
, isStringArray
, &kSCPropNetEthernetMediaOptions
, NULL
, NULL
},
1465 { "av" , NULL
, isOther
, &kSCPropNetEthernetCapabilityAV
, __doCapability
, NULL
},
1466 { "lro" , NULL
, isOther
, &kSCPropNetEthernetCapabilityLRO
, __doCapability
, NULL
},
1467 { "rxcsum" , NULL
, isOther
, &kSCPropNetEthernetCapabilityRXCSUM
, __doCapability
, NULL
},
1468 { "tso" , NULL
, isOther
, &kSCPropNetEthernetCapabilityTSO
, __doCapability
, NULL
},
1469 { "txcsum" , NULL
, isOther
, &kSCPropNetEthernetCapabilityTXCSUM
, __doCapability
, NULL
},
1471 { "rank" , NULL
, isOther
, NULL
, __doRank
, NULL
},
1473 { "qos" , NULL
, isOther
, NULL
, __doQoSMarking
, NULL
},
1475 { "?" , NULL
, isHelp
, NULL
, NULL
,
1476 "\nEthernet configuration commands\n\n"
1477 " set interface [mtu n] [media type] [mediaopts opts]\n"
1478 " set interface [rank [{First|Last|Never|Scoped}]]\n"
1479 " set interface [qos [<qos-options>]]\n"
1482 #define N_ETHERNET_OPTIONS (sizeof(ethernetOptions) / sizeof(ethernetOptions[0]))
1486 set_interface_ethernet(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1488 CFStringRef interfaceName
;
1491 interfaceName
= SCNetworkInterfaceGetBSDName(net_interface
);
1492 if (interfaceName
== NULL
) {
1493 SCPrint(TRUE
, stdout
, CFSTR("no BSD interface\n"));
1497 ok
= _process_options(ethernetOptions
, N_ETHERNET_OPTIONS
, argc
, argv
, newConfiguration
);
1499 // validate configuration
1500 if (!validateMediaOptions(net_interface
, newConfiguration
)) {
1510 #pragma mark IPSec options
1514 __doIPSecSharedSecret(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1516 #pragma unused(description)
1517 #pragma unused(info)
1518 CFStringRef encryptionType
;
1521 SCPrint(TRUE
, stdout
, CFSTR("IPSec shared secret not specified\n"));
1525 encryptionType
= CFDictionaryGetValue(newConfiguration
, kSCPropNetIPSecSharedSecretEncryption
);
1526 if (strlen(argv
[0]) > 0) {
1527 if (encryptionType
== NULL
) {
1528 #ifdef INLINE_PASSWORDS_USE_CFSTRING
1531 pw
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
1532 #else // INLINE_PASSWORDS_USE_CFSTRING
1534 CFMutableDataRef pw
;
1537 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
1538 n
= CFStringGetLength(str
);
1539 pw
= CFDataCreateMutable(NULL
, n
* sizeof(UniChar
));
1540 CFDataSetLength(pw
, n
* sizeof(UniChar
));
1541 /* ALIGN: CF aligns to at least >8 bytes */
1542 CFStringGetCharacters(str
,
1544 (UniChar
*)(void *)CFDataGetMutableBytePtr(pw
));
1546 #endif // INLINE_PASSWORDS_USE_CFSTRING
1548 CFDictionarySetValue(newConfiguration
, key
, pw
);
1550 } else if (CFEqual(encryptionType
, kSCValNetIPSecSharedSecretEncryptionKeychain
)) {
1555 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
1556 pw
= CFStringCreateExternalRepresentation(NULL
, str
, kCFStringEncodingUTF8
, 0);
1557 ok
= SCNetworkInterfaceSetPassword(net_interface
,
1558 kSCNetworkInterfacePasswordTypeIPSecSharedSecret
,
1564 updateInterfaceConfiguration(newConfiguration
);
1569 SCPrint(TRUE
, stdout
, CFSTR("IPSec shared secret type \"%@\" not supported\n"), encryptionType
);
1573 if (encryptionType
== NULL
) {
1574 CFDictionaryRemoveValue(newConfiguration
, key
);
1575 } else if (CFEqual(encryptionType
, kSCValNetIPSecSharedSecretEncryptionKeychain
)) {
1577 ok
= SCNetworkInterfaceRemovePassword(net_interface
, kSCNetworkInterfacePasswordTypeIPSecSharedSecret
);
1579 updateInterfaceConfiguration(newConfiguration
);
1584 SCPrint(TRUE
, stdout
, CFSTR("IPSec shared secret type \"%@\" not supported\n"), encryptionType
);
1594 __doIPSecSharedSecretType(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1596 #pragma unused(description)
1597 #pragma unused(info)
1599 SCPrint(TRUE
, stdout
, CFSTR("IPSec shared secret type mode not specified\n"));
1603 if (strlen(argv
[0]) > 0) {
1604 if (strcasecmp(argv
[0], "keychain") == 0) {
1605 CFDictionarySetValue(newConfiguration
, key
, kSCValNetIPSecSharedSecretEncryptionKeychain
);
1607 SCPrint(TRUE
, stdout
, CFSTR("invalid shared secret type\n"));
1611 CFDictionaryRemoveValue(newConfiguration
, key
);
1614 // encryption type changed, reset shared secret
1615 CFDictionaryRemoveValue(newConfiguration
, kSCPropNetIPSecSharedSecret
);
1622 __doIPSecXAuthPassword(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1624 #pragma unused(description)
1625 #pragma unused(info)
1626 CFStringRef encryptionType
;
1629 SCPrint(TRUE
, stdout
, CFSTR("IPSec XAuth password not specified\n"));
1633 encryptionType
= CFDictionaryGetValue(newConfiguration
, kSCPropNetIPSecXAuthPasswordEncryption
);
1634 if (strlen(argv
[0]) > 0) {
1635 if (encryptionType
== NULL
) {
1636 #ifdef INLINE_PASSWORDS_USE_CFSTRING
1639 pw
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
1640 #else // INLINE_PASSWORDS_USE_CFSTRING
1642 CFMutableDataRef pw
;
1645 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
1646 n
= CFStringGetLength(str
);
1647 pw
= CFDataCreateMutable(NULL
, n
* sizeof(UniChar
));
1648 CFDataSetLength(pw
, n
* sizeof(UniChar
));
1649 /* ALIGN: CF aligns to at least >8 byte boundries */
1650 CFStringGetCharacters(str
,
1652 (UniChar
*)(void *)CFDataGetMutableBytePtr(pw
));
1654 #endif // INLINE_PASSWORDS_USE_CFSTRING
1656 CFDictionarySetValue(newConfiguration
, key
, pw
);
1658 } else if (CFEqual(encryptionType
, kSCValNetIPSecXAuthPasswordEncryptionKeychain
)) {
1663 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
1664 pw
= CFStringCreateExternalRepresentation(NULL
, str
, kCFStringEncodingUTF8
, 0);
1665 ok
= SCNetworkInterfaceSetPassword(net_interface
,
1666 kSCNetworkInterfacePasswordTypeIPSecXAuth
,
1672 updateInterfaceConfiguration(newConfiguration
);
1677 SCPrint(TRUE
, stdout
, CFSTR("IPSec XAuthPassword type \"%@\" not supported\n"), encryptionType
);
1681 if (encryptionType
== NULL
) {
1682 CFDictionaryRemoveValue(newConfiguration
, key
);
1683 } else if (CFEqual(encryptionType
, kSCValNetIPSecXAuthPasswordEncryptionKeychain
)) {
1686 ok
= SCNetworkInterfaceRemovePassword(net_interface
, kSCNetworkInterfacePasswordTypeIPSecXAuth
);
1688 updateInterfaceConfiguration(newConfiguration
);
1693 SCPrint(TRUE
, stdout
, CFSTR("IPSec XAuthPassword type \"%@\" not supported\n"), encryptionType
);
1703 __doIPSecXAuthPasswordType(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1705 #pragma unused(description)
1706 #pragma unused(info)
1708 SCPrint(TRUE
, stdout
, CFSTR("IPSec XAuth password type mode not specified\n"));
1712 if (strlen(argv
[0]) > 0) {
1713 if (strcasecmp(argv
[0], "keychain") == 0) {
1714 CFDictionarySetValue(newConfiguration
, key
, kSCValNetIPSecXAuthPasswordEncryptionKeychain
);
1716 SCPrint(TRUE
, stdout
, CFSTR("invalid XAuth password type\n"));
1720 CFDictionaryRemoveValue(newConfiguration
, key
);
1723 // encryption type changed, reset XAuthPassword
1724 CFDictionaryRemoveValue(newConfiguration
, kSCPropNetIPSecXAuthPassword
);
1730 static CF_RETURNS_RETAINED CFStringRef
1731 __cleanupDomainName(CFStringRef domain
)
1733 CFMutableStringRef newDomain
;
1735 newDomain
= CFStringCreateMutableCopy(NULL
, 0, domain
);
1736 CFStringTrimWhitespace(newDomain
);
1737 CFStringTrim(newDomain
, CFSTR("."));
1738 if (CFStringGetLength(newDomain
) == 0) {
1739 CFRelease(newDomain
);
1748 __doOnDemandDomains(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1750 #pragma unused(description)
1751 #pragma unused(info)
1752 CFMutableArrayRef domains
;
1755 SCPrint(TRUE
, stdout
, CFSTR("OnDemand domain name(s) not specified\n"));
1759 domains
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
1761 if (strlen(argv
[0]) > 0) {
1765 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
1766 array
= CFStringCreateArrayBySeparatingStrings(NULL
, str
, CFSTR(","));
1769 if (array
!= NULL
) {
1771 CFIndex n
= CFArrayGetCount(array
);
1773 for (i
= 0; i
< n
; i
++) {
1776 domain
= __cleanupDomainName(CFArrayGetValueAtIndex(array
, i
));
1777 if (domain
!= NULL
) {
1778 CFArrayAppendValue(domains
, domain
);
1783 SCPrint(TRUE
, stdout
, CFSTR("invalid OnDemand domain name\n"));
1791 if (CFArrayGetCount(domains
) > 0) {
1792 CFDictionarySetValue(newConfiguration
, key
, domains
);
1794 CFDictionaryRemoveValue(newConfiguration
, key
);
1802 static options ipsecOnDemandOptions
[] = {
1803 { "OnDemandMatchDomainsAlways" , "domain", isOther
, &kSCPropNetIPSecOnDemandMatchDomainsAlways
, __doOnDemandDomains
, NULL
},
1804 { "always" , "domain", isOther
, &kSCPropNetIPSecOnDemandMatchDomainsAlways
, __doOnDemandDomains
, NULL
},
1805 { "OnDemandMatchDomainsOnRetry", "domain", isOther
, &kSCPropNetIPSecOnDemandMatchDomainsOnRetry
, __doOnDemandDomains
, NULL
},
1806 { "retry" , "domain", isOther
, &kSCPropNetIPSecOnDemandMatchDomainsOnRetry
, __doOnDemandDomains
, NULL
},
1807 { "OnDemandMatchDomainsNever" , "domain", isOther
, &kSCPropNetIPSecOnDemandMatchDomainsNever
, __doOnDemandDomains
, NULL
},
1808 { "never" , "domain", isOther
, &kSCPropNetIPSecOnDemandMatchDomainsNever
, __doOnDemandDomains
, NULL
},
1810 { "?" , NULL
, isHelp
, NULL
, NULL
,
1811 "\nOnDemandMatch configuration commands\n\n"
1812 " set interface OnDemandMatch [always domain-name[,domain-name]]\n"
1813 " set interface OnDemandMatch [retry domain-name[,domain-name]]\n"
1814 " set interface OnDemandMatch [never domain-name[,domain-name]]\n"
1817 #define N_IPSEC_ONDEMAND_OPTIONS (sizeof(ipsecOnDemandOptions) / sizeof(ipsecOnDemandOptions[0]))
1821 __doIPSecOnDemandMatch(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1824 #pragma unused(description)
1825 #pragma unused(info)
1829 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
1833 ok
= _process_options(ipsecOnDemandOptions
, N_IPSEC_ONDEMAND_OPTIONS
, argc
, argv
, newConfiguration
);
1844 static selections ipsecAuthenticationMethodSelections
[] = {
1845 { CFSTR("SharedSecret"), &kSCValNetIPSecAuthenticationMethodSharedSecret
, 0 },
1846 { CFSTR("Certificate") , &kSCValNetIPSecAuthenticationMethodCertificate
, 0 },
1847 { CFSTR("Hybrid") , &kSCValNetIPSecAuthenticationMethodHybrid
, 0 },
1852 static selections ipsecLocalIdentifierTypeSelections
[] = {
1853 { CFSTR("KeyID") , &kSCValNetIPSecLocalIdentifierTypeKeyID
, 0 },
1858 static options ipsecOptions
[] = {
1859 { "AuthenticationMethod" , NULL
, isChooseOne
, &kSCPropNetIPSecAuthenticationMethod
, NULL
, (void *)ipsecAuthenticationMethodSelections
},
1860 { "LocalIdentifier" , NULL
, isString
, &kSCPropNetIPSecLocalIdentifier
, NULL
, NULL
},
1861 { "group" , NULL
, isString
, &kSCPropNetIPSecLocalIdentifier
, NULL
, NULL
},
1862 { "LocalIdentifierType" , NULL
, isChooseOne
, &kSCPropNetIPSecLocalIdentifierType
, NULL
, (void *)ipsecLocalIdentifierTypeSelections
},
1863 { "RemoteAddress" , NULL
, isString
, &kSCPropNetIPSecRemoteAddress
, NULL
, NULL
},
1864 { "SharedSecret" , NULL
, isOther
, &kSCPropNetIPSecSharedSecret
, __doIPSecSharedSecret
, NULL
},
1865 { "SharedSecretEncryption" , NULL
, isOther
, &kSCPropNetIPSecSharedSecretEncryption
, __doIPSecSharedSecretType
, NULL
},
1868 { "XAuthEnabled" , NULL
, isBoolean
, &kSCPropNetIPSecXAuthEnabled
, NULL
, NULL
},
1869 { "XAuthName" , NULL
, isString
, &kSCPropNetIPSecXAuthName
, NULL
, NULL
},
1870 { "XAuthPassword" , NULL
, isOther
, &kSCPropNetIPSecXAuthPassword
, __doIPSecXAuthPassword
, NULL
},
1871 { "XAuthPasswordEncryption", NULL
, isOther
, &kSCPropNetIPSecXAuthPasswordEncryption
, __doIPSecXAuthPasswordType
, NULL
},
1873 // --- OnDemand: ---
1874 { "OnDemandEnabled" , NULL
, isBoolean
, &kSCPropNetIPSecOnDemandEnabled
, NULL
, NULL
},
1875 { "OnDemandMatch" , NULL
, isOther
, NULL
, __doIPSecOnDemandMatch
, NULL
},
1877 { "?" , NULL
, isHelp
, NULL
, NULL
,
1878 "\nIPSec configuration commands\n\n"
1879 " set interface [AuthenticationMethod {SharedSecret|Certificate|Hybrid}]\n"
1880 " set interface [LocalIdentifier group]\n"
1881 " set interface [LocalIdentifierType {KeyID}]\n"
1882 " set interface [RemoteAddress name-or-address]\n"
1883 " set interface [SharedSecret secret]\n"
1884 " set interface [SharedSecretEncryption {Keychain}]\n"
1885 " set interface [XAuthEnabled {enable|disable}]\n"
1886 " set interface [XAuthPassword password]\n"
1887 " set interface [XAuthPasswordEncryption {Keychain}]\n"
1888 " set interface [OnDemandEnabled {enable|disable}]\n"
1889 " set interface [OnDemandMatch <match-options>]\n"
1892 #define N_IPSEC_OPTIONS (sizeof(ipsecOptions) / sizeof(ipsecOptions[0]))
1896 set_interface_ipsec(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1900 ok
= _process_options(ipsecOptions
, N_IPSEC_OPTIONS
, argc
, argv
, newConfiguration
);
1906 #pragma mark FireWire options
1909 static options firewireOptions
[] = {
1910 { "mtu" , NULL
, isNumber
, &kSCPropNetEthernetMTU
, NULL
, NULL
},
1911 { "media" , NULL
, isString
, &kSCPropNetEthernetMediaSubType
, NULL
, NULL
},
1912 { "mediaopt" , NULL
, isStringArray
, &kSCPropNetEthernetMediaOptions
, NULL
, NULL
},
1914 { "?" , NULL
, isHelp
, NULL
, NULL
,
1915 "\nFireWire configuration commands\n\n"
1916 " set interface [mtu n] [media type] [mediaopts opts]\n"
1919 #define N_FIREWIRE_OPTIONS (sizeof(firewireOptions) / sizeof(firewireOptions[0]))
1923 set_interface_firewire(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1925 CFStringRef interfaceName
;
1928 interfaceName
= SCNetworkInterfaceGetBSDName(net_interface
);
1929 if (interfaceName
== NULL
) {
1930 SCPrint(TRUE
, stdout
, CFSTR("no BSD interface\n"));
1934 ok
= _process_options(firewireOptions
, N_FIREWIRE_OPTIONS
, argc
, argv
, newConfiguration
);
1936 // validate configuration
1937 if (!validateMediaOptions(net_interface
, newConfiguration
)) {
1947 #pragma mark Modem options
1950 static selections modemDialSelections
[] = {
1951 { CFSTR("ignore"), &kSCValNetModemDialModeIgnoreDialTone
, 0 },
1952 { CFSTR("manual"), &kSCValNetModemDialModeManual
, 0 },
1953 { CFSTR("wait") , &kSCValNetModemDialModeWaitForDialTone
, 0 },
1957 static options modemOptions
[] = {
1958 { "ConnectionPersonality" , "NULL" , isString
, &kSCPropNetModemConnectionPersonality
, NULL
, NULL
},
1959 { "DeviceModel" , "model" , isString
, &kSCPropNetModemDeviceModel
, NULL
, NULL
},
1960 { "DeviceVendor" , "vendor", isString
, &kSCPropNetModemDeviceVendor
, NULL
, NULL
},
1961 { "ConnectionScript" , "script", isString
, &kSCPropNetModemConnectionScript
, NULL
, NULL
},
1962 { "DialMode" , "mode" , isChooseOne
, &kSCPropNetModemDialMode
, NULL
, (void *)modemDialSelections
},
1963 { "CallWaiting" , NULL
, isBoolean
, &kSCPropNetModemHoldEnabled
, NULL
, NULL
},
1964 { "CallWaitingAlert" , NULL
, isBoolean
, &kSCPropNetModemHoldCallWaitingAudibleAlert
, NULL
, NULL
},
1965 { "CallWaitingDisconnectOnAnswer", NULL
, isBoolean
, &kSCPropNetModemHoldDisconnectOnAnswer
, NULL
, NULL
},
1966 { "DataCompression" , NULL
, isBoolean
, &kSCPropNetModemDataCompression
, NULL
, NULL
},
1967 { "ErrorCorrection" , NULL
, isBoolean
, &kSCPropNetModemErrorCorrection
, NULL
, NULL
},
1968 { "HoldReminder" , NULL
, isBoolean
, &kSCPropNetModemHoldReminder
, NULL
, NULL
},
1969 { "HoldReminderTime" , "time" , isNumber
, &kSCPropNetModemHoldReminderTime
, NULL
, NULL
},
1970 { "PulseDial" , NULL
, isBoolean
, &kSCPropNetModemPulseDial
, NULL
, NULL
},
1971 { "Speaker" , NULL
, isBoolean
, &kSCPropNetModemSpeaker
, NULL
, NULL
},
1973 { "?" , NULL
, isHelp
, NULL
, NULL
,
1974 "\nModem configuration commands\n\n"
1975 " set interface [DeviceVendor vendor]\n"
1976 " set interface [DeviceModel model]\n"
1977 " set interface [ConnectionPersonality personality]\n"
1979 " set interface [ConnectionScript connection-script]\n"
1981 " set interface [CallWaiting {enable|disable}]\n"
1982 " set interface [CallWaitingAlert {enable|disable}]\n"
1983 " set interface [CallWaitingDisconnectOnAnswer {enable|disable}]\n"
1984 " set interface [DialMode {ignore|wait}]\n"
1985 " set interface [DataCompression {enable|disable}]\n"
1986 " set interface [ErrorCorrection {enable|disable}]\n"
1987 " set interface [HoldReminder {enable|disable}]\n"
1988 " set interface [HoldReminderTime n]\n"
1989 " set interface [PulseDial {enable|disable}]\n"
1990 " set interface [Speaker {enable|disable}]\n"
1993 #define N_MODEM_OPTIONS (sizeof(modemOptions) / sizeof(modemOptions[0]))
1997 set_interface_modem(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
2001 ok
= _process_options(modemOptions
, N_MODEM_OPTIONS
, argc
, argv
, newConfiguration
);
2007 #pragma mark PPP options
2011 __doPPPAuthPW(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
2013 #pragma unused(description)
2014 #pragma unused(info)
2015 CFStringRef encryptionType
;
2018 SCPrint(TRUE
, stdout
, CFSTR("PPP password not specified\n"));
2022 encryptionType
= CFDictionaryGetValue(newConfiguration
, kSCPropNetPPPAuthPasswordEncryption
);
2023 if (strlen(argv
[0]) > 0) {
2024 if (encryptionType
== NULL
) {
2025 #ifdef INLINE_PASSWORDS_USE_CFSTRING
2028 pw
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
2029 #else // INLINE_PASSWORDS_USE_CFSTRING
2031 CFMutableDataRef pw
;
2034 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
2035 n
= CFStringGetLength(str
);
2036 pw
= CFDataCreateMutable(NULL
, n
* sizeof(UniChar
));
2037 CFDataSetLength(pw
, n
* sizeof(UniChar
));
2038 /* ALIGN: CF aligns to at least >8 byte boundries */
2039 CFStringGetCharacters(str
,
2041 (UniChar
*)(void *)CFDataGetMutableBytePtr(pw
));
2043 #endif // INLINE_PASSWORDS_USE_CFSTRING
2045 CFDictionarySetValue(newConfiguration
, key
, pw
);
2047 } else if (CFEqual(encryptionType
, kSCValNetPPPAuthPasswordEncryptionKeychain
)) {
2052 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
2053 pw
= CFStringCreateExternalRepresentation(NULL
, str
, kCFStringEncodingUTF8
, 0);
2054 ok
= SCNetworkInterfaceSetPassword(net_interface
,
2055 kSCNetworkInterfacePasswordTypePPP
,
2061 updateInterfaceConfiguration(newConfiguration
);
2066 SCPrint(TRUE
, stdout
, CFSTR("PPP password type \"%@\" not supported\n"), encryptionType
);
2070 if (encryptionType
== NULL
) {
2071 CFDictionaryRemoveValue(newConfiguration
, key
);
2072 } else if (CFEqual(encryptionType
, kSCValNetPPPAuthPasswordEncryptionKeychain
)) {
2075 ok
= SCNetworkInterfaceRemovePassword(net_interface
, kSCNetworkInterfacePasswordTypePPP
);
2077 updateInterfaceConfiguration(newConfiguration
);
2082 SCPrint(TRUE
, stdout
, CFSTR("PPP password type \"%@\" not supported\n"), encryptionType
);
2092 __doPPPAuthPWType(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
2094 #pragma unused(description)
2095 #pragma unused(info)
2097 SCPrint(TRUE
, stdout
, CFSTR("PPP password type mode not specified\n"));
2101 if (strlen(argv
[0]) > 0) {
2102 if (strcasecmp(argv
[0], "keychain") == 0) {
2103 CFDictionarySetValue(newConfiguration
, key
, kSCValNetPPPAuthPasswordEncryptionKeychain
);
2105 SCPrint(TRUE
, stdout
, CFSTR("invalid password type\n"));
2109 CFDictionaryRemoveValue(newConfiguration
, key
);
2112 // encryption type changed, reset password
2113 CFDictionaryRemoveValue(newConfiguration
, kSCPropNetPPPAuthPassword
);
2119 static options l2tp_ipsecOptions
[] = {
2120 { "SharedSecret" , NULL
, isOther
, &kSCPropNetIPSecSharedSecret
, __doIPSecSharedSecret
, NULL
},
2121 { "SharedSecretEncryption", NULL
, isOther
, &kSCPropNetIPSecSharedSecretEncryption
, __doIPSecSharedSecretType
, NULL
},
2123 { "?" , NULL
, isHelp
, NULL
, NULL
,
2124 "\nIPSec configuration commands\n\n"
2125 " set interface ipsec [SharedSecret secret]\n"
2126 " set interface ipsec [SharedSecretEncryption {Keychain}]\n"
2129 #define N_L2TP_IPSEC_OPTIONS (sizeof(l2tp_ipsecOptions) / sizeof(l2tp_ipsecOptions[0]))
2133 __doPPPIPSec(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newPPPConfiguration
)
2136 #pragma unused(description)
2137 #pragma unused(info)
2138 #pragma unused(newPPPConfiguration)
2139 SCNetworkInterfaceRef childInterface
;
2140 CFStringRef childInterfaceType
;
2141 CFDictionaryRef configuration
;
2142 CFMutableDictionaryRef newConfiguration
;
2146 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
2150 childInterface
= SCNetworkInterfaceGetInterface(net_interface
);
2151 if (childInterface
== NULL
) {
2152 SCPrint(TRUE
, stdout
, CFSTR("this interfaces configuration cannot be changed\n"));
2156 childInterfaceType
= SCNetworkInterfaceGetInterfaceType(childInterface
);
2157 if (!CFEqual(childInterfaceType
, kSCNetworkInterfaceTypeL2TP
)) {
2158 SCPrint(TRUE
, stdout
, CFSTR("this interfaces configuration cannot be changed\n"));
2162 configuration
= SCNetworkInterfaceGetExtendedConfiguration(net_interface
, kSCEntNetIPSec
);
2163 if (configuration
== NULL
) {
2164 newConfiguration
= CFDictionaryCreateMutable(NULL
,
2166 &kCFTypeDictionaryKeyCallBacks
,
2167 &kCFTypeDictionaryValueCallBacks
);
2169 newConfiguration
= CFDictionaryCreateMutableCopy(NULL
, 0, configuration
);
2170 CFDictionaryRemoveValue(newConfiguration
, kSCResvInactive
);
2173 ok
= _process_options(l2tp_ipsecOptions
, N_L2TP_IPSEC_OPTIONS
, argc
, argv
, newConfiguration
);
2178 if (((configuration
== NULL
) && (CFDictionaryGetCount(newConfiguration
) > 0)) ||
2179 ((configuration
!= NULL
) && !CFEqual(configuration
, newConfiguration
))) {
2180 if (!SCNetworkInterfaceSetExtendedConfiguration(net_interface
, kSCEntNetIPSec
, newConfiguration
)) {
2181 if (SCError() == kSCStatusNoKey
) {
2182 SCPrint(TRUE
, stdout
, CFSTR("could not update per-service interface configuration\n"));
2184 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
2189 _prefs_changed
= TRUE
;
2194 if (newConfiguration
!= NULL
) CFRelease(newConfiguration
);
2200 static options pppOnDemandOptions
[] = {
2201 { "OnDemandMatchDomainsAlways" , "domain", isOther
, &kSCPropNetPPPOnDemandMatchDomainsAlways
, __doOnDemandDomains
, NULL
},
2202 { "always" , "domain", isOther
, &kSCPropNetPPPOnDemandMatchDomainsAlways
, __doOnDemandDomains
, NULL
},
2203 { "OnDemandMatchDomainsOnRetry", "domain", isOther
, &kSCPropNetPPPOnDemandMatchDomainsOnRetry
, __doOnDemandDomains
, NULL
},
2204 { "retry" , "domain", isOther
, &kSCPropNetPPPOnDemandMatchDomainsOnRetry
, __doOnDemandDomains
, NULL
},
2205 { "OnDemandMatchDomainsNever" , "domain", isOther
, &kSCPropNetPPPOnDemandMatchDomainsNever
, __doOnDemandDomains
, NULL
},
2206 { "never" , "domain", isOther
, &kSCPropNetPPPOnDemandMatchDomainsNever
, __doOnDemandDomains
, NULL
},
2208 { "?" , NULL
, isHelp
, NULL
, NULL
,
2209 "\nOnDemandMatch configuration commands\n\n"
2210 " set interface OnDemand always domain-name[,domain-name]\n"
2211 " set interface OnDemand retry domain-name[,domain-name]\n"
2212 " set interface OnDemand never domain-name[,domain-name]\n"
2215 #define N_PPP_ONDEMAND_OPTIONS (sizeof(pppOnDemandOptions) / sizeof(pppOnDemandOptions[0]))
2219 __doPPPOnDemandMatch(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
2224 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
2228 ok
= _process_options(pppOnDemandOptions
, N_PPP_ONDEMAND_OPTIONS
, argc
, argv
, newConfiguration
);
2240 static selections authPromptSelections
[] = {
2241 { CFSTR("before"), &kSCValNetPPPAuthPromptBefore
, 0 },
2242 { CFSTR("after") , &kSCValNetPPPAuthPromptAfter
, 0 },
2247 static selections authProtocolSelections
[] = {
2248 { CFSTR("CHAP") , &kSCValNetPPPAuthProtocolCHAP
, 0 },
2249 { CFSTR("EAP") , &kSCValNetPPPAuthProtocolEAP
, 0 },
2250 { CFSTR("MSCHAP1"), &kSCValNetPPPAuthProtocolMSCHAP1
, 0 },
2251 { CFSTR("MSCHAP2"), &kSCValNetPPPAuthProtocolMSCHAP2
, 0 },
2252 { CFSTR("PAP") , &kSCValNetPPPAuthProtocolPAP
, 0 },
2257 static options pppOptions
[] = {
2258 { "ACSP" , NULL
, isBoolean
, &kSCPropNetPPPACSPEnabled
, NULL
, NULL
},
2259 { "ConnectTime" , "?time" , isNumber
, &kSCPropNetPPPConnectTime
, NULL
, NULL
},
2260 { "DialOnDemand" , NULL
, isBoolean
, &kSCPropNetPPPDialOnDemand
, NULL
, NULL
},
2261 { "DisconnectOnFastUserSwitch", NULL
, isBoolean
, &kSCPropNetPPPDisconnectOnFastUserSwitch
, NULL
, NULL
},
2262 { "DisconnectOnIdle" , NULL
, isBoolean
, &kSCPropNetPPPDisconnectOnIdle
, NULL
, NULL
},
2263 { "DisconnectOnIdleTimer" , "timeout" , isNumber
, &kSCPropNetPPPDisconnectOnIdleTimer
, NULL
, NULL
},
2264 { "DisconnectOnLogout" , NULL
, isBoolean
, &kSCPropNetPPPDisconnectOnLogout
, NULL
, NULL
},
2265 { "DisconnectOnSleep" , NULL
, isBoolean
, &kSCPropNetPPPDisconnectOnSleep
, NULL
, NULL
},
2266 { "DisconnectTime" , "?time" , isNumber
, &kSCPropNetPPPDisconnectTime
, NULL
, NULL
},
2267 { "IdleReminder" , NULL
, isBoolean
, &kSCPropNetPPPIdleReminder
, NULL
, NULL
},
2268 { "IdleReminderTimer" , "time" , isNumber
, &kSCPropNetPPPIdleReminderTimer
, NULL
, NULL
},
2269 { "Logfile" , "path" , isString
, &kSCPropNetPPPLogfile
, NULL
, NULL
},
2270 #pragma GCC diagnostic push
2271 #pragma GCC diagnostic ignored "-Wdeprecated"
2272 { "Plugins" , "plugin" , isStringArray
, &kSCPropNetPPPPlugins
, NULL
, NULL
},
2273 #pragma GCC diagnostic pop
2274 { "RetryConnectTime" , "time" , isNumber
, &kSCPropNetPPPRetryConnectTime
, NULL
, NULL
},
2275 { "SessionTimer" , "time" , isNumber
, &kSCPropNetPPPSessionTimer
, NULL
, NULL
},
2276 { "UseSessionTimer" , NULL
, isBoolean
, &kSCPropNetPPPUseSessionTimer
, NULL
, NULL
},
2277 { "VerboseLogging" , NULL
, isBoolean
, &kSCPropNetPPPVerboseLogging
, NULL
, NULL
},
2280 #pragma GCC diagnostic push
2281 #pragma GCC diagnostic ignored "-Wdeprecated"
2282 { "AuthEAPPlugins" , "plugin" , isStringArray
, &kSCPropNetPPPAuthEAPPlugins
, NULL
, NULL
},
2283 #pragma GCC diagnostic pop
2284 { "AuthName" , "account" , isString
, &kSCPropNetPPPAuthName
, NULL
, NULL
},
2285 { "Account" , "account" , isString
, &kSCPropNetPPPAuthName
, NULL
, NULL
},
2286 { "AuthPassword" , "password" , isOther
, &kSCPropNetPPPAuthPassword
, __doPPPAuthPW
, NULL
},
2287 { "Password" , "password" , isOther
, &kSCPropNetPPPAuthPassword
, __doPPPAuthPW
, NULL
},
2288 { "AuthPasswordEncryption" , "type" , isOther
, &kSCPropNetPPPAuthPasswordEncryption
, __doPPPAuthPWType
, NULL
},
2289 { "AuthPrompt" , "before/after", isChooseOne
, &kSCPropNetPPPAuthPrompt
, NULL
, (void *)authPromptSelections
},
2290 { "AuthProtocol" , "protocol" , isChooseMultiple
, &kSCPropNetPPPAuthProtocol
, NULL
, (void *)authProtocolSelections
},
2293 { "CommRemoteAddress" , "phone#" , isString
, &kSCPropNetPPPCommRemoteAddress
, NULL
, NULL
},
2294 { "Number" , "phone#" , isString
, &kSCPropNetPPPCommRemoteAddress
, NULL
, NULL
},
2295 { "CommAlternateRemoteAddress", "phone#" , isString
, &kSCPropNetPPPCommAlternateRemoteAddress
, NULL
, NULL
},
2296 { "CommConnectDelay" , "time" , isNumber
, &kSCPropNetPPPCommConnectDelay
, NULL
, NULL
},
2297 { "CommDisplayTerminalWindow" , NULL
, isBoolean
, &kSCPropNetPPPCommDisplayTerminalWindow
, NULL
, NULL
},
2298 { "CommRedialCount" , "retry count" , isNumber
, &kSCPropNetPPPCommRedialCount
, NULL
, NULL
},
2299 { "CommRedialEnabled" , NULL
, isBoolean
, &kSCPropNetPPPCommRedialEnabled
, NULL
, NULL
},
2300 { "CommRedialInterval" , "retry delay" , isNumber
, &kSCPropNetPPPCommRedialInterval
, NULL
, NULL
},
2301 { "CommTerminalScript" , "script" , isString
, &kSCPropNetPPPCommTerminalScript
, NULL
, NULL
},
2302 { "CommUseTerminalScript" , NULL
, isBoolean
, &kSCPropNetPPPCommUseTerminalScript
, NULL
, NULL
},
2305 { "CCPEnabled" , NULL
, isBoolean
, &kSCPropNetPPPCCPEnabled
, NULL
, NULL
},
2306 { "CCPMPPE40Enabled" , NULL
, isBoolean
, &kSCPropNetPPPCCPMPPE40Enabled
, NULL
, NULL
},
2307 { "CCPMPPE128Enabled" , NULL
, isBoolean
, &kSCPropNetPPPCCPMPPE128Enabled
, NULL
, NULL
},
2310 { "IPCPCompressionVJ" , NULL
, isBoolean
, &kSCPropNetPPPIPCPCompressionVJ
, NULL
, NULL
},
2311 { "IPCPUsePeerDNS" , NULL
, isBoolean
, &kSCPropNetPPPIPCPUsePeerDNS
, NULL
, NULL
},
2314 { "LCPEchoEnabled" , NULL
, isBoolean
, &kSCPropNetPPPLCPEchoEnabled
, NULL
, NULL
},
2315 { "LCPEchoFailure" , NULL
, isNumber
, &kSCPropNetPPPLCPEchoFailure
, NULL
, NULL
},
2316 { "LCPEchoInterval" , NULL
, isNumber
, &kSCPropNetPPPLCPEchoInterval
, NULL
, NULL
},
2317 { "LCPCompressionACField" , NULL
, isBoolean
, &kSCPropNetPPPLCPCompressionACField
, NULL
, NULL
},
2318 { "LCPCompressionPField" , NULL
, isBoolean
, &kSCPropNetPPPLCPCompressionPField
, NULL
, NULL
},
2319 { "LCPMRU" , NULL
, isNumber
, &kSCPropNetPPPLCPMRU
, NULL
, NULL
},
2320 { "LCPMTU" , NULL
, isNumber
, &kSCPropNetPPPLCPMTU
, NULL
, NULL
},
2321 { "LCPReceiveACCM" , NULL
, isNumber
, &kSCPropNetPPPLCPReceiveACCM
, NULL
, NULL
},
2322 { "LCPTransmitACCM" , NULL
, isNumber
, &kSCPropNetPPPLCPTransmitACCM
, NULL
, NULL
},
2325 { "IPSec" , NULL
, isOther
, NULL
, __doPPPIPSec
, NULL
},
2328 // --- OnDemand: ---
2329 { "OnDemandEnabled" , NULL
, isBoolean
, &kSCPropNetPPPOnDemandEnabled
, NULL
, NULL
},
2330 { "OnDemandMatch" , NULL
, isOther
, NULL
, __doPPPOnDemandMatch
, NULL
},
2334 { "?" , NULL
, isHelp
, NULL
, NULL
,
2335 "\nPPP configuration commands\n\n"
2336 " set interface [Account account]\n"
2337 " set interface [Password password]\n"
2338 " set interface [Number telephone-number]\n"
2339 " set interface [AlternateNumber telephone-number]\n"
2340 " set interface [IdleReminder {enable|disable}]\n"
2341 " set interface [IdleReminderTimer time-in-seconds]\n"
2342 " set interface [DisconnectOnIdle {enable|disable}]\n"
2343 " set interface [DisconnectOnIdleTimer time-in-seconds]\n"
2344 " set interface [DisconnectOnLogout {enable|disable}]\n"
2345 " set interface [IPSec <ipsec-options>]\n"
2347 " set interface [OnDemandEnabled {enable|disable}]\n"
2348 " set interface [OnDemandMatch <match-options>]\n"
2352 #define N_PPP_OPTIONS (sizeof(pppOptions) / sizeof(pppOptions[0]))
2356 set_interface_ppp(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
2360 ok
= _process_options(pppOptions
, N_PPP_OPTIONS
, argc
, argv
, newConfiguration
);
2366 #pragma mark VLAN options
2370 set_interface_vlan(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
2372 #pragma unused(argc)
2373 #pragma unused(argv)
2374 #pragma unused(newConfiguration)
2375 // xxxxx ("device", "tag")
2376 SCPrint(TRUE
, stdout
, CFSTR("vlan interface management not yet supported\n"));
2382 #pragma mark VPN options
2386 __doVPNAuthPW(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
2388 #pragma unused(description)
2389 #pragma unused(info)
2390 CFStringRef encryptionType
;
2393 SCPrint(TRUE
, stdout
, CFSTR("VPN password not specified\n"));
2397 encryptionType
= CFDictionaryGetValue(newConfiguration
, kSCPropNetVPNAuthPasswordEncryption
);
2398 if (strlen(argv
[0]) > 0) {
2399 if (encryptionType
== NULL
) {
2400 #ifdef INLINE_PASSWORDS_USE_CFSTRING
2403 pw
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
2404 #else // INLINE_PASSWORDS_USE_CFSTRING
2406 CFMutableDataRef pw
;
2409 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
2410 n
= CFStringGetLength(str
);
2411 pw
= CFDataCreateMutable(NULL
, n
* sizeof(UniChar
));
2412 CFDataSetLength(pw
, n
* sizeof(UniChar
));
2413 CFStringGetCharacters(str
,
2415 (UniChar
*)(void *)CFDataGetMutableBytePtr(pw
));
2417 #endif // INLINE_PASSWORDS_USE_CFSTRING
2419 CFDictionarySetValue(newConfiguration
, key
, pw
);
2421 } else if (CFEqual(encryptionType
, kSCValNetVPNAuthPasswordEncryptionKeychain
)) {
2426 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
2427 pw
= CFStringCreateExternalRepresentation(NULL
, str
, kCFStringEncodingUTF8
, 0);
2428 ok
= SCNetworkInterfaceSetPassword(net_interface
,
2429 kSCNetworkInterfacePasswordTypeVPN
,
2435 updateInterfaceConfiguration(newConfiguration
);
2440 SCPrint(TRUE
, stdout
, CFSTR("VPN password type \"%@\" not supported\n"), encryptionType
);
2444 if (encryptionType
== NULL
) {
2445 CFDictionaryRemoveValue(newConfiguration
, key
);
2446 } else if (CFEqual(encryptionType
, kSCValNetVPNAuthPasswordEncryptionKeychain
)) {
2449 ok
= SCNetworkInterfaceRemovePassword(net_interface
, kSCNetworkInterfacePasswordTypeVPN
);
2451 updateInterfaceConfiguration(newConfiguration
);
2456 SCPrint(TRUE
, stdout
, CFSTR("PPP password type \"%@\" not supported\n"), encryptionType
);
2466 __doVPNAuthPWType(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
2468 #pragma unused(description)
2469 #pragma unused(info)
2471 SCPrint(TRUE
, stdout
, CFSTR("VPN password type mode not specified\n"));
2475 if (strlen(argv
[0]) > 0) {
2476 if (strcasecmp(argv
[0], "keychain") == 0) {
2477 CFDictionarySetValue(newConfiguration
, key
, kSCValNetVPNAuthPasswordEncryptionKeychain
);
2478 } else if (strcasecmp(argv
[0], "prompt") == 0) {
2479 CFDictionarySetValue(newConfiguration
, key
, kSCValNetVPNAuthPasswordEncryptionPrompt
);
2481 SCPrint(TRUE
, stdout
, CFSTR("invalid password type\n"));
2485 CFDictionaryRemoveValue(newConfiguration
, key
);
2488 // encryption type changed, reset password
2489 CFDictionaryRemoveValue(newConfiguration
, kSCPropNetVPNAuthPassword
);
2495 static selections vpnAuthenticationMethodSelections
[] = {
2496 { CFSTR("Password") , &kSCValNetVPNAuthenticationMethodPassword
, 0 },
2497 { CFSTR("Certificate") , &kSCValNetVPNAuthenticationMethodCertificate
, 0 },
2502 static options vpnOptions
[] = {
2503 { "AuthName" , "account" , isString
, &kSCPropNetVPNAuthName
, NULL
, NULL
},
2504 { "Account" , "account" , isString
, &kSCPropNetVPNAuthName
, NULL
, NULL
},
2505 { "AuthPassword" , "password" , isOther
, &kSCPropNetVPNAuthPassword
, __doVPNAuthPW
, NULL
},
2506 { "Password" , "password" , isOther
, &kSCPropNetVPNAuthPassword
, __doVPNAuthPW
, NULL
},
2507 { "AuthPasswordEncryption" , "type" , isOther
, &kSCPropNetVPNAuthPasswordEncryption
, __doVPNAuthPWType
, NULL
},
2508 { "AuthenticationMethod" , NULL
, isChooseOne
, &kSCPropNetVPNAuthenticationMethod
, NULL
, (void *)vpnAuthenticationMethodSelections
},
2509 { "ConnectTime" , "?time" , isNumber
, &kSCPropNetVPNConnectTime
, NULL
, NULL
},
2510 { "DisconnectOnFastUserSwitch", NULL
, isBoolean
, &kSCPropNetVPNDisconnectOnFastUserSwitch
, NULL
, NULL
},
2511 { "DisconnectOnIdle" , NULL
, isBoolean
, &kSCPropNetVPNDisconnectOnIdle
, NULL
, NULL
},
2512 { "DisconnectOnIdleTimer" , "timeout" , isNumber
, &kSCPropNetVPNDisconnectOnIdleTimer
, NULL
, NULL
},
2513 { "DisconnectOnLogout" , NULL
, isBoolean
, &kSCPropNetVPNDisconnectOnLogout
, NULL
, NULL
},
2514 { "DisconnectOnSleep" , NULL
, isBoolean
, &kSCPropNetVPNDisconnectOnSleep
, NULL
, NULL
},
2515 { "Logfile" , "path" , isString
, &kSCPropNetVPNLogfile
, NULL
, NULL
},
2516 { "MTU" , NULL
, isNumber
, &kSCPropNetVPNMTU
, NULL
, NULL
},
2517 { "RemoteAddress" , "server" , isString
, &kSCPropNetVPNRemoteAddress
, NULL
, NULL
},
2518 { "Server" , "server" , isString
, &kSCPropNetVPNRemoteAddress
, NULL
, NULL
},
2519 { "VerboseLogging" , NULL
, isBoolean
, &kSCPropNetVPNVerboseLogging
, NULL
, NULL
},
2522 { "?" , NULL
, isHelp
, NULL
, NULL
,
2523 "\nVPN configuration commands\n\n"
2524 " set interface [Server server]\n"
2525 " set interface [Account account]\n"
2526 " set interface [Password password]\n"
2529 #define N_VPN_OPTIONS (sizeof(vpnOptions) / sizeof(vpnOptions[0]))
2533 set_interface_vpn(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
2537 ok
= _process_options(vpnOptions
, N_VPN_OPTIONS
, argc
, argv
, newConfiguration
);
2543 #pragma mark [more] Interface management
2548 set_interface(int argc
, char **argv
)
2550 CFDictionaryRef configuration
;
2551 CFStringRef interfaceType
;
2552 CFMutableDictionaryRef newConfiguration
= NULL
;
2555 if (net_interface
== NULL
) {
2556 SCPrint(TRUE
, stdout
, CFSTR("interface not selected\n"));
2561 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
2565 configuration
= SCNetworkInterfaceGetConfiguration(net_interface
);
2566 if (configuration
!= NULL
) {
2567 configuration
= CFDictionaryCreateCopy(NULL
, configuration
);
2568 newConfiguration
= CFDictionaryCreateMutableCopy(NULL
, 0, configuration
);
2569 CFDictionaryRemoveValue(newConfiguration
, kSCResvInactive
);
2571 newConfiguration
= CFDictionaryCreateMutable(NULL
,
2573 &kCFTypeDictionaryKeyCallBacks
,
2574 &kCFTypeDictionaryValueCallBacks
);
2577 interfaceType
= SCNetworkInterfaceGetInterfaceType(net_interface
);
2579 if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeEthernet
)) {
2580 ok
= set_interface_ethernet(argc
, argv
, newConfiguration
);
2581 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeFireWire
)) {
2582 ok
= set_interface_firewire(argc
, argv
, newConfiguration
);
2583 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeIPSec
)) {
2584 ok
= set_interface_ipsec(argc
, argv
, newConfiguration
);
2585 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeModem
)) {
2586 ok
= set_interface_modem(argc
, argv
, newConfiguration
);
2587 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeIEEE80211
)) {
2588 ok
= set_interface_airport(argc
, argv
, newConfiguration
);
2589 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypePPP
)) {
2590 ok
= set_interface_ppp(argc
, argv
, newConfiguration
);
2591 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeBond
)) {
2592 ok
= set_interface_bond(argc
, argv
, newConfiguration
);
2593 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeBridge
)) {
2594 ok
= set_interface_bridge(argc
, argv
, newConfiguration
);
2595 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeVLAN
)) {
2596 ok
= set_interface_vlan(argc
, argv
, newConfiguration
);
2597 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeVPN
)) {
2598 ok
= set_interface_vpn(argc
, argv
, newConfiguration
);
2600 SCPrint(TRUE
, stdout
, CFSTR("this interfaces configuration cannot be changed\n"));
2607 if (((configuration
== NULL
) && (CFDictionaryGetCount(newConfiguration
) > 0)) ||
2608 ((configuration
!= NULL
) && !CFEqual(configuration
, newConfiguration
))) {
2609 if (!SCNetworkInterfaceSetConfiguration(net_interface
, newConfiguration
)) {
2610 if (SCError() == kSCStatusNoKey
) {
2611 SCPrint(TRUE
, stdout
, CFSTR("could not update per-service interface configuration\n"));
2613 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
2618 _prefs_changed
= TRUE
;
2623 if (configuration
!= NULL
) CFRelease(configuration
);
2624 if (newConfiguration
!= NULL
) CFRelease(newConfiguration
);
2629 /* -------------------- */
2634 show_interface(int argc
, char **argv
)
2636 SCNetworkInterfaceRef interface
;
2639 interface
= _find_interface(argc
, argv
, NULL
);
2641 if (net_interface
!= NULL
) {
2642 interface
= net_interface
;
2644 SCPrint(TRUE
, stdout
, CFSTR("interface not selected\n"));
2649 if (interface
!= NULL
) {
2650 _show_interface(interface
, CFSTR(""), TRUE
);
2657 /* -------------------- */
2661 CF_RETURNS_RETAINED CFStringRef
2662 _interface_description(SCNetworkInterfaceRef interface
)
2664 CFMutableStringRef description
;
2665 CFStringRef if_bsd_name
;
2666 CFStringRef if_type
;
2668 description
= CFStringCreateMutable(NULL
, 0);
2670 if_type
= SCNetworkInterfaceGetInterfaceType(interface
);
2671 CFStringAppend(description
, if_type
);
2673 if_bsd_name
= SCNetworkInterfaceGetBSDName(interface
);
2674 if (if_bsd_name
!= NULL
) {
2675 CFStringAppendFormat(description
, NULL
, CFSTR(" (%@)"), if_bsd_name
);
2678 interface
= SCNetworkInterfaceGetInterface(interface
);
2679 while ((interface
!= NULL
) &&
2680 !CFEqual(interface
, kSCNetworkInterfaceIPv4
)) {
2681 CFStringRef childDescription
;
2683 childDescription
= _interface_description(interface
);
2684 CFStringAppendFormat(description
, NULL
, CFSTR(" / %@"), childDescription
);
2685 CFRelease(childDescription
);
2687 interface
= SCNetworkInterfaceGetInterface(interface
);