1
0

ip.h 4.3 KB

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