From 85b34d353bf8dbb21731623226f009df1a1d9d01 Mon Sep 17 00:00:00 2001 From: Sergey Bolshakov Date: Wed, 19 Sep 2007 00:46:56 +0400 Subject: [PATCH] dhcp next-server and root-path options can be used, if no server nor directory params supplied in automatic mode. --- dhcp.c | 19 ++++++++++++++----- network.c | 26 ++++++++++++++++++-------- network.h | 3 ++- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/dhcp.c b/dhcp.c index 0b2885f..529154e 100644 --- a/dhcp.c +++ b/dhcp.c @@ -54,18 +54,19 @@ typedef int bp_int32; typedef short bp_int16; -#define BOOTP_OPTION_NETMASK 1 -#define BOOTP_OPTION_GATEWAY 3 +#define BOOTP_OPTION_NETMASK 1 +#define BOOTP_OPTION_GATEWAY 3 #define BOOTP_OPTION_DNS 6 -#define BOOTP_OPTION_HOSTNAME 12 +#define BOOTP_OPTION_HOSTNAME 12 #define BOOTP_OPTION_DOMAIN 15 -#define BOOTP_OPTION_BROADCAST 28 +#define BOOTP_OPTION_ROOTPATH 17 +#define BOOTP_OPTION_BROADCAST 28 #define DHCP_OPTION_REQADDR 50 #define DHCP_OPTION_LEASE 51 #define DHCP_OPTION_TYPE 53 #define DHCP_OPTION_SERVER 54 -#define DHCP_OPTION_OPTIONREQ 55 +#define DHCP_OPTION_OPTIONREQ 55 #define DHCP_OPTION_MAXSIZE 57 #define BOOTP_CLIENT_PORT 68 @@ -209,6 +210,7 @@ static void parse_reply(struct bootp_request * breq, struct interface_info * int unsigned char option, length; memcpy(&intf->ip, &breq->yiaddr, 4); + memcpy(&next_server, &breq->server_ip, 4); chptr = breq->vendor; chptr += 4; @@ -258,6 +260,12 @@ static void parse_reply(struct bootp_request * breq, struct interface_info * int log_message("got hostname %s", hostname); break; + case BOOTP_OPTION_ROOTPATH: + memcpy(tmp_str, chptr, length); + tmp_str[length] = '\0'; + rootpath = strdup(tmp_str); + log_message("got next-server: %s rootpath: %s", inet_ntoa(next_server), rootpath); + break; } chptr += length; @@ -581,6 +589,7 @@ enum return_type perform_dhcp(struct interface_info * intf) requested_options[num_options++] = BOOTP_OPTION_GATEWAY; requested_options[num_options++] = BOOTP_OPTION_DNS; requested_options[num_options++] = BOOTP_OPTION_DOMAIN; + requested_options[num_options++] = BOOTP_OPTION_ROOTPATH; requested_options[num_options++] = BOOTP_OPTION_BROADCAST; add_vendor_code(&breq, DHCP_OPTION_OPTIONREQ, num_options, requested_options); diff --git a/network.c b/network.c index fcc33f0..093b0af 100644 --- a/network.c +++ b/network.c @@ -187,9 +187,11 @@ int configure_net_device(struct interface_info * intf) /* host network informations */ char * hostname = NULL; char * domain = NULL; +char * rootpath = NULL; struct in_addr gateway = { 0 }; struct in_addr dns_server = { 0 }; struct in_addr dns_server2 = { 0 }; +struct in_addr next_server = { 0 }; static int add_default_route(void) { @@ -644,15 +646,23 @@ enum return_type nfs_prepare(void) "and the directory (or ISO image file) containing the %s Distribution.", version); results = ask_from_entries_auto(msg, questions, &answers, 40, questions_auto, NULL); if (results != RETURN_OK || streq(answers[0], "")) { - unset_param(MODE_AUTOMATIC); /* we are in a fallback mode */ - return nfs_prepare(); + if (next_server.s_addr && rootpath != NULL) { + log_message("Using params supplied by DHCP"); + nfsmount_location = malloc(strlen(rootpath) + 17); + strcpy(nfsmount_location, inet_ntoa(next_server)); + strcat(nfsmount_location, ":"); + strcat(nfsmount_location, rootpath); + } else { + unset_param(MODE_AUTOMATIC); /* we are in a fallback mode */ + return nfs_prepare(); + } + } else { + nfsmount_location = malloc(strlen(answers[0]) + strlen(answers[1]) + 2); + strcpy(nfsmount_location, answers[0]); + strcat(nfsmount_location, ":"); + strcat(nfsmount_location, answers[1]); } - - nfsmount_location = malloc(strlen(answers[0]) + strlen(answers[1]) + 2); - strcpy(nfsmount_location, answers[0]); - strcat(nfsmount_location, ":"); - strcat(nfsmount_location, answers[1]); - + if (my_mount(nfsmount_location, IMAGE_LOCATION, "nfs", 0) == -1) { char location_full[500]; char *s; diff --git a/network.h b/network.h index 02eea45..97a4faa 100644 --- a/network.h +++ b/network.h @@ -52,10 +52,11 @@ int configure_net_device(struct interface_info * intf); extern char * hostname; extern char * domain; +extern char * rootpath; extern struct in_addr gateway; extern struct in_addr dns_server; extern struct in_addr dns_server2; - +extern struct in_addr next_server; #endif