ia64/xen-unstable

changeset 1552:e9509ea8fb90

bitkeeper revision 1.1005 (40d99af0Cf4EQLv6pL5rlJVam_lZHg)

Remove some obsolete miscellaneous tools.
author kaf24@scramble.cl.cam.ac.uk
date Wed Jun 23 15:00:00 2004 +0000 (2004-06-23)
parents f023d40722e4
children d1bba652eb21
files .rootkeys tools/Makefile tools/balloon/Makefile tools/balloon/README tools/balloon/balloon.c tools/misc/Makefile tools/misc/xen-mkdevnodes tools/misc/xen_dmesg.py tools/misc/xen_log.c tools/misc/xen_nat_enable tools/misc/xen_nat_enable.README tools/nsplitd/Makefile tools/nsplitd/nsplitd.c
line diff
     1.1 --- a/.rootkeys	Wed Jun 23 14:39:39 2004 +0000
     1.2 +++ b/.rootkeys	Wed Jun 23 15:00:00 2004 +0000
     1.3 @@ -153,9 +153,6 @@ 3e5a4e681xMPdF9xCMwpyfuYMySU5g linux-2.4
     1.4  409ba2e7akOFqQUg6Qyg2s28xcXiMg linux-2.4.26-xen-sparse/mm/page_alloc.c
     1.5  3e5a4e683HKVU-sxtagrDasRB8eBVw linux-2.4.26-xen-sparse/mm/swapfile.c
     1.6  3f776bd1Hy9rn69ntXBhPReUFw9IEA tools/Makefile
     1.7 -3e6377b24eQqYMsDi9XrFkIgTzZ47A tools/balloon/Makefile
     1.8 -3e6377d6eiFjF1hHIS6JEIOFk62xSA tools/balloon/README
     1.9 -3e6377dbGcgnisKw16DPCaND7oGO3Q tools/balloon/balloon.c
    1.10  401d7e160vaxMBAUSLSicuZ7AQjJ3w tools/examples/Makefile
    1.11  401d7e16UgeqroJQTIhwkrDVkoWgZQ tools/examples/README
    1.12  401d7e16GS8YesM1zateRbaOoI6YLQ tools/examples/defaults
    1.13 @@ -177,16 +174,9 @@ 3f6dc142IHaf6XIcAYGmhV9nNSIHFQ tools/mis
    1.14  3f870808_8aFBAcZbWiWGdgrGQyIEw tools/misc/p4perf.h
    1.15  3f5ef5a2ir1kVAthS14Dc5QIRCEFWg tools/misc/xen-clone
    1.16  3f5ef5a2dTZP0nnsFoeq2jRf3mWDDg tools/misc/xen-clone.README
    1.17 -3f1668d4-FUY6Enc7MB3GcwUtfJ5HA tools/misc/xen-mkdevnodes
    1.18  3f870808zS6T6iFhqYPGelroZlVfGQ tools/misc/xen_cpuperf.c
    1.19 -401d7e16hWEsgEnMwbPM9sKyInomWw tools/misc/xen_dmesg.py
    1.20 -3f8bcf29ulZIC9rC4wM70H_q4s6VPg tools/misc/xen_log.c
    1.21 -3f13d81eQ9Vz-h-6RDGFkNR9CRP95g tools/misc/xen_nat_enable
    1.22 -3f13d81e6Z6806ihYYUw8GVKNkYnuw tools/misc/xen_nat_enable.README
    1.23  405eedf6_nnNhFQ1I85lhCkLK6jFGA tools/misc/xencons
    1.24  4056f5155QYZdsk-1fLdjsZPFTnlhg tools/misc/xensymoops.py
    1.25 -4022a73cEKvrYe_DVZW2JlAxobg9wg tools/nsplitd/Makefile
    1.26 -4022a73cKms4Oq030x2JBzUB426lAQ tools/nsplitd/nsplitd.c
    1.27  3fbca441SjQr8vJwTQIgH1laysaWog tools/xc/Makefile
    1.28  3fbba6dbDfYvJSsw9500b4SZyUhxjQ tools/xc/lib/Makefile
    1.29  3fbba6dc1uU7U3IFeF6A-XEOYF2MkQ tools/xc/lib/rpm.spec
     2.1 --- a/tools/Makefile	Wed Jun 23 14:39:39 2004 +0000
     2.2 +++ b/tools/Makefile	Wed Jun 23 15:00:00 2004 +0000
     2.3 @@ -1,6 +1,5 @@
     2.4  
     2.5  all:	
     2.6 -	$(MAKE) -C balloon
     2.7  	$(MAKE) -C xc
     2.8  	$(MAKE) -C misc
     2.9  	$(MAKE) -C examples
    2.10 @@ -10,7 +9,6 @@ all:
    2.11  	$(MAKE) -C xenmgr
    2.12  
    2.13  install: all
    2.14 -	$(MAKE) -C balloon install
    2.15  	$(MAKE) -C xc install
    2.16  	$(MAKE) -C misc install
    2.17  	$(MAKE) -C examples install
    2.18 @@ -24,11 +22,9 @@ dist: $(TARGET)
    2.19  
    2.20  
    2.21  clean:
    2.22 -	$(MAKE) -C balloon clean
    2.23  	$(MAKE) -C xc clean
    2.24  	$(MAKE) -C misc clean
    2.25  	$(MAKE) -C examples clean
    2.26 -	$(MAKE) -C nsplitd clean
    2.27  	$(MAKE) -C xentrace clean
    2.28  	$(MAKE) -C xenctl clean
    2.29  	$(MAKE) -C xend clean
     3.1 --- a/tools/balloon/Makefile	Wed Jun 23 14:39:39 2004 +0000
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,13 +0,0 @@
     3.4 -
     3.5 -CC     = gcc
     3.6 -CFLAGS = -Wall -O3
     3.7 -TARGET = balloon
     3.8 -
     3.9 -all: $(TARGET)
    3.10 -
    3.11 -install: all
    3.12 -	mkdir -p $(prefix)/usr/bin
    3.13 -	install -m0755 $(TARGET) $(prefix)/usr/bin
    3.14 -
    3.15 -clean:
    3.16 -	$(RM) *.o $(TARGET) *~
     4.1 --- a/tools/balloon/README	Wed Jun 23 14:39:39 2004 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,17 +0,0 @@
     4.4 -
     4.5 -The Xen balloon driver supports two operations:
     4.6 - 1. Inflating - which means domain giving up pages of memory to Xen.
     4.7 - 2. Deflating - which means reclaiming memory pages from Xen.
     4.8 -
     4.9 -Currently a domain can only claim pages from Xen up to the number of 
    4.10 -previously released ones. This is to change. 
    4.11 -
    4.12 -Example:
    4.13 -
    4.14 -# balloon inflate 1000
    4.15 -
    4.16 -Give up 1000 pages to Xen.
    4.17 -
    4.18 -# balloon deflate 1000
    4.19 -
    4.20 -Claim 1000 pages from Xen.
     5.1 --- a/tools/balloon/balloon.c	Wed Jun 23 14:39:39 2004 +0000
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,113 +0,0 @@
     5.4 -/******************************************************************************
     5.5 - * balloon.c
     5.6 - *
     5.7 - * Xen balloon driver userspace control tool. Used to shrink/grow domain's 
     5.8 - * memory.
     5.9 - *
    5.10 - * Copyright (c) 2003, B Dragovic
    5.11 - */
    5.12 -
    5.13 -#include <stdio.h>
    5.14 -#include <stdlib.h>
    5.15 -#include <string.h>
    5.16 -#include <errno.h>
    5.17 -#include <unistd.h>
    5.18 -#include <sys/types.h>
    5.19 -#include <sys/stat.h>
    5.20 -#include <fcntl.h>
    5.21 -
    5.22 -#define INFLATE_BALLOON      "inflate"   /* return mem to hypervisor */
    5.23 -#define DEFLATE_BALLOON      "deflate"   /* claim mem from hypervisor */
    5.24 -
    5.25 -/* THIS IS SHARED WITH THE LINUX BALLOON DRIVER */
    5.26 -#define USER_INFLATE_BALLOON  1   /* return mem to hypervisor */
    5.27 -#define USER_DEFLATE_BALLOON  2   /* claim mem from hypervisor */
    5.28 -typedef struct user_balloon_op {
    5.29 -    unsigned int    op;
    5.30 -    unsigned long   size;
    5.31 -} user_balloon_op_t;
    5.32 -/* END OF CODE SHARED WITH THE LINUX BALLOON DRIVER */
    5.33 -
    5.34 -static int open_balloon_proc()
    5.35 -{
    5.36 -    return open("/proc/xen/balloon", O_RDWR);
    5.37 -}
    5.38 -
    5.39 -/* inflate balloon function signals to kernel it should relinquish memory */
    5.40 -static int inflate_balloon(unsigned long num_pages)
    5.41 -{
    5.42 -    user_balloon_op_t bop;
    5.43 -    int proc_fd;
    5.44 -
    5.45 -    if((proc_fd = open_balloon_proc()) <= 0){
    5.46 -        printf("Error opening balloon proc file.\n");
    5.47 -        return 0;
    5.48 -    }
    5.49 -
    5.50 -    bop.op   = USER_INFLATE_BALLOON;
    5.51 -    bop.size = num_pages;
    5.52 -    if ( write(proc_fd, &bop, sizeof(bop)) <= 0 )
    5.53 -    {
    5.54 -        printf("Error writing to balloon proc file.\n");
    5.55 -        return 0;
    5.56 -    }
    5.57 -
    5.58 -    close(proc_fd);
    5.59 -    return 1;
    5.60 -}
    5.61 -
    5.62 -/* deflate balloon function signals to kernel it should claim memory */
    5.63 -static int deflate_balloon(unsigned long num_pages)
    5.64 -{
    5.65 -    user_balloon_op_t bop;
    5.66 -    int proc_fd;
    5.67 -
    5.68 -    if((proc_fd = open_balloon_proc()) <= 0){
    5.69 -        printf("Error opening balloon proc file.\n");
    5.70 -        return 0;
    5.71 -    }
    5.72 -
    5.73 -    bop.op   = USER_DEFLATE_BALLOON;
    5.74 -    bop.size = num_pages;
    5.75 -    if(write(proc_fd, &bop, sizeof(bop)) <= 0){
    5.76 -        printf("Error writing to balloon proc file.\n");
    5.77 -        return 0;
    5.78 -    }
    5.79 -
    5.80 -    close(proc_fd);
    5.81 -    return 1;
    5.82 -}
    5.83 -
    5.84 -int main(int argc, char *argv[])
    5.85 -{
    5.86 -    unsigned long num_pages;
    5.87 -
    5.88 -    if(argc < 2){
    5.89 -        printf("Usage: balloon <inflate|deflate> <num_pages>\n");
    5.90 -        return -1;
    5.91 -    }
    5.92 -
    5.93 -    num_pages = atol(argv[2]);
    5.94 -
    5.95 -    if(!strcmp(argv[1], INFLATE_BALLOON)){
    5.96 -        if(!inflate_balloon(num_pages)){
    5.97 -            perror("Inflating balloon failed");
    5.98 -            return -1;
    5.99 -        }
   5.100 -
   5.101 -    } else if (!strcmp(argv[1], DEFLATE_BALLOON)){
   5.102 -        if(!deflate_balloon(num_pages)){
   5.103 -            perror("Deflating balloon failed");
   5.104 -            return -1;
   5.105 -        }
   5.106 -
   5.107 -    } else {
   5.108 -        printf("Unrecognized command line argument.\n");
   5.109 -        return -1;
   5.110 -    }
   5.111 -
   5.112 -    return 0;
   5.113 -}
   5.114 -
   5.115 -    
   5.116 -
     6.1 --- a/tools/misc/Makefile	Wed Jun 23 14:39:39 2004 +0000
     6.2 +++ b/tools/misc/Makefile	Wed Jun 23 15:00:00 2004 +0000
     6.3 @@ -11,8 +11,7 @@ OBJS     = $(patsubst %.c,%.o,$(SRCS))
     6.4  
     6.5  TARGETS  = xen_cpuperf
     6.6  
     6.7 -INSTALL  = $(TARGETS) xen-mkdevnodes xen_nat_enable xen-clone
     6.8 -INSTALL += xen_dmesg.py xencons
     6.9 +INSTALL  = $(TARGETS) xencons
    6.10  
    6.11  all: $(TARGETS)
    6.12  	$(MAKE) -C miniterm
     7.1 --- a/tools/misc/xen-mkdevnodes	Wed Jun 23 14:39:39 2004 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,21 +0,0 @@
     7.4 -#! /bin/bash
     7.5 -
     7.6 -BASE=${1:?"base directory missing (eg. /dev)"}
     7.7 -
     7.8 -rm -f ${BASE}/xvd[abcdefghijklmnop]*
     7.9 -
    7.10 -# XLVIRT is 16 devices of 15 partitions
    7.11 -
    7.12 -LETTERS="a b c d e f g h i j k l m n o p"
    7.13 -PARTITIONS="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"
    7.14 -
    7.15 -j=0
    7.16 -for l in ${LETTERS}; do
    7.17 -    mknod ${BASE}/xvd${l} b 125 ${j}
    7.18 -    chmod 600 ${BASE}/xvd${l}
    7.19 -    for i in ${PARTITIONS}; do
    7.20 -        mknod ${BASE}/xvd${l}${i} b 125 $(($i+$j))
    7.21 -        chmod 600 ${BASE}/xvd${l}${i}
    7.22 -    done
    7.23 -    j=$(($j+16))
    7.24 -done
     8.1 --- a/tools/misc/xen_dmesg.py	Wed Jun 23 14:39:39 2004 +0000
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,26 +0,0 @@
     8.4 -#!/usr/bin/env python
     8.5 -
     8.6 -"""Reads out the contents of the console ring
     8.7 -
     8.8 -Usage: readconsolering.py [-c]
     8.9 -The -c option causes the contents to be cleared.
    8.10 -"""
    8.11 -
    8.12 -import sys, Xc # import the Xc Xen Control module
    8.13 -
    8.14 -xc = Xc.new() # get a new instance of the control interface
    8.15 -
    8.16 -clear_buffer = False
    8.17 -
    8.18 -if sys.argv[1:] != []:
    8.19 -    if sys.argv[1] == "-c":
    8.20 -        clear_buffer = True
    8.21 -    else:
    8.22 -        print >> sys.stderr, "Usage: " + sys.argv[0] + """ [-c]
    8.23 -       Reads the contents of the console buffer.
    8.24 -       (specifying -c will also clear current contents)"""
    8.25 -
    8.26 -# Get the console ring's contents as a string and print it out.
    8.27 -# If argument to readconsolering is true then the buffer is cleared as well as
    8.28 -# fetching the (pre-clearing) contents.
    8.29 -print xc.readconsolering(clear_buffer)
     9.1 --- a/tools/misc/xen_log.c	Wed Jun 23 14:39:39 2004 +0000
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,174 +0,0 @@
     9.4 -
     9.5 -#include <netinet/in.h>
     9.6 -#include <sys/types.h>
     9.7 -#include <sys/socket.h>
     9.8 -#include <stdio.h>
     9.9 -#include <stdlib.h>
    9.10 -#include <syslog.h>
    9.11 -#include <errno.h>
    9.12 -#include <unistd.h>
    9.13 -#include <fcntl.h>
    9.14 -#include <signal.h>
    9.15 -#include <string.h>
    9.16 -
    9.17 -#include "dom0_defs.h"
    9.18 -#include "mem_defs.h"
    9.19 -
    9.20 -#define SILENT_ERRORS_FROM_XEN
    9.21 -#define SYSLOG 1
    9.22 -#define SYSLOGTO LOG_LOCAL5
    9.23 -
    9.24 -int logoutput;
    9.25 -
    9.26 -void stripit(char *str)
    9.27 -{
    9.28 -    int i;
    9.29 -    for ( i = 0; str[i]; i++ )
    9.30 -        if ( (str[i] == '\n') || (str[i] == '\r') ) 
    9.31 -            str[i] = '\0';
    9.32 -}
    9.33 -
    9.34 -void errexit(char *str)
    9.35 -{
    9.36 -    if ( logoutput == SYSLOG )
    9.37 -    {
    9.38 -        stripit(str);
    9.39 -        syslog(LOG_ERR, "%s failed: %d (%m)", str, errno);
    9.40 -    } 
    9.41 -    else 
    9.42 -    {
    9.43 -        printf("%s", str);
    9.44 -    }
    9.45 -    exit(1);
    9.46 -}
    9.47 -
    9.48 -void log(char *str)
    9.49 -{
    9.50 -    if ( logoutput == SYSLOG )
    9.51 -    {
    9.52 -        stripit(str);
    9.53 -        syslog(LOG_INFO, "%s", str);
    9.54 -    } 
    9.55 -    else 
    9.56 -    {
    9.57 -        printf("%s", str);
    9.58 -    }
    9.59 -}
    9.60 -
    9.61 -void process(void)
    9.62 -{
    9.63 -    dom0_op_t op;
    9.64 -    unsigned char buf[208], obuf[224];
    9.65 -    struct sockaddr_in addr, from;
    9.66 -    int fromlen = sizeof(from);
    9.67 -    int len, fd = socket(PF_INET, SOCK_DGRAM, 0);
    9.68 -    unsigned short int lastport = 0, curport = 0;
    9.69 -    
    9.70 -    if ( fd < 0 )
    9.71 -        errexit("could not open datagram socket");
    9.72 -
    9.73 -    memset(&addr, 0, sizeof(addr));
    9.74 -    addr.sin_addr.s_addr = htonl(0xa9fe0100); /* 169.254.1.0 */
    9.75 -    addr.sin_port = htons(666);
    9.76 -    addr.sin_family = AF_INET;
    9.77 -
    9.78 -    if ( bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0 )
    9.79 -        errexit("could not bind to local address and port");
    9.80 -
    9.81 -    op.cmd = DOM0_GETDOMAININFO;
    9.82 -
    9.83 -    while ( (len = recvfrom(fd, buf, sizeof(buf), 0,
    9.84 -                            (struct sockaddr *)&from, &fromlen)) >= 0 )
    9.85 -    {
    9.86 -        curport = ntohs(from.sin_port);
    9.87 -        if ( lastport != curport )
    9.88 -        {
    9.89 -            op.u.getdomaininfo.domain = (int)curport;
    9.90 -            if ( do_dom0_op(&op) < 0 )
    9.91 -                log("Error resolving domain name\n");
    9.92 -            else
    9.93 -                lastport = curport;
    9.94 -        }
    9.95 -
    9.96 -        sprintf(obuf, "[%s] %s", op.u.getdomaininfo.name, buf);
    9.97 -        log(obuf);
    9.98 -
    9.99 -        fromlen = sizeof(from);
   9.100 -    }
   9.101 -}
   9.102 -
   9.103 -void closeall(int fd)
   9.104 -{
   9.105 -    int fdlimit = sysconf(_SC_OPEN_MAX);
   9.106 -
   9.107 -    while (fd < fdlimit)
   9.108 -        close(fd++);
   9.109 -}
   9.110 -
   9.111 -int daemon(int nochdir, int noclose)
   9.112 -{
   9.113 -    switch (fork())
   9.114 -    {
   9.115 -    case 0:  break;
   9.116 -    case -1: return -1;
   9.117 -    default: _exit(0);
   9.118 -    }
   9.119 -
   9.120 -    if (setsid() < 0)
   9.121 -        return -1;
   9.122 -
   9.123 -    switch (fork())
   9.124 -    {
   9.125 -    case 0:  break;
   9.126 -    case -1: return -1;
   9.127 -    default: _exit(0);
   9.128 -    }
   9.129 -
   9.130 -    if (!nochdir)
   9.131 -        chdir("/");
   9.132 -
   9.133 -    if (!noclose)
   9.134 -    {
   9.135 -        closeall(0);
   9.136 -        open("/dev/null",O_RDWR);
   9.137 -        dup(0); dup(0);
   9.138 -    }
   9.139 -
   9.140 -    return 0;
   9.141 -}
   9.142 -
   9.143 -int main(int argc, char **argv)
   9.144 -{
   9.145 -    int c;
   9.146 -
   9.147 -    logoutput = 0;
   9.148 -    opterr = 0;
   9.149 -
   9.150 -    while ( (c = getopt (argc, argv, "dh")) != -1 )
   9.151 -    {
   9.152 -        switch(c)
   9.153 -        {
   9.154 -        case 'd':
   9.155 -            logoutput = SYSLOG;
   9.156 -            if (daemon(0,0) < 0)
   9.157 -            {
   9.158 -                errno = 2;
   9.159 -                errexit("daemon");
   9.160 -            } else {
   9.161 -                openlog("xen_log", LOG_PID, SYSLOGTO);
   9.162 -            }
   9.163 -            break;
   9.164 -        case 'h':
   9.165 -            printf("Usage: xen_log [options]\n");
   9.166 -            printf("Capture and display output of xen domains.\n\n");
   9.167 -            printf("  -d       Daemonize and send output to syslog.\n");
   9.168 -            exit(0);
   9.169 -            break;
   9.170 -        }
   9.171 -    }
   9.172 -
   9.173 -    process();
   9.174 -
   9.175 -    return 0;
   9.176 -}
   9.177 -
    10.1 --- a/tools/misc/xen_nat_enable	Wed Jun 23 14:39:39 2004 +0000
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,35 +0,0 @@
    10.4 -#!/bin/sh
    10.5 -
    10.6 -run_iptables() {
    10.7 -    if ! iptables $@ ; then
    10.8 -	echo "iptables returned error; have you built netfilter?"; exit 1
    10.9 -    fi
   10.10 -}
   10.11 -
   10.12 -ifconfig eth0 up
   10.13 -ifconfig eth0:xen 169.254.1.0 up
   10.14 -
   10.15 -run_iptables -t filter -F
   10.16 -run_iptables -t nat -F
   10.17 -run_iptables -t filter -X
   10.18 -run_iptables -t nat -X
   10.19 -run_iptables -t filter -P FORWARD DROP
   10.20 -run_iptables -t filter -A FORWARD -i eth0 -o eth0 -s 169.254.0.0/16 -j ACCEPT
   10.21 -run_iptables -t filter -A FORWARD -i eth0 -o eth0 -d 169.254.0.0/16 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
   10.22 -run_iptables -t nat -A POSTROUTING -o eth0 -s 169.254.1.0 -j RETURN
   10.23 -run_iptables -t nat -A POSTROUTING -o eth0 -s 169.254.0.0/16 -j MASQUERADE
   10.24 -echo 1 > /proc/sys/net/ipv4/ip_forward
   10.25 -
   10.26 -#set up some port redirects for ssh
   10.27 -run_iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 2201 -j DNAT --to 169.254.1.1:22
   10.28 -run_iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 2202 -j DNAT --to 169.254.1.2:22
   10.29 -run_iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 2203 -j DNAT --to 169.254.1.3:22
   10.30 -run_iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 2204 -j DNAT --to 169.254.1.4:22
   10.31 -run_iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 2205 -j DNAT --to 169.254.1.5:22
   10.32 -run_iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 2206 -j DNAT --to 169.254.1.6:22
   10.33 -run_iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 2207 -j DNAT --to 169.254.1.7:22
   10.34 -run_iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 2208 -j DNAT --to 169.254.1.8:22
   10.35 -run_iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 2209 -j DNAT --to 169.254.1.9:22
   10.36 -run_iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 2210 -j DNAT --to 169.254.1.10:22
   10.37 -
   10.38 -
    11.1 --- a/tools/misc/xen_nat_enable.README	Wed Jun 23 14:39:39 2004 +0000
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,24 +0,0 @@
    11.4 -To use NAT in domain 0 to give access for other domains:
    11.5 -1) Make sure domain 0's kernel contains at least the following options:
    11.6 -   (other domains don't need this)
    11.7 -
    11.8 -CONFIG_NETFILTER=y
    11.9 -CONFIG_IP_NF_CONNTRACK=y
   11.10 -CONFIG_IP_NF_FTP=y
   11.11 -CONFIG_IP_NF_IPTABLES=y
   11.12 -CONFIG_IP_NF_MATCH_STATE=y
   11.13 -CONFIG_IP_NF_FILTER=y
   11.14 -CONFIG_IP_NF_NAT=y
   11.15 -CONFIG_IP_NF_NAT_NEEDED=y
   11.16 -CONFIG_IP_NF_TARGET_MASQUERADE=y
   11.17 -CONFIG_IP_NF_NAT_FTP=y
   11.18 -
   11.19 -2) Run the enable_nat script on domain 0 startup. This will bind
   11.20 -   169.254.1.0 to domain 0 and set up iptables for NAT. Make sure
   11.21 -   that the real IP address for eth0 has been set before running the
   11.22 -   script.
   11.23 -3) Give the other domains IP addresses in 169.254.0.0/16 and a default
   11.24 -   gateway of 169.254.1.0.
   11.25 -4) It should now work. Domains 1 and higher should be able to make
   11.26 -   outgoing connections through NAT. FTP active or passive should both
   11.27 -   work thanks to FTP connection tracking
    12.1 --- a/tools/nsplitd/Makefile	Wed Jun 23 14:39:39 2004 +0000
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,22 +0,0 @@
    12.4 -
    12.5 -CC     = gcc
    12.6 -CFLAGS = -Wall -O3
    12.7 -CFILES = $(wildcard *.c)
    12.8 -
    12.9 -HDRS     = $(wildcard *.h)
   12.10 -OBJS     = $(patsubst %.c,%.o,$(wildcard *.c))
   12.11 -
   12.12 -TARGET   = nsplitd
   12.13 -
   12.14 -all: $(TARGET)
   12.15 -
   12.16 -install: all
   12.17 -
   12.18 -clean:
   12.19 -	$(RM) *.o $(TARGET) *~
   12.20 -
   12.21 -$(TARGET): $(OBJS)
   12.22 -	$(CC) $(CFLAGS) -o $@ $^
   12.23 -
   12.24 -%.o: %.c $(HDRS) Makefile
   12.25 -	$(CC) $(CFLAGS) -c -o $@ $<
    13.1 --- a/tools/nsplitd/nsplitd.c	Wed Jun 23 14:39:39 2004 +0000
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,686 +0,0 @@
    13.4 -/*
    13.5 - *	nsplitd.c
    13.6 - *	---------
    13.7 - *
    13.8 - * $Id: nsplitd.c,v 2.6 1998/09/17 14:28:37 sde1000 Exp $
    13.9 - *
   13.10 - * Copyright (c) 1995, University of Cambridge Computer Laboratory,
   13.11 - * Copyright (c) 1995, Richard Black, All Rights Reserved.
   13.12 - *
   13.13 - *
   13.14 - * A complete re-implementation of DME's nsplitd for use from inetd
   13.15 - *
   13.16 - */
   13.17 -
   13.18 -/* The basic stream comes in (via inetd) and we then conenct to
   13.19 - * somewhere else providing a loop-through service, except we offer
   13.20 - * two other ports for connection - one of which gets a second channel
   13.21 - * using the top bit to distinguish, and the other is a master control
   13.22 - * port (normally used for gdb) which gets complete exclusive access
   13.23 - * for its duration.
   13.24 - *
   13.25 - * Originally designed for multiplexing a xwcons/telnet with a gdb
   13.26 - * post-mortem debugging session.
   13.27 - *
   13.28 - * Here is a picture:
   13.29 - *
   13.30 - * 					    port0 (from inetd)
   13.31 - *      8-bit connection     	       	   /
   13.32 - * 	   made by us	   <----> nsplitd <-----gdbport (default port0+2)
   13.33 - * 	to host:port/tcp		  |\
   13.34 - * 					  | port1 (default port0+1)
   13.35 - *                                         \
   13.36 - *                                          control (default port0+3)
   13.37 - *
   13.38 - * If port1 is explicitly disabled (through a command-line option) then
   13.39 - * port0 becomes 8-bit clean.
   13.40 - */
   13.41 -
   13.42 -/*
   13.43 - * N.B.: We do NOT support 8 bit stdin/stdout usage on a
   13.44 - * /dev/... because to do that right involves much messing with ioctl
   13.45 - * and TIOC... etc.  If you want to do that sort of thing then the
   13.46 - * right way to do it is to chain this onto wconsd (which does know
   13.47 - * about and understand all the ioctl and TIOC grief).
   13.48 - */
   13.49 -
   13.50 -#include <sys/types.h>
   13.51 -#include <stdarg.h>
   13.52 -#include <stdio.h>
   13.53 -#include <stdlib.h>
   13.54 -#include <assert.h>
   13.55 -#include <errno.h>
   13.56 -#include <unistd.h>
   13.57 -#include <ctype.h>
   13.58 -#include <netdb.h>
   13.59 -#include <string.h>
   13.60 -
   13.61 -#include <sys/time.h>
   13.62 -#include <sys/signal.h>
   13.63 -#include <sys/socket.h>
   13.64 -#include <netinet/in.h>
   13.65 -#include <netinet/tcp.h>
   13.66 -#include <arpa/inet.h>
   13.67 -#include <sys/ioctl.h>
   13.68 -#include <syslog.h>
   13.69 -
   13.70 -#ifndef FALSE
   13.71 -#define FALSE 0
   13.72 -#endif
   13.73 -#ifndef TRUE
   13.74 -#define TRUE 1
   13.75 -#endif
   13.76 -
   13.77 -#ifndef LOG_DAEMON
   13.78 -#define LOG_DAEMON 0
   13.79 -#endif
   13.80 -
   13.81 -#define DB(x)  /* ((x), fflush(stderr)) */
   13.82 -
   13.83 -extern char *optarg;
   13.84 -
   13.85 -extern int optind, opterr, optopt;
   13.86 -
   13.87 -static char *prog_name;
   13.88 -
   13.89 -static void usage(void)
   13.90 -{
   13.91 -    fprintf(stderr, "This program (%s) should be run via inetd (tcp)\n\n",
   13.92 -	    prog_name);
   13.93 -    fprintf(stderr, "usage: %s [-h<highport>][-g<gdbport>]"
   13.94 -	    "[-c<ctlport>][-8] host:service\n",
   13.95 -	    prog_name);
   13.96 -    exit(1);
   13.97 -}
   13.98 -
   13.99 -static void fault(char *format, ...)
  13.100 -{
  13.101 -    va_list		ap;
  13.102 -    char		logbuf[1024];
  13.103 -
  13.104 -    va_start(ap, format);
  13.105 -    fprintf(stderr, "%s: ", prog_name);
  13.106 -    vfprintf(stderr, format, ap);
  13.107 -    fflush(stderr);
  13.108 -    va_end(ap);
  13.109 -    
  13.110 -    /* XXX This is a bit dubious, but there is no vsyslog */
  13.111 -    va_start(ap, format);
  13.112 -    vsprintf(logbuf, format, ap);
  13.113 -    syslog(LOG_ERR, logbuf);
  13.114 -    va_end(ap);
  13.115 -    exit(1);
  13.116 -}
  13.117 -
  13.118 -static int getservice(char *name, unsigned short *port)
  13.119 -{
  13.120 -    struct servent		*se;
  13.121 -
  13.122 -    if (!name) return -1;
  13.123 -
  13.124 -    if (isdigit(name[0]))
  13.125 -	*port = atoi(name);
  13.126 -    else
  13.127 -    {
  13.128 -	if (!(se = getservbyname(name, "tcp")))
  13.129 -	    return -1;
  13.130 -	*port = ntohs(se->s_port);
  13.131 -    }
  13.132 -    return 0;
  13.133 -}
  13.134 -
  13.135 -/* 
  13.136 - *  connect_host: connect to ("name", "port")
  13.137 - */
  13.138 -static int connect_host (char *name, unsigned int port)
  13.139 -{
  13.140 -    int			fd;
  13.141 -    struct hostent	*hostent;
  13.142 -    struct sockaddr_in	sin;
  13.143 -    int			on;
  13.144 -    
  13.145 -    if ((fd = socket (AF_INET, SOCK_STREAM, 0)) < 0)
  13.146 -	fault("socket");
  13.147 -    
  13.148 -    if (!(hostent = gethostbyname(name)))
  13.149 -	fault("gethostbyname: %s: %s\n", name, strerror(errno));
  13.150 -    
  13.151 -    memset(&sin, 0, sizeof(sin));
  13.152 -    sin.sin_family = AF_INET;
  13.153 -    sin.sin_port   = htons (port);
  13.154 -    memcpy(&sin.sin_addr.s_addr, hostent->h_addr, sizeof(struct in_addr));
  13.155 -    
  13.156 -    if (connect(fd, (struct sockaddr *) &sin, sizeof (sin)) < 0)
  13.157 -	fault("connect: %s:%u: %s\n", name, port, strerror(errno));
  13.158 -    
  13.159 -    on = 1;
  13.160 -    if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof (on)) < 0)
  13.161 -	syslog(LOG_WARNING, "setsockopt (TCP_NODELAY): %m");
  13.162 -
  13.163 -    on = 1;
  13.164 -    if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof (on)) < 0)
  13.165 -	syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");
  13.166 -
  13.167 -    return fd;
  13.168 -}
  13.169 -
  13.170 -/*
  13.171 - * open a tcp socket and start listening for connections on it
  13.172 - */
  13.173 -static int startlistening(unsigned short port)
  13.174 -{
  13.175 -    int			fd, on;
  13.176 -    struct sockaddr_in	sin;
  13.177 -
  13.178 -    if ((fd = socket (AF_INET, SOCK_STREAM, 0)) < 0)
  13.179 -	fault("socket");
  13.180 -    
  13.181 -    on = 1;
  13.182 -    if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0)
  13.183 -      syslog(LOG_WARNING, "setsockopt (SO_REUSEADDR): %m");
  13.184 -
  13.185 -    memset(&sin, 0, sizeof(sin));
  13.186 -    sin.sin_family      = AF_INET;
  13.187 -    sin.sin_port        = htons (port);
  13.188 -    sin.sin_addr.s_addr = INADDR_ANY;
  13.189 -    if (bind(fd, &sin, sizeof(sin)) < 0)
  13.190 -	fault("bind: %u: %s\n", port, strerror(errno));
  13.191 -    
  13.192 -    if (listen(fd, 1) < 0)
  13.193 -	fault("listen: %s\n", strerror(errno));
  13.194 -    
  13.195 -    return fd;
  13.196 -}
  13.197 -
  13.198 -static void noblock(int fd)
  13.199 -{
  13.200 -    int on=1;
  13.201 -    
  13.202 -    if (ioctl(fd, FIONBIO, &on) < 0)
  13.203 -	fault("ioctl: FIONBIO: %s\n", strerror(errno));
  13.204 -}
  13.205 -
  13.206 -
  13.207 -/* You might not believe this, but fd_sets don't have to be a 32-bit
  13.208 - * integer.  In particular, in glibc2 it is an array of unsigned
  13.209 - * longs.  Hence, this hacked up FD_SET_rjb() that works out if it
  13.210 - * would have been a nop. */
  13.211 -#define FD_SET_rjb(fd, setp) \
  13.212 -do {						\
  13.213 -    if ((fd) != 32)				\
  13.214 -	FD_SET((fd), (setp));			\
  13.215 -} while(0)
  13.216 -
  13.217 -#define FD_ISSET_rjb(fd, setp) (((fd) != 32)? FD_ISSET((fd), (setp)) : 0)
  13.218 -
  13.219 -#define MAXSIZE	256
  13.220 -
  13.221 -/* -----------------------------------------------------------------
  13.222 - * The main bit of the algorithm. Note we use 32 to mean not connected
  13.223 - * because this gives us 1<<32 == 0. We could have done this one
  13.224 - * character at a time, but that would have been very inefficient and
  13.225 - * not the unix way.  */
  13.226 -static int debug;
  13.227 -
  13.228 -static void doit(int actl, int acto, int lish, int lisg, int lisc)
  13.229 -{
  13.230 -    int		acth, actg, actc;
  13.231 -    int		gdbmode = FALSE;
  13.232 -    char	gibuf[MAXSIZE], oibuf[MAXSIZE];
  13.233 -    char	libuf[MAXSIZE], lobuf[MAXSIZE];
  13.234 -    char	hibuf[MAXSIZE], hobuf[MAXSIZE];
  13.235 -    char	ctlbuf[MAXSIZE];
  13.236 -    fd_set	rdfs, wrfs, exfs;
  13.237 -    int		gicc, oicc, licc, locc, hicc, hocc, ctlcc;
  13.238 -    char	*giptr, *oiptr, *liptr, *loptr, *hiptr, *hoptr;
  13.239 -    int		rc, fromlen;
  13.240 -    struct sockaddr_in		from;
  13.241 -    
  13.242 -    gicc = oicc = licc = locc = hicc = hocc = ctlcc = 0;
  13.243 -    acth = actg = actc = 32;			/* XXX yummy */
  13.244 -
  13.245 -    noblock(actl);
  13.246 -    noblock(acto);
  13.247 -
  13.248 -    for(;;)
  13.249 -    {
  13.250 -	FD_ZERO(&rdfs);
  13.251 -	FD_ZERO(&wrfs);
  13.252 -	FD_ZERO(&exfs);
  13.253 -
  13.254 -	/* always take input from the control port (if it's connected) */
  13.255 -	FD_SET_rjb(actc, &rdfs);
  13.256 -
  13.257 -	if (gdbmode)
  13.258 -	{
  13.259 -	    if (oicc)
  13.260 -		FD_SET_rjb(actg, &wrfs);
  13.261 -	    else
  13.262 -		FD_SET_rjb(acto, &rdfs);
  13.263 -	    
  13.264 -	    if (gicc)
  13.265 -		FD_SET_rjb(acto, &wrfs);
  13.266 -	    else
  13.267 -		FD_SET_rjb(actg, &rdfs);
  13.268 -	}
  13.269 -	else
  13.270 -	{
  13.271 -	    /* There is no such thing as oibuf because its been split into
  13.272 -	     * lobuf and hobuf
  13.273 -	     */
  13.274 -	    if (locc || hocc)
  13.275 -	    {
  13.276 -		if (locc)
  13.277 -		    FD_SET_rjb(actl, &wrfs);
  13.278 -		if (hocc)
  13.279 -		    FD_SET_rjb(acth, &wrfs);
  13.280 -	    }
  13.281 -	    else
  13.282 -		FD_SET_rjb(acto, &rdfs);
  13.283 -	    
  13.284 -	    if (licc)
  13.285 -		FD_SET_rjb(acto, &wrfs);
  13.286 -	    else
  13.287 -		FD_SET_rjb(actl, &rdfs);
  13.288 -	    
  13.289 -	    if (hicc)
  13.290 -		FD_SET_rjb(acto, &wrfs);
  13.291 -	    else
  13.292 -		FD_SET_rjb(acth, &rdfs);
  13.293 -	}
  13.294 -	
  13.295 -	if (acth == 32 && lish>=0)	FD_SET_rjb(lish, &rdfs);
  13.296 -	if (actg == 32)			FD_SET_rjb(lisg, &rdfs);
  13.297 -	if (actc == 32)			FD_SET_rjb(lisc, &rdfs);
  13.298 -
  13.299 -	/* now make exfs the union of the read and write fd sets, plus
  13.300 -	 * "actl" */
  13.301 -	{
  13.302 -	    int i;
  13.303 -	    exfs = rdfs;
  13.304 -	    for(i=0; i<32; i++)  /* XXX we only copy fd numbers up to 31 */
  13.305 -		if (FD_ISSET(i, &wrfs))
  13.306 -		    FD_SET_rjb(i, &exfs);
  13.307 -	    FD_SET_rjb(actl, &exfs);
  13.308 -	}
  13.309 -
  13.310 -	/* XXX AND: can't print something of type fd_set as %x - it
  13.311 -         * might be an array */
  13.312 -	DB(fprintf(stderr, "%s: before select: %08x %08x %08x\n",
  13.313 -		   prog_name, rdfs, wrfs, exfs));
  13.314 -	
  13.315 -	if (select(32, &rdfs, &wrfs, &exfs, NULL) < 0)
  13.316 -	    fault("select: %s\n", strerror(errno));
  13.317 -	
  13.318 -	DB(fprintf(stderr, "%s: after  select: %08x %08x %08x\n",
  13.319 -		   prog_name, rdfs, wrfs, exfs));
  13.320 -	
  13.321 -	/* XXX it appears that a non-blocking socket may not show up
  13.322 -	 * correctly in exfs but instead goes readable with no data in
  13.323 -	 * it. Thus we check for zero and goto the appropriate close
  13.324 -	 * method.  */
  13.325 -
  13.326 -	/* Deal with exceptions */
  13.327 -	if (FD_ISSET_rjb(actg, &exfs))
  13.328 -	{
  13.329 -	exfs_actg:
  13.330 -	    close(actg);
  13.331 -	    gdbmode = FALSE;
  13.332 -	    oicc = 0;
  13.333 -	    oiptr = oibuf;
  13.334 -	    actg = 32;
  13.335 -	    continue;		/* because assumptions changed */
  13.336 -	}
  13.337 -	if (FD_ISSET_rjb(acth, &exfs))
  13.338 -	{
  13.339 -	exfs_acth:
  13.340 -	    close(acth);
  13.341 -	    hicc = hocc = 0;
  13.342 -	    hiptr = hibuf;
  13.343 -	    hoptr = hibuf;
  13.344 -	    acth = 32;
  13.345 -	    continue;		/* because assumptions changed */
  13.346 -	}
  13.347 -	if (FD_ISSET_rjb(actl, &exfs) ||
  13.348 -	    FD_ISSET_rjb(acto, &exfs))
  13.349 -	{
  13.350 -	exfs_actl:
  13.351 -	exfs_acto:
  13.352 -	    /* Thats all folks ... */
  13.353 -	    break;
  13.354 -	}
  13.355 -	if (FD_ISSET_rjb(actc, &exfs))
  13.356 -	{
  13.357 -	exfs_ctl:
  13.358 -	    close(actc);
  13.359 -	    actc = 32;
  13.360 -	    ctlcc = 0;
  13.361 -	    continue;
  13.362 -	}
  13.363 -
  13.364 -	/* Deal with reading */
  13.365 -	if (FD_ISSET_rjb(acto, &rdfs))
  13.366 -	{
  13.367 -	    if ((oicc = read(acto, oiptr = oibuf, MAXSIZE)) < 0)
  13.368 -		fault("read acto: %d: %s\n", oicc, strerror(errno));
  13.369 -	    if (!oicc) goto exfs_acto;
  13.370 -	    
  13.371 -	    if (!gdbmode)
  13.372 -	    {
  13.373 -		int t;
  13.374 -
  13.375 -		assert((locc == 0) && (hocc == 0));
  13.376 -		loptr = lobuf;
  13.377 -		hoptr = hobuf;
  13.378 -		
  13.379 -		if (lish>=0) {
  13.380 -		    for(t=0; t<oicc; t++)
  13.381 -			if (oibuf[t] & 0x80)
  13.382 -			    hobuf[hocc++] = oibuf[t] & 0x7f;
  13.383 -			else
  13.384 -			    lobuf[locc++] = oibuf[t];
  13.385 -		} else {
  13.386 -		    for (t=0; t<oicc; t++)
  13.387 -			lobuf[locc++] = oibuf[t];
  13.388 -		}
  13.389 -		/* If no high connection scratch that */
  13.390 -		if (acth == 32)
  13.391 -		    hocc=0;
  13.392 -	    }
  13.393 -	}
  13.394 -	if (FD_ISSET_rjb(actl, &rdfs))
  13.395 -	{
  13.396 -	    if ((licc = read(actl, liptr = libuf, MAXSIZE)) < 0)
  13.397 -		fault("read actl: %d: %s\n", licc, strerror(errno));
  13.398 -	    if (!licc) goto exfs_actl;
  13.399 -	}
  13.400 -	if (FD_ISSET_rjb(acth, &rdfs))
  13.401 -	{
  13.402 -	    int t;
  13.403 -	    
  13.404 -	    if ((hicc = read(acth, hiptr = hibuf, MAXSIZE)) < 0)
  13.405 -		fault("read acth: %d: %s\n", hicc, strerror(errno));
  13.406 -	    if (!hicc) goto exfs_acth;
  13.407 -	    for(t=0; t<hicc; t++)
  13.408 -		hibuf[t] |= 0x80;
  13.409 -	}
  13.410 -	if (FD_ISSET_rjb(actg, &rdfs))
  13.411 -	{
  13.412 -	    if ((gicc = read(actg, giptr = gibuf, MAXSIZE)) < 0)
  13.413 -		fault("read actg: %d: %s\n", gicc, strerror(errno));
  13.414 -	    if (debug) write(1, giptr, gicc);		/* XXX */
  13.415 -	    if (!gicc) goto exfs_actg;
  13.416 -	}
  13.417 -	if (FD_ISSET_rjb(actc, &rdfs))
  13.418 -	{
  13.419 -	    if ((ctlcc = read(actc, ctlbuf, MAXSIZE)) < 0)
  13.420 -		fault("read actc: %d: %s\n", ctlcc, strerror(errno));
  13.421 -	    if (debug) write(1, ctlbuf, gicc);
  13.422 -	    if (!ctlcc) goto exfs_ctl;
  13.423 -	    if (ctlbuf[0] == 'r') /* reset command */
  13.424 -	    {
  13.425 -		syslog(LOG_INFO, "reset command read, exiting");
  13.426 -		if (debug) write(1, "reseting\n", sizeof("reseting\n"));
  13.427 -		break;
  13.428 -	    }
  13.429 -	}
  13.430 -	
  13.431 -	/* Deal with writing */
  13.432 -	if (FD_ISSET_rjb(actg, &wrfs))
  13.433 -	{
  13.434 -	    /* We must be in gdb mode so send oi buffer data */
  13.435 -	    assert(gdbmode);
  13.436 -	    if (debug) write(2, oiptr, oicc);		/* XXX */
  13.437 -	    if ((rc = write(actg, oiptr, oicc)) <= 0)
  13.438 -		fault("write actg: %d: %s\n", rc, strerror(errno));
  13.439 -	    oiptr += rc;
  13.440 -	    oicc  -= rc;
  13.441 -	}
  13.442 -	if (FD_ISSET_rjb(actl, &wrfs))
  13.443 -	{
  13.444 -	    if ((rc = write(actl, loptr, locc)) <= 0)
  13.445 -		fault("write actl: %d: %s\n", rc, strerror(errno));
  13.446 -	    loptr += rc;
  13.447 -	    locc  -= rc;
  13.448 -	}
  13.449 -	if (FD_ISSET_rjb(acth, &wrfs))
  13.450 -	{
  13.451 -	    if ((rc = write(acth, hoptr, hocc)) <= 0)
  13.452 -		fault("write acth: %d: %s\n", rc, strerror(errno));
  13.453 -	    hoptr += rc;
  13.454 -	    hocc  -= rc;
  13.455 -	}
  13.456 -	if (FD_ISSET_rjb(acto, &wrfs))
  13.457 -	{
  13.458 -	    /* If in gdb mode send gdb input, otherwise send low data
  13.459 -	       preferentially */
  13.460 -	    if (gdbmode)
  13.461 -	    {
  13.462 -		assert(gicc);
  13.463 -		if ((rc = write(acto, giptr, gicc)) <= 0)
  13.464 -		    fault("write acto: %d: %s\n", rc, strerror(errno));
  13.465 -		giptr += rc;
  13.466 -		gicc  -= rc;
  13.467 -	    }
  13.468 -	    else
  13.469 -	    {
  13.470 -		if (licc)
  13.471 -		{
  13.472 -		    if ((rc = write(acto, liptr, licc)) <= 0)
  13.473 -			fault("write acto: %d: %s\n", rc, strerror(errno));
  13.474 -		    liptr += rc;
  13.475 -		    licc  -= rc;
  13.476 -		}
  13.477 -		else
  13.478 -		{
  13.479 -		    assert(hicc);
  13.480 -		    if ((rc = write(acto, hiptr, hicc)) <= 0)
  13.481 -			fault("write acto: %d: %s\n", rc, strerror(errno));
  13.482 -		    hiptr += rc;
  13.483 -		    hicc  -= rc;
  13.484 -		}
  13.485 -	    }
  13.486 -	}
  13.487 -	
  13.488 -	/* Deals with new connections */
  13.489 -	if ((acth == 32) && lish>=0 && (FD_ISSET_rjb(lish, &rdfs)))
  13.490 -	{
  13.491 -	    fromlen = sizeof(from);
  13.492 -	    if ((acth = accept(lish, &from, &fromlen)) < 0)
  13.493 -	    {
  13.494 -		syslog(LOG_WARNING, "accept: %m");
  13.495 -		acth = 32;
  13.496 -	    }
  13.497 -	    else
  13.498 -	    {
  13.499 -		noblock(acth);
  13.500 -		hicc = hocc = 0;
  13.501 -		syslog(LOG_INFO, "highbit client peer is %s:%u\n",
  13.502 -		       inet_ntoa(from.sin_addr), ntohs(from.sin_port));
  13.503 -	    }
  13.504 -	}
  13.505 -	
  13.506 -	if ((actg == 32) && (FD_ISSET_rjb(lisg, &rdfs)))
  13.507 -	{
  13.508 -	    fromlen = sizeof(from);
  13.509 -	    if ((actg = accept(lisg, &from, &fromlen)) < 0)
  13.510 -	    {
  13.511 -		syslog(LOG_WARNING, "accept: %m");
  13.512 -		actg = 32;
  13.513 -	    }
  13.514 -	    else
  13.515 -	    {
  13.516 -		noblock(actg);
  13.517 -		gicc = 0;
  13.518 -		gdbmode = TRUE;
  13.519 -		syslog(LOG_INFO, "gdb client peer is %s:%u\n",
  13.520 -		       inet_ntoa(from.sin_addr), ntohs(from.sin_port));
  13.521 -	    }
  13.522 -	}
  13.523 -
  13.524 -	if ((actc == 32) && (FD_ISSET_rjb(lisc, &rdfs)))
  13.525 -	{
  13.526 -	    fromlen = sizeof(from);
  13.527 -	    if ((actc = accept(lisc, &from, &fromlen)) < 0)
  13.528 -	    {
  13.529 -		syslog(LOG_WARNING, "accept (ctl): %m");
  13.530 -		actc = 32;
  13.531 -	    }
  13.532 -	    else
  13.533 -	    {
  13.534 -		noblock(actc);
  13.535 -		syslog(LOG_INFO, "ctl client peer is %s:%u\n",
  13.536 -		       inet_ntoa(from.sin_addr), ntohs(from.sin_port));
  13.537 -	    }
  13.538 -	}
  13.539 -	    
  13.540 -	/* Back to top of loop */
  13.541 -    }
  13.542 -    
  13.543 -    /* We are bailing because one of the primary connections has gone
  13.544 -     * away. We close these all explicitly here because that way the
  13.545 -     * timeout on reusing the port numbers is smnaller. */
  13.546 -    
  13.547 -    close(acth);
  13.548 -    close(actg);
  13.549 -    /* XXX AND: why are we closing all these "character counts" ?? */
  13.550 -    close(gicc);
  13.551 -    close(oicc);
  13.552 -    close(licc);
  13.553 -    close(locc);
  13.554 -    close(hicc);
  13.555 -    close(hocc);
  13.556 -}
  13.557 -
  13.558 -/*
  13.559 - * ------------------------------------------------------------
  13.560 - */
  13.561 -int main(int argc, char **argv)
  13.562 -{
  13.563 -    /* In general, suffix "l" is low channel, "h" is high channel, "g"
  13.564 -     * is gdb channel, "c" is control channel and "o" is output channel.
  13.565 -     */
  13.566 -    struct sockaddr_in		from;
  13.567 -    int				infd = 0, outfd;
  13.568 -    unsigned short		portl, porth, portg, portc, porto;
  13.569 -    int				on = 1, c;
  13.570 -    char			*outname, *outservice;
  13.571 -    int				fromlen;
  13.572 -    int				lish, lisg, lisc;
  13.573 -#if 0
  13.574 -    FILE			*newerr;
  13.575 -#endif /* 0 */
  13.576 -    
  13.577 -    prog_name = argv[0];
  13.578 -
  13.579 -    if (isatty(infd))
  13.580 -	usage();
  13.581 -
  13.582 -    /* Here, then not just a simple idiot. */
  13.583 -
  13.584 -    signal(SIGPIPE, SIG_IGN);
  13.585 -
  13.586 -    openlog(prog_name, LOG_PID, LOG_DAEMON);
  13.587 -
  13.588 -    fromlen = sizeof(from);
  13.589 -    if (getsockname(infd, &from, &fromlen) < 0)
  13.590 -	fault("getsockname: %s", strerror(errno));
  13.591 -    if ((fromlen != sizeof(from)) || (from.sin_family != AF_INET))
  13.592 -	fault("not an inet socket (family=%d)\n", from.sin_family);
  13.593 -    
  13.594 -    portl = ntohs(from.sin_port);
  13.595 -    porth = portl+1;
  13.596 -    portg = porth+1;
  13.597 -    portc = portg+1;
  13.598 -
  13.599 -    fromlen = sizeof(from);
  13.600 -    if (getpeername(infd, &from, &fromlen) < 0)
  13.601 -	fault("getpeername: %s", strerror(errno));
  13.602 -    if ((fromlen != sizeof(from)) || (from.sin_family != AF_INET))
  13.603 -	fault("not an inet socket (family=%d)\n", from.sin_family);
  13.604 -
  13.605 -    syslog(LOG_INFO, "on port %u peer is %s:%u\n", portl,
  13.606 -	   inet_ntoa(from.sin_addr), ntohs(from.sin_port));
  13.607 -    
  13.608 -    if (setsockopt(infd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof (on)) < 0)
  13.609 -	syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");
  13.610 -
  13.611 -    /* from here on, we map stderr to output on the connection so we can
  13.612 -     * report errors to the remote user.
  13.613 -     */
  13.614 -#if 0
  13.615 -    if (!(newerr = fdopen(infd, "w")))
  13.616 -	syslog(LOG_WARNING, "fdopen: %m");
  13.617 -    else
  13.618 -	*stderr = *newerr;
  13.619 -#endif
  13.620 -	
  13.621 -    while((c = getopt(argc, argv, "d8h:g:c:")) != EOF)
  13.622 -    {
  13.623 -	switch(c)
  13.624 -	{
  13.625 -	case 'd':
  13.626 -	    debug++;
  13.627 -	    break;
  13.628 -	    
  13.629 -	case 'h':
  13.630 -	    /* high bit port */
  13.631 -	    if (getservice(optarg, &porth) < 0)
  13.632 -		fault("getservice failed (high port '%s')\n", optarg);
  13.633 -	    break;
  13.634 -	    
  13.635 -	case 'g':
  13.636 -	    /* gdb port */
  13.637 -	    if (getservice(optarg, &portg) < 0)
  13.638 -		fault("getservice failed (gdb port '%s')\n", optarg);
  13.639 -	    break;
  13.640 -
  13.641 -	case 'c':
  13.642 -	    /* control port */
  13.643 -	    if (getservice(optarg, &portc) < 0)
  13.644 -		fault("getservice failed (control port '%s')\n", optarg);
  13.645 -	    break;
  13.646 -
  13.647 -	case '8':
  13.648 -	    /* 8-bit clean; no high port */
  13.649 -	    porth=0;
  13.650 -	    break;
  13.651 -
  13.652 -	default:
  13.653 -	    fault("bad argument list!\n");
  13.654 -	}
  13.655 -    }
  13.656 -    
  13.657 -    if (argc != optind + 1)
  13.658 -	fault("unparsed arguments (%d!=%d)\n", argc, optind+1);
  13.659 -
  13.660 -    outname = argv[optind];
  13.661 -    if (!(outservice = strchr(outname, ':')))
  13.662 -	fault("output arg '%s' doesn't contain ':'\n", outname);
  13.663 -    *outservice++ = 0;
  13.664 -    if (getservice(outservice, &porto) < 0)
  13.665 -	fault("getservice failed (output port '%s')\n", outservice);
  13.666 -    
  13.667 -    /* Time to start the sockets */
  13.668 -
  13.669 -    if (porth) {
  13.670 -	lish  = startlistening(porth);
  13.671 -    } else {
  13.672 -	lish  = -1;
  13.673 -    }
  13.674 -    lisg  = startlistening(portg);
  13.675 -    lisc  = startlistening(portc);
  13.676 -    
  13.677 -    outfd = connect_host(outname, porto);
  13.678 -    
  13.679 -    doit(infd, outfd, lish, lisg, lisc);
  13.680 -
  13.681 -    syslog(LOG_INFO, "terminating normally\n");
  13.682 -
  13.683 -    fclose(stderr);
  13.684 -
  13.685 -    closelog();
  13.686 -    exit(0); 
  13.687 -}
  13.688 -
  13.689 -/* End $Id: nsplitd.c,v 2.6 1998/09/17 14:28:37 sde1000 Exp $ */