1
0
mirror of https://github.com/PDP-10/klh10.git synced 2026-01-11 23:52:54 +00:00

Patch applied. No conflicts.

klh10$ patch -p1 <tuntap.patch
Hmm...  Looks like a new-style context diff to me...
The text leading up to this was:
--------------------------
|*** klh10-2.0h/bld/lnx86/00build       2005-02-22 02:47:02.000000000
|-0500
|--- klh10-2.0i/bld/lnx86/00build       2005-09-10 01:05:48.000000000
|-0400
--------------------------
Patching file bld/lnx86/00build using Plan A...
Hunk #1 succeeded at 1.
Hmm...  The next patch looks like a new-style context diff to me...
The text leading up to this was:
--------------------------
|*** klh10-2.0h/src/dpimp.c     2003-02-23 13:07:35.000000000 -0500
|--- klh10-2.0i/src/dpimp.c     2005-09-11 10:14:55.000000000 -0400
--------------------------
Patching file src/dpimp.c using Plan A...
Hunk #1 succeeded at 279.
Hunk #2 succeeded at 501.
Hunk #3 succeeded at 563.
Hunk #4 succeeded at 573.
Hunk #5 succeeded at 637.
Hunk #6 succeeded at 695.
Hunk #7 succeeded at 709.
Hunk #8 succeeded at 1755.
Hmm...  The next patch looks like a new-style context diff to me...
The text leading up to this was:
--------------------------
|*** klh10-2.0h/src/dpimp.h     2001-11-19 05:45:49.000000000 -0500
|--- klh10-2.0i/src/dpimp.h     2005-08-16 20:05:22.000000000 -0400
--------------------------
Patching file src/dpimp.h using Plan A...
Hunk #1 succeeded at 106.
Hmm...  The next patch looks like a new-style context diff to me...
The text leading up to this was:
--------------------------
|*** klh10-2.0h/src/dpni20.c    2003-02-23 13:07:50.000000000 -0500
|--- klh10-2.0i/src/dpni20.c    2005-09-09 20:50:47.000000000 -0400
--------------------------
Patching file src/dpni20.c using Plan A...
Hunk #1 succeeded at 177.
Hunk #2 succeeded at 388.
Hunk #3 succeeded at 456.
Hunk #4 succeeded at 491.
Hunk #5 succeeded at 506.
Hunk #6 succeeded at 1463.
Hunk #7 succeeded at 1531.
Hunk #8 succeeded at 1543.
Hmm...  The next patch looks like a new-style context diff to me...
The text leading up to this was:
--------------------------
|*** klh10-2.0h/src/dpni20.h    2001-11-10 16:29:01.000000000 -0500
|--- klh10-2.0i/src/dpni20.h    2005-08-16 20:05:22.000000000 -0400
--------------------------
Patching file src/dpni20.h using Plan A...
Hunk #1 succeeded at 52.
Hmm...  The next patch looks like a new-style context diff to me...
The text leading up to this was:
--------------------------
|diff -r -c --exclude='*.orig' --unidirectional-new-file
|klh10-2.0h/src/dvlhdh.c klh10-2.0i/src/dvlhdh.c
|*** klh10-2.0h/src/dvlhdh.c    2001-11-19 05:47:54.000000000 -0500
|--- klh10-2.0i/src/dvlhdh.c    2005-08-16 20:05:22.000000000 -0400
--------------------------
Patching file src/dvlhdh.c using Plan A...
Hunk #1 succeeded at 103.
Hunk #2 succeeded at 172.
Hunk #3 succeeded at 303.
Hunk #4 succeeded at 1066.
Hmm...  The next patch looks like a new-style context diff to me...
The text leading up to this was:
--------------------------
|*** klh10-2.0h/src/dvni20.c    2001-11-10 16:29:03.000000000 -0500
|--- klh10-2.0i/src/dvni20.c    2005-08-16 20:05:22.000000000 -0400
--------------------------
Patching file src/dvni20.c using Plan A...
Hunk #1 succeeded at 157.
Hunk #2 succeeded at 295.
Hunk #3 succeeded at 393.
Hunk #4 succeeded at 720.
Hmm...  The next patch looks like a new-style context diff to me...
The text leading up to this was:
--------------------------
|*** klh10-2.0h/src/Makefile.mk 2005-02-22 02:16:14.000000000 -0500
|--- klh10-2.0i/src/Makefile.mk 2005-08-16 20:05:22.000000000 -0400
--------------------------
Patching file src/Makefile.mk using Plan A...
Hunk #1 succeeded at 302.
Hmm...  The next patch looks like a new-style context diff to me...
The text leading up to this was:
--------------------------
|*** klh10-2.0h/src/osdnet.c    2005-04-28 18:01:04.000000000 -0400
|--- klh10-2.0i/src/osdnet.c    2005-09-11 11:12:41.000000000 -0400
--------------------------
Patching file src/osdnet.c using Plan A...
Hunk #1 succeeded at 812.
Hunk #2 succeeded at 1131.
Hunk #3 succeeded at 1162.
Hunk #4 succeeded at 1225.
Hunk #5 succeeded at 1616.
Hunk #6 succeeded at 1633.
Hunk #7 succeeded at 1691.
Hunk #8 succeeded at 1721.
Hunk #9 succeeded at 1817.
Hmm...  The next patch looks like a new-style context diff to me...
The text leading up to this was:
--------------------------
|*** klh10-2.0h/src/osdnet.h    2001-11-19 05:34:01.000000000 -0500
|--- klh10-2.0i/src/osdnet.h    2005-08-16 20:05:22.000000000 -0400
--------------------------
Patching file src/osdnet.h using Plan A...
Hunk #1 succeeded at 69.
Hunk #2 succeeded at 146.
Hunk #3 succeeded at 382.
done
klh10$
This commit is contained in:
Olaf Seibert 2015-07-21 23:37:45 +02:00
parent fcd51e4ce0
commit 0fdbb8f017
10 changed files with 166 additions and 31 deletions

