ip.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. typedef struct Conv Conv;
  10. typedef struct Fragment4 Fragment4;
  11. typedef struct Fragment6 Fragment6;
  12. typedef struct Fs Fs;
  13. typedef union Hwaddr Hwaddr;
  14. typedef struct IP IP;
  15. typedef struct IPaux IPaux;
  16. typedef struct Ip4hdr Ip4hdr;
  17. typedef struct Ipfrag Ipfrag;
  18. typedef struct Ipself Ipself;
  19. typedef struct Ipselftab Ipselftab;
  20. typedef struct Iplink Iplink;
  21. typedef struct Iplifc Iplifc;
  22. typedef struct Ipmulti Ipmulti;
  23. typedef struct Ipifc Ipifc;
  24. typedef struct Iphash Iphash;
  25. typedef struct Ipht Ipht;
  26. typedef struct Netlog Netlog;
  27. typedef struct Medium Medium;
  28. typedef struct Proto Proto;
  29. typedef struct Arpent Arpent;
  30. typedef struct Arp Arp;
  31. typedef struct Route Route;
  32. typedef struct Routerparams Routerparams;
  33. typedef struct Hostparams Hostparams;
  34. typedef struct v6router v6router;
  35. typedef struct v6params v6params;
  36. #pragma incomplete Arp
  37. #pragma incomplete Ipself
  38. #pragma incomplete Ipselftab
  39. #pragma incomplete IP
  40. #pragma incomplete Netlog
  41. enum
  42. {
  43. Addrlen= 64,
  44. Maxproto= 20,
  45. Nhash= 64,
  46. Maxincall= 64, /* max. conn.s in listen q not accepted yet */
  47. Nchans= 1024,
  48. MAClen= 16, /* int32_test mac address */
  49. MAXTTL= 255,
  50. DFLTTOS= 0,
  51. IPaddrlen= 16,
  52. IPv4addrlen= 4,
  53. IPv4off= 12,
  54. IPllen= 4,
  55. /* ip versions */
  56. V4= 4,
  57. V6= 6,
  58. IP_VER4= 0x40,
  59. IP_VER6= 0x60,
  60. IP_HLEN4= 5, /* v4: Header length in words */
  61. IP_DF= 0x4000, /* v4: Don't fragment */
  62. IP_MF= 0x2000, /* v4: More fragments */
  63. IP4HDR= 20, /* sizeof(Ip4hdr) */
  64. IP_MAX= 64*1024, /* Max. Internet packet size, v4 & v6 */
  65. /* 2^Lroot trees in the root table */
  66. Lroot= 10,
  67. Maxpath = 64,
  68. };
  69. enum
  70. {
  71. Idle= 0,
  72. Announcing= 1,
  73. Announced= 2,
  74. Connecting= 3,
  75. Connected= 4,
  76. };
  77. /* MIB II counters */
  78. enum
  79. {
  80. Forwarding,
  81. DefaultTTL,
  82. InReceives,
  83. InHdrErrors,
  84. InAddrErrors,
  85. ForwDatagrams,
  86. InUnknownProtos,
  87. InDiscards,
  88. InDelivers,
  89. OutRequests,
  90. OutDiscards,
  91. OutNoRoutes,
  92. ReasmTimeout,
  93. ReasmReqds,
  94. ReasmOKs,
  95. ReasmFails,
  96. FragOKs,
  97. FragFails,
  98. FragCreates,
  99. Nipstats,
  100. };
  101. struct Fragment4
  102. {
  103. Block* blist;
  104. Fragment4* next;
  105. uint32_t src;
  106. uint32_t dst;
  107. uint16_t id;
  108. uint32_t age;
  109. };
  110. struct Fragment6
  111. {
  112. Block* blist;
  113. Fragment6* next;
  114. uint8_t src[IPaddrlen];
  115. uint8_t dst[IPaddrlen];
  116. uint id;
  117. uint32_t age;
  118. };
  119. struct Ipfrag
  120. {
  121. uint16_t foff;
  122. uint16_t flen;
  123. uint8_t payload[];
  124. };
  125. #define IPFRAGSZ offsetof(Ipfrag, payload[0])
  126. /* an instance of IP */
  127. struct IP
  128. {
  129. uint64_t stats[Nipstats];
  130. QLock fraglock4;
  131. Fragment4* flisthead4;
  132. Fragment4* fragfree4;
  133. Ref id4;
  134. QLock fraglock6;
  135. Fragment6* flisthead6;
  136. Fragment6* fragfree6;
  137. Ref id6;
  138. int iprouting; /* true if we route like a gateway */
  139. };
  140. /* on the wire packet header */
  141. struct Ip4hdr
  142. {
  143. uint8_t vihl; /* Version and header length */
  144. uint8_t tos; /* Type of service */
  145. uint8_t length[2]; /* packet length */
  146. uint8_t id[2]; /* ip->identification */
  147. uint8_t frag[2]; /* Fragment information */
  148. uint8_t ttl; /* Time to live */
  149. uint8_t proto; /* Protocol */
  150. uint8_t cksum[2]; /* Header checksum */
  151. uint8_t src[4]; /* IP source */
  152. uint8_t dst[4]; /* IP destination */
  153. };
  154. /*
  155. * one per conversation directory
  156. */
  157. struct Conv
  158. {
  159. QLock ql;
  160. int x; /* conversation index */
  161. Proto* p;
  162. int restricted; /* remote port is restricted */
  163. uint ttl; /* max time to live */
  164. uint tos; /* type of service */
  165. int ignoreadvice; /* don't terminate connection on icmp errors */
  166. uint8_t ipversion;
  167. uint8_t laddr[IPaddrlen]; /* local IP address */
  168. uint8_t raddr[IPaddrlen]; /* remote IP address */
  169. uint16_t lport; /* local port number */
  170. uint16_t rport; /* remote port number */
  171. char *owner; /* protections */
  172. int perm;
  173. int inuse; /* opens of listen/data/ctl */
  174. int length;
  175. int state;
  176. int maxfragsize; /* If set, used for fragmentation */
  177. /* udp specific */
  178. int headers; /* data src/dst headers in udp */
  179. int reliable; /* true if reliable udp */
  180. Conv* incall; /* calls waiting to be listened for */
  181. Conv* next;
  182. Queue* rq; /* queued data waiting to be read */
  183. Queue* wq; /* queued data waiting to be written */
  184. Queue* eq; /* returned error packets */
  185. Queue* sq; /* snooping queue */
  186. Ref snoopers; /* number of processes with snoop open */
  187. QLock car;
  188. Rendez cr;
  189. char cerr[ERRMAX];
  190. QLock listenq;
  191. Rendez listenr;
  192. Ipmulti *multi; /* multicast bindings for this interface */
  193. void* ptcl; /* protocol specific stuff */
  194. Route *r; /* last route used */
  195. uint32_t rgen; /* routetable generation for *r */
  196. };
  197. struct Medium
  198. {
  199. char *name;
  200. int hsize; /* medium header size */
  201. int mintu; /* default min mtu */
  202. int maxtu; /* default max mtu */
  203. int maclen; /* mac address length */
  204. void (*bind)(Ipifc*, int, char**);
  205. void (*unbind)(Ipifc*);
  206. void (*bwrite)(Ipifc *ifc, Block *b, int version, uint8_t *ip);
  207. /* for arming interfaces to receive multicast */
  208. void (*addmulti)(Ipifc *ifc, uint8_t *a, uint8_t *ia);
  209. void (*remmulti)(Ipifc *ifc, uint8_t *a, uint8_t *ia);
  210. /* process packets written to 'data' */
  211. void (*pktin)(Fs *f, Ipifc *ifc, Block *bp);
  212. /* routes for router boards */
  213. void (*addroute)(Ipifc *ifc, int, uint8_t*, uint8_t*, uint8_t*, int);
  214. void (*remroute)(Ipifc *ifc, int, uint8_t*, uint8_t*);
  215. void (*flushroutes)(Ipifc *ifc);
  216. /* for routing multicast groups */
  217. void (*joinmulti)(Ipifc *ifc, uint8_t *a, uint8_t *ia);
  218. void (*leavemulti)(Ipifc *ifc, uint8_t *a, uint8_t *ia);
  219. /* address resolution */
  220. void (*ares)(Fs*, int, uint8_t*, uint8_t*, int, int); /* resolve */
  221. void (*areg)(Ipifc*, uint8_t*); /* register */
  222. /* v6 address generation */
  223. void (*pref2addr)(uint8_t *pref, uint8_t *ea);
  224. int unbindonclose; /* if non-zero, unbind on last close */
  225. };
  226. /* logical interface associated with a physical one */
  227. struct Iplifc
  228. {
  229. uint8_t local[IPaddrlen];
  230. uint8_t mask[IPaddrlen];
  231. uint8_t remote[IPaddrlen];
  232. uint8_t net[IPaddrlen];
  233. uint8_t tentative; /* =1 => v6 dup disc on, =0 => confirmed unique */
  234. uint8_t onlink; /* =1 => onlink, =0 offlink. */
  235. uint8_t autoflag; /* v6 autonomous flag */
  236. int32_t validlt; /* v6 valid lifetime */
  237. int32_t preflt; /* v6 preferred lifetime */
  238. int32_t origint; /* time when addr was added */
  239. Iplink *link; /* addresses linked to this lifc */
  240. Iplifc *next;
  241. };
  242. /* binding twixt Ipself and Iplifc */
  243. struct Iplink
  244. {
  245. Ipself *self;
  246. Iplifc *lifc;
  247. Iplink *selflink; /* next link for this local address */
  248. Iplink *lifclink; /* next link for this ifc */
  249. uint32_t expire;
  250. Iplink *next; /* free list */
  251. int ref;
  252. };
  253. /* rfc 2461, pp.40—43. */
  254. /* default values, one per stack */
  255. struct Routerparams {
  256. int mflag; /* flag: managed address configuration */
  257. int oflag; /* flag: other stateful configuration */
  258. int maxraint; /* max. router adv interval (ms) */
  259. int minraint; /* min. router adv interval (ms) */
  260. int linkmtu; /* mtu options */
  261. int reachtime; /* reachable time */
  262. int rxmitra; /* retransmit interval */
  263. int ttl; /* cur hop count limit */
  264. int routerlt; /* router lifetime */
  265. };
  266. struct Hostparams {
  267. int rxmithost;
  268. };
  269. struct Ipifc
  270. {
  271. RWlock rwl;
  272. Conv *conv; /* link to its conversation structure */
  273. char dev[64]; /* device we're attached to */
  274. Medium *medium; /* Media pointer */
  275. int maxtu; /* Maximum transfer unit */
  276. int mintu; /* Minumum tranfer unit */
  277. int mbps; /* megabits per second */
  278. void *arg; /* medium specific */
  279. int reassemble; /* reassemble IP packets before forwarding */
  280. /* these are used so that we can unbind on the fly */
  281. Lock idlock;
  282. uint8_t ifcid; /* incremented each 'bind/unbind/add/remove' */
  283. int ref; /* number of proc's using this ipifc */
  284. Rendez wait; /* where unbinder waits for ref == 0 */
  285. int unbinding;
  286. uint8_t mac[MAClen]; /* MAC address */
  287. Iplifc *lifc; /* logical interfaces on this physical one */
  288. uint32_t in, out; /* message statistics */
  289. uint32_t inerr, outerr; /* ... */
  290. uint8_t sendra6; /* flag: send router advs on this ifc */
  291. uint8_t recvra6; /* flag: recv router advs on this ifc */
  292. Routerparams rp; /* router parameters as in RFC 2461, pp.40—43.
  293. used only if node is router */
  294. };
  295. /*
  296. * one per multicast-lifc pair used by a Conv
  297. */
  298. struct Ipmulti
  299. {
  300. uint8_t ma[IPaddrlen];
  301. uint8_t ia[IPaddrlen];
  302. Ipmulti *next;
  303. };
  304. /*
  305. * hash table for 2 ip addresses + 2 ports
  306. */
  307. enum
  308. {
  309. Nipht= 521, /* convenient prime */
  310. IPmatchexact= 0, /* match on 4 tuple */
  311. IPmatchany, /* *!* */
  312. IPmatchport, /* *!port */
  313. IPmatchaddr, /* addr!* */
  314. IPmatchpa, /* addr!port */
  315. };
  316. struct Iphash
  317. {
  318. Iphash *next;
  319. Conv *c;
  320. int match;
  321. };
  322. struct Ipht
  323. {
  324. Lock l;
  325. Iphash *tab[Nipht];
  326. };
  327. void iphtadd(Ipht*, Conv*);
  328. void iphtrem(Ipht*, Conv*);
  329. Conv* iphtlook(Ipht *ht, uint8_t *sa, uint16_t sp, uint8_t *da, uint16_t dp);
  330. /*
  331. * one per multiplexed protocol
  332. */
  333. struct Proto
  334. {
  335. QLock ql;
  336. char* name; /* protocol name */
  337. int x; /* protocol index */
  338. int ipproto; /* ip protocol type */
  339. char* (*connect)(Conv*, char**, int);
  340. char* (*announce)(Conv*, char**, int);
  341. char* (*bind)(Conv*, char**, int);
  342. int (*state)(Conv*, char*, int);
  343. void (*create)(Conv*);
  344. void (*close)(Conv*);
  345. void (*rcv)(Proto*, Ipifc*, Block*);
  346. char* (*ctl)(Conv*, char**, int);
  347. void (*advise)(Proto*, Block*, char*);
  348. int (*stats)(Proto*, char*, int);
  349. int (*local)(Conv*, char*, int);
  350. int (*remote)(Conv*, char*, int);
  351. int (*inuse)(Conv*);
  352. int (*gc)(Proto*); /* returns true if any conversations are freed */
  353. Fs *f; /* file system this proto is part of */
  354. Conv **conv; /* array of conversations */
  355. int ptclsize; /* size of per protocol ctl block */
  356. int nc; /* number of conversations */
  357. int ac;
  358. Qid qid; /* qid for protocol directory */
  359. uint16_t nextrport;
  360. void *priv;
  361. };
  362. /*
  363. * one per IP protocol stack
  364. */
  365. struct Fs
  366. {
  367. RWlock rwl;
  368. int dev;
  369. int np;
  370. Proto* p[Maxproto+1]; /* list of supported protocols */
  371. Proto* t2p[256]; /* vector of all protocols */
  372. Proto* ipifc; /* kludge for ipifcremroute & ipifcaddroute */
  373. Proto* ipmux; /* kludge for finding an ip multiplexor */
  374. IP *ip;
  375. Ipselftab *self;
  376. Arp *arp;
  377. v6params *v6p;
  378. Route *v4root[1<<Lroot]; /* v4 routing forest */
  379. Route *v6root[1<<Lroot]; /* v6 routing forest */
  380. Route *queue; /* used as temp when reinjecting routes */
  381. Netlog *alog;
  382. char ndb[1024]; /* an ndb entry for this interface */
  383. int ndbvers;
  384. int32_t ndbmtime;
  385. };
  386. /* one per default router known to host */
  387. struct v6router {
  388. uint8_t inuse;
  389. Ipifc *ifc;
  390. int ifcid;
  391. uint8_t routeraddr[IPaddrlen];
  392. int32_t ltorigin;
  393. Routerparams rp;
  394. };
  395. struct v6params
  396. {
  397. Routerparams rp; /* v6 params, one copy per node now */
  398. Hostparams hp;
  399. v6router v6rlist[3]; /* max 3 default routers, currently */
  400. int cdrouter; /* uses only v6rlist[cdrouter] if */
  401. /* cdrouter >= 0. */
  402. };
  403. int Fsconnected(Conv*, char*);
  404. Conv* Fsnewcall(Conv*, uint8_t*, uint16_t, uint8_t*, uint16_t, uint8_t);
  405. int Fspcolstats(char*, int);
  406. int Fsproto(Fs*, Proto*);
  407. int Fsbuiltinproto(Fs*, uint8_t);
  408. Conv* Fsprotoclone(Proto*, char*);
  409. Proto* Fsrcvpcol(Fs*, uint8_t);
  410. Proto* Fsrcvpcolx(Fs*, uint8_t);
  411. char* Fsstdconnect(Conv*, char**, int);
  412. char* Fsstdannounce(Conv*, char**, int);
  413. char* Fsstdbind(Conv*, char**, int);
  414. uint32_t scalednconv(void);
  415. void closeconv(Conv*);
  416. /*
  417. * logging
  418. */
  419. enum
  420. {
  421. Logip= 1<<1,
  422. Logtcp= 1<<2,
  423. Logfs= 1<<3,
  424. Logicmp= 1<<5,
  425. Logudp= 1<<6,
  426. Logcompress= 1<<7,
  427. Loggre= 1<<9,
  428. Logppp= 1<<10,
  429. Logtcprxmt= 1<<11,
  430. Logigmp= 1<<12,
  431. Logudpmsg= 1<<13,
  432. Logipmsg= 1<<14,
  433. Logrudp= 1<<15,
  434. Logrudpmsg= 1<<16,
  435. Logesp= 1<<17,
  436. Logtcpwin= 1<<18,
  437. };
  438. void netloginit(Fs*);
  439. void netlogopen(Fs*);
  440. void netlogclose(Fs*);
  441. void netlogctl(Fs*, char*, int);
  442. int32_t netlogread(Fs*, void*, uint32_t, int32_t);
  443. void netlog(Fs*, int, char*, ...);
  444. void ifcloginit(Fs*);
  445. int32_t ifclogread(Fs*, Chan *,void*, uint32_t, int32_t);
  446. void ifclog(Fs*, uint8_t *, int);
  447. void ifclogopen(Fs*, Chan*);
  448. void ifclogclose(Fs*, Chan*);
  449. #pragma varargck argpos netlog 3
  450. /*
  451. * iproute.c
  452. */
  453. typedef struct RouteTree RouteTree;
  454. typedef struct Routewalk Routewalk;
  455. typedef struct V4route V4route;
  456. typedef struct V6route V6route;
  457. enum
  458. {
  459. /* type bits */
  460. Rv4= (1<<0), /* this is a version 4 route */
  461. Rifc= (1<<1), /* this route is a directly connected interface */
  462. Rptpt= (1<<2), /* this route is a pt to pt interface */
  463. Runi= (1<<3), /* a unicast self address */
  464. Rbcast= (1<<4), /* a broadcast self address */
  465. Rmulti= (1<<5), /* a multicast self address */
  466. Rproxy= (1<<6), /* this route should be proxied */
  467. };
  468. struct Routewalk
  469. {
  470. int o;
  471. int h;
  472. char* p;
  473. char* e;
  474. void* state;
  475. void (*walk)(Route*, Routewalk*);
  476. };
  477. struct RouteTree
  478. {
  479. Route* right;
  480. Route* left;
  481. Route* mid;
  482. uint8_t depth;
  483. uint8_t type;
  484. uint8_t ifcid; /* must match ifc->id */
  485. Ipifc *ifc;
  486. char tag[4];
  487. int ref;
  488. };
  489. struct V4route
  490. {
  491. uint32_t address;
  492. uint32_t endaddress;
  493. uint8_t gate[IPv4addrlen];
  494. };
  495. struct V6route
  496. {
  497. uint32_t address[IPllen];
  498. uint32_t endaddress[IPllen];
  499. uint8_t gate[IPaddrlen];
  500. };
  501. struct Route
  502. {
  503. RouteTree RouteTree;
  504. union {
  505. V6route v6;
  506. V4route v4;
  507. };
  508. };
  509. extern void v4addroute(Fs *f, char *tag, uint8_t *a, uint8_t *mask, uint8_t *gate, int type);
  510. extern void v6addroute(Fs *f, char *tag, uint8_t *a, uint8_t *mask, uint8_t *gate, int type);
  511. extern void v4delroute(Fs *f, uint8_t *a, uint8_t *mask, int dolock);
  512. extern void v6delroute(Fs *f, uint8_t *a, uint8_t *mask, int dolock);
  513. extern Route* v4lookup(Fs *f, uint8_t *a, Conv *c);
  514. extern Route* v6lookup(Fs *f, uint8_t *a, Conv *c);
  515. extern int32_t routeread(Fs *f, char*, uint32_t, int);
  516. extern int32_t routewrite(Fs *f, Chan*, char*, int);
  517. extern void routetype(int, char*);
  518. extern void ipwalkroutes(Fs*, Routewalk*);
  519. extern void convroute(Route*, uint8_t*, uint8_t*, uint8_t*, char*, int*);
  520. /*
  521. * devip.c
  522. */
  523. /*
  524. * Hanging off every ip channel's ->aux is the following structure.
  525. * It maintains the state used by devip and iproute.
  526. */
  527. struct IPaux
  528. {
  529. char *owner; /* the user that did the attach */
  530. char tag[4];
  531. };
  532. extern IPaux* newipaux(char*, char*);
  533. /*
  534. * arp.c
  535. */
  536. struct Arpent
  537. {
  538. uint8_t ip[IPaddrlen];
  539. uint8_t mac[MAClen];
  540. Medium *type; /* media type */
  541. Arpent* hash;
  542. Block* hold;
  543. Block* last;
  544. uint ctime; /* time entry was created or refreshed */
  545. uint utime; /* time entry was last used */
  546. uint8_t state;
  547. Arpent *nextrxt; /* re-transmit chain */
  548. uint rtime; /* time for next retransmission */
  549. uint8_t rxtsrem;
  550. Ipifc *ifc;
  551. uint8_t ifcid; /* must match ifc->id */
  552. };
  553. extern void arpinit(Fs*);
  554. extern int arpread(Arp*, char*, uint32_t, int);
  555. extern int arpwrite(Fs*, char*, int);
  556. extern Arpent* arpget(Arp*, Block *bp, int version, Ipifc *ifc, uint8_t *ip, uint8_t *h);
  557. extern void arprelease(Arp*, Arpent *a);
  558. extern Block* arpresolve(Arp*, Arpent *a, Medium *type, uint8_t *mac);
  559. extern void arpenter(Fs*, int version, uint8_t *ip, uint8_t *mac, int len, int norefresh);
  560. /*
  561. * ipaux.c
  562. */
  563. extern int myetheraddr(uint8_t*, char*);
  564. extern int64_t parseip(uint8_t*, char*);
  565. extern int64_t parseipmask(uint8_t*, char*);
  566. extern char* v4parseip(uint8_t*, char*);
  567. extern void maskip(uint8_t *from, uint8_t *mask, uint8_t *to);
  568. extern int parsemac(uint8_t *to, char *from, int len);
  569. extern uint8_t* defmask(uint8_t*);
  570. extern int isv4(uint8_t*);
  571. extern void v4tov6(uint8_t *v6, uint8_t *v4);
  572. extern int v6tov4(uint8_t *v4, uint8_t *v6);
  573. extern int eipfmt(Fmt*);
  574. #define ipmove(x, y) memmove(x, y, IPaddrlen)
  575. #define ipcmp(x, y) ( (x)[IPaddrlen-1] != (y)[IPaddrlen-1] || memcmp(x, y, IPaddrlen) )
  576. extern uint8_t IPv4bcast[IPaddrlen];
  577. extern uint8_t IPv4bcastobs[IPaddrlen];
  578. extern uint8_t IPv4allsys[IPaddrlen];
  579. extern uint8_t IPv4allrouter[IPaddrlen];
  580. extern uint8_t IPnoaddr[IPaddrlen];
  581. extern uint8_t v4prefix[IPaddrlen];
  582. extern uint8_t IPallbits[IPaddrlen];
  583. #define NOW TK2MS(sys->machptr[0]->ticks)
  584. /*
  585. * media
  586. */
  587. extern Medium ethermedium;
  588. extern Medium nullmedium;
  589. extern Medium pktmedium;
  590. /*
  591. * ipifc.c
  592. */
  593. extern Medium* ipfindmedium(char *name);
  594. extern void addipmedium(Medium *med);
  595. extern int ipforme(Fs*, uint8_t *addr);
  596. extern int iptentative(Fs*, uint8_t *addr);
  597. extern int ipisbm(uint8_t *);
  598. extern int ipismulticast(uint8_t *);
  599. extern Ipifc* findipifc(Fs*, uint8_t *remote, int type);
  600. extern void findlocalip(Fs*, uint8_t *local, uint8_t *remote);
  601. extern int ipv4local(Ipifc *ifc, uint8_t *addr);
  602. extern int ipv6local(Ipifc *ifc, uint8_t *addr);
  603. extern int ipv6anylocal(Ipifc *ifc, uint8_t *addr);
  604. extern Iplifc* iplocalonifc(Ipifc *ifc, uint8_t *ip);
  605. extern int ipproxyifc(Fs *f, Ipifc *ifc, uint8_t *ip);
  606. extern int ipismulticast(uint8_t *ip);
  607. extern int ipisbooting(void);
  608. extern int ipifccheckin(Ipifc *ifc, Medium *med);
  609. extern void ipifccheckout(Ipifc *ifc);
  610. extern int ipifcgrab(Ipifc *ifc);
  611. extern void ipifcaddroute(Fs*, int, uint8_t*, uint8_t*, uint8_t*, int);
  612. extern void ipifcremroute(Fs*, int, uint8_t*, uint8_t*);
  613. extern void ipifcremmulti(Conv *c, uint8_t *ma, uint8_t *ia);
  614. extern void ipifcaddmulti(Conv *c, uint8_t *ma, uint8_t *ia);
  615. extern char* ipifcrem(Ipifc *ifc, char **argv, int argc);
  616. extern char* ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp);
  617. extern int32_t ipselftabread(Fs*, char *a, uint32_t offset, int n);
  618. extern char* ipifcadd6(Ipifc *ifc, char**argv, int argc);
  619. /*
  620. * ip.c
  621. */
  622. extern void iprouting(Fs*, int);
  623. extern void icmpnoconv(Fs*, Block*);
  624. extern void icmpcantfrag(Fs*, Block*, int);
  625. extern void icmpttlexceeded(Fs*, uint8_t*, Block*);
  626. extern uint16_t ipcsum(uint8_t*);
  627. extern void ipiput4(Fs*, Ipifc*, Block*);
  628. extern void ipiput6(Fs*, Ipifc*, Block*);
  629. extern int ipoput4(Fs*, Block*, int, int, int, Conv*);
  630. extern int ipoput6(Fs*, Block*, int, int, int, Conv*);
  631. extern int ipstats(Fs*, char*, int);
  632. extern uint16_t ptclbsum(uint8_t*, int);
  633. extern uint16_t ptclcsum(Block*, int, int);
  634. extern void ip_init(Fs*);
  635. extern void update_mtucache(uint8_t*, uint32_t);
  636. extern uint32_t restrict_mtu(uint8_t*, uint32_t);
  637. /*
  638. * bootp.c
  639. */
  640. extern int bootpread(char*, uint32_t, int);
  641. /*
  642. * resolving inferno/plan9 differences
  643. */
  644. char* commonuser(void);
  645. char* commonerror(void);
  646. /*
  647. * chandial.c
  648. */
  649. extern Chan* chandial(char*, char*, char*, Chan**);
  650. /*
  651. * global to all of the stack
  652. */
  653. extern void (*igmpreportfn)(Ipifc*, uint8_t*);