From patchwork Tue Sep 26 03:42:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikunj A Dadhania X-Patchwork-Id: 818435 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y1RcB6lx1z9t49 for ; Tue, 26 Sep 2017 13:42:50 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3y1RcB5kR8zDsP8 for ; Tue, 26 Sep 2017 13:42:50 +1000 (AEST) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=nikunj@linux.vnet.ibm.com; receiver=) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3y1Rc70rbWzDsMB for ; Tue, 26 Sep 2017 13:42:46 +1000 (AEST) Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v8Q3eVFr107614 for ; Mon, 25 Sep 2017 23:42:44 -0400 Received: from e23smtp06.au.ibm.com (e23smtp06.au.ibm.com [202.81.31.148]) by mx0b-001b2d01.pphosted.com with ESMTP id 2d7b6ucgv9-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 25 Sep 2017 23:42:44 -0400 Received: from localhost by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 26 Sep 2017 13:42:41 +1000 Received: from d23relay06.au.ibm.com (202.81.31.225) by e23smtp06.au.ibm.com (202.81.31.212) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 26 Sep 2017 13:42:40 +1000 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay06.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v8Q3gdva38928512 for ; Tue, 26 Sep 2017 13:42:39 +1000 Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v8Q3gUi8009158 for ; Tue, 26 Sep 2017 13:42:30 +1000 Received: from abhimanyu.in.ibm.com (abhimanyu.in.ibm.com [9.124.35.240]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v8Q3gSkk009119; Tue, 26 Sep 2017 13:42:29 +1000 From: Nikunj A Dadhania To: slof@lists.ozlabs.org Date: Tue, 26 Sep 2017 09:12:32 +0530 X-Mailer: git-send-email 2.9.3 X-TM-AS-MML: disable x-cbid: 17092603-0040-0000-0000-00000357DF9D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17092603-0041-0000-0000-00000CD8C6A6 Message-Id: <20170926034232.23709-1-nikunj@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-09-26_02:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1709260056 Subject: [SLOF] [PATCH v2] netboot: Create bootp-response when bootp is used X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" According to TFTP Booting extension, after the success of BOOTP, BOOTREPLY packet should be copied to bootp-response property under "/chosen" While in current case, even when DHCP was used, bootp-response was being set. So set bootp-response when BOOTP is used and dhcp-response for DHCP Signed-off-by: Nikunj A Dadhania --- include/helpers.h | 2 ++ lib/libnet/libnet.code | 4 +-- lib/libnet/netapps.h | 4 +-- lib/libnet/netload.c | 60 +++++++++++++++++++++++++++++++++++--------- slof/fs/packages/obp-tftp.fs | 13 +--------- slof/helpers.c | 20 +++++++++++++++ 6 files changed, 74 insertions(+), 29 deletions(-) diff --git a/include/helpers.h b/include/helpers.h index c86c468..04ee771 100644 --- a/include/helpers.h +++ b/include/helpers.h @@ -36,6 +36,8 @@ extern void SLOF_pci_config_write16(long offset, long value); extern void SLOF_pci_config_write8(long offset, long value); extern void *SLOF_translate_my_address(void *addr); extern int write_mm_log(char *data, unsigned int len, unsigned short type); +extern void SLOF_encode_bootp_response(void *addr, size_t size); +extern void SLOF_encode_dhcp_response(void *addr, size_t size); #define offset_of(type, member) ((long) &((type *)0)->member) #define container_of(ptr, type, member) ({ \ diff --git a/lib/libnet/libnet.code b/lib/libnet/libnet.code index 3602543..2746782 100644 --- a/lib/libnet/libnet.code +++ b/lib/libnet/libnet.code @@ -6,11 +6,9 @@ PRIM(NET_X2d_LOAD) char *arg = TOS.a; POP; int blocksize = TOS.n; POP; int hugeload = TOS.n; POP; - void *replybuf = TOS.a; POP; long maxlen = TOS.n; POP; void *loadaddr = TOS.a; - TOS.n = netload(loadaddr, maxlen, replybuf, hugeload, blocksize, - arg, alen); + TOS.n = netload(loadaddr, maxlen, hugeload, blocksize, arg, alen); MIRP PRIM(NET_X2d_PING) diff --git a/lib/libnet/netapps.h b/lib/libnet/netapps.h index 2fea4a7..0e637e1 100644 --- a/lib/libnet/netapps.h +++ b/lib/libnet/netapps.h @@ -18,8 +18,8 @@ struct filename_ip; -extern int netload(char *buffer, int len, char *ret_buffer, int huge_load, - int block_size, char *args_fs, int alen); +extern int netload(char *buffer, int len, int huge_load, int block_size, + char *args_fs, int alen); extern int ping(char *args_fs, int alen); extern int dhcp(char *ret_buffer, struct filename_ip *fn_ip, unsigned int retries, int flags); diff --git a/lib/libnet/netload.c b/lib/libnet/netload.c index cecb2a0..74e3464 100644 --- a/lib/libnet/netload.c +++ b/lib/libnet/netload.c @@ -34,6 +34,7 @@ #define IP_INIT_DHCPV6_STATELESS 3 #define IP_INIT_IPV6_MANUAL 4 +#define MAX_PKT_SIZE 1720 #define DEFAULT_BOOT_RETRIES 10 #define DEFAULT_TFTP_RETRIES 20 static int ip_version = 4; @@ -493,8 +494,24 @@ static int tftp_load(filename_ip_t *fnip, unsigned char *buffer, int len, return rc; } -int netload(char *buffer, int len, char *ret_buffer, int huge_load, - int block_size, char *args_fs, int alen) +static void encode_response(char *pkt_buffer, size_t size, int ip_init) +{ + switch(ip_init) { + case IP_INIT_BOOTP: + SLOF_encode_bootp_response(pkt_buffer, size); + break; + case IP_INIT_DHCP: + case IP_INIT_DHCPV6_STATELESS: + case IP_INIT_DEFAULT: + SLOF_encode_dhcp_response(pkt_buffer, size); + break; + default: + break; + } +} + +int netload(char *buffer, int len, int huge_load, int block_size, + char *args_fs, int alen) { int rc; filename_ip_t fn_ip; @@ -506,6 +523,14 @@ int netload(char *buffer, int len, char *ret_buffer, int huge_load, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; uint8_t own_mac[6]; + char *pkt_buffer; + + pkt_buffer = SLOF_alloc_mem(MAX_PKT_SIZE); + if (!pkt_buffer) { + puts("ERROR: Unable to allocate memory"); + return -1; + } + memset(pkt_buffer, 0, MAX_PKT_SIZE); puts("\n Initializing NIC"); memset(&fn_ip, 0, sizeof(filename_ip_t)); @@ -533,11 +558,13 @@ int netload(char *buffer, int len, char *ret_buffer, int huge_load, if (fd_device == -1) { netload_error(0x3000, "Could not read MAC address"); - return -100; + rc = -100; + goto err_out; } else if (fd_device == -2) { netload_error(0x3006, "Could not initialize network device"); - return -101; + rc = -101; + goto err_out; } fn_ip.fd = fd_device; @@ -556,7 +583,8 @@ int netload(char *buffer, int len, char *ret_buffer, int huge_load, char args[256]; if (alen > sizeof(args) - 1) { puts("ERROR: Parameter string is too long."); - return -7; + rc = -7; + goto err_out; } /* Convert forth string into NUL-terminated C-string */ strncpy(args, args_fs, alen); @@ -615,13 +643,13 @@ int netload(char *buffer, int len, char *ret_buffer, int huge_load, else { memcpy(&fn_ip.server_ip, obp_tftp_args.giaddr, 4); } - rc = bootp(ret_buffer, &fn_ip, obp_tftp_args.bootp_retries); + rc = bootp(pkt_buffer, &fn_ip, obp_tftp_args.bootp_retries); break; case IP_INIT_DHCP: - rc = dhcp(ret_buffer, &fn_ip, obp_tftp_args.bootp_retries, F_IPV4); + rc = dhcp(pkt_buffer, &fn_ip, obp_tftp_args.bootp_retries, F_IPV4); break; case IP_INIT_DHCPV6_STATELESS: - rc = dhcp(ret_buffer, &fn_ip, + rc = dhcp(pkt_buffer, &fn_ip, obp_tftp_args.bootp_retries, F_IPV6); break; case IP_INIT_IPV6_MANUAL: @@ -637,7 +665,7 @@ int netload(char *buffer, int len, char *ret_buffer, int huge_load, } break; case IP_INIT_DEFAULT: - rc = dhcp(ret_buffer, &fn_ip, obp_tftp_args.bootp_retries, 0); + rc = dhcp(pkt_buffer, &fn_ip, obp_tftp_args.bootp_retries, 0); break; case IP_INIT_NONE: default: @@ -668,7 +696,8 @@ int netload(char *buffer, int len, char *ret_buffer, int huge_load, if (rc == -1) { netload_error(0x3001, "Could not get IP address"); close(fn_ip.fd); - return -101; + rc = -101; + goto err_out; } if (ip_version == 4) { @@ -689,12 +718,14 @@ int netload(char *buffer, int len, char *ret_buffer, int huge_load, ((fn_ip.server_ip >> 8) & 0xFF), ( fn_ip.server_ip & 0xFF)); close(fn_ip.fd); - return -102; + rc = -102; + goto err_out; } if (rc == -4 || rc == -3) { netload_error(0x3008, "Can't obtain TFTP server IP address"); close(fn_ip.fd); - return -107; + rc = -107; + goto err_out; } /*********************************************************** @@ -732,5 +763,10 @@ int netload(char *buffer, int len, char *ret_buffer, int huge_load, close(fn_ip.fd); + if (rc >= 0) { + encode_response(pkt_buffer, MAX_PKT_SIZE, obp_tftp_args.ip_init); + } + err_out: + SLOF_free_mem(pkt_buffer, MAX_PKT_SIZE); return rc; } diff --git a/slof/fs/packages/obp-tftp.fs b/slof/fs/packages/obp-tftp.fs index 63171d0..17fb980 100644 --- a/slof/fs/packages/obp-tftp.fs +++ b/slof/fs/packages/obp-tftp.fs @@ -28,24 +28,13 @@ VARIABLE huge-tftp-load 1 huge-tftp-load ! 60000000 ( addr maxlen ) - \ Allocate 1720 bytes to store the BOOTP-REPLY packet - 6B8 alloc-mem dup >r ( addr maxlen replybuf ) - huge-tftp-load @ d# 1428 ( addr maxlen replybuf hugetftp blocksize ) + huge-tftp-load @ d# 1428 ( addr maxlen hugetftp blocksize ) \ Add OBP-TFTP Bootstring argument, e.g. "10.128.0.1,bootrom.bin,10.128.40.1" my-args net-load dup 0< IF drop 0 THEN - \ Recover buffer address of BOOTP-REPLY packet - r> - r> r> over IF s" bootpath" set-chosen ELSE 2drop THEN r> r> over IF s" bootargs" set-chosen ELSE 2drop THEN - - \ Store BOOTP-REPLY packet as property - dup 6B8 encode-bytes s" bootp-response" s" /chosen" find-node set-property - - \ free buffer - 6B8 free-mem ; : close ( -- ) diff --git a/slof/helpers.c b/slof/helpers.c index d074178..a8d575c 100644 --- a/slof/helpers.c +++ b/slof/helpers.c @@ -180,3 +180,23 @@ int write_mm_log(char *data, unsigned int len, unsigned short type) return forth_eval_pop("write-mm-log"); } + +static void SLOF_encode_response(void *addr, size_t size,char *s) +{ + forth_push((unsigned long)addr); + forth_push(size); + forth_eval("encode-bytes"); + forth_push((unsigned long)s); + forth_push(strlen(s)); + forth_eval("set-chosen"); +} + +void SLOF_encode_bootp_response(void *addr, size_t size) +{ + SLOF_encode_response(addr, size, "bootp-response"); +} + +void SLOF_encode_dhcp_response(void *addr, size_t size) +{ + SLOF_encode_response(addr, size, "dhcp-response"); +}