/* 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 * * 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 #include #include #include #include #include #include MODULE_LICENSE("GPL"); MODULE_AUTHOR("Netfilter Core Team "); 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; iports, 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, const struct ip6t_ip6 *ip, void *matchinfo, unsigned int matchsize, unsigned int hook_mask) { const struct ip6t_multiport *multiinfo = matchinfo; if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_multiport))) return 0; /* 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) && matchsize == IP6T_ALIGN(sizeof(struct ip6t_multiport)) && (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", .match = &match, .checkentry = &checkentry, .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);