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
;
74 SHELL_PARAM_ITEM mIfConfig6CheckList
[] = {
101 VAR_CHECK_ITEM mIfConfig6SetCheckList
[] = {
155 @param List Pointer to ARG_LIST to free.
158 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
);
206 // init a node for the list head.
208 ArgNode
= (ARG_LIST
*) AllocateZeroPool (sizeof (ARG_LIST
));
209 if (ArgNode
== NULL
) {
215 // Split the local copy and save in the list node.
217 while (*Str
!= L
'\0') {
218 if (*Str
== Separator
) {
220 ArgNode
->Arg
= ArgStr
;
222 ArgNode
->Next
= (ARG_LIST
*) AllocateZeroPool (sizeof (ARG_LIST
));
223 if (ArgNode
->Next
== NULL
) {
225 // Free the local copy of string stored in the first node
227 FreePool (ArgList
->Arg
);
228 IfConfig6FreeArgList (ArgList
);
231 ArgNode
= ArgNode
->Next
;
237 ArgNode
->Arg
= ArgStr
;
238 ArgNode
->Next
= NULL
;
244 Check the correctness of input Args with '-s' option.
246 @param[in] CheckList The pointer of VAR_CHECK_ITEM array.
247 @param[in] Name The pointer of input arg.
248 @param[in] Init The switch to execute the check.
250 @return The value of VAR_CHECK_CODE.
254 IfConfig6RetriveCheckListByName(
255 IN VAR_CHECK_ITEM
*CheckList
,
260 STATIC UINT32 CheckDuplicate
;
261 STATIC UINT32 CheckConflict
;
262 VAR_CHECK_CODE RtCode
;
274 Arg
= CheckList
[Index
];
277 // Check the Duplicated/Conflicted/Unknown input Args.
279 while (Arg
.FlagStr
!= NULL
) {
280 if (StrCmp (Arg
.FlagStr
, Name
) == 0) {
282 if (CheckDuplicate
& Arg
.FlagID
) {
283 RtCode
= VarCheckDuplicate
;
287 if (CheckConflict
& Arg
.ConflictMask
) {
288 RtCode
= VarCheckConflict
;
292 CheckDuplicate
|= Arg
.FlagID
;
293 CheckConflict
|= Arg
.ConflictMask
;
297 Arg
= CheckList
[++Index
];
300 if (Arg
.FlagStr
== NULL
) {
301 RtCode
= VarCheckUnknown
;
308 The notify function of create event when performing a manual config.
310 @param[in] Event The event this notify function registered to.
311 @param[in] Context Pointer to the context data registered to the event.
316 IfConfig6ManualAddressNotify (
321 *((BOOLEAN
*) Context
) = TRUE
;
327 @param[in] Node The pointer of MAC address buffer.
328 @param[in] Size The size of MAC address buffer.
332 IfConfig6PrintMacAddr (
339 ASSERT (Size
<= MACADDRMAXSIZE
);
341 for (Index
= 0; Index
< Size
; Index
++) {
342 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_MAC_ADDR_BODY
), gShellNetwork2HiiHandle
, Node
[Index
]);
343 if (Index
+ 1 < Size
) {
344 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_COLON
), gShellNetwork2HiiHandle
);
348 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_NEWLINE
), gShellNetwork2HiiHandle
);
354 @param[in] Ip The pointer of Ip bufffer in EFI_IPv6_ADDRESS format.
355 @param[in] PrefixLen The pointer of PrefixLen that describes the size Prefix.
359 IfConfig6PrintIpAddr (
360 IN EFI_IPv6_ADDRESS
*Ip
,
369 for (Index
= 0; Index
< PREFIXMAXLEN
; Index
= Index
+ 2) {
371 if (!Short
&& (Index
+ 1 < PREFIXMAXLEN
) && (Index
% 2 == 0) && (Ip
->Addr
[Index
] == 0) && (Ip
->Addr
[Index
+ 1] == 0)) {
373 // Deal with the case of ::.
377 // :: is at the beginning of the address.
379 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_COLON
), gShellNetwork2HiiHandle
);
381 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_COLON
), gShellNetwork2HiiHandle
);
383 while ((Ip
->Addr
[Index
] == 0) && (Ip
->Addr
[Index
+ 1] == 0) && (Index
< PREFIXMAXLEN
)) {
385 if (Index
> PREFIXMAXLEN
- 2) {
392 if (Index
== PREFIXMAXLEN
) {
394 // :: is at the end of the address.
400 if (Index
< PREFIXMAXLEN
- 1) {
401 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_IP_ADDR_BODY
), gShellNetwork2HiiHandle
, Ip
->Addr
[Index
]);
402 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_IP_ADDR_BODY
), gShellNetwork2HiiHandle
, Ip
->Addr
[Index
+ 1]);
405 if (Index
+ 2 < PREFIXMAXLEN
) {
406 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_COLON
), gShellNetwork2HiiHandle
);
410 if (PrefixLen
!= NULL
) {
411 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_PREFIX_LEN
), gShellNetwork2HiiHandle
, *PrefixLen
);
416 Pick up host IPv6 address in string format from Args with "-s" option and convert it to EFI_IP6_CONFIG_MANUAL_ADDRESS format.
418 @param[in, out] Arg The pointer of the address of ARG_LIST which save Args with the "-s" option.
419 @param[out] Buf The pointer of the address of EFI_IP6_CONFIG_MANUAL_ADDRESS.
420 @param[out] BufSize The pointer of BufSize that describes the size of Buf in bytes.
422 @retval EFI_SUCCESS The convertion is successful.
423 @retval Others Does't find the host address, or it is an invalid IPv6 address in string format.
427 IfConfig6ParseManualAddressList (
428 IN OUT ARG_LIST
**Arg
,
429 OUT EFI_IP6_CONFIG_MANUAL_ADDRESS
**Buf
,
434 EFI_IP6_CONFIG_MANUAL_ADDRESS
*AddrBuf
;
436 EFI_IPv6_ADDRESS Address
;
445 Status
= EFI_SUCCESS
;
448 // Go through the list to check the correctness of input host ip6 address.
450 while ((!EFI_ERROR (Status
)) && (VarArg
!= NULL
)) {
452 Status
= NetLibStrToIp6andPrefix (VarArg
->Arg
, &Address
, &Prefix
);
454 if (EFI_ERROR (Status
)) {
461 VarArg
= VarArg
->Next
;
466 return EFI_INVALID_PARAMETER
;
469 AddrBuf
= AllocateZeroPool (AddrCnt
* sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
));
470 ASSERT (AddrBuf
!= NULL
);
474 Status
= EFI_SUCCESS
;
477 // Go through the list to fill in the EFI_IP6_CONFIG_MANUAL_ADDRESS structure.
479 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) {
494 AddrBuf
[AddrCnt
].IsAnycast
= FALSE
;
495 AddrBuf
[AddrCnt
].PrefixLength
= Prefix
;
496 IP6_COPY_ADDRESS (&AddrBuf
[AddrCnt
].Address
, &Address
);
497 VarArg
= VarArg
->Next
;
503 if (EFI_ERROR (Status
) && (Status
!= EFI_INVALID_PARAMETER
)) {
508 *BufSize
= AddrCnt
* sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
);
519 Pick up gw/dns IPv6 address in string format from Args with "-s" option and convert it to EFI_IPv6_ADDRESS format.
521 @param[in, out] Arg The pointer of the address of ARG_LIST that save Args with the "-s" option.
522 @param[out] Buf The pointer of the address of EFI_IPv6_ADDRESS.
523 @param[out] BufSize The pointer of BufSize that describes the size of Buf in bytes.
525 @retval EFI_SUCCESS The conversion is successful.
526 @retval Others Doesn't find the host address, or it is an invalid IPv6 address in string format.
530 IfConfig6ParseGwDnsAddressList (
531 IN OUT ARG_LIST
**Arg
,
532 OUT EFI_IPv6_ADDRESS
**Buf
,
537 EFI_IPv6_ADDRESS
*AddrBuf
;
539 EFI_IPv6_ADDRESS Address
;
547 Status
= EFI_SUCCESS
;
550 // Go through the list to check the correctness of input gw/dns address.
552 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
)) {
583 Status
= NetLibStrToIp6andPrefix (VarArg
->Arg
, &Address
, &Prefix
);
585 if (EFI_ERROR (Status
)) {
589 IP6_COPY_ADDRESS (&AddrBuf
[AddrCnt
], &Address
);
591 VarArg
= VarArg
->Next
;
597 if (EFI_ERROR (Status
) && (Status
!= EFI_INVALID_PARAMETER
)) {
602 *BufSize
= AddrCnt
* sizeof (EFI_IPv6_ADDRESS
);
613 Parse InterfaceId in string format from Args with the "-s" option and convert it to EFI_IP6_CONFIG_INTERFACE_ID format.
615 @param[in, out] Arg The pointer of the address of ARG_LIST that saves Args with the "-s" option.
616 @param[out] IfId The pointer of EFI_IP6_CONFIG_INTERFACE_ID.
618 @retval EFI_SUCCESS The get status processed successfullly.
619 @retval EFI_INVALID_PARAMETER The get status process failed.
623 IfConfig6ParseInterfaceId (
624 IN OUT ARG_LIST
**Arg
,
625 OUT EFI_IP6_CONFIG_INTERFACE_ID
**IfId
633 return EFI_INVALID_PARAMETER
;
638 ASSERT (IfId
!= NULL
);
639 *IfId
= AllocateZeroPool (sizeof (EFI_IP6_CONFIG_INTERFACE_ID
));
640 ASSERT (*IfId
!= NULL
);
642 while ((*IdStr
!= L
'\0') && (Index
< 8)) {
645 while ((*IdStr
!= L
':') && (*IdStr
!= L
'\0')) {
647 if ((*IdStr
<= L
'F') && (*IdStr
>= L
'A')) {
648 NodeVal
= (UINT8
)((NodeVal
<< 4) + *IdStr
- L
'A' + 10);
649 } else if ((*IdStr
<= L
'f') && (*IdStr
>= L
'a')) {
650 NodeVal
= (UINT8
)((NodeVal
<< 4) + *IdStr
- L
'a' + 10);
651 } else if ((*IdStr
<= L
'9') && (*IdStr
>= L
'0')) {
652 NodeVal
= (UINT8
)((NodeVal
<< 4) + *IdStr
- L
'0');
655 return EFI_INVALID_PARAMETER
;
661 (*IfId
)->Id
[Index
++] = NodeVal
;
663 if (*IdStr
== L
':') {
673 Parse dad in string format from Args with the "-s" option and convert it to UINT32 format.
675 @param[in, out] Arg The pointer of the address of ARG_LIST that saves Args with the "-s" option.
676 @param[out] Xmits The pointer of Xmits.
678 @retval EFI_SUCCESS The get status processed successfully.
679 @retval others The get status process failed.
683 IfConfig6ParseDadXmits (
684 IN OUT ARG_LIST
**Arg
,
691 return EFI_INVALID_PARAMETER
;
694 ValStr
= (*Arg
)->Arg
;
697 while (*ValStr
!= L
'\0') {
699 if ((*ValStr
<= L
'9') && (*ValStr
>= L
'0')) {
701 *Xmits
= (*Xmits
* 10) + (*ValStr
- L
'0');
705 return EFI_INVALID_PARAMETER
;
716 The get current status of all handles.
718 @param[in] ImageHandle The handle of ImageHandle.
719 @param[in] IfName The pointer of IfName(interface name).
720 @param[in] IfList The pointer of IfList(interface list).
722 @retval EFI_SUCCESS The get status processed successfully.
723 @retval others The get status process failed.
727 IfConfig6GetInterfaceInfo (
728 IN EFI_HANDLE ImageHandle
,
730 IN LIST_ENTRY
*IfList
736 EFI_HANDLE
*HandleBuffer
;
737 EFI_IP6_CONFIG_PROTOCOL
*Ip6Cfg
;
738 EFI_IP6_CONFIG_INTERFACE_INFO
*IfInfo
;
739 IFCONFIG6_INTERFACE_CB
*IfCb
;
749 // Locate all the handles with ip6 service binding protocol.
751 Status
= gBS
->LocateHandleBuffer (
753 &gEfiIp6ServiceBindingProtocolGuid
,
758 if (EFI_ERROR (Status
) || (HandleNum
== 0)) {
763 // Enumerate all handles that installed with ip6 service binding protocol.
765 for (HandleIndex
= 0; HandleIndex
< HandleNum
; HandleIndex
++) {
771 // Ip6config protocol and ip6 service binding protocol are installed
772 // on the same handle.
774 ASSERT (HandleBuffer
!= NULL
);
775 Status
= gBS
->HandleProtocol (
776 HandleBuffer
[HandleIndex
],
777 &gEfiIp6ConfigProtocolGuid
,
781 if (EFI_ERROR (Status
)) {
785 // Get the interface information size.
787 Status
= Ip6Cfg
->GetData (
789 Ip6ConfigDataTypeInterfaceInfo
,
794 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
795 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA
), gShellNetwork2HiiHandle
, Status
);
799 IfInfo
= AllocateZeroPool (DataSize
);
801 if (IfInfo
== NULL
) {
802 Status
= EFI_OUT_OF_RESOURCES
;
806 // Get the interface info.
808 Status
= Ip6Cfg
->GetData (
810 Ip6ConfigDataTypeInterfaceInfo
,
815 if (EFI_ERROR (Status
)) {
816 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA
), gShellNetwork2HiiHandle
, Status
);
820 // Check the interface name if required.
822 if ((IfName
!= NULL
) && (StrCmp (IfName
, IfInfo
->Name
) != 0)) {
829 // Get the size of dns server list.
831 Status
= Ip6Cfg
->GetData (
833 Ip6ConfigDataTypeDnsServer
,
838 if ((Status
!= EFI_BUFFER_TOO_SMALL
) && (Status
!= EFI_NOT_FOUND
)) {
839 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA
), gShellNetwork2HiiHandle
, Status
);
843 IfCb
= AllocateZeroPool (sizeof (IFCONFIG6_INTERFACE_CB
) + DataSize
);
846 Status
= EFI_OUT_OF_RESOURCES
;
850 IfCb
->NicHandle
= HandleBuffer
[HandleIndex
];
851 IfCb
->IfInfo
= IfInfo
;
852 IfCb
->IfCfg
= Ip6Cfg
;
853 IfCb
->DnsCnt
= (UINT32
) (DataSize
/ sizeof (EFI_IPv6_ADDRESS
));
856 // Get the dns server list if has.
860 Status
= Ip6Cfg
->GetData (
862 Ip6ConfigDataTypeDnsServer
,
867 if (EFI_ERROR (Status
)) {
868 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA
), gShellNetwork2HiiHandle
, Status
);
873 // Get the interface id if has.
875 DataSize
= sizeof (EFI_IP6_CONFIG_INTERFACE_ID
);
876 IfCb
->IfId
= AllocateZeroPool (DataSize
);
878 if (IfCb
->IfId
== NULL
) {
882 Status
= Ip6Cfg
->GetData (
884 Ip6ConfigDataTypeAltInterfaceId
,
889 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_FOUND
)) {
890 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA
), gShellNetwork2HiiHandle
, Status
);
894 if (Status
== EFI_NOT_FOUND
) {
895 FreePool (IfCb
->IfId
);
899 // Get the config policy.
901 DataSize
= sizeof (EFI_IP6_CONFIG_POLICY
);
902 Status
= Ip6Cfg
->GetData (
904 Ip6ConfigDataTypePolicy
,
909 if (EFI_ERROR (Status
)) {
910 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA
), gShellNetwork2HiiHandle
, Status
);
914 // Get the dad transmits.
916 DataSize
= sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS
);
917 Status
= Ip6Cfg
->GetData (
919 Ip6ConfigDataTypeDupAddrDetectTransmits
,
924 if (EFI_ERROR (Status
)) {
925 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_IP6CFG_GETDATA
), gShellNetwork2HiiHandle
, Status
);
929 InsertTailList (IfList
, &IfCb
->Link
);
931 if ((IfName
!= NULL
) && (StrCmp (IfName
, IfInfo
->Name
) == 0)) {
933 // Only need the appointed interface, keep the allocated buffer.
941 if (HandleBuffer
!= NULL
) {
942 FreePool (HandleBuffer
);
949 if (IfInfo
!= NULL
) {
954 if (IfCb
->IfId
!= NULL
) {
955 FreePool (IfCb
->IfId
);
965 The list process of the IfConfig6 application.
967 @param[in] IfList The pointer of IfList(interface list).
969 @retval SHELL_SUCCESS The IfConfig6 list processed successfully.
970 @retval others The IfConfig6 list process failed.
974 IfConfig6ShowInterfaceInfo (
975 IN LIST_ENTRY
*IfList
979 IFCONFIG6_INTERFACE_CB
*IfCb
;
982 Entry
= IfList
->ForwardLink
;
984 if (IsListEmpty (IfList
)) {
985 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_INTERFACE
), gShellNetwork2HiiHandle
);
989 // Go through the interface list.
991 while (Entry
!= IfList
) {
993 IfCb
= BASE_CR (Entry
, IFCONFIG6_INTERFACE_CB
, Link
);
995 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_BREAK
), gShellNetwork2HiiHandle
);
998 // Print interface name.
1000 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_IF_NAME
), gShellNetwork2HiiHandle
, IfCb
->IfInfo
->Name
);
1003 // Print interface config policy.
1005 if (IfCb
->Policy
== Ip6ConfigPolicyAutomatic
) {
1006 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_POLICY_AUTO
), gShellNetwork2HiiHandle
);
1008 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_POLICY_MAN
), gShellNetwork2HiiHandle
);
1012 // Print dad transmit.
1014 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_DAD_TRANSMITS
), gShellNetwork2HiiHandle
, IfCb
->Xmits
);
1017 // Print interface id if has.
1019 if (IfCb
->IfId
!= NULL
) {
1020 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_INTERFACE_ID_HEAD
), gShellNetwork2HiiHandle
);
1022 IfConfig6PrintMacAddr (
1028 // Print mac address of the interface.
1030 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_MAC_ADDR_HEAD
), gShellNetwork2HiiHandle
);
1032 IfConfig6PrintMacAddr (
1033 IfCb
->IfInfo
->HwAddress
.Addr
,
1034 IfCb
->IfInfo
->HwAddressSize
1038 // Print ip addresses list of the interface.
1040 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_IP_ADDR_HEAD
), gShellNetwork2HiiHandle
);
1042 for (Index
= 0; Index
< IfCb
->IfInfo
->AddressInfoCount
; Index
++) {
1043 IfConfig6PrintIpAddr (
1044 &IfCb
->IfInfo
->AddressInfo
[Index
].Address
,
1045 &IfCb
->IfInfo
->AddressInfo
[Index
].PrefixLength
1047 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_NEWLINE
), gShellNetwork2HiiHandle
);
1051 // Print dns server addresses list of the interface if has.
1053 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_DNS_ADDR_HEAD
), gShellNetwork2HiiHandle
);
1055 for (Index
= 0; Index
< IfCb
->DnsCnt
; Index
++) {
1056 IfConfig6PrintIpAddr (
1057 &IfCb
->DnsAddr
[Index
],
1060 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_NEWLINE
), gShellNetwork2HiiHandle
);
1064 // Print route table of the interface if has.
1066 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_ROUTE_HEAD
), gShellNetwork2HiiHandle
);
1068 for (Index
= 0; Index
< IfCb
->IfInfo
->RouteCount
; Index
++) {
1069 IfConfig6PrintIpAddr (
1070 &IfCb
->IfInfo
->RouteTable
[Index
].Destination
,
1071 &IfCb
->IfInfo
->RouteTable
[Index
].PrefixLength
1073 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_JOINT
), gShellNetwork2HiiHandle
);
1075 IfConfig6PrintIpAddr (
1076 &IfCb
->IfInfo
->RouteTable
[Index
].Gateway
,
1079 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_NEWLINE
), gShellNetwork2HiiHandle
);
1082 Entry
= Entry
->ForwardLink
;
1085 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_BREAK
), gShellNetwork2HiiHandle
);
1086 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_INFO_NEWLINE
), gShellNetwork2HiiHandle
);
1088 return SHELL_SUCCESS
;
1092 The clean process of the IfConfig6 application.
1094 @param[in] IfList The pointer of IfList(interface list).
1095 @param[in] IfName The pointer of interface name.
1097 @retval SHELL_SUCCESS The IfConfig6 clean processed successfully.
1098 @retval others The IfConfig6 clean process failed.
1102 IfConfig6ClearInterfaceInfo (
1103 IN LIST_ENTRY
*IfList
,
1108 SHELL_STATUS ShellStatus
;
1110 IFCONFIG6_INTERFACE_CB
*IfCb
;
1111 EFI_IP6_CONFIG_POLICY Policy
;
1113 Entry
= IfList
->ForwardLink
;
1114 Status
= EFI_SUCCESS
;
1115 ShellStatus
= SHELL_SUCCESS
;
1117 if (IsListEmpty (IfList
)) {
1118 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_INTERFACE
), gShellNetwork2HiiHandle
);
1122 // Go through the interface list.If the interface name is specified, then
1123 // need to refresh the configuration.
1125 while (Entry
!= IfList
) {
1127 IfCb
= BASE_CR (Entry
, IFCONFIG6_INTERFACE_CB
, Link
);
1129 if ((IfName
!= NULL
) && (StrCmp (IfName
, IfCb
->IfInfo
->Name
) == 0)) {
1130 Policy
= Ip6ConfigPolicyManual
;
1132 Status
= IfCb
->IfCfg
->SetData (
1134 Ip6ConfigDataTypePolicy
,
1135 sizeof (EFI_IP6_CONFIG_POLICY
),
1138 if (EFI_ERROR (Status
)) {
1139 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellNetwork2HiiHandle
, L
"ifconfig6");
1140 ShellStatus
= SHELL_ACCESS_DENIED
;
1145 Policy
= Ip6ConfigPolicyAutomatic
;
1147 Status
= IfCb
->IfCfg
->SetData (
1149 Ip6ConfigDataTypePolicy
,
1150 sizeof (EFI_IP6_CONFIG_POLICY
),
1154 if (EFI_ERROR (Status
)) {
1155 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellNetwork2HiiHandle
, L
"ifconfig6");
1156 ShellStatus
= SHELL_ACCESS_DENIED
;
1160 Entry
= Entry
->ForwardLink
;
1167 The set process of the IfConfig6 application.
1169 @param[in] IfList The pointer of IfList(interface list).
1170 @param[in] VarArg The pointer of ARG_LIST(Args with "-s" option).
1172 @retval SHELL_SUCCESS The IfConfig6 set processed successfully.
1173 @retval others The IfConfig6 set process failed.
1177 IfConfig6SetInterfaceInfo (
1178 IN LIST_ENTRY
*IfList
,
1183 SHELL_STATUS ShellStatus
;
1184 IFCONFIG6_INTERFACE_CB
*IfCb
;
1185 EFI_IP6_CONFIG_MANUAL_ADDRESS
*CfgManAddr
;
1186 EFI_IPv6_ADDRESS
*CfgAddr
;
1188 EFI_IP6_CONFIG_INTERFACE_ID
*InterfaceId
;
1191 UINTN CurDadXmitsLen
;
1192 EFI_IP6_CONFIG_POLICY Policy
;
1194 VAR_CHECK_CODE CheckCode
;
1195 EFI_EVENT TimeOutEvt
;
1196 EFI_EVENT MappedEvt
;
1197 BOOLEAN IsAddressOk
;
1202 BOOLEAN IsAddressSet
;
1203 EFI_IP6_CONFIG_INTERFACE_INFO
*IfInfo
;
1213 if (IsListEmpty (IfList
)) {
1214 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_INTERFACE
), gShellNetwork2HiiHandle
);
1215 return SHELL_INVALID_PARAMETER
;
1218 // Make sure to set only one interface each time.
1220 IfCb
= BASE_CR (IfList
->ForwardLink
, IFCONFIG6_INTERFACE_CB
, Link
);
1221 Status
= EFI_SUCCESS
;
1222 ShellStatus
= SHELL_SUCCESS
;
1225 // Initialize check list mechanism.
1227 CheckCode
= IfConfig6RetriveCheckListByName(
1234 // Create events & timers for asynchronous settings.
1236 Status
= gBS
->CreateEvent (
1243 if (EFI_ERROR (Status
)) {
1244 ShellStatus
= SHELL_ACCESS_DENIED
;
1248 Status
= gBS
->CreateEvent (
1251 IfConfig6ManualAddressNotify
,
1255 if (EFI_ERROR (Status
)) {
1256 ShellStatus
= SHELL_ACCESS_DENIED
;
1260 // Parse the setting variables.
1262 while (VarArg
!= NULL
) {
1264 // Check invalid parameters (duplication & unknown & conflict).
1266 CheckCode
= IfConfig6RetriveCheckListByName(
1267 mIfConfig6SetCheckList
,
1272 if (VarCheckOk
!= CheckCode
) {
1273 switch (CheckCode
) {
1274 case VarCheckDuplicate
:
1275 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_DUPLICATE_COMMAND
), gShellNetwork2HiiHandle
, VarArg
->Arg
);
1278 case VarCheckConflict
:
1279 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_CONFLICT_COMMAND
), gShellNetwork2HiiHandle
, VarArg
->Arg
);
1282 case VarCheckUnknown
:
1283 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_UNKNOWN_COMMAND
), gShellNetwork2HiiHandle
, VarArg
->Arg
);
1290 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
;
1349 } else if (StrCmp (VarArg
->Arg
, L
"host") == 0) {
1351 // Parse till the next tag or the end of command line.
1353 VarArg
= VarArg
->Next
;
1354 Status
= IfConfig6ParseManualAddressList (
1360 if (EFI_ERROR (Status
)) {
1361 if (Status
== EFI_INVALID_PARAMETER
) {
1362 ShellStatus
= SHELL_INVALID_PARAMETER
;
1363 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_LACK_ARGUMENTS
), gShellNetwork2HiiHandle
, L
"host");
1366 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
)) {
1477 IsAddressSet
= TRUE
;
1482 if (!IsAddressSet
) {
1483 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_ADDRESS_FAILED
), gShellNetwork2HiiHandle
);
1484 IfConfig6PrintIpAddr (
1485 &CfgManAddr
[Index
].Address
,
1486 &CfgManAddr
[Index
].PrefixLength
1488 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
;
1514 // Set static gateway ip6 address list.
1516 Status
= IfCb
->IfCfg
->SetData (
1518 Ip6ConfigDataTypeGateway
,
1523 if (EFI_ERROR (Status
)) {
1524 ShellStatus
= SHELL_ACCESS_DENIED
;
1525 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
;
1551 // Set static DNS server ip6 address list.
1553 Status
= IfCb
->IfCfg
->SetData (
1555 Ip6ConfigDataTypeDnsServer
,
1560 if (EFI_ERROR (Status
)) {
1561 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
;
1577 // Set alternative interface id.
1579 Status
= IfCb
->IfCfg
->SetData (
1581 Ip6ConfigDataTypeAltInterfaceId
,
1582 sizeof (EFI_IP6_CONFIG_INTERFACE_ID
),
1586 if (EFI_ERROR (Status
)) {
1587 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
;
1603 // Set dad transmits count.
1605 Status
= IfCb
->IfCfg
->SetData (
1607 Ip6ConfigDataTypeDupAddrDetectTransmits
,
1608 sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS
),
1612 if (EFI_ERROR(Status
)) {
1613 ShellStatus
= SHELL_ACCESS_DENIED
;
1621 if (CfgManAddr
!= NULL
) {
1622 FreePool (CfgManAddr
);
1625 if (CfgAddr
!= NULL
) {
1629 if (MappedEvt
!= NULL
) {
1630 gBS
->CloseEvent (MappedEvt
);
1633 if (TimeOutEvt
!= NULL
) {
1634 gBS
->CloseEvent (TimeOutEvt
);
1637 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
) {
1736 IfCb
= BASE_CR (Entry
, IFCONFIG6_INTERFACE_CB
, Link
);
1738 RemoveEntryList (&IfCb
->Link
);
1740 if (IfCb
->IfId
!= NULL
) {
1742 FreePool (IfCb
->IfId
);
1745 if (IfCb
->IfInfo
!= NULL
) {
1747 FreePool (IfCb
->IfInfo
);
1753 NextEntry
= Entry
->ForwardLink
;
1760 Function for 'ifconfig6' command.
1762 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1763 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1765 @retval SHELL_SUCCESS ifconfig6 command processed successfully.
1766 @retval others The ifconfig6 command process failed.
1771 ShellCommandRunIfconfig6 (
1772 IN EFI_HANDLE ImageHandle
,
1773 IN EFI_SYSTEM_TABLE
*SystemTable
1777 SHELL_STATUS ShellStatus
;
1778 IFCONFIG6_PRIVATE_DATA
*Private
;
1779 LIST_ENTRY
*ParamPackage
;
1780 CONST CHAR16
*ValueStr
;
1782 CHAR16
*ProblemParam
;
1786 Status
= EFI_INVALID_PARAMETER
;
1787 ShellStatus
= SHELL_SUCCESS
;
1789 Status
= ShellCommandLineParseEx (mIfConfig6CheckList
, &ParamPackage
, &ProblemParam
, TRUE
, FALSE
);
1790 if (EFI_ERROR (Status
)) {
1791 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_INVALID_COMMAND
), gShellNetwork2HiiHandle
, L
"ifconfig6", ProblemParam
);
1792 ShellStatus
= SHELL_INVALID_PARAMETER
;
1797 // To handle no option.
1799 if (!ShellCommandLineGetFlag (ParamPackage
, L
"-r") && !ShellCommandLineGetFlag (ParamPackage
, L
"-s") &&
1800 !ShellCommandLineGetFlag (ParamPackage
, L
"-?") && !ShellCommandLineGetFlag (ParamPackage
, L
"-l")) {
1801 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_LACK_OPTION
), gShellNetwork2HiiHandle
);
1802 ShellStatus
= SHELL_INVALID_PARAMETER
;
1806 // To handle conflict options.
1808 if (((ShellCommandLineGetFlag (ParamPackage
, L
"-r")) && (ShellCommandLineGetFlag (ParamPackage
, L
"-s"))) ||
1809 ((ShellCommandLineGetFlag (ParamPackage
, L
"-r")) && (ShellCommandLineGetFlag (ParamPackage
, L
"-l"))) ||
1810 ((ShellCommandLineGetFlag (ParamPackage
, L
"-r")) && (ShellCommandLineGetFlag (ParamPackage
, L
"-?"))) ||
1811 ((ShellCommandLineGetFlag (ParamPackage
, L
"-s")) && (ShellCommandLineGetFlag (ParamPackage
, L
"-l"))) ||
1812 ((ShellCommandLineGetFlag (ParamPackage
, L
"-s")) && (ShellCommandLineGetFlag (ParamPackage
, L
"-?"))) ||
1813 ((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
;
1841 Private
->IfName
= Str
;
1845 // To get interface name for the clear option.
1847 if (ShellCommandLineGetFlag (ParamPackage
, L
"-r")) {
1848 Private
->OpCode
= IfConfig6OpClear
;
1849 ValueStr
= ShellCommandLineGetValue (ParamPackage
, L
"-r");
1850 if (ValueStr
!= NULL
) {
1851 Str
= AllocateCopyPool (StrSize (ValueStr
), ValueStr
);
1853 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_OUT_MEM
), gShellNetwork2HiiHandle
, L
"ifconfig6");
1854 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
1857 Private
->IfName
= Str
;
1861 // To get interface name and corresponding Args for the set option.
1863 if (ShellCommandLineGetFlag (ParamPackage
, L
"-s")) {
1865 ValueStr
= ShellCommandLineGetValue (ParamPackage
, L
"-s");
1866 if (ValueStr
== NULL
) {
1867 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_LACK_INTERFACE
), gShellNetwork2HiiHandle
);
1868 ShellStatus
= SHELL_INVALID_PARAMETER
;
1872 // To split the configuration into multi-section.
1874 ArgList
= IfConfig6SplitStrToList (ValueStr
, L
' ');
1875 if (ArgList
== NULL
) {
1876 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_OUT_MEM
), gShellNetwork2HiiHandle
, L
"ifconfig6");
1877 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
1881 Private
->OpCode
= IfConfig6OpSet
;
1882 Private
->IfName
= ArgList
->Arg
;
1884 Private
->VarArg
= ArgList
->Next
;
1886 if (Private
->IfName
== NULL
|| Private
->VarArg
== NULL
) {
1887 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_IFCONFIG6_ERR_LACK_COMMAND
), gShellNetwork2HiiHandle
);
1888 ShellStatus
= SHELL_INVALID_PARAMETER
;
1893 // Main process of ifconfig6.
1895 ShellStatus
= IfConfig6 (Private
);
1899 ShellCommandLineFreeVarList (ParamPackage
);
1900 if (Private
!= NULL
) {
1901 IfConfig6Cleanup (Private
);