blob: d314844af12b080991e082a108d83be27d426a41 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Kernel module to match TOS values. */
2
3/* (C) 1999-2001 Paul `Rusty' Russell
4 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
Jan Engelhardt6709dbb2007-02-07 15:11:19 -080011#include <linux/ip.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/module.h>
13#include <linux/skbuff.h>
14
15#include <linux/netfilter_ipv4/ipt_tos.h>
Jan Engelhardt6709dbb2007-02-07 15:11:19 -080016#include <linux/netfilter/x_tables.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18MODULE_LICENSE("GPL");
19MODULE_DESCRIPTION("iptables TOS match module");
20
21static int
22match(const struct sk_buff *skb,
23 const struct net_device *in,
24 const struct net_device *out,
Patrick McHardyc4986732006-03-20 18:02:56 -080025 const struct xt_match *match,
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 const void *matchinfo,
27 int offset,
Harald Welte2e4e6a12006-01-12 13:30:04 -080028 unsigned int protoff,
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 int *hotdrop)
30{
31 const struct ipt_tos_info *info = matchinfo;
32
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -070033 return (ip_hdr(skb)->tos == info->tos) ^ info->invert;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034}
35
Jan Engelhardt6709dbb2007-02-07 15:11:19 -080036static struct xt_match tos_match = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 .name = "tos",
Jan Engelhardt6709dbb2007-02-07 15:11:19 -080038 .family = AF_INET,
Patrick McHardy1d5cd902006-03-20 18:01:14 -080039 .match = match,
40 .matchsize = sizeof(struct ipt_tos_info),
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 .me = THIS_MODULE,
42};
43
Andrew Morton65b4b4e2006-03-28 16:37:06 -080044static int __init ipt_multiport_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
Jan Engelhardt6709dbb2007-02-07 15:11:19 -080046 return xt_register_match(&tos_match);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}
48
Andrew Morton65b4b4e2006-03-28 16:37:06 -080049static void __exit ipt_multiport_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
Jan Engelhardt6709dbb2007-02-07 15:11:19 -080051 xt_unregister_match(&tos_match);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052}
53
Andrew Morton65b4b4e2006-03-28 16:37:06 -080054module_init(ipt_multiport_init);
55module_exit(ipt_multiport_fini);