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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 <ipxe/dhcp.h>
  23. #include <ipxe/dhcppkt.h>
  24. #include <ipxe/netdevice.h>
  25. #include <ipxe/iobuf.h>
  26. #include <ipxe/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.used_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,
  63. DHCP_SETTINGS_NAME ) ) != 0 )
  64. DBG ( "DHCP could not register cached settings: %s\n",
  65. strerror ( rc ) );
  66. dhcppkt_put ( dhcppkt );
  67. DBG ( "DHCP registered cached settings\n" );
  68. }