grpc 1.43.1 → 1.44.0.pre2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (382) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +84 -64
  3. data/include/grpc/grpc_security.h +10 -0
  4. data/include/grpc/impl/codegen/compression_types.h +0 -2
  5. data/include/grpc/impl/codegen/grpc_types.h +6 -0
  6. data/src/core/ext/filters/client_channel/backend_metric.h +1 -1
  7. data/src/core/ext/filters/client_channel/client_channel.cc +62 -68
  8. data/src/core/ext/filters/client_channel/client_channel.h +8 -8
  9. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +1 -1
  10. data/src/core/ext/filters/client_channel/config_selector.h +4 -4
  11. data/src/core/ext/filters/client_channel/dynamic_filters.h +1 -1
  12. data/src/core/ext/filters/client_channel/health/health_check_client.cc +16 -14
  13. data/src/core/ext/filters/client_channel/health/health_check_client.h +3 -3
  14. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -1
  15. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +4 -3
  16. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +6 -5
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +3 -7
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +31 -32
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +0 -7
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +1 -1
  21. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +1 -1
  23. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +43 -29
  24. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +6 -2
  25. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +120 -68
  26. data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +60 -48
  27. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +62 -61
  28. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +16 -11
  29. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +11 -5
  30. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +19 -15
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +1 -1
  32. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +14 -12
  33. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +3 -2
  34. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +50 -105
  35. data/src/core/ext/filters/client_channel/lb_policy.cc +15 -14
  36. data/src/core/ext/filters/client_channel/lb_policy.h +19 -3
  37. data/src/core/ext/filters/client_channel/resolver/binder/binder_resolver.cc +3 -3
  38. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +207 -81
  39. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +22 -12
  40. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +19 -15
  41. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +23 -38
  42. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +118 -207
  43. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +25 -32
  44. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +1 -1
  45. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +82 -73
  46. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +10 -10
  47. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +2 -1
  48. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +2 -5
  49. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +5 -5
  50. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +157 -67
  51. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +1 -1
  52. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +2 -2
  53. data/src/core/ext/filters/client_channel/retry_filter.cc +37 -64
  54. data/src/core/ext/filters/client_channel/retry_service_config.cc +1 -1
  55. data/src/core/ext/filters/client_channel/retry_service_config.h +1 -1
  56. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +1 -1
  57. data/src/core/ext/filters/client_channel/subchannel.cc +12 -16
  58. data/src/core/ext/filters/client_channel/subchannel.h +2 -3
  59. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +37 -48
  60. data/src/core/ext/filters/fault_injection/service_config_parser.cc +6 -8
  61. data/src/core/ext/filters/fault_injection/service_config_parser.h +1 -1
  62. data/src/core/ext/filters/http/client/http_client_filter.cc +51 -122
  63. data/src/core/ext/filters/http/client_authority_filter.cc +8 -24
  64. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +42 -140
  65. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +5 -25
  66. data/src/core/ext/filters/http/server/http_server_filter.cc +50 -135
  67. data/src/core/ext/filters/message_size/message_size_filter.cc +1 -1
  68. data/src/core/ext/filters/message_size/message_size_filter.h +1 -1
  69. data/src/core/ext/filters/rbac/rbac_filter.cc +157 -0
  70. data/src/core/ext/filters/rbac/rbac_filter.h +74 -0
  71. data/src/core/ext/filters/rbac/rbac_service_config_parser.cc +605 -0
  72. data/src/core/ext/filters/rbac/rbac_service_config_parser.h +70 -0
  73. data/src/core/ext/filters/server_config_selector/server_config_selector.h +3 -2
  74. data/src/core/ext/filters/server_config_selector/server_config_selector_filter.cc +11 -6
  75. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +1 -1
  76. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +1 -1
  77. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +89 -29
  78. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +0 -1
  79. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +45 -186
  80. data/src/core/ext/transport/chttp2/transport/frame_data.cc +0 -1
  81. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +341 -279
  82. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +69 -159
  83. data/src/core/ext/transport/chttp2/transport/hpack_encoder_table.cc +1 -1
  84. data/src/core/ext/transport/chttp2/transport/hpack_encoder_table.h +2 -0
  85. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +19 -32
  86. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +0 -1
  87. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +94 -1
  88. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +2 -24
  89. data/src/core/ext/transport/chttp2/transport/internal.h +0 -33
  90. data/src/core/ext/transport/chttp2/transport/parsing.cc +0 -6
  91. data/src/core/ext/transport/chttp2/transport/writing.cc +47 -116
  92. data/src/core/ext/transport/inproc/inproc_plugin.cc +0 -4
  93. data/src/core/ext/transport/inproc/inproc_transport.cc +11 -63
  94. data/src/core/ext/transport/inproc/inproc_transport.h +0 -3
  95. data/src/core/ext/upb-generated/envoy/extensions/filters/http/rbac/v3/rbac.upb.c +61 -0
  96. data/src/core/ext/upb-generated/envoy/extensions/filters/http/rbac/v3/rbac.upb.h +146 -0
  97. data/src/core/ext/upbdefs-generated/envoy/config/rbac/v3/rbac.upbdefs.c +188 -0
  98. data/src/core/ext/upbdefs-generated/envoy/config/rbac/v3/rbac.upbdefs.h +70 -0
  99. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/rbac/v3/rbac.upbdefs.c +56 -0
  100. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/rbac/v3/rbac.upbdefs.h +40 -0
  101. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/checked.upbdefs.c +154 -0
  102. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/checked.upbdefs.h +95 -0
  103. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/eval.upbdefs.c +58 -0
  104. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/eval.upbdefs.h +55 -0
  105. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/explain.upbdefs.c +44 -0
  106. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/explain.upbdefs.h +40 -0
  107. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/syntax.upbdefs.c +153 -0
  108. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/syntax.upbdefs.h +100 -0
  109. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/value.upbdefs.c +75 -0
  110. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/value.upbdefs.h +55 -0
  111. data/src/core/ext/xds/upb_utils.h +65 -0
  112. data/src/core/ext/xds/xds_api.cc +81 -3458
  113. data/src/core/ext/xds/xds_api.h +56 -611
  114. data/src/core/ext/xds/xds_bootstrap.cc +189 -125
  115. data/src/core/ext/xds/xds_bootstrap.h +20 -15
  116. data/src/core/ext/xds/xds_certificate_provider.h +1 -0
  117. data/src/core/ext/xds/xds_channel_creds.cc +108 -0
  118. data/src/core/ext/xds/xds_channel_creds.h +50 -0
  119. data/src/core/ext/xds/xds_client.cc +584 -994
  120. data/src/core/ext/xds/xds_client.h +78 -135
  121. data/src/core/ext/xds/xds_cluster.cc +451 -0
  122. data/src/core/ext/xds/xds_cluster.h +111 -0
  123. data/src/core/ext/xds/xds_common_types.cc +388 -0
  124. data/src/core/ext/xds/xds_common_types.h +110 -0
  125. data/src/core/ext/xds/xds_endpoint.cc +364 -0
  126. data/src/core/ext/xds/xds_endpoint.h +135 -0
  127. data/src/core/ext/xds/xds_http_filters.cc +5 -0
  128. data/src/core/ext/xds/xds_http_rbac_filter.cc +563 -0
  129. data/src/core/ext/xds/xds_http_rbac_filter.h +54 -0
  130. data/src/core/ext/xds/xds_listener.cc +1036 -0
  131. data/src/core/ext/xds/xds_listener.h +220 -0
  132. data/src/core/ext/{transport/chttp2/transport/hpack_utils.h → xds/xds_resource_type.cc} +12 -9
  133. data/src/core/ext/xds/xds_resource_type.h +98 -0
  134. data/src/core/ext/xds/xds_resource_type_impl.h +87 -0
  135. data/src/core/ext/xds/xds_route_config.cc +993 -0
  136. data/src/core/ext/xds/xds_route_config.h +215 -0
  137. data/src/core/ext/xds/xds_routing.cc +11 -8
  138. data/src/core/ext/xds/xds_routing.h +8 -5
  139. data/src/core/ext/xds/xds_server_config_fetcher.cc +159 -99
  140. data/src/core/lib/address_utils/parse_address.cc +20 -0
  141. data/src/core/lib/address_utils/parse_address.h +5 -0
  142. data/src/core/lib/address_utils/sockaddr_utils.cc +33 -36
  143. data/src/core/lib/address_utils/sockaddr_utils.h +1 -16
  144. data/src/core/lib/backoff/backoff.cc +4 -30
  145. data/src/core/lib/backoff/backoff.h +3 -3
  146. data/src/core/lib/channel/channel_args.cc +0 -1
  147. data/src/core/lib/channel/channel_stack.cc +8 -0
  148. data/src/core/lib/channel/channel_stack.h +1 -1
  149. data/src/core/lib/channel/channel_stack_builder.cc +5 -9
  150. data/src/core/lib/channel/channel_stack_builder.h +4 -7
  151. data/src/core/lib/channel/channelz.cc +1 -0
  152. data/src/core/lib/compression/compression.cc +19 -111
  153. data/src/core/lib/compression/compression_internal.cc +142 -202
  154. data/src/core/lib/compression/compression_internal.h +64 -69
  155. data/src/core/lib/compression/message_compress.cc +11 -11
  156. data/src/core/lib/compression/message_compress.h +2 -2
  157. data/src/core/lib/gpr/useful.h +4 -0
  158. data/src/core/lib/gprpp/bitset.h +7 -0
  159. data/src/core/lib/gprpp/chunked_vector.h +45 -3
  160. data/src/core/lib/gprpp/status_helper.cc +20 -28
  161. data/src/core/lib/gprpp/status_helper.h +6 -19
  162. data/src/core/lib/gprpp/table.h +11 -0
  163. data/src/core/lib/http/httpcli.cc +37 -46
  164. data/src/core/lib/http/httpcli.h +3 -15
  165. data/src/core/lib/iomgr/call_combiner.cc +15 -4
  166. data/src/core/lib/iomgr/closure.h +29 -9
  167. data/src/core/lib/iomgr/combiner.cc +25 -3
  168. data/src/core/lib/iomgr/error.cc +2 -0
  169. data/src/core/lib/iomgr/error.h +3 -0
  170. data/src/core/lib/iomgr/event_engine/iomgr.cc +3 -2
  171. data/src/core/lib/iomgr/event_engine/resolved_address_internal.cc +6 -0
  172. data/src/core/lib/iomgr/event_engine/resolved_address_internal.h +2 -0
  173. data/src/core/lib/iomgr/event_engine/resolver.cc +66 -48
  174. data/src/core/lib/iomgr/event_engine/resolver.h +56 -0
  175. data/src/core/lib/iomgr/exec_ctx.cc +22 -9
  176. data/src/core/lib/iomgr/executor.cc +10 -1
  177. data/src/core/lib/iomgr/fork_posix.cc +3 -2
  178. data/src/core/lib/iomgr/iomgr_custom.cc +4 -1
  179. data/src/core/lib/iomgr/iomgr_posix.cc +2 -2
  180. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +2 -2
  181. data/src/core/lib/iomgr/iomgr_windows.cc +2 -2
  182. data/src/core/lib/iomgr/port.h +2 -2
  183. data/src/core/lib/iomgr/resolve_address.cc +5 -24
  184. data/src/core/lib/iomgr/resolve_address.h +47 -44
  185. data/src/core/lib/iomgr/resolve_address_custom.cc +131 -109
  186. data/src/core/lib/iomgr/resolve_address_custom.h +101 -19
  187. data/src/core/lib/iomgr/resolve_address_impl.h +59 -0
  188. data/src/core/lib/iomgr/resolve_address_posix.cc +82 -66
  189. data/src/core/lib/iomgr/resolve_address_posix.h +47 -0
  190. data/src/core/lib/iomgr/resolve_address_windows.cc +93 -74
  191. data/src/core/lib/iomgr/resolve_address_windows.h +47 -0
  192. data/src/core/lib/iomgr/resolved_address.h +39 -0
  193. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +1 -0
  194. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +1 -0
  195. data/src/core/lib/iomgr/unix_sockets_posix.cc +22 -34
  196. data/src/core/lib/iomgr/unix_sockets_posix.h +4 -7
  197. data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +6 -15
  198. data/src/core/lib/matchers/matchers.cc +1 -1
  199. data/src/core/lib/promise/activity.h +49 -20
  200. data/src/core/lib/promise/detail/status.h +5 -0
  201. data/src/core/{ext/filters/client_channel → lib/resolver}/resolver.cc +17 -25
  202. data/src/core/{ext/filters/client_channel → lib/resolver}/resolver.h +43 -44
  203. data/src/core/{ext/filters/client_channel → lib/resolver}/resolver_factory.h +10 -5
  204. data/src/core/{ext/filters/client_channel → lib/resolver}/resolver_registry.cc +3 -2
  205. data/src/core/{ext/filters/client_channel → lib/resolver}/resolver_registry.h +4 -5
  206. data/src/core/{ext/filters/client_channel → lib/resolver}/server_address.cc +1 -1
  207. data/src/core/{ext/filters/client_channel → lib/resolver}/server_address.h +4 -4
  208. data/src/core/lib/resource_quota/api.h +0 -1
  209. data/src/core/lib/{gprpp → resource_quota}/arena.cc +16 -13
  210. data/src/core/lib/{gprpp → resource_quota}/arena.h +24 -13
  211. data/src/core/lib/security/authorization/evaluate_args.cc +30 -15
  212. data/src/core/lib/security/authorization/evaluate_args.h +1 -0
  213. data/src/core/lib/security/authorization/grpc_authorization_engine.cc +60 -0
  214. data/src/core/lib/security/authorization/grpc_authorization_engine.h +62 -0
  215. data/src/core/lib/security/authorization/matchers.cc +227 -0
  216. data/src/core/lib/security/authorization/matchers.h +211 -0
  217. data/src/core/lib/security/authorization/rbac_policy.cc +442 -0
  218. data/src/core/lib/security/authorization/rbac_policy.h +170 -0
  219. data/src/core/lib/security/context/security_context.cc +4 -2
  220. data/src/core/lib/security/context/security_context.h +1 -1
  221. data/src/core/lib/security/credentials/composite/composite_credentials.cc +5 -5
  222. data/src/core/lib/security/credentials/composite/composite_credentials.h +4 -3
  223. data/src/core/lib/security/credentials/credentials.h +10 -20
  224. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +6 -9
  225. data/src/core/lib/security/credentials/external/external_account_credentials.cc +7 -9
  226. data/src/core/lib/security/credentials/external/external_account_credentials.h +2 -7
  227. data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +2 -3
  228. data/src/core/lib/security/credentials/fake/fake_credentials.cc +5 -4
  229. data/src/core/lib/security/credentials/fake/fake_credentials.h +8 -7
  230. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +2 -5
  231. data/src/core/lib/security/credentials/iam/iam_credentials.cc +16 -19
  232. data/src/core/lib/security/credentials/iam/iam_credentials.h +6 -5
  233. data/src/core/lib/security/credentials/jwt/json_token.cc +4 -6
  234. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +16 -28
  235. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +8 -8
  236. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +6 -13
  237. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +44 -57
  238. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +13 -15
  239. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -7
  240. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +5 -4
  241. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +1 -10
  242. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +6 -0
  243. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +7 -0
  244. data/src/core/lib/security/credentials/xds/xds_credentials.h +1 -1
  245. data/src/core/lib/security/security_connector/security_connector.cc +0 -4
  246. data/src/core/lib/security/security_connector/security_connector.h +5 -1
  247. data/src/core/lib/security/security_connector/ssl_utils.cc +14 -24
  248. data/src/core/lib/security/security_connector/ssl_utils.h +5 -14
  249. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +2 -3
  250. data/src/core/lib/security/transport/auth_filters.h +7 -0
  251. data/src/core/lib/security/transport/client_auth_filter.cc +53 -33
  252. data/src/core/lib/security/transport/server_auth_filter.cc +40 -35
  253. data/src/core/{ext → lib}/service_config/service_config.cc +2 -2
  254. data/src/core/{ext → lib}/service_config/service_config.h +4 -4
  255. data/src/core/{ext → lib}/service_config/service_config_call_data.h +5 -5
  256. data/src/core/{ext → lib}/service_config/service_config_parser.cc +1 -1
  257. data/src/core/{ext → lib}/service_config/service_config_parser.h +3 -3
  258. data/src/core/lib/slice/slice.cc +3 -1
  259. data/src/core/lib/slice/slice.h +43 -13
  260. data/src/core/lib/slice/slice_intern.cc +3 -101
  261. data/src/core/lib/slice/slice_internal.h +1 -2
  262. data/src/core/lib/slice/slice_refcount.h +4 -13
  263. data/src/core/lib/slice/slice_refcount_base.h +0 -16
  264. data/src/core/lib/surface/call.cc +140 -382
  265. data/src/core/lib/surface/call.h +4 -4
  266. data/src/core/lib/surface/channel.cc +42 -44
  267. data/src/core/lib/surface/channel.h +4 -4
  268. data/src/core/lib/surface/init.cc +0 -2
  269. data/src/core/lib/surface/lame_client.cc +0 -1
  270. data/src/core/lib/surface/server.cc +12 -29
  271. data/src/core/lib/surface/server.h +2 -2
  272. data/src/core/lib/surface/version.cc +2 -2
  273. data/src/core/lib/transport/error_utils.h +14 -0
  274. data/src/core/lib/transport/metadata_batch.h +799 -717
  275. data/src/core/lib/transport/parsed_metadata.cc +2 -0
  276. data/src/core/lib/transport/parsed_metadata.h +95 -92
  277. data/src/core/lib/transport/timeout_encoding.cc +200 -66
  278. data/src/core/lib/transport/timeout_encoding.h +40 -10
  279. data/src/core/lib/transport/transport.h +1 -1
  280. data/src/core/lib/transport/transport_op_string.cc +6 -39
  281. data/src/core/lib/uri/uri_parser.cc +223 -53
  282. data/src/core/lib/uri/uri_parser.h +36 -23
  283. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -3
  284. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +1 -1
  285. data/src/core/tsi/ssl/session_cache/ssl_session.h +2 -4
  286. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +3 -5
  287. data/src/core/tsi/ssl_transport_security.cc +53 -13
  288. data/src/core/tsi/ssl_transport_security.h +18 -6
  289. data/src/ruby/ext/grpc/extconf.rb +10 -3
  290. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  291. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +3 -0
  292. data/src/ruby/lib/grpc/version.rb +1 -1
  293. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +2 -1
  294. data/third_party/abseil-cpp/absl/base/internal/fast_type_id.h +48 -0
  295. data/third_party/abseil-cpp/absl/random/bernoulli_distribution.h +200 -0
  296. data/third_party/abseil-cpp/absl/random/beta_distribution.h +427 -0
  297. data/third_party/abseil-cpp/absl/random/discrete_distribution.cc +98 -0
  298. data/third_party/abseil-cpp/absl/random/discrete_distribution.h +247 -0
  299. data/third_party/abseil-cpp/absl/random/distributions.h +452 -0
  300. data/third_party/abseil-cpp/absl/random/exponential_distribution.h +165 -0
  301. data/third_party/abseil-cpp/absl/random/gaussian_distribution.cc +104 -0
  302. data/third_party/abseil-cpp/absl/random/gaussian_distribution.h +275 -0
  303. data/third_party/abseil-cpp/absl/random/internal/distribution_caller.h +92 -0
  304. data/third_party/abseil-cpp/absl/random/internal/fast_uniform_bits.h +268 -0
  305. data/third_party/abseil-cpp/absl/random/internal/fastmath.h +57 -0
  306. data/third_party/abseil-cpp/absl/random/internal/generate_real.h +144 -0
  307. data/third_party/abseil-cpp/absl/random/internal/iostream_state_saver.h +245 -0
  308. data/third_party/abseil-cpp/absl/random/internal/nonsecure_base.h +150 -0
  309. data/third_party/abseil-cpp/absl/random/internal/pcg_engine.h +308 -0
  310. data/third_party/abseil-cpp/absl/random/internal/platform.h +171 -0
  311. data/third_party/abseil-cpp/absl/random/internal/pool_urbg.cc +253 -0
  312. data/third_party/abseil-cpp/absl/random/internal/pool_urbg.h +131 -0
  313. data/third_party/abseil-cpp/absl/random/internal/randen.cc +91 -0
  314. data/third_party/abseil-cpp/absl/random/internal/randen.h +102 -0
  315. data/third_party/abseil-cpp/absl/random/internal/randen_detect.cc +221 -0
  316. data/third_party/abseil-cpp/absl/random/internal/randen_detect.h +33 -0
  317. data/third_party/abseil-cpp/absl/random/internal/randen_engine.h +239 -0
  318. data/third_party/abseil-cpp/absl/random/internal/randen_hwaes.cc +526 -0
  319. data/third_party/abseil-cpp/absl/random/internal/randen_hwaes.h +50 -0
  320. data/third_party/abseil-cpp/absl/random/internal/randen_round_keys.cc +462 -0
  321. data/third_party/abseil-cpp/absl/random/internal/randen_slow.cc +471 -0
  322. data/third_party/abseil-cpp/absl/random/internal/randen_slow.h +40 -0
  323. data/third_party/abseil-cpp/absl/random/internal/randen_traits.h +88 -0
  324. data/third_party/abseil-cpp/absl/random/internal/salted_seed_seq.h +167 -0
  325. data/third_party/abseil-cpp/absl/random/internal/seed_material.cc +267 -0
  326. data/third_party/abseil-cpp/absl/random/internal/seed_material.h +104 -0
  327. data/third_party/abseil-cpp/absl/random/internal/traits.h +101 -0
  328. data/third_party/abseil-cpp/absl/random/internal/uniform_helper.h +244 -0
  329. data/third_party/abseil-cpp/absl/random/internal/wide_multiply.h +111 -0
  330. data/third_party/abseil-cpp/absl/random/log_uniform_int_distribution.h +257 -0
  331. data/third_party/abseil-cpp/absl/random/poisson_distribution.h +258 -0
  332. data/third_party/abseil-cpp/absl/random/random.h +189 -0
  333. data/third_party/abseil-cpp/absl/random/seed_gen_exception.cc +46 -0
  334. data/third_party/abseil-cpp/absl/random/seed_gen_exception.h +55 -0
  335. data/third_party/abseil-cpp/absl/random/seed_sequences.cc +29 -0
  336. data/third_party/abseil-cpp/absl/random/seed_sequences.h +110 -0
  337. data/third_party/abseil-cpp/absl/random/uniform_int_distribution.h +275 -0
  338. data/third_party/abseil-cpp/absl/random/uniform_real_distribution.h +202 -0
  339. data/third_party/abseil-cpp/absl/random/zipf_distribution.h +271 -0
  340. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_enc.c +1 -0
  341. data/third_party/boringssl-with-bazel/src/crypto/base64/base64.c +13 -0
  342. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +21 -0
  343. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/cipher.c +12 -0
  344. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/ecdsa.c +1 -2
  345. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +2 -2
  346. data/third_party/boringssl-with-bazel/src/crypto/mem.c +1 -1
  347. data/third_party/boringssl-with-bazel/src/crypto/pkcs7/pkcs7.c +29 -0
  348. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/internal.h +0 -1
  349. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8.c +1 -1
  350. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8_x509.c +1 -1
  351. data/third_party/boringssl-with-bazel/src/include/openssl/base64.h +8 -0
  352. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +13 -1
  353. data/third_party/boringssl-with-bazel/src/include/openssl/dsa.h +10 -0
  354. data/third_party/boringssl-with-bazel/src/include/openssl/hpke.h +1 -1
  355. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs7.h +9 -4
  356. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs8.h +6 -1
  357. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +23 -2
  358. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +4 -0
  359. data/third_party/xxhash/xxhash.h +607 -352
  360. metadata +149 -77
  361. data/src/core/ext/transport/chttp2/transport/hpack_encoder_index.h +0 -107
  362. data/src/core/ext/transport/chttp2/transport/hpack_utils.cc +0 -46
  363. data/src/core/ext/transport/chttp2/transport/popularity_count.h +0 -60
  364. data/src/core/lib/compression/algorithm_metadata.h +0 -62
  365. data/src/core/lib/compression/compression_args.cc +0 -140
  366. data/src/core/lib/compression/compression_args.h +0 -58
  367. data/src/core/lib/compression/stream_compression.cc +0 -81
  368. data/src/core/lib/compression/stream_compression.h +0 -117
  369. data/src/core/lib/compression/stream_compression_gzip.cc +0 -231
  370. data/src/core/lib/compression/stream_compression_gzip.h +0 -28
  371. data/src/core/lib/compression/stream_compression_identity.cc +0 -91
  372. data/src/core/lib/compression/stream_compression_identity.h +0 -29
  373. data/src/core/lib/security/credentials/credentials_metadata.cc +0 -61
  374. data/src/core/lib/slice/static_slice.cc +0 -377
  375. data/src/core/lib/slice/static_slice.h +0 -300
  376. data/src/core/lib/transport/metadata.cc +0 -714
  377. data/src/core/lib/transport/metadata.h +0 -449
  378. data/src/core/lib/transport/metadata_batch.cc +0 -99
  379. data/src/core/lib/transport/static_metadata.cc +0 -1032
  380. data/src/core/lib/transport/static_metadata.h +0 -322
  381. data/src/core/lib/transport/status_metadata.cc +0 -63
  382. data/src/core/lib/transport/status_metadata.h +0 -48
@@ -18,64 +18,21 @@
18
18
 
19
19
  #include "src/core/ext/xds/xds_api.h"
20
20
 
21
- #include <algorithm>
22
- #include <cctype>
23
- #include <cstdint>
24
- #include <cstdlib>
21
+ #include <set>
25
22
  #include <string>
23
+ #include <vector>
26
24
 
27
25
  #include "absl/strings/str_cat.h"
