grpc 1.43.1 → 1.44.0.pre2

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

Potentially problematic release.


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

Files changed (382) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +84 -64
  3. data/include/grpc/grpc_security.h +10 -0
  4. data/include/grpc/impl/codegen/compression_types.h +0 -2
  5. data/include/grpc/impl/codegen/grpc_types.h +6 -0
  6. data/src/core/ext/filters/client_channel/backend_metric.h +1 -1
  7. data/src/core/ext/filters/client_channel/client_channel.cc +62 -68
  8. data/src/core/ext/filters/client_channel/client_channel.h +8 -8
  9. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +1 -1
  10. data/src/core/ext/filters/client_channel/config_selector.h +4 -4
  11. data/src/core/ext/filters/client_channel/dynamic_filters.h +1 -1
  12. data/src/core/ext/filters/client_channel/health/health_check_client.cc +16 -14
  13. data/src/core/ext/filters/client_channel/health/health_check_client.h +3 -3
  14. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -1
  15. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +4 -3
  16. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +6 -5
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +3 -7
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +31 -32
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +0 -7
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +1 -1
  21. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +1 -1
  23. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +43 -29
  24. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +6 -2
  25. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +120 -68
  26. data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +60 -48
  27. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +62 -61
  28. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +16 -11
  29. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +11 -5
  30. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +19 -15
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +1 -1
  32. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +14 -12
  33. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +3 -2
  34. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +50 -105
  35. data/src/core/ext/filters/client_channel/lb_policy.cc +15 -14
  36. data/src/core/ext/filters/client_channel/lb_policy.h +19 -3
  37. data/src/core/ext/filters/client_channel/resolver/binder/binder_resolver.cc +3 -3
  38. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +207 -81
  39. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +22 -12
  40. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +19 -15
  41. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +23 -38
  42. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +118 -207
  43. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +25 -32
  44. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +1 -1
  45. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +82 -73
  46. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +10 -10
  47. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +2 -1
  48. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +2 -5
  49. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +5 -5
  50. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +157 -67
  51. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +1 -1
  52. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +2 -2
  53. data/src/core/ext/filters/client_channel/retry_filter.cc +37 -64
  54. data/src/core/ext/filters/client_channel/retry_service_config.cc +1 -1
  55. data/src/core/ext/filters/client_channel/retry_service_config.h +1 -1
  56. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +1 -1
  57. data/src/core/ext/filters/client_channel/subchannel.cc +12 -16
  58. data/src/core/ext/filters/client_channel/subchannel.h +2 -3
  59. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +37 -48
  60. data/src/core/ext/filters/fault_injection/service_config_parser.cc +6 -8
  61. data/src/core/ext/filters/fault_injection/service_config_parser.h +1 -1
  62. data/src/core/ext/filters/http/client/http_client_filter.cc +51 -122
  63. data/src/core/ext/filters/http/client_authority_filter.cc +8 -24
  64. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +42 -140
  65. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +5 -25
  66. data/src/core/ext/filters/http/server/http_server_filter.cc +50 -135
  67. data/src/core/ext/filters/message_size/message_size_filter.cc +1 -1
  68. data/src/core/ext/filters/message_size/message_size_filter.h +1 -1
  69. data/src/core/ext/filters/rbac/rbac_filter.cc +157 -0
  70. data/src/core/ext/filters/rbac/rbac_filter.h +74 -0
  71. data/src/core/ext/filters/rbac/rbac_service_config_parser.cc +605 -0
  72. data/src/core/ext/filters/rbac/rbac_service_config_parser.h +70 -0
  73. data/src/core/ext/filters/server_config_selector/server_config_selector.h +3 -2
  74. data/src/core/ext/filters/server_config_selector/server_config_selector_filter.cc +11 -6
  75. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +1 -1
  76. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +1 -1
  77. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +89 -29
  78. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +0 -1
  79. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +45 -186
  80. data/src/core/ext/transport/chttp2/transport/frame_data.cc +0 -1
  81. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +341 -279
  82. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +69 -159
  83. data/src/core/ext/transport/chttp2/transport/hpack_encoder_table.cc +1 -1
  84. data/src/core/ext/transport/chttp2/transport/hpack_encoder_table.h +2 -0
  85. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +19 -32
  86. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +0 -1
  87. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +94 -1
  88. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +2 -24
  89. data/src/core/ext/transport/chttp2/transport/internal.h +0 -33
  90. data/src/core/ext/transport/chttp2/transport/parsing.cc +0 -6
  91. data/src/core/ext/transport/chttp2/transport/writing.cc +47 -116
  92. data/src/core/ext/transport/inproc/inproc_plugin.cc +0 -4
  93. data/src/core/ext/transport/inproc/inproc_transport.cc +11 -63
  94. data/src/core/ext/transport/inproc/inproc_transport.h +0 -3
  95. data/src/core/ext/upb-generated/envoy/extensions/filters/http/rbac/v3/rbac.upb.c +61 -0
  96. data/src/core/ext/upb-generated/envoy/extensions/filters/http/rbac/v3/rbac.upb.h +146 -0
  97. data/src/core/ext/upbdefs-generated/envoy/config/rbac/v3/rbac.upbdefs.c +188 -0
  98. data/src/core/ext/upbdefs-generated/envoy/config/rbac/v3/rbac.upbdefs.h +70 -0
  99. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/rbac/v3/rbac.upbdefs.c +56 -0
  100. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/rbac/v3/rbac.upbdefs.h +40 -0
  101. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/checked.upbdefs.c +154 -0
  102. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/checked.upbdefs.h +95 -0
  103. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/eval.upbdefs.c +58 -0
  104. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/eval.upbdefs.h +55 -0
  105. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/explain.upbdefs.c +44 -0
  106. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/explain.upbdefs.h +40 -0
  107. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/syntax.upbdefs.c +153 -0
  108. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/syntax.upbdefs.h +100 -0
  109. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/value.upbdefs.c +75 -0
  110. data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/value.upbdefs.h +55 -0
  111. data/src/core/ext/xds/upb_utils.h +65 -0
  112. data/src/core/ext/xds/xds_api.cc +81 -3458
  113. data/src/core/ext/xds/xds_api.h +56 -611
  114. data/src/core/ext/xds/xds_bootstrap.cc +189 -125
  115. data/src/core/ext/xds/xds_bootstrap.h +20 -15
  116. data/src/core/ext/xds/xds_certificate_provider.h +1 -0
  117. data/src/core/ext/xds/xds_channel_creds.cc +108 -0
  118. data/src/core/ext/xds/xds_channel_creds.h +50 -0
  119. data/src/core/ext/xds/xds_client.cc +584 -994
  120. data/src/core/ext/xds/xds_client.h +78 -135
  121. data/src/core/ext/xds/xds_cluster.cc +451 -0
  122. data/src/core/ext/xds/xds_cluster.h +111 -0
  123. data/src/core/ext/xds/xds_common_types.cc +388 -0
  124. data/src/core/ext/xds/xds_common_types.h +110 -0
  125. data/src/core/ext/xds/xds_endpoint.cc +364 -0
  126. data/src/core/ext/xds/xds_endpoint.h +135 -0
  127. data/src/core/ext/xds/xds_http_filters.cc +5 -0
  128. data/src/core/ext/xds/xds_http_rbac_filter.cc +563 -0
  129. data/src/core/ext/xds/xds_http_rbac_filter.h +54 -0
  130. data/src/core/ext/xds/xds_listener.cc +1036 -0
  131. data/src/core/ext/xds/xds_listener.h +220 -0
  132. data/src/core/ext/{transport/chttp2/transport/hpack_utils.h → xds/xds_resource_type.cc} +12 -9
  133. data/src/core/ext/xds/xds_resource_type.h +98 -0
  134. data/src/core/ext/xds/xds_resource_type_impl.h +87 -0
  135. data/src/core/ext/xds/xds_route_config.cc +993 -0
  136. data/src/core/ext/xds/xds_route_config.h +215 -0
  137. data/src/core/ext/xds/xds_routing.cc +11 -8
  138. data/src/core/ext/xds/xds_routing.h +8 -5
  139. data/src/core/ext/xds/xds_server_config_fetcher.cc +159 -99
  140. data/src/core/lib/address_utils/parse_address.cc +20 -0
  141. data/src/core/lib/address_utils/parse_address.h +5 -0
  142. data/src/core/lib/address_utils/sockaddr_utils.cc +33 -36
  143. data/src/core/lib/address_utils/sockaddr_utils.h +1 -16
  144. data/src/core/lib/backoff/backoff.cc +4 -30
  145. data/src/core/lib/backoff/backoff.h +3 -3
  146. data/src/core/lib/channel/channel_args.cc +0 -1
  147. data/src/core/lib/channel/channel_stack.cc +8 -0
  148. data/src/core/lib/channel/channel_stack.h +1 -1
  149. data/src/core/lib/channel/channel_stack_builder.cc +5 -9
  150. data/src/core/lib/channel/channel_stack_builder.h +4 -7
  151. data/src/core/lib/channel/channelz.cc +1 -0
  152. data/src/core/lib/compression/compression.cc +19 -111
  153. data/src/core/lib/compression/compression_internal.cc +142 -202
  154. data/src/core/lib/compression/compression_internal.h +64 -69
  155. data/src/core/lib/compression/message_compress.cc +11 -11
  156. data/src/core/lib/compression/message_compress.h +2 -2
  157. data/src/core/lib/gpr/useful.h +4 -0
  158. data/src/core/lib/gprpp/bitset.h +7 -0
  159. data/src/core/lib/gprpp/chunked_vector.h +45 -3
  160. data/src/core/lib/gprpp/status_helper.cc +20 -28
  161. data/src/core/lib/gprpp/status_helper.h +6 -19
  162. data/src/core/lib/gprpp/table.h +11 -0
  163. data/src/core/lib/http/httpcli.cc +37 -46
  164. data/src/core/lib/http/httpcli.h +3 -15
  165. data/src/core/lib/iomgr/call_combiner.cc +15 -4
  166. data/src/core/lib/iomgr/closure.h +29 -9
  167. data/src/core/lib/iomgr/combiner.cc +25 -3
  168. data/src/core/lib/iomgr/error.cc +2 -0
  169. data/src/core/lib/iomgr/error.h +3 -0
  170. data/src/core/lib/iomgr/event_engine/iomgr.cc +3 -2
  171. data/src/core/lib/iomgr/event_engine/resolved_address_internal.cc +6 -0
  172. data/src/core/lib/iomgr/event_engine/resolved_address_internal.h +2 -0
  173. data/src/core/lib/iomgr/event_engine/resolver.cc +66 -48
  174. data/src/core/lib/iomgr/event_engine/resolver.h +56 -0
  175. data/src/core/lib/iomgr/exec_ctx.cc +22 -9
  176. data/src/core/lib/iomgr/executor.cc +10 -1
  177. data/src/core/lib/iomgr/fork_posix.cc +3 -2
  178. data/src/core/lib/iomgr/iomgr_custom.cc +4 -1
  179. data/src/core/lib/iomgr/iomgr_posix.cc +2 -2
  180. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +2 -2
  181. data/src/core/lib/iomgr/iomgr_windows.cc +2 -2
  182. data/src/core/lib/iomgr/port.h +2 -2
  183. data/src/core/lib/iomgr/resolve_address.cc +5 -24
  184. data/src/core/lib/iomgr/resolve_address.h +47 -44
  185. data/src/core/lib/iomgr/resolve_address_custom.cc +131 -109
  186. data/src/core/lib/iomgr/resolve_address_custom.h +101 -19
  187. data/src/core/lib/iomgr/resolve_address_impl.h +59 -0
  188. data/src/core/lib/iomgr/resolve_address_posix.cc +82 -66
  189. data/src/core/lib/iomgr/resolve_address_posix.h +47 -0
  190. data/src/core/lib/iomgr/resolve_address_windows.cc +93 -74
  191. data/src/core/lib/iomgr/resolve_address_windows.h +47 -0
  192. data/src/core/lib/iomgr/resolved_address.h +39 -0
  193. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +1 -0
  194. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +1 -0
  195. data/src/core/lib/iomgr/unix_sockets_posix.cc +22 -34
  196. data/src/core/lib/iomgr/unix_sockets_posix.h +4 -7
  197. data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +6 -15
  198. data/src/core/lib/matchers/matchers.cc +1 -1
  199. data/src/core/lib/promise/activity.h +49 -20
  200. data/src/core/lib/promise/detail/status.h +5 -0
  201. data/src/core/{ext/filters/client_channel → lib/resolver}/resolver.cc +17 -25
  202. data/src/core/{ext/filters/client_channel → lib/resolver}/resolver.h +43 -44
  203. data/src/core/{ext/filters/client_channel → lib/resolver}/resolver_factory.h +10 -5
  204. data/src/core/{ext/filters/client_channel → lib/resolver}/resolver_registry.cc +3 -2
  205. data/src/core/{ext/filters/client_channel → lib/resolver}/resolver_registry.h +4 -5
  206. data/src/core/{ext/filters/client_channel → lib/resolver}/server_address.cc +1 -1
  207. data/src/core/{ext/filters/client_channel → lib/resolver}/server_address.h +4 -4
  208. data/src/core/lib/resource_quota/api.h +0 -1
  209. data/src/core/lib/{gprpp → resource_quota}/arena.cc +16 -13
  210. data/src/core/lib/{gprpp → resource_quota}/arena.h +24 -13
  211. data/src/core/lib/security/authorization/evaluate_args.cc +30 -15
  212. data/src/core/lib/security/authorization/evaluate_args.h +1 -0
  213. data/src/core/lib/security/authorization/grpc_authorization_engine.cc +60 -0
  214. data/src/core/lib/security/authorization/grpc_authorization_engine.h +62 -0
  215. data/src/core/lib/security/authorization/matchers.cc +227 -0
  216. data/src/core/lib/security/authorization/matchers.h +211 -0
  217. data/src/core/lib/security/authorization/rbac_policy.cc +442 -0
  218. data/src/core/lib/security/authorization/rbac_policy.h +170 -0
  219. data/src/core/lib/security/context/security_context.cc +4 -2
  220. data/src/core/lib/security/context/security_context.h +1 -1
  221. data/src/core/lib/security/credentials/composite/composite_credentials.cc +5 -5
  222. data/src/core/lib/security/credentials/composite/composite_credentials.h +4 -3
  223. data/src/core/lib/security/credentials/credentials.h +10 -20
  224. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +6 -9
  225. data/src/core/lib/security/credentials/external/external_account_credentials.cc +7 -9
  226. data/src/core/lib/security/credentials/external/external_account_credentials.h +2 -7
  227. data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +2 -3
  228. data/src/core/lib/security/credentials/fake/fake_credentials.cc +5 -4
  229. data/src/core/lib/security/credentials/fake/fake_credentials.h +8 -7
  230. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +2 -5
  231. data/src/core/lib/security/credentials/iam/iam_credentials.cc +16 -19
  232. data/src/core/lib/security/credentials/iam/iam_credentials.h +6 -5
  233. data/src/core/lib/security/credentials/jwt/json_token.cc +4 -6
  234. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +16 -28
  235. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +8 -8
  236. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +6 -13
  237. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +44 -57
  238. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +13 -15
  239. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -7
  240. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +5 -4
  241. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +1 -10
  242. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +6 -0
  243. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +7 -0
  244. data/src/core/lib/security/credentials/xds/xds_credentials.h +1 -1
  245. data/src/core/lib/security/security_connector/security_connector.cc +0 -4
  246. data/src/core/lib/security/security_connector/security_connector.h +5 -1
  247. data/src/core/lib/security/security_connector/ssl_utils.cc +14 -24
  248. data/src/core/lib/security/security_connector/ssl_utils.h +5 -14
  249. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +2 -3
  250. data/src/core/lib/security/transport/auth_filters.h +7 -0
  251. data/src/core/lib/security/transport/client_auth_filter.cc +53 -33
  252. data/src/core/lib/security/transport/server_auth_filter.cc +40 -35
  253. data/src/core/{ext → lib}/service_config/service_config.cc +2 -2
  254. data/src/core/{ext → lib}/service_config/service_config.h +4 -4
  255. data/src/core/{ext → lib}/service_config/service_config_call_data.h +5 -5
  256. data/src/core/{ext → lib}/service_config/service_config_parser.cc +1 -1
  257. data/src/core/{ext → lib}/service_config/service_config_parser.h +3 -3
  258. data/src/core/lib/slice/slice.cc +3 -1
  259. data/src/core/lib/slice/slice.h +43 -13
  260. data/src/core/lib/slice/slice_intern.cc +3 -101
  261. data/src/core/lib/slice/slice_internal.h +1 -2
  262. data/src/core/lib/slice/slice_refcount.h +4 -13
  263. data/src/core/lib/slice/slice_refcount_base.h +0 -16
  264. data/src/core/lib/surface/call.cc +140 -382
  265. data/src/core/lib/surface/call.h +4 -4
  266. data/src/core/lib/surface/channel.cc +42 -44
  267. data/src/core/lib/surface/channel.h +4 -4
  268. data/src/core/lib/surface/init.cc +0 -2
  269. data/src/core/lib/surface/lame_client.cc +0 -1
  270. data/src/core/lib/surface/server.cc +12 -29
  271. data/src/core/lib/surface/server.h +2 -2
  272. data/src/core/lib/surface/version.cc +2 -2
  273. data/src/core/lib/transport/error_utils.h +14 -0
  274. data/src/core/lib/transport/metadata_batch.h +799 -717
  275. data/src/core/lib/transport/parsed_metadata.cc +2 -0
  276. data/src/core/lib/transport/parsed_metadata.h +95 -92
  277. data/src/core/lib/transport/timeout_encoding.cc +200 -66
  278. data/src/core/lib/transport/timeout_encoding.h +40 -10
  279. data/src/core/lib/transport/transport.h +1 -1
  280. data/src/core/lib/transport/transport_op_string.cc +6 -39
  281. data/src/core/lib/uri/uri_parser.cc +223 -53
  282. data/src/core/lib/uri/uri_parser.h +36 -23
  283. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -3
  284. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +1 -1
  285. data/src/core/tsi/ssl/session_cache/ssl_session.h +2 -4
  286. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +3 -5
  287. data/src/core/tsi/ssl_transport_security.cc +53 -13
  288. data/src/core/tsi/ssl_transport_security.h +18 -6
  289. data/src/ruby/ext/grpc/extconf.rb +10 -3
  290. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  291. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +3 -0
  292. data/src/ruby/lib/grpc/version.rb +1 -1
  293. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +2 -1
  294. data/third_party/abseil-cpp/absl/base/internal/fast_type_id.h +48 -0
  295. data/third_party/abseil-cpp/absl/random/bernoulli_distribution.h +200 -0
  296. data/third_party/abseil-cpp/absl/random/beta_distribution.h +427 -0
  297. data/third_party/abseil-cpp/absl/random/discrete_distribution.cc +98 -0
  298. data/third_party/abseil-cpp/absl/random/discrete_distribution.h +247 -0
  299. data/third_party/abseil-cpp/absl/random/distributions.h +452 -0
  300. data/third_party/abseil-cpp/absl/random/exponential_distribution.h +165 -0
  301. data/third_party/abseil-cpp/absl/random/gaussian_distribution.cc +104 -0
  302. data/third_party/abseil-cpp/absl/random/gaussian_distribution.h +275 -0
  303. data/third_party/abseil-cpp/absl/random/internal/distribution_caller.h +92 -0
  304. data/third_party/abseil-cpp/absl/random/internal/fast_uniform_bits.h +268 -0
  305. data/third_party/abseil-cpp/absl/random/internal/fastmath.h +57 -0
  306. data/third_party/abseil-cpp/absl/random/internal/generate_real.h +144 -0
  307. data/third_party/abseil-cpp/absl/random/internal/iostream_state_saver.h +245 -0
  308. data/third_party/abseil-cpp/absl/random/internal/nonsecure_base.h +150 -0
  309. data/third_party/abseil-cpp/absl/random/internal/pcg_engine.h +308 -0
  310. data/third_party/abseil-cpp/absl/random/internal/platform.h +171 -0
  311. data/third_party/abseil-cpp/absl/random/internal/pool_urbg.cc +253 -0
  312. data/third_party/abseil-cpp/absl/random/internal/pool_urbg.h +131 -0
  313. data/third_party/abseil-cpp/absl/random/internal/randen.cc +91 -0
  314. data/third_party/abseil-cpp/absl/random/internal/randen.h +102 -0
  315. data/third_party/abseil-cpp/absl/random/internal/randen_detect.cc +221 -0
  316. data/third_party/abseil-cpp/absl/random/internal/randen_detect.h +33 -0
  317. data/third_party/abseil-cpp/absl/random/internal/randen_engine.h +239 -0
  318. data/third_party/abseil-cpp/absl/random/internal/randen_hwaes.cc +526 -0
  319. data/third_party/abseil-cpp/absl/random/internal/randen_hwaes.h +50 -0
  320. data/third_party/abseil-cpp/absl/random/internal/randen_round_keys.cc +462 -0
  321. data/third_party/abseil-cpp/absl/random/internal/randen_slow.cc +471 -0
  322. data/third_party/abseil-cpp/absl/random/internal/randen_slow.h +40 -0
  323. data/third_party/abseil-cpp/absl/random/internal/randen_traits.h +88 -0
  324. data/third_party/abseil-cpp/absl/random/internal/salted_seed_seq.h +167 -0
  325. data/third_party/abseil-cpp/absl/random/internal/seed_material.cc +267 -0
  326. data/third_party/abseil-cpp/absl/random/internal/seed_material.h +104 -0
  327. data/third_party/abseil-cpp/absl/random/internal/traits.h +101 -0
  328. data/third_party/abseil-cpp/absl/random/internal/uniform_helper.h +244 -0
  329. data/third_party/abseil-cpp/absl/random/internal/wide_multiply.h +111 -0
  330. data/third_party/abseil-cpp/absl/random/log_uniform_int_distribution.h +257 -0
  331. data/third_party/abseil-cpp/absl/random/poisson_distribution.h +258 -0
  332. data/third_party/abseil-cpp/absl/random/random.h +189 -0
  333. data/third_party/abseil-cpp/absl/random/seed_gen_exception.cc +46 -0
  334. data/third_party/abseil-cpp/absl/random/seed_gen_exception.h +55 -0
  335. data/third_party/abseil-cpp/absl/random/seed_sequences.cc +29 -0
  336. data/third_party/abseil-cpp/absl/random/seed_sequences.h +110 -0
  337. data/third_party/abseil-cpp/absl/random/uniform_int_distribution.h +275 -0
  338. data/third_party/abseil-cpp/absl/random/uniform_real_distribution.h +202 -0
  339. data/third_party/abseil-cpp/absl/random/zipf_distribution.h +271 -0
  340. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_enc.c +1 -0
  341. data/third_party/boringssl-with-bazel/src/crypto/base64/base64.c +13 -0
  342. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +21 -0
  343. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/cipher.c +12 -0
  344. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/ecdsa.c +1 -2
  345. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +2 -2
  346. data/third_party/boringssl-with-bazel/src/crypto/mem.c +1 -1
  347. data/third_party/boringssl-with-bazel/src/crypto/pkcs7/pkcs7.c +29 -0
  348. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/internal.h +0 -1
  349. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8.c +1 -1
  350. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8_x509.c +1 -1
  351. data/third_party/boringssl-with-bazel/src/include/openssl/base64.h +8 -0
  352. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +13 -1
  353. data/third_party/boringssl-with-bazel/src/include/openssl/dsa.h +10 -0
  354. data/third_party/boringssl-with-bazel/src/include/openssl/hpke.h +1 -1
  355. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs7.h +9 -4
  356. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs8.h +6 -1
  357. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +23 -2
  358. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +4 -0
  359. data/third_party/xxhash/xxhash.h +607 -352
  360. metadata +149 -77
  361. data/src/core/ext/transport/chttp2/transport/hpack_encoder_index.h +0 -107
  362. data/src/core/ext/transport/chttp2/transport/hpack_utils.cc +0 -46
  363. data/src/core/ext/transport/chttp2/transport/popularity_count.h +0 -60
  364. data/src/core/lib/compression/algorithm_metadata.h +0 -62
  365. data/src/core/lib/compression/compression_args.cc +0 -140
  366. data/src/core/lib/compression/compression_args.h +0 -58
  367. data/src/core/lib/compression/stream_compression.cc +0 -81
  368. data/src/core/lib/compression/stream_compression.h +0 -117
  369. data/src/core/lib/compression/stream_compression_gzip.cc +0 -231
  370. data/src/core/lib/compression/stream_compression_gzip.h +0 -28
  371. data/src/core/lib/compression/stream_compression_identity.cc +0 -91
  372. data/src/core/lib/compression/stream_compression_identity.h +0 -29
  373. data/src/core/lib/security/credentials/credentials_metadata.cc +0 -61
  374. data/src/core/lib/slice/static_slice.cc +0 -377
  375. data/src/core/lib/slice/static_slice.h +0 -300
  376. data/src/core/lib/transport/metadata.cc +0 -714
  377. data/src/core/lib/transport/metadata.h +0 -449
  378. data/src/core/lib/transport/metadata_batch.cc +0 -99
  379. data/src/core/lib/transport/static_metadata.cc +0 -1032
  380. data/src/core/lib/transport/static_metadata.h +0 -322
  381. data/src/core/lib/transport/status_metadata.cc +0 -63
  382. data/src/core/lib/transport/status_metadata.h +0 -48
