Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/kern/subr_tftproot.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/kern/subr_tftproot.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.7 retrieving revision 1.21 diff -u -p -r1.7 -r1.21 --- src/sys/kern/subr_tftproot.c 2009/03/14 15:36:22 1.7 +++ src/sys/kern/subr_tftproot.c 2018/02/08 09:05:20 1.21 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_tftproot.c,v 1.7 2009/03/14 15:36:22 dsl Exp $ */ +/* $NetBSD: subr_tftproot.c,v 1.21 2018/02/08 09:05:20 dholland Exp $ */ /*- * Copyright (c) 2007 Emmanuel Dreyfus, all rights reserved. @@ -39,10 +39,11 @@ #include "opt_md.h" #include -__KERNEL_RCSID(0, "$NetBSD: subr_tftproot.c,v 1.7 2009/03/14 15:36:22 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_tftproot.c,v 1.21 2018/02/08 09:05:20 dholland Exp $"); #include #include +#include #include #include #include @@ -64,8 +65,6 @@ __KERNEL_RCSID(0, "$NetBSD: subr_tftproo #include #include -extern void mdattach(int); - /* * Copied from */ @@ -114,29 +113,36 @@ struct tftproot_handle { #define TRH_FINISHED 1 -int tftproot_dhcpboot(struct device *); +int tftproot_dhcpboot(device_t); static int tftproot_getfile(struct tftproot_handle *, struct lwp *); -static int tftproot_recv(struct mbuf*, void*); +static int tftproot_recv(struct mbuf **, void *); int -tftproot_dhcpboot(struct device *bootdv) +tftproot_dhcpboot(device_t bootdv) { struct nfs_diskless *nd = NULL; struct ifnet *ifp = NULL; struct lwp *l; struct tftproot_handle trh; - struct device *dv; + device_t dv; int error = -1; if (rootspec != NULL) { - IFNET_FOREACH(ifp) + int s = pserialize_read_enter(); + IFNET_READER_FOREACH(ifp) if (strcmp(rootspec, ifp->if_xname) == 0) break; - } else if ((bootdv != NULL && device_class(bootdv) == DV_IFNET)) { - IFNET_FOREACH(ifp) + pserialize_read_exit(s); + } + + if ((ifp == NULL) && + (bootdv != NULL && device_class(bootdv) == DV_IFNET)) { + int s = pserialize_read_enter(); + IFNET_READER_FOREACH(ifp) if (strcmp(device_xname(bootdv), ifp->if_xname) == 0) break; + pserialize_read_exit(s); } if (ifp == NULL) { @@ -178,7 +184,7 @@ tftproot_dhcpboot(struct device *bootdv) printf("tftproot: bootfile=%s\n", nd->nd_bootfile); - bzero(&trh, sizeof(trh)); + memset(&trh, 0, sizeof(trh)); trh.trh_nd = nd; trh.trh_block = 1; @@ -203,14 +209,13 @@ tftproot_getfile(struct tftproot_handle struct socket *so = NULL; struct mbuf *m_serv = NULL; struct mbuf *m_outbuf = NULL; - struct sockaddr_in *sin; + struct sockaddr_in sin; struct tftphdr *tftp; size_t packetlen, namelen; int error = -1; const char octetstr[] = "octet"; size_t hdrlen = sizeof(*tftp) - sizeof(tftp->th_data); char *cp; - /* struct device *dv; */ if ((error = socreate(AF_INET, &so, SOCK_DGRAM, 0, l, NULL)) != 0) { DPRINTF(("%s():%d socreate returned %d\n", @@ -230,11 +235,8 @@ tftproot_getfile(struct tftproot_handle /* * Set server address and port */ - m_serv = m_get(M_WAIT, MT_SONAME); - m_serv->m_len = sizeof(*sin); - sin = mtod(m_serv, struct sockaddr_in *); - memcpy(sin, &trh->trh_nd->nd_root.ndm_saddr, sizeof(*sin)); - sin->sin_port = htons(IPPORT_TFTP); + memcpy(&sin, &trh->trh_nd->nd_root.ndm_saddr, sizeof(sin)); + sin.sin_port = htons(IPPORT_TFTP); /* * Set send buffer, prepare the TFTP packet @@ -251,7 +253,7 @@ tftproot_getfile(struct tftproot_handle m_clget(m_outbuf, M_WAIT); m_outbuf->m_len = packetlen; m_outbuf->m_pkthdr.len = packetlen; - m_outbuf->m_pkthdr.rcvif = NULL; + m_reset_rcvif(m_outbuf); tftp = mtod(m_outbuf, struct tftphdr *); memset(tftp, 0, packetlen); @@ -265,9 +267,8 @@ tftproot_getfile(struct tftproot_handle /* * Perform the file transfer */ - sin = (struct sockaddr_in *)&trh->trh_nd->nd_root.ndm_saddr; printf("tftproot: download %s:%s ", - inet_ntoa(sin->sin_addr), trh->trh_nd->nd_bootfile); + inet_ntoa(sin.sin_addr), trh->trh_nd->nd_bootfile); do { /* @@ -284,7 +285,7 @@ tftproot_getfile(struct tftproot_handle * We get the sender address here, which should be * the same server with a different port */ - if ((error = nfs_boot_sendrecv(so, m_serv, NULL, m_outbuf, + if ((error = nfs_boot_sendrecv(so, &sin, NULL, m_outbuf, tftproot_recv, NULL, &m_serv, trh, l)) != 0) { DPRINTF(("%s():%d sendrecv failed %d\n", __func__, __LINE__, error)); @@ -292,7 +293,7 @@ tftproot_getfile(struct tftproot_handle } /* - * Accomodate the packet length for acks. + * Accommodate the packet length for acks. * This is really needed only on first pass */ m_outbuf->m_len = hdrlen; @@ -313,16 +314,16 @@ tftproot_getfile(struct tftproot_handle printf("\n"); /* - * Ack the last block. so_send frees m_outbuf, therefore - * we do not want to free it ourselves. - * Ignore errors, as we already have the whole file. + * Ack the last block. Ignore errors, as we already have the whole + * file. */ - if ((error = (*so->so_send)(so, m_serv, NULL, + if ((error = (*so->so_send)(so, mtod(m_serv, struct sockaddr *), NULL, m_outbuf, NULL, 0, l)) != 0) DPRINTF(("%s():%d tftproot: sosend returned %d\n", __func__, __LINE__, error)); - else - m_outbuf = NULL; + + /* Freed by the protocol */ + m_outbuf = NULL; /* * And use it as the root ramdisk. @@ -330,7 +331,6 @@ tftproot_getfile(struct tftproot_handle DPRINTF(("%s():%d RAMdisk loaded: %ld@%p\n", __func__, __LINE__, trh->trh_len, trh->trh_base)); md_root_setconf(trh->trh_base, trh->trh_len); - mdattach(0); error = 0; out: @@ -347,10 +347,11 @@ out: } static int -tftproot_recv(struct mbuf *m, void *ctx) +tftproot_recv(struct mbuf **mp, void *ctx) { struct tftproot_handle *trh = ctx; struct tftphdr *tftp; + struct mbuf *m = *mp; size_t newlen; size_t hdrlen = sizeof(*tftp) - sizeof(tftp->th_data); @@ -377,7 +378,7 @@ tftproot_recv(struct mbuf *m, void *ctx) * Examine the TFTP header */ if (m->m_len > sizeof(*tftp)) { - if ((m = m_pullup(m, sizeof(*tftp))) == NULL) { + if ((m = *mp = m_pullup(m, sizeof(*tftp))) == NULL) { DPRINTF(("%s():%d m_pullup failed\n", __func__, __LINE__)); return -1; @@ -437,7 +438,7 @@ tftproot_recv(struct mbuf *m, void *ctx) } /* - * Grow the receiving buffer to accomodate new data + * Grow the receiving buffer to accommodate new data */ newlen = trh->trh_len + (m->m_pkthdr.len - hdrlen); if ((trh->trh_base = realloc(trh->trh_base,