28
- #include "absl/strings/str_format.h"
29
- #include "absl/strings/str_join.h"
30
- #include "absl/strings/str_split.h"
31
26
  #include "envoy/admin/v3/config_dump.upb.h"
32
- #include "envoy/config/cluster/v3/circuit_breaker.upb.h"
33
- #include "envoy/config/cluster/v3/cluster.upb.h"
34
- #include "envoy/config/cluster/v3/cluster.upbdefs.h"
35
- #include "envoy/config/core/v3/address.upb.h"
36
27
  #include "envoy/config/core/v3/base.upb.h"
37
- #include "envoy/config/core/v3/base.upbdefs.h"
38
- #include "envoy/config/core/v3/config_source.upb.h"
39
- #include "envoy/config/core/v3/health_check.upb.h"
40
- #include "envoy/config/core/v3/protocol.upb.h"
41
- #include "envoy/config/endpoint/v3/endpoint.upb.h"
42
- #include "envoy/config/endpoint/v3/endpoint.upbdefs.h"
43
- #include "envoy/config/endpoint/v3/endpoint_components.upb.h"
44
28
  #include "envoy/config/endpoint/v3/load_report.upb.h"
45
- #include "envoy/config/listener/v3/api_listener.upb.h"
46
- #include "envoy/config/listener/v3/listener.upb.h"
47
- #include "envoy/config/listener/v3/listener.upbdefs.h"
48
- #include "envoy/config/listener/v3/listener_components.upb.h"
49
- #include "envoy/config/route/v3/route.upb.h"
50
- #include "envoy/config/route/v3/route.upbdefs.h"
51
- #include "envoy/config/route/v3/route_components.upb.h"
52
- #include "envoy/config/route/v3/route_components.upbdefs.h"
53
- #include "envoy/extensions/clusters/aggregate/v3/cluster.upb.h"
54
- #include "envoy/extensions/clusters/aggregate/v3/cluster.upbdefs.h"
55
- #include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h"
56
- #include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h"
57
- #include "envoy/extensions/transport_sockets/tls/v3/common.upb.h"
58
- #include "envoy/extensions/transport_sockets/tls/v3/tls.upb.h"
59
- #include "envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.h"
60
- #include "envoy/service/cluster/v3/cds.upb.h"
61
- #include "envoy/service/cluster/v3/cds.upbdefs.h"
62
29
  #include "envoy/service/discovery/v3/discovery.upb.h"
63
30
  #include "envoy/service/discovery/v3/discovery.upbdefs.h"
64
- #include "envoy/service/endpoint/v3/eds.upb.h"
65
- #include "envoy/service/endpoint/v3/eds.upbdefs.h"
66
- #include "envoy/service/listener/v3/lds.upb.h"
67
31
  #include "envoy/service/load_stats/v3/lrs.upb.h"
68
32
  #include "envoy/service/load_stats/v3/lrs.upbdefs.h"
69
- #include "envoy/service/route/v3/rds.upb.h"
70
- #include "envoy/service/route/v3/rds.upbdefs.h"
71
33
  #include "envoy/service/status/v3/csds.upb.h"
72
34
  #include "envoy/service/status/v3/csds.upbdefs.h"
73
- #include "envoy/type/matcher/v3/regex.upb.h"
74
- #include "envoy/type/matcher/v3/string.upb.h"
75
- #include "envoy/type/v3/percent.upb.h"
76
- #include "envoy/type/v3/range.upb.h"
77
35
  #include "google/protobuf/any.upb.h"
78
- #include "google/protobuf/duration.upb.h"
79
36
  #include "google/protobuf/struct.upb.h"
80
37
  #include "google/protobuf/timestamp.upb.h"
81
38
  #include "google/protobuf/wrappers.upb.h"
@@ -83,13 +40,16 @@
83
40
  #include "upb/text_encode.h"
84
41
  #include "upb/upb.h"
85
42
  #include "upb/upb.hpp"
86
- #include "xds/type/v3/typed_struct.upb.h"
87
43
 
88
44
  #include <grpc/impl/codegen/log.h>
89
45
  #include <grpc/support/alloc.h>
90
46
  #include <grpc/support/string_util.h>
91
47
 
48
+ #include "src/core/ext/xds/upb_utils.h"
49
+ #include "src/core/ext/xds/xds_common_types.h"
50
+ #include "src/core/ext/xds/xds_resource_type.h"
92
51
  #include "src/core/ext/xds/xds_routing.h"
52
+ #include "src/core/lib/address_utils/parse_address.h"
93
53
  #include "src/core/lib/address_utils/sockaddr_utils.h"
94
54
  #include "src/core/lib/gpr/env.h"
95
55
  #include "src/core/lib/gpr/string.h"
@@ -102,764 +62,6 @@
102
62
 
