plan 9 kernel history: overview | file list | diff list

1991/1204/port/ipdat.h (diff list | history)

port/ipdat.h on 1991/0424
1991/0424    
typedef struct Ipconv	Ipconv; 
typedef struct Ipifc	Ipifc; 
typedef struct Fragq	Fragq; 
typedef struct Ipfrag	Ipfrag; 
typedef ulong		Ipaddr; 
typedef ushort		Port; 
typedef struct Udphdr	Udphdr; 
typedef struct Etherhdr	Etherhdr; 
typedef struct Reseq	Reseq; 
typedef struct Tcp	Tcp; 
typedef struct Tcpctl	Tcpctl; 
typedef struct Tcphdr	Tcphdr; 
typedef struct Timer	Timer; 
1991/1012    
typedef struct Ilhdr	Ilhdr; 
typedef struct Ilcb	Ilcb; 
1991/0424    
 
1991/1012    
struct Etherhdr 
{ 
1991/0424    
#define ETHER_HDR	14 
	uchar	d[6]; 
	uchar	s[6]; 
	uchar	type[2]; 
 
	/* Now we have the ip fields */ 
#define ETHER_IPHDR	20 
	uchar	vihl;		/* Version and header length */ 
	uchar	tos;		/* Type of service */ 
	uchar	length[2];	/* packet length */ 
	uchar	id[2];		/* Identification */ 
	uchar	frag[2];	/* Fragment information */ 
	uchar	ttl;		/* Time to live */ 
	uchar	proto;		/* Protocol */ 
	uchar	cksum[2];	/* Header checksum */ 
	uchar	src[4];		/* Ip source */ 
	uchar	dst[4];		/* Ip destination */ 
}; 
 
/* Ethernet packet types */ 
#define ET_IP	0x0800 
 
/* A userlevel data gram */ 
1991/1012    
struct Udphdr 
{ 
1991/0424    
#define UDP_EHSIZE	22 
	uchar	d[6];		/* Ethernet destination */ 
	uchar	s[6];		/* Ethernet source */ 
	uchar	type[2];	/* Ethernet packet type */ 
1991/1024    
 
1991/0424    
	uchar	vihl;		/* Version and header length */ 
	uchar	tos;		/* Type of service */ 
	uchar	length[2];	/* packet length */ 
	uchar	id[2];		/* Identification */ 
	uchar	frag[2];	/* Fragment information */ 
 
	/* Udp pseudo ip really starts here */ 
#define UDP_PHDRSIZE	12 
#define UDP_HDRSIZE	20 
	uchar	Unused;	 
	uchar	udpproto;	/* Protocol */ 
	uchar	udpplen[2];	/* Header plus data length */ 
	uchar	udpsrc[4];	/* Ip source */ 
	uchar	udpdst[4];	/* Ip destination */ 
	uchar	udpsport[2];	/* Source port */ 
	uchar	udpdport[2];	/* Destination port */ 
	uchar	udplen[2];	/* data length */ 
	uchar	udpcksum[2];	/* Checksum */ 
}; 
 
1991/1012    
struct Ilhdr 
{ 
1991/1014    
#define IL_EHSIZE	34 
1991/1012    
	uchar	d[6];		/* Ethernet destination */ 
	uchar	s[6];		/* Ethernet source */ 
	uchar	type[2];	/* Ethernet packet type */ 
1991/1024    
 
1991/1012    
	uchar	vihl;		/* Version and header length */ 
	uchar	tos;		/* Type of service */ 
	uchar	length[2];	/* packet length */ 
	uchar	id[2];		/* Identification */ 
	uchar	frag[2];	/* Fragment information */ 
1991/1014    
	uchar	ttl;		/* Time to live */ 
	uchar	proto;		/* Protocol */ 
	uchar	cksum[2];	/* Header checksum */ 
	uchar	src[4];		/* Ip source */ 
	uchar	dst[4];		/* Ip destination */ 
1991/1019    
#define IL_HDRSIZE	18	 
1991/1012    
	uchar	ilsum[2];	/* Checksum including header */ 
	uchar	illen[2];	/* Packet length */ 
	uchar	iltype;		/* Packet type */ 
	uchar	ilspec;		/* Special */ 
	uchar	ilsrc[2];	/* Src port */ 
	uchar	ildst[2];	/* Dst port */ 
	uchar	ilid[4];	/* Sequence id */ 
	uchar	ilack[4];	/* Acked sequence */ 
}; 
 
