From 7b86659847b3654196b354e8578d4d1299306803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Victor?= Date: Tue, 3 Aug 2021 16:29:19 +0200 Subject: [PATCH 1/2] Respond to NOP pkts with IP info This allows ITS to pick up the IP configured here, instead of having to recompile ITS to match any change. --- src/dpimp.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/dpimp.h | 2 +- src/dvlhdh.c | 2 ++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/dpimp.c b/src/dpimp.c index 1617293..85060c8 100644 --- a/src/dpimp.c +++ b/src/dpimp.c @@ -322,6 +322,7 @@ void ether_write(struct eth_header *, unsigned char *, int); void ihl_frag(int, unsigned char *); void ihl_hhsend(struct dpimp_s *, int, unsigned char *); +static void ihl_hhsend_nop(struct dpimp_s *dpimp); void dumppkt(unsigned char *, int); /* Error and diagnostic output */ @@ -1417,6 +1418,11 @@ imptohost(struct dpimp_s *dpimp) ether_hdr_offset = ETHER_HDRSIZ; } + // wait here for first NOP received + dp_xswait(dpx); + // then send a NOP reply to host + ihl_hhsend_nop(dpimp); + for (;;) { /* Make sure that buffer is free before clobbering it */ dp_xswait(dpx); /* Wait until buff free */ @@ -1540,6 +1546,57 @@ unsigned char ihobuf[SIH_HSIZ+SI_LDRSIZ] = { }; +static void +ihl_hhsend_nop(struct dpimp_s *dpimp) +/* Send NOP response to host */ +{ + struct dpx_s *dpx = dp_dpxfr(&dp); + size_t off, max; + unsigned int m; + int cnt, nmsiz = 0; + unsigned char *ea = (unsigned char *)&ehost_ip; + unsigned char *buff = dp_xsbuff(dpx, &max); /* get initial buffer ptr */ + dp_xswait(dpx); /* wait until buff free */ + off = 0; // hmm + memset(buff, 0, SIH_HSIZ+SI_LDRSIZ); + // fill buff with NOP leader with IP info + buff[SIH_HSIZ+SIL_FMT] = 017; // format + // could use SIL_HTY which is next to the rest, but this is easy to test IMP in ITS. + buff[SIH_HSIZ+SIL_NET] = ea[0]; // network, "currently set to zero" + buff[SIH_HSIZ+SIL_TYP] = SIMT_NOP; // message type + // source host and imp + buff[SIH_HSIZ+SIL_HST] = ea[1]; + buff[SIH_HSIZ+SIL_IMP1] = ea[2]; + buff[SIH_HSIZ+SIL_IMP0] = ea[3]; + if (ihost_nm.s_addr == 0) + // the netmask for tun really shouldn't matter. + nmsiz = 24; + else { + // calculate netmask size - is there a cleverer way? + m = ihost_nm.s_addr; + if (m != 0) { + while ((m & 1) == 0) m >>= 1; + } + while (((m & 1) == 1) && (nmsiz < 32)) { + nmsiz++; + m >>= 1; + } + } + // abuse these bits which are not used by NOP normally (handling type) + buff[SIH_HSIZ+SIL_HTY] = nmsiz; + if (DBGFLG) + fprintf(stderr,"IMP: sending NOP (ehost %#x, imask %#x) with address %d.%d.%d.%d and mask size %d\r\n", + ntohl(ehost_ip.s_addr), ntohl(ihost_nm.s_addr), + buff[SIH_HSIZ+SIL_NET], buff[SIH_HSIZ+SIL_HST], buff[SIH_HSIZ+SIL_IMP1], buff[SIH_HSIZ+SIL_IMP0], + buff[SIH_HSIZ+SIL_HTY]); + // send it off + cnt = SIH_HSIZ + SI_LDRSIZ; + dpimp->dpimp_inoff = off; + dp_xsend(dpx, DPIMP_RPKT, cnt+off); + if (DBGFLG) + fprintf(stderr, "[dpimp-R: sent NOP RPKT %d+%d]", (int)off, cnt); +} + void ihl_hhsend(struct dpimp_s *dpimp, int cnt, @@ -1726,6 +1783,10 @@ hosttoimp(struct dpimp_s *dpimp) /* A real IMP would examine this to see how much padding to ** add onto its leaders. However, ITS never wants any. */ + if (DBGFLG) fprintf(stderr, "[dpimp-W: NOP]\r\n"); + // respond with a NOP including IP address and mask + // #### NOTE: using dpxfr to let imptohost proceed, instead of dvlhdh doing it + dp_xrdone(dp_dpxfr(&dp)); break; case SIMT_DERR: /* Error in Data (has msg-id) */ diff --git a/src/dpimp.h b/src/dpimp.h index 8812293..1e21197 100644 --- a/src/dpimp.h +++ b/src/dpimp.h @@ -93,7 +93,7 @@ /* Version of DPIMP-specific shared memory structure */ -#define DPIMP_VERSION ((1<<10) | (1<<5) | (3)) /* 1.1.3 */ +#define DPIMP_VERSION ((1<<10) | (1<<5) | (4)) /* 1.1.3 */ #define IFNAM_LEN 16 /* at least IFNAMSIZ! */ diff --git a/src/dvlhdh.c b/src/dvlhdh.c index ac6b27f..a590198 100644 --- a/src/dvlhdh.c +++ b/src/dvlhdh.c @@ -1293,7 +1293,9 @@ imp_incheck(register struct lhdh *lh) switch (dp_xrcmd(dpx)) { case DPIMP_INIT: /* Do stuff to turn on IMP ready line? */ +#if 0 // #### NOTE: let hosttoimp do this when the first NOP arrives dp_xrdone(dpx); /* ACK it */ +#endif return 0; /* No actual input */ case DPIMP_RPKT: /* Input packet ready! */ From 98fa6ee89084a5e1211c606e1e5bbf763ae63c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Victor?= Date: Tue, 3 Aug 2021 16:49:59 +0200 Subject: [PATCH 2/2] Comment to match --- src/dpimp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dpimp.h b/src/dpimp.h index 1e21197..9d74978 100644 --- a/src/dpimp.h +++ b/src/dpimp.h @@ -93,7 +93,7 @@ /* Version of DPIMP-specific shared memory structure */ -#define DPIMP_VERSION ((1<<10) | (1<<5) | (4)) /* 1.1.3 */ +#define DPIMP_VERSION ((1<<10) | (1<<5) | (4)) /* 1.1.4 */ #define IFNAM_LEN 16 /* at least IFNAMSIZ! */