103
63
  namespace grpc_core {
104
64
 
105
- // TODO(donnadionne): Check to see if cluster types aggregate_cluster and
106
- // logical_dns are enabled, this will be
107
- // removed once the cluster types are fully integration-tested and enabled by
108
- // default.
109
- bool XdsAggregateAndLogicalDnsClusterEnabled() {
110
- char* value = gpr_getenv(
111
- "GRPC_XDS_EXPERIMENTAL_ENABLE_AGGREGATE_AND_LOGICAL_DNS_CLUSTER");
112
- bool parsed_value;
113
- bool parse_succeeded = gpr_parse_bool_value(value, &parsed_value);
114
- gpr_free(value);
115
- return parse_succeeded && parsed_value;
116
- }
117
-
118
- // TODO(yashykt): Remove once RBAC is no longer experimental
119
- bool XdsRbacEnabled() {
120
- char* value = gpr_getenv("GRPC_XDS_EXPERIMENTAL_RBAC");
121
- bool parsed_value;
122
- bool parse_succeeded = gpr_parse_bool_value(value, &parsed_value);
123
- gpr_free(value);
124
- return parse_succeeded && parsed_value;
125
- }
126
-
127
- //
128
- // XdsApi::RetryPolicy
129
- //
130
-
131
- std::string XdsApi::RetryPolicy::RetryBackOff::ToString() const {
132
- std::vector<std::string> contents;
133
- contents.push_back(
134
- absl::StrCat("RetryBackOff Base: ", base_interval.ToString()));
135
- contents.push_back(
136
- absl::StrCat("RetryBackOff max: ", max_interval.ToString()));
137
- return absl::StrJoin(contents, ",");
138
- }
139
-
140
- std::string XdsApi::RetryPolicy::ToString() const {
141
- std::vector<std::string> contents;
142
- contents.push_back(absl::StrFormat("num_retries=%d", num_retries));
143
- contents.push_back(retry_back_off.ToString());
144
- return absl::StrCat("{", absl::StrJoin(contents, ","), "}");
145
- }
146
-
147
- //
148
- // XdsApi::Route::Matchers
149
- //
150
-
151
- std::string XdsApi::Route::Matchers::ToString() const {
152
- std::vector<std::string> contents;
153
- contents.push_back(
154
- absl::StrFormat("PathMatcher{%s}", path_matcher.ToString()));
155
- for (const HeaderMatcher& header_matcher : header_matchers) {
156
- contents.push_back(header_matcher.ToString());
157
- }
158
- if (fraction_per_million.has_value()) {
159
- contents.push_back(absl::StrFormat("Fraction Per Million %d",
160
- fraction_per_million.value()));
161
- }
162
- return absl::StrJoin(contents, "\n");
163
- }
164
-
165
- //
166
- // XdsApi::Route::RouteAction::HashPolicy
167
- //
168
-
169
- XdsApi::Route::RouteAction::HashPolicy::HashPolicy(const HashPolicy& other)
170
- : type(other.type),
171
- header_name(other.header_name),
172
- regex_substitution(other.regex_substitution) {
173
- if (other.regex != nullptr) {
174
- regex =
175
- absl::make_unique<RE2>(other.regex->pattern(), other.regex->options());
176
- }
177
- }
178
-
179
- XdsApi::Route::RouteAction::HashPolicy&
180
- XdsApi::Route::RouteAction::HashPolicy::operator=(const HashPolicy& other) {
181
- type = other.type;
182
- header_name = other.header_name;
183
- if (other.regex != nullptr) {
184
- regex =
185
- absl::make_unique<RE2>(other.regex->pattern(), other.regex->options());
186
- }
187
- regex_substitution = other.regex_substitution;
188
- return *this;
189
- }
190
-
191
- XdsApi::Route::RouteAction::HashPolicy::HashPolicy(HashPolicy&& other) noexcept
192
- : type(other.type),
193
- header_name(std::move(other.header_name)),
194
- regex(std::move(other.regex)),
195
- regex_substitution(std::move(other.regex_substitution)) {}
196
-
197
- XdsApi::Route::RouteAction::HashPolicy&
198
- XdsApi::Route::RouteAction::HashPolicy::operator=(HashPolicy&& other) noexcept {
199
- type = other.type;
200
- header_name = std::move(other.header_name);
201
- regex = std::move(other.regex);
202
- regex_substitution = std::move(other.regex_substitution);
203
- return *this;
204
- }
205
-
206
- bool XdsApi::Route::RouteAction::HashPolicy::HashPolicy::operator==(
207
- const HashPolicy& other) const {
208
- if (type != other.type) return false;
209
- if (type == Type::HEADER) {
210
- if (regex == nullptr) {
211
- if (other.regex != nullptr) return false;
212
- } else {
213
- if (other.regex == nullptr) return false;
214
- return header_name == other.header_name &&
215
- regex->pattern() == other.regex->pattern() &&
216
- regex_substitution == other.regex_substitution;
217
- }
218
- }
219
- return true;
220
- }
221
-
222
- std::string XdsApi::Route::RouteAction::HashPolicy::ToString() const {
223
- std::vector<std::string> contents;
224
- switch (type) {
225
- case Type::HEADER:
226
- contents.push_back("type=HEADER");
227
- break;
228
- case Type::CHANNEL_ID:
229
- contents.push_back("type=CHANNEL_ID");
230
- break;
231
- }
232
- contents.push_back(
233
- absl::StrFormat("terminal=%s", terminal ? "true" : "false"));
234
- if (type == Type::HEADER) {
235
- contents.push_back(absl::StrFormat(
236
- "Header %s:/%s/%s", header_name,
237
- (regex == nullptr) ? "" : regex->pattern(), regex_substitution));
238
- }
239
- return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
240
- }
241
-
242
- //
243
- // XdsApi::Route::RouteAction::ClusterWeight
244
- //
245
-
246
- std::string XdsApi::Route::RouteAction::ClusterWeight::ToString() const {
247
- std::vector<std::string> contents;
248
- contents.push_back(absl::StrCat("cluster=", name));
249
- contents.push_back(absl::StrCat("weight=", weight));
250
- if (!typed_per_filter_config.empty()) {
251
- std::vector<std::string> parts;
252
- for (const auto& p : typed_per_filter_config) {
253
- const std::string& key = p.first;
254
- const auto& config = p.second;
255
- parts.push_back(absl::StrCat(key, "=", config.ToString()));
256
- }
257
- contents.push_back(absl::StrCat("typed_per_filter_config={",
258
- absl::StrJoin(parts, ", "), "}"));
259
- }
260
- return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
261
- }
262
-
263
- //
264
- // XdsApi::Route::RouteAction
265
- //
266
-
267
- std::string XdsApi::Route::RouteAction::ToString() const {
268
- std::vector<std::string> contents;
269
- for (const HashPolicy& hash_policy : hash_policies) {
270
- contents.push_back(absl::StrCat("hash_policy=", hash_policy.ToString()));
271
- }
272
- if (retry_policy.has_value()) {
273
- contents.push_back(absl::StrCat("retry_policy=", retry_policy->ToString()));
274
- }
275
- if (!cluster_name.empty()) {
276
- contents.push_back(absl::StrFormat("Cluster name: %s", cluster_name));
277
- }
278
- for (const ClusterWeight& cluster_weight : weighted_clusters) {
279
- contents.push_back(cluster_weight.ToString());
280
- }
281
- if (max_stream_duration.has_value()) {
282
- contents.push_back(max_stream_duration->ToString());
283
- }
284
- return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
285
- }
286
-
287
- //
288
- // XdsApi::Route
289
- //
290
-
291
- std::string XdsApi::Route::ToString() const {
292
- std::vector<std::string> contents;
293
- contents.push_back(matchers.ToString());
294
- auto* route_action = absl::get_if<XdsApi::Route::RouteAction>(&action);
295
- if (route_action != nullptr) {
296
- contents.push_back(absl::StrCat("route=", route_action->ToString()));
297
- } else if (absl::holds_alternative<XdsApi::Route::NonForwardingAction>(
298
- action)) {
299
- contents.push_back("non_forwarding_action={}");
300
- } else {
301
- contents.push_back("unknown_action={}");
302
- }
303
- if (!typed_per_filter_config.empty()) {
304
- contents.push_back("typed_per_filter_config={");
305
- for (const auto& p : typed_per_filter_config) {
306
- const std::string& name = p.first;
307
- const auto& config = p.second;
308
- contents.push_back(absl::StrCat(" ", name, "=", config.ToString()));
309
- }
310
- contents.push_back("}");
311
- }
312
- return absl::StrJoin(contents, "\n");
313
- }
314
-
315
- //
316
- // XdsApi::RdsUpdate
317
- //
318
-
319
- std::string XdsApi::RdsUpdate::ToString() const {
320
- std::vector<std::string> vhosts;
321
- for (const VirtualHost& vhost : virtual_hosts) {
322
- vhosts.push_back(
323
- absl::StrCat("vhost={\n"
324
- " domains=[",
325
- absl::StrJoin(vhost.domains, ", "),
326
- "]\n"
327
- " routes=[\n"));
328
- for (const XdsApi::Route& route : vhost.routes) {
329
- vhosts.push_back(" {\n");
330
- vhosts.push_back(route.ToString());
331
- vhosts.push_back("\n }\n");
332
- }
333
- vhosts.push_back(" ]\n");
334
- vhosts.push_back(" typed_per_filter_config={\n");
335
- for (const auto& p : vhost.typed_per_filter_config) {
336
- const std::string& name = p.first;
337
- const auto& config = p.second;
338
- vhosts.push_back(
339
- absl::StrCat(" ", name, "=", config.ToString(), "\n"));
340
- }
341
- vhosts.push_back(" }\n");
342
- vhosts.push_back("]\n");
343
- }
344
- return absl::StrJoin(vhosts, "");
345
- }
346
-
347
- //
348
- // XdsApi::CommonTlsContext::CertificateValidationContext
349
- //
350
-
351
- std::string XdsApi::CommonTlsContext::CertificateValidationContext::ToString()
352
- const {
353
- std::vector<std::string> contents;
354
- for (const auto& match : match_subject_alt_names) {
355
- contents.push_back(match.ToString());
356
- }
357
- return absl::StrFormat("{match_subject_alt_names=[%s]}",
358
- absl::StrJoin(contents, ", "));
359
- }
360
-
361
- bool XdsApi::CommonTlsContext::CertificateValidationContext::Empty() const {
362
- return match_subject_alt_names.empty();
363
- }
364
-
365
- //
366
- // XdsApi::CommonTlsContext::CertificateProviderPluginInstance
367
- //
368
-
369
- std::string
370
- XdsApi::CommonTlsContext::CertificateProviderPluginInstance::ToString() const {
371
- absl::InlinedVector<std::string, 2> contents;
372
- if (!instance_name.empty()) {
373
- contents.push_back(absl::StrFormat("instance_name=%s", instance_name));
374
- }
375
- if (!certificate_name.empty()) {
376
- contents.push_back(
377
- absl::StrFormat("certificate_name=%s", certificate_name));
378
- }
379
- return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
380
- }
381
-
382
- bool XdsApi::CommonTlsContext::CertificateProviderPluginInstance::Empty()
383
- const {
384
- return instance_name.empty() && certificate_name.empty();
385
- }
386
-
387
- //
388
- // XdsApi::CommonTlsContext
389
- //
390
-
391
- std::string XdsApi::CommonTlsContext::ToString() const {
392
- absl::InlinedVector<std::string, 2> contents;
393
- if (!tls_certificate_provider_instance.Empty()) {
394
- contents.push_back(
395
- absl::StrFormat("tls_certificate_provider_instance=%s",
396
- tls_certificate_provider_instance.ToString()));
397
- }
398
- if (!certificate_validation_context.Empty()) {
399
- contents.push_back(
400
- absl::StrFormat("certificate_validation_context=%s",
401
- certificate_validation_context.ToString()));
402
- }
403
- return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
404
- }
405
-
406
- bool XdsApi::CommonTlsContext::Empty() const {
407
- return tls_certificate_provider_instance.Empty() &&
408
- certificate_validation_context.Empty();
409
- }
410
-
411
- //
412
- // XdsApi::DownstreamTlsContext
413
- //
414
-
415
- std::string XdsApi::DownstreamTlsContext::ToString() const {
416
- return absl::StrFormat("common_tls_context=%s, require_client_certificate=%s",
417
- common_tls_context.ToString(),
418
- require_client_certificate ? "true" : "false");
419
- }
420
-
421
- bool XdsApi::DownstreamTlsContext::Empty() const {
422
- return common_tls_context.Empty();
423
- }
424
-
425
- //
426
- // XdsApi::LdsUpdate::HttpConnectionManager
427
- //
428
-
429
- std::string XdsApi::LdsUpdate::HttpConnectionManager::ToString() const {
430
- absl::InlinedVector<std::string, 4> contents;
431
- contents.push_back(absl::StrFormat(
432
- "route_config_name=%s",
433
- !route_config_name.empty() ? route_config_name.c_str() : "<inlined>"));
434
- contents.push_back(absl::StrFormat("http_max_stream_duration=%s",
435
- http_max_stream_duration.ToString()));
436
- if (rds_update.has_value()) {
437
- contents.push_back(
438
- absl::StrFormat("rds_update=%s", rds_update->ToString()));
439
- }
440
- if (!http_filters.empty()) {
441
- std::vector<std::string> filter_strings;
442
- for (const auto& http_filter : http_filters) {
443
- filter_strings.push_back(http_filter.ToString());
444
- }
445
- contents.push_back(absl::StrCat("http_filters=[",
446
- absl::StrJoin(filter_strings, ", "), "]"));
447
- }
448
- return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
449
- }
450
-
451
- //
452
- // XdsApi::LdsUpdate::HttpFilter
453
- //
454
-
455
- std::string XdsApi::LdsUpdate::HttpConnectionManager::HttpFilter::ToString()
456
- const {
457
- return absl::StrCat("{name=", name, ", config=", config.ToString(), "}");
458
- }
459
-
460
- //
461
- // XdsApi::LdsUpdate::FilterChainData
462
- //
463
-
464
- std::string XdsApi::LdsUpdate::FilterChainData::ToString() const {
465
- return absl::StrCat(
466
- "{downstream_tls_context=", downstream_tls_context.ToString(),
467
- " http_connection_manager=", http_connection_manager.ToString(), "}");
468
- }
469
-
470
- //
471
- // XdsApi::LdsUpdate::FilterChainMap::CidrRange
472
- //
473
-
474
- std::string XdsApi::LdsUpdate::FilterChainMap::CidrRange::ToString() const {
475
- return absl::StrCat(
476
- "{address_prefix=", grpc_sockaddr_to_string(&address, false),
477
- ", prefix_len=", prefix_len, "}");
478
- }
479
-
480
- //
481
- // FilterChain
482
- //
483
-
484
- struct FilterChain {
485
- struct FilterChainMatch {
486
- uint32_t destination_port = 0;
487
- std::vector<XdsApi::LdsUpdate::FilterChainMap::CidrRange> prefix_ranges;
488
- XdsApi::LdsUpdate::FilterChainMap::ConnectionSourceType source_type =
489
- XdsApi::LdsUpdate::FilterChainMap::ConnectionSourceType::kAny;
490
- std::vector<XdsApi::LdsUpdate::FilterChainMap::CidrRange>
491
- source_prefix_ranges;
492
- std::vector<uint32_t> source_ports;
493
- std::vector<std::string> server_names;
494
- std::string transport_protocol;
495
- std::vector<std::string> application_protocols;
496
-
497
- std::string ToString() const;
498
- } filter_chain_match;
499
-
500
- std::shared_ptr<XdsApi::LdsUpdate::FilterChainData> filter_chain_data;
501
- };
502
-
503
- std::string FilterChain::FilterChainMatch::ToString() const {
504
- absl::InlinedVector<std::string, 8> contents;
505
- if (destination_port != 0) {
506
- contents.push_back(absl::StrCat("destination_port=", destination_port));
507
- }
508
- if (!prefix_ranges.empty()) {
509
- std::vector<std::string> prefix_ranges_content;
510
- for (const auto& range : prefix_ranges) {
511
- prefix_ranges_content.push_back(range.ToString());
512
- }
513
- contents.push_back(absl::StrCat(
514
- "prefix_ranges={", absl::StrJoin(prefix_ranges_content, ", "), "}"));
515
- }
516
- if (source_type == XdsApi::LdsUpdate::FilterChainMap::ConnectionSourceType::
517
- kSameIpOrLoopback) {
518
- contents.push_back("source_type=SAME_IP_OR_LOOPBACK");
519
- } else if (source_type == XdsApi::LdsUpdate::FilterChainMap::
520
- ConnectionSourceType::kExternal) {
521
- contents.push_back("source_type=EXTERNAL");
522
- }
523
- if (!source_prefix_ranges.empty()) {
524
- std::vector<std::string> source_prefix_ranges_content;
525
- for (const auto& range : source_prefix_ranges) {
526
- source_prefix_ranges_content.push_back(range.ToString());
527
- }
528
- contents.push_back(
529
- absl::StrCat("source_prefix_ranges={",
530
- absl::StrJoin(source_prefix_ranges_content, ", "), "}"));
531
- }
532
- if (!source_ports.empty()) {
533
- contents.push_back(
534
- absl::StrCat("source_ports={", absl::StrJoin(source_ports, ", "), "}"));
535
- }
536
- if (!server_names.empty()) {
537
- contents.push_back(
538
- absl::StrCat("server_names={", absl::StrJoin(server_names, ", "), "}"));
539
- }
540
- if (!transport_protocol.empty()) {
541
- contents.push_back(absl::StrCat("transport_protocol=", transport_protocol));
542
- }
543
- if (!application_protocols.empty()) {
544
- contents.push_back(absl::StrCat("application_protocols={",
545
- absl::StrJoin(application_protocols, ", "),
546
- "}"));
547
- }
548
- return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
549
- }
550
-
551
- //
552
- // XdsApi::LdsUpdate::FilterChainMap
553
- //
554
-
555
- std::string XdsApi::LdsUpdate::FilterChainMap::ToString() const {
556
- std::vector<std::string> contents;
557
- for (const auto& destination_ip : destination_ip_vector) {
558
- for (int source_type = 0; source_type < 3; ++source_type) {
559
- for (const auto& source_ip :
560
- destination_ip.source_types_array[source_type]) {
561
- for (const auto& source_port_pair : source_ip.ports_map) {
562
- FilterChain::FilterChainMatch filter_chain_match;
563
- if (destination_ip.prefix_range.has_value()) {
564
- filter_chain_match.prefix_ranges.push_back(
565
- *destination_ip.prefix_range);
566
- }
567
- filter_chain_match.source_type = static_cast<
568
- XdsApi::LdsUpdate::FilterChainMap::ConnectionSourceType>(
569
- source_type);
570
- if (source_ip.prefix_range.has_value()) {
571
- filter_chain_match.source_prefix_ranges.push_back(
572
- *source_ip.prefix_range);
573
- }
574
- if (source_port_pair.first != 0) {
575
- filter_chain_match.source_ports.push_back(source_port_pair.first);
576
- }
577
- contents.push_back(absl::StrCat(
578
- "{filter_chain_match=", filter_chain_match.ToString(),
579
- ", filter_chain=", source_port_pair.second.data->ToString(),
580
- "}"));
581
- }
582
- }
583
- }
584
- }
585
- return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
586
- }
587
-
588
- //
589
- // XdsApi::LdsUpdate
590
- //
591
-
592
- std::string XdsApi::LdsUpdate::ToString() const {
593
- absl::InlinedVector<std::string, 4> contents;
594
- if (type == ListenerType::kTcpListener) {
595
- contents.push_back(absl::StrCat("address=", address));
596
- contents.push_back(
597
- absl::StrCat("filter_chain_map=", filter_chain_map.ToString()));
598
- if (default_filter_chain.has_value()) {
599
- contents.push_back(absl::StrCat("default_filter_chain=",
600
- default_filter_chain->ToString()));
601
- }
602
- } else if (type == ListenerType::kHttpApiListener) {
603
- contents.push_back(absl::StrFormat("http_connection_manager=%s",
604
- http_connection_manager.ToString()));
605
- }
606
- return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
607
- }
608
-
609
- //
610
- // XdsApi::CdsUpdate
611
- //
612
-
613
- std::string XdsApi::CdsUpdate::ToString() const {
614
- absl::InlinedVector<std::string, 8> contents;
615
- switch (cluster_type) {
616
- case EDS:
617
- contents.push_back("cluster_type=EDS");
618
- if (!eds_service_name.empty()) {
619
- contents.push_back(
620
- absl::StrFormat("eds_service_name=%s", eds_service_name));
621
- }
622
- break;
623
- case LOGICAL_DNS:
624
- contents.push_back("cluster_type=LOGICAL_DNS");
625
- contents.push_back(absl::StrFormat("dns_hostname=%s", dns_hostname));
626
- break;
627
- case AGGREGATE:
628
- contents.push_back("cluster_type=AGGREGATE");
629
- contents.push_back(
630
- absl::StrFormat("prioritized_cluster_names=[%s]",
631
- absl::StrJoin(prioritized_cluster_names, ", ")));
632
- }
633
- if (!common_tls_context.Empty()) {
634
- contents.push_back(absl::StrFormat("common_tls_context=%s",
635
- common_tls_context.ToString()));
636
- }
637
- if (lrs_load_reporting_server_name.has_value()) {
638
- contents.push_back(absl::StrFormat("lrs_load_reporting_server_name=%s",
639
- lrs_load_reporting_server_name.value()));
640
- }
641
- contents.push_back(absl::StrCat("lb_policy=", lb_policy));
642
- if (lb_policy == "RING_HASH") {
643
- contents.push_back(absl::StrCat("min_ring_size=", min_ring_size));
644
- contents.push_back(absl::StrCat("max_ring_size=", max_ring_size));
645
- }
646
- contents.push_back(
647
- absl::StrFormat("max_concurrent_requests=%d", max_concurrent_requests));
648
- return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
649
- }
650
-
651
- //
652
- // XdsApi::EdsUpdate
653
- //
654
-
655
- std::string XdsApi::EdsUpdate::Priority::Locality::ToString() const {
656
- std::vector<std::string> endpoint_strings;
657
- for (const ServerAddress& endpoint : endpoints) {
658
- endpoint_strings.emplace_back(endpoint.ToString());
659
- }
660
- return absl::StrCat("{name=", name->AsHumanReadableString(),
661
- ", lb_weight=", lb_weight, ", endpoints=[",
662
- absl::StrJoin(endpoint_strings, ", "), "]}");
663
- }
664
-
665
- bool XdsApi::EdsUpdate::Priority::operator==(const Priority& other) const {
666
- if (localities.size() != other.localities.size()) return false;
667
- auto it1 = localities.begin();
668
- auto it2 = other.localities.begin();
669
- while (it1 != localities.end()) {
670
- if (*it1->first != *it2->first) return false;
671
- if (it1->second != it2->second) return false;
672
- ++it1;
673
- ++it2;
674
- }
675
- return true;
676
- }
677
-
678
- std::string XdsApi::EdsUpdate::Priority::ToString() const {
679
- std::vector<std::string> locality_strings;
680
- for (const auto& p : localities) {
681
- locality_strings.emplace_back(p.second.ToString());
682
- }
683
- return absl::StrCat("[", absl::StrJoin(locality_strings, ", "), "]");
684
- }
685
-
686
- bool XdsApi::EdsUpdate::DropConfig::ShouldDrop(
687
- const std::string** category_name) const {
688
- for (size_t i = 0; i < drop_category_list_.size(); ++i) {
689
- const auto& drop_category = drop_category_list_[i];
690
- // Generate a random number in [0, 1000000).
691
- const uint32_t random = static_cast<uint32_t>(rand()) % 1000000;
692
- if (random < drop_category.parts_per_million) {
693
- *category_name = &drop_category.name;
694
- return true;
695
- }
696
- }
697
- return false;
698
- }
699
-
700
- std::string XdsApi::EdsUpdate::DropConfig::ToString() const {
701
- std::vector<std::string> category_strings;
702
- for (const DropCategory& category : drop_category_list_) {
703
- category_strings.emplace_back(
704
- absl::StrCat(category.name, "=", category.parts_per_million));
705
- }
706
- return absl::StrCat("{[", absl::StrJoin(category_strings, ", "),
707
- "], drop_all=", drop_all_, "}");
708
- }
709
-
710
- std::string XdsApi::EdsUpdate::ToString() const {
711
- std::vector<std::string> priority_strings;
712
- for (size_t i = 0; i < priorities.size(); ++i) {
713
- const Priority& priority = priorities[i];
714
- priority_strings.emplace_back(
715
- absl::StrCat("priority ", i, ": ", priority.ToString()));
716
- }
717
- return absl::StrCat("priorities=[", absl::StrJoin(priority_strings, ", "),
718
- "], drop_config=", drop_config->ToString());
719
- }
720
-
721
- //
722
- // XdsApi
723
- //
724
-
725
- // TODO(roth): All constants and functions for individual resource types
726
- // should be merged into the XdsResourceType abstraction.
727
- const char* XdsApi::kLdsTypeUrl = "envoy.config.listener.v3.Listener";
728
- const char* XdsApi::kRdsTypeUrl = "envoy.config.route.v3.RouteConfiguration";
729
- const char* XdsApi::kCdsTypeUrl = "envoy.config.cluster.v3.Cluster";
730
- const char* XdsApi::kEdsTypeUrl =
731
- "envoy.config.endpoint.v3.ClusterLoadAssignment";
732
-
733
- namespace {
734
-
735
- const char* kLdsV2TypeUrl = "envoy.api.v2.Listener";
736
- const char* kRdsV2TypeUrl = "envoy.api.v2.RouteConfiguration";
737
- const char* kCdsV2TypeUrl = "envoy.api.v2.Cluster";
738
- const char* kEdsV2TypeUrl = "envoy.api.v2.ClusterLoadAssignment";
739
-
740
- bool IsLdsInternal(absl::string_view type_url, bool* is_v2 = nullptr) {
741
- if (type_url == XdsApi::kLdsTypeUrl) return true;
742
- if (type_url == kLdsV2TypeUrl) {
743
- if (is_v2 != nullptr) *is_v2 = true;
744
- return true;
745
- }
746
- return false;
747
- }
748
-
749
- bool IsRdsInternal(absl::string_view type_url, bool* /*is_v2*/ = nullptr) {
750
- return type_url == XdsApi::kRdsTypeUrl || type_url == kRdsV2TypeUrl;
751
- }
752
-
753
- bool IsCdsInternal(absl::string_view type_url, bool* /*is_v2*/ = nullptr) {
754
- return type_url == XdsApi::kCdsTypeUrl || type_url == kCdsV2TypeUrl;
755
- }
756
-
757
- bool IsEdsInternal(absl::string_view type_url, bool* /*is_v2*/ = nullptr) {
758
- return type_url == XdsApi::kEdsTypeUrl || type_url == kEdsV2TypeUrl;
759
- }
760
-
761
- absl::string_view TypeUrlExternalToInternal(bool use_v3,
762
- const std::string& type_url) {
763
- if (!use_v3) {
764
- if (type_url == XdsApi::kLdsTypeUrl) {
765
- return kLdsV2TypeUrl;
766
- }
767
- if (type_url == XdsApi::kRdsTypeUrl) {
768
- return kRdsV2TypeUrl;
769
- }
770
- if (type_url == XdsApi::kCdsTypeUrl) {
771
- return kCdsV2TypeUrl;
772
- }
773
- if (type_url == XdsApi::kEdsTypeUrl) {
774
- return kEdsV2TypeUrl;
775
- }
776
- }
777
- return type_url;
778
- }
779
-
780
- std::string TypeUrlInternalToExternal(absl::string_view type_url) {
781
- if (type_url == kLdsV2TypeUrl) {
782
- return XdsApi::kLdsTypeUrl;
783
- } else if (type_url == kRdsV2TypeUrl) {
784
- return XdsApi::kRdsTypeUrl;
785
- } else if (type_url == kCdsV2TypeUrl) {
786
- return XdsApi::kCdsTypeUrl;
787
- } else if (type_url == kEdsV2TypeUrl) {
788
- return XdsApi::kEdsTypeUrl;
789
- }
790
- return std::string(type_url);
791
- }
792
-
793
- struct EncodingContext {
794
- XdsClient* client; // Used only for logging. Unsafe for dereferencing.
795
- TraceFlag* tracer;
796
- upb_symtab* symtab;
797
- upb_arena* arena;
798
- bool use_v3;
799
- const CertificateProviderStore::PluginDefinitionMap*
800
- certificate_provider_definition_map;
801
- };
802
-
803
- class XdsResourceType {
804
- public:
805
- // A base type for resource data.
806
- struct ResourceData {};
807
-
808
- struct DecodeResult {
809
- std::string name;
810
- absl::StatusOr<std::unique_ptr<ResourceData>> resource;
811
- };
812
-
813
- virtual ~XdsResourceType() = default;
814
-
815
- virtual absl::string_view type_url() const = 0;
816
-
817
- virtual absl::string_view v2_type_url() const = 0;
818
-
819
- virtual absl::StatusOr<DecodeResult> Decode(
820
- const EncodingContext& context, absl::string_view serialized_resource,
821
- bool is_v2) const = 0;
822
-
823
- bool IsType(absl::string_view resource_type, bool* is_v2) const {
824
- if (resource_type == type_url()) return true;
825
- if (resource_type == v2_type_url()) {
826
- if (is_v2 != nullptr) *is_v2 = true;
827
- return true;
828
- }
829
- return false;
830
- }
831
- };
832
-
833
- absl::StatusOr<XdsApi::ResourceName> ParseResourceNameInternal(
834
- absl::string_view name,
835
- std::function<bool(absl::string_view, bool*)> is_expected_type) {
836
- // Old-style names use the empty string for authority.
837
- // authority is prefixed with "old:" to indicate that it's an old-style name.
838
- if (!absl::StartsWith(name, "xdstp:")) {
839
- return XdsApi::ResourceName{"old:", std::string(name)};
840
- }
841
- // New style name. Parse URI.
842
- auto uri = URI::Parse(name);
843
- if (!uri.ok()) return uri.status();
844
- // Split the resource type off of the path to get the id.
845
- std::pair<absl::string_view, absl::string_view> path_parts =
846
- absl::StrSplit(uri->path(), absl::MaxSplits('/', 1));
847
- if (!is_expected_type(path_parts.first, nullptr)) {
848
- return absl::InvalidArgumentError(
849
- "xdstp URI path must indicate valid xDS resource type");
850
- }
851
- std::vector<std::pair<absl::string_view, absl::string_view>> query_parameters(
852
- uri->query_parameter_map().begin(), uri->query_parameter_map().end());
853
- std::sort(query_parameters.begin(), query_parameters.end());
854
- return XdsApi::ResourceName{
855
- absl::StrCat("xdstp:", uri->authority()),
856
- absl::StrCat(
857
- path_parts.second, (query_parameters.empty() ? "?" : ""),
858
- absl::StrJoin(query_parameters, "&", absl::PairFormatter("=")))};
859
- }
860
-
861
- } // namespace
862
-
863
65
  // If gRPC is built with -DGRPC_XDS_USER_AGENT_NAME_SUFFIX="...", that string
864
66
  // will be appended to the user agent name reported to the xDS server.
865
67
  #ifdef GRPC_XDS_USER_AGENT_NAME_SUFFIX
@@ -881,11 +83,13 @@ absl::StatusOr<XdsApi::ResourceName> ParseResourceNameInternal(
881
83
  XdsApi::XdsApi(XdsClient* client, TraceFlag* tracer,
882
84
  const XdsBootstrap::Node* node,
883
85
  const CertificateProviderStore::PluginDefinitionMap*
884
- certificate_provider_definition_map)
86
+ certificate_provider_definition_map,
87
+ upb::SymbolTable* symtab)
885
88
  : client_(client),
886
89
  tracer_(tracer),
887
90
  node_(node),
888
91
  certificate_provider_definition_map_(certificate_provider_definition_map),
92
+ symtab_(symtab),
889
93
  build_version_(absl::StrCat("gRPC C-core ", GPR_PLATFORM_STRING, " ",
890
94
  grpc_version_string(),
891
95
  GRPC_XDS_USER_AGENT_NAME_SUFFIX_STRING,
@@ -895,71 +99,14 @@ XdsApi::XdsApi(XdsClient* client, TraceFlag* tracer,
895
99
  user_agent_version_(
896
100
  absl::StrCat("C-core ", grpc_version_string(),
897
101
  GRPC_XDS_USER_AGENT_NAME_SUFFIX_STRING,
898
- GRPC_XDS_USER_AGENT_VERSION_SUFFIX_STRING)) {
899
- // Populate upb symtab with xDS proto messages that we want to print
900
- // properly in logs.
901
- // Note: This won't actually work properly until upb adds support for
902
- // Any fields in textproto printing (internal b/178821188).
903
- envoy_config_listener_v3_Listener_getmsgdef(symtab_.ptr());
904
- envoy_config_route_v3_RouteConfiguration_getmsgdef(symtab_.ptr());
905
- envoy_config_cluster_v3_Cluster_getmsgdef(symtab_.ptr());
906
- envoy_extensions_clusters_aggregate_v3_ClusterConfig_getmsgdef(symtab_.ptr());
907
- envoy_config_cluster_v3_Cluster_getmsgdef(symtab_.ptr());
908
- envoy_config_endpoint_v3_ClusterLoadAssignment_getmsgdef(symtab_.ptr());
909
- envoy_extensions_transport_sockets_tls_v3_UpstreamTlsContext_getmsgdef(
910
- symtab_.ptr());
911
- envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_getmsgdef(
912
- symtab_.ptr());
913
- // Load HTTP filter proto messages into the upb symtab.
914
- XdsHttpFilterRegistry::PopulateSymtab(symtab_.ptr());
915
- }
916
-
917
- bool XdsApi::IsLds(absl::string_view type_url) {
918
- return IsLdsInternal(type_url);
919
- }
920
-
921
- bool XdsApi::IsRds(absl::string_view type_url) {
922
- return IsRdsInternal(type_url);
923
- }
924
-
925
- bool XdsApi::IsCds(absl::string_view type_url) {
926
- return IsCdsInternal(type_url);
927
- }
928
-
929
- bool XdsApi::IsEds(absl::string_view type_url) {
930
- return IsEdsInternal(type_url);
931
- }
932
-
933
- absl::StatusOr<XdsApi::ResourceName> XdsApi::ParseResourceName(
934
- absl::string_view name, bool (*is_expected_type)(absl::string_view)) {
935
- return ParseResourceNameInternal(
936
- name, [is_expected_type](absl::string_view type, bool*) {
937
- return is_expected_type(type);
938
- });
939
- }
940
-
941
- std::string XdsApi::ConstructFullResourceName(absl::string_view authority,
942
- absl::string_view resource_type,
943
- absl::string_view name) {
944
- if (absl::ConsumePrefix(&authority, "xdstp:")) {
945
- return absl::StrCat("xdstp://", authority, "/", resource_type, "/", name);
946
- } else {
947
- return std::string(absl::StripPrefix(name, "old:"));
948
- }
949
- }
102
+ GRPC_XDS_USER_AGENT_VERSION_SUFFIX_STRING)) {}
950
103
 
951
104
  namespace {
952
105
 
953
- // Works for both std::string and absl::string_view.
954
- template <typename T>
955
- inline upb_strview StdStringToUpbString(const T& str) {
956
- return upb_strview_make(str.data(), str.size());
957
- }
958
-
959
- void PopulateMetadataValue(const EncodingContext& context,
106
+ void PopulateMetadataValue(const XdsEncodingContext& context,
960
107
  google_protobuf_Value* value_pb, const Json& value);
961
108
 
962
- void PopulateListValue(const EncodingContext& context,
109
+ void PopulateListValue(const XdsEncodingContext& context,
963
110
  google_protobuf_ListValue* list_value,
964
111
  const Json::Array& values) {
965
112
  for (const auto& value : values) {
@@ -969,7 +116,7 @@ void PopulateListValue(const EncodingContext& context,
969
116
  }
970
117
  }
971
118
 
972
- void PopulateMetadata(const EncodingContext& context,
119
+ void PopulateMetadata(const XdsEncodingContext& context,
973
120
  google_protobuf_Struct* metadata_pb,
974
121
  const Json::Object& metadata) {
975
122
  for (const auto& p : metadata) {
@@ -980,7 +127,7 @@ void PopulateMetadata(const EncodingContext& context,
980
127
  }
981
128
  }
982
129
 
983
- void PopulateMetadataValue(const EncodingContext& context,
130
+ void PopulateMetadataValue(const XdsEncodingContext& context,
984
131
  google_protobuf_Value* value_pb, const Json& value) {
985
132
  switch (value.type()) {
986
133
  case Json::Type::JSON_NULL:
@@ -1036,7 +183,7 @@ std::string EncodeStringField(uint32_t field_number, const std::string& str) {
1036
183
  EncodeVarint(str.size()) + str;
1037
184
  }
1038
185
 
1039
- void PopulateBuildVersion(const EncodingContext& context,
186
+ void PopulateBuildVersion(const XdsEncodingContext& context,
1040
187
  envoy_config_core_v3_Node* node_msg,
1041
188
  const std::string& build_version) {
1042
189
  std::string encoded_build_version = EncodeStringField(5, build_version);
@@ -1048,7 +195,7 @@ void PopulateBuildVersion(const EncodingContext& context,
1048
195
  encoded_build_version.size(), context.arena);
1049
196
  }
1050
197
 
1051
- void PopulateNode(const EncodingContext& context,
198
+ void PopulateNode(const XdsEncodingContext& context,
1052
199
  const XdsBootstrap::Node* node,
1053
200
  const std::string& build_version,
1054
201
  const std::string& user_agent_name,
@@ -1098,16 +245,8 @@ void PopulateNode(const EncodingContext& context,
1098
245
  context.arena);
1099
246
  }
1100
247
 
1101
- inline absl::string_view UpbStringToAbsl(const upb_strview& str) {
1102
- return absl::string_view(str.data, str.size);
1103
- }
1104
-
1105
- inline std::string UpbStringToStdString(const upb_strview& str) {
1106
- return std::string(str.data, str.size);
1107
- }
1108
-
1109
248
  void MaybeLogDiscoveryRequest(
1110
- const EncodingContext& context,
249
+ const XdsEncodingContext& context,
1111
250
  const envoy_service_discovery_v3_DiscoveryRequest* request) {
1112
251
  if (GRPC_TRACE_FLAG_ENABLED(*context.tracer) &&
1113
252
  gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
@@ -1121,7 +260,7 @@ void MaybeLogDiscoveryRequest(
1121
260
  }
1122
261
 
1123
262
  grpc_slice SerializeDiscoveryRequest(
1124
- const EncodingContext& context,
263
+ const XdsEncodingContext& context,
1125
264
  envoy_service_discovery_v3_DiscoveryRequest* request) {
1126
265
  size_t output_length;
1127
266
  char* output = envoy_service_discovery_v3_DiscoveryRequest_serialize(
@@ -1132,28 +271,24 @@ grpc_slice SerializeDiscoveryRequest(
1132
271
  } // namespace
1133
272
 
1134
273
  grpc_slice XdsApi::CreateAdsRequest(
1135
- const XdsBootstrap::XdsServer& server, const std::string& type_url,
1136
- const std::map<absl::string_view /*authority*/,
1137
- std::set<absl::string_view /*name*/>>& resource_names,
1138
- const std::string& version, const std::string& nonce,
1139
- grpc_error_handle error, bool populate_node) {
274
+ const XdsBootstrap::XdsServer& server, absl::string_view type_url,
275
+ absl::string_view version, absl::string_view nonce,
276
+ const std::vector<std::string>& resource_names, grpc_error_handle error,
277
+ bool populate_node) {
1140
278
  upb::Arena arena;
1141
- const EncodingContext context = {client_,
1142
- tracer_,
1143
- symtab_.ptr(),
1144
- arena.ptr(),
1145
- server.ShouldUseV3(),
1146
- certificate_provider_definition_map_};
279
+ const XdsEncodingContext context = {client_,
280
+ tracer_,
281
+ symtab_->ptr(),
282
+ arena.ptr(),
283
+ server.ShouldUseV3(),
284
+ certificate_provider_definition_map_};
1147
285
  // Create a request.
1148
286
  envoy_service_discovery_v3_DiscoveryRequest* request =
1149
287
  envoy_service_discovery_v3_DiscoveryRequest_new(arena.ptr());
1150
288
  // Set type_url.
1151
- absl::string_view real_type_url =
1152
- TypeUrlExternalToInternal(server.ShouldUseV3(), type_url);
1153
- std::string real_type_url_str =
1154
- absl::StrCat("type.googleapis.com/", real_type_url);
289
+ std::string type_url_str = absl::StrCat("type.googleapis.com/", type_url);
1155
290
  envoy_service_discovery_v3_DiscoveryRequest_set_type_url(
1156
- request, StdStringToUpbString(real_type_url_str));
291
+ request, StdStringToUpbString(type_url_str));
1157
292
  // Set version_info.
1158
293
  if (!version.empty()) {
1159
294
  envoy_service_discovery_v3_DiscoveryRequest_set_version_info(
@@ -1189,27 +324,10 @@ grpc_slice XdsApi::CreateAdsRequest(
1189
324
  PopulateNode(context, node_, build_version_, user_agent_name_,
1190
325
  user_agent_version_, node_msg);
1191
326
  }
1192
- // A vector for temporary local storage of resource name strings.
1193
- std::vector<std::string> resource_name_storage;
1194
- // Make sure the vector is sized right up-front, so that reallocations
1195
- // don't move the strings out from under the upb proto object that
1196
- // points to them.
1197
- size_t size = 0;
1198
- for (const auto& p : resource_names) {
1199
- size += p.second.size();
1200
- }
1201
- resource_name_storage.reserve(size);
1202
327
  // Add resource_names.
1203
- for (const auto& a : resource_names) {
1204
- absl::string_view authority = a.first;
1205
- for (const auto& p : a.second) {
1206
- absl::string_view resource_id = p;
1207
- resource_name_storage.push_back(
1208
- ConstructFullResourceName(authority, real_type_url, resource_id));
1209
- envoy_service_discovery_v3_DiscoveryRequest_add_resource_names(
1210
- request, StdStringToUpbString(resource_name_storage.back()),
1211
- arena.ptr());
1212
- }
328
+ for (const std::string& resource_name : resource_names) {
329
+ envoy_service_discovery_v3_DiscoveryRequest_add_resource_names(
330
+ request, StdStringToUpbString(resource_name), arena.ptr());
1213
331
  }
1214
332
  MaybeLogDiscoveryRequest(context, request);
1215
333
  return SerializeDiscoveryRequest(context, request);
@@ -1218,7 +336,7 @@ grpc_slice XdsApi::CreateAdsRequest(
1218
336
  namespace {
1219
337
 
1220
338
  void MaybeLogDiscoveryResponse(
1221
- const EncodingContext& context,
339
+ const XdsEncodingContext& context,
1222
340
  const envoy_service_discovery_v3_DiscoveryResponse* response) {
1223
341
  if (GRPC_TRACE_FLAG_ENABLED(*context.tracer) &&
1224
342
  gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
@@ -1231,2556 +349,61 @@ void MaybeLogDiscoveryResponse(
1231
349
  }
1232
350
  }
1233
351
 
1234
- void MaybeLogListener(const EncodingContext& context,
1235
- const envoy_config_listener_v3_Listener* listener) {
1236
- if (GRPC_TRACE_FLAG_ENABLED(*context.tracer) &&
1237
- gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
1238
- const upb_msgdef* msg_type =
1239
- envoy_config_listener_v3_Listener_getmsgdef(context.symtab);
1240
- char buf[10240];
1241
- upb_text_encode(listener, msg_type, nullptr, 0, buf, sizeof(buf));
1242
- gpr_log(GPR_DEBUG, "[xds_client %p] Listener: %s", context.client, buf);
1243
- }
1244
- }
1245
-
1246
- void MaybeLogHttpConnectionManager(
1247
- const EncodingContext& context,
1248
- const envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager*
1249
- http_connection_manager_config) {
1250
- if (GRPC_TRACE_FLAG_ENABLED(*context.tracer) &&
1251
- gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
1252
- const upb_msgdef* msg_type =
1253
- envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_getmsgdef(
1254
- context.symtab);
1255
- char buf[10240];
1256
- upb_text_encode(http_connection_manager_config, msg_type, nullptr, 0, buf,
1257
- sizeof(buf));
1258
- gpr_log(GPR_DEBUG, "[xds_client %p] HttpConnectionManager: %s",
1259
- context.client, buf);
1260
- }
1261
- }
1262
-
1263
- void MaybeLogRouteConfiguration(
1264
- const EncodingContext& context,
1265
- const envoy_config_route_v3_RouteConfiguration* route_config) {
1266
- if (GRPC_TRACE_FLAG_ENABLED(*context.tracer) &&
1267
- gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
1268
- const upb_msgdef* msg_type =
1269
- envoy_config_route_v3_RouteConfiguration_getmsgdef(context.symtab);
1270
- char buf[10240];
1271
- upb_text_encode(route_config, msg_type, nullptr, 0, buf, sizeof(buf));
1272
- gpr_log(GPR_DEBUG, "[xds_client %p] RouteConfiguration: %s", context.client,
1273
- buf);
1274
- }
1275
- }
1276
-
1277
- void MaybeLogCluster(const EncodingContext& context,
1278
- const envoy_config_cluster_v3_Cluster* cluster) {
1279
- if (GRPC_TRACE_FLAG_ENABLED(*context.tracer) &&
1280
- gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
1281
- const upb_msgdef* msg_type =
1282
- envoy_config_cluster_v3_Cluster_getmsgdef(context.symtab);
1283
- char buf[10240];
1284
- upb_text_encode(cluster, msg_type, nullptr, 0, buf, sizeof(buf));
1285
- gpr_log(GPR_DEBUG, "[xds_client %p] Cluster: %s", context.client, buf);
1286
- }
1287
- }
1288
-
1289
- void MaybeLogClusterLoadAssignment(
1290
- const EncodingContext& context,
1291
- const envoy_config_endpoint_v3_ClusterLoadAssignment* cla) {
1292
- if (GRPC_TRACE_FLAG_ENABLED(*context.tracer) &&
1293
- gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
1294
- const upb_msgdef* msg_type =
1295
- envoy_config_endpoint_v3_ClusterLoadAssignment_getmsgdef(
1296
- context.symtab);
1297
- char buf[10240];
1298
- upb_text_encode(cla, msg_type, nullptr, 0, buf, sizeof(buf));
1299
- gpr_log(GPR_DEBUG, "[xds_client %p] ClusterLoadAssignment: %s",
1300
- context.client, buf);
1301
- }
1302
- }
1303
-
1304
- grpc_error_handle RoutePathMatchParse(
1305
- const envoy_config_route_v3_RouteMatch* match, XdsApi::Route* route,
1306
- bool* ignore_route) {
1307
- auto* case_sensitive_ptr =
1308
- envoy_config_route_v3_RouteMatch_case_sensitive(match);
1309
- bool case_sensitive = true;
1310
- if (case_sensitive_ptr != nullptr) {
1311
- case_sensitive = google_protobuf_BoolValue_value(case_sensitive_ptr);
1312
- }
1313
- StringMatcher::Type type;
1314
- std::string match_string;
1315
- if (envoy_config_route_v3_RouteMatch_has_prefix(match)) {
1316
- absl::string_view prefix =
1317
- UpbStringToAbsl(envoy_config_route_v3_RouteMatch_prefix(match));
1318
- // Empty prefix "" is accepted.
1319
- if (!prefix.empty()) {
1320
- // Prefix "/" is accepted.
1321
- if (prefix[0] != '/') {
1322
- // Prefix which does not start with a / will never match anything, so
1323
- // ignore this route.
1324
- *ignore_route = true;
1325
- return GRPC_ERROR_NONE;
1326
- }
1327
- std::vector<absl::string_view> prefix_elements =
1328
- absl::StrSplit(prefix.substr(1), absl::MaxSplits('/', 2));
1329
- if (prefix_elements.size() > 2) {
1330
- // Prefix cannot have more than 2 slashes.
1331
- *ignore_route = true;
1332
- return GRPC_ERROR_NONE;
1333
- } else if (prefix_elements.size() == 2 && prefix_elements[0].empty()) {
1334
- // Prefix contains empty string between the 2 slashes
1335
- *ignore_route = true;
1336
- return GRPC_ERROR_NONE;
1337
- }
1338
- }
1339
- type = StringMatcher::Type::kPrefix;
1340
- match_string = std::string(prefix);
1341
- } else if (envoy_config_route_v3_RouteMatch_has_path(match)) {
1342
- absl::string_view path =
1343
- UpbStringToAbsl(envoy_config_route_v3_RouteMatch_path(match));
1344
- if (path.empty()) {
1345
- // Path that is empty will never match anything, so ignore this route.
1346
- *ignore_route = true;
1347
- return GRPC_ERROR_NONE;
1348
- }
1349
- if (path[0] != '/') {
1350
- // Path which does not start with a / will never match anything, so
1351
- // ignore this route.
1352
- *ignore_route = true;
1353
- return GRPC_ERROR_NONE;
1354
- }
1355
- std::vector<absl::string_view> path_elements =
1356
- absl::StrSplit(path.substr(1), absl::MaxSplits('/', 2));
1357
- if (path_elements.size() != 2) {
1358
- // Path not in the required format of /service/method will never match
1359
- // anything, so ignore this route.
1360
- *ignore_route = true;
1361
- return GRPC_ERROR_NONE;
1362
- } else if (path_elements[0].empty()) {
1363
- // Path contains empty service name will never match anything, so ignore
1364
- // this route.
1365
- *ignore_route = true;
1366
- return GRPC_ERROR_NONE;
1367
- } else if (path_elements[1].empty()) {
1368
- // Path contains empty method name will never match anything, so ignore
1369
- // this route.
1370
- *ignore_route = true;
1371
- return GRPC_ERROR_NONE;
1372
- }
1373
- type = StringMatcher::Type::kExact;
1374
- match_string = std::string(path);
1375
- } else if (envoy_config_route_v3_RouteMatch_has_safe_regex(match)) {
1376
- const envoy_type_matcher_v3_RegexMatcher* regex_matcher =
1377
- envoy_config_route_v3_RouteMatch_safe_regex(match);
1378
- GPR_ASSERT(regex_matcher != nullptr);
1379
- type = StringMatcher::Type::kSafeRegex;
1380
- match_string = UpbStringToStdString(
1381
- envoy_type_matcher_v3_RegexMatcher_regex(regex_matcher));
1382
- } else {
1383
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1384
- "Invalid route path specifier specified.");
1385
- }
1386
- absl::StatusOr<StringMatcher> string_matcher =
1387
- StringMatcher::Create(type, match_string, case_sensitive);
1388
- if (!string_matcher.ok()) {
1389
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
1390
- absl::StrCat("path matcher: ", string_matcher.status().message()));
1391
- }
1392
- route->matchers.path_matcher = std::move(string_matcher.value());
1393
- return GRPC_ERROR_NONE;
1394
- }
1395
-
1396
- grpc_error_handle RouteHeaderMatchersParse(
1397
- const envoy_config_route_v3_RouteMatch* match, XdsApi::Route* route) {
1398
- size_t size;
1399
- const envoy_config_route_v3_HeaderMatcher* const* headers =
1400
- envoy_config_route_v3_RouteMatch_headers(match, &size);
1401
- for (size_t i = 0; i < size; ++i) {
1402
- const envoy_config_route_v3_HeaderMatcher* header = headers[i];
1403
- const std::string name =
1404
- UpbStringToStdString(envoy_config_route_v3_HeaderMatcher_name(header));
1405
- HeaderMatcher::Type type;
1406
- std::string match_string;
1407
- int64_t range_start = 0;
1408
- int64_t range_end = 0;
1409
- bool present_match = false;
1410
- if (envoy_config_route_v3_HeaderMatcher_has_exact_match(header)) {
1411
- type = HeaderMatcher::Type::kExact;
1412
- match_string = UpbStringToStdString(
1413
- envoy_config_route_v3_HeaderMatcher_exact_match(header));
1414
- } else if (envoy_config_route_v3_HeaderMatcher_has_safe_regex_match(
1415
- header)) {
1416
- const envoy_type_matcher_v3_RegexMatcher* regex_matcher =
1417
- envoy_config_route_v3_HeaderMatcher_safe_regex_match(header);
1418
- GPR_ASSERT(regex_matcher != nullptr);
1419
- type = HeaderMatcher::Type::kSafeRegex;
1420
- match_string = UpbStringToStdString(
1421
- envoy_type_matcher_v3_RegexMatcher_regex(regex_matcher));
1422
- } else if (envoy_config_route_v3_HeaderMatcher_has_range_match(header)) {
1423
- type = HeaderMatcher::Type::kRange;
1424
- const envoy_type_v3_Int64Range* range_matcher =
1425
- envoy_config_route_v3_HeaderMatcher_range_match(header);
1426
- range_start = envoy_type_v3_Int64Range_start(range_matcher);
1427
- range_end = envoy_type_v3_Int64Range_end(range_matcher);
1428
- } else if (envoy_config_route_v3_HeaderMatcher_has_present_match(header)) {
1429
- type = HeaderMatcher::Type::kPresent;
1430
- present_match = envoy_config_route_v3_HeaderMatcher_present_match(header);
1431
- } else if (envoy_config_route_v3_HeaderMatcher_has_prefix_match(header)) {
1432
- type = HeaderMatcher::Type::kPrefix;
1433
- match_string = UpbStringToStdString(
1434
- envoy_config_route_v3_HeaderMatcher_prefix_match(header));
1435
- } else if (envoy_config_route_v3_HeaderMatcher_has_suffix_match(header)) {
1436
- type = HeaderMatcher::Type::kSuffix;
1437
- match_string = UpbStringToStdString(
1438
- envoy_config_route_v3_HeaderMatcher_suffix_match(header));
1439
- } else if (envoy_config_route_v3_HeaderMatcher_has_contains_match(header)) {
1440
- type = HeaderMatcher::Type::kContains;
1441
- match_string = UpbStringToStdString(
1442
- envoy_config_route_v3_HeaderMatcher_contains_match(header));
1443
- } else {
1444
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1445
- "Invalid route header matcher specified.");
1446
- }
1447
- bool invert_match =
1448
- envoy_config_route_v3_HeaderMatcher_invert_match(header);
1449
- absl::StatusOr<HeaderMatcher> header_matcher =
1450
- HeaderMatcher::Create(name, type, match_string, range_start, range_end,
1451
- present_match, invert_match);
1452
- if (!header_matcher.ok()) {
1453
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
1454
- absl::StrCat("header matcher: ", header_matcher.status().message()));
1455
- }
1456
- route->matchers.header_matchers.emplace_back(
1457
- std::move(header_matcher.value()));
1458
- }
1459
- return GRPC_ERROR_NONE;
1460
- }
1461
-
1462
- grpc_error_handle RouteRuntimeFractionParse(
1463
- const envoy_config_route_v3_RouteMatch* match, XdsApi::Route* route) {
1464
- const envoy_config_core_v3_RuntimeFractionalPercent* runtime_fraction =
1465
- envoy_config_route_v3_RouteMatch_runtime_fraction(match);
1466
- if (runtime_fraction != nullptr) {
1467
- const envoy_type_v3_FractionalPercent* fraction =
1468
- envoy_config_core_v3_RuntimeFractionalPercent_default_value(
1469
- runtime_fraction);
1470
- if (fraction != nullptr) {
1471
- uint32_t numerator = envoy_type_v3_FractionalPercent_numerator(fraction);
1472
- const auto denominator =
1473
- static_cast<envoy_type_v3_FractionalPercent_DenominatorType>(
1474
- envoy_type_v3_FractionalPercent_denominator(fraction));
1475
- // Normalize to million.
1476
- switch (denominator) {
1477
- case envoy_type_v3_FractionalPercent_HUNDRED:
1478
- numerator *= 10000;
1479
- break;
1480
- case envoy_type_v3_FractionalPercent_TEN_THOUSAND:
1481
- numerator *= 100;
1482
- break;
1483
- case envoy_type_v3_FractionalPercent_MILLION:
1484
- break;
1485
- default:
1486
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1487
- "Unknown denominator type");
1488
- }
1489
- route->matchers.fraction_per_million = numerator;
1490
- }
1491
- }
1492
- return GRPC_ERROR_NONE;
1493
- }
1494
-
1495
- grpc_error_handle ExtractHttpFilterTypeName(const EncodingContext& context,
1496
- const google_protobuf_Any* any,
1497
- absl::string_view* filter_type) {
1498
- *filter_type = UpbStringToAbsl(google_protobuf_Any_type_url(any));
1499
- if (*filter_type == "type.googleapis.com/xds.type.v3.TypedStruct" ||
1500
- *filter_type == "type.googleapis.com/udpa.type.v1.TypedStruct") {
1501
- upb_strview any_value = google_protobuf_Any_value(any);
1502
- const auto* typed_struct = xds_type_v3_TypedStruct_parse(
1503
- any_value.data, any_value.size, context.arena);
1504
- if (typed_struct == nullptr) {
1505
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1506
- "could not parse TypedStruct from filter config");
1507
- }
1508
- *filter_type =
1509
- UpbStringToAbsl(xds_type_v3_TypedStruct_type_url(typed_struct));
1510
- }
1511
- *filter_type = absl::StripPrefix(*filter_type, "type.googleapis.com/");
1512
- return GRPC_ERROR_NONE;
1513
- }
1514
-
1515
- template <typename ParentType, typename EntryType>
1516
- grpc_error_handle ParseTypedPerFilterConfig(
1517
- const EncodingContext& context, const ParentType* parent,
1518
- const EntryType* (*entry_func)(const ParentType*, size_t*),
1519
- upb_strview (*key_func)(const EntryType*),
1520
- const google_protobuf_Any* (*value_func)(const EntryType*),
1521
- XdsApi::TypedPerFilterConfig* typed_per_filter_config) {
1522
- size_t filter_it = UPB_MAP_BEGIN;
1523
- while (true) {
1524
- const auto* filter_entry = entry_func(parent, &filter_it);
1525
- if (filter_entry == nullptr) break;
1526
- absl::string_view key = UpbStringToAbsl(key_func(filter_entry));
1527
- if (key.empty()) {
1528
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("empty filter name in map");
1529
- }
1530
- const google_protobuf_Any* any = value_func(filter_entry);
1531
- GPR_ASSERT(any != nullptr);
1532
- absl::string_view filter_type =
1533
- UpbStringToAbsl(google_protobuf_Any_type_url(any));
1534
- if (filter_type.empty()) {
1535
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
1536
- absl::StrCat("no filter config specified for filter name ", key));
1537
- }
1538
- bool is_optional = false;
1539
- if (filter_type ==
1540
- "type.googleapis.com/envoy.config.route.v3.FilterConfig") {
1541
- upb_strview any_value = google_protobuf_Any_value(any);
1542
- const auto* filter_config = envoy_config_route_v3_FilterConfig_parse(
1543
- any_value.data, any_value.size, context.arena);
1544
- if (filter_config == nullptr) {
1545
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
1546
- absl::StrCat("could not parse FilterConfig wrapper for ", key));
1547
- }
1548
- is_optional =
1549
- envoy_config_route_v3_FilterConfig_is_optional(filter_config);
1550
- any = envoy_config_route_v3_FilterConfig_config(filter_config);
1551
- if (any == nullptr) {
1552
- if (is_optional) continue;
1553
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
1554
- absl::StrCat("no filter config specified for filter name ", key));
1555
- }
1556
- }
1557
- grpc_error_handle error =
1558
- ExtractHttpFilterTypeName(context, any, &filter_type);
1559
- if (error != GRPC_ERROR_NONE) return error;
1560
- const XdsHttpFilterImpl* filter_impl =
1561
- XdsHttpFilterRegistry::GetFilterForType(filter_type);
1562
- if (filter_impl == nullptr) {
1563
- if (is_optional) continue;
1564
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
1565
- absl::StrCat("no filter registered for config type ", filter_type));
1566
- }
1567
- absl::StatusOr<XdsHttpFilterImpl::FilterConfig> filter_config =
1568
- filter_impl->GenerateFilterConfigOverride(
1569
- google_protobuf_Any_value(any), context.arena);
1570
- if (!filter_config.ok()) {
1571
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat(
1572
- "filter config for type ", filter_type,
1573
- " failed to parse: ", filter_config.status().ToString()));
1574
- }
1575
- (*typed_per_filter_config)[std::string(key)] = std::move(*filter_config);
1576
- }
1577
- return GRPC_ERROR_NONE;
1578
- }
1579
-
1580
- XdsApi::Duration DurationParse(const google_protobuf_Duration* proto_duration) {
1581
- XdsApi::Duration duration;
1582
- duration.seconds = google_protobuf_Duration_seconds(proto_duration);
1583
- duration.nanos = google_protobuf_Duration_nanos(proto_duration);
1584
- return duration;
1585
- }
1586
-
1587
- grpc_error_handle RetryPolicyParse(
1588
- const EncodingContext& context,
1589
- const envoy_config_route_v3_RetryPolicy* retry_policy,
1590
- absl::optional<XdsApi::RetryPolicy>* retry) {
1591
- std::vector<grpc_error_handle> errors;
1592
- XdsApi::RetryPolicy retry_to_return;
1593
- auto retry_on = UpbStringToStdString(
1594
- envoy_config_route_v3_RetryPolicy_retry_on(retry_policy));
1595
- std::vector<absl::string_view> codes = absl::StrSplit(retry_on, ',');
1596
- for (const auto& code : codes) {
1597
- if (code == "cancelled") {
1598
- retry_to_return.retry_on.Add(GRPC_STATUS_CANCELLED);
1599
- } else if (code == "deadline-exceeded") {
1600
- retry_to_return.retry_on.Add(GRPC_STATUS_DEADLINE_EXCEEDED);
1601
- } else if (code == "internal") {
1602
- retry_to_return.retry_on.Add(GRPC_STATUS_INTERNAL);
1603
- } else if (code == "resource-exhausted") {
1604
- retry_to_return.retry_on.Add(GRPC_STATUS_RESOURCE_EXHAUSTED);
1605
- } else if (code == "unavailable") {
1606
- retry_to_return.retry_on.Add(GRPC_STATUS_UNAVAILABLE);
1607
- } else {
1608
- if (GRPC_TRACE_FLAG_ENABLED(*context.tracer)) {
1609
- gpr_log(GPR_INFO, "Unsupported retry_on policy %s.",
1610
- std::string(code).c_str());
1611
- }
1612
- }
1613
- }
1614
- const google_protobuf_UInt32Value* num_retries =
1615
- envoy_config_route_v3_RetryPolicy_num_retries(retry_policy);
1616
- if (num_retries != nullptr) {
1617
- uint32_t num_retries_value = google_protobuf_UInt32Value_value(num_retries);
1618
- if (num_retries_value == 0) {
1619
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1620
- "RouteAction RetryPolicy num_retries set to invalid value 0."));
1621
- } else {
1622
- retry_to_return.num_retries = num_retries_value;
1623
- }
1624
- } else {
1625
- retry_to_return.num_retries = 1;
1626
- }
1627
- const envoy_config_route_v3_RetryPolicy_RetryBackOff* backoff =
1628
- envoy_config_route_v3_RetryPolicy_retry_back_off(retry_policy);
1629
- if (backoff != nullptr) {
1630
- const google_protobuf_Duration* base_interval =
1631
- envoy_config_route_v3_RetryPolicy_RetryBackOff_base_interval(backoff);
1632
- if (base_interval == nullptr) {
1633
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1634
- "RouteAction RetryPolicy RetryBackoff missing base interval."));
1635
- } else {
1636
- retry_to_return.retry_back_off.base_interval =
1637
- DurationParse(base_interval);
1638
- }
1639
- const google_protobuf_Duration* max_interval =
1640
- envoy_config_route_v3_RetryPolicy_RetryBackOff_max_interval(backoff);
1641
- XdsApi::Duration max;
1642
- if (max_interval != nullptr) {
1643
- max = DurationParse(max_interval);
1644
- } else {
1645
- // if max interval is not set, it is 10x the base, if the value in nanos
1646
- // can yield another second, adjust the value in seconds accordingly.
1647
- max.seconds = retry_to_return.retry_back_off.base_interval.seconds * 10;
1648
- max.nanos = retry_to_return.retry_back_off.base_interval.nanos * 10;
1649
- if (max.nanos > 1000000000) {
1650
- max.seconds += max.nanos / 1000000000;
1651
- max.nanos = max.nanos % 1000000000;
1652
- }
1653
- }
1654
- retry_to_return.retry_back_off.max_interval = max;
1655
- } else {
1656
- retry_to_return.retry_back_off.base_interval.seconds = 0;
1657
- retry_to_return.retry_back_off.base_interval.nanos = 25000000;
1658
- retry_to_return.retry_back_off.max_interval.seconds = 0;
1659
- retry_to_return.retry_back_off.max_interval.nanos = 250000000;
1660
- }
1661
- if (errors.empty()) {
1662
- *retry = retry_to_return;
1663
- return GRPC_ERROR_NONE;
1664
- } else {
1665
- return GRPC_ERROR_CREATE_FROM_VECTOR("errors parsing retry policy",
1666
- &errors);
1667
- }
1668
- }
1669
-
1670
- grpc_error_handle RouteActionParse(const EncodingContext& context,
1671
- const envoy_config_route_v3_Route* route_msg,
1672
- XdsApi::Route::RouteAction* route,
1673
- bool* ignore_route) {
1674
- const envoy_config_route_v3_RouteAction* route_action =
1675
- envoy_config_route_v3_Route_route(route_msg);
1676
- // Get the cluster or weighted_clusters in the RouteAction.
1677
- if (envoy_config_route_v3_RouteAction_has_cluster(route_action)) {
1678
- route->cluster_name = UpbStringToStdString(
1679
- envoy_config_route_v3_RouteAction_cluster(route_action));
1680
- if (route->cluster_name.empty()) {
1681
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1682
- "RouteAction cluster contains empty cluster name.");
1683
- }
1684
- } else if (envoy_config_route_v3_RouteAction_has_weighted_clusters(
1685
- route_action)) {
1686
- const envoy_config_route_v3_WeightedCluster* weighted_cluster =
1687
- envoy_config_route_v3_RouteAction_weighted_clusters(route_action);
1688
- uint32_t total_weight = 100;
1689
- const google_protobuf_UInt32Value* weight =
1690
- envoy_config_route_v3_WeightedCluster_total_weight(weighted_cluster);
1691
- if (weight != nullptr) {
1692
- total_weight = google_protobuf_UInt32Value_value(weight);
1693
- }
1694
- size_t clusters_size;
1695
- const envoy_config_route_v3_WeightedCluster_ClusterWeight* const* clusters =
1696
- envoy_config_route_v3_WeightedCluster_clusters(weighted_cluster,
1697
- &clusters_size);
1698
- uint32_t sum_of_weights = 0;
1699
- for (size_t j = 0; j < clusters_size; ++j) {
1700
- const envoy_config_route_v3_WeightedCluster_ClusterWeight*
1701
- cluster_weight = clusters[j];
1702
- XdsApi::Route::RouteAction::ClusterWeight cluster;
1703
- cluster.name = UpbStringToStdString(
1704
- envoy_config_route_v3_WeightedCluster_ClusterWeight_name(
1705
- cluster_weight));
1706
- if (cluster.name.empty()) {
1707
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1708
- "RouteAction weighted_cluster cluster contains empty cluster "
1709
- "name.");
1710
- }
1711
- const google_protobuf_UInt32Value* weight =
1712
- envoy_config_route_v3_WeightedCluster_ClusterWeight_weight(
1713
- cluster_weight);
1714
- if (weight == nullptr) {
1715
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1716
- "RouteAction weighted_cluster cluster missing weight");
1717
- }
1718
- cluster.weight = google_protobuf_UInt32Value_value(weight);
1719
- if (cluster.weight == 0) continue;
1720
- sum_of_weights += cluster.weight;
1721
- if (context.use_v3) {
1722
- grpc_error_handle error = ParseTypedPerFilterConfig<
1723
- envoy_config_route_v3_WeightedCluster_ClusterWeight,
1724
- envoy_config_route_v3_WeightedCluster_ClusterWeight_TypedPerFilterConfigEntry>(
1725
- context, cluster_weight,
1726
- envoy_config_route_v3_WeightedCluster_ClusterWeight_typed_per_filter_config_next,
1727
- envoy_config_route_v3_WeightedCluster_ClusterWeight_TypedPerFilterConfigEntry_key,
1728
- envoy_config_route_v3_WeightedCluster_ClusterWeight_TypedPerFilterConfigEntry_value,
1729
- &cluster.typed_per_filter_config);
1730
- if (error != GRPC_ERROR_NONE) return error;
1731
- }
1732
- route->weighted_clusters.emplace_back(std::move(cluster));
1733
- }
1734
- if (total_weight != sum_of_weights) {
1735
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1736
- "RouteAction weighted_cluster has incorrect total weight");
1737
- }
1738
- if (route->weighted_clusters.empty()) {
1739
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1740
- "RouteAction weighted_cluster has no valid clusters specified.");
1741
- }
1742
- } else {
1743
- // No cluster or weighted_clusters found in RouteAction, ignore this route.
1744
- *ignore_route = true;
1745
- }
1746
- if (!*ignore_route) {
1747
- const envoy_config_route_v3_RouteAction_MaxStreamDuration*
1748
- max_stream_duration =
1749
- envoy_config_route_v3_RouteAction_max_stream_duration(route_action);
1750
- if (max_stream_duration != nullptr) {
1751
- const google_protobuf_Duration* duration =
1752
- envoy_config_route_v3_RouteAction_MaxStreamDuration_grpc_timeout_header_max(
1753
- max_stream_duration);
1754
- if (duration == nullptr) {
1755
- duration =
1756
- envoy_config_route_v3_RouteAction_MaxStreamDuration_max_stream_duration(
1757
- max_stream_duration);
1758
- }
1759
- if (duration != nullptr) {
1760
- route->max_stream_duration = DurationParse(duration);
1761
- }
1762
- }
1763
- }
1764
- // Get HashPolicy from RouteAction
1765
- size_t size = 0;
1766
- const envoy_config_route_v3_RouteAction_HashPolicy* const* hash_policies =
1767
- envoy_config_route_v3_RouteAction_hash_policy(route_action, &size);
1768
- for (size_t i = 0; i < size; ++i) {
1769
- const envoy_config_route_v3_RouteAction_HashPolicy* hash_policy =
1770
- hash_policies[i];
1771
- XdsApi::Route::RouteAction::HashPolicy policy;
1772
- policy.terminal =
1773
- envoy_config_route_v3_RouteAction_HashPolicy_terminal(hash_policy);
1774
- const envoy_config_route_v3_RouteAction_HashPolicy_Header* header;
1775
- const envoy_config_route_v3_RouteAction_HashPolicy_FilterState*
1776
- filter_state;
1777
- if ((header = envoy_config_route_v3_RouteAction_HashPolicy_header(
1778
- hash_policy)) != nullptr) {
1779
- policy.type = XdsApi::Route::RouteAction::HashPolicy::Type::HEADER;
1780
- policy.header_name = UpbStringToStdString(
1781
- envoy_config_route_v3_RouteAction_HashPolicy_Header_header_name(
1782
- header));
1783
- const struct envoy_type_matcher_v3_RegexMatchAndSubstitute*
1784
- regex_rewrite =
1785
- envoy_config_route_v3_RouteAction_HashPolicy_Header_regex_rewrite(
1786
- header);
1787
- if (regex_rewrite != nullptr) {
1788
- const envoy_type_matcher_v3_RegexMatcher* regex_matcher =
1789
- envoy_type_matcher_v3_RegexMatchAndSubstitute_pattern(
1790
- regex_rewrite);
1791
- if (regex_matcher == nullptr) {
1792
- gpr_log(
1793
- GPR_DEBUG,
1794
- "RouteAction HashPolicy contains policy specifier Header with "
1795
- "RegexMatchAndSubstitution but RegexMatcher pattern is "
1796
- "missing");
1797
- continue;
1798
- }
1799
- RE2::Options options;
1800
- policy.regex = absl::make_unique<RE2>(
1801
- UpbStringToStdString(
1802
- envoy_type_matcher_v3_RegexMatcher_regex(regex_matcher)),
1803
- options);
1804
- if (!policy.regex->ok()) {
1805
- gpr_log(
1806
- GPR_DEBUG,
1807
- "RouteAction HashPolicy contains policy specifier Header with "
1808
- "RegexMatchAndSubstitution but RegexMatcher pattern does not "
1809
- "compile");
1810
- continue;
1811
- }
1812
- policy.regex_substitution = UpbStringToStdString(
1813
- envoy_type_matcher_v3_RegexMatchAndSubstitute_substitution(
1814
- regex_rewrite));
1815
- }
1816
- } else if ((filter_state =
1817
- envoy_config_route_v3_RouteAction_HashPolicy_filter_state(
1818
- hash_policy)) != nullptr) {
1819
- std::string key = UpbStringToStdString(
1820
- envoy_config_route_v3_RouteAction_HashPolicy_FilterState_key(
1821
- filter_state));
1822
- if (key == "io.grpc.channel_id") {
1823
- policy.type = XdsApi::Route::RouteAction::HashPolicy::Type::CHANNEL_ID;
1824
- } else {
1825
- gpr_log(GPR_DEBUG,
1826
- "RouteAction HashPolicy contains policy specifier "
1827
- "FilterState but "
1828
- "key is not io.grpc.channel_id.");
1829
- continue;
1830
- }
1831
- } else {
1832
- gpr_log(GPR_DEBUG,
1833
- "RouteAction HashPolicy contains unsupported policy specifier.");
1834
- continue;
1835
- }
1836
- route->hash_policies.emplace_back(std::move(policy));
1837
- }
1838
- // Get retry policy
1839
- const envoy_config_route_v3_RetryPolicy* retry_policy =
1840
- envoy_config_route_v3_RouteAction_retry_policy(route_action);
1841
- if (retry_policy != nullptr) {
1842
- absl::optional<XdsApi::RetryPolicy> retry;
1843
- grpc_error_handle error = RetryPolicyParse(context, retry_policy, &retry);
1844
- if (error != GRPC_ERROR_NONE) return error;
1845
- route->retry_policy = retry;
1846
- }
1847
- return GRPC_ERROR_NONE;
1848
- }
1849
-
1850
- grpc_error_handle RouteConfigParse(
1851
- const EncodingContext& context,
1852
- const envoy_config_route_v3_RouteConfiguration* route_config,
1853
- bool /*is_v2*/, XdsApi::RdsUpdate* rds_update) {
1854
- // Get the virtual hosts.
1855
- size_t num_virtual_hosts;
1856
- const envoy_config_route_v3_VirtualHost* const* virtual_hosts =
1857
- envoy_config_route_v3_RouteConfiguration_virtual_hosts(
1858
- route_config, &num_virtual_hosts);
1859
- for (size_t i = 0; i < num_virtual_hosts; ++i) {
1860
- rds_update->virtual_hosts.emplace_back();
1861
- XdsApi::RdsUpdate::VirtualHost& vhost = rds_update->virtual_hosts.back();
1862
- // Parse domains.
1863
- size_t domain_size;
1864
- upb_strview const* domains = envoy_config_route_v3_VirtualHost_domains(
1865
- virtual_hosts[i], &domain_size);
1866
- for (size_t j = 0; j < domain_size; ++j) {
1867
- std::string domain_pattern = UpbStringToStdString(domains[j]);
1868
- if (!XdsRouting::IsValidDomainPattern(domain_pattern)) {
1869
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
1870
- absl::StrCat("Invalid domain pattern \"", domain_pattern, "\"."));
1871
- }
1872
- vhost.domains.emplace_back(std::move(domain_pattern));
1873
- }
1874
- if (vhost.domains.empty()) {
1875
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("VirtualHost has no domains");
1876
- }
1877
- // Parse typed_per_filter_config.
1878
- if (context.use_v3) {
1879
- grpc_error_handle error = ParseTypedPerFilterConfig<
1880
- envoy_config_route_v3_VirtualHost,
1881
- envoy_config_route_v3_VirtualHost_TypedPerFilterConfigEntry>(
1882
- context, virtual_hosts[i],
1883
- envoy_config_route_v3_VirtualHost_typed_per_filter_config_next,
1884
- envoy_config_route_v3_VirtualHost_TypedPerFilterConfigEntry_key,
1885
- envoy_config_route_v3_VirtualHost_TypedPerFilterConfigEntry_value,
1886
- &vhost.typed_per_filter_config);
1887
- if (error != GRPC_ERROR_NONE) return error;
1888
- }
1889
- // Parse retry policy.
1890
- absl::optional<XdsApi::RetryPolicy> virtual_host_retry_policy;
1891
- const envoy_config_route_v3_RetryPolicy* retry_policy =
1892
- envoy_config_route_v3_VirtualHost_retry_policy(virtual_hosts[i]);
1893
- if (retry_policy != nullptr) {
1894
- grpc_error_handle error =
1895
- RetryPolicyParse(context, retry_policy, &virtual_host_retry_policy);
1896
- if (error != GRPC_ERROR_NONE) return error;
1897
- }
1898
- // Parse routes.
1899
- size_t num_routes;
1900
- const envoy_config_route_v3_Route* const* routes =
1901
- envoy_config_route_v3_VirtualHost_routes(virtual_hosts[i], &num_routes);
1902
- if (num_routes < 1) {
1903
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1904
- "No route found in the virtual host.");
1905
- }
1906
- // Loop over the whole list of routes
1907
- for (size_t j = 0; j < num_routes; ++j) {
1908
- const envoy_config_route_v3_RouteMatch* match =
1909
- envoy_config_route_v3_Route_match(routes[j]);
1910
- if (match == nullptr) {
1911
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Match can't be null.");
1912
- }
1913
- size_t query_parameters_size;
1914
- static_cast<void>(envoy_config_route_v3_RouteMatch_query_parameters(
1915
- match, &query_parameters_size));
1916
- if (query_parameters_size > 0) {
1917
- continue;
1918
- }
1919
- XdsApi::Route route;
1920
- bool ignore_route = false;
1921
- grpc_error_handle error =
1922
- RoutePathMatchParse(match, &route, &ignore_route);
1923
- if (error != GRPC_ERROR_NONE) return error;
1924
- if (ignore_route) continue;
1925
- error = RouteHeaderMatchersParse(match, &route);
1926
- if (error != GRPC_ERROR_NONE) return error;
1927
- error = RouteRuntimeFractionParse(match, &route);
1928
- if (error != GRPC_ERROR_NONE) return error;
1929
- if (envoy_config_route_v3_Route_has_route(routes[j])) {
1930
- route.action.emplace<XdsApi::Route::RouteAction>();
1931
- auto& route_action =
1932
- absl::get<XdsApi::Route::RouteAction>(route.action);
1933
- error =
1934
- RouteActionParse(context, routes[j], &route_action, &ignore_route);
1935
- if (error != GRPC_ERROR_NONE) return error;
1936
- if (ignore_route) continue;
1937
- if (route_action.retry_policy == absl::nullopt &&
1938
- retry_policy != nullptr) {
1939
- route_action.retry_policy = virtual_host_retry_policy;
1940
- }
1941
- } else if (envoy_config_route_v3_Route_has_non_forwarding_action(
1942
- routes[j])) {
1943
- route.action.emplace<XdsApi::Route::NonForwardingAction>();
1944
- }
1945
- if (context.use_v3) {
1946
- grpc_error_handle error = ParseTypedPerFilterConfig<
1947
- envoy_config_route_v3_Route,
1948
- envoy_config_route_v3_Route_TypedPerFilterConfigEntry>(
1949
- context, routes[j],
1950
- envoy_config_route_v3_Route_typed_per_filter_config_next,
1951
- envoy_config_route_v3_Route_TypedPerFilterConfigEntry_key,
1952
- envoy_config_route_v3_Route_TypedPerFilterConfigEntry_value,
1953
- &route.typed_per_filter_config);
1954
- if (error != GRPC_ERROR_NONE) return error;
1955
- }
1956
- vhost.routes.emplace_back(std::move(route));
1957
- }
1958
- if (vhost.routes.empty()) {
1959
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("No valid routes specified.");
1960
- }
1961
- }
1962
- return GRPC_ERROR_NONE;
1963
- }
1964
-
1965
- // CertificateProviderInstance is deprecated but we are still supporting it for
1966
- // backward compatibility reasons. Note that we still parse the data into the
1967
- // same CertificateProviderPluginInstance struct since the fields are the same.
1968
- // TODO(yashykt): Remove this once we stop supporting the old way of fetching
1969
- // certificate provider instances.
1970
- grpc_error_handle CertificateProviderInstanceParse(
1971
- const EncodingContext& context,
1972
- const envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_CertificateProviderInstance*
1973
- certificate_provider_instance_proto,
1974
- XdsApi::CommonTlsContext::CertificateProviderPluginInstance*
1975
- certificate_provider_plugin_instance) {
1976
- *certificate_provider_plugin_instance = {
1977
- UpbStringToStdString(
1978
- envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_CertificateProviderInstance_instance_name(
1979
- certificate_provider_instance_proto)),
1980
- UpbStringToStdString(
1981
- envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_CertificateProviderInstance_certificate_name(
1982
- certificate_provider_instance_proto))};
1983
- if (context.certificate_provider_definition_map->find(
1984
- certificate_provider_plugin_instance->instance_name) ==
1985
- context.certificate_provider_definition_map->end()) {
1986
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
1987
- absl::StrCat("Unrecognized certificate provider instance name: ",
1988
- certificate_provider_plugin_instance->instance_name));
1989
- }
1990
- return GRPC_ERROR_NONE;
1991
- }
1992
-
1993
- grpc_error_handle CertificateProviderPluginInstanceParse(
1994
- const EncodingContext& context,
1995
- const envoy_extensions_transport_sockets_tls_v3_CertificateProviderPluginInstance*
1996
- certificate_provider_plugin_instance_proto,
1997
- XdsApi::CommonTlsContext::CertificateProviderPluginInstance*
1998
- certificate_provider_plugin_instance) {
1999
- *certificate_provider_plugin_instance = {
2000
- UpbStringToStdString(
2001
- envoy_extensions_transport_sockets_tls_v3_CertificateProviderPluginInstance_instance_name(
2002
- certificate_provider_plugin_instance_proto)),
2003
- UpbStringToStdString(
2004
- envoy_extensions_transport_sockets_tls_v3_CertificateProviderPluginInstance_certificate_name(
2005
- certificate_provider_plugin_instance_proto))};
2006
- if (context.certificate_provider_definition_map->find(
2007
- certificate_provider_plugin_instance->instance_name) ==
2008
- context.certificate_provider_definition_map->end()) {
2009
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
2010
- absl::StrCat("Unrecognized certificate provider instance name: ",
2011
- certificate_provider_plugin_instance->instance_name));
2012
- }
2013
- return GRPC_ERROR_NONE;
2014
- }
2015
-
2016
- grpc_error_handle CertificateValidationContextParse(
2017
- const EncodingContext& context,
2018
- const envoy_extensions_transport_sockets_tls_v3_CertificateValidationContext*
2019
- certificate_validation_context_proto,
2020
- XdsApi::CommonTlsContext::CertificateValidationContext*
2021
- certificate_validation_context) {
2022
- std::vector<grpc_error_handle> errors;
2023
- size_t len = 0;
2024
- auto* subject_alt_names_matchers =
2025
- envoy_extensions_transport_sockets_tls_v3_CertificateValidationContext_match_subject_alt_names(
2026
- certificate_validation_context_proto, &len);
2027
- for (size_t i = 0; i < len; ++i) {
2028
- StringMatcher::Type type;
2029
- std::string matcher;
2030
- if (envoy_type_matcher_v3_StringMatcher_has_exact(
2031
- subject_alt_names_matchers[i])) {
2032
- type = StringMatcher::Type::kExact;
2033
- matcher = UpbStringToStdString(envoy_type_matcher_v3_StringMatcher_exact(
2034
- subject_alt_names_matchers[i]));
2035
- } else if (envoy_type_matcher_v3_StringMatcher_has_prefix(
2036
- subject_alt_names_matchers[i])) {
2037
- type = StringMatcher::Type::kPrefix;
2038
- matcher = UpbStringToStdString(envoy_type_matcher_v3_StringMatcher_prefix(
2039
- subject_alt_names_matchers[i]));
2040
- } else if (envoy_type_matcher_v3_StringMatcher_has_suffix(
2041
- subject_alt_names_matchers[i])) {
2042
- type = StringMatcher::Type::kSuffix;
2043
- matcher = UpbStringToStdString(envoy_type_matcher_v3_StringMatcher_suffix(
2044
- subject_alt_names_matchers[i]));
2045
- } else if (envoy_type_matcher_v3_StringMatcher_has_contains(
2046
- subject_alt_names_matchers[i])) {
2047
- type = StringMatcher::Type::kContains;
2048
- matcher =
2049
- UpbStringToStdString(envoy_type_matcher_v3_StringMatcher_contains(
2050
- subject_alt_names_matchers[i]));
2051
- } else if (envoy_type_matcher_v3_StringMatcher_has_safe_regex(
2052
- subject_alt_names_matchers[i])) {
2053
- type = StringMatcher::Type::kSafeRegex;
2054
- auto* regex_matcher = envoy_type_matcher_v3_StringMatcher_safe_regex(
2055
- subject_alt_names_matchers[i]);
2056
- matcher = UpbStringToStdString(
2057
- envoy_type_matcher_v3_RegexMatcher_regex(regex_matcher));
2058
- } else {
2059
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2060
- "Invalid StringMatcher specified"));
2061
- continue;
2062
- }
2063
- bool ignore_case = envoy_type_matcher_v3_StringMatcher_ignore_case(
2064
- subject_alt_names_matchers[i]);
2065
- absl::StatusOr<StringMatcher> string_matcher =
2066
- StringMatcher::Create(type, matcher,
2067
- /*case_sensitive=*/!ignore_case);
2068
- if (!string_matcher.ok()) {
2069
- errors.push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING(
2070
- absl::StrCat("string matcher: ", string_matcher.status().message())));
2071
- continue;
2072
- }
2073
- if (type == StringMatcher::Type::kSafeRegex && ignore_case) {
2074
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2075
- "StringMatcher: ignore_case has no effect for SAFE_REGEX."));
2076
- continue;
2077
- }
2078
- certificate_validation_context->match_subject_alt_names.push_back(
2079
- std::move(string_matcher.value()));
2080
- }
2081
- auto* ca_certificate_provider_instance =
2082
- envoy_extensions_transport_sockets_tls_v3_CertificateValidationContext_ca_certificate_provider_instance(
2083
- certificate_validation_context_proto);
2084
- if (ca_certificate_provider_instance != nullptr) {
2085
- grpc_error_handle error = CertificateProviderPluginInstanceParse(
2086
- context, ca_certificate_provider_instance,
2087
- &certificate_validation_context->ca_certificate_provider_instance);
2088
- if (error != GRPC_ERROR_NONE) errors.push_back(error);
2089
- }
2090
- if (envoy_extensions_transport_sockets_tls_v3_CertificateValidationContext_verify_certificate_spki(
2091
- certificate_validation_context_proto, nullptr) != nullptr) {
2092
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2093
- "CertificateValidationContext: verify_certificate_spki "
2094
- "unsupported"));
2095
- }
2096
- if (envoy_extensions_transport_sockets_tls_v3_CertificateValidationContext_verify_certificate_hash(
2097
- certificate_validation_context_proto, nullptr) != nullptr) {
2098
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2099
- "CertificateValidationContext: verify_certificate_hash "
2100
- "unsupported"));
2101
- }
2102
- auto* require_signed_certificate_timestamp =
2103
- envoy_extensions_transport_sockets_tls_v3_CertificateValidationContext_require_signed_certificate_timestamp(
2104
- certificate_validation_context_proto);
2105
- if (require_signed_certificate_timestamp != nullptr &&
2106
- google_protobuf_BoolValue_value(require_signed_certificate_timestamp)) {
2107
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2108
- "CertificateValidationContext: "
2109
- "require_signed_certificate_timestamp unsupported"));
2110
- }
2111
- if (envoy_extensions_transport_sockets_tls_v3_CertificateValidationContext_has_crl(
2112
- certificate_validation_context_proto)) {
2113
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2114
- "CertificateValidationContext: crl unsupported"));
2115
- }
2116
- if (envoy_extensions_transport_sockets_tls_v3_CertificateValidationContext_has_custom_validator_config(
2117
- certificate_validation_context_proto)) {
2118
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2119
- "CertificateValidationContext: custom_validator_config "
2120
- "unsupported"));
2121
- }
2122
- return GRPC_ERROR_CREATE_FROM_VECTOR(
2123
- "Error parsing CertificateValidationContext", &errors);
2124
- }
2125
-
2126
- grpc_error_handle CommonTlsContextParse(
2127
- const EncodingContext& context,
2128
- const envoy_extensions_transport_sockets_tls_v3_CommonTlsContext*
2129
- common_tls_context_proto,
2130
- XdsApi::CommonTlsContext* common_tls_context) {
2131
- std::vector<grpc_error_handle> errors;
2132
- // The validation context is derived from the oneof in
2133
- // 'validation_context_type'. 'validation_context_sds_secret_config' is not
2134
- // supported.
2135
- auto* combined_validation_context =
2136
- envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_combined_validation_context(
2137
- common_tls_context_proto);
2138
- if (combined_validation_context != nullptr) {
2139
- auto* default_validation_context =
2140
- envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_CombinedCertificateValidationContext_default_validation_context(
2141
- combined_validation_context);
2142
- if (default_validation_context != nullptr) {
2143
- grpc_error_handle error = CertificateValidationContextParse(
2144
- context, default_validation_context,
2145
- &common_tls_context->certificate_validation_context);
2146
- if (error != GRPC_ERROR_NONE) errors.push_back(error);
2147
- }
2148
- // If after parsing default_validation_context,
2149
- // common_tls_context->certificate_validation_context.ca_certificate_provider_instance
2150
- // is empty, fall back onto
2151
- // 'validation_context_certificate_provider_instance' inside
2152
- // 'combined_validation_context'. Note that this way of fetching root
2153
- // certificates is deprecated and will be removed in the future.
2154
- // TODO(yashykt): Remove this once it's no longer needed.
2155
- auto* validation_context_certificate_provider_instance =
2156
- envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_CombinedCertificateValidationContext_validation_context_certificate_provider_instance(
2157
- combined_validation_context);
2158
- if (common_tls_context->certificate_validation_context
2159
- .ca_certificate_provider_instance.Empty() &&
2160
- validation_context_certificate_provider_instance != nullptr) {
2161
- grpc_error_handle error = CertificateProviderInstanceParse(
2162
- context, validation_context_certificate_provider_instance,
2163
- &common_tls_context->certificate_validation_context
2164
- .ca_certificate_provider_instance);
2165
- if (error != GRPC_ERROR_NONE) errors.push_back(error);
2166
- }
2167
- } else {
2168
- auto* validation_context =
2169
- envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_validation_context(
2170
- common_tls_context_proto);
2171
- if (validation_context != nullptr) {
2172
- grpc_error_handle error = CertificateValidationContextParse(
2173
- context, validation_context,
2174
- &common_tls_context->certificate_validation_context);
2175
- if (error != GRPC_ERROR_NONE) errors.push_back(error);
2176
- } else if (
2177
- envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_has_validation_context_sds_secret_config(
2178
- common_tls_context_proto)) {
2179
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2180
- "validation_context_sds_secret_config unsupported"));
2181
- }
2182
- }
2183
- auto* tls_certificate_provider_instance =
2184
- envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_tls_certificate_provider_instance(
2185
- common_tls_context_proto);
2186
- if (tls_certificate_provider_instance != nullptr) {
2187
- grpc_error_handle error = CertificateProviderPluginInstanceParse(
2188
- context, tls_certificate_provider_instance,
2189
- &common_tls_context->tls_certificate_provider_instance);
2190
- if (error != GRPC_ERROR_NONE) errors.push_back(error);
2191
- } else {
2192
- // Fall back onto 'tls_certificate_certificate_provider_instance'. Note that
2193
- // this way of fetching identity certificates is deprecated and will be
2194
- // removed in the future.
2195
- // TODO(yashykt): Remove this once it's no longer needed.
2196
- auto* tls_certificate_certificate_provider_instance =
2197
- envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_tls_certificate_certificate_provider_instance(
2198
- common_tls_context_proto);
2199
- if (tls_certificate_certificate_provider_instance != nullptr) {
2200
- grpc_error_handle error = CertificateProviderInstanceParse(
2201
- context, tls_certificate_certificate_provider_instance,
2202
- &common_tls_context->tls_certificate_provider_instance);
2203
- if (error != GRPC_ERROR_NONE) errors.push_back(error);
2204
- } else {
2205
- if (envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_has_tls_certificates(
2206
- common_tls_context_proto)) {
2207
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2208
- "tls_certificates unsupported"));
2209
- }
2210
- if (envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_has_tls_certificate_sds_secret_configs(
2211
- common_tls_context_proto)) {
2212
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2213
- "tls_certificate_sds_secret_configs unsupported"));
2214
- }
2215
- }
2216
- }
2217
- if (envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_has_tls_params(
2218
- common_tls_context_proto)) {
2219
- errors.push_back(
2220
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("tls_params unsupported"));
2221
- }
2222
- if (envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_has_custom_handshaker(
2223
- common_tls_context_proto)) {
2224
- errors.push_back(
2225
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("custom_handshaker unsupported"));
2226
- }
2227
- return GRPC_ERROR_CREATE_FROM_VECTOR("Error parsing CommonTlsContext",
2228
- &errors);
2229
- }
2230
-
2231
- grpc_error_handle HttpConnectionManagerParse(
2232
- bool is_client, const EncodingContext& context,
2233
- const envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager*
2234
- http_connection_manager_proto,
2235
- bool is_v2,
2236
- XdsApi::LdsUpdate::HttpConnectionManager* http_connection_manager) {
2237
- MaybeLogHttpConnectionManager(context, http_connection_manager_proto);
2238
- // Obtain max_stream_duration from Http Protocol Options.
2239
- const envoy_config_core_v3_HttpProtocolOptions* options =
2240
- envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_common_http_protocol_options(
2241
- http_connection_manager_proto);
2242
- if (options != nullptr) {
2243
- const google_protobuf_Duration* duration =
2244
- envoy_config_core_v3_HttpProtocolOptions_max_stream_duration(options);
2245
- if (duration != nullptr) {
2246
- http_connection_manager->http_max_stream_duration =
2247
- DurationParse(duration);
2248
- }
2249
- }
2250
- // Parse filters.
2251
- if (!is_v2) {
2252
- size_t num_filters = 0;
2253
- const auto* http_filters =
2254
- envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_http_filters(
2255
- http_connection_manager_proto, &num_filters);
2256
- std::set<absl::string_view> names_seen;
2257
- for (size_t i = 0; i < num_filters; ++i) {
2258
- const auto* http_filter = http_filters[i];
2259
- absl::string_view name = UpbStringToAbsl(
2260
- envoy_extensions_filters_network_http_connection_manager_v3_HttpFilter_name(
2261
- http_filter));
2262
- if (name.empty()) {
2263
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
2264
- absl::StrCat("empty filter name at index ", i));
2265
- }
2266
- if (names_seen.find(name) != names_seen.end()) {
2267
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
2268
- absl::StrCat("duplicate HTTP filter name: ", name));
2269
- }
2270
- names_seen.insert(name);
2271
- const bool is_optional =
2272
- envoy_extensions_filters_network_http_connection_manager_v3_HttpFilter_is_optional(
2273
- http_filter);
2274
- const google_protobuf_Any* any =
2275
- envoy_extensions_filters_network_http_connection_manager_v3_HttpFilter_typed_config(
2276
- http_filter);
2277
- if (any == nullptr) {
2278
- if (is_optional) continue;
2279
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
2280
- absl::StrCat("no filter config specified for filter name ", name));
2281
- }
2282
- absl::string_view filter_type;
2283
- grpc_error_handle error =
2284
- ExtractHttpFilterTypeName(context, any, &filter_type);
2285
- if (error != GRPC_ERROR_NONE) return error;
2286
- const XdsHttpFilterImpl* filter_impl =
2287
- XdsHttpFilterRegistry::GetFilterForType(filter_type);
2288
- if (filter_impl == nullptr) {
2289
- if (is_optional) continue;
2290
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
2291
- absl::StrCat("no filter registered for config type ", filter_type));
2292
- }
2293
- if ((is_client && !filter_impl->IsSupportedOnClients()) ||
2294
- (!is_client && !filter_impl->IsSupportedOnServers())) {
2295
- if (is_optional) continue;
2296
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
2297
- absl::StrFormat("Filter %s is not supported on %s", filter_type,
2298
- is_client ? "clients" : "servers"));
2299
- }
2300
- absl::StatusOr<XdsHttpFilterImpl::FilterConfig> filter_config =
2301
- filter_impl->GenerateFilterConfig(google_protobuf_Any_value(any),
2302
- context.arena);
2303
- if (!filter_config.ok()) {
2304
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat(
2305
- "filter config for type ", filter_type,
2306
- " failed to parse: ", filter_config.status().ToString()));
2307
- }
2308
- http_connection_manager->http_filters.emplace_back(
2309
- XdsApi::LdsUpdate::HttpConnectionManager::HttpFilter{
2310
- std::string(name), std::move(*filter_config)});
2311
- }
2312
- if (http_connection_manager->http_filters.empty()) {
2313
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2314
- "Expected at least one HTTP filter");
2315
- }
2316
- // Make sure that the last filter is terminal and non-last filters are
2317
- // non-terminal. Note that this check is being performed in a separate loop
2318
- // to take care of the case where there are two terminal filters in the list
2319
- // out of which only one gets added in the final list.
2320
- for (const auto& http_filter : http_connection_manager->http_filters) {
2321
- const XdsHttpFilterImpl* filter_impl =
2322
- XdsHttpFilterRegistry::GetFilterForType(
2323
- http_filter.config.config_proto_type_name);
2324
- if (&http_filter != &http_connection_manager->http_filters.back()) {
2325
- // Filters before the last filter must not be terminal.
2326
- if (filter_impl->IsTerminalFilter()) {
2327
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
2328
- absl::StrCat("terminal filter for config type ",
2329
- http_filter.config.config_proto_type_name,
2330
- " must be the last filter in the chain"));
2331
- }
2332
- } else {
2333
- // The last filter must be terminal.
2334
- if (!filter_impl->IsTerminalFilter()) {
2335
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
2336
- absl::StrCat("non-terminal filter for config type ",
2337
- http_filter.config.config_proto_type_name,
2338
- " is the last filter in the chain"));
2339
- }
2340
- }
2341
- }
2342
- } else {
2343
- // If using a v2 config, we just hard-code a list containing only the
2344
- // router filter without actually looking at the config. This ensures
2345
- // that the right thing happens in the xds resolver without having
2346
- // to expose whether the resource we received was v2 or v3.
2347
- http_connection_manager->http_filters.emplace_back(
2348
- XdsApi::LdsUpdate::HttpConnectionManager::HttpFilter{
2349
- "router", {kXdsHttpRouterFilterConfigName, Json()}});
2350
- }
2351
- // Guarding parsing of RouteConfig on the server side with the environmental
2352
- // variable since that's the first feature on the server side that will be
2353
- // using this.
2354
- if (is_client || XdsRbacEnabled()) {
2355
- // Found inlined route_config. Parse it to find the cluster_name.
2356
- if (envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_has_route_config(
2357
- http_connection_manager_proto)) {
2358
- const envoy_config_route_v3_RouteConfiguration* route_config =
2359
- envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_route_config(
2360
- http_connection_manager_proto);
2361
- XdsApi::RdsUpdate rds_update;
2362
- grpc_error_handle error =
2363
- RouteConfigParse(context, route_config, is_v2, &rds_update);
2364
- if (error != GRPC_ERROR_NONE) return error;
2365
- http_connection_manager->rds_update = std::move(rds_update);
2366
- return GRPC_ERROR_NONE;
2367
- }
2368
- // Validate that RDS must be used to get the route_config dynamically.
2369
- const envoy_extensions_filters_network_http_connection_manager_v3_Rds* rds =
2370
- envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_rds(
2371
- http_connection_manager_proto);
2372
- if (rds == nullptr) {
2373
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2374
- "HttpConnectionManager neither has inlined route_config nor RDS.");
2375
- }
2376
- // Check that the ConfigSource specifies ADS.
2377
- const envoy_config_core_v3_ConfigSource* config_source =
2378
- envoy_extensions_filters_network_http_connection_manager_v3_Rds_config_source(
2379
- rds);
2380
- if (config_source == nullptr) {
2381
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2382
- "HttpConnectionManager missing config_source for RDS.");
2383
- }
2384
- if (!envoy_config_core_v3_ConfigSource_has_ads(config_source)) {
2385
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2386
- "HttpConnectionManager ConfigSource for RDS does not specify ADS.");
2387
- }
2388
- // Get the route_config_name.
2389
- http_connection_manager->route_config_name = UpbStringToStdString(
2390
- envoy_extensions_filters_network_http_connection_manager_v3_Rds_route_config_name(
2391
- rds));
2392
- }
2393
- return GRPC_ERROR_NONE;
2394
- }
2395
-
2396
- grpc_error_handle LdsResourceParseClient(
2397
- const EncodingContext& context,
2398
- const envoy_config_listener_v3_ApiListener* api_listener, bool is_v2,
2399
- XdsApi::LdsUpdate* lds_update) {
2400
- lds_update->type = XdsApi::LdsUpdate::ListenerType::kHttpApiListener;
2401
- const upb_strview encoded_api_listener = google_protobuf_Any_value(
2402
- envoy_config_listener_v3_ApiListener_api_listener(api_listener));
2403
- const auto* http_connection_manager =
2404
- envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_parse(
2405
- encoded_api_listener.data, encoded_api_listener.size, context.arena);
2406
- if (http_connection_manager == nullptr) {
2407
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2408
- "Could not parse HttpConnectionManager config from ApiListener");
2409
- }
2410
- return HttpConnectionManagerParse(true /* is_client */, context,
2411
- http_connection_manager, is_v2,
2412
- &lds_update->http_connection_manager);
2413
- }
2414
-
2415
- grpc_error_handle DownstreamTlsContextParse(
2416
- const EncodingContext& context,
2417
- const envoy_config_core_v3_TransportSocket* transport_socket,
2418
- XdsApi::DownstreamTlsContext* downstream_tls_context) {
2419
- absl::string_view name = UpbStringToAbsl(
2420
- envoy_config_core_v3_TransportSocket_name(transport_socket));
2421
- if (name != "envoy.transport_sockets.tls") {
2422
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
2423
- absl::StrCat("Unrecognized transport socket: ", name));
2424
- }
2425
- auto* typed_config =
2426
- envoy_config_core_v3_TransportSocket_typed_config(transport_socket);
2427
- std::vector<grpc_error_handle> errors;
2428
- if (typed_config != nullptr) {
2429
- const upb_strview encoded_downstream_tls_context =
2430
- google_protobuf_Any_value(typed_config);
2431
- auto* downstream_tls_context_proto =
2432
- envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_parse(
2433
- encoded_downstream_tls_context.data,
2434
- encoded_downstream_tls_context.size, context.arena);
2435
- if (downstream_tls_context_proto == nullptr) {
2436
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2437
- "Can't decode downstream tls context.");
2438
- }
2439
- auto* common_tls_context =
2440
- envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_common_tls_context(
2441
- downstream_tls_context_proto);
2442
- if (common_tls_context != nullptr) {
2443
- grpc_error_handle error =
2444
- CommonTlsContextParse(context, common_tls_context,
2445
- &downstream_tls_context->common_tls_context);
2446
- if (error != GRPC_ERROR_NONE) errors.push_back(error);
2447
- }
2448
- auto* require_client_certificate =
2449
- envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_require_client_certificate(
2450
- downstream_tls_context_proto);
2451
- if (require_client_certificate != nullptr) {
2452
- downstream_tls_context->require_client_certificate =
2453
- google_protobuf_BoolValue_value(require_client_certificate);
2454
- }
2455
- auto* require_sni =
2456
- envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_require_sni(
2457
- downstream_tls_context_proto);
2458
- if (require_sni != nullptr &&
2459
- google_protobuf_BoolValue_value(require_sni)) {
2460
- errors.push_back(
2461
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("require_sni: unsupported"));
2462
- }
2463
- if (envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_ocsp_staple_policy(
2464
- downstream_tls_context_proto) !=
2465
- envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_LENIENT_STAPLING) {
2466
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2467
- "ocsp_staple_policy: Only LENIENT_STAPLING supported"));
2468
- }
2469
- }
2470
- if (downstream_tls_context->common_tls_context
2471
- .tls_certificate_provider_instance.instance_name.empty()) {
2472
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2473
- "TLS configuration provided but no "
2474
- "tls_certificate_provider_instance found."));
2475
- }
2476
- if (downstream_tls_context->require_client_certificate &&
2477
- downstream_tls_context->common_tls_context.certificate_validation_context
2478
- .ca_certificate_provider_instance.instance_name.empty()) {
2479
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2480
- "TLS configuration requires client certificates but no certificate "
2481
- "provider instance specified for validation."));
2482
- }
2483
- if (!downstream_tls_context->common_tls_context.certificate_validation_context
2484
- .match_subject_alt_names.empty()) {
2485
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2486
- "match_subject_alt_names not supported on servers"));
2487
- }
2488
- return GRPC_ERROR_CREATE_FROM_VECTOR("Error parsing DownstreamTlsContext",
2489
- &errors);
2490
- }
2491
-
2492
- grpc_error_handle CidrRangeParse(
2493
- const envoy_config_core_v3_CidrRange* cidr_range_proto,
2494
- XdsApi::LdsUpdate::FilterChainMap::CidrRange* cidr_range) {
2495
- std::string address_prefix = UpbStringToStdString(
2496
- envoy_config_core_v3_CidrRange_address_prefix(cidr_range_proto));
2497
- grpc_error_handle error =
2498
- grpc_string_to_sockaddr(&cidr_range->address, address_prefix.c_str(), 0);
2499
- if (error != GRPC_ERROR_NONE) return error;
2500
- cidr_range->prefix_len = 0;
2501
- auto* prefix_len_proto =
2502
- envoy_config_core_v3_CidrRange_prefix_len(cidr_range_proto);
2503
- if (prefix_len_proto != nullptr) {
2504
- cidr_range->prefix_len = std::min(
2505
- google_protobuf_UInt32Value_value(prefix_len_proto),
2506
- (reinterpret_cast<const grpc_sockaddr*>(cidr_range->address.addr))
2507
- ->sa_family == GRPC_AF_INET
2508
- ? uint32_t(32)
2509
- : uint32_t(128));
2510
- }
2511
- // Normalize the network address by masking it with prefix_len
2512
- grpc_sockaddr_mask_bits(&cidr_range->address, cidr_range->prefix_len);
2513
- return GRPC_ERROR_NONE;
2514
- }
2515
-
2516
- grpc_error_handle FilterChainMatchParse(
2517
- const envoy_config_listener_v3_FilterChainMatch* filter_chain_match_proto,
2518
- FilterChain::FilterChainMatch* filter_chain_match) {
2519
- auto* destination_port =
2520
- envoy_config_listener_v3_FilterChainMatch_destination_port(
2521
- filter_chain_match_proto);
2522
- if (destination_port != nullptr) {
2523
- filter_chain_match->destination_port =
2524
- google_protobuf_UInt32Value_value(destination_port);
2525
- }
2526
- size_t size = 0;
2527
- auto* prefix_ranges = envoy_config_listener_v3_FilterChainMatch_prefix_ranges(
2528
- filter_chain_match_proto, &size);
2529
- filter_chain_match->prefix_ranges.reserve(size);
2530
- for (size_t i = 0; i < size; i++) {
2531
- XdsApi::LdsUpdate::FilterChainMap::CidrRange cidr_range;
2532
- grpc_error_handle error = CidrRangeParse(prefix_ranges[i], &cidr_range);
2533
- if (error != GRPC_ERROR_NONE) return error;
2534
- filter_chain_match->prefix_ranges.push_back(cidr_range);
2535
- }
2536
- filter_chain_match->source_type =
2537
- static_cast<XdsApi::LdsUpdate::FilterChainMap::ConnectionSourceType>(
2538
- envoy_config_listener_v3_FilterChainMatch_source_type(
2539
- filter_chain_match_proto));
2540
- auto* source_prefix_ranges =
2541
- envoy_config_listener_v3_FilterChainMatch_source_prefix_ranges(
2542
- filter_chain_match_proto, &size);
2543
- filter_chain_match->source_prefix_ranges.reserve(size);
2544
- for (size_t i = 0; i < size; i++) {
2545
- XdsApi::LdsUpdate::FilterChainMap::CidrRange cidr_range;
2546
- grpc_error_handle error =
2547
- CidrRangeParse(source_prefix_ranges[i], &cidr_range);
2548
- if (error != GRPC_ERROR_NONE) return error;
2549
- filter_chain_match->source_prefix_ranges.push_back(cidr_range);
2550
- }
2551
- auto* source_ports = envoy_config_listener_v3_FilterChainMatch_source_ports(
2552
- filter_chain_match_proto, &size);
2553
- filter_chain_match->source_ports.reserve(size);
2554
- for (size_t i = 0; i < size; i++) {
2555
- filter_chain_match->source_ports.push_back(source_ports[i]);
2556
- }
2557
- auto* server_names = envoy_config_listener_v3_FilterChainMatch_server_names(
2558
- filter_chain_match_proto, &size);
2559
- for (size_t i = 0; i < size; i++) {
2560
- filter_chain_match->server_names.push_back(
2561
- UpbStringToStdString(server_names[i]));
2562
- }
2563
- filter_chain_match->transport_protocol = UpbStringToStdString(
2564
- envoy_config_listener_v3_FilterChainMatch_transport_protocol(
2565
- filter_chain_match_proto));
2566
- auto* application_protocols =
2567
- envoy_config_listener_v3_FilterChainMatch_application_protocols(
2568
- filter_chain_match_proto, &size);
2569
- for (size_t i = 0; i < size; i++) {
2570
- filter_chain_match->application_protocols.push_back(
2571
- UpbStringToStdString(application_protocols[i]));
2572
- }
2573
- return GRPC_ERROR_NONE;
2574
- }
2575
-
2576
- grpc_error_handle FilterChainParse(
2577
- const EncodingContext& context,
2578
- const envoy_config_listener_v3_FilterChain* filter_chain_proto, bool is_v2,
2579
- FilterChain* filter_chain) {
2580
- std::vector<grpc_error_handle> errors;
2581
- auto* filter_chain_match =
2582
- envoy_config_listener_v3_FilterChain_filter_chain_match(
2583
- filter_chain_proto);
2584
- if (filter_chain_match != nullptr) {
2585
- grpc_error_handle error = FilterChainMatchParse(
2586
- filter_chain_match, &filter_chain->filter_chain_match);
2587
- if (error != GRPC_ERROR_NONE) errors.push_back(error);
2588
- }
2589
- filter_chain->filter_chain_data =
2590
- std::make_shared<XdsApi::LdsUpdate::FilterChainData>();
2591
- // Parse the filters list. Currently we only support HttpConnectionManager.
2592
- size_t size = 0;
2593
- auto* filters =
2594
- envoy_config_listener_v3_FilterChain_filters(filter_chain_proto, &size);
2595
- if (size != 1) {
2596
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2597
- "FilterChain should have exactly one filter: HttpConnectionManager; no "
2598
- "other filter is supported at the moment"));
2599
- } else {
2600
- auto* typed_config =
2601
- envoy_config_listener_v3_Filter_typed_config(filters[0]);
2602
- if (typed_config == nullptr) {
2603
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2604
- "No typed_config found in filter."));
2605
- } else {
2606
- absl::string_view type_url =
2607
- UpbStringToAbsl(google_protobuf_Any_type_url(typed_config));
2608
- if (type_url !=
2609
- "type.googleapis.com/"
2610
- "envoy.extensions.filters.network.http_connection_manager.v3."
2611
- "HttpConnectionManager") {
2612
- errors.push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING(
2613
- absl::StrCat("Unsupported filter type ", type_url)));
2614
- } else {
2615
- const upb_strview encoded_http_connection_manager =
2616
- google_protobuf_Any_value(typed_config);
2617
- const auto* http_connection_manager =
2618
- envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_parse(
2619
- encoded_http_connection_manager.data,
2620
- encoded_http_connection_manager.size, context.arena);
2621
- if (http_connection_manager == nullptr) {
2622
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2623
- "Could not parse HttpConnectionManager config from filter "
2624
- "typed_config"));
2625
- } else {
2626
- grpc_error_handle error = HttpConnectionManagerParse(
2627
- false /* is_client */, context, http_connection_manager, is_v2,
2628
- &filter_chain->filter_chain_data->http_connection_manager);
2629
- if (error != GRPC_ERROR_NONE) errors.push_back(error);
2630
- }
2631
- }
2632
- }
2633
- }
2634
- auto* transport_socket =
2635
- envoy_config_listener_v3_FilterChain_transport_socket(filter_chain_proto);
2636
- if (transport_socket != nullptr) {
2637
- grpc_error_handle error = DownstreamTlsContextParse(
2638
- context, transport_socket,
2639
- &filter_chain->filter_chain_data->downstream_tls_context);
2640
- if (error != GRPC_ERROR_NONE) errors.push_back(error);
2641
- }
2642
- return GRPC_ERROR_CREATE_FROM_VECTOR("Error parsing FilterChain", &errors);
2643
- }
2644
-
2645
- grpc_error_handle AddressParse(
2646
- const envoy_config_core_v3_Address* address_proto, std::string* address) {
2647
- const auto* socket_address =
2648
- envoy_config_core_v3_Address_socket_address(address_proto);
2649
- if (socket_address == nullptr) {
2650
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2651
- "Address does not have socket_address");
2652
- }
2653
- if (envoy_config_core_v3_SocketAddress_protocol(socket_address) !=
2654
- envoy_config_core_v3_SocketAddress_TCP) {
2655
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2656
- "SocketAddress protocol is not TCP");
2657
- }
2658
- uint32_t port = envoy_config_core_v3_SocketAddress_port_value(socket_address);
2659
- if (port > 65535) {
2660
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Invalid port");
2661
- }
2662
- *address = JoinHostPort(
2663
- UpbStringToAbsl(
2664
- envoy_config_core_v3_SocketAddress_address(socket_address)),
2665
- port);
2666
- return GRPC_ERROR_NONE;
2667
- }
2668
-
2669
- // An intermediate map for filter chains that we create to validate the list of
2670
- // filter chains received from the control plane and to finally create
2671
- // XdsApi::LdsUpdate::FilterChainMap
2672
- struct InternalFilterChainMap {
2673
- using SourceIpMap =
2674
- std::map<std::string, XdsApi::LdsUpdate::FilterChainMap::SourceIp>;
2675
- using ConnectionSourceTypesArray = std::array<SourceIpMap, 3>;
2676
- struct DestinationIp {
2677
- absl::optional<XdsApi::LdsUpdate::FilterChainMap::CidrRange> prefix_range;
2678
- bool transport_protocol_raw_buffer_provided = false;
2679
- ConnectionSourceTypesArray source_types_array;
2680
- };
2681
- using DestinationIpMap = std::map<std::string, DestinationIp>;
2682
- DestinationIpMap destination_ip_map;
2683
- };
2684
-
2685
- grpc_error_handle AddFilterChainDataForSourcePort(
2686
- const FilterChain& filter_chain,
2687
- XdsApi::LdsUpdate::FilterChainMap::SourcePortsMap* ports_map,
2688
- uint32_t port) {
2689
- auto insert_result = ports_map->emplace(
2690
- port, XdsApi::LdsUpdate::FilterChainMap::FilterChainDataSharedPtr{
2691
- filter_chain.filter_chain_data});
2692
- if (!insert_result.second) {
2693
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat(
2694
- "Duplicate matching rules detected when adding filter chain: ",
2695
- filter_chain.filter_chain_match.ToString()));
2696
- }
2697
- return GRPC_ERROR_NONE;
2698
- }
2699
-
2700
- grpc_error_handle AddFilterChainDataForSourcePorts(
2701
- const FilterChain& filter_chain,
2702
- XdsApi::LdsUpdate::FilterChainMap::SourcePortsMap* ports_map) {
2703
- if (filter_chain.filter_chain_match.source_ports.empty()) {
2704
- return AddFilterChainDataForSourcePort(filter_chain, ports_map, 0);
2705
- } else {
2706
- for (uint32_t port : filter_chain.filter_chain_match.source_ports) {
2707
- grpc_error_handle error =
2708
- AddFilterChainDataForSourcePort(filter_chain, ports_map, port);
2709
- if (error != GRPC_ERROR_NONE) return error;
2710
- }
2711
- }
2712
- return GRPC_ERROR_NONE;
2713
- }
2714
-
2715
- grpc_error_handle AddFilterChainDataForSourceIpRange(
2716
- const FilterChain& filter_chain,
2717
- InternalFilterChainMap::SourceIpMap* source_ip_map) {
2718
- if (filter_chain.filter_chain_match.source_prefix_ranges.empty()) {
2719
- auto insert_result = source_ip_map->emplace(
2720
- "", XdsApi::LdsUpdate::FilterChainMap::SourceIp());
2721
- return AddFilterChainDataForSourcePorts(
2722
- filter_chain, &insert_result.first->second.ports_map);
2723
- } else {
2724
- for (const auto& prefix_range :
2725
- filter_chain.filter_chain_match.source_prefix_ranges) {
2726
- auto insert_result = source_ip_map->emplace(
2727
- absl::StrCat(grpc_sockaddr_to_string(&prefix_range.address, false),
2728
- "/", prefix_range.prefix_len),
2729
- XdsApi::LdsUpdate::FilterChainMap::SourceIp());
2730
- if (insert_result.second) {
2731
- insert_result.first->second.prefix_range.emplace(prefix_range);
2732
- }
2733
- grpc_error_handle error = AddFilterChainDataForSourcePorts(
2734
- filter_chain, &insert_result.first->second.ports_map);
2735
- if (error != GRPC_ERROR_NONE) return error;
2736
- }
2737
- }
2738
- return GRPC_ERROR_NONE;
2739
- }
2740
-
2741
- grpc_error_handle AddFilterChainDataForSourceType(
2742
- const FilterChain& filter_chain,
2743
- InternalFilterChainMap::DestinationIp* destination_ip) {
2744
- GPR_ASSERT(static_cast<unsigned int>(
2745
- filter_chain.filter_chain_match.source_type) < 3);
2746
- return AddFilterChainDataForSourceIpRange(
2747
- filter_chain, &destination_ip->source_types_array[static_cast<int>(
2748
- filter_chain.filter_chain_match.source_type)]);
2749
- }
2750
-
2751
- grpc_error_handle AddFilterChainDataForApplicationProtocols(
2752
- const FilterChain& filter_chain,
2753
- InternalFilterChainMap::DestinationIp* destination_ip) {
2754
- // Only allow filter chains that do not mention application protocols
2755
- if (!filter_chain.filter_chain_match.application_protocols.empty()) {
2756
- return GRPC_ERROR_NONE;
2757
- }
2758
- return AddFilterChainDataForSourceType(filter_chain, destination_ip);
2759
- }
2760
-
2761
- grpc_error_handle AddFilterChainDataForTransportProtocol(
2762
- const FilterChain& filter_chain,
2763
- InternalFilterChainMap::DestinationIp* destination_ip) {
2764
- const std::string& transport_protocol =
2765
- filter_chain.filter_chain_match.transport_protocol;
2766
- // Only allow filter chains with no transport protocol or "raw_buffer"
2767
- if (!transport_protocol.empty() && transport_protocol != "raw_buffer") {
2768
- return GRPC_ERROR_NONE;
2769
- }
2770
- // If for this configuration, we've already seen filter chains that mention
2771
- // the transport protocol as "raw_buffer", we will never match filter chains
2772
- // that do not mention it.
2773
- if (destination_ip->transport_protocol_raw_buffer_provided &&
2774
- transport_protocol.empty()) {
2775
- return GRPC_ERROR_NONE;
2776
- }
2777
- if (!transport_protocol.empty() &&
2778
- !destination_ip->transport_protocol_raw_buffer_provided) {
2779
- destination_ip->transport_protocol_raw_buffer_provided = true;
2780
- // Clear out the previous entries if any since those entries did not mention
2781
- // "raw_buffer"
2782
- destination_ip->source_types_array =
2783
- InternalFilterChainMap::ConnectionSourceTypesArray();
2784
- }
2785
- return AddFilterChainDataForApplicationProtocols(filter_chain,
2786
- destination_ip);
2787
- }
2788
-
2789
- grpc_error_handle AddFilterChainDataForServerNames(
2790
- const FilterChain& filter_chain,
2791
- InternalFilterChainMap::DestinationIp* destination_ip) {
2792
- // Don't continue adding filter chains with server names mentioned
2793
- if (!filter_chain.filter_chain_match.server_names.empty()) {
2794
- return GRPC_ERROR_NONE;
2795
- }
2796
- return AddFilterChainDataForTransportProtocol(filter_chain, destination_ip);
2797
- }
2798
-
2799
- grpc_error_handle AddFilterChainDataForDestinationIpRange(
2800
- const FilterChain& filter_chain,
2801
- InternalFilterChainMap::DestinationIpMap* destination_ip_map) {
2802
- if (filter_chain.filter_chain_match.prefix_ranges.empty()) {
2803
- auto insert_result = destination_ip_map->emplace(
2804
- "", InternalFilterChainMap::DestinationIp());
2805
- return AddFilterChainDataForServerNames(filter_chain,
2806
- &insert_result.first->second);
2807
- } else {
2808
- for (const auto& prefix_range :
2809
- filter_chain.filter_chain_match.prefix_ranges) {
2810
- auto insert_result = destination_ip_map->emplace(
2811
- absl::StrCat(grpc_sockaddr_to_string(&prefix_range.address, false),
2812
- "/", prefix_range.prefix_len),
2813
- InternalFilterChainMap::DestinationIp());
2814
- if (insert_result.second) {
2815
- insert_result.first->second.prefix_range.emplace(prefix_range);
2816
- }
2817
- grpc_error_handle error = AddFilterChainDataForServerNames(
2818
- filter_chain, &insert_result.first->second);
2819
- if (error != GRPC_ERROR_NONE) return error;
2820
- }
2821
- }
2822
- return GRPC_ERROR_NONE;
2823
- }
2824
-
2825
- XdsApi::LdsUpdate::FilterChainMap BuildFromInternalFilterChainMap(
2826
- InternalFilterChainMap* internal_filter_chain_map) {
2827
- XdsApi::LdsUpdate::FilterChainMap filter_chain_map;
2828
- for (auto& destination_ip_pair :
2829
- internal_filter_chain_map->destination_ip_map) {
2830
- XdsApi::LdsUpdate::FilterChainMap::DestinationIp destination_ip;
2831
- destination_ip.prefix_range = destination_ip_pair.second.prefix_range;
2832
- for (int i = 0; i < 3; i++) {
2833
- auto& source_ip_map = destination_ip_pair.second.source_types_array[i];
2834
- for (auto& source_ip_pair : source_ip_map) {
2835
- destination_ip.source_types_array[i].push_back(
2836
- std::move(source_ip_pair.second));
2837
- }
2838
- }
2839
- filter_chain_map.destination_ip_vector.push_back(std::move(destination_ip));
2840
- }
2841
- return filter_chain_map;
2842
- }
2843
-
2844
- grpc_error_handle BuildFilterChainMap(
2845
- const std::vector<FilterChain>& filter_chains,
2846
- XdsApi::LdsUpdate::FilterChainMap* filter_chain_map) {
2847
- InternalFilterChainMap internal_filter_chain_map;
2848
- for (const auto& filter_chain : filter_chains) {
2849
- // Discard filter chain entries that specify destination port
2850
- if (filter_chain.filter_chain_match.destination_port != 0) continue;
2851
- grpc_error_handle error = AddFilterChainDataForDestinationIpRange(
2852
- filter_chain, &internal_filter_chain_map.destination_ip_map);
2853
- if (error != GRPC_ERROR_NONE) return error;
2854
- }
2855
- *filter_chain_map =
2856
- BuildFromInternalFilterChainMap(&internal_filter_chain_map);
2857
- return GRPC_ERROR_NONE;
2858
- }
2859
-
2860
- grpc_error_handle LdsResourceParseServer(
2861
- const EncodingContext& context,
2862
- const envoy_config_listener_v3_Listener* listener, bool is_v2,
2863
- XdsApi::LdsUpdate* lds_update) {
2864
- lds_update->type = XdsApi::LdsUpdate::ListenerType::kTcpListener;
2865
- grpc_error_handle error =
2866
- AddressParse(envoy_config_listener_v3_Listener_address(listener),
2867
- &lds_update->address);
2868
- if (error != GRPC_ERROR_NONE) return error;
2869
- const auto* use_original_dst =
2870
- envoy_config_listener_v3_Listener_use_original_dst(listener);
2871
- if (use_original_dst != nullptr) {
2872
- if (google_protobuf_BoolValue_value(use_original_dst)) {
2873
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2874
- "Field \'use_original_dst\' is not supported.");
2875
- }
2876
- }
2877
- size_t size = 0;
2878
- auto* filter_chains =
2879
- envoy_config_listener_v3_Listener_filter_chains(listener, &size);
2880
- std::vector<FilterChain> parsed_filter_chains;
2881
- parsed_filter_chains.reserve(size);
2882
- for (size_t i = 0; i < size; i++) {
2883
- FilterChain filter_chain;
2884
- error = FilterChainParse(context, filter_chains[i], is_v2, &filter_chain);
2885
- if (error != GRPC_ERROR_NONE) return error;
2886
- parsed_filter_chains.push_back(std::move(filter_chain));
2887
- }
2888
- error =
2889
- BuildFilterChainMap(parsed_filter_chains, &lds_update->filter_chain_map);
2890
- if (error != GRPC_ERROR_NONE) return error;
2891
- auto* default_filter_chain =
2892
- envoy_config_listener_v3_Listener_default_filter_chain(listener);
2893
- if (default_filter_chain != nullptr) {
2894
- FilterChain filter_chain;
2895
- error =
2896
- FilterChainParse(context, default_filter_chain, is_v2, &filter_chain);
2897
- if (error != GRPC_ERROR_NONE) return error;
2898
- if (filter_chain.filter_chain_data != nullptr) {
2899
- lds_update->default_filter_chain =
2900
- std::move(*filter_chain.filter_chain_data);
2901
- }
2902
- }
2903
- if (size == 0 && default_filter_chain == nullptr) {
2904
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("No filter chain provided.");
2905
- }
2906
- return GRPC_ERROR_NONE;
2907
- }
2908
-
2909
- grpc_error_handle LdsResourceParse(
2910
- const EncodingContext& context,
2911
- const envoy_config_listener_v3_Listener* listener, bool is_v2,
2912
- XdsApi::LdsUpdate* lds_update) {
2913
- // Check whether it's a client or server listener.
2914
- const envoy_config_listener_v3_ApiListener* api_listener =
2915
- envoy_config_listener_v3_Listener_api_listener(listener);
2916
- const envoy_config_core_v3_Address* address =
2917
- envoy_config_listener_v3_Listener_address(listener);
2918
- if (api_listener != nullptr && address != nullptr) {
2919
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2920
- "Listener has both address and ApiListener");
2921
- }
2922
- if (api_listener == nullptr && address == nullptr) {
2923
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2924
- "Listener has neither address nor ApiListener");
2925
- }
2926
- // Validate Listener fields.
2927
- grpc_error_handle error = GRPC_ERROR_NONE;
2928
- if (api_listener != nullptr) {
2929
- error = LdsResourceParseClient(context, api_listener, is_v2, lds_update);
2930
- } else {
2931
- error = LdsResourceParseServer(context, listener, is_v2, lds_update);
2932
- }
2933
- return error;
2934
- }
2935
-
2936
- grpc_error_handle UpstreamTlsContextParse(
2937
- const EncodingContext& context,
2938
- const envoy_config_core_v3_TransportSocket* transport_socket,
2939
- XdsApi::CommonTlsContext* common_tls_context) {
2940
- // Record Upstream tls context
2941
- absl::string_view name = UpbStringToAbsl(
2942
- envoy_config_core_v3_TransportSocket_name(transport_socket));
2943
- if (name != "envoy.transport_sockets.tls") {
2944
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
2945
- absl::StrCat("Unrecognized transport socket: ", name));
2946
- }
2947
- auto* typed_config =
2948
- envoy_config_core_v3_TransportSocket_typed_config(transport_socket);
2949
- if (typed_config != nullptr) {
2950
- const upb_strview encoded_upstream_tls_context =
2951
- google_protobuf_Any_value(typed_config);
2952
- auto* upstream_tls_context =
2953
- envoy_extensions_transport_sockets_tls_v3_UpstreamTlsContext_parse(
2954
- encoded_upstream_tls_context.data,
2955
- encoded_upstream_tls_context.size, context.arena);
2956
- if (upstream_tls_context == nullptr) {
2957
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2958
- "Can't decode upstream tls context.");
2959
- }
2960
- auto* common_tls_context_proto =
2961
- envoy_extensions_transport_sockets_tls_v3_UpstreamTlsContext_common_tls_context(
2962
- upstream_tls_context);
2963
- if (common_tls_context_proto != nullptr) {
2964
- grpc_error_handle error = CommonTlsContextParse(
2965
- context, common_tls_context_proto, common_tls_context);
2966
- if (error != GRPC_ERROR_NONE) {
2967
- return grpc_error_add_child(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2968
- "Error parsing UpstreamTlsContext"),
2969
- error);
2970
- }
2971
- }
2972
- }
2973
- if (common_tls_context->certificate_validation_context
2974
- .ca_certificate_provider_instance.instance_name.empty()) {
2975
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2976
- "UpstreamTlsContext: TLS configuration provided but no "
2977
- "ca_certificate_provider_instance found.");
2978
- }
2979
- return GRPC_ERROR_NONE;
2980
- }
2981
-
2982
- grpc_error_handle CdsLogicalDnsParse(
2983
- const envoy_config_cluster_v3_Cluster* cluster,
2984
- XdsApi::CdsUpdate* cds_update) {
2985
- const auto* load_assignment =
2986
- envoy_config_cluster_v3_Cluster_load_assignment(cluster);
2987
- if (load_assignment == nullptr) {
2988
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2989
- "load_assignment not present for LOGICAL_DNS cluster");
2990
- }
2991
- size_t num_localities;
2992
- const auto* const* localities =
2993
- envoy_config_endpoint_v3_ClusterLoadAssignment_endpoints(load_assignment,
2994
- &num_localities);
2995
- if (num_localities != 1) {
2996
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
2997
- absl::StrCat("load_assignment for LOGICAL_DNS cluster must have "
2998
- "exactly one locality, found ",
2999
- num_localities));
3000
- }
3001
- size_t num_endpoints;
3002
- const auto* const* endpoints =
3003
- envoy_config_endpoint_v3_LocalityLbEndpoints_lb_endpoints(localities[0],
3004
- &num_endpoints);
3005
- if (num_endpoints != 1) {
3006
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
3007
- absl::StrCat("locality for LOGICAL_DNS cluster must have "
3008
- "exactly one endpoint, found ",
3009
- num_endpoints));
3010
- }
3011
- const auto* endpoint =
3012
- envoy_config_endpoint_v3_LbEndpoint_endpoint(endpoints[0]);
3013
- if (endpoint == nullptr) {
3014
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
3015
- "LbEndpoint endpoint field not set");
3016
- }
3017
- const auto* address = envoy_config_endpoint_v3_Endpoint_address(endpoint);
3018
- if (address == nullptr) {
3019
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
3020
- "Endpoint address field not set");
3021
- }
3022
- const auto* socket_address =
3023
- envoy_config_core_v3_Address_socket_address(address);
3024
- if (socket_address == nullptr) {
3025
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
3026
- "Address socket_address field not set");
3027
- }
3028
- if (envoy_config_core_v3_SocketAddress_resolver_name(socket_address).size !=
3029
- 0) {
3030
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
3031
- "LOGICAL_DNS clusters must NOT have a custom resolver name set");
3032
- }
3033
- absl::string_view address_str = UpbStringToAbsl(
3034
- envoy_config_core_v3_SocketAddress_address(socket_address));
3035
- if (address_str.empty()) {
3036
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
3037
- "SocketAddress address field not set");
3038
- }
3039
- if (!envoy_config_core_v3_SocketAddress_has_port_value(socket_address)) {
3040
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
3041
- "SocketAddress port_value field not set");
3042
- }
3043
- cds_update->dns_hostname = JoinHostPort(
3044
- address_str,
3045
- envoy_config_core_v3_SocketAddress_port_value(socket_address));
3046
- return GRPC_ERROR_NONE;
3047
- }
3048
-
3049
- grpc_error_handle CdsResourceParse(
3050
- const EncodingContext& context,
3051
- const envoy_config_cluster_v3_Cluster* cluster, bool /*is_v2*/,
3052
- XdsApi::CdsUpdate* cds_update) {
3053
- std::vector<grpc_error_handle> errors;
3054
- // Check the cluster_discovery_type.
3055
- if (!envoy_config_cluster_v3_Cluster_has_type(cluster) &&
3056
- !envoy_config_cluster_v3_Cluster_has_cluster_type(cluster)) {
3057
- errors.push_back(
3058
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("DiscoveryType not found."));
3059
- } else if (envoy_config_cluster_v3_Cluster_type(cluster) ==
3060
- envoy_config_cluster_v3_Cluster_EDS) {
3061
- cds_update->cluster_type = XdsApi::CdsUpdate::ClusterType::EDS;
3062
- // Check the EDS config source.
3063
- const envoy_config_cluster_v3_Cluster_EdsClusterConfig* eds_cluster_config =
3064
- envoy_config_cluster_v3_Cluster_eds_cluster_config(cluster);
3065
- const envoy_config_core_v3_ConfigSource* eds_config =
3066
- envoy_config_cluster_v3_Cluster_EdsClusterConfig_eds_config(
3067
- eds_cluster_config);
3068
- if (!envoy_config_core_v3_ConfigSource_has_ads(eds_config)) {
3069
- errors.push_back(
3070
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("EDS ConfigSource is not ADS."));
3071
- }
3072
- // Record EDS service_name (if any).
3073
- upb_strview service_name =
3074
- envoy_config_cluster_v3_Cluster_EdsClusterConfig_service_name(
3075
- eds_cluster_config);
3076
- if (service_name.size != 0) {
3077
- cds_update->eds_service_name = UpbStringToStdString(service_name);
3078
- }
3079
- } else if (!XdsAggregateAndLogicalDnsClusterEnabled()) {
3080
- errors.push_back(
3081
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("DiscoveryType is not valid."));
3082
- } else if (envoy_config_cluster_v3_Cluster_type(cluster) ==
3083
- envoy_config_cluster_v3_Cluster_LOGICAL_DNS) {
3084
- cds_update->cluster_type = XdsApi::CdsUpdate::ClusterType::LOGICAL_DNS;
3085
- grpc_error_handle error = CdsLogicalDnsParse(cluster, cds_update);
3086
- if (error != GRPC_ERROR_NONE) errors.push_back(error);
3087
- } else {
3088
- if (!envoy_config_cluster_v3_Cluster_has_cluster_type(cluster)) {
3089
- errors.push_back(
3090
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("DiscoveryType is not valid."));
3091
- } else {
3092
- const envoy_config_cluster_v3_Cluster_CustomClusterType*
3093
- custom_cluster_type =
3094
- envoy_config_cluster_v3_Cluster_cluster_type(cluster);
3095
- upb_strview type_name =
3096
- envoy_config_cluster_v3_Cluster_CustomClusterType_name(
3097
- custom_cluster_type);
3098
- if (UpbStringToAbsl(type_name) != "envoy.clusters.aggregate") {
3099
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
3100
- "DiscoveryType is not valid."));
3101
- } else {
3102
- cds_update->cluster_type = XdsApi::CdsUpdate::ClusterType::AGGREGATE;
3103
- // Retrieve aggregate clusters.
3104
- const google_protobuf_Any* typed_config =
3105
- envoy_config_cluster_v3_Cluster_CustomClusterType_typed_config(
3106
- custom_cluster_type);
3107
- const upb_strview aggregate_cluster_config_upb_strview =
3108
- google_protobuf_Any_value(typed_config);
3109
- const envoy_extensions_clusters_aggregate_v3_ClusterConfig*
3110
- aggregate_cluster_config =
3111
- envoy_extensions_clusters_aggregate_v3_ClusterConfig_parse(
3112
- aggregate_cluster_config_upb_strview.data,
3113
- aggregate_cluster_config_upb_strview.size, context.arena);
3114
- if (aggregate_cluster_config == nullptr) {
3115
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
3116
- "Can't parse aggregate cluster."));
3117
- } else {
3118
- size_t size;
3119
- const upb_strview* clusters =
3120
- envoy_extensions_clusters_aggregate_v3_ClusterConfig_clusters(
3121
- aggregate_cluster_config, &size);
3122
- for (size_t i = 0; i < size; ++i) {
3123
- const upb_strview cluster = clusters[i];
3124
- cds_update->prioritized_cluster_names.emplace_back(
3125
- UpbStringToStdString(cluster));
3126
- }
3127
- }
3128
- }
3129
- }
3130
- }
3131
- // Check the LB policy.
3132
- if (envoy_config_cluster_v3_Cluster_lb_policy(cluster) ==
3133
- envoy_config_cluster_v3_Cluster_ROUND_ROBIN) {
3134
- cds_update->lb_policy = "ROUND_ROBIN";
3135
- } else if (envoy_config_cluster_v3_Cluster_lb_policy(cluster) ==
3136
- envoy_config_cluster_v3_Cluster_RING_HASH) {
3137
- cds_update->lb_policy = "RING_HASH";
3138
- // Record ring hash lb config
3139
- auto* ring_hash_config =
3140
- envoy_config_cluster_v3_Cluster_ring_hash_lb_config(cluster);
3141
- if (ring_hash_config != nullptr) {
3142
- const google_protobuf_UInt64Value* max_ring_size =
3143
- envoy_config_cluster_v3_Cluster_RingHashLbConfig_maximum_ring_size(
3144
- ring_hash_config);
3145
- if (max_ring_size != nullptr) {
3146
- cds_update->max_ring_size =
3147
- google_protobuf_UInt64Value_value(max_ring_size);
3148
- if (cds_update->max_ring_size > 8388608 ||
3149
- cds_update->max_ring_size == 0) {
3150
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
3151
- "max_ring_size is not in the range of 1 to 8388608."));
3152
- }
3153
- }
3154
- const google_protobuf_UInt64Value* min_ring_size =
3155
- envoy_config_cluster_v3_Cluster_RingHashLbConfig_minimum_ring_size(
3156
- ring_hash_config);
3157
- if (min_ring_size != nullptr) {
3158
- cds_update->min_ring_size =
3159
- google_protobuf_UInt64Value_value(min_ring_size);
3160
- if (cds_update->min_ring_size > 8388608 ||
3161
- cds_update->min_ring_size == 0) {
3162
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
3163
- "min_ring_size is not in the range of 1 to 8388608."));
3164
- }
3165
- if (cds_update->min_ring_size > cds_update->max_ring_size) {
3166
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
3167
- "min_ring_size cannot be greater than max_ring_size."));
3168
- }
3169
- }
3170
- if (envoy_config_cluster_v3_Cluster_RingHashLbConfig_hash_function(
3171
- ring_hash_config) !=
3172
- envoy_config_cluster_v3_Cluster_RingHashLbConfig_XX_HASH) {
3173
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
3174
- "ring hash lb config has invalid hash function."));
3175
- }
3176
- }
3177
- } else {
3178
- errors.push_back(
3179
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("LB policy is not supported."));
3180
- }
3181
- auto* transport_socket =
3182
- envoy_config_cluster_v3_Cluster_transport_socket(cluster);
3183
- if (transport_socket != nullptr) {
3184
- grpc_error_handle error = UpstreamTlsContextParse(
3185
- context, transport_socket, &cds_update->common_tls_context);
3186
- if (error != GRPC_ERROR_NONE) {
3187
- errors.push_back(
3188
- grpc_error_add_child(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
3189
- "Error parsing security configuration"),
3190
- error));
3191
- }
3192
- }
3193
- // Record LRS server name (if any).
3194
- const envoy_config_core_v3_ConfigSource* lrs_server =
3195
- envoy_config_cluster_v3_Cluster_lrs_server(cluster);
3196
- if (lrs_server != nullptr) {
3197
- if (!envoy_config_core_v3_ConfigSource_has_self(lrs_server)) {
3198
- errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
3199
- ": LRS ConfigSource is not self."));
3200
- }
3201
- cds_update->lrs_load_reporting_server_name.emplace("");
3202
- }
3203
- // The Cluster resource encodes the circuit breaking parameters in a list of
3204
- // Thresholds messages, where each message specifies the parameters for a
3205
- // particular RoutingPriority. we will look only at the first entry in the
3206
- // list for priority DEFAULT and default to 1024 if not found.
3207
- if (envoy_config_cluster_v3_Cluster_has_circuit_breakers(cluster)) {
3208
- const envoy_config_cluster_v3_CircuitBreakers* circuit_breakers =
3209
- envoy_config_cluster_v3_Cluster_circuit_breakers(cluster);
3210
- size_t num_thresholds;
3211
- const envoy_config_cluster_v3_CircuitBreakers_Thresholds* const*
3212
- thresholds = envoy_config_cluster_v3_CircuitBreakers_thresholds(
3213
- circuit_breakers, &num_thresholds);
3214
- for (size_t i = 0; i < num_thresholds; ++i) {
3215
- const auto* threshold = thresholds[i];
3216
- if (envoy_config_cluster_v3_CircuitBreakers_Thresholds_priority(
3217
- threshold) == envoy_config_core_v3_DEFAULT) {
3218
- const google_protobuf_UInt32Value* max_requests =
3219
- envoy_config_cluster_v3_CircuitBreakers_Thresholds_max_requests(
3220
- threshold);
3221
- if (max_requests != nullptr) {
3222
- cds_update->max_concurrent_requests =
3223
- google_protobuf_UInt32Value_value(max_requests);
3224
- }
3225
- break;
3226
- }
3227
- }
3228
- }
3229
- return GRPC_ERROR_CREATE_FROM_VECTOR("errors parsing CDS resource", &errors);
3230
- }
3231
-
3232
- grpc_error_handle ServerAddressParseAndAppend(
3233
- const envoy_config_endpoint_v3_LbEndpoint* lb_endpoint,
3234
- ServerAddressList* list) {
3235
- // If health_status is not HEALTHY or UNKNOWN, skip this endpoint.
3236
- const int32_t health_status =
3237
- envoy_config_endpoint_v3_LbEndpoint_health_status(lb_endpoint);
3238
- if (health_status != envoy_config_core_v3_UNKNOWN &&
3239
- health_status != envoy_config_core_v3_HEALTHY) {
3240
- return GRPC_ERROR_NONE;
3241
- }
3242
- // Find the ip:port.
3243
- const envoy_config_endpoint_v3_Endpoint* endpoint =
3244
- envoy_config_endpoint_v3_LbEndpoint_endpoint(lb_endpoint);
3245
- const envoy_config_core_v3_Address* address =
3246
- envoy_config_endpoint_v3_Endpoint_address(endpoint);
3247
- const envoy_config_core_v3_SocketAddress* socket_address =
3248
- envoy_config_core_v3_Address_socket_address(address);
3249
- std::string address_str = UpbStringToStdString(
3250
- envoy_config_core_v3_SocketAddress_address(socket_address));
3251
- uint32_t port = envoy_config_core_v3_SocketAddress_port_value(socket_address);
3252
- if (GPR_UNLIKELY(port >> 16) != 0) {
3253
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Invalid port.");
3254
- }
3255
- // Find load_balancing_weight for the endpoint.
3256
- const google_protobuf_UInt32Value* load_balancing_weight =
3257
- envoy_config_endpoint_v3_LbEndpoint_load_balancing_weight(lb_endpoint);
3258
- const int32_t weight =
3259
- load_balancing_weight != nullptr
3260
- ? google_protobuf_UInt32Value_value(load_balancing_weight)
3261
- : 500;
3262
- if (weight == 0) {
3263
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
3264
- "Invalid endpoint weight of 0.");
3265
- }
3266
- // Populate grpc_resolved_address.
3267
- grpc_resolved_address addr;
3268
- grpc_error_handle error =
3269
- grpc_string_to_sockaddr(&addr, address_str.c_str(), port);
3270
- if (error != GRPC_ERROR_NONE) return error;
3271
- // Append the address to the list.
3272
- std::map<const char*, std::unique_ptr<ServerAddress::AttributeInterface>>
3273
- attributes;
3274
- attributes[ServerAddressWeightAttribute::kServerAddressWeightAttributeKey] =
3275
- absl::make_unique<ServerAddressWeightAttribute>(weight);
3276
- list->emplace_back(addr, nullptr, std::move(attributes));
3277
- return GRPC_ERROR_NONE;
3278
- }
3279
-
3280
- grpc_error_handle LocalityParse(
3281
- const envoy_config_endpoint_v3_LocalityLbEndpoints* locality_lb_endpoints,
3282
- XdsApi::EdsUpdate::Priority::Locality* output_locality, size_t* priority) {
3283
- // Parse LB weight.
3284
- const google_protobuf_UInt32Value* lb_weight =
3285
- envoy_config_endpoint_v3_LocalityLbEndpoints_load_balancing_weight(
3286
- locality_lb_endpoints);
3287
- // If LB weight is not specified, it means this locality is assigned no load.
3288
- // TODO(juanlishen): When we support CDS to configure the inter-locality
3289
- // policy, we should change the LB weight handling.
3290
- output_locality->lb_weight =
3291
- lb_weight != nullptr ? google_protobuf_UInt32Value_value(lb_weight) : 0;
3292
- if (output_locality->lb_weight == 0) return GRPC_ERROR_NONE;
3293
- // Parse locality name.
3294
- const envoy_config_core_v3_Locality* locality =
3295
- envoy_config_endpoint_v3_LocalityLbEndpoints_locality(
3296
- locality_lb_endpoints);
3297
- if (locality == nullptr) {
3298
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty locality.");
3299
- }
3300
- std::string region =
3301
- UpbStringToStdString(envoy_config_core_v3_Locality_region(locality));
3302
- std::string zone =
3303
- UpbStringToStdString(envoy_config_core_v3_Locality_region(locality));
3304
- std::string sub_zone =
3305
- UpbStringToStdString(envoy_config_core_v3_Locality_sub_zone(locality));
3306
- output_locality->name = MakeRefCounted<XdsLocalityName>(
3307
- std::move(region), std::move(zone), std::move(sub_zone));
3308
- // Parse the addresses.
3309
- size_t size;
3310
- const envoy_config_endpoint_v3_LbEndpoint* const* lb_endpoints =
3311
- envoy_config_endpoint_v3_LocalityLbEndpoints_lb_endpoints(
3312
- locality_lb_endpoints, &size);
3313
- for (size_t i = 0; i < size; ++i) {
3314
- grpc_error_handle error = ServerAddressParseAndAppend(
3315
- lb_endpoints[i], &output_locality->endpoints);
3316
- if (error != GRPC_ERROR_NONE) return error;
3317
- }
3318
- // Parse the priority.
3319
- *priority = envoy_config_endpoint_v3_LocalityLbEndpoints_priority(
3320
- locality_lb_endpoints);
3321
- return GRPC_ERROR_NONE;
3322
- }
3323
-
3324
- grpc_error_handle DropParseAndAppend(
3325
- const envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload*
3326
- drop_overload,
3327
- XdsApi::EdsUpdate::DropConfig* drop_config) {
3328
- // Get the category.
3329
- std::string category = UpbStringToStdString(
3330
- envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload_category(
3331
- drop_overload));
3332
- if (category.empty()) {
3333
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty drop category name");
3334
- }
3335
- // Get the drop rate (per million).
3336
- const envoy_type_v3_FractionalPercent* drop_percentage =
3337
- envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload_drop_percentage(
3338
- drop_overload);
3339
- uint32_t numerator =
3340
- envoy_type_v3_FractionalPercent_numerator(drop_percentage);
3341
- const auto denominator =
3342
- static_cast<envoy_type_v3_FractionalPercent_DenominatorType>(
3343
- envoy_type_v3_FractionalPercent_denominator(drop_percentage));
3344
- // Normalize to million.
3345
- switch (denominator) {
3346
- case envoy_type_v3_FractionalPercent_HUNDRED:
3347
- numerator *= 10000;
3348
- break;
3349
- case envoy_type_v3_FractionalPercent_TEN_THOUSAND:
3350
- numerator *= 100;
3351
- break;
3352
- case envoy_type_v3_FractionalPercent_MILLION:
3353
- break;
3354
- default:
3355
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Unknown denominator type");
3356
- }
3357
- // Cap numerator to 1000000.
3358
- numerator = std::min(numerator, 1000000u);
3359
- drop_config->AddCategory(std::move(category), numerator);
3360
- return GRPC_ERROR_NONE;
3361
- }
3362
-
3363
- grpc_error_handle EdsResourceParse(
3364
- const EncodingContext& /*context*/,
3365
- const envoy_config_endpoint_v3_ClusterLoadAssignment*
3366
- cluster_load_assignment,
3367
- bool /*is_v2*/, XdsApi::EdsUpdate* eds_update) {
3368
- std::vector<grpc_error_handle> errors;
3369
- // Get the endpoints.
3370
- size_t locality_size;
3371
- const envoy_config_endpoint_v3_LocalityLbEndpoints* const* endpoints =
3372
- envoy_config_endpoint_v3_ClusterLoadAssignment_endpoints(
3373
- cluster_load_assignment, &locality_size);
3374
- for (size_t j = 0; j < locality_size; ++j) {
3375
- size_t priority;
3376
- XdsApi::EdsUpdate::Priority::Locality locality;
3377
- grpc_error_handle error = LocalityParse(endpoints[j], &locality, &priority);
3378
- if (error != GRPC_ERROR_NONE) {
3379
- errors.push_back(error);
3380
- continue;
3381
- }
3382
- // Filter out locality with weight 0.
3383
- if (locality.lb_weight == 0) continue;
3384
- // Make sure prorities is big enough. Note that they might not
3385
- // arrive in priority order.
3386
- while (eds_update->priorities.size() < priority + 1) {
3387
- eds_update->priorities.emplace_back();
3388
- }
3389
- eds_update->priorities[priority].localities.emplace(locality.name.get(),
3390
- std::move(locality));
3391
- }
3392
- for (const auto& priority : eds_update->priorities) {
3393
- if (priority.localities.empty()) {
3394
- errors.push_back(
3395
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("sparse priority list"));
3396
- }
3397
- }
3398
- // Get the drop config.
3399
- eds_update->drop_config = MakeRefCounted<XdsApi::EdsUpdate::DropConfig>();
3400
- const envoy_config_endpoint_v3_ClusterLoadAssignment_Policy* policy =
3401
- envoy_config_endpoint_v3_ClusterLoadAssignment_policy(
3402
- cluster_load_assignment);
3403
- if (policy != nullptr) {
3404
- size_t drop_size;
3405
- const envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload* const*
3406
- drop_overload =
3407
- envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_drop_overloads(
3408
- policy, &drop_size);
3409
- for (size_t j = 0; j < drop_size; ++j) {
3410
- grpc_error_handle error =
3411
- DropParseAndAppend(drop_overload[j], eds_update->drop_config.get());
3412
- if (error != GRPC_ERROR_NONE) {
3413
- errors.push_back(
3414
- grpc_error_add_child(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
3415
- "drop config validation error"),
3416
- error));
3417
- }
3418
- }
3419
- }
3420
- return GRPC_ERROR_CREATE_FROM_VECTOR("errors parsing EDS resource", &errors);
3421
- }
3422
-
3423
- class ListenerResourceType : public XdsResourceType {
3424
- public:
3425
- struct ListenerData : public ResourceData {
3426
- XdsApi::LdsUpdate resource;
3427
- };
3428
-
3429
- absl::string_view type_url() const override { return XdsApi::kLdsTypeUrl; }
3430
- absl::string_view v2_type_url() const override { return kLdsV2TypeUrl; }
3431
-
3432
- absl::StatusOr<DecodeResult> Decode(const EncodingContext& context,
3433
- absl::string_view serialized_resource,
3434
- bool is_v2) const override {
3435
- // Parse serialized proto.
3436
- auto* resource = envoy_config_listener_v3_Listener_parse(
3437
- serialized_resource.data(), serialized_resource.size(), context.arena);
3438
- if (resource == nullptr) {
3439
- return absl::InvalidArgumentError("Can't parse Listener resource.");
3440
- }
3441
- MaybeLogListener(context, resource);
3442
- // Validate resource.
3443
- DecodeResult result;
3444
- result.name =
3445
- UpbStringToStdString(envoy_config_listener_v3_Listener_name(resource));
3446
- auto listener_data = absl::make_unique<ListenerData>();
3447
- grpc_error_handle error =
3448
- LdsResourceParse(context, resource, is_v2, &listener_data->resource);
3449
- if (error != GRPC_ERROR_NONE) {
3450
- result.resource =
3451
- absl::InvalidArgumentError(grpc_error_std_string(error));
3452
- GRPC_ERROR_UNREF(error);
3453
- } else {
3454
- result.resource = std::move(listener_data);
3455
- }
3456
- return std::move(result);
3457
- }
3458
- };
3459
-
3460
- class RouteConfigResourceType : public XdsResourceType {
3461
- public:
3462
- struct RouteConfigData : public ResourceData {
3463
- XdsApi::RdsUpdate resource;
3464
- };
3465
-
3466
- absl::string_view type_url() const override { return XdsApi::kRdsTypeUrl; }
3467
- absl::string_view v2_type_url() const override { return kRdsV2TypeUrl; }
3468
-
3469
- absl::StatusOr<DecodeResult> Decode(const EncodingContext& context,
3470
- absl::string_view serialized_resource,
3471
- bool is_v2) const override {
3472
- // Parse serialized proto.
3473
- auto* resource = envoy_config_route_v3_RouteConfiguration_parse(
3474
- serialized_resource.data(), serialized_resource.size(), context.arena);
3475
- if (resource == nullptr) {
3476
- return absl::InvalidArgumentError("Can't parse Listener resource.");
3477
- }
3478
- MaybeLogRouteConfiguration(context, resource);
3479
- // Validate resource.
3480
- DecodeResult result;
3481
- result.name = UpbStringToStdString(
3482
- envoy_config_route_v3_RouteConfiguration_name(resource));
3483
- auto route_config_data = absl::make_unique<RouteConfigData>();
3484
- grpc_error_handle error = RouteConfigParse(context, resource, is_v2,
3485
- &route_config_data->resource);
3486
- if (error != GRPC_ERROR_NONE) {
3487
- result.resource =
3488
- absl::InvalidArgumentError(grpc_error_std_string(error));
3489
- GRPC_ERROR_UNREF(error);
3490
- } else {
3491
- result.resource = std::move(route_config_data);
3492
- }
3493
- return std::move(result);
3494
- }
3495
- };
3496
-
3497
- class ClusterResourceType : public XdsResourceType {
3498
- public:
3499
- struct ClusterData : public ResourceData {
3500
- XdsApi::CdsUpdate resource;
3501
- };
3502
-
3503
- absl::string_view type_url() const override { return XdsApi::kCdsTypeUrl; }
3504
- absl::string_view v2_type_url() const override { return kCdsV2TypeUrl; }
3505
-
3506
- absl::StatusOr<DecodeResult> Decode(const EncodingContext& context,
3507
- absl::string_view serialized_resource,
3508
- bool is_v2) const override {
3509
- // Parse serialized proto.
3510
- auto* resource = envoy_config_cluster_v3_Cluster_parse(
3511
- serialized_resource.data(), serialized_resource.size(), context.arena);
3512
- if (resource == nullptr) {
3513
- return absl::InvalidArgumentError("Can't parse Listener resource.");
3514
- }
3515
- MaybeLogCluster(context, resource);
3516
- // Validate resource.
3517
- DecodeResult result;
3518
- result.name =
3519
- UpbStringToStdString(envoy_config_cluster_v3_Cluster_name(resource));
3520
- auto cluster_data = absl::make_unique<ClusterData>();
3521
- grpc_error_handle error =
3522
- CdsResourceParse(context, resource, is_v2, &cluster_data->resource);
3523
- if (error != GRPC_ERROR_NONE) {
3524
- result.resource =
3525
- absl::InvalidArgumentError(grpc_error_std_string(error));
3526
- GRPC_ERROR_UNREF(error);
3527
- } else {
3528
- result.resource = std::move(cluster_data);
3529
- }
3530
- return std::move(result);
3531
- }
3532
- };
3533
-
3534
- class EndpointResourceType : public XdsResourceType {
3535
- public:
3536
- struct EndpointData : public ResourceData {
3537
- XdsApi::EdsUpdate resource;
3538
- };
3539
-
3540
- absl::string_view type_url() const override { return XdsApi::kEdsTypeUrl; }
3541
- absl::string_view v2_type_url() const override { return kEdsV2TypeUrl; }
3542
-
3543
- absl::StatusOr<DecodeResult> Decode(const EncodingContext& context,
3544
- absl::string_view serialized_resource,
3545
- bool is_v2) const override {
3546
- // Parse serialized proto.
3547
- auto* resource = envoy_config_endpoint_v3_ClusterLoadAssignment_parse(
3548
- serialized_resource.data(), serialized_resource.size(), context.arena);
3549
- if (resource == nullptr) {
3550
- return absl::InvalidArgumentError("Can't parse Listener resource.");
3551
- }
3552
- MaybeLogClusterLoadAssignment(context, resource);
3553
- // Validate resource.
3554
- DecodeResult result;
3555
- result.name = UpbStringToStdString(
3556
- envoy_config_endpoint_v3_ClusterLoadAssignment_cluster_name(resource));
3557
- auto endpoint_data = absl::make_unique<EndpointData>();
3558
- grpc_error_handle error =
3559
- EdsResourceParse(context, resource, is_v2, &endpoint_data->resource);
3560
- if (error != GRPC_ERROR_NONE) {
3561
- result.resource =
3562
- absl::InvalidArgumentError(grpc_error_std_string(error));
3563
- GRPC_ERROR_UNREF(error);
3564
- } else {
3565
- result.resource = std::move(endpoint_data);
3566
- }
3567
- return std::move(result);
3568
- }
3569
- };
3570
-
3571
- grpc_error_handle AdsResourceParse(
3572
- const EncodingContext& context, XdsResourceType* type, size_t idx,
3573
- const google_protobuf_Any* resource_any,
3574
- const std::map<absl::string_view /*authority*/,
3575
- std::set<absl::string_view /*name*/>>&
3576
- subscribed_resource_names,
3577
- std::function<grpc_error_handle(
3578
- absl::string_view, XdsApi::ResourceName,
3579
- std::unique_ptr<XdsResourceType::ResourceData>, std::string)>
3580
- add_result_func,
3581
- std::set<XdsApi::ResourceName>* resource_names_failed) {
3582
- // Check the type_url of the resource.
3583
- absl::string_view type_url = absl::StripPrefix(
3584
- UpbStringToAbsl(google_protobuf_Any_type_url(resource_any)),
3585
- "type.googleapis.com/");
3586
- bool is_v2 = false;
3587
- if (!type->IsType(type_url, &is_v2)) {
3588
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
3589
- absl::StrCat("resource index ", idx, ": found resource type ", type_url,
3590
- " in response for type ", type->type_url()));
3591
- }
3592
- // Parse the resource.
3593
- absl::string_view serialized_resource =
3594
- UpbStringToAbsl(google_protobuf_Any_value(resource_any));
3595
- absl::StatusOr<XdsResourceType::DecodeResult> result =
3596
- type->Decode(context, serialized_resource, is_v2);
3597
- if (!result.ok()) {
3598
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
3599
- absl::StrCat("resource index ", idx, ": ", result.status().ToString()));
3600
- }
3601
- // Check the resource name.
3602
- auto resource_name = ParseResourceNameInternal(
3603
- result->name, [type](absl::string_view type_url, bool* is_v2) {
3604
- return type->IsType(type_url, is_v2);
3605
- });
3606
- if (!resource_name.ok()) {
3607
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat(
3608
- "resource index ", idx, ": Cannot parse xDS resource name \"",
3609
- result->name, "\""));
3610
- }
3611
- // Ignore unexpected names.
3612
- auto iter = subscribed_resource_names.find(resource_name->authority);
3613
- if (iter == subscribed_resource_names.end() ||
3614
- iter->second.find(resource_name->id) == iter->second.end()) {
3615
- return GRPC_ERROR_NONE;
3616
- }
3617
- // Check that resource was valid.
3618
- if (!result->resource.ok()) {
3619
- resource_names_failed->insert(*resource_name);
3620
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat(
3621
- "resource index ", idx, ": ", result->name,
3622
- ": validation error: ", result->resource.status().ToString()));
3623
- }
3624
- // Add result.
3625
- grpc_error_handle error = add_result_func(result->name, *resource_name,
3626
- std::move(*result->resource),
3627
- std::string(serialized_resource));
3628
- if (error != GRPC_ERROR_NONE) {
3629
- resource_names_failed->insert(*resource_name);
3630
- return grpc_error_add_child(
3631
- GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat(
3632
- "resource index ", idx, ": ", result->name, ": validation error")),
3633
- error);
3634
- }
3635
- return GRPC_ERROR_NONE;
3636
- }
3637
-
3638
- template <typename UpdateMap, typename ResourceTypeData>
3639
- grpc_error_handle AddResult(
3640
- UpdateMap* update_map, absl::string_view resource_name_string,
3641
- XdsApi::ResourceName resource_name,
3642
- std::unique_ptr<XdsResourceType::ResourceData> resource,
3643
- std::string serialized_resource) {
3644
- // Reject duplicate names.
3645
- if (update_map->find(resource_name) != update_map->end()) {
3646
- return GRPC_ERROR_CREATE_FROM_CPP_STRING(
3647
- absl::StrCat("duplicate resource name \"", resource_name_string, "\""));
3648
- }
3649
- // Save result.
3650
- auto& resource_data = (*update_map)[resource_name];
3651
- ResourceTypeData* typed_resource =
3652
- static_cast<ResourceTypeData*>(resource.get());
3653
- resource_data.resource = std::move(typed_resource->resource);
3654
- resource_data.serialized_proto = std::move(serialized_resource);
3655
- return GRPC_ERROR_NONE;
3656
- }
3657
-
3658
352
  } // namespace
