1 /* $OpenBSD: pf_osfp.c,v 1.15 2008/06/14 02:22:13 henning Exp $ */ 2 3 /* 4 * Copyright (c) 2003 Mike Frantzen <frantzen@w4g.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 * 18 */ 19 20 #include <sys/param.h> 21 #include <sys/socket.h> 22 #ifdef _KERNEL 23 # include <sys/systm.h> 24 #endif /* _KERNEL */ 25 #include <sys/mbuf.h> 26 27 #include <netinet/in.h> 28 #include <netinet/in_systm.h> 29 #include <netinet/ip.h> 30 #include <netinet/tcp.h> 31 32 #include <net/if.h> 33 #include <net/pf/pfvar.h> 34 35 #include <netinet/ip6.h> 36 #ifdef _KERNEL 37 #include <netinet6/in6_var.h> 38 #endif 39 40 41 #ifdef _KERNEL 42 # define DPFPRINTF(format, x...) \ 43 if (pf_status.debug >= PF_DEBUG_NOISY) \ 44 kprintf(format , ##x) 45 typedef vm_zone_t pool_t; 46 47 #else 48 /* Userland equivalents so we can lend code to tcpdump et al. */ 49 50 # include <arpa/inet.h> 51 # include <errno.h> 52 # include <stdio.h> 53 # include <stdlib.h> 54 # include <string.h> 55 # include <netdb.h> 56 # define pool_t int 57 # define pool_get(pool, flags) malloc(*(pool)) 58 # define pool_put(pool, item) free(item) 59 # define pool_init(pool, size, a, ao, f, m, p) (*(pool)) = (size) 60 61 # ifdef PFDEBUG 62 # include <sys/stdarg.h> 63 # define DPFPRINTF(format, x...) fprintf(stderr, format , ##x) 64 # else 65 # define DPFPRINTF(format, x...) ((void)0) 66 # endif /* PFDEBUG */ 67 #endif /* _KERNEL */ 68 69 70 SLIST_HEAD(pf_osfp_list, pf_os_fingerprint) pf_osfp_list; 71 pool_t pf_osfp_entry_pl; 72 pool_t pf_osfp_pl; 73 74 struct pf_os_fingerprint *pf_osfp_find(struct pf_osfp_list *, 75 struct pf_os_fingerprint *, u_int8_t); 76 struct pf_os_fingerprint *pf_osfp_find_exact(struct pf_osfp_list *, 77 struct pf_os_fingerprint *); 78 void pf_osfp_insert(struct pf_osfp_list *, 79 struct pf_os_fingerprint *); 80 81 82 #ifdef _KERNEL 83 /* 84 * Passively fingerprint the OS of the host (IPv4 TCP SYN packets only) 85 * Returns the list of possible OSes. 86 */ 87 struct pf_osfp_enlist * 88 pf_osfp_fingerprint(struct pf_pdesc *pd, struct mbuf *m, int off, 89 const struct tcphdr *tcp) 90 { 91 struct ip *ip; 92 struct ip6_hdr *ip6; 93 char hdr[60]; 94 95 if ((pd->af != PF_INET && pd->af != PF_INET6) || 96 pd->proto != IPPROTO_TCP || (tcp->th_off << 2) < sizeof(*tcp)) 97 return (NULL); 98 99 if (pd->af == PF_INET) { 100 ip = mtod(m, struct ip *); 101 ip6 = (struct ip6_hdr *)NULL; 102 } else { 103 ip = (struct ip *)NULL; 104 ip6 = mtod(m, struct ip6_hdr *); 105 } 106 if (!pf_pull_hdr(m, off, hdr, tcp->th_off << 2, NULL, NULL, 107 pd->af)) return (NULL); 108 109 return (pf_osfp_fingerprint_hdr(ip, ip6, (struct tcphdr *)hdr)); 110 } 111 #endif /* _KERNEL */ 112 113 struct pf_osfp_enlist * 114 pf_osfp_fingerprint_hdr(const struct ip *ip, const struct ip6_hdr *ip6, const struct tcphdr *tcp) 115 { 116 struct pf_os_fingerprint fp, *fpresult; 117 int cnt, optlen = 0; 118 const u_int8_t *optp; 119 #ifdef _KERNEL 120 char srcname[128]; 121 #else 122 char srcname[NI_MAXHOST]; 123 #endif 124 125 if ((tcp->th_flags & (TH_SYN|TH_ACK)) != TH_SYN) 126 return (NULL); 127 if (ip) { 128 if ((ip->ip_off & IP_OFFMASK) != 0) 129 return (NULL); 130 } 131 132 memset(&fp, 0, sizeof(fp)); 133 134 if (ip) { 135 #ifndef _KERNEL 136 struct sockaddr_in sin; 137 #endif 138 139 fp.fp_psize = ip->ip_len; 140 fp.fp_ttl = ip->ip_ttl; 141 if (ip->ip_off & IP_DF) 142 fp.fp_flags |= PF_OSFP_DF; 143 #ifdef _KERNEL 144 strlcpy(srcname, inet_ntoa(ip->ip_src), sizeof(srcname)); 145 #else 146 memset(&sin, 0, sizeof(sin)); 147 sin.sin_family = AF_INET; 148 sin.sin_len = sizeof(struct sockaddr_in); 149 sin.sin_addr = ip->ip_src; 150 (void)getnameinfo((struct sockaddr *)&sin, 151 sizeof(struct sockaddr_in), srcname, sizeof(srcname), 152 NULL, 0, NI_NUMERICHOST); 153 #endif 154 } 155 #ifdef INET6 156 else if (ip6) { 157 #ifndef _KERNEL 158 struct sockaddr_in6 sin6; 159 #endif 160 161 /* jumbo payload? */ 162 fp.fp_psize = sizeof(struct ip6_hdr) + ntohs(ip6->ip6_plen); 163 fp.fp_ttl = ip6->ip6_hlim; 164 fp.fp_flags |= PF_OSFP_DF; 165 fp.fp_flags |= PF_OSFP_INET6; 166 #ifdef _KERNEL 167 strlcpy(srcname, ip6_sprintf((struct in6_addr *)&ip6->ip6_src), 168 sizeof(srcname)); 169 #else 170 memset(&sin6, 0, sizeof(sin6)); 171 sin6.sin6_family = AF_INET6; 172 sin6.sin6_len = sizeof(struct sockaddr_in6); 173 sin6.sin6_addr = ip6->ip6_src; 174 (void)getnameinfo((struct sockaddr *)&sin6, 175 sizeof(struct sockaddr_in6), srcname, sizeof(srcname), 176 NULL, 0, NI_NUMERICHOST); 177 #endif 178 } 179 #endif 180 else 181 return (NULL); 182 fp.fp_wsize = ntohs(tcp->th_win); 183 184 185 cnt = (tcp->th_off << 2) - sizeof(*tcp); 186 optp = (const u_int8_t *)((const char *)tcp + sizeof(*tcp)); 187 for (; cnt > 0; cnt -= optlen, optp += optlen) { 188 if (*optp == TCPOPT_EOL) 189 break; 190 191 fp.fp_optcnt++; 192 if (*optp == TCPOPT_NOP) { 193 fp.fp_tcpopts = (fp.fp_tcpopts << PF_OSFP_TCPOPT_BITS) | 194 PF_OSFP_TCPOPT_NOP; 195 optlen = 1; 196 } else { 197 if (cnt < 2) 198 return (NULL); 199 optlen = optp[1]; 200 if (optlen > cnt || optlen < 2) 201 return (NULL); 202 switch (*optp) { 203 case TCPOPT_MAXSEG: 204 if (optlen >= TCPOLEN_MAXSEG) 205 memcpy(&fp.fp_mss, &optp[2], 206 sizeof(fp.fp_mss)); 207 fp.fp_tcpopts = (fp.fp_tcpopts << 208 PF_OSFP_TCPOPT_BITS) | PF_OSFP_TCPOPT_MSS; 209 fp.fp_mss = ntohs(fp.fp_mss); 210 break; 211 case TCPOPT_WINDOW: 212 if (optlen >= TCPOLEN_WINDOW) 213 memcpy(&fp.fp_wscale, &optp[2], 214 sizeof(fp.fp_wscale)); 215 fp.fp_tcpopts = (fp.fp_tcpopts << 216 PF_OSFP_TCPOPT_BITS) | 217 PF_OSFP_TCPOPT_WSCALE; 218 break; 219 case TCPOPT_SACK_PERMITTED: 220 fp.fp_tcpopts = (fp.fp_tcpopts << 221 PF_OSFP_TCPOPT_BITS) | PF_OSFP_TCPOPT_SACK; 222 break; 223 case TCPOPT_TIMESTAMP: 224 if (optlen >= TCPOLEN_TIMESTAMP) { 225 u_int32_t ts; 226 memcpy(&ts, &optp[2], sizeof(ts)); 227 if (ts == 0) 228 fp.fp_flags |= PF_OSFP_TS0; 229 230 } 231 fp.fp_tcpopts = (fp.fp_tcpopts << 232 PF_OSFP_TCPOPT_BITS) | PF_OSFP_TCPOPT_TS; 233 break; 234 default: 235 return (NULL); 236 } 237 } 238 optlen = MAX(optlen, 1); /* paranoia */ 239 } 240 241 DPFPRINTF("fingerprinted %s:%d %d:%d:%d:%d:%llx (%d) " 242 "(TS=%s,M=%s%d,W=%s%d)\n", 243 srcname, ntohs(tcp->th_sport), 244 fp.fp_wsize, fp.fp_ttl, (fp.fp_flags & PF_OSFP_DF) != 0, 245 fp.fp_psize, (long long int)fp.fp_tcpopts, fp.fp_optcnt, 246 (fp.fp_flags & PF_OSFP_TS0) ? "0" : "", 247 (fp.fp_flags & PF_OSFP_MSS_MOD) ? "%" : 248 (fp.fp_flags & PF_OSFP_MSS_DC) ? "*" : "", 249 fp.fp_mss, 250 (fp.fp_flags & PF_OSFP_WSCALE_MOD) ? "%" : 251 (fp.fp_flags & PF_OSFP_WSCALE_DC) ? "*" : "", 252 fp.fp_wscale); 253 254 if ((fpresult = pf_osfp_find(&pf_osfp_list, &fp, 255 PF_OSFP_MAXTTL_OFFSET))) 256 return (&fpresult->fp_oses); 257 return (NULL); 258 } 259 260 /* Match a fingerprint ID against a list of OSes */ 261 int 262 pf_osfp_match(struct pf_osfp_enlist *list, pf_osfp_t os) 263 { 264 struct pf_osfp_entry *entry; 265 int os_class, os_version, os_subtype; 266 int en_class, en_version, en_subtype; 267 268 if (os == PF_OSFP_ANY) 269 return (1); 270 if (list == NULL) { 271 DPFPRINTF("osfp no match against %x\n", os); 272 return (os == PF_OSFP_UNKNOWN); 273 } 274 PF_OSFP_UNPACK(os, os_class, os_version, os_subtype); 275 SLIST_FOREACH(entry, list, fp_entry) { 276 PF_OSFP_UNPACK(entry->fp_os, en_class, en_version, en_subtype); 277 if ((os_class == PF_OSFP_ANY || en_class == os_class) && 278 (os_version == PF_OSFP_ANY || en_version == os_version) && 279 (os_subtype == PF_OSFP_ANY || en_subtype == os_subtype)) { 280 DPFPRINTF("osfp matched %s %s %s %x==%x\n", 281 entry->fp_class_nm, entry->fp_version_nm, 282 entry->fp_subtype_nm, os, entry->fp_os); 283 return (1); 284 } 285 } 286 DPFPRINTF("fingerprint 0x%x didn't match\n", os); 287 return (0); 288 } 289 290 /* Initialize the OS fingerprint system */ 291 int 292 pf_osfp_initialize(void) 293 { 294 int error = 0; 295 296 #ifdef _KERNEL 297 do { 298 error = ENOMEM; 299 pf_osfp_entry_pl = pf_osfp_pl = NULL; 300 ZONE_CREATE(pf_osfp_entry_pl, struct pf_osfp_entry, "pfospfen"); 301 ZONE_CREATE(pf_osfp_pl, struct pf_os_fingerprint, "pfosfp"); 302 error = 0; 303 } while(0); 304 #else 305 pool_init(&pf_osfp_entry_pl, sizeof(struct pf_osfp_entry), 0, 0, 0, 306 "pfosfpen", NULL); 307 pool_init(&pf_osfp_pl, sizeof(struct pf_os_fingerprint), 0, 0, 0, 308 "pfosfp", NULL); 309 #endif 310 SLIST_INIT(&pf_osfp_list); 311 312 return (error); 313 } 314 315 #ifdef _KERNEL 316 void 317 pf_osfp_cleanup(void) 318 { 319 ZONE_DESTROY(pf_osfp_entry_pl); 320 ZONE_DESTROY(pf_osfp_pl); 321 } 322 #endif 323 324 /* Flush the fingerprint list */ 325 void 326 pf_osfp_flush(void) 327 { 328 struct pf_os_fingerprint *fp; 329 struct pf_osfp_entry *entry; 330 331 while ((fp = SLIST_FIRST(&pf_osfp_list))) { 332 SLIST_REMOVE_HEAD(&pf_osfp_list, fp_next); 333 while ((entry = SLIST_FIRST(&fp->fp_oses))) { 334 SLIST_REMOVE_HEAD(&fp->fp_oses, fp_entry); 335 pool_put(&pf_osfp_entry_pl, entry); 336 } 337 pool_put(&pf_osfp_pl, fp); 338 } 339 } 340 341 342 /* Add a fingerprint */ 343 int 344 pf_osfp_add(struct pf_osfp_ioctl *fpioc) 345 { 346 struct pf_os_fingerprint *fp, fpadd; 347 struct pf_osfp_entry *entry; 348 349 memset(&fpadd, 0, sizeof(fpadd)); 350 fpadd.fp_tcpopts = fpioc->fp_tcpopts; 351 fpadd.fp_wsize = fpioc->fp_wsize; 352 fpadd.fp_psize = fpioc->fp_psize; 353 fpadd.fp_mss = fpioc->fp_mss; 354 fpadd.fp_flags = fpioc->fp_flags; 355 fpadd.fp_optcnt = fpioc->fp_optcnt; 356 fpadd.fp_wscale = fpioc->fp_wscale; 357 fpadd.fp_ttl = fpioc->fp_ttl; 358 359 #if 0 /* XXX RYAN wants to fix logging */ 360 DPFPRINTF("adding osfp %s %s %s = %s%d:%d:%d:%s%d:0x%llx %d " 361 "(TS=%s,M=%s%d,W=%s%d) %x\n", 362 fpioc->fp_os.fp_class_nm, fpioc->fp_os.fp_version_nm, 363 fpioc->fp_os.fp_subtype_nm, 364 (fpadd.fp_flags & PF_OSFP_WSIZE_MOD) ? "%" : 365 (fpadd.fp_flags & PF_OSFP_WSIZE_MSS) ? "S" : 366 (fpadd.fp_flags & PF_OSFP_WSIZE_MTU) ? "T" : 367 (fpadd.fp_flags & PF_OSFP_WSIZE_DC) ? "*" : "", 368 fpadd.fp_wsize, 369 fpadd.fp_ttl, 370 (fpadd.fp_flags & PF_OSFP_DF) ? 1 : 0, 371 (fpadd.fp_flags & PF_OSFP_PSIZE_MOD) ? "%" : 372 (fpadd.fp_flags & PF_OSFP_PSIZE_DC) ? "*" : "", 373 fpadd.fp_psize, 374 (long long int)fpadd.fp_tcpopts, fpadd.fp_optcnt, 375 (fpadd.fp_flags & PF_OSFP_TS0) ? "0" : "", 376 (fpadd.fp_flags & PF_OSFP_MSS_MOD) ? "%" : 377 (fpadd.fp_flags & PF_OSFP_MSS_DC) ? "*" : "", 378 fpadd.fp_mss, 379 (fpadd.fp_flags & PF_OSFP_WSCALE_MOD) ? "%" : 380 (fpadd.fp_flags & PF_OSFP_WSCALE_DC) ? "*" : "", 381 fpadd.fp_wscale, 382 fpioc->fp_os.fp_os); 383 #endif 384 385 if ((fp = pf_osfp_find_exact(&pf_osfp_list, &fpadd))) { 386 SLIST_FOREACH(entry, &fp->fp_oses, fp_entry) { 387 if (PF_OSFP_ENTRY_EQ(entry, &fpioc->fp_os)) 388 return (EEXIST); 389 } 390 if ((entry = pool_get(&pf_osfp_entry_pl, 391 PR_WAITOK|PR_LIMITFAIL)) == NULL) 392 return (ENOMEM); 393 } else { 394 if ((fp = pool_get(&pf_osfp_pl, 395 PR_WAITOK|PR_LIMITFAIL)) == NULL) 396 return (ENOMEM); 397 memset(fp, 0, sizeof(*fp)); 398 fp->fp_tcpopts = fpioc->fp_tcpopts; 399 fp->fp_wsize = fpioc->fp_wsize; 400 fp->fp_psize = fpioc->fp_psize; 401 fp->fp_mss = fpioc->fp_mss; 402 fp->fp_flags = fpioc->fp_flags; 403 fp->fp_optcnt = fpioc->fp_optcnt; 404 fp->fp_wscale = fpioc->fp_wscale; 405 fp->fp_ttl = fpioc->fp_ttl; 406 SLIST_INIT(&fp->fp_oses); 407 if ((entry = pool_get(&pf_osfp_entry_pl, 408 PR_WAITOK|PR_LIMITFAIL)) == NULL) { 409 pool_put(&pf_osfp_pl, fp); 410 return (ENOMEM); 411 } 412 pf_osfp_insert(&pf_osfp_list, fp); 413 } 414 memcpy(entry, &fpioc->fp_os, sizeof(*entry)); 415 416 /* Make sure the strings are NUL terminated */ 417 entry->fp_class_nm[sizeof(entry->fp_class_nm)-1] = '\0'; 418 entry->fp_version_nm[sizeof(entry->fp_version_nm)-1] = '\0'; 419 entry->fp_subtype_nm[sizeof(entry->fp_subtype_nm)-1] = '\0'; 420 421 SLIST_INSERT_HEAD(&fp->fp_oses, entry, fp_entry); 422 423 #ifdef PFDEBUG 424 if ((fp = pf_osfp_validate())) 425 kprintf("Invalid fingerprint list\n"); 426 #endif /* PFDEBUG */ 427 return (0); 428 } 429 430 431 /* Find a fingerprint in the list */ 432 struct pf_os_fingerprint * 433 pf_osfp_find(struct pf_osfp_list *list, struct pf_os_fingerprint *find, 434 u_int8_t ttldiff) 435 { 436 struct pf_os_fingerprint *f; 437 438 #define MATCH_INT(_MOD, _DC, _field) \ 439 if ((f->fp_flags & _DC) == 0) { \ 440 if ((f->fp_flags & _MOD) == 0) { \ 441 if (f->_field != find->_field) \ 442 continue; \ 443 } else { \ 444 if (f->_field == 0 || find->_field % f->_field) \ 445 continue; \ 446 } \ 447 } 448 449 SLIST_FOREACH(f, list, fp_next) { 450 if (f->fp_tcpopts != find->fp_tcpopts || 451 f->fp_optcnt != find->fp_optcnt || 452 f->fp_ttl < find->fp_ttl || 453 f->fp_ttl - find->fp_ttl > ttldiff || 454 (f->fp_flags & (PF_OSFP_DF|PF_OSFP_TS0)) != 455 (find->fp_flags & (PF_OSFP_DF|PF_OSFP_TS0))) 456 continue; 457 458 MATCH_INT(PF_OSFP_PSIZE_MOD, PF_OSFP_PSIZE_DC, fp_psize) 459 MATCH_INT(PF_OSFP_MSS_MOD, PF_OSFP_MSS_DC, fp_mss) 460 MATCH_INT(PF_OSFP_WSCALE_MOD, PF_OSFP_WSCALE_DC, fp_wscale) 461 if ((f->fp_flags & PF_OSFP_WSIZE_DC) == 0) { 462 if (f->fp_flags & PF_OSFP_WSIZE_MSS) { 463 if (find->fp_mss == 0) 464 continue; 465 466 /* Some "smart" NAT devices and DSL routers will tweak the MSS size and 467 * will set it to whatever is suitable for the link type. 468 */ 469 #define SMART_MSS 1460 470 if ((find->fp_wsize % find->fp_mss || 471 find->fp_wsize / find->fp_mss != 472 f->fp_wsize) && 473 (find->fp_wsize % SMART_MSS || 474 find->fp_wsize / SMART_MSS != 475 f->fp_wsize)) 476 continue; 477 } else if (f->fp_flags & PF_OSFP_WSIZE_MTU) { 478 if (find->fp_mss == 0) 479 continue; 480 481 #define MTUOFF (sizeof(struct ip) + sizeof(struct tcphdr)) 482 #define SMART_MTU (SMART_MSS + MTUOFF) 483 if ((find->fp_wsize % (find->fp_mss + MTUOFF) || 484 find->fp_wsize / (find->fp_mss + MTUOFF) != 485 f->fp_wsize) && 486 (find->fp_wsize % SMART_MTU || 487 find->fp_wsize / SMART_MTU != 488 f->fp_wsize)) 489 continue; 490 } else if (f->fp_flags & PF_OSFP_WSIZE_MOD) { 491 if (f->fp_wsize == 0 || find->fp_wsize % 492 f->fp_wsize) 493 continue; 494 } else { 495 if (f->fp_wsize != find->fp_wsize) 496 continue; 497 } 498 } 499 return (f); 500 } 501 502 return (NULL); 503 } 504 505 /* Find an exact fingerprint in the list */ 506 struct pf_os_fingerprint * 507 pf_osfp_find_exact(struct pf_osfp_list *list, struct pf_os_fingerprint *find) 508 { 509 struct pf_os_fingerprint *f; 510 511 SLIST_FOREACH(f, list, fp_next) { 512 if (f->fp_tcpopts == find->fp_tcpopts && 513 f->fp_wsize == find->fp_wsize && 514 f->fp_psize == find->fp_psize && 515 f->fp_mss == find->fp_mss && 516 f->fp_flags == find->fp_flags && 517 f->fp_optcnt == find->fp_optcnt && 518 f->fp_wscale == find->fp_wscale && 519 f->fp_ttl == find->fp_ttl) 520 return (f); 521 } 522 523 return (NULL); 524 } 525 526 /* Insert a fingerprint into the list */ 527 void 528 pf_osfp_insert(struct pf_osfp_list *list, struct pf_os_fingerprint *ins) 529 { 530 struct pf_os_fingerprint *f, *prev = NULL; 531 532 /* XXX need to go semi tree based. can key on tcp options */ 533 534 SLIST_FOREACH(f, list, fp_next) 535 prev = f; 536 if (prev) 537 SLIST_INSERT_AFTER(prev, ins, fp_next); 538 else 539 SLIST_INSERT_HEAD(list, ins, fp_next); 540 } 541 542 /* Fill a fingerprint by its number (from an ioctl) */ 543 int 544 pf_osfp_get(struct pf_osfp_ioctl *fpioc) 545 { 546 struct pf_os_fingerprint *fp; 547 struct pf_osfp_entry *entry; 548 int num = fpioc->fp_getnum; 549 int i = 0; 550 551 552 memset(fpioc, 0, sizeof(*fpioc)); 553 SLIST_FOREACH(fp, &pf_osfp_list, fp_next) { 554 SLIST_FOREACH(entry, &fp->fp_oses, fp_entry) { 555 if (i++ == num) { 556 fpioc->fp_mss = fp->fp_mss; 557 fpioc->fp_wsize = fp->fp_wsize; 558 fpioc->fp_flags = fp->fp_flags; 559 fpioc->fp_psize = fp->fp_psize; 560 fpioc->fp_ttl = fp->fp_ttl; 561 fpioc->fp_wscale = fp->fp_wscale; 562 fpioc->fp_getnum = num; 563 memcpy(&fpioc->fp_os, entry, 564 sizeof(fpioc->fp_os)); 565 return (0); 566 } 567 } 568 } 569 570 return (EBUSY); 571 } 572 573 574 /* Validate that each signature is reachable */ 575 struct pf_os_fingerprint * 576 pf_osfp_validate(void) 577 { 578 struct pf_os_fingerprint *f, *f2, find; 579 580 SLIST_FOREACH(f, &pf_osfp_list, fp_next) { 581 memcpy(&find, f, sizeof(find)); 582 583 /* We do a few MSS/th_win percolations to make things unique */ 584 if (find.fp_mss == 0) 585 find.fp_mss = 128; 586 if (f->fp_flags & PF_OSFP_WSIZE_MSS) 587 find.fp_wsize *= find.fp_mss; 588 else if (f->fp_flags & PF_OSFP_WSIZE_MTU) 589 find.fp_wsize *= (find.fp_mss + 40); 590 else if (f->fp_flags & PF_OSFP_WSIZE_MOD) 591 find.fp_wsize *= 2; 592 if (f != (f2 = pf_osfp_find(&pf_osfp_list, &find, 0))) { 593 if (f2) 594 kprintf("Found \"%s %s %s\" instead of " 595 "\"%s %s %s\"\n", 596 SLIST_FIRST(&f2->fp_oses)->fp_class_nm, 597 SLIST_FIRST(&f2->fp_oses)->fp_version_nm, 598 SLIST_FIRST(&f2->fp_oses)->fp_subtype_nm, 599 SLIST_FIRST(&f->fp_oses)->fp_class_nm, 600 SLIST_FIRST(&f->fp_oses)->fp_version_nm, 601 SLIST_FIRST(&f->fp_oses)->fp_subtype_nm); 602 else 603 kprintf("Couldn't find \"%s %s %s\"\n", 604 SLIST_FIRST(&f->fp_oses)->fp_class_nm, 605 SLIST_FIRST(&f->fp_oses)->fp_version_nm, 606 SLIST_FIRST(&f->fp_oses)->fp_subtype_nm); 607 return (f); 608 } 609 } 610 return (NULL); 611 } 612