ipaux.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. #include "u.h"
  2. #include "../port/lib.h"
  3. #include "mem.h"
  4. #include "dat.h"
  5. #include "fns.h"
  6. #include "../port/error.h"
  7. #include "ip.h"
  8. #include "ipv6.h"
  9. /*
  10. * well known IP addresses
  11. */
  12. uchar IPv4bcast[IPaddrlen] = {
  13. 0, 0, 0, 0,
  14. 0, 0, 0, 0,
  15. 0, 0, 0xff, 0xff,
  16. 0xff, 0xff, 0xff, 0xff
  17. };
  18. uchar IPv4allsys[IPaddrlen] = {
  19. 0, 0, 0, 0,
  20. 0, 0, 0, 0,
  21. 0, 0, 0xff, 0xff,
  22. 0xe0, 0, 0, 0x01
  23. };
  24. uchar IPv4allrouter[IPaddrlen] = {
  25. 0, 0, 0, 0,
  26. 0, 0, 0, 0,
  27. 0, 0, 0xff, 0xff,
  28. 0xe0, 0, 0, 0x02
  29. };
  30. uchar IPallbits[IPaddrlen] = {
  31. 0xff, 0xff, 0xff, 0xff,
  32. 0xff, 0xff, 0xff, 0xff,
  33. 0xff, 0xff, 0xff, 0xff,
  34. 0xff, 0xff, 0xff, 0xff
  35. };
  36. uchar IPnoaddr[IPaddrlen];
  37. /*
  38. * prefix of all v4 addresses
  39. */
  40. uchar v4prefix[IPaddrlen] = {
  41. 0, 0, 0, 0,
  42. 0, 0, 0, 0,
  43. 0, 0, 0xff, 0xff,
  44. 0, 0, 0, 0
  45. };
  46. char *v6hdrtypes[Maxhdrtype] =
  47. {
  48. [HBH] "HopbyHop",
  49. [ICMP] "ICMP",
  50. [IGMP] "IGMP",
  51. [GGP] "GGP",
  52. [IPINIP] "IP",
  53. [ST] "ST",
  54. [TCP] "TCP",
  55. [UDP] "UDP",
  56. [ISO_TP4] "ISO_TP4",
  57. [RH] "Routinghdr",
  58. [FH] "Fraghdr",
  59. [IDRP] "IDRP",
  60. [RSVP] "RSVP",
  61. [AH] "Authhdr",
  62. [ESP] "ESP",
  63. [ICMPv6] "ICMPv6",
  64. [NNH] "Nonexthdr",
  65. [ISO_IP] "ISO_IP",
  66. [IGRP] "IGRP",
  67. [OSPF] "OSPF",
  68. };
  69. /*
  70. * well known IPv6 addresses
  71. */
  72. uchar v6Unspecified[IPaddrlen] = {
  73. 0, 0, 0, 0,
  74. 0, 0, 0, 0,
  75. 0, 0, 0, 0,
  76. 0, 0, 0, 0
  77. };
  78. uchar v6loopback[IPaddrlen] = {
  79. 0, 0, 0, 0,
  80. 0, 0, 0, 0,
  81. 0, 0, 0, 0,
  82. 0, 0, 0, 0x01
  83. };
  84. uchar v6linklocal[IPaddrlen] = {
  85. 0xfe, 0x80, 0, 0,
  86. 0, 0, 0, 0,
  87. 0, 0, 0, 0,
  88. 0, 0, 0, 0
  89. };
  90. uchar v6linklocalmask[IPaddrlen] = {
  91. 0xff, 0xff, 0xff, 0xff,
  92. 0xff, 0xff, 0xff, 0xff,
  93. 0, 0, 0, 0,
  94. 0, 0, 0, 0
  95. };
  96. int v6llpreflen = 8; /* link-local prefix length */
  97. uchar v6glunicast[IPaddrlen] = {
  98. 0x08, 0, 0, 0,
  99. 0, 0, 0, 0,
  100. 0, 0, 0, 0,
  101. 0, 0, 0, 0
  102. };
  103. uchar v6multicast[IPaddrlen] = {
  104. 0xff, 0, 0, 0,
  105. 0, 0, 0, 0,
  106. 0, 0, 0, 0,
  107. 0, 0, 0, 0
  108. };
  109. uchar v6multicastmask[IPaddrlen] = {
  110. 0xff, 0, 0, 0,
  111. 0, 0, 0, 0,
  112. 0, 0, 0, 0,
  113. 0, 0, 0, 0
  114. };
  115. int v6mcpreflen = 1; /* multicast prefix length */
  116. uchar v6allnodesN[IPaddrlen] = {
  117. 0xff, 0x01, 0, 0,
  118. 0, 0, 0, 0,
  119. 0, 0, 0, 0,
  120. 0, 0, 0, 0x01
  121. };
  122. uchar v6allnodesNmask[IPaddrlen] = {
  123. 0xff, 0xff, 0, 0,
  124. 0, 0, 0, 0,
  125. 0, 0, 0, 0,
  126. 0, 0, 0, 0
  127. };
  128. int v6aNpreflen = 2; /* all nodes (N) prefix */
  129. uchar v6allnodesL[IPaddrlen] = {
  130. 0xff, 0x02, 0, 0,
  131. 0, 0, 0, 0,
  132. 0, 0, 0, 0,
  133. 0, 0, 0, 0x01
  134. };
  135. uchar v6allnodesLmask[IPaddrlen] = {
  136. 0xff, 0xff, 0, 0,
  137. 0, 0, 0, 0,
  138. 0, 0, 0, 0,
  139. 0, 0, 0, 0
  140. };
  141. int v6aLpreflen = 2; /* all nodes (L) prefix */
  142. uchar v6allroutersN[IPaddrlen] = {
  143. 0xff, 0x01, 0, 0,
  144. 0, 0, 0, 0,
  145. 0, 0, 0, 0,
  146. 0, 0, 0, 0x02
  147. };
  148. uchar v6allroutersL[IPaddrlen] = {
  149. 0xff, 0x02, 0, 0,
  150. 0, 0, 0, 0,
  151. 0, 0, 0, 0,
  152. 0, 0, 0, 0x02
  153. };
  154. uchar v6allroutersS[IPaddrlen] = {
  155. 0xff, 0x05, 0, 0,
  156. 0, 0, 0, 0,
  157. 0, 0, 0, 0,
  158. 0, 0, 0, 0x02
  159. };
  160. uchar v6solicitednode[IPaddrlen] = {
  161. 0xff, 0x02, 0, 0,
  162. 0, 0, 0, 0,
  163. 0, 0, 0, 0x01,
  164. 0xff, 0, 0, 0
  165. };
  166. uchar v6solicitednodemask[IPaddrlen] = {
  167. 0xff, 0xff, 0xff, 0xff,
  168. 0xff, 0xff, 0xff, 0xff,
  169. 0xff, 0xff, 0xff, 0xff,
  170. 0xff, 0x0, 0x0, 0x0
  171. };
  172. int v6snpreflen = 13;
  173. ushort
  174. ptclcsum(Block *bp, int offset, int len)
  175. {
  176. uchar *addr;
  177. ulong losum, hisum;
  178. ushort csum;
  179. int odd, blocklen, x;
  180. /* Correct to front of data area */
  181. while(bp != nil && offset && offset >= BLEN(bp)) {
  182. offset -= BLEN(bp);
  183. bp = bp->next;
  184. }
  185. if(bp == nil)
  186. return 0;
  187. addr = bp->rp + offset;
  188. blocklen = BLEN(bp) - offset;
  189. if(bp->next == nil) {
  190. if(blocklen < len)
  191. len = blocklen;
  192. return ~ptclbsum(addr, len) & 0xffff;
  193. }
  194. losum = 0;
  195. hisum = 0;
  196. odd = 0;
  197. while(len) {
  198. x = blocklen;
  199. if(len < x)
  200. x = len;
  201. csum = ptclbsum(addr, x);
  202. if(odd)
  203. hisum += csum;
  204. else
  205. losum += csum;
  206. odd = (odd+x) & 1;
  207. len -= x;
  208. bp = bp->next;
  209. if(bp == nil)
  210. break;
  211. blocklen = BLEN(bp);
  212. addr = bp->rp;
  213. }
  214. losum += hisum>>8;
  215. losum += (hisum&0xff)<<8;
  216. while((csum = losum>>16) != 0)
  217. losum = csum + (losum & 0xffff);
  218. return ~losum & 0xffff;
  219. }
  220. enum
  221. {
  222. Isprefix= 16,
  223. };
  224. static uchar prefixvals[256] =
  225. {
  226. [0x00] 0 | Isprefix,
  227. [0x80] 1 | Isprefix,
  228. [0xC0] 2 | Isprefix,
  229. [0xE0] 3 | Isprefix,
  230. [0xF0] 4 | Isprefix,
  231. [0xF8] 5 | Isprefix,
  232. [0xFC] 6 | Isprefix,
  233. [0xFE] 7 | Isprefix,
  234. [0xFF] 8 | Isprefix,
  235. };
  236. int
  237. eipfmt(Fmt *f)
  238. {
  239. char buf[5*8];
  240. static char *efmt = "%.2lux%.2lux%.2lux%.2lux%.2lux%.2lux";
  241. static char *ifmt = "%d.%d.%d.%d";
  242. uchar *p, ip[16];
  243. ulong *lp;
  244. ushort s;
  245. int i, j, n, eln, eli;
  246. switch(f->r) {
  247. case 'E': /* Ethernet address */
  248. p = va_arg(f->args, uchar*);
  249. snprint(buf, sizeof buf, efmt, p[0], p[1], p[2], p[3], p[4], p[5]);
  250. return fmtstrcpy(f, buf);
  251. case 'I': /* Ip address */
  252. p = va_arg(f->args, uchar*);
  253. common:
  254. if(memcmp(p, v4prefix, 12) == 0){
  255. snprint(buf, sizeof buf, ifmt, p[12], p[13], p[14], p[15]);
  256. return fmtstrcpy(f, buf);
  257. }
  258. /* find longest elision */
  259. eln = eli = -1;
  260. for(i = 0; i < 16; i += 2){
  261. for(j = i; j < 16; j += 2)
  262. if(p[j] != 0 || p[j+1] != 0)
  263. break;
  264. if(j > i && j - i > eln){
  265. eli = i;
  266. eln = j - i;
  267. }
  268. }
  269. /* print with possible elision */
  270. n = 0;
  271. for(i = 0; i < 16; i += 2){
  272. if(i == eli){
  273. n += sprint(buf+n, "::");
  274. i += eln;
  275. if(i >= 16)
  276. break;
  277. } else if(i != 0)
  278. n += sprint(buf+n, ":");
  279. s = (p[i]<<8) + p[i+1];
  280. n += sprint(buf+n, "%ux", s);
  281. }
  282. return fmtstrcpy(f, buf);
  283. case 'i': /* v6 address as 4 longs */
  284. lp = va_arg(f->args, ulong*);
  285. for(i = 0; i < 4; i++)
  286. hnputl(ip+4*i, *lp++);
  287. p = ip;
  288. goto common;
  289. case 'V': /* v4 ip address */
  290. p = va_arg(f->args, uchar*);
  291. snprint(buf, sizeof buf, ifmt, p[0], p[1], p[2], p[3]);
  292. return fmtstrcpy(f, buf);
  293. case 'M': /* ip mask */
  294. p = va_arg(f->args, uchar*);
  295. /* look for a prefix mask */
  296. for(i = 0; i < 16; i++)
  297. if(p[i] != 0xff)
  298. break;
  299. if(i < 16){
  300. if((prefixvals[p[i]] & Isprefix) == 0)
  301. goto common;
  302. for(j = i+1; j < 16; j++)
  303. if(p[j] != 0)
  304. goto common;
  305. n = 8*i + (prefixvals[p[i]] & ~Isprefix);
  306. } else
  307. n = 8*16;
  308. /* got one, use /xx format */
  309. snprint(buf, sizeof buf, "/%d", n);
  310. return fmtstrcpy(f, buf);
  311. }
  312. return fmtstrcpy(f, "(eipfmt)");
  313. }
  314. #define CLASS(p) ((*(uchar*)(p))>>6)
  315. extern char*
  316. v4parseip(uchar *to, char *from)
  317. {
  318. int i;
  319. char *p;
  320. p = from;
  321. for(i = 0; i < 4 && *p; i++){
  322. to[i] = strtoul(p, &p, 0);
  323. if(*p == '.')
  324. p++;
  325. }
  326. switch(CLASS(to)){
  327. case 0: /* class A - 1 uchar net */
  328. case 1:
  329. if(i == 3){
  330. to[3] = to[2];
  331. to[2] = to[1];
  332. to[1] = 0;
  333. } else if(i == 2){
  334. to[3] = to[1];
  335. to[1] = 0;
  336. }
  337. break;
  338. case 2: /* class B - 2 uchar net */
  339. if(i == 3){
  340. to[3] = to[2];
  341. to[2] = 0;
  342. }
  343. break;
  344. }
  345. return p;
  346. }
  347. int
  348. isv4(uchar *ip)
  349. {
  350. return memcmp(ip, v4prefix, IPv4off) == 0;
  351. }
  352. /*
  353. * the following routines are unrolled with no memset's to speed
  354. * up the usual case
  355. */
  356. void
  357. v4tov6(uchar *v6, uchar *v4)
  358. {
  359. v6[0] = 0;
  360. v6[1] = 0;
  361. v6[2] = 0;
  362. v6[3] = 0;
  363. v6[4] = 0;
  364. v6[5] = 0;
  365. v6[6] = 0;
  366. v6[7] = 0;
  367. v6[8] = 0;
  368. v6[9] = 0;
  369. v6[10] = 0xff;
  370. v6[11] = 0xff;
  371. v6[12] = v4[0];
  372. v6[13] = v4[1];
  373. v6[14] = v4[2];
  374. v6[15] = v4[3];
  375. }
  376. int
  377. v6tov4(uchar *v4, uchar *v6)
  378. {
  379. if(v6[0] == 0
  380. && v6[1] == 0
  381. && v6[2] == 0
  382. && v6[3] == 0
  383. && v6[4] == 0
  384. && v6[5] == 0
  385. && v6[6] == 0
  386. && v6[7] == 0
  387. && v6[8] == 0
  388. && v6[9] == 0
  389. && v6[10] == 0xff
  390. && v6[11] == 0xff)
  391. {
  392. v4[0] = v6[12];
  393. v4[1] = v6[13];
  394. v4[2] = v6[14];
  395. v4[3] = v6[15];
  396. return 0;
  397. } else {
  398. memset(v4, 0, 4);
  399. return -1;
  400. }
  401. }
  402. ulong
  403. parseip(uchar *to, char *from)
  404. {
  405. int i, elipsis = 0, v4 = 1;
  406. ulong x;
  407. char *p, *op;
  408. memset(to, 0, IPaddrlen);
  409. p = from;
  410. for(i = 0; i < 16 && *p; i+=2){
  411. op = p;
  412. x = strtoul(p, &p, 16);
  413. if(*p == '.' || (*p == 0 && i == 0)){
  414. p = v4parseip(to+i, op);
  415. i += 4;
  416. break;
  417. } else {
  418. to[i] = x>>8;
  419. to[i+1] = x;
  420. }
  421. if(*p == ':'){
  422. v4 = 0;
  423. if(*++p == ':'){
  424. elipsis = i+2;
  425. p++;
  426. }
  427. }
  428. }
  429. if(i < 16){
  430. memmove(&to[elipsis+16-i], &to[elipsis], i-elipsis);
  431. memset(&to[elipsis], 0, 16-i);
  432. }
  433. if(v4){
  434. to[10] = to[11] = 0xff;
  435. return nhgetl(to+12);
  436. } else
  437. return 6;
  438. }
  439. /*
  440. * hack to allow ip v4 masks to be entered in the old
  441. * style
  442. */
  443. ulong
  444. parseipmask(uchar *to, char *from)
  445. {
  446. ulong x;
  447. int i;
  448. uchar *p;
  449. if(*from == '/'){
  450. /* as a number of prefix bits */
  451. i = atoi(from+1);
  452. if(i < 0)
  453. i = 0;
  454. if(i > 128)
  455. i = 128;
  456. memset(to, 0, IPaddrlen);
  457. for(p = to; i >= 8; i -= 8)
  458. *p++ = 0xff;
  459. if(i > 0)
  460. *p = ~((1<<(8-i))-1);
  461. x = nhgetl(to+IPv4off);
  462. } else {
  463. /* as a straight bit mask */
  464. x = parseip(to, from);
  465. if(memcmp(to, v4prefix, IPv4off) == 0)
  466. memset(to, 0xff, IPv4off);
  467. }
  468. return x;
  469. }
  470. void
  471. maskip(uchar *from, uchar *mask, uchar *to)
  472. {
  473. int i;
  474. for(i = 0; i < IPaddrlen; i++)
  475. to[i] = from[i] & mask[i];
  476. }
  477. uchar classmask[4][16] = {
  478. 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0x00,0x00,0x00,
  479. 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0x00,0x00,0x00,
  480. 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0xff,0x00,0x00,
  481. 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0x00,
  482. };
  483. uchar*
  484. defmask(uchar *ip)
  485. {
  486. if(isv4(ip))
  487. return classmask[ip[IPv4off]>>6];
  488. else {
  489. if(ipcmp(ip, v6loopback) == 0)
  490. return IPallbits;
  491. else if(memcmp(ip, v6linklocal, v6llpreflen) == 0)
  492. return v6linklocalmask;
  493. else if(memcmp(ip, v6solicitednode, v6snpreflen) == 0)
  494. return v6solicitednodemask;
  495. else if(memcmp(ip, v6multicast, v6mcpreflen) == 0)
  496. return v6multicastmask;
  497. return IPallbits;
  498. }
  499. }
  500. void
  501. ipv62smcast(uchar *smcast, uchar *a)
  502. {
  503. assert(IPaddrlen == 16);
  504. memmove(smcast, v6solicitednode, IPaddrlen);
  505. smcast[13] = a[13];
  506. smcast[14] = a[14];
  507. smcast[15] = a[15];
  508. }
  509. /*
  510. * parse a hex mac address
  511. */
  512. int
  513. parsemac(uchar *to, char *from, int len)
  514. {
  515. char nip[4];
  516. char *p;
  517. int i;
  518. p = from;
  519. memset(to, 0, len);
  520. for(i = 0; i < len; i++){
  521. if(p[0] == '\0' || p[1] == '\0')
  522. break;
  523. nip[0] = p[0];
  524. nip[1] = p[1];
  525. nip[2] = '\0';
  526. p += 2;
  527. to[i] = strtoul(nip, 0, 16);
  528. if(*p == ':')
  529. p++;
  530. }
  531. return i;
  532. }
  533. /*
  534. * hashing tcp, udp, ... connections
  535. */
  536. ulong
  537. iphash(uchar *sa, ushort sp, uchar *da, ushort dp)
  538. {
  539. return ((sa[IPaddrlen-1]<<24) ^ (sp << 16) ^ (da[IPaddrlen-1]<<8) ^ dp ) % Nhash;
  540. }
  541. void
  542. iphtadd(Ipht *ht, Conv *c)
  543. {
  544. ulong hv;
  545. Iphash *h;
  546. hv = iphash(c->raddr, c->rport, c->laddr, c->lport);
  547. h = smalloc(sizeof(*h));
  548. if(ipcmp(c->raddr, IPnoaddr) != 0)
  549. h->match = IPmatchexact;
  550. else {
  551. if(ipcmp(c->laddr, IPnoaddr) != 0){
  552. if(c->lport == 0)
  553. h->match = IPmatchaddr;
  554. else
  555. h->match = IPmatchpa;
  556. } else {
  557. if(c->lport == 0)
  558. h->match = IPmatchany;
  559. else
  560. h->match = IPmatchport;
  561. }
  562. }
  563. h->c = c;
  564. lock(ht);
  565. h->next = ht->tab[hv];
  566. ht->tab[hv] = h;
  567. unlock(ht);
  568. }
  569. void
  570. iphtrem(Ipht *ht, Conv *c)
  571. {
  572. ulong hv;
  573. Iphash **l, *h;
  574. hv = iphash(c->raddr, c->rport, c->laddr, c->lport);
  575. lock(ht);
  576. for(l = &ht->tab[hv]; (*l) != nil; l = &(*l)->next)
  577. if((*l)->c == c){
  578. h = *l;
  579. (*l) = h->next;
  580. free(h);
  581. break;
  582. }
  583. unlock(ht);
  584. }
  585. /* look for a matching conversation with the following precedence
  586. * connected && raddr,rport,laddr,lport
  587. * announced && laddr,lport
  588. * announced && *,lport
  589. * announced && laddr,*
  590. * announced && *,*
  591. */
  592. Conv*
  593. iphtlook(Ipht *ht, uchar *sa, ushort sp, uchar *da, ushort dp)
  594. {
  595. ulong hv;
  596. Iphash *h;
  597. Conv *c;
  598. /* exact 4 pair match (connection) */
  599. hv = iphash(sa, sp, da, dp);
  600. lock(ht);
  601. for(h = ht->tab[hv]; h != nil; h = h->next){
  602. if(h->match != IPmatchexact)
  603. continue;
  604. c = h->c;
  605. if(sp == c->rport && dp == c->lport
  606. && ipcmp(sa, c->raddr) == 0 && ipcmp(da, c->laddr) == 0){
  607. unlock(ht);
  608. return c;
  609. }
  610. }
  611. /* match local address and port */
  612. hv = iphash(IPnoaddr, 0, da, dp);
  613. for(h = ht->tab[hv]; h != nil; h = h->next){
  614. if(h->match != IPmatchpa)
  615. continue;
  616. c = h->c;
  617. if(dp == c->lport && ipcmp(da, c->laddr) == 0){
  618. unlock(ht);
  619. return c;
  620. }
  621. }
  622. /* match just port */
  623. hv = iphash(IPnoaddr, 0, IPnoaddr, dp);
  624. for(h = ht->tab[hv]; h != nil; h = h->next){
  625. if(h->match != IPmatchport)
  626. continue;
  627. c = h->c;
  628. if(dp == c->lport){
  629. unlock(ht);
  630. return c;
  631. }
  632. }
  633. /* match local address */
  634. hv = iphash(IPnoaddr, 0, da, 0);
  635. for(h = ht->tab[hv]; h != nil; h = h->next){
  636. if(h->match != IPmatchaddr)
  637. continue;
  638. c = h->c;
  639. if(ipcmp(da, c->laddr) == 0){
  640. unlock(ht);
  641. return c;
  642. }
  643. }
  644. /* look for something that matches anything */
  645. hv = iphash(IPnoaddr, 0, IPnoaddr, 0);
  646. for(h = ht->tab[hv]; h != nil; h = h->next){
  647. if(h->match != IPmatchany)
  648. continue;
  649. c = h->c;
  650. unlock(ht);
  651. return c;
  652. }
  653. unlock(ht);
  654. return nil;
  655. }