3659
353
 
3660
- XdsApi::AdsParseResult XdsApi::ParseAdsResponse(
3661
- const XdsBootstrap::XdsServer& server, const grpc_slice& encoded_response,
3662
- const std::map<absl::string_view /*authority*/,
3663
- std::set<absl::string_view /*name*/>>&
3664
- subscribed_listener_names,
3665
- const std::map<absl::string_view /*authority*/,
3666
- std::set<absl::string_view /*name*/>>&
3667
- subscribed_route_config_names,
3668
- const std::map<absl::string_view /*authority*/,
3669
- std::set<absl::string_view /*name*/>>&
3670
- subscribed_cluster_names,
3671
- const std::map<absl::string_view /*authority*/,
3672
- std::set<absl::string_view /*name*/>>&
3673
- subscribed_eds_service_names) {
3674
- AdsParseResult result;
354
+ absl::Status XdsApi::ParseAdsResponse(const XdsBootstrap::XdsServer& server,
355
+ const grpc_slice& encoded_response,
356
+ AdsResponseParserInterface* parser) {
3675
357
  upb::Arena arena;
3676
- const EncodingContext context = {client_,
3677
- tracer_,
3678
- symtab_.ptr(),
3679
- arena.ptr(),
3680
- server.ShouldUseV3(),
3681
- certificate_provider_definition_map_};
358
+ const XdsEncodingContext context = {client_,
359
+ tracer_,
360
+ symtab_->ptr(),
361
+ arena.ptr(),
362
+ server.ShouldUseV3(),
363
+ certificate_provider_definition_map_};
3682
364
  // Decode the response.
3683
365
  const envoy_service_discovery_v3_DiscoveryResponse* response =
3684
366
  envoy_service_discovery_v3_DiscoveryResponse_parse(
3685
367
  reinterpret_cast<const char*>(GRPC_SLICE_START_PTR(encoded_response)),
3686
368
  GRPC_SLICE_LENGTH(encoded_response), arena.ptr());
3687
- // If decoding fails, output an empty type_url and return.
369
+ // If decoding fails, report a fatal error and return.
3688
370
  if (response == nullptr) {
3689
- result.parse_error =
3690
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode DiscoveryResponse.");
3691
- return result;
371
+ return absl::InvalidArgumentError("Can't decode DiscoveryResponse.");
3692
372
  }
3693
373
  MaybeLogDiscoveryResponse(context, response);
3694
- // Record the type_url, the version_info, and the nonce of the response.
3695
- result.type_url = TypeUrlInternalToExternal(absl::StripPrefix(
374
+ // Report the type_url, version, nonce, and number of resources to the parser.
375
+ AdsResponseParserInterface::AdsResponseFields fields;
376
+ fields.type_url = std::string(absl::StripPrefix(
3696
377
  UpbStringToAbsl(
3697
378
  envoy_service_discovery_v3_DiscoveryResponse_type_url(response)),
3698
379
  "type.googleapis.com/"));
3699
- result.version = UpbStringToStdString(
380
+ fields.version = UpbStringToStdString(
3700
381
  envoy_service_discovery_v3_DiscoveryResponse_version_info(response));
3701
- result.nonce = UpbStringToStdString(
382
+ fields.nonce = UpbStringToStdString(
3702
383
  envoy_service_discovery_v3_DiscoveryResponse_nonce(response));
3703
- // Get the resources from the response.
3704
- std::vector<grpc_error_handle> errors;
3705
- size_t size;
384
+ size_t num_resources;
3706
385
  const google_protobuf_Any* const* resources =
3707
- envoy_service_discovery_v3_DiscoveryResponse_resources(response, &size);
3708
- for (size_t i = 0; i < size; ++i) {
3709
- // Parse the response according to the resource type.
3710
- // TODO(roth): When we have time, change the API here to avoid the need
3711
- // for templating and conditionals.
3712
- grpc_error_handle parse_error = GRPC_ERROR_NONE;
3713
- if (IsLds(result.type_url)) {
3714
- ListenerResourceType resource_type;
3715
- auto& update_map = result.lds_update_map;
3716
- parse_error = AdsResourceParse(
3717
- context, &resource_type, i, resources[i], subscribed_listener_names,
3718
- [&update_map](absl::string_view resource_name_string,
3719
- XdsApi::ResourceName resource_name,
3720
- std::unique_ptr<XdsResourceType::ResourceData> resource,
3721
- std::string serialized_resource) {
3722
- return AddResult<LdsUpdateMap, ListenerResourceType::ListenerData>(
3723
- &update_map, resource_name_string, std::move(resource_name),
3724
- std::move(resource), std::move(serialized_resource));
3725
- },
3726
- &result.resource_names_failed);
3727
- } else if (IsRds(result.type_url)) {
3728
- RouteConfigResourceType resource_type;
3729
- auto& update_map = result.rds_update_map;
3730
- parse_error = AdsResourceParse(
3731
- context, &resource_type, i, resources[i],
3732
- subscribed_route_config_names,
3733
- [&update_map](absl::string_view resource_name_string,
3734
- XdsApi::ResourceName resource_name,
3735
- std::unique_ptr<XdsResourceType::ResourceData> resource,
3736
- std::string serialized_resource) {
3737
- return AddResult<RdsUpdateMap,
3738
- RouteConfigResourceType::RouteConfigData>(
3739
- &update_map, resource_name_string, std::move(resource_name),
3740
- std::move(resource), std::move(serialized_resource));
3741
- },
3742
- &result.resource_names_failed);
3743
- } else if (IsCds(result.type_url)) {
3744
- ClusterResourceType resource_type;
3745
- auto& update_map = result.cds_update_map;
3746
- parse_error = AdsResourceParse(
3747
- context, &resource_type, i, resources[i], subscribed_cluster_names,
3748
- [&update_map](absl::string_view resource_name_string,
3749
- XdsApi::ResourceName resource_name,
3750
- std::unique_ptr<XdsResourceType::ResourceData> resource,
3751
- std::string serialized_resource) {
3752
- return AddResult<CdsUpdateMap, ClusterResourceType::ClusterData>(
3753
- &update_map, resource_name_string, std::move(resource_name),
3754
- std::move(resource), std::move(serialized_resource));
3755
- },
3756
- &result.resource_names_failed);
3757
- } else if (IsEds(result.type_url)) {
3758
- EndpointResourceType resource_type;
3759
- auto& update_map = result.eds_update_map;
3760
- parse_error = AdsResourceParse(
3761
- context, &resource_type, i, resources[i],
3762
- subscribed_eds_service_names,
3763
- [&update_map](absl::string_view resource_name_string,
3764
- XdsApi::ResourceName resource_name,
3765
- std::unique_ptr<XdsResourceType::ResourceData> resource,
3766
- std::string serialized_resource) {
3767
- return AddResult<EdsUpdateMap, EndpointResourceType::EndpointData>(
3768
- &update_map, resource_name_string, std::move(resource_name),
3769
- std::move(resource), std::move(serialized_resource));
3770
- },
3771
- &result.resource_names_failed);
3772
- }
3773
- if (parse_error != GRPC_ERROR_NONE) errors.push_back(parse_error);
3774
- }
3775
- result.parse_error =
3776
- GRPC_ERROR_CREATE_FROM_VECTOR("errors parsing ADS response", &errors);
3777
- return result;
386
+ envoy_service_discovery_v3_DiscoveryResponse_resources(response,
387
+ &num_resources);
388
+ fields.num_resources = num_resources;
389
+ absl::Status status = parser->ProcessAdsResponseFields(std::move(fields));
390
+ if (!status.ok()) return status;
391
+ // Process each resource.
392
+ for (size_t i = 0; i < num_resources; ++i) {
393
+ absl::string_view type_url = absl::StripPrefix(
394
+ UpbStringToAbsl(google_protobuf_Any_type_url(resources[i])),
395
+ "type.googleapis.com/");
396
+ absl::string_view serialized_resource =
397
+ UpbStringToAbsl(google_protobuf_Any_value(resources[i]));
398
+ parser->ParseResource(context, i, type_url, serialized_resource);
399
+ }
400
+ return absl::OkStatus();
3778
401
  }
3779
402
 
3780
403
  namespace {
3781
404
 
3782
405
  void MaybeLogLrsRequest(
3783
- const EncodingContext& context,
406
+ const XdsEncodingContext& context,
3784
407
  const envoy_service_load_stats_v3_LoadStatsRequest* request) {
3785
408
  if (GRPC_TRACE_FLAG_ENABLED(*context.tracer) &&
3786
409
  gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
@@ -3794,7 +417,7 @@ void MaybeLogLrsRequest(
3794
417
  }
3795
418
 
3796
419
  grpc_slice SerializeLrsRequest(
3797
- const EncodingContext& context,
420
+ const XdsEncodingContext& context,
3798
421
  const envoy_service_load_stats_v3_LoadStatsRequest* request) {
3799
422
  size_t output_length;
3800
423
  char* output = envoy_service_load_stats_v3_LoadStatsRequest_serialize(
@@ -3807,12 +430,12 @@ grpc_slice SerializeLrsRequest(
3807
430
  grpc_slice XdsApi::CreateLrsInitialRequest(
3808
431
  const XdsBootstrap::XdsServer& server) {
3809
432
  upb::Arena arena;
3810
- const EncodingContext context = {client_,
3811
- tracer_,
3812
- symtab_.ptr(),
3813
- arena.ptr(),
3814
- server.ShouldUseV3(),
3815
- certificate_provider_definition_map_};
433
+ const XdsEncodingContext context = {client_,
434
+ tracer_,
435
+ symtab_->ptr(),
436
+ arena.ptr(),
437
+ server.ShouldUseV3(),
438
+ certificate_provider_definition_map_};
3816
439
  // Create a request.
3817
440
  envoy_service_load_stats_v3_LoadStatsRequest* request =
3818
441
  envoy_service_load_stats_v3_LoadStatsRequest_new(arena.ptr());
@@ -3832,7 +455,7 @@ grpc_slice XdsApi::CreateLrsInitialRequest(
3832
455
  namespace {
3833
456
 
3834
457
  void LocalityStatsPopulate(
3835
- const EncodingContext& context,
458
+ const XdsEncodingContext& context,
3836
459
  envoy_config_endpoint_v3_UpstreamLocalityStats* output,
3837
460
  const XdsLocalityName& locality_name,
3838
461
  const XdsClusterLocalityStats::Snapshot& snapshot) {
@@ -3882,8 +505,8 @@ void LocalityStatsPopulate(
3882
505
  grpc_slice XdsApi::CreateLrsRequest(
3883
506
  ClusterLoadReportMap cluster_load_report_map) {
3884
507
  upb::Arena arena;
3885
- const EncodingContext context = {
3886
- client_, tracer_, symtab_.ptr(),
508
+ const XdsEncodingContext context = {
509
+ client_, tracer_, symtab_->ptr(),
3887
510
  arena.ptr(), false, certificate_provider_definition_map_};
3888
511
  // Create a request.
3889
512
  envoy_service_load_stats_v3_LoadStatsRequest* request =
@@ -3986,8 +609,8 @@ grpc_error_handle XdsApi::ParseLrsResponse(
3986
609
 
3987
610
  namespace {
3988
611
 
3989
- google_protobuf_Timestamp* GrpcMillisToTimestamp(const EncodingContext& context,
3990
- grpc_millis value) {
612
+ google_protobuf_Timestamp* GrpcMillisToTimestamp(
613
+ const XdsEncodingContext& context, grpc_millis value) {
3991
614
  google_protobuf_Timestamp* timestamp =
3992
615
  google_protobuf_Timestamp_new(context.arena);
3993
616
  gpr_timespec timespec = grpc_millis_to_timespec(value, GPR_CLOCK_REALTIME);
@@ -4006,8 +629,8 @@ std::string XdsApi::AssembleClientConfig(
4006
629
  // Fill-in the node information
4007
630
  auto* node = envoy_service_status_v3_ClientConfig_mutable_node(client_config,
4008
631
  arena.ptr());
4009
- const EncodingContext context = {
4010
- client_, tracer_, symtab_.ptr(),
632
+ const XdsEncodingContext context = {
633
+ client_, tracer_, symtab_->ptr(),
4011
634
  arena.ptr(), true, certificate_provider_definition_map_};
4012
635
  PopulateNode(context, node_, build_version_, user_agent_name_,
4013
636
  user_agent_version_, node);