grpc 1.36.0 → 1.37.0.pre1

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 (221) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +65 -37
  3. data/include/grpc/grpc.h +15 -1
  4. data/include/grpc/impl/codegen/port_platform.h +2 -0
  5. data/src/core/ext/filters/client_channel/client_channel.cc +327 -305
  6. data/src/core/ext/filters/client_channel/client_channel_factory.h +2 -1
  7. data/src/core/ext/filters/client_channel/config_selector.h +8 -0
  8. data/src/core/ext/filters/client_channel/dynamic_filters.cc +9 -4
  9. data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +24 -142
  10. data/src/core/ext/filters/client_channel/global_subchannel_pool.h +15 -10
  11. data/src/core/ext/filters/client_channel/lb_policy.cc +3 -0
  12. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +23 -0
  13. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h +27 -0
  14. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +7 -22
  15. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +1 -1
  16. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +2 -2
  17. data/src/core/ext/filters/client_channel/local_subchannel_pool.cc +27 -67
  18. data/src/core/ext/filters/client_channel/local_subchannel_pool.h +10 -9
  19. data/src/core/ext/filters/client_channel/resolver.cc +3 -0
  20. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +2 -2
  21. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +3 -1
  22. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +5 -9
  23. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +18 -3
  24. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +295 -91
  25. data/src/core/ext/filters/client_channel/server_address.cc +3 -0
  26. data/src/core/ext/filters/client_channel/subchannel.cc +69 -146
  27. data/src/core/ext/filters/client_channel/subchannel.h +63 -95
  28. data/src/core/ext/filters/client_channel/subchannel_pool_interface.cc +16 -2
  29. data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +10 -8
  30. data/src/core/ext/filters/client_idle/client_idle_filter.cc +1 -1
  31. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +495 -0
  32. data/src/core/ext/filters/fault_injection/fault_injection_filter.h +39 -0
  33. data/src/core/ext/filters/fault_injection/service_config_parser.cc +189 -0
  34. data/src/core/ext/filters/fault_injection/service_config_parser.h +85 -0
  35. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc +1 -1
  36. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +1 -1
  37. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +3 -2
  38. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +1 -1
  39. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +3 -2
  40. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +457 -170
  41. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
  42. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +39 -7
  43. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +12 -1
  44. data/src/core/ext/transport/chttp2/transport/frame_data.cc +5 -1
  45. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +1 -1
  46. data/src/core/ext/transport/chttp2/transport/internal.h +1 -0
  47. data/src/core/ext/upb-generated/envoy/admin/v3/config_dump.upb.c +406 -0
  48. data/src/core/ext/upb-generated/envoy/admin/v3/config_dump.upb.h +1459 -0
  49. data/src/core/ext/upb-generated/envoy/config/bootstrap/v3/bootstrap.upb.c +350 -0
  50. data/src/core/ext/upb-generated/envoy/config/bootstrap/v3/bootstrap.upb.h +1348 -0
  51. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +6 -0
  52. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +25 -0
  53. data/src/core/ext/upb-generated/envoy/config/metrics/v3/stats.upb.c +144 -0
  54. data/src/core/ext/upb-generated/envoy/config/metrics/v3/stats.upb.h +488 -0
  55. data/src/core/ext/upb-generated/envoy/config/overload/v3/overload.upb.c +141 -0
  56. data/src/core/ext/upb-generated/envoy/config/overload/v3/overload.upb.h +452 -0
  57. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +15 -0
  58. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +44 -0
  59. data/src/core/ext/upb-generated/envoy/extensions/filters/common/fault/v3/fault.upb.c +79 -0
  60. data/src/core/ext/upb-generated/envoy/extensions/filters/common/fault/v3/fault.upb.h +268 -0
  61. data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.c +78 -0
  62. data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.h +281 -0
  63. data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.c +41 -0
  64. data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.h +113 -0
  65. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +6 -5
  66. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +13 -9
  67. data/src/core/ext/upb-generated/envoy/service/status/v3/csds.upb.c +93 -0
  68. data/src/core/ext/upb-generated/envoy/service/status/v3/csds.upb.h +323 -0
  69. data/src/core/ext/upb-generated/envoy/type/matcher/v3/node.upb.c +36 -0
  70. data/src/core/ext/upb-generated/envoy/type/matcher/v3/node.upb.h +90 -0
  71. data/src/core/ext/upb-generated/envoy/type/matcher/v3/struct.upb.c +46 -0
  72. data/src/core/ext/upb-generated/envoy/type/matcher/v3/struct.upb.h +124 -0
  73. data/src/core/ext/upb-generated/udpa/type/v1/typed_struct.upb.c +33 -0
  74. data/src/core/ext/upb-generated/udpa/type/v1/typed_struct.upb.h +77 -0
  75. data/src/core/ext/upbdefs-generated/envoy/admin/v3/config_dump.upbdefs.c +354 -0
  76. data/src/core/ext/upbdefs-generated/envoy/admin/v3/config_dump.upbdefs.h +140 -0
  77. data/src/core/ext/upbdefs-generated/envoy/config/bootstrap/v3/bootstrap.upbdefs.c +383 -0
  78. data/src/core/ext/upbdefs-generated/envoy/config/bootstrap/v3/bootstrap.upbdefs.h +115 -0
  79. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.c +10 -7
  80. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.h +5 -0
  81. data/src/core/ext/upbdefs-generated/envoy/config/metrics/v3/stats.upbdefs.c +141 -0
  82. data/src/core/ext/upbdefs-generated/envoy/config/metrics/v3/stats.upbdefs.h +70 -0
  83. data/src/core/ext/upbdefs-generated/envoy/config/overload/v3/overload.upbdefs.c +141 -0
  84. data/src/core/ext/upbdefs-generated/envoy/config/overload/v3/overload.upbdefs.h +70 -0
  85. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.c +13 -7
  86. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.h +5 -0
  87. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/common/fault/v3/fault.upbdefs.c +102 -0
  88. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/common/fault/v3/fault.upbdefs.h +55 -0
  89. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/fault/v3/fault.upbdefs.c +120 -0
  90. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/fault/v3/fault.upbdefs.h +45 -0
  91. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/router/v3/router.upbdefs.c +76 -0
  92. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/router/v3/router.upbdefs.h +35 -0
  93. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +21 -20
  94. data/src/core/ext/upbdefs-generated/envoy/service/status/v3/csds.upbdefs.c +130 -0
  95. data/src/core/ext/upbdefs-generated/envoy/service/status/v3/csds.upbdefs.h +50 -0
  96. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/node.upbdefs.c +56 -0
  97. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/node.upbdefs.h +35 -0
  98. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/struct.upbdefs.c +63 -0
  99. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/struct.upbdefs.h +40 -0
  100. data/src/core/ext/upbdefs-generated/udpa/type/v1/typed_struct.upbdefs.c +44 -0
  101. data/src/core/ext/upbdefs-generated/udpa/type/v1/typed_struct.upbdefs.h +35 -0
  102. data/src/core/ext/xds/xds_api.cc +1591 -279
  103. data/src/core/ext/xds/xds_api.h +279 -39
  104. data/src/core/ext/xds/xds_bootstrap.cc +21 -5
  105. data/src/core/ext/xds/xds_bootstrap.h +5 -1
  106. data/src/core/ext/xds/xds_client.cc +168 -23
  107. data/src/core/ext/xds/xds_client.h +26 -0
  108. data/src/core/ext/xds/xds_client_stats.h +2 -2
  109. data/src/core/ext/xds/xds_http_fault_filter.cc +226 -0
  110. data/src/core/ext/xds/xds_http_fault_filter.h +63 -0
  111. data/src/core/ext/xds/xds_http_filters.cc +114 -0
  112. data/src/core/ext/xds/xds_http_filters.h +130 -0
  113. data/src/core/ext/xds/xds_server_config_fetcher.cc +391 -126
  114. data/src/core/lib/channel/channel_stack.cc +12 -0
  115. data/src/core/lib/channel/channel_stack.h +7 -0
  116. data/src/core/lib/channel/channelz.cc +92 -4
  117. data/src/core/lib/channel/channelz.h +30 -1
  118. data/src/core/lib/channel/channelz_registry.cc +14 -0
  119. data/src/core/lib/channel/handshaker.cc +0 -39
  120. data/src/core/lib/channel/handshaker.h +0 -17
  121. data/src/core/lib/channel/status_util.cc +12 -2
  122. data/src/core/lib/channel/status_util.h +5 -0
  123. data/src/core/lib/gpr/sync_abseil.cc +3 -6
  124. data/src/core/lib/gpr/sync_windows.cc +2 -2
  125. data/src/core/lib/gprpp/atomic.h +3 -3
  126. data/src/core/lib/gprpp/dual_ref_counted.h +3 -3
  127. data/src/core/lib/gprpp/ref_counted_ptr.h +2 -0
  128. data/src/core/lib/gprpp/thd.h +1 -1
  129. data/src/core/lib/iomgr/buffer_list.h +1 -1
  130. data/src/core/lib/iomgr/cfstream_handle.cc +2 -2
  131. data/src/core/lib/iomgr/error.h +1 -1
  132. data/src/core/lib/iomgr/ev_apple.cc +1 -1
  133. data/src/core/lib/iomgr/ev_epoll1_linux.cc +3 -3
  134. data/src/core/lib/iomgr/ev_posix.cc +3 -3
  135. data/src/core/lib/iomgr/exec_ctx.cc +6 -2
  136. data/src/core/lib/iomgr/resource_quota.cc +1 -1
  137. data/src/core/lib/iomgr/sockaddr_utils.cc +120 -0
  138. data/src/core/lib/iomgr/sockaddr_utils.h +25 -0
  139. data/src/core/lib/iomgr/tcp_posix.cc +1 -4
  140. data/src/core/lib/iomgr/tcp_uv.cc +2 -2
  141. data/src/core/lib/iomgr/timer_generic.cc +2 -2
  142. data/src/core/lib/iomgr/timer_manager.cc +1 -1
  143. data/src/core/lib/iomgr/wakeup_fd_nospecial.cc +1 -1
  144. data/src/core/lib/{security/authorization → matchers}/matchers.cc +8 -8
  145. data/src/core/lib/{security/authorization → matchers}/matchers.h +14 -12
  146. data/src/core/lib/security/security_connector/ssl_utils.cc +6 -4
  147. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +6 -0
  148. data/src/core/lib/security/transport/security_handshaker.cc +32 -2
  149. data/src/core/lib/slice/slice_intern.cc +6 -7
  150. data/src/core/lib/surface/channel.h +3 -3
  151. data/src/core/lib/surface/completion_queue.cc +1 -1
  152. data/src/core/lib/surface/lame_client.cc +38 -19
  153. data/src/core/lib/surface/lame_client.h +4 -3
  154. data/src/core/lib/surface/server.cc +40 -33
  155. data/src/core/lib/surface/server.h +74 -15
  156. data/src/core/lib/surface/version.cc +1 -1
  157. data/src/core/lib/transport/metadata_batch.cc +27 -0
  158. data/src/core/lib/transport/metadata_batch.h +14 -0
  159. data/src/core/plugin_registry/grpc_plugin_registry.cc +6 -0
  160. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +1 -4
  161. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +1 -1
  162. data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +1 -3
  163. data/src/core/tsi/fake_transport_security.cc +10 -1
  164. data/src/ruby/ext/grpc/extconf.rb +9 -1
  165. data/src/ruby/ext/grpc/rb_channel.c +10 -1
  166. data/src/ruby/ext/grpc/rb_channel_credentials.c +11 -1
  167. data/src/ruby/ext/grpc/rb_channel_credentials.h +4 -0
  168. data/src/ruby/ext/grpc/rb_compression_options.c +1 -1
  169. data/src/ruby/ext/grpc/rb_enable_cpp.cc +1 -1
  170. data/src/ruby/ext/grpc/rb_grpc.c +4 -0
  171. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  172. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +4 -1
  173. data/src/ruby/ext/grpc/rb_server.c +13 -1
  174. data/src/ruby/ext/grpc/rb_server_credentials.c +19 -3
  175. data/src/ruby/ext/grpc/rb_server_credentials.h +4 -0
  176. data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +215 -0
  177. data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +35 -0
  178. data/src/ruby/ext/grpc/rb_xds_server_credentials.c +169 -0
  179. data/src/ruby/ext/grpc/rb_xds_server_credentials.h +35 -0
  180. data/src/ruby/lib/grpc/generic/client_stub.rb +4 -2
  181. data/src/ruby/lib/grpc/version.rb +1 -1
  182. data/src/ruby/spec/call_spec.rb +1 -1
  183. data/src/ruby/spec/channel_credentials_spec.rb +32 -0
  184. data/src/ruby/spec/channel_spec.rb +17 -6
  185. data/src/ruby/spec/client_auth_spec.rb +27 -1
  186. data/src/ruby/spec/errors_spec.rb +1 -1
  187. data/src/ruby/spec/generic/active_call_spec.rb +2 -2
  188. data/src/ruby/spec/generic/client_stub_spec.rb +4 -4
  189. data/src/ruby/spec/generic/rpc_server_spec.rb +1 -1
  190. data/src/ruby/spec/server_credentials_spec.rb +25 -0
  191. data/src/ruby/spec/server_spec.rb +22 -0
  192. data/third_party/boringssl-with-bazel/err_data.c +255 -255
  193. data/third_party/boringssl-with-bazel/src/crypto/cpu-arm-linux.c +11 -2
  194. data/third_party/boringssl-with-bazel/src/crypto/cpu-arm.c +3 -3
  195. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/cipher.c +21 -13
  196. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/rand.c +7 -5
  197. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +0 -28
  198. data/third_party/boringssl-with-bazel/src/crypto/x509/x_attrib.c +22 -17
  199. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.c +3 -1
  200. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +4 -0
  201. data/third_party/boringssl-with-bazel/src/include/openssl/cpu.h +22 -32
  202. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +25 -9
  203. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +0 -1
  204. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +33 -19
  205. data/third_party/xxhash/xxhash.h +5443 -0
  206. metadata +93 -49
  207. data/src/core/lib/security/authorization/authorization_engine.cc +0 -177
  208. data/src/core/lib/security/authorization/authorization_engine.h +0 -84
  209. data/src/core/lib/security/authorization/evaluate_args.cc +0 -148
  210. data/src/core/lib/security/authorization/evaluate_args.h +0 -59
  211. data/src/core/lib/security/authorization/mock_cel/activation.h +0 -57
  212. data/src/core/lib/security/authorization/mock_cel/cel_expr_builder_factory.h +0 -44
  213. data/src/core/lib/security/authorization/mock_cel/cel_expression.h +0 -69
  214. data/src/core/lib/security/authorization/mock_cel/cel_value.h +0 -99
  215. data/src/core/lib/security/authorization/mock_cel/evaluator_core.h +0 -67
  216. data/src/core/lib/security/authorization/mock_cel/flat_expr_builder.h +0 -57
  217. data/third_party/abseil-cpp/absl/container/flat_hash_set.h +0 -504
  218. data/third_party/upb/upb/json_decode.c +0 -1443
  219. data/third_party/upb/upb/json_decode.h +0 -23
  220. data/third_party/upb/upb/json_encode.c +0 -713
  221. data/third_party/upb/upb/json_encode.h +0 -36