1991/1014    
struct Ilcb				/* Control block */ 
1991/1012    
{ 
1991/1124    
	int	state;			/* Connection state */ 
 
	QLock	ackq;			/* Unacknowledged queue */ 
1991/1012    
	Block	*unacked; 
	Block	*unackedtail; 
1991/1124    
 
	QLock	outo;			/* Out of order packet queue */ 
1991/1012    
	Block	*outoforder; 
1991/1124    
	int	oblks;			/* Number of blocks in queue */ 
 
	ulong	next;			/* Id of next to send */ 
	ulong	recvd;			/* Last packet received */ 
	ulong	start;			/* Local start id */ 
	ulong	rstart;			/* Remote start id */ 
 
	int	timeout;		/* Time out counter */ 
	int	slowtime;		/* Slow time counter */ 
	int	fasttime;		/* Retransmission timer */ 
	int	acktime;		/* Acknowledge timer */ 
 
	int	rtt;			/* Average round trip time */ 
	ulong	rttack;			/* The ack we are waiting for */ 
	ulong	ackms;			/* Time we issued */ 
 
	int	window;			/* Maximum receive window */ 
1991/1012    
}; 
 
1991/1014    
enum					/* Packet types */ 
1991/1012    
{ 
	Ilsync, 
	Ildata, 
	Ildataquery, 
	Ilack, 
	Ilquerey, 
	Ilstate, 
1991/1101    
	Ilclose, 
1991/1012    
}; 
 
1991/1014    
enum					/* Connection state */ 
{ 
	Ilclosed, 
	Ilsyncer, 
	Ilsyncee, 
	Ilestablished, 
	Illistening, 
	Ilclosing, 
}; 
 
1991/0424    
#define TCP_PKT	(TCP_EHSIZE+TCP_IPLEN+TCP_PHDRSIZE) 
 
1991/1012    
struct Tcphdr 
{ 
1991/0424    
#define TCP_EHSIZE	14 
	uchar	d[6];		/* Ethernet destination */ 
	uchar	s[6];		/* Ethernet source */ 
	uchar	type[2];	/* Ethernet packet type */ 
#define TCP_IPLEN	8 
	uchar	vihl;		/* Version and header length */ 
	uchar	tos;		/* Type of service */ 
	uchar	length[2];	/* packet length */ 
	uchar	id[2];		/* Identification */ 
	uchar	frag[2];	/* Fragment information */ 
 
#define TCP_PHDRSIZE	12	 
	uchar	Unused; 
	uchar	proto; 
	uchar	tcplen[2]; 
	uchar	tcpsrc[4]; 
	uchar	tcpdst[4]; 
 
#define TCP_HDRSIZE	20 
	uchar	tcpsport[2]; 
	uchar	tcpdport[2]; 
	uchar	tcpseq[4]; 
	uchar	tcpack[4]; 
	uchar	tcpflag[2]; 
	uchar	tcpwin[2]; 
	uchar	tcpcksum[2]; 
	uchar	tcpurg[2]; 
 
	/* Options segment */ 
	uchar	tcpopt[2]; 
	uchar	tcpmss[2]; 
1991/1012    
}; 
1991/0424    
 
 
 
1991/1012    
struct Timer 
{ 
1991/0424    
	Timer	*next; 
	Timer	*prev; 
	int	state; 
	int	start; 
	int	count; 
	void	(*func)(void*); 
	void	*arg; 
1991/1012    
}; 
1991/0424    
 
1991/1012    
struct Tcpctl 
{ 
1991/0424    
	QLock; 
	uchar	state;		/* Connection state */ 
	uchar	type;		/* Listening or active connection */ 
	uchar	code;		/* Icmp code */		 
	struct { 
		int una;	/* Unacked data pointer */ 
		int nxt;	/* Next sequence expected */ 
		int ptr;	/* Data pointer */ 
		ushort wnd;	/* Tcp send window */ 
		int up;		/* Urgent data pointer */ 
		int wl1; 
		int wl2; 
	} snd; 
	int	iss; 
	ushort	cwind; 
	ushort	ssthresh; 
	int	resent; 
	struct { 
		int nxt; 
		ushort wnd; 
		int up; 
	} rcv; 
	int	irs; 
	ushort	mss; 
	int	rerecv; 
	ushort	window; 
	int	max_snd; 
	int	last_ack; 
	char	backoff; 
	char	flags; 
	char	tos; 
 
