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 <net/if_types.h>
68 #include <net/if_dl.h>
71 #include <nfs/nfsproto.h>
72 #include <nfsclient/nfs.h>
73 #include <nfs/nfsdiskless.h>
75 #include <nfs/xdr_subs.h>
78 #define BOOTP_MIN_LEN 300 /* Minimum size of bootp udp packet */
80 #ifndef BOOTP_SETTLE_DELAY
81 #define BOOTP_SETTLE_DELAY 3
85 * What is the longest we will wait before re-sending a request?
86 * Note this is also the frequency of "RPC timeout" messages.
87 * The re-send loop count sup linearly to this maximum, so the
88 * first complaint will happen after (1+2+3+4+5)=15 seconds.
90 #define MAX_RESEND_DELAY 5 /* seconds */
92 /* Definitions from RFC951 */
101 struct in_addr ciaddr;
102 struct in_addr yiaddr;
103 struct in_addr siaddr;
104 struct in_addr giaddr;
105 unsigned char chaddr[16];
108 unsigned char vend[1222];
111 struct bootpc_ifcontext {
112 struct bootpc_ifcontext *next;
113 struct bootp_packet call;
114 struct bootp_packet reply;
120 struct sockaddr_dl *sdl;
121 struct sockaddr_in myaddr;
122 struct sockaddr_in netmask;
123 struct sockaddr_in gw;
124 struct sockaddr_in broadcast; /* Different for each interface */
140 int dhcpquerytype; /* dhcp type sent */
141 struct in_addr dhcpserver;
145 #define TAG_MAXLEN 1024
146 struct bootpc_tagcontext {
147 char buf[TAG_MAXLEN + 1];
155 struct bootpc_globalcontext {
156 struct bootpc_ifcontext *interfaces;
157 struct bootpc_ifcontext *lastinterface;
164 struct bootp_packet reply;
166 struct bootpc_ifcontext *setrootfs;
167 struct bootpc_ifcontext *sethostname;
168 struct bootpc_tagcontext tmptag;
169 struct bootpc_tagcontext tag;
172 #define IPPORT_BOOTPC 68
173 #define IPPORT_BOOTPS 67
175 #define BOOTP_REQUEST 1
176 #define BOOTP_REPLY 2
179 #define TAG_PAD 0 /* Pad option, implicit length 1 */
180 #define TAG_SUBNETMASK 1 /* RFC 950 subnet mask */
181 #define TAG_ROUTERS 3 /* Routers (in order of preference) */
182 #define TAG_HOSTNAME 12 /* Client host name */
183 #define TAG_ROOT 17 /* Root path */
185 /* DHCP specific tags */
186 #define TAG_OVERLOAD 52 /* Option Overload */
187 #define TAG_MAXMSGSIZE 57 /* Maximum DHCP Message Size */
189 #define TAG_END 255 /* End Option (i.e. no more options) */
191 /* Overload values */
192 #define OVERLOAD_FILE 1
193 #define OVERLOAD_SNAME 2
195 /* Site specific tags: */
196 #define TAG_ROOTOPTS 130
197 #define TAG_COOKIE 134 /* ascii info for userland, via sysctl */
199 #define TAG_DHCP_MSGTYPE 53
200 #define TAG_DHCP_REQ_ADDR 50
201 #define TAG_DHCP_SERVERID 54
202 #define TAG_DHCP_LEASETIME 51
204 #define TAG_VENDOR_INDENTIFIER 60
207 #define DHCP_DISCOVER 1
209 #define DHCP_REQUEST 3
212 /* NFS read/write block size */
213 #ifndef BOOTP_BLOCKSIZE
214 #define BOOTP_BLOCKSIZE 8192
217 static char bootp_cookie[128];
218 SYSCTL_STRING(_kern, OID_AUTO, bootp_cookie, CTLFLAG_RD,
219 bootp_cookie, 0, "Cookie (T134) supplied by bootp server");
222 static int md_mount(struct sockaddr_in *mdsin, char *path, u_char *fhp,
223 int *fhsizep, struct nfs_args *args, struct thread *td);
224 static int setfs(struct sockaddr_in *addr, char *path, char *p,
225 const struct in_addr *siaddr);
226 static int getdec(char **ptr);
227 static int getip(char **ptr, struct in_addr *ip);
228 static void mountopts(struct nfs_args *args, char *p);
229 static int xdr_opaque_decode(struct mbuf **ptr, u_char *buf, int len);
230 static int xdr_int_decode(struct mbuf **ptr, int *iptr);
231 static void print_in_addr(struct in_addr addr);
232 static void print_sin_addr(struct sockaddr_in *addr);
233 static void clear_sinaddr(struct sockaddr_in *sin);
234 static void allocifctx(struct bootpc_globalcontext *gctx);
235 static void bootpc_compose_query(struct bootpc_ifcontext *ifctx,
236 struct bootpc_globalcontext *gctx, struct thread *td);
237 static unsigned char *bootpc_tag(struct bootpc_tagcontext *tctx,
238 struct bootp_packet *bp, int len, int tag);
239 static void bootpc_tag_helper(struct bootpc_tagcontext *tctx,
240 unsigned char *start, int len, int tag);
243 void bootpboot_p_sa(struct sockaddr *sa, struct sockaddr *ma);
244 void bootpboot_p_rtentry(struct rtentry *rt);
245 void bootpboot_p_tree(struct radix_node *rn);
246 void bootpboot_p_rtlist(void);
247 void bootpboot_p_if(struct ifnet *ifp, struct ifaddr *ifa);
248 void bootpboot_p_iflist(void);
251 static int bootpc_call(struct bootpc_globalcontext *gctx,
254 static int bootpc_fakeup_interface(struct bootpc_ifcontext *ifctx,
255 struct bootpc_globalcontext *gctx, struct thread *td);
257 static int bootpc_adjust_interface(struct bootpc_ifcontext *ifctx,
258 struct bootpc_globalcontext *gctx, struct thread *td);
260 static void bootpc_decode_reply(struct nfsv3_diskless *nd,
261 struct bootpc_ifcontext *ifctx,
262 struct bootpc_globalcontext *gctx);
264 static int bootpc_received(struct bootpc_globalcontext *gctx,
265 struct bootpc_ifcontext *ifctx);
267 static __inline int bootpc_ifctx_isresolved(struct bootpc_ifcontext *ifctx);
268 static __inline int bootpc_ifctx_isunresolved(struct bootpc_ifcontext *ifctx);
269 static __inline int bootpc_ifctx_isfailed(struct bootpc_ifcontext *ifctx);
272 * In order to have multiple active interfaces with address 0.0.0.0
273 * and be able to send data to a selected interface, we perform
276 * - The 'broadcast' address is different for each interface.
278 * - We temporarily add routing pointing 255.255.255.255 to the
279 * selected interface broadcast address, thus the packet sent
280 * goes to that interface.
285 bootpboot_p_sa(struct sockaddr *sa, struct sockaddr *ma)
289 printf("(sockaddr *) <null>");
292 switch (sa->sa_family) {
295 struct sockaddr_in *sin;
297 sin = (struct sockaddr_in *) sa;
301 sin = (struct sockaddr_in *) ma;
309 struct sockaddr_dl *sli;
312 sli = (struct sockaddr_dl *) sa;
313 printf("link %.*s ", sli->sdl_nlen, sli->sdl_data);
314 for (i = 0; i < sli->sdl_alen; i++) {
317 printf("%x", ((unsigned char *) LLADDR(sli))[i]);
322 printf("af%d", sa->sa_family);
327 bootpboot_p_rtentry(struct rtentry *rt)
330 bootpboot_p_sa(rt_key(rt), rt_mask(rt));
332 bootpboot_p_sa(rt->rt_gateway, NULL);
334 printf("flags %x", (unsigned short) rt->rt_flags);
335 printf(" %d", (int) rt->rt_rmx.rmx_expire);
336 printf(" %s\n", rt->rt_ifp->if_xname);
340 bootpboot_p_tree(struct radix_node *rn)
344 if (rn->rn_bit < 0) {
345 if ((rn->rn_flags & RNF_ROOT) != 0) {
347 bootpboot_p_rtentry((struct rtentry *) rn);
349 rn = rn->rn_dupedkey;
351 bootpboot_p_tree(rn->rn_left);
352 bootpboot_p_tree(rn->rn_right);
359 bootpboot_p_rtlist(void)
361 struct radix_node_head *rnh;
363 printf("Routing table:\n");
364 rnh = rt_tables_get_rnh(0, AF_INET);
367 RADIX_NODE_HEAD_RLOCK(rnh); /* could sleep XXX */
368 bootpboot_p_tree(rnh->rnh_treetop);
369 RADIX_NODE_HEAD_RUNLOCK(rnh);
373 bootpboot_p_if(struct ifnet *ifp, struct ifaddr *ifa)
376 printf("%s flags %x, addr ",
377 ifp->if_xname, ifp->if_flags);
378 print_sin_addr((struct sockaddr_in *) ifa->ifa_addr);
379 printf(", broadcast ");
380 print_sin_addr((struct sockaddr_in *) ifa->ifa_dstaddr);
381 printf(", netmask ");
382 print_sin_addr((struct sockaddr_in *) ifa->ifa_netmask);
387 bootpboot_p_iflist(void)
392 printf("Interface list:\n");
394 for (ifp = TAILQ_FIRST(&V_ifnet);
396 ifp = TAILQ_NEXT(ifp, if_link)) {
397 for (ifa = TAILQ_FIRST(&ifp->if_addrhead);
399 ifa = TAILQ_NEXT(ifa, ifa_link))
400 if (ifa->ifa_addr->sa_family == AF_INET)
401 bootpboot_p_if(ifp, ifa);
405 #endif /* defined(BOOTP_DEBUG) */
408 clear_sinaddr(struct sockaddr_in *sin)
411 bzero(sin, sizeof(*sin));
412 sin->sin_len = sizeof(*sin);
413 sin->sin_family = AF_INET;
414 sin->sin_addr.s_addr = INADDR_ANY; /* XXX: htonl(INAADDR_ANY) ? */
419 allocifctx(struct bootpc_globalcontext *gctx)
421 struct bootpc_ifcontext *ifctx;
422 ifctx = (struct bootpc_ifcontext *) malloc(sizeof(*ifctx),
423 M_TEMP, M_WAITOK | M_ZERO);
425 panic("Failed to allocate bootp interface context structure");
427 ifctx->xid = gctx->xid;
429 ifctx->state = IF_BOOTP_UNRESOLVED;
431 ifctx->state = IF_DHCP_UNRESOLVED;
434 if (gctx->interfaces != NULL)
435 gctx->lastinterface->next = ifctx;
437 gctx->interfaces = ifctx;
438 gctx->lastinterface = ifctx;
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)
574 struct sockaddr_in *sin, dst;
578 int error, on, rcvflg, timo, len;
582 struct bootpc_ifcontext *ifctx;
589 * Create socket and set its recieve timeout.
591 error = socreate(AF_INET, &so, SOCK_DGRAM, 0, td->td_ucred, td);
597 bzero(&sopt, sizeof(sopt));
598 sopt.sopt_dir = SOPT_SET;
599 sopt.sopt_level = SOL_SOCKET;
600 sopt.sopt_name = SO_RCVTIMEO;
602 sopt.sopt_valsize = sizeof tv;
604 error = sosetopt(so, &sopt);
612 sopt.sopt_name = SO_BROADCAST;
614 sopt.sopt_valsize = sizeof on;
616 error = sosetopt(so, &sopt);
625 sopt.sopt_name = SO_DONTROUTE;
627 sopt.sopt_valsize = sizeof on;
629 error = sosetopt(so, &sopt);
634 * Bind the local endpoint to a bootp client port.
638 sin->sin_port = htons(IPPORT_BOOTPC);
639 error = sobind(so, (struct sockaddr *)sin, td);
641 printf("bind failed\n");
646 * Setup socket address for the server.
650 sin->sin_addr.s_addr = INADDR_BROADCAST;
651 sin->sin_port = htons(IPPORT_BOOTPS);
654 * Send it, repeatedly, until a reply is received,
655 * but delay each re-send by an increasing amount.
656 * If the delay hits the maximum, start complaining.
665 for (ifctx = gctx->interfaces;
667 ifctx = ifctx->next) {
668 if (bootpc_ifctx_isresolved(ifctx) != 0 &&
669 bootpc_tag(&gctx->tmptag, &ifctx->reply,
675 for (ifctx = gctx->interfaces;
677 ifctx = ifctx->next) {
678 ifctx->outstanding = 0;
679 if (bootpc_ifctx_isresolved(ifctx) != 0 &&
683 if (bootpc_ifctx_isfailed(ifctx) != 0)
687 ifctx->outstanding = 1;
689 /* Proceed to next step in DHCP negotiation */
690 if ((ifctx->state == IF_DHCP_OFFERED &&
691 ifctx->dhcpquerytype != DHCP_REQUEST) ||
692 (ifctx->state == IF_DHCP_UNRESOLVED &&
693 ifctx->dhcpquerytype != DHCP_DISCOVER) ||
694 (ifctx->state == IF_BOOTP_UNRESOLVED &&
695 ifctx->dhcpquerytype != DHCP_NOMSG)) {
697 bootpc_compose_query(ifctx, gctx, td);
700 /* Send BOOTP request (or re-send). */
702 if (ifctx->sentmsg == 0) {
703 switch(ifctx->dhcpquerytype) {
715 printf("Sending %s packet from "
716 "interface %s (%*D)\n",
718 ifctx->ireq.ifr_name,
719 ifctx->sdl->sdl_alen,
720 (unsigned char *) LLADDR(ifctx->sdl),
725 aio.iov_base = (caddr_t) &ifctx->call;
726 aio.iov_len = sizeof(ifctx->call);
730 auio.uio_segflg = UIO_SYSSPACE;
731 auio.uio_rw = UIO_WRITE;
733 auio.uio_resid = sizeof(ifctx->call);
736 /* Set netmask to 0.0.0.0 */
738 sin = (struct sockaddr_in *) &ifctx->ireq.ifr_addr;
740 error = ifioctl(ifctx->so, SIOCSIFNETMASK,
741 (caddr_t) &ifctx->ireq, td);
744 "set if netmask, error=%d",
747 error = sosend(so, (struct sockaddr *) &dst,
748 &auio, NULL, NULL, 0, td);
750 printf("bootpc_call: sosend: %d state %08x\n",
751 error, (int) so->so_state);
754 /* XXX: Is this needed ? */
755 pause("bootpw", hz/10);
757 /* Set netmask to 255.0.0.0 */
759 sin = (struct sockaddr_in *) &ifctx->ireq.ifr_addr;
761 sin->sin_addr.s_addr = htonl(0xff000000u);
762 error = ifioctl(ifctx->so, SIOCSIFNETMASK,
763 (caddr_t) &ifctx->ireq, td);
766 "set if netmask, error=%d",
771 if (outstanding == 0 &&
772 (rtimo == 0 || time_second >= rtimo)) {
777 /* Determine new timeout. */
778 if (timo < MAX_RESEND_DELAY)
781 printf("DHCP/BOOTP timeout for server ");
782 print_sin_addr(&dst);
787 * Wait for up to timo seconds for a reply.
788 * The socket receive timeout was set to 1 second.
790 atimo = timo + time_second;
791 while (time_second < atimo) {
792 aio.iov_base = (caddr_t) &gctx->reply;
793 aio.iov_len = sizeof(gctx->reply);
797 auio.uio_segflg = UIO_SYSSPACE;
798 auio.uio_rw = UIO_READ;
800 auio.uio_resid = sizeof(gctx->reply);
804 error = soreceive(so, NULL, &auio,
805 NULL, NULL, &rcvflg);
806 gctx->secs = time_second - gctx->starttime;
807 for (ifctx = gctx->interfaces;
809 ifctx = ifctx->next) {
810 if (bootpc_ifctx_isresolved(ifctx) != 0 ||
811 bootpc_ifctx_isfailed(ifctx) != 0)
814 ifctx->call.secs = htons(gctx->secs);
816 if (error == EWOULDBLOCK)
820 len = sizeof(gctx->reply) - auio.uio_resid;
822 /* Do we have the required number of bytes ? */
823 if (len < BOOTP_MIN_LEN)
825 gctx->replylen = len;
828 if (gctx->reply.op != BOOTP_REPLY)
831 /* Is this an answer to our query */
832 for (ifctx = gctx->interfaces;
834 ifctx = ifctx->next) {
835 if (gctx->reply.xid != ifctx->call.xid)
838 /* Same HW address size ? */
839 if (gctx->reply.hlen != ifctx->call.hlen)
842 /* Correct HW address ? */
843 if (bcmp(gctx->reply.chaddr,
845 ifctx->call.hlen) != 0)
852 s = bootpc_tag(&gctx->tmptag,
865 s = "DHCP (unexpected)";
871 printf("Received %s packet"
874 ifctx->ireq.ifr_name);
875 print_in_addr(gctx->reply.siaddr);
876 if (gctx->reply.giaddr.s_addr !=
879 print_in_addr(gctx->reply.giaddr);
881 if (bootpc_received(gctx, ifctx) != 0) {
882 printf(" (accepted)");
883 if (ifctx->outstanding) {
884 ifctx->outstanding = 0;
887 /* Network settle delay */
888 if (outstanding == 0)
889 atimo = time_second +
892 printf(" (ignored)");
893 if (ifctx->gotrootpath) {
895 rtimo = time_second +
897 printf(" (got root path)");
899 printf(" (no root path)");
904 if (gctx->secs > BOOTP_TIMEOUT && BOOTP_TIMEOUT > 0)
907 /* Force a retry if halfway in DHCP negotiation */
909 for (ifctx = gctx->interfaces; ifctx != NULL;
910 ifctx = ifctx->next) {
911 if (ifctx->state == IF_DHCP_OFFERED) {
912 if (ifctx->dhcpquerytype == DHCP_DISCOVER)
915 ifctx->state = IF_DHCP_UNRESOLVED;
922 if (gotrootpath != 0) {
923 gctx->gotrootpath = gotrootpath;
924 if (rtimo != 0 && time_second >= rtimo)
927 } /* forever send/receive */
930 * XXX: These are errors of varying seriousness being silently
934 for (ifctx = gctx->interfaces; ifctx != NULL; ifctx = ifctx->next) {
935 if (bootpc_ifctx_isresolved(ifctx) == 0) {
936 printf("%s timeout for interface %s\n",
937 ifctx->dhcpquerytype != DHCP_NOMSG ?
939 ifctx->ireq.ifr_name);
942 if (gctx->gotrootpath != 0) {
944 printf("Got a root path, ignoring remaining timeout\n");
949 #ifndef BOOTP_NFSROOT
950 for (ifctx = gctx->interfaces; ifctx != NULL; ifctx = ifctx->next) {
951 if (bootpc_ifctx_isresolved(ifctx) != 0) {
968 bootpc_fakeup_interface(struct bootpc_ifcontext *ifctx,
969 struct bootpc_globalcontext *gctx, struct thread *td)
971 struct sockaddr_in *sin;
976 struct sockaddr_dl *sdl;
978 error = socreate(AF_INET, &ifctx->so, SOCK_DGRAM, 0, td->td_ucred, td);
980 panic("nfs_boot: socreate, error=%d", error);
986 * Bring up the interface.
988 * Get the old interface flags and or IFF_UP into them; if
989 * IFF_UP set blindly, interface selection can be clobbered.
991 error = ifioctl(so, SIOCGIFFLAGS, (caddr_t)ireq, td);
993 panic("bootpc_fakeup_interface: GIFFLAGS, error=%d", error);
994 ireq->ifr_flags |= IFF_UP;
995 error = ifioctl(so, SIOCSIFFLAGS, (caddr_t)ireq, td);
997 panic("bootpc_fakeup_interface: SIFFLAGS, error=%d", error);
1000 * Do enough of ifconfig(8) so that the chosen interface
1001 * can talk to the servers. (just set the address)
1004 /* addr is 0.0.0.0 */
1006 sin = (struct sockaddr_in *) &ireq->ifr_addr;
1008 error = ifioctl(so, SIOCSIFADDR, (caddr_t) ireq, td);
1009 if (error != 0 && (error != EEXIST || ifctx == gctx->interfaces))
1010 panic("bootpc_fakeup_interface: "
1011 "set if addr, error=%d", error);
1013 /* netmask is 255.0.0.0 */
1015 sin = (struct sockaddr_in *) &ireq->ifr_addr;
1017 sin->sin_addr.s_addr = htonl(0xff000000u);
1018 error = ifioctl(so, SIOCSIFNETMASK, (caddr_t)ireq, td);
1020 panic("bootpc_fakeup_interface: set if netmask, error=%d",
1023 /* Broadcast is 255.255.255.255 */
1025 sin = (struct sockaddr_in *)&ireq->ifr_addr;
1027 clear_sinaddr(&ifctx->broadcast);
1028 sin->sin_addr.s_addr = htonl(INADDR_BROADCAST);
1029 ifctx->broadcast.sin_addr.s_addr = sin->sin_addr.s_addr;
1031 error = ifioctl(so, SIOCSIFBRDADDR, (caddr_t)ireq, td);
1033 panic("bootpc_fakeup_interface: "
1034 "set if broadcast addr, error=%d",
1037 /* Get HW address */
1040 TAILQ_FOREACH(ifa, &ifctx->ifp->if_addrhead, ifa_link)
1041 if (ifa->ifa_addr->sa_family == AF_LINK) {
1042 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
1043 if (sdl->sdl_type == IFT_ETHER)
1048 panic("bootpc: Unable to find HW address for %s",
1049 ifctx->ireq.ifr_name);
1057 bootpc_adjust_interface(struct bootpc_ifcontext *ifctx,
1058 struct bootpc_globalcontext *gctx, struct thread *td)
1061 struct sockaddr_in defdst;
1062 struct sockaddr_in defmask;
1063 struct sockaddr_in *sin;
1066 struct sockaddr_in *myaddr;
1067 struct sockaddr_in *netmask;
1068 struct sockaddr_in *gw;
1070 ireq = &ifctx->ireq;
1072 myaddr = &ifctx->myaddr;
1073 netmask = &ifctx->netmask;
1076 if (bootpc_ifctx_isresolved(ifctx) == 0) {
1078 /* Shutdown interfaces where BOOTP failed */
1080 printf("Shutdown interface %s\n", ifctx->ireq.ifr_name);
1081 error = ifioctl(so, SIOCGIFFLAGS, (caddr_t)ireq, td);
1083 panic("bootpc_adjust_interface: "
1084 "SIOCGIFFLAGS, error=%d", error);
1085 ireq->ifr_flags &= ~IFF_UP;
1086 error = ifioctl(so, SIOCSIFFLAGS, (caddr_t)ireq, td);
1088 panic("bootpc_adjust_interface: "
1089 "SIOCSIFFLAGS, error=%d", error);
1091 sin = (struct sockaddr_in *) &ireq->ifr_addr;
1093 error = ifioctl(so, SIOCDIFADDR, (caddr_t) ireq, td);
1094 if (error != 0 && (error != EEXIST ||
1095 ifctx == gctx->interfaces))
1096 panic("bootpc_adjust_interface: "
1097 "SIOCDIFADDR, error=%d", error);
1102 printf("Adjusted interface %s\n", ifctx->ireq.ifr_name);
1104 * Do enough of ifconfig(8) so that the chosen interface
1105 * can talk to the servers. (just set the address)
1107 bcopy(netmask, &ireq->ifr_addr, sizeof(*netmask));
1108 error = ifioctl(so, SIOCSIFNETMASK, (caddr_t) ireq, td);
1110 panic("bootpc_adjust_interface: "
1111 "set if netmask, error=%d", error);
1113 /* Broadcast is with host part of IP address all 1's */
1115 sin = (struct sockaddr_in *) &ireq->ifr_addr;
1117 sin->sin_addr.s_addr = myaddr->sin_addr.s_addr |
1118 ~ netmask->sin_addr.s_addr;
1119 error = ifioctl(so, SIOCSIFBRDADDR, (caddr_t) ireq, td);
1121 panic("bootpc_adjust_interface: "
1122 "set if broadcast addr, error=%d", error);
1124 bcopy(myaddr, &ireq->ifr_addr, sizeof(*myaddr));
1125 error = ifioctl(so, SIOCSIFADDR, (caddr_t) ireq, td);
1126 if (error != 0 && (error != EEXIST || ifctx == gctx->interfaces))
1127 panic("bootpc_adjust_interface: "
1128 "set if addr, error=%d", error);
1130 /* Add new default route */
1132 if (ifctx->gotgw != 0 || gctx->gotgw == 0) {
1133 clear_sinaddr(&defdst);
1134 clear_sinaddr(&defmask);
1135 /* XXX MRT just table 0 */
1136 error = rtrequest_fib(RTM_ADD,
1137 (struct sockaddr *) &defdst, (struct sockaddr *) gw,
1138 (struct sockaddr *) &defmask,
1139 (RTF_UP | RTF_GATEWAY | RTF_STATIC), NULL, RT_DEFAULT_FIB);
1141 printf("bootpc_adjust_interface: "
1142 "add net route, error=%d\n", error);
1151 setfs(struct sockaddr_in *addr, char *path, char *p,
1152 const struct in_addr *siaddr)
1155 if (getip(&p, &addr->sin_addr) == 0) {
1156 if (siaddr != NULL && *p == '/')
1157 bcopy(siaddr, &addr->sin_addr, sizeof(struct in_addr));
1166 addr->sin_len = sizeof(struct sockaddr_in);
1167 addr->sin_family = AF_INET;
1169 strlcpy(path, p, MNAMELEN);
1174 getip(char **ptr, struct in_addr *addr)
1182 if (((val = getdec(&p)) < 0) || (val > 255))
1188 if (((val = getdec(&p)) < 0) || (val > 255))
1194 if (((val = getdec(&p)) < 0) || (val > 255))
1200 if (((val = getdec(&p)) < 0) || (val > 255))
1204 addr->s_addr = htonl(ip);
1217 if ((*p < '0') || (*p > '9'))
1219 while ((*p >= '0') && (*p <= '9')) {
1220 ret = ret * 10 + (*p - '0');
1228 mountopts(struct nfs_args *args, char *p)
1230 args->version = NFS_ARGSVERSION;
1231 args->rsize = BOOTP_BLOCKSIZE;
1232 args->wsize = BOOTP_BLOCKSIZE;
1233 args->flags = NFSMNT_RSIZE | NFSMNT_WSIZE | NFSMNT_RESVPORT;
1234 args->sotype = SOCK_DGRAM;
1236 nfs_parse_options(p, args);
1240 xdr_opaque_decode(struct mbuf **mptr, u_char *buf, int len)
1246 alignedlen = ( len + 3 ) & ~3;
1248 if (m->m_len < alignedlen) {
1249 m = m_pullup(m, alignedlen);
1255 bcopy(mtod(m, u_char *), buf, len);
1256 m_adj(m, alignedlen);
1262 xdr_int_decode(struct mbuf **mptr, int *iptr)
1266 if (xdr_opaque_decode(mptr, (u_char *) &i, sizeof(u_int32_t)) != 0)
1268 *iptr = fxdr_unsigned(u_int32_t, i);
1273 print_sin_addr(struct sockaddr_in *sin)
1276 print_in_addr(sin->sin_addr);
1280 print_in_addr(struct in_addr addr)
1284 ip = ntohl(addr.s_addr);
1285 printf("%d.%d.%d.%d",
1286 ip >> 24, (ip >> 16) & 255, (ip >> 8) & 255, ip & 255);
1290 bootpc_compose_query(struct bootpc_ifcontext *ifctx,
1291 struct bootpc_globalcontext *gctx, struct thread *td)
1293 unsigned char *vendp;
1294 unsigned char vendor_client[64];
1296 uint8_t vendor_client_len;
1298 ifctx->gotrootpath = 0;
1300 bzero((caddr_t) &ifctx->call, sizeof(ifctx->call));
1303 ifctx->call.op = BOOTP_REQUEST; /* BOOTREQUEST */
1304 ifctx->call.htype = 1; /* 10mb ethernet */
1305 ifctx->call.hlen = ifctx->sdl->sdl_alen;/* Hardware address length */
1306 ifctx->call.hops = 0;
1307 if (bootpc_ifctx_isunresolved(ifctx) != 0)
1309 ifctx->call.xid = txdr_unsigned(ifctx->xid);
1310 bcopy(LLADDR(ifctx->sdl), &ifctx->call.chaddr, ifctx->sdl->sdl_alen);
1312 vendp = ifctx->call.vend;
1313 *vendp++ = 99; /* RFC1048 cookie */
1317 *vendp++ = TAG_MAXMSGSIZE;
1319 *vendp++ = (sizeof(struct bootp_packet) >> 8) & 255;
1320 *vendp++ = sizeof(struct bootp_packet) & 255;
1322 snprintf(vendor_client, sizeof(vendor_client), "%s:%s:%s",
1323 ostype, MACHINE, osrelease);
1324 vendor_client_len = strlen(vendor_client);
1325 *vendp++ = TAG_VENDOR_INDENTIFIER;
1326 *vendp++ = vendor_client_len;
1327 memcpy(vendp, vendor_client, vendor_client_len);
1328 vendp += vendor_client_len;
1329 ifctx->dhcpquerytype = DHCP_NOMSG;
1330 switch (ifctx->state) {
1331 case IF_DHCP_UNRESOLVED:
1332 *vendp++ = TAG_DHCP_MSGTYPE;
1334 *vendp++ = DHCP_DISCOVER;
1335 ifctx->dhcpquerytype = DHCP_DISCOVER;
1336 ifctx->gotdhcpserver = 0;
1338 case IF_DHCP_OFFERED:
1339 *vendp++ = TAG_DHCP_MSGTYPE;
1341 *vendp++ = DHCP_REQUEST;
1342 ifctx->dhcpquerytype = DHCP_REQUEST;
1343 *vendp++ = TAG_DHCP_REQ_ADDR;
1345 memcpy(vendp, &ifctx->reply.yiaddr, 4);
1347 if (ifctx->gotdhcpserver != 0) {
1348 *vendp++ = TAG_DHCP_SERVERID;
1350 memcpy(vendp, &ifctx->dhcpserver, 4);
1353 *vendp++ = TAG_DHCP_LEASETIME;
1355 leasetime = htonl(300);
1356 memcpy(vendp, &leasetime, 4);
1364 ifctx->call.secs = 0;
1365 ifctx->call.flags = htons(0x8000); /* We need a broadcast answer */
1369 bootpc_hascookie(struct bootp_packet *bp)
1372 return (bp->vend[0] == 99 && bp->vend[1] == 130 &&
1373 bp->vend[2] == 83 && bp->vend[3] == 99);
1377 bootpc_tag_helper(struct bootpc_tagcontext *tctx,
1378 unsigned char *start, int len, int tag)
1384 if (tctx->badtag != 0 || tctx->badopt != 0)
1392 if (code == TAG_PAD)
1394 if (code == TAG_END)
1396 if (j >= ej || j + *j + 1 > ej) {
1402 if (tctx->taglen + len > TAG_MAXLEN) {
1408 memcpy(tctx->buf + tctx->taglen,
1410 tctx->taglen += len;
1412 if (code == TAG_OVERLOAD)
1413 tctx->overload = *j;
1419 static unsigned char *
1420 bootpc_tag(struct bootpc_tagcontext *tctx,
1421 struct bootp_packet *bp, int len, int tag)
1429 if (bootpc_hascookie(bp) == 0)
1432 bootpc_tag_helper(tctx, &bp->vend[4],
1433 (unsigned char *) bp + len - &bp->vend[4], tag);
1435 if ((tctx->overload & OVERLOAD_FILE) != 0)
1436 bootpc_tag_helper(tctx,
1437 (unsigned char *) bp->file,
1440 if ((tctx->overload & OVERLOAD_SNAME) != 0)
1441 bootpc_tag_helper(tctx,
1442 (unsigned char *) bp->sname,
1446 if (tctx->badopt != 0 || tctx->badtag != 0 || tctx->foundopt == 0)
1448 tctx->buf[tctx->taglen] = '\0';
1453 bootpc_decode_reply(struct nfsv3_diskless *nd, struct bootpc_ifcontext *ifctx,
1454 struct bootpc_globalcontext *gctx)
1460 ifctx->gotnetmask = 0;
1462 clear_sinaddr(&ifctx->myaddr);
1463 clear_sinaddr(&ifctx->netmask);
1464 clear_sinaddr(&ifctx->gw);
1466 ifctx->myaddr.sin_addr = ifctx->reply.yiaddr;
1468 ip = ntohl(ifctx->myaddr.sin_addr.s_addr);
1470 printf("%s at ", ifctx->ireq.ifr_name);
1471 print_sin_addr(&ifctx->myaddr);
1473 print_in_addr(ifctx->reply.siaddr);
1475 ifctx->gw.sin_addr = ifctx->reply.giaddr;
1476 if (ifctx->reply.giaddr.s_addr != htonl(INADDR_ANY)) {
1477 printf(" via gateway ");
1478 print_in_addr(ifctx->reply.giaddr);
1481 /* This call used for the side effect (overload flag) */
1482 (void) bootpc_tag(&gctx->tmptag,
1483 &ifctx->reply, ifctx->replylen, TAG_END);
1485 if ((gctx->tmptag.overload & OVERLOAD_SNAME) == 0)
1486 if (ifctx->reply.sname[0] != '\0')
1487 printf(" server name %s", ifctx->reply.sname);
1488 if ((gctx->tmptag.overload & OVERLOAD_FILE) == 0)
1489 if (ifctx->reply.file[0] != '\0')
1490 printf(" boot file %s", ifctx->reply.file);
1494 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
1497 if (gctx->tag.taglen != 4)
1498 panic("bootpc: subnet mask len is %d",
1500 bcopy(p, &ifctx->netmask.sin_addr, 4);
1501 ifctx->gotnetmask = 1;
1502 printf("subnet mask ");
1503 print_sin_addr(&ifctx->netmask);
1507 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
1511 if (gctx->tag.taglen % 4)
1512 panic("bootpc: Router Len is %d", gctx->tag.taglen);
1513 if (gctx->tag.taglen > 0) {
1514 bcopy(p, &ifctx->gw.sin_addr, 4);
1516 print_sin_addr(&ifctx->gw);
1523 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
1526 if (gctx->setrootfs != NULL) {
1527 printf("rootfs %s (ignored) ", p);
1528 } else if (setfs(&nd->root_saddr,
1529 nd->root_hostnam, p, &ifctx->reply.siaddr)) {
1531 printf("root_server ");
1532 print_sin_addr(&nd->root_saddr);
1535 printf("rootfs %s ", p);
1536 gctx->gotrootpath = 1;
1537 ifctx->gotrootpath = 1;
1538 gctx->setrootfs = ifctx;
1540 p = bootpc_tag(&gctx->tag, &ifctx->reply,
1544 mountopts(&nd->root_args, p);
1545 printf("rootopts %s ", p);
1548 panic("Failed to set rootfs to %s", p);
1551 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
1554 if (gctx->tag.taglen >= MAXHOSTNAMELEN)
1555 panic("bootpc: hostname >= %d bytes",
1557 if (gctx->sethostname != NULL) {
1558 printf("hostname %s (ignored) ", p);
1560 strcpy(nd->my_hostnam, p);
1561 mtx_lock(&prison0.pr_mtx);
1562 strcpy(prison0.pr_hostname, p);
1563 mtx_unlock(&prison0.pr_mtx);
1564 printf("hostname %s ", p);
1565 gctx->sethostname = ifctx;
1568 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
1570 if (p != NULL) { /* store in a sysctl variable */
1571 int i, l = sizeof(bootp_cookie) - 1;
1572 for (i = 0; i < l && p[i] != '\0'; i++)
1573 bootp_cookie[i] = p[i];
1580 if (ifctx->gotnetmask == 0) {
1581 if (IN_CLASSA(ntohl(ifctx->myaddr.sin_addr.s_addr)))
1582 ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSA_NET);
1583 else if (IN_CLASSB(ntohl(ifctx->myaddr.sin_addr.s_addr)))
1584 ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSB_NET);
1586 ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSC_NET);
1588 if (ifctx->gotgw == 0) {
1590 ifctx->gw.sin_addr.s_addr = ifctx->myaddr.sin_addr.s_addr;
1597 struct bootpc_ifcontext *ifctx, *nctx; /* Interface BOOTP contexts */
1598 struct bootpc_globalcontext *gctx; /* Global BOOTP context */
1601 #ifndef BOOTP_WIRED_TO
1604 struct nfsv3_diskless *nd;
1607 nd = &nfsv3_diskless;
1611 * If already filled in, don't touch it here
1613 if (nfs_diskless_valid != 0)
1616 gctx = malloc(sizeof(*gctx), M_TEMP, M_WAITOK | M_ZERO);
1618 panic("Failed to allocate bootp global context structure");
1620 gctx->xid = ~0xFFFF;
1621 gctx->starttime = time_second;
1624 * Find a network interface.
1626 CURVNET_SET(TD_TO_VNET(td));
1627 #ifdef BOOTP_WIRED_TO
1628 printf("bootpc_init: wired to interface '%s'\n",
1629 __XSTRING(BOOTP_WIRED_TO));
1633 * Preallocate interface context storage, if another interface
1634 * attaches and wins the race, it won't be eligible for bootp.
1637 for (ifp = TAILQ_FIRST(&V_ifnet), ifcnt = 0;
1639 ifp = TAILQ_NEXT(ifp, if_link)) {
1640 if ((ifp->if_flags &
1641 (IFF_LOOPBACK | IFF_POINTOPOINT | IFF_BROADCAST)) !=
1648 panic("bootpc_init: no eligible interfaces");
1649 for (; ifcnt > 0; ifcnt--)
1654 for (ifp = TAILQ_FIRST(&V_ifnet), ifctx = gctx->interfaces;
1655 ifp != NULL && ifctx != NULL;
1656 ifp = TAILQ_NEXT(ifp, if_link)) {
1657 strlcpy(ifctx->ireq.ifr_name, ifp->if_xname,
1658 sizeof(ifctx->ireq.ifr_name));
1659 #ifdef BOOTP_WIRED_TO
1660 if (strcmp(ifctx->ireq.ifr_name,
1661 __XSTRING(BOOTP_WIRED_TO)) != 0)
1664 if ((ifp->if_flags &
1665 (IFF_LOOPBACK | IFF_POINTOPOINT | IFF_BROADCAST)) !=
1670 ifctx = ifctx->next;
1675 if (gctx->interfaces == NULL || gctx->interfaces->ifp == NULL) {
1676 #ifdef BOOTP_WIRED_TO
1677 panic("bootpc_init: Could not find interface specified "
1678 "by BOOTP_WIRED_TO: "
1679 __XSTRING(BOOTP_WIRED_TO));
1681 panic("bootpc_init: no suitable interface");
1685 for (ifctx = gctx->interfaces; ifctx != NULL; ifctx = ifctx->next)
1686 bootpc_fakeup_interface(ifctx, gctx, td);
1688 for (ifctx = gctx->interfaces; ifctx != NULL; ifctx = ifctx->next)
1689 bootpc_compose_query(ifctx, gctx, td);
1691 error = bootpc_call(gctx, td);
1694 #ifdef BOOTP_NFSROOT
1695 panic("BOOTP call failed");
1697 printf("BOOTP call failed\n");
1701 rootdevnames[0] = "nfs:";
1703 rootdevnames[1] = "oldnfs:";
1705 mountopts(&nd->root_args, NULL);
1707 for (ifctx = gctx->interfaces; ifctx != NULL; ifctx = ifctx->next)
1708 if (bootpc_ifctx_isresolved(ifctx) != 0)
1709 bootpc_decode_reply(nd, ifctx, gctx);
1711 #ifdef BOOTP_NFSROOT
1712 if (gctx->gotrootpath == 0)
1713 panic("bootpc: No root path offered");
1716 for (ifctx = gctx->interfaces; ifctx != NULL; ifctx = ifctx->next) {
1717 bootpc_adjust_interface(ifctx, gctx, td);
1722 for (ifctx = gctx->interfaces; ifctx != NULL; ifctx = ifctx->next)
1723 if (ifctx->gotrootpath != 0)
1725 if (ifctx == NULL) {
1726 for (ifctx = gctx->interfaces;
1728 ifctx = ifctx->next)
1729 if (bootpc_ifctx_isresolved(ifctx) != 0)
1735 if (gctx->gotrootpath != 0) {
1737 setenv("boot.netif.name", ifctx->ifp->if_xname);
1739 error = md_mount(&nd->root_saddr, nd->root_hostnam,
1740 nd->root_fh, &nd->root_fhsize,
1741 &nd->root_args, td);
1743 panic("nfs_boot: mountd root, error=%d", error);
1745 nfs_diskless_valid = 3;
1748 strcpy(nd->myif.ifra_name, ifctx->ireq.ifr_name);
1749 bcopy(&ifctx->myaddr, &nd->myif.ifra_addr, sizeof(ifctx->myaddr));
1750 bcopy(&ifctx->myaddr, &nd->myif.ifra_broadaddr, sizeof(ifctx->myaddr));
1751 ((struct sockaddr_in *) &nd->myif.ifra_broadaddr)->sin_addr.s_addr =
1752 ifctx->myaddr.sin_addr.s_addr |
1753 ~ ifctx->netmask.sin_addr.s_addr;
1754 bcopy(&ifctx->netmask, &nd->myif.ifra_mask, sizeof(ifctx->netmask));
1757 for (ifctx = gctx->interfaces; ifctx != NULL; ifctx = nctx) {
1759 free(ifctx, M_TEMP);
1766 * Given a server pathname, get an NFS file handle.
1767 * Also, sets sin->sin_port to the NFS service port.
1770 md_mount(struct sockaddr_in *mdsin, char *path, u_char *fhp, int *fhsizep,
1771 struct nfs_args *args, struct thread *td)
1779 #define RPCPROG_MNT 100005
1780 #define RPCMNT_VER1 1
1781 #define RPCMNT_VER3 3
1782 #define RPCMNT_MOUNT 1
1783 #define AUTH_SYS 1 /* unix style (uid, gids) */
1784 #define AUTH_UNIX AUTH_SYS
1786 /* XXX honor v2/v3 flags in args->flags? */
1788 /* First try NFS v3 */
1789 /* Get port number for MOUNTD. */
1790 error = krpc_portmap(mdsin, RPCPROG_MNT, RPCMNT_VER3,
1791 &mdsin->sin_port, td);
1793 m = xdr_string_encode(path, strlen(path));
1795 /* Do RPC to mountd. */
1796 error = krpc_call(mdsin, RPCPROG_MNT, RPCMNT_VER3,
1797 RPCMNT_MOUNT, &m, NULL, td);
1800 args->flags |= NFSMNT_NFSV3;
1803 /* Fallback to NFS v2 */
1805 /* Get port number for MOUNTD. */
1806 error = krpc_portmap(mdsin, RPCPROG_MNT, RPCMNT_VER1,
1807 &mdsin->sin_port, td);
1811 m = xdr_string_encode(path, strlen(path));
1813 /* Do RPC to mountd. */
1814 error = krpc_call(mdsin, RPCPROG_MNT, RPCMNT_VER1,
1815 RPCMNT_MOUNT, &m, NULL, td);
1817 return error; /* message already freed */
1823 if (xdr_int_decode(&m, &error) != 0 || error != 0)
1826 if ((args->flags & NFSMNT_NFSV3) != 0) {
1827 if (xdr_int_decode(&m, fhsizep) != 0 ||
1828 *fhsizep > NFSX_V3FHMAX ||
1832 *fhsizep = NFSX_V2FH;
1834 if (xdr_opaque_decode(&m, fhp, *fhsizep) != 0)
1837 if (args->flags & NFSMNT_NFSV3) {
1838 if (xdr_int_decode(&m, &authcount) != 0)
1841 if (authcount < 0 || authcount > 100)
1843 while (authcount > 0) {
1844 if (xdr_int_decode(&m, &authver) != 0)
1846 if (authver == AUTH_UNIX)
1850 if (authunixok == 0)
1854 /* Set port number for NFS use. */
1855 error = krpc_portmap(mdsin, NFS_PROG,
1857 NFSMNT_NFSV3) ? NFS_VER3 : NFS_VER2,
1858 &mdsin->sin_port, td);
1870 SYSINIT(bootp_rootconf, SI_SUB_ROOT_CONF, SI_ORDER_FIRST, bootpc_init, NULL);