@@ -0,0 +1,63 @@
1
+ /* This file was generated by upbc (the upb compiler) from the input
2
+ * file:
3
+ *
4
+ * envoy/type/matcher/v3/struct.proto
5
+ *
6
+ * Do not edit -- your changes will be discarded when the file is
7
+ * regenerated. */
8
+
9
+ #include "upb/def.h"
10
+ #include "envoy/type/matcher/v3/struct.upbdefs.h"
11
+
12
+ extern upb_def_init envoy_type_matcher_v3_value_proto_upbdefinit;
13
+ extern upb_def_init udpa_annotations_status_proto_upbdefinit;
14
+ extern upb_def_init udpa_annotations_versioning_proto_upbdefinit;
15
+ extern upb_def_init validate_validate_proto_upbdefinit;
16
+ extern const upb_msglayout envoy_type_matcher_v3_StructMatcher_msginit;
17
+ extern const upb_msglayout envoy_type_matcher_v3_StructMatcher_PathSegment_msginit;
18
+
19
+ static const upb_msglayout *layouts[2] = {
20
+ &envoy_type_matcher_v3_StructMatcher_msginit,
21
+ &envoy_type_matcher_v3_StructMatcher_PathSegment_msginit,
22
+ };
23
+
24
+ static const char descriptor[576] = {'\n', '\"', 'e', 'n', 'v', 'o', 'y', '/', 't', 'y', 'p', 'e', '/', 'm', 'a', 't', 'c', 'h', 'e', 'r', '/', 'v', '3', '/', 's',
25
+ 't', 'r', 'u', 'c', 't', '.', 'p', 'r', 'o', 't', 'o', '\022', '\025', 'e', 'n', 'v', 'o', 'y', '.', 't', 'y', 'p', 'e', '.', 'm',
26
+ 'a', 't', 'c', 'h', 'e', 'r', '.', 'v', '3', '\032', '!', 'e', 'n', 'v', 'o', 'y', '/', 't', 'y', 'p', 'e', '/', 'm', 'a', 't',
27
+ 'c', 'h', 'e', 'r', '/', 'v', '3', '/', 'v', 'a', 'l', 'u', 'e', '.', 'p', 'r', 'o', 't', 'o', '\032', '\035', 'u', 'd', 'p', 'a',
28
+ '/', 'a', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', 's', '/', 's', 't', 'a', 't', 'u', 's', '.', 'p', 'r', 'o', 't', 'o',
29
+ '\032', '!', 'u', 'd', 'p', 'a', '/', 'a', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', 's', '/', 'v', 'e', 'r', 's', 'i', 'o',
30
+ 'n', 'i', 'n', 'g', '.', 'p', 'r', 'o', 't', 'o', '\032', '\027', 'v', 'a', 'l', 'i', 'd', 'a', 't', 'e', '/', 'v', 'a', 'l', 'i',
31
+ 'd', 'a', 't', 'e', '.', 'p', 'r', 'o', 't', 'o', '\"', '\276', '\002', '\n', '\r', 'S', 't', 'r', 'u', 'c', 't', 'M', 'a', 't', 'c',
32
+ 'h', 'e', 'r', '\022', 'N', '\n', '\004', 'p', 'a', 't', 'h', '\030', '\002', ' ', '\003', '(', '\013', '2', '0', '.', 'e', 'n', 'v', 'o', 'y',
33
+ '.', 't', 'y', 'p', 'e', '.', 'm', 'a', 't', 'c', 'h', 'e', 'r', '.', 'v', '3', '.', 'S', 't', 'r', 'u', 'c', 't', 'M', 'a',
34
+ 't', 'c', 'h', 'e', 'r', '.', 'P', 'a', 't', 'h', 'S', 'e', 'g', 'm', 'e', 'n', 't', 'B', '\010', '\372', 'B', '\005', '\222', '\001', '\002',
35
+ '\010', '\001', 'R', '\004', 'p', 'a', 't', 'h', '\022', 'C', '\n', '\005', 'v', 'a', 'l', 'u', 'e', '\030', '\003', ' ', '\001', '(', '\013', '2', '#',
36
+ '.', 'e', 'n', 'v', 'o', 'y', '.', 't', 'y', 'p', 'e', '.', 'm', 'a', 't', 'c', 'h', 'e', 'r', '.', 'v', '3', '.', 'V', 'a',
37
+ 'l', 'u', 'e', 'M', 'a', 't', 'c', 'h', 'e', 'r', 'B', '\010', '\372', 'B', '\005', '\212', '\001', '\002', '\020', '\001', 'R', '\005', 'v', 'a', 'l',
38
+ 'u', 'e', '\032', 'o', '\n', '\013', 'P', 'a', 't', 'h', 'S', 'e', 'g', 'm', 'e', 'n', 't', '\022', '\033', '\n', '\003', 'k', 'e', 'y', '\030',
39
+ '\001', ' ', '\001', '(', '\t', 'B', '\007', '\372', 'B', '\004', 'r', '\002', '\020', '\001', 'H', '\000', 'R', '\003', 'k', 'e', 'y', ':', '3', '\232', '\305',
40
+ '\210', '\036', '.', '\n', ',', 'e', 'n', 'v', 'o', 'y', '.', 't', 'y', 'p', 'e', '.', 'm', 'a', 't', 'c', 'h', 'e', 'r', '.', 'S',
41
+ 't', 'r', 'u', 'c', 't', 'M', 'a', 't', 'c', 'h', 'e', 'r', '.', 'P', 'a', 't', 'h', 'S', 'e', 'g', 'm', 'e', 'n', 't', 'B',
42
+ '\016', '\n', '\007', 's', 'e', 'g', 'm', 'e', 'n', 't', '\022', '\003', '\370', 'B', '\001', ':', '\'', '\232', '\305', '\210', '\036', '\"', '\n', ' ', 'e',
43
+ 'n', 'v', 'o', 'y', '.', 't', 'y', 'p', 'e', '.', 'm', 'a', 't', 'c', 'h', 'e', 'r', '.', 'S', 't', 'r', 'u', 'c', 't', 'M',
44
+ 'a', 't', 'c', 'h', 'e', 'r', 'B', '<', '\n', '#', 'i', 'o', '.', 'e', 'n', 'v', 'o', 'y', 'p', 'r', 'o', 'x', 'y', '.', 'e',
45
+ 'n', 'v', 'o', 'y', '.', 't', 'y', 'p', 'e', '.', 'm', 'a', 't', 'c', 'h', 'e', 'r', '.', 'v', '3', 'B', '\013', 'S', 't', 'r',
46
+ 'u', 'c', 't', 'P', 'r', 'o', 't', 'o', 'P', '\001', '\272', '\200', '\310', '\321', '\006', '\002', '\020', '\002', 'b', '\006', 'p', 'r', 'o', 't', 'o',
47
+ '3',
48
+ };
49
+
50
+ static upb_def_init *deps[5] = {
51
+ &envoy_type_matcher_v3_value_proto_upbdefinit,
52
+ &udpa_annotations_status_proto_upbdefinit,
53
+ &udpa_annotations_versioning_proto_upbdefinit,
54
+ &validate_validate_proto_upbdefinit,
55
+ NULL
56
+ };
57
+
58
+ upb_def_init envoy_type_matcher_v3_struct_proto_upbdefinit = {
59
+ deps,
60
+ layouts,
61
+ "envoy/type/matcher/v3/struct.proto",
62
+ UPB_STRVIEW_INIT(descriptor, 576)
63
+ };
@@ -0,0 +1,40 @@
1
+ /* This file was generated by upbc (the upb compiler) from the input
2
+ * file:
3
+ *
4
+ * envoy/type/matcher/v3/struct.proto
5
+ *
6
+ * Do not edit -- your changes will be discarded when the file is
7
+ * regenerated. */
8
+
9
+ #ifndef ENVOY_TYPE_MATCHER_V3_STRUCT_PROTO_UPBDEFS_H_
10
+ #define ENVOY_TYPE_MATCHER_V3_STRUCT_PROTO_UPBDEFS_H_
11
+
12
+ #include "upb/def.h"
13
+ #include "upb/port_def.inc"
14
+ #ifdef __cplusplus
15
+ extern "C" {
16
+ #endif
17
+
18
+ #include "upb/def.h"
19
+
20
+ #include "upb/port_def.inc"
21
+
22
+ extern upb_def_init envoy_type_matcher_v3_struct_proto_upbdefinit;
23
+
24
+ UPB_INLINE const upb_msgdef *envoy_type_matcher_v3_StructMatcher_getmsgdef(upb_symtab *s) {
25
+ _upb_symtab_loaddefinit(s, &envoy_type_matcher_v3_struct_proto_upbdefinit);
26
+ return upb_symtab_lookupmsg(s, "envoy.type.matcher.v3.StructMatcher");
27
+ }
28
+
29
+ UPB_INLINE const upb_msgdef *envoy_type_matcher_v3_StructMatcher_PathSegment_getmsgdef(upb_symtab *s) {
30
+ _upb_symtab_loaddefinit(s, &envoy_type_matcher_v3_struct_proto_upbdefinit);
31
+ return upb_symtab_lookupmsg(s, "envoy.type.matcher.v3.StructMatcher.PathSegment");
32
+ }
33
+
34
+ #ifdef __cplusplus
35
+ } /* extern "C" */
36
+ #endif
37
+
38
+ #include "upb/port_undef.inc"
39
+
40
+ #endif /* ENVOY_TYPE_MATCHER_V3_STRUCT_PROTO_UPBDEFS_H_ */
@@ -0,0 +1,44 @@
1
+ /* This file was generated by upbc (the upb compiler) from the input
2
+ * file:
3
+ *
4
+ * udpa/type/v1/typed_struct.proto
5
+ *
6
+ * Do not edit -- your changes will be discarded when the file is
7
+ * regenerated. */
8
+
9
+ #include "upb/def.h"
10
+ #include "udpa/type/v1/typed_struct.upbdefs.h"
11
+
12
+ extern upb_def_init validate_validate_proto_upbdefinit;
13
+ extern upb_def_init google_protobuf_struct_proto_upbdefinit;
14
+ extern const upb_msglayout udpa_type_v1_TypedStruct_msginit;
15
+
16
+ static const upb_msglayout *layouts[1] = {
17
+ &udpa_type_v1_TypedStruct_msginit,
18
+ };
19
+
20
+ static const char descriptor[251] = {'\n', '\037', 'u', 'd', 'p', 'a', '/', 't', 'y', 'p', 'e', '/', 'v', '1', '/', 't', 'y', 'p', 'e', 'd', '_', 's', 't', 'r', 'u',
21
+ 'c', 't', '.', 'p', 'r', 'o', 't', 'o', '\022', '\014', 'u', 'd', 'p', 'a', '.', 't', 'y', 'p', 'e', '.', 'v', '1', '\032', '\027', 'v',
22
+ 'a', 'l', 'i', 'd', 'a', 't', 'e', '/', 'v', 'a', 'l', 'i', 'd', 'a', 't', 'e', '.', 'p', 'r', 'o', 't', 'o', '\032', '\034', 'g',
23
+ 'o', 'o', 'g', 'l', 'e', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 's', 't', 'r', 'u', 'c', 't', '.', 'p', 'r', 'o',
24
+ 't', 'o', '\"', 'W', '\n', '\013', 'T', 'y', 'p', 'e', 'd', 'S', 't', 'r', 'u', 'c', 't', '\022', '\031', '\n', '\010', 't', 'y', 'p', 'e',
25
+ '_', 'u', 'r', 'l', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\007', 't', 'y', 'p', 'e', 'U', 'r', 'l', '\022', '-', '\n', '\005', 'v', 'a',
26
+ 'l', 'u', 'e', '\030', '\002', ' ', '\001', '(', '\013', '2', '\027', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b',
27
+ 'u', 'f', '.', 'S', 't', 'r', 'u', 'c', 't', 'R', '\005', 'v', 'a', 'l', 'u', 'e', 'B', '2', '\n', '\034', 'c', 'o', 'm', '.', 'g',
28
+ 'i', 't', 'h', 'u', 'b', '.', 'u', 'd', 'p', 'a', '.', 'u', 'd', 'p', 'a', '.', 't', 'y', 'p', 'e', '.', 'v', '1', 'B', '\020',
29
+ 'T', 'y', 'p', 'e', 'd', 'S', 't', 'r', 'u', 'c', 't', 'P', 'r', 'o', 't', 'o', 'P', '\001', 'b', '\006', 'p', 'r', 'o', 't', 'o',
30
+ '3',
31
+ };
32
+
33
+ static upb_def_init *deps[3] = {
34
+ &validate_validate_proto_upbdefinit,
35
+ &google_protobuf_struct_proto_upbdefinit,
36
+ NULL
37
+ };
38
+
39
+ upb_def_init udpa_type_v1_typed_struct_proto_upbdefinit = {
40
+ deps,
41
+ layouts,
42
+ "udpa/type/v1/typed_struct.proto",
43
+ UPB_STRVIEW_INIT(descriptor, 251)
44
+ };
@@ -0,0 +1,35 @@
1
+ /* This file was generated by upbc (the upb compiler) from the input
2
+ * file:
3
+ *
4
+ * udpa/type/v1/typed_struct.proto
5
+ *
6
+ * Do not edit -- your changes will be discarded when the file is
7
+ * regenerated. */
8
+
9
+ #ifndef UDPA_TYPE_V1_TYPED_STRUCT_PROTO_UPBDEFS_H_
10
+ #define UDPA_TYPE_V1_TYPED_STRUCT_PROTO_UPBDEFS_H_
11
+
12
+ #include "upb/def.h"
13
+ #include "upb/port_def.inc"
14
+ #ifdef __cplusplus
15
+ extern "C" {
16
+ #endif
17
+
18
+ #include "upb/def.h"
19
+
20
+ #include "upb/port_def.inc"
21
+
22
+ extern upb_def_init udpa_type_v1_typed_struct_proto_upbdefinit;
23
+
24
+ UPB_INLINE const upb_msgdef *udpa_type_v1_TypedStruct_getmsgdef(upb_symtab *s) {
25
+ _upb_symtab_loaddefinit(s, &udpa_type_v1_typed_struct_proto_upbdefinit);
26
+ return upb_symtab_lookupmsg(s, "udpa.type.v1.TypedStruct");
27
+ }
28
+
29
+ #ifdef __cplusplus
30
+ } /* extern "C" */
31
+ #endif
32
+
33
+ #include "upb/port_undef.inc"
34
+
35
+ #endif /* UDPA_TYPE_V1_TYPED_STRUCT_PROTO_UPBDEFS_H_ */
@@ -28,27 +28,13 @@
28
28
  #include "absl/strings/str_format.h"
29
29
  #include "absl/strings/str_join.h"
30
30
  #include "absl/strings/str_split.h"
31
-
32
- #include "upb/upb.hpp"
33
-
34
- #include <grpc/impl/codegen/log.h>
35
- #include <grpc/support/alloc.h>
36
- #include <grpc/support/string_util.h>
37
-
38
- #include "src/core/ext/xds/xds_api.h"
39
- #include "src/core/lib/gpr/env.h"
40
- #include "src/core/lib/gpr/string.h"
41
- #include "src/core/lib/gpr/useful.h"
42
- #include "src/core/lib/gprpp/host_port.h"
43
- #include "src/core/lib/iomgr/error.h"
44
- #include "src/core/lib/iomgr/sockaddr_utils.h"
45
- #include "src/core/lib/slice/slice_utils.h"
46
-
31
+ #include "envoy/admin/v3/config_dump.upb.h"
47
32
  #include "envoy/config/cluster/v3/circuit_breaker.upb.h"
48
33
  #include "envoy/config/cluster/v3/cluster.upb.h"
49
34
  #include "envoy/config/cluster/v3/cluster.upbdefs.h"
50
35
  #include "envoy/config/core/v3/address.upb.h"
51
36
  #include "envoy/config/core/v3/base.upb.h"
37
+ #include "envoy/config/core/v3/base.upbdefs.h"
52
38
  #include "envoy/config/core/v3/config_source.upb.h"
53
39
  #include "envoy/config/core/v3/health_check.upb.h"
54
40
  #include "envoy/config/core/v3/protocol.upb.h"
@@ -58,14 +44,19 @@
58
44
  #include "envoy/config/endpoint/v3/load_report.upb.h"
59
45
  #include "envoy/config/listener/v3/api_listener.upb.h"
60
46
  #include "envoy/config/listener/v3/listener.upb.h"
47
+ #include "envoy/config/listener/v3/listener.upbdefs.h"
61
48
  #include "envoy/config/listener/v3/listener_components.upb.h"
62
49
  #include "envoy/config/route/v3/route.upb.h"
63
50
  #include "envoy/config/route/v3/route.upbdefs.h"
64
51
  #include "envoy/config/route/v3/route_components.upb.h"
52
+ #include "envoy/config/route/v3/route_components.upbdefs.h"
65
53
  #include "envoy/extensions/clusters/aggregate/v3/cluster.upb.h"
54
+ #include "envoy/extensions/clusters/aggregate/v3/cluster.upbdefs.h"
66
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"
67
57
  #include "envoy/extensions/transport_sockets/tls/v3/common.upb.h"
68
58
  #include "envoy/extensions/transport_sockets/tls/v3/tls.upb.h"
59
+ #include "envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.h"
69
60
  #include "envoy/service/cluster/v3/cds.upb.h"
70
61
  #include "envoy/service/cluster/v3/cds.upbdefs.h"
71
62
  #include "envoy/service/discovery/v3/discovery.upb.h"
@@ -77,6 +68,8 @@
77
68
  #include "envoy/service/load_stats/v3/lrs.upbdefs.h"
78
69
  #include "envoy/service/route/v3/rds.upb.h"
79
70
  #include "envoy/service/route/v3/rds.upbdefs.h"
71
+ #include "envoy/service/status/v3/csds.upb.h"
72
+ #include "envoy/service/status/v3/csds.upbdefs.h"
80
73
  #include "envoy/type/matcher/v3/regex.upb.h"
81
74
  #include "envoy/type/matcher/v3/string.upb.h"
82
75
  #include "envoy/type/v3/percent.upb.h"
@@ -84,23 +77,30 @@
84
77
  #include "google/protobuf/any.upb.h"
85
78
  #include "google/protobuf/duration.upb.h"
86
79
  #include "google/protobuf/struct.upb.h"
80
+ #include "google/protobuf/timestamp.upb.h"
87
81
  #include "google/protobuf/wrappers.upb.h"
88
82
  #include "google/rpc/status.upb.h"
83
+ #include "udpa/type/v1/typed_struct.upb.h"
89
84
  #include "upb/text_encode.h"
90
85
  #include "upb/upb.h"
86
+ #include "upb/upb.hpp"
91
87
 
