19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/module.h>
21 #include <linux/kernel.h>
26 #include <linux/list.h>
29 #include <linux/slab.h>
30 #include <linux/tcp.h>
35 #include <linux/netfilter/nfnetlink.h>
36 #include <linux/netfilter/x_tables.h>
59 static struct list_head xt_osf_fingers[2];
65 static int xt_osf_add_callback(
struct sock *ctnl,
struct sk_buff *
skb,
67 const struct nlattr *
const osf_attrs[])
79 f = nla_data(osf_attrs[OSF_ATTR_FINGER]);
108 static int xt_osf_remove_callback(
struct sock *ctnl,
struct sk_buff *skb,
110 const struct nlattr *
const osf_attrs[])
116 if (!osf_attrs[OSF_ATTR_FINGER])
119 f = nla_data(osf_attrs[OSF_ATTR_FINGER]);
140 .call = xt_osf_add_callback,
142 .policy = xt_osf_policy,
145 .call = xt_osf_remove_callback,
147 .policy = xt_osf_policy,
155 .cb = xt_osf_nfnetlink_callbacks,
161 const struct iphdr *
ip = ip_hdr(skb);
165 return ip->
ttl == f_ttl;
168 else if (ip->
ttl <= f_ttl)
171 struct in_device *in_dev = __in_dev_get_rcu(skb->
dev);
175 if (inet_ifa_match(ip->
saddr, ifa)) {
176 ret = (ip->
ttl == f_ttl);
186 return ip->
ttl == f_ttl;
193 const struct iphdr *ip = ip_hdr(skb);
197 unsigned int optsize = 0, check_WSS = 0;
200 const unsigned char *optp =
NULL, *_optp =
NULL;
208 tcp = skb_header_pointer(skb, ip_hdrlen(skb),
sizeof(
struct tcphdr), &_tcph);
219 if (tcp->doff * 4 >
sizeof(
struct tcphdr)) {
220 optsize = tcp->doff * 4 -
sizeof(
struct tcphdr);
222 _optp = optp = skb_header_pointer(skb, ip_hdrlen(skb) +
223 sizeof(
struct tcphdr), optsize, opts);
227 list_for_each_entry_rcu(kf, &xt_osf_fingers[df], finger_entry) {
236 if (totlen == f->
ss && xt_osf_ttl(skb, info, f->
ttl)) {
237 int foptsize, optnum;
248 for (optnum = 0; optnum < f->
opt_num; ++optnum)
249 foptsize += f->
opt[optnum].length;
256 check_WSS = f->
wss.wc;
258 for (optnum = 0; optnum < f->
opt_num; ++optnum) {
259 if (f->
opt[optnum].kind == (*optp)) {
261 const __u8 *optend = optp + len;
292 if (f->
wss.val == 0 || window == f->
wss.val)
302 #define SMART_MSS_1 1460
303 #define SMART_MSS_2 1448
304 if (window == f->
wss.val * mss ||
305 window == f->
wss.val * SMART_MSS_1 ||
306 window == f->
wss.val * SMART_MSS_2)
310 if (window == f->
wss.val * (mss + 40) ||
311 window == f->
wss.val * (SMART_MSS_1 + 40) ||
312 window == f->
wss.val * (SMART_MSS_2 + 40))
316 if ((window % f->
wss.val) == 0)
330 "%s [%s:%s] : %pI4:%d -> %pI4:%d hops=%d\n",
345 "Remote OS is not known: %pI4:%u -> %pI4:%u\n",
355 static struct xt_match xt_osf_match = {
363 .
match = xt_osf_match_packet,
368 static int __init xt_osf_init(
void)
374 INIT_LIST_HEAD(&xt_osf_fingers[i]);
378 pr_err(
"Failed to register OSF nsfnetlink helper (%d)\n", err);
384 pr_err(
"Failed to register OS fingerprint "
385 "matching module (%d)\n", err);
397 static void __exit xt_osf_fini(
void)
408 list_for_each_entry_rcu(f, &xt_osf_fingers[i],
finger_entry) {