	Block	*rcvq; 
	ushort	rcvcnt; 
 
	Block	*sndq;			/* List of data going out */ 
	ushort	sndcnt;			/* Amount of data in send queue */ 
 
	Reseq	*reseq;			/* Resequencing queue */ 
	Timer	timer;			  
	Timer	acktimer;		/* Acknoledge timer */ 
	Timer	rtt_timer;		/* Round trip timer */ 
	int	rttseq;			/* Round trip sequence */ 
	int	srtt;			/* Shortened round trip */ 
	int	mdev;			/* Mean deviation of round trip */ 
}; 
 
1991/1012    
struct	Tcp 
{ 
1991/0424    
	Port	source; 
	Port	dest; 
	int	seq; 
	int	ack; 
	char	flags; 
	ushort	wnd; 
	ushort	up; 
	ushort	mss; 
1991/1012    
}; 
1991/0424    
 
1991/1012    
struct Reseq 
{ 
1991/0424    
	Reseq 	*next; 
	Tcp	seg; 
	Block	*bp; 
	ushort	length; 
	char	tos; 
1991/1012    
}; 
1991/0424    
 
1991/1104    
/* An ip interface used for UDP/TCP/IL */ 
1991/1012    
struct Ipconv 
{ 
1991/0424    
	QLock;				/* Ref count lock */ 
	int 	ref; 
1991/1115    
	int	index; 
1991/0424    
	Qinfo	*stproto;		/* Stream protocol for this device */ 
1991/1126    
	Network	*net;			/* user level network interface */ 
1991/0424    
	Ipaddr	dst;			/* Destination from connect */ 
	Port	psrc;			/* Source port */ 
	Port	pdst;			/* Destination port */ 
 
	Ipifc	*ipinterface;		/* Ip protocol interface */ 
	Queue	*readq;			/* Pointer to upstream read q */ 
	QLock	listenq;		/* List of people waiting incoming cons */ 
	Rendez	listenr;		/* Some where to sleep while waiting */ 
		 
	char	err;			/* Async protocol error */ 
	int	backlog;		/* Maximum number of waiting connections */ 
	int	curlog;			/* Number of waiting connections */ 
1991/1023    
	int 	newcon;			/* Flags that this is the start of a connection */ 
 
1991/1012    
	union { 
		Tcpctl	tcpctl;			/* Tcp control block */ 
		Ilcb	ilctl;			/* Il control block */ 
	}; 
1991/0424    
}; 
 
#define	MAX_TIME	100000000	/* Forever */ 
#define TCP_ACK		200		/* Timed ack sequence every 200ms */ 
 
#define URG	0x20 
#define ACK	0x10 
#define PSH	0x08 
#define RST	0x04 
#define SYN	0x02 
#define FIN	0x01 
 
#define EOL_KIND	0 
#define NOOP_KIND	1 
#define MSS_KIND	2 
 
#define MSS_LENGTH	4 
#define MSL2		10 
#define MSPTICK		200 
1991/1204    
#define DEF_MSS		512 
1991/0424    
#define DEF_RTT		1000 
#define	TCPOOB_HADDATA	1 
#define	TCPOOB_HAVEDATA 2 
 
#define TCP_PASSIVE	0 
#define TCP_ACTIVE	1 
1991/1014    
#define IL_PASSIVE	0 
#define IL_ACTIVE	1 
1991/0424    
 
#define MAXBACKOFF	5 
#define FORCE		1 
#define	CLONE		2 
#define RETRAN		4 
#define ACTIVE		8 
#define SYNACK		16 
#define AGAIN		8 
#define DGAIN		4 
 
#define TIMER_STOP	0 
#define TIMER_RUN	1 
#define TIMER_EXPIRE	2 
 
1991/0705    
#define Nreseq		64 
 
1991/0424    
#define	set_timer(t,x)	(((t)->start) = (x)/MSPTICK) 
#define	dur_timer(t)	((t)->start) 
#define	read_timer(t)	((t)->count) 
#define	run_timer(t)	((t)->state == TIMER_RUN) 
 
