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

1993/0220/port/ipdat.h (diff list | history)

port/ipdat.h on 1992/0625
1992/0625    
typedef struct Etherhdr	Etherhdr; 
1991/0424    
typedef struct Fragq	Fragq; 
1992/0625    
typedef struct Ilcb	Ilcb; 
typedef struct Ilhdr	Ilhdr; 
1991/0424    
typedef ulong		Ipaddr; 
1992/0625    
typedef struct Ipconv	Ipconv; 
typedef struct Ipfrag	Ipfrag; 
typedef struct Ipifc	Ipifc; 
1991/0424    
typedef ushort		Port; 
typedef struct Reseq	Reseq; 
typedef struct Tcp	Tcp; 
typedef struct Tcpctl	Tcpctl; 
typedef struct Tcphdr	Tcphdr; 
typedef struct Timer	Timer; 
1992/0625    
typedef struct Udphdr	Udphdr; 
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 
 
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 */ 
}; 
 
1992/0625    
struct Ilcb			/* Control block */ 
1991/1012    
{ 
1992/0625    
	int	state;		/* Connection state */ 
1991/1124    
 
1992/0625    
	Rendez	syncer;		/* where syncer waits for a connect */ 
1992/0303    
 
1992/0625    
	QLock	ackq;		/* Unacknowledged queue */ 
1991/1012    
	Block	*unacked; 
	Block	*unackedtail; 
1991/1124    
 
1992/0625    
	QLock	outo;		/* Out of order packet queue */ 
1991/1012    
	Block	*outoforder; 
1991/1124    
 
1992/0103    
	Lock	nxl; 
1992/0625    
	ulong	next;		/* Id of next to send */ 
	ulong	recvd;		/* Last packet received */ 
	ulong	start;		/* Local start id */ 
	ulong	rstart;		/* Remote start id */ 
1991/1124    
 
1992/0625    
	int	timeout;	/* Time out counter */ 
	int	slowtime;	/* Slow time counter */ 
	int	fasttime;	/* Retransmission timer */ 
	int	acktime;	/* Acknowledge timer */ 
	int	querytime;	/* Query timer */ 
	int	deathtime;	/* Time to kill connection */ 
1991/1124    
 
1992/0625    
	int	rtt;		/* Average round trip time */ 
	ulong	rttack;		/* The ack we are waiting for */ 
	ulong	ackms;		/* Time we issued */ 
1991/1124    
 
1992/0625    
	int	window;		/* Maximum receive window */ 
1991/1012    
}; 
 
1992/0625    
enum				/* Packet types */ 
1991/1012    
{ 
	Ilsync, 
	Ildata, 
	Ildataquery, 
	Ilack, 
	Ilquerey, 
	Ilstate, 
1991/1101    
	Ilclose, 
1991/1012    
}; 
 
