summaryrefslogtreecommitdiffstats
path: root/target/linux/realtek/files/net/netfilter
diff options
context:
space:
mode:
authorRoman Yeryomin <roman@advem.lv>2012-09-13 00:40:35 +0300
committerRoman Yeryomin <roman@advem.lv>2012-12-03 00:13:21 +0200
commit5deb3317cb51ac52de922bb55f8492624018906d (patch)
treec2fbe6346699d9bb0f2100490c3029519bb8fde8 /target/linux/realtek/files/net/netfilter
parent0239d37124f9184b478a42de8a7fa1bc85a6a6fe (diff)
Add realtek target files
Signed-off-by: Roman Yeryomin <roman@advem.lv>
Diffstat (limited to 'target/linux/realtek/files/net/netfilter')
-rw-r--r--target/linux/realtek/files/net/netfilter/xt_phyport.c147
-rw-r--r--target/linux/realtek/files/net/netfilter/xt_vlanpriority.c138
2 files changed, 285 insertions, 0 deletions
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 <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/skbuff.h>
+#include <linux/if_ether.h>
+#include <linux/etherdevice.h>
+
+#include <linux/netfilter_ipv4.h>
+#include <linux/netfilter_ipv6.h>
+#include <linux/netfilter/xt_phyport.h>
+#include <linux/netfilter/x_tables.h>
+#include <net/dst.h>
+
+#if 0 //defined(CONFIG_RTL_IPTABLES_RULE_2_ACL)
+#include <net/rtl/rtl_types.h>
+#include <net/rtl/rtl865x_netif.h>
+#endif
+
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
+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 <bo_zhao@realsil.com.cn>
+ *
+ * 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/skbuff.h>
+
+#include <linux/netfilter/x_tables.h>
+#include <linux/netfilter/xt_vlanpriority.h>
+
+#if defined(CONFIG_RTL_IPTABLES_RULE_2_ACL)
+#include <net/rtl/rtl_types.h>
+#include <net/rtl/rtl865x_netif.h>
+#endif
+
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("ZhaoBo <bo_zhao@realsil.com.cn>");
+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);