155578Sbostic /*
255578Sbostic * Copyright (c) 1988, 1992 The University of Utah and the Center
355578Sbostic * for Software Science (CSS).
4*61443Sbostic * Copyright (c) 1992, 1993
5*61443Sbostic * The Regents of the University of California. All rights reserved.
655578Sbostic *
755578Sbostic * This code is derived from software contributed to Berkeley by
855578Sbostic * the Center for Software Science of the University of Utah Computer
955578Sbostic * Science Department. CSS requests users of this software to return
1055578Sbostic * to css-dist@cs.utah.edu any improvements that they make and grant
1155578Sbostic * CSS redistribution rights.
1255578Sbostic *
1355578Sbostic * %sccs.include.redist.c%
1455578Sbostic *
15*61443Sbostic * @(#)rmpproto.c 8.1 (Berkeley) 06/04/93
1655578Sbostic *
1755578Sbostic * Utah $Hdr: rmpproto.c 3.1 92/07/06$
1855578Sbostic * Author: Jeff Forys, University of Utah CSS
1955578Sbostic */
2055578Sbostic
2155578Sbostic #ifndef lint
22*61443Sbostic static char sccsid[] = "@(#)rmpproto.c 8.1 (Berkeley) 06/04/93";
2355578Sbostic #endif /* not lint */
2455578Sbostic
2555600Sbostic #include <sys/param.h>
2655600Sbostic #include <sys/time.h>
2755578Sbostic
2855600Sbostic #include <errno.h>
2955600Sbostic #include <fcntl.h>
3055600Sbostic #include <stdio.h>
3155600Sbostic #include <string.h>
3255578Sbostic #include <syslog.h>
3355600Sbostic #include <unistd.h>
3455600Sbostic #include "defs.h"
3555578Sbostic
3655578Sbostic /*
3755578Sbostic ** ProcessPacket -- determine packet type and do what's required.
3855578Sbostic **
3955578Sbostic ** An RMP BOOT packet has been received. Look at the type field
4055578Sbostic ** and process Boot Requests, Read Requests, and Boot Complete
4155578Sbostic ** packets. Any other type will be dropped with a warning msg.
4255578Sbostic **
4355578Sbostic ** Parameters:
4455578Sbostic ** rconn - the new connection
4555578Sbostic ** client - list of files available to this host
4655578Sbostic **
4755578Sbostic ** Returns:
4855578Sbostic ** Nothing.
4955578Sbostic **
5055578Sbostic ** Side Effects:
5155578Sbostic ** - If this is a valid boot request, it will be added to
5255578Sbostic ** the linked list of outstanding requests (RmpConns).
5355578Sbostic ** - If this is a valid boot complete, its associated
5455578Sbostic ** entry in RmpConns will be deleted.
5555578Sbostic ** - Also, unless we run out of memory, a reply will be
5655578Sbostic ** sent to the host that sent the packet.
5755578Sbostic */
5855600Sbostic void
ProcessPacket(rconn,client)5955578Sbostic ProcessPacket(rconn, client)
6055600Sbostic RMPCONN *rconn;
6155600Sbostic CLIENT *client;
6255578Sbostic {
6355578Sbostic struct rmp_packet *rmp;
6455600Sbostic RMPCONN *rconnout;
6555578Sbostic
6655578Sbostic rmp = &rconn->rmp; /* cache pointer to RMP packet */
6755578Sbostic
6855578Sbostic switch(rmp->r_type) { /* do what we came here to do */
6955578Sbostic case RMP_BOOT_REQ: /* boot request */
7055578Sbostic if ((rconnout = NewConn(rconn)) == NULL)
7155578Sbostic return;
7255578Sbostic
7355578Sbostic /*
7455578Sbostic * If the Session ID is 0xffff, this is a "probe"
7555578Sbostic * packet and we do not want to add the connection
7655578Sbostic * to the linked list of active connections. There
7755578Sbostic * are two types of probe packets, if the Sequence
7855578Sbostic * Number is 0 they want to know our host name, o/w
7955578Sbostic * they want the name of the file associated with
8055578Sbostic * the number spec'd by the Sequence Number.
8155578Sbostic *
8255578Sbostic * If this is an actual boot request, open the file
8355578Sbostic * and send a reply. If SendBootRepl() does not
8455578Sbostic * return 0, add the connection to the linked list
8555578Sbostic * of active connections, otherwise delete it since
8655578Sbostic * an error was encountered.
8755578Sbostic */
8855578Sbostic if (rmp->r_brq.rmp_session == RMP_PROBESID) {
8955578Sbostic if (WORDZE(rmp->r_brq.rmp_seqno))
9055578Sbostic (void) SendServerID(rconnout);
9155578Sbostic else
9255578Sbostic (void) SendFileNo(rmp, rconnout,
9355578Sbostic client? client->files:
9455578Sbostic BootFiles);
9555578Sbostic FreeConn(rconnout);
9655578Sbostic } else {
9755578Sbostic if (SendBootRepl(rmp, rconnout,
9855578Sbostic client? client->files: BootFiles))
9955578Sbostic AddConn(rconnout);
10055578Sbostic else
10155578Sbostic FreeConn(rconnout);
10255578Sbostic }
10355578Sbostic break;
10455578Sbostic
10555578Sbostic case RMP_BOOT_REPL: /* boot reply (not valid) */
10655578Sbostic syslog(LOG_WARNING, "%s: sent a boot reply",
10755578Sbostic EnetStr(rconn));
10855578Sbostic break;
10955578Sbostic
11055578Sbostic case RMP_READ_REQ: /* read request */
11155578Sbostic /*
11255578Sbostic * Send a portion of the boot file.
11355578Sbostic */
11455578Sbostic (void) SendReadRepl(rconn);
11555578Sbostic break;
11655578Sbostic
11755578Sbostic case RMP_READ_REPL: /* read reply (not valid) */
11855578Sbostic syslog(LOG_WARNING, "%s: sent a read reply",
11955578Sbostic EnetStr(rconn));
12055578Sbostic break;
12155578Sbostic
12255578Sbostic case RMP_BOOT_DONE: /* boot complete */
12355578Sbostic /*
12455578Sbostic * Remove the entry from the linked list of active
12555578Sbostic * connections.
12655578Sbostic */
12755578Sbostic (void) BootDone(rconn);
12855578Sbostic break;
12955578Sbostic
13055578Sbostic default: /* unknown RMP packet type */
13155578Sbostic syslog(LOG_WARNING, "%s: unknown packet type (%u)",
13255578Sbostic EnetStr(rconn), rmp->r_type);
13355578Sbostic }
13455578Sbostic }
13555578Sbostic
13655578Sbostic /*
13755578Sbostic ** SendServerID -- send our host name to who ever requested it.
13855578Sbostic **
13955578Sbostic ** Parameters:
14055578Sbostic ** rconn - the reply packet to be formatted.
14155578Sbostic **
14255578Sbostic ** Returns:
14355578Sbostic ** 1 on success, 0 on failure.
14455578Sbostic **
14555578Sbostic ** Side Effects:
14655578Sbostic ** none.
14755578Sbostic */
14855578Sbostic int
SendServerID(rconn)14955578Sbostic SendServerID(rconn)
15055600Sbostic RMPCONN *rconn;
15155578Sbostic {
15255578Sbostic register struct rmp_packet *rpl;
15355578Sbostic register char *src, *dst;
15455578Sbostic register u_char *size;
15555578Sbostic
15655578Sbostic rpl = &rconn->rmp; /* cache ptr to RMP packet */
15755578Sbostic
15855578Sbostic /*
15955578Sbostic * Set up assorted fields in reply packet.
16055578Sbostic */
16155578Sbostic rpl->r_brpl.rmp_type = RMP_BOOT_REPL;
16255578Sbostic rpl->r_brpl.rmp_retcode = RMP_E_OKAY;
16355578Sbostic ZEROWORD(rpl->r_brpl.rmp_seqno);
16455578Sbostic rpl->r_brpl.rmp_session = 0;
16555578Sbostic rpl->r_brpl.rmp_version = RMP_VERSION;
16655578Sbostic
16755578Sbostic size = &rpl->r_brpl.rmp_flnmsize; /* ptr to length of host name */
16855578Sbostic
16955578Sbostic /*
17055578Sbostic * Copy our host name into the reply packet incrementing the
17155578Sbostic * length as we go. Stop at RMP_HOSTLEN or the first dot.
17255578Sbostic */
17355578Sbostic src = MyHost;
17455578Sbostic dst = (char *) &rpl->r_brpl.rmp_flnm;
17555578Sbostic for (*size = 0; *size < RMP_HOSTLEN; (*size)++) {
17655578Sbostic if (*src == '.' || *src == '\0')
17755578Sbostic break;
17855578Sbostic *dst++ = *src++;
17955578Sbostic }
18055578Sbostic
18155578Sbostic rconn->rmplen = RMPBOOTSIZE(*size); /* set packet length */
18255578Sbostic
18355578Sbostic return(SendPacket(rconn)); /* send packet */
18455578Sbostic }
18555578Sbostic
18655578Sbostic /*
18755578Sbostic ** SendFileNo -- send the name of a bootable file to the requester.
18855578Sbostic **
18955578Sbostic ** Parameters:
19055578Sbostic ** req - RMP BOOT packet containing the request.
19155578Sbostic ** rconn - the reply packet to be formatted.
19255578Sbostic ** filelist - list of files available to the requester.
19355578Sbostic **
19455578Sbostic ** Returns:
19555578Sbostic ** 1 on success, 0 on failure.
19655578Sbostic **
19755578Sbostic ** Side Effects:
19855578Sbostic ** none.
19955578Sbostic */
20055578Sbostic int
SendFileNo(req,rconn,filelist)20155600Sbostic SendFileNo(req, rconn, filelist)
20255600Sbostic struct rmp_packet *req;
20355600Sbostic RMPCONN *rconn;
20455600Sbostic char *filelist[];
20555578Sbostic {
20655578Sbostic register struct rmp_packet *rpl;
20755578Sbostic register char *src, *dst;
20855578Sbostic register u_char *size, i;
20955578Sbostic
21055578Sbostic GETWORD(req->r_brpl.rmp_seqno, i); /* SeqNo is really FileNo */
21155578Sbostic rpl = &rconn->rmp; /* cache ptr to RMP packet */
21255578Sbostic
21355578Sbostic /*
21455578Sbostic * Set up assorted fields in reply packet.
21555578Sbostic */
21655578Sbostic rpl->r_brpl.rmp_type = RMP_BOOT_REPL;
21755578Sbostic PUTWORD(i, rpl->r_brpl.rmp_seqno);
21855578Sbostic i--;
21955578Sbostic rpl->r_brpl.rmp_session = 0;
22055578Sbostic rpl->r_brpl.rmp_version = RMP_VERSION;
22155578Sbostic
22255578Sbostic size = &rpl->r_brpl.rmp_flnmsize; /* ptr to length of filename */
22355578Sbostic *size = 0; /* init length to zero */
22455578Sbostic
22555578Sbostic /*
22655578Sbostic * Copy the file name into the reply packet incrementing the
22755578Sbostic * length as we go. Stop at end of string or when RMPBOOTDATA
22855578Sbostic * characters have been copied. Also, set return code to
22955578Sbostic * indicate success or "no more files".
23055578Sbostic */
23155578Sbostic if (i < C_MAXFILE && filelist[i] != NULL) {
23255578Sbostic src = filelist[i];
23355578Sbostic dst = (char *)&rpl->r_brpl.rmp_flnm;
23455578Sbostic for (; *src && *size < RMPBOOTDATA; (*size)++) {
23555578Sbostic if (*src == '\0')
23655578Sbostic break;
23755578Sbostic *dst++ = *src++;
23855578Sbostic }
23955578Sbostic rpl->r_brpl.rmp_retcode = RMP_E_OKAY;
24055578Sbostic } else
24155578Sbostic rpl->r_brpl.rmp_retcode = RMP_E_NODFLT;
24255578Sbostic
24355578Sbostic rconn->rmplen = RMPBOOTSIZE(*size); /* set packet length */
24455578Sbostic
24555578Sbostic return(SendPacket(rconn)); /* send packet */
24655578Sbostic }
24755578Sbostic
24855578Sbostic /*
24955578Sbostic ** SendBootRepl -- open boot file and respond to boot request.
25055578Sbostic **
25155578Sbostic ** Parameters:
25255578Sbostic ** req - RMP BOOT packet containing the request.
25355578Sbostic ** rconn - the reply packet to be formatted.
25455578Sbostic ** filelist - list of files available to the requester.
25555578Sbostic **
25655578Sbostic ** Returns:
25755578Sbostic ** 1 on success, 0 on failure.
25855578Sbostic **
25955578Sbostic ** Side Effects:
26055578Sbostic ** none.
26155578Sbostic */
26255600Sbostic int
SendBootRepl(req,rconn,filelist)26355600Sbostic SendBootRepl(req, rconn, filelist)
26455600Sbostic struct rmp_packet *req;
26555600Sbostic RMPCONN *rconn;
26655600Sbostic char *filelist[];
26755578Sbostic {
26855600Sbostic int retval;
26955578Sbostic char *filename, filepath[RMPBOOTDATA+1];
27055600Sbostic RMPCONN *oldconn;
27155578Sbostic register struct rmp_packet *rpl;
27255578Sbostic register char *src, *dst1, *dst2;
27355578Sbostic register u_char i;
27455578Sbostic
27555578Sbostic /*
27655578Sbostic * If another connection already exists, delete it since we
27755578Sbostic * are obviously starting again.
27855578Sbostic */
27955578Sbostic if ((oldconn = FindConn(rconn)) != NULL) {
28055578Sbostic syslog(LOG_WARNING, "%s: dropping existing connection",
28155578Sbostic EnetStr(oldconn));
28255578Sbostic RemoveConn(oldconn);
28355578Sbostic }
28455578Sbostic
28555578Sbostic rpl = &rconn->rmp; /* cache ptr to RMP packet */
28655578Sbostic
28755578Sbostic /*
28855578Sbostic * Set up assorted fields in reply packet.
28955578Sbostic */
29055578Sbostic rpl->r_brpl.rmp_type = RMP_BOOT_REPL;
29155578Sbostic COPYWORD(req->r_brq.rmp_seqno, rpl->r_brpl.rmp_seqno);
29255578Sbostic rpl->r_brpl.rmp_session = GenSessID();
29355578Sbostic rpl->r_brpl.rmp_version = RMP_VERSION;
29455578Sbostic rpl->r_brpl.rmp_flnmsize = req->r_brq.rmp_flnmsize;
29555578Sbostic
29655578Sbostic /*
29755578Sbostic * Copy file name to `filepath' string, and into reply packet.
29855578Sbostic */
29955578Sbostic src = &req->r_brq.rmp_flnm;
30055578Sbostic dst1 = filepath;
30155578Sbostic dst2 = &rpl->r_brpl.rmp_flnm;
30255578Sbostic for (i = 0; i < req->r_brq.rmp_flnmsize; i++)
30355578Sbostic *dst1++ = *dst2++ = *src++;
30455578Sbostic *dst1 = '\0';
30555578Sbostic
30655578Sbostic /*
30755578Sbostic * If we are booting HP-UX machines, their secondary loader will
30855578Sbostic * ask for files like "/hp-ux". As a security measure, we do not
30955578Sbostic * allow boot files to lay outside the boot directory (unless they
31055578Sbostic * are purposely link'd out. So, make `filename' become the path-
31155578Sbostic * stripped file name and spoof the client into thinking that it
31255578Sbostic * really got what it wanted.
31355578Sbostic */
31455578Sbostic filename = (filename = rindex(filepath,'/'))? ++filename: filepath;
31555578Sbostic
31655578Sbostic /*
31755578Sbostic * Check that this is a valid boot file name.
31855578Sbostic */
31955578Sbostic for (i = 0; i < C_MAXFILE && filelist[i] != NULL; i++)
32055578Sbostic if (STREQN(filename, filelist[i]))
32155578Sbostic goto match;
32255578Sbostic
32355578Sbostic /*
32455578Sbostic * Invalid boot file name, set error and send reply packet.
32555578Sbostic */
32655578Sbostic rpl->r_brpl.rmp_retcode = RMP_E_NOFILE;
32755578Sbostic retval = 0;
32855578Sbostic goto sendpkt;
32955578Sbostic
33055578Sbostic match:
33155578Sbostic /*
33255578Sbostic * This is a valid boot file. Open the file and save the file
33355578Sbostic * descriptor associated with this connection and set success
33455578Sbostic * indication. If the file couldnt be opened, set error:
33555578Sbostic * "no such file or dir" - RMP_E_NOFILE
33655578Sbostic * "file table overflow" - RMP_E_BUSY
33755578Sbostic * "too many open files" - RMP_E_BUSY
33855578Sbostic * anything else - RMP_E_OPENFILE
33955578Sbostic */
34055578Sbostic if ((rconn->bootfd = open(filename, O_RDONLY, 0600)) < 0) {
34155578Sbostic rpl->r_brpl.rmp_retcode = (errno == ENOENT)? RMP_E_NOFILE:
34255578Sbostic (errno == EMFILE || errno == ENFILE)? RMP_E_BUSY:
34355578Sbostic RMP_E_OPENFILE;
34455578Sbostic retval = 0;
34555578Sbostic } else {
34655578Sbostic rpl->r_brpl.rmp_retcode = RMP_E_OKAY;
34755578Sbostic retval = 1;
34855578Sbostic }
34955578Sbostic
35055578Sbostic sendpkt:
35155578Sbostic syslog(LOG_INFO, "%s: request to boot %s (%s)",
35255578Sbostic EnetStr(rconn), filename, retval? "granted": "denied");
35355578Sbostic
35455578Sbostic rconn->rmplen = RMPBOOTSIZE(rpl->r_brpl.rmp_flnmsize);
35555578Sbostic
35655578Sbostic return (retval & SendPacket(rconn));
35755578Sbostic }
35855578Sbostic
35955578Sbostic /*
36055578Sbostic ** SendReadRepl -- send a portion of the boot file to the requester.
36155578Sbostic **
36255578Sbostic ** Parameters:
36355578Sbostic ** rconn - the reply packet to be formatted.
36455578Sbostic **
36555578Sbostic ** Returns:
36655578Sbostic ** 1 on success, 0 on failure.
36755578Sbostic **
36855578Sbostic ** Side Effects:
36955578Sbostic ** none.
37055578Sbostic */
37155578Sbostic int
SendReadRepl(rconn)37255578Sbostic SendReadRepl(rconn)
37355600Sbostic RMPCONN *rconn;
37455578Sbostic {
37555600Sbostic int retval;
37655600Sbostic RMPCONN *oldconn;
37755578Sbostic register struct rmp_packet *rpl, *req;
37855578Sbostic register int size = 0;
37955578Sbostic int madeconn = 0;
38055578Sbostic
38155578Sbostic /*
38255578Sbostic * Find the old connection. If one doesnt exist, create one only
38355578Sbostic * to return the error code.
38455578Sbostic */
38555578Sbostic if ((oldconn = FindConn(rconn)) == NULL) {
38655578Sbostic if ((oldconn = NewConn(rconn)) == NULL)
38755578Sbostic return(0);
38855578Sbostic syslog(LOG_ERR, "SendReadRepl: no active connection (%s)",
38955578Sbostic EnetStr(rconn));
39055578Sbostic madeconn++;
39155578Sbostic }
39255578Sbostic
39355578Sbostic req = &rconn->rmp; /* cache ptr to request packet */
39455578Sbostic rpl = &oldconn->rmp; /* cache ptr to reply packet */
39555578Sbostic
39655578Sbostic if (madeconn) { /* no active connection above; abort */
39755578Sbostic rpl->r_rrpl.rmp_retcode = RMP_E_ABORT;
39855578Sbostic retval = 1;
39955578Sbostic goto sendpkt;
40055578Sbostic }
40155578Sbostic
40255578Sbostic /*
40355578Sbostic * Make sure Session ID's match.
40455578Sbostic */
40555578Sbostic if (req->r_rrq.rmp_session !=
40655578Sbostic ((rpl->r_type == RMP_BOOT_REPL)? rpl->r_brpl.rmp_session:
40755578Sbostic rpl->r_rrpl.rmp_session)) {
40855578Sbostic syslog(LOG_ERR, "SendReadRepl: bad session id (%s)",
40955578Sbostic EnetStr(rconn));
41055578Sbostic rpl->r_rrpl.rmp_retcode = RMP_E_BADSID;
41155578Sbostic retval = 1;
41255578Sbostic goto sendpkt;
41355578Sbostic }
41455578Sbostic
41555578Sbostic /*
41655578Sbostic * If the requester asks for more data than we can fit,
41755578Sbostic * silently clamp the request size down to RMPREADDATA.
41855578Sbostic *
41955578Sbostic * N.B. I do not know if this is "legal", however it seems
42055578Sbostic * to work. This is necessary for bpfwrite() on machines
42155578Sbostic * with MCLBYTES less than 1514.
42255578Sbostic */
42355578Sbostic if (req->r_rrq.rmp_size > RMPREADDATA)
42455578Sbostic req->r_rrq.rmp_size = RMPREADDATA;
42555578Sbostic
42655578Sbostic /*
42755578Sbostic * Position read head on file according to info in request packet.
42855578Sbostic */
42955578Sbostic GETWORD(req->r_rrq.rmp_offset, size);
43055578Sbostic if (lseek(oldconn->bootfd, (off_t)size, L_SET) < 0) {
43155578Sbostic syslog(LOG_ERR, "SendReadRepl: lseek: %m (%s)",
43255578Sbostic EnetStr(rconn));
43355578Sbostic rpl->r_rrpl.rmp_retcode = RMP_E_ABORT;
43455578Sbostic retval = 1;
43555578Sbostic goto sendpkt;
43655578Sbostic }
43755578Sbostic
43855578Sbostic /*
43955578Sbostic * Read data directly into reply packet.
44055578Sbostic */
44155578Sbostic if ((size = read(oldconn->bootfd, &rpl->r_rrpl.rmp_data,
44255578Sbostic (int) req->r_rrq.rmp_size)) <= 0) {
44355578Sbostic if (size < 0) {
44455578Sbostic syslog(LOG_ERR, "SendReadRepl: read: %m (%s)",
44555578Sbostic EnetStr(rconn));
44655578Sbostic rpl->r_rrpl.rmp_retcode = RMP_E_ABORT;
44755578Sbostic } else {
44855578Sbostic rpl->r_rrpl.rmp_retcode = RMP_E_EOF;
44955578Sbostic }
45055578Sbostic retval = 1;
45155578Sbostic goto sendpkt;
45255578Sbostic }
45355578Sbostic
45455578Sbostic /*
45555578Sbostic * Set success indication.
45655578Sbostic */
45755578Sbostic rpl->r_rrpl.rmp_retcode = RMP_E_OKAY;
45855578Sbostic
45955578Sbostic sendpkt:
46055578Sbostic /*
46155578Sbostic * Set up assorted fields in reply packet.
46255578Sbostic */
46355578Sbostic rpl->r_rrpl.rmp_type = RMP_READ_REPL;
46455578Sbostic COPYWORD(req->r_rrq.rmp_offset, rpl->r_rrpl.rmp_offset);
46555578Sbostic rpl->r_rrpl.rmp_session = req->r_rrq.rmp_session;
46655578Sbostic
46755578Sbostic oldconn->rmplen = RMPREADSIZE(size); /* set size of packet */
46855578Sbostic
46955578Sbostic retval &= SendPacket(oldconn); /* send packet */
47055578Sbostic
47155578Sbostic if (madeconn) /* clean up after ourself */
47255578Sbostic FreeConn(oldconn);
47355578Sbostic
47455578Sbostic return (retval);
47555578Sbostic }
47655578Sbostic
47755578Sbostic /*
47855578Sbostic ** BootDone -- free up memory allocated for a connection.
47955578Sbostic **
48055578Sbostic ** Parameters:
48155578Sbostic ** rconn - incoming boot complete packet.
48255578Sbostic **
48355578Sbostic ** Returns:
48455578Sbostic ** 1 on success, 0 on failure.
48555578Sbostic **
48655578Sbostic ** Side Effects:
48755578Sbostic ** none.
48855578Sbostic */
48955578Sbostic int
BootDone(rconn)49055578Sbostic BootDone(rconn)
49155600Sbostic RMPCONN *rconn;
49255578Sbostic {
49355600Sbostic RMPCONN *oldconn;
49455578Sbostic struct rmp_packet *rpl;
49555578Sbostic
49655578Sbostic /*
49755578Sbostic * If we cant find the connection, ignore the request.
49855578Sbostic */
49955578Sbostic if ((oldconn = FindConn(rconn)) == NULL) {
50055578Sbostic syslog(LOG_ERR, "BootDone: no existing connection (%s)",
50155578Sbostic EnetStr(rconn));
50255578Sbostic return(0);
50355578Sbostic }
50455578Sbostic
50555578Sbostic rpl = &oldconn->rmp; /* cache ptr to RMP packet */
50655578Sbostic
50755578Sbostic /*
50855578Sbostic * Make sure Session ID's match.
50955578Sbostic */
51055578Sbostic if (rconn->rmp.r_rrq.rmp_session !=
51155578Sbostic ((rpl->r_type == RMP_BOOT_REPL)? rpl->r_brpl.rmp_session:
51255578Sbostic rpl->r_rrpl.rmp_session)) {
51355578Sbostic syslog(LOG_ERR, "BootDone: bad session id (%s)",
51455578Sbostic EnetStr(rconn));
51555578Sbostic return(0);
51655578Sbostic }
51755578Sbostic
51855578Sbostic RemoveConn(oldconn); /* remove connection */
51955578Sbostic
52055578Sbostic syslog(LOG_INFO, "%s: boot complete", EnetStr(rconn));
52155578Sbostic
52255578Sbostic return(1);
52355578Sbostic }
52455578Sbostic
52555578Sbostic /*
52655578Sbostic ** SendPacket -- send an RMP packet to a remote host.
52755578Sbostic **
52855578Sbostic ** Parameters:
52955578Sbostic ** rconn - packet to be sent.
53055578Sbostic **
53155578Sbostic ** Returns:
53255578Sbostic ** 1 on success, 0 on failure.
53355578Sbostic **
53455578Sbostic ** Side Effects:
53555578Sbostic ** none.
53655578Sbostic */
53755578Sbostic int
SendPacket(rconn)53855578Sbostic SendPacket(rconn)
53955600Sbostic register RMPCONN *rconn;
54055578Sbostic {
54155578Sbostic /*
54255578Sbostic * Set Ethernet Destination address to Source (BPF and the enet
54355578Sbostic * driver will take care of getting our source address set).
54455578Sbostic */
54555578Sbostic bcopy((char *)&rconn->rmp.hp_hdr.saddr[0],
54655578Sbostic (char *)&rconn->rmp.hp_hdr.daddr[0], RMP_ADDRLEN);
54755578Sbostic rconn->rmp.hp_hdr.len = rconn->rmplen - sizeof(struct hp_hdr);
54855578Sbostic
54955578Sbostic /*
55055578Sbostic * Reverse 802.2/HP Extended Source & Destination Access Pts.
55155578Sbostic */
55255578Sbostic rconn->rmp.hp_llc.dxsap = HPEXT_SXSAP;
55355578Sbostic rconn->rmp.hp_llc.sxsap = HPEXT_DXSAP;
55455578Sbostic
55555578Sbostic /*
55655578Sbostic * Last time this connection was active.
55755578Sbostic */
55855578Sbostic (void) gettimeofday(&rconn->tstamp, (struct timezone *)0);
55955578Sbostic
56055578Sbostic if (DbgFp != NULL) /* display packet */
56155578Sbostic DispPkt(rconn,DIR_SENT);
56255578Sbostic
56355578Sbostic /*
56455578Sbostic * Send RMP packet to remote host.
56555578Sbostic */
56655578Sbostic return(BpfWrite(rconn));
56755578Sbostic }
568