92
- namespace grpc_core {
88
+ #include <grpc/impl/codegen/log.h>
89
+ #include <grpc/support/alloc.h>
90
+ #include <grpc/support/string_util.h>
93
91
 
94
- // TODO(donnadionne): Check to see if timeout is enabled, this will be
95
- // removed once timeout feature is fully integration-tested and enabled by
96
- // default.
97
- bool XdsTimeoutEnabled() {
98
- char* value = gpr_getenv("GRPC_XDS_EXPERIMENTAL_ENABLE_TIMEOUT");
99
- bool parsed_value;
100
- bool parse_succeeded = gpr_parse_bool_value(value, &parsed_value);
101
- gpr_free(value);
102
- return parse_succeeded && parsed_value;
103
- }
92
+ #include "src/core/ext/xds/xds_api.h"
93
+ #include "src/core/lib/gpr/env.h"
94
+ #include "src/core/lib/gpr/string.h"
95
+ #include "src/core/lib/gpr/useful.h"
96
+ #include "src/core/lib/gprpp/host_port.h"
97
+ #include "src/core/lib/iomgr/error.h"
98
+ #include "src/core/lib/iomgr/sockaddr.h"
99
+ #include "src/core/lib/iomgr/sockaddr_utils.h"
100
+ #include "src/core/lib/iomgr/socket_utils.h"
101
+ #include "src/core/lib/slice/slice_utils.h"
102
+
103
+ namespace grpc_core {
104
104
 
105
105
  // TODO(donnadionne): Check to see if cluster types aggregate_cluster and
106
106
  // logical_dns are enabled, this will be
@@ -137,6 +137,83 @@ bool XdsSecurityEnabled() {
137
137
  return parse_succeeded && parsed_value;
138
138
  }
139
139
 
140
+ //
141
+ // XdsApi::Route::HashPolicy
142
+ //
143
+
144
+ XdsApi::Route::HashPolicy::HashPolicy(const HashPolicy& other)
145
+ : type(other.type),
146
+ header_name(other.header_name),
147
+ regex_substitution(other.regex_substitution) {
148
+ if (other.regex != nullptr) {
149
+ regex =
150
+ absl::make_unique<RE2>(other.regex->pattern(), other.regex->options());
151
+ }
152
+ }
153
+
154
+ XdsApi::Route::HashPolicy& XdsApi::Route::HashPolicy::operator=(
155
+ const HashPolicy& other) {
156
+ type = other.type;
157
+ header_name = other.header_name;
158
+ if (other.regex != nullptr) {
159
+ regex =
160
+ absl::make_unique<RE2>(other.regex->pattern(), other.regex->options());
161
+ }
162
+ regex_substitution = other.regex_substitution;
163
+ return *this;
164
+ }
165
+
166
+ XdsApi::Route::HashPolicy::HashPolicy(HashPolicy&& other) noexcept
167
+ : type(other.type),
168
+ header_name(std::move(other.header_name)),
169
+ regex(std::move(other.regex)),
170
+ regex_substitution(std::move(other.regex_substitution)) {}
171
+
172
+ XdsApi::Route::HashPolicy& XdsApi::Route::HashPolicy::operator=(
173
+ HashPolicy&& other) noexcept {
174
+ type = other.type;
175
+ header_name = std::move(other.header_name);
176
+ regex = std::move(other.regex);
177
+ regex_substitution = std::move(other.regex_substitution);
178
+ return *this;
179
+ }
180
+
181
+ bool XdsApi::Route::HashPolicy::HashPolicy::operator==(
182
+ const HashPolicy& other) const {
183
+ if (type != other.type) return false;
184
+ if (type == Type::HEADER) {
185
+ if (regex == nullptr) {
186
+ if (other.regex != nullptr) return false;
187
+ } else {
188
+ if (other.regex == nullptr) return false;
189
+ return header_name == other.header_name &&
190
+ regex->pattern() == other.regex->pattern() &&
191
+ regex_substitution == other.regex_substitution;
192
+ }
193
+ }
194
+ return true;
195
+ }
196
+
197
+ std::string XdsApi::Route::HashPolicy::ToString() const {
198
+ std::vector<std::string> contents;
199
+ switch (type) {
200
+ case Type::HEADER:
201
+ contents.push_back("type=HEADER");
202
+ break;
203
+ case Type::CHANNEL_ID:
204
+ contents.push_back("type=CHANNEL_ID");
205
+ break;
206
+ }
207
+ contents.push_back(
208
+ absl::StrFormat("terminal=%s", terminal ? "true" : "false"));
209
+ if (type == Type::HEADER) {
210
+ contents.push_back(absl::StrFormat(
211
+ "Header %s:/%s/%s", header_name,
212
+ (regex == nullptr) ? "" : regex->pattern(), regex_substitution));
213
+ }
214
+ return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
215
+ }
216
+
140
217
  //
141
218
  // XdsApi::Route
142
219
  //
@@ -156,12 +233,28 @@ std::string XdsApi::Route::Matchers::ToString() const {
156
233
  }
157
234
 
158
235
  std::string XdsApi::Route::ClusterWeight::ToString() const {
159
- return absl::StrFormat("{cluster=%s, weight=%d}", name, weight);
236
+ std::vector<std::string> contents;
237
+ contents.push_back(absl::StrCat("cluster=", name));
238
+ contents.push_back(absl::StrCat("weight=", weight));
239
+ if (!typed_per_filter_config.empty()) {
240
+ std::vector<std::string> parts;
241
+ for (const auto& p : typed_per_filter_config) {
242
+ const std::string& key = p.first;
243
+ const auto& config = p.second;
244
+ parts.push_back(absl::StrCat(key, "=", config.ToString()));
245
+ }
246
+ contents.push_back(absl::StrCat("typed_per_filter_config={",
247
+ absl::StrJoin(parts, ", "), "}"));
248
+ }
249
+ return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
160
250
  }
161
251
 
162
252
  std::string XdsApi::Route::ToString() const {
163
253
  std::vector<std::string> contents;
164
254
  contents.push_back(matchers.ToString());
255
+ for (const HashPolicy& hash_policy : hash_policies) {
256
+ contents.push_back(absl::StrCat("hash_policy=", hash_policy.ToString()));
257
+ }
165
258
  if (!cluster_name.empty()) {
166
259
  contents.push_back(absl::StrFormat("Cluster name: %s", cluster_name));
167
260
  }
@@ -171,6 +264,15 @@ std::string XdsApi::Route::ToString() const {
171
264
  if (max_stream_duration.has_value()) {
172
265
  contents.push_back(max_stream_duration->ToString());
173
266
  }
267
+ if (!typed_per_filter_config.empty()) {
268
+ contents.push_back("typed_per_filter_config={");
269
+ for (const auto& p : typed_per_filter_config) {
270
+ const std::string& name = p.first;
271
+ const auto& config = p.second;
272
+ contents.push_back(absl::StrCat(" ", name, "=", config.ToString()));
273
+ }
274
+ contents.push_back("}");
275
+ }
174
276
  return absl::StrJoin(contents, "\n");
175
277
  }
176
278
 
@@ -193,6 +295,14 @@ std::string XdsApi::RdsUpdate::ToString() const {
193
295
  vhosts.push_back("\n }\n");
194
296
  }
195
297
  vhosts.push_back(" ]\n");
298
+ vhosts.push_back(" typed_per_filter_config={\n");
299
+ for (const auto& p : vhost.typed_per_filter_config) {
300
+ const std::string& name = p.first;
301
+ const auto& config = p.second;
302
+ vhosts.push_back(
303
+ absl::StrCat(" ", name, "=", config.ToString(), "\n"));
304
+ }
305
+ vhosts.push_back(" }\n");
196
306
  vhosts.push_back("]\n");
197
307
  }
198
308
  return absl::StrJoin(vhosts, "");
@@ -398,27 +508,186 @@ bool XdsApi::DownstreamTlsContext::Empty() const {
398
508
  return common_tls_context.Empty();
399
509
  }
400
510
 
511
+ //
512
+ // XdsApi::LdsUpdate::HttpConnectionManager
513
+ //
514
+
515
+ std::string XdsApi::LdsUpdate::HttpConnectionManager::ToString() const {
516
+ absl::InlinedVector<std::string, 4> contents;
517
+ contents.push_back(absl::StrFormat(
518
+ "route_config_name=%s",
519
+ !route_config_name.empty() ? route_config_name.c_str() : "<inlined>"));
520
+ contents.push_back(absl::StrFormat("http_max_stream_duration=%s",
521
+ http_max_stream_duration.ToString()));
522
+ if (rds_update.has_value()) {
523
+ contents.push_back(
524
+ absl::StrFormat("rds_update=%s", rds_update->ToString()));
525
+ }
526
+ if (!http_filters.empty()) {
527
+ std::vector<std::string> filter_strings;
528
+ for (const auto& http_filter : http_filters) {
529
+ filter_strings.push_back(http_filter.ToString());
530
+ }
531
+ contents.push_back(absl::StrCat("http_filters=[",
532
+ absl::StrJoin(filter_strings, ", "), "]"));
533
+ }
534
+ return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
535
+ }
536
+
537
+ //
538
+ // XdsApi::LdsUpdate::HttpFilter
539
+ //
540
+
541
+ std::string XdsApi::LdsUpdate::HttpConnectionManager::HttpFilter::ToString()
542
+ const {
543
+ return absl::StrCat("{name=", name, ", config=", config.ToString(), "}");
544
+ }
545
+
546
+ //
547
+ // XdsApi::LdsUpdate::FilterChainData
548
+ //
549
+
550
+ std::string XdsApi::LdsUpdate::FilterChainData::ToString() const {
551
+ return absl::StrCat(
552
+ "{downstream_tls_context=", downstream_tls_context.ToString(),
553
+ " http_connection_manager=", http_connection_manager.ToString(), "}");
554
+ }
555
+
556
+ //
557
+ // XdsApi::LdsUpdate::FilterChainMap::CidrRange
558
+ //
559
+
560
+ std::string XdsApi::LdsUpdate::FilterChainMap::CidrRange::ToString() const {
561
+ return absl::StrCat(
562
+ "{address_prefix=", grpc_sockaddr_to_string(&address, false),
563
+ ", prefix_len=", prefix_len, "}");
564
+ }
565
+
566
+ //
567
+ // FilterChain
568
+ //
569
+
570
+ struct FilterChain {
571
+ struct FilterChainMatch {
572
+ uint32_t destination_port = 0;
573
+ std::vector<XdsApi::LdsUpdate::FilterChainMap::CidrRange> prefix_ranges;
574
+ XdsApi::LdsUpdate::FilterChainMap::ConnectionSourceType source_type =
575
+ XdsApi::LdsUpdate::FilterChainMap::ConnectionSourceType::kAny;
576
+ std::vector<XdsApi::LdsUpdate::FilterChainMap::CidrRange>
577
+ source_prefix_ranges;
578
+ std::vector<uint32_t> source_ports;
579
+ std::vector<std::string> server_names;
580
+ std::string transport_protocol;
581
+ std::vector<std::string> application_protocols;
582
+
583
+ std::string ToString() const;
584
+ } filter_chain_match;
585
+
586
+ std::shared_ptr<XdsApi::LdsUpdate::FilterChainData> filter_chain_data;
587
+ };
588
+
589
+ std::string FilterChain::FilterChainMatch::ToString() const {
590
+ absl::InlinedVector<std::string, 8> contents;
591
+ if (destination_port != 0) {
592
+ contents.push_back(absl::StrCat("destination_port=", destination_port));
593
+ }
594
+ if (!prefix_ranges.empty()) {
595
+ std::vector<std::string> prefix_ranges_content;
596
+ for (const auto& range : prefix_ranges) {
597
+ prefix_ranges_content.push_back(range.ToString());
598
+ }
599
+ contents.push_back(absl::StrCat(
600
+ "prefix_ranges={", absl::StrJoin(prefix_ranges_content, ", "), "}"));
601
+ }
602
+ if (source_type == XdsApi::LdsUpdate::FilterChainMap::ConnectionSourceType::
603
+ kSameIpOrLoopback) {
604
+ contents.push_back("source_type=SAME_IP_OR_LOOPBACK");
605
+ } else if (source_type == XdsApi::LdsUpdate::FilterChainMap::
606
+ ConnectionSourceType::kExternal) {
607
+ contents.push_back("source_type=EXTERNAL");
608
+ }
609
+ if (!source_prefix_ranges.empty()) {
610
+ std::vector<std::string> source_prefix_ranges_content;
611
+ for (const auto& range : source_prefix_ranges) {
612
+ source_prefix_ranges_content.push_back(range.ToString());
613
+ }
614
+ contents.push_back(
615
+ absl::StrCat("source_prefix_ranges={",
616
+ absl::StrJoin(source_prefix_ranges_content, ", "), "}"));
617
+ }
618
+ if (!source_ports.empty()) {
619
+ contents.push_back(
620
+ absl::StrCat("source_ports={", absl::StrJoin(source_ports, ", "), "}"));
621
+ }
622
+ if (!server_names.empty()) {
623
+ contents.push_back(
624
+ absl::StrCat("server_names={", absl::StrJoin(server_names, ", "), "}"));
625
+ }
626
+ if (!transport_protocol.empty()) {
627
+ contents.push_back(absl::StrCat("transport_protocol=", transport_protocol));
628
+ }
629
+ if (!application_protocols.empty()) {
630
+ contents.push_back(absl::StrCat("application_protocols={",
631
+ absl::StrJoin(application_protocols, ", "),
632
+ "}"));
633
+ }
634
+ return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
635
+ }
636
+
637
+ //
638
+ // XdsApi::LdsUpdate::FilterChainMap
639
+ //
640
+
641
+ std::string XdsApi::LdsUpdate::FilterChainMap::ToString() const {
642
+ std::vector<std::string> contents;
643
+ for (const auto& destination_ip : destination_ip_vector) {
644
+ for (int source_type = 0; source_type < 3; ++source_type) {
645
+ for (const auto& source_ip :
646
+ destination_ip.source_types_array[source_type]) {
647
+ for (const auto& source_port_pair : source_ip.ports_map) {
648
+ FilterChain::FilterChainMatch filter_chain_match;
649
+ if (destination_ip.prefix_range.has_value()) {
650
+ filter_chain_match.prefix_ranges.push_back(
651
+ *destination_ip.prefix_range);
652
+ }
653
+ filter_chain_match.source_type = static_cast<
654
+ XdsApi::LdsUpdate::FilterChainMap::ConnectionSourceType>(
655
+ source_type);
656
+ if (source_ip.prefix_range.has_value()) {
657
+ filter_chain_match.source_prefix_ranges.push_back(
658
+ *source_ip.prefix_range);
659
+ }
660
+ if (source_port_pair.first != 0) {
661
+ filter_chain_match.source_ports.push_back(source_port_pair.first);
662
+ }
663
+ contents.push_back(absl::StrCat(
664
+ "{filter_chain_match=", filter_chain_match.ToString(),
665
+ ", filter_chain=", source_port_pair.second.data->ToString(),
666
+ "}"));
667
+ }
668
+ }
669
+ }
670
+ }
671
+ return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
672
+ }
673
+
401
674
  //
402
675
  // XdsApi::LdsUpdate
403
676
  //
404
677
 
405
678
  std::string XdsApi::LdsUpdate::ToString() const {
406
- absl::InlinedVector<std::string, 3> contents;
679
+ absl::InlinedVector<std::string, 4> contents;
407
680
  if (type == ListenerType::kTcpListener) {
408
- if (!downstream_tls_context.Empty()) {
409
- contents.push_back(absl::StrFormat("downstream_tls_context=%s",
410
- downstream_tls_context.ToString()));
681
+ contents.push_back(absl::StrCat("address=", address));
682
+ contents.push_back(
683
+ absl::StrCat("filter_chain_map=", filter_chain_map.ToString()));
684
+ if (default_filter_chain.has_value()) {
685
+ contents.push_back(absl::StrCat("default_filter_chain=",
686
+ default_filter_chain->ToString()));
411
687
  }
412
688
  } else if (type == ListenerType::kHttpApiListener) {
413
- contents.push_back(absl::StrFormat(
414
- "route_config_name=%s",
415
- !route_config_name.empty() ? route_config_name.c_str() : "<inlined>"));
416
- contents.push_back(absl::StrFormat("http_max_stream_duration=%s",
417
- http_max_stream_duration.ToString()));
418
- if (rds_update.has_value()) {
419
- contents.push_back(
420
- absl::StrFormat("rds_update=%s", rds_update->ToString()));
421
- }
689
+ contents.push_back(absl::StrFormat("http_connection_manager=%s",
690
+ http_connection_manager.ToString()));
422
691
  }
423
692
  return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
424
693
  }
@@ -538,8 +807,13 @@ const char* kCdsV2TypeUrl = "type.googleapis.com/envoy.api.v2.Cluster";
538
807
  const char* kEdsV2TypeUrl =
539
808
  "type.googleapis.com/envoy.api.v2.ClusterLoadAssignment";
540
809
 
541
- bool IsLds(absl::string_view type_url) {
542
- return type_url == XdsApi::kLdsTypeUrl || type_url == kLdsV2TypeUrl;
810
+ bool IsLds(absl::string_view type_url, bool* is_v2 = nullptr) {
811
+ if (type_url == XdsApi::kLdsTypeUrl) return true;
812
+ if (type_url == kLdsV2TypeUrl) {
813
+ if (is_v2 != nullptr) *is_v2 = true;
814
+ return true;
815
+ }
816
+ return false;
543
817
  }
544
818
 
545
819
  bool IsRds(absl::string_view type_url) {
@@ -563,39 +837,67 @@ XdsApi::XdsApi(XdsClient* client, TraceFlag* tracer,
563
837
  node_(node),
564
838
  build_version_(absl::StrCat("gRPC C-core ", GPR_PLATFORM_STRING, " ",
565
839
  grpc_version_string())),
566
- user_agent_name_(absl::StrCat("gRPC C-core ", GPR_PLATFORM_STRING)) {}
840
+ user_agent_name_(absl::StrCat("gRPC C-core ", GPR_PLATFORM_STRING)) {
841
+ // Populate upb symtab with xDS proto messages that we want to print
842
+ // properly in logs.
843
+ // Note: This won't actually work properly until upb adds support for
844
+ // Any fields in textproto printing (internal b/178821188).
845
+ envoy_config_listener_v3_Listener_getmsgdef(symtab_.ptr());
846
+ envoy_config_route_v3_RouteConfiguration_getmsgdef(symtab_.ptr());
847
+ envoy_config_cluster_v3_Cluster_getmsgdef(symtab_.ptr());
848
+ envoy_extensions_clusters_aggregate_v3_ClusterConfig_getmsgdef(symtab_.ptr());
849
+ envoy_config_cluster_v3_Cluster_getmsgdef(symtab_.ptr());
850
+ envoy_config_endpoint_v3_ClusterLoadAssignment_getmsgdef(symtab_.ptr());
851
+ envoy_extensions_transport_sockets_tls_v3_UpstreamTlsContext_getmsgdef(
852
+ symtab_.ptr());
853
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_getmsgdef(
854
+ symtab_.ptr());
855
+ // Load HTTP filter proto messages into the upb symtab.
856
+ XdsHttpFilterRegistry::PopulateSymtab(symtab_.ptr());
857
+ }
567
858
 
568
859
  namespace {
569
860
 
861
+ struct EncodingContext {
862
+ XdsClient* client;
863
+ TraceFlag* tracer;
864
+ upb_symtab* symtab;
865
+ upb_arena* arena;
866
+ bool use_v3;
867
+ };
868
+
570
869
  // Works for both std::string and absl::string_view.
571
870
  template <typename T>
572
871
  inline upb_strview StdStringToUpbString(const T& str) {
573
872
  return upb_strview_make(str.data(), str.size());
574
873
  }
575
874
 
576
- void PopulateMetadataValue(upb_arena* arena, google_protobuf_Value* value_pb,
577
- const Json& value);
875
+ void PopulateMetadataValue(const EncodingContext& context,
876
+ google_protobuf_Value* value_pb, const Json& value);
578
877
 
579
- void PopulateListValue(upb_arena* arena, google_protobuf_ListValue* list_value,
878
+ void PopulateListValue(const EncodingContext& context,
879
+ google_protobuf_ListValue* list_value,
580
880
  const Json::Array& values) {
581
881
  for (const auto& value : values) {
582
- auto* value_pb = google_protobuf_ListValue_add_values(list_value, arena);
583
- PopulateMetadataValue(arena, value_pb, value);
882
+ auto* value_pb =
883
+ google_protobuf_ListValue_add_values(list_value, context.arena);
884
+ PopulateMetadataValue(context, value_pb, value);
584
885
  }
585
886
  }
586
887
 
587
- void PopulateMetadata(upb_arena* arena, google_protobuf_Struct* metadata_pb,
888
+ void PopulateMetadata(const EncodingContext& context,
889
+ google_protobuf_Struct* metadata_pb,
588
890
  const Json::Object& metadata) {
589
891
  for (const auto& p : metadata) {
590
- google_protobuf_Value* value = google_protobuf_Value_new(arena);
591
- PopulateMetadataValue(arena, value, p.second);
892
+ google_protobuf_Value* value = google_protobuf_Value_new(context.arena);
893
+ PopulateMetadataValue(context, value, p.second);
592
894
  google_protobuf_Struct_fields_set(
593
- metadata_pb, StdStringToUpbString(p.first), value, arena);
895
+ metadata_pb, StdStringToUpbString(p.first), value, context.arena);
594
896
  }
595
897
  }
596
898
 
597
- void PopulateMetadataValue(upb_arena* arena, google_protobuf_Value* value_pb,
598
- const Json& value) {
899
+ void PopulateMetadataValue(const EncodingContext& context,
900
+ google_protobuf_Value* value_pb, const Json& value) {
599
901
  switch (value.type()) {
600
902
  case Json::Type::JSON_NULL:
601
903
  google_protobuf_Value_set_null_value(value_pb, 0);
@@ -616,14 +918,14 @@ void PopulateMetadataValue(upb_arena* arena, google_protobuf_Value* value_pb,
616
918
  break;
617
919
  case Json::Type::OBJECT: {
618
920
  google_protobuf_Struct* struct_value =
619
- google_protobuf_Value_mutable_struct_value(value_pb, arena);
620
- PopulateMetadata(arena, struct_value, value.object_value());
921
+ google_protobuf_Value_mutable_struct_value(value_pb, context.arena);
922
+ PopulateMetadata(context, struct_value, value.object_value());
621
923
  break;
622
924
  }
623
925
  case Json::Type::ARRAY: {
624
926
  google_protobuf_ListValue* list_value =
625
- google_protobuf_Value_mutable_list_value(value_pb, arena);
626
- PopulateListValue(arena, list_value, value.array_value());
927
+ google_protobuf_Value_mutable_list_value(value_pb, context.arena);
928
+ PopulateListValue(context, list_value, value.array_value());
627
929
  break;
628
930
  }
629
931
  }
@@ -650,7 +952,8 @@ std::string EncodeStringField(uint32_t field_number, const std::string& str) {
650
952
  EncodeVarint(str.size()) + str;
651
953
  }
652
954
 
653
- void PopulateBuildVersion(upb_arena* arena, envoy_config_core_v3_Node* node_msg,
955
+ void PopulateBuildVersion(const EncodingContext& context,
956
+ envoy_config_core_v3_Node* node_msg,
654
957
  const std::string& build_version) {
655
958
  std::string encoded_build_version = EncodeStringField(5, build_version);
656
959
  // TODO(roth): This should use upb_msg_addunknown(), but that API is
@@ -658,10 +961,11 @@ void PopulateBuildVersion(upb_arena* arena, envoy_config_core_v3_Node* node_msg,
658
961
  // API for now. Change this once we upgrade to a version of upb that
659
962
  // fixes this bug.
660
963
  _upb_msg_addunknown(node_msg, encoded_build_version.data(),
661
- encoded_build_version.size(), arena);
964
+ encoded_build_version.size(), context.arena);
662
965
  }
663
966
 
664
- void PopulateNode(upb_arena* arena, const XdsBootstrap::Node* node, bool use_v3,
967
+ void PopulateNode(const EncodingContext& context,
968
+ const XdsBootstrap::Node* node,
665
969
  const std::string& build_version,
666
970
  const std::string& user_agent_name,
667
971
  envoy_config_core_v3_Node* node_msg) {
@@ -676,13 +980,13 @@ void PopulateNode(upb_arena* arena, const XdsBootstrap::Node* node, bool use_v3,
676
980
  }
677
981
  if (!node->metadata.object_value().empty()) {
678
982
  google_protobuf_Struct* metadata =
679
- envoy_config_core_v3_Node_mutable_metadata(node_msg, arena);
680
- PopulateMetadata(arena, metadata, node->metadata.object_value());
983
+ envoy_config_core_v3_Node_mutable_metadata(node_msg, context.arena);
984
+ PopulateMetadata(context, metadata, node->metadata.object_value());
681
985
  }
682
986
  if (!node->locality_region.empty() || !node->locality_zone.empty() ||
683
- !node->locality_subzone.empty()) {
987
+ !node->locality_sub_zone.empty()) {
684
988
  envoy_config_core_v3_Locality* locality =
685
- envoy_config_core_v3_Node_mutable_locality(node_msg, arena);
989
+ envoy_config_core_v3_Node_mutable_locality(node_msg, context.arena);
686
990
  if (!node->locality_region.empty()) {
687
991
  envoy_config_core_v3_Locality_set_region(
688
992
  locality, StdStringToUpbString(node->locality_region));
@@ -691,14 +995,14 @@ void PopulateNode(upb_arena* arena, const XdsBootstrap::Node* node, bool use_v3,
691
995
  envoy_config_core_v3_Locality_set_zone(
692
996
  locality, StdStringToUpbString(node->locality_zone));
693
997
  }
694
- if (!node->locality_subzone.empty()) {
998
+ if (!node->locality_sub_zone.empty()) {
695
999
  envoy_config_core_v3_Locality_set_sub_zone(
696
- locality, StdStringToUpbString(node->locality_subzone));
1000
+ locality, StdStringToUpbString(node->locality_sub_zone));
697
1001
  }
698
1002
  }
699
1003
  }
700
- if (!use_v3) {
701
- PopulateBuildVersion(arena, node_msg, build_version);
1004
+ if (!context.use_v3) {
1005
+ PopulateBuildVersion(context, node_msg, build_version);
702
1006
  }
703
1007
  envoy_config_core_v3_Node_set_user_agent_name(
704
1008
  node_msg, StdStringToUpbString(user_agent_name));
@@ -706,7 +1010,7 @@ void PopulateNode(upb_arena* arena, const XdsBootstrap::Node* node, bool use_v3,
706
1010
  node_msg, upb_strview_makez(grpc_version_string()));
707
1011
  envoy_config_core_v3_Node_add_client_features(
708
1012
  node_msg, upb_strview_makez("envoy.lb.does_not_support_overprovisioning"),
709
- arena);
1013
+ context.arena);
710
1014
  }
711
1015
 
712
1016
  inline absl::string_view UpbStringToAbsl(const upb_strview& str) {
@@ -718,24 +1022,25 @@ inline std::string UpbStringToStdString(const upb_strview& str) {
718
1022
  }
719
1023
 
720
1024
  void MaybeLogDiscoveryRequest(
721
- XdsClient* client, TraceFlag* tracer, upb_symtab* symtab,
1025
+ const EncodingContext& context,
722
1026
  const envoy_service_discovery_v3_DiscoveryRequest* request) {
723
- if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
1027
+ if (GRPC_TRACE_FLAG_ENABLED(*context.tracer) &&
724
1028
  gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
725
1029
  const upb_msgdef* msg_type =
726
- envoy_service_discovery_v3_DiscoveryRequest_getmsgdef(symtab);
1030
+ envoy_service_discovery_v3_DiscoveryRequest_getmsgdef(context.symtab);
727
1031
  char buf[10240];
728
1032
  upb_text_encode(request, msg_type, nullptr, 0, buf, sizeof(buf));
729
- gpr_log(GPR_DEBUG, "[xds_client %p] constructed ADS request: %s", client,
730
- buf);
1033
+ gpr_log(GPR_DEBUG, "[xds_client %p] constructed ADS request: %s",
1034
+ context.client, buf);
731
1035
  }
732
1036
  }
733
1037
 
734
1038
  grpc_slice SerializeDiscoveryRequest(
735
- upb_arena* arena, envoy_service_discovery_v3_DiscoveryRequest* request) {
1039
+ const EncodingContext& context,
1040
+ envoy_service_discovery_v3_DiscoveryRequest* request) {
736
1041
  size_t output_length;
737
1042
  char* output = envoy_service_discovery_v3_DiscoveryRequest_serialize(
738
- request, arena, &output_length);
1043
+ request, context.arena, &output_length);
739
1044
  return grpc_slice_from_copied_buffer(output, output_length);
740
1045
  }
741
1046
 
@@ -766,6 +1071,8 @@ grpc_slice XdsApi::CreateAdsRequest(
766
1071
  const std::string& version, const std::string& nonce, grpc_error* error,
767
1072
  bool populate_node) {
768
1073
  upb::Arena arena;
1074
+ const EncodingContext context = {client_, tracer_, symtab_.ptr(), arena.ptr(),
1075
+ server.ShouldUseV3()};
769
1076
  // Create a request.
770
1077
  envoy_service_discovery_v3_DiscoveryRequest* request =
771
1078
  envoy_service_discovery_v3_DiscoveryRequest_new(arena.ptr());
@@ -805,69 +1112,88 @@ grpc_slice XdsApi::CreateAdsRequest(
805
1112
  envoy_config_core_v3_Node* node_msg =
806
1113
  envoy_service_discovery_v3_DiscoveryRequest_mutable_node(request,
807
1114
  arena.ptr());
808
- PopulateNode(arena.ptr(), node_, server.ShouldUseV3(), build_version_,
809
- user_agent_name_, node_msg);
1115
+ PopulateNode(context, node_, build_version_, user_agent_name_, node_msg);
810
1116
  }
811
1117
  // Add resource_names.
812
1118
  for (const auto& resource_name : resource_names) {
813
1119
  envoy_service_discovery_v3_DiscoveryRequest_add_resource_names(
814
1120
  request, StdStringToUpbString(resource_name), arena.ptr());
815
1121
  }
816
- MaybeLogDiscoveryRequest(client_, tracer_, symtab_.ptr(), request);
817
- return SerializeDiscoveryRequest(arena.ptr(), request);
1122
+ MaybeLogDiscoveryRequest(context, request);
1123
+ return SerializeDiscoveryRequest(context, request);
818
1124
  }
819
1125
 
820
1126
  namespace {
821
1127
 
822
1128
  void MaybeLogDiscoveryResponse(
823
- XdsClient* client, TraceFlag* tracer, upb_symtab* symtab,
1129
+ const EncodingContext& context,
824
1130
  const envoy_service_discovery_v3_DiscoveryResponse* response) {
825
- if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
1131
+ if (GRPC_TRACE_FLAG_ENABLED(*context.tracer) &&
826
1132
  gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
827
1133
  const upb_msgdef* msg_type =
828
- envoy_service_discovery_v3_DiscoveryResponse_getmsgdef(symtab);
1134
+ envoy_service_discovery_v3_DiscoveryResponse_getmsgdef(context.symtab);
829
1135
  char buf[10240];
830
1136
  upb_text_encode(response, msg_type, nullptr, 0, buf, sizeof(buf));
831
- gpr_log(GPR_DEBUG, "[xds_client %p] received response: %s", client, buf);
1137
+ gpr_log(GPR_DEBUG, "[xds_client %p] received response: %s", context.client,
1138
+ buf);
1139
+ }
1140
+ }
1141
+
1142
+ void MaybeLogHttpConnectionManager(
1143
+ const EncodingContext& context,
1144
+ const envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager*
1145
+ http_connection_manager_config) {
1146
+ if (GRPC_TRACE_FLAG_ENABLED(*context.tracer) &&
1147
+ gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
1148
+ const upb_msgdef* msg_type =
1149
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_getmsgdef(
1150
+ context.symtab);
1151
+ char buf[10240];
1152
+ upb_text_encode(http_connection_manager_config, msg_type, nullptr, 0, buf,
1153
+ sizeof(buf));
1154
+ gpr_log(GPR_DEBUG, "[xds_client %p] HttpConnectionManager: %s",
1155
+ context.client, buf);
832
1156
  }
833
1157
  }
834
1158
 
835
1159
  void MaybeLogRouteConfiguration(
836
- XdsClient* client, TraceFlag* tracer, upb_symtab* symtab,
1160
+ const EncodingContext& context,
837
1161
  const envoy_config_route_v3_RouteConfiguration* route_config) {
838
- if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
1162
+ if (GRPC_TRACE_FLAG_ENABLED(*context.tracer) &&
839
1163
  gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
840
1164
  const upb_msgdef* msg_type =
841
- envoy_config_route_v3_RouteConfiguration_getmsgdef(symtab);
1165
+ envoy_config_route_v3_RouteConfiguration_getmsgdef(context.symtab);
842
1166
  char buf[10240];
843
1167
  upb_text_encode(route_config, msg_type, nullptr, 0, buf, sizeof(buf));
844
- gpr_log(GPR_DEBUG, "[xds_client %p] RouteConfiguration: %s", client, buf);
1168
+ gpr_log(GPR_DEBUG, "[xds_client %p] RouteConfiguration: %s", context.client,
1169
+ buf);
845
1170
  }
846
1171
  }
847
1172
 
848
- void MaybeLogCluster(XdsClient* client, TraceFlag* tracer, upb_symtab* symtab,
1173
+ void MaybeLogCluster(const EncodingContext& context,
849
1174
  const envoy_config_cluster_v3_Cluster* cluster) {
850
- if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
1175
+ if (GRPC_TRACE_FLAG_ENABLED(*context.tracer) &&
851
1176
  gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
852
1177
  const upb_msgdef* msg_type =
853
- envoy_config_cluster_v3_Cluster_getmsgdef(symtab);
1178
+ envoy_config_cluster_v3_Cluster_getmsgdef(context.symtab);
854
1179
  char buf[10240];
855
1180
  upb_text_encode(cluster, msg_type, nullptr, 0, buf, sizeof(buf));
856
- gpr_log(GPR_DEBUG, "[xds_client %p] Cluster: %s", client, buf);
1181
+ gpr_log(GPR_DEBUG, "[xds_client %p] Cluster: %s", context.client, buf);
857
1182
  }
858
1183
  }
859
1184
 
860
1185
  void MaybeLogClusterLoadAssignment(
861
- XdsClient* client, TraceFlag* tracer, upb_symtab* symtab,
1186
+ const EncodingContext& context,
862
1187
  const envoy_config_endpoint_v3_ClusterLoadAssignment* cla) {
863
- if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
1188
+ if (GRPC_TRACE_FLAG_ENABLED(*context.tracer) &&
864
1189
  gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
865
1190
  const upb_msgdef* msg_type =
866
- envoy_config_endpoint_v3_ClusterLoadAssignment_getmsgdef(symtab);
1191
+ envoy_config_endpoint_v3_ClusterLoadAssignment_getmsgdef(
1192
+ context.symtab);
867
1193
  char buf[10240];
868
1194
  upb_text_encode(cla, msg_type, nullptr, 0, buf, sizeof(buf));
869
- gpr_log(GPR_DEBUG, "[xds_client %p] ClusterLoadAssignment: %s", client,
870
- buf);
1195
+ gpr_log(GPR_DEBUG, "[xds_client %p] ClusterLoadAssignment: %s",
1196
+ context.client, buf);
871
1197
  }
872
1198
  }
873
1199
 
@@ -1064,7 +1390,96 @@ grpc_error* RouteRuntimeFractionParse(
1064
1390
  return GRPC_ERROR_NONE;
1065
1391
  }
1066
1392
 
1067
- grpc_error* RouteActionParse(const envoy_config_route_v3_Route* route_msg,
1393
+ grpc_error* ExtractHttpFilterTypeName(const EncodingContext& context,
1394
+ const google_protobuf_Any* any,
1395
+ absl::string_view* filter_type) {
1396
+ *filter_type = UpbStringToAbsl(google_protobuf_Any_type_url(any));
1397
+ if (*filter_type == "type.googleapis.com/udpa.type.v1.TypedStruct") {
1398
+ upb_strview any_value = google_protobuf_Any_value(any);
1399
+ const auto* typed_struct = udpa_type_v1_TypedStruct_parse(
1400
+ any_value.data, any_value.size, context.arena);
1401
+ if (typed_struct == nullptr) {
1402
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1403
+ "could not parse TypedStruct from filter config");
1404
+ }
1405
+ *filter_type =
1406
+ UpbStringToAbsl(udpa_type_v1_TypedStruct_type_url(typed_struct));
1407
+ }
1408
+ *filter_type = absl::StripPrefix(*filter_type, "type.googleapis.com/");
1409
+ return GRPC_ERROR_NONE;
1410
+ }
1411
+
1412
+ template <typename ParentType, typename EntryType>
1413
+ grpc_error* ParseTypedPerFilterConfig(
1414
+ const EncodingContext& context, const ParentType* parent,
1415
+ const EntryType* (*entry_func)(const ParentType*, size_t*),
1416
+ upb_strview (*key_func)(const EntryType*),
1417
+ const google_protobuf_Any* (*value_func)(const EntryType*),
1418
+ XdsApi::TypedPerFilterConfig* typed_per_filter_config) {
1419
+ size_t filter_it = UPB_MAP_BEGIN;
1420
+ while (true) {
1421
+ const auto* filter_entry = entry_func(parent, &filter_it);
1422
+ if (filter_entry == nullptr) break;
1423
+ absl::string_view key = UpbStringToAbsl(key_func(filter_entry));
1424
+ if (key.empty()) {
1425
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("empty filter name in map");
1426
+ }
1427
+ const google_protobuf_Any* any = value_func(filter_entry);
1428
+ GPR_ASSERT(any != nullptr);
1429
+ absl::string_view filter_type =
1430
+ UpbStringToAbsl(google_protobuf_Any_type_url(any));
1431
+ if (filter_type.empty()) {
1432
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1433
+ absl::StrCat("no filter config specified for filter name ", key)
1434
+ .c_str());
1435
+ }
1436
+ bool is_optional = false;
1437
+ if (filter_type ==
1438
+ "type.googleapis.com/envoy.config.route.v3.FilterConfig") {
1439
+ upb_strview any_value = google_protobuf_Any_value(any);
1440
+ const auto* filter_config = envoy_config_route_v3_FilterConfig_parse(
1441
+ any_value.data, any_value.size, context.arena);
1442
+ if (filter_config == nullptr) {
1443
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1444
+ absl::StrCat("could not parse FilterConfig wrapper for ", key)
1445
+ .c_str());
1446
+ }
1447
+ is_optional =
1448
+ envoy_config_route_v3_FilterConfig_is_optional(filter_config);
1449
+ any = envoy_config_route_v3_FilterConfig_config(filter_config);
1450
+ if (any == nullptr) {
1451
+ if (is_optional) continue;
1452
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1453
+ absl::StrCat("no filter config specified for filter name ", key)
1454
+ .c_str());
1455
+ }
1456
+ }
1457
+ grpc_error* error = ExtractHttpFilterTypeName(context, any, &filter_type);
1458
+ if (error != GRPC_ERROR_NONE) return error;
1459
+ const XdsHttpFilterImpl* filter_impl =
1460
+ XdsHttpFilterRegistry::GetFilterForType(filter_type);
1461
+ if (filter_impl == nullptr) {
1462
+ if (is_optional) continue;
1463
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1464
+ absl::StrCat("no filter registered for config type ", filter_type)
1465
+ .c_str());
1466
+ }
1467
+ absl::StatusOr<XdsHttpFilterImpl::FilterConfig> filter_config =
1468
+ filter_impl->GenerateFilterConfigOverride(
1469
+ google_protobuf_Any_value(any), context.arena);
1470
+ if (!filter_config.ok()) {
1471
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1472
+ absl::StrCat("filter config for type ", filter_type,
1473
+ " failed to parse: ", filter_config.status().ToString())
1474
+ .c_str());
1475
+ }
1476
+ (*typed_per_filter_config)[std::string(key)] = std::move(*filter_config);
1477
+ }
1478
+ return GRPC_ERROR_NONE;
1479
+ }
1480
+
1481
+ grpc_error* RouteActionParse(const EncodingContext& context,
1482
+ const envoy_config_route_v3_Route* route_msg,
1068
1483
  XdsApi::Route* route, bool* ignore_route) {
1069
1484
  if (!envoy_config_route_v3_Route_has_route(route_msg)) {
1070
1485
  return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
@@ -1117,6 +1532,17 @@ grpc_error* RouteActionParse(const envoy_config_route_v3_Route* route_msg,
1117
1532
  cluster.weight = google_protobuf_UInt32Value_value(weight);
1118
1533
  if (cluster.weight == 0) continue;
1119
1534
  sum_of_weights += cluster.weight;
1535
+ if (context.use_v3) {
1536
+ grpc_error* error = ParseTypedPerFilterConfig<
1537
+ envoy_config_route_v3_WeightedCluster_ClusterWeight,
1538
+ envoy_config_route_v3_WeightedCluster_ClusterWeight_TypedPerFilterConfigEntry>(
1539
+ context, cluster_weight,
1540
+ envoy_config_route_v3_WeightedCluster_ClusterWeight_typed_per_filter_config_next,
1541
+ envoy_config_route_v3_WeightedCluster_ClusterWeight_TypedPerFilterConfigEntry_key,
1542
+ envoy_config_route_v3_WeightedCluster_ClusterWeight_TypedPerFilterConfigEntry_value,
1543
+ &cluster.typed_per_filter_config);
1544
+ if (error != GRPC_ERROR_NONE) return error;
1545
+ }
1120
1546
  route->weighted_clusters.emplace_back(std::move(cluster));
1121
1547
  }
1122
1548
  if (total_weight != sum_of_weights) {
@@ -1131,7 +1557,7 @@ grpc_error* RouteActionParse(const envoy_config_route_v3_Route* route_msg,
1131
1557
  // No cluster or weighted_clusters found in RouteAction, ignore this route.
1132
1558
  *ignore_route = true;
1133
1559
  }
1134
- if (XdsTimeoutEnabled() && !*ignore_route) {
1560
+ if (!*ignore_route) {
1135
1561
  const envoy_config_route_v3_RouteAction_MaxStreamDuration*
1136
1562
  max_stream_duration =
1137
1563
  envoy_config_route_v3_RouteAction_max_stream_duration(route_action);
@@ -1152,20 +1578,102 @@ grpc_error* RouteActionParse(const envoy_config_route_v3_Route* route_msg,
1152
1578
  }
1153
1579
  }
1154
1580
  }
1581
+ // Get HashPolicy from RouteAction
1582
+ if (XdsRingHashEnabled()) {
1583
+ size_t size = 0;
1584
+ const envoy_config_route_v3_RouteAction_HashPolicy* const* hash_policies =
1585
+ envoy_config_route_v3_RouteAction_hash_policy(route_action, &size);
1586
+ for (size_t i = 0; i < size; ++i) {
1587
+ const envoy_config_route_v3_RouteAction_HashPolicy* hash_policy =
1588
+ hash_policies[i];
1589
+ XdsApi::Route::HashPolicy policy;
1590
+ policy.terminal =
1591
+ envoy_config_route_v3_RouteAction_HashPolicy_terminal(hash_policy);
1592
+ const envoy_config_route_v3_RouteAction_HashPolicy_Header* header;
1593
+ const envoy_config_route_v3_RouteAction_HashPolicy_FilterState*
1594
+ filter_state;
1595
+ if ((header = envoy_config_route_v3_RouteAction_HashPolicy_header(
1596
+ hash_policy)) != nullptr) {
1597
+ policy.type = XdsApi::Route::HashPolicy::Type::HEADER;
1598
+ policy.header_name = UpbStringToStdString(
1599
+ envoy_config_route_v3_RouteAction_HashPolicy_Header_header_name(
1600
+ header));
1601
+ const struct envoy_type_matcher_v3_RegexMatchAndSubstitute*
1602
+ regex_rewrite =
1603
+ envoy_config_route_v3_RouteAction_HashPolicy_Header_regex_rewrite(
1604
+ header);
1605
+ if (regex_rewrite == nullptr) {
1606
+ gpr_log(
1607
+ GPR_DEBUG,
1608
+ "RouteAction HashPolicy contains policy specifier Header with "
1609
+ "RegexMatchAndSubstitution but Regex is missing");
1610
+ continue;
1611
+ }
1612
+ const envoy_type_matcher_v3_RegexMatcher* regex_matcher =
1613
+ envoy_type_matcher_v3_RegexMatchAndSubstitute_pattern(
1614
+ regex_rewrite);
1615
+ if (regex_matcher == nullptr) {
1616
+ gpr_log(
1617
+ GPR_DEBUG,
1618
+ "RouteAction HashPolicy contains policy specifier Header with "
1619
+ "RegexMatchAndSubstitution but RegexMatcher pattern is "
1620
+ "missing");
1621
+ continue;
1622
+ }
1623
+ RE2::Options options;
1624
+ policy.regex = absl::make_unique<RE2>(
1625
+ UpbStringToStdString(
1626
+ envoy_type_matcher_v3_RegexMatcher_regex(regex_matcher)),
1627
+ options);
1628
+ if (!policy.regex->ok()) {
1629
+ gpr_log(
1630
+ GPR_DEBUG,
1631
+ "RouteAction HashPolicy contains policy specifier Header with "
1632
+ "RegexMatchAndSubstitution but RegexMatcher pattern does not "
1633
+ "compile");
1634
+ continue;
1635
+ }
1636
+ policy.regex_substitution = UpbStringToStdString(
1637
+ envoy_type_matcher_v3_RegexMatchAndSubstitute_substitution(
1638
+ regex_rewrite));
1639
+ } else if ((filter_state =
1640
+ envoy_config_route_v3_RouteAction_HashPolicy_filter_state(
1641
+ hash_policy)) != nullptr) {
1642
+ std::string key = UpbStringToStdString(
1643
+ envoy_config_route_v3_RouteAction_HashPolicy_FilterState_key(
1644
+ filter_state));
1645
+ if (key == "io.grpc.channel_id") {
1646
+ policy.type = XdsApi::Route::HashPolicy::Type::CHANNEL_ID;
1647
+ } else {
1648
+ gpr_log(GPR_DEBUG,
1649
+ "RouteAction HashPolicy contains policy specifier "
1650
+ "FilterState but "
1651
+ "key is not io.grpc.channel_id.");
1652
+ continue;
1653
+ }
1654
+ } else {
1655
+ gpr_log(
1656
+ GPR_DEBUG,
1657
+ "RouteAction HashPolicy contains unsupported policy specifier.");
1658
+ continue;
1659
+ }
1660
+ route->hash_policies.emplace_back(std::move(policy));
1661
+ }
1662
+ }
1155
1663
  return GRPC_ERROR_NONE;
1156
1664
  }
1157
1665
 
1158
1666
  grpc_error* RouteConfigParse(
1159
- XdsClient* client, TraceFlag* tracer, upb_symtab* symtab,
1667
+ const EncodingContext& context,
1160
1668
  const envoy_config_route_v3_RouteConfiguration* route_config,
1161
1669
  XdsApi::RdsUpdate* rds_update) {
1162
- MaybeLogRouteConfiguration(client, tracer, symtab, route_config);
1670
+ MaybeLogRouteConfiguration(context, route_config);
1163
1671
  // Get the virtual hosts.
1164
- size_t size;
1672
+ size_t num_virtual_hosts;
1165
1673
  const envoy_config_route_v3_VirtualHost* const* virtual_hosts =
1166
- envoy_config_route_v3_RouteConfiguration_virtual_hosts(route_config,
1167
- &size);
1168
- for (size_t i = 0; i < size; ++i) {
1674
+ envoy_config_route_v3_RouteConfiguration_virtual_hosts(
1675
+ route_config, &num_virtual_hosts);
1676
+ for (size_t i = 0; i < num_virtual_hosts; ++i) {
1169
1677
  rds_update->virtual_hosts.emplace_back();
1170
1678
  XdsApi::RdsUpdate::VirtualHost& vhost = rds_update->virtual_hosts.back();
1171
1679
  // Parse domains.
@@ -1185,6 +1693,18 @@ grpc_error* RouteConfigParse(
1185
1693
  if (vhost.domains.empty()) {
1186
1694
  return GRPC_ERROR_CREATE_FROM_STATIC_STRING("VirtualHost has no domains");
1187
1695
  }
1696
+ // Parse typed_per_filter_config.
1697
+ if (context.use_v3) {
1698
+ grpc_error* error = ParseTypedPerFilterConfig<
1699
+ envoy_config_route_v3_VirtualHost,
1700
+ envoy_config_route_v3_VirtualHost_TypedPerFilterConfigEntry>(
1701
+ context, virtual_hosts[i],
1702
+ envoy_config_route_v3_VirtualHost_typed_per_filter_config_next,
1703
+ envoy_config_route_v3_VirtualHost_TypedPerFilterConfigEntry_key,
1704
+ envoy_config_route_v3_VirtualHost_TypedPerFilterConfigEntry_value,
1705
+ &vhost.typed_per_filter_config);
1706
+ if (error != GRPC_ERROR_NONE) return error;
1707
+ }
1188
1708
  // Parse routes.
1189
1709
  size_t num_routes;
1190
1710
  const envoy_config_route_v3_Route* const* routes =
@@ -1197,6 +1717,9 @@ grpc_error* RouteConfigParse(
1197
1717
  for (size_t j = 0; j < num_routes; ++j) {
1198
1718
  const envoy_config_route_v3_RouteMatch* match =
1199
1719
  envoy_config_route_v3_Route_match(routes[j]);
1720
+ if (match == nullptr) {
1721
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Match can't be null.");
1722
+ }
1200
1723
  size_t query_parameters_size;
1201
1724
  static_cast<void>(envoy_config_route_v3_RouteMatch_query_parameters(
1202
1725
  match, &query_parameters_size));
@@ -1212,9 +1735,20 @@ grpc_error* RouteConfigParse(
1212
1735
  if (error != GRPC_ERROR_NONE) return error;
1213
1736
  error = RouteRuntimeFractionParse(match, &route);
1214
1737
  if (error != GRPC_ERROR_NONE) return error;
1215
- error = RouteActionParse(routes[j], &route, &ignore_route);
1738
+ error = RouteActionParse(context, routes[j], &route, &ignore_route);
1216
1739
  if (error != GRPC_ERROR_NONE) return error;
1217
1740
  if (ignore_route) continue;
1741
+ if (context.use_v3) {
1742
+ grpc_error* error = ParseTypedPerFilterConfig<
1743
+ envoy_config_route_v3_Route,
1744
+ envoy_config_route_v3_Route_TypedPerFilterConfigEntry>(
1745
+ context, routes[j],
1746
+ envoy_config_route_v3_Route_typed_per_filter_config_next,
1747
+ envoy_config_route_v3_Route_TypedPerFilterConfigEntry_key,
1748
+ envoy_config_route_v3_Route_TypedPerFilterConfigEntry_value,
1749
+ &route.typed_per_filter_config);
1750
+ if (error != GRPC_ERROR_NONE) return error;
1751
+ }
1218
1752
  vhost.routes.emplace_back(std::move(route));
1219
1753
  }
1220
1754
  if (vhost.routes.empty()) {
@@ -1336,150 +1870,631 @@ grpc_error* CommonTlsContextParse(
1336
1870
  return GRPC_ERROR_NONE;
1337
1871
  }
1338
1872
 
1873
+ grpc_error* HttpConnectionManagerParse(
1874
+ bool is_client, const EncodingContext& context,
1875
+ const envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager*
1876
+ http_connection_manager_proto,
1877
+ bool is_v2,
1878
+ XdsApi::LdsUpdate::HttpConnectionManager* http_connection_manager) {
1879
+ MaybeLogHttpConnectionManager(context, http_connection_manager_proto);
1880
+ // Obtain max_stream_duration from Http Protocol Options.
1881
+ const envoy_config_core_v3_HttpProtocolOptions* options =
1882
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_common_http_protocol_options(
1883
+ http_connection_manager_proto);
1884
+ if (options != nullptr) {
1885
+ const google_protobuf_Duration* duration =
1886
+ envoy_config_core_v3_HttpProtocolOptions_max_stream_duration(options);
1887
+ if (duration != nullptr) {
1888
+ http_connection_manager->http_max_stream_duration.seconds =
1889
+ google_protobuf_Duration_seconds(duration);
1890
+ http_connection_manager->http_max_stream_duration.nanos =
1891
+ google_protobuf_Duration_nanos(duration);
1892
+ }
1893
+ }
1894
+ // Parse filters.
1895
+ if (!is_v2) {
1896
+ size_t num_filters = 0;
1897
+ const auto* http_filters =
1898
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_http_filters(
1899
+ http_connection_manager_proto, &num_filters);
1900
+ std::set<absl::string_view> names_seen;
1901
+ for (size_t i = 0; i < num_filters; ++i) {
1902
+ const auto* http_filter = http_filters[i];
1903
+ absl::string_view name = UpbStringToAbsl(
1904
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpFilter_name(
1905
+ http_filter));
1906
+ if (name.empty()) {
1907
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1908
+ absl::StrCat("empty filter name at index ", i).c_str());
1909
+ }
1910
+ if (names_seen.find(name) != names_seen.end()) {
1911
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1912
+ absl::StrCat("duplicate HTTP filter name: ", name).c_str());
1913
+ }
1914
+ names_seen.insert(name);
1915
+ const bool is_optional =
1916
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpFilter_is_optional(
1917
+ http_filter);
1918
+ const google_protobuf_Any* any =
1919
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpFilter_typed_config(
1920
+ http_filter);
1921
+ if (any == nullptr) {
1922
+ if (is_optional) continue;
1923
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1924
+ absl::StrCat("no filter config specified for filter name ", name)
1925
+ .c_str());
1926
+ }
1927
+ absl::string_view filter_type;
1928
+ grpc_error* error = ExtractHttpFilterTypeName(context, any, &filter_type);
1929
+ if (error != GRPC_ERROR_NONE) return error;
1930
+ const XdsHttpFilterImpl* filter_impl =
1931
+ XdsHttpFilterRegistry::GetFilterForType(filter_type);
1932
+ if (filter_impl == nullptr) {
1933
+ if (is_optional) continue;
1934
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1935
+ absl::StrCat("no filter registered for config type ", filter_type)
1936
+ .c_str());
1937
+ }
1938
+ if ((is_client && !filter_impl->IsSupportedOnClients()) ||
1939
+ (!is_client && !filter_impl->IsSupportedOnServers())) {
1940
+ if (is_optional) continue;
1941
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1942
+ absl::StrFormat("Filter %s is not supported on %s", filter_type,
1943
+ is_client ? "clients" : "servers")
1944
+ .c_str());
1945
+ }
1946
+ absl::StatusOr<XdsHttpFilterImpl::FilterConfig> filter_config =
1947
+ filter_impl->GenerateFilterConfig(google_protobuf_Any_value(any),
1948
+ context.arena);
1949
+ if (!filter_config.ok()) {
1950
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1951
+ absl::StrCat(
1952
+ "filter config for type ", filter_type,
1953
+ " failed to parse: ", filter_config.status().ToString())
1954
+ .c_str());
1955
+ }
1956
+ http_connection_manager->http_filters.emplace_back(
1957
+ XdsApi::LdsUpdate::HttpConnectionManager::HttpFilter{
1958
+ std::string(name), std::move(*filter_config)});
1959
+ }
1960
+ } else {
1961
+ // If using a v2 config, we just hard-code a list containing only the
1962
+ // router filter without actually looking at the config. This ensures
1963
+ // that the right thing happens in the xds resolver without having
1964
+ // to expose whether the resource we received was v2 or v3.
1965
+ http_connection_manager->http_filters.emplace_back(
1966
+ XdsApi::LdsUpdate::HttpConnectionManager::HttpFilter{
1967
+ "router", {kXdsHttpRouterFilterConfigName, Json()}});
1968
+ }
1969
+ if (is_client) {
1970
+ // Found inlined route_config. Parse it to find the cluster_name.
1971
+ if (envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_has_route_config(
1972
+ http_connection_manager_proto)) {
1973
+ const envoy_config_route_v3_RouteConfiguration* route_config =
1974
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_route_config(
1975
+ http_connection_manager_proto);
1976
+ XdsApi::RdsUpdate rds_update;
1977
+ grpc_error* error = RouteConfigParse(context, route_config, &rds_update);
1978
+ if (error != GRPC_ERROR_NONE) return error;
1979
+ http_connection_manager->rds_update = std::move(rds_update);
1980
+ return GRPC_ERROR_NONE;
1981
+ }
1982
+ // Validate that RDS must be used to get the route_config dynamically.
1983
+ const envoy_extensions_filters_network_http_connection_manager_v3_Rds* rds =
1984
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_rds(
1985
+ http_connection_manager_proto);
1986
+ if (rds == nullptr) {
1987
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1988
+ "HttpConnectionManager neither has inlined route_config nor RDS.");
1989
+ }
1990
+ // Check that the ConfigSource specifies ADS.
1991
+ const envoy_config_core_v3_ConfigSource* config_source =
1992
+ envoy_extensions_filters_network_http_connection_manager_v3_Rds_config_source(
1993
+ rds);
1994
+ if (config_source == nullptr) {
1995
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1996
+ "HttpConnectionManager missing config_source for RDS.");
1997
+ }
1998
+ if (!envoy_config_core_v3_ConfigSource_has_ads(config_source)) {
1999
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2000
+ "HttpConnectionManager ConfigSource for RDS does not specify ADS.");
2001
+ }
2002
+ // Get the route_config_name.
2003
+ http_connection_manager->route_config_name = UpbStringToStdString(
2004
+ envoy_extensions_filters_network_http_connection_manager_v3_Rds_route_config_name(
2005
+ rds));
2006
+ }
2007
+ return GRPC_ERROR_NONE;
2008
+ }
2009
+
1339
2010
  grpc_error* LdsResponseParseClient(
1340
- XdsClient* client, TraceFlag* tracer, upb_symtab* symtab, upb_arena* arena,
1341
- const envoy_config_listener_v3_ApiListener* api_listener,
2011
+ const EncodingContext& context,
2012
+ const envoy_config_listener_v3_ApiListener* api_listener, bool is_v2,
1342
2013
  XdsApi::LdsUpdate* lds_update) {
1343
2014
  lds_update->type = XdsApi::LdsUpdate::ListenerType::kHttpApiListener;
1344
2015
  const upb_strview encoded_api_listener = google_protobuf_Any_value(
1345
2016
  envoy_config_listener_v3_ApiListener_api_listener(api_listener));
1346
- const envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager*
1347
- http_connection_manager =
1348
- envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_parse(
1349
- encoded_api_listener.data, encoded_api_listener.size, arena);
2017
+ const auto* http_connection_manager =
2018
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_parse(
2019
+ encoded_api_listener.data, encoded_api_listener.size, context.arena);
1350
2020
  if (http_connection_manager == nullptr) {
1351
2021
  return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1352
2022
  "Could not parse HttpConnectionManager config from ApiListener");
1353
2023
  }
1354
- if (XdsTimeoutEnabled()) {
1355
- // Obtain max_stream_duration from Http Protocol Options.
1356
- const envoy_config_core_v3_HttpProtocolOptions* options =
1357
- envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_common_http_protocol_options(
1358
- http_connection_manager);
1359
- if (options != nullptr) {
1360
- const google_protobuf_Duration* duration =
1361
- envoy_config_core_v3_HttpProtocolOptions_max_stream_duration(options);
1362
- if (duration != nullptr) {
1363
- lds_update->http_max_stream_duration.seconds =
1364
- google_protobuf_Duration_seconds(duration);
1365
- lds_update->http_max_stream_duration.nanos =
1366
- google_protobuf_Duration_nanos(duration);
2024
+ return HttpConnectionManagerParse(true /* is_client */, context,
2025
+ http_connection_manager, is_v2,
2026
+ &lds_update->http_connection_manager);
2027
+ }
2028
+
2029
+ grpc_error* DownstreamTlsContextParse(
2030
+ const EncodingContext& context,
2031
+ const envoy_config_core_v3_TransportSocket* transport_socket,
2032
+ XdsApi::DownstreamTlsContext* downstream_tls_context) {
2033
+ absl::string_view name = UpbStringToAbsl(
2034
+ envoy_config_core_v3_TransportSocket_name(transport_socket));
2035
+ if (name == "envoy.transport_sockets.tls") {
2036
+ auto* typed_config =
2037
+ envoy_config_core_v3_TransportSocket_typed_config(transport_socket);
2038
+ if (typed_config != nullptr) {
2039
+ const upb_strview encoded_downstream_tls_context =
2040
+ google_protobuf_Any_value(typed_config);
2041
+ auto* downstream_tls_context_proto =
2042
+ envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_parse(
2043
+ encoded_downstream_tls_context.data,
2044
+ encoded_downstream_tls_context.size, context.arena);
2045
+ if (downstream_tls_context_proto == nullptr) {
2046
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2047
+ "Can't decode downstream tls context.");
2048
+ }
2049
+ auto* common_tls_context =
2050
+ envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_common_tls_context(
2051
+ downstream_tls_context_proto);
2052
+ if (common_tls_context != nullptr) {
2053
+ grpc_error* error = CommonTlsContextParse(
2054
+ common_tls_context, &downstream_tls_context->common_tls_context);
2055
+ if (error != GRPC_ERROR_NONE) return error;
2056
+ }
2057
+ auto* require_client_certificate =
2058
+ envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_require_client_certificate(
2059
+ downstream_tls_context_proto);
2060
+ if (require_client_certificate != nullptr) {
2061
+ downstream_tls_context->require_client_certificate =
2062
+ google_protobuf_BoolValue_value(require_client_certificate);
1367
2063
  }
1368
2064
  }
2065
+ if (downstream_tls_context->common_tls_context
2066
+ .tls_certificate_certificate_provider_instance.instance_name
2067
+ .empty()) {
2068
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2069
+ "TLS configuration provided but no "
2070
+ "tls_certificate_certificate_provider_instance found.");
2071
+ }
1369
2072
  }
1370
- // Found inlined route_config. Parse it to find the cluster_name.
1371
- if (envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_has_route_config(
1372
- http_connection_manager)) {
1373
- const envoy_config_route_v3_RouteConfiguration* route_config =
1374
- envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_route_config(
1375
- http_connection_manager);
1376
- XdsApi::RdsUpdate rds_update;
1377
- grpc_error* error =
1378
- RouteConfigParse(client, tracer, symtab, route_config, &rds_update);
2073
+ return GRPC_ERROR_NONE;
2074
+ }
2075
+
2076
+ grpc_error* CidrRangeParse(
2077
+ const envoy_config_core_v3_CidrRange* cidr_range_proto,
2078
+ XdsApi::LdsUpdate::FilterChainMap::CidrRange* cidr_range) {
2079
+ std::string address_prefix = UpbStringToStdString(
2080
+ envoy_config_core_v3_CidrRange_address_prefix(cidr_range_proto));
2081
+ grpc_error* error = grpc_string_to_sockaddr_new(&cidr_range->address,
2082
+ address_prefix.c_str(), 0);
2083
+ if (error != GRPC_ERROR_NONE) return error;
2084
+ cidr_range->prefix_len = 0;
2085
+ auto* prefix_len_proto =
2086
+ envoy_config_core_v3_CidrRange_prefix_len(cidr_range_proto);
2087
+ if (prefix_len_proto != nullptr) {
2088
+ cidr_range->prefix_len = std::min(
2089
+ google_protobuf_UInt32Value_value(prefix_len_proto),
2090
+ (reinterpret_cast<const grpc_sockaddr*>(cidr_range->address.addr))
2091
+ ->sa_family == GRPC_AF_INET
2092
+ ? uint32_t(32)
2093
+ : uint32_t(128));
2094
+ }
2095
+ // Normalize the network address by masking it with prefix_len
2096
+ grpc_sockaddr_mask_bits(&cidr_range->address, cidr_range->prefix_len);
2097
+ return GRPC_ERROR_NONE;
2098
+ }
2099
+
2100
+ grpc_error* FilterChainMatchParse(
2101
+ const envoy_config_listener_v3_FilterChainMatch* filter_chain_match_proto,
2102
+ FilterChain::FilterChainMatch* filter_chain_match) {
2103
+ auto* destination_port =
2104
+ envoy_config_listener_v3_FilterChainMatch_destination_port(
2105
+ filter_chain_match_proto);
2106
+ if (destination_port != nullptr) {
2107
+ filter_chain_match->destination_port =
2108
+ google_protobuf_UInt32Value_value(destination_port);
2109
+ }
2110
+ size_t size = 0;
2111
+ auto* prefix_ranges = envoy_config_listener_v3_FilterChainMatch_prefix_ranges(
2112
+ filter_chain_match_proto, &size);
2113
+ filter_chain_match->prefix_ranges.reserve(size);
2114
+ for (size_t i = 0; i < size; i++) {
2115
+ XdsApi::LdsUpdate::FilterChainMap::CidrRange cidr_range;
2116
+ grpc_error* error = CidrRangeParse(prefix_ranges[i], &cidr_range);
1379
2117
  if (error != GRPC_ERROR_NONE) return error;
1380
- lds_update->rds_update = std::move(rds_update);
1381
- return GRPC_ERROR_NONE;
2118
+ filter_chain_match->prefix_ranges.push_back(cidr_range);
2119
+ }
2120
+ filter_chain_match->source_type =
2121
+ static_cast<XdsApi::LdsUpdate::FilterChainMap::ConnectionSourceType>(
2122
+ envoy_config_listener_v3_FilterChainMatch_source_type(
2123
+ filter_chain_match_proto));
2124
+ auto* source_prefix_ranges =
2125
+ envoy_config_listener_v3_FilterChainMatch_source_prefix_ranges(
2126
+ filter_chain_match_proto, &size);
2127
+ filter_chain_match->source_prefix_ranges.reserve(size);
2128
+ for (size_t i = 0; i < size; i++) {
2129
+ XdsApi::LdsUpdate::FilterChainMap::CidrRange cidr_range;
2130
+ grpc_error* error = CidrRangeParse(source_prefix_ranges[i], &cidr_range);
2131
+ if (error != GRPC_ERROR_NONE) return error;
2132
+ filter_chain_match->source_prefix_ranges.push_back(cidr_range);
2133
+ }
2134
+ auto* source_ports = envoy_config_listener_v3_FilterChainMatch_source_ports(
2135
+ filter_chain_match_proto, &size);
2136
+ filter_chain_match->source_ports.reserve(size);
2137
+ for (size_t i = 0; i < size; i++) {
2138
+ filter_chain_match->source_ports.push_back(source_ports[i]);
2139
+ }
2140
+ auto* server_names = envoy_config_listener_v3_FilterChainMatch_server_names(
2141
+ filter_chain_match_proto, &size);
2142
+ for (size_t i = 0; i < size; i++) {
2143
+ filter_chain_match->server_names.push_back(
2144
+ UpbStringToStdString(server_names[i]));
2145
+ }
2146
+ filter_chain_match->transport_protocol = UpbStringToStdString(
2147
+ envoy_config_listener_v3_FilterChainMatch_transport_protocol(
2148
+ filter_chain_match_proto));
2149
+ auto* application_protocols =
2150
+ envoy_config_listener_v3_FilterChainMatch_application_protocols(
2151
+ filter_chain_match_proto, &size);
2152
+ for (size_t i = 0; i < size; i++) {
2153
+ filter_chain_match->application_protocols.push_back(
2154
+ UpbStringToStdString(application_protocols[i]));
1382
2155
  }
1383
- // Validate that RDS must be used to get the route_config dynamically.
1384
- if (!envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_has_rds(
1385
- http_connection_manager)) {
2156
+ return GRPC_ERROR_NONE;
2157
+ }
2158
+
2159
+ grpc_error* FilterChainParse(
2160
+ const EncodingContext& context,
2161
+ const envoy_config_listener_v3_FilterChain* filter_chain_proto, bool is_v2,
2162
+ FilterChain* filter_chain) {
2163
+ grpc_error* error = GRPC_ERROR_NONE;
2164
+ auto* filter_chain_match =
2165
+ envoy_config_listener_v3_FilterChain_filter_chain_match(
2166
+ filter_chain_proto);
2167
+ if (filter_chain_match != nullptr) {
2168
+ error = FilterChainMatchParse(filter_chain_match,
2169
+ &filter_chain->filter_chain_match);
2170
+ if (error != GRPC_ERROR_NONE) return error;
2171
+ }
2172
+ // Parse the filters list. Currently we only support HttpConnectionManager.
2173
+ size_t size = 0;
2174
+ auto* filters =
2175
+ envoy_config_listener_v3_FilterChain_filters(filter_chain_proto, &size);
2176
+ if (size != 1) {
2177
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2178
+ "FilterChain should have exactly one filter: HttpConnectionManager; no "
2179
+ "other filter is supported at the moment");
2180
+ }
2181
+ auto* typed_config = envoy_config_listener_v3_Filter_typed_config(filters[0]);
2182
+ if (typed_config == nullptr) {
1386
2183
  return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1387
- "HttpConnectionManager neither has inlined route_config nor RDS.");
1388
- }
1389
- const envoy_extensions_filters_network_http_connection_manager_v3_Rds* rds =
1390
- envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_rds(
1391
- http_connection_manager);
1392
- // Check that the ConfigSource specifies ADS.
1393
- const envoy_config_core_v3_ConfigSource* config_source =
1394
- envoy_extensions_filters_network_http_connection_manager_v3_Rds_config_source(
1395
- rds);
1396
- if (config_source == nullptr) {
2184
+ "No typed_config found in filter.");
2185
+ }
2186
+ absl::string_view type_url =
2187
+ UpbStringToAbsl(google_protobuf_Any_type_url(typed_config));
2188
+ if (type_url !=
2189
+ "type.googleapis.com/"
2190
+ "envoy.extensions.filters.network.http_connection_manager.v3."
2191
+ "HttpConnectionManager") {
2192
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
2193
+ absl::StrCat("Unsupported filter type ", type_url).c_str());
2194
+ }
2195
+ const upb_strview encoded_http_connection_manager =
2196
+ google_protobuf_Any_value(typed_config);
2197
+ const auto* http_connection_manager =
2198
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_parse(
2199
+ encoded_http_connection_manager.data,
2200
+ encoded_http_connection_manager.size, context.arena);
2201
+ if (http_connection_manager == nullptr) {
1397
2202
  return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1398
- "HttpConnectionManager missing config_source for RDS.");
2203
+ "Could not parse HttpConnectionManager config from filter "
2204
+ "typed_config");
2205
+ }
2206
+ filter_chain->filter_chain_data =
2207
+ std::make_shared<XdsApi::LdsUpdate::FilterChainData>();
2208
+ error = HttpConnectionManagerParse(
2209
+ false /* is_client */, context, http_connection_manager, is_v2,
2210
+ &filter_chain->filter_chain_data->http_connection_manager);
2211
+ if (error != GRPC_ERROR_NONE) return error;
2212
+ // Get the DownstreamTlsContext for the filter chain
2213
+ if (XdsSecurityEnabled()) {
2214
+ auto* transport_socket =
2215
+ envoy_config_listener_v3_FilterChain_transport_socket(
2216
+ filter_chain_proto);
2217
+ if (transport_socket != nullptr) {
2218
+ error = DownstreamTlsContextParse(
2219
+ context, transport_socket,
2220
+ &filter_chain->filter_chain_data->downstream_tls_context);
2221
+ }
2222
+ }
2223
+ return error;
2224
+ }
2225
+
2226
+ grpc_error* AddressParse(const envoy_config_core_v3_Address* address_proto,
2227
+ std::string* address) {
2228
+ const auto* socket_address =
2229
+ envoy_config_core_v3_Address_socket_address(address_proto);
2230
+ if (socket_address == nullptr) {
2231
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
2232
+ "Address does not have socket_address");
1399
2233
  }
1400
- if (!envoy_config_core_v3_ConfigSource_has_ads(config_source)) {
2234
+ if (envoy_config_core_v3_SocketAddress_protocol(socket_address) !=
2235
+ envoy_config_core_v3_SocketAddress_TCP) {
1401
2236
  return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1402
- "HttpConnectionManager ConfigSource for RDS does not specify ADS.");
2237
+ "SocketAddress protocol is not TCP");
2238
+ }
2239
+ uint32_t port = envoy_config_core_v3_SocketAddress_port_value(socket_address);
2240
+ if (port > 65535) {
2241
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Invalid port");
1403
2242
  }
1404
- // Get the route_config_name.
1405
- lds_update->route_config_name = UpbStringToStdString(
1406
- envoy_extensions_filters_network_http_connection_manager_v3_Rds_route_config_name(
1407
- rds));
2243
+ *address = JoinHostPort(
2244
+ UpbStringToAbsl(
2245
+ envoy_config_core_v3_SocketAddress_address(socket_address)),
2246
+ port);
2247
+ return GRPC_ERROR_NONE;
2248
+ }
2249
+
2250
+ // An intermediate map for filter chains that we create to validate the list of
2251
+ // filter chains received from the control plane and to finally create
2252
+ // XdsApi::LdsUpdate::FilterChainMap
2253
+ struct InternalFilterChainMap {
2254
+ using SourceIpMap =
2255
+ std::map<std::string, XdsApi::LdsUpdate::FilterChainMap::SourceIp>;
2256
+ using ConnectionSourceTypesArray = std::array<SourceIpMap, 3>;
2257
+ struct DestinationIp {
2258
+ absl::optional<XdsApi::LdsUpdate::FilterChainMap::CidrRange> prefix_range;
2259
+ bool transport_protocol_raw_buffer_provided = false;
2260
+ ConnectionSourceTypesArray source_types_array;
2261
+ };
2262
+ using DestinationIpMap = std::map<std::string, DestinationIp>;
2263
+ DestinationIpMap destination_ip_map;
2264
+ };
2265
+
2266
+ grpc_error* AddFilterChainDataForSourcePort(
2267
+ const FilterChain& filter_chain,
2268
+ XdsApi::LdsUpdate::FilterChainMap::SourcePortsMap* ports_map,
2269
+ uint32_t port) {
2270
+ auto insert_result = ports_map->emplace(
2271
+ port, XdsApi::LdsUpdate::FilterChainMap::FilterChainDataSharedPtr{
2272
+ filter_chain.filter_chain_data});
2273
+ if (!insert_result.second) {
2274
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
2275
+ absl::StrCat(
2276
+ "Duplicate matching rules detected when adding filter chain: ",
2277
+ filter_chain.filter_chain_match.ToString())
2278
+ .c_str());
2279
+ }
2280
+ return GRPC_ERROR_NONE;
2281
+ }
2282
+
2283
+ grpc_error* AddFilterChainDataForSourcePorts(
2284
+ const FilterChain& filter_chain,
2285
+ XdsApi::LdsUpdate::FilterChainMap::SourcePortsMap* ports_map) {
2286
+ if (filter_chain.filter_chain_match.source_ports.empty()) {
2287
+ return AddFilterChainDataForSourcePort(filter_chain, ports_map, 0);
2288
+ } else {
2289
+ for (uint32_t port : filter_chain.filter_chain_match.source_ports) {
2290
+ grpc_error* error =
2291
+ AddFilterChainDataForSourcePort(filter_chain, ports_map, port);
2292
+ if (error != GRPC_ERROR_NONE) return error;
2293
+ }
2294
+ }
2295
+ return GRPC_ERROR_NONE;
2296
+ }
2297
+
2298
+ grpc_error* AddFilterChainDataForSourceIpRange(
2299
+ const FilterChain& filter_chain,
2300
+ InternalFilterChainMap::SourceIpMap* source_ip_map) {
2301
+ if (filter_chain.filter_chain_match.source_prefix_ranges.empty()) {
2302
+ auto insert_result = source_ip_map->emplace(
2303
+ "", XdsApi::LdsUpdate::FilterChainMap::SourceIp());
2304
+ return AddFilterChainDataForSourcePorts(
2305
+ filter_chain, &insert_result.first->second.ports_map);
2306
+ } else {
2307
+ for (const auto& prefix_range :
2308
+ filter_chain.filter_chain_match.source_prefix_ranges) {
2309
+ auto insert_result = source_ip_map->emplace(
2310
+ absl::StrCat(grpc_sockaddr_to_string(&prefix_range.address, false),
2311
+ "/", prefix_range.prefix_len),
2312
+ XdsApi::LdsUpdate::FilterChainMap::SourceIp());
2313
+ if (insert_result.second) {
2314
+ insert_result.first->second.prefix_range.emplace(prefix_range);
2315
+ }
2316
+ grpc_error* error = AddFilterChainDataForSourcePorts(
2317
+ filter_chain, &insert_result.first->second.ports_map);
2318
+ if (error != GRPC_ERROR_NONE) return error;
2319
+ }
2320
+ }
2321
+ return GRPC_ERROR_NONE;
2322
+ }
2323
+
2324
+ grpc_error* AddFilterChainDataForSourceType(
2325
+ const FilterChain& filter_chain,
2326
+ InternalFilterChainMap::DestinationIp* destination_ip) {
2327
+ GPR_ASSERT(static_cast<unsigned int>(
2328
+ filter_chain.filter_chain_match.source_type) < 3);
2329
+ return AddFilterChainDataForSourceIpRange(
2330
+ filter_chain, &destination_ip->source_types_array[static_cast<int>(
2331
+ filter_chain.filter_chain_match.source_type)]);
2332
+ }
2333
+
2334
+ grpc_error* AddFilterChainDataForApplicationProtocols(
2335
+ const FilterChain& filter_chain,
2336
+ InternalFilterChainMap::DestinationIp* destination_ip) {
2337
+ // Only allow filter chains that do not mention application protocols
2338
+ if (!filter_chain.filter_chain_match.application_protocols.empty()) {
2339
+ return GRPC_ERROR_NONE;
2340
+ }
2341
+ return AddFilterChainDataForSourceType(filter_chain, destination_ip);
2342
+ }
2343
+
2344
+ grpc_error* AddFilterChainDataForTransportProtocol(
2345
+ const FilterChain& filter_chain,
2346
+ InternalFilterChainMap::DestinationIp* destination_ip) {
2347
+ const std::string& transport_protocol =
2348
+ filter_chain.filter_chain_match.transport_protocol;
2349
+ // Only allow filter chains with no transport protocol or "raw_buffer"
2350
+ if (!transport_protocol.empty() && transport_protocol != "raw_buffer") {
2351
+ return GRPC_ERROR_NONE;
2352
+ }
2353
+ // If for this configuration, we've already seen filter chains that mention
2354
+ // the transport protocol as "raw_buffer", we will never match filter chains
2355
+ // that do not mention it.
2356
+ if (destination_ip->transport_protocol_raw_buffer_provided &&
2357
+ transport_protocol.empty()) {
2358
+ return GRPC_ERROR_NONE;
2359
+ }
2360
+ if (!transport_protocol.empty() &&
2361
+ !destination_ip->transport_protocol_raw_buffer_provided) {
2362
+ destination_ip->transport_protocol_raw_buffer_provided = true;
2363
+ // Clear out the previous entries if any since those entries did not mention
2364
+ // "raw_buffer"
2365
+ destination_ip->source_types_array =
2366
+ InternalFilterChainMap::ConnectionSourceTypesArray();
2367
+ }
2368
+ return AddFilterChainDataForApplicationProtocols(filter_chain,
2369
+ destination_ip);
2370
+ }
2371
+
2372
+ grpc_error* AddFilterChainDataForServerNames(
2373
+ const FilterChain& filter_chain,
2374
+ InternalFilterChainMap::DestinationIp* destination_ip) {
2375
+ // Don't continue adding filter chains with server names mentioned
2376
+ if (!filter_chain.filter_chain_match.server_names.empty()) {
2377
+ return GRPC_ERROR_NONE;
2378
+ }
2379
+ return AddFilterChainDataForTransportProtocol(filter_chain, destination_ip);
2380
+ }
2381
+
2382
+ grpc_error* AddFilterChainDataForDestinationIpRange(
2383
+ const FilterChain& filter_chain,
2384
+ InternalFilterChainMap::DestinationIpMap* destination_ip_map) {
2385
+ if (filter_chain.filter_chain_match.prefix_ranges.empty()) {
2386
+ auto insert_result = destination_ip_map->emplace(
2387
+ "", InternalFilterChainMap::DestinationIp());
2388
+ return AddFilterChainDataForServerNames(filter_chain,
2389
+ &insert_result.first->second);
2390
+ } else {
2391
+ for (const auto& prefix_range :
2392
+ filter_chain.filter_chain_match.prefix_ranges) {
2393
+ auto insert_result = destination_ip_map->emplace(
2394
+ absl::StrCat(grpc_sockaddr_to_string(&prefix_range.address, false),
2395
+ "/", prefix_range.prefix_len),
2396
+ InternalFilterChainMap::DestinationIp());
2397
+ if (insert_result.second) {
2398
+ insert_result.first->second.prefix_range.emplace(prefix_range);
2399
+ }
2400
+ grpc_error* error = AddFilterChainDataForServerNames(
2401
+ filter_chain, &insert_result.first->second);
2402
+ if (error != GRPC_ERROR_NONE) return error;
2403
+ }
2404
+ }
2405
+ return GRPC_ERROR_NONE;
2406
+ }
2407
+
2408
+ XdsApi::LdsUpdate::FilterChainMap BuildFromInternalFilterChainMap(
2409
+ InternalFilterChainMap* internal_filter_chain_map) {
2410
+ XdsApi::LdsUpdate::FilterChainMap filter_chain_map;
2411
+ for (auto& destination_ip_pair :
2412
+ internal_filter_chain_map->destination_ip_map) {
2413
+ XdsApi::LdsUpdate::FilterChainMap::DestinationIp destination_ip;
2414
+ destination_ip.prefix_range = destination_ip_pair.second.prefix_range;
2415
+ for (int i = 0; i < 3; i++) {
2416
+ auto& source_ip_map = destination_ip_pair.second.source_types_array[i];
2417
+ for (auto& source_ip_pair : source_ip_map) {
2418
+ destination_ip.source_types_array[i].push_back(
2419
+ std::move(source_ip_pair.second));
2420
+ }
2421
+ }
2422
+ filter_chain_map.destination_ip_vector.push_back(std::move(destination_ip));
2423
+ }
2424
+ return filter_chain_map;
2425
+ }
2426
+
2427
+ grpc_error* BuildFilterChainMap(
2428
+ const std::vector<FilterChain>& filter_chains,
2429
+ XdsApi::LdsUpdate::FilterChainMap* filter_chain_map) {
2430
+ InternalFilterChainMap internal_filter_chain_map;
2431
+ for (const auto& filter_chain : filter_chains) {
2432
+ // Discard filter chain entries that specify destination port
2433
+ if (filter_chain.filter_chain_match.destination_port != 0) continue;
2434
+ grpc_error* error = AddFilterChainDataForDestinationIpRange(
2435
+ filter_chain, &internal_filter_chain_map.destination_ip_map);
2436
+ if (error != GRPC_ERROR_NONE) return error;
2437
+ }
2438
+ *filter_chain_map =
2439
+ BuildFromInternalFilterChainMap(&internal_filter_chain_map);
1408
2440
  return GRPC_ERROR_NONE;
1409
2441
  }
1410
2442
 
1411
2443
  grpc_error* LdsResponseParseServer(
1412
- upb_arena* arena, const envoy_config_listener_v3_Listener* listener,
1413
- const std::string& /*listener_name*/,
1414
- const envoy_config_core_v3_Address* /*address*/,
2444
+ const EncodingContext& context,
2445
+ const envoy_config_listener_v3_Listener* listener, bool is_v2,
1415
2446
  XdsApi::LdsUpdate* lds_update) {
1416
2447
  lds_update->type = XdsApi::LdsUpdate::ListenerType::kTcpListener;
1417
- // TODO(yashykt): Support filter chain match.
1418
- // Right now, we are supporting and expecting only one entry in filter_chains.
2448
+ grpc_error* error =
2449
+ AddressParse(envoy_config_listener_v3_Listener_address(listener),
2450
+ &lds_update->address);
2451
+ if (error != GRPC_ERROR_NONE) return error;
2452
+ const auto* use_original_dst =
2453
+ envoy_config_listener_v3_Listener_use_original_dst(listener);
2454
+ if (use_original_dst != nullptr) {
2455
+ if (google_protobuf_BoolValue_value(use_original_dst)) {
2456
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2457
+ "Field \'use_original_dst\' is not supported.");
2458
+ }
2459
+ }
1419
2460
  size_t size = 0;
1420
2461
  auto* filter_chains =
1421
2462
  envoy_config_listener_v3_Listener_filter_chains(listener, &size);
1422
- if (size != 1) {
1423
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1424
- "Only one filter_chain supported.");
1425
- }
1426
- // Get the DownstreamTlsContext from the match
1427
- if (XdsSecurityEnabled()) {
1428
- auto* transport_socket =
1429
- envoy_config_listener_v3_FilterChain_transport_socket(filter_chains[0]);
1430
- if (transport_socket != nullptr) {
1431
- absl::string_view name = UpbStringToAbsl(
1432
- envoy_config_core_v3_TransportSocket_name(transport_socket));
1433
- if (name == "envoy.transport_sockets.tls") {
1434
- auto* typed_config =
1435
- envoy_config_core_v3_TransportSocket_typed_config(transport_socket);
1436
- if (typed_config != nullptr) {
1437
- const upb_strview encoded_downstream_tls_context =
1438
- google_protobuf_Any_value(typed_config);
1439
- auto* downstream_tls_context =
1440
- envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_parse(
1441
- encoded_downstream_tls_context.data,
1442
- encoded_downstream_tls_context.size, arena);
1443
- if (downstream_tls_context == nullptr) {
1444
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1445
- "Can't decode downstream tls context.");
1446
- }
1447
- auto* common_tls_context =
1448
- envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_common_tls_context(
1449
- downstream_tls_context);
1450
- if (common_tls_context != nullptr) {
1451
- grpc_error* error = CommonTlsContextParse(
1452
- common_tls_context,
1453
- &lds_update->downstream_tls_context.common_tls_context);
1454
- if (error != GRPC_ERROR_NONE) return error;
1455
- }
1456
- auto* require_client_certificate =
1457
- envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_require_client_certificate(
1458
- downstream_tls_context);
1459
- if (require_client_certificate != nullptr) {
1460
- lds_update->downstream_tls_context.require_client_certificate =
1461
- google_protobuf_BoolValue_value(require_client_certificate);
1462
- }
1463
- }
1464
- if (lds_update->downstream_tls_context.common_tls_context
1465
- .tls_certificate_certificate_provider_instance.instance_name
1466
- .empty()) {
1467
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1468
- "TLS configuration provided but no "
1469
- "tls_certificate_certificate_provider_instance found.");
1470
- }
1471
- }
2463
+ std::vector<FilterChain> parsed_filter_chains;
2464
+ parsed_filter_chains.reserve(size);
2465
+ for (size_t i = 0; i < size; i++) {
2466
+ FilterChain filter_chain;
2467
+ error = FilterChainParse(context, filter_chains[i], is_v2, &filter_chain);
2468
+ if (error != GRPC_ERROR_NONE) return error;
2469
+ parsed_filter_chains.push_back(std::move(filter_chain));
2470
+ }
2471
+ error =
2472
+ BuildFilterChainMap(parsed_filter_chains, &lds_update->filter_chain_map);
2473
+ if (error != GRPC_ERROR_NONE) return error;
2474
+ auto* default_filter_chain =
2475
+ envoy_config_listener_v3_Listener_default_filter_chain(listener);
2476
+ if (default_filter_chain != nullptr) {
2477
+ FilterChain filter_chain;
2478
+ error =
2479
+ FilterChainParse(context, default_filter_chain, is_v2, &filter_chain);
2480
+ if (error != GRPC_ERROR_NONE) return error;
2481
+ if (filter_chain.filter_chain_data != nullptr) {
2482
+ lds_update->default_filter_chain =
2483
+ std::move(*filter_chain.filter_chain_data);
1472
2484
  }
1473
2485
  }
2486
+ if (size == 0 && default_filter_chain == nullptr) {
2487
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("No filter chain provided.");
2488
+ }
1474
2489
  return GRPC_ERROR_NONE;
1475
2490
  }
1476
2491
 
1477
2492
  grpc_error* LdsResponseParse(
1478
- XdsClient* client, TraceFlag* tracer, upb_symtab* symtab,
2493
+ const EncodingContext& context,
1479
2494
  const envoy_service_discovery_v3_DiscoveryResponse* response,
1480
2495
  const std::set<absl::string_view>& expected_listener_names,
1481
2496
  XdsApi::LdsUpdateMap* lds_update_map,
1482
- std::set<std::string>* resource_names_failed, upb_arena* arena) {
2497
+ std::set<std::string>* resource_names_failed) {
1483
2498
  std::vector<grpc_error*> errors;
1484
2499
  // Get the resources from the response.
1485
2500
  size_t size;
@@ -1489,7 +2504,8 @@ grpc_error* LdsResponseParse(
1489
2504
  // Check the type_url of the resource.
1490
2505
  absl::string_view type_url =
1491
2506
  UpbStringToAbsl(google_protobuf_Any_type_url(resources[i]));
1492
- if (!IsLds(type_url)) {
2507
+ bool is_v2 = false;
2508
+ if (!IsLds(type_url, &is_v2)) {
1493
2509
  errors.push_back(GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1494
2510
  absl::StrCat("resource index ", i, ": Resource is not LDS.")
1495
2511
  .c_str()));
@@ -1499,8 +2515,8 @@ grpc_error* LdsResponseParse(
1499
2515
  const upb_strview encoded_listener =
1500
2516
  google_protobuf_Any_value(resources[i]);
1501
2517
  const envoy_config_listener_v3_Listener* listener =
1502
- envoy_config_listener_v3_Listener_parse(encoded_listener.data,
1503
- encoded_listener.size, arena);
2518
+ envoy_config_listener_v3_Listener_parse(
2519
+ encoded_listener.data, encoded_listener.size, context.arena);
1504
2520
  if (listener == nullptr) {
1505
2521
  errors.push_back(GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1506
2522
  absl::StrCat("resource index ", i, ": Can't decode listener.")
@@ -1522,7 +2538,11 @@ grpc_error* LdsResponseParse(
1522
2538
  resource_names_failed->insert(listener_name);
1523
2539
  continue;
1524
2540
  }
1525
- XdsApi::LdsUpdate& lds_update = (*lds_update_map)[listener_name];
2541
+ // Serialize into JSON and store it in the LdsUpdateMap
2542
+ XdsApi::LdsResourceData& lds_resource_data =
2543
+ (*lds_update_map)[listener_name];
2544
+ XdsApi::LdsUpdate& lds_update = lds_resource_data.resource;
2545
+ lds_resource_data.serialized_proto = UpbStringToStdString(encoded_listener);
1526
2546
  // Check whether it's a client or server listener.
1527
2547
  const envoy_config_listener_v3_ApiListener* api_listener =
1528
2548
  envoy_config_listener_v3_Listener_api_listener(listener);
@@ -1546,11 +2566,9 @@ grpc_error* LdsResponseParse(
1546
2566
  }
1547
2567
  grpc_error* error = GRPC_ERROR_NONE;
1548
2568
  if (api_listener != nullptr) {
1549
- error = LdsResponseParseClient(client, tracer, symtab, arena,
1550
- api_listener, &lds_update);
2569
+ error = LdsResponseParseClient(context, api_listener, is_v2, &lds_update);
1551
2570
  } else {
1552
- error = LdsResponseParseServer(arena, listener, listener_name, address,
1553
- &lds_update);
2571
+ error = LdsResponseParseServer(context, listener, is_v2, &lds_update);
1554
2572
  }
1555
2573
  if (error != GRPC_ERROR_NONE) {
1556
2574
  errors.push_back(grpc_error_add_child(
@@ -1564,11 +2582,11 @@ grpc_error* LdsResponseParse(
1564
2582
  }
1565
2583
 
1566
2584
  grpc_error* RdsResponseParse(
1567
- XdsClient* client, TraceFlag* tracer, upb_symtab* symtab,
2585
+ const EncodingContext& context,
1568
2586
  const envoy_service_discovery_v3_DiscoveryResponse* response,
1569
2587
  const std::set<absl::string_view>& expected_route_configuration_names,
1570
2588
  XdsApi::RdsUpdateMap* rds_update_map,
1571
- std::set<std::string>* resource_names_failed, upb_arena* arena) {
2589
+ std::set<std::string>* resource_names_failed) {
1572
2590
  std::vector<grpc_error*> errors;
1573
2591
  // Get the resources from the response.
1574
2592
  size_t size;
@@ -1589,7 +2607,8 @@ grpc_error* RdsResponseParse(
1589
2607
  google_protobuf_Any_value(resources[i]);
1590
2608
  const envoy_config_route_v3_RouteConfiguration* route_config =
1591
2609
  envoy_config_route_v3_RouteConfiguration_parse(
1592
- encoded_route_config.data, encoded_route_config.size, arena);
2610
+ encoded_route_config.data, encoded_route_config.size,
2611
+ context.arena);
1593
2612
  if (route_config == nullptr) {
1594
2613
  errors.push_back(GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1595
2614
  absl::StrCat("resource index ", i, ": Can't decode route_config.")
@@ -1612,10 +2631,14 @@ grpc_error* RdsResponseParse(
1612
2631
  resource_names_failed->insert(route_config_name);
1613
2632
  continue;
1614
2633
  }
2634
+ // Serialize into JSON and store it in the RdsUpdateMap
2635
+ XdsApi::RdsResourceData& rds_resource_data =
2636
+ (*rds_update_map)[route_config_name];
2637
+ XdsApi::RdsUpdate& rds_update = rds_resource_data.resource;
2638
+ rds_resource_data.serialized_proto =
2639
+ UpbStringToStdString(encoded_route_config);
1615
2640
  // Parse the route_config.
1616
- XdsApi::RdsUpdate& rds_update = (*rds_update_map)[route_config_name];
1617
- grpc_error* error =
1618
- RouteConfigParse(client, tracer, symtab, route_config, &rds_update);
2641
+ grpc_error* error = RouteConfigParse(context, route_config, &rds_update);
1619
2642
  if (error != GRPC_ERROR_NONE) {
1620
2643
  errors.push_back(grpc_error_add_child(
1621
2644
  GRPC_ERROR_CREATE_FROM_COPIED_STRING(
@@ -1628,11 +2651,11 @@ grpc_error* RdsResponseParse(
1628
2651
  }
1629
2652
 
1630
2653
  grpc_error* CdsResponseParse(
1631
- XdsClient* client, TraceFlag* tracer, upb_symtab* symtab,
2654
+ const EncodingContext& context,
1632
2655
  const envoy_service_discovery_v3_DiscoveryResponse* response,
1633
2656
  const std::set<absl::string_view>& expected_cluster_names,
1634
2657
  XdsApi::CdsUpdateMap* cds_update_map,
1635
- std::set<std::string>* resource_names_failed, upb_arena* arena) {
2658
+ std::set<std::string>* resource_names_failed) {
1636
2659
  std::vector<grpc_error*> errors;
1637
2660
  // Get the resources from the response.
1638
2661
  size_t size;
@@ -1652,15 +2675,15 @@ grpc_error* CdsResponseParse(
1652
2675
  // Decode the cluster.
1653
2676
  const upb_strview encoded_cluster = google_protobuf_Any_value(resources[i]);
1654
2677
  const envoy_config_cluster_v3_Cluster* cluster =
1655
- envoy_config_cluster_v3_Cluster_parse(encoded_cluster.data,
1656
- encoded_cluster.size, arena);
2678
+ envoy_config_cluster_v3_Cluster_parse(
2679
+ encoded_cluster.data, encoded_cluster.size, context.arena);
1657
2680
  if (cluster == nullptr) {
1658
2681
  errors.push_back(GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1659
2682
  absl::StrCat("resource index ", i, ": Can't decode cluster.")
1660
2683
  .c_str()));
1661
2684
  continue;
1662
2685
  }
1663
- MaybeLogCluster(client, tracer, symtab, cluster);
2686
+ MaybeLogCluster(context, cluster);
1664
2687
  // Ignore unexpected cluster names.
1665
2688
  std::string cluster_name =
1666
2689
  UpbStringToStdString(envoy_config_cluster_v3_Cluster_name(cluster));
@@ -1676,7 +2699,11 @@ grpc_error* CdsResponseParse(
1676
2699
  resource_names_failed->insert(cluster_name);
1677
2700
  continue;
1678
2701
  }
1679
- XdsApi::CdsUpdate& cds_update = (*cds_update_map)[cluster_name];
2702
+ // Serialize into JSON and store it in the CdsUpdateMap
2703
+ XdsApi::CdsResourceData& cds_resource_data =
2704
+ (*cds_update_map)[cluster_name];
2705
+ XdsApi::CdsUpdate& cds_update = cds_resource_data.resource;
2706
+ cds_resource_data.serialized_proto = UpbStringToStdString(encoded_cluster);
1680
2707
  // Check the cluster_discovery_type.
1681
2708
  if (!envoy_config_cluster_v3_Cluster_has_type(cluster) &&
1682
2709
  !envoy_config_cluster_v3_Cluster_has_cluster_type(cluster)) {
@@ -1737,7 +2764,7 @@ grpc_error* CdsResponseParse(
1737
2764
  aggregate_cluster_config =
1738
2765
  envoy_extensions_clusters_aggregate_v3_ClusterConfig_parse(
1739
2766
  aggregate_cluster_config_upb_strview.data,
1740
- aggregate_cluster_config_upb_strview.size, arena);
2767
+ aggregate_cluster_config_upb_strview.size, context.arena);
1741
2768
  if (aggregate_cluster_config == nullptr) {
1742
2769
  errors.push_back(GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1743
2770
  absl::StrCat(cluster_name, ": Can't parse aggregate cluster.")
@@ -1872,7 +2899,7 @@ grpc_error* CdsResponseParse(
1872
2899
  auto* upstream_tls_context =
1873
2900
  envoy_extensions_transport_sockets_tls_v3_UpstreamTlsContext_parse(
1874
2901
  encoded_upstream_tls_context.data,
1875
- encoded_upstream_tls_context.size, arena);
2902
+ encoded_upstream_tls_context.size, context.arena);
1876
2903
  if (upstream_tls_context == nullptr) {
1877
2904
  errors.push_back(GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1878
2905
  absl::StrCat(cluster_name,
@@ -1981,7 +3008,9 @@ grpc_error* ServerAddressParseAndAppend(
1981
3008
  }
1982
3009
  // Populate grpc_resolved_address.
1983
3010
  grpc_resolved_address addr;
1984
- grpc_string_to_sockaddr(&addr, address_str.c_str(), port);
3011
+ grpc_error* error =
3012
+ grpc_string_to_sockaddr_new(&addr, address_str.c_str(), port);
3013
+ if (error != GRPC_ERROR_NONE) return error;
1985
3014
  // Append the address to the list.
1986
3015
  list->emplace_back(addr, nullptr);
1987
3016
  return GRPC_ERROR_NONE;
@@ -2004,6 +3033,9 @@ grpc_error* LocalityParse(
2004
3033
  const envoy_config_core_v3_Locality* locality =
2005
3034
  envoy_config_endpoint_v3_LocalityLbEndpoints_locality(
2006
3035
  locality_lb_endpoints);
3036
+ if (locality == nullptr) {
3037
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty locality.");
3038
+ }
2007
3039
  std::string region =
2008
3040
  UpbStringToStdString(envoy_config_core_v3_Locality_region(locality));
2009
3041
  std::string zone =
@@ -2068,11 +3100,11 @@ grpc_error* DropParseAndAppend(
2068
3100
  }
2069
3101
 
2070
3102
  grpc_error* EdsResponseParse(
2071
- XdsClient* client, TraceFlag* tracer, upb_symtab* symtab,
3103
+ const EncodingContext& context,
2072
3104
  const envoy_service_discovery_v3_DiscoveryResponse* response,
2073
3105
  const std::set<absl::string_view>& expected_eds_service_names,
2074
3106
  XdsApi::EdsUpdateMap* eds_update_map,
2075
- std::set<std::string>* resource_names_failed, upb_arena* arena) {
3107
+ std::set<std::string>* resource_names_failed) {
2076
3108
  std::vector<grpc_error*> errors;
2077
3109
  // Get the resources from the response.
2078
3110
  size_t size;
@@ -2094,7 +3126,7 @@ grpc_error* EdsResponseParse(
2094
3126
  envoy_config_endpoint_v3_ClusterLoadAssignment* cluster_load_assignment =
2095
3127
  envoy_config_endpoint_v3_ClusterLoadAssignment_parse(
2096
3128
  encoded_cluster_load_assignment.data,
2097
- encoded_cluster_load_assignment.size, arena);
3129
+ encoded_cluster_load_assignment.size, context.arena);
2098
3130
  if (cluster_load_assignment == nullptr) {
2099
3131
  errors.push_back(GRPC_ERROR_CREATE_FROM_COPIED_STRING(
2100
3132
  absl::StrCat("resource index ", i,
@@ -2102,8 +3134,7 @@ grpc_error* EdsResponseParse(
2102
3134
  .c_str()));
2103
3135
  continue;
2104
3136
  }
2105
- MaybeLogClusterLoadAssignment(client, tracer, symtab,
2106
- cluster_load_assignment);
3137
+ MaybeLogClusterLoadAssignment(context, cluster_load_assignment);
2107
3138
  // Check the EDS service name. Ignore unexpected names.
2108
3139
  std::string eds_service_name = UpbStringToStdString(
2109
3140
  envoy_config_endpoint_v3_ClusterLoadAssignment_cluster_name(
@@ -2120,7 +3151,12 @@ grpc_error* EdsResponseParse(
2120
3151
  resource_names_failed->insert(eds_service_name);
2121
3152
  continue;
2122
3153
  }
2123
- XdsApi::EdsUpdate& eds_update = (*eds_update_map)[eds_service_name];
3154
+ // Serialize into JSON and store it in the EdsUpdateMap
3155
+ XdsApi::EdsResourceData& eds_resource_data =
3156
+ (*eds_update_map)[eds_service_name];
3157
+ XdsApi::EdsUpdate& eds_update = eds_resource_data.resource;
3158
+ eds_resource_data.serialized_proto =
3159
+ UpbStringToStdString(encoded_cluster_load_assignment);
2124
3160
  // Get the endpoints.
2125
3161
  size_t locality_size;
2126
3162
  const envoy_config_endpoint_v3_LocalityLbEndpoints* const* endpoints =
@@ -2214,13 +3250,15 @@ void MoveUpdatesToFailedSet(UpdateMap* update_map,
2214
3250
  } // namespace
2215
3251
 
2216
3252
  XdsApi::AdsParseResult XdsApi::ParseAdsResponse(
2217
- const grpc_slice& encoded_response,
3253
+ const XdsBootstrap::XdsServer& server, const grpc_slice& encoded_response,
2218
3254
  const std::set<absl::string_view>& expected_listener_names,
2219
3255
  const std::set<absl::string_view>& expected_route_configuration_names,
2220
3256
  const std::set<absl::string_view>& expected_cluster_names,
2221
3257
  const std::set<absl::string_view>& expected_eds_service_names) {
2222
3258
  AdsParseResult result;
2223
3259
  upb::Arena arena;
3260
+ const EncodingContext context = {client_, tracer_, symtab_.ptr(), arena.ptr(),
3261
+ server.ShouldUseV3()};
2224
3262
  // Decode the response.
2225
3263
  const envoy_service_discovery_v3_DiscoveryResponse* response =
2226
3264
  envoy_service_discovery_v3_DiscoveryResponse_parse(
@@ -2232,7 +3270,7 @@ XdsApi::AdsParseResult XdsApi::ParseAdsResponse(
2232
3270
  GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode DiscoveryResponse.");
2233
3271
  return result;
2234
3272
  }
2235
- MaybeLogDiscoveryResponse(client_, tracer_, symtab_.ptr(), response);
3273
+ MaybeLogDiscoveryResponse(context, response);
2236
3274
  // Record the type_url, the version_info, and the nonce of the response.
2237
3275
  result.type_url = TypeUrlInternalToExternal(UpbStringToAbsl(
2238
3276
  envoy_service_discovery_v3_DiscoveryResponse_type_url(response)));
@@ -2242,34 +3280,33 @@ XdsApi::AdsParseResult XdsApi::ParseAdsResponse(
2242
3280
  envoy_service_discovery_v3_DiscoveryResponse_nonce(response));
2243
3281
  // Parse the response according to the resource type.
2244
3282
  if (IsLds(result.type_url)) {
2245
- result.parse_error = LdsResponseParse(
2246
- client_, tracer_, symtab_.ptr(), response, expected_listener_names,
2247
- &result.lds_update_map, &result.resource_names_failed, arena.ptr());
3283
+ result.parse_error =
3284
+ LdsResponseParse(context, response, expected_listener_names,
3285
+ &result.lds_update_map, &result.resource_names_failed);
2248
3286
  if (result.parse_error != GRPC_ERROR_NONE) {
2249
3287
  MoveUpdatesToFailedSet(&result.lds_update_map,
2250
3288
  &result.resource_names_failed);
2251
3289
  }
2252
3290
  } else if (IsRds(result.type_url)) {
2253
- result.parse_error = RdsResponseParse(
2254
- client_, tracer_, symtab_.ptr(), response,
2255
- expected_route_configuration_names, &result.rds_update_map,
2256
- &result.resource_names_failed, arena.ptr());
3291
+ result.parse_error =
3292
+ RdsResponseParse(context, response, expected_route_configuration_names,
3293
+ &result.rds_update_map, &result.resource_names_failed);
2257
3294
  if (result.parse_error != GRPC_ERROR_NONE) {
2258
3295
  MoveUpdatesToFailedSet(&result.rds_update_map,
2259
3296
  &result.resource_names_failed);
2260
3297
  }
2261
3298
  } else if (IsCds(result.type_url)) {
2262
- result.parse_error = CdsResponseParse(
2263
- client_, tracer_, symtab_.ptr(), response, expected_cluster_names,
2264
- &result.cds_update_map, &result.resource_names_failed, arena.ptr());
3299
+ result.parse_error =
3300
+ CdsResponseParse(context, response, expected_cluster_names,
3301
+ &result.cds_update_map, &result.resource_names_failed);
2265
3302
  if (result.parse_error != GRPC_ERROR_NONE) {
2266
3303
  MoveUpdatesToFailedSet(&result.cds_update_map,
2267
3304
  &result.resource_names_failed);
2268
3305
  }
2269
3306
  } else if (IsEds(result.type_url)) {
2270
- result.parse_error = EdsResponseParse(
2271
- client_, tracer_, symtab_.ptr(), response, expected_eds_service_names,
2272
- &result.eds_update_map, &result.resource_names_failed, arena.ptr());
3307
+ result.parse_error =
3308
+ EdsResponseParse(context, response, expected_eds_service_names,
3309
+ &result.eds_update_map, &result.resource_names_failed);
2273
3310
  if (result.parse_error != GRPC_ERROR_NONE) {
2274
3311
  MoveUpdatesToFailedSet(&result.eds_update_map,
2275
3312
  &result.resource_names_failed);
@@ -2281,25 +3318,25 @@ XdsApi::AdsParseResult XdsApi::ParseAdsResponse(
2281
3318
  namespace {
2282
3319
 
2283
3320
  void MaybeLogLrsRequest(
2284
- XdsClient* client, TraceFlag* tracer, upb_symtab* symtab,
3321
+ const EncodingContext& context,
2285
3322
  const envoy_service_load_stats_v3_LoadStatsRequest* request) {
2286
- if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
3323
+ if (GRPC_TRACE_FLAG_ENABLED(*context.tracer) &&
2287
3324
  gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
2288
3325
  const upb_msgdef* msg_type =
2289
- envoy_service_load_stats_v3_LoadStatsRequest_getmsgdef(symtab);
3326
+ envoy_service_load_stats_v3_LoadStatsRequest_getmsgdef(context.symtab);
2290
3327
  char buf[10240];
2291
3328
  upb_text_encode(request, msg_type, nullptr, 0, buf, sizeof(buf));
2292
- gpr_log(GPR_DEBUG, "[xds_client %p] constructed LRS request: %s", client,
2293
- buf);
3329
+ gpr_log(GPR_DEBUG, "[xds_client %p] constructed LRS request: %s",
3330
+ context.client, buf);
2294
3331
  }
2295
3332
  }
2296
3333
 
2297
3334
  grpc_slice SerializeLrsRequest(
2298
- const envoy_service_load_stats_v3_LoadStatsRequest* request,
2299
- upb_arena* arena) {
3335
+ const EncodingContext& context,
3336
+ const envoy_service_load_stats_v3_LoadStatsRequest* request) {
2300
3337
  size_t output_length;
2301
3338
  char* output = envoy_service_load_stats_v3_LoadStatsRequest_serialize(
2302
- request, arena, &output_length);
3339
+ request, context.arena, &output_length);
2303
3340
  return grpc_slice_from_copied_buffer(output, output_length);
2304
3341
  }
2305
3342
 
@@ -2308,6 +3345,8 @@ grpc_slice SerializeLrsRequest(
2308
3345
  grpc_slice XdsApi::CreateLrsInitialRequest(
2309
3346
  const XdsBootstrap::XdsServer& server) {
2310
3347
  upb::Arena arena;
3348
+ const EncodingContext context = {client_, tracer_, symtab_.ptr(), arena.ptr(),
3349
+ server.ShouldUseV3()};
2311
3350
  // Create a request.
2312
3351
  envoy_service_load_stats_v3_LoadStatsRequest* request =
2313
3352
  envoy_service_load_stats_v3_LoadStatsRequest_new(arena.ptr());
@@ -2315,25 +3354,25 @@ grpc_slice XdsApi::CreateLrsInitialRequest(
2315
3354
  envoy_config_core_v3_Node* node_msg =
2316
3355
  envoy_service_load_stats_v3_LoadStatsRequest_mutable_node(request,
2317
3356
  arena.ptr());
2318
- PopulateNode(arena.ptr(), node_, server.ShouldUseV3(), build_version_,
2319
- user_agent_name_, node_msg);
3357
+ PopulateNode(context, node_, build_version_, user_agent_name_, node_msg);
2320
3358
  envoy_config_core_v3_Node_add_client_features(
2321
3359
  node_msg, upb_strview_makez("envoy.lrs.supports_send_all_clusters"),
2322
3360
  arena.ptr());
2323
- MaybeLogLrsRequest(client_, tracer_, symtab_.ptr(), request);
2324
- return SerializeLrsRequest(request, arena.ptr());
3361
+ MaybeLogLrsRequest(context, request);
3362
+ return SerializeLrsRequest(context, request);
2325
3363
  }
2326
3364
 
2327
3365
  namespace {
2328
3366
 
2329
3367
  void LocalityStatsPopulate(
3368
+ const EncodingContext& context,
2330
3369
  envoy_config_endpoint_v3_UpstreamLocalityStats* output,
2331
3370
  const XdsLocalityName& locality_name,
2332
- const XdsClusterLocalityStats::Snapshot& snapshot, upb_arena* arena) {
3371
+ const XdsClusterLocalityStats::Snapshot& snapshot) {
2333
3372
  // Set locality.
2334
3373
  envoy_config_core_v3_Locality* locality =
2335
- envoy_config_endpoint_v3_UpstreamLocalityStats_mutable_locality(output,
2336
- arena);
3374
+ envoy_config_endpoint_v3_UpstreamLocalityStats_mutable_locality(
3375
+ output, context.arena);
2337
3376
  if (!locality_name.region().empty()) {
2338
3377
  envoy_config_core_v3_Locality_set_region(
2339
3378
  locality, StdStringToUpbString(locality_name.region()));
@@ -2361,7 +3400,7 @@ void LocalityStatsPopulate(
2361
3400
  const XdsClusterLocalityStats::BackendMetric& metric_value = p.second;
2362
3401
  envoy_config_endpoint_v3_EndpointLoadMetricStats* load_metric =
2363
3402
  envoy_config_endpoint_v3_UpstreamLocalityStats_add_load_metric_stats(
2364
- output, arena);
3403
+ output, context.arena);
2365
3404
  envoy_config_endpoint_v3_EndpointLoadMetricStats_set_metric_name(
2366
3405
  load_metric, StdStringToUpbString(metric_name));
2367
3406
  envoy_config_endpoint_v3_EndpointLoadMetricStats_set_num_requests_finished_with_metric(
@@ -2376,6 +3415,8 @@ void LocalityStatsPopulate(
2376
3415
  grpc_slice XdsApi::CreateLrsRequest(
2377
3416
  ClusterLoadReportMap cluster_load_report_map) {
2378
3417
  upb::Arena arena;
3418
+ const EncodingContext context = {client_, tracer_, symtab_.ptr(), arena.ptr(),
3419
+ false};
2379
3420
  // Create a request.
2380
3421
  envoy_service_load_stats_v3_LoadStatsRequest* request =
2381
3422
  envoy_service_load_stats_v3_LoadStatsRequest_new(arena.ptr());
@@ -2402,8 +3443,7 @@ grpc_slice XdsApi::CreateLrsRequest(
2402
3443
  envoy_config_endpoint_v3_UpstreamLocalityStats* locality_stats =
2403
3444
  envoy_config_endpoint_v3_ClusterStats_add_upstream_locality_stats(
2404
3445
  cluster_stats, arena.ptr());
2405
- LocalityStatsPopulate(locality_stats, locality_name, snapshot,
2406
- arena.ptr());
3446
+ LocalityStatsPopulate(context, locality_stats, locality_name, snapshot);
2407
3447
  }
2408
3448
  // Add dropped requests.
2409
3449
  uint64_t total_dropped_requests = 0;
@@ -2432,8 +3472,8 @@ grpc_slice XdsApi::CreateLrsRequest(
2432
3472
  google_protobuf_Duration_set_seconds(load_report_interval, timespec.tv_sec);
2433
3473
  google_protobuf_Duration_set_nanos(load_report_interval, timespec.tv_nsec);
2434
3474
  }
2435
- MaybeLogLrsRequest(client_, tracer_, symtab_.ptr(), request);
2436
- return SerializeLrsRequest(request, arena.ptr());
3475
+ MaybeLogLrsRequest(context, request);
3476
+ return SerializeLrsRequest(context, request);
2437
3477
  }
2438
3478
 
2439
3479
  grpc_error* XdsApi::ParseLrsResponse(const grpc_slice& encoded_response,
@@ -2476,4 +3516,276 @@ grpc_error* XdsApi::ParseLrsResponse(const grpc_slice& encoded_response,
2476
3516
  return GRPC_ERROR_NONE;
2477
3517
  }
2478
3518
 
3519
+ namespace {
3520
+ google_protobuf_Timestamp* GrpcMillisToTimestamp(const EncodingContext& context,
3521
+ grpc_millis value) {
3522
+ google_protobuf_Timestamp* timestamp =
3523
+ google_protobuf_Timestamp_new(context.arena);
3524
+ gpr_timespec timespec = grpc_millis_to_timespec(value, GPR_CLOCK_MONOTONIC);
3525
+ google_protobuf_Timestamp_set_seconds(timestamp, timespec.tv_sec);
3526
+ google_protobuf_Timestamp_set_nanos(timestamp, timespec.tv_nsec);
3527
+ return timestamp;
3528
+ }
3529
+
3530
+ envoy_admin_v3_UpdateFailureState* CreateUpdateFailureStateUpb(
3531
+ const EncodingContext& context,
3532
+ const XdsApi::ResourceMetadata* resource_metadata) {
3533
+ auto* update_failure_state =
3534
+ envoy_admin_v3_UpdateFailureState_new(context.arena);
3535
+ envoy_admin_v3_UpdateFailureState_set_details(
3536
+ update_failure_state,
3537
+ StdStringToUpbString(resource_metadata->failed_details));
3538
+ envoy_admin_v3_UpdateFailureState_set_version_info(
3539
+ update_failure_state,
3540
+ StdStringToUpbString(resource_metadata->failed_version));
3541
+ envoy_admin_v3_UpdateFailureState_set_last_update_attempt(
3542
+ update_failure_state,
3543
+ GrpcMillisToTimestamp(context, resource_metadata->failed_update_time));
3544
+ return update_failure_state;
3545
+ }
3546
+
3547
+ void DumpLdsConfig(const EncodingContext& context,
3548
+ const XdsApi::ResourceTypeMetadata& resource_type_metadata,
3549
+ envoy_service_status_v3_PerXdsConfig* per_xds_config) {
3550
+ upb_strview kLdsTypeUrlUpb = upb_strview_makez(XdsApi::kLdsTypeUrl);
3551
+ auto* listener_config_dump =
3552
+ envoy_service_status_v3_PerXdsConfig_mutable_listener_config(
3553
+ per_xds_config, context.arena);
3554
+ envoy_admin_v3_ListenersConfigDump_set_version_info(
3555
+ listener_config_dump,
3556
+ StdStringToUpbString(resource_type_metadata.version));
3557
+ for (auto& p : resource_type_metadata.resource_metadata_map) {
3558
+ absl::string_view name = p.first;
3559
+ const XdsApi::ResourceMetadata* meta = p.second;
3560
+ const upb_strview name_upb = StdStringToUpbString(name);
3561
+ auto* dynamic_listener =
3562
+ envoy_admin_v3_ListenersConfigDump_add_dynamic_listeners(
3563
+ listener_config_dump, context.arena);
3564
+ envoy_admin_v3_ListenersConfigDump_DynamicListener_set_name(
3565
+ dynamic_listener, name_upb);
3566
+ envoy_admin_v3_ListenersConfigDump_DynamicListener_set_client_status(
3567
+ dynamic_listener, meta->client_status);
3568
+ if (!meta->serialized_proto.empty()) {
3569
+ // Set in-effective listeners
3570
+ auto* dynamic_listener_state =
3571
+ envoy_admin_v3_ListenersConfigDump_DynamicListener_mutable_active_state(
3572
+ dynamic_listener, context.arena);
3573
+ envoy_admin_v3_ListenersConfigDump_DynamicListenerState_set_version_info(
3574
+ dynamic_listener_state, StdStringToUpbString(meta->version));
3575
+ envoy_admin_v3_ListenersConfigDump_DynamicListenerState_set_last_updated(
3576
+ dynamic_listener_state,
3577
+ GrpcMillisToTimestamp(context, meta->update_time));
3578
+ auto* listener_any =
3579
+ envoy_admin_v3_ListenersConfigDump_DynamicListenerState_mutable_listener(
3580
+ dynamic_listener_state, context.arena);
3581
+ google_protobuf_Any_set_type_url(listener_any, kLdsTypeUrlUpb);
3582
+ google_protobuf_Any_set_value(
3583
+ listener_any, StdStringToUpbString(meta->serialized_proto));
3584
+ }
3585
+ if (meta->client_status == XdsApi::ResourceMetadata::NACKED) {
3586
+ // Set error_state if NACKED
3587
+ envoy_admin_v3_ListenersConfigDump_DynamicListener_set_error_state(
3588
+ dynamic_listener, CreateUpdateFailureStateUpb(context, meta));
3589
+ }
3590
+ }
3591
+ }
3592
+
3593
+ void DumpRdsConfig(const EncodingContext& context,
3594
+ const XdsApi::ResourceTypeMetadata& resource_type_metadata,
3595
+ envoy_service_status_v3_PerXdsConfig* per_xds_config) {
3596
+ upb_strview kRdsTypeUrlUpb = upb_strview_makez(XdsApi::kRdsTypeUrl);
3597
+ auto* route_config_dump =
3598
+ envoy_service_status_v3_PerXdsConfig_mutable_route_config(per_xds_config,
3599
+ context.arena);
3600
+ for (auto& p : resource_type_metadata.resource_metadata_map) {
3601
+ absl::string_view name = p.first;
3602
+ const XdsApi::ResourceMetadata* meta = p.second;
3603
+ const upb_strview name_upb = StdStringToUpbString(name);
3604
+ auto* dynamic_route_config =
3605
+ envoy_admin_v3_RoutesConfigDump_add_dynamic_route_configs(
3606
+ route_config_dump, context.arena);
3607
+ envoy_admin_v3_RoutesConfigDump_DynamicRouteConfig_set_client_status(
3608
+ dynamic_route_config, meta->client_status);
3609
+ auto* route_config_any =
3610
+ envoy_admin_v3_RoutesConfigDump_DynamicRouteConfig_mutable_route_config(
3611
+ dynamic_route_config, context.arena);
3612
+ if (!meta->serialized_proto.empty()) {
3613
+ // Set in-effective route configs
3614
+ envoy_admin_v3_RoutesConfigDump_DynamicRouteConfig_set_version_info(
3615
+ dynamic_route_config, StdStringToUpbString(meta->version));
3616
+ envoy_admin_v3_RoutesConfigDump_DynamicRouteConfig_set_last_updated(
3617
+ dynamic_route_config,
3618
+ GrpcMillisToTimestamp(context, meta->update_time));
3619
+ google_protobuf_Any_set_type_url(route_config_any, kRdsTypeUrlUpb);
3620
+ google_protobuf_Any_set_value(
3621
+ route_config_any, StdStringToUpbString(meta->serialized_proto));
3622
+ } else {
3623
+ // If there isn't a working route config, we still need to print the
3624
+ // name.
3625
+ auto* route_config =
3626
+ envoy_config_route_v3_RouteConfiguration_new(context.arena);
3627
+ envoy_config_route_v3_RouteConfiguration_set_name(route_config, name_upb);
3628
+ size_t length;
3629
+ char* bytes = envoy_config_route_v3_RouteConfiguration_serialize(
3630
+ route_config, context.arena, &length);
3631
+ google_protobuf_Any_set_type_url(route_config_any, kRdsTypeUrlUpb);
3632
+ google_protobuf_Any_set_value(route_config_any,
3633
+ upb_strview_make(bytes, length));
3634
+ }
3635
+ if (meta->client_status == XdsApi::ResourceMetadata::NACKED) {
3636
+ // Set error_state if NACKED
3637
+ envoy_admin_v3_RoutesConfigDump_DynamicRouteConfig_set_error_state(
3638
+ dynamic_route_config, CreateUpdateFailureStateUpb(context, meta));
3639
+ }
3640
+ }
3641
+ }
3642
+
3643
+ void DumpCdsConfig(const EncodingContext& context,
3644
+ const XdsApi::ResourceTypeMetadata& resource_type_metadata,
3645
+ envoy_service_status_v3_PerXdsConfig* per_xds_config) {
3646
+ upb_strview kCdsTypeUrlUpb = upb_strview_makez(XdsApi::kCdsTypeUrl);
3647
+ auto* cluster_config_dump =
3648
+ envoy_service_status_v3_PerXdsConfig_mutable_cluster_config(
3649
+ per_xds_config, context.arena);
3650
+ envoy_admin_v3_ClustersConfigDump_set_version_info(
3651
+ cluster_config_dump,
3652
+ StdStringToUpbString(resource_type_metadata.version));
3653
+ for (auto& p : resource_type_metadata.resource_metadata_map) {
3654
+ absl::string_view name = p.first;
3655
+ const XdsApi::ResourceMetadata* meta = p.second;
3656
+ const upb_strview name_upb = StdStringToUpbString(name);
3657
+ auto* dynamic_cluster =
3658
+ envoy_admin_v3_ClustersConfigDump_add_dynamic_active_clusters(
3659
+ cluster_config_dump, context.arena);
3660
+ envoy_admin_v3_ClustersConfigDump_DynamicCluster_set_client_status(
3661
+ dynamic_cluster, meta->client_status);
3662
+ auto* cluster_any =
3663
+ envoy_admin_v3_ClustersConfigDump_DynamicCluster_mutable_cluster(
3664
+ dynamic_cluster, context.arena);
3665
+ if (!meta->serialized_proto.empty()) {
3666
+ // Set in-effective clusters
3667
+ envoy_admin_v3_ClustersConfigDump_DynamicCluster_set_version_info(
3668
+ dynamic_cluster, StdStringToUpbString(meta->version));
3669
+ envoy_admin_v3_ClustersConfigDump_DynamicCluster_set_last_updated(
3670
+ dynamic_cluster, GrpcMillisToTimestamp(context, meta->update_time));
3671
+ google_protobuf_Any_set_type_url(cluster_any, kCdsTypeUrlUpb);
3672
+ google_protobuf_Any_set_value(
3673
+ cluster_any, StdStringToUpbString(meta->serialized_proto));
3674
+ } else {
3675
+ // If there isn't a working cluster, we still need to print the name.
3676
+ auto* cluster = envoy_config_cluster_v3_Cluster_new(context.arena);
3677
+ envoy_config_cluster_v3_Cluster_set_name(cluster, name_upb);
3678
+ size_t length;
3679
+ char* bytes = envoy_config_cluster_v3_Cluster_serialize(
3680
+ cluster, context.arena, &length);
3681
+ google_protobuf_Any_set_type_url(cluster_any, kCdsTypeUrlUpb);
3682
+ google_protobuf_Any_set_value(cluster_any,
3683
+ upb_strview_make(bytes, length));
3684
+ }
3685
+ if (meta->client_status == XdsApi::ResourceMetadata::NACKED) {
3686
+ // Set error_state if NACKED
3687
+ envoy_admin_v3_ClustersConfigDump_DynamicCluster_set_error_state(
3688
+ dynamic_cluster, CreateUpdateFailureStateUpb(context, meta));
3689
+ }
3690
+ }
3691
+ }
3692
+
3693
+ void DumpEdsConfig(const EncodingContext& context,
3694
+ const XdsApi::ResourceTypeMetadata& resource_type_metadata,
3695
+ envoy_service_status_v3_PerXdsConfig* per_xds_config) {
3696
+ upb_strview kEdsTypeUrlUpb = upb_strview_makez(XdsApi::kEdsTypeUrl);
3697
+ auto* endpoint_config_dump =
3698
+ envoy_service_status_v3_PerXdsConfig_mutable_endpoint_config(
3699
+ per_xds_config, context.arena);
3700
+ for (auto& p : resource_type_metadata.resource_metadata_map) {
3701
+ absl::string_view name = p.first;
3702
+ const XdsApi::ResourceMetadata* meta = p.second;
3703
+ const upb_strview name_upb = StdStringToUpbString(name);
3704
+ auto* dynamic_endpoint =
3705
+ envoy_admin_v3_EndpointsConfigDump_add_dynamic_endpoint_configs(
3706
+ endpoint_config_dump, context.arena);
3707
+ envoy_admin_v3_EndpointsConfigDump_DynamicEndpointConfig_set_client_status(
3708
+ dynamic_endpoint, meta->client_status);
3709
+ auto* endpoint_any =
3710
+ envoy_admin_v3_EndpointsConfigDump_DynamicEndpointConfig_mutable_endpoint_config(
3711
+ dynamic_endpoint, context.arena);
3712
+ if (!meta->serialized_proto.empty()) {
3713
+ // Set in-effective endpoints
3714
+ envoy_admin_v3_EndpointsConfigDump_DynamicEndpointConfig_set_version_info(
3715
+ dynamic_endpoint, StdStringToUpbString(meta->version));
3716
+ envoy_admin_v3_EndpointsConfigDump_DynamicEndpointConfig_set_last_updated(
3717
+ dynamic_endpoint, GrpcMillisToTimestamp(context, meta->update_time));
3718
+ google_protobuf_Any_set_type_url(endpoint_any, kEdsTypeUrlUpb);
3719
+ google_protobuf_Any_set_value(
3720
+ endpoint_any, StdStringToUpbString(meta->serialized_proto));
3721
+ } else {
3722
+ // If there isn't a working endpoint, we still need to print the name.
3723
+ auto* cluster_load_assignment =
3724
+ envoy_config_endpoint_v3_ClusterLoadAssignment_new(context.arena);
3725
+ envoy_config_endpoint_v3_ClusterLoadAssignment_set_cluster_name(
3726
+ cluster_load_assignment, name_upb);
3727
+ size_t length;
3728
+ char* bytes = envoy_config_endpoint_v3_ClusterLoadAssignment_serialize(
3729
+ cluster_load_assignment, context.arena, &length);
3730
+ google_protobuf_Any_set_type_url(endpoint_any, kEdsTypeUrlUpb);
3731
+ google_protobuf_Any_set_value(endpoint_any,
3732
+ upb_strview_make(bytes, length));
3733
+ }
3734
+ if (meta->client_status == XdsApi::ResourceMetadata::NACKED) {
3735
+ // Set error_state if NACKED
3736
+ envoy_admin_v3_EndpointsConfigDump_DynamicEndpointConfig_set_error_state(
3737
+ dynamic_endpoint, CreateUpdateFailureStateUpb(context, meta));
3738
+ }
3739
+ }
3740
+ }
3741
+
3742
+ } // namespace
3743
+
3744
+ std::string XdsApi::AssembleClientConfig(
3745
+ const ResourceTypeMetadataMap& resource_type_metadata_map) {
3746
+ upb::Arena arena;
3747
+ // Create the ClientConfig for resource metadata from XdsClient
3748
+ auto* client_config = envoy_service_status_v3_ClientConfig_new(arena.ptr());
3749
+ // Fill-in the node information
3750
+ auto* node = envoy_service_status_v3_ClientConfig_mutable_node(client_config,
3751
+ arena.ptr());
3752
+ const EncodingContext context = {client_, tracer_, symtab_.ptr(), arena.ptr(),
3753
+ true};
3754
+ PopulateNode(context, node_, build_version_, user_agent_name_, node);
3755
+ // Dump each xDS-type config into PerXdsConfig
3756
+ for (auto& p : resource_type_metadata_map) {
3757
+ absl::string_view type_url = p.first;
3758
+ const ResourceTypeMetadata& resource_type_metadata = p.second;
3759
+ if (type_url == kLdsTypeUrl) {
3760
+ auto* per_xds_config =
3761
+ envoy_service_status_v3_ClientConfig_add_xds_config(client_config,
3762
+ context.arena);
3763
+ DumpLdsConfig(context, resource_type_metadata, per_xds_config);
3764
+ } else if (type_url == kRdsTypeUrl) {
3765
+ auto* per_xds_config =
3766
+ envoy_service_status_v3_ClientConfig_add_xds_config(client_config,
3767
+ context.arena);
3768
+ DumpRdsConfig(context, resource_type_metadata, per_xds_config);
3769
+ } else if (type_url == kCdsTypeUrl) {
3770
+ auto* per_xds_config =
3771
+ envoy_service_status_v3_ClientConfig_add_xds_config(client_config,
3772
+ context.arena);
3773
+ DumpCdsConfig(context, resource_type_metadata, per_xds_config);
3774
+ } else if (type_url == kEdsTypeUrl) {
3775
+ auto* per_xds_config =
3776
+ envoy_service_status_v3_ClientConfig_add_xds_config(client_config,
3777
+ context.arena);
3778
+ DumpEdsConfig(context, resource_type_metadata, per_xds_config);
3779
+ } else {
3780
+ gpr_log(GPR_ERROR, "invalid type_url %s", std::string(type_url).c_str());
3781
+ return "";
3782
+ }
3783
+ }
3784
+ // Serialize the upb message to bytes
3785
+ size_t output_length;
3786
+ char* output = envoy_service_status_v3_ClientConfig_serialize(
3787
+ client_config, arena.ptr(), &output_length);
3788
+ return std::string(output, output_length);
3789
+ }
3790
+
2479
3791
  } // namespace grpc_core