@@ -0,0 +1,1036 @@
1
+ //
2
+ // Copyright 2018 gRPC authors.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ //
16
+
17
+ #include <grpc/support/port_platform.h>
18
+
19
+ #include "src/core/ext/xds/xds_listener.h"
20
+
21
+ #include "absl/strings/str_cat.h"
22
+ #include "absl/strings/str_format.h"
23
+ #include "absl/strings/str_join.h"
24
+ #include "absl/strings/str_split.h"
25
+ #include "envoy/config/core/v3/address.upb.h"
26
+ #include "envoy/config/core/v3/base.upb.h"
27
+ #include "envoy/config/core/v3/config_source.upb.h"
28
+ #include "envoy/config/core/v3/protocol.upb.h"
29
+ #include "envoy/config/listener/v3/api_listener.upb.h"
30
+ #include "envoy/config/listener/v3/listener.upb.h"
31
+ #include "envoy/config/listener/v3/listener.upbdefs.h"
32
+ #include "envoy/config/listener/v3/listener_components.upb.h"
33
+ #include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h"
34
+ #include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h"
35
+ #include "google/protobuf/wrappers.upb.h"
36
+ #include "upb/text_encode.h"
37
+ #include "upb/upb.h"
38
+ #include "upb/upb.hpp"
39
+
40
+ #include "src/core/lib/address_utils/parse_address.h"
41
+ #include "src/core/lib/address_utils/sockaddr_utils.h"
42
+ #include "src/core/lib/gprpp/host_port.h"
43
+ #include "src/core/lib/iomgr/sockaddr.h"
44
+
45
+ namespace grpc_core {
46
+
47
+ //
48
+ // XdsListenerResource::DownstreamTlsContext
49
+ //
50
+
51
+ std::string XdsListenerResource::DownstreamTlsContext::ToString() const {
52
+ return absl::StrFormat("common_tls_context=%s, require_client_certificate=%s",
53
+ common_tls_context.ToString(),
54
+ require_client_certificate ? "true" : "false");
55
+ }
56
+
57
+ bool XdsListenerResource::DownstreamTlsContext::Empty() const {
58
+ return common_tls_context.Empty();
59
+ }
60
+
61
+ //
62
+ // XdsListenerResource::HttpConnectionManager
63
+ //
64
+
65
+ std::string XdsListenerResource::HttpConnectionManager::ToString() const {
66
+ absl::InlinedVector<std::string, 4> contents;
67
+ contents.push_back(absl::StrFormat(
68
+ "route_config_name=%s",
69
+ !route_config_name.empty() ? route_config_name.c_str() : "<inlined>"));
70
+ contents.push_back(absl::StrFormat("http_max_stream_duration=%s",
71
+ http_max_stream_duration.ToString()));
72
+ if (rds_update.has_value()) {
73
+ contents.push_back(
74
+ absl::StrFormat("rds_update=%s", rds_update->ToString()));
75
+ }
76
+ if (!http_filters.empty()) {
77
+ std::vector<std::string> filter_strings;
78
+ for (const auto& http_filter : http_filters) {
79
+ filter_strings.push_back(http_filter.ToString());
80
+ }
81
+ contents.push_back(absl::StrCat("http_filters=[",
82
+ absl::StrJoin(filter_strings, ", "), "]"));
83
+ }
84
+ return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
85
+ }
86
+
87
+ //
88
+ // XdsListenerResource::HttpFilter
89
+ //
90
+
91
+ std::string XdsListenerResource::HttpConnectionManager::HttpFilter::ToString()
92
+ const {
93
+ return absl::StrCat("{name=", name, ", config=", config.ToString(), "}");
94
+ }
95
+
96
+ //
97
+ // XdsListenerResource::FilterChainData
98
+ //
99
+
100
+ std::string XdsListenerResource::FilterChainData::ToString() const {
101
+ return absl::StrCat(
102
+ "{downstream_tls_context=", downstream_tls_context.ToString(),
103
+ " http_connection_manager=", http_connection_manager.ToString(), "}");
104
+ }
105
+
106
+ //
107
+ // XdsListenerResource::FilterChainMap::CidrRange
108
+ //
109
+
110
+ std::string XdsListenerResource::FilterChainMap::CidrRange::ToString() const {
111
+ return absl::StrCat(
112
+ "{address_prefix=", grpc_sockaddr_to_string(&address, false),
113
+ ", prefix_len=", prefix_len, "}");
114
+ }
115
+
116
+ //
117
+ // FilterChain
118
+ //
119
+
120
+ struct FilterChain {
121
+ struct FilterChainMatch {
122
+ uint32_t destination_port = 0;
123
+ std::vector<XdsListenerResource::FilterChainMap::CidrRange> prefix_ranges;
124
+ XdsListenerResource::FilterChainMap::ConnectionSourceType source_type =
125
+ XdsListenerResource::FilterChainMap::ConnectionSourceType::kAny;
126
+ std::vector<XdsListenerResource::FilterChainMap::CidrRange>
127
+ source_prefix_ranges;
128
+ std::vector<uint32_t> source_ports;
129
+ std::vector<std::string> server_names;
130
+ std::string transport_protocol;
131
+ std::vector<std::string> application_protocols;
132
+
133
+ std::string ToString() const;
134
+ } filter_chain_match;
135
+
136
+ std::shared_ptr<XdsListenerResource::FilterChainData> filter_chain_data;
137
+ };
138
+
139
+ std::string FilterChain::FilterChainMatch::ToString() const {
140
+ absl::InlinedVector<std::string, 8> contents;
141
+ if (destination_port != 0) {
142
+ contents.push_back(absl::StrCat("destination_port=", destination_port));
143
+ }
144
+ if (!prefix_ranges.empty()) {
145
+ std::vector<std::string> prefix_ranges_content;
146
+ for (const auto& range : prefix_ranges) {
147
+ prefix_ranges_content.push_back(range.ToString());
148
+ }
149
+ contents.push_back(absl::StrCat(
150
+ "prefix_ranges={", absl::StrJoin(prefix_ranges_content, ", "), "}"));
151
+ }
152
+ if (source_type == XdsListenerResource::FilterChainMap::ConnectionSourceType::
153
+ kSameIpOrLoopback) {
154
+ contents.push_back("source_type=SAME_IP_OR_LOOPBACK");
155
+ } else if (source_type == XdsListenerResource::FilterChainMap::
156
+ ConnectionSourceType::kExternal) {
157
+ contents.push_back("source_type=EXTERNAL");
158
+ }
159
+ if (!source_prefix_ranges.empty()) {
160
+ std::vector<std::string> source_prefix_ranges_content;
161
+ for (const auto& range : source_prefix_ranges) {
162
+ source_prefix_ranges_content.push_back(range.ToString());
163
+ }
164
+ contents.push_back(
165
+ absl::StrCat("source_prefix_ranges={",
166
+ absl::StrJoin(source_prefix_ranges_content, ", "), "}"));
167
+ }
168
+ if (!source_ports.empty()) {
169
+ contents.push_back(
170
+ absl::StrCat("source_ports={", absl::StrJoin(source_ports, ", "), "}"));
171
+ }
172
+ if (!server_names.empty()) {
173
+ contents.push_back(
174
+ absl::StrCat("server_names={", absl::StrJoin(server_names, ", "), "}"));
175
+ }
176
+ if (!transport_protocol.empty()) {
177
+ contents.push_back(absl::StrCat("transport_protocol=", transport_protocol));
178
+ }
179
+ if (!application_protocols.empty()) {
180
+ contents.push_back(absl::StrCat("application_protocols={",
181
+ absl::StrJoin(application_protocols, ", "),
182
+ "}"));
183
+ }
184
+ return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
185
+ }
186
+
187
+ //
188
+ // XdsListenerResource::FilterChainMap
189
+ //
190
+
191
+ std::string XdsListenerResource::FilterChainMap::ToString() const {
192
+ std::vector<std::string> contents;
193
+ for (const auto& destination_ip : destination_ip_vector) {
194
+ for (int source_type = 0; source_type < 3; ++source_type) {
195
+ for (const auto& source_ip :
196
+ destination_ip.source_types_array[source_type]) {
197
+ for (const auto& source_port_pair : source_ip.ports_map) {
198
+ FilterChain::FilterChainMatch filter_chain_match;
199
+ if (destination_ip.prefix_range.has_value()) {
200
+ filter_chain_match.prefix_ranges.push_back(
201
+ *destination_ip.prefix_range);
202
+ }
203
+ filter_chain_match.source_type = static_cast<
204
+ XdsListenerResource::FilterChainMap::ConnectionSourceType>(
205
+ source_type);
206
+ if (source_ip.prefix_range.has_value()) {
207
+ filter_chain_match.source_prefix_ranges.push_back(
208
+ *source_ip.prefix_range);
209
+ }
210
+ if (source_port_pair.first != 0) {
211
+ filter_chain_match.source_ports.push_back(source_port_pair.first);
212
+ }
213
+ contents.push_back(absl::StrCat(
214
+ "{filter_chain_match=", filter_chain_match.ToString(),
215
+ ", filter_chain=", source_port_pair.second.data->ToString(),
216
+ "}"));
217
+ }
218
+ }
219
+ }
220
+ }
221
+ return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
222
+ }
223
+
224
+ //
225
+ // XdsListenerResource
226
+ //
227
+
228
+ std::string XdsListenerResource::ToString() const {
229
+ absl::InlinedVector<std::string, 4> contents;
230
+ if (type == ListenerType::kTcpListener) {
231
+ contents.push_back(absl::StrCat("address=", address));
232
+ contents.push_back(
233
+ absl::StrCat("filter_chain_map=", filter_chain_map.ToString()));
234
+ if (default_filter_chain.has_value()) {
235
+ contents.push_back(absl::StrCat("default_filter_chain=",
236
+ default_filter_chain->ToString()));
237
+ }
238
+ } else if (type == ListenerType::kHttpApiListener) {
239
+ contents.push_back(absl::StrFormat("http_connection_manager=%s",
240
+ http_connection_manager.ToString()));
241
+ }
242
+ return absl::StrCat("{", absl::StrJoin(contents, ", "), "}");
243
+ }
244
+
245
+ //
246
+ // XdsListenerResourceType
247
+ //
248
+
249
+ namespace {
250
+
251
+ void MaybeLogHttpConnectionManager(
252
+ const XdsEncodingContext& context,
253
+ const envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager*
254
+ http_connection_manager_config) {
255
+ if (GRPC_TRACE_FLAG_ENABLED(*context.tracer) &&
256
+ gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
257
+ const upb_msgdef* msg_type =
258
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_getmsgdef(
259
+ context.symtab);
260
+ char buf[10240];
261
+ upb_text_encode(http_connection_manager_config, msg_type, nullptr, 0, buf,
262
+ sizeof(buf));
263
+ gpr_log(GPR_DEBUG, "[xds_client %p] HttpConnectionManager: %s",
264
+ context.client, buf);
265
+ }
266
+ }
267
+
268
+ grpc_error_handle HttpConnectionManagerParse(
269
+ bool is_client, const XdsEncodingContext& context,
270
+ const envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager*
271
+ http_connection_manager_proto,
272
+ bool is_v2,
273
+ XdsListenerResource::HttpConnectionManager* http_connection_manager) {
274
+ MaybeLogHttpConnectionManager(context, http_connection_manager_proto);
275
+ // NACK a non-zero `xff_num_trusted_hops` and a `non-empty
276
+ // original_ip_detection_extensions` as mentioned in
277
+ // https://github.com/grpc/proposal/blob/master/A41-xds-rbac.md
278
+ if (envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_xff_num_trusted_hops(
279
+ http_connection_manager_proto) != 0) {
280
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
281
+ "'xff_num_trusted_hops' must be zero");
282
+ }
283
+ if (envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_has_original_ip_detection_extensions(
284
+ http_connection_manager_proto)) {
285
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
286
+ "'original_ip_detection_extensions' must be empty");
287
+ }
288
+ // Obtain max_stream_duration from Http Protocol Options.
289
+ const envoy_config_core_v3_HttpProtocolOptions* options =
290
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_common_http_protocol_options(
291
+ http_connection_manager_proto);
292
+ if (options != nullptr) {
293
+ const google_protobuf_Duration* duration =
294
+ envoy_config_core_v3_HttpProtocolOptions_max_stream_duration(options);
295
+ if (duration != nullptr) {
296
+ http_connection_manager->http_max_stream_duration =
297
+ Duration::Parse(duration);
298
+ }
299
+ }
300
+ // Parse filters.
301
+ if (!is_v2) {
302
+ size_t num_filters = 0;
303
+ const auto* http_filters =
304
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_http_filters(
305
+ http_connection_manager_proto, &num_filters);
306
+ std::set<absl::string_view> names_seen;
307
+ for (size_t i = 0; i < num_filters; ++i) {
308
+ const auto* http_filter = http_filters[i];
309
+ absl::string_view name = UpbStringToAbsl(
310
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpFilter_name(
311
+ http_filter));
312
+ if (name.empty()) {
313
+ return GRPC_ERROR_CREATE_FROM_CPP_STRING(
314
+ absl::StrCat("empty filter name at index ", i));
315
+ }
316
+ if (names_seen.find(name) != names_seen.end()) {
317
+ return GRPC_ERROR_CREATE_FROM_CPP_STRING(
318
+ absl::StrCat("duplicate HTTP filter name: ", name));
319
+ }
320
+ names_seen.insert(name);
321
+ const bool is_optional =
322
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpFilter_is_optional(
323
+ http_filter);
324
+ const google_protobuf_Any* any =
325
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpFilter_typed_config(
326
+ http_filter);
327
+ if (any == nullptr) {
328
+ if (is_optional) continue;
329
+ return GRPC_ERROR_CREATE_FROM_CPP_STRING(
330
+ absl::StrCat("no filter config specified for filter name ", name));
331
+ }
332
+ absl::string_view filter_type;
333
+ grpc_error_handle error =
334
+ ExtractHttpFilterTypeName(context, any, &filter_type);
335
+ if (error != GRPC_ERROR_NONE) return error;
336
+ const XdsHttpFilterImpl* filter_impl =
337
+ XdsHttpFilterRegistry::GetFilterForType(filter_type);
338
+ if (filter_impl == nullptr) {
339
+ if (is_optional) continue;
340
+ return GRPC_ERROR_CREATE_FROM_CPP_STRING(
341
+ absl::StrCat("no filter registered for config type ", filter_type));
342
+ }
343
+ if ((is_client && !filter_impl->IsSupportedOnClients()) ||
344
+ (!is_client && !filter_impl->IsSupportedOnServers())) {
345
+ if (is_optional) continue;
346
+ return GRPC_ERROR_CREATE_FROM_CPP_STRING(
347
+ absl::StrFormat("Filter %s is not supported on %s", filter_type,
348
+ is_client ? "clients" : "servers"));
349
+ }
350
+ absl::StatusOr<XdsHttpFilterImpl::FilterConfig> filter_config =
351
+ filter_impl->GenerateFilterConfig(google_protobuf_Any_value(any),
352
+ context.arena);
353
+ if (!filter_config.ok()) {
354
+ return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat(
355
+ "filter config for type ", filter_type,
356
+ " failed to parse: ", StatusToString(filter_config.status())));
357
+ }
358
+ http_connection_manager->http_filters.emplace_back(
359
+ XdsListenerResource::HttpConnectionManager::HttpFilter{
360
+ std::string(name), std::move(*filter_config)});
361
+ }
362
+ if (http_connection_manager->http_filters.empty()) {
363
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
364
+ "Expected at least one HTTP filter");
365
+ }
366
+ // Make sure that the last filter is terminal and non-last filters are
367
+ // non-terminal. Note that this check is being performed in a separate loop
368
+ // to take care of the case where there are two terminal filters in the list
369
+ // out of which only one gets added in the final list.
370
+ for (const auto& http_filter : http_connection_manager->http_filters) {
371
+ const XdsHttpFilterImpl* filter_impl =
372
+ XdsHttpFilterRegistry::GetFilterForType(
373
+ http_filter.config.config_proto_type_name);
374
+ if (&http_filter != &http_connection_manager->http_filters.back()) {
375
+ // Filters before the last filter must not be terminal.
376
+ if (filter_impl->IsTerminalFilter()) {
377
+ return GRPC_ERROR_CREATE_FROM_CPP_STRING(
378
+ absl::StrCat("terminal filter for config type ",
379
+ http_filter.config.config_proto_type_name,
380
+ " must be the last filter in the chain"));
381
+ }
382
+ } else {
383
+ // The last filter must be terminal.
384
+ if (!filter_impl->IsTerminalFilter()) {
385
+ return GRPC_ERROR_CREATE_FROM_CPP_STRING(
386
+ absl::StrCat("non-terminal filter for config type ",
387
+ http_filter.config.config_proto_type_name,
388
+ " is the last filter in the chain"));
389
+ }
390
+ }
391
+ }
392
+ } else {
393
+ // If using a v2 config, we just hard-code a list containing only the
394
+ // router filter without actually looking at the config. This ensures
395
+ // that the right thing happens in the xds resolver without having
396
+ // to expose whether the resource we received was v2 or v3.
397
+ http_connection_manager->http_filters.emplace_back(
398
+ XdsListenerResource::HttpConnectionManager::HttpFilter{
399
+ "router", {kXdsHttpRouterFilterConfigName, Json()}});
400
+ }
401
+ // Guarding parsing of RouteConfig on the server side with the environmental
402
+ // variable since that's the first feature on the server side that will be
403
+ // using this.
404
+ if (is_client || XdsRbacEnabled()) {
405
+ // Found inlined route_config. Parse it to find the cluster_name.
406
+ if (envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_has_route_config(
407
+ http_connection_manager_proto)) {
408
+ const envoy_config_route_v3_RouteConfiguration* route_config =
409
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_route_config(
410
+ http_connection_manager_proto);
411
+ XdsRouteConfigResource rds_update;
412
+ grpc_error_handle error =
413
+ XdsRouteConfigResource::Parse(context, route_config, &rds_update);
414
+ if (error != GRPC_ERROR_NONE) return error;
415
+ http_connection_manager->rds_update = std::move(rds_update);
416
+ return GRPC_ERROR_NONE;
417
+ }
418
+ // Validate that RDS must be used to get the route_config dynamically.
419
+ const envoy_extensions_filters_network_http_connection_manager_v3_Rds* rds =
420
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_rds(
421
+ http_connection_manager_proto);
422
+ if (rds == nullptr) {
423
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
424
+ "HttpConnectionManager neither has inlined route_config nor RDS.");
425
+ }
426
+ // Check that the ConfigSource specifies ADS.
427
+ const envoy_config_core_v3_ConfigSource* config_source =
428
+ envoy_extensions_filters_network_http_connection_manager_v3_Rds_config_source(
429
+ rds);
430
+ if (config_source == nullptr) {
431
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
432
+ "HttpConnectionManager missing config_source for RDS.");
433
+ }
434
+ if (!envoy_config_core_v3_ConfigSource_has_ads(config_source)) {
435
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
436
+ "HttpConnectionManager ConfigSource for RDS does not specify ADS.");
437
+ }
438
+ // Get the route_config_name.
439
+ http_connection_manager->route_config_name = UpbStringToStdString(
440
+ envoy_extensions_filters_network_http_connection_manager_v3_Rds_route_config_name(
441
+ rds));
442
+ }
443
+ return GRPC_ERROR_NONE;
444
+ }
445
+
446
+ grpc_error_handle LdsResourceParseClient(
447
+ const XdsEncodingContext& context,
448
+ const envoy_config_listener_v3_ApiListener* api_listener, bool is_v2,
449
+ XdsListenerResource* lds_update) {
450
+ lds_update->type = XdsListenerResource::ListenerType::kHttpApiListener;
451
+ const upb_strview encoded_api_listener = google_protobuf_Any_value(
452
+ envoy_config_listener_v3_ApiListener_api_listener(api_listener));
453
+ const auto* http_connection_manager =
454
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_parse(
455
+ encoded_api_listener.data, encoded_api_listener.size, context.arena);
456
+ if (http_connection_manager == nullptr) {
457
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
458
+ "Could not parse HttpConnectionManager config from ApiListener");
459
+ }
460
+ return HttpConnectionManagerParse(true /* is_client */, context,
461
+ http_connection_manager, is_v2,
462
+ &lds_update->http_connection_manager);
463
+ }
464
+
465
+ grpc_error_handle DownstreamTlsContextParse(
466
+ const XdsEncodingContext& context,
467
+ const envoy_config_core_v3_TransportSocket* transport_socket,
468
+ XdsListenerResource::DownstreamTlsContext* downstream_tls_context) {
469
+ absl::string_view name = UpbStringToAbsl(
470
+ envoy_config_core_v3_TransportSocket_name(transport_socket));
471
+ if (name != "envoy.transport_sockets.tls") {
472
+ return GRPC_ERROR_CREATE_FROM_CPP_STRING(
473
+ absl::StrCat("Unrecognized transport socket: ", name));
474
+ }
475
+ auto* typed_config =
476
+ envoy_config_core_v3_TransportSocket_typed_config(transport_socket);
477
+ std::vector<grpc_error_handle> errors;
478
+ if (typed_config != nullptr) {
479
+ const upb_strview encoded_downstream_tls_context =
480
+ google_protobuf_Any_value(typed_config);
481
+ auto* downstream_tls_context_proto =
482
+ envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_parse(
483
+ encoded_downstream_tls_context.data,
484
+ encoded_downstream_tls_context.size, context.arena);
485
+ if (downstream_tls_context_proto == nullptr) {
486
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
487
+ "Can't decode downstream tls context.");
488
+ }
489
+ auto* common_tls_context =
490
+ envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_common_tls_context(
491
+ downstream_tls_context_proto);
492
+ if (common_tls_context != nullptr) {
493
+ grpc_error_handle error =
494
+ CommonTlsContext::Parse(context, common_tls_context,
495
+ &downstream_tls_context->common_tls_context);
496
+ if (error != GRPC_ERROR_NONE) errors.push_back(error);
497
+ }
498
+ auto* require_client_certificate =
499
+ envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_require_client_certificate(
500
+ downstream_tls_context_proto);
501
+ if (require_client_certificate != nullptr) {
502
+ downstream_tls_context->require_client_certificate =
503
+ google_protobuf_BoolValue_value(require_client_certificate);
504
+ }
505
+ auto* require_sni =
506
+ envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_require_sni(
507
+ downstream_tls_context_proto);
508
+ if (require_sni != nullptr &&
509
+ google_protobuf_BoolValue_value(require_sni)) {
510
+ errors.push_back(
511
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("require_sni: unsupported"));
512
+ }
513
+ if (envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_ocsp_staple_policy(
514
+ downstream_tls_context_proto) !=
515
+ envoy_extensions_transport_sockets_tls_v3_DownstreamTlsContext_LENIENT_STAPLING) {
516
+ errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
517
+ "ocsp_staple_policy: Only LENIENT_STAPLING supported"));
518
+ }
519
+ }
520
+ if (downstream_tls_context->common_tls_context
521
+ .tls_certificate_provider_instance.instance_name.empty()) {
522
+ errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
523
+ "TLS configuration provided but no "
524
+ "tls_certificate_provider_instance found."));
525
+ }
526
+ if (downstream_tls_context->require_client_certificate &&
527
+ downstream_tls_context->common_tls_context.certificate_validation_context
528
+ .ca_certificate_provider_instance.instance_name.empty()) {
529
+ errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
530
+ "TLS configuration requires client certificates but no certificate "
531
+ "provider instance specified for validation."));
532
+ }
533
+ if (!downstream_tls_context->common_tls_context.certificate_validation_context
534
+ .match_subject_alt_names.empty()) {
535
+ errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
536
+ "match_subject_alt_names not supported on servers"));
537
+ }
538
+ return GRPC_ERROR_CREATE_FROM_VECTOR("Error parsing DownstreamTlsContext",
539
+ &errors);
540
+ }
541
+
542
+ grpc_error_handle CidrRangeParse(
543
+ const envoy_config_core_v3_CidrRange* cidr_range_proto,
544
+ XdsListenerResource::FilterChainMap::CidrRange* cidr_range) {
545
+ std::string address_prefix = UpbStringToStdString(
546
+ envoy_config_core_v3_CidrRange_address_prefix(cidr_range_proto));
547
+ grpc_error_handle error =
548
+ grpc_string_to_sockaddr(&cidr_range->address, address_prefix.c_str(), 0);
549
+ if (error != GRPC_ERROR_NONE) return error;
550
+ cidr_range->prefix_len = 0;
551
+ auto* prefix_len_proto =
552
+ envoy_config_core_v3_CidrRange_prefix_len(cidr_range_proto);
553
+ if (prefix_len_proto != nullptr) {
554
+ cidr_range->prefix_len = std::min(
555
+ google_protobuf_UInt32Value_value(prefix_len_proto),
556
+ (reinterpret_cast<const grpc_sockaddr*>(cidr_range->address.addr))
557
+ ->sa_family == GRPC_AF_INET
558
+ ? uint32_t(32)
559
+ : uint32_t(128));
560
+ }
561
+ // Normalize the network address by masking it with prefix_len
562
+ grpc_sockaddr_mask_bits(&cidr_range->address, cidr_range->prefix_len);
563
+ return GRPC_ERROR_NONE;
564
+ }
565
+
566
+ grpc_error_handle FilterChainMatchParse(
567
+ const envoy_config_listener_v3_FilterChainMatch* filter_chain_match_proto,
568
+ FilterChain::FilterChainMatch* filter_chain_match) {
569
+ auto* destination_port =
570
+ envoy_config_listener_v3_FilterChainMatch_destination_port(
571
+ filter_chain_match_proto);
572
+ if (destination_port != nullptr) {
573
+ filter_chain_match->destination_port =
574
+ google_protobuf_UInt32Value_value(destination_port);
575
+ }
576
+ size_t size = 0;
577
+ auto* prefix_ranges = envoy_config_listener_v3_FilterChainMatch_prefix_ranges(
578
+ filter_chain_match_proto, &size);
579
+ filter_chain_match->prefix_ranges.reserve(size);
580
+ for (size_t i = 0; i < size; i++) {
581
+ XdsListenerResource::FilterChainMap::CidrRange cidr_range;
582
+ grpc_error_handle error = CidrRangeParse(prefix_ranges[i], &cidr_range);
583
+ if (error != GRPC_ERROR_NONE) return error;
584
+ filter_chain_match->prefix_ranges.push_back(cidr_range);
585
+ }
586
+ filter_chain_match->source_type =
587
+ static_cast<XdsListenerResource::FilterChainMap::ConnectionSourceType>(
588
+ envoy_config_listener_v3_FilterChainMatch_source_type(
589
+ filter_chain_match_proto));
590
+ auto* source_prefix_ranges =
591
+ envoy_config_listener_v3_FilterChainMatch_source_prefix_ranges(
592
+ filter_chain_match_proto, &size);
593
+ filter_chain_match->source_prefix_ranges.reserve(size);
594
+ for (size_t i = 0; i < size; i++) {
595
+ XdsListenerResource::FilterChainMap::CidrRange cidr_range;
596
+ grpc_error_handle error =
597
+ CidrRangeParse(source_prefix_ranges[i], &cidr_range);
598
+ if (error != GRPC_ERROR_NONE) return error;
599
+ filter_chain_match->source_prefix_ranges.push_back(cidr_range);
600
+ }
601
+ auto* source_ports = envoy_config_listener_v3_FilterChainMatch_source_ports(
602
+ filter_chain_match_proto, &size);
603
+ filter_chain_match->source_ports.reserve(size);
604
+ for (size_t i = 0; i < size; i++) {
605
+ filter_chain_match->source_ports.push_back(source_ports[i]);
606
+ }
607
+ auto* server_names = envoy_config_listener_v3_FilterChainMatch_server_names(
608
+ filter_chain_match_proto, &size);
609
+ for (size_t i = 0; i < size; i++) {
610
+ filter_chain_match->server_names.push_back(
611
+ UpbStringToStdString(server_names[i]));
612
+ }
613
+ filter_chain_match->transport_protocol = UpbStringToStdString(
614
+ envoy_config_listener_v3_FilterChainMatch_transport_protocol(
615
+ filter_chain_match_proto));
616
+ auto* application_protocols =
617
+ envoy_config_listener_v3_FilterChainMatch_application_protocols(
618
+ filter_chain_match_proto, &size);
619
+ for (size_t i = 0; i < size; i++) {
620
+ filter_chain_match->application_protocols.push_back(
621
+ UpbStringToStdString(application_protocols[i]));
622
+ }
623
+ return GRPC_ERROR_NONE;
624
+ }
625
+
626
+ grpc_error_handle FilterChainParse(
627
+ const XdsEncodingContext& context,
628
+ const envoy_config_listener_v3_FilterChain* filter_chain_proto, bool is_v2,
629
+ FilterChain* filter_chain) {
630
+ std::vector<grpc_error_handle> errors;
631
+ auto* filter_chain_match =
632
+ envoy_config_listener_v3_FilterChain_filter_chain_match(
633
+ filter_chain_proto);
634
+ if (filter_chain_match != nullptr) {
635
+ grpc_error_handle error = FilterChainMatchParse(
636
+ filter_chain_match, &filter_chain->filter_chain_match);
637
+ if (error != GRPC_ERROR_NONE) errors.push_back(error);
638
+ }
639
+ filter_chain->filter_chain_data =
640
+ std::make_shared<XdsListenerResource::FilterChainData>();
641
+ // Parse the filters list. Currently we only support HttpConnectionManager.
642
+ size_t size = 0;
643
+ auto* filters =
644
+ envoy_config_listener_v3_FilterChain_filters(filter_chain_proto, &size);
645
+ if (size != 1) {
646
+ errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
647
+ "FilterChain should have exactly one filter: HttpConnectionManager; no "
648
+ "other filter is supported at the moment"));
649
+ } else {
650
+ auto* typed_config =
651
+ envoy_config_listener_v3_Filter_typed_config(filters[0]);
652
+ if (typed_config == nullptr) {
653
+ errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
654
+ "No typed_config found in filter."));
655
+ } else {
656
+ absl::string_view type_url =
657
+ UpbStringToAbsl(google_protobuf_Any_type_url(typed_config));
658
+ if (type_url !=
659
+ "type.googleapis.com/"
660
+ "envoy.extensions.filters.network.http_connection_manager.v3."
661
+ "HttpConnectionManager") {
662
+ errors.push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING(
663
+ absl::StrCat("Unsupported filter type ", type_url)));
664
+ } else {
665
+ const upb_strview encoded_http_connection_manager =
666
+ google_protobuf_Any_value(typed_config);
667
+ const auto* http_connection_manager =
668
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_parse(
669
+ encoded_http_connection_manager.data,
670
+ encoded_http_connection_manager.size, context.arena);
671
+ if (http_connection_manager == nullptr) {
672
+ errors.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
673
+ "Could not parse HttpConnectionManager config from filter "
674
+ "typed_config"));
675
+ } else {
676
+ grpc_error_handle error = HttpConnectionManagerParse(
677
+ false /* is_client */, context, http_connection_manager, is_v2,
678
+ &filter_chain->filter_chain_data->http_connection_manager);
679
+ if (error != GRPC_ERROR_NONE) errors.push_back(error);
680
+ }
681
+ }
682
+ }
683
+ }
684
+ auto* transport_socket =
685
+ envoy_config_listener_v3_FilterChain_transport_socket(filter_chain_proto);
686
+ if (transport_socket != nullptr) {
687
+ grpc_error_handle error = DownstreamTlsContextParse(
688
+ context, transport_socket,
689
+ &filter_chain->filter_chain_data->downstream_tls_context);
690
+ if (error != GRPC_ERROR_NONE) errors.push_back(error);
691
+ }
692
+ return GRPC_ERROR_CREATE_FROM_VECTOR("Error parsing FilterChain", &errors);
693
+ }
694
+
695
+ grpc_error_handle AddressParse(
696
+ const envoy_config_core_v3_Address* address_proto, std::string* address) {
697
+ const auto* socket_address =
698
+ envoy_config_core_v3_Address_socket_address(address_proto);
699
+ if (socket_address == nullptr) {
700
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
701
+ "Address does not have socket_address");
702
+ }
703
+ if (envoy_config_core_v3_SocketAddress_protocol(socket_address) !=
704
+ envoy_config_core_v3_SocketAddress_TCP) {
705
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
706
+ "SocketAddress protocol is not TCP");
707
+ }
708
+ uint32_t port = envoy_config_core_v3_SocketAddress_port_value(socket_address);
709
+ if (port > 65535) {
710
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Invalid port");
711
+ }
712
+ *address = JoinHostPort(
713
+ UpbStringToAbsl(
714
+ envoy_config_core_v3_SocketAddress_address(socket_address)),
715
+ port);
716
+ return GRPC_ERROR_NONE;
717
+ }
718
+
719
+ // An intermediate map for filter chains that we create to validate the list of
720
+ // filter chains received from the control plane and to finally create
721
+ // XdsListenerResource::FilterChainMap
722
+ struct InternalFilterChainMap {
723
+ using SourceIpMap =
724
+ std::map<std::string, XdsListenerResource::FilterChainMap::SourceIp>;
725
+ using ConnectionSourceTypesArray = std::array<SourceIpMap, 3>;
726
+ struct DestinationIp {
727
+ absl::optional<XdsListenerResource::FilterChainMap::CidrRange> prefix_range;
728
+ bool transport_protocol_raw_buffer_provided = false;
729
+ ConnectionSourceTypesArray source_types_array;
730
+ };
731
+ using DestinationIpMap = std::map<std::string, DestinationIp>;
732
+ DestinationIpMap destination_ip_map;
733
+ };
734
+
735
+ grpc_error_handle AddFilterChainDataForSourcePort(
736
+ const FilterChain& filter_chain,
737
+ XdsListenerResource::FilterChainMap::SourcePortsMap* ports_map,
738
+ uint32_t port) {
739
+ auto insert_result = ports_map->emplace(
740
+ port, XdsListenerResource::FilterChainMap::FilterChainDataSharedPtr{
741
+ filter_chain.filter_chain_data});
742
+ if (!insert_result.second) {
743
+ return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat(
744
+ "Duplicate matching rules detected when adding filter chain: ",
745
+ filter_chain.filter_chain_match.ToString()));
746
+ }
747
+ return GRPC_ERROR_NONE;
748
+ }
749
+
750
+ grpc_error_handle AddFilterChainDataForSourcePorts(
751
+ const FilterChain& filter_chain,
752
+ XdsListenerResource::FilterChainMap::SourcePortsMap* ports_map) {
753
+ if (filter_chain.filter_chain_match.source_ports.empty()) {
754
+ return AddFilterChainDataForSourcePort(filter_chain, ports_map, 0);
755
+ } else {
756
+ for (uint32_t port : filter_chain.filter_chain_match.source_ports) {
757
+ grpc_error_handle error =
758
+ AddFilterChainDataForSourcePort(filter_chain, ports_map, port);
759
+ if (error != GRPC_ERROR_NONE) return error;
760
+ }
761
+ }
762
+ return GRPC_ERROR_NONE;
763
+ }
764
+
765
+ grpc_error_handle AddFilterChainDataForSourceIpRange(
766
+ const FilterChain& filter_chain,
767
+ InternalFilterChainMap::SourceIpMap* source_ip_map) {
768
+ if (filter_chain.filter_chain_match.source_prefix_ranges.empty()) {
769
+ auto insert_result = source_ip_map->emplace(
770
+ "", XdsListenerResource::FilterChainMap::SourceIp());
771
+ return AddFilterChainDataForSourcePorts(
772
+ filter_chain, &insert_result.first->second.ports_map);
773
+ } else {
774
+ for (const auto& prefix_range :
775
+ filter_chain.filter_chain_match.source_prefix_ranges) {
776
+ auto insert_result = source_ip_map->emplace(
777
+ absl::StrCat(grpc_sockaddr_to_string(&prefix_range.address, false),
778
+ "/", prefix_range.prefix_len),
779
+ XdsListenerResource::FilterChainMap::SourceIp());
780
+ if (insert_result.second) {
781
+ insert_result.first->second.prefix_range.emplace(prefix_range);
782
+ }
783
+ grpc_error_handle error = AddFilterChainDataForSourcePorts(
784
+ filter_chain, &insert_result.first->second.ports_map);
785
+ if (error != GRPC_ERROR_NONE) return error;
786
+ }
787
+ }
788
+ return GRPC_ERROR_NONE;
789
+ }
790
+
791
+ grpc_error_handle AddFilterChainDataForSourceType(
792
+ const FilterChain& filter_chain,
793
+ InternalFilterChainMap::DestinationIp* destination_ip) {
794
+ GPR_ASSERT(static_cast<unsigned int>(
795
+ filter_chain.filter_chain_match.source_type) < 3);
796
+ return AddFilterChainDataForSourceIpRange(
797
+ filter_chain, &destination_ip->source_types_array[static_cast<int>(
798
+ filter_chain.filter_chain_match.source_type)]);
799
+ }
800
+
801
+ grpc_error_handle AddFilterChainDataForApplicationProtocols(
802
+ const FilterChain& filter_chain,
803
+ InternalFilterChainMap::DestinationIp* destination_ip) {
804
+ // Only allow filter chains that do not mention application protocols
805
+ if (!filter_chain.filter_chain_match.application_protocols.empty()) {
806
+ return GRPC_ERROR_NONE;
807
+ }
808
+ return AddFilterChainDataForSourceType(filter_chain, destination_ip);
809
+ }
810
+
811
+ grpc_error_handle AddFilterChainDataForTransportProtocol(
812
+ const FilterChain& filter_chain,
813
+ InternalFilterChainMap::DestinationIp* destination_ip) {
814
+ const std::string& transport_protocol =
815
+ filter_chain.filter_chain_match.transport_protocol;
816
+ // Only allow filter chains with no transport protocol or "raw_buffer"
817
+ if (!transport_protocol.empty() && transport_protocol != "raw_buffer") {
818
+ return GRPC_ERROR_NONE;
819
+ }
820
+ // If for this configuration, we've already seen filter chains that mention
821
+ // the transport protocol as "raw_buffer", we will never match filter chains
822
+ // that do not mention it.
823
+ if (destination_ip->transport_protocol_raw_buffer_provided &&
824
+ transport_protocol.empty()) {
825
+ return GRPC_ERROR_NONE;
826
+ }
827
+ if (!transport_protocol.empty() &&
828
+ !destination_ip->transport_protocol_raw_buffer_provided) {
829
+ destination_ip->transport_protocol_raw_buffer_provided = true;
830
+ // Clear out the previous entries if any since those entries did not mention
831
+ // "raw_buffer"
832
+ destination_ip->source_types_array =
833
+ InternalFilterChainMap::ConnectionSourceTypesArray();
834
+ }
835
+ return AddFilterChainDataForApplicationProtocols(filter_chain,
836
+ destination_ip);
837
+ }
838
+
839
+ grpc_error_handle AddFilterChainDataForServerNames(
840
+ const FilterChain& filter_chain,
841
+ InternalFilterChainMap::DestinationIp* destination_ip) {
842
+ // Don't continue adding filter chains with server names mentioned
843
+ if (!filter_chain.filter_chain_match.server_names.empty()) {
844
+ return GRPC_ERROR_NONE;
845
+ }
846
+ return AddFilterChainDataForTransportProtocol(filter_chain, destination_ip);
847
+ }
848
+
849
+ grpc_error_handle AddFilterChainDataForDestinationIpRange(
850
+ const FilterChain& filter_chain,
851
+ InternalFilterChainMap::DestinationIpMap* destination_ip_map) {
852
+ if (filter_chain.filter_chain_match.prefix_ranges.empty()) {
853
+ auto insert_result = destination_ip_map->emplace(
854
+ "", InternalFilterChainMap::DestinationIp());
855
+ return AddFilterChainDataForServerNames(filter_chain,
856
+ &insert_result.first->second);
857
+ } else {
858
+ for (const auto& prefix_range :
859
+ filter_chain.filter_chain_match.prefix_ranges) {
860
+ auto insert_result = destination_ip_map->emplace(
861
+ absl::StrCat(grpc_sockaddr_to_string(&prefix_range.address, false),
862
+ "/", prefix_range.prefix_len),
863
+ InternalFilterChainMap::DestinationIp());
864
+ if (insert_result.second) {
865
+ insert_result.first->second.prefix_range.emplace(prefix_range);
866
+ }
867
+ grpc_error_handle error = AddFilterChainDataForServerNames(
868
+ filter_chain, &insert_result.first->second);
869
+ if (error != GRPC_ERROR_NONE) return error;
870
+ }
871
+ }
872
+ return GRPC_ERROR_NONE;
873
+ }
874
+
875
+ XdsListenerResource::FilterChainMap BuildFromInternalFilterChainMap(
876
+ InternalFilterChainMap* internal_filter_chain_map) {
877
+ XdsListenerResource::FilterChainMap filter_chain_map;
878
+ for (auto& destination_ip_pair :
879
+ internal_filter_chain_map->destination_ip_map) {
880
+ XdsListenerResource::FilterChainMap::DestinationIp destination_ip;
881
+ destination_ip.prefix_range = destination_ip_pair.second.prefix_range;
882
+ for (int i = 0; i < 3; i++) {
883
+ auto& source_ip_map = destination_ip_pair.second.source_types_array[i];
884
+ for (auto& source_ip_pair : source_ip_map) {
885
+ destination_ip.source_types_array[i].push_back(
886
+ std::move(source_ip_pair.second));
887
+ }
888
+ }
889
+ filter_chain_map.destination_ip_vector.push_back(std::move(destination_ip));
890
+ }
891
+ return filter_chain_map;
892
+ }
893
+
894
+ grpc_error_handle BuildFilterChainMap(
895
+ const std::vector<FilterChain>& filter_chains,
896
+ XdsListenerResource::FilterChainMap* filter_chain_map) {
897
+ InternalFilterChainMap internal_filter_chain_map;
898
+ for (const auto& filter_chain : filter_chains) {
899
+ // Discard filter chain entries that specify destination port
900
+ if (filter_chain.filter_chain_match.destination_port != 0) continue;
901
+ grpc_error_handle error = AddFilterChainDataForDestinationIpRange(
902
+ filter_chain, &internal_filter_chain_map.destination_ip_map);
903
+ if (error != GRPC_ERROR_NONE) return error;
904
+ }
905
+ *filter_chain_map =
906
+ BuildFromInternalFilterChainMap(&internal_filter_chain_map);
907
+ return GRPC_ERROR_NONE;
908
+ }
909
+
910
+ grpc_error_handle LdsResourceParseServer(
911
+ const XdsEncodingContext& context,
912
+ const envoy_config_listener_v3_Listener* listener, bool is_v2,
913
+ XdsListenerResource* lds_update) {
914
+ lds_update->type = XdsListenerResource::ListenerType::kTcpListener;
915
+ grpc_error_handle error =
916
+ AddressParse(envoy_config_listener_v3_Listener_address(listener),
917
+ &lds_update->address);
918
+ if (error != GRPC_ERROR_NONE) return error;
919
+ const auto* use_original_dst =
920
+ envoy_config_listener_v3_Listener_use_original_dst(listener);
921
+ if (use_original_dst != nullptr) {
922
+ if (google_protobuf_BoolValue_value(use_original_dst)) {
923
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
924
+ "Field \'use_original_dst\' is not supported.");
925
+ }
926
+ }
927
+ size_t size = 0;
928
+ auto* filter_chains =
929
+ envoy_config_listener_v3_Listener_filter_chains(listener, &size);
930
+ std::vector<FilterChain> parsed_filter_chains;
931
+ parsed_filter_chains.reserve(size);
932
+ for (size_t i = 0; i < size; i++) {
933
+ FilterChain filter_chain;
934
+ error = FilterChainParse(context, filter_chains[i], is_v2, &filter_chain);
935
+ if (error != GRPC_ERROR_NONE) return error;
936
+ parsed_filter_chains.push_back(std::move(filter_chain));
937
+ }
938
+ error =
939
+ BuildFilterChainMap(parsed_filter_chains, &lds_update->filter_chain_map);
940
+ if (error != GRPC_ERROR_NONE) return error;
941
+ auto* default_filter_chain =
942
+ envoy_config_listener_v3_Listener_default_filter_chain(listener);
943
+ if (default_filter_chain != nullptr) {
944
+ FilterChain filter_chain;
945
+ error =
946
+ FilterChainParse(context, default_filter_chain, is_v2, &filter_chain);
947
+ if (error != GRPC_ERROR_NONE) return error;
948
+ if (filter_chain.filter_chain_data != nullptr) {
949
+ lds_update->default_filter_chain =
950
+ std::move(*filter_chain.filter_chain_data);
951
+ }
952
+ }
953
+ if (size == 0 && default_filter_chain == nullptr) {
954
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("No filter chain provided.");
955
+ }
956
+ return GRPC_ERROR_NONE;
957
+ }
958
+
959
+ grpc_error_handle LdsResourceParse(
960
+ const XdsEncodingContext& context,
961
+ const envoy_config_listener_v3_Listener* listener, bool is_v2,
962
+ XdsListenerResource* lds_update) {
963
+ // Check whether it's a client or server listener.
964
+ const envoy_config_listener_v3_ApiListener* api_listener =
965
+ envoy_config_listener_v3_Listener_api_listener(listener);
966
+ const envoy_config_core_v3_Address* address =
967
+ envoy_config_listener_v3_Listener_address(listener);
968
+ if (api_listener != nullptr && address != nullptr) {
969
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
970
+ "Listener has both address and ApiListener");
971
+ }
972
+ if (api_listener == nullptr && address == nullptr) {
973
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
974
+ "Listener has neither address nor ApiListener");
975
+ }
976
+ // Validate Listener fields.
977
+ grpc_error_handle error = GRPC_ERROR_NONE;
978
+ if (api_listener != nullptr) {
979
+ error = LdsResourceParseClient(context, api_listener, is_v2, lds_update);
980
+ } else {
981
+ error = LdsResourceParseServer(context, listener, is_v2, lds_update);
982
+ }
983
+ return error;
984
+ }
985
+
986
+ void MaybeLogListener(const XdsEncodingContext& context,
987
+ const envoy_config_listener_v3_Listener* listener) {
988
+ if (GRPC_TRACE_FLAG_ENABLED(*context.tracer) &&
989
+ gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
990
+ const upb_msgdef* msg_type =
991
+ envoy_config_listener_v3_Listener_getmsgdef(context.symtab);
992
+ char buf[10240];
993
+ upb_text_encode(listener, msg_type, nullptr, 0, buf, sizeof(buf));
994
+ gpr_log(GPR_DEBUG, "[xds_client %p] Listener: %s", context.client, buf);
995
+ }
996
+ }
997
+
998
+ } // namespace
999
+
1000
+ absl::StatusOr<XdsResourceType::DecodeResult> XdsListenerResourceType::Decode(
1001
+ const XdsEncodingContext& context, absl::string_view serialized_resource,
1002
+ bool is_v2) const {
1003
+ // Parse serialized proto.
1004
+ auto* resource = envoy_config_listener_v3_Listener_parse(
1005
+ serialized_resource.data(), serialized_resource.size(), context.arena);
1006
+ if (resource == nullptr) {
1007
+ return absl::InvalidArgumentError("Can't parse Listener resource.");
1008
+ }
1009
+ MaybeLogListener(context, resource);
1010
+ // Validate resource.
1011
+ DecodeResult result;
1012
+ result.name =
1013
+ UpbStringToStdString(envoy_config_listener_v3_Listener_name(resource));
1014
+ auto listener_data = absl::make_unique<ResourceDataSubclass>();
1015
+ grpc_error_handle error =
1016
+ LdsResourceParse(context, resource, is_v2, &listener_data->resource);
1017
+ if (error != GRPC_ERROR_NONE) {
1018
+ std::string error_str = grpc_error_std_string(error);
1019
+ GRPC_ERROR_UNREF(error);
1020
+ if (GRPC_TRACE_FLAG_ENABLED(*context.tracer)) {
1021
+ gpr_log(GPR_ERROR, "[xds_client %p] invalid Listener %s: %s",
1022
+ context.client, result.name.c_str(), error_str.c_str());
1023
+ }
1024
+ result.resource = absl::InvalidArgumentError(error_str);
1025
+ } else {
1026
+ if (GRPC_TRACE_FLAG_ENABLED(*context.tracer)) {
1027
+ gpr_log(GPR_INFO, "[xds_client %p] parsed Listener %s: %s",
1028
+ context.client, result.name.c_str(),
1029
+ listener_data->resource.ToString().c_str());
1030
+ }
1031
+ result.resource = std::move(listener_data);
1032
+ }
1033
+ return std::move(result);
1034
+ }
1035
+
1036
+ } // namespace grpc_core