mirror of
https://github.com/PDP-10/klh10.git
synced 2026-01-11 23:52:54 +00:00
Merge branch 'mmcm-tuntap' because it didn't break on NetBSD.
This commit is contained in:
commit
37cbb5150b
@ -1,2 +1,2 @@
|
||||
#!/bin/sh
|
||||
make base-kl CONFFLAGS_AUX=-DKLH10_I_CIRC=1 LDFLAGS=-static
|
||||
make -k base-kl CONFFLAGS_AUX="-DKLH10_I_CIRC=1"
|
||||
|
||||
@ -308,7 +308,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) \
|
||||
|
||||
@ -28,6 +28,7 @@ CFLAGS_LINT = -ansi -pedantic -Wall -Wshadow \
|
||||
|
||||
# Source definitions
|
||||
CENVFLAGS = -DCENV_CPU_ALPHA=1 -DCENV_SYS_LINUX=1 -DKLH10_DEV_LITES=1 \
|
||||
-DKLH10_NET_TUN=1 \
|
||||
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
|
||||
|
||||
# Any target with no customized rule here is simply passed on to the
|
||||
|
||||
@ -28,6 +28,7 @@ CFLAGS_LINT = -ansi -pedantic -Wall -Wshadow \
|
||||
|
||||
# Source definitions
|
||||
CENVFLAGS = -DCENV_CPU_I386=1 -DCENV_SYS_LINUX=1 -DKLH10_DEV_LITES=1 \
|
||||
-DKLH10_NET_TUN=1 \
|
||||
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
|
||||
|
||||
# Any target with no customized rule here is simply passed on to the
|
||||
|
||||
33
src/dpimp.c
33
src/dpimp.c
@ -283,7 +283,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 */
|
||||
@ -501,7 +505,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! */
|
||||
@ -559,6 +567,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));
|
||||
@ -568,10 +577,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.
|
||||
@ -626,6 +641,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 */
|
||||
@ -682,6 +699,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.
|
||||
@ -694,12 +713,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
|
||||
}
|
||||
}
|
||||
|
||||
@ -1734,7 +1759,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];
|
||||
|
||||
@ -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 */
|
||||
|
||||
33
src/dpni20.c
33
src/dpni20.c
@ -178,7 +178,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";
|
||||
@ -384,14 +389,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));
|
||||
}
|
||||
@ -448,6 +459,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))) {
|
||||
@ -479,6 +494,7 @@ void net_init(register struct dpni20_s *dpni)
|
||||
dbprintln("Using default interface \"%s\"", dpni->dpni_ifnam);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Now set remaining stuff */
|
||||
|
||||
@ -493,12 +509,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
|
||||
}
|
||||
|
||||
|
||||
@ -1460,10 +1482,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 || KLH10_NET_TAP_BRIDGE
|
||||
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 */
|
||||
|
||||
@ -1531,7 +1553,7 @@ void ethtoten(register struct dpni20_s *dpni)
|
||||
}
|
||||
}
|
||||
#endif /* KLH10_NET_LNX */
|
||||
#if KLH10_NET_NIT || KLH10_NET_DLPI || KLH10_NET_PFLT || KLH10_NET_LNX || KLH10_NET_TAP_BRIDGE
|
||||
#if !KLH10_NET_BPF
|
||||
#if 0
|
||||
if (DBGFLG)
|
||||
if (((struct ether_header *)buff)->ether_type == htons(ETHERTYPE_ARP))
|
||||
@ -1543,9 +1565,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 || NET_TAP_BRIDGE */
|
||||
#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
|
||||
|
||||
@ -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 */
|
||||
|
||||
11
src/dvlhdh.c
11
src/dvlhdh.c
@ -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) */
|
||||
|
||||
|
||||
11
src/dvni20.c
11
src/dvni20.c
@ -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) */
|
||||
|
||||
|
||||
98
src/osdnet.c
98
src/osdnet.c
@ -835,7 +835,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;
|
||||
@ -1169,7 +1169,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 || KLH10_NET_TAP_BRIDGE \
|
||||
#if CENV_SYS_DECOSF || CENV_SYS_LINUX || KLH10_NET_TAP_BRIDGE \
|
||||
|| (CENV_SYS_FREEBSD && defined(SIOCSIFLLADDR))
|
||||
|
||||
/* Common preamble code */
|
||||
@ -1200,7 +1200,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.
|
||||
@ -1265,7 +1265,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;
|
||||
@ -1657,9 +1657,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 */
|
||||
@ -1669,33 +1674,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",
|
||||
@ -1703,6 +1732,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
|
||||
@ -1732,6 +1762,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 */
|
||||
@ -1811,8 +1858,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)
|
||||
|
||||
@ -72,7 +72,7 @@
|
||||
#if !(KLH10_NET_NIT || KLH10_NET_DLPI || KLH10_NET_BPF || KLH10_NET_PFLT || \
|
||||
KLH10_NET_TUN || KLH10_NET_LNX || KLH10_NET_TAP_BRIDGE)
|
||||
/* None explicitly specified, pick a reasonable default */
|
||||
# if ((CENV_SYS_NETBSD || CENV_SYS_FREEBSD) && OSN_USE_IPONLY)
|
||||
# if ((CENV_SYS_NETBSD || 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)
|
||||
@ -153,6 +153,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
|
||||
|
||||
|
||||
@ -386,6 +389,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 *);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user