1992/0625    
enum				/* Connection state */ 
1991/1014    
{ 
	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    
 
1992/0906    
enum 
{ 
	TimerOFF	= 0, 
	TimerON		= 1, 
	TimerDONE	= 2, 
}; 
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    
 
1992/0128    
struct Tctl 
1991/1012    
{ 
1992/0906    
	uchar	state;			/* Connection state */ 
	uchar	type;			/* Listening or active connection */ 
	uchar	code;			/* Icmp code */		 
1991/0424    
	struct { 
1993/0220    
		ulong	una;		/* Unacked data pointer */ 
		ulong	nxt;		/* Next sequence expected */ 
		ulong	ptr;		/* Data pointer */ 
1992/0906    
		ushort	wnd;		/* Tcp send window */ 
1993/0220    
		ulong	up;		/* Urgent data pointer */ 
		ulong	wl1; 
		ulong	wl2; 
1991/0424    
	} snd; 
1992/0625    
	struct { 
1993/0218    
		ulong	nxt;		/* Receive pointer to next byte slot */ 
1992/0906    
		ushort	wnd;		/* Receive window incoming */ 
1993/0220    
		ulong	up;		/* Urgent pointer */ 
1992/0625    
	} rcv; 
1993/0220    
	ulong	iss;			/* Initial sequence number */ 
1992/0906    
	ushort	cwind;			/* Congestion window */ 
	ushort	ssthresh;		/* Slow start threshold */ 
	int	resent;			/* Bytes just resent */ 
	int	irs;			/* Initial received squence */ 
	ushort	mss;			/* Mean segment size */ 
	int	rerecv;			/* Overlap of data rerecevived */ 
	ushort	window;			/* Recevive window */ 
	int	max_snd;		/* Max send */ 
1993/0218    
	ulong	last_ack;		/* Last acknowledege received */ 
1992/0906    
	char	backoff;		/* Exponential backoff counter */ 
	char	flags;			/* State flags */ 
	char	tos;			/* Type of service */ 
1991/0424    
 
1992/0906    
	Blist	rcvq;			/* Received data */ 
	ulong	rcvcnt;			/* Bytes queued for upstream */ 
1991/0424    
 
1992/0906    
	Block	*sndq;			/* List of data going out */ 
	ulong	sndcnt;			/* Amount of data in send queue */ 
1992/1221    
	Rendez	sndr;			/* process flow control */ 
	QLock	sndrlock; 
	int	sndfull; 
1991/0424    
 
1992/0906    
	Reseq	*reseq;			/* Resequencing queue */ 
	Timer	timer;			/* Activity timer */ 
	Timer	acktimer;		/* Acknoledge timer */ 
	Timer	rtt_timer;		/* Round trip timer */ 
1993/0220    
	ulong	rttseq;			/* Round trip sequence */ 
1992/0906    
	int	srtt;			/* Shortened round trip */ 
	int	mdev;			/* Mean deviation of round trip */ 
1991/0424    
}; 
1992/0310    
 
1992/0128    
struct Tcpctl 
{ 
	QLock; 
1992/0303    
	Rendez syner; 
1992/0416    
	struct Tctl; 
1992/0128    
}; 
1991/0424    
 
1991/1012    
struct	Tcp 
{ 
1991/0424    
	Port	source; 
	Port	dest; 
1993/0220    
	ulong	seq; 
	ulong	ack; 
1991/0424    
	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 
{ 
1992/0906    
	QLock;				/* Ref count lock */ 
	Netprot;			/* stat info */ 
1991/0424    
	int 	ref; 
1992/0906    
	Ipaddr	dst;			/* Destination from connect */ 
	Port	psrc;			/* Source port */ 
	Port	pdst;			/* Destination port */ 
1991/0424    
 
1992/0906    
	Ipifc	*ifc;			/* 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 */ 
1991/0424    
		 
1992/0906    
	char	*err;			/* Async protocol error */ 
	int	backlog;		/* Maximum number of waiting connections */ 
	int	headers;		/* include header in packet */ 
	int	curlog;			/* Number of waiting connections */ 
	Ipconv 	*newcon;		/* This is the start of a connection */ 
1991/1023    
 
1991/1012    
	union { 
1992/0906    
		Tcpctl	tcpctl;		/* Tcp control block */ 
		Ilcb	ilctl;		/* Il control block */ 
1991/1012    
	}; 
1991/0424    
}; 
 
1992/0906    
enum 
{ 
	MAX_TIME 	= (1<<20),	/* Forever */ 
1993/0218    
	TCP_ACK		= 50,		/* Timed ack sequence in ms */ 
1991/0424    
 
1992/0906    
	URG		= 0x20,		/* Data marked urgent */ 
	ACK		= 0x10,		/* Aknowledge is valid */ 
	PSH		= 0x08,		/* Whole data pipe is pushed */ 
	RST		= 0x04,		/* Reset connection */ 
	SYN		= 0x02,		/* Pkt. is synchronise */ 
	FIN		= 0x01,		/* Start close down */ 
1991/0424    
 
1992/0625    
	EOL_KIND	= 0, 
	NOOP_KIND	= 1, 
	MSS_KIND	= 2, 
1991/0424    
 
1992/0906    
	MSS_LENGTH	= 4,		/* Mean segment size */ 
1992/0625    
	MSL2		= 10, 
1993/0218    
	MSPTICK		= 50,		/* Milliseconds per timer tick */ 
1992/0906    
	DEF_MSS		= 1024,		/* Default mean segment */ 
	DEF_RTT		= 1000,		/* Default round trip */ 
1991/0424    
 
1992/0906    
	TCP_PASSIVE	= 0,		/* Listen connection */ 
	TCP_ACTIVE	= 1,		/* Outgoing connection */ 
1992/0625    
	IL_PASSIVE	= 0, 
	IL_ACTIVE	= 1, 
1991/0424    
 
1992/0625    
	MAXBACKOFF	= 5, 
	FORCE		= 1, 
	CLONE		= 2, 
	RETRAN		= 4, 
	ACTIVE		= 8, 
	SYNACK		= 16, 
	AGAIN		= 8, 
	DGAIN		= 4, 
}; 
1991/0424    
 
#define	set_timer(t,x)	(((t)->start) = (x)/MSPTICK) 
1992/0906    
#define	run_timer(t)	((t)->state == TimerON) 
1991/0424    
 
1992/0906    
enum					/* Tcp connection states */ 
1991/1012    
{ 
1992/0625    
	Closed		= 0, 
1991/12171    
	Listen, 
	Syn_sent, 
	Syn_received, 
	Established, 
	Finwait1, 
	Finwait2, 
	Close_wait, 
	Closing, 
	Last_ack, 
	Time_wait 
1991/1012    
}; 
1991/0424    
 
1992/0626    
enum 
{ 
	Nipconv=	512,		/* max conversations per interface */ 
1992/0627    
	Udphdrsize=	6,		/* size if a to/from user Udp header */ 
1992/0626    
}; 
 
1991/0424    
/* 
 * Ip interface structure. We have one for each active protocol driver 
 */ 
1991/1012    
struct Ipifc  
{ 
1991/0424    
	QLock; 
1992/0626    
	Network;				/* user level network interface */ 
	Ipifc		*next; 
	int 		inited; 
1991/0424    
	uchar		protocol;		/* Ip header protocol number */ 
1992/0626    
	void (*iprcv)	(Ipifc*, Block*);	/* Receive demultiplexor */ 
1991/0424    
	int		maxmtu;			/* Maximum transfer unit */ 
	int		minmtu;			/* Minumum tranfer unit */ 
	int		hsize;			/* Media header size */	 
1992/0307    
	ulong		chkerrs;		/* checksum errors */ 
1992/0626    
	Ipconv		**conv;			/* conversations */ 
1991/0424    
}; 
 
1992/0626    
 
1991/1012    
struct Fragq 
{ 
1991/0424    
	QLock; 
	Block  *blist; 
	Fragq  *next; 
	Ipaddr src; 
	Ipaddr dst; 
	ushort id; 
1991/1216    
	ulong  age; 
1991/1012    
}; 
1991/0424    
 
1991/1012    
struct Ipfrag 
{ 
1991/0424    
	ushort	foff; 
	ushort	flen; 
1991/1012    
}; 
1991/0424    
 
1992/0625    
enum { 
	IP_VER		= 0x40,			/* Using IP version 4 */ 
	IP_HLEN		= 0x05,			/* Header length in characters */ 
	IP_DF		= 0x4000,		/* Don't fragment */ 
	IP_MF		= 0x2000,		/* More fragments */ 
1991/0424    
 
1992/0625    
	/* Sizes */ 
	IP_MAX		= (32*1024),		/* Maximum Internet packet size */ 
	UDP_MAX		= (IP_MAX-ETHER_IPHDR),	/* Maximum UDP datagram size */ 
	UDP_DATMAX	= (UDP_MAX-UDP_HDRSIZE),/* Maximum amount of udp data */ 
	IL_DATMAX	= (IP_MAX-IL_HDRSIZE),	/* Maximum IL data in one ip packet */ 
1991/0424    
 
1992/0625    
	/* Protocol numbers */ 
	IP_UDPPROTO	= 17, 
	IP_TCPPROTO	= 6, 
	IP_ILPROTO	= 40, 
1991/0424    
 
1992/0625    
	/* Protocol port numbers */ 
	PORTALLOC	= 5000,			/* First automatic allocated port */ 
	PRIVPORTALLOC	= 600,			/* First priveleged port allocated */ 
1992/12051    
	UNPRIVPORTALLOC	= 1024,			/* First unpriveleged port allocated */ 
1992/0625    
	PORTMAX		= 30000,		/* Last port to allocte */ 
}; 
1991/0424    
 
1992/0625    
void	add_reseq(Tcpctl *, char, Tcp *, Block *, ushort); 
int	arp_lookup(uchar*, uchar*); 
int	backoff(int); 
Block*	btrim(Block*, int, int); 
1992/0826    
void	localclose(Ipconv *, char []); 
1992/0625    
int	dupb(Block **, Block *, int, int); 
void	extract_oob(Block **, Block **, Tcp *); 
void	get_reseq(Tcpctl *, char *, Tcp *, Block **, ushort *); 
void	hnputl(uchar*, ulong); 
void	hnputs(uchar*, ushort); 
Block*	htontcp(Tcp *, Block *, Tcphdr *); 
Block*	htontcp(Tcp *, Block *, Tcphdr *); 
void	iloutoforder(Ipconv*, Ilhdr*, Block*); 
void	ilstart(Ipconv *, int, int); 
int	inb_window(Tcpctl *, int); 
void	init_tcpctl(Ipconv *); 
void	initfrag(int); 
1992/0711    
void	initipifc(Ipifc*, uchar, void (*)(Ipifc*, Block*), int, int, int); 
Ipconv*	ip_conn(Ipifc*, Port, Port, Ipaddr dest); 
1991/0424    
ushort	ip_csum(uchar*); 
1992/0625    
Block*	ip_reassemble(int, Block*, Etherhdr*); 
int	ipclonecon(Chan *); 
int	ipconbusy(Ipconv*); 
1992/0626    
Ipconv*	ipcreateconv(Ipifc*, int); 
1992/0625    
int	ipforme(uchar*); 
Fragq*	ipfragallo(void); 
void	ipfragfree(Fragq*, int); 
1992/0626    
Ipconv*	ipincoming(Ipifc*, Ipconv*); 
1992/0625    
int	iplisten(Chan *); 
void	iplocalfill(Chan*, char*, int); 
void	ipmkdir(Qinfo *, Dirtab *, Ipconv *); 
1991/0424    
Ipaddr	ipparse(char*); 
1992/0625    
void	ipremotefill(Chan*, char*, int); 
void	iproute(uchar*, uchar*); 
void	ipsetaddrs(void); 
void	ipstatusfill(Chan*, char*, int); 
1992/0626    
Port	nextport(Ipifc*, int); 
1991/0424    
ushort	nhgets(uchar*); 
1992/0626    
ulong	nhgetl(uchar*); 
1992/0625    
int	ntohtcp(Tcp *, Block **); 
1991/0424    
int	ntohtcp(Tcp*, Block**); 
1992/0626    
Ipconv*	portused(Ipifc*, Port); 
1992/0625    
void	ppkt(Block*); 
1991/0424    
void	proc_syn(Ipconv*, char, Tcp*); 
1992/0625    
ushort	ptcl_csum(Block*bp, int, int); 
int	pullb(Block **, int); 
void	reset(Ipaddr, Ipaddr, char, ushort, Tcp*); 
1992/0903    
void	tcpsndsyn(Tcpctl*); 
1993/0220    
int	seq_ge(ulong, ulong); 
int	seq_gt(ulong, ulong); 
int	seq_gt(ulong, ulong); 
int	seq_le(ulong, ulong); 
int	seq_lt(ulong, ulong); 
int	seq_within(ulong, ulong, ulong); 
int	seq_within(ulong, ulong, ulong); 
1992/0903    
void	tcpsetstate(Ipconv *, char); 
void	tcpgo(Timer *); 
void	tcphalt(Timer *); 
void	tcpxstate(Ipconv*, char oldstate, char newstate); 
void	tcpacktimer(void *); 
void	tcpinput(Ipifc*, Block *); 
void	tcpoutput(Ipconv*); 
void	tcptimeout(void *); 
1992/0625    
void	tcpackproc(void*); 
1991/0424    
void	tcpflow(void*); 
1992/0416    
void	tcpflushincoming(Ipconv*); 
1992/0625    
void	tcprcvwin(Ipconv *); 
void	tcpstart(Ipconv *, int, ushort, char); 
int	trim(Tcpctl *, Tcp *, Block **, ushort *); 
1992/0626    
void	udprcvmsg(Ipifc*, Block*); 
1992/0625    
void	update(Ipconv *, Tcp *); 
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)) 
1992/0130    
#define BLKFRAG(xp)	((Ipfrag *)((xp)->base)) 
1991/0424    
#define PREC(x)		((x)>>5 & 7) 
 
1992/0214    
extern Ipaddr Myip[7]; 
1991/0424    
extern Ipaddr Mymask; 
1992/0304    
extern Ipaddr Mynetmask; 
1991/0424    
extern Ipaddr classmask[4]; 
1992/0626    
extern Ipifc *ipifc[]; 
1991/0424    
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; 
1992/0213    
 
/* offsets into Myip */ 
1992/0313    
enum 
{ 
1992/0625    
	Myself		= 0, 
	Mybcast		= 1, 
	Mynet		= 3, 
	Mysubnet	= 5, 
1992/0213    
}; 


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