TianoCore EDK2 master
Loading...
Searching...
No Matches
DnsDriver.c
Go to the documentation of this file.
1
9#include "DnsImpl.h"
10
11EFI_DRIVER_BINDING_PROTOCOL gDns4DriverBinding = {
15 DNS_VERSION,
16 NULL,
17 NULL
18};
19
20EFI_DRIVER_BINDING_PROTOCOL gDns6DriverBinding = {
24 DNS_VERSION,
25 NULL,
26 NULL
27};
28
29EFI_SERVICE_BINDING_PROTOCOL mDns4ServiceBinding = {
32};
33
34EFI_SERVICE_BINDING_PROTOCOL mDns6ServiceBinding = {
37};
38
39DNS_DRIVER_DATA *mDriverData = NULL;
40
47VOID
49 IN DNS_INSTANCE *Instance
50 )
51{
52 ZeroMem (&Instance->Dns4CfgData, sizeof (EFI_DNS4_CONFIG_DATA));
53
54 ZeroMem (&Instance->Dns6CfgData, sizeof (EFI_DNS6_CONFIG_DATA));
55
56 if (!NetMapIsEmpty (&Instance->Dns4TxTokens)) {
57 Dns4InstanceCancelToken (Instance, NULL);
58 }
59
60 if (!NetMapIsEmpty (&Instance->Dns6TxTokens)) {
61 Dns6InstanceCancelToken (Instance, NULL);
62 }
63
64 if (Instance->UdpIo != NULL) {
65 UdpIoFreeIo (Instance->UdpIo);
66 }
67
68 FreePool (Instance);
69}
70
83 IN DNS_SERVICE *Service,
84 OUT DNS_INSTANCE **Instance
85 )
86{
87 DNS_INSTANCE *DnsIns;
88
89 *Instance = NULL;
90
91 DnsIns = AllocateZeroPool (sizeof (DNS_INSTANCE));
92 if (DnsIns == NULL) {
93 return EFI_OUT_OF_RESOURCES;
94 }
95
96 DnsIns->Signature = DNS_INSTANCE_SIGNATURE;
97 InitializeListHead (&DnsIns->Link);
98 DnsIns->State = DNS_STATE_UNCONFIGED;
99 DnsIns->InDestroy = FALSE;
100 DnsIns->Service = Service;
101
102 if (Service->IpVersion == IP_VERSION_4) {
103 CopyMem (&DnsIns->Dns4, &mDns4Protocol, sizeof (DnsIns->Dns4));
104 NetMapInit (&DnsIns->Dns4TxTokens);
105 } else {
106 CopyMem (&DnsIns->Dns6, &mDns6Protocol, sizeof (DnsIns->Dns6));
107 NetMapInit (&DnsIns->Dns6TxTokens);
108 }
109
110 DnsIns->UdpIo = UdpIoCreateIo (
111 Service->ControllerHandle,
112 Service->ImageHandle,
114 Service->IpVersion,
115 DnsIns
116 );
117 if (DnsIns->UdpIo == NULL) {
118 FreePool (DnsIns);
119 return EFI_OUT_OF_RESOURCES;
120 }
121
122 *Instance = DnsIns;
123
124 return EFI_SUCCESS;
125}
126
138EFIAPI
140 IN LIST_ENTRY *Entry,
141 IN VOID *Context
142 )
143{
144 DNS_INSTANCE *Instance;
145 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
146 UINTN NumberOfChildren;
147 EFI_HANDLE *ChildHandleBuffer;
148
149 if ((Entry == NULL) || (Context == NULL)) {
150 return EFI_INVALID_PARAMETER;
151 }
152
153 Instance = NET_LIST_USER_STRUCT_S (Entry, DNS_INSTANCE, Link, DNS_INSTANCE_SIGNATURE);
154 ServiceBinding = ((DNS_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *)Context)->ServiceBinding;
155 NumberOfChildren = ((DNS_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *)Context)->NumberOfChildren;
156 ChildHandleBuffer = ((DNS_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *)Context)->ChildHandleBuffer;
157
158 if (!NetIsInHandleBuffer (Instance->ChildHandle, NumberOfChildren, ChildHandleBuffer)) {
159 return EFI_SUCCESS;
160 }
161
162 return ServiceBinding->DestroyChild (ServiceBinding, Instance->ChildHandle);
163}
164
178EFIAPI
180 IN UDP_IO *UdpIo,
181 IN VOID *Context
182 )
183{
184 return EFI_SUCCESS;
185}
186
193VOID
195 IN DNS_SERVICE *DnsSb
196 )
197{
198 UdpIoFreeIo (DnsSb->ConnectUdp);
199
200 if (DnsSb->TimerToGetMap != NULL) {
201 gBS->CloseEvent (DnsSb->TimerToGetMap);
202 }
203
204 if (DnsSb->Timer != NULL) {
205 gBS->CloseEvent (DnsSb->Timer);
206 }
207
208 FreePool (DnsSb);
209}
210
230 IN EFI_HANDLE Controller,
231 IN EFI_HANDLE Image,
232 IN UINT8 IpVersion,
233 OUT DNS_SERVICE **Service
234 )
235{
236 EFI_STATUS Status;
237 DNS_SERVICE *DnsSb;
238
239 Status = EFI_SUCCESS;
240 DnsSb = NULL;
241
242 *Service = NULL;
243
244 DnsSb = AllocateZeroPool (sizeof (DNS_SERVICE));
245 if (DnsSb == NULL) {
246 return EFI_OUT_OF_RESOURCES;
247 }
248
249 DnsSb->Signature = DNS_SERVICE_SIGNATURE;
250
251 if (IpVersion == IP_VERSION_4) {
252 DnsSb->ServiceBinding = mDns4ServiceBinding;
253 } else {
254 DnsSb->ServiceBinding = mDns6ServiceBinding;
255 }
256
257 DnsSb->Dns4ChildrenNum = 0;
258 InitializeListHead (&DnsSb->Dns4ChildrenList);
259
260 DnsSb->Dns6ChildrenNum = 0;
261 InitializeListHead (&DnsSb->Dns6ChildrenList);
262
263 DnsSb->ControllerHandle = Controller;
264 DnsSb->ImageHandle = Image;
265
266 DnsSb->TimerToGetMap = NULL;
267
268 DnsSb->Timer = NULL;
269
270 DnsSb->IpVersion = IpVersion;
271
272 //
273 // Create the timer used to time out the procedure which is used to
274 // get the default IP address.
275 //
276 Status = gBS->CreateEvent (
277 EVT_TIMER,
278 TPL_CALLBACK,
279 NULL,
280 NULL,
281 &DnsSb->TimerToGetMap
282 );
283 if (EFI_ERROR (Status)) {
284 FreePool (DnsSb);
285 return Status;
286 }
287
288 //
289 // Create the timer to retransmit packets.
290 //
291 Status = gBS->CreateEvent (
292 EVT_NOTIFY_SIGNAL | EVT_TIMER,
293 TPL_CALLBACK,
295 DnsSb,
296 &DnsSb->Timer
297 );
298 if (EFI_ERROR (Status)) {
299 if (DnsSb->TimerToGetMap != NULL) {
300 gBS->CloseEvent (DnsSb->TimerToGetMap);
301 }
302
303 FreePool (DnsSb);
304 return Status;
305 }
306
307 DnsSb->ConnectUdp = NULL;
308 DnsSb->ConnectUdp = UdpIoCreateIo (
309 Controller,
310 Image,
312 DnsSb->IpVersion,
313 NULL
314 );
315 if (DnsSb->ConnectUdp == NULL) {
316 if (DnsSb->TimerToGetMap != NULL) {
317 gBS->CloseEvent (DnsSb->TimerToGetMap);
318 }
319
320 gBS->CloseEvent (DnsSb->Timer);
321 FreePool (DnsSb);
322 return EFI_DEVICE_ERROR;
323 }
324
325 *Service = DnsSb;
326 return Status;
327}
328
339EFIAPI
341 IN EFI_HANDLE ImageHandle
342 )
343{
344 EFI_STATUS Status;
345
346 LIST_ENTRY *Entry;
347 DNS4_CACHE *ItemCache4;
348 DNS4_SERVER_IP *ItemServerIp4;
349 DNS6_CACHE *ItemCache6;
350 DNS6_SERVER_IP *ItemServerIp6;
351
352 ItemCache4 = NULL;
353 ItemServerIp4 = NULL;
354 ItemCache6 = NULL;
355 ItemServerIp6 = NULL;
356
357 //
358 // Disconnect the driver specified by ImageHandle
359 //
360 Status = NetLibDefaultUnload (ImageHandle);
361 if (EFI_ERROR (Status)) {
362 return Status;
363 }
364
365 //
366 // Free mDriverData.
367 //
368 if (mDriverData != NULL) {
369 if (mDriverData->Timer != NULL) {
370 gBS->CloseEvent (mDriverData->Timer);
371 }
372
373 while (!IsListEmpty (&mDriverData->Dns4CacheList)) {
374 Entry = NetListRemoveHead (&mDriverData->Dns4CacheList);
375 ASSERT (Entry != NULL);
376 ItemCache4 = NET_LIST_USER_STRUCT (Entry, DNS4_CACHE, AllCacheLink);
377 FreePool (ItemCache4->DnsCache.HostName);
378 FreePool (ItemCache4->DnsCache.IpAddress);
379 FreePool (ItemCache4);
380 }
381
382 while (!IsListEmpty (&mDriverData->Dns4ServerList)) {
383 Entry = NetListRemoveHead (&mDriverData->Dns4ServerList);
384 ASSERT (Entry != NULL);
385 ItemServerIp4 = NET_LIST_USER_STRUCT (Entry, DNS4_SERVER_IP, AllServerLink);
386 FreePool (ItemServerIp4);
387 }
388
389 while (!IsListEmpty (&mDriverData->Dns6CacheList)) {
390 Entry = NetListRemoveHead (&mDriverData->Dns6CacheList);
391 ASSERT (Entry != NULL);
392 ItemCache6 = NET_LIST_USER_STRUCT (Entry, DNS6_CACHE, AllCacheLink);
393 FreePool (ItemCache6->DnsCache.HostName);
394 FreePool (ItemCache6->DnsCache.IpAddress);
395 FreePool (ItemCache6);
396 }
397
398 while (!IsListEmpty (&mDriverData->Dns6ServerList)) {
399 Entry = NetListRemoveHead (&mDriverData->Dns6ServerList);
400 ASSERT (Entry != NULL);
401 ItemServerIp6 = NET_LIST_USER_STRUCT (Entry, DNS6_SERVER_IP, AllServerLink);
402 FreePool (ItemServerIp6);
403 }
404
405 FreePool (mDriverData);
406 }
407
408 return Status;
409}
410
423EFIAPI
425 IN EFI_HANDLE ImageHandle,
426 IN EFI_SYSTEM_TABLE *SystemTable
427 )
428{
429 EFI_STATUS Status;
430
431 Status = EFI_SUCCESS;
432
433 //
434 // Install the Dns4 Driver Binding Protocol.
435 //
437 ImageHandle,
438 SystemTable,
439 &gDns4DriverBinding,
440 ImageHandle,
443 );
444 if (EFI_ERROR (Status)) {
445 return Status;
446 }
447
448 //
449 // Install the Dns6 Driver Binding Protocol.
450 //
452 ImageHandle,
453 SystemTable,
454 &gDns6DriverBinding,
455 NULL,
458 );
459 if (EFI_ERROR (Status)) {
460 goto Error1;
461 }
462
463 //
464 // Create the driver data structures.
465 //
466 mDriverData = AllocateZeroPool (sizeof (DNS_DRIVER_DATA));
467 if (mDriverData == NULL) {
468 Status = EFI_OUT_OF_RESOURCES;
469 goto Error2;
470 }
471
472 //
473 // Create the timer event to update DNS cache list.
474 //
475 Status = gBS->CreateEvent (
476 EVT_NOTIFY_SIGNAL | EVT_TIMER,
477 TPL_CALLBACK,
479 NULL,
480 &mDriverData->Timer
481 );
482 if (EFI_ERROR (Status)) {
483 goto Error3;
484 }
485
486 Status = gBS->SetTimer (mDriverData->Timer, TimerPeriodic, TICKS_PER_SECOND);
487 if (EFI_ERROR (Status)) {
488 goto Error4;
489 }
490
491 InitializeListHead (&mDriverData->Dns4CacheList);
492 InitializeListHead (&mDriverData->Dns4ServerList);
493 InitializeListHead (&mDriverData->Dns6CacheList);
494 InitializeListHead (&mDriverData->Dns6ServerList);
495
496 return Status;
497
498Error4:
499 gBS->CloseEvent (mDriverData->Timer);
500
501Error3:
502 FreePool (mDriverData);
503
504Error2:
506 &gDns6DriverBinding,
509 );
510
511Error1:
513 &gDns4DriverBinding,
516 );
517
518 return Status;
519}
520
564EFIAPI
567 IN EFI_HANDLE ControllerHandle,
568 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
569 )
570{
571 EFI_STATUS Status;
572
573 //
574 // Test for the Dns4ServiceBinding Protocol.
575 //
576 Status = gBS->OpenProtocol (
577 ControllerHandle,
578 &gEfiDns4ServiceBindingProtocolGuid,
579 NULL,
580 This->DriverBindingHandle,
581 ControllerHandle,
582 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
583 );
584 if (!EFI_ERROR (Status)) {
585 return EFI_ALREADY_STARTED;
586 }
587
588 //
589 // Test for the Udp4ServiceBinding Protocol.
590 //
591 Status = gBS->OpenProtocol (
592 ControllerHandle,
593 &gEfiUdp4ServiceBindingProtocolGuid,
594 NULL,
595 This->DriverBindingHandle,
596 ControllerHandle,
597 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
598 );
599
600 return Status;
601}
602
639EFIAPI
642 IN EFI_HANDLE ControllerHandle,
643 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
644 )
645{
646 DNS_SERVICE *DnsSb;
647 EFI_STATUS Status;
648
649 Status = DnsCreateService (ControllerHandle, This->DriverBindingHandle, IP_VERSION_4, &DnsSb);
650 if (EFI_ERROR (Status)) {
651 return Status;
652 }
653
654 ASSERT (DnsSb != NULL);
655
656 Status = gBS->SetTimer (DnsSb->Timer, TimerPeriodic, TICKS_PER_SECOND);
657 if (EFI_ERROR (Status)) {
658 goto ON_ERROR;
659 }
660
661 //
662 // Install the Dns4ServiceBinding Protocol onto ControllerHandle.
663 //
664 Status = gBS->InstallMultipleProtocolInterfaces (
665 &ControllerHandle,
666 &gEfiDns4ServiceBindingProtocolGuid,
667 &DnsSb->ServiceBinding,
668 NULL
669 );
670 if (EFI_ERROR (Status)) {
671 goto ON_ERROR;
672 }
673
674 return EFI_SUCCESS;
675
676ON_ERROR:
677 DnsDestroyService (DnsSb);
678
679 return Status;
680}
681
709EFIAPI
712 IN EFI_HANDLE ControllerHandle,
713 IN UINTN NumberOfChildren,
714 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
715 )
716{
717 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
718 DNS_SERVICE *DnsSb;
719 EFI_HANDLE NicHandle;
720 EFI_STATUS Status;
721 LIST_ENTRY *List;
723
724 //
725 // DNS driver opens UDP child, So, Controller is a UDP
726 // child handle. Locate the Nic handle first. Then get the
727 // DNS private data back.
728 //
729 NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiUdp4ProtocolGuid);
730
731 if (NicHandle == NULL) {
732 return EFI_SUCCESS;
733 }
734
735 Status = gBS->OpenProtocol (
736 NicHandle,
737 &gEfiDns4ServiceBindingProtocolGuid,
738 (VOID **)&ServiceBinding,
739 This->DriverBindingHandle,
740 NicHandle,
741 EFI_OPEN_PROTOCOL_GET_PROTOCOL
742 );
743 if (EFI_ERROR (Status)) {
744 return EFI_DEVICE_ERROR;
745 }
746
747 DnsSb = DNS_SERVICE_FROM_THIS (ServiceBinding);
748
749 if (!IsListEmpty (&DnsSb->Dns4ChildrenList)) {
750 //
751 // Destroy the Dns child instance in ChildHandleBuffer.
752 //
753 List = &DnsSb->Dns4ChildrenList;
754 Context.ServiceBinding = ServiceBinding;
755 Context.NumberOfChildren = NumberOfChildren;
756 Context.ChildHandleBuffer = ChildHandleBuffer;
757 Status = NetDestroyLinkList (
758 List,
760 &Context,
761 NULL
762 );
763 }
764
765 if ((NumberOfChildren == 0) && IsListEmpty (&DnsSb->Dns4ChildrenList)) {
766 gBS->UninstallProtocolInterface (
767 NicHandle,
768 &gEfiDns4ServiceBindingProtocolGuid,
769 ServiceBinding
770 );
771
772 DnsDestroyService (DnsSb);
773
774 if (gDnsControllerNameTable != NULL) {
775 FreeUnicodeStringTable (gDnsControllerNameTable);
776 gDnsControllerNameTable = NULL;
777 }
778
779 Status = EFI_SUCCESS;
780 }
781
782 return Status;
783}
784
828EFIAPI
831 IN EFI_HANDLE ControllerHandle,
832 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
833 )
834{
835 EFI_STATUS Status;
836
837 //
838 // Test for the Dns6ServiceBinding Protocol
839 //
840 Status = gBS->OpenProtocol (
841 ControllerHandle,
842 &gEfiDns6ServiceBindingProtocolGuid,
843 NULL,
844 This->DriverBindingHandle,
845 ControllerHandle,
846 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
847 );
848 if (!EFI_ERROR (Status)) {
849 return EFI_ALREADY_STARTED;
850 }
851
852 //
853 // Test for the Udp6ServiceBinding Protocol
854 //
855 Status = gBS->OpenProtocol (
856 ControllerHandle,
857 &gEfiUdp6ServiceBindingProtocolGuid,
858 NULL,
859 This->DriverBindingHandle,
860 ControllerHandle,
861 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
862 );
863
864 return Status;
865}
866
903EFIAPI
906 IN EFI_HANDLE ControllerHandle,
907 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
908 )
909{
910 DNS_SERVICE *DnsSb;
911 EFI_STATUS Status;
912
913 Status = DnsCreateService (ControllerHandle, This->DriverBindingHandle, IP_VERSION_6, &DnsSb);
914 if (EFI_ERROR (Status)) {
915 return Status;
916 }
917
918 ASSERT (DnsSb != NULL);
919
920 Status = gBS->SetTimer (DnsSb->Timer, TimerPeriodic, TICKS_PER_SECOND);
921 if (EFI_ERROR (Status)) {
922 goto ON_ERROR;
923 }
924
925 //
926 // Install the Dns6ServiceBinding Protocol onto ControllerHandle
927 //
928 Status = gBS->InstallMultipleProtocolInterfaces (
929 &ControllerHandle,
930 &gEfiDns6ServiceBindingProtocolGuid,
931 &DnsSb->ServiceBinding,
932 NULL
933 );
934
935 if (EFI_ERROR (Status)) {
936 goto ON_ERROR;
937 }
938
939 return EFI_SUCCESS;
940
941ON_ERROR:
942 DnsDestroyService (DnsSb);
943
944 return Status;
945}
946
974EFIAPI
977 IN EFI_HANDLE ControllerHandle,
978 IN UINTN NumberOfChildren,
979 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
980 )
981{
982 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
983 DNS_SERVICE *DnsSb;
984 EFI_HANDLE NicHandle;
985 EFI_STATUS Status;
986 LIST_ENTRY *List;
988
989 //
990 // DNS driver opens UDP child, So, Controller is a UDP
991 // child handle. Locate the Nic handle first. Then get the
992 // DNS private data back.
993 //
994 NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiUdp6ProtocolGuid);
995
996 if (NicHandle == NULL) {
997 return EFI_SUCCESS;
998 }
999
1000 Status = gBS->OpenProtocol (
1001 NicHandle,
1002 &gEfiDns6ServiceBindingProtocolGuid,
1003 (VOID **)&ServiceBinding,
1004 This->DriverBindingHandle,
1005 NicHandle,
1006 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1007 );
1008 if (EFI_ERROR (Status)) {
1009 return EFI_DEVICE_ERROR;
1010 }
1011
1012 DnsSb = DNS_SERVICE_FROM_THIS (ServiceBinding);
1013
1014 if (!IsListEmpty (&DnsSb->Dns6ChildrenList)) {
1015 //
1016 // Destroy the Dns child instance in ChildHandleBuffer.
1017 //
1018 List = &DnsSb->Dns6ChildrenList;
1019 Context.ServiceBinding = ServiceBinding;
1020 Context.NumberOfChildren = NumberOfChildren;
1021 Context.ChildHandleBuffer = ChildHandleBuffer;
1022 Status = NetDestroyLinkList (
1023 List,
1025 &Context,
1026 NULL
1027 );
1028 }
1029
1030 if ((NumberOfChildren == 0) && IsListEmpty (&DnsSb->Dns6ChildrenList)) {
1031 gBS->UninstallProtocolInterface (
1032 NicHandle,
1033 &gEfiDns6ServiceBindingProtocolGuid,
1034 ServiceBinding
1035 );
1036
1037 DnsDestroyService (DnsSb);
1038
1039 if (gDnsControllerNameTable != NULL) {
1040 FreeUnicodeStringTable (gDnsControllerNameTable);
1041 gDnsControllerNameTable = NULL;
1042 }
1043
1044 Status = EFI_SUCCESS;
1045 }
1046
1047 return Status;
1048}
1049
1070EFIAPI
1073 IN EFI_HANDLE *ChildHandle
1074 )
1075{
1076 DNS_SERVICE *DnsSb;
1077 DNS_INSTANCE *Instance;
1078 EFI_STATUS Status;
1079 EFI_TPL OldTpl;
1080 VOID *Udp4;
1081
1082 if ((This == NULL) || (ChildHandle == NULL)) {
1083 return EFI_INVALID_PARAMETER;
1084 }
1085
1086 DnsSb = DNS_SERVICE_FROM_THIS (This);
1087
1088 Status = DnsCreateInstance (DnsSb, &Instance);
1089 if (EFI_ERROR (Status)) {
1090 return Status;
1091 }
1092
1093 ASSERT (Instance != NULL);
1094
1095 //
1096 // Install the DNS protocol onto ChildHandle
1097 //
1098 Status = gBS->InstallMultipleProtocolInterfaces (
1099 ChildHandle,
1100 &gEfiDns4ProtocolGuid,
1101 &Instance->Dns4,
1102 NULL
1103 );
1104 if (EFI_ERROR (Status)) {
1105 goto ON_ERROR;
1106 }
1107
1108 Instance->ChildHandle = *ChildHandle;
1109
1110 //
1111 // Open the Udp4 protocol BY_CHILD.
1112 //
1113 Status = gBS->OpenProtocol (
1114 DnsSb->ConnectUdp->UdpHandle,
1115 &gEfiUdp4ProtocolGuid,
1116 (VOID **)&Udp4,
1117 gDns4DriverBinding.DriverBindingHandle,
1118 Instance->ChildHandle,
1119 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1120 );
1121 if (EFI_ERROR (Status)) {
1122 gBS->UninstallMultipleProtocolInterfaces (
1123 Instance->ChildHandle,
1124 &gEfiDns4ProtocolGuid,
1125 &Instance->Dns4,
1126 NULL
1127 );
1128
1129 goto ON_ERROR;
1130 }
1131
1132 //
1133 // Open the Udp4 protocol by child.
1134 //
1135 Status = gBS->OpenProtocol (
1136 Instance->UdpIo->UdpHandle,
1137 &gEfiUdp4ProtocolGuid,
1138 (VOID **)&Udp4,
1139 gDns4DriverBinding.DriverBindingHandle,
1140 Instance->ChildHandle,
1141 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1142 );
1143 if (EFI_ERROR (Status)) {
1144 //
1145 // Close the Udp4 protocol.
1146 //
1147 gBS->CloseProtocol (
1148 DnsSb->ConnectUdp->UdpHandle,
1149 &gEfiUdp4ProtocolGuid,
1150 gDns4DriverBinding.DriverBindingHandle,
1151 *ChildHandle
1152 );
1153
1154 gBS->UninstallMultipleProtocolInterfaces (
1155 Instance->ChildHandle,
1156 &gEfiDns4ProtocolGuid,
1157 &Instance->Dns4,
1158 NULL
1159 );
1160
1161 goto ON_ERROR;
1162 }
1163
1164 //
1165 // Add it to the parent's child list.
1166 //
1167 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1168
1169 InsertTailList (&DnsSb->Dns4ChildrenList, &Instance->Link);
1170 DnsSb->Dns4ChildrenNum++;
1171
1172 gBS->RestoreTPL (OldTpl);
1173
1174 return EFI_SUCCESS;
1175
1176ON_ERROR:
1177
1178 DnsDestroyInstance (Instance);
1179 return Status;
1180}
1181
1201EFIAPI
1204 IN EFI_HANDLE ChildHandle
1205 )
1206{
1207 DNS_SERVICE *DnsSb;
1208 DNS_INSTANCE *Instance;
1209
1210 EFI_DNS4_PROTOCOL *Dns4;
1211 EFI_STATUS Status;
1212 EFI_TPL OldTpl;
1213
1214 if ((This == NULL) || (ChildHandle == NULL)) {
1215 return EFI_INVALID_PARAMETER;
1216 }
1217
1218 //
1219 // Retrieve the private context data structures
1220 //
1221 Status = gBS->OpenProtocol (
1222 ChildHandle,
1223 &gEfiDns4ProtocolGuid,
1224 (VOID **)&Dns4,
1225 gDns4DriverBinding.DriverBindingHandle,
1226 ChildHandle,
1227 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1228 );
1229
1230 if (EFI_ERROR (Status)) {
1231 return EFI_UNSUPPORTED;
1232 }
1233
1234 Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL4 (Dns4);
1235 DnsSb = DNS_SERVICE_FROM_THIS (This);
1236
1237 if (Instance->Service != DnsSb) {
1238 return EFI_INVALID_PARAMETER;
1239 }
1240
1241 if (Instance->InDestroy) {
1242 return EFI_SUCCESS;
1243 }
1244
1245 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1246
1247 Instance->InDestroy = TRUE;
1248
1249 //
1250 // Close the Udp4 protocol.
1251 //
1252 gBS->CloseProtocol (
1253 DnsSb->ConnectUdp->UdpHandle,
1254 &gEfiUdp4ProtocolGuid,
1255 gDns4DriverBinding.DriverBindingHandle,
1256 ChildHandle
1257 );
1258
1259 gBS->CloseProtocol (
1260 Instance->UdpIo->UdpHandle,
1261 &gEfiUdp4ProtocolGuid,
1262 gDns4DriverBinding.DriverBindingHandle,
1263 ChildHandle
1264 );
1265
1266 gBS->RestoreTPL (OldTpl);
1267
1268 //
1269 // Uninstall the DNS protocol first to enable a top down destruction.
1270 //
1271 Status = gBS->UninstallProtocolInterface (
1272 ChildHandle,
1273 &gEfiDns4ProtocolGuid,
1274 Dns4
1275 );
1276
1277 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1278
1279 if (EFI_ERROR (Status)) {
1280 Instance->InDestroy = FALSE;
1281 gBS->RestoreTPL (OldTpl);
1282 return Status;
1283 }
1284
1285 RemoveEntryList (&Instance->Link);
1286 DnsSb->Dns4ChildrenNum--;
1287
1288 gBS->RestoreTPL (OldTpl);
1289
1290 DnsDestroyInstance (Instance);
1291 return EFI_SUCCESS;
1292}
1293
1314EFIAPI
1317 IN EFI_HANDLE *ChildHandle
1318 )
1319{
1320 DNS_SERVICE *DnsSb;
1321 DNS_INSTANCE *Instance;
1322 EFI_STATUS Status;
1323 EFI_TPL OldTpl;
1324 VOID *Udp6;
1325
1326 if ((This == NULL) || (ChildHandle == NULL)) {
1327 return EFI_INVALID_PARAMETER;
1328 }
1329
1330 DnsSb = DNS_SERVICE_FROM_THIS (This);
1331
1332 Status = DnsCreateInstance (DnsSb, &Instance);
1333 if (EFI_ERROR (Status)) {
1334 return Status;
1335 }
1336
1337 ASSERT (Instance != NULL);
1338
1339 //
1340 // Install the DNS protocol onto ChildHandle
1341 //
1342 Status = gBS->InstallMultipleProtocolInterfaces (
1343 ChildHandle,
1344 &gEfiDns6ProtocolGuid,
1345 &Instance->Dns6,
1346 NULL
1347 );
1348 if (EFI_ERROR (Status)) {
1349 goto ON_ERROR;
1350 }
1351
1352 Instance->ChildHandle = *ChildHandle;
1353
1354 //
1355 // Open the Udp6 protocol BY_CHILD.
1356 //
1357 Status = gBS->OpenProtocol (
1358 DnsSb->ConnectUdp->UdpHandle,
1359 &gEfiUdp6ProtocolGuid,
1360 (VOID **)&Udp6,
1361 gDns6DriverBinding.DriverBindingHandle,
1362 Instance->ChildHandle,
1363 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1364 );
1365 if (EFI_ERROR (Status)) {
1366 gBS->UninstallMultipleProtocolInterfaces (
1367 Instance->ChildHandle,
1368 &gEfiDns6ProtocolGuid,
1369 &Instance->Dns6,
1370 NULL
1371 );
1372
1373 goto ON_ERROR;
1374 }
1375
1376 //
1377 // Open the Udp6 protocol by child.
1378 //
1379 Status = gBS->OpenProtocol (
1380 Instance->UdpIo->UdpHandle,
1381 &gEfiUdp6ProtocolGuid,
1382 (VOID **)&Udp6,
1383 gDns6DriverBinding.DriverBindingHandle,
1384 Instance->ChildHandle,
1385 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1386 );
1387 if (EFI_ERROR (Status)) {
1388 //
1389 // Close the Udp6 protocol.
1390 //
1391 gBS->CloseProtocol (
1392 DnsSb->ConnectUdp->UdpHandle,
1393 &gEfiUdp6ProtocolGuid,
1394 gDns6DriverBinding.DriverBindingHandle,
1395 *ChildHandle
1396 );
1397
1398 gBS->UninstallMultipleProtocolInterfaces (
1399 Instance->ChildHandle,
1400 &gEfiDns6ProtocolGuid,
1401 &Instance->Dns6,
1402 NULL
1403 );
1404
1405 goto ON_ERROR;
1406 }
1407
1408 //
1409 // Add it to the parent's child list.
1410 //
1411 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1412
1413 InsertTailList (&DnsSb->Dns6ChildrenList, &Instance->Link);
1414 DnsSb->Dns6ChildrenNum++;
1415
1416 gBS->RestoreTPL (OldTpl);
1417
1418 return EFI_SUCCESS;
1419
1420ON_ERROR:
1421
1422 DnsDestroyInstance (Instance);
1423 return Status;
1424}
1425
1445EFIAPI
1448 IN EFI_HANDLE ChildHandle
1449 )
1450{
1451 DNS_SERVICE *DnsSb;
1452 DNS_INSTANCE *Instance;
1453
1454 EFI_DNS6_PROTOCOL *Dns6;
1455 EFI_STATUS Status;
1456 EFI_TPL OldTpl;
1457
1458 if ((This == NULL) || (ChildHandle == NULL)) {
1459 return EFI_INVALID_PARAMETER;
1460 }
1461
1462 //
1463 // Retrieve the private context data structures
1464 //
1465 Status = gBS->OpenProtocol (
1466 ChildHandle,
1467 &gEfiDns6ProtocolGuid,
1468 (VOID **)&Dns6,
1469 gDns6DriverBinding.DriverBindingHandle,
1470 ChildHandle,
1471 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1472 );
1473
1474 if (EFI_ERROR (Status)) {
1475 return EFI_UNSUPPORTED;
1476 }
1477
1478 Instance = DNS_INSTANCE_FROM_THIS_PROTOCOL6 (Dns6);
1479 DnsSb = DNS_SERVICE_FROM_THIS (This);
1480
1481 if (Instance->Service != DnsSb) {
1482 return EFI_INVALID_PARAMETER;
1483 }
1484
1485 if (Instance->InDestroy) {
1486 return EFI_SUCCESS;
1487 }
1488
1489 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1490
1491 Instance->InDestroy = TRUE;
1492
1493 //
1494 // Close the Udp6 protocol.
1495 //
1496 gBS->CloseProtocol (
1497 DnsSb->ConnectUdp->UdpHandle,
1498 &gEfiUdp6ProtocolGuid,
1499 gDns6DriverBinding.DriverBindingHandle,
1500 ChildHandle
1501 );
1502
1503 gBS->CloseProtocol (
1504 Instance->UdpIo->UdpHandle,
1505 &gEfiUdp6ProtocolGuid,
1506 gDns6DriverBinding.DriverBindingHandle,
1507 ChildHandle
1508 );
1509
1510 gBS->RestoreTPL (OldTpl);
1511
1512 //
1513 // Uninstall the DNS protocol first to enable a top down destruction.
1514 //
1515 Status = gBS->UninstallProtocolInterface (
1516 ChildHandle,
1517 &gEfiDns6ProtocolGuid,
1518 Dns6
1519 );
1520
1521 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1522
1523 if (EFI_ERROR (Status)) {
1524 Instance->InDestroy = FALSE;
1525 gBS->RestoreTPL (OldTpl);
1526 return Status;
1527 }
1528
1529 RemoveEntryList (&Instance->Link);
1530 DnsSb->Dns6ChildrenNum--;
1531
1532 gBS->RestoreTPL (OldTpl);
1533
1534 DnsDestroyInstance (Instance);
1535 return EFI_SUCCESS;
1536}
UINT64 UINTN
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
Definition: LinkedList.c:403
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
Definition: LinkedList.c:590
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
Definition: LinkedList.c:182
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID DnsDestroyInstance(IN DNS_INSTANCE *Instance)
Definition: DnsDriver.c:48
EFI_STATUS EFIAPI DnsDestroyChildEntryInHandleBuffer(IN LIST_ENTRY *Entry, IN VOID *Context)
Definition: DnsDriver.c:139
EFI_STATUS EFIAPI DnsDriverEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: DnsDriver.c:424
EFI_STATUS EFIAPI Dns4DriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer OPTIONAL)
Definition: DnsDriver.c:710
EFI_STATUS EFIAPI Dns4ServiceBindingDestroyChild(IN EFI_SERVICE_BINDING_PROTOCOL *This, IN EFI_HANDLE ChildHandle)
Definition: DnsDriver.c:1202
EFI_STATUS DnsCreateService(IN EFI_HANDLE Controller, IN EFI_HANDLE Image, IN UINT8 IpVersion, OUT DNS_SERVICE **Service)
Definition: DnsDriver.c:229
EFI_STATUS EFIAPI Dns6DriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer OPTIONAL)
Definition: DnsDriver.c:975
EFI_STATUS EFIAPI Dns6ServiceBindingCreateChild(IN EFI_SERVICE_BINDING_PROTOCOL *This, IN EFI_HANDLE *ChildHandle)
Definition: DnsDriver.c:1315
EFI_STATUS EFIAPI DnsUnload(IN EFI_HANDLE ImageHandle)
Definition: DnsDriver.c:340
EFI_STATUS EFIAPI Dns6DriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
Definition: DnsDriver.c:904
EFI_STATUS EFIAPI Dns6DriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
Definition: DnsDriver.c:829
EFI_STATUS EFIAPI Dns4DriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
Definition: DnsDriver.c:565
EFI_STATUS EFIAPI Dns4DriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
Definition: DnsDriver.c:640
EFI_STATUS EFIAPI Dns6ServiceBindingDestroyChild(IN EFI_SERVICE_BINDING_PROTOCOL *This, IN EFI_HANDLE ChildHandle)
Definition: DnsDriver.c:1446
EFI_STATUS DnsCreateInstance(IN DNS_SERVICE *Service, OUT DNS_INSTANCE **Instance)
Definition: DnsDriver.c:82
VOID DnsDestroyService(IN DNS_SERVICE *DnsSb)
Definition: DnsDriver.c:194
EFI_STATUS EFIAPI Dns4ServiceBindingCreateChild(IN EFI_SERVICE_BINDING_PROTOCOL *This, IN EFI_HANDLE *ChildHandle)
Definition: DnsDriver.c:1071
EFI_STATUS EFIAPI DnsConfigNullUdp(IN UDP_IO *UdpIo, IN VOID *Context)
Definition: DnsDriver.c:179
EFI_STATUS Dns4InstanceCancelToken(IN DNS_INSTANCE *Instance, IN EFI_DNS4_COMPLETION_TOKEN *Token)
Definition: DnsImpl.c:287
EFI_STATUS Dns6InstanceCancelToken(IN DNS_INSTANCE *Instance, IN EFI_DNS6_COMPLETION_TOKEN *Token)
Definition: DnsImpl.c:345
VOID EFIAPI DnsOnTimerUpdate(IN EFI_EVENT Event, IN VOID *Context)
Definition: DnsImpl.c:2219
VOID EFIAPI DnsOnTimerRetransmit(IN EFI_EVENT Event, IN VOID *Context)
Definition: DnsImpl.c:2098
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
LIST_ENTRY *EFIAPI NetListRemoveHead(IN OUT LIST_ENTRY *Head)
Definition: DxeNetLib.c:1090
VOID EFIAPI NetMapInit(IN OUT NET_MAP *Map)
Definition: DxeNetLib.c:1343
EFI_STATUS EFIAPI NetLibDefaultUnload(IN EFI_HANDLE ImageHandle)
Definition: DxeNetLib.c:1846
BOOLEAN EFIAPI NetIsInHandleBuffer(IN EFI_HANDLE Handle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer OPTIONAL)
Definition: DxeNetLib.c:1306
BOOLEAN EFIAPI NetMapIsEmpty(IN NET_MAP *Map)
Definition: DxeNetLib.c:1413
EFI_HANDLE EFIAPI NetLibGetNicHandle(IN EFI_HANDLE Controller, IN EFI_GUID *ProtocolGuid)
Definition: DxeNetLib.c:3019
EFI_STATUS EFIAPI NetDestroyLinkList(IN LIST_ENTRY *List, IN NET_DESTROY_LINK_LIST_CALLBACK CallBack, IN VOID *Context OPTIONAL, OUT UINTN *ListLength OPTIONAL)
Definition: DxeNetLib.c:1236
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gDnsComponentName2
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gDnsComponentName
Definition: ComponentName.c:99
EFI_STATUS EFIAPI UdpIoFreeIo(IN UDP_IO *UdpIo)
Definition: DxeUdpIoLib.c:809
UDP_IO *EFIAPI UdpIoCreateIo(IN EFI_HANDLE Controller, IN EFI_HANDLE ImageHandle, IN UDP_IO_CONFIG Configure, IN UINT8 UdpVersion, IN VOID *Context)
Definition: DxeUdpIoLib.c:602
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
UINTN EFI_TPL
Definition: UefiBaseType.h:41
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI EfiLibUninstallDriverBindingComponentName2(IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName OPTIONAL, IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL)
EFI_STATUS EFIAPI EfiLibInstallDriverBindingComponentName2(IN CONST EFI_HANDLE ImageHandle, IN CONST EFI_SYSTEM_TABLE *SystemTable, IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, IN EFI_HANDLE DriverBindingHandle, IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName OPTIONAL, IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL)
EFI_STATUS EFIAPI FreeUnicodeStringTable(IN EFI_UNICODE_STRING_TABLE *UnicodeStringTable)
Definition: UefiLib.c:1257
@ TimerPeriodic
Definition: UefiSpec.h:535
LIST_ENTRY Dns4CacheList
Ticking timer for DNS cache update.
Definition: DnsDriver.h:37
UINT8 IpVersion
Ticking timer for packet retransmission.
Definition: DnsDriver.h:61
CHAR16 * HostName
Definition: Dns4.h:102
EFI_IPv4_ADDRESS * IpAddress
Definition: Dns4.h:106
EFI_IPv6_ADDRESS * IpAddress
Definition: Dns6.h:97
CHAR16 * HostName
Definition: Dns6.h:93