From 5deb3317cb51ac52de922bb55f8492624018906d Mon Sep 17 00:00:00 2001 From: Roman Yeryomin Date: Thu, 13 Sep 2012 00:40:35 +0300 Subject: Add realtek target files Signed-off-by: Roman Yeryomin --- .../linux/realtek/files/net/netfilter/xt_phyport.c | 147 +++++++++++++++++++++ .../realtek/files/net/netfilter/xt_vlanpriority.c | 138 +++++++++++++++++++ 2 files changed, 285 insertions(+) create mode 100644 target/linux/realtek/files/net/netfilter/xt_phyport.c create mode 100644 target/linux/realtek/files/net/netfilter/xt_vlanpriority.c (limited to 'target/linux/realtek/files/net/netfilter') diff --git a/target/linux/realtek/files/net/netfilter/xt_phyport.c b/target/linux/realtek/files/net/netfilter/xt_phyport.c new file mode 100644 index 000000000..621d5d2ca --- /dev/null +++ b/target/linux/realtek/files/net/netfilter/xt_phyport.c @@ -0,0 +1,147 @@ +/* Kernel module to match MAC address parameters. */ + +/* (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 +#include +#include + +#if 0 //defined(CONFIG_RTL_IPTABLES_RULE_2_ACL) +#include +#include +#endif + + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Netfilter Core Team "); +MODULE_DESCRIPTION("Xtables: MAC address match"); +MODULE_ALIAS("ipt_phyport"); +MODULE_ALIAS("ip6t_phyport"); + +static bool +checkentry(const struct xt_mtchk_param *par) +{ + const struct xt_phyport_info *phyportinfo = par->matchinfo; + + if(phyportinfo->flags & PORT_SRC){ + if (phyportinfo->srcport> 4) { + printk(KERN_WARNING "phy port source port: only supports port number 0~4\n"); + return 0; + } + } + else if(phyportinfo->flags & PORT_DST){ + if (phyportinfo->dstport> 4) { + printk(KERN_WARNING "phy port dest port: only supports port number 0~4\n"); + return 0; + } + } + else{ + printk(KERN_WARNING "wrong phy port flags 0x%x\n", phyportinfo->flags); + return 0; + } + + return 1; +} + +static bool phyport_mt(const struct sk_buff *skb, const struct xt_match_param *par) +{ + const struct xt_phyport_info *info = par->matchinfo; + + if (info->flags & PORT_SRC) { + if((skb->srcPhyPort != info->srcport) ^ (!!(info->flags & PORT_SRC_INV))){ + return false; + } + } + else if (info->flags & PORT_DST) { + if((skb->dstPhyPort != info->dstport) ^ (!!(info->flags & PORT_DST_INV))){ + return false; + } + } + else{ + printk(KERN_WARNING "wrong phy port flags 0x%x\n", info->flags); + return false; + } + + return true; +} + +#if 0 //defined(CONFIG_RTL_IPTABLES_RULE_2_ACL) +static int phyport_match2acl(const char *tablename, + const void *ip, + const struct xt_match *match, + void *matchinfo, + void *acl_rule, + unsigned int *invflags) +{ + + const struct xt_phyport_info *info = matchinfo; + rtl865x_AclRule_t *rule = (rtl865x_AclRule_t *)acl_rule; + if(matchinfo == NULL || rule == NULL) + return 1; + + rule->ruleType_ = RTL865X_ACL_MAC; + + //To initial first + memset(rule->srcMac_.octet, 0, ETH_ALEN); + memset(rule->srcMacMask_.octet, 0, ETH_ALEN); + memset(rule->dstMac_.octet, 0, ETH_ALEN); + memset(rule->dstMacMask_.octet, 0, ETH_ALEN); + + if (info->flags & MAC_SRC) { + memcpy(rule->srcMac_.octet, info->srcaddr.macaddr, ETH_ALEN); + memset(rule->srcMacMask_.octet, 0xff, ETH_ALEN); + } + + if (info->flags & MAC_DST) { + memcpy(rule->dstMac_.octet, info->dstaddr.macaddr, ETH_ALEN); + memset(rule->dstMacMask_.octet, 0xff, ETH_ALEN); + } + + rule->typeLen_ = rule->typeLenMask_ = 0; + + return 0; +} +#endif + +static struct xt_match phyport_mt_reg __read_mostly = { + .name = "phyport", + .revision = 0, + .family = NFPROTO_UNSPEC, + .checkentry = checkentry, + .match = phyport_mt, + .matchsize = sizeof(struct xt_phyport_info), +/* .hooks = (1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_IN) | + (1 << NF_INET_FORWARD), +*/ + .me = THIS_MODULE, +#if 0 //defined(CONFIG_RTL_IPTABLES_RULE_2_ACL) + .match2acl = phyport_match2acl, +#endif + +}; + +static int __init phyport_mt_init(void) +{ + return xt_register_match(&phyport_mt_reg); +} + +static void __exit phyport_mt_exit(void) +{ + xt_unregister_match(&phyport_mt_reg); +} + +module_init(phyport_mt_init); +module_exit(phyport_mt_exit); diff --git a/target/linux/realtek/files/net/netfilter/xt_vlanpriority.c b/target/linux/realtek/files/net/netfilter/xt_vlanpriority.c new file mode 100644 index 000000000..6c3c38d98 --- /dev/null +++ b/target/linux/realtek/files/net/netfilter/xt_vlanpriority.c @@ -0,0 +1,138 @@ +/* Kernel module to match Realsil extension functions. */ + +/* (C) 2009-2011 ZhaoBo + * + * 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 + +#if defined(CONFIG_RTL_IPTABLES_RULE_2_ACL) +#include +#include +#endif + + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("ZhaoBo "); +MODULE_DESCRIPTION("iptables realsil extensions matching module"); +MODULE_ALIAS("ipt_vlanpriority"); +MODULE_ALIAS("ip6t_vlanpriority"); + +static bool +match(const struct sk_buff *skb, const struct xt_match_param *par) +{ + const struct xt_vlanpriority_info *info = par->matchinfo; + + return (skb->srcVlanPriority== info->priority) ^ info->invert; +} + +static bool +checkentry(const struct xt_mtchk_param *par) +{ + const struct xt_vlanpriority_info *minfo = par->matchinfo; + + if (minfo->priority > 7) { + printk(KERN_WARNING "vlan priority: only supports priority 0~7\n"); + return 0; + } + return 1; +} + +#ifdef CONFIG_COMPAT +struct compat_xt_vlanpriority_info { + u_int8_t priority; + u_int8_t invert; + u_int16_t __pad2; +}; + +static void compat_from_user(void *dst, void *src) +{ + struct compat_xt_vlanpriority_info *cm = src; + struct xt_vlanpriority_info m = { + .priority = cm->priority, + .invert = cm->invert, + }; + memcpy(dst, &m, sizeof(m)); +} + +static int compat_to_user(void __user *dst, void *src) +{ + struct xt_vlanpriority_info *m = src; + struct compat_xt_vlanpriority_info cm = { + .priority = cm->priority, + .invert = cm->invert, + }; + return copy_to_user(dst, &cm, sizeof(cm)) ? -EFAULT : 0; +} +#endif /* CONFIG_COMPAT */ + +#if defined(CONFIG_RTL_IPTABLES_RULE_2_ACL) +static int vlanpriority_match2acl(const char *tablename, + const void *ip, + const struct xt_match *match, + void *matchinfo, + void *acl_rule, + unsigned int *invflags) +{ + + const struct xt_vlanpriority_info *info = matchinfo; + rtl865x_AclRule_t *rule = (rtl865x_AclRule_t *)acl_rule; + + if(matchinfo == NULL || rule == NULL) + return 1; + +#if defined(CONFIG_RTL_QOS_8021P_SUPPORT) + rule->ruleType_ = RTL865X_ACL_802D1P; + rule->vlanTagPri_ = info->priority; +#endif + + return 0; +} +#endif + +static struct xt_match xt_vlanpriority_match[] = { + { + .name = "vlanpriority", + .family = AF_INET, + .checkentry = checkentry, + .match = match, + .matchsize = sizeof(struct xt_vlanpriority_info), +#ifdef CONFIG_COMPAT + .compatsize = sizeof(struct compat_xt_vlanpriority_info), + .compat_from_user = compat_from_user, + .compat_to_user = compat_to_user, +#endif +#if defined(CONFIG_RTL_IPTABLES_RULE_2_ACL) + .match2acl = vlanpriority_match2acl, +#endif + .me = THIS_MODULE, + }, + { + .name = "vlanpriority", + .family = AF_INET6, + .checkentry = checkentry, + .match = match, + .matchsize = sizeof(struct xt_vlanpriority_info), + .me = THIS_MODULE, + }, +}; + +static int __init xt_vlanpriority_init(void) +{ + return xt_register_matches(xt_vlanpriority_match, ARRAY_SIZE(xt_vlanpriority_match)); +} + +static void __exit xt_vlanpriority_fini(void) +{ + xt_unregister_matches(xt_vlanpriority_match, ARRAY_SIZE(xt_vlanpriority_match)); +} + +module_init(xt_vlanpriority_init); +module_exit(xt_vlanpriority_fini); -- cgit v1.2.3