1/* 2 * IP tables module for matching the value of the incoming ether port 3 * for Ralink SoC platform. 4 * 5 * (C) 2009 by Y.Y. Huang <yy_huang@ralinktech.com.tw> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 */ 11 12#include <linux/module.h> 13#include <linux/skbuff.h> 14#include <linux/ip.h> 15#include <linux/ipv6.h> 16 17#include <linux/netfilter/xt_ethport.h> 18#include <linux/netfilter/x_tables.h> 19 20MODULE_AUTHOR("Y.Y. Huang <yy_huang@ralinktech.com.tw>"); 21MODULE_DESCRIPTION("x_tables Ra SoC Ethernet incoming port matching module"); 22MODULE_LICENSE("GPL"); 23MODULE_ALIAS("ipt_ethport"); 24MODULE_ALIAS("ip6t_ethport"); 25 26static bool match(const struct sk_buff *skb, struct xt_action_param *par) 27{ 28 const struct xt_ethport_info *info = par->matchinfo; 29 u_int8_t portnum = skb->priority; 30 31 return (portnum == info->portnum) ^ !!info->invert; 32} 33 34static bool match6(const struct sk_buff *skb, struct xt_action_param *par) 35{ 36 const struct xt_ethport_info *info = par->matchinfo; 37 u_int8_t portnum = skb->priority; 38 39 return (portnum == info->portnum) ^ !!info->invert; 40} 41 42static int checkentry(const struct xt_mtchk_param *par) 43{ 44 const u_int8_t portnum = ((struct xt_ethport_info *)(par->matchinfo))->portnum; 45 46 if (portnum > XT_ETHPORT_MAX) { 47 printk(KERN_ERR "xt_ethport: port number %x is out of range(%x)\n", portnum, XT_ETHPORT_MAX); 48 return -EINVAL; 49 } 50 51 return 0; 52} 53 54static struct xt_match xt_ethport_match[] = { 55 { 56 .name = "ethport", 57 .family = AF_INET, 58 .checkentry = checkentry, 59 .match = match, 60 .matchsize = sizeof(struct xt_ethport_info), 61 .me = THIS_MODULE, 62 }, 63 { 64 .name = "ethport", 65 .family = AF_INET6, 66 .checkentry = checkentry, 67 .match = match6, 68 .matchsize = sizeof(struct xt_ethport_info), 69 .me = THIS_MODULE, 70 }, 71}; 72 73static int __init xt_ethport_match_init(void) 74{ 75 return xt_register_matches(xt_ethport_match, ARRAY_SIZE(xt_ethport_match)); 76} 77 78static void __exit xt_ethport_match_fini(void) 79{ 80 xt_unregister_matches(xt_ethport_match, ARRAY_SIZE(xt_ethport_match)); 81} 82 83module_init(xt_ethport_match_init); 84module_exit(xt_ethport_match_fini); 85