Deleted Added
full compact
20d19
< #ifdef __FreeBSD__
22,23c21
< __FBSDID("$FreeBSD: head/sys/contrib/pf/net/pf_osfp.c 223637 2011-06-28 11:57:25Z bz $");
< #endif
---
> __FBSDID("$FreeBSD: head/sys/contrib/pf/net/pf_osfp.c 240233 2012-09-08 06:41:54Z glebius $");
25a24
> #include <sys/kernel.h>
27,33d25
< #ifdef _KERNEL
< #include <sys/systm.h>
< #ifndef __FreeBSD__
< #include <sys/pool.h>
< #endif
< #endif /* _KERNEL */
< #include <sys/mbuf.h>
36d27
< #include <netinet/in_systm.h>
44d34
< #ifdef _KERNEL
46d35
< #endif
48,50c37
<
< #ifdef _KERNEL
< #ifdef __FreeBSD__
---
> static MALLOC_DEFINE(M_PFOSFP, "pf_osfp", "pf(4) operating system fingerprints");
54,63d40
< #else
< #define DPFPRINTF(format, x...) \
< if (pf_status.debug >= PF_DEBUG_NOISY) \
< printf(format , ##x)
< #endif
< #ifdef __FreeBSD__
< typedef uma_zone_t pool_t;
< #else
< typedef struct pool pool_t;
< #endif
65,92d41
< #else
< /* Userland equivalents so we can lend code to tcpdump et al. */
<
< #include <arpa/inet.h>
< #include <errno.h>
< #include <stdio.h>
< #include <stdlib.h>
< #include <string.h>
< #include <netdb.h>
< #define pool_t int
< #define pool_get(pool, flags) malloc(*(pool))
< #define pool_put(pool, item) free(item)
< #define pool_init(pool, size, a, ao, f, m, p) (*(pool)) = (size)
<
< #ifdef __FreeBSD__
< #define NTOHS(x) (x) = ntohs((u_int16_t)(x))
< #endif
<
< #ifdef PFDEBUG
< #include <sys/stdarg.h>
< #define DPFPRINTF(format, x...) fprintf(stderr, format , ##x)
< #else
< #define DPFPRINTF(format, x...) ((void)0)
< #endif /* PFDEBUG */
< #endif /* _KERNEL */
<
<
< #ifdef __FreeBSD__
94c43,44
< VNET_DEFINE(struct pf_osfp_list, pf_osfp_list);
---
> static VNET_DEFINE(struct pf_osfp_list, pf_osfp_list) =
> SLIST_HEAD_INITIALIZER();
96,104d45
< VNET_DEFINE(pool_t, pf_osfp_entry_pl);
< #define pf_osfp_entry_pl VNET(pf_osfp_entry_pl)
< VNET_DEFINE(pool_t, pf_osfp_pl);
< #define pf_osfp_pl VNET(pf_osfp_pl)
< #else
< SLIST_HEAD(pf_osfp_list, pf_os_fingerprint) pf_osfp_list;
< pool_t pf_osfp_entry_pl;
< pool_t pf_osfp_pl;
< #endif
106c47,50
< struct pf_os_fingerprint *pf_osfp_find(struct pf_osfp_list *,
---
> static struct pf_osfp_enlist *pf_osfp_fingerprint_hdr(const struct ip *,
> const struct ip6_hdr *,
> const struct tcphdr *);
> static struct pf_os_fingerprint *pf_osfp_find(struct pf_osfp_list *,
108c52
< struct pf_os_fingerprint *pf_osfp_find_exact(struct pf_osfp_list *,
---
> static struct pf_os_fingerprint *pf_osfp_find_exact(struct pf_osfp_list *,
110c54
< void pf_osfp_insert(struct pf_osfp_list *,
---
> static void pf_osfp_insert(struct pf_osfp_list *,
111a56,58
> #ifdef PFDEBUG
> static struct pf_os_fingerprint *pf_osfp_validate(void);
> #endif
113,114d59
<
< #ifdef _KERNEL
143d87
< #endif /* _KERNEL */
145c89
< struct pf_osfp_enlist *
---
> static struct pf_osfp_enlist *
151d94
< #ifdef _KERNEL
153,155d95
< #else
< char srcname[NI_MAXHOST];
< #endif
167,170d106
< #ifndef _KERNEL
< struct sockaddr_in sin;
< #endif
<
175d110
< #ifdef _KERNEL
177,185d111
< #else
< memset(&sin, 0, sizeof(sin));
< sin.sin_family = AF_INET;
< sin.sin_len = sizeof(struct sockaddr_in);
< sin.sin_addr = ip->ip_src;
< (void)getnameinfo((struct sockaddr *)&sin,
< sizeof(struct sockaddr_in), srcname, sizeof(srcname),
< NULL, 0, NI_NUMERICHOST);
< #endif
189,192d114
< #ifndef _KERNEL
< struct sockaddr_in6 sin6;
< #endif
<
198d119
< #ifdef _KERNEL
201,209d121
< #else
< memset(&sin6, 0, sizeof(sin6));
< sin6.sin6_family = AF_INET6;
< sin6.sin6_len = sizeof(struct sockaddr_in6);
< sin6.sin6_addr = ip6->ip6_src;
< (void)getnameinfo((struct sockaddr *)&sin6,
< sizeof(struct sockaddr_in6), srcname, sizeof(srcname),
< NULL, 0, NI_NUMERICHOST);
< #endif
287d198
< #ifdef __FreeBSD__
289,291d199
< #else
< if ((fpresult = pf_osfp_find(&pf_osfp_list, &fp,
< #endif
327,372d234
< /* Initialize the OS fingerprint system */
< #ifdef __FreeBSD__
< int
< #else
< void
< #endif
< pf_osfp_initialize(void)
< {
< #if defined(__FreeBSD__) && defined(_KERNEL)
< int error = ENOMEM;
<
< do {
< pf_osfp_entry_pl = pf_osfp_pl = NULL;
< UMA_CREATE(pf_osfp_entry_pl, struct pf_osfp_entry, "pfospfen");
< UMA_CREATE(pf_osfp_pl, struct pf_os_fingerprint, "pfosfp");
< error = 0;
< } while(0);
<
< SLIST_INIT(&V_pf_osfp_list);
< #else
< pool_init(&pf_osfp_entry_pl, sizeof(struct pf_osfp_entry), 0, 0, 0,
< "pfosfpen", &pool_allocator_nointr);
< pool_init(&pf_osfp_pl, sizeof(struct pf_os_fingerprint), 0, 0, 0,
< "pfosfp", &pool_allocator_nointr);
< SLIST_INIT(&pf_osfp_list);
< #endif
<
< #ifdef __FreeBSD__
< #ifdef _KERNEL
< return (error);
< #else
< return (0);
< #endif
< #endif
< }
<
< #if defined(__FreeBSD__) && (_KERNEL)
< void
< pf_osfp_cleanup(void)
< {
<
< UMA_DESTROY(pf_osfp_entry_pl);
< UMA_DESTROY(pf_osfp_pl);
< }
< #endif
<
380d241
< #ifdef __FreeBSD__
383,386d243
< #else
< while ((fp = SLIST_FIRST(&pf_osfp_list))) {
< SLIST_REMOVE_HEAD(&pf_osfp_list, fp_next);
< #endif
389c246
< pool_put(&pf_osfp_entry_pl, entry);
---
> free(entry, M_PFOSFP);
391c248
< pool_put(&pf_osfp_pl, fp);
---
> free(fp, M_PFOSFP);
402a260,261
> PF_RULES_WASSERT();
>
439d297
< #ifdef __FreeBSD__
441,443d298
< #else
< if ((fp = pf_osfp_find_exact(&pf_osfp_list, &fpadd))) {
< #endif
448,453c303,304
< if ((entry = pool_get(&pf_osfp_entry_pl,
< #ifdef __FreeBSD__
< PR_NOWAIT)) == NULL)
< #else
< PR_WAITOK|PR_LIMITFAIL)) == NULL)
< #endif
---
> if ((entry = malloc(sizeof(*entry), M_PFOSFP, M_NOWAIT))
> == NULL)
456,461c307,308
< if ((fp = pool_get(&pf_osfp_pl,
< #ifdef __FreeBSD__
< PR_NOWAIT)) == NULL)
< #else
< PR_WAITOK|PR_LIMITFAIL)) == NULL)
< #endif
---
> if ((fp = malloc(sizeof(*fp), M_PFOSFP, M_ZERO | M_NOWAIT))
> == NULL)
463d309
< memset(fp, 0, sizeof(*fp));
473,479c319,321
< if ((entry = pool_get(&pf_osfp_entry_pl,
< #ifdef __FreeBSD__
< PR_NOWAIT)) == NULL) {
< #else
< PR_WAITOK|PR_LIMITFAIL)) == NULL) {
< #endif
< pool_put(&pf_osfp_pl, fp);
---
> if ((entry = malloc(sizeof(*entry), M_PFOSFP, M_NOWAIT))
> == NULL) {
> free(fp, M_PFOSFP);
482d323
< #ifdef __FreeBSD__
484,486d324
< #else
< pf_osfp_insert(&pf_osfp_list, fp);
< #endif
506c344
< struct pf_os_fingerprint *
---
> static struct pf_os_fingerprint *
581c419
< struct pf_os_fingerprint *
---
> static struct pf_os_fingerprint *
602c440
< void
---
> static void
628d465
< #ifdef __FreeBSD__
630,632d466
< #else
< SLIST_FOREACH(fp, &pf_osfp_list, fp_next) {
< #endif
652a487
> #ifdef PFDEBUG
654c489
< struct pf_os_fingerprint *
---
> static struct pf_os_fingerprint *
659d493
< #ifdef __FreeBSD__
661,663d494
< #else
< SLIST_FOREACH(f, &pf_osfp_list, fp_next) {
< #endif
675d505
< #ifdef __FreeBSD__
677,679d506
< #else
< if (f != (f2 = pf_osfp_find(&pf_osfp_list, &find, 0))) {
< #endif
698a526
> #endif /* PFDEBUG */