xref: /aosp_15_r20/external/cronet/net/dns/BUILD.gn (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Copyright 2018 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//net/features.gni")
6import("//testing/libfuzzer/fuzzer_test.gni")
7import("//third_party/protobuf/proto_library.gni")
8
9enable_built_in_dns = use_blink
10
11source_set("dns") {
12  # Due to circular dependencies, should only be depended on through //net.
13  visibility = [
14    "//net",
15    "//net/http:transport_security_state_generated_files",
16  ]
17
18  # Internals only intended for use inside network stack (and tests).
19  friend = [
20    "//chrome/browser:test_support",
21    "//chrome/test/*",
22    "//components/certificate_transparency:unit_tests",
23    "//components/cronet/*",
24
25    # Needed for brokering system DNS resolution out of the network service.
26    "//content/browser/system_dns_resolution",
27    "//content/test/*",
28    "//net/*",
29    "//services/network/*",
30  ]
31
32  public = []
33  sources = [
34    "address_info.cc",
35    "address_info.h",
36    "address_sorter.h",
37    "context_host_resolver.cc",
38    "context_host_resolver.h",
39    "dns_alias_utility.cc",
40    "dns_alias_utility.h",
41    "dns_config.cc",
42    "dns_config_service.cc",
43    "dns_config_service.h",
44    "dns_hosts.cc",
45    "dns_hosts.h",
46    "dns_names_util.cc",
47    "dns_names_util.h",
48    "dns_query.cc",
49    "dns_query.h",
50    "dns_reloader.cc",
51    "dns_reloader.h",
52    "dns_response.cc",
53    "dns_response_result_extractor.cc",
54    "dns_response_result_extractor.h",
55    "dns_server_iterator.cc",
56    "dns_server_iterator.h",
57    "dns_session.cc",
58    "dns_session.h",
59    "dns_task_results_manager.cc",
60    "dns_task_results_manager.h",
61    "dns_transaction.cc",
62    "dns_udp_tracker.cc",
63    "dns_udp_tracker.h",
64    "dns_util.cc",
65    "dns_util.h",
66    "host_cache.cc",
67    "host_resolver.cc",
68    "host_resolver_cache.cc",
69    "host_resolver_cache.h",
70    "host_resolver_dns_task.cc",
71    "host_resolver_dns_task.h",
72    "host_resolver_internal_result.cc",
73    "host_resolver_internal_result.h",
74    "host_resolver_manager.cc",
75    "host_resolver_manager_job.cc",
76    "host_resolver_manager_job.h",
77    "host_resolver_manager_request_impl.cc",
78    "host_resolver_manager_request_impl.h",
79    "host_resolver_manager_service_endpoint_request_impl.cc",
80    "host_resolver_manager_service_endpoint_request_impl.h",
81    "host_resolver_mdns_listener_impl.cc",
82    "host_resolver_mdns_listener_impl.h",
83    "host_resolver_mdns_task.cc",
84    "host_resolver_mdns_task.h",
85    "host_resolver_nat64_task.cc",
86    "host_resolver_nat64_task.h",
87    "host_resolver_proc.cc",
88    "host_resolver_proc.h",
89    "host_resolver_system_task.cc",
90    "host_resolver_system_task.h",
91    "https_record_rdata.cc",
92    "httpssvc_metrics.cc",
93    "httpssvc_metrics.h",
94    "loopback_only.cc",
95    "loopback_only.h",
96    "mapped_host_resolver.cc",
97    "nsswitch_reader.cc",
98    "nsswitch_reader.h",
99    "opt_record_rdata.cc",
100    "record_parsed.cc",
101    "record_rdata.cc",
102    "resolve_context.cc",
103    "resolve_context.h",
104    "serial_worker.cc",
105    "serial_worker.h",
106    "system_dns_config_change_notifier.cc",
107    "system_dns_config_change_notifier.h",
108    "test_dns_config_service.cc",
109    "test_dns_config_service.h",
110  ]
111
112  if (is_win) {
113    sources += [
114      "address_sorter_win.cc",
115      "dns_config_service_win.cc",
116      "dns_config_service_win.h",
117    ]
118  }
119
120  if (is_mac) {
121    sources += [
122      "dns_config_watcher_mac.cc",
123      "dns_config_watcher_mac.h",
124      "notify_watcher_mac.cc",
125      "notify_watcher_mac.h",
126    ]
127  }
128
129  if (is_fuchsia) {
130    sources += [
131      "dns_config_service_fuchsia.cc",
132      "dns_config_service_fuchsia.h",
133    ]
134  }
135
136  if (is_android) {
137    sources += [
138      "dns_config_service_android.cc",
139      "dns_config_service_android.h",
140    ]
141  } else if (is_linux) {
142    sources += [
143      "dns_config_service_linux.cc",
144      "dns_config_service_linux.h",
145    ]
146  } else if (is_posix) {
147    sources += [
148      "dns_config_service_posix.cc",
149      "dns_config_service_posix.h",
150    ]
151  }
152
153  if (enable_built_in_dns) {
154    sources += [ "dns_client.cc" ]
155
156    if (is_posix || is_fuchsia) {
157      sources += [
158        "address_sorter_posix.cc",
159        "address_sorter_posix.h",
160      ]
161    }
162  }
163
164  if (enable_mdns) {
165    sources += [
166      "mdns_cache.cc",
167      "mdns_cache.h",
168      "mdns_client.cc",
169      "mdns_client_impl.cc",
170      "mdns_client_impl.h",
171    ]
172  }
173
174  deps = [ "//net:net_deps" ]
175
176  public_deps = [
177    ":dns_client",
178    ":host_resolver",
179    ":host_resolver_manager",
180    ":mdns_client",
181    "//net:net_public_deps",
182  ]
183
184  allow_circular_includes_from = [
185    ":dns_client",
186    ":host_resolver",
187    ":host_resolver_manager",
188    ":mdns_client",
189  ]
190}
191
192# The standard API of net/dns.
193#
194# Should typically only be used within the network service. Usage external to
195# the network service should instead use network service Mojo IPCs for host
196# resolution. See ResolveHost() in
197# /services/network/public/mojom/network_context.mojom and
198# /services/network/public/mojom/host_resolver.mojom.
199source_set("host_resolver") {
200  # Due to circular dependencies, should only be depended on through //net.
201  # Limit visibility to //net and other source_sets with the same access
202  # restriction.
203  visibility = [
204    ":dns",
205    ":dns_client",
206    ":host_resolver_manager",
207    ":mdns_client",
208    "//net",
209  ]
210
211  # Restricted access so we can keep track of all usage external to the
212  # network stack and network service.
213  friend = [
214    # chromecast/browser/url_request_context_factory.cc
215    # URLRequestContext creation for chromecast.
216    "//chromecast/browser",
217
218    # URLRequestContext and HttpNetworkSession::Context creation for iOS.
219    "//ios/components/io_thread",
220    "//ios/web/shell",
221    "//ios/web_view:*",
222
223    # Tests and test support.
224    "//chrome/browser:test_support",
225    "//chrome/test/*",
226    "//components/grpc_support/test:unit_tests",
227    "//content/shell:content_shell_lib",
228    "//content/test:*",
229
230    # Stand-alone tools.
231    "//google_apis/gcm:mcs_probe",
232
233    # Network stack/service.
234    "//components/certificate_transparency/*",
235    "//components/cronet/*",
236    "//net/*",
237    "//services/network/*",
238  ]
239
240  sources = [
241    "dns_config.h",
242    "host_cache.h",
243    "host_resolver.h",
244    "mapped_host_resolver.h",
245  ]
246  public = []
247
248  deps = [
249    "//net:net_deps",
250    "//net/dns/public",
251  ]
252  public_deps = [ "//net:net_public_deps" ]
253
254  allow_circular_includes_from = [ "//net/dns/public" ]
255}
256
257# Shared mostly-global handler of HostResolver requests.
258#
259# Typically should only be directly interacted with by NetworkService (or other
260# mostly-global creators of request contexts), standalone tools, and tests. Host
261# resolution should generally instead go through HostResolvers received from
262# URLRequestContext or network service Mojo IPCs.
263source_set("host_resolver_manager") {
264  # Due to circular dependencies, should only be depended on through //net.
265  # Limit visibility to //net and other source_sets with the same access
266  # restriction.
267  visibility = [
268    ":dns",
269    ":host_resolver",
270    "//net",
271  ]
272
273  # Restricted access so we can keep track of all usage external to the
274  # network stack and network service.
275  friend = [
276    # chromecast/browser/url_request_context_factory.cc
277    # URLRequestContext creation for chromecast.
278    "//chromecast/browser",
279
280    # Tests and test support.
281    "//components/cronet:cronet_common_unittests",
282
283    # Network stack/service.
284    "//net/*",
285    "//services/network/*",
286  ]
287
288  sources = [ "host_resolver_manager.h" ]
289  public = []
290
291  deps = [
292    ":host_resolver",
293    "//net:net_deps",
294    "//net/dns/public",
295  ]
296  public_deps = [ "//net:net_public_deps" ]
297}
298
299# DnsClient interfaces. Primarily intended as part of the implementation of the
300# standard HostResolver interface, but can be used as an alternative external
301# interface for advanced usage.
302source_set("dns_client") {
303  # Due to circular dependencies, should only be depended on through //net.
304  # Limit visibility to //net and other source_sets with the same access
305  # restriction.
306  visibility = [
307    ":dns",
308    ":mdns_client",
309    "//net",
310  ]
311
312  # Restricted access so we can keep track of all usage external to the
313  # network stack.
314  friend = [
315    # chrome/browser/local_discovery/service_discovery_client_impl.cc
316    # Result parsing utilities for parsing results read through MdnsClient.
317    # TODO(crbug.com/874662): Remove once migrated to network service.
318    "//chrome/browser",
319
320    # chrome/browser/ash/smb_client/discovery/mdns_host_locator.cc
321    # Result parsing for results read through MdnsClient.
322    # TODO(crbug.com/902531): Remove once migrated to network service.
323    "//chrome/browser/ash",
324
325    # Tests and test support
326    "//chrome/browser:test_support",
327    "//chrome/test/*",
328
329    # Network stack/service
330    "//components/certificate_transparency/*",
331    "//net/*",
332    "//services/network/*",
333  ]
334
335  sources = [
336    "dns_client.h",
337    "dns_response.h",
338    "dns_transaction.h",
339    "https_record_rdata.h",
340    "opt_record_rdata.h",
341    "record_parsed.h",
342    "record_rdata.h",
343  ]
344  public = []
345
346  deps = [
347    ":host_resolver",
348    "//net:net_deps",
349  ]
350  public_deps = [
351    "//net:net_public_deps",
352    "//net/dns/public",
353  ]
354}
355
356# MdnsClient interfaces.
357source_set("mdns_client") {
358  # Due to circular dependencies, should only be depended on through //net.
359  # Limit visibility to //net and other source_sets with the same access
360  # restriction.
361  visibility = [
362    ":dns",
363    "//net",
364  ]
365
366  # Restricted access so we can keep track of all usage external to the
367  # network stack.
368  friend = [
369    # chrome/browser/local_discovery/service_discovery_client_mdns.h
370    # chrome/browser/local_discovery/service_discovery_client_impl.h
371    # Makes MDNS queries using MDnsClient.
372    # TODO(crbug.com/874662): Remove once migrated to network service.
373    "//chrome/browser",
374
375    # chrome/tools/service_discovery_sniffer/service_discovery_sniffer.cc
376    # Creates MDnsClient instance and passes to ServiceDiscoveryClientImpl.
377    # TODO(crbug.com/874662): Remove once discovery client migrated.
378    "//chrome/tools/service_discovery_sniffer",
379
380    # chrome/browser/ash/smb_client/discovery/mdns_host_locator.h
381    # chrome/browser/ash/smb_client/discovery/mdns_host_locator.cc
382    # Makes MDNS queries using MDnsClient.
383    # TODO(crbug.com/902531): Remove once migrated to network service.
384    "//chrome/browser/ash",
385
386    # Tests and test support
387    "//chrome/browser:test_support",
388
389    # Network stack/service
390    "//net/*",
391    "//services/network/*",
392  ]
393
394  public = []
395  sources = []
396
397  if (enable_mdns) {
398    sources += [ "mdns_client.h" ]
399  }
400
401  deps = [
402    ":dns_client",
403    ":host_resolver",
404    "//net:net_deps",
405  ]
406  public_deps = [ "//net:net_public_deps" ]
407}
408
409source_set("tests") {
410  testonly = true
411  sources = [
412    "address_info_unittest.cc",
413    "context_host_resolver_unittest.cc",
414    "dns_alias_utility_unittest.cc",
415    "dns_config_service_unittest.cc",
416    "dns_hosts_unittest.cc",
417    "dns_names_util_unittest.cc",
418    "dns_query_unittest.cc",
419    "dns_response_result_extractor_unittest.cc",
420    "dns_response_unittest.cc",
421    "dns_task_results_manager_unittest.cc",
422    "dns_transaction_unittest.cc",
423    "dns_udp_tracker_unittest.cc",
424    "dns_util_unittest.cc",
425    "host_cache_unittest.cc",
426    "host_resolver_cache_unittest.cc",
427    "host_resolver_internal_result_unittest.cc",
428    "host_resolver_manager_ipv6_reachability_override_unittest.cc",
429    "host_resolver_manager_unittest.cc",
430    "host_resolver_service_endpoint_request_unittest.cc",
431    "https_record_rdata_unittest.cc",
432    "httpssvc_metrics_unittest.cc",
433    "loopback_only_unittest.cc",
434    "mapped_host_resolver_unittest.cc",
435    "nsswitch_reader_unittest.cc",
436    "opt_record_rdata_unittest.cc",
437    "record_parsed_unittest.cc",
438    "record_rdata_unittest.cc",
439    "resolve_context_unittest.cc",
440    "serial_worker_unittest.cc",
441    "system_dns_config_change_notifier_unittest.cc",
442  ]
443
444  if (is_win) {
445    sources += [ "dns_config_service_win_unittest.cc" ]
446  }
447
448  if (is_android) {
449    sources += [ "dns_config_service_android_unittest.cc" ]
450  } else if (is_linux) {
451    sources += [ "dns_config_service_linux_unittest.cc" ]
452  } else if (is_posix) {
453    sources += [ "dns_config_service_posix_unittest.cc" ]
454  }
455
456  if (enable_built_in_dns) {
457    sources += [
458      "address_sorter_unittest.cc",
459      "dns_client_unittest.cc",
460    ]
461    if (is_posix || is_fuchsia) {
462      sources += [ "address_sorter_posix_unittest.cc" ]
463    }
464  }
465
466  if (enable_mdns) {
467    sources += [
468      "mdns_cache_unittest.cc",
469      "mdns_client_unittest.cc",
470    ]
471  }
472
473  deps = [
474    "//base",
475    "//net",
476    "//net:test_support",
477    "//testing/gmock",
478    "//testing/gtest",
479  ]
480}
481
482source_set("test_support") {
483  visibility = [ "//net:test_support" ]
484  testonly = true
485  sources = [
486    "dns_test_util.cc",
487    "host_resolver_internal_result_test_util.cc",
488    "host_resolver_results_test_util.cc",
489    "mock_host_resolver.cc",
490  ]
491  public = [
492    "dns_test_util.h",
493    "host_resolver_internal_result_test_util.h",
494    "host_resolver_manager_unittest.h",
495    "host_resolver_results_test_util.h",
496    "mock_host_resolver.h",
497  ]
498
499  if (enable_mdns) {
500    sources += [
501      "mock_mdns_client.cc",
502      "mock_mdns_socket_factory.cc",
503    ]
504    public += [
505      "mock_mdns_client.h",
506      "mock_mdns_socket_factory.h",
507    ]
508  }
509
510  deps = [
511    "//base",
512    "//base/test:test_support",
513    "//net",
514    "//testing/gmock",
515    "//testing/gtest",
516  ]
517}
518
519if (use_fuzzing_engine) {
520  # fuzzer_test targets are no-op when |use_fuzzing_engine| is false. Fuzzer
521  # support targets should be disabled too.
522  source_set("fuzzer_test_support") {
523    testonly = true
524    sources = [
525      "fuzzed_host_resolver_util.cc",
526      "fuzzed_host_resolver_util.h",
527    ]
528    deps = [
529      "//base",
530      "//base/test:test_support",
531      "//net",
532    ]
533  }
534}
535
536proto_library("host_cache_fuzzer_proto") {
537  proto_in_dir = "//"
538  sources = [ "host_cache_fuzzer.proto" ]
539  deps = [ "//testing/libfuzzer/proto:json_proto" ]
540}
541
542fuzzer_test("net_dns_host_cache_fuzzer") {
543  sources = [ "host_cache_fuzzer.cc" ]
544  deps = [
545    ":host_cache_fuzzer_proto",
546    "//base",
547    "//net",
548    "//net:net_fuzzer_test_support",
549    "//testing/libfuzzer/proto:json_proto",
550    "//testing/libfuzzer/proto:json_proto_converter",
551    "//third_party/libprotobuf-mutator",
552  ]
553  dict = "//testing/libfuzzer/fuzzers/dicts/json.dict"
554}
555
556fuzzer_test("net_dns_hosts_parse_fuzzer") {
557  sources = [ "dns_hosts_parse_fuzzer.cc" ]
558  deps = [
559    "//base",
560    "//net",
561    "//net:net_fuzzer_test_support",
562  ]
563  dict = "//net/data/fuzzer_dictionaries/net_dns_hosts_parse_fuzzer.dict"
564}
565
566fuzzer_test("net_dns_host_resolver_cache_fuzzer") {
567  sources = [ "host_resolver_cache_fuzzer.cc" ]
568  deps = [
569    "//base",
570    "//net",
571    "//net:net_fuzzer_test_support",
572    "//testing/libfuzzer/proto:json_proto",
573    "//testing/libfuzzer/proto:json_proto_converter",
574    "//third_party/libprotobuf-mutator",
575  ]
576}
577
578fuzzer_test("net_dns_https_record_rdata_fuzzer") {
579  sources = [ "https_record_rdata_fuzzer.cc" ]
580  deps = [
581    "//base",
582    "//net",
583    "//net:net_fuzzer_test_support",
584  ]
585  dict = "//net/data/fuzzer_dictionaries/net_dns_record_fuzzer.dict"
586}
587
588fuzzer_test("net_dns_nsswitch_reader_fuzzer") {
589  sources = [ "nsswitch_reader_fuzzer.cc" ]
590  deps = [
591    "//base",
592    "//net",
593    "//net:net_fuzzer_test_support",
594  ]
595  dict = "//net/data/fuzzer_dictionaries/net_dns_nsswitch_reader_fuzzer.dict"
596}
597
598fuzzer_test("net_dns_record_fuzzer") {
599  sources = [ "dns_record_fuzzer.cc" ]
600  deps = [
601    "//base",
602    "//net",
603    "//net:net_fuzzer_test_support",
604  ]
605  dict = "//net/data/fuzzer_dictionaries/net_dns_record_fuzzer.dict"
606}
607
608fuzzer_test("net_dns_query_parse_fuzzer") {
609  sources = [ "dns_query_parse_fuzzer.cc" ]
610  deps = [
611    "//base",
612    "//net",
613    "//net:net_fuzzer_test_support",
614  ]
615  dict = "//net/data/fuzzer_dictionaries/net_dns_record_fuzzer.dict"
616}
617
618fuzzer_test("net_dns_response_fuzzer") {
619  sources = [ "dns_response_fuzzer.cc" ]
620  deps = [
621    "//base",
622    "//net",
623    "//net:net_fuzzer_test_support",
624  ]
625  dict = "//net/data/fuzzer_dictionaries/net_dns_record_fuzzer.dict"
626}
627
628fuzzer_test("net_host_resolver_manager_fuzzer") {
629  sources = [ "host_resolver_manager_fuzzer.cc" ]
630  deps = [
631    "//base",
632    "//net",
633    "//net:net_fuzzer_test_support",
634    "//net:test_support",
635  ]
636  dict = "//net/data/fuzzer_dictionaries/net_host_resolver_manager_fuzzer.dict"
637  libfuzzer_options = [ "max_len=4096" ]
638}
639
640if (is_win) {
641  fuzzer_test("net_dns_parse_domain_ascii_win_fuzzer") {
642    sources = [ "dns_parse_domain_ascii_win_fuzzer.cc" ]
643    deps = [
644      "//base",
645      "//net",
646      "//net:net_fuzzer_test_support",
647    ]
648    dict = "//net/data/fuzzer_dictionaries/net_dns_hosts_parse_fuzzer.dict"
649    seed_corpus = "//net/data/fuzzer_data/dns_parse_domain_ascii_win_fuzzer"
650  }
651}
652