View File

@ -1,2 +1,2 @@
#!/bin/sh
make base-kl CONFFLAGS_AUX=-DKLH10_I_CIRC=1 LDFLAGS=-static
make -k base-kl CONFFLAGS_AUX="-DKLH10_NET_TUN=1 -DKLH10_I_CIRC=1"

View File

@ -302,7 +302,6 @@ base-ks-its:
-DKLH10_DEV_DPRPXX=1 \
-DKLH10_DEV_DPIMP=1 \
-DKLH10_SIMP=0 \
-DKLH10_NET_TUN=SYS_FREEBSD \
-DKLH10_MEM_SHARED=1 \
$(TINTFLAGS) \
$(DINTFLAGS) \

View File

@ -279,7 +279,11 @@ struct in_addr ehost_ip; /* Emulated host IP addr, net order */
struct in_addr ihost_ip; /* IMP/Native host IP addr, net order */
struct in_addr ihost_nm; /* IMP/Native host subnet netmask, net order */
struct in_addr ihost_net; /* IMP/Native host net #, net order */
#if KLH10_NET_TUN
struct in_addr tun_ip; /* IP addr of tunnel */
#else
struct in_addr gwdef_ip; /* IP addr of default prime gateway */
#endif
struct ether_addr ehost_ea; /* Emulated host ethernet addr */
struct ether_addr ihost_ea; /* IMP/Native host ethernet addr */
@ -497,7 +501,11 @@ main(int argc, char **argv)
shared DP area.
*/
memcpy((void *)&ehost_ip, dpimp->dpimp_ip, 4); /* Host IP addr */
#if KLH10_NET_TUN
memcpy((void *)&tun_ip, dpimp->dpimp_tun, 4); /* Tunnel addr */
#else
memcpy((void *)&gwdef_ip, dpimp->dpimp_gw, 4); /* Default GW addr */
#endif
memcpy((void *)&ehost_ea, dpimp->dpimp_eth, 6); /* Host Ether addr */
/* IMP must always have IP address specified! */
@ -555,6 +563,7 @@ main(int argc, char **argv)
char ipbuf[OSN_IPSTRSIZ];
char eabuf[OSN_EASTRSIZ];
#if !KLH10_NET_TUN
dbprintln("ifc \"%s\" => ether %s",
dpimp->dpimp_ifnam,
eth_adrsprint(eabuf, (unsigned char *)&ihost_ea));
@ -564,10 +573,16 @@ main(int argc, char **argv)
ip_adrsprint(ipbuf, (unsigned char *)&ihost_nm));
dbprintln(" net %s",
ip_adrsprint(ipbuf, (unsigned char *)&ihost_net));
dbprintln(" HOST: %s",
ip_adrsprint(ipbuf, (unsigned char *)&ehost_ip));
dbprintln(" gwdef %s",
ip_adrsprint(ipbuf, (unsigned char *)&gwdef_ip));
#else
dbprintln("ifc \"%s\"",
dpimp->dpimp_ifnam);
dbprintln(" tun %s",
ip_adrsprint(ipbuf, (unsigned char *)&tun_ip));
#endif
dbprintln(" HOST %s",
ip_adrsprint(ipbuf, (unsigned char *)&ehost_ip));
}
/* Init ARP stuff - ensure can talk to native host.
@ -622,6 +637,8 @@ net_init(register struct dpimp_s *dpimp)
{
struct ifreq ifr;
#if !KLH10_NET_TUN
#if 1 /* This code is identical to dpni20 - merge in osdnet? */
/* Ensure network device name, if specified, isn't too long */
@ -678,6 +695,8 @@ net_init(register struct dpimp_s *dpimp)
if (gwdef_ip.s_addr == -1 || gwdef_ip.s_addr == 0)
efatal(1, "No default prime gateway specified");
#endif
/* Set up appropriate net fd and packet filter.
** Should also determine interface's ethernet addr, if possible,
** and set ihost_ea.
@ -690,12 +709,18 @@ net_init(register struct dpimp_s *dpimp)
npf.osnpf_rdtmo = dpimp->dpimp_rdtmo;
npf.osnpf_backlog = dpimp->dpimp_backlog;
npf.osnpf_ip.ia_addr = ehost_ip;
#if KLH10_NET_TUN
npf.osnpf_tun.ia_addr = tun_ip;
#endif
/* 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 */
pffd = osn_pfinit(&npf, (void *)dpimp); /* Will abort if fails */
ea_set(&ihost_ea, &npf.osnpf_ea); /* Copy actual ea if one */
#if KLH10_NET_TUN
tun_ip = npf.osnpf_tun.ia_addr; /* Copy actual tun if any */
#endif
}
}
@ -1730,7 +1755,11 @@ ihl_hhsend(register struct dpimp_s *dpimp,
/* Hack to set host/imp value as properly as possible. */
memcpy((char *)&haddr.ia_octet[0], pp + IPBOFF_SRC, 4);
if ((haddr.ia_addr.s_addr & ihost_nm.s_addr) != ihost_net.s_addr) {
#if !KLH10_NET_TUN
haddr.ia_addr = gwdef_ip; /* Not local, use default GW */
#else
haddr.ia_addr = tun_ip; /* Not local, use tunnel end */
#endif
}
ihobuf[SIH_HSIZ+SIL_HST] = haddr.ia_octet[1];

View File

@ -106,6 +106,7 @@ struct dpimp_s {
unsigned char dpimp_eth[6]; /* CD Ethernet address of interface */
unsigned char dpimp_ip[4]; /* C 10's IP address to filter on, if shared */
unsigned char dpimp_gw[4]; /* C Default GW address for IMP to use */
unsigned char dpimp_tun[4]; /* CD Tunnel address for IMP */
int dpimp_inoff; /* C Offset in buffer of input (I->H) data */
int dpimp_outoff; /* D Offset in buffer of output (H->I) data */
int dpimp_backlog; /* C Max sys backlog of rcvd packets */

View File

@ -177,7 +177,12 @@ int pffd; /* Packet-Filter FD (bidirectional) */
struct dp_s dp; /* Device-Process struct for DP ops */
struct in_addr ehost_ip; /* Emulated host IP addr, net order */
#if 0
struct in_addr ihost_ip; /* Native host's IP addr, net order */
#endif
#if KLH10_NET_TUN
struct in_addr tun_ip; /* Tunnel IP addr, net order */
#endif
struct ether_addr ihost_ea; /* Native host ether addr for selected ifc */
/* Debug flag reference. Use DBGFLG within functions that have "dpni";
@ -383,14 +388,20 @@ main(int argc, char **argv)
net_init(dpni);
/* Make this a status (rather than debug) printout? */
if (DBGFLG) {
if (swstatus) {
char sbuf[OSN_IPSTRSIZ+OSN_EASTRSIZ]; /* Lazily ensure big enough */
dbprintln("ifc \"%s\" => ether %s",
dpni->dpni_ifnam,
eth_adrsprint(sbuf, (unsigned char *)&ihost_ea));
#if 0
dbprintln(" addr %s",
ip_adrsprint(sbuf, (unsigned char *)&ihost_ip));
#endif
#if KLH10_NET_TUN
dbprintln(" tun %s",
ip_adrsprint(sbuf, (unsigned char *)&tun_ip));
#endif
dbprintln(" VHOST %s",
ip_adrsprint(sbuf, (unsigned char *)&ehost_ip));
}
@ -445,6 +456,10 @@ void net_init(register struct dpni20_s *dpni)
/* Get the IP address we need to filter on, if shared */
memcpy((char *)&ehost_ip, (char *)&dpni->dpni_ip, 4);
#if KLH10_NET_TUN
/* Get the IP address for the tunnel, if specified */
memcpy((char *)&tun_ip, (char *)&dpni->dpni_tun, 4);
#else
/* Ensure network device name, if specified, isn't too long */
if (dpni->dpni_ifnam[0] && (strlen(dpni->dpni_ifnam)
>= sizeof(ifr.ifr_name))) {
@ -476,6 +491,7 @@ void net_init(register struct dpni20_s *dpni)
dbprintln("Using default interface \"%s\"", dpni->dpni_ifnam);
}
}
#endif
/* Now set remaining stuff */
@ -490,12 +506,18 @@ void net_init(register struct dpni20_s *dpni)
npf.osnpf_rdtmo = dpni->dpni_rdtmo;
npf.osnpf_backlog = dpni->dpni_backlog;
npf.osnpf_ip.ia_addr = ehost_ip;
#if KLH10_NET_TUN
npf.osnpf_tun.ia_addr = tun_ip;
#endif
/* 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, dpni->dpni_eth); /* Set requested ea if any */
pffd = osn_pfinit(&npf, (void *)dpni); /* Will abort if fails */
ea_set(&ihost_ea, &npf.osnpf_ea); /* Copy actual ea */
#if KLH10_NET_TUN
tun_ip = npf.osnpf_tun.ia_addr; /* Get actual tunnel addr */
#endif
}
/* Now set any return info values in shared struct.
@ -1441,10 +1463,10 @@ void ethtoten(register struct dpni20_s *dpni)
cnt = data.len;
/* Else cnt must be -1 as call failed */
}
#elif KLH10_NET_NIT || KLH10_NET_PFLT || KLH10_NET_LNX
cnt = read(pffd, buff, max);
#elif KLH10_NET_BPF
cnt = read(pffd, tbuff, tmax);
#else
cnt = read(pffd, buff, max);
#endif
if (cnt <= cmin) { /* Must get enough for ether header */
@ -1509,7 +1531,7 @@ void ethtoten(register struct dpni20_s *dpni)
continue; /* Drop packet, continue reading */
}
#endif /* KLH10_NET_LNX */
#if KLH10_NET_NIT || KLH10_NET_DLPI || KLH10_NET_PFLT || KLH10_NET_LNX
#if !KLH10_NET_BPF
#if 0
if (DBGFLG)
if (((struct ether_header *)buff)->ether_type == htons(ETHERTYPE_ARP))
@ -1521,9 +1543,8 @@ void ethtoten(register struct dpni20_s *dpni)
if (DBGFLG)
dbprint("sent RPKT");
#endif /* KLH10_NET_NIT || KLH10_NET_DLPI || KLH10_NET_PFLT || KLH10_NET_LNX */
#else
#if KLH10_NET_BPF
/* Screwy BPF algorithm requires more overhead because there's
no way to ensure only one packet is read at a time; the call
may return a buffer of several packets, each of which must

View File

@ -52,6 +52,7 @@ struct dpni20_s {
char dpni_ifnam[16]; /* CD Interface name if any */
unsigned char dpni_eth[6]; /* CD Ethernet address of interface */
unsigned char dpni_ip[4]; /* C 10's IP address to filter on, if shared */
unsigned char dpni_tun[4]; /* CD host's IP address on tunnel */
int dpni_backlog; /* C Max sys backlog of rcvd packets */
int dpni_dedic; /* C TRUE if dedicated ifc, else shared */
int dpni_decnet; /* C TRUE to seize DECNET packets, if shared */

