From patchwork Tue Sep 19 09:58:38 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: 815400 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 3xxJHR24CYz9s7F for ; Tue, 19 Sep 2017 19:58:59 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xxJHR0LRgzDqT0 for ; Tue, 19 Sep 2017 19:58:59 +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 3xxJHL34GtzDq8f for ; Tue, 19 Sep 2017 19:58:53 +1000 (AEST) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v8J9sVSu093605 for ; Tue, 19 Sep 2017 05:58:51 -0400 Received: from e23smtp03.au.ibm.com (e23smtp03.au.ibm.com [202.81.31.145]) by mx0b-001b2d01.pphosted.com with ESMTP id 2d2urpuhv4-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 19 Sep 2017 05:58:50 -0400 Received: from localhost by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 19 Sep 2017 19:58:46 +1000 Received: from d23relay07.au.ibm.com (202.81.31.226) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 19 Sep 2017 19:58:45 +1000 Received: from d23av05.au.ibm.com (d23av05.au.ibm.com [9.190.234.119]) by d23relay07.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v8J9wiET41091164 for ; Tue, 19 Sep 2017 19:58:44 +1000 Received: from d23av05.au.ibm.com (localhost [127.0.0.1]) by d23av05.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v8J9wixf009199 for ; Tue, 19 Sep 2017 19:58:44 +1000 Received: from abhimanyu.in.ibm.com (abhimanyu.in.ibm.com [9.124.35.198]) by d23av05.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v8J9wgtX009126; Tue, 19 Sep 2017 19:58:43 +1000 From: Nikunj A Dadhania To: slof@lists.ozlabs.org Date: Tue, 19 Sep 2017 15:28:38 +0530 X-Mailer: git-send-email 2.9.3 X-TM-AS-MML: disable x-cbid: 17091909-0008-0000-0000-000001584745 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17091909-0009-0000-0000-0000098D8F66 Message-Id: <20170919095838.6513-1-nikunj@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-09-19_04:, , 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-1709190141 Subject: [SLOF] [PATCH] 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 | 40 ++++++++++++++++++++++++++++++++++------ slof/fs/packages/obp-tftp.fs | 13 +------------ slof/helpers.c | 20 ++++++++++++++++++++ 6 files changed, 60 insertions(+), 23 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..3e54ded 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)); @@ -615,13 +640,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 +662,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: @@ -732,5 +757,8 @@ 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); + } 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"); +}