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.

dhcpmgmt.c 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (C) 2007 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., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. #include <string.h>
  20. #include <stdio.h>
  21. #include <errno.h>
  22. #include <ipxe/netdevice.h>
  23. #include <ipxe/dhcp.h>
  24. #include <ipxe/monojob.h>
  25. #include <ipxe/process.h>
  26. #include <usr/ifmgmt.h>
  27. #include <usr/dhcpmgmt.h>
  28. #define LINK_WAIT_MS 15000
  29. /** @file
  30. *
  31. * DHCP management
  32. *
  33. */
  34. int dhcp ( struct net_device *netdev ) {
  35. struct dhcphdr *dhcphdr;
  36. typeof ( dhcphdr->chaddr ) chaddr;
  37. unsigned int hlen;
  38. unsigned int i;
  39. int rc;
  40. /* Check we can open the interface first */
  41. if ( ( rc = ifopen ( netdev ) ) != 0 )
  42. return rc;
  43. /* Wait for link-up */
  44. if ( ( rc = iflinkwait ( netdev, LINK_WAIT_MS ) ) != 0 )
  45. return rc;
  46. /* Perform DHCP */
  47. printf ( "DHCP (%s", netdev->name );
  48. hlen = dhcp_chaddr ( netdev, chaddr, NULL );
  49. for ( i = 0 ; i < hlen ; i++ )
  50. printf ( "%c%02x", ( i ? ':' : ' ' ), chaddr[i] );
  51. printf ( ")" );
  52. if ( ( rc = start_dhcp ( &monojob, netdev ) ) == 0 ) {
  53. rc = monojob_wait ( "" );
  54. } else if ( rc > 0 ) {
  55. printf ( " using cached\n" );
  56. rc = 0;
  57. }
  58. return rc;
  59. }
  60. int pxebs ( struct net_device *netdev, unsigned int pxe_type ) {
  61. int rc;
  62. /* Perform PXE Boot Server Discovery */
  63. printf ( "PXEBS (%s type %d)", netdev->name, pxe_type );
  64. if ( ( rc = start_pxebs ( &monojob, netdev, pxe_type ) ) == 0 )
  65. rc = monojob_wait ( "" );
  66. return rc;
  67. }