1999-08-28 01:08:13 +00:00
|
|
|
/* $FreeBSD$ */
|
1997-05-11 18:05:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Gordon Ross, Adam Glass
|
|
|
|
* Copyright (c) 1992 Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by the Computer Systems Engineering group
|
|
|
|
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
|
|
|
* contributed to Berkeley.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Lawrence Berkeley Laboratory and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* based on:
|
|
|
|
* nfs/krpc_subr.c
|
|
|
|
* $NetBSD: krpc_subr.c,v 1.10 1995/08/08 20:43:43 gwr Exp $
|
|
|
|
*/
|
|
|
|
|
1998-01-09 03:21:07 +00:00
|
|
|
#include "opt_bootp.h"
|
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/sockio.h>
|
2000-10-29 01:19:32 +00:00
|
|
|
#include <sys/malloc.h>
|
1997-05-11 18:05:39 +00:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
1998-03-28 10:33:27 +00:00
|
|
|
#include <sys/uio.h>
|
1997-05-11 18:05:39 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
|
|
|
|
#include <nfs/rpcv2.h>
|
|
|
|
#include <nfs/nfsproto.h>
|
|
|
|
#include <nfs/nfs.h>
|
|
|
|
#include <nfs/nfsdiskless.h>
|
|
|
|
#include <nfs/krpc.h>
|
|
|
|
#include <nfs/xdr_subs.h>
|
|
|
|
|
|
|
|
|
1998-01-18 18:46:20 +00:00
|
|
|
#define BOOTP_MIN_LEN 300 /* Minimum size of bootp udp packet */
|
1997-05-11 18:05:39 +00:00
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
#ifndef BOOTP_SETTLE_DELAY
|
|
|
|
#define BOOTP_SETTLE_DELAY 3
|
|
|
|
#endif
|
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
/*
|
|
|
|
* What is the longest we will wait before re-sending a request?
|
|
|
|
* Note this is also the frequency of "RPC timeout" messages.
|
|
|
|
* The re-send loop count sup linearly to this maximum, so the
|
|
|
|
* first complaint will happen after (1+2+3+4+5)=15 seconds.
|
|
|
|
*/
|
|
|
|
#define MAX_RESEND_DELAY 5 /* seconds */
|
|
|
|
|
|
|
|
/* Definitions from RFC951 */
|
|
|
|
struct bootp_packet {
|
2000-10-24 22:40:18 +00:00
|
|
|
u_int8_t op;
|
|
|
|
u_int8_t htype;
|
|
|
|
u_int8_t hlen;
|
|
|
|
u_int8_t hops;
|
|
|
|
u_int32_t xid;
|
|
|
|
u_int16_t secs;
|
|
|
|
u_int16_t flags;
|
|
|
|
struct in_addr ciaddr;
|
|
|
|
struct in_addr yiaddr;
|
|
|
|
struct in_addr siaddr;
|
|
|
|
struct in_addr giaddr;
|
|
|
|
unsigned char chaddr[16];
|
|
|
|
char sname[64];
|
|
|
|
char file[128];
|
|
|
|
unsigned char vend[256];
|
1997-05-11 18:05:39 +00:00
|
|
|
};
|
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
struct bootpc_ifcontext {
|
|
|
|
struct bootpc_ifcontext *next;
|
|
|
|
struct bootp_packet call;
|
|
|
|
struct bootp_packet reply;
|
|
|
|
int replylen;
|
|
|
|
int overload;
|
|
|
|
struct socket *so;
|
|
|
|
struct ifreq ireq;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct sockaddr_dl *sdl;
|
|
|
|
struct sockaddr_in myaddr;
|
|
|
|
struct sockaddr_in netmask;
|
|
|
|
struct sockaddr_in gw;
|
|
|
|
struct sockaddr_in broadcast; /* Different for each interface */
|
|
|
|
int gotgw;
|
|
|
|
int gotnetmask;
|
|
|
|
int gotrootpath;
|
|
|
|
int outstanding;
|
|
|
|
int sentmsg;
|
|
|
|
u_int32_t xid;
|
|
|
|
enum {
|
|
|
|
IF_BOOTP_UNRESOLVED,
|
|
|
|
IF_BOOTP_RESOLVED,
|
|
|
|
IF_DHCP_OFFERED,
|
|
|
|
IF_DHCP_RESOLVED,
|
|
|
|
IF_BOOTP_FAILED
|
|
|
|
} state;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TAG_MAXLEN 1024
|
|
|
|
struct bootpc_tagcontext {
|
|
|
|
char buf[TAG_MAXLEN + 1];
|
|
|
|
int overload;
|
|
|
|
int badopt;
|
|
|
|
int badtag;
|
|
|
|
int foundopt;
|
|
|
|
int taglen;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bootpc_globalcontext {
|
|
|
|
struct bootpc_ifcontext *interfaces;
|
|
|
|
struct bootpc_ifcontext *lastinterface;
|
|
|
|
u_int32_t xid;
|
|
|
|
int gotrootpath;
|
|
|
|
int gotswappath;
|
|
|
|
int gotgw;
|
|
|
|
int ifnum;
|
|
|
|
int secs;
|
|
|
|
int starttime;
|
|
|
|
struct bootp_packet reply;
|
|
|
|
int replylen;
|
|
|
|
struct bootpc_ifcontext *setswapfs;
|
|
|
|
struct bootpc_ifcontext *setrootfs;
|
|
|
|
struct bootpc_ifcontext *sethostname;
|
|
|
|
char lookup_path[24];
|
|
|
|
struct bootpc_tagcontext tmptag;
|
|
|
|
struct bootpc_tagcontext tag;
|
|
|
|
};
|
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
#define IPPORT_BOOTPC 68
|
|
|
|
#define IPPORT_BOOTPS 67
|
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
#define BOOTP_REQUEST 1
|
|
|
|
#define BOOTP_REPLY 2
|
|
|
|
|
|
|
|
/* Common tags */
|
|
|
|
#define TAG_PAD 0 /* Pad option, implicit length 1 */
|
|
|
|
#define TAG_SUBNETMASK 1 /* RFC 950 subnet mask */
|
|
|
|
#define TAG_ROUTERS 3 /* Routers (in order of preference) */
|
|
|
|
#define TAG_HOSTNAME 12 /* Client host name */
|
|
|
|
#define TAG_ROOT 17 /* Root path */
|
|
|
|
|
|
|
|
/* DHCP specific tags */
|
|
|
|
#define TAG_OVERLOAD 52 /* Option Overload */
|
|
|
|
#define TAG_MAXMSGSIZE 57 /* Maximum DHCP Message Size */
|
|
|
|
|
|
|
|
#define TAG_END 255 /* End Option (i.e. no more options) */
|
|
|
|
|
|
|
|
/* Overload values */
|
|
|
|
#define OVERLOAD_FILE 1
|
|
|
|
#define OVERLOAD_SNAME 2
|
|
|
|
|
|
|
|
/* Site specific tags: */
|
|
|
|
#define TAG_SWAP 128
|
|
|
|
#define TAG_SWAPSIZE 129
|
|
|
|
#define TAG_ROOTOPTS 130
|
|
|
|
#define TAG_SWAPOPTS 131
|
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
extern int nfs_diskless_valid;
|
|
|
|
extern struct nfsv3_diskless nfsv3_diskless;
|
|
|
|
|
|
|
|
/* mountd RPC */
|
2000-10-24 22:40:18 +00:00
|
|
|
static int md_mount(struct sockaddr_in *mdsin, char *path,
|
|
|
|
u_char *fhp, int *fhsizep,
|
|
|
|
struct nfs_args *args,struct proc *procp);
|
|
|
|
static int md_lookup_swap(struct sockaddr_in *mdsin,char *path,
|
|
|
|
u_char *fhp, int *fhsizep,
|
|
|
|
struct nfs_args *args,
|
|
|
|
struct proc *procp);
|
|
|
|
static int setfs(struct sockaddr_in *addr, char *path, char *p);
|
|
|
|
static int getdec(char **ptr);
|
|
|
|
static char *substr(char *a,char *b);
|
|
|
|
static void mountopts(struct nfs_args *args, char *p);
|
|
|
|
static int xdr_opaque_decode(struct mbuf **ptr, u_char *buf, int len);
|
|
|
|
static int xdr_int_decode(struct mbuf **ptr, int *iptr);
|
2000-10-29 01:19:32 +00:00
|
|
|
static void print_in_addr(struct in_addr addr);
|
|
|
|
static void print_sin_addr(struct sockaddr_in *addr);
|
|
|
|
static void clear_sinaddr(struct sockaddr_in *sin);
|
|
|
|
static
|
|
|
|
struct bootpc_ifcontext *allocifctx(struct bootpc_globalcontext *gctx);
|
|
|
|
static void bootpc_compose_query(struct bootpc_ifcontext *ifctx,
|
|
|
|
struct bootpc_globalcontext *gctx,
|
|
|
|
struct proc *procp);
|
|
|
|
static unsigned char *bootpc_tag(struct bootpc_tagcontext *tctx,
|
|
|
|
struct bootp_packet *bp, int len, int tag);
|
|
|
|
static void bootpc_tag_helper(struct bootpc_tagcontext *tctx,
|
|
|
|
unsigned char *start, int len, int tag);
|
1997-05-11 18:05:39 +00:00
|
|
|
|
|
|
|
#ifdef BOOTP_DEBUG
|
|
|
|
void bootpboot_p_sa(struct sockaddr *sa,struct sockaddr *ma);
|
|
|
|
void bootpboot_p_ma(struct sockaddr *ma);
|
|
|
|
void bootpboot_p_rtentry(struct rtentry *rt);
|
|
|
|
void bootpboot_p_tree(struct radix_node *rn);
|
|
|
|
void bootpboot_p_rtlist(void);
|
2000-10-29 01:19:32 +00:00
|
|
|
void bootpboot_p_if(struct ifnet *ifp, struct ifaddr *ifa);
|
1997-05-11 18:05:39 +00:00
|
|
|
void bootpboot_p_iflist(void);
|
|
|
|
#endif
|
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
static int bootpc_call(struct bootpc_globalcontext *gctx,
|
1998-02-09 06:11:36 +00:00
|
|
|
struct proc *procp);
|
1997-05-11 18:05:39 +00:00
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
static int bootpc_fakeup_interface(struct bootpc_ifcontext *ifctx,
|
|
|
|
struct bootpc_globalcontext *gctx,
|
2000-10-24 22:40:18 +00:00
|
|
|
struct proc *procp);
|
1997-05-11 18:05:39 +00:00
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
static int bootpc_adjust_interface(struct bootpc_ifcontext *ifctx,
|
|
|
|
struct bootpc_globalcontext *gctx,
|
2000-10-24 22:40:18 +00:00
|
|
|
struct proc *procp);
|
1997-05-11 18:05:39 +00:00
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
static void bootpc_decode_reply(struct nfsv3_diskless *nd,
|
|
|
|
struct bootpc_ifcontext *ifctx,
|
|
|
|
struct bootpc_globalcontext *gctx);
|
|
|
|
|
|
|
|
static int bootpc_received(struct bootpc_globalcontext *gctx,
|
|
|
|
struct bootpc_ifcontext *ifctx);
|
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
void bootpc_init(void);
|
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
/*
|
|
|
|
* In order to have multiple active interfaces with address 0.0.0.0
|
|
|
|
* and be able to send data to a selected interface, we perform
|
|
|
|
* some tricks:
|
|
|
|
*
|
|
|
|
* - The 'broadcast' address is different for each interface.
|
|
|
|
*
|
|
|
|
* - We temporarily add routing pointing 255.255.255.255 to the
|
|
|
|
* selected interface broadcast address, thus the packet sent
|
|
|
|
* goes to that interface.
|
|
|
|
*/
|
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
#ifdef BOOTP_DEBUG
|
2000-10-24 22:40:18 +00:00
|
|
|
void
|
|
|
|
bootpboot_p_sa(struct sockaddr *sa,
|
|
|
|
struct sockaddr *ma)
|
1997-05-11 18:05:39 +00:00
|
|
|
{
|
2000-10-24 22:40:18 +00:00
|
|
|
if (sa == NULL) {
|
|
|
|
printf("(sockaddr *) <null>");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (sa->sa_family) {
|
|
|
|
case AF_INET:
|
|
|
|
{
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in *) sa;
|
2000-10-29 01:19:32 +00:00
|
|
|
printf("inet ");
|
|
|
|
print_sin_addr(sin);
|
2000-10-24 22:40:18 +00:00
|
|
|
if (ma != NULL) {
|
|
|
|
sin = (struct sockaddr_in *) ma;
|
2000-10-29 01:19:32 +00:00
|
|
|
printf(" mask ");
|
|
|
|
print_sin_addr(sin);
|
2000-10-24 22:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AF_LINK:
|
|
|
|
{
|
|
|
|
struct sockaddr_dl *sli;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sli = (struct sockaddr_dl *) sa;
|
|
|
|
printf("link %.*s ", sli->sdl_nlen, sli->sdl_data);
|
|
|
|
for (i = 0; i < sli->sdl_alen; i++) {
|
|
|
|
if (i > 0)
|
|
|
|
printf(":");
|
|
|
|
printf("%x", ((unsigned char *) LLADDR(sli))[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("af%d", sa->sa_family);
|
|
|
|
}
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
bootpboot_p_ma(struct sockaddr *ma)
|
1997-05-11 18:05:39 +00:00
|
|
|
{
|
2000-10-24 22:40:18 +00:00
|
|
|
if (ma == NULL) {
|
|
|
|
printf("<null>");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("%x", *(int *)ma);
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
bootpboot_p_rtentry(struct rtentry *rt)
|
1997-05-11 18:05:39 +00:00
|
|
|
{
|
2000-10-24 22:40:18 +00:00
|
|
|
bootpboot_p_sa(rt_key(rt), rt_mask(rt));
|
|
|
|
printf(" ");
|
|
|
|
bootpboot_p_ma(rt->rt_genmask);
|
|
|
|
printf(" ");
|
|
|
|
bootpboot_p_sa(rt->rt_gateway, NULL);
|
|
|
|
printf(" ");
|
|
|
|
printf("flags %x", (unsigned short) rt->rt_flags);
|
|
|
|
printf(" %d", (int) rt->rt_rmx.rmx_expire);
|
|
|
|
printf(" %s%d\n", rt->rt_ifp->if_name, rt->rt_ifp->if_unit);
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
bootpboot_p_tree(struct radix_node *rn)
|
1997-05-11 18:05:39 +00:00
|
|
|
{
|
2000-10-24 22:40:18 +00:00
|
|
|
while (rn != NULL) {
|
2000-10-24 23:33:01 +00:00
|
|
|
if (rn->rn_bit < 0) {
|
2000-10-24 22:40:18 +00:00
|
|
|
if ((rn->rn_flags & RNF_ROOT) != 0) {
|
|
|
|
} else {
|
|
|
|
bootpboot_p_rtentry((struct rtentry *) rn);
|
|
|
|
}
|
|
|
|
rn = rn->rn_dupedkey;
|
|
|
|
} else {
|
2000-10-24 23:33:01 +00:00
|
|
|
bootpboot_p_tree(rn->rn_left);
|
|
|
|
bootpboot_p_tree(rn->rn_right);
|
2000-10-24 22:40:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
bootpboot_p_rtlist(void)
|
1997-05-11 18:05:39 +00:00
|
|
|
{
|
2000-10-24 22:40:18 +00:00
|
|
|
printf("Routing table:\n");
|
|
|
|
bootpboot_p_tree(rt_tables[AF_INET]->rnh_treetop);
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
bootpboot_p_if(struct ifnet *ifp, struct ifaddr *ifa)
|
|
|
|
{
|
|
|
|
printf("%s%d flags %x, addr ",
|
|
|
|
ifp->if_name,
|
|
|
|
ifp->if_unit,
|
|
|
|
(unsigned short) ifp->if_flags);
|
|
|
|
print_sin_addr((struct sockaddr_in *) ifa->ifa_addr);
|
|
|
|
printf(", broadcast ");
|
|
|
|
print_sin_addr((struct sockaddr_in *) ifa->ifa_dstaddr);
|
|
|
|
printf(", netmask ");
|
|
|
|
print_sin_addr((struct sockaddr_in *) ifa->ifa_netmask);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
void
|
|
|
|
bootpboot_p_iflist(void)
|
1997-05-11 18:05:39 +00:00
|
|
|
{
|
2000-10-24 22:40:18 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
|
|
|
|
printf("Interface list:\n");
|
|
|
|
for (ifp = TAILQ_FIRST(&ifnet);
|
|
|
|
ifp != NULL;
|
2000-10-29 01:19:32 +00:00
|
|
|
ifp = TAILQ_NEXT(ifp, if_link)) {
|
2000-10-24 22:40:18 +00:00
|
|
|
for (ifa = TAILQ_FIRST(&ifp->if_addrhead);
|
|
|
|
ifa != NULL;
|
2000-10-29 01:19:32 +00:00
|
|
|
ifa = TAILQ_NEXT(ifa, ifa_link))
|
|
|
|
if (ifa->ifa_addr->sa_family == AF_INET)
|
|
|
|
bootpboot_p_if(ifp, ifa);
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-29 01:19:32 +00:00
|
|
|
#endif /* defined(BOOTP_DEBUG) */
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
clear_sinaddr(struct sockaddr_in *sin)
|
|
|
|
{
|
|
|
|
bzero(sin, sizeof(*sin));
|
|
|
|
sin->sin_len = sizeof(*sin);
|
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
sin->sin_addr.s_addr = INADDR_ANY; /* XXX: htonl(INAADDR_ANY) ? */
|
|
|
|
sin->sin_port = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct bootpc_ifcontext *
|
|
|
|
allocifctx(struct bootpc_globalcontext *gctx)
|
|
|
|
{
|
|
|
|
struct bootpc_ifcontext *ifctx;
|
|
|
|
ifctx = (struct bootpc_ifcontext *) malloc(sizeof(*ifctx),
|
|
|
|
M_TEMP, M_WAITOK);
|
|
|
|
if (ifctx == NULL)
|
|
|
|
panic("Failed to allocate bootp interface context structure");
|
|
|
|
|
|
|
|
bzero(ifctx, sizeof(*ifctx));
|
|
|
|
ifctx->xid = gctx->xid;
|
|
|
|
gctx->xid += 0x100;
|
|
|
|
return ifctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
bootpc_received(struct bootpc_globalcontext *gctx,
|
|
|
|
struct bootpc_ifcontext *ifctx)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Need timeout for fallback to less
|
|
|
|
* desirable alternative.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* This call used for the side effect (badopt flag) */
|
|
|
|
(void) bootpc_tag(&gctx->tmptag, &gctx->reply,
|
|
|
|
gctx->replylen,
|
|
|
|
TAG_END);
|
|
|
|
|
|
|
|
/* If packet is invalid, ignore it */
|
|
|
|
if (gctx->tmptag.badopt != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Ignore packet unless it gives us a root tag we didn't have */
|
|
|
|
|
|
|
|
if (ifctx->state == IF_BOOTP_RESOLVED &&
|
|
|
|
(bootpc_tag(&gctx->tmptag, &ifctx->reply,
|
|
|
|
ifctx->replylen,
|
|
|
|
TAG_ROOT) != NULL ||
|
|
|
|
bootpc_tag(&gctx->tmptag, &gctx->reply,
|
|
|
|
gctx->replylen,
|
|
|
|
TAG_ROOT) == NULL))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bcopy(&gctx->reply,
|
|
|
|
&ifctx->reply,
|
|
|
|
gctx->replylen);
|
|
|
|
ifctx->replylen = gctx->replylen;
|
|
|
|
|
|
|
|
/* XXX: Only reset if 'perfect' response */
|
|
|
|
ifctx->state = IF_BOOTP_RESOLVED;
|
|
|
|
ifctx->gotrootpath = (bootpc_tag(&gctx->tmptag, &ifctx->reply,
|
|
|
|
ifctx->replylen,
|
|
|
|
TAG_ROOT) != NULL);
|
|
|
|
ifctx->gotgw = (bootpc_tag(&gctx->tmptag, &ifctx->reply,
|
|
|
|
ifctx->replylen,
|
|
|
|
TAG_ROUTERS) != NULL);
|
|
|
|
ifctx->gotnetmask = (bootpc_tag(&gctx->tmptag, &ifctx->reply,
|
|
|
|
ifctx->replylen,
|
|
|
|
TAG_SUBNETMASK) != NULL);
|
|
|
|
return 1;
|
|
|
|
}
|
1997-05-11 18:05:39 +00:00
|
|
|
|
1998-02-09 06:11:36 +00:00
|
|
|
static int
|
2000-10-29 01:19:32 +00:00
|
|
|
bootpc_call(struct bootpc_globalcontext *gctx,
|
2000-10-24 22:40:18 +00:00
|
|
|
struct proc *procp)
|
1997-05-11 18:05:39 +00:00
|
|
|
{
|
|
|
|
struct socket *so;
|
2000-10-29 01:19:32 +00:00
|
|
|
struct sockaddr_in *sin, dst;
|
1997-05-11 18:05:39 +00:00
|
|
|
struct uio auio;
|
1998-08-23 03:07:17 +00:00
|
|
|
struct sockopt sopt;
|
1997-05-11 18:05:39 +00:00
|
|
|
struct iovec aio;
|
2000-10-29 01:19:32 +00:00
|
|
|
int error, on, rcvflg, timo, len;
|
|
|
|
time_t atimo;
|
|
|
|
time_t rtimo;
|
1998-08-23 03:07:17 +00:00
|
|
|
struct timeval tv;
|
2000-10-29 01:19:32 +00:00
|
|
|
struct bootpc_ifcontext *ifctx;
|
|
|
|
int outstanding;
|
|
|
|
int gotrootpath;
|
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
/*
|
|
|
|
* Create socket and set its recieve timeout.
|
|
|
|
*/
|
2000-10-29 01:19:32 +00:00
|
|
|
error = socreate(AF_INET, &so, SOCK_DGRAM, 0, procp);
|
|
|
|
if (error != 0)
|
1997-05-11 18:05:39 +00:00
|
|
|
goto out;
|
2000-10-29 01:19:32 +00:00
|
|
|
|
1998-08-23 03:07:17 +00:00
|
|
|
tv.tv_sec = 1;
|
|
|
|
tv.tv_usec = 0;
|
2000-10-29 01:19:32 +00:00
|
|
|
bzero(&sopt, sizeof(sopt));
|
1998-08-23 03:07:17 +00:00
|
|
|
sopt.sopt_level = SOL_SOCKET;
|
|
|
|
sopt.sopt_name = SO_RCVTIMEO;
|
|
|
|
sopt.sopt_val = &tv;
|
|
|
|
sopt.sopt_valsize = sizeof tv;
|
2000-10-29 01:19:32 +00:00
|
|
|
|
|
|
|
error = sosetopt(so, &sopt);
|
|
|
|
if (error != 0)
|
1997-05-11 18:05:39 +00:00
|
|
|
goto out;
|
2000-10-29 01:19:32 +00:00
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
/*
|
|
|
|
* Enable broadcast.
|
|
|
|
*/
|
1998-08-23 03:07:17 +00:00
|
|
|
on = 1;
|
2000-10-29 01:19:32 +00:00
|
|
|
sopt.sopt_name = SO_BROADCAST;
|
1998-08-23 03:07:17 +00:00
|
|
|
sopt.sopt_val = &on;
|
|
|
|
sopt.sopt_valsize = sizeof on;
|
2000-10-29 01:19:32 +00:00
|
|
|
|
|
|
|
error = sosetopt(so, &sopt);
|
|
|
|
if (error != 0)
|
1998-08-23 03:07:17 +00:00
|
|
|
goto out;
|
1997-05-11 18:05:39 +00:00
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
/*
|
|
|
|
* Disable routing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
on = 1;
|
|
|
|
sopt.sopt_name = SO_DONTROUTE;
|
|
|
|
sopt.sopt_val = &on;
|
|
|
|
sopt.sopt_valsize = sizeof on;
|
|
|
|
|
|
|
|
error = sosetopt(so, &sopt);
|
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
/*
|
|
|
|
* Bind the local endpoint to a bootp client port.
|
|
|
|
*/
|
2000-10-29 01:19:32 +00:00
|
|
|
sin = &dst;
|
|
|
|
clear_sinaddr(sin);
|
1997-05-11 18:05:39 +00:00
|
|
|
sin->sin_port = htons(IPPORT_BOOTPC);
|
1997-08-16 19:16:27 +00:00
|
|
|
error = sobind(so, (struct sockaddr *)sin, procp);
|
2000-10-29 01:19:32 +00:00
|
|
|
if (error != 0) {
|
1997-05-11 18:05:39 +00:00
|
|
|
printf("bind failed\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2000-10-29 01:19:32 +00:00
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
/*
|
|
|
|
* Setup socket address for the server.
|
|
|
|
*/
|
2000-10-29 01:19:32 +00:00
|
|
|
sin = &dst;
|
|
|
|
clear_sinaddr(sin);
|
1997-05-11 18:05:39 +00:00
|
|
|
sin->sin_addr.s_addr = INADDR_BROADCAST;
|
|
|
|
sin->sin_port = htons(IPPORT_BOOTPS);
|
2000-10-29 01:19:32 +00:00
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
/*
|
|
|
|
* Send it, repeatedly, until a reply is received,
|
|
|
|
* but delay each re-send by an increasing amount.
|
|
|
|
* If the delay hits the maximum, start complaining.
|
|
|
|
*/
|
|
|
|
timo = 0;
|
2000-10-29 01:19:32 +00:00
|
|
|
rtimo = 0;
|
1997-05-11 18:05:39 +00:00
|
|
|
for (;;) {
|
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
outstanding = 0;
|
|
|
|
gotrootpath = 0;
|
|
|
|
|
|
|
|
for (ifctx = gctx->interfaces;
|
|
|
|
ifctx != NULL;
|
|
|
|
ifctx = ifctx->next) {
|
|
|
|
if (ifctx->state == IF_BOOTP_RESOLVED &&
|
|
|
|
bootpc_tag(&gctx->tmptag, &ifctx->reply,
|
|
|
|
ifctx->replylen,
|
|
|
|
TAG_ROOT) != NULL)
|
|
|
|
gotrootpath = 1;
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
2000-10-29 01:19:32 +00:00
|
|
|
|
|
|
|
for (ifctx = gctx->interfaces;
|
|
|
|
ifctx != NULL;
|
|
|
|
ifctx = ifctx->next) {
|
|
|
|
ifctx->outstanding = 0;
|
|
|
|
if (ifctx->state == IF_BOOTP_RESOLVED &&
|
|
|
|
gotrootpath != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ifctx->state == IF_BOOTP_FAILED)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
outstanding++;
|
|
|
|
ifctx->outstanding = 1;
|
1997-05-11 18:05:39 +00:00
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
/* Send BOOTP request (or re-send). */
|
|
|
|
|
|
|
|
if (ifctx->sentmsg == 0) {
|
|
|
|
printf("Sending BOOTP Query packet from "
|
|
|
|
"interface %s (%*D)\n",
|
|
|
|
ifctx->ireq.ifr_name,
|
|
|
|
ifctx->sdl->sdl_alen,
|
|
|
|
(unsigned char *) LLADDR(ifctx->sdl),
|
|
|
|
":");
|
|
|
|
ifctx->sentmsg = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
aio.iov_base = (caddr_t) &ifctx->call;
|
|
|
|
aio.iov_len = sizeof(ifctx->call);
|
|
|
|
|
|
|
|
auio.uio_iov = &aio;
|
|
|
|
auio.uio_iovcnt = 1;
|
|
|
|
auio.uio_segflg = UIO_SYSSPACE;
|
|
|
|
auio.uio_rw = UIO_WRITE;
|
|
|
|
auio.uio_offset = 0;
|
|
|
|
auio.uio_resid = sizeof(ifctx->call);
|
|
|
|
auio.uio_procp = procp;
|
|
|
|
|
|
|
|
/* Set netmask to 0.0.0.0 */
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in *) &ifctx->ireq.ifr_addr;
|
|
|
|
clear_sinaddr(sin);
|
|
|
|
error = ifioctl(ifctx->so, SIOCSIFNETMASK,
|
|
|
|
(caddr_t) &ifctx->ireq, procp);
|
|
|
|
if (error != 0)
|
|
|
|
panic("bootpc_call:"
|
|
|
|
"set if netmask, error=%d",
|
|
|
|
error);
|
|
|
|
|
|
|
|
error = sosend(so, (struct sockaddr *) &dst,
|
|
|
|
&auio, NULL, NULL, 0, procp);
|
|
|
|
if (error != 0) {
|
|
|
|
printf("bootpc_call: sosend: %d state %08x\n",
|
|
|
|
error, (int) so->so_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: Is this needed ? */
|
|
|
|
tsleep(&error, PZERO + 8, "bootpw", 10);
|
|
|
|
|
|
|
|
/* Set netmask to 255.0.0.0 */
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in *) &ifctx->ireq.ifr_addr;
|
|
|
|
clear_sinaddr(sin);
|
|
|
|
sin->sin_addr.s_addr = htonl(0xff000000u);
|
|
|
|
error = ifioctl(ifctx->so, SIOCSIFNETMASK,
|
|
|
|
(caddr_t) &ifctx->ireq, procp);
|
|
|
|
if (error != 0)
|
|
|
|
panic("bootpc_call:"
|
|
|
|
"set if netmask, error=%d",
|
|
|
|
error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outstanding == 0 &&
|
|
|
|
(rtimo == 0 || time_second >= rtimo)) {
|
|
|
|
error = 0;
|
|
|
|
goto gotreply;
|
|
|
|
}
|
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
/* Determine new timeout. */
|
|
|
|
if (timo < MAX_RESEND_DELAY)
|
|
|
|
timo++;
|
2000-10-29 01:19:32 +00:00
|
|
|
else {
|
|
|
|
printf("BOOTP timeout for server ");
|
|
|
|
print_sin_addr(&dst);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
/*
|
|
|
|
* Wait for up to timo seconds for a reply.
|
|
|
|
* The socket receive timeout was set to 1 second.
|
|
|
|
*/
|
2000-10-29 01:19:32 +00:00
|
|
|
atimo = timo + time_second;
|
|
|
|
while (time_second < atimo) {
|
|
|
|
aio.iov_base = (caddr_t) &gctx->reply;
|
|
|
|
aio.iov_len = sizeof(gctx->reply);
|
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
auio.uio_iov = &aio;
|
|
|
|
auio.uio_iovcnt = 1;
|
|
|
|
auio.uio_segflg = UIO_SYSSPACE;
|
|
|
|
auio.uio_rw = UIO_READ;
|
|
|
|
auio.uio_offset = 0;
|
2000-10-29 01:19:32 +00:00
|
|
|
auio.uio_resid = sizeof(gctx->reply);
|
1997-05-11 18:05:39 +00:00
|
|
|
auio.uio_procp = procp;
|
|
|
|
|
|
|
|
rcvflg = 0;
|
2000-10-24 22:40:18 +00:00
|
|
|
error = soreceive(so, NULL, &auio,
|
|
|
|
NULL, NULL, &rcvflg);
|
2000-10-29 01:19:32 +00:00
|
|
|
gctx->secs = time_second - gctx->starttime;
|
|
|
|
for (ifctx = gctx->interfaces;
|
|
|
|
ifctx != NULL;
|
|
|
|
ifctx = ifctx->next) {
|
|
|
|
if (ifctx->state == IF_BOOTP_RESOLVED)
|
|
|
|
continue;
|
|
|
|
if (ifctx->state == IF_BOOTP_FAILED)
|
|
|
|
continue;
|
|
|
|
ifctx->call.secs = htons(gctx->secs);
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
2000-10-29 01:19:32 +00:00
|
|
|
if (error == EWOULDBLOCK)
|
|
|
|
continue;
|
|
|
|
if (error != 0)
|
1997-05-11 18:05:39 +00:00
|
|
|
goto out;
|
2000-10-29 01:19:32 +00:00
|
|
|
len = sizeof(gctx->reply) - auio.uio_resid;
|
|
|
|
|
1998-01-18 18:46:20 +00:00
|
|
|
/* Do we have the required number of bytes ? */
|
|
|
|
if (len < BOOTP_MIN_LEN)
|
1997-05-11 18:05:39 +00:00
|
|
|
continue;
|
2000-10-29 01:19:32 +00:00
|
|
|
gctx->replylen = len;
|
|
|
|
|
|
|
|
/* Is it a reply? */
|
|
|
|
if (gctx->reply.op != BOOTP_REPLY)
|
2000-10-24 22:40:18 +00:00
|
|
|
continue;
|
2000-10-29 01:19:32 +00:00
|
|
|
|
|
|
|
/* Is this an answer to our query */
|
|
|
|
for (ifctx = gctx->interfaces;
|
|
|
|
ifctx != NULL;
|
|
|
|
ifctx = ifctx->next) {
|
|
|
|
if (gctx->reply.xid != ifctx->call.xid)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Same HW address size ? */
|
|
|
|
if (gctx->reply.hlen != ifctx->call.hlen)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Correct HW address ? */
|
|
|
|
if (bcmp(gctx->reply.chaddr,
|
|
|
|
ifctx->call.chaddr,
|
|
|
|
ifctx->call.hlen) != 0)
|
|
|
|
continue;
|
1997-05-11 18:05:39 +00:00
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
break;
|
|
|
|
}
|
1997-05-11 18:05:39 +00:00
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
if (ifctx != NULL) {
|
|
|
|
printf("Received BOOTP Reply packet"
|
|
|
|
" on %s from ",
|
|
|
|
ifctx->ireq.ifr_name);
|
|
|
|
print_in_addr(gctx->reply.siaddr);
|
|
|
|
if (gctx->reply.giaddr.s_addr !=
|
|
|
|
htonl(INADDR_ANY)) {
|
|
|
|
printf(" via ");
|
|
|
|
print_in_addr(gctx->reply.giaddr);
|
|
|
|
}
|
|
|
|
if (bootpc_received(gctx, ifctx) != 0) {
|
|
|
|
printf(" (accepted)");
|
|
|
|
if (ifctx->outstanding) {
|
|
|
|
ifctx->outstanding = 0;
|
|
|
|
outstanding--;
|
|
|
|
}
|
|
|
|
/* Network settle delay */
|
|
|
|
if (outstanding == 0)
|
|
|
|
atimo = time_second +
|
|
|
|
BOOTP_SETTLE_DELAY;
|
|
|
|
} else
|
|
|
|
printf(" (ignored)");
|
|
|
|
if (ifctx->gotrootpath) {
|
|
|
|
gotrootpath = 1;
|
|
|
|
rtimo = time_second +
|
|
|
|
BOOTP_SETTLE_DELAY;
|
|
|
|
printf(" (got root path)");
|
|
|
|
} else
|
|
|
|
printf(" (no root path)");
|
|
|
|
printf("\n");
|
|
|
|
}
|
1997-05-11 18:05:39 +00:00
|
|
|
} /* while secs */
|
2000-10-29 01:19:32 +00:00
|
|
|
#ifdef BOOTP_TIMEOUT
|
|
|
|
if (gctx->secs > BOOTP_TIMEOUT && BOOTP_TIMEOUT > 0)
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
if (gotrootpath != 0) {
|
|
|
|
gctx->gotrootpath = gotrootpath;
|
|
|
|
if (rtimo != 0 && time_second >= rtimo)
|
|
|
|
break;
|
|
|
|
}
|
1997-05-11 18:05:39 +00:00
|
|
|
} /* forever send/receive */
|
2000-10-29 01:19:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: These are errors of varying seriousness being silently
|
|
|
|
* ignored
|
|
|
|
*/
|
1997-05-11 18:05:39 +00:00
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
for (ifctx = gctx->interfaces; ifctx != NULL; ifctx = ifctx->next) {
|
|
|
|
if (ifctx->state != IF_BOOTP_RESOLVED) {
|
|
|
|
printf("BOOTP timeout for interface %s\n",
|
|
|
|
ifctx->ireq.ifr_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gctx->gotrootpath != 0) {
|
|
|
|
#if 0
|
|
|
|
printf("Got a root path, ignoring remaining timeout\n");
|
|
|
|
#endif
|
|
|
|
error = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
#ifndef BOOTP_NFSROOT
|
|
|
|
for (ifctx = gctx->interfaces; ifctx != NULL; ifctx = ifctx->next) {
|
|
|
|
if (ifctx->state == IF_BOOTP_RESOLVED) {
|
|
|
|
error = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1997-05-11 18:05:39 +00:00
|
|
|
error = ETIMEDOUT;
|
|
|
|
goto out;
|
2000-10-29 01:19:32 +00:00
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
gotreply:
|
|
|
|
out:
|
1997-05-11 18:05:39 +00:00
|
|
|
soclose(so);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
static int
|
2000-10-29 01:19:32 +00:00
|
|
|
bootpc_fakeup_interface(struct bootpc_ifcontext *ifctx,
|
|
|
|
struct bootpc_globalcontext *gctx,
|
1997-05-11 18:05:39 +00:00
|
|
|
struct proc *procp)
|
|
|
|
{
|
2000-10-24 22:40:18 +00:00
|
|
|
struct sockaddr_in *sin;
|
|
|
|
int error;
|
2000-10-29 01:19:32 +00:00
|
|
|
|
|
|
|
struct ifreq *ireq;
|
|
|
|
struct socket *so;
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
struct sockaddr_dl *sdl;
|
|
|
|
|
|
|
|
error = socreate(AF_INET, &ifctx->so, SOCK_DGRAM, 0, procp);
|
|
|
|
if (error != 0)
|
|
|
|
panic("nfs_boot: socreate, error=%d", error);
|
|
|
|
|
|
|
|
ireq = &ifctx->ireq;
|
|
|
|
so = ifctx->so;
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Bring up the interface.
|
|
|
|
*
|
|
|
|
* Get the old interface flags and or IFF_UP into them; if
|
|
|
|
* IFF_UP set blindly, interface selection can be clobbered.
|
|
|
|
*/
|
|
|
|
error = ifioctl(so, SIOCGIFFLAGS, (caddr_t)ireq, procp);
|
2000-10-29 01:19:32 +00:00
|
|
|
if (error != 0)
|
2000-10-24 22:40:18 +00:00
|
|
|
panic("bootpc_fakeup_interface: GIFFLAGS, error=%d", error);
|
|
|
|
ireq->ifr_flags |= IFF_UP;
|
|
|
|
error = ifioctl(so, SIOCSIFFLAGS, (caddr_t)ireq, procp);
|
2000-10-29 01:19:32 +00:00
|
|
|
if (error != 0)
|
2000-10-24 22:40:18 +00:00
|
|
|
panic("bootpc_fakeup_interface: SIFFLAGS, error=%d", error);
|
2000-10-29 01:19:32 +00:00
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
/*
|
|
|
|
* Do enough of ifconfig(8) so that the chosen interface
|
|
|
|
* can talk to the servers. (just set the address)
|
|
|
|
*/
|
2000-10-29 01:19:32 +00:00
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
/* addr is 0.0.0.0 */
|
2000-10-29 01:19:32 +00:00
|
|
|
|
|
|
|
sin = (struct sockaddr_in *) &ireq->ifr_addr;
|
|
|
|
clear_sinaddr(sin);
|
|
|
|
error = ifioctl(so, SIOCSIFADDR, (caddr_t) ireq, procp);
|
|
|
|
if (error != 0 && (error != EEXIST || ifctx == gctx->interfaces))
|
|
|
|
panic("bootpc_fakeup_interface: "
|
|
|
|
"set if addr, error=%d", error);
|
|
|
|
|
|
|
|
/* netmask is 255.0.0.0 */
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in *) &ireq->ifr_addr;
|
|
|
|
clear_sinaddr(sin);
|
|
|
|
sin->sin_addr.s_addr = htonl(0xff000000u);
|
2000-10-24 22:40:18 +00:00
|
|
|
error = ifioctl(so, SIOCSIFNETMASK, (caddr_t)ireq, procp);
|
2000-10-29 01:19:32 +00:00
|
|
|
if (error != 0)
|
|
|
|
panic("bootpc_fakeup_interface: set if netmask, error=%d",
|
|
|
|
error);
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
/* Broadcast is 255.255.255.255 */
|
2000-10-29 01:19:32 +00:00
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
sin = (struct sockaddr_in *)&ireq->ifr_addr;
|
2000-10-29 01:19:32 +00:00
|
|
|
clear_sinaddr(sin);
|
|
|
|
clear_sinaddr(&ifctx->broadcast);
|
|
|
|
sin->sin_addr.s_addr = htonl(INADDR_BROADCAST);
|
|
|
|
ifctx->broadcast.sin_addr.s_addr = sin->sin_addr.s_addr;
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
error = ifioctl(so, SIOCSIFBRDADDR, (caddr_t)ireq, procp);
|
2000-10-29 01:19:32 +00:00
|
|
|
if (error != 0)
|
|
|
|
panic("bootpc_fakeup_interface: "
|
|
|
|
"set if broadcast addr, error=%d",
|
|
|
|
error);
|
|
|
|
|
|
|
|
/* Get HW address */
|
|
|
|
|
|
|
|
sdl = NULL;
|
|
|
|
for (ifa = TAILQ_FIRST(&ifctx->ifp->if_addrhead);
|
|
|
|
ifa != NULL;
|
|
|
|
ifa = TAILQ_NEXT(ifa,ifa_link))
|
|
|
|
if (ifa->ifa_addr->sa_family == AF_LINK &&
|
|
|
|
(sdl = ((struct sockaddr_dl *) ifa->ifa_addr)) != NULL &&
|
|
|
|
sdl->sdl_type == IFT_ETHER)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (sdl == NULL)
|
|
|
|
panic("bootpc: Unable to find HW address for %s",
|
|
|
|
ifctx->ireq.ifr_name);
|
|
|
|
ifctx->sdl = sdl;
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
return error;
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
static int
|
2000-10-29 01:19:32 +00:00
|
|
|
bootpc_adjust_interface(struct bootpc_ifcontext *ifctx,
|
|
|
|
struct bootpc_globalcontext *gctx,
|
1997-05-11 18:05:39 +00:00
|
|
|
struct proc *procp)
|
|
|
|
{
|
2000-10-24 22:40:18 +00:00
|
|
|
int error;
|
2000-10-29 01:19:32 +00:00
|
|
|
struct sockaddr_in defdst;
|
|
|
|
struct sockaddr_in defmask;
|
2000-10-24 22:40:18 +00:00
|
|
|
struct sockaddr_in *sin;
|
2000-10-29 01:19:32 +00:00
|
|
|
|
|
|
|
struct ifreq *ireq;
|
|
|
|
struct socket *so;
|
|
|
|
struct sockaddr_in *myaddr;
|
|
|
|
struct sockaddr_in *netmask;
|
|
|
|
struct sockaddr_in *gw;
|
1997-05-11 18:05:39 +00:00
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
ireq = &ifctx->ireq;
|
|
|
|
so = ifctx->so;
|
|
|
|
myaddr = &ifctx->myaddr;
|
|
|
|
netmask = &ifctx->netmask;
|
|
|
|
gw = &ifctx->gw;
|
|
|
|
|
|
|
|
if (ifctx->state != IF_BOOTP_RESOLVED) {
|
|
|
|
|
|
|
|
/* Shutdown interfaces where BOOTP failed */
|
|
|
|
|
|
|
|
printf("Shutdown interface %s\n", ifctx->ireq.ifr_name);
|
|
|
|
error = ifioctl(so, SIOCGIFFLAGS, (caddr_t)ireq, procp);
|
|
|
|
if (error != 0)
|
|
|
|
panic("bootpc_adjust_interface: "
|
|
|
|
"SIOCGIFFLAGS, error=%d", error);
|
|
|
|
ireq->ifr_flags &= ~IFF_UP;
|
|
|
|
error = ifioctl(so, SIOCSIFFLAGS, (caddr_t)ireq, procp);
|
|
|
|
if (error != 0)
|
|
|
|
panic("bootpc_adjust_interface: "
|
|
|
|
"SIOCSIFFLAGS, error=%d", error);
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in *) &ireq->ifr_addr;
|
|
|
|
clear_sinaddr(sin);
|
|
|
|
error = ifioctl(so, SIOCDIFADDR, (caddr_t) ireq, procp);
|
|
|
|
if (error != 0 && (error != EEXIST ||
|
|
|
|
ifctx == gctx->interfaces))
|
|
|
|
panic("bootpc_adjust_interface: "
|
|
|
|
"SIOCDIFADDR, error=%d", error);
|
|
|
|
|
|
|
|
return 0;
|
2000-10-24 22:40:18 +00:00
|
|
|
}
|
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
printf("Adjusted interface %s\n", ifctx->ireq.ifr_name);
|
2000-10-24 22:40:18 +00:00
|
|
|
/*
|
|
|
|
* Do enough of ifconfig(8) so that the chosen interface
|
|
|
|
* can talk to the servers. (just set the address)
|
|
|
|
*/
|
|
|
|
bcopy(netmask, &ireq->ifr_addr, sizeof(*netmask));
|
2000-10-29 01:19:32 +00:00
|
|
|
error = ifioctl(so, SIOCSIFNETMASK, (caddr_t) ireq, procp);
|
2000-10-24 22:40:18 +00:00
|
|
|
if (error != 0)
|
2000-10-29 01:19:32 +00:00
|
|
|
panic("bootpc_adjust_interface: "
|
|
|
|
"set if netmask, error=%d", error);
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
/* Broadcast is with host part of IP address all 1's */
|
2000-10-29 01:19:32 +00:00
|
|
|
|
|
|
|
sin = (struct sockaddr_in *) &ireq->ifr_addr;
|
|
|
|
clear_sinaddr(sin);
|
2000-10-24 22:40:18 +00:00
|
|
|
sin->sin_addr.s_addr = myaddr->sin_addr.s_addr |
|
|
|
|
~ netmask->sin_addr.s_addr;
|
2000-10-29 01:19:32 +00:00
|
|
|
error = ifioctl(so, SIOCSIFBRDADDR, (caddr_t) ireq, procp);
|
2000-10-24 22:40:18 +00:00
|
|
|
if (error != 0)
|
2000-10-29 01:19:32 +00:00
|
|
|
panic("bootpc_adjust_interface: "
|
|
|
|
"set if broadcast addr, error=%d", error);
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
bcopy(myaddr, &ireq->ifr_addr, sizeof(*myaddr));
|
2000-10-29 01:19:32 +00:00
|
|
|
error = ifioctl(so, SIOCSIFADDR, (caddr_t) ireq, procp);
|
|
|
|
if (error != 0 && (error != EEXIST || ifctx == gctx->interfaces))
|
|
|
|
panic("bootpc_adjust_interface: "
|
|
|
|
"set if addr, error=%d", error);
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
/* Add new default route */
|
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
if (ifctx->gotgw != 0 || gctx->gotgw == 0) {
|
|
|
|
clear_sinaddr(&defdst);
|
|
|
|
clear_sinaddr(&defmask);
|
|
|
|
error = rtrequest(RTM_ADD,
|
|
|
|
(struct sockaddr *) &defdst,
|
|
|
|
(struct sockaddr *) gw,
|
|
|
|
(struct sockaddr *) &defmask,
|
|
|
|
(RTF_UP | RTF_GATEWAY | RTF_STATIC), NULL);
|
|
|
|
if (error != 0) {
|
|
|
|
printf("bootpc_adjust_interface: "
|
|
|
|
"add net route, error=%d\n", error);
|
|
|
|
return error;
|
|
|
|
}
|
2000-10-24 22:40:18 +00:00
|
|
|
}
|
2000-10-29 01:19:32 +00:00
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
return 0;
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
setfs(struct sockaddr_in *addr, char *path, char *p)
|
1997-05-11 18:05:39 +00:00
|
|
|
{
|
2000-10-24 22:40:18 +00:00
|
|
|
unsigned int ip;
|
1997-05-14 01:36:51 +00:00
|
|
|
int val;
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
ip = 0;
|
|
|
|
if (((val = getdec(&p)) < 0) || (val > 255))
|
|
|
|
return 0;
|
1997-05-14 01:36:51 +00:00
|
|
|
ip = val << 24;
|
2000-10-24 22:40:18 +00:00
|
|
|
if (*p != '.')
|
|
|
|
return 0;
|
1997-05-14 01:36:51 +00:00
|
|
|
p++;
|
2000-10-24 22:40:18 +00:00
|
|
|
if (((val = getdec(&p)) < 0) || (val > 255))
|
|
|
|
return 0;
|
1997-05-14 01:36:51 +00:00
|
|
|
ip |= (val << 16);
|
2000-10-24 22:40:18 +00:00
|
|
|
if (*p != '.')
|
|
|
|
return 0;
|
1997-05-14 01:36:51 +00:00
|
|
|
p++;
|
2000-10-24 22:40:18 +00:00
|
|
|
if (((val = getdec(&p)) < 0) || (val > 255))
|
|
|
|
return 0;
|
1997-05-14 01:36:51 +00:00
|
|
|
ip |= (val << 8);
|
2000-10-24 22:40:18 +00:00
|
|
|
if (*p != '.')
|
|
|
|
return 0;
|
1997-05-14 01:36:51 +00:00
|
|
|
p++;
|
2000-10-24 22:40:18 +00:00
|
|
|
if (((val = getdec(&p)) < 0) || (val > 255))
|
|
|
|
return 0;
|
1997-05-14 01:36:51 +00:00
|
|
|
ip |= val;
|
2000-10-24 22:40:18 +00:00
|
|
|
if (*p != ':')
|
|
|
|
return 0;
|
1997-05-14 01:36:51 +00:00
|
|
|
p++;
|
2000-10-24 22:40:18 +00:00
|
|
|
|
1997-05-14 01:36:51 +00:00
|
|
|
addr->sin_addr.s_addr = htonl(ip);
|
|
|
|
addr->sin_len = sizeof(struct sockaddr_in);
|
|
|
|
addr->sin_family = AF_INET;
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
strncpy(path, p, MNAMELEN - 1);
|
|
|
|
return 1;
|
1997-05-14 01:36:51 +00:00
|
|
|
}
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
getdec(char **ptr)
|
1997-05-14 01:36:51 +00:00
|
|
|
{
|
2000-10-24 22:40:18 +00:00
|
|
|
char *p;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
p = *ptr;
|
|
|
|
ret = 0;
|
|
|
|
if ((*p < '0') || (*p > '9'))
|
|
|
|
return -1;
|
1997-05-14 01:36:51 +00:00
|
|
|
while ((*p >= '0') && (*p <= '9')) {
|
2000-10-24 22:40:18 +00:00
|
|
|
ret = ret * 10 + (*p - '0');
|
1997-05-14 01:36:51 +00:00
|
|
|
p++;
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
1997-05-14 01:36:51 +00:00
|
|
|
*ptr = p;
|
2000-10-24 22:40:18 +00:00
|
|
|
return ret;
|
1997-05-14 01:36:51 +00:00
|
|
|
}
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
static char *
|
|
|
|
substr(char *a, char *b)
|
1997-05-14 01:36:51 +00:00
|
|
|
{
|
|
|
|
char *loc1;
|
|
|
|
char *loc2;
|
2000-10-24 22:40:18 +00:00
|
|
|
|
1997-05-14 01:36:51 +00:00
|
|
|
while (*a != '\0') {
|
|
|
|
loc1 = a;
|
|
|
|
loc2 = b;
|
|
|
|
while (*loc1 == *loc2++) {
|
2000-10-24 22:40:18 +00:00
|
|
|
if (*loc1 == '\0')
|
|
|
|
return 0;
|
1997-05-14 01:36:51 +00:00
|
|
|
loc1++;
|
2000-10-24 22:40:18 +00:00
|
|
|
if (*loc2 == '\0')
|
|
|
|
return loc1;
|
1997-05-14 01:36:51 +00:00
|
|
|
}
|
2000-10-24 22:40:18 +00:00
|
|
|
a++;
|
1997-05-14 01:36:51 +00:00
|
|
|
}
|
2000-10-24 22:40:18 +00:00
|
|
|
return 0;
|
1997-05-14 01:36:51 +00:00
|
|
|
}
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
mountopts(struct nfs_args *args, char *p)
|
1997-05-14 01:36:51 +00:00
|
|
|
{
|
|
|
|
char *tmp;
|
2000-10-24 22:40:18 +00:00
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
args->version = NFS_ARGSVERSION;
|
|
|
|
args->rsize = 8192;
|
|
|
|
args->wsize = 8192;
|
1997-05-14 01:36:51 +00:00
|
|
|
args->flags = NFSMNT_RSIZE | NFSMNT_WSIZE | NFSMNT_RESVPORT;
|
|
|
|
args->sotype = SOCK_DGRAM;
|
2000-10-29 01:19:32 +00:00
|
|
|
if (p == NULL)
|
|
|
|
return;
|
2000-10-24 22:40:18 +00:00
|
|
|
if ((tmp = (char *)substr(p, "rsize=")))
|
|
|
|
args->rsize = getdec(&tmp);
|
|
|
|
if ((tmp = (char *)substr(p, "wsize=")))
|
|
|
|
args->wsize = getdec(&tmp);
|
|
|
|
if ((tmp = (char *)substr(p, "intr")))
|
1997-05-14 01:36:51 +00:00
|
|
|
args->flags |= NFSMNT_INT;
|
2000-10-24 22:40:18 +00:00
|
|
|
if ((tmp = (char *)substr(p, "soft")))
|
1997-05-14 01:36:51 +00:00
|
|
|
args->flags |= NFSMNT_SOFT;
|
2000-10-24 22:40:18 +00:00
|
|
|
if ((tmp = (char *)substr(p, "noconn")))
|
1997-05-14 01:36:51 +00:00
|
|
|
args->flags |= NFSMNT_NOCONN;
|
|
|
|
if ((tmp = (char *)substr(p, "tcp")))
|
2000-10-24 22:40:18 +00:00
|
|
|
args->sotype = SOCK_STREAM;
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
xdr_opaque_decode(struct mbuf **mptr, u_char *buf, int len)
|
1997-06-12 14:08:20 +00:00
|
|
|
{
|
2000-10-24 22:40:18 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
int alignedlen;
|
|
|
|
|
|
|
|
m = *mptr;
|
|
|
|
alignedlen = ( len + 3 ) & ~3;
|
|
|
|
|
|
|
|
if (m->m_len < alignedlen) {
|
|
|
|
m = m_pullup(m, alignedlen);
|
|
|
|
if (m == NULL) {
|
|
|
|
*mptr = NULL;
|
|
|
|
return EBADRPC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bcopy(mtod(m, u_char *), buf, len);
|
|
|
|
m_adj(m, alignedlen);
|
|
|
|
*mptr = m;
|
|
|
|
return 0;
|
1997-06-12 14:08:20 +00:00
|
|
|
}
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
xdr_int_decode(struct mbuf **mptr, int *iptr)
|
1997-06-12 14:08:20 +00:00
|
|
|
{
|
2000-10-24 22:40:18 +00:00
|
|
|
u_int32_t i;
|
|
|
|
if (xdr_opaque_decode(mptr, (u_char *) &i, sizeof(u_int32_t)) != 0)
|
|
|
|
return EBADRPC;
|
|
|
|
*iptr = fxdr_unsigned(u_int32_t, i);
|
|
|
|
return 0;
|
1997-06-12 14:08:20 +00:00
|
|
|
}
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
static void
|
2000-10-29 01:19:32 +00:00
|
|
|
print_sin_addr(struct sockaddr_in *sin)
|
1997-06-12 14:08:20 +00:00
|
|
|
{
|
2000-10-29 01:19:32 +00:00
|
|
|
print_in_addr(sin->sin_addr);
|
|
|
|
}
|
1997-06-12 14:08:20 +00:00
|
|
|
|
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
static void
|
|
|
|
print_in_addr(struct in_addr addr)
|
|
|
|
{
|
|
|
|
unsigned int ip;
|
|
|
|
|
|
|
|
ip = ntohl(addr.s_addr);
|
|
|
|
printf("%d.%d.%d.%d",
|
2000-10-24 22:40:18 +00:00
|
|
|
ip >> 24, (ip >> 16) & 255, (ip >> 8) & 255, ip & 255);
|
1997-06-12 14:08:20 +00:00
|
|
|
}
|
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
static void
|
|
|
|
bootpc_compose_query(ifctx, gctx, procp)
|
|
|
|
struct bootpc_ifcontext *ifctx;
|
|
|
|
struct bootpc_globalcontext *gctx;
|
|
|
|
struct proc *procp;
|
|
|
|
{
|
|
|
|
|
|
|
|
gctx->gotrootpath = 0;
|
|
|
|
gctx->gotswappath = 0;
|
|
|
|
gctx->gotgw = 0;
|
|
|
|
ifctx->gotrootpath = 0;
|
|
|
|
|
|
|
|
bzero((caddr_t) &ifctx->call, sizeof(ifctx->call));
|
|
|
|
|
|
|
|
/* bootpc part */
|
|
|
|
ifctx->call.op = BOOTP_REQUEST; /* BOOTREQUEST */
|
|
|
|
ifctx->call.htype = 1; /* 10mb ethernet */
|
|
|
|
ifctx->call.hlen = ifctx->sdl->sdl_alen;/* Hardware address length */
|
|
|
|
ifctx->call.hops = 0;
|
|
|
|
ifctx->xid++;
|
|
|
|
ifctx->call.xid = txdr_unsigned(ifctx->xid);
|
|
|
|
bcopy(LLADDR(ifctx->sdl), &ifctx->call.chaddr, ifctx->sdl->sdl_alen);
|
|
|
|
|
|
|
|
ifctx->call.vend[0] = 99; /* RFC1048 cookie */
|
|
|
|
ifctx->call.vend[1] = 130;
|
|
|
|
ifctx->call.vend[2] = 83;
|
|
|
|
ifctx->call.vend[3] = 99;
|
|
|
|
ifctx->call.vend[4] = TAG_MAXMSGSIZE;
|
|
|
|
ifctx->call.vend[5] = 2;
|
|
|
|
ifctx->call.vend[6] = (sizeof(struct bootp_packet) >> 8) & 255;
|
|
|
|
ifctx->call.vend[7] = sizeof(struct bootp_packet) & 255;
|
|
|
|
ifctx->call.vend[8] = TAG_END;
|
|
|
|
|
|
|
|
ifctx->call.secs = 0;
|
|
|
|
ifctx->call.flags = htons(0x8000); /* We need an broadcast answer */
|
|
|
|
}
|
2000-10-24 22:40:18 +00:00
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
bootpc_hascookie(struct bootp_packet *bp)
|
|
|
|
{
|
|
|
|
return (bp->vend[0] == 99 && bp->vend[1] == 130 &&
|
|
|
|
bp->vend[2] == 83 && bp->vend[3] == 99);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
bootpc_tag_helper(struct bootpc_tagcontext *tctx,
|
|
|
|
unsigned char *start,
|
|
|
|
int len,
|
|
|
|
int tag)
|
|
|
|
{
|
|
|
|
unsigned char *j;
|
|
|
|
unsigned char *ej;
|
|
|
|
unsigned char code;
|
|
|
|
|
|
|
|
if (tctx->badtag != 0 || tctx->badopt != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
j = start;
|
|
|
|
ej = j + len;
|
|
|
|
|
|
|
|
while (j < ej) {
|
|
|
|
code = *j++;
|
|
|
|
if (code == TAG_PAD)
|
|
|
|
continue;
|
|
|
|
if (code == TAG_END)
|
|
|
|
return;
|
|
|
|
if (j >= ej || j + *j + 1 > ej) {
|
|
|
|
tctx->badopt = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
len = *j++;
|
|
|
|
if (code == tag) {
|
|
|
|
if (tctx->taglen + len > TAG_MAXLEN) {
|
|
|
|
tctx->badtag = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tctx->foundopt = 1;
|
|
|
|
if (len > 0)
|
|
|
|
memcpy(tctx->buf + tctx->taglen,
|
|
|
|
j, len);
|
|
|
|
tctx->taglen += len;
|
|
|
|
}
|
|
|
|
if (code == TAG_OVERLOAD)
|
|
|
|
tctx->overload = *j;
|
|
|
|
|
|
|
|
j += len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned char *
|
|
|
|
bootpc_tag(struct bootpc_tagcontext *tctx,
|
|
|
|
struct bootp_packet *bp,
|
|
|
|
int len,
|
|
|
|
int tag)
|
|
|
|
{
|
|
|
|
unsigned char *j;
|
|
|
|
unsigned char *ej;
|
|
|
|
|
|
|
|
tctx->overload = 0;
|
|
|
|
tctx->badopt = 0;
|
|
|
|
tctx->badtag = 0;
|
|
|
|
tctx->foundopt = 0;
|
|
|
|
tctx->taglen = 0;
|
|
|
|
|
|
|
|
if (bootpc_hascookie(bp) == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
j = &bp->vend[4];
|
|
|
|
ej = (unsigned char *) bp + len;
|
|
|
|
|
|
|
|
bootpc_tag_helper(tctx, &bp->vend[4],
|
|
|
|
(unsigned char *) bp + len - &bp->vend[4], tag);
|
|
|
|
|
|
|
|
if ((tctx->overload & OVERLOAD_FILE) != 0)
|
|
|
|
bootpc_tag_helper(tctx,
|
|
|
|
(unsigned char *) bp->file,
|
|
|
|
sizeof(bp->file),
|
|
|
|
tag);
|
|
|
|
if ((tctx->overload & OVERLOAD_SNAME) != 0)
|
|
|
|
bootpc_tag_helper(tctx,
|
|
|
|
(unsigned char *) bp->sname,
|
|
|
|
sizeof(bp->sname),
|
|
|
|
tag);
|
|
|
|
|
|
|
|
if (tctx->badopt != 0 || tctx->badtag != 0 || tctx->foundopt == 0)
|
|
|
|
return NULL;
|
|
|
|
tctx->buf[tctx->taglen] = '\0';
|
|
|
|
return tctx->buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
bootpc_decode_reply(nd, ifctx, gctx)
|
|
|
|
struct nfsv3_diskless *nd;
|
|
|
|
struct bootpc_ifcontext *ifctx;
|
|
|
|
struct bootpc_globalcontext *gctx;
|
1997-05-11 18:05:39 +00:00
|
|
|
{
|
2000-10-24 22:40:18 +00:00
|
|
|
char *p;
|
|
|
|
unsigned int ip;
|
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
ifctx->gotgw = 0;
|
|
|
|
ifctx->gotnetmask = 0;
|
1997-05-11 18:05:39 +00:00
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
clear_sinaddr(&ifctx->myaddr);
|
|
|
|
clear_sinaddr(&ifctx->netmask);
|
|
|
|
clear_sinaddr(&ifctx->gw);
|
|
|
|
|
|
|
|
ifctx->myaddr.sin_addr = ifctx->reply.yiaddr;
|
|
|
|
|
|
|
|
ip = ntohl(ifctx->myaddr.sin_addr.s_addr);
|
|
|
|
snprintf(gctx->lookup_path, sizeof(gctx->lookup_path),
|
|
|
|
"swap.%d.%d.%d.%d",
|
|
|
|
ip >> 24, (ip >> 16) & 255, (ip >> 8) & 255, ip & 255);
|
|
|
|
|
|
|
|
printf("%s at ", ifctx->ireq.ifr_name);
|
|
|
|
print_sin_addr(&ifctx->myaddr);
|
|
|
|
printf(" server ");
|
|
|
|
print_in_addr(ifctx->reply.siaddr);
|
|
|
|
|
|
|
|
ifctx->gw.sin_addr = ifctx->reply.giaddr;
|
|
|
|
if (ifctx->reply.giaddr.s_addr != htonl(INADDR_ANY)) {
|
|
|
|
printf(" via gateway ");
|
|
|
|
print_in_addr(ifctx->reply.giaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This call used for the side effect (overload flag) */
|
|
|
|
(void) bootpc_tag(&gctx->tmptag,
|
|
|
|
&ifctx->reply, ifctx->replylen, TAG_END);
|
|
|
|
|
|
|
|
if ((gctx->tmptag.overload & OVERLOAD_SNAME) == 0)
|
|
|
|
if (ifctx->reply.sname[0] != '\0')
|
|
|
|
printf(" server name %s", ifctx->reply.sname);
|
|
|
|
if ((gctx->tmptag.overload & OVERLOAD_FILE) == 0)
|
|
|
|
if (ifctx->reply.file[0] != '\0')
|
|
|
|
printf(" boot file %s", ifctx->reply.file);
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
|
|
|
|
TAG_SUBNETMASK);
|
|
|
|
if (p != NULL) {
|
|
|
|
if (gctx->tag.taglen != 4)
|
|
|
|
panic("bootpc: subnet mask len is %d",
|
|
|
|
gctx->tag.taglen);
|
|
|
|
bcopy(p, &ifctx->netmask.sin_addr, 4);
|
|
|
|
ifctx->gotnetmask = 1;
|
|
|
|
printf("subnet mask ");
|
|
|
|
print_sin_addr(&ifctx->netmask);
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
|
|
|
|
TAG_ROUTERS);
|
|
|
|
if (p != NULL) {
|
|
|
|
/* Routers */
|
|
|
|
if (gctx->tag.taglen % 4)
|
|
|
|
panic("bootpc: Router Len is %d", gctx->tag.taglen);
|
|
|
|
if (gctx->tag.taglen > 0) {
|
|
|
|
bcopy(p, &ifctx->gw.sin_addr, 4);
|
|
|
|
printf("router ");
|
|
|
|
print_sin_addr(&ifctx->gw);
|
|
|
|
printf(" ");
|
|
|
|
ifctx->gotgw = 1;
|
|
|
|
gctx->gotgw = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
|
|
|
|
TAG_ROOT);
|
|
|
|
if (p != NULL) {
|
|
|
|
if (gctx->setrootfs != NULL) {
|
|
|
|
printf("rootfs %s (ignored) ", p);
|
|
|
|
} else if (setfs(&nd->root_saddr,
|
|
|
|
nd->root_hostnam, p)) {
|
|
|
|
printf("rootfs %s ",p);
|
|
|
|
gctx->gotrootpath = 1;
|
|
|
|
ifctx->gotrootpath = 1;
|
|
|
|
gctx->setrootfs = ifctx;
|
|
|
|
|
|
|
|
p = bootpc_tag(&gctx->tag, &ifctx->reply,
|
|
|
|
ifctx->replylen,
|
|
|
|
TAG_ROOTOPTS);
|
|
|
|
if (p != NULL) {
|
|
|
|
mountopts(&nd->root_args, p);
|
|
|
|
printf("rootopts %s ", p);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
panic("Failed to set rootfs to %s",p);
|
|
|
|
}
|
|
|
|
|
|
|
|
p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
|
|
|
|
TAG_SWAP);
|
|
|
|
if (p != NULL) {
|
|
|
|
if (gctx->setswapfs != NULL) {
|
|
|
|
printf("swapfs %s (ignored) ", p);
|
|
|
|
} else if (setfs(&nd->swap_saddr,
|
|
|
|
nd->swap_hostnam, p)) {
|
|
|
|
gctx->gotswappath = 1;
|
|
|
|
gctx->setswapfs = ifctx;
|
|
|
|
printf("swapfs %s ", p);
|
|
|
|
|
|
|
|
p = bootpc_tag(&gctx->tag, &ifctx->reply,
|
|
|
|
ifctx->replylen,
|
|
|
|
TAG_SWAPOPTS);
|
|
|
|
if (p != NULL) {
|
|
|
|
/* swap mount options */
|
|
|
|
mountopts(&nd->swap_args, p);
|
|
|
|
printf("swapopts %s ", p);
|
|
|
|
}
|
|
|
|
|
|
|
|
p = bootpc_tag(&gctx->tag, &ifctx->reply,
|
|
|
|
ifctx->replylen,
|
|
|
|
TAG_SWAPSIZE);
|
|
|
|
if (p != NULL) {
|
|
|
|
int swaplen;
|
|
|
|
if (gctx->tag.taglen != 4)
|
|
|
|
panic("bootpc: "
|
|
|
|
"Expected 4 bytes for swaplen, "
|
|
|
|
"not %d bytes",
|
|
|
|
gctx->tag.taglen);
|
|
|
|
bcopy(p, &swaplen, 4);
|
|
|
|
nd->swap_nblks = ntohl(swaplen);
|
|
|
|
printf("swapsize %d KB ",
|
|
|
|
nd->swap_nblks);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
panic("Failed to set swapfs to %s", p);
|
|
|
|
}
|
|
|
|
|
|
|
|
p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
|
|
|
|
TAG_HOSTNAME);
|
|
|
|
if (p != NULL) {
|
|
|
|
if (gctx->tag.taglen >= MAXHOSTNAMELEN)
|
|
|
|
panic("bootpc: hostname >= %d bytes",
|
|
|
|
MAXHOSTNAMELEN);
|
|
|
|
if (gctx->sethostname != NULL) {
|
|
|
|
printf("hostname %s (ignored) ", p);
|
|
|
|
} else {
|
|
|
|
strcpy(nd->my_hostnam, p);
|
|
|
|
strcpy(hostname, p);
|
|
|
|
printf("hostname %s ",hostname);
|
|
|
|
gctx->sethostname = ifctx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
if (ifctx->gotnetmask == 0) {
|
|
|
|
if (IN_CLASSA(ntohl(ifctx->myaddr.sin_addr.s_addr)))
|
|
|
|
ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSA_NET);
|
|
|
|
else if (IN_CLASSB(ntohl(ifctx->myaddr.sin_addr.s_addr)))
|
|
|
|
ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSB_NET);
|
|
|
|
else
|
|
|
|
ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSC_NET);
|
|
|
|
}
|
|
|
|
if (ifctx->gotgw == 0) {
|
|
|
|
/* Use proxyarp */
|
|
|
|
ifctx->gw.sin_addr.s_addr = ifctx->myaddr.sin_addr.s_addr;
|
|
|
|
}
|
|
|
|
}
|
2000-10-24 22:40:18 +00:00
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
void
|
|
|
|
bootpc_init(void)
|
|
|
|
{
|
|
|
|
struct bootpc_ifcontext *ifctx, *nctx; /* Interface BOOTP contexts */
|
|
|
|
struct bootpc_globalcontext *gctx; /* Global BOOTP context */
|
|
|
|
struct ifnet *ifp;
|
|
|
|
int error;
|
2000-10-24 22:40:18 +00:00
|
|
|
struct nfsv3_diskless *nd;
|
|
|
|
struct proc *procp;
|
|
|
|
|
|
|
|
nd = &nfsv3_diskless;
|
|
|
|
procp = curproc;
|
2000-10-29 01:19:32 +00:00
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
/*
|
|
|
|
* If already filled in, don't touch it here
|
|
|
|
*/
|
|
|
|
if (nfs_diskless_valid != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait until arp entries can be handled.
|
|
|
|
*/
|
|
|
|
while (time_second == 0)
|
|
|
|
tsleep(&time_second, PZERO + 8, "arpkludge", 10);
|
2000-10-29 01:19:32 +00:00
|
|
|
|
|
|
|
gctx = malloc(sizeof(*gctx), M_TEMP, M_WAITOK);
|
|
|
|
if (gctx == NULL)
|
|
|
|
panic("Failed to allocate bootp global context structure");
|
|
|
|
|
|
|
|
bzero(gctx, sizeof(*gctx));
|
|
|
|
gctx->xid = ~0xFFFF;
|
|
|
|
gctx->starttime = time_second;
|
|
|
|
|
|
|
|
ifctx = allocifctx(gctx);
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a network interface.
|
|
|
|
*/
|
1998-03-14 04:13:56 +00:00
|
|
|
#ifdef BOOTP_WIRED_TO
|
2000-10-24 22:40:18 +00:00
|
|
|
printf("bootpc_init: wired to interface '%s'\n",
|
|
|
|
__XSTRING(BOOTP_WIRED_TO));
|
1998-03-14 04:13:56 +00:00
|
|
|
#endif
|
2000-10-29 01:19:32 +00:00
|
|
|
bzero(&ifctx->ireq, sizeof(ifctx->ireq));
|
2000-10-24 22:40:18 +00:00
|
|
|
for (ifp = TAILQ_FIRST(&ifnet);
|
|
|
|
ifp != NULL;
|
2000-10-29 01:19:32 +00:00
|
|
|
ifp = TAILQ_NEXT(ifp, if_link)) {
|
|
|
|
snprintf(ifctx->ireq.ifr_name, sizeof(ifctx->ireq.ifr_name),
|
2000-10-24 22:40:18 +00:00
|
|
|
"%s%d", ifp->if_name, ifp->if_unit);
|
1998-03-14 04:13:56 +00:00
|
|
|
#ifdef BOOTP_WIRED_TO
|
2000-10-29 01:19:32 +00:00
|
|
|
if (strcmp(ifctx->ireq.ifr_name,
|
|
|
|
__XSTRING(BOOTP_WIRED_TO)) != 0)
|
|
|
|
continue;
|
1998-03-14 04:13:56 +00:00
|
|
|
#else
|
2000-10-24 22:40:18 +00:00
|
|
|
if ((ifp->if_flags &
|
2000-10-29 01:19:32 +00:00
|
|
|
(IFF_LOOPBACK | IFF_POINTOPOINT | IFF_BROADCAST)) !=
|
|
|
|
IFF_BROADCAST)
|
|
|
|
continue;
|
1998-03-14 04:13:56 +00:00
|
|
|
#endif
|
2000-10-29 01:19:32 +00:00
|
|
|
if (gctx->interfaces != NULL)
|
|
|
|
gctx->lastinterface->next = ifctx;
|
|
|
|
else
|
|
|
|
gctx->interfaces = ifctx;
|
|
|
|
ifctx->ifp = ifp;
|
|
|
|
gctx->lastinterface = ifctx;
|
|
|
|
ifctx = allocifctx(gctx);
|
2000-10-24 22:40:18 +00:00
|
|
|
}
|
2000-10-29 01:19:32 +00:00
|
|
|
free(ifctx, M_TEMP);
|
|
|
|
|
|
|
|
if (gctx->interfaces == NULL) {
|
|
|
|
#ifdef BOOTP_WIRED_TO
|
|
|
|
panic("bootpc_init: Could not find interface specified "
|
|
|
|
"by BOOTP_WIRED_TO: "
|
|
|
|
__XSTRING(BOOTP_WIRED_TO));
|
|
|
|
#else
|
2000-10-24 22:40:18 +00:00
|
|
|
panic("bootpc_init: no suitable interface");
|
1997-05-11 18:05:39 +00:00
|
|
|
#endif
|
2000-10-29 01:19:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (ifctx = gctx->interfaces; ifctx != NULL; ifctx = ifctx->next)
|
|
|
|
bootpc_fakeup_interface(ifctx, gctx, procp);
|
|
|
|
|
|
|
|
for (ifctx = gctx->interfaces; ifctx != NULL; ifctx = ifctx->next)
|
|
|
|
bootpc_compose_query(ifctx, gctx, procp);
|
|
|
|
|
|
|
|
ifctx = gctx->interfaces;
|
|
|
|
error = bootpc_call(gctx, procp);
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
if (error != 0) {
|
1997-05-11 18:05:39 +00:00
|
|
|
#ifdef BOOTP_NFSROOT
|
2000-10-24 22:40:18 +00:00
|
|
|
panic("BOOTP call failed");
|
2000-10-29 01:19:32 +00:00
|
|
|
#else
|
|
|
|
printf("BOOTP call failed\n");
|
1997-05-11 18:05:39 +00:00
|
|
|
#endif
|
|
|
|
}
|
2000-10-29 01:19:32 +00:00
|
|
|
|
|
|
|
mountopts(&nd->root_args, NULL);
|
|
|
|
|
|
|
|
mountopts(&nd->swap_args, NULL);
|
2000-10-24 22:40:18 +00:00
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
for (ifctx = gctx->interfaces; ifctx != NULL; ifctx = ifctx->next)
|
|
|
|
if (ifctx->state == IF_BOOTP_RESOLVED)
|
|
|
|
bootpc_decode_reply(nd, ifctx, gctx);
|
|
|
|
|
|
|
|
if (gctx->gotswappath == 0)
|
2000-10-24 22:40:18 +00:00
|
|
|
nd->swap_nblks = 0;
|
1997-05-11 18:05:39 +00:00
|
|
|
#ifdef BOOTP_NFSROOT
|
2000-10-29 01:19:32 +00:00
|
|
|
if (gctx->gotrootpath == 0)
|
2000-10-24 22:40:18 +00:00
|
|
|
panic("bootpc: No root path offered");
|
1997-05-11 18:05:39 +00:00
|
|
|
#endif
|
2000-10-29 01:19:32 +00:00
|
|
|
|
|
|
|
for (ifctx = gctx->interfaces; ifctx != NULL; ifctx = ifctx->next) {
|
|
|
|
bootpc_adjust_interface(ifctx, gctx, procp);
|
|
|
|
|
|
|
|
soclose(ifctx->so);
|
2000-10-24 22:40:18 +00:00
|
|
|
}
|
1997-05-11 18:05:39 +00:00
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
for (ifctx = gctx->interfaces; ifctx != NULL; ifctx = ifctx->next)
|
|
|
|
if (ifctx->gotrootpath != 0)
|
|
|
|
break;
|
|
|
|
if (ifctx == NULL) {
|
|
|
|
for (ifctx = gctx->interfaces;
|
|
|
|
ifctx != NULL;
|
|
|
|
ifctx = ifctx->next)
|
|
|
|
if (ifctx->state == IF_BOOTP_RESOLVED)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ifctx == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (gctx->gotrootpath != 0) {
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
error = md_mount(&nd->root_saddr, nd->root_hostnam,
|
|
|
|
nd->root_fh, &nd->root_fhsize,
|
|
|
|
&nd->root_args, procp);
|
|
|
|
if (error != 0)
|
|
|
|
panic("nfs_boot: mountd root, error=%d", error);
|
1997-05-14 01:36:51 +00:00
|
|
|
|
2000-10-29 01:19:32 +00:00
|
|
|
if (gctx->gotswappath != 0) {
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
error = md_mount(&nd->swap_saddr,
|
|
|
|
nd->swap_hostnam,
|
|
|
|
nd->swap_fh, &nd->swap_fhsize,
|
|
|
|
&nd->swap_args, procp);
|
|
|
|
if (error != 0)
|
|
|
|
panic("nfs_boot: mountd swap, error=%d",
|
|
|
|
error);
|
|
|
|
|
|
|
|
error = md_lookup_swap(&nd->swap_saddr,
|
2000-10-29 01:19:32 +00:00
|
|
|
gctx->lookup_path,
|
2000-10-24 22:40:18 +00:00
|
|
|
nd->swap_fh, &nd->swap_fhsize,
|
|
|
|
&nd->swap_args, procp);
|
|
|
|
if (error != 0)
|
|
|
|
panic("nfs_boot: lookup swap, error=%d",
|
|
|
|
error);
|
|
|
|
}
|
|
|
|
nfs_diskless_valid = 3;
|
|
|
|
}
|
2000-10-29 01:19:32 +00:00
|
|
|
|
|
|
|
strcpy(nd->myif.ifra_name, ifctx->ireq.ifr_name);
|
|
|
|
bcopy(&ifctx->myaddr, &nd->myif.ifra_addr, sizeof(ifctx->myaddr));
|
|
|
|
bcopy(&ifctx->myaddr, &nd->myif.ifra_broadaddr, sizeof(ifctx->myaddr));
|
2000-10-24 22:40:18 +00:00
|
|
|
((struct sockaddr_in *) &nd->myif.ifra_broadaddr)->sin_addr.s_addr =
|
2000-10-29 01:19:32 +00:00
|
|
|
ifctx->myaddr.sin_addr.s_addr |
|
|
|
|
~ ifctx->netmask.sin_addr.s_addr;
|
|
|
|
bcopy(&ifctx->netmask, &nd->myif.ifra_mask, sizeof(ifctx->netmask));
|
|
|
|
|
|
|
|
out:
|
|
|
|
for (ifctx = gctx->interfaces; ifctx != NULL; ifctx = nctx) {
|
|
|
|
nctx = ifctx->next;
|
|
|
|
free(ifctx, M_TEMP);
|
|
|
|
}
|
|
|
|
free(gctx, M_TEMP);
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
/*
|
|
|
|
* RPC: mountd/mount
|
|
|
|
* Given a server pathname, get an NFS file handle.
|
|
|
|
* Also, sets sin->sin_port to the NFS service port.
|
|
|
|
*/
|
|
|
|
static int
|
2000-10-24 22:40:18 +00:00
|
|
|
md_mount(struct sockaddr_in *mdsin, /* mountd server address */
|
|
|
|
char *path,
|
|
|
|
u_char *fhp,
|
|
|
|
int *fhsizep,
|
|
|
|
struct nfs_args *args,
|
|
|
|
struct proc *procp)
|
1997-05-11 18:05:39 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
int error;
|
|
|
|
int authunixok;
|
|
|
|
int authcount;
|
|
|
|
int authver;
|
2000-10-24 22:40:18 +00:00
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
#ifdef BOOTP_NFSV3
|
|
|
|
/* First try NFS v3 */
|
|
|
|
/* Get port number for MOUNTD. */
|
|
|
|
error = krpc_portmap(mdsin, RPCPROG_MNT, RPCMNT_VER3,
|
2000-10-24 22:40:18 +00:00
|
|
|
&mdsin->sin_port, procp);
|
|
|
|
if (error == 0) {
|
|
|
|
m = xdr_string_encode(path, strlen(path));
|
|
|
|
|
|
|
|
/* Do RPC to mountd. */
|
|
|
|
error = krpc_call(mdsin, RPCPROG_MNT, RPCMNT_VER3,
|
2000-10-24 23:33:01 +00:00
|
|
|
RPCMNT_MOUNT, &m, NULL, procp);
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
2000-10-24 22:40:18 +00:00
|
|
|
if (error == 0) {
|
|
|
|
args->flags |= NFSMNT_NFSV3;
|
1997-05-11 18:05:39 +00:00
|
|
|
} else {
|
|
|
|
#endif
|
2000-10-24 22:40:18 +00:00
|
|
|
/* Fallback to NFS v2 */
|
|
|
|
|
|
|
|
/* Get port number for MOUNTD. */
|
|
|
|
error = krpc_portmap(mdsin, RPCPROG_MNT, RPCMNT_VER1,
|
|
|
|
&mdsin->sin_port, procp);
|
|
|
|
if (error != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
m = xdr_string_encode(path, strlen(path));
|
|
|
|
|
|
|
|
/* Do RPC to mountd. */
|
|
|
|
error = krpc_call(mdsin, RPCPROG_MNT, RPCMNT_VER1,
|
2000-10-24 23:33:01 +00:00
|
|
|
RPCMNT_MOUNT, &m, NULL, procp);
|
2000-10-24 22:40:18 +00:00
|
|
|
if (error != 0)
|
|
|
|
return error; /* message already freed */
|
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
#ifdef BOOTP_NFSV3
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
if (xdr_int_decode(&m, &error) != 0 || error != 0)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
if ((args->flags & NFSMNT_NFSV3) != 0) {
|
|
|
|
if (xdr_int_decode(&m, fhsizep) != 0 ||
|
|
|
|
*fhsizep > NFSX_V3FHMAX ||
|
|
|
|
*fhsizep <= 0)
|
|
|
|
goto bad;
|
|
|
|
} else
|
|
|
|
*fhsizep = NFSX_V2FH;
|
1997-05-11 18:05:39 +00:00
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
if (xdr_opaque_decode(&m, fhp, *fhsizep) != 0)
|
|
|
|
goto bad;
|
1997-05-11 18:05:39 +00:00
|
|
|
|
|
|
|
if (args->flags & NFSMNT_NFSV3) {
|
2000-10-24 22:40:18 +00:00
|
|
|
if (xdr_int_decode(&m, &authcount) != 0)
|
|
|
|
goto bad;
|
|
|
|
authunixok = 0;
|
|
|
|
if (authcount < 0 || authcount > 100)
|
|
|
|
goto bad;
|
|
|
|
while (authcount > 0) {
|
|
|
|
if (xdr_int_decode(&m, &authver) != 0)
|
|
|
|
goto bad;
|
|
|
|
if (authver == RPCAUTH_UNIX)
|
|
|
|
authunixok = 1;
|
|
|
|
authcount--;
|
|
|
|
}
|
|
|
|
if (authunixok == 0)
|
|
|
|
goto bad;
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set port number for NFS use. */
|
2000-10-24 22:40:18 +00:00
|
|
|
error = krpc_portmap(mdsin, NFS_PROG,
|
|
|
|
(args->flags &
|
|
|
|
NFSMNT_NFSV3) ? NFS_VER3 : NFS_VER2,
|
1997-05-11 18:05:39 +00:00
|
|
|
&mdsin->sin_port, procp);
|
2000-10-24 22:40:18 +00:00
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
goto out;
|
2000-10-24 22:40:18 +00:00
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
bad:
|
|
|
|
error = EBADRPC;
|
2000-10-24 22:40:18 +00:00
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
out:
|
|
|
|
m_freem(m);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
1997-06-12 14:08:20 +00:00
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
static int
|
|
|
|
md_lookup_swap(struct sockaddr_in *mdsin, /* mountd server address */
|
|
|
|
char *path,
|
|
|
|
u_char *fhp,
|
|
|
|
int *fhsizep,
|
|
|
|
struct nfs_args *args,
|
|
|
|
struct proc *procp)
|
1997-05-11 18:05:39 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
int error;
|
|
|
|
int size = -1;
|
|
|
|
int attribs_present;
|
|
|
|
int status;
|
1997-06-12 14:08:20 +00:00
|
|
|
union {
|
2000-10-24 22:40:18 +00:00
|
|
|
u_int32_t v2[17];
|
|
|
|
u_int32_t v3[21];
|
1997-06-12 14:08:20 +00:00
|
|
|
} fattribs;
|
2000-10-24 22:40:18 +00:00
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
m = m_get(M_WAIT,MT_DATA);
|
2000-10-24 22:40:18 +00:00
|
|
|
if (m == NULL)
|
1997-05-11 18:05:39 +00:00
|
|
|
return ENOBUFS;
|
2000-10-24 22:40:18 +00:00
|
|
|
|
|
|
|
if ((args->flags & NFSMNT_NFSV3) != 0) {
|
|
|
|
*mtod(m, u_int32_t *) = txdr_unsigned(*fhsizep);
|
|
|
|
bcopy(fhp, mtod(m, u_char *) + sizeof(u_int32_t), *fhsizep);
|
|
|
|
m->m_len = *fhsizep + sizeof(u_int32_t);
|
1997-05-11 18:05:39 +00:00
|
|
|
} else {
|
2000-10-24 22:40:18 +00:00
|
|
|
bcopy(fhp, mtod(m, u_char *), NFSX_V2FH);
|
|
|
|
m->m_len = NFSX_V2FH;
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m->m_next = xdr_string_encode(path, strlen(path));
|
2000-10-24 22:40:18 +00:00
|
|
|
if (m->m_next == NULL) {
|
|
|
|
error = ENOBUFS;
|
|
|
|
goto out;
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Do RPC to nfsd. */
|
2000-10-24 22:40:18 +00:00
|
|
|
if ((args->flags & NFSMNT_NFSV3) != 0)
|
|
|
|
error = krpc_call(mdsin, NFS_PROG, NFS_VER3,
|
|
|
|
NFSPROC_LOOKUP, &m, NULL, procp);
|
|
|
|
else
|
|
|
|
error = krpc_call(mdsin, NFS_PROG, NFS_VER2,
|
|
|
|
NFSV2PROC_LOOKUP, &m, NULL, procp);
|
|
|
|
if (error != 0)
|
|
|
|
return error; /* message already freed */
|
|
|
|
|
|
|
|
if (xdr_int_decode(&m, &status) != 0)
|
|
|
|
goto bad;
|
|
|
|
if (status != 0) {
|
|
|
|
error = ENOENT;
|
|
|
|
goto out;
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
if ((args->flags & NFSMNT_NFSV3) != 0) {
|
|
|
|
if (xdr_int_decode(&m, fhsizep) != 0 ||
|
|
|
|
*fhsizep > NFSX_V3FHMAX ||
|
|
|
|
*fhsizep <= 0)
|
|
|
|
goto bad;
|
1997-05-11 18:05:39 +00:00
|
|
|
} else
|
2000-10-24 22:40:18 +00:00
|
|
|
*fhsizep = NFSX_V2FH;
|
1997-05-11 18:05:39 +00:00
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
if (xdr_opaque_decode(&m, fhp, *fhsizep) != 0)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
if ((args->flags & NFSMNT_NFSV3) != 0) {
|
|
|
|
if (xdr_int_decode(&m, &attribs_present) != 0)
|
|
|
|
goto bad;
|
|
|
|
if (attribs_present != 0) {
|
|
|
|
if (xdr_opaque_decode(&m, (u_char *) &fattribs.v3,
|
|
|
|
sizeof(u_int32_t) * 21) != 0)
|
|
|
|
goto bad;
|
|
|
|
size = fxdr_unsigned(u_int32_t, fattribs.v3[6]);
|
|
|
|
}
|
1997-06-12 14:08:20 +00:00
|
|
|
} else {
|
2000-10-24 22:40:18 +00:00
|
|
|
if (xdr_opaque_decode(&m,(u_char *) &fattribs.v2,
|
|
|
|
sizeof(u_int32_t) * 17) != 0)
|
|
|
|
goto bad;
|
|
|
|
size = fxdr_unsigned(u_int32_t, fattribs.v2[5]);
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
|
|
|
|
2000-10-24 22:40:18 +00:00
|
|
|
if (nfsv3_diskless.swap_nblks == 0 && size != -1) {
|
|
|
|
nfsv3_diskless.swap_nblks = size / 1024;
|
|
|
|
printf("md_lookup_swap: Swap size is %d KB\n",
|
|
|
|
nfsv3_diskless.swap_nblks);
|
1997-05-11 18:05:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
goto out;
|
2000-10-24 22:40:18 +00:00
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
bad:
|
|
|
|
error = EBADRPC;
|
2000-10-24 22:40:18 +00:00
|
|
|
|
1997-05-11 18:05:39 +00:00
|
|
|
out:
|
|
|
|
m_freem(m);
|
|
|
|
return error;
|
|
|
|
}
|