您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (C) 2017 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. /**
  25. * @file
  26. *
  27. * Google Compute Engine (GCE) metadata retrieval
  28. *
  29. * For some unspecified "security" reason, the Google Compute Engine
  30. * metadata server will refuse any requests that do not include the
  31. * non-standard HTTP header "Metadata-Flavor: Google".
  32. */
  33. #include <strings.h>
  34. #include <stdio.h>
  35. #include <ipxe/http.h>
  36. /** Metadata host name
  37. *
  38. * This is used to identify metadata requests, in the absence of any
  39. * more robust mechanism.
  40. */
  41. #define GCE_METADATA_HOST_NAME "metadata.google.internal"
  42. /**
  43. * Construct HTTP "Metadata-Flavor" header
  44. *
  45. * @v http HTTP transaction
  46. * @v buf Buffer
  47. * @v len Length of buffer
  48. * @ret len Length of header value, or negative error
  49. */
  50. static int http_format_metadata_flavor ( struct http_transaction *http,
  51. char *buf, size_t len ) {
  52. /* Do nothing unless this appears to be a Google Compute
  53. * Engine metadata request.
  54. */
  55. if ( strcasecmp ( http->request.host, GCE_METADATA_HOST_NAME ) != 0 )
  56. return 0;
  57. /* Construct host URI */
  58. return snprintf ( buf, len, "Google" );
  59. }
  60. /** HTTP "Metadata-Flavor" header */
  61. struct http_request_header http_request_metadata_flavor __http_request_header ={
  62. .name = "Metadata-Flavor",
  63. .format = http_format_metadata_flavor,
  64. };