vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

ip.h (3281B)


      1 
      2 enum 
      3 {
      4 	IPaddrlen=	16,
      5 	IPv4addrlen=	4,
      6 	IPv4off=	12,
      7 	IPllen=		4,
      8 	IPV4HDR_LEN=	20,
      9 
     10 	/* vihl & vcf[0] values */
     11 	IP_VER4= 	0x40,
     12 	IP_VER6=	0x60,
     13 };
     14 
     15 #define ISIPV6MCAST(addr)	((addr)[0] == 0xff)
     16 #define ISIPV6LINKLOCAL(addr) ((addr)[0] == 0xfe && ((addr)[1] & 0xc0) == 0x80)
     17 
     18 /*
     19  * ipv6 constants
     20  * `ra' is `router advertisement', `rs' is `router solicitation'.
     21  * `na' is `neighbour advertisement'.
     22  */
     23 enum {
     24 	IPV6HDR_LEN	= 40,
     25 
     26 	/* neighbour discovery option types */
     27 	V6nd_srclladdr	= 1,
     28 	V6nd_targlladdr	= 2,
     29 	V6nd_pfxinfo	= 3,
     30 	V6nd_redirhdr	= 4,
     31 	V6nd_mtu	= 5,
     32 	/* new since rfc2461; see iana.org/assignments/icmpv6-parameters */
     33 	V6nd_home	= 8,
     34 	V6nd_srcaddrs	= 9,		/* rfc3122 */
     35 	V6nd_ip		= 17,
     36 	/* /lib/rfc/drafts/draft-jeong-dnsop-ipv6-dns-discovery-12.txt */
     37 	V6nd_rdns	= 25,
     38 	/* plan 9 extensions */
     39 	V6nd_9fs	= 250,
     40 	V6nd_9auth	= 251,
     41 
     42 	/* Router constants (all times in ms.) */
     43 	Maxv6initraintvl= 16000,
     44 	Maxv6initras	= 3,
     45 	Maxv6finalras	= 3,
     46 	Minv6interradelay= 3000,
     47 	Maxv6radelay	= 500,
     48 
     49 	/* Host constants */
     50 	Maxv6rsdelay	= 1000,
     51 	V6rsintvl	= 4000,
     52 	Maxv6rss	= 3,
     53 
     54 	/* Node constants */
     55 	Maxv6mcastrss	= 3,
     56 	Maxv6unicastrss	= 3,
     57 	Maxv6anycastdelay= 1000,
     58 	Maxv6na		= 3,
     59 	V6reachabletime	= 30000,
     60 	V6retranstimer	= 1000,
     61 	V6initprobedelay= 5000,
     62 };
     63 
     64 /* V6 header on the wire */
     65 typedef struct Ip6hdr Ip6hdr;
     66 struct Ip6hdr {
     67 	uchar	vcf[4];		/* version:4, traffic class:8, flow label:20 */
     68 	uchar	ploadlen[2];	/* payload length: packet length - 40 */
     69 	uchar	proto;		/* next header type */
     70 	uchar	ttl;		/* hop limit */
     71 	uchar	src[IPaddrlen];	/* source address */
     72 	uchar	dst[IPaddrlen];	/* destination address */
     73 	uchar	payload[];
     74 };
     75 
     76 /*
     77  *  user-level icmpv6 with control message "headers"
     78  */
     79 typedef struct Icmp6hdr Icmp6hdr;
     80 struct Icmp6hdr {
     81 	uchar	_0_[8];
     82 	uchar	laddr[IPaddrlen];	/* local address */
     83 	uchar	raddr[IPaddrlen];	/* remote address */
     84 };
     85 
     86 /*
     87  *  user level udp headers with control message "headers"
     88  */
     89 enum 
     90 {
     91 	Udphdrsize=	52,	/* size of a Udphdr */
     92 };
     93 
     94 typedef struct Udphdr Udphdr;
     95 struct Udphdr
     96 {
     97 	uchar	raddr[IPaddrlen];	/* V6 remote address */
     98 	uchar	laddr[IPaddrlen];	/* V6 local address */
     99 	uchar	ifcaddr[IPaddrlen];	/* V6 ifc addr msg was received on */
    100 	uchar	rport[2];		/* remote port */
    101 	uchar	lport[2];		/* local port */
    102 };
    103 
    104 uchar*	defmask(uchar*);
    105 void	maskip(uchar*, uchar*, uchar*);
    106 int	eipfmt(Fmt*);
    107 int	isv4(uchar*);
    108 vlong	parseip(uchar*, char*);
    109 vlong	parseipmask(uchar*, char*);
    110 char*	v4parseip(uchar*, char*);
    111 char*	v4parsecidr(uchar*, uchar*, char*);
    112 int	parseether(uchar*, char*);
    113 int	myipaddr(uchar*, char*);
    114 int	myetheraddr(uchar*, char*);
    115 int	equivip4(uchar*, uchar*);
    116 int	equivip6(uchar*, uchar*);
    117 
    118 void	hnputv(void*, uvlong);
    119 void	hnputl(void*, uint);
    120 void	hnputs(void*, ushort);
    121 uvlong	nhgetv(void*);
    122 uint	nhgetl(void*);
    123 ushort	nhgets(void*);
    124 ushort	ptclbsum(uchar*, int);
    125 
    126 int	v6tov4(uchar*, uchar*);
    127 void	v4tov6(uchar*, uchar*);
    128 
    129 #define	ipcmp(x, y) memcmp(x, y, IPaddrlen)
    130 #define	ipmove(x, y) memmove(x, y, IPaddrlen)
    131 
    132 extern uchar IPv4bcast[IPaddrlen];
    133 extern uchar IPv4bcastobs[IPaddrlen];
    134 extern uchar IPv4allsys[IPaddrlen];
    135 extern uchar IPv4allrouter[IPaddrlen];
    136 extern uchar IPnoaddr[IPaddrlen];
    137 extern uchar v4prefix[IPaddrlen];
    138 extern uchar IPallbits[IPaddrlen];
    139 
    140 #define CLASS(p) ((*(uchar*)(p))>>6)
    141