|
|
1.1 ! root 1: /* ! 2: * Copyright (C) 2007 Michael Brown <[email protected]>. ! 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: ! 19: FILE_LICENCE ( GPL2_OR_LATER ); ! 20: ! 21: #include <string.h> ! 22: #include <stdio.h> ! 23: #include <errno.h> ! 24: #include <ipxe/netdevice.h> ! 25: #include <ipxe/dhcp.h> ! 26: #include <ipxe/monojob.h> ! 27: #include <ipxe/process.h> ! 28: #include <usr/ifmgmt.h> ! 29: #include <usr/dhcpmgmt.h> ! 30: ! 31: #define LINK_WAIT_MS 15000 ! 32: ! 33: /** @file ! 34: * ! 35: * DHCP management ! 36: * ! 37: */ ! 38: ! 39: int dhcp ( struct net_device *netdev ) { ! 40: struct dhcphdr *dhcphdr; ! 41: typeof ( dhcphdr->chaddr ) chaddr; ! 42: unsigned int hlen; ! 43: unsigned int i; ! 44: int rc; ! 45: ! 46: /* Check we can open the interface first */ ! 47: if ( ( rc = ifopen ( netdev ) ) != 0 ) ! 48: return rc; ! 49: ! 50: /* Wait for link-up */ ! 51: if ( ( rc = iflinkwait ( netdev, LINK_WAIT_MS ) ) != 0 ) ! 52: return rc; ! 53: ! 54: /* Perform DHCP */ ! 55: printf ( "DHCP (%s", netdev->name ); ! 56: hlen = dhcp_chaddr ( netdev, chaddr, NULL ); ! 57: for ( i = 0 ; i < hlen ; i++ ) ! 58: printf ( "%c%02x", ( i ? ':' : ' ' ), chaddr[i] ); ! 59: printf ( ")" ); ! 60: ! 61: if ( ( rc = start_dhcp ( &monojob, netdev ) ) == 0 ) { ! 62: rc = monojob_wait ( "" ); ! 63: } else if ( rc > 0 ) { ! 64: printf ( " using cached\n" ); ! 65: rc = 0; ! 66: } ! 67: ! 68: return rc; ! 69: } ! 70: ! 71: int pxebs ( struct net_device *netdev, unsigned int pxe_type ) { ! 72: int rc; ! 73: ! 74: /* Perform PXE Boot Server Discovery */ ! 75: printf ( "PXEBS (%s type %d)", netdev->name, pxe_type ); ! 76: if ( ( rc = start_pxebs ( &monojob, netdev, pxe_type ) ) == 0 ) ! 77: rc = monojob_wait ( "" ); ! 78: ! 79: return rc; ! 80: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.