You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cachedhcp.c 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (C) 2009 Joshua Oreman <oremanj@rwcr.net>.
  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. FILE_LICENCE ( GPL2_OR_LATER );
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <ipxe/dhcp.h>
  24. #include <ipxe/dhcppkt.h>
  25. #include <ipxe/netdevice.h>
  26. #include <ipxe/iobuf.h>
  27. #include <ipxe/uaccess.h>
  28. /** @file
  29. *
  30. * Cached DHCP packet handling
  31. *
  32. */
  33. /**
  34. * Store cached DHCPACK packet
  35. *
  36. * @v data User pointer to cached DHCP packet data
  37. * @v len Length of cached DHCP packet data
  38. * @ret rc Return status code
  39. *
  40. * This function should be called by the architecture-specific
  41. * get_cached_dhcpack() handler.
  42. */
  43. void store_cached_dhcpack ( userptr_t data, size_t len ) {
  44. struct dhcp_packet *dhcppkt;
  45. struct dhcphdr *dhcphdr;
  46. struct settings *parent;
  47. int rc;
  48. /* Create DHCP packet */
  49. dhcppkt = zalloc ( sizeof ( *dhcppkt ) + len );
  50. if ( ! dhcppkt )
  51. return;
  52. /* Fill in data for DHCP packet */
  53. dhcphdr = ( ( ( void * ) dhcppkt ) + sizeof ( * dhcppkt ) );
  54. copy_from_user ( dhcphdr, data, 0, len );
  55. dhcppkt_init ( dhcppkt, dhcphdr, len );
  56. DBG_HD ( dhcppkt->options.data, dhcppkt->options.used_len );
  57. /* Register settings on the last opened network device.
  58. * This will have the effect of registering cached settings
  59. * with a network device when "dhcp netX" is performed for that
  60. * device, which is usually what we want.
  61. */
  62. parent = netdev_settings ( last_opened_netdev() );
  63. if ( ( rc = register_settings ( &dhcppkt->settings, parent,
  64. DHCP_SETTINGS_NAME ) ) != 0 )
  65. DBG ( "DHCP could not register cached settings: %s\n",
  66. strerror ( rc ) );
  67. dhcppkt_put ( dhcppkt );
  68. DBG ( "DHCP registered cached settings\n" );
  69. }