From f6b5ab23df11c7d73c5c34ba266d051588762dbd Mon Sep 17 00:00:00 2001 From: Bart De Schuymer Date: Sat, 27 Sep 2003 19:38:32 +0000 Subject: *** empty log message *** --- kernel/linux2.5/net/bridge/netfilter/ebt_among.c | 117 ++++++++++------------- 1 file changed, 50 insertions(+), 67 deletions(-) (limited to 'kernel/linux2.5/net/bridge/netfilter') diff --git a/kernel/linux2.5/net/bridge/netfilter/ebt_among.c b/kernel/linux2.5/net/bridge/netfilter/ebt_among.c index e4b2268..54c85d0 100644 --- a/kernel/linux2.5/net/bridge/netfilter/ebt_among.c +++ b/kernel/linux2.5/net/bridge/netfilter/ebt_among.c @@ -14,10 +14,6 @@ #include #include -/* -#define DEBUG -*/ - static int ebt_mac_wormhash_contains(const struct ebt_mac_wormhash *wh, const char *mac, uint32_t ip) { @@ -30,6 +26,7 @@ static int ebt_mac_wormhash_contains(const struct ebt_mac_wormhash *wh, int start, limit, i; uint32_t cmp[2] = { 0, 0 }; int key = (const unsigned char) mac[5]; + memcpy(((char *) cmp) + 2, mac, 6); start = wh->table[key]; limit = wh->table[key + 1]; @@ -46,7 +43,9 @@ static int ebt_mac_wormhash_contains(const struct ebt_mac_wormhash *wh, for (i = start; i < limit; i++) { p = &wh->pool[i]; if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) { - return 1; + if (p->ip == 0) { + return 1; + } } } } @@ -57,7 +56,8 @@ static int ebt_mac_wormhash_check_integrity(const struct ebt_mac_wormhash *wh) { int i; - for (i=0; i<256; i++) { + + for (i = 0; i < 256; i++) { if (wh->table[i] > wh->table[i + 1]) return -0x100 - i; if (wh->table[i] < 0) @@ -70,57 +70,44 @@ static int ebt_mac_wormhash_check_integrity(const struct ebt_mac_wormhash return 0; } -static int get_ip_dst(const struct sk_buff *skb, uint32_t * addr) +static int get_ip_dst(const struct sk_buff *skb, uint32_t *addr) { if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP)) { - *addr = skb->nh.iph->daddr; - return 1; - } - if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) { - - uint32_t arp_len = sizeof(struct arphdr) + - (2 * (((*skb).nh.arph)->ar_hln)) + - (2 * (((*skb).nh.arph)->ar_pln)); - - /* Make sure the packet is long enough. */ - if ((((*skb).nh.raw) + arp_len) > (*skb).tail) - return 0; - /* IPv4 addresses are always 4 bytes. */ - if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t)) - return 0; - - memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) + - (2 * (((*skb).nh.arph)->ar_hln)) + - (((*skb).nh.arph)->ar_pln), sizeof(uint32_t)); - - return 2; + struct iphdr iph; + + if (skb_copy_bits(skb, 0, &iph, sizeof(iph))) + return -1; + *addr = iph.daddr; + } else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) { + struct arphdr arph; + + if (skb_copy_bits(skb, 0, &arph, sizeof(arph)) || + arph.ar_pln != sizeof(uint32_t) || arph.ar_hln != ETH_ALEN) + return -1; + if (skb_copy_bits(skb, sizeof(struct arphdr) + + 2 * ETH_ALEN + sizeof(uint32_t), addr, sizeof(addr))) + return -1; } return 0; } -static int get_ip_src(const struct sk_buff *skb, uint32_t * addr) +static int get_ip_src(const struct sk_buff *skb, uint32_t *addr) { if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP)) { - *addr = skb->nh.iph->saddr; - return 1; - } - if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) { - - uint32_t arp_len = sizeof(struct arphdr) + - (2 * (((*skb).nh.arph)->ar_hln)) + - (2 * (((*skb).nh.arph)->ar_pln)); - - /* Make sure the packet is long enough. */ - if ((((*skb).nh.raw) + arp_len) > (*skb).tail) - return 0; - /* IPv4 addresses are always 4 bytes. */ - if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t)) - return 0; - - memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) + - ((((*skb).nh.arph)->ar_hln)), sizeof(uint32_t)); - - return 2; + struct iphdr iph; + + if (skb_copy_bits(skb, 0, &iph, sizeof(iph))) + return -1; + *addr = iph.saddr; + } else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) { + struct arphdr arph; + + if (skb_copy_bits(skb, 0, &arph, sizeof(arph)) || + arph.ar_pln != sizeof(uint32_t) || arph.ar_hln != ETH_ALEN) + return -1; + if (skb_copy_bits(skb, sizeof(struct arphdr) + + ETH_ALEN, addr, sizeof(addr))) + return -1; } return 0; } @@ -140,33 +127,31 @@ static int ebt_filter_among(const struct sk_buff *skb, if (wh_src) { smac = skb->mac.ethernet->h_source; - get_ip_src(skb, &sip); + if (get_ip_src(skb, &sip)) + return EBT_NOMATCH; if (!(info->bitmask & EBT_AMONG_SRC_NEG)) { /* we match only if it contains */ - if (!ebt_mac_wormhash_contains(wh_src, smac, sip)) { + if (!ebt_mac_wormhash_contains(wh_src, smac, sip)) return EBT_NOMATCH; - } } else { /* we match only if it DOES NOT contain */ - if (ebt_mac_wormhash_contains(wh_src, smac, sip)) { + if (ebt_mac_wormhash_contains(wh_src, smac, sip)) return EBT_NOMATCH; - } } } if (wh_dst) { dmac = skb->mac.ethernet->h_dest; - get_ip_dst(skb, &dip); + if (get_ip_dst(skb, &dip)) + return EBT_NOMATCH; if (!(info->bitmask & EBT_AMONG_DST_NEG)) { /* we match only if it contains */ - if (!ebt_mac_wormhash_contains(wh_dst, dmac, dip)) { + if (!ebt_mac_wormhash_contains(wh_dst, dmac, dip)) return EBT_NOMATCH; - } } else { /* we match only if it DOES NOT contain */ - if (ebt_mac_wormhash_contains(wh_dst, dmac, dip)) { + if (ebt_mac_wormhash_contains(wh_dst, dmac, dip)) return EBT_NOMATCH; - } } } @@ -181,12 +166,13 @@ static int ebt_among_check(const char *tablename, unsigned int hookmask, int expected_length = sizeof(struct ebt_among_info); const struct ebt_mac_wormhash *wh_dst, *wh_src; int err; + wh_dst = ebt_among_wh_dst(info); wh_src = ebt_among_wh_src(info); expected_length += ebt_mac_wormhash_size(wh_dst); expected_length += ebt_mac_wormhash_size(wh_src); - if (datalen < EBT_ALIGN(expected_length)) { + if (datalen != EBT_ALIGN(expected_length)) { printk(KERN_WARNING "ebtables: among: wrong size: %d" "against expected %d, rounded to %d\n", @@ -208,12 +194,10 @@ static int ebt_among_check(const char *tablename, unsigned int hookmask, } static struct ebt_match filter_among = { - {NULL, NULL}, - EBT_AMONG_MATCH, - ebt_filter_among, - ebt_among_check, - NULL, - THIS_MODULE + .name = EBT_AMONG_MATCH, + .match = ebt_filter_among, + .check = ebt_among_check, + .me = THIS_MODULE, }; static int __init init(void) @@ -228,5 +212,4 @@ static void __exit fini(void) module_init(init); module_exit(fini); -EXPORT_NO_SYMBOLS; MODULE_LICENSE("GPL"); -- cgit v1.2.3