2 * Copyright (c) 1995 Gordon Ross, Adam Glass
3 * Copyright (c) 1992 Regents of the University of California.
6 * This software was developed by the Computer Systems Engineering group
7 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
8 * contributed to Berkeley.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Lawrence Berkeley Laboratory and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * $NetBSD: krpc_subr.c,v 1.10 1995/08/08 20:43:43 gwr Exp $
43 #include <sys/cdefs.h>
44 __FBSDID("$FreeBSD$");
46 #include "opt_bootp.h"
49 #include <sys/param.h>
50 #include <sys/systm.h>
52 #include <sys/kernel.h>
53 #include <sys/sockio.h>
54 #include <sys/malloc.h>
55 #include <sys/mount.h>
58 #include <sys/socket.h>
59 #include <sys/socketvar.h>
60 #include <sys/sysctl.h>
64 #include <net/route.h>
66 #include <netinet/in.h>
67 #include <netinet/in_var.h>
68 #include <net/if_types.h>
69 #include <net/if_dl.h>
72 #include <nfs/nfsproto.h>
73 #include <nfsclient/nfs.h>
74 #include <nfs/nfsdiskless.h>
76 #include <nfs/xdr_subs.h>
79 #define BOOTP_MIN_LEN 300 /* Minimum size of bootp udp packet */
81 #ifndef BOOTP_SETTLE_DELAY
82 #define BOOTP_SETTLE_DELAY 3
86 * Wait 10 seconds for interface appearance
87 * USB ethernet adapters might require some time to pop up
89 #ifndef BOOTP_IFACE_WAIT_TIMEOUT
90 #define BOOTP_IFACE_WAIT_TIMEOUT 10
94 * What is the longest we will wait before re-sending a request?
95 * Note this is also the frequency of "RPC timeout" messages.
96 * The re-send loop count sup linearly to this maximum, so the
97 * first complaint will happen after (1+2+3+4+5)=15 seconds.
99 #define MAX_RESEND_DELAY 5 /* seconds */
101 /* Definitions from RFC951 */
102 struct bootp_packet {
110 struct in_addr ciaddr;
111 struct in_addr yiaddr;
112 struct in_addr siaddr;
113 struct in_addr giaddr;
114 unsigned char chaddr[16];
117 unsigned char vend[1222];
120 struct bootpc_ifcontext {
121 STAILQ_ENTRY(bootpc_ifcontext) next;
122 struct bootp_packet call;
123 struct bootp_packet reply;
128 struct in_aliasreq _in_alias_req;
130 #define ireq _req._ifreq
131 #define iareq _req._in_alias_req
133 struct sockaddr_dl *sdl;
134 struct sockaddr_in myaddr;
135 struct sockaddr_in netmask;
136 struct sockaddr_in gw;
152 int dhcpquerytype; /* dhcp type sent */
153 struct in_addr dhcpserver;
157 #define TAG_MAXLEN 1024
158 struct bootpc_tagcontext {
159 char buf[TAG_MAXLEN + 1];
167 struct bootpc_globalcontext {
168 STAILQ_HEAD(, bootpc_ifcontext) interfaces;
175 struct bootp_packet reply;
177 struct bootpc_ifcontext *setrootfs;
178 struct bootpc_ifcontext *sethostname;
179 struct bootpc_tagcontext tmptag;
180 struct bootpc_tagcontext tag;
183 #define IPPORT_BOOTPC 68
184 #define IPPORT_BOOTPS 67
186 #define BOOTP_REQUEST 1
187 #define BOOTP_REPLY 2
190 #define TAG_PAD 0 /* Pad option, implicit length 1 */
191 #define TAG_SUBNETMASK 1 /* RFC 950 subnet mask */
192 #define TAG_ROUTERS 3 /* Routers (in order of preference) */
193 #define TAG_HOSTNAME 12 /* Client host name */
194 #define TAG_ROOT 17 /* Root path */
196 /* DHCP specific tags */
197 #define TAG_OVERLOAD 52 /* Option Overload */
198 #define TAG_MAXMSGSIZE 57 /* Maximum DHCP Message Size */
200 #define TAG_END 255 /* End Option (i.e. no more options) */
202 /* Overload values */
203 #define OVERLOAD_FILE 1
204 #define OVERLOAD_SNAME 2
206 /* Site specific tags: */
207 #define TAG_ROOTOPTS 130
208 #define TAG_COOKIE 134 /* ascii info for userland, via sysctl */
210 #define TAG_DHCP_MSGTYPE 53
211 #define TAG_DHCP_REQ_ADDR 50
212 #define TAG_DHCP_SERVERID 54
213 #define TAG_DHCP_LEASETIME 51
215 #define TAG_VENDOR_INDENTIFIER 60
218 #define DHCP_DISCOVER 1
220 #define DHCP_REQUEST 3
223 /* NFS read/write block size */
224 #ifndef BOOTP_BLOCKSIZE
225 #define BOOTP_BLOCKSIZE 8192
228 static char bootp_cookie[128];
229 static struct socket *bootp_so;
230 SYSCTL_STRING(_kern, OID_AUTO, bootp_cookie, CTLFLAG_RD,
231 bootp_cookie, 0, "Cookie (T134) supplied by bootp server");
234 static int md_mount(struct sockaddr_in *mdsin, char *path, u_char *fhp,
235 int *fhsizep, struct nfs_args *args, struct thread *td);
236 static int setfs(struct sockaddr_in *addr, char *path, char *p,
237 const struct in_addr *siaddr);
238 static int getdec(char **ptr);
239 static int getip(char **ptr, struct in_addr *ip);
240 static void mountopts(struct nfs_args *args, char *p);
241 static int xdr_opaque_decode(struct mbuf **ptr, u_char *buf, int len);
242 static int xdr_int_decode(struct mbuf **ptr, int *iptr);
243 static void print_in_addr(struct in_addr addr);
244 static void print_sin_addr(struct sockaddr_in *addr);
245 static void clear_sinaddr(struct sockaddr_in *sin);
246 static void allocifctx(struct bootpc_globalcontext *gctx);
247 static void bootpc_compose_query(struct bootpc_ifcontext *ifctx,
249 static unsigned char *bootpc_tag(struct bootpc_tagcontext *tctx,
250 struct bootp_packet *bp, int len, int tag);
251 static void bootpc_tag_helper(struct bootpc_tagcontext *tctx,
252 unsigned char *start, int len, int tag);
255 void bootpboot_p_sa(struct sockaddr *sa, struct sockaddr *ma);
256 void bootpboot_p_rtentry(struct rtentry *rt);
257 void bootpboot_p_tree(struct radix_node *rn);
258 void bootpboot_p_rtlist(void);
259 void bootpboot_p_if(struct ifnet *ifp, struct ifaddr *ifa);
260 void bootpboot_p_iflist(void);
263 static int bootpc_call(struct bootpc_globalcontext *gctx,
266 static void bootpc_fakeup_interface(struct bootpc_ifcontext *ifctx,
269 static int bootpc_adjust_interface(struct bootpc_ifcontext *ifctx,
270 struct bootpc_globalcontext *gctx, struct thread *td);
272 static void bootpc_decode_reply(struct nfsv3_diskless *nd,
273 struct bootpc_ifcontext *ifctx,
274 struct bootpc_globalcontext *gctx);
276 static int bootpc_received(struct bootpc_globalcontext *gctx,
277 struct bootpc_ifcontext *ifctx);
279 static __inline int bootpc_ifctx_isresolved(struct bootpc_ifcontext *ifctx);
280 static __inline int bootpc_ifctx_isunresolved(struct bootpc_ifcontext *ifctx);
281 static __inline int bootpc_ifctx_isfailed(struct bootpc_ifcontext *ifctx);
284 * In order to have multiple active interfaces with address 0.0.0.0
285 * and be able to send data to a selected interface, we first set
286 * mask to /8 on all interfaces, and temporarily set it to /0 when
292 bootpboot_p_sa(struct sockaddr *sa, struct sockaddr *ma)
296 printf("(sockaddr *) <null>");
299 switch (sa->sa_family) {
302 struct sockaddr_in *sin;
304 sin = (struct sockaddr_in *) sa;
308 sin = (struct sockaddr_in *) ma;
316 struct sockaddr_dl *sli;
319 sli = (struct sockaddr_dl *) sa;
320 printf("link %.*s ", sli->sdl_nlen, sli->sdl_data);
321 for (i = 0; i < sli->sdl_alen; i++) {
324 printf("%x", ((unsigned char *) LLADDR(sli))[i]);
329 printf("af%d", sa->sa_family);
334 bootpboot_p_rtentry(struct rtentry *rt)
337 bootpboot_p_sa(rt_key(rt), rt_mask(rt));
339 bootpboot_p_sa(rt->rt_gateway, NULL);
341 printf("flags %x", (unsigned short) rt->rt_flags);
342 printf(" %d", (int) rt->rt_rmx.rmx_expire);
343 printf(" %s\n", rt->rt_ifp->if_xname);
347 bootpboot_p_tree(struct radix_node *rn)
351 if (rn->rn_bit < 0) {
352 if ((rn->rn_flags & RNF_ROOT) != 0) {
354 bootpboot_p_rtentry((struct rtentry *) rn);
356 rn = rn->rn_dupedkey;
358 bootpboot_p_tree(rn->rn_left);
359 bootpboot_p_tree(rn->rn_right);
366 bootpboot_p_rtlist(void)
368 struct radix_node_head *rnh;
370 printf("Routing table:\n");
371 rnh = rt_tables_get_rnh(0, AF_INET);
374 RADIX_NODE_HEAD_RLOCK(rnh); /* could sleep XXX */
375 bootpboot_p_tree(rnh->rnh_treetop);
376 RADIX_NODE_HEAD_RUNLOCK(rnh);
380 bootpboot_p_if(struct ifnet *ifp, struct ifaddr *ifa)
383 printf("%s flags %x, addr ",
384 ifp->if_xname, ifp->if_flags);
385 print_sin_addr((struct sockaddr_in *) ifa->ifa_addr);
386 printf(", broadcast ");
387 print_sin_addr((struct sockaddr_in *) ifa->ifa_dstaddr);
388 printf(", netmask ");
389 print_sin_addr((struct sockaddr_in *) ifa->ifa_netmask);
394 bootpboot_p_iflist(void)
399 printf("Interface list:\n");
401 for (ifp = TAILQ_FIRST(&V_ifnet);
403 ifp = TAILQ_NEXT(ifp, if_link)) {
404 for (ifa = TAILQ_FIRST(&ifp->if_addrhead);
406 ifa = TAILQ_NEXT(ifa, ifa_link))
407 if (ifa->ifa_addr->sa_family == AF_INET)
408 bootpboot_p_if(ifp, ifa);
412 #endif /* defined(BOOTP_DEBUG) */
415 clear_sinaddr(struct sockaddr_in *sin)
418 bzero(sin, sizeof(*sin));
419 sin->sin_len = sizeof(*sin);
420 sin->sin_family = AF_INET;
421 sin->sin_addr.s_addr = INADDR_ANY; /* XXX: htonl(INAADDR_ANY) ? */
426 allocifctx(struct bootpc_globalcontext *gctx)
428 struct bootpc_ifcontext *ifctx;
430 ifctx = malloc(sizeof(*ifctx), M_TEMP, M_WAITOK | M_ZERO);
431 ifctx->xid = gctx->xid;
433 ifctx->state = IF_BOOTP_UNRESOLVED;
435 ifctx->state = IF_DHCP_UNRESOLVED;
438 STAILQ_INSERT_TAIL(&gctx->interfaces, ifctx, next);
442 bootpc_ifctx_isresolved(struct bootpc_ifcontext *ifctx)
445 if (ifctx->state == IF_BOOTP_RESOLVED ||
446 ifctx->state == IF_DHCP_RESOLVED)
452 bootpc_ifctx_isunresolved(struct bootpc_ifcontext *ifctx)
455 if (ifctx->state == IF_BOOTP_UNRESOLVED ||
456 ifctx->state == IF_DHCP_UNRESOLVED)
462 bootpc_ifctx_isfailed(struct bootpc_ifcontext *ifctx)
465 if (ifctx->state == IF_BOOTP_FAILED ||
466 ifctx->state == IF_DHCP_FAILED)
472 bootpc_received(struct bootpc_globalcontext *gctx,
473 struct bootpc_ifcontext *ifctx)
475 unsigned char dhcpreplytype;
479 * Need timeout for fallback to less
480 * desirable alternative.
483 /* This call used for the side effect (badopt flag) */
484 (void) bootpc_tag(&gctx->tmptag, &gctx->reply,
488 /* If packet is invalid, ignore it */
489 if (gctx->tmptag.badopt != 0)
492 p = bootpc_tag(&gctx->tmptag, &gctx->reply,
493 gctx->replylen, TAG_DHCP_MSGTYPE);
497 dhcpreplytype = DHCP_NOMSG;
499 switch (ifctx->dhcpquerytype) {
501 if (dhcpreplytype != DHCP_OFFER /* Normal DHCP offer */
502 #ifndef BOOTP_FORCE_DHCP
503 && dhcpreplytype != DHCP_NOMSG /* Fallback to BOOTP */
509 if (dhcpreplytype != DHCP_ACK)
515 /* Ignore packet unless it gives us a root tag we didn't have */
517 if ((ifctx->state == IF_BOOTP_RESOLVED ||
518 (ifctx->dhcpquerytype == DHCP_DISCOVER &&
519 (ifctx->state == IF_DHCP_OFFERED ||
520 ifctx->state == IF_DHCP_RESOLVED))) &&
521 (bootpc_tag(&gctx->tmptag, &ifctx->reply,
524 bootpc_tag(&gctx->tmptag, &gctx->reply,
529 bcopy(&gctx->reply, &ifctx->reply, gctx->replylen);
530 ifctx->replylen = gctx->replylen;
532 /* XXX: Only reset if 'perfect' response */
533 if (ifctx->state == IF_BOOTP_UNRESOLVED)
534 ifctx->state = IF_BOOTP_RESOLVED;
535 else if (ifctx->state == IF_DHCP_UNRESOLVED &&
536 ifctx->dhcpquerytype == DHCP_DISCOVER) {
537 if (dhcpreplytype == DHCP_OFFER)
538 ifctx->state = IF_DHCP_OFFERED;
540 ifctx->state = IF_BOOTP_RESOLVED; /* Fallback */
541 } else if (ifctx->state == IF_DHCP_OFFERED &&
542 ifctx->dhcpquerytype == DHCP_REQUEST)
543 ifctx->state = IF_DHCP_RESOLVED;
546 if (ifctx->dhcpquerytype == DHCP_DISCOVER &&
547 ifctx->state != IF_BOOTP_RESOLVED) {
548 p = bootpc_tag(&gctx->tmptag, &ifctx->reply,
549 ifctx->replylen, TAG_DHCP_SERVERID);
550 if (p != NULL && gctx->tmptag.taglen == 4) {
551 memcpy(&ifctx->dhcpserver, p, 4);
552 ifctx->gotdhcpserver = 1;
554 ifctx->gotdhcpserver = 0;
558 ifctx->gotrootpath = (bootpc_tag(&gctx->tmptag, &ifctx->reply,
561 ifctx->gotgw = (bootpc_tag(&gctx->tmptag, &ifctx->reply,
563 TAG_ROUTERS) != NULL);
564 ifctx->gotnetmask = (bootpc_tag(&gctx->tmptag, &ifctx->reply,
566 TAG_SUBNETMASK) != NULL);
571 bootpc_call(struct bootpc_globalcontext *gctx, struct thread *td)
573 struct sockaddr_in *sin, dst;
577 int error, on, rcvflg, timo, len;
581 struct bootpc_ifcontext *ifctx;
589 bzero(&sopt, sizeof(sopt));
590 sopt.sopt_dir = SOPT_SET;
591 sopt.sopt_level = SOL_SOCKET;
592 sopt.sopt_name = SO_RCVTIMEO;
594 sopt.sopt_valsize = sizeof tv;
596 error = sosetopt(bootp_so, &sopt);
604 sopt.sopt_name = SO_BROADCAST;
606 sopt.sopt_valsize = sizeof on;
608 error = sosetopt(bootp_so, &sopt);
617 sopt.sopt_name = SO_DONTROUTE;
619 sopt.sopt_valsize = sizeof on;
621 error = sosetopt(bootp_so, &sopt);
626 * Bind the local endpoint to a bootp client port.
630 sin->sin_port = htons(IPPORT_BOOTPC);
631 error = sobind(bootp_so, (struct sockaddr *)sin, td);
633 printf("bind failed\n");
638 * Setup socket address for the server.
642 sin->sin_addr.s_addr = INADDR_BROADCAST;
643 sin->sin_port = htons(IPPORT_BOOTPS);
646 * Send it, repeatedly, until a reply is received,
647 * but delay each re-send by an increasing amount.
648 * If the delay hits the maximum, start complaining.
657 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) {
658 if (bootpc_ifctx_isresolved(ifctx) != 0 &&
659 bootpc_tag(&gctx->tmptag, &ifctx->reply,
665 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) {
666 struct in_aliasreq *ifra = &ifctx->iareq;
667 sin = (struct sockaddr_in *)&ifra->ifra_mask;
669 ifctx->outstanding = 0;
670 if (bootpc_ifctx_isresolved(ifctx) != 0 &&
674 if (bootpc_ifctx_isfailed(ifctx) != 0)
678 ifctx->outstanding = 1;
680 /* Proceed to next step in DHCP negotiation */
681 if ((ifctx->state == IF_DHCP_OFFERED &&
682 ifctx->dhcpquerytype != DHCP_REQUEST) ||
683 (ifctx->state == IF_DHCP_UNRESOLVED &&
684 ifctx->dhcpquerytype != DHCP_DISCOVER) ||
685 (ifctx->state == IF_BOOTP_UNRESOLVED &&
686 ifctx->dhcpquerytype != DHCP_NOMSG)) {
688 bootpc_compose_query(ifctx, td);
691 /* Send BOOTP request (or re-send). */
693 if (ifctx->sentmsg == 0) {
694 switch(ifctx->dhcpquerytype) {
706 printf("Sending %s packet from "
707 "interface %s (%*D)\n",
709 ifctx->ireq.ifr_name,
710 ifctx->sdl->sdl_alen,
711 (unsigned char *) LLADDR(ifctx->sdl),
716 aio.iov_base = (caddr_t) &ifctx->call;
717 aio.iov_len = sizeof(ifctx->call);
721 auio.uio_segflg = UIO_SYSSPACE;
722 auio.uio_rw = UIO_WRITE;
724 auio.uio_resid = sizeof(ifctx->call);
727 /* Set netmask to 0.0.0.0 */
729 error = ifioctl(bootp_so, SIOCAIFADDR, (caddr_t)ifra,
732 panic("%s: SIOCAIFADDR, error=%d", __func__,
735 error = sosend(bootp_so, (struct sockaddr *) &dst,
736 &auio, NULL, NULL, 0, td);
738 printf("%s: sosend: %d state %08x\n", __func__,
739 error, (int )bootp_so->so_state);
741 /* Set netmask to 255.0.0.0 */
742 sin->sin_addr.s_addr = htonl(IN_CLASSA_NET);
743 error = ifioctl(bootp_so, SIOCAIFADDR, (caddr_t)ifra,
746 panic("%s: SIOCAIFADDR, error=%d", __func__,
750 if (outstanding == 0 &&
751 (rtimo == 0 || time_second >= rtimo)) {
756 /* Determine new timeout. */
757 if (timo < MAX_RESEND_DELAY)
760 printf("DHCP/BOOTP timeout for server ");
761 print_sin_addr(&dst);
766 * Wait for up to timo seconds for a reply.
767 * The socket receive timeout was set to 1 second.
769 atimo = timo + time_second;
770 while (time_second < atimo) {
771 aio.iov_base = (caddr_t) &gctx->reply;
772 aio.iov_len = sizeof(gctx->reply);
776 auio.uio_segflg = UIO_SYSSPACE;
777 auio.uio_rw = UIO_READ;
779 auio.uio_resid = sizeof(gctx->reply);
783 error = soreceive(bootp_so, NULL, &auio,
784 NULL, NULL, &rcvflg);
785 gctx->secs = time_second - gctx->starttime;
786 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) {
787 if (bootpc_ifctx_isresolved(ifctx) != 0 ||
788 bootpc_ifctx_isfailed(ifctx) != 0)
791 ifctx->call.secs = htons(gctx->secs);
793 if (error == EWOULDBLOCK)
797 len = sizeof(gctx->reply) - auio.uio_resid;
799 /* Do we have the required number of bytes ? */
800 if (len < BOOTP_MIN_LEN)
802 gctx->replylen = len;
805 if (gctx->reply.op != BOOTP_REPLY)
808 /* Is this an answer to our query */
809 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) {
810 if (gctx->reply.xid != ifctx->call.xid)
813 /* Same HW address size ? */
814 if (gctx->reply.hlen != ifctx->call.hlen)
817 /* Correct HW address ? */
818 if (bcmp(gctx->reply.chaddr,
820 ifctx->call.hlen) != 0)
827 s = bootpc_tag(&gctx->tmptag,
840 s = "DHCP (unexpected)";
846 printf("Received %s packet"
849 ifctx->ireq.ifr_name);
850 print_in_addr(gctx->reply.siaddr);
851 if (gctx->reply.giaddr.s_addr !=
854 print_in_addr(gctx->reply.giaddr);
856 if (bootpc_received(gctx, ifctx) != 0) {
857 printf(" (accepted)");
858 if (ifctx->outstanding) {
859 ifctx->outstanding = 0;
862 /* Network settle delay */
863 if (outstanding == 0)
864 atimo = time_second +
867 printf(" (ignored)");
868 if (ifctx->gotrootpath) {
870 rtimo = time_second +
872 printf(" (got root path)");
874 printf(" (no root path)");
879 if (gctx->secs > BOOTP_TIMEOUT && BOOTP_TIMEOUT > 0)
882 /* Force a retry if halfway in DHCP negotiation */
884 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
885 if (ifctx->state == IF_DHCP_OFFERED) {
886 if (ifctx->dhcpquerytype == DHCP_DISCOVER)
889 ifctx->state = IF_DHCP_UNRESOLVED;
895 if (gotrootpath != 0) {
896 gctx->gotrootpath = gotrootpath;
897 if (rtimo != 0 && time_second >= rtimo)
900 } /* forever send/receive */
903 * XXX: These are errors of varying seriousness being silently
907 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
908 if (bootpc_ifctx_isresolved(ifctx) == 0) {
909 printf("%s timeout for interface %s\n",
910 ifctx->dhcpquerytype != DHCP_NOMSG ?
912 ifctx->ireq.ifr_name);
915 if (gctx->gotrootpath != 0) {
917 printf("Got a root path, ignoring remaining timeout\n");
922 #ifndef BOOTP_NFSROOT
923 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
924 if (bootpc_ifctx_isresolved(ifctx) != 0) {
936 bootpc_fakeup_interface(struct bootpc_ifcontext *ifctx, struct thread *td)
939 struct in_aliasreq *ifra;
940 struct sockaddr_in *sin;
944 ifra = &ifctx->iareq;
947 * Bring up the interface.
949 * Get the old interface flags and or IFF_UP into them; if
950 * IFF_UP set blindly, interface selection can be clobbered.
952 error = ifioctl(bootp_so, SIOCGIFFLAGS, (caddr_t)ifr, td);
954 panic("%s: SIOCGIFFLAGS, error=%d", __func__, error);
955 ifr->ifr_flags |= IFF_UP;
956 error = ifioctl(bootp_so, SIOCSIFFLAGS, (caddr_t)ifr, td);
958 panic("%s: SIOCSIFFLAGS, error=%d", __func__, error);
961 * Do enough of ifconfig(8) so that the chosen interface
962 * can talk to the servers. Set address to 0.0.0.0/8 and
963 * broadcast address to local broadcast.
965 sin = (struct sockaddr_in *)&ifra->ifra_addr;
967 sin = (struct sockaddr_in *)&ifra->ifra_mask;
969 sin->sin_addr.s_addr = htonl(IN_CLASSA_NET);
970 sin = (struct sockaddr_in *)&ifra->ifra_broadaddr;
972 sin->sin_addr.s_addr = htonl(INADDR_BROADCAST);
973 error = ifioctl(bootp_so, SIOCAIFADDR, (caddr_t)ifra, td);
975 panic("%s: SIOCAIFADDR, error=%d", __func__, error);
979 bootpc_shutdown_interface(struct bootpc_ifcontext *ifctx, struct thread *td)
982 struct sockaddr_in *sin;
987 printf("Shutdown interface %s\n", ifctx->ireq.ifr_name);
988 error = ifioctl(bootp_so, SIOCGIFFLAGS, (caddr_t)ifr, td);
990 panic("%s: SIOCGIFFLAGS, error=%d", __func__, error);
991 ifr->ifr_flags &= ~IFF_UP;
992 error = ifioctl(bootp_so, SIOCSIFFLAGS, (caddr_t)ifr, td);
994 panic("%s: SIOCSIFFLAGS, error=%d", __func__, error);
996 sin = (struct sockaddr_in *) &ifr->ifr_addr;
998 error = ifioctl(bootp_so, SIOCDIFADDR, (caddr_t) ifr, td);
1000 panic("%s: SIOCDIFADDR, error=%d", __func__, error);
1004 bootpc_adjust_interface(struct bootpc_ifcontext *ifctx,
1005 struct bootpc_globalcontext *gctx, struct thread *td)
1008 struct sockaddr_in defdst;
1009 struct sockaddr_in defmask;
1010 struct sockaddr_in *sin;
1012 struct in_aliasreq *ifra;
1013 struct sockaddr_in *myaddr;
1014 struct sockaddr_in *netmask;
1015 struct sockaddr_in *gw;
1018 ifra = &ifctx->iareq;
1019 myaddr = &ifctx->myaddr;
1020 netmask = &ifctx->netmask;
1023 if (bootpc_ifctx_isresolved(ifctx) == 0) {
1024 /* Shutdown interfaces where BOOTP failed */
1025 bootpc_shutdown_interface(ifctx, td);
1029 printf("Adjusted interface %s\n", ifctx->ireq.ifr_name);
1031 * Do enough of ifconfig(8) so that the chosen interface
1032 * can talk to the servers. (just set the address)
1034 sin = (struct sockaddr_in *) &ifr->ifr_addr;
1036 error = ifioctl(bootp_so, SIOCDIFADDR, (caddr_t) ifr, td);
1038 panic("%s: SIOCDIFADDR, error=%d", __func__, error);
1040 bcopy(myaddr, &ifra->ifra_addr, sizeof(*myaddr));
1041 bcopy(netmask, &ifra->ifra_mask, sizeof(*netmask));
1042 clear_sinaddr(&ifra->ifra_broadaddr);
1043 ifra->ifra_broadaddr.sin_addr.s_addr = myaddr->sin_addr.s_addr |
1044 ~netmask->sin_addr.s_addr;
1046 error = ifioctl(bootp_so, SIOCAIFADDR, (caddr_t)ifra, td);
1048 panic("%s: SIOCAIFADDR, error=%d", __func__, error);
1050 /* Add new default route */
1052 if (ifctx->gotgw != 0 || gctx->gotgw == 0) {
1053 clear_sinaddr(&defdst);
1054 clear_sinaddr(&defmask);
1055 /* XXX MRT just table 0 */
1056 error = rtrequest_fib(RTM_ADD,
1057 (struct sockaddr *) &defdst, (struct sockaddr *) gw,
1058 (struct sockaddr *) &defmask,
1059 (RTF_UP | RTF_GATEWAY | RTF_STATIC), NULL, RT_DEFAULT_FIB);
1061 printf("%s: RTM_ADD, error=%d\n", __func__, error);
1070 setfs(struct sockaddr_in *addr, char *path, char *p,
1071 const struct in_addr *siaddr)
1074 if (getip(&p, &addr->sin_addr) == 0) {
1075 if (siaddr != NULL && *p == '/')
1076 bcopy(siaddr, &addr->sin_addr, sizeof(struct in_addr));
1085 addr->sin_len = sizeof(struct sockaddr_in);
1086 addr->sin_family = AF_INET;
1088 strlcpy(path, p, MNAMELEN);
1093 getip(char **ptr, struct in_addr *addr)
1101 if (((val = getdec(&p)) < 0) || (val > 255))
1107 if (((val = getdec(&p)) < 0) || (val > 255))
1113 if (((val = getdec(&p)) < 0) || (val > 255))
1119 if (((val = getdec(&p)) < 0) || (val > 255))
1123 addr->s_addr = htonl(ip);
1136 if ((*p < '0') || (*p > '9'))
1138 while ((*p >= '0') && (*p <= '9')) {
1139 ret = ret * 10 + (*p - '0');
1147 mountopts(struct nfs_args *args, char *p)
1149 args->version = NFS_ARGSVERSION;
1150 args->rsize = BOOTP_BLOCKSIZE;
1151 args->wsize = BOOTP_BLOCKSIZE;
1152 args->flags = NFSMNT_RSIZE | NFSMNT_WSIZE | NFSMNT_RESVPORT;
1153 args->sotype = SOCK_DGRAM;
1155 nfs_parse_options(p, args);
1159 xdr_opaque_decode(struct mbuf **mptr, u_char *buf, int len)
1165 alignedlen = ( len + 3 ) & ~3;
1167 if (m->m_len < alignedlen) {
1168 m = m_pullup(m, alignedlen);
1174 bcopy(mtod(m, u_char *), buf, len);
1175 m_adj(m, alignedlen);
1181 xdr_int_decode(struct mbuf **mptr, int *iptr)
1185 if (xdr_opaque_decode(mptr, (u_char *) &i, sizeof(u_int32_t)) != 0)
1187 *iptr = fxdr_unsigned(u_int32_t, i);
1192 print_sin_addr(struct sockaddr_in *sin)
1195 print_in_addr(sin->sin_addr);
1199 print_in_addr(struct in_addr addr)
1203 ip = ntohl(addr.s_addr);
1204 printf("%d.%d.%d.%d",
1205 ip >> 24, (ip >> 16) & 255, (ip >> 8) & 255, ip & 255);
1209 bootpc_compose_query(struct bootpc_ifcontext *ifctx, struct thread *td)
1211 unsigned char *vendp;
1212 unsigned char vendor_client[64];
1214 uint8_t vendor_client_len;
1216 ifctx->gotrootpath = 0;
1218 bzero((caddr_t) &ifctx->call, sizeof(ifctx->call));
1221 ifctx->call.op = BOOTP_REQUEST; /* BOOTREQUEST */
1222 ifctx->call.htype = 1; /* 10mb ethernet */
1223 ifctx->call.hlen = ifctx->sdl->sdl_alen;/* Hardware address length */
1224 ifctx->call.hops = 0;
1225 if (bootpc_ifctx_isunresolved(ifctx) != 0)
1227 ifctx->call.xid = txdr_unsigned(ifctx->xid);
1228 bcopy(LLADDR(ifctx->sdl), &ifctx->call.chaddr, ifctx->sdl->sdl_alen);
1230 vendp = ifctx->call.vend;
1231 *vendp++ = 99; /* RFC1048 cookie */
1235 *vendp++ = TAG_MAXMSGSIZE;
1237 *vendp++ = (sizeof(struct bootp_packet) >> 8) & 255;
1238 *vendp++ = sizeof(struct bootp_packet) & 255;
1240 snprintf(vendor_client, sizeof(vendor_client), "%s:%s:%s",
1241 ostype, MACHINE, osrelease);
1242 vendor_client_len = strlen(vendor_client);
1243 *vendp++ = TAG_VENDOR_INDENTIFIER;
1244 *vendp++ = vendor_client_len;
1245 memcpy(vendp, vendor_client, vendor_client_len);
1246 vendp += vendor_client_len;
1247 ifctx->dhcpquerytype = DHCP_NOMSG;
1248 switch (ifctx->state) {
1249 case IF_DHCP_UNRESOLVED:
1250 *vendp++ = TAG_DHCP_MSGTYPE;
1252 *vendp++ = DHCP_DISCOVER;
1253 ifctx->dhcpquerytype = DHCP_DISCOVER;
1254 ifctx->gotdhcpserver = 0;
1256 case IF_DHCP_OFFERED:
1257 *vendp++ = TAG_DHCP_MSGTYPE;
1259 *vendp++ = DHCP_REQUEST;
1260 ifctx->dhcpquerytype = DHCP_REQUEST;
1261 *vendp++ = TAG_DHCP_REQ_ADDR;
1263 memcpy(vendp, &ifctx->reply.yiaddr, 4);
1265 if (ifctx->gotdhcpserver != 0) {
1266 *vendp++ = TAG_DHCP_SERVERID;
1268 memcpy(vendp, &ifctx->dhcpserver, 4);
1271 *vendp++ = TAG_DHCP_LEASETIME;
1273 leasetime = htonl(300);
1274 memcpy(vendp, &leasetime, 4);
1282 ifctx->call.secs = 0;
1283 ifctx->call.flags = htons(0x8000); /* We need a broadcast answer */
1287 bootpc_hascookie(struct bootp_packet *bp)
1290 return (bp->vend[0] == 99 && bp->vend[1] == 130 &&
1291 bp->vend[2] == 83 && bp->vend[3] == 99);
1295 bootpc_tag_helper(struct bootpc_tagcontext *tctx,
1296 unsigned char *start, int len, int tag)
1302 if (tctx->badtag != 0 || tctx->badopt != 0)
1310 if (code == TAG_PAD)
1312 if (code == TAG_END)
1314 if (j >= ej || j + *j + 1 > ej) {
1320 if (tctx->taglen + len > TAG_MAXLEN) {
1326 memcpy(tctx->buf + tctx->taglen,
1328 tctx->taglen += len;
1330 if (code == TAG_OVERLOAD)
1331 tctx->overload = *j;
1337 static unsigned char *
1338 bootpc_tag(struct bootpc_tagcontext *tctx,
1339 struct bootp_packet *bp, int len, int tag)
1347 if (bootpc_hascookie(bp) == 0)
1350 bootpc_tag_helper(tctx, &bp->vend[4],
1351 (unsigned char *) bp + len - &bp->vend[4], tag);
1353 if ((tctx->overload & OVERLOAD_FILE) != 0)
1354 bootpc_tag_helper(tctx,
1355 (unsigned char *) bp->file,
1358 if ((tctx->overload & OVERLOAD_SNAME) != 0)
1359 bootpc_tag_helper(tctx,
1360 (unsigned char *) bp->sname,
1364 if (tctx->badopt != 0 || tctx->badtag != 0 || tctx->foundopt == 0)
1366 tctx->buf[tctx->taglen] = '\0';
1371 bootpc_decode_reply(struct nfsv3_diskless *nd, struct bootpc_ifcontext *ifctx,
1372 struct bootpc_globalcontext *gctx)
1378 ifctx->gotnetmask = 0;
1380 clear_sinaddr(&ifctx->myaddr);
1381 clear_sinaddr(&ifctx->netmask);
1382 clear_sinaddr(&ifctx->gw);
1384 ifctx->myaddr.sin_addr = ifctx->reply.yiaddr;
1386 ip = ntohl(ifctx->myaddr.sin_addr.s_addr);
1388 printf("%s at ", ifctx->ireq.ifr_name);
1389 print_sin_addr(&ifctx->myaddr);
1391 print_in_addr(ifctx->reply.siaddr);
1393 ifctx->gw.sin_addr = ifctx->reply.giaddr;
1394 if (ifctx->reply.giaddr.s_addr != htonl(INADDR_ANY)) {
1395 printf(" via gateway ");
1396 print_in_addr(ifctx->reply.giaddr);
1399 /* This call used for the side effect (overload flag) */
1400 (void) bootpc_tag(&gctx->tmptag,
1401 &ifctx->reply, ifctx->replylen, TAG_END);
1403 if ((gctx->tmptag.overload & OVERLOAD_SNAME) == 0)
1404 if (ifctx->reply.sname[0] != '\0')
1405 printf(" server name %s", ifctx->reply.sname);
1406 if ((gctx->tmptag.overload & OVERLOAD_FILE) == 0)
1407 if (ifctx->reply.file[0] != '\0')
1408 printf(" boot file %s", ifctx->reply.file);
1412 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
1415 if (gctx->tag.taglen != 4)
1416 panic("bootpc: subnet mask len is %d",
1418 bcopy(p, &ifctx->netmask.sin_addr, 4);
1419 ifctx->gotnetmask = 1;
1420 printf("subnet mask ");
1421 print_sin_addr(&ifctx->netmask);
1425 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
1429 if (gctx->tag.taglen % 4)
1430 panic("bootpc: Router Len is %d", gctx->tag.taglen);
1431 if (gctx->tag.taglen > 0) {
1432 bcopy(p, &ifctx->gw.sin_addr, 4);
1434 print_sin_addr(&ifctx->gw);
1441 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
1444 if (gctx->setrootfs != NULL) {
1445 printf("rootfs %s (ignored) ", p);
1446 } else if (setfs(&nd->root_saddr,
1447 nd->root_hostnam, p, &ifctx->reply.siaddr)) {
1449 printf("root_server ");
1450 print_sin_addr(&nd->root_saddr);
1453 printf("rootfs %s ", p);
1454 gctx->gotrootpath = 1;
1455 ifctx->gotrootpath = 1;
1456 gctx->setrootfs = ifctx;
1458 p = bootpc_tag(&gctx->tag, &ifctx->reply,
1462 mountopts(&nd->root_args, p);
1463 printf("rootopts %s ", p);
1466 panic("Failed to set rootfs to %s", p);
1469 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
1472 if (gctx->tag.taglen >= MAXHOSTNAMELEN)
1473 panic("bootpc: hostname >= %d bytes",
1475 if (gctx->sethostname != NULL) {
1476 printf("hostname %s (ignored) ", p);
1478 strcpy(nd->my_hostnam, p);
1479 mtx_lock(&prison0.pr_mtx);
1480 strcpy(prison0.pr_hostname, p);
1481 mtx_unlock(&prison0.pr_mtx);
1482 printf("hostname %s ", p);
1483 gctx->sethostname = ifctx;
1486 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
1488 if (p != NULL) { /* store in a sysctl variable */
1489 int i, l = sizeof(bootp_cookie) - 1;
1490 for (i = 0; i < l && p[i] != '\0'; i++)
1491 bootp_cookie[i] = p[i];
1498 if (ifctx->gotnetmask == 0) {
1499 if (IN_CLASSA(ntohl(ifctx->myaddr.sin_addr.s_addr)))
1500 ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSA_NET);
1501 else if (IN_CLASSB(ntohl(ifctx->myaddr.sin_addr.s_addr)))
1502 ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSB_NET);
1504 ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSC_NET);
1506 if (ifctx->gotgw == 0) {
1508 ifctx->gw.sin_addr.s_addr = ifctx->myaddr.sin_addr.s_addr;
1515 struct bootpc_ifcontext *ifctx; /* Interface BOOTP contexts */
1516 struct bootpc_globalcontext *gctx; /* Global BOOTP context */
1518 struct sockaddr_dl *sdl;
1521 #ifndef BOOTP_WIRED_TO
1524 struct nfsv3_diskless *nd;
1529 timeout = BOOTP_IFACE_WAIT_TIMEOUT * hz;
1532 nd = &nfsv3_diskless;
1536 * If already filled in, don't touch it here
1538 if (nfs_diskless_valid != 0)
1541 gctx = malloc(sizeof(*gctx), M_TEMP, M_WAITOK | M_ZERO);
1542 STAILQ_INIT(&gctx->interfaces);
1543 gctx->xid = ~0xFFFF;
1544 gctx->starttime = time_second;
1547 * Find a network interface.
1549 CURVNET_SET(TD_TO_VNET(td));
1550 #ifdef BOOTP_WIRED_TO
1551 printf("%s: wired to interface '%s'\n", __func__,
1552 __XSTRING(BOOTP_WIRED_TO));
1556 * Preallocate interface context storage, if another interface
1557 * attaches and wins the race, it won't be eligible for bootp.
1561 TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
1562 if ((ifp->if_flags &
1563 (IFF_LOOPBACK | IFF_POINTOPOINT | IFF_BROADCAST)) !=
1566 switch (ifp->if_alloctype) {
1578 panic("%s: no eligible interfaces", __func__);
1579 for (; ifcnt > 0; ifcnt--)
1584 ifctx = STAILQ_FIRST(&gctx->interfaces);
1586 TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
1589 #ifdef BOOTP_WIRED_TO
1590 if (strcmp(ifp->if_xname, __XSTRING(BOOTP_WIRED_TO)) != 0)
1593 if ((ifp->if_flags &
1594 (IFF_LOOPBACK | IFF_POINTOPOINT | IFF_BROADCAST)) !=
1597 switch (ifp->if_alloctype) {
1606 strlcpy(ifctx->ireq.ifr_name, ifp->if_xname,
1607 sizeof(ifctx->ireq.ifr_name));
1610 /* Get HW address */
1612 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
1613 if (ifa->ifa_addr->sa_family == AF_LINK) {
1614 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
1615 if (sdl->sdl_type == IFT_ETHER)
1619 panic("bootpc: Unable to find HW address for %s",
1620 ifctx->ireq.ifr_name);
1623 ifctx = STAILQ_NEXT(ifctx, next);
1628 if (STAILQ_EMPTY(&gctx->interfaces) ||
1629 STAILQ_FIRST(&gctx->interfaces)->ifp == NULL) {
1631 pause("bootpc", delay);
1635 #ifdef BOOTP_WIRED_TO
1636 panic("%s: Could not find interface specified "
1637 "by BOOTP_WIRED_TO: "
1638 __XSTRING(BOOTP_WIRED_TO), __func__);
1640 panic("%s: no suitable interface", __func__);
1644 error = socreate(AF_INET, &bootp_so, SOCK_DGRAM, 0, td->td_ucred, td);
1646 panic("%s: socreate, error=%d", __func__, error);
1648 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
1649 bootpc_fakeup_interface(ifctx, td);
1651 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
1652 bootpc_compose_query(ifctx, td);
1654 error = bootpc_call(gctx, td);
1657 #ifdef BOOTP_NFSROOT
1658 panic("BOOTP call failed");
1660 printf("BOOTP call failed\n");
1664 rootdevnames[0] = "nfs:";
1666 rootdevnames[1] = "oldnfs:";
1668 mountopts(&nd->root_args, NULL);
1670 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
1671 if (bootpc_ifctx_isresolved(ifctx) != 0)
1672 bootpc_decode_reply(nd, ifctx, gctx);
1674 #ifdef BOOTP_NFSROOT
1675 if (gctx->gotrootpath == 0)
1676 panic("bootpc: No root path offered");
1679 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
1680 bootpc_adjust_interface(ifctx, gctx, td);
1684 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
1685 if (ifctx->gotrootpath != 0)
1687 if (ifctx == NULL) {
1688 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
1689 if (bootpc_ifctx_isresolved(ifctx) != 0)
1695 if (gctx->gotrootpath != 0) {
1697 setenv("boot.netif.name", ifctx->ifp->if_xname);
1699 error = md_mount(&nd->root_saddr, nd->root_hostnam,
1700 nd->root_fh, &nd->root_fhsize,
1701 &nd->root_args, td);
1703 panic("nfs_boot: mountd root, error=%d", error);
1705 nfs_diskless_valid = 3;
1708 strcpy(nd->myif.ifra_name, ifctx->ireq.ifr_name);
1709 bcopy(&ifctx->myaddr, &nd->myif.ifra_addr, sizeof(ifctx->myaddr));
1710 bcopy(&ifctx->myaddr, &nd->myif.ifra_broadaddr, sizeof(ifctx->myaddr));
1711 ((struct sockaddr_in *) &nd->myif.ifra_broadaddr)->sin_addr.s_addr =
1712 ifctx->myaddr.sin_addr.s_addr |
1713 ~ ifctx->netmask.sin_addr.s_addr;
1714 bcopy(&ifctx->netmask, &nd->myif.ifra_mask, sizeof(ifctx->netmask));
1717 while((ifctx = STAILQ_FIRST(&gctx->interfaces)) != NULL) {
1718 STAILQ_REMOVE_HEAD(&gctx->interfaces, next);
1719 free(ifctx, M_TEMP);
1726 * Given a server pathname, get an NFS file handle.
1727 * Also, sets sin->sin_port to the NFS service port.
1730 md_mount(struct sockaddr_in *mdsin, char *path, u_char *fhp, int *fhsizep,
1731 struct nfs_args *args, struct thread *td)
1739 #define RPCPROG_MNT 100005
1740 #define RPCMNT_VER1 1
1741 #define RPCMNT_VER3 3
1742 #define RPCMNT_MOUNT 1
1743 #define AUTH_SYS 1 /* unix style (uid, gids) */
1744 #define AUTH_UNIX AUTH_SYS
1746 /* XXX honor v2/v3 flags in args->flags? */
1748 /* First try NFS v3 */
1749 /* Get port number for MOUNTD. */
1750 error = krpc_portmap(mdsin, RPCPROG_MNT, RPCMNT_VER3,
1751 &mdsin->sin_port, td);
1753 m = xdr_string_encode(path, strlen(path));
1755 /* Do RPC to mountd. */
1756 error = krpc_call(mdsin, RPCPROG_MNT, RPCMNT_VER3,
1757 RPCMNT_MOUNT, &m, NULL, td);
1760 args->flags |= NFSMNT_NFSV3;
1763 /* Fallback to NFS v2 */
1765 /* Get port number for MOUNTD. */
1766 error = krpc_portmap(mdsin, RPCPROG_MNT, RPCMNT_VER1,
1767 &mdsin->sin_port, td);
1771 m = xdr_string_encode(path, strlen(path));
1773 /* Do RPC to mountd. */
1774 error = krpc_call(mdsin, RPCPROG_MNT, RPCMNT_VER1,
1775 RPCMNT_MOUNT, &m, NULL, td);
1777 return error; /* message already freed */
1783 if (xdr_int_decode(&m, &error) != 0 || error != 0)
1786 if ((args->flags & NFSMNT_NFSV3) != 0) {
1787 if (xdr_int_decode(&m, fhsizep) != 0 ||
1788 *fhsizep > NFSX_V3FHMAX ||
1792 *fhsizep = NFSX_V2FH;
1794 if (xdr_opaque_decode(&m, fhp, *fhsizep) != 0)
1797 if (args->flags & NFSMNT_NFSV3) {
1798 if (xdr_int_decode(&m, &authcount) != 0)
1801 if (authcount < 0 || authcount > 100)
1803 while (authcount > 0) {
1804 if (xdr_int_decode(&m, &authver) != 0)
1806 if (authver == AUTH_UNIX)
1810 if (authunixok == 0)
1814 /* Set port number for NFS use. */
1815 error = krpc_portmap(mdsin, NFS_PROG,
1817 NFSMNT_NFSV3) ? NFS_VER3 : NFS_VER2,
1818 &mdsin->sin_port, td);
1830 SYSINIT(bootp_rootconf, SI_SUB_ROOT_CONF, SI_ORDER_FIRST, bootpc_init, NULL);