1991/1012    
enum 
{ 
1991/0424    
	CLOSED = 0, 
	LISTEN, 
	SYN_SENT, 
	SYN_RECEIVED, 
	ESTABLISHED, 
	FINWAIT1, 
	FINWAIT2, 
	CLOSE_WAIT, 
	CLOSING, 
	LAST_ACK, 
	TIME_WAIT 
1991/1012    
}; 
1991/0424    
 
/* 
 * Ip interface structure. We have one for each active protocol driver 
 */ 
1991/1012    
struct Ipifc  
{ 
1991/0424    
	QLock; 
	int 		ref; 
	uchar		protocol;		/* Ip header protocol number */ 
	char		name[NAMELEN];		/* Protocol name */ 
	void (*iprcv)	(Ipconv *, Block *);	/* Receive demultiplexor */ 
	Ipconv		*connections;		/* Connection list */ 
	int		maxmtu;			/* Maximum transfer unit */ 
	int		minmtu;			/* Minumum tranfer unit */ 
	int		hsize;			/* Media header size */	 
	Lock;	 
}; 
 
1991/1012    
struct Fragq 
{ 
1991/0424    
	QLock; 
	Block  *blist; 
	Fragq  *next; 
	Ipaddr src; 
	Ipaddr dst; 
	ushort id; 
1991/1012    
}; 
1991/0424    
 
1991/1012    
struct Ipfrag 
{ 
1991/0424    
	ushort	foff; 
	ushort	flen; 
1991/1012    
}; 
1991/0424    
 
#define IP_VER	0x40			/* Using IP version 4 */ 
#define IP_HLEN 0x05			/* Header length in characters */ 
#define IP_DF	0x4000			/* Don't fragment */ 
#define IP_MF	0x2000			/* More fragments */ 
 
#define	ICMP_ECHOREPLY		0	/* Echo Reply */ 
#define	ICMP_UNREACH		3	/* Destination Unreachable */ 
#define	ICMP_SOURCEQUENCH	4	/* Source Quench */ 
#define	ICMP_REDIRECT		5	/* Redirect */ 
#define	ICMP_ECHO		8	/* Echo Request */ 
#define	ICMP_TIMXCEED		11	/* Time-to-live Exceeded */ 
#define	ICMP_PARAMPROB		12	/* Parameter Problem */ 
#define	ICMP_TSTAMP		13	/* Timestamp */ 
#define	ICMP_TSTAMPREPLY	14	/* Timestamp Reply */ 
#define	ICMP_IREQ		15	/* Information Request */ 
#define	ICMP_IREQREPLY		16	/* Information Reply */ 
 
/* Sizes */ 
1991/1124    
#define IP_MAX		(32*1024)		/* Maximum Internet packet size */ 
1991/0424    
#define UDP_MAX		(IP_MAX-ETHER_IPHDR)	/* Maximum UDP datagram size */ 
#define UDP_DATMAX	(UDP_MAX-UDP_HDRSIZE)	/* Maximum amount of udp data */ 
1991/1012    
#define IL_DATMAX	(IP_MAX-IL_HDRSIZE)	/* Maximum IL data in one ip packet */ 
1991/0424    
 
/* Protocol numbers */ 
#define IP_UDPPROTO	17 
#define IP_TCPPROTO	6 
1991/1012    
#define	IP_ILPROTO	190		/* I have no idea */ 
1991/0424    
 
/* Protocol port numbers */ 
#define PORTALLOC	5000		/* First automatic allocated port */ 
#define PRIVPORTALLOC	600		/* First priveleged port allocated */ 
#define PORTMAX		30000		/* Last port to allocte */ 
 
