mirror of
https://github.com/PDP-10/klh10.git
synced 2026-01-11 23:52:54 +00:00
Implement QUIT messages to IMP and NI20
so that they can do cleanup at the end: mostly important for tun, tap, and bridge that may have been created.
This commit is contained in:
parent
1a512d7628
commit
563368b75b
44
src/dpimp.c
44
src/dpimp.c
@ -275,6 +275,7 @@ int mylockid; /* Locker IDs: 1 for W, 0 for R */
|
||||
int othlockid;
|
||||
int swstatus = TRUE;
|
||||
struct pfdata pfdata; /* Packet-Filter state */
|
||||
struct osnpf npf; /* Configuration data */
|
||||
|
||||
struct in_addr ehost_ip; /* Emulated guest IP addr, net order */
|
||||
struct in_addr ihost_ip; /* IMP/Native host IP addr, net order */
|
||||
@ -621,7 +622,10 @@ main(int argc, char **argv)
|
||||
|
||||
hosttoimp(dpimp); /* Parent process handles output */
|
||||
|
||||
return 1; /* Never returns, but placate compiler */
|
||||
osn_pfdeinit(&pfdata, &npf);/* Clean up created tunnels etc */
|
||||
dp_xrdone(dp_dpxto(&dp));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* NET_INIT - Initialize net-related variables,
|
||||
@ -688,24 +692,20 @@ net_init(struct dpimp_s *dpimp)
|
||||
** Should also determine interface's ethernet addr, if possible,
|
||||
** and set ihost_ea.
|
||||
*/
|
||||
{
|
||||
struct osnpf npf; /* Configuration data */
|
||||
|
||||
npf.osnpf_ifnam = dpimp->dpimp_ifnam;
|
||||
npf.osnpf_ifmeth = dpimp->dpimp_ifmeth;
|
||||
npf.osnpf_dedic = FALSE; /* Force filtering always! */
|
||||
npf.osnpf_rdtmo = dpimp->dpimp_rdtmo;
|
||||
npf.osnpf_backlog = dpimp->dpimp_backlog;
|
||||
npf.osnpf_ip.ia_addr = ehost_ip;
|
||||
npf.osnpf_tun.ia_addr = tun_ip;
|
||||
/* Ether addr is both a potential arg and a returned value;
|
||||
the packetfilter open may use and/or change it.
|
||||
*/
|
||||
ea_set(&npf.osnpf_ea, dpimp->dpimp_eth);/* Set requested ea if any */
|
||||
osn_pfinit(&pfdata, &npf, (void *)dpimp);/* Will abort if fails */
|
||||
ea_set(&ihost_ea, &npf.osnpf_ea); /* Copy actual ea if one */
|
||||
tun_ip = npf.osnpf_tun.ia_addr; /* Copy actual tun if any */
|
||||
}
|
||||
npf.osnpf_ifnam = dpimp->dpimp_ifnam;
|
||||
npf.osnpf_ifmeth = dpimp->dpimp_ifmeth;
|
||||
npf.osnpf_dedic = FALSE; /* Force filtering always! */
|
||||
npf.osnpf_rdtmo = dpimp->dpimp_rdtmo;
|
||||
npf.osnpf_backlog = dpimp->dpimp_backlog;
|
||||
npf.osnpf_ip.ia_addr = ehost_ip;
|
||||
npf.osnpf_tun.ia_addr = tun_ip;
|
||||
/* Ether addr is both a potential arg and a returned value;
|
||||
the packetfilter open may use and/or change it.
|
||||
*/
|
||||
ea_set(&npf.osnpf_ea, dpimp->dpimp_eth);/* Set requested ea if any */
|
||||
osn_pfinit(&pfdata, &npf, (void *)dpimp);/* Will abort if fails */
|
||||
ea_set(&ihost_ea, &npf.osnpf_ea); /* Copy actual ea if one */
|
||||
tun_ip = npf.osnpf_tun.ia_addr; /* Copy actual tun if any */
|
||||
|
||||
if (!pfdata.pf_ip4_only) {
|
||||
/* Now set remaining stuff */
|
||||
@ -1646,6 +1646,12 @@ hosttoimp(struct dpimp_s *dpimp)
|
||||
fprintf(stderr, "[dpimp-W: SPKT %d]", rcnt);
|
||||
}
|
||||
break;
|
||||
|
||||
case DPIMP_QUIT:
|
||||
if (DBGFLG)
|
||||
fprintf(stderr, "[dpimp-W: QUIT]\r\n");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/* Come here to handle output packet */
|
||||
|
||||
@ -154,6 +154,7 @@ but the alignment may make it slightly easier for O/S I/O).
|
||||
#define DPIMP_RESET 0 /* Reset DP */
|
||||
#define DPIMP_SPKT 1 /* Send data packet to ethernet */
|
||||
#define DPIMP_SETETH 2 /* Set hardware ethernet address */
|
||||
#define DPIMP_QUIT 3 /* Clean up and exit */
|
||||
|
||||
/* From DP to 10 */
|
||||
#define DPIMP_INIT 1 /* DP->10 Finished init */
|
||||
|
||||
10
src/dpni20.c
10
src/dpni20.c
@ -442,9 +442,10 @@ main(int argc, char **argv)
|
||||
progname = progname_w; /* Reset progname to indicate identity */
|
||||
tentoeth(dpni); /* Parent process handles output to net */
|
||||
|
||||
osn_pfdeinit(&pfdata, &npf);
|
||||
osn_pfdeinit(&pfdata, &npf);/* Clean up created tunnels etc */
|
||||
dp_xrdone(dp_dpxto(&dp));
|
||||
|
||||
return 1; /* Never returns, but placate compiler */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* NET_INIT - Initialize net-related variables,
|
||||
@ -1359,6 +1360,11 @@ void tentoeth(struct dpni20_s *dpni)
|
||||
#endif
|
||||
break;
|
||||
|
||||
case DPNI_QUIT:
|
||||
if (DBGFLG)
|
||||
dbprint("QUIT");
|
||||
return;
|
||||
|
||||
default:
|
||||
dbprintln("Unknown cmd %d", dp_xrcmd(dpx));
|
||||
break;
|
||||
|
||||
@ -70,6 +70,7 @@ struct dpni20_s {
|
||||
#define DPNI_SETETH 2 /* Set hardware ethernet address */
|
||||
#define DPNI_SETMCAT 3 /* Set hardware multicasts from MCAT table */
|
||||
#define DPNI_SETPTT 4 /* Set packetfilter using PTT */
|
||||
#define DPNI_QUIT 5 /* Clean up and exit */
|
||||
|
||||
/* From DP to 10 */
|
||||
#define DPNI_INIT 1 /* DP->10 Finished init */
|
||||
|
||||
33
src/dvlhdh.c
33
src/dvlhdh.c
@ -1141,18 +1141,47 @@ imp_start(register struct lhdh *lh)
|
||||
if (DVDEBUG(lh))
|
||||
fprintf(DVDBF(lh), " started!]\r\n");
|
||||
|
||||
lh->lh_dpstate = TRUE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* IMP_QUIT - Tells the IMP process to quit
|
||||
** and clean up resources such as networking tunnels.
|
||||
*/
|
||||
static void
|
||||
imp_quit(register struct lhdh *lh)
|
||||
{
|
||||
struct dpx_s *dpx = dp_dpxto(&lh->lh_dp);
|
||||
|
||||
/* Make sure we can send the message, or just skip it if not */
|
||||
if (lh->lh_dpstate) {
|
||||
if (DVDEBUG(lh))
|
||||
fprintf(DVDBF(lh), " [Sending QUIT to IMP]");
|
||||
|
||||
/* Make sure we can output message and just skip it if not */
|
||||
if (dp_xswait(dpx)) {
|
||||
dp_xsend(dpx, DPIMP_QUIT, 0);
|
||||
dp_xswait(dpx);
|
||||
}
|
||||
} else {
|
||||
if (DVDEBUG(lh))
|
||||
fprintf(DVDBF(lh), "[No need to send QUIT to IMP]");
|
||||
}
|
||||
}
|
||||
|
||||
/* IMP_STOP - Stops IMP and drops Host Ready by killing IMP subproc,
|
||||
** but allow restarting.
|
||||
*/
|
||||
static void
|
||||
imp_stop(register struct lhdh *lh)
|
||||
{
|
||||
struct dpx_s *dpx = dp_dpxto(&lh->lh_dp);
|
||||
|
||||
if (DVDEBUG(lh))
|
||||
fprintf(DVDBF(lh), "[IMP: stopping...");
|
||||
|
||||
imp_quit(lh);
|
||||
dp_stop(&lh->lh_dp, 1); /* Say to kill and wait 1 sec for synch */
|
||||
|
||||
lh->lh_dpstate = FALSE; /* No longer there and ready */
|
||||
@ -1169,6 +1198,8 @@ imp_kill(register struct lhdh *lh)
|
||||
if (DVDEBUG(lh))
|
||||
fprintf(DVDBF(lh), "[IMP kill]\r\n");
|
||||
|
||||
imp_quit(lh);
|
||||
|
||||
lh->lh_dpstate = FALSE;
|
||||
(*lh->lh_dv.dv_evreg)( /* Flush all event handlers for device */
|
||||
(struct device *)lh,
|
||||
@ -1549,6 +1580,8 @@ imp_stop(register struct lhdh *lh)
|
||||
if (DVDEBUG(lh))
|
||||
fprintf(DVDBF(lh), "[IMP stop - %d]\r\n", lh->lh_imppid);
|
||||
|
||||
/* Should send a QUIT message here */
|
||||
|
||||
if (lh->lh_imppid) {
|
||||
int status;
|
||||
kill(lh->lh_imppid, SIGKILL);
|
||||
|
||||
23
src/dvni20.c
23
src/dvni20.c
@ -769,6 +769,28 @@ ni20_reset(struct device *d)
|
||||
ni20_clear((struct ni20 *)d);
|
||||
}
|
||||
|
||||
/* NI20_QUIT - Tells the IMP process to quit
|
||||
** and clean up resources such as networking tunnels.
|
||||
*/
|
||||
static void
|
||||
ni20_quit(struct ni20 *ni)
|
||||
{
|
||||
struct dpx_s *dpx = &(ni->ni_dp.dp_adr->dpc_frdp);
|
||||
|
||||
/* Make sure we can send the message, or just skip it if not */
|
||||
if (ni->ni_dpstate) {
|
||||
if (DVDEBUG(ni))
|
||||
fprintf(NIDBF(ni), " [Sending QUIT to NI20]");
|
||||
|
||||
if (dp_xswait(dpx)) {
|
||||
dp_xsend(dpx, DPNI_QUIT, 0);
|
||||
dp_xswait(dpx);
|
||||
}
|
||||
} else {
|
||||
if (DVDEBUG(ni))
|
||||
fprintf(NIDBF(ni), "[No need to send QUIT to NI20]");
|
||||
}
|
||||
}
|
||||
|
||||
/* NI20_POWOFF - Handle "power-off" which usually means the KLH10 is
|
||||
** being shut down. This is important if using a dev subproc!
|
||||
@ -1558,6 +1580,7 @@ ni20_stop(register struct ni20 *ni)
|
||||
fprintf(NIDBF(ni), "[ni20_stop: stopping...");
|
||||
|
||||
if (ni->ni_dp.dp_chpid) {
|
||||
ni20_quit(ni);
|
||||
dp_stop(&ni->ni_dp, 1); /* Say to kill and wait 1 sec for synch */
|
||||
}
|
||||
|
||||
|
||||
@ -1936,7 +1936,7 @@ osn_pfinit_tuntap(struct pfdata *pfdata, struct osnpf *osnpf, void *arg)
|
||||
|
||||
|
||||
/*
|
||||
* Too bad that this is never called...
|
||||
* Clean up any tunnels or bridges or whatever we have created.
|
||||
*/
|
||||
void
|
||||
osn_pfdeinit_tuntap(struct pfdata *pfdata, struct osnpf *osnpf)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user