View File

@ -103,6 +103,7 @@ struct lhdh {
int lh_rdtmo; /* # secs to timeout on packetfilter reads */
unsigned char lh_ipadr[4]; /* KLH10 IP address to filter on */
unsigned char lh_gwadr[4]; /* Gateway IP address to use when needed */
unsigned char lh_tunadr[4]; /* Tunnel IP address on local side */
unsigned char lh_ethadr[6]; /* Ether address to use, if dedicated */
char *lh_dpname; /* Pointer to dev process pathname */
@ -171,6 +172,7 @@ static int imp_outxfer(struct lhdh *lh);
\
prmdef(LHDHP_IP, "ipaddr"), /* IP address of KLH10, if shared */\
prmdef(LHDHP_GW, "gwaddr"), /* IP address of prime GW to use */\
prmdef(LHDHP_TUN,"tunaddr"), /* IP address of local side of tunnel */\
prmdef(LHDHP_EN, "enaddr"), /* Ethernet address to use (override) */\
prmdef(LHDHP_IFC,"ifc"), /* Ethernet interface name */\
prmdef(LHDHP_BKL,"backlog"),/* Max bklog for rcvd pkts (else sys deflt) */\
@ -301,6 +303,13 @@ lhdh_conf(FILE *f, char *s, struct lhdh *lh)
break;
continue;
case LHDHP_TUN: /* Parse as IP address: u.u.u.u */
if (!prm.prm_val)
break;
if (!parip(prm.prm_val, &lh->lh_tunadr[0]))
break;
continue;
case LHDHP_EN: /* Parse as EN address in hex */
if (!prm.prm_val)
break;
@ -1057,6 +1066,8 @@ imp_init(register struct lhdh *lh, FILE *of)
lh->lh_ipadr, 4);
memcpy((char *)dpc->dpimp_gw, /* Set our GW address for IMP */
lh->lh_gwadr, 4);
memcpy((char *)dpc->dpimp_tun, /* Set our IP address for tunnel */
lh->lh_tunadr, 4); /* (all zero if none) */
memcpy(dpc->dpimp_eth, /* Set EN address if any given */
lh->lh_ethadr, 6); /* (all zero if none) */

