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.2KB

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