/* Stuff to go in funs.h someday */ 
Ipifc   *newipifc(uchar, void (*)(Ipconv *, Block*), Ipconv *, int, int, int, char*); 
void	closeipifc(Ipifc*); 
ushort	ip_csum(uchar*); 
int	arp_lookup(uchar*, uchar*); 
Ipaddr	ipparse(char*); 
void	hnputs(uchar*, ushort); 
void	hnputl(uchar*, ulong); 
ulong	nhgetl(uchar*); 
ushort	nhgets(uchar*); 
ushort	ptcl_csum(Block*bp, int, int); 
void	ppkt(Block*); 
void	udprcvmsg(Ipconv *, Block*); 
Block	*btrim(Block*, int, int); 
Block	*ip_reassemble(int, Block*, Etherhdr*); 
Ipconv	*portused(Ipconv *, Port); 
Port	nextport(Ipconv *, Port); 
Fragq   *ipfragallo(void); 
void	ipfragfree(Fragq*); 
void	iproute(uchar*, uchar*); 
void	initfrag(int); 
int	ntohtcp(Tcp*, Block**); 
void	reset(Ipaddr, Ipaddr, char, ushort, Tcp*); 
void	proc_syn(Ipconv*, char, Tcp*); 
void	send_syn(Tcpctl*); 
void	tcp_output(Ipconv*); 
int	seq_within(int, int, int); 
void	update(Ipconv *, Tcp *); 
int	trim(Tcpctl *, Tcp *, Block **, ushort *); 
void	add_reseq(Tcpctl *, char, Tcp *, Block *, ushort); 
void	close_self(Ipconv *, int); 
int	seq_gt(int, int); 
Ipconv	*ip_conn(Ipconv *, Port, Port, Ipaddr dest, char proto); 
void	ipmkdir(Qinfo *, Dirtab *, Ipconv *); 
1991/1115    
Ipconv	*ipincoming(Ipconv*, Ipconv*); 
1991/0424    
int	inb_window(Tcpctl *, int); 
Block	*htontcp(Tcp *, Block *, Tcphdr *); 
void	start_timer(Timer *); 
void	stop_timer(Timer *); 
int	copyupb(Block **, uchar *, int); 
void	init_tcpctl(Ipconv *); 
void	close_self(Ipconv *, int); 
int	iss(void); 
int	seq_within(int, int, int); 
int	seq_lt(int, int); 
int	seq_le(int, int); 
int	seq_gt(int, int); 
int	seq_ge(int, int); 
void	setstate(Ipconv *, char); 
void	tcpackproc(void*); 
Block 	*htontcp(Tcp *, Block *, Tcphdr *); 
int	ntohtcp(Tcp *, Block **); 
void	extract_oob(Block **, Block **, Tcp *); 
void	get_reseq(Tcpctl *, char *, Tcp *, Block **, ushort *); 
void	state_upcall(Ipconv*, char oldstate, char newstate); 
int	backoff(int); 
int	dupb(Block **, Block *, int, int); 
void	tcp_input(Ipconv *, Block *); 
void 	tcprcvwin(Ipconv *); 
1991/1014    
void	tcpstart(Ipconv *, int, ushort, char); 
1991/1015    
void	ilstart(Ipconv *, int, int); 
1991/0424    
void	tcpflow(void*); 
void 	tcp_timeout(void *); 
void	tcp_acktimer(void *); 
1991/1114    
int	ipclonecon(Chan *); 
int	iplisten(Chan *); 
1991/1025    
void	iloutoforder(Ipconv*, Ilhdr*, Block*); 
1991/1114    
void	iplocalfill(Chan*, char*, int); 
void	ipremotefill(Chan*, char*, int); 
void	ipstatusfill(Chan*, char*, int); 
1991/1126    
int	ipforme(uchar*); 
1991/0424    
 
#define	fmtaddr(xx)	(xx>>24)&0xff,(xx>>16)&0xff,(xx>>8)&0xff,xx&0xff 
#define	MIN(a, b)	((a) < (b) ? (a) : (b)) 
#define MAX(a, b)	((a) > (b) ? (a) : (b)) 
#define BLKIP(xp)	((Etherhdr *)((xp)->rptr)) 
#define BLKFRAG(xp)	((Ipfrag *)((xp)->rptr)) 
#define PREC(x)		((x)>>5 & 7) 
 
#define WORKBUF		64 
 
extern Ipaddr Myip; 
extern Ipaddr Mymask; 
extern Ipaddr classmask[4]; 
extern Ipconv *ipconv[]; 
extern char *tcpstate[]; 
1991/1015    
extern char *ilstate[]; 
1991/0424    
extern Rendez tcpflowr; 
extern Qinfo tcpinfo; 
extern Qinfo ipinfo; 
extern Qinfo udpinfo; 
1991/1012    
extern Qinfo ilinfo; 
1991/1029    
extern Qinfo arpinfo; 
1991/1019    
extern Queue *Ipoutput; 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)