View File

@ -157,6 +157,7 @@ struct ni20 {
int ni_lsapf; /* TRUE to filter on LSAP addr (if shared) */
int ni_lsap; /* LSAP src/dst address for above */
unsigned char ni_ipadr[4]; /* KLH10 IP address to filter (if shared) */
unsigned char ni_tunadr[4]; /* Tunnel IP address (if masquerading) */
int32 ni_c3dly; /* Initial-cmd delay in ticks */
int32 ni_c3dlyct; /* Countdown (no delay if 0) */
@ -294,6 +295,7 @@ static uint32 ni_ecpdigest(unsigned char *ucp, int len);
prmdef(NIP_BKL,"backlog"),/* Max bklog for rcvd pkts (else sys default) */\
prmdef(NIP_DED,"dedic"), /* TRUE= Ifc dedicated (else shared) */\
prmdef(NIP_IP, "ipaddr"), /* IP address of KLH10, if shared */\
prmdef(NIP_TUN, "tunaddr"), /* IP address of local end of tunnel */\
prmdef(NIP_DEC,"decnet"), /* TRUE= if shared, seize DECNET pkts */\
prmdef(NIP_ARP,"doarp"), /* TRUE= if shared, do ARP hackery */\
prmdef(NIP_LSAP,"lsap"), /* Set= if shared, filter on LSAP pkts */\
@ -391,6 +393,13 @@ ni20_conf(FILE *f, char *s, struct ni20 *ni)
break;
continue;
case NIP_TUN: /* Parse as IP address: u.u.u.u */
if (!prm.prm_val)
break;
if (!parip(prm.prm_val, &ni->ni_tunadr[0]))
break;
continue;
case NIP_EN: /* Parse as EN address in hex */
if (!prm.prm_val)
break;
@ -711,6 +720,8 @@ ni20_init(struct device *d,
dpc->dpni_ifnam[0] = '\0'; /* No specific interface */
memcpy((char *)dpc->dpni_ip, /* Set our IP address for filter */
ni->ni_ipadr, 4);
memcpy((char *)dpc->dpni_tun, /* Set IP address for tunnel */
ni->ni_tunadr, 4);
memcpy(dpc->dpni_eth, /* Set EN address if any given */
ni->ni_ethadr, 6); /* (all zero if none) */

View File

@ -812,7 +812,7 @@ osn_ifeaget(int s, /* Socket for (AF_INET, SOCK_DGRAM, 0) */
ea_set(def, ifdev.default_pa);
}
#elif KLH10_NET_LNX
#elif CENV_SYS_LINUX
{
int ownsock = FALSE;
struct ifreq ifr;
@ -1131,7 +1131,7 @@ osn_ifeaset(int s, /* Socket for (AF_INET, SOCK_DGRAM, 0) */
char *ifnam, /* Interface name */
unsigned char *newpa) /* New ether address */
{
#if CENV_SYS_DECOSF || KLH10_NET_LNX \
#if CENV_SYS_DECOSF || CENV_SYS_LINUX \
|| (CENV_SYS_FREEBSD && defined(SIOCSIFLLADDR))
/* Common preamble code */
@ -1162,7 +1162,7 @@ osn_ifeaset(int s, /* Socket for (AF_INET, SOCK_DGRAM, 0) */
return FALSE;
}
# elif KLH10_NET_LNX
# elif CENV_SYS_LINUX
/* Address family must match what device thinks it is, so find that
out first... sigh.
@ -1225,7 +1225,7 @@ osn_ifmcset(int s,
int delf,
unsigned char *pa)
{
#if CENV_SYS_DECOSF || KLH10_NET_LNX || CENV_SYS_FREEBSD
#if CENV_SYS_DECOSF || CENV_SYS_LINUX || CENV_SYS_FREEBSD
/* Common preamble code */
int ownsock = FALSE;
@ -1616,9 +1616,14 @@ osn_pfinit(register struct osnpf *osnpf, void *arg)
{
int allowextern = TRUE; /* For now, always try for external access */
int fd;
#if CENV_SYS_LINUX /* [BV: tun support for Linux] */
struct ifreq ifr;
char ifnam[IFNAMSIZ];
#else
char tunname[sizeof "/dev/tun000"];
char *ifnam = tunname + sizeof("/dev/")-1;
int i = -1;
#endif
char ipb1[OSN_IPSTRSIZ];
char ipb2[OSN_IPSTRSIZ];
struct ifent *ife = NULL; /* Native host's default IP interface if one */
@ -1628,33 +1633,57 @@ osn_pfinit(register struct osnpf *osnpf, void *arg)
/* Remote address is always that of emulated machine */
ipremote = osnpf->osnpf_ip.ia_addr;
iplocal = osnpf->osnpf_tun.ia_addr;
/* Local address is that of hardware machine if we want to permit
external access. If not, it doesn't matter (and may not even
exist, if there is no hardware interface)
*/
if (allowextern) {
if (osn_iftab_init(IFTAB_IPS) && (ife = osn_ipdefault())) {
iplocal = ife->ife_ipia;
} else {
error("Cannot find default IP interface for host");
allowextern = FALSE;
}
}
if (!allowextern) {
/* Make up bogus IP address for internal use */
memcpy((char *)&iplocal, ipremset, 4);
/* Local address can be set explicitly if we plan to do full IP
masquerading. */
if (memcmp((char *)&iplocal, "\0\0\0\0", IP_ADRSIZ) == 0) {
/* Local address is that of hardware machine if we want to permit
external access. If not, it doesn't matter (and may not even
exist, if there is no hardware interface)
*/
if (allowextern) {
if (osn_iftab_init(IFTAB_IPS) && (ife = osn_ipdefault())) {
iplocal = ife->ife_ipia;
} else {
error("Cannot find default IP interface for host");
allowextern = FALSE;
}
}
if (!allowextern) {
/* Make up bogus IP address for internal use */
memcpy((char *)&iplocal, ipremset, 4);
}
osnpf->osnpf_tun.ia_addr = iplocal;
}
if (DP_DBGFLG)
dbprint("Opening TUN device");
#if CENV_SYS_LINUX /* [BV: Linux way] */
if ((fd = open("/dev/net/tun", O_RDWR)) < 0) /* get a fresh device */
esfatal(0, "Couldn't open tunnel device /dev/net/tun");
memset(&ifr, 0, sizeof(ifr));
#if OSN_USE_IPONLY
ifr.ifr_flags = IFF_TUN | IFF_NO_PI; /* TUN (no Ethernet headers), no pkt info */
#else
ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* TAP (yes Ethernet headers), no pkt info */
#endif
if (ioctl(fd, TUNSETIFF, (void *) &ifr) < 0) /* turn it on */
esfatal(0, "Couldn't set tun device");
strcpy(ifnam, ifr.ifr_name); /* get device name (typically "tun0") */
#else
do {
#if OSN_USE_IPONLY
sprintf(tunname, "/dev/tun%d", ++i);
#else
sprintf(tunname, "/dev/tap%d", ++i);
#endif
} while ((fd = open(tunname, O_RDWR)) < 0 && errno == EBUSY);
if (fd < 0)
esfatal(1, "Couldn't open tunnel device %s", tunname);
#endif
if (DP_DBGFLG)
dbprintln("Opened %s, configuring for local %s, remote %s",
@ -1662,6 +1691,7 @@ osn_pfinit(register struct osnpf *osnpf, void *arg)
ip_adrsprint(ipb1, (unsigned char *)&iplocal),
ip_adrsprint(ipb2, (unsigned char *)&ipremote));
strcpy(osnpf->osnpf_ifnam, ifnam);
/* Activate TUN device.
First address is "local" -- doesn't matter if all we care about is
@ -1691,6 +1721,23 @@ osn_pfinit(register struct osnpf *osnpf, void *arg)
esfatal(1, "osn_pfinit: ifconfig failed to initialize tunnel device?");
}
}
#elif CENV_SYS_LINUX /* [BV: Linux tun device] */
/* "Hacky" but simple method */
{
char cmdbuff[128];
int res;
/* ifconfig DEV IPLOCAL pointopoint IPREMOTE */
sprintf(cmdbuff, "ifconfig %s %s pointopoint %s up",
ifnam,
ip_adrsprint(ipb1, (unsigned char *)&iplocal),
ip_adrsprint(ipb2, (unsigned char *)&ipremote));
if (DP_DBGFLG)
dbprintln("running \"%s\"",cmdbuff);
if ((res = system(cmdbuff)) != 0) {
esfatal(1, "osn_pfinit: ifconfig failed to initialize tunnel device?");
}
}
#else
{
/* Internal method */
@ -1770,8 +1817,19 @@ osn_pfinit(register struct osnpf *osnpf, void *arg)
/* Return that as our ether address */
ea_set((char *)&osnpf->osnpf_ea, ife->ife_ea);
} else {
/* Assume no useful ether addr */
/* ARP hackery will be handled by IP masquerading and packet forwarding. */
#if 1 /*OSN_USE_IPONLY*/ /* TOPS-20 does not like NI20 with made up address? */
/* Assume no useful ether addr for tun interface. */
ea_clr((char *)&osnpf->osnpf_ea);
#else
/* Assign requested address to tap interface or get kernel assigned one. */
if (memcmp((char *)&osnpf->osnpf_ea, "\0\0\0\0\0\0", ETHER_ADRSIZ) == 0) {
osn_ifeaget(-1, ifnam, (unsigned char *)&osnpf->osnpf_ea, NULL);
}
else {
osn_ifeaset(-1, ifnam, (unsigned char *)&osnpf->osnpf_ea);
}
#endif
}
if (DP_DBGFLG)

View File

@ -69,7 +69,7 @@
#if !(KLH10_NET_NIT || KLH10_NET_DLPI || KLH10_NET_BPF || KLH10_NET_PFLT || \
KLH10_NET_TUN || KLH10_NET_LNX)
/* None explicitly specified, pick a reasonable default */
# if (CENV_SYS_FREEBSD && OSN_USE_IPONLY)
# if ((CENV_SYS_FREEBSD || CENV_SYS_LINUX) && OSN_USE_IPONLY)
# undef KLH10_NET_TUN
# define KLH10_NET_TUN 1
# elif (CENV_SYS_NETBSD || CENV_SYS_FREEBSD)
@ -146,6 +146,9 @@
# include <linux/if_packet.h>
# include <linux/if_ether.h> /* The L2 protocols */
# endif
#elif KLH10_NET_TUN && CENV_SYS_LINUX /* [BV: tun support for Linux] */
# include <linux/if_tun.h>
#endif
@ -379,6 +382,7 @@ struct osnpf { /* Arg struct for common initialization params */
int osnpf_rdtmo; /* Read timeout, if any */
int osnpf_backlog; /* Allow # backlogged packets, if any */
union ipaddr osnpf_ip; /* IP address to use */
union ipaddr osnpf_tun; /* INOUT: IP address of tunnel */
struct ether_addr osnpf_ea; /* OUT: ether address of ifc */
};
int osn_pfinit(struct osnpf *, void *);