2 * Copyright (c) 2004-2011 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>
37 #include <SystemConfiguration/LinkConfiguration.h>
40 #if TARGET_OS_EMBEDDED
41 #define INLINE_PASSWORDS_USE_CFSTRING
42 #endif // TARGET_OS_EMBEDDED
46 #pragma mark Interface management
52 CFMutableArrayRef interfaces
;
53 CFArrayRef real_interfaces
;
55 real_interfaces
= _SCNetworkInterfaceCopyAllWithPreferences(prefs
);
56 if (real_interfaces
== NULL
) {
57 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
61 interfaces
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
63 // include real interfaces
64 CFArrayAppendArray(interfaces
,
66 CFRangeMake(0, CFArrayGetCount(real_interfaces
)));
67 CFRelease(real_interfaces
);
69 // include pseudo interfaces
70 CFArrayAppendValue(interfaces
, kSCNetworkInterfaceLoopback
);
71 CFArrayAppendValue(interfaces
, kSCNetworkInterfaceIPv4
);
73 // include interfaces that we have created
74 if (new_interfaces
!= NULL
) {
75 CFArrayAppendArray(interfaces
,
77 CFRangeMake(0, CFArrayGetCount(new_interfaces
)));
80 return (CFArrayRef
)interfaces
;
86 _find_interface(int argc
, char **argv
, int *nArgs
)
88 Boolean allowIndex
= TRUE
;
90 CFArrayRef myInterfaces
= interfaces
;
92 CFStringRef select_name
= NULL
;
93 SCNetworkInterfaceRef selected
= NULL
;
96 SCPrint(TRUE
, stdout
, CFSTR("no interface specified\n"));
100 if (nArgs
!= NULL
) *nArgs
= 1;
102 if (strcasecmp(argv
[0], "$child") == 0) {
103 if (net_interface
== NULL
) {
104 SCPrint(TRUE
, stdout
, CFSTR("interface not selected\n"));
108 selected
= SCNetworkInterfaceGetInterface(net_interface
);
109 if(selected
== NULL
) {
110 SCPrint(TRUE
, stdout
, CFSTR("no child interface\n"));
114 } else if (strcasecmp(argv
[0], "$service") == 0) {
115 if (net_service
== NULL
) {
116 SCPrint(TRUE
, stdout
, CFSTR("service not selected\n"));
120 selected
= SCNetworkServiceGetInterface(net_service
);
121 if(selected
== NULL
) {
122 SCPrint(TRUE
, stdout
, CFSTR("no interface for service\n"));
128 #if !TARGET_OS_IPHONE
129 else if (strcasecmp(argv
[0], "$bond") == 0) {
130 CFStringRef interfaceType
;
132 if (net_interface
== NULL
) {
133 SCPrint(TRUE
, stdout
, CFSTR("interface not selected\n"));
137 interfaceType
= SCNetworkInterfaceGetInterfaceType(net_interface
);
138 if (!CFEqual(interfaceType
, kSCNetworkInterfaceTypeBond
)) {
139 SCPrint(TRUE
, stdout
, CFSTR("interface not Bond\n"));
144 SCPrint(TRUE
, stdout
, CFSTR("no member interface specified\n"));
149 if (nArgs
!= NULL
) *nArgs
+= 1;
151 myInterfaces
= SCBondInterfaceGetMemberInterfaces(net_interface
);
152 if (myInterfaces
== NULL
) {
153 SCPrint(TRUE
, stdout
, CFSTR("no member interfaces\n"));
158 #endif // !TARGET_OS_IPHONE
160 else if (strcasecmp(argv
[0], "$bridge") == 0) {
161 CFStringRef interfaceType
;
163 if (net_interface
== NULL
) {
164 SCPrint(TRUE
, stdout
, CFSTR("interface not selected\n"));
168 interfaceType
= SCNetworkInterfaceGetInterfaceType(net_interface
);
169 if (!CFEqual(interfaceType
, kSCNetworkInterfaceTypeBridge
)) {
170 SCPrint(TRUE
, stdout
, CFSTR("interface not Bridge\n"));
175 SCPrint(TRUE
, stdout
, CFSTR("no member interface specified\n"));
180 if (nArgs
!= NULL
) *nArgs
+= 1;
182 myInterfaces
= SCBridgeInterfaceGetMemberInterfaces(net_interface
);
183 if (myInterfaces
== NULL
) {
184 SCPrint(TRUE
, stdout
, CFSTR("no member interfaces\n"));
190 else if (strcasecmp(argv
[0], "$vlan") == 0) {
191 CFStringRef interfaceType
;
193 if (net_interface
== NULL
) {
194 SCPrint(TRUE
, stdout
, CFSTR("interface not selected\n"));
198 interfaceType
= SCNetworkInterfaceGetInterfaceType(net_interface
);
199 if (!CFEqual(interfaceType
, kSCNetworkInterfaceTypeVLAN
)) {
200 SCPrint(TRUE
, stdout
, CFSTR("interface not VLAN\n"));
204 selected
= SCVLANInterfaceGetPhysicalInterface(net_interface
);
205 if(selected
== NULL
) {
206 SCPrint(TRUE
, stdout
, CFSTR("no physical interface\n"));
212 if ((myInterfaces
== NULL
) && (interfaces
== NULL
)) {
213 interfaces
= _copy_interfaces();
214 if (interfaces
== NULL
) {
217 myInterfaces
= interfaces
;
221 // try to select the interface by its display name
223 select_name
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
225 n
= (myInterfaces
!= NULL
) ? CFArrayGetCount(myInterfaces
) : 0;
226 for (i
= 0; i
< n
; i
++) {
227 SCNetworkInterfaceRef interface
;
228 CFStringRef interfaceName
;
230 interface
= CFArrayGetValueAtIndex(myInterfaces
, i
);
231 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
232 if ((interfaceName
!= NULL
) && CFEqual(select_name
, interfaceName
)) {
233 if (selected
== NULL
) {
234 selected
= interface
;
236 // if multiple interfaces match
238 SCPrint(TRUE
, stdout
, CFSTR("multiple interfaces match\n"));
244 if (selected
!= NULL
) {
248 // try to select the interface by its BSD name
250 for (i
= 0; i
< n
; i
++) {
251 SCNetworkInterfaceRef interface
;
252 CFStringRef bsd_name
= NULL
;
254 interface
= CFArrayGetValueAtIndex(myInterfaces
, i
);
255 while ((interface
!= NULL
) && (bsd_name
== NULL
)) {
256 bsd_name
= SCNetworkInterfaceGetBSDName(interface
);
257 if (bsd_name
== NULL
) {
258 interface
= SCNetworkInterfaceGetInterface(interface
);
262 if ((bsd_name
!= NULL
) && CFEqual(select_name
, bsd_name
)) {
263 if (selected
== NULL
) {
264 selected
= interface
;
266 // if multiple interfaces match
268 SCPrint(TRUE
, stdout
, CFSTR("multiple interfaces match\n"));
274 if (selected
!= NULL
) {
278 // try to select the interface by its interface type
280 for (i
= 0; i
< n
; i
++) {
281 SCNetworkInterfaceRef interface
;
282 CFStringRef interfaceType
;
284 interface
= CFArrayGetValueAtIndex(myInterfaces
, i
);
285 interfaceType
= SCNetworkInterfaceGetInterfaceType(interface
);
286 if (CFEqual(select_name
, interfaceType
)) {
287 if (selected
== NULL
) {
288 selected
= interface
;
290 // if multiple interfaces match
292 SCPrint(TRUE
, stdout
, CFSTR("multiple interfaces match\n"));
298 if (selected
!= NULL
) {
307 // try to select the interface by its index
310 val
= strtol(str
, &end
, 10);
311 if ((*str
!= '\0') &&
312 ((*end
== '\0') || (*end
== '.')) &&
314 if ((val
> 0) && (val
<= n
)) {
315 selected
= CFArrayGetValueAtIndex(myInterfaces
, val
- 1);
319 val
= strtol(str
, &end
, 10);
320 if ((*str
!= '\0') && (*end
== '\0') && (errno
== 0)) {
322 selected
= SCNetworkInterfaceGetInterface(selected
);
323 if (selected
== NULL
) {
333 if (selected
!= NULL
) {
337 SCPrint(TRUE
, stdout
, CFSTR("no match\n"));
341 if (select_name
!= NULL
) CFRelease(select_name
);
346 /* -------------------- */
351 create_interface(int argc
, char **argv
)
353 SCNetworkInterfaceRef interface
;
354 CFStringRef interfaceName
;
355 CFStringRef interfaceType
;
356 SCNetworkInterfaceRef new_interface
;
359 SCPrint(TRUE
, stdout
, CFSTR("what interface type?\n"));
363 interfaceType
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
367 if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeBond
)) {
368 SCPrint(TRUE
, stdout
, CFSTR("bond creation not yet supported\n"));
371 if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeBridge
)) {
372 SCPrint(TRUE
, stdout
, CFSTR("bridge creation not yet supported\n"));
375 if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeVLAN
)) {
376 SCPrint(TRUE
, stdout
, CFSTR("vlan creation not yet supported\n"));
381 if (net_interface
== NULL
) {
382 SCPrint(TRUE
, stdout
, CFSTR("no network interface selected\n"));
386 interface
= net_interface
;
388 interface
= _find_interface(argc
, argv
, NULL
);
391 if (interface
== NULL
) {
395 new_interface
= SCNetworkInterfaceCreateWithInterface(interface
, interfaceType
);
396 if (new_interface
== NULL
) {
397 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
401 if (new_interfaces
== NULL
) {
402 new_interfaces
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
404 CFArrayAppendValue(new_interfaces
, new_interface
);
406 if (net_interface
!= NULL
) CFRelease(net_interface
);
407 net_interface
= new_interface
;
409 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(net_interface
);
410 if (interfaceName
== NULL
) {
411 interfaceName
= SCNetworkInterfaceGetBSDName(net_interface
);
413 if (interfaceName
== NULL
) {
414 interfaceName
= SCNetworkInterfaceGetInterfaceType(net_interface
);
416 SCPrint(TRUE
, stdout
, CFSTR("interface \"%@\" created and selected\n"), interfaceName
);
420 CFRelease(interfaceType
);
425 /* -------------------- */
430 select_interface(int argc
, char **argv
)
432 SCNetworkInterfaceRef interface
;
434 interface
= _find_interface(argc
, argv
, NULL
);
435 if (interface
!= NULL
) {
436 CFStringRef interfaceName
;
438 if (net_interface
!= NULL
) CFRelease(net_interface
);
439 net_interface
= CFRetain(interface
);
441 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
442 if (interfaceName
== NULL
) {
443 interfaceName
= SCNetworkInterfaceGetBSDName(interface
);
445 if (interfaceName
== NULL
) {
446 interfaceName
= SCNetworkInterfaceGetInterfaceType(interface
);
449 SCPrint(TRUE
, stdout
, CFSTR("interface \"%@\" selected\n"), interfaceName
);
456 /* -------------------- */
461 _show_interface(SCNetworkInterfaceRef interface
, CFStringRef prefix
, Boolean showChild
)
463 CFDictionaryRef configuration
;
464 CFStringRef if_bsd_name
;
465 CFStringRef if_localized_name
;
466 CFStringRef if_mac_address
;
468 CFArrayRef supported
;
470 if_localized_name
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
471 if (if_localized_name
!= NULL
) {
472 SCPrint(TRUE
, stdout
, CFSTR("%@ name = %@\n"), prefix
, if_localized_name
);
475 if_bsd_name
= SCNetworkInterfaceGetBSDName(interface
);
476 if (if_bsd_name
!= NULL
) {
477 SCPrint(TRUE
, stdout
, CFSTR("%@ interface name = %@\n"), prefix
, if_bsd_name
);
480 if_type
= SCNetworkInterfaceGetInterfaceType(interface
);
481 SCPrint(TRUE
, stdout
, CFSTR("%@ type = %@\n"), prefix
, if_type
);
483 if_mac_address
= SCNetworkInterfaceGetHardwareAddressString(interface
);
484 if (if_mac_address
!= NULL
) {
485 SCPrint(TRUE
, stdout
, CFSTR("%@ address = %@\n"), prefix
, if_mac_address
);
488 configuration
= SCNetworkInterfaceGetConfiguration(interface
);
489 if ((configuration
!= NULL
) &&
490 CFDictionaryContainsKey(configuration
, kSCResvInactive
)) {
491 configuration
= NULL
;
494 if (if_bsd_name
!= NULL
) {
495 CFArrayRef available
;
496 CFDictionaryRef active
;
497 CFDictionaryRef cap_current
;
502 cap_current
= SCNetworkInterfaceCopyCapability(interface
, NULL
);
503 if (cap_current
!= NULL
) {
505 CFArrayRef cap_names
;
506 CFMutableArrayRef cap_sorted
;
510 n
= CFDictionaryGetCount(cap_current
);
511 keys
= CFAllocatorAllocate(NULL
, n
* sizeof(CFStringRef
), 0);
512 CFDictionaryGetKeysAndValues(cap_current
, keys
, NULL
);
513 cap_names
= CFArrayCreate(NULL
, keys
, n
, &kCFTypeArrayCallBacks
);
514 CFAllocatorDeallocate(NULL
, keys
);
516 cap_sorted
= CFArrayCreateMutableCopy(NULL
, 0, cap_names
);
517 CFRelease(cap_names
);
519 CFArraySortValues(cap_sorted
, CFRangeMake(0, n
), (CFComparatorFunction
)CFStringCompare
, NULL
);
521 SCPrint(TRUE
, stdout
, CFSTR("%@ capabilities = "), prefix
);
522 for (i
= 0; i
< n
; i
++) {
523 CFStringRef cap_name
;
525 CFNumberRef val
= NULL
;
527 cap_name
= CFArrayGetValueAtIndex(cap_sorted
, i
);
528 if (configuration
!= NULL
) {
529 val
= CFDictionaryGetValue(configuration
, cap_name
);
531 if (!isA_CFNumber(val
)) {
532 val
= CFDictionaryGetValue(cap_current
, cap_name
);
535 SCPrint(TRUE
, stdout
, CFSTR("%s%@%c"),
538 (CFNumberGetValue(val
, kCFNumberIntType
, &cap_val
) &&
539 (cap_val
!= 0)) ? '+' : '-');
541 SCPrint(TRUE
, stdout
, CFSTR("\n"));
543 CFRelease(cap_sorted
);
544 CFRelease(cap_current
);
547 if (SCNetworkInterfaceCopyMTU(interface
, &mtu_cur
, &mtu_min
, &mtu_max
)) {
548 char isCurrent
= '*';
550 if (configuration
!= NULL
) {
554 num
= CFDictionaryGetValue(configuration
, kSCPropNetEthernetMTU
);
555 if (isA_CFNumber(num
)) {
556 CFNumberGetValue(num
, kCFNumberIntType
, &mtu_req
);
557 if (mtu_cur
!= mtu_req
) {
564 SCPrint(TRUE
, stdout
, CFSTR("%@ mtu %c = %d (%d < n < %d)\n"),
572 if (SCNetworkInterfaceCopyMediaOptions(interface
, NULL
, &active
, &available
, TRUE
)) {
573 char isCurrent
= ' ';
574 CFArrayRef options
= NULL
;
575 CFArrayRef options_req
= NULL
;
576 CFStringRef subtype
= NULL
;
577 CFStringRef subtype_req
= NULL
;
579 if (configuration
!= NULL
) {
580 subtype_req
= CFDictionaryGetValue(configuration
, kSCPropNetEthernetMediaSubType
);
581 options_req
= CFDictionaryGetValue(configuration
, kSCPropNetEthernetMediaOptions
);
584 if (subtype_req
== NULL
) {
585 subtype_req
= CFSTR("autoselect");
588 if (active
!= NULL
) {
589 subtype
= CFDictionaryGetValue(active
, kSCPropNetEthernetMediaSubType
);
590 options
= CFDictionaryGetValue(active
, kSCPropNetEthernetMediaOptions
);
593 if (subtype
!= NULL
) {
594 if (((subtype_req
!= NULL
) &&
595 CFEqual(subtype
, subtype_req
)) &&
596 ((options
== options_req
) ||
597 ((options
!= NULL
) &&
598 (options_req
!= NULL
) &&
599 CFEqual(options
, options_req
)))
602 } else if ((subtype_req
== NULL
) ||
603 ((subtype_req
!= NULL
) &&
604 CFEqual(subtype_req
, CFSTR("autoselect")))) {
605 // if requested subtype not specified or "autoselect"
610 if (subtype_req
!= NULL
) {
611 SCPrint(TRUE
, stdout
, CFSTR("%@ media %c = %@"),
616 if ((options_req
!= NULL
) &&
617 (CFArrayGetCount(options_req
) > 0)) {
618 CFStringRef options_str
;
620 options_str
= CFStringCreateByCombiningStrings(NULL
, options_req
, CFSTR(","));
621 SCPrint(TRUE
, stdout
, CFSTR(" <%@>"), options_str
);
622 CFRelease(options_str
);
625 SCPrint(TRUE
, stdout
, CFSTR("\n"));
628 SCPrint(TRUE
, stdout
, CFSTR("\n"));
630 if (available
!= NULL
) {
635 subtypes
= SCNetworkInterfaceCopyMediaSubTypes(available
);
636 n_subtypes
= (subtypes
!= NULL
) ? CFArrayGetCount(subtypes
) : 0;
637 for (i
= 0; i
< n_subtypes
; i
++) {
639 CFIndex n_subtype_options
;
641 CFArrayRef subtype_options
;
643 subtype
= CFArrayGetValueAtIndex(subtypes
, i
);
644 subtype_options
= SCNetworkInterfaceCopyMediaSubTypeOptions(available
, subtype
);
645 n_subtype_options
= (subtype_options
!= NULL
) ? CFArrayGetCount(subtype_options
) : 0;
646 for (j
= 0; j
< n_subtype_options
; j
++) {
647 char isCurrent
= ' ';
650 options
= CFArrayGetValueAtIndex(subtype_options
, j
);
652 if (((subtype_req
!= NULL
) &&
653 CFEqual(subtype
, subtype_req
)) &&
654 ((options
== options_req
) ||
655 ((options
!= NULL
) &&
656 (options_req
!= NULL
) &&
657 CFEqual(options
, options_req
)))
662 SCPrint(TRUE
, stdout
, CFSTR("%@ %s %c = %@"),
664 ((i
== 0) && (j
== 0)) ? "supported media" : " ",
668 if ((options
!= NULL
) &&
669 (CFArrayGetCount(options
) > 0)) {
670 CFStringRef options_str
;
672 options_str
= CFStringCreateByCombiningStrings(NULL
, options
, CFSTR(","));
673 SCPrint(TRUE
, stdout
, CFSTR(" <%@>"), options_str
);
674 CFRelease(options_str
);
677 SCPrint(TRUE
, stdout
, CFSTR("\n"));
679 if (subtype_options
!= NULL
) CFRelease(subtype_options
);
681 if (subtypes
!= NULL
) CFRelease(subtypes
);
684 SCPrint(TRUE
, stdout
, CFSTR("\n"));
688 supported
= SCNetworkInterfaceGetSupportedInterfaceTypes(interface
);
689 SCPrint(TRUE
, stdout
, CFSTR("%@ supported interfaces = "), prefix
);
690 if (supported
!= NULL
) {
692 CFIndex n
= CFArrayGetCount(supported
);
694 for (i
= 0; i
< n
; i
++) {
695 SCPrint(TRUE
, stdout
, CFSTR("%s%@"),
696 (i
== 0) ? "" : ", ",
697 CFArrayGetValueAtIndex(supported
, i
));
700 SCPrint(TRUE
, stdout
, CFSTR("\n"));
702 supported
= SCNetworkInterfaceGetSupportedProtocolTypes(interface
);
703 SCPrint(TRUE
, stdout
, CFSTR("%@ supported protocols = "), prefix
);
704 if (supported
!= NULL
) {
706 CFIndex n
= CFArrayGetCount(supported
);
708 for (i
= 0; i
< n
; i
++) {
709 SCPrint(TRUE
, stdout
, CFSTR("%s%@"),
710 (i
== 0) ? "" : ", ",
711 CFArrayGetValueAtIndex(supported
, i
));
714 SCPrint(TRUE
, stdout
, CFSTR("\n"));
716 if (configuration
!= NULL
) {
717 CFMutableDictionaryRef effective
;
719 effective
= CFDictionaryCreateMutableCopy(NULL
, 0, configuration
);
721 // remove known (and already reported) interface configuration keys
722 if (CFDictionaryContainsKey(effective
, kSCResvInactive
)) {
723 CFDictionaryRemoveAllValues(effective
);
725 CFDictionaryRemoveValue(effective
, kSCPropNetEthernetMTU
);
726 CFDictionaryRemoveValue(effective
, kSCPropNetEthernetMediaSubType
);
727 CFDictionaryRemoveValue(effective
, kSCPropNetEthernetMediaOptions
);
729 if (CFDictionaryGetCount(effective
) > 0) {
730 SCPrint(TRUE
, stdout
, CFSTR("\n%@ per-interface configuration\n"), prefix
);
731 _show_entity(effective
, prefix
);
734 CFRelease(effective
);
737 if (CFEqual(if_type
, kSCNetworkInterfaceTypePPP
)) {
738 SCNetworkInterfaceRef childInterface
;
740 childInterface
= SCNetworkInterfaceGetInterface(interface
);
741 if (childInterface
!= NULL
) {
742 CFStringRef childInterfaceType
;
744 childInterfaceType
= SCNetworkInterfaceGetInterfaceType(childInterface
);
745 if (CFEqual(childInterfaceType
, kSCNetworkInterfaceTypeL2TP
)) {
746 CFDictionaryRef ipsec_configuration
;
748 ipsec_configuration
= SCNetworkInterfaceGetExtendedConfiguration(interface
, kSCEntNetIPSec
);
749 if (isA_CFDictionary(ipsec_configuration
) &&
750 (CFDictionaryGetCount(ipsec_configuration
) > 0)) {
751 SCPrint(TRUE
, stdout
, CFSTR("\n%@ per-interface IPSec configuration\n"), prefix
);
752 _show_entity(ipsec_configuration
, prefix
);
759 SCPrint(TRUE
, stdout
, CFSTR("\n%@\n"), interface
);
762 interface
= SCNetworkInterfaceGetInterface(interface
);
763 if (interface
!= NULL
) {
764 CFStringRef newPrefix
;
766 newPrefix
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%@ "), prefix
);
767 SCPrint(TRUE
, stdout
, CFSTR("\n%@child interface\n"), newPrefix
);
768 _show_interface(interface
, newPrefix
, showChild
);
769 CFRelease(newPrefix
);
776 /* -------------------- */
780 validateMediaOptions(SCNetworkInterfaceRef interface
, CFMutableDictionaryRef newConfiguration
)
787 mtu
= CFDictionaryGetValue(newConfiguration
, kSCPropNetEthernetMTU
);
788 if (isA_CFNumber(mtu
)) {
793 if (!SCNetworkInterfaceCopyMTU(interface
, NULL
, &mtu_min
, &mtu_max
)) {
794 SCPrint(TRUE
, stdout
, CFSTR("cannot set MTU\n"));
798 if (!CFNumberGetValue(mtu
, kCFNumberIntType
, &mtu_val
) ||
799 (mtu_val
< mtu_min
) ||
800 (mtu_val
> mtu_max
)) {
801 SCPrint(TRUE
, stdout
, CFSTR("mtu out of range\n"));
806 subtype
= CFDictionaryGetValue(newConfiguration
, kSCPropNetEthernetMediaSubType
);
807 options
= CFDictionaryGetValue(newConfiguration
, kSCPropNetEthernetMediaOptions
);
809 if (subtype
!= NULL
) {
810 CFArrayRef available
= NULL
;
811 CFArrayRef config_options
= options
;
812 CFArrayRef subtypes
= NULL
;
813 CFArrayRef subtype_options
= NULL
;
817 if (options
== NULL
) {
818 config_options
= CFArrayCreate(NULL
, NULL
, 0, &kCFTypeArrayCallBacks
);
821 if (!SCNetworkInterfaceCopyMediaOptions(interface
, NULL
, NULL
, &available
, FALSE
)) {
822 SCPrint(TRUE
, stdout
, CFSTR("media type / options not available\n"));
826 if (available
== NULL
) {
830 subtypes
= SCNetworkInterfaceCopyMediaSubTypes(available
);
831 if ((subtypes
== NULL
) ||
832 !CFArrayContainsValue(subtypes
,
833 CFRangeMake(0, CFArrayGetCount(subtypes
)),
835 SCPrint(TRUE
, stdout
, CFSTR("media type not valid\n"));
839 subtype_options
= SCNetworkInterfaceCopyMediaSubTypeOptions(available
, subtype
);
840 if ((subtype_options
== NULL
) ||
841 !CFArrayContainsValue(subtype_options
,
842 CFRangeMake(0, CFArrayGetCount(subtype_options
)),
844 SCPrint(TRUE
, stdout
, CFSTR("media options not valid for \"%@\"\n"), subtype
);
848 if (options
== NULL
) {
849 CFDictionarySetValue(newConfiguration
, kSCPropNetEthernetMediaOptions
, config_options
);
856 if (available
!= NULL
) CFRelease(available
);
857 if (subtypes
!= NULL
) CFRelease(subtypes
);
858 if (subtype_options
!= NULL
) CFRelease(subtype_options
);
859 if (options
== NULL
) CFRelease(config_options
);
861 if (options
!= NULL
) {
862 SCPrint(TRUE
, stdout
, CFSTR("media type and options must both be specified\n"));
871 /* -------------------- */
876 show_interfaces(int argc
, char **argv
)
881 if (interfaces
!= NULL
) CFRelease(interfaces
);
882 interfaces
= _copy_interfaces();
883 if (interfaces
== NULL
) {
887 n
= CFArrayGetCount(interfaces
);
888 for (i
= 0; i
< n
; i
++) {
889 CFIndex childIndex
= 0;
890 SCNetworkInterfaceRef interface
;
892 interface
= CFArrayGetValueAtIndex(interfaces
, i
);
894 CFStringRef interfaceName
;
897 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
898 if (interfaceName
== NULL
) {
899 interfaceName
= SCNetworkInterfaceGetBSDName(interface
);
901 if (interfaceName
== NULL
) {
902 interfaceName
= SCNetworkInterfaceGetInterfaceType(interface
);
906 if ((net_interface
!= NULL
) && CFEqual(interface
, net_interface
)) {
910 if (childIndex
== 0) {
911 SCPrint(TRUE
, stdout
, CFSTR("%c%2d: %@\n"),
916 SCPrint(TRUE
, stdout
, CFSTR("%c%2d.%d: %@\n"),
923 interface
= SCNetworkInterfaceGetInterface(interface
);
925 } while (interface
!= NULL
);
932 /* -------------------- */
936 __doRank(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
938 SCNetworkInterfaceRef interface
;
939 CFStringRef interfaceName
;
941 SCNetworkServicePrimaryRank rank
= kSCNetworkServicePrimaryRankDefault
;
942 SCDynamicStoreRef store
;
945 SCPrint(TRUE
, stdout
,
946 CFSTR("%s not specified\n"),
947 description
!= NULL
? description
: "rank");
951 if (strlen(argv
[0]) == 0) {
952 rank
= kSCNetworkServicePrimaryRankDefault
;
953 } else if ((strcasecmp(argv
[0], "First") == 0)) {
954 rank
= kSCNetworkServicePrimaryRankFirst
;
955 } else if ((strcasecmp(argv
[0], "Last") == 0)) {
956 rank
= kSCNetworkServicePrimaryRankLast
;
957 } else if ((strcasecmp(argv
[0], "Never") == 0)) {
958 rank
= kSCNetworkServicePrimaryRankNever
;
960 SCPrint(TRUE
, stdout
, CFSTR("invalid rank\n"));
964 interfaceName
= SCNetworkInterfaceGetBSDName(net_interface
);
965 if (interfaceName
== NULL
) {
966 SCPrint(TRUE
, stdout
, CFSTR("no BSD interface\n"));
970 store
= SCDynamicStoreCreate(NULL
, CFSTR("scutil --net"), NULL
, NULL
);
971 interface
= _SCNetworkInterfaceCopyActive(store
, interfaceName
);
973 if (interface
== NULL
) {
974 SCPrint(TRUE
, stdout
, CFSTR("No active interface\n"));
978 ok
= SCNetworkInterfaceSetPrimaryRank(interface
, rank
);
979 CFRelease(interface
);
981 SCPrint(TRUE
, stdout
, CFSTR("could not update per-interface rank\n"));
989 /* -------------------- */
993 _replaceOne(const void *key
, const void *value
, void *context
)
995 CFMutableDictionaryRef newConfiguration
= (CFMutableDictionaryRef
)context
;
997 CFDictionarySetValue(newConfiguration
, key
, value
);
1003 updateInterfaceConfiguration(CFMutableDictionaryRef newConfiguration
)
1005 CFDictionaryRef configuration
;
1007 CFDictionaryRemoveAllValues(newConfiguration
);
1009 configuration
= SCNetworkInterfaceGetConfiguration(net_interface
);
1010 if (configuration
!= NULL
) {
1011 CFDictionaryApplyFunction(configuration
, _replaceOne
, (void *)newConfiguration
);
1019 #pragma mark Bond options
1022 static options bondOptions
[] = {
1023 { "mtu" , NULL
, isNumber
, &kSCPropNetEthernetMTU
, NULL
, NULL
},
1024 // xxx { "+device" , ... },
1025 // xxx { "-device" , ... },
1027 { "?" , NULL
, isHelp
, NULL
, NULL
,
1028 "\nBond configuration commands\n\n"
1029 " set interface [mtu n] [media type] [mediaopts opts]\n"
1032 #define N_BOND_OPTIONS (sizeof(bondOptions) / sizeof(bondOptions[0]))
1036 set_interface_bond(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1038 CFStringRef interfaceName
;
1041 interfaceName
= SCNetworkInterfaceGetBSDName(net_interface
);
1042 if (interfaceName
== NULL
) {
1043 SCPrint(TRUE
, stdout
, CFSTR("no BSD interface\n"));
1047 ok
= _process_options(bondOptions
, N_BOND_OPTIONS
, argc
, argv
, newConfiguration
);
1049 // validate configuration
1050 if (!validateMediaOptions(net_interface
, newConfiguration
)) {
1060 #pragma mark Bridge options
1063 static options bridgeOptions
[] = {
1064 { "mtu" , NULL
, isNumber
, &kSCPropNetEthernetMTU
, NULL
, NULL
},
1065 // xxx { "+device" , ... },
1066 // xxx { "-device" , ... },
1068 { "?" , NULL
, isHelp
, NULL
, NULL
,
1069 "\nBridge configuration commands\n\n"
1070 " set interface [mtu n] [media type] [mediaopts opts]\n"
1073 #define N_BRIDGE_OPTIONS (sizeof(bridgeOptions) / sizeof(bridgeOptions[0]))
1077 set_interface_bridge(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1079 CFStringRef interfaceName
;
1082 interfaceName
= SCNetworkInterfaceGetBSDName(net_interface
);
1083 if (interfaceName
== NULL
) {
1084 SCPrint(TRUE
, stdout
, CFSTR("no BSD interface\n"));
1088 ok
= _process_options(bridgeOptions
, N_BRIDGE_OPTIONS
, argc
, argv
, newConfiguration
);
1090 // validate configuration
1091 if (!validateMediaOptions(net_interface
, newConfiguration
)) {
1101 #pragma mark AirPort options
1104 static options airportOptions
[] = {
1105 { "mtu" , NULL
, isNumber
, &kSCPropNetEthernetMTU
, NULL
, NULL
},
1106 { "media" , NULL
, isString
, &kSCPropNetEthernetMediaSubType
, NULL
, NULL
},
1107 { "mediaopt" , NULL
, isStringArray
, &kSCPropNetEthernetMediaOptions
, NULL
, NULL
},
1109 { "rank" , NULL
, isOther
, NULL
, __doRank
, NULL
},
1111 { "?" , NULL
, isHelp
, NULL
, NULL
,
1112 "\nAirPort configuration commands\n\n"
1113 " set interface [mtu n] [media type] [mediaopts opts]\n"
1116 #define N_AIRPORT_OPTIONS (sizeof(airportOptions) / sizeof(airportOptions[0]))
1120 set_interface_airport(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1122 CFStringRef interfaceName
;
1125 interfaceName
= SCNetworkInterfaceGetBSDName(net_interface
);
1126 if (interfaceName
== NULL
) {
1127 SCPrint(TRUE
, stdout
, CFSTR("no BSD interface\n"));
1131 ok
= _process_options(airportOptions
, N_AIRPORT_OPTIONS
, argc
, argv
, newConfiguration
);
1133 // validate configuration
1134 if (!validateMediaOptions(net_interface
, newConfiguration
)) {
1144 #pragma mark Ethernet options
1148 __doCapability(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1153 SCPrint(TRUE
, stdout
,
1154 CFSTR("%s not specified\n"),
1155 description
!= NULL
? description
: "enable/disable");
1159 if (strlen(argv
[0]) == 0) {
1160 ok
= SCNetworkInterfaceSetCapability(net_interface
, key
, NULL
);
1161 } else if ((strcasecmp(argv
[0], "disable") == 0) ||
1162 (strcasecmp(argv
[0], "no" ) == 0) ||
1163 (strcasecmp(argv
[0], "off" ) == 0) ||
1164 (strcasecmp(argv
[0], "0" ) == 0)) {
1165 ok
= SCNetworkInterfaceSetCapability(net_interface
, key
, CFNumberRef_0
);
1166 } else if ((strcasecmp(argv
[0], "enable") == 0) ||
1167 (strcasecmp(argv
[0], "yes" ) == 0) ||
1168 (strcasecmp(argv
[0], "on" ) == 0) ||
1169 (strcasecmp(argv
[0], "1" ) == 0)) {
1170 ok
= SCNetworkInterfaceSetCapability(net_interface
, key
, CFNumberRef_1
);
1172 SCPrint(TRUE
, stdout
, CFSTR("invalid value\n"));
1177 updateInterfaceConfiguration(newConfiguration
);
1179 SCPrint(TRUE
, stdout
,
1180 CFSTR("%@ not updated: %s\n"),
1182 SCErrorString(SCError()));
1190 static options ethernetOptions
[] = {
1191 { "mtu" , NULL
, isNumber
, &kSCPropNetEthernetMTU
, NULL
, NULL
},
1192 { "media" , NULL
, isString
, &kSCPropNetEthernetMediaSubType
, NULL
, NULL
},
1193 { "mediaopt" , NULL
, isStringArray
, &kSCPropNetEthernetMediaOptions
, NULL
, NULL
},
1195 { "av" , NULL
, isOther
, &kSCPropNetEthernetCapabilityAV
, __doCapability
, NULL
},
1196 { "lro" , NULL
, isOther
, &kSCPropNetEthernetCapabilityLRO
, __doCapability
, NULL
},
1197 { "rxcsum" , NULL
, isOther
, &kSCPropNetEthernetCapabilityRXCSUM
, __doCapability
, NULL
},
1198 { "tso" , NULL
, isOther
, &kSCPropNetEthernetCapabilityTSO
, __doCapability
, NULL
},
1199 { "txcsum" , NULL
, isOther
, &kSCPropNetEthernetCapabilityTXCSUM
, __doCapability
, NULL
},
1201 { "rank" , NULL
, isOther
, NULL
, __doRank
, NULL
},
1203 { "?" , NULL
, isHelp
, NULL
, NULL
,
1204 "\nEthernet configuration commands\n\n"
1205 " set interface [mtu n] [media type] [mediaopts opts]\n"
1208 #define N_ETHERNET_OPTIONS (sizeof(ethernetOptions) / sizeof(ethernetOptions[0]))
1212 set_interface_ethernet(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1214 CFStringRef interfaceName
;
1217 interfaceName
= SCNetworkInterfaceGetBSDName(net_interface
);
1218 if (interfaceName
== NULL
) {
1219 SCPrint(TRUE
, stdout
, CFSTR("no BSD interface\n"));
1223 ok
= _process_options(ethernetOptions
, N_ETHERNET_OPTIONS
, argc
, argv
, newConfiguration
);
1225 // validate configuration
1226 if (!validateMediaOptions(net_interface
, newConfiguration
)) {
1236 #pragma mark IPSec options
1240 __doIPSecSharedSecret(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1242 CFStringRef encryptionType
;
1245 SCPrint(TRUE
, stdout
, CFSTR("IPSec shared secret not specified\n"));
1249 encryptionType
= CFDictionaryGetValue(newConfiguration
, kSCPropNetIPSecSharedSecretEncryption
);
1250 if (strlen(argv
[0]) > 0) {
1251 if (encryptionType
== NULL
) {
1252 #ifdef INLINE_PASSWORDS_USE_CFSTRING
1255 pw
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
1256 #else // INLINE_PASSWORDS_USE_CFSTRING
1258 CFMutableDataRef pw
;
1261 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
1262 n
= CFStringGetLength(str
);
1263 pw
= CFDataCreateMutable(NULL
, n
* sizeof(UniChar
));
1264 CFDataSetLength(pw
, n
* sizeof(UniChar
));
1265 /* ALIGN: CF aligns to at least >8 bytes */
1266 CFStringGetCharacters(str
,
1268 (UniChar
*)(void *)CFDataGetMutableBytePtr(pw
));
1270 #endif // INLINE_PASSWORDS_USE_CFSTRING
1272 CFDictionarySetValue(newConfiguration
, key
, pw
);
1274 } else if (CFEqual(encryptionType
, kSCValNetIPSecSharedSecretEncryptionKeychain
)) {
1279 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
1280 pw
= CFStringCreateExternalRepresentation(NULL
, str
, kCFStringEncodingUTF8
, 0);
1281 ok
= SCNetworkInterfaceSetPassword(net_interface
,
1282 kSCNetworkInterfacePasswordTypeIPSecSharedSecret
,
1288 updateInterfaceConfiguration(newConfiguration
);
1293 SCPrint(TRUE
, stdout
, CFSTR("IPSec shared secret type \"%@\" not supported\n"), encryptionType
);
1297 if (encryptionType
== NULL
) {
1298 CFDictionaryRemoveValue(newConfiguration
, key
);
1299 } else if (CFEqual(encryptionType
, kSCValNetIPSecSharedSecretEncryptionKeychain
)) {
1301 ok
= SCNetworkInterfaceRemovePassword(net_interface
, kSCNetworkInterfacePasswordTypeIPSecSharedSecret
);
1303 updateInterfaceConfiguration(newConfiguration
);
1308 SCPrint(TRUE
, stdout
, CFSTR("IPSec shared secret type \"%@\" not supported\n"), encryptionType
);
1318 __doIPSecSharedSecretType(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1321 SCPrint(TRUE
, stdout
, CFSTR("IPSec shared secret type mode not specified\n"));
1325 if (strlen(argv
[0]) > 0) {
1326 if (strcasecmp(argv
[0], "keychain") == 0) {
1327 CFDictionarySetValue(newConfiguration
, key
, kSCValNetIPSecSharedSecretEncryptionKeychain
);
1329 SCPrint(TRUE
, stdout
, CFSTR("invalid shared secret type\n"));
1333 CFDictionaryRemoveValue(newConfiguration
, key
);
1336 // encryption type changed, reset shared secret
1337 CFDictionaryRemoveValue(newConfiguration
, kSCPropNetIPSecSharedSecret
);
1344 __doIPSecXAuthPassword(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1346 CFStringRef encryptionType
;
1349 SCPrint(TRUE
, stdout
, CFSTR("IPSec XAuth password not specified\n"));
1353 encryptionType
= CFDictionaryGetValue(newConfiguration
, kSCPropNetIPSecXAuthPasswordEncryption
);
1354 if (strlen(argv
[0]) > 0) {
1355 if (encryptionType
== NULL
) {
1356 #ifdef INLINE_PASSWORDS_USE_CFSTRING
1359 pw
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
1360 #else // INLINE_PASSWORDS_USE_CFSTRING
1362 CFMutableDataRef pw
;
1365 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
1366 n
= CFStringGetLength(str
);
1367 pw
= CFDataCreateMutable(NULL
, n
* sizeof(UniChar
));
1368 CFDataSetLength(pw
, n
* sizeof(UniChar
));
1369 /* ALIGN: CF aligns to at least >8 byte boundries */
1370 CFStringGetCharacters(str
,
1372 (UniChar
*)(void *)CFDataGetMutableBytePtr(pw
));
1374 #endif // INLINE_PASSWORDS_USE_CFSTRING
1376 CFDictionarySetValue(newConfiguration
, key
, pw
);
1378 } else if (CFEqual(encryptionType
, kSCValNetIPSecXAuthPasswordEncryptionKeychain
)) {
1383 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
1384 pw
= CFStringCreateExternalRepresentation(NULL
, str
, kCFStringEncodingUTF8
, 0);
1385 ok
= SCNetworkInterfaceSetPassword(net_interface
,
1386 kSCNetworkInterfacePasswordTypeIPSecXAuth
,
1392 updateInterfaceConfiguration(newConfiguration
);
1397 SCPrint(TRUE
, stdout
, CFSTR("IPSec XAuthPassword type \"%@\" not supported\n"), encryptionType
);
1401 if (encryptionType
== NULL
) {
1402 CFDictionaryRemoveValue(newConfiguration
, key
);
1403 } else if (CFEqual(encryptionType
, kSCValNetIPSecXAuthPasswordEncryptionKeychain
)) {
1406 ok
= SCNetworkInterfaceRemovePassword(net_interface
, kSCNetworkInterfacePasswordTypeIPSecXAuth
);
1408 updateInterfaceConfiguration(newConfiguration
);
1413 SCPrint(TRUE
, stdout
, CFSTR("IPSec XAuthPassword type \"%@\" not supported\n"), encryptionType
);
1423 __doIPSecXAuthPasswordType(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1426 SCPrint(TRUE
, stdout
, CFSTR("IPSec XAuth password type mode not specified\n"));
1430 if (strlen(argv
[0]) > 0) {
1431 if (strcasecmp(argv
[0], "keychain") == 0) {
1432 CFDictionarySetValue(newConfiguration
, key
, kSCValNetIPSecXAuthPasswordEncryptionKeychain
);
1434 SCPrint(TRUE
, stdout
, CFSTR("invalid XAuth password type\n"));
1438 CFDictionaryRemoveValue(newConfiguration
, key
);
1441 // encryption type changed, reset XAuthPassword
1442 CFDictionaryRemoveValue(newConfiguration
, kSCPropNetIPSecXAuthPassword
);
1448 static CF_RETURNS_RETAINED CFStringRef
1449 __cleanupDomainName(CFStringRef domain
)
1451 CFMutableStringRef newDomain
;
1453 newDomain
= CFStringCreateMutableCopy(NULL
, 0, domain
);
1454 CFStringTrimWhitespace(newDomain
);
1455 CFStringTrim(newDomain
, CFSTR("."));
1456 if (CFStringGetLength(newDomain
) == 0) {
1457 CFRelease(newDomain
);
1466 __doOnDemandDomains(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1468 CFMutableArrayRef domains
;
1471 SCPrint(TRUE
, stdout
, CFSTR("OnDemand domain name(s) not specified\n"));
1475 domains
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
1477 if (strlen(argv
[0]) > 0) {
1481 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
1482 array
= CFStringCreateArrayBySeparatingStrings(NULL
, str
, CFSTR(","));
1485 if (array
!= NULL
) {
1487 CFIndex n
= CFArrayGetCount(array
);
1489 for (i
= 0; i
< n
; i
++) {
1492 domain
= __cleanupDomainName(CFArrayGetValueAtIndex(array
, i
));
1493 if (domain
!= NULL
) {
1494 CFArrayAppendValue(domains
, domain
);
1499 SCPrint(TRUE
, stdout
, CFSTR("invalid OnDemand domain name\n"));
1507 if (CFArrayGetCount(domains
) > 0) {
1508 CFDictionarySetValue(newConfiguration
, key
, domains
);
1510 CFDictionaryRemoveValue(newConfiguration
, key
);
1518 static options ipsecOnDemandOptions
[] = {
1519 { "OnDemandMatchDomainsAlways" , "domain", isOther
, &kSCPropNetIPSecOnDemandMatchDomainsAlways
, __doOnDemandDomains
, NULL
},
1520 { "always" , "domain", isOther
, &kSCPropNetIPSecOnDemandMatchDomainsAlways
, __doOnDemandDomains
, NULL
},
1521 { "OnDemandMatchDomainsOnRetry", "domain", isOther
, &kSCPropNetIPSecOnDemandMatchDomainsOnRetry
, __doOnDemandDomains
, NULL
},
1522 { "retry" , "domain", isOther
, &kSCPropNetIPSecOnDemandMatchDomainsOnRetry
, __doOnDemandDomains
, NULL
},
1523 { "OnDemandMatchDomainsNever" , "domain", isOther
, &kSCPropNetIPSecOnDemandMatchDomainsNever
, __doOnDemandDomains
, NULL
},
1524 { "never" , "domain", isOther
, &kSCPropNetIPSecOnDemandMatchDomainsNever
, __doOnDemandDomains
, NULL
},
1526 { "?" , NULL
, isHelp
, NULL
, NULL
,
1527 "\nOnDemandMatch configuration commands\n\n"
1528 " set interface OnDemandMatch always domain-name[,domain-name]\n"
1529 " set interface OnDemandMatch retry domain-name[,domain-name]\n"
1530 " set interface OnDemandMatch never domain-name[,domain-name]\n"
1533 #define N_IPSEC_ONDEMAND_OPTIONS (sizeof(ipsecOnDemandOptions) / sizeof(ipsecOnDemandOptions[0]))
1537 __doIPSecOnDemandMatch(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1542 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
1546 ok
= _process_options(ipsecOnDemandOptions
, N_IPSEC_ONDEMAND_OPTIONS
, argc
, argv
, newConfiguration
);
1557 static selections ipsecAuthenticationMethodSelections
[] = {
1558 { CFSTR("SharedSecret"), &kSCValNetIPSecAuthenticationMethodSharedSecret
, 0 },
1559 { CFSTR("Certificate") , &kSCValNetIPSecAuthenticationMethodCertificate
, 0 },
1560 { CFSTR("Hybrid") , &kSCValNetIPSecAuthenticationMethodHybrid
, 0 },
1565 static selections ipsecLocalIdentifierTypeSelections
[] = {
1566 { CFSTR("KeyID") , &kSCValNetIPSecLocalIdentifierTypeKeyID
, 0 },
1571 static options ipsecOptions
[] = {
1572 { "AuthenticationMethod" , NULL
, isChooseOne
, &kSCPropNetIPSecAuthenticationMethod
, NULL
, (void *)ipsecAuthenticationMethodSelections
},
1573 { "LocalIdentifier" , NULL
, isString
, &kSCPropNetIPSecLocalIdentifier
, NULL
, NULL
},
1574 { "group" , NULL
, isString
, &kSCPropNetIPSecLocalIdentifier
, NULL
, NULL
},
1575 { "LocalIdentifierType" , NULL
, isChooseOne
, &kSCPropNetIPSecLocalIdentifierType
, NULL
, (void *)ipsecLocalIdentifierTypeSelections
},
1576 { "RemoteAddress" , NULL
, isString
, &kSCPropNetIPSecRemoteAddress
, NULL
, NULL
},
1577 { "SharedSecret" , NULL
, isOther
, &kSCPropNetIPSecSharedSecret
, __doIPSecSharedSecret
, NULL
},
1578 { "SharedSecretEncryption" , NULL
, isOther
, &kSCPropNetIPSecSharedSecretEncryption
, __doIPSecSharedSecretType
, NULL
},
1581 { "XAuthEnabled" , NULL
, isBoolean
, &kSCPropNetIPSecXAuthEnabled
, NULL
, NULL
},
1582 { "XAuthName" , NULL
, isString
, &kSCPropNetIPSecXAuthName
, NULL
, NULL
},
1583 { "XAuthPassword" , NULL
, isOther
, &kSCPropNetIPSecXAuthPassword
, __doIPSecXAuthPassword
, NULL
},
1584 { "XAuthPasswordEncryption", NULL
, isOther
, &kSCPropNetIPSecXAuthPasswordEncryption
, __doIPSecXAuthPasswordType
, NULL
},
1586 // --- OnDemand: ---
1587 { "OnDemandEnabled" , NULL
, isBoolean
, &kSCPropNetIPSecOnDemandEnabled
, NULL
, NULL
},
1588 { "OnDemandMatch" , NULL
, isOther
, NULL
, __doIPSecOnDemandMatch
, NULL
},
1590 { "?" , NULL
, isHelp
, NULL
, NULL
,
1591 "\nIPSec configuration commands\n\n"
1592 " set interface [AuthenticationMethod {SharedSecret|Certificate|Hybrid}]\n"
1593 " set interface [LocalIdentifier group]\n"
1594 " set interface [LocalIdentifierType {KeyID}]\n"
1595 " set interface [RemoteAddress name-or-address]\n"
1596 " set interface [SharedSecret secret]\n"
1597 " set interface [SharedSecretEncryption {Keychain}]\n"
1598 " set interface [XAuthEnabled {enable|disable}]\n"
1599 " set interface [XAuthPassword password]\n"
1600 " set interface [XAuthPasswordEncryption {Keychain}]\n"
1601 " set interface [OnDemandEnabled {enable|disable}]\n"
1602 " set interface [OnDemandMatch <match-options>]\n"
1605 #define N_IPSEC_OPTIONS (sizeof(ipsecOptions) / sizeof(ipsecOptions[0]))
1609 set_interface_ipsec(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1613 ok
= _process_options(ipsecOptions
, N_IPSEC_OPTIONS
, argc
, argv
, newConfiguration
);
1619 #pragma mark FireWire options
1622 static options firewireOptions
[] = {
1623 { "mtu" , NULL
, isNumber
, &kSCPropNetEthernetMTU
, NULL
, NULL
},
1624 { "media" , NULL
, isString
, &kSCPropNetEthernetMediaSubType
, NULL
, NULL
},
1625 { "mediaopt" , NULL
, isStringArray
, &kSCPropNetEthernetMediaOptions
, NULL
, NULL
},
1627 { "?" , NULL
, isHelp
, NULL
, NULL
,
1628 "\nFireWire configuration commands\n\n"
1629 " set interface [mtu n] [media type] [mediaopts opts]\n"
1632 #define N_FIREWIRE_OPTIONS (sizeof(firewireOptions) / sizeof(firewireOptions[0]))
1636 set_interface_firewire(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1638 CFStringRef interfaceName
;
1641 interfaceName
= SCNetworkInterfaceGetBSDName(net_interface
);
1642 if (interfaceName
== NULL
) {
1643 SCPrint(TRUE
, stdout
, CFSTR("no BSD interface\n"));
1647 ok
= _process_options(firewireOptions
, N_FIREWIRE_OPTIONS
, argc
, argv
, newConfiguration
);
1649 // validate configuration
1650 if (!validateMediaOptions(net_interface
, newConfiguration
)) {
1660 #pragma mark Modem options
1663 static selections modemDialSelections
[] = {
1664 { CFSTR("ignore"), &kSCValNetModemDialModeIgnoreDialTone
, 0 },
1665 { CFSTR("manual"), &kSCValNetModemDialModeManual
, 0 },
1666 { CFSTR("wait") , &kSCValNetModemDialModeWaitForDialTone
, 0 },
1670 static options modemOptions
[] = {
1671 { "ConnectionScript" , "script", isString
, &kSCPropNetModemConnectionScript
, NULL
, NULL
},
1672 { "DialMode" , "mode" , isChooseOne
, &kSCPropNetModemDialMode
, NULL
, (void *)modemDialSelections
},
1673 { "CallWaiting" , NULL
, isBoolean
, &kSCPropNetModemHoldEnabled
, NULL
, NULL
},
1674 { "CallWaitingAlert" , NULL
, isBoolean
, &kSCPropNetModemHoldCallWaitingAudibleAlert
, NULL
, NULL
},
1675 { "CallWaitingDisconnectOnAnswer", NULL
, isBoolean
, &kSCPropNetModemHoldDisconnectOnAnswer
, NULL
, NULL
},
1676 { "DataCompression" , NULL
, isBoolean
, &kSCPropNetModemDataCompression
, NULL
, NULL
},
1677 { "ErrorCorrection" , NULL
, isBoolean
, &kSCPropNetModemErrorCorrection
, NULL
, NULL
},
1678 { "HoldReminder" , NULL
, isBoolean
, &kSCPropNetModemHoldReminder
, NULL
, NULL
},
1679 { "HoldReminderTime" , "time" , isNumber
, &kSCPropNetModemHoldReminderTime
, NULL
, NULL
},
1680 { "PulseDial" , NULL
, isBoolean
, &kSCPropNetModemPulseDial
, NULL
, NULL
},
1681 { "Speaker" , NULL
, isBoolean
, &kSCPropNetModemSpeaker
, NULL
, NULL
},
1683 { "?" , NULL
, isHelp
, NULL
, NULL
,
1684 "\nModem configuration commands\n\n"
1685 " set interface [ConnectionScript connection-script]\n"
1686 " set interface [CallWaiting {enable|disable}]\n"
1687 " set interface [CallWaitingAlert {enable|disable}]\n"
1688 " set interface [CallWaitingDisconnectOnAnswer {enable|disable}]\n"
1689 " set interface [DialMode {ignore|wait}]\n"
1690 " set interface [DataCompression {enable|disable}]\n"
1691 " set interface [ErrorCorrection {enable|disable}]\n"
1692 " set interface [HoldReminder {enable|disable}]\n"
1693 " set interface [HoldReminderTime n]\n"
1694 " set interface [PulseDial {enable|disable}]\n"
1695 " set interface [Speaker {enable|disable}]\n"
1698 #define N_MODEM_OPTIONS (sizeof(modemOptions) / sizeof(modemOptions[0]))
1702 set_interface_modem(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1706 ok
= _process_options(modemOptions
, N_MODEM_OPTIONS
, argc
, argv
, newConfiguration
);
1712 #pragma mark PPP options
1716 __doPPPAuthPW(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1718 CFStringRef encryptionType
;
1721 SCPrint(TRUE
, stdout
, CFSTR("PPP password not specified\n"));
1725 encryptionType
= CFDictionaryGetValue(newConfiguration
, kSCPropNetPPPAuthPasswordEncryption
);
1726 if (strlen(argv
[0]) > 0) {
1727 if (encryptionType
== NULL
) {
1728 #ifdef INLINE_PASSWORDS_USE_CFSTRING
1731 pw
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
1732 #else // INLINE_PASSWORDS_USE_CFSTRING
1734 CFMutableDataRef pw
;
1737 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
1738 n
= CFStringGetLength(str
);
1739 pw
= CFDataCreateMutable(NULL
, n
* sizeof(UniChar
));
1740 CFDataSetLength(pw
, n
* sizeof(UniChar
));
1741 /* ALIGN: CF aligns to at least >8 byte boundries */
1742 CFStringGetCharacters(str
,
1744 (UniChar
*)(void *)CFDataGetMutableBytePtr(pw
));
1746 #endif // INLINE_PASSWORDS_USE_CFSTRING
1748 CFDictionarySetValue(newConfiguration
, key
, pw
);
1750 } else if (CFEqual(encryptionType
, kSCValNetPPPAuthPasswordEncryptionKeychain
)) {
1755 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
1756 pw
= CFStringCreateExternalRepresentation(NULL
, str
, kCFStringEncodingUTF8
, 0);
1757 ok
= SCNetworkInterfaceSetPassword(net_interface
,
1758 kSCNetworkInterfacePasswordTypePPP
,
1764 updateInterfaceConfiguration(newConfiguration
);
1769 SCPrint(TRUE
, stdout
, CFSTR("PPP password type \"%@\" not supported\n"), encryptionType
);
1773 if (encryptionType
== NULL
) {
1774 CFDictionaryRemoveValue(newConfiguration
, key
);
1775 } else if (CFEqual(encryptionType
, kSCValNetPPPAuthPasswordEncryptionKeychain
)) {
1778 ok
= SCNetworkInterfaceRemovePassword(net_interface
, kSCNetworkInterfacePasswordTypePPP
);
1780 updateInterfaceConfiguration(newConfiguration
);
1785 SCPrint(TRUE
, stdout
, CFSTR("PPP password type \"%@\" not supported\n"), encryptionType
);
1795 __doPPPAuthPWType(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1798 SCPrint(TRUE
, stdout
, CFSTR("PPP password type mode not specified\n"));
1802 if (strlen(argv
[0]) > 0) {
1803 if (strcasecmp(argv
[0], "keychain") == 0) {
1804 CFDictionarySetValue(newConfiguration
, key
, kSCValNetPPPAuthPasswordEncryptionKeychain
);
1806 SCPrint(TRUE
, stdout
, CFSTR("invalid password type\n"));
1810 CFDictionaryRemoveValue(newConfiguration
, key
);
1813 // encryption type changed, reset password
1814 CFDictionaryRemoveValue(newConfiguration
, kSCPropNetPPPAuthPassword
);
1820 static options l2tp_ipsecOptions
[] = {
1821 { "SharedSecret" , NULL
, isOther
, &kSCPropNetIPSecSharedSecret
, __doIPSecSharedSecret
, NULL
},
1822 { "SharedSecretEncryption", NULL
, isOther
, &kSCPropNetIPSecSharedSecretEncryption
, __doIPSecSharedSecretType
, NULL
},
1824 { "?" , NULL
, isHelp
, NULL
, NULL
,
1825 "\nIPSec configuration commands\n\n"
1826 " set interface ipsec [SharedSecret secret]\n"
1827 " set interface ipsec [SharedSecretEncryption {Keychain}]\n"
1830 #define N_L2TP_IPSEC_OPTIONS (sizeof(l2tp_ipsecOptions) / sizeof(l2tp_ipsecOptions[0]))
1834 __doPPPIPSec(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newPPPConfiguration
)
1836 SCNetworkInterfaceRef childInterface
;
1837 CFStringRef childInterfaceType
;
1838 CFDictionaryRef configuration
;
1839 CFMutableDictionaryRef newConfiguration
;
1843 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
1847 childInterface
= SCNetworkInterfaceGetInterface(net_interface
);
1848 if (childInterface
== NULL
) {
1849 SCPrint(TRUE
, stdout
, CFSTR("this interfaces configuration cannot be changed\n"));
1853 childInterfaceType
= SCNetworkInterfaceGetInterfaceType(childInterface
);
1854 if (!CFEqual(childInterfaceType
, kSCNetworkInterfaceTypeL2TP
)) {
1855 SCPrint(TRUE
, stdout
, CFSTR("this interfaces configuration cannot be changed\n"));
1859 configuration
= SCNetworkInterfaceGetExtendedConfiguration(net_interface
, kSCEntNetIPSec
);
1860 if (configuration
== NULL
) {
1861 newConfiguration
= CFDictionaryCreateMutable(NULL
,
1863 &kCFTypeDictionaryKeyCallBacks
,
1864 &kCFTypeDictionaryValueCallBacks
);
1866 newConfiguration
= CFDictionaryCreateMutableCopy(NULL
, 0, configuration
);
1867 CFDictionaryRemoveValue(newConfiguration
, kSCResvInactive
);
1870 ok
= _process_options(l2tp_ipsecOptions
, N_L2TP_IPSEC_OPTIONS
, argc
, argv
, newConfiguration
);
1875 if (((configuration
== NULL
) && (CFDictionaryGetCount(newConfiguration
) > 0)) ||
1876 ((configuration
!= NULL
) && !CFEqual(configuration
, newConfiguration
))) {
1877 if (!SCNetworkInterfaceSetExtendedConfiguration(net_interface
, kSCEntNetIPSec
, newConfiguration
)) {
1878 if (SCError() == kSCStatusNoKey
) {
1879 SCPrint(TRUE
, stdout
, CFSTR("could not update per-service interface configuration\n"));
1881 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
1886 _prefs_changed
= TRUE
;
1891 if (newConfiguration
!= NULL
) CFRelease(newConfiguration
);
1897 static options pppOnDemandOptions
[] = {
1898 { "OnDemandMatchDomainsAlways" , "domain", isOther
, &kSCPropNetPPPOnDemandMatchDomainsAlways
, __doOnDemandDomains
, NULL
},
1899 { "always" , "domain", isOther
, &kSCPropNetPPPOnDemandMatchDomainsAlways
, __doOnDemandDomains
, NULL
},
1900 { "OnDemandMatchDomainsOnRetry", "domain", isOther
, &kSCPropNetPPPOnDemandMatchDomainsOnRetry
, __doOnDemandDomains
, NULL
},
1901 { "retry" , "domain", isOther
, &kSCPropNetPPPOnDemandMatchDomainsOnRetry
, __doOnDemandDomains
, NULL
},
1902 { "OnDemandMatchDomainsNever" , "domain", isOther
, &kSCPropNetPPPOnDemandMatchDomainsNever
, __doOnDemandDomains
, NULL
},
1903 { "never" , "domain", isOther
, &kSCPropNetPPPOnDemandMatchDomainsNever
, __doOnDemandDomains
, NULL
},
1905 { "?" , NULL
, isHelp
, NULL
, NULL
,
1906 "\nOnDemandMatch configuration commands\n\n"
1907 " set interface OnDemand always domain-name[,domain-name]\n"
1908 " set interface OnDemand retry domain-name[,domain-name]\n"
1909 " set interface OnDemand never domain-name[,domain-name]\n"
1912 #define N_PPP_ONDEMAND_OPTIONS (sizeof(pppOnDemandOptions) / sizeof(pppOnDemandOptions[0]))
1916 __doPPPOnDemandMatch(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
1921 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
1925 ok
= _process_options(pppOnDemandOptions
, N_PPP_ONDEMAND_OPTIONS
, argc
, argv
, newConfiguration
);
1937 static selections authPromptSelections
[] = {
1938 { CFSTR("before"), &kSCValNetPPPAuthPromptBefore
, 0 },
1939 { CFSTR("after") , &kSCValNetPPPAuthPromptAfter
, 0 },
1944 static selections authProtocolSelections
[] = {
1945 { CFSTR("CHAP") , &kSCValNetPPPAuthProtocolCHAP
, 0 },
1946 { CFSTR("EAP") , &kSCValNetPPPAuthProtocolEAP
, 0 },
1947 { CFSTR("MSCHAP1"), &kSCValNetPPPAuthProtocolMSCHAP1
, 0 },
1948 { CFSTR("MSCHAP2"), &kSCValNetPPPAuthProtocolMSCHAP2
, 0 },
1949 { CFSTR("PAP") , &kSCValNetPPPAuthProtocolPAP
, 0 },
1954 static options pppOptions
[] = {
1955 { "ACSP" , NULL
, isBoolean
, &kSCPropNetPPPACSPEnabled
, NULL
, NULL
},
1956 { "ConnectTime" , "?time" , isNumber
, &kSCPropNetPPPConnectTime
, NULL
, NULL
},
1957 { "DialOnDemand" , NULL
, isBoolean
, &kSCPropNetPPPDialOnDemand
, NULL
, NULL
},
1958 { "DisconnectOnFastUserSwitch", NULL
, isBoolean
, &kSCPropNetPPPDisconnectOnFastUserSwitch
, NULL
, NULL
},
1959 { "DisconnectOnIdle" , NULL
, isBoolean
, &kSCPropNetPPPDisconnectOnIdle
, NULL
, NULL
},
1960 { "DisconnectOnIdleTimer" , "timeout" , isNumber
, &kSCPropNetPPPDisconnectOnIdleTimer
, NULL
, NULL
},
1961 { "DisconnectOnLogout" , NULL
, isBoolean
, &kSCPropNetPPPDisconnectOnLogout
, NULL
, NULL
},
1962 { "DisconnectOnSleep" , NULL
, isBoolean
, &kSCPropNetPPPDisconnectOnSleep
, NULL
, NULL
},
1963 { "DisconnectTime" , "?time" , isNumber
, &kSCPropNetPPPDisconnectTime
, NULL
, NULL
},
1964 { "IdleReminder" , NULL
, isBoolean
, &kSCPropNetPPPIdleReminder
, NULL
, NULL
},
1965 { "IdleReminderTimer" , "time" , isNumber
, &kSCPropNetPPPIdleReminderTimer
, NULL
, NULL
},
1966 { "Logfile" , "path" , isString
, &kSCPropNetPPPLogfile
, NULL
, NULL
},
1967 { "Plugins" , "plugin" , isStringArray
, &kSCPropNetPPPPlugins
, NULL
, NULL
},
1968 { "RetryConnectTime" , "time" , isNumber
, &kSCPropNetPPPRetryConnectTime
, NULL
, NULL
},
1969 { "SessionTimer" , "time" , isNumber
, &kSCPropNetPPPSessionTimer
, NULL
, NULL
},
1970 { "UseSessionTimer" , NULL
, isBoolean
, &kSCPropNetPPPUseSessionTimer
, NULL
, NULL
},
1971 { "VerboseLogging" , NULL
, isBoolean
, &kSCPropNetPPPVerboseLogging
, NULL
, NULL
},
1974 { "AuthEAPPlugins" , "plugin" , isStringArray
, &kSCPropNetPPPAuthEAPPlugins
, NULL
, NULL
},
1975 { "AuthName" , "account" , isString
, &kSCPropNetPPPAuthName
, NULL
, NULL
},
1976 { "Account" , "account" , isString
, &kSCPropNetPPPAuthName
, NULL
, NULL
},
1977 { "AuthPassword" , "password" , isOther
, &kSCPropNetPPPAuthPassword
, __doPPPAuthPW
, NULL
},
1978 { "Password" , "password" , isOther
, &kSCPropNetPPPAuthPassword
, __doPPPAuthPW
, NULL
},
1979 { "AuthPasswordEncryption" , "type" , isOther
, &kSCPropNetPPPAuthPasswordEncryption
, __doPPPAuthPWType
, NULL
},
1980 { "AuthPrompt" , "before/after", isChooseOne
, &kSCPropNetPPPAuthPrompt
, NULL
, (void *)authPromptSelections
},
1981 { "AuthProtocol" , "protocol" , isChooseMultiple
, &kSCPropNetPPPAuthProtocol
, NULL
, (void *)authProtocolSelections
},
1984 { "CommRemoteAddress" , "phone#" , isString
, &kSCPropNetPPPCommRemoteAddress
, NULL
, NULL
},
1985 { "CommAlternateRemoteAddress", "phone#" , isString
, &kSCPropNetPPPCommAlternateRemoteAddress
, NULL
, NULL
},
1986 { "CommConnectDelay" , "time" , isNumber
, &kSCPropNetPPPCommConnectDelay
, NULL
, NULL
},
1987 { "CommDisplayTerminalWindow" , NULL
, isBoolean
, &kSCPropNetPPPCommDisplayTerminalWindow
, NULL
, NULL
},
1988 { "CommRedialCount" , "retry count" , isNumber
, &kSCPropNetPPPCommRedialCount
, NULL
, NULL
},
1989 { "CommRedialEnabled" , NULL
, isBoolean
, &kSCPropNetPPPCommRedialEnabled
, NULL
, NULL
},
1990 { "CommRedialInterval" , "retry delay" , isNumber
, &kSCPropNetPPPCommRedialInterval
, NULL
, NULL
},
1991 { "CommTerminalScript" , "script" , isString
, &kSCPropNetPPPCommTerminalScript
, NULL
, NULL
},
1992 { "CommUseTerminalScript" , NULL
, isBoolean
, &kSCPropNetPPPCommUseTerminalScript
, NULL
, NULL
},
1995 { "CCPEnabled" , NULL
, isBoolean
, &kSCPropNetPPPCCPEnabled
, NULL
, NULL
},
1996 { "CCPMPPE40Enabled" , NULL
, isBoolean
, &kSCPropNetPPPCCPMPPE40Enabled
, NULL
, NULL
},
1997 { "CCPMPPE128Enabled" , NULL
, isBoolean
, &kSCPropNetPPPCCPMPPE128Enabled
, NULL
, NULL
},
2000 { "IPCPCompressionVJ" , NULL
, isBoolean
, &kSCPropNetPPPIPCPCompressionVJ
, NULL
, NULL
},
2001 { "IPCPUsePeerDNS" , NULL
, isBoolean
, &kSCPropNetPPPIPCPUsePeerDNS
, NULL
, NULL
},
2004 { "LCPEchoEnabled" , NULL
, isBoolean
, &kSCPropNetPPPLCPEchoEnabled
, NULL
, NULL
},
2005 { "LCPEchoFailure" , NULL
, isNumber
, &kSCPropNetPPPLCPEchoFailure
, NULL
, NULL
},
2006 { "LCPEchoInterval" , NULL
, isNumber
, &kSCPropNetPPPLCPEchoInterval
, NULL
, NULL
},
2007 { "LCPCompressionACField" , NULL
, isBoolean
, &kSCPropNetPPPLCPCompressionACField
, NULL
, NULL
},
2008 { "LCPCompressionPField" , NULL
, isBoolean
, &kSCPropNetPPPLCPCompressionPField
, NULL
, NULL
},
2009 { "LCPMRU" , NULL
, isNumber
, &kSCPropNetPPPLCPMRU
, NULL
, NULL
},
2010 { "LCPMTU" , NULL
, isNumber
, &kSCPropNetPPPLCPMTU
, NULL
, NULL
},
2011 { "LCPReceiveACCM" , NULL
, isNumber
, &kSCPropNetPPPLCPReceiveACCM
, NULL
, NULL
},
2012 { "LCPTransmitACCM" , NULL
, isNumber
, &kSCPropNetPPPLCPTransmitACCM
, NULL
, NULL
},
2015 { "IPSec" , NULL
, isOther
, NULL
, __doPPPIPSec
, NULL
},
2018 // --- OnDemand: ---
2019 { "OnDemandEnabled" , NULL
, isBoolean
, &kSCPropNetPPPOnDemandEnabled
, NULL
, NULL
},
2020 { "OnDemandMatch" , NULL
, isOther
, NULL
, __doPPPOnDemandMatch
, NULL
},
2024 { "?" , NULL
, isHelp
, NULL
, NULL
,
2025 "\nPPP configuration commands\n\n"
2026 " set interface [Account account]\n"
2027 " set interface [Password password]\n"
2028 " set interface [Number telephone-number]\n"
2029 " set interface [AlternateNumber telephone-number]\n"
2030 " set interface [IdleReminder {enable|disable}]\n"
2031 " set interface [IdleReminderTimer time-in-seconds]\n"
2032 " set interface [DisconnectOnIdle {enable|disable}]\n"
2033 " set interface [DisconnectOnIdleTimer time-in-seconds]\n"
2034 " set interface [DisconnectOnLogout {enable|disable}]\n"
2035 " set interface [IPSec <ipsec-options>]\n"
2037 " set interface [OnDemandEnabled {enable|disable}]\n"
2038 " set interface [OnDemandMatch <match-options>]\n"
2042 #define N_PPP_OPTIONS (sizeof(pppOptions) / sizeof(pppOptions[0]))
2046 set_interface_ppp(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
2050 ok
= _process_options(pppOptions
, N_PPP_OPTIONS
, argc
, argv
, newConfiguration
);
2056 #pragma mark VLAN options
2060 set_interface_vlan(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
2062 // xxxxx ("device", "tag")
2063 SCPrint(TRUE
, stdout
, CFSTR("vlan interface management not yet supported\n"));
2069 #pragma mark VPN options
2073 __doVPNAuthPW(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
2075 CFStringRef encryptionType
;
2078 SCPrint(TRUE
, stdout
, CFSTR("VPN password not specified\n"));
2082 encryptionType
= CFDictionaryGetValue(newConfiguration
, kSCPropNetVPNAuthPasswordEncryption
);
2083 if (strlen(argv
[0]) > 0) {
2084 if (encryptionType
== NULL
) {
2085 #ifdef INLINE_PASSWORDS_USE_CFSTRING
2088 pw
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
2089 #else // INLINE_PASSWORDS_USE_CFSTRING
2091 CFMutableDataRef pw
;
2094 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
2095 n
= CFStringGetLength(str
);
2096 pw
= CFDataCreateMutable(NULL
, n
* sizeof(UniChar
));
2097 CFDataSetLength(pw
, n
* sizeof(UniChar
));
2098 CFStringGetCharacters(str
,
2100 (UniChar
*)(void *)CFDataGetMutableBytePtr(pw
));
2102 #endif // INLINE_PASSWORDS_USE_CFSTRING
2104 CFDictionarySetValue(newConfiguration
, key
, pw
);
2106 } else if (CFEqual(encryptionType
, kSCValNetVPNAuthPasswordEncryptionKeychain
)) {
2111 str
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
2112 pw
= CFStringCreateExternalRepresentation(NULL
, str
, kCFStringEncodingUTF8
, 0);
2113 ok
= SCNetworkInterfaceSetPassword(net_interface
,
2114 kSCNetworkInterfacePasswordTypeVPN
,
2120 updateInterfaceConfiguration(newConfiguration
);
2125 SCPrint(TRUE
, stdout
, CFSTR("VPN password type \"%@\" not supported\n"), encryptionType
);
2129 if (encryptionType
== NULL
) {
2130 CFDictionaryRemoveValue(newConfiguration
, key
);
2131 } else if (CFEqual(encryptionType
, kSCValNetVPNAuthPasswordEncryptionKeychain
)) {
2134 ok
= SCNetworkInterfaceRemovePassword(net_interface
, kSCNetworkInterfacePasswordTypeVPN
);
2136 updateInterfaceConfiguration(newConfiguration
);
2141 SCPrint(TRUE
, stdout
, CFSTR("PPP password type \"%@\" not supported\n"), encryptionType
);
2151 __doVPNAuthPWType(CFStringRef key
, const char *description
, void *info
, int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
2154 SCPrint(TRUE
, stdout
, CFSTR("VPN password type mode not specified\n"));
2158 if (strlen(argv
[0]) > 0) {
2159 if (strcasecmp(argv
[0], "keychain") == 0) {
2160 CFDictionarySetValue(newConfiguration
, key
, kSCValNetVPNAuthPasswordEncryptionKeychain
);
2161 } else if (strcasecmp(argv
[0], "prompt") == 0) {
2162 CFDictionarySetValue(newConfiguration
, key
, kSCValNetVPNAuthPasswordEncryptionPrompt
);
2164 SCPrint(TRUE
, stdout
, CFSTR("invalid password type\n"));
2168 CFDictionaryRemoveValue(newConfiguration
, key
);
2171 // encryption type changed, reset password
2172 CFDictionaryRemoveValue(newConfiguration
, kSCPropNetVPNAuthPassword
);
2178 static selections vpnAuthenticationMethodSelections
[] = {
2179 { CFSTR("Password") , &kSCValNetVPNAuthenticationMethodPassword
, 0 },
2180 { CFSTR("Certificate") , &kSCValNetVPNAuthenticationMethodCertificate
, 0 },
2185 static options vpnOptions
[] = {
2186 { "AuthName" , "account" , isString
, &kSCPropNetVPNAuthName
, NULL
, NULL
},
2187 { "Account" , "account" , isString
, &kSCPropNetVPNAuthName
, NULL
, NULL
},
2188 { "AuthPassword" , "password" , isOther
, &kSCPropNetVPNAuthPassword
, __doVPNAuthPW
, NULL
},
2189 { "Password" , "password" , isOther
, &kSCPropNetVPNAuthPassword
, __doVPNAuthPW
, NULL
},
2190 { "AuthPasswordEncryption" , "type" , isOther
, &kSCPropNetVPNAuthPasswordEncryption
, __doVPNAuthPWType
, NULL
},
2191 { "AuthenticationMethod" , NULL
, isChooseOne
, &kSCPropNetVPNAuthenticationMethod
, NULL
, (void *)vpnAuthenticationMethodSelections
},
2192 { "ConnectTime" , "?time" , isNumber
, &kSCPropNetVPNConnectTime
, NULL
, NULL
},
2193 { "DisconnectOnFastUserSwitch", NULL
, isBoolean
, &kSCPropNetVPNDisconnectOnFastUserSwitch
, NULL
, NULL
},
2194 { "DisconnectOnIdle" , NULL
, isBoolean
, &kSCPropNetVPNDisconnectOnIdle
, NULL
, NULL
},
2195 { "DisconnectOnIdleTimer" , "timeout" , isNumber
, &kSCPropNetVPNDisconnectOnIdleTimer
, NULL
, NULL
},
2196 { "DisconnectOnLogout" , NULL
, isBoolean
, &kSCPropNetVPNDisconnectOnLogout
, NULL
, NULL
},
2197 { "DisconnectOnSleep" , NULL
, isBoolean
, &kSCPropNetVPNDisconnectOnSleep
, NULL
, NULL
},
2198 { "Logfile" , "path" , isString
, &kSCPropNetVPNLogfile
, NULL
, NULL
},
2199 { "MTU" , NULL
, isNumber
, &kSCPropNetVPNMTU
, NULL
, NULL
},
2200 { "RemoteAddress" , "server" , isString
, &kSCPropNetVPNRemoteAddress
, NULL
, NULL
},
2201 { "Server" , "server" , isString
, &kSCPropNetVPNRemoteAddress
, NULL
, NULL
},
2202 { "VerboseLogging" , NULL
, isBoolean
, &kSCPropNetVPNVerboseLogging
, NULL
, NULL
},
2205 { "?" , NULL
, isHelp
, NULL
, NULL
,
2206 "\nVPN configuration commands\n\n"
2207 " set interface [Server server]\n"
2208 " set interface [Account account]\n"
2209 " set interface [Password password]\n"
2212 #define N_VPN_OPTIONS (sizeof(vpnOptions) / sizeof(vpnOptions[0]))
2216 set_interface_vpn(int argc
, char **argv
, CFMutableDictionaryRef newConfiguration
)
2220 ok
= _process_options(vpnOptions
, N_VPN_OPTIONS
, argc
, argv
, newConfiguration
);
2226 #pragma mark [more] Interface management
2231 set_interface(int argc
, char **argv
)
2233 CFDictionaryRef configuration
;
2234 CFStringRef interfaceType
;
2235 CFMutableDictionaryRef newConfiguration
= NULL
;
2238 if (net_interface
== NULL
) {
2239 SCPrint(TRUE
, stdout
, CFSTR("interface not selected\n"));
2244 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
2248 configuration
= SCNetworkInterfaceGetConfiguration(net_interface
);
2249 if (configuration
!= NULL
) {
2250 configuration
= CFDictionaryCreateCopy(NULL
, configuration
);
2251 newConfiguration
= CFDictionaryCreateMutableCopy(NULL
, 0, configuration
);
2252 CFDictionaryRemoveValue(newConfiguration
, kSCResvInactive
);
2254 newConfiguration
= CFDictionaryCreateMutable(NULL
,
2256 &kCFTypeDictionaryKeyCallBacks
,
2257 &kCFTypeDictionaryValueCallBacks
);
2260 interfaceType
= SCNetworkInterfaceGetInterfaceType(net_interface
);
2262 if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeEthernet
)) {
2263 ok
= set_interface_ethernet(argc
, argv
, newConfiguration
);
2264 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeFireWire
)) {
2265 ok
= set_interface_firewire(argc
, argv
, newConfiguration
);
2266 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeIPSec
)) {
2267 ok
= set_interface_ipsec(argc
, argv
, newConfiguration
);
2268 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeModem
)) {
2269 ok
= set_interface_modem(argc
, argv
, newConfiguration
);
2270 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeIEEE80211
)) {
2271 ok
= set_interface_airport(argc
, argv
, newConfiguration
);
2272 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypePPP
)) {
2273 ok
= set_interface_ppp(argc
, argv
, newConfiguration
);
2274 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeBond
)) {
2275 ok
= set_interface_bond(argc
, argv
, newConfiguration
);
2276 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeBridge
)) {
2277 ok
= set_interface_bridge(argc
, argv
, newConfiguration
);
2278 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeVLAN
)) {
2279 ok
= set_interface_vlan(argc
, argv
, newConfiguration
);
2280 } else if (CFEqual(interfaceType
, kSCNetworkInterfaceTypeVPN
)) {
2281 ok
= set_interface_vpn(argc
, argv
, newConfiguration
);
2283 SCPrint(TRUE
, stdout
, CFSTR("this interfaces configuration cannot be changed\n"));
2290 if (((configuration
== NULL
) && (CFDictionaryGetCount(newConfiguration
) > 0)) ||
2291 ((configuration
!= NULL
) && !CFEqual(configuration
, newConfiguration
))) {
2292 if (!SCNetworkInterfaceSetConfiguration(net_interface
, newConfiguration
)) {
2293 if (SCError() == kSCStatusNoKey
) {
2294 SCPrint(TRUE
, stdout
, CFSTR("could not update per-service interface configuration\n"));
2296 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
2301 _prefs_changed
= TRUE
;
2306 if (configuration
!= NULL
) CFRelease(configuration
);
2307 if (newConfiguration
!= NULL
) CFRelease(newConfiguration
);
2312 /* -------------------- */
2317 show_interface(int argc
, char **argv
)
2319 SCNetworkInterfaceRef interface
;
2322 interface
= _find_interface(argc
, argv
, NULL
);
2324 if (net_interface
!= NULL
) {
2325 interface
= net_interface
;
2327 SCPrint(TRUE
, stdout
, CFSTR("interface not selected\n"));
2332 if (interface
!= NULL
) {
2333 _show_interface(interface
, CFSTR(""), TRUE
);
2340 /* -------------------- */
2344 CF_RETURNS_RETAINED CFStringRef
2345 _interface_description(SCNetworkInterfaceRef interface
)
2347 CFMutableStringRef description
;
2348 CFStringRef if_bsd_name
;
2349 CFStringRef if_type
;
2351 description
= CFStringCreateMutable(NULL
, 0);
2353 if_type
= SCNetworkInterfaceGetInterfaceType(interface
);
2354 CFStringAppend(description
, if_type
);
2356 if_bsd_name
= SCNetworkInterfaceGetBSDName(interface
);
2357 if (if_bsd_name
!= NULL
) {
2358 CFStringAppendFormat(description
, NULL
, CFSTR(" (%@)"), if_bsd_name
);
2361 interface
= SCNetworkInterfaceGetInterface(interface
);
2362 while ((interface
!= NULL
) &&
2363 !CFEqual(interface
, kSCNetworkInterfaceIPv4
)) {
2364 CFStringRef childDescription
;
2366 childDescription
= _interface_description(interface
);
2367 CFStringAppendFormat(description
, NULL
, CFSTR(" / %@"), childDescription
);
2368 CFRelease(childDescription
);
2370 interface
= SCNetworkInterfaceGetInterface(interface
);