Deleted Added
full compact
pf_osfp.c (126259) pf_osfp.c (126261)
1/* $FreeBSD: head/sys/contrib/pf/net/pf_osfp.c 126261 2004-02-26 02:34:12Z mlaier $ */
1/* $OpenBSD: pf_osfp.c,v 1.3 2003/08/27 18:23:36 frantzen 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.

--- 22 unchanged lines hidden (view full) ---

31
32#include <net/if.h>
33#include <net/pfvar.h>
34
35#ifdef INET6
36#include <netinet/ip6.h>
37#endif /* INET6 */
38
2/* $OpenBSD: pf_osfp.c,v 1.3 2003/08/27 18:23:36 frantzen Exp $ */
3
4/*
5 * Copyright (c) 2003 Mike Frantzen <frantzen@w4g.org>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.

--- 22 unchanged lines hidden (view full) ---

32
33#include <net/if.h>
34#include <net/pfvar.h>
35
36#ifdef INET6
37#include <netinet/ip6.h>
38#endif /* INET6 */
39
39
40#ifdef _KERNEL
41# define DPFPRINTF(format, x...) \
42 if (pf_status.debug >= PF_DEBUG_NOISY) \
43 printf(format , ##x)
40#ifdef _KERNEL
41# define DPFPRINTF(format, x...) \
42 if (pf_status.debug >= PF_DEBUG_NOISY) \
43 printf(format , ##x)
44#if defined(__FreeBSD__)
45typedef uma_zone_t pool_t;
46#else
44typedef struct pool pool_t;
47typedef struct pool pool_t;
48#endif
45
46#else
47/* Userland equivalents so we can lend code to tcpdump et al. */
48
49# include <arpa/inet.h>
50# include <errno.h>
51# include <stdio.h>
52# include <stdlib.h>
53# define pool_t int
54# define pool_get(pool, flags) malloc(*(pool))
55# define pool_put(pool, item) free(item)
56# define pool_init(pool, size, a, ao, f, m, p) (*(pool)) = (size)
57
49
50#else
51/* Userland equivalents so we can lend code to tcpdump et al. */
52
53# include <arpa/inet.h>
54# include <errno.h>
55# include <stdio.h>
56# include <stdlib.h>
57# define pool_t int
58# define pool_get(pool, flags) malloc(*(pool))
59# define pool_put(pool, item) free(item)
60# define pool_init(pool, size, a, ao, f, m, p) (*(pool)) = (size)
61
62# if defined(__FreeBSD__)
63# define NTOHS(x) (x) = ntohs((u_int16_t)(x))
64# endif
65
58# ifdef PFDEBUG
59# include <stdarg.h>
60# define DPFPRINTF(format, x...) fprintf(stderr, format , ##x)
61# else
62# define DPFPRINTF(format, x...) ((void)0)
63# endif /* PFDEBUG */
64#endif /* _KERNEL */
65

--- 35 unchanged lines hidden (view full) ---

101}
102#endif /* _KERNEL */
103
104struct pf_osfp_enlist *
105pf_osfp_fingerprint_hdr(const struct ip *ip, const struct tcphdr *tcp)
106{
107 struct pf_os_fingerprint fp, *fpresult;
108 int cnt, optlen = 0;
66# ifdef PFDEBUG
67# include <stdarg.h>
68# define DPFPRINTF(format, x...) fprintf(stderr, format , ##x)
69# else
70# define DPFPRINTF(format, x...) ((void)0)
71# endif /* PFDEBUG */
72#endif /* _KERNEL */
73

--- 35 unchanged lines hidden (view full) ---

109}
110#endif /* _KERNEL */
111
112struct pf_osfp_enlist *
113pf_osfp_fingerprint_hdr(const struct ip *ip, const struct tcphdr *tcp)
114{
115 struct pf_os_fingerprint fp, *fpresult;
116 int cnt, optlen = 0;
109 u_int8_t *optp;
117 const u_int8_t *optp;
110
111 if ((tcp->th_flags & (TH_SYN|TH_ACK)) != TH_SYN || (ip->ip_off &
112 htons(IP_OFFMASK)))
113 return (NULL);
114
115 memset(&fp, 0, sizeof(fp));
116
117 fp.fp_psize = ntohs(ip->ip_len);
118 fp.fp_ttl = ip->ip_ttl;
119 if (ip->ip_off & htons(IP_DF))
120 fp.fp_flags |= PF_OSFP_DF;
121 fp.fp_wsize = ntohs(tcp->th_win);
122
123
124 cnt = (tcp->th_off << 2) - sizeof(*tcp);
118
119 if ((tcp->th_flags & (TH_SYN|TH_ACK)) != TH_SYN || (ip->ip_off &
120 htons(IP_OFFMASK)))
121 return (NULL);
122
123 memset(&fp, 0, sizeof(fp));
124
125 fp.fp_psize = ntohs(ip->ip_len);
126 fp.fp_ttl = ip->ip_ttl;
127 if (ip->ip_off & htons(IP_DF))
128 fp.fp_flags |= PF_OSFP_DF;
129 fp.fp_wsize = ntohs(tcp->th_win);
130
131
132 cnt = (tcp->th_off << 2) - sizeof(*tcp);
125 optp = (caddr_t)tcp + sizeof(*tcp);
133 optp = (const u_int8_t *)((const char *)tcp + sizeof(*tcp));
126 for (; cnt > 0; cnt -= optlen, optp += optlen) {
127 if (*optp == TCPOPT_EOL)
128 break;
129
130 fp.fp_optcnt++;
131 if (*optp == TCPOPT_NOP) {
132 fp.fp_tcpopts = (fp.fp_tcpopts << PF_OSFP_TCPOPT_BITS) |
133 PF_OSFP_TCPOPT_NOP;

--- 89 unchanged lines hidden (view full) ---

223 return (1);
224 }
225 }
226 DPFPRINTF("fingerprint 0x%x didn't match\n", os);
227 return (0);
228}
229
230/* Initialize the OS fingerprint system */
134 for (; cnt > 0; cnt -= optlen, optp += optlen) {
135 if (*optp == TCPOPT_EOL)
136 break;
137
138 fp.fp_optcnt++;
139 if (*optp == TCPOPT_NOP) {
140 fp.fp_tcpopts = (fp.fp_tcpopts << PF_OSFP_TCPOPT_BITS) |
141 PF_OSFP_TCPOPT_NOP;

--- 89 unchanged lines hidden (view full) ---

231 return (1);
232 }
233 }
234 DPFPRINTF("fingerprint 0x%x didn't match\n", os);
235 return (0);
236}
237
238/* Initialize the OS fingerprint system */
239#if defined(__FreeBSD__)
240int
241#else
231void
242void
243#endif
232pf_osfp_initialize(void)
233{
244pf_osfp_initialize(void)
245{
246#if defined(__FreeBSD__) && defined(_KERNEL)
247 int error = ENOMEM;
248
249 do {
250 pf_osfp_entry_pl = pf_osfp_pl = NULL;
251 UMA_CREATE(pf_osfp_entry_pl, struct pf_osfp_entry, "pfospfen");
252 UMA_CREATE(pf_osfp_pl, struct pf_os_fingerprint, "pfosfp");
253 error = 0;
254 } while(0);
255#else
234 pool_init(&pf_osfp_entry_pl, sizeof(struct pf_osfp_entry), 0, 0, 0,
235 "pfosfpen", NULL);
236 pool_init(&pf_osfp_pl, sizeof(struct pf_os_fingerprint), 0, 0, 0,
237 "pfosfp", NULL);
256 pool_init(&pf_osfp_entry_pl, sizeof(struct pf_osfp_entry), 0, 0, 0,
257 "pfosfpen", NULL);
258 pool_init(&pf_osfp_pl, sizeof(struct pf_os_fingerprint), 0, 0, 0,
259 "pfosfp", NULL);
260#endif
238 SLIST_INIT(&pf_osfp_list);
261 SLIST_INIT(&pf_osfp_list);
262#if defined(__FreeBSD__)
263#if defined(_KERNEL)
264 return (error);
265#else
266 return (0);
267#endif
268#endif
239}
240
269}
270
271#if defined(__FreeBSD__) && (_KERNEL)
272void
273pf_osfp_cleanup(void)
274{
275 UMA_DESTROY(pf_osfp_entry_pl);
276 UMA_DESTROY(pf_osfp_pl);
277}
278#endif
279
241/* Flush the fingerprint list */
242void
243pf_osfp_flush(void)
244{
245 struct pf_os_fingerprint *fp;
246 struct pf_osfp_entry *entry;
247
248 while ((fp = SLIST_FIRST(&pf_osfp_list))) {

--- 276 unchanged lines hidden ---
280/* Flush the fingerprint list */
281void
282pf_osfp_flush(void)
283{
284 struct pf_os_fingerprint *fp;
285 struct pf_osfp_entry *entry;
286
287 while ((fp = SLIST_FIRST(&pf_osfp_list))) {

--- 276 unchanged lines hidden ---