5 * Bart De Schuymer <bdschuym@pandora.be>
10 * added ip-sport and ip-dport
11 * Innominate Security Technologies AG <mhopf@innominate.com>
17 #include <linux/module.h>
18 #include <linux/netfilter/x_tables.h>
19 #include <linux/netfilter_bridge/ebtables.h>
20 #include <linux/netfilter_bridge/ebt_ip.h>
28 ebt_ip_mt(const struct sk_buff *skb, const struct net_device *in,
29 const struct net_device *out, const struct xt_match *match,
30 const void *data, int offset, unsigned int protoff, bool *hotdrop)
32 const struct ebt_ip_info *info = data;
33 const struct iphdr *ih;
35 const struct tcpudphdr *pptr;
36 struct tcpudphdr _ports;
38 ih = skb_header_pointer(skb, 0, sizeof(_iph), &_iph);
41 if (info->bitmask & EBT_IP_TOS &&
42 FWINV(info->tos != ih->tos, EBT_IP_TOS))
44 if (info->bitmask & EBT_IP_SOURCE &&
45 FWINV((ih->saddr & info->smsk) !=
46 info->saddr, EBT_IP_SOURCE))
48 if ((info->bitmask & EBT_IP_DEST) &&
49 FWINV((ih->daddr & info->dmsk) !=
50 info->daddr, EBT_IP_DEST))
52 if (info->bitmask & EBT_IP_PROTO) {
53 if (FWINV(info->protocol != ih->protocol, EBT_IP_PROTO))
55 if (!(info->bitmask & EBT_IP_DPORT) &&
56 !(info->bitmask & EBT_IP_SPORT))
58 if (ntohs(ih->frag_off) & IP_OFFSET)
60 pptr = skb_header_pointer(skb, ih->ihl*4,
61 sizeof(_ports), &_ports);
64 if (info->bitmask & EBT_IP_DPORT) {
65 u32 dst = ntohs(pptr->dst);
66 if (FWINV(dst < info->dport[0] ||
71 if (info->bitmask & EBT_IP_SPORT) {
72 u32 src = ntohs(pptr->src);
73 if (FWINV(src < info->sport[0] ||
83 ebt_ip_mt_check(const char *table, const void *entry,
84 const struct xt_match *match, void *data,
85 unsigned int hook_mask)
87 const struct ebt_ip_info *info = data;
88 const struct ebt_entry *e = entry;
90 if (e->ethproto != htons(ETH_P_IP) ||
91 e->invflags & EBT_IPROTO)
93 if (info->bitmask & ~EBT_IP_MASK || info->invflags & ~EBT_IP_MASK)
95 if (info->bitmask & (EBT_IP_DPORT | EBT_IP_SPORT)) {
96 if (info->invflags & EBT_IP_PROTO)
98 if (info->protocol != IPPROTO_TCP &&
99 info->protocol != IPPROTO_UDP &&
100 info->protocol != IPPROTO_UDPLITE &&
101 info->protocol != IPPROTO_SCTP &&
102 info->protocol != IPPROTO_DCCP)
105 if (info->bitmask & EBT_IP_DPORT && info->dport[0] > info->dport[1])
107 if (info->bitmask & EBT_IP_SPORT && info->sport[0] > info->sport[1])
112 static struct xt_match ebt_ip_mt_reg __read_mostly = {
115 .family = NFPROTO_BRIDGE,
117 .checkentry = ebt_ip_mt_check,
118 .matchsize = XT_ALIGN(sizeof(struct ebt_ip_info)),
122 static int __init ebt_ip_init(void)
124 return xt_register_match(&ebt_ip_mt_reg);
127 static void __exit ebt_ip_fini(void)
129 xt_unregister_match(&ebt_ip_mt_reg);
132 module_init(ebt_ip_init);
133 module_exit(ebt_ip_fini);
134 MODULE_DESCRIPTION("Ebtables: IPv4 protocol packet match");
135 MODULE_LICENSE("GPL");