2 * IP tables module for matching the value of the incoming ether port
3 * for Ralink SoC platform.
5 * (C) 2009 by Y.Y. Huang <yy_huang@ralinktech.com.tw>
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.
12 #include <linux/module.h>
13 #include <linux/skbuff.h>
15 #include <linux/ipv6.h>
17 #include <linux/netfilter/xt_ethport.h>
18 #include <linux/netfilter/x_tables.h>
20 MODULE_AUTHOR("Y.Y. Huang <yy_huang@ralinktech.com.tw>");
21 MODULE_DESCRIPTION("x_tables Ra SoC Ethernet incoming port matching module");
22 MODULE_LICENSE("GPL");
23 MODULE_ALIAS("ipt_ethport");
24 MODULE_ALIAS("ip6t_ethport");
26 static bool match(const struct sk_buff
*skb
, struct xt_action_param
*par
)
28 const struct xt_ethport_info
*info
= par
->matchinfo
;
29 u_int8_t portnum
= skb
->priority
;
31 return (portnum
== info
->portnum
) ^ !!info
->invert
;
34 static bool match6(const struct sk_buff
*skb
, struct xt_action_param
*par
)
36 const struct xt_ethport_info
*info
= par
->matchinfo
;
37 u_int8_t portnum
= skb
->priority
;
39 return (portnum
== info
->portnum
) ^ !!info
->invert
;
42 static int checkentry(const struct xt_mtchk_param
*par
)
44 const u_int8_t portnum
= ((struct xt_ethport_info
*)(par
->matchinfo
))->portnum
;
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
);
54 static struct xt_match xt_ethport_match
[] = {
58 .checkentry
= checkentry
,
60 .matchsize
= sizeof(struct xt_ethport_info
),
66 .checkentry
= checkentry
,
68 .matchsize
= sizeof(struct xt_ethport_info
),
73 static int __init
xt_ethport_match_init(void)
75 return xt_register_matches(xt_ethport_match
, ARRAY_SIZE(xt_ethport_match
));
78 static void __exit
xt_ethport_match_fini(void)
80 xt_unregister_matches(xt_ethport_match
, ARRAY_SIZE(xt_ethport_match
));
83 module_init(xt_ethport_match_init
);
84 module_exit(xt_ethport_match_fini
);