Skip to content

Commit 51c23b4

Browse files
committed
netfilter: nf_osf: add nf_osf_find()
This new function returns the OS genre as a string. Plan is to use to from the new nft_osf extension. Note that this doesn't yet support ttl options, but it could be easily extended to do so. Tested-by: Fernando Fernandez Mancera <ffmancera@riseup.net> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 222440b commit 51c23b4

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎include/linux/netfilter/nf_osf.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _NFOSF_H
3+
#define _NFOSF_H
4+
15
#include <uapi/linux/netfilter/nf_osf.h>
26

37
/* Initial window size option state machine: multiple of mss, mtu or
@@ -31,3 +35,8 @@ bool nf_osf_match(const struct sk_buff *skb, u_int8_t family,
3135
int hooknum, struct net_device *in, struct net_device *out,
3236
const struct nf_osf_info *info, struct net *net,
3337
const struct list_head *nf_osf_fingers);
38+
39+
const char *nf_osf_find(const struct sk_buff *skb,
40+
const struct list_head *nf_osf_fingers);
41+
42+
#endif /* _NFOSF_H */

‎net/netfilter/nf_osf.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,34 @@ nf_osf_match(const struct sk_buff *skb, u_int8_t family,
249249
}
250250
EXPORT_SYMBOL_GPL(nf_osf_match);
251251

252+
const char *nf_osf_find(const struct sk_buff *skb,
253+
const struct list_head *nf_osf_fingers)
254+
{
255+
const struct iphdr *ip = ip_hdr(skb);
256+
const struct nf_osf_user_finger *f;
257+
unsigned char opts[MAX_IPOPTLEN];
258+
const struct nf_osf_finger *kf;
259+
struct nf_osf_hdr_ctx ctx;
260+
const struct tcphdr *tcp;
261+
const char *genre = NULL;
262+
263+
memset(&ctx, 0, sizeof(ctx));
264+
265+
tcp = nf_osf_hdr_ctx_init(&ctx, skb, ip, opts);
266+
if (!tcp)
267+
return false;
268+
269+
list_for_each_entry_rcu(kf, &nf_osf_fingers[ctx.df], finger_entry) {
270+
f = &kf->finger;
271+
if (!nf_osf_match_one(skb, f, -1, &ctx))
272+
continue;
273+
274+
genre = f->genre;
275+
break;
276+
}
277+
278+
return genre;
279+
}
280+
EXPORT_SYMBOL_GPL(nf_osf_find);
281+
252282
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)