2 The implementation for Shell command IfConfig6.
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2017 Hewlett Packard Enterprise Development LP<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "UefiShellNetwork2CommandsLib.h"
19 VarCheckReserved
= -1,
33 } VAR_CHECK_FLAG_TYPE
;
35 #define MACADDRMAXSIZE 32
36 #define PREFIXMAXLEN 16
38 typedef struct _IFCONFIG6_INTERFACE_CB
{
41 EFI_IP6_CONFIG_PROTOCOL
*IfCfg
;
42 EFI_IP6_CONFIG_INTERFACE_INFO
*IfInfo
;
43 EFI_IP6_CONFIG_INTERFACE_ID
*IfId
;
44 EFI_IP6_CONFIG_POLICY Policy
;
45 EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS Xmits
;
47 EFI_IPv6_ADDRESS DnsAddr
[1];
48 } IFCONFIG6_INTERFACE_CB
;
50 typedef struct _ARG_LIST ARG_LIST
;
57 typedef struct _IFCONFIG6_PRIVATE_DATA
{
58 EFI_HANDLE ImageHandle
;
64 } IFCONFIG6_PRIVATE_DATA
;
66 typedef struct _VAR_CHECK_ITEM
{
70 VAR_CHECK_FLAG_TYPE FlagType
;
73 SHELL_PARAM_ITEM mIfConfig6CheckList
[] = {
100 VAR_CHECK_ITEM mIfConfig6SetCheckList
[] = {
154 @param List Pointer to ARG_LIST to free.
157 IfConfig6FreeArgList (
163 while (List
->Next
!= NULL
) {
173 Split a string with specified separator and save the substring to a list.
175 @param[in] String The pointer of the input string.
176 @param[in] Separator The specified separator.
178 @return The pointer of headnode of ARG_LIST.
182 IfConfig6SplitStrToList (
183 IN CONST CHAR16
*String
,
192 if ((String
== NULL
) || (*String
== L
'\0')) {
197 // Copy the CONST string to a local copy.
199 Str
= AllocateCopyPool (StrSize (String
), String
);
207 // init a node for the list head.
209 ArgNode
= (ARG_LIST
*)AllocateZeroPool (sizeof (ARG_LIST
));
210 if (ArgNode
== NULL
) {
217 // Split the local copy and save in the list node.
219 while (*Str
!= L
'\0') {
220 if (*Str
== Separator
) {
222 ArgNode
->Arg
= ArgStr
;
224 ArgNode
->Next
= (ARG_LIST
*)AllocateZeroPool (sizeof (ARG_LIST
));
225 if (ArgNode
->Next
== NULL
) {
227 // Free the local copy of string stored in the first node
229 FreePool (ArgList
->Arg
);
230 IfConfig6FreeArgList (ArgList
);
234 ArgNode
= ArgNode
->Next
;
240 ArgNode
->Arg
= ArgStr
;
241 ArgNode
->Next
= NULL
;
247 Check the correctness of input Args with '-s' option.
249 @param[in] CheckList The pointer of VAR_CHECK_ITEM array.
250 @param[in] Name The pointer of input arg.
251 @param[in] Init The switch to execute the check.
253 @return The value of VAR_CHECK_CODE.
257 IfConfig6RetriveCheckListByName (
258 IN VAR_CHECK_ITEM
*CheckList
,
263 STATIC UINT32 CheckDuplicate
;
264 STATIC UINT32 CheckConflict
;
265 VAR_CHECK_CODE RtCode
;
277 Arg
= CheckList
[Index
];
280 // Check the Duplicated/Conflicted/Unknown input Args.
282 while (Arg
.FlagStr
!= NULL
) {
283 if (StrCmp (Arg
.FlagStr
, Name
) == 0) {
284 if (CheckDuplicate
& Arg
.FlagID
) {
285 RtCode
= VarCheckDuplicate
;
289 if (CheckConflict
& Arg
.ConflictMask
) {
290 RtCode
= VarCheckConflict
;
294 CheckDuplicate
|= Arg
.FlagID
;
295 CheckConflict
|= Arg
.ConflictMask
;
299 Arg
= CheckList
[++Index
];
302 if (Arg
.FlagStr
== NULL
) {
303 RtCode
= VarCheckUnknown
;
310 The notify function of create event when performing a manual config.
312 @param[in] Event The event this notify function registered to.
313 @param[in] Context Pointer to the context data registered to the event.
318 IfConfig6ManualAddressNotify (
323 *((BOOLEAN
*)Context
) = TRUE
;
329 @param[in] Node The pointer of MAC address buffer.
330 @param[in] Size The size of MAC address buffer.
334 IfConfig6PrintMacAddr (
341 ASSERT (Size
<= MACADDRMAXSIZE
);
343 for (Index
= 0; Index
< Size
; Index
++) {
344 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_MAC_ADDR_BODY
), gShellNetwork2HiiHandle
, Node
[Index
]);
345 if (Index
+ 1 < Size
) {
346 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_COLON
), gShellNetwork2HiiHandle
);
350 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_NEWLINE
), gShellNetwork2HiiHandle
);
356 @param[in] Ip The pointer of Ip bufffer in EFI_IPv6_ADDRESS format.
357 @param[in] PrefixLen The pointer of PrefixLen that describes the size Prefix.
361 IfConfig6PrintIpAddr (
362 IN EFI_IPv6_ADDRESS
*Ip
,
371 for (Index
= 0; Index
< PREFIXMAXLEN
; Index
= Index
+ 2) {
372 if (!Short
&& (Index
+ 1 < PREFIXMAXLEN
) && (Index
% 2 == 0) && (Ip
->Addr
[Index
] == 0) && (Ip
->Addr
[Index
+ 1] == 0)) {
374 // Deal with the case of ::.
378 // :: is at the beginning of the address.
380 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_COLON
), gShellNetwork2HiiHandle
);
383 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_COLON
), gShellNetwork2HiiHandle
);
385 while ((Ip
->Addr
[Index
] == 0) && (Ip
->Addr
[Index
+ 1] == 0) && (Index
< PREFIXMAXLEN
)) {
387 if (Index
> PREFIXMAXLEN
- 2) {
394 if (Index
== PREFIXMAXLEN
) {
396 // :: is at the end of the address.
402 if (Index
< PREFIXMAXLEN
- 1) {
403 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_IP_ADDR_BODY
), gShellNetwork2HiiHandle
, Ip
->Addr
[Index
]);
404 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_IP_ADDR_BODY
), gShellNetwork2HiiHandle
, Ip
->Addr
[Index
+ 1]);
407 if (Index
+ 2 < PREFIXMAXLEN
) {
408 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_COLON
), gShellNetwork2HiiHandle
);
412 if (PrefixLen
!= NULL
) {
413 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_PREFIX_LEN
), gShellNetwork2HiiHandle
, *PrefixLen
);
418 Pick up host IPv6 address in string format from Args with "-s" option and convert it to EFI_IP6_CONFIG_MANUAL_ADDRESS format.
420 @param[in, out] Arg The pointer of the address of ARG_LIST which save Args with the "-s" option.
421 @param[out] Buf The pointer of the address of EFI_IP6_CONFIG_MANUAL_ADDRESS.
422 @param[out] BufSize The pointer of BufSize that describes the size of Buf in bytes.
424 @retval EFI_SUCCESS The convertion is successful.
425 @retval Others Does't find the host address, or it is an invalid IPv6 address in string format.
429 IfConfig6ParseManualAddressList (
430 IN OUT ARG_LIST
**Arg
,
431 OUT EFI_IP6_CONFIG_MANUAL_ADDRESS
**Buf
,
436 EFI_IP6_CONFIG_MANUAL_ADDRESS
*AddrBuf
;
438 EFI_IPv6_ADDRESS Address
;
447 Status
= EFI_SUCCESS
;
450 // Go through the list to check the correctness of input host ip6 address.
452 while ((!EFI_ERROR (Status
)) && (VarArg
!= NULL
)) {
453 Status
= NetLibStrToIp6andPrefix (VarArg
->Arg
, &Address
, &Prefix
);
455 if (EFI_ERROR (Status
)) {
462 VarArg
= VarArg
->Next
;
467 return EFI_INVALID_PARAMETER
;
470 AddrBuf
= AllocateZeroPool (AddrCnt
* sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
));
471 ASSERT (AddrBuf
!= NULL
);
475 Status
= EFI_SUCCESS
;
478 // Go through the list to fill in the EFI_IP6_CONFIG_MANUAL_ADDRESS structure.
480 while ((!EFI_ERROR (Status
)) && (VarArg
!= NULL
)) {
481 Status
= NetLibStrToIp6andPrefix (VarArg
->Arg
, &Address
, &Prefix
);
483 if (EFI_ERROR (Status
)) {
488 // If prefix length is not set, set it as Zero here. In the IfConfigSetInterfaceInfo()
489 // Zero prefix, length will be transfered to default prefix length.
491 if (Prefix
== 0xFF) {
495 AddrBuf
[AddrCnt
].IsAnycast
= FALSE
;
496 AddrBuf
[AddrCnt
].PrefixLength
= Prefix
;
497 IP6_COPY_ADDRESS (&AddrBuf
[AddrCnt
].Address
, &Address
);
498 VarArg
= VarArg
->Next
;
504 if (EFI_ERROR (Status
) && (Status
!= EFI_INVALID_PARAMETER
)) {
509 *BufSize
= AddrCnt
* sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
);
520 Pick up gw/dns IPv6 address in string format from Args with "-s" option and convert it to EFI_IPv6_ADDRESS format.
522 @param[in, out] Arg The pointer of the address of ARG_LIST that save Args with the "-s" option.
523 @param[out] Buf The pointer of the address of EFI_IPv6_ADDRESS.
524 @param[out] BufSize The pointer of BufSize that describes the size of Buf in bytes.
526 @retval EFI_SUCCESS The conversion is successful.
527 @retval Others Doesn't find the host address, or it is an invalid IPv6 address in string format.
531 IfConfig6ParseGwDnsAddressList (
532 IN OUT ARG_LIST
**Arg
,
533 OUT EFI_IPv6_ADDRESS
**Buf
,
538 EFI_IPv6_ADDRESS
*AddrBuf
;
540 EFI_IPv6_ADDRESS Address
;
548 Status
= EFI_SUCCESS
;
551 // Go through the list to check the correctness of input gw/dns address.
553 while ((!EFI_ERROR (Status
)) && (VarArg
!= NULL
)) {
554 Status
= NetLibStrToIp6andPrefix (VarArg
->Arg
, &Address
, &Prefix
);
556 if (EFI_ERROR (Status
)) {
563 VarArg
= VarArg
->Next
;
568 return EFI_INVALID_PARAMETER
;
571 AddrBuf
= AllocateZeroPool (AddrCnt
* sizeof (EFI_IPv6_ADDRESS
));
572 ASSERT (AddrBuf
!= NULL
);
576 Status
= EFI_SUCCESS
;
579 // Go through the list to fill in the EFI_IPv6_ADDRESS structure.
581 while ((!EFI_ERROR (Status
)) && (VarArg
!= NULL
)) {
582 Status
= NetLibStrToIp6andPrefix (VarArg
->Arg
, &Address
, &Prefix
);
584 if (EFI_ERROR (Status
)) {
588 IP6_COPY_ADDRESS (&AddrBuf
[AddrCnt
], &Address
);
590 VarArg
= VarArg
->Next
;
596 if (EFI_ERROR (Status
) && (Status
!= EFI_INVALID_PARAMETER
)) {
601 *BufSize
= AddrCnt
* sizeof (EFI_IPv6_ADDRESS
);
612 Parse InterfaceId in string format from Args with the "-s" option and convert it to EFI_IP6_CONFIG_INTERFACE_ID format.
614 @param[in, out] Arg The pointer of the address of ARG_LIST that saves Args with the "-s" option.
615 @param[out] IfId The pointer of EFI_IP6_CONFIG_INTERFACE_ID.
617 @retval EFI_SUCCESS The get status processed successfullly.
618 @retval EFI_INVALID_PARAMETER The get status process failed.
622 IfConfig6ParseInterfaceId (
623 IN OUT ARG_LIST
**Arg
,
624 OUT EFI_IP6_CONFIG_INTERFACE_ID
**IfId
632 return EFI_INVALID_PARAMETER
;
637 ASSERT (IfId
!= NULL
);
638 *IfId
= AllocateZeroPool (sizeof (EFI_IP6_CONFIG_INTERFACE_ID
));
639 ASSERT (*IfId
!= NULL
);
641 while ((*IdStr
!= L
'\0') && (Index
< 8)) {
643 while ((*IdStr
!= L
':') && (*IdStr
!= L
'\0')) {
644 if ((*IdStr
<= L
'F') && (*IdStr
>= L
'A')) {
645 NodeVal
= (UINT8
)((NodeVal
<< 4) + *IdStr
- L
'A' + 10);
646 } else if ((*IdStr
<= L
'f') && (*IdStr
>= L
'a')) {
647 NodeVal
= (UINT8
)((NodeVal
<< 4) + *IdStr
- L
'a' + 10);
648 } else if ((*IdStr
<= L
'9') && (*IdStr
>= L
'0')) {
649 NodeVal
= (UINT8
)((NodeVal
<< 4) + *IdStr
- L
'0');
652 return EFI_INVALID_PARAMETER
;
658 (*IfId
)->Id
[Index
++] = NodeVal
;
660 if (*IdStr
== L
':') {
670 Parse dad in string format from Args with the "-s" option and convert it to UINT32 format.
672 @param[in, out] Arg The pointer of the address of ARG_LIST that saves Args with the "-s" option.
673 @param[out] Xmits The pointer of Xmits.
675 @retval EFI_SUCCESS The get status processed successfully.
676 @retval others The get status process failed.
680 IfConfig6ParseDadXmits (
681 IN OUT ARG_LIST
**Arg
,
688 return EFI_INVALID_PARAMETER
;
691 ValStr
= (*Arg
)->Arg
;
694 while (*ValStr
!= L
'\0') {
695 if ((*ValStr
<= L
'9') && (*ValStr
>= L
'0')) {
696 *Xmits
= (*Xmits
* 10) + (*ValStr
- L
'0');
698 return EFI_INVALID_PARAMETER
;
709 The get current status of all handles.
711 @param[in] ImageHandle The handle of ImageHandle.
712 @param[in] IfName The pointer of IfName(interface name).
713 @param[in] IfList The pointer of IfList(interface list).
715 @retval EFI_SUCCESS The get status processed successfully.
716 @retval others The get status process failed.
720 IfConfig6GetInterfaceInfo (
721 IN EFI_HANDLE ImageHandle
,
723 IN LIST_ENTRY
*IfList
729 EFI_HANDLE
*HandleBuffer
;
730 EFI_IP6_CONFIG_PROTOCOL
*Ip6Cfg
;
731 EFI_IP6_CONFIG_INTERFACE_INFO
*IfInfo
;
732 IFCONFIG6_INTERFACE_CB
*IfCb
;
742 // Locate all the handles with ip6 service binding protocol.
744 Status
= gBS
->LocateHandleBuffer (
746 &gEfiIp6ServiceBindingProtocolGuid
,
751 if (EFI_ERROR (Status
) || (HandleNum
== 0)) {
756 // Enumerate all handles that installed with ip6 service binding protocol.
758 for (HandleIndex
= 0; HandleIndex
< HandleNum
; HandleIndex
++) {
764 // Ip6config protocol and ip6 service binding protocol are installed
765 // on the same handle.
767 ASSERT (HandleBuffer
!= NULL
);
768 Status
= gBS
->HandleProtocol (
769 HandleBuffer
[HandleIndex
],
770 &gEfiIp6ConfigProtocolGuid
,
774 if (EFI_ERROR (Status
)) {
779 // Get the interface information size.
781 Status
= Ip6Cfg
->GetData (
783 Ip6ConfigDataTypeInterfaceInfo
,
788 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
789 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA
), gShellNetwork2HiiHandle
, Status
);
793 IfInfo
= AllocateZeroPool (DataSize
);
795 if (IfInfo
== NULL
) {
796 Status
= EFI_OUT_OF_RESOURCES
;
801 // Get the interface info.
803 Status
= Ip6Cfg
->GetData (
805 Ip6ConfigDataTypeInterfaceInfo
,
810 if (EFI_ERROR (Status
)) {
811 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA
), gShellNetwork2HiiHandle
, Status
);
816 // Check the interface name if required.
818 if ((IfName
!= NULL
) && (StrCmp (IfName
, IfInfo
->Name
) != 0)) {
825 // Get the size of dns server list.
827 Status
= Ip6Cfg
->GetData (
829 Ip6ConfigDataTypeDnsServer
,
834 if ((Status
!= EFI_BUFFER_TOO_SMALL
) && (Status
!= EFI_NOT_FOUND
)) {
835 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA
), gShellNetwork2HiiHandle
, Status
);
839 IfCb
= AllocateZeroPool (sizeof (IFCONFIG6_INTERFACE_CB
) + DataSize
);
842 Status
= EFI_OUT_OF_RESOURCES
;
846 IfCb
->NicHandle
= HandleBuffer
[HandleIndex
];
847 IfCb
->IfInfo
= IfInfo
;
848 IfCb
->IfCfg
= Ip6Cfg
;
849 IfCb
->DnsCnt
= (UINT32
)(DataSize
/ sizeof (EFI_IPv6_ADDRESS
));
852 // Get the dns server list if has.
855 Status
= Ip6Cfg
->GetData (
857 Ip6ConfigDataTypeDnsServer
,
862 if (EFI_ERROR (Status
)) {
863 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA
), gShellNetwork2HiiHandle
, Status
);
869 // Get the interface id if has.
871 DataSize
= sizeof (EFI_IP6_CONFIG_INTERFACE_ID
);
872 IfCb
->IfId
= AllocateZeroPool (DataSize
);
874 if (IfCb
->IfId
== NULL
) {
878 Status
= Ip6Cfg
->GetData (
880 Ip6ConfigDataTypeAltInterfaceId
,
885 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_FOUND
)) {
886 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA
), gShellNetwork2HiiHandle
, Status
);
890 if (Status
== EFI_NOT_FOUND
) {
891 FreePool (IfCb
->IfId
);
896 // Get the config policy.
898 DataSize
= sizeof (EFI_IP6_CONFIG_POLICY
);
899 Status
= Ip6Cfg
->GetData (
901 Ip6ConfigDataTypePolicy
,
906 if (EFI_ERROR (Status
)) {
907 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA
), gShellNetwork2HiiHandle
, Status
);
912 // Get the dad transmits.
914 DataSize
= sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS
);
915 Status
= Ip6Cfg
->GetData (
917 Ip6ConfigDataTypeDupAddrDetectTransmits
,
922 if (EFI_ERROR (Status
)) {
923 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA
), gShellNetwork2HiiHandle
, Status
);
927 InsertTailList (IfList
, &IfCb
->Link
);
929 if ((IfName
!= NULL
) && (StrCmp (IfName
, IfInfo
->Name
) == 0)) {
931 // Only need the appointed interface, keep the allocated buffer.
939 if (HandleBuffer
!= NULL
) {
940 FreePool (HandleBuffer
);
947 if (IfInfo
!= NULL
) {
952 if (IfCb
->IfId
!= NULL
) {
953 FreePool (IfCb
->IfId
);
963 The list process of the IfConfig6 application.
965 @param[in] IfList The pointer of IfList(interface list).
967 @retval SHELL_SUCCESS The IfConfig6 list processed successfully.
968 @retval others The IfConfig6 list process failed.
972 IfConfig6ShowInterfaceInfo (
973 IN LIST_ENTRY
*IfList
977 IFCONFIG6_INTERFACE_CB
*IfCb
;
980 Entry
= IfList
->ForwardLink
;
982 if (IsListEmpty (IfList
)) {
983 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_INTERFACE
), gShellNetwork2HiiHandle
);
987 // Go through the interface list.
989 while (Entry
!= IfList
) {
990 IfCb
= BASE_CR (Entry
, IFCONFIG6_INTERFACE_CB
, Link
);
992 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_BREAK
), gShellNetwork2HiiHandle
);
995 // Print interface name.
997 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_IF_NAME
), gShellNetwork2HiiHandle
, IfCb
->IfInfo
->Name
);
1000 // Print interface config policy.
1002 if (IfCb
->Policy
== Ip6ConfigPolicyAutomatic
) {
1003 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_POLICY_AUTO
), gShellNetwork2HiiHandle
);
1005 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_POLICY_MAN
), gShellNetwork2HiiHandle
);
1009 // Print dad transmit.
1011 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_DAD_TRANSMITS
), gShellNetwork2HiiHandle
, IfCb
->Xmits
);
1014 // Print interface id if has.
1016 if (IfCb
->IfId
!= NULL
) {
1017 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_INTERFACE_ID_HEAD
), gShellNetwork2HiiHandle
);
1019 IfConfig6PrintMacAddr (
1026 // Print mac address of the interface.
1028 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_MAC_ADDR_HEAD
), gShellNetwork2HiiHandle
);
1030 IfConfig6PrintMacAddr (
1031 IfCb
->IfInfo
->HwAddress
.Addr
,
1032 IfCb
->IfInfo
->HwAddressSize
1036 // Print ip addresses list of the interface.
1038 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_IP_ADDR_HEAD
), gShellNetwork2HiiHandle
);
1040 for (Index
= 0; Index
< IfCb
->IfInfo
->AddressInfoCount
; Index
++) {
1041 IfConfig6PrintIpAddr (
1042 &IfCb
->IfInfo
->AddressInfo
[Index
].Address
,
1043 &IfCb
->IfInfo
->AddressInfo
[Index
].PrefixLength
1045 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_NEWLINE
), gShellNetwork2HiiHandle
);
1049 // Print dns server addresses list of the interface if has.
1051 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_DNS_ADDR_HEAD
), gShellNetwork2HiiHandle
);
1053 for (Index
= 0; Index
< IfCb
->DnsCnt
; Index
++) {
1054 IfConfig6PrintIpAddr (
1055 &IfCb
->DnsAddr
[Index
],
1058 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_NEWLINE
), gShellNetwork2HiiHandle
);
1062 // Print route table of the interface if has.
1064 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_ROUTE_HEAD
), gShellNetwork2HiiHandle
);
1066 for (Index
= 0; Index
< IfCb
->IfInfo
->RouteCount
; Index
++) {
1067 IfConfig6PrintIpAddr (
1068 &IfCb
->IfInfo
->RouteTable
[Index
].Destination
,
1069 &IfCb
->IfInfo
->RouteTable
[Index
].PrefixLength
1071 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_JOINT
), gShellNetwork2HiiHandle
);
1073 IfConfig6PrintIpAddr (
1074 &IfCb
->IfInfo
->RouteTable
[Index
].Gateway
,
1077 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_NEWLINE
), gShellNetwork2HiiHandle
);
1080 Entry
= Entry
->ForwardLink
;
1083 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_BREAK
), gShellNetwork2HiiHandle
);
1084 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_NEWLINE
), gShellNetwork2HiiHandle
);
1086 return SHELL_SUCCESS
;
1090 The clean process of the IfConfig6 application.
1092 @param[in] IfList The pointer of IfList(interface list).
1093 @param[in] IfName The pointer of interface name.
1095 @retval SHELL_SUCCESS The IfConfig6 clean processed successfully.
1096 @retval others The IfConfig6 clean process failed.
1100 IfConfig6ClearInterfaceInfo (
1101 IN LIST_ENTRY
*IfList
,
1106 SHELL_STATUS ShellStatus
;
1108 IFCONFIG6_INTERFACE_CB
*IfCb
;
1109 EFI_IP6_CONFIG_POLICY Policy
;
1111 Entry
= IfList
->ForwardLink
;
1112 Status
= EFI_SUCCESS
;
1113 ShellStatus
= SHELL_SUCCESS
;
1115 if (IsListEmpty (IfList
)) {
1116 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_INTERFACE
), gShellNetwork2HiiHandle
);
1120 // Go through the interface list.If the interface name is specified, then
1121 // need to refresh the configuration.
1123 while (Entry
!= IfList
) {
1124 IfCb
= BASE_CR (Entry
, IFCONFIG6_INTERFACE_CB
, Link
);
1126 if ((IfName
!= NULL
) && (StrCmp (IfName
, IfCb
->IfInfo
->Name
) == 0)) {
1127 Policy
= Ip6ConfigPolicyManual
;
1129 Status
= IfCb
->IfCfg
->SetData (
1131 Ip6ConfigDataTypePolicy
,
1132 sizeof (EFI_IP6_CONFIG_POLICY
),
1135 if (EFI_ERROR (Status
)) {
1136 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellNetwork2HiiHandle
, L
"ifconfig6");
1137 ShellStatus
= SHELL_ACCESS_DENIED
;
1142 Policy
= Ip6ConfigPolicyAutomatic
;
1144 Status
= IfCb
->IfCfg
->SetData (
1146 Ip6ConfigDataTypePolicy
,
1147 sizeof (EFI_IP6_CONFIG_POLICY
),
1151 if (EFI_ERROR (Status
)) {
1152 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellNetwork2HiiHandle
, L
"ifconfig6");
1153 ShellStatus
= SHELL_ACCESS_DENIED
;
1157 Entry
= Entry
->ForwardLink
;
1164 The set process of the IfConfig6 application.
1166 @param[in] IfList The pointer of IfList(interface list).
1167 @param[in] VarArg The pointer of ARG_LIST(Args with "-s" option).
1169 @retval SHELL_SUCCESS The IfConfig6 set processed successfully.
1170 @retval others The IfConfig6 set process failed.
1174 IfConfig6SetInterfaceInfo (
1175 IN LIST_ENTRY
*IfList
,
1180 SHELL_STATUS ShellStatus
;
1181 IFCONFIG6_INTERFACE_CB
*IfCb
;
1182 EFI_IP6_CONFIG_MANUAL_ADDRESS
*CfgManAddr
;
1183 EFI_IPv6_ADDRESS
*CfgAddr
;
1185 EFI_IP6_CONFIG_INTERFACE_ID
*InterfaceId
;
1188 UINTN CurDadXmitsLen
;
1189 EFI_IP6_CONFIG_POLICY Policy
;
1191 VAR_CHECK_CODE CheckCode
;
1192 EFI_EVENT TimeOutEvt
;
1193 EFI_EVENT MappedEvt
;
1194 BOOLEAN IsAddressOk
;
1199 BOOLEAN IsAddressSet
;
1200 EFI_IP6_CONFIG_INTERFACE_INFO
*IfInfo
;
1210 if (IsListEmpty (IfList
)) {
1211 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_INTERFACE
), gShellNetwork2HiiHandle
);
1212 return SHELL_INVALID_PARAMETER
;
1216 // Make sure to set only one interface each time.
1218 IfCb
= BASE_CR (IfList
->ForwardLink
, IFCONFIG6_INTERFACE_CB
, Link
);
1219 Status
= EFI_SUCCESS
;
1220 ShellStatus
= SHELL_SUCCESS
;
1223 // Initialize check list mechanism.
1225 CheckCode
= IfConfig6RetriveCheckListByName (
1232 // Create events & timers for asynchronous settings.
1234 Status
= gBS
->CreateEvent (
1241 if (EFI_ERROR (Status
)) {
1242 ShellStatus
= SHELL_ACCESS_DENIED
;
1246 Status
= gBS
->CreateEvent (
1249 IfConfig6ManualAddressNotify
,
1253 if (EFI_ERROR (Status
)) {
1254 ShellStatus
= SHELL_ACCESS_DENIED
;
1259 // Parse the setting variables.
1261 while (VarArg
!= NULL
) {
1263 // Check invalid parameters (duplication & unknown & conflict).
1265 CheckCode
= IfConfig6RetriveCheckListByName (
1266 mIfConfig6SetCheckList
,
1271 if (VarCheckOk
!= CheckCode
) {
1272 switch (CheckCode
) {
1273 case VarCheckDuplicate
:
1274 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_DUPLICATE_COMMAND
), gShellNetwork2HiiHandle
, VarArg
->Arg
);
1277 case VarCheckConflict
:
1278 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_CONFLICT_COMMAND
), gShellNetwork2HiiHandle
, VarArg
->Arg
);
1281 case VarCheckUnknown
:
1282 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_UNKNOWN_COMMAND
), gShellNetwork2HiiHandle
, VarArg
->Arg
);
1289 VarArg
= VarArg
->Next
;
1294 // Process valid variables.
1296 if (StrCmp (VarArg
->Arg
, L
"auto") == 0) {
1298 // Set automaic config policy
1300 Policy
= Ip6ConfigPolicyAutomatic
;
1301 Status
= IfCb
->IfCfg
->SetData (
1303 Ip6ConfigDataTypePolicy
,
1304 sizeof (EFI_IP6_CONFIG_POLICY
),
1308 if (EFI_ERROR (Status
)) {
1309 ShellStatus
= SHELL_ACCESS_DENIED
;
1313 VarArg
= VarArg
->Next
;
1315 if (VarArg
!= NULL
) {
1316 if (StrCmp (VarArg
->Arg
, L
"host") == 0) {
1317 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_IP_CONFIG
), gShellNetwork2HiiHandle
, Status
);
1318 ShellStatus
= SHELL_INVALID_PARAMETER
;
1320 } else if (StrCmp (VarArg
->Arg
, L
"gw") == 0) {
1321 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_GW_CONFIG
), gShellNetwork2HiiHandle
, Status
);
1322 ShellStatus
= SHELL_INVALID_PARAMETER
;
1324 } else if (StrCmp (VarArg
->Arg
, L
"dns") == 0) {
1325 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_DNS_CONFIG
), gShellNetwork2HiiHandle
, Status
);
1326 ShellStatus
= SHELL_INVALID_PARAMETER
;
1330 } else if (StrCmp (VarArg
->Arg
, L
"man") == 0) {
1332 // Set manual config policy.
1334 Policy
= Ip6ConfigPolicyManual
;
1335 Status
= IfCb
->IfCfg
->SetData (
1337 Ip6ConfigDataTypePolicy
,
1338 sizeof (EFI_IP6_CONFIG_POLICY
),
1342 if (EFI_ERROR (Status
)) {
1343 ShellStatus
= SHELL_ACCESS_DENIED
;
1347 VarArg
= VarArg
->Next
;
1348 } else if (StrCmp (VarArg
->Arg
, L
"host") == 0) {
1350 // Parse till the next tag or the end of command line.
1352 VarArg
= VarArg
->Next
;
1353 Status
= IfConfig6ParseManualAddressList (
1359 if (EFI_ERROR (Status
)) {
1360 if (Status
== EFI_INVALID_PARAMETER
) {
1361 ShellStatus
= SHELL_INVALID_PARAMETER
;
1362 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_LACK_ARGUMENTS
), gShellNetwork2HiiHandle
, L
"host");
1365 ShellStatus
= SHELL_ACCESS_DENIED
;
1371 // Set static host ip6 address list.
1372 // This is a asynchronous process.
1374 IsAddressOk
= FALSE
;
1376 Status
= IfCb
->IfCfg
->RegisterDataNotify (
1378 Ip6ConfigDataTypeManualAddress
,
1381 if (EFI_ERROR (Status
)) {
1382 ShellStatus
= SHELL_ACCESS_DENIED
;
1386 Status
= IfCb
->IfCfg
->SetData (
1388 Ip6ConfigDataTypeManualAddress
,
1393 if (Status
== EFI_NOT_READY
) {
1395 // Get current dad transmits count.
1397 CurDadXmitsLen
= sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS
);
1398 IfCb
->IfCfg
->GetData (
1400 Ip6ConfigDataTypeDupAddrDetectTransmits
,
1405 gBS
->SetTimer (TimeOutEvt
, TimerRelative
, 50000000 + 10000000 * CurDadXmits
);
1407 while (EFI_ERROR (gBS
->CheckEvent (TimeOutEvt
))) {
1409 Status
= EFI_SUCCESS
;
1415 IfCb
->IfCfg
->UnregisterDataNotify (
1417 Ip6ConfigDataTypeManualAddress
,
1421 if (EFI_ERROR (Status
)) {
1422 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_MAN_HOST
), gShellNetwork2HiiHandle
, Status
);
1423 ShellStatus
= SHELL_ACCESS_DENIED
;
1428 // Check whether the address is set successfully.
1432 Status
= IfCb
->IfCfg
->GetData (
1434 Ip6ConfigDataTypeInterfaceInfo
,
1439 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1440 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA
), gShellNetwork2HiiHandle
, Status
);
1441 ShellStatus
= SHELL_ACCESS_DENIED
;
1445 IfInfo
= AllocateZeroPool (DataSize
);
1447 if (IfInfo
== NULL
) {
1448 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
1452 Status
= IfCb
->IfCfg
->GetData (
1454 Ip6ConfigDataTypeInterfaceInfo
,
1459 if (EFI_ERROR (Status
)) {
1460 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA
), gShellNetwork2HiiHandle
, Status
);
1461 ShellStatus
= SHELL_ACCESS_DENIED
;
1465 for ( Index
= 0; Index
< (UINTN
)(AddrSize
/ sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
)); Index
++) {
1466 IsAddressSet
= FALSE
;
1468 // By default, the prefix length 0 is regarded as 64.
1470 if (CfgManAddr
[Index
].PrefixLength
== 0) {
1471 CfgManAddr
[Index
].PrefixLength
= 64;
1474 for (Index2
= 0; Index2
< IfInfo
->AddressInfoCount
; Index2
++) {
1475 if (EFI_IP6_EQUAL (&IfInfo
->AddressInfo
[Index2
].Address
, &CfgManAddr
[Index
].Address
) &&
1476 (IfInfo
->AddressInfo
[Index2
].PrefixLength
== CfgManAddr
[Index
].PrefixLength
))
1478 IsAddressSet
= TRUE
;
1483 if (!IsAddressSet
) {
1484 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_ADDRESS_FAILED
), gShellNetwork2HiiHandle
);
1485 IfConfig6PrintIpAddr (
1486 &CfgManAddr
[Index
].Address
,
1487 &CfgManAddr
[Index
].PrefixLength
1489 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_NEWLINE
), gShellNetwork2HiiHandle
);
1492 } else if (StrCmp (VarArg
->Arg
, L
"gw") == 0) {
1494 // Parse till the next tag or the end of command line.
1496 VarArg
= VarArg
->Next
;
1497 Status
= IfConfig6ParseGwDnsAddressList (
1503 if (EFI_ERROR (Status
)) {
1504 if (Status
== EFI_INVALID_PARAMETER
) {
1505 ShellStatus
= SHELL_INVALID_PARAMETER
;
1506 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_LACK_ARGUMENTS
), gShellNetwork2HiiHandle
, L
"gw");
1509 ShellStatus
= SHELL_ACCESS_DENIED
;
1515 // Set static gateway ip6 address list.
1517 Status
= IfCb
->IfCfg
->SetData (
1519 Ip6ConfigDataTypeGateway
,
1524 if (EFI_ERROR (Status
)) {
1525 ShellStatus
= SHELL_ACCESS_DENIED
;
1526 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_MAN_GW
), gShellNetwork2HiiHandle
, Status
);
1529 } else if (StrCmp (VarArg
->Arg
, L
"dns") == 0) {
1531 // Parse till the next tag or the end of command line.
1533 VarArg
= VarArg
->Next
;
1534 Status
= IfConfig6ParseGwDnsAddressList (
1540 if (EFI_ERROR (Status
)) {
1541 if (Status
== EFI_INVALID_PARAMETER
) {
1542 ShellStatus
= SHELL_INVALID_PARAMETER
;
1543 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_LACK_ARGUMENTS
), gShellNetwork2HiiHandle
, L
"dns");
1546 ShellStatus
= SHELL_ACCESS_DENIED
;
1552 // Set static DNS server ip6 address list.
1554 Status
= IfCb
->IfCfg
->SetData (
1556 Ip6ConfigDataTypeDnsServer
,
1561 if (EFI_ERROR (Status
)) {
1562 ShellStatus
= SHELL_ACCESS_DENIED
;
1565 } else if (StrCmp (VarArg
->Arg
, L
"id") == 0) {
1567 // Parse till the next tag or the end of command line.
1569 VarArg
= VarArg
->Next
;
1570 Status
= IfConfig6ParseInterfaceId (&VarArg
, &InterfaceId
);
1572 if (EFI_ERROR (Status
)) {
1573 ShellStatus
= SHELL_INVALID_PARAMETER
;
1578 // Set alternative interface id.
1580 Status
= IfCb
->IfCfg
->SetData (
1582 Ip6ConfigDataTypeAltInterfaceId
,
1583 sizeof (EFI_IP6_CONFIG_INTERFACE_ID
),
1587 if (EFI_ERROR (Status
)) {
1588 ShellStatus
= SHELL_ACCESS_DENIED
;
1591 } else if (StrCmp (VarArg
->Arg
, L
"dad") == 0) {
1593 // Parse till the next tag or the end of command line.
1595 VarArg
= VarArg
->Next
;
1596 Status
= IfConfig6ParseDadXmits (&VarArg
, &DadXmits
);
1598 if (EFI_ERROR (Status
)) {
1599 ShellStatus
= SHELL_ACCESS_DENIED
;
1604 // Set dad transmits count.
1606 Status
= IfCb
->IfCfg
->SetData (
1608 Ip6ConfigDataTypeDupAddrDetectTransmits
,
1609 sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS
),
1613 if (EFI_ERROR (Status
)) {
1614 ShellStatus
= SHELL_ACCESS_DENIED
;
1622 if (CfgManAddr
!= NULL
) {
1623 FreePool (CfgManAddr
);
1626 if (CfgAddr
!= NULL
) {
1630 if (MappedEvt
!= NULL
) {
1631 gBS
->CloseEvent (MappedEvt
);
1634 if (TimeOutEvt
!= NULL
) {
1635 gBS
->CloseEvent (TimeOutEvt
);
1638 if (IfInfo
!= NULL
) {
1646 The IfConfig6 main process.
1648 @param[in] Private The pointer of IFCONFIG6_PRIVATE_DATA.
1650 @retval SHELL_SUCCESS IfConfig6 processed successfully.
1651 @retval others The IfConfig6 process failed.
1656 IN IFCONFIG6_PRIVATE_DATA
*Private
1660 SHELL_STATUS ShellStatus
;
1662 ShellStatus
= SHELL_SUCCESS
;
1665 // Get configure information of all interfaces.
1667 Status
= IfConfig6GetInterfaceInfo (
1668 Private
->ImageHandle
,
1673 if (EFI_ERROR (Status
)) {
1674 ShellStatus
= SHELL_NOT_FOUND
;
1678 switch (Private
->OpCode
) {
1679 case IfConfig6OpList
:
1680 ShellStatus
= IfConfig6ShowInterfaceInfo (&Private
->IfList
);
1683 case IfConfig6OpClear
:
1684 ShellStatus
= IfConfig6ClearInterfaceInfo (&Private
->IfList
, Private
->IfName
);
1687 case IfConfig6OpSet
:
1688 ShellStatus
= IfConfig6SetInterfaceInfo (&Private
->IfList
, Private
->VarArg
);
1692 ShellStatus
= SHELL_UNSUPPORTED
;
1701 The IfConfig6 cleanup process, free the allocated memory.
1703 @param[in] Private The pointer of IFCONFIG6_PRIVATE_DATA.
1708 IN IFCONFIG6_PRIVATE_DATA
*Private
1712 LIST_ENTRY
*NextEntry
;
1713 IFCONFIG6_INTERFACE_CB
*IfCb
;
1715 ASSERT (Private
!= NULL
);
1718 // Clean the list which save the set config Args.
1720 if (Private
->VarArg
!= NULL
) {
1721 IfConfig6FreeArgList (Private
->VarArg
);
1724 if (Private
->IfName
!= NULL
) {
1725 FreePool (Private
->IfName
);
1729 // Clean the IFCONFIG6_INTERFACE_CB list.
1731 Entry
= Private
->IfList
.ForwardLink
;
1732 NextEntry
= Entry
->ForwardLink
;
1734 while (Entry
!= &Private
->IfList
) {
1735 IfCb
= BASE_CR (Entry
, IFCONFIG6_INTERFACE_CB
, Link
);
1737 RemoveEntryList (&IfCb
->Link
);
1739 if (IfCb
->IfId
!= NULL
) {
1740 FreePool (IfCb
->IfId
);
1743 if (IfCb
->IfInfo
!= NULL
) {
1744 FreePool (IfCb
->IfInfo
);
1750 NextEntry
= Entry
->ForwardLink
;
1757 Function for 'ifconfig6' command.
1759 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1760 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1762 @retval SHELL_SUCCESS ifconfig6 command processed successfully.
1763 @retval others The ifconfig6 command process failed.
1768 ShellCommandRunIfconfig6 (
1769 IN EFI_HANDLE ImageHandle
,
1770 IN EFI_SYSTEM_TABLE
*SystemTable
1774 SHELL_STATUS ShellStatus
;
1775 IFCONFIG6_PRIVATE_DATA
*Private
;
1776 LIST_ENTRY
*ParamPackage
;
1777 CONST CHAR16
*ValueStr
;
1779 CHAR16
*ProblemParam
;
1783 Status
= EFI_INVALID_PARAMETER
;
1784 ShellStatus
= SHELL_SUCCESS
;
1786 Status
= ShellCommandLineParseEx (mIfConfig6CheckList
, &ParamPackage
, &ProblemParam
, TRUE
, FALSE
);
1787 if (EFI_ERROR (Status
)) {
1788 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_COMMAND
), gShellNetwork2HiiHandle
, L
"ifconfig6", ProblemParam
);
1789 ShellStatus
= SHELL_INVALID_PARAMETER
;
1794 // To handle no option.
1796 if (!ShellCommandLineGetFlag (ParamPackage
, L
"-r") && !ShellCommandLineGetFlag (ParamPackage
, L
"-s") &&
1797 !ShellCommandLineGetFlag (ParamPackage
, L
"-?") && !ShellCommandLineGetFlag (ParamPackage
, L
"-l"))
1799 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_LACK_OPTION
), gShellNetwork2HiiHandle
);
1800 ShellStatus
= SHELL_INVALID_PARAMETER
;
1805 // To handle conflict options.
1807 if (((ShellCommandLineGetFlag (ParamPackage
, L
"-r")) && (ShellCommandLineGetFlag (ParamPackage
, L
"-s"))) ||
1808 ((ShellCommandLineGetFlag (ParamPackage
, L
"-r")) && (ShellCommandLineGetFlag (ParamPackage
, L
"-l"))) ||
1809 ((ShellCommandLineGetFlag (ParamPackage
, L
"-r")) && (ShellCommandLineGetFlag (ParamPackage
, L
"-?"))) ||
1810 ((ShellCommandLineGetFlag (ParamPackage
, L
"-s")) && (ShellCommandLineGetFlag (ParamPackage
, L
"-l"))) ||
1811 ((ShellCommandLineGetFlag (ParamPackage
, L
"-s")) && (ShellCommandLineGetFlag (ParamPackage
, L
"-?"))) ||
1812 ((ShellCommandLineGetFlag (ParamPackage
, L
"-l")) && (ShellCommandLineGetFlag (ParamPackage
, L
"-?"))))
1814 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_CONFLICT_OPTIONS
), gShellNetwork2HiiHandle
);
1815 ShellStatus
= SHELL_INVALID_PARAMETER
;
1819 Private
= AllocateZeroPool (sizeof (IFCONFIG6_PRIVATE_DATA
));
1821 if (Private
== NULL
) {
1822 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
1826 InitializeListHead (&Private
->IfList
);
1829 // To get interface name for the list option.
1831 if (ShellCommandLineGetFlag (ParamPackage
, L
"-l")) {
1832 Private
->OpCode
= IfConfig6OpList
;
1833 ValueStr
= ShellCommandLineGetValue (ParamPackage
, L
"-l");
1834 if (ValueStr
!= NULL
) {
1835 Str
= AllocateCopyPool (StrSize (ValueStr
), ValueStr
);
1837 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_OUT_MEM
), gShellNetwork2HiiHandle
, L
"ifconfig6");
1838 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
1842 Private
->IfName
= Str
;
1847 // To get interface name for the clear option.
1849 if (ShellCommandLineGetFlag (ParamPackage
, L
"-r")) {
1850 Private
->OpCode
= IfConfig6OpClear
;
1851 ValueStr
= ShellCommandLineGetValue (ParamPackage
, L
"-r");
1852 if (ValueStr
!= NULL
) {
1853 Str
= AllocateCopyPool (StrSize (ValueStr
), ValueStr
);
1855 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_OUT_MEM
), gShellNetwork2HiiHandle
, L
"ifconfig6");
1856 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
1860 Private
->IfName
= Str
;
1865 // To get interface name and corresponding Args for the set option.
1867 if (ShellCommandLineGetFlag (ParamPackage
, L
"-s")) {
1868 ValueStr
= ShellCommandLineGetValue (ParamPackage
, L
"-s");
1869 if (ValueStr
== NULL
) {
1870 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_LACK_INTERFACE
), gShellNetwork2HiiHandle
);
1871 ShellStatus
= SHELL_INVALID_PARAMETER
;
1876 // To split the configuration into multi-section.
1878 ArgList
= IfConfig6SplitStrToList (ValueStr
, L
' ');
1879 if (ArgList
== NULL
) {
1880 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_OUT_MEM
), gShellNetwork2HiiHandle
, L
"ifconfig6");
1881 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
1885 Private
->OpCode
= IfConfig6OpSet
;
1886 Private
->IfName
= ArgList
->Arg
;
1888 Private
->VarArg
= ArgList
->Next
;
1890 if ((Private
->IfName
== NULL
) || (Private
->VarArg
== NULL
)) {
1891 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_LACK_COMMAND
), gShellNetwork2HiiHandle
);
1892 ShellStatus
= SHELL_INVALID_PARAMETER
;
1898 // Main process of ifconfig6.
1900 ShellStatus
= IfConfig6 (Private
);
1904 ShellCommandLineFreeVarList (ParamPackage
);
1905 if (Private
!= NULL
) {
1906 IfConfig6Cleanup (Private
);