2005-04-16 22:20:36 +00:00
|
|
|
/* Kernel module to match one of a list of TCP/UDP ports: ports are in
|
|
|
|
the same place so we can treat them as equal. */
|
|
|
|
|
|
|
|
/* (C) 1999-2001 Paul `Rusty' Russell
|
|
|
|
* (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/udp.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/in.h>
|
|
|
|
|
|
|
|
#include <linux/netfilter_ipv6/ip6t_multiport.h>
|
|
|
|
#include <linux/netfilter_ipv6/ip6_tables.h>
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
|
|
|
|
MODULE_DESCRIPTION("ip6tables match for multiple ports");
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#define duprintf(format, args...) printk(format , ## args)
|
|
|
|
#else
|
|
|
|
#define duprintf(format, args...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Returns 1 if the port is matched by the test, 0 otherwise. */
|
|
|
|
static inline int
|
|
|
|
ports_match(const u_int16_t *portlist, enum ip6t_multiport_flags flags,
|
|
|
|
u_int8_t count, u_int16_t src, u_int16_t dst)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<count; i++) {
|
|
|
|
if (flags != IP6T_MULTIPORT_DESTINATION
|
|
|
|
&& portlist[i] == src)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (flags != IP6T_MULTIPORT_SOURCE
|
|
|
|
&& portlist[i] == dst)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
match(const struct sk_buff *skb,
|
|
|
|
const struct net_device *in,
|
|
|
|
const struct net_device *out,
|
2006-03-21 02:02:56 +00:00
|
|
|
const struct xt_match *match,
|
2005-04-16 22:20:36 +00:00
|
|
|
const void *matchinfo,
|
|
|
|
int offset,
|
|
|
|
unsigned int protoff,
|
|
|
|
int *hotdrop)
|
|
|
|
{
|
|
|
|
u16 _ports[2], *pptr;
|
|
|
|
const struct ip6t_multiport *multiinfo = matchinfo;
|
|
|
|
|
|
|
|
/* Must not be a fragment. */
|
|
|
|
if (offset)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Must be big enough to read ports (both UDP and TCP have
|
|
|
|
them at the start). */
|
|
|
|
pptr = skb_header_pointer(skb, protoff, sizeof(_ports), &_ports[0]);
|
|
|
|
if (pptr == NULL) {
|
|
|
|
/* We've been asked to examine this packet, and we
|
|
|
|
* can't. Hence, no choice but to drop.
|
|
|
|
*/
|
|
|
|
duprintf("ip6t_multiport:"
|
|
|
|
" Dropping evil offset=0 tinygram.\n");
|
|
|
|
*hotdrop = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ports_match(multiinfo->ports,
|
|
|
|
multiinfo->flags, multiinfo->count,
|
|
|
|
ntohs(pptr[0]), ntohs(pptr[1]));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called when user tries to insert an entry of this type. */
|
|
|
|
static int
|
|
|
|
checkentry(const char *tablename,
|
[NETFILTER] x_tables: Abstraction layer for {ip,ip6,arp}_tables
This monster-patch tries to do the best job for unifying the data
structures and backend interfaces for the three evil clones ip_tables,
ip6_tables and arp_tables. In an ideal world we would never have
allowed this kind of copy+paste programming... but well, our world
isn't (yet?) ideal.
o introduce a new x_tables module
o {ip,arp,ip6}_tables depend on this x_tables module
o registration functions for tables, matches and targets are only
wrappers around x_tables provided functions
o all matches/targets that are used from ip_tables and ip6_tables
are now implemented as xt_FOOBAR.c files and provide module aliases
to ipt_FOOBAR and ip6t_FOOBAR
o header files for xt_matches are in include/linux/netfilter/,
include/linux/netfilter_{ipv4,ipv6} contains compatibility wrappers
around the xt_FOOBAR.h headers
Based on this patchset we're going to further unify the code,
gradually getting rid of all the layer 3 specific assumptions.
Signed-off-by: Harald Welte <laforge@netfilter.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-01-12 21:30:04 +00:00
|
|
|
const void *info,
|
2006-03-21 02:02:56 +00:00
|
|
|
const struct xt_match *match,
|
2005-04-16 22:20:36 +00:00
|
|
|
void *matchinfo,
|
|
|
|
unsigned int matchsize,
|
|
|
|
unsigned int hook_mask)
|
|
|
|
{
|
[NETFILTER] x_tables: Abstraction layer for {ip,ip6,arp}_tables
This monster-patch tries to do the best job for unifying the data
structures and backend interfaces for the three evil clones ip_tables,
ip6_tables and arp_tables. In an ideal world we would never have
allowed this kind of copy+paste programming... but well, our world
isn't (yet?) ideal.
o introduce a new x_tables module
o {ip,arp,ip6}_tables depend on this x_tables module
o registration functions for tables, matches and targets are only
wrappers around x_tables provided functions
o all matches/targets that are used from ip_tables and ip6_tables
are now implemented as xt_FOOBAR.c files and provide module aliases
to ipt_FOOBAR and ip6t_FOOBAR
o header files for xt_matches are in include/linux/netfilter/,
include/linux/netfilter_{ipv4,ipv6} contains compatibility wrappers
around the xt_FOOBAR.h headers
Based on this patchset we're going to further unify the code,
gradually getting rid of all the layer 3 specific assumptions.
Signed-off-by: Harald Welte <laforge@netfilter.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-01-12 21:30:04 +00:00
|
|
|
const struct ip6t_ip6 *ip = info;
|
2005-04-16 22:20:36 +00:00
|
|
|
const struct ip6t_multiport *multiinfo = matchinfo;
|
|
|
|
|
|
|
|
/* Must specify proto == TCP/UDP, no unknown flags or bad count */
|
|
|
|
return (ip->proto == IPPROTO_TCP || ip->proto == IPPROTO_UDP)
|
|
|
|
&& !(ip->invflags & IP6T_INV_PROTO)
|
|
|
|
&& (multiinfo->flags == IP6T_MULTIPORT_SOURCE
|
|
|
|
|| multiinfo->flags == IP6T_MULTIPORT_DESTINATION
|
|
|
|
|| multiinfo->flags == IP6T_MULTIPORT_EITHER)
|
|
|
|
&& multiinfo->count <= IP6T_MULTI_PORTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ip6t_match multiport_match = {
|
|
|
|
.name = "multiport",
|
2006-03-21 02:01:43 +00:00
|
|
|
.match = match,
|
|
|
|
.matchsize = sizeof(struct ip6t_multiport),
|
|
|
|
.checkentry = checkentry,
|
2005-04-16 22:20:36 +00:00
|
|
|
.me = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init init(void)
|
|
|
|
{
|
|
|
|
return ip6t_register_match(&multiport_match);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit fini(void)
|
|
|
|
{
|
|
|
|
ip6t_unregister_match(&multiport_match);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(init);
|
|
|
|
module_exit(fini);
|