Skip to content

Commit

Permalink
Merge pull request #626 from ghaerr/tcp2
Browse files Browse the repository at this point in the history
[ktcp] Further cleanup and enhancements to networking
  • Loading branch information
ghaerr authored May 12, 2020
2 parents dbf00e1 + a9508ac commit 552b5e7
Show file tree
Hide file tree
Showing 27 changed files with 128 additions and 75 deletions.
1 change: 0 additions & 1 deletion config-emu86
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ CONFIG_SOCKET=y
# CONFIG_NANO is not set
CONFIG_INET=y
CONFIG_CSLIP=y
CONFIG_INET_STATUS=y
# CONFIG_UNIX is not set

#
Expand Down
1 change: 0 additions & 1 deletion elks/arch/i86/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ CONFIG_SOCKET=y
# CONFIG_NANO is not set
CONFIG_INET=y
CONFIG_CSLIP=y
CONFIG_INET_STATUS=y
# CONFIG_UNIX is not set

#
Expand Down
12 changes: 7 additions & 5 deletions elks/arch/i86/drivers/char/pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,21 @@ size_t pty_read (struct inode *inode, struct file *file, char *data, size_t len)
size_t pty_write (struct inode *inode, struct file *file, char *data, size_t len)
{
int count = 0;
int err;
register int ret;

struct tty *tty = determine_tty (inode->i_rdev);
if (tty == NULL) return -EBADF;

while (count < len) {
err = chq_wait_wr (&tty->inq, (file->f_flags & O_NONBLOCK) | count);
if (err < 0) {
if (count == 0) count = err;
ret = chq_wait_wr (&tty->inq, (file->f_flags & O_NONBLOCK) | count);
if (ret < 0) {
if (count == 0) count = ret;
break;
}

chq_addch (&tty->inq, get_user_char ((void *)(data++)));
ret = get_user_char ((void *)(data++));
if (!tty_intcheck(tty, ret))
chq_addch (&tty->inq, ret);
count++;
}

Expand Down
51 changes: 26 additions & 25 deletions elks/arch/i86/drivers/net/ne2k-mac.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,43 @@

// TODO: move definitions to ne2k-defs.s

// I/O base @ 300h
// adjust only this line for card base address
base = 0x0300 // I/O base address

io_ne2k_command = 0x0300

io_ne2k_rx_first = 0x0301 // page 0
io_ne2k_rx_last = 0x0302 // page 0
io_ne2k_rx_get = 0x0303 // page 0
// register array
io_ne2k_command = base+0x00 // command
io_ne2k_rx_first = base+0x01 // page 0
io_ne2k_rx_last = base+0x02 // page 0
io_ne2k_rx_get = base+0x03 // page 0

// This is not a true NE2K register
//io_ne2k_rx_put1 = 0x0306 // page 0 - read
//io_ne2k_rx_put1 = base+0x06 // page 0 - read

io_ne2k_tx_start = 0x0304 // page 0 - write
io_ne2k_tx_len1 = 0x0305 // page 0 - write
io_ne2k_tx_len2 = 0x0306 // page 0 - write
io_ne2k_tx_start = base+0x04 // page 0 - write
io_ne2k_tx_len1 = base+0x05 // page 0 - write
io_ne2k_tx_len2 = base+0x06 // page 0 - write

io_ne2k_int_stat = 0x0307 // page 0
io_ne2k_int_stat = base+0x07 // page 0

io_ne2k_dma_addr1 = 0x0308 // page 0
io_ne2k_dma_addr2 = 0x0309 // page 0
io_ne2k_dma_len1 = 0x030A // page 0 - write
io_ne2k_dma_len2 = 0x030B // page 0 - write
io_ne2k_dma_addr1 = base+0x08 // page 0
io_ne2k_dma_addr2 = base+0x09 // page 0
io_ne2k_dma_len1 = base+0x0A // page 0 - write
io_ne2k_dma_len2 = base+0x0B // page 0 - write

io_ne2k_rx_stat = 0x030C // page 0 - read
io_ne2k_rx_stat = base+0x0C // page 0 - read

io_ne2k_rx_conf = 0x030C // page 0 - write
io_ne2k_tx_conf = 0x030D // page 0 - write
io_ne2k_data_conf = 0x030E // page 0 - write
io_ne2k_int_mask = 0x030F // page 0 - write
io_ne2k_rx_conf = base+0x0C // page 0 - write
io_ne2k_tx_conf = base+0x0D // page 0 - write
io_ne2k_data_conf = base+0x0E // page 0 - write
io_ne2k_int_mask = base+0x0F // page 0 - write

io_ne2k_unicast = 0x0301 // page 1 - 6 bytes
io_ne2k_rx_put = 0x0307 // page 1
io_ne2k_multicast = 0x0308 // page 1 - 8 bytes
io_ne2k_unicast = base+0x01 // page 1 - 6 bytes
io_ne2k_rx_put = base+0x07 // page 1
io_ne2k_multicast = base+0x08 // page 1 - 8 bytes

io_ne2k_data_io = 0x0310 // 2 bytes
io_ne2k_data_io = base+0x10 // 2 bytes

io_ne2k_reset = 0x031F
io_ne2k_reset = base+0x1F


// Ring segmentation
Expand Down
1 change: 0 additions & 1 deletion elks/net/config.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ mainmenu_option next_comment
bool ' TCP/IP sockets' CONFIG_INET y
if [ "$CONFIG_INET" = "y" ]; then
bool ' CSLIP TCP/IP header compression' CONFIG_CSLIP n
bool ' Enable status report' CONFIG_INET_STATUS y
fi

bool ' UNIX sockets' CONFIG_UNIX n
Expand Down
8 changes: 7 additions & 1 deletion elkscmd/ash/linenoise_elks.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@

/* set these to 0 to reduce the code size */
#define COMPLETION_ON 1
#define DYNAMIC_LINELEN 0
#define MULTILINE_ON 0
#define HINTS_ON 0
#define MASK_ON 0
Expand Down Expand Up @@ -307,6 +308,7 @@ static void disableRawMode(int fd) {
rawmode = 0;
}

#if DYNAMIC_LINELEN
/* Use the ESC [6n escape sequence to query the horizontal cursor position
* and return it. On error -1 is returned, on success the position of the
* cursor. */
Expand Down Expand Up @@ -341,10 +343,13 @@ static int getCursorPosition(int ifd, int ofd) {
if (sscanf(buf+2,"%d;%d",&rows,&cols) != 2) return -1;
return cols;
}
#endif /* DYNAMIC_LINELEN*/

/* Try to get the number of columns in the current terminal, or assume 80
* if it fails. */
static int getColumns(int ifd, int ofd) {
static int getColumns(int ifd, int ofd)
{
#if DYNAMIC_LINELEN
struct winsize ws;

if (ioctl(1, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0) {
Expand Down Expand Up @@ -379,6 +384,7 @@ static int getColumns(int ifd, int ofd) {
}

failed:
#endif /* DYNAMIC_LINELEN*/
return 80;
}

Expand Down
29 changes: 11 additions & 18 deletions elkscmd/inet/telnetd/telnetd.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,14 @@
static char buf_in [MAX_BUFFER];
static char buf_out [MAX_BUFFER];

//char * nargv[2] = {"/bin/login", NULL};
char * nargv[2] = {"/bin/sash", NULL};

void sigchild(int signo)
{
fprintf(stderr, "Signal received:%d", signo);
exit(0);
}
char *nargv[2] = {"/bin/login", NULL};

static pid_t term_init(int sockfd, int *pty_fd)
{
int n = 0;
int tty_fd;
pid_t pid;
char pty_name[12];
struct termios termios;

again:
sprintf(pty_name, "/dev/ptyp%d", n);
Expand All @@ -50,8 +42,6 @@ static pid_t term_init(int sockfd, int *pty_fd)
fprintf(stderr, "Can't create pty %s\n", pty_name);
return -1;
}
//signal(SIGCHLD, sigchild);
//signal(SIGINT, sigchild);
signal(SIGCHLD, SIG_IGN);
signal(SIGINT, SIG_IGN);

Expand All @@ -66,18 +56,21 @@ static pid_t term_init(int sockfd, int *pty_fd)
close(STDOUT_FILENO);
close(STDERR_FILENO);
close(*pty_fd);

setsid();
pty_name[5] = 't'; /* results in: /dev/ttyp%d */
if ((tty_fd = open(pty_name, O_RDWR)) < 0) {
fprintf(stderr, "telnetd: Can't open pty %s\n", pty_name);
exit(1);
}

/* turn off echo*/
#if 0
struct termios termios;
/* turn off echo - not needed with telnet ECHO option on*/
tcgetattr(tty_fd, &termios);
termios.c_lflag &= ~(ECHO);
tcsetattr(tty_fd, TCSANOW, &termios);
#endif

dup2(tty_fd, STDIN_FILENO);
dup2(tty_fd, STDOUT_FILENO);
Expand All @@ -93,11 +86,11 @@ static void telnet_init(int ofd)
{
tel_init();

//telopt(ofd, WILL, TELOPT_SGA);
//telopt(ofd, DO, TELOPT_SGA);
//telopt(ofd, WILL, TELOPT_BINARY);
//telopt(ofd, DO, TELOPT_BINARY);
//telopt(ofd, WILL, TELOPT_ECHO);
telopt(ofd, WILL, TELOPT_SGA);
telopt(ofd, DO, TELOPT_SGA);
telopt(ofd, WILL, TELOPT_BINARY);
telopt(ofd, DO, TELOPT_BINARY);
telopt(ofd, WILL, TELOPT_ECHO);
//telopt(ofd, DO, TELOPT_WINCH);
}

Expand Down
2 changes: 2 additions & 0 deletions elkscmd/ktcp/arp.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <linuxmt/arpa/inet.h>

#include "deveth.h"
#include "tcp.h"
#include "tcpdev.h"
#include "ip.h"
#include "arp.h"

Expand Down
1 change: 1 addition & 0 deletions elkscmd/ktcp/arp.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void arp_cache_add (ipaddr_t ip_addr, eth_addr_t * eth_addr);
int arp_cache_get (ipaddr_t ip_addr, eth_addr_t * eth_addr);

void arp_proc (char * packet, int size);
int arp_request(ipaddr_t ipaddress);


#endif /* !ARP_H */
2 changes: 2 additions & 0 deletions elkscmd/ktcp/deveth.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "config.h"
#include "deveth.h"
#include "tcp.h"
#include "ip.h"
#include "tcpdev.h"
#include "arp.h"

Expand Down
2 changes: 1 addition & 1 deletion elkscmd/ktcp/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include <sys/stat.h>
#include <fcntl.h>
#include "slip.h"
#include "icmp.h"
#include "ip.h"
#include "icmp.h"
#include <linuxmt/arpa/inet.h>

int icmp_init(void)
Expand Down
3 changes: 3 additions & 0 deletions elkscmd/ktcp/icmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@

#define PROTO_ICMP 1

int icmp_init(void);
void icmp_process(struct iphdr_s *iph, char *packet);

#endif
7 changes: 4 additions & 3 deletions elkscmd/ktcp/ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@

#include "ip.h"
#include "icmp.h"
#include "slip.h"
#include "tcp.h"
#include "tcpdev.h"
#include <linuxmt/arpa/inet.h>
#include "deveth.h"
#include "arp.h"

#if 0
#define IP_VERSION(s) ((s)->version_ihl>>4&0xf)
Expand Down Expand Up @@ -160,7 +162,6 @@ void ip_sendpacket(char *packet,int len,struct addr_pair *apair)
{
struct iphdr_s *iph = (struct iphdr_s *)ipbuf;
__u16 tlen;
ipaddr_t tmpaddress;
char llbuf[15];
struct ip_ll *ipll = (struct ip_ll *)llbuf;
ipaddr_t ip_addr;
Expand All @@ -169,8 +170,8 @@ void ip_sendpacket(char *packet,int len,struct addr_pair *apair)
unsigned char *addr = (unsigned char *) &apair->daddr;
debug_ip("IPSEND daddr: %d.%d.%d.%d\n", addr [0], addr [1], addr [2], addr [3]);

if (apair->daddr == local_ip || apair->daddr == 0x0100007f) //FIXME
goto local;
if (apair->daddr == local_ip || apair->daddr == 0x0100007f) //FIXME
goto local;

if (dev->type == 1) { /* Ethernet */
debug_ip("ETH ROUTE\n");
Expand Down
4 changes: 4 additions & 0 deletions elkscmd/ktcp/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ struct ip_ll

extern int tcpdevfd;

int ip_init(void);
void ip_recvpacket(char *packet, int size);
void ip_sendpacket(char *packet, int len, struct addr_pair *apair);

#endif
8 changes: 5 additions & 3 deletions elkscmd/ktcp/ktcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
#include <string.h>

#include "slip.h"
#include "tcp.h"
#include "tcp_output.h"
#include "tcpdev.h"
#include "timer.h"
#include <linuxmt/arpa/inet.h>
#include "ip.h"
#include "tcp.h"
#include "icmp.h"
#include "netconf.h"
#include "deveth.h"
#include "arp.h"

#ifdef DEBUG
#define debug printf
Expand All @@ -38,7 +41,7 @@ char deveth[] = "/dev/eth";

static int intfd;

unsigned long int in_aton(const char *str)
unsigned long in_aton(const char *str)
{
unsigned long l = 0;
unsigned int val;
Expand Down Expand Up @@ -102,7 +105,6 @@ extern int cbs_in_user_timeout;

int main(int argc,char **argv)
{
__u8 * addr;
int daemon = 0;
speed_t baudrate = 0;
char *progname = argv[0];
Expand Down
7 changes: 4 additions & 3 deletions elkscmd/ktcp/netconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "config.h"
#include <linuxmt/arpa/inet.h>
#include "tcp.h"
#include "tcp_cb.h"
#include "tcpdev.h"
#include "netconf.h"

Expand Down Expand Up @@ -39,7 +40,7 @@ void netconf_send(struct tcpcb_s *cb)
if (sreq.type == NS_GENERAL) {
gstats.cb_num = tcpcb_num;
gstats.retrans_memory = tcp_retrans_memory;
tcpcb_buf_write(cb, &gstats, sizeof(gstats));
tcpcb_buf_write(cb, (unsigned char *)&gstats, sizeof(gstats));
} else if (sreq.type == NS_CB) {
ncb = tcpcb_getbynum(sreq.extra);
if (ncb) {
Expand All @@ -51,7 +52,7 @@ void netconf_send(struct tcpcb_s *cb)
cbstats.localport = ncb->localport;
} else
cbstats.valid = 0;
tcpcb_buf_write(cb, &cbstats, sizeof(cbstats) );
tcpcb_buf_write(cb, (unsigned char *)&cbstats, sizeof(cbstats) );
}
cb->bytes_to_push = CB_BUF_USED(cb);
cb->bytes_to_push = CB_BUF_USED(cb);
}
Loading

0 comments on commit 552b5e7

Please sign in to comment.