]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/bridge/netfilter/ebt_log.c
netfilter: Use unsigned types for hooknum and pf vars
[net-next-2.6.git] / net / bridge / netfilter / ebt_log.c
index 457815fb558440fefeedb04a01d22dccdffcf27d..3770cd8a7b3ab9c21416267a4a694646d2579c6e 100644 (file)
 #include <linux/in.h>
 #include <linux/if_arp.h>
 #include <linux/spinlock.h>
+#include <net/netfilter/nf_log.h>
+#include <linux/ipv6.h>
+#include <net/ipv6.h>
+#include <linux/in6.h>
 
 static DEFINE_SPINLOCK(ebt_log_lock);
 
 static int ebt_log_check(const char *tablename, unsigned int hookmask,
    const struct ebt_entry *e, void *data, unsigned int datalen)
 {
-       struct ebt_log_info *info = (struct ebt_log_info *)data;
+       struct ebt_log_info *info = data;
 
        if (datalen != EBT_ALIGN(sizeof(struct ebt_log_info)))
                return -EINVAL;
@@ -49,7 +53,7 @@ struct arppayload
        unsigned char ip_dst[4];
 };
 
-static void print_MAC(unsigned char *p)
+static void print_MAC(const unsigned char *p)
 {
        int i;
 
@@ -57,9 +61,30 @@ static void print_MAC(unsigned char *p)
                printk("%02x%c", *p, i == ETH_ALEN - 1 ? ' ':':');
 }
 
+static void
+print_ports(const struct sk_buff *skb, uint8_t protocol, int offset)
+{
+       if (protocol == IPPROTO_TCP ||
+           protocol == IPPROTO_UDP ||
+           protocol == IPPROTO_UDPLITE ||
+           protocol == IPPROTO_SCTP ||
+           protocol == IPPROTO_DCCP) {
+               const struct tcpudphdr *pptr;
+               struct tcpudphdr _ports;
+
+               pptr = skb_header_pointer(skb, offset,
+                                         sizeof(_ports), &_ports);
+               if (pptr == NULL) {
+                       printk(" INCOMPLETE TCP/UDP header");
+                       return;
+               }
+               printk(" SPT=%u DPT=%u", ntohs(pptr->src), ntohs(pptr->dst));
+       }
+}
+
 #define myNIPQUAD(a) a[0], a[1], a[2], a[3]
 static void
-ebt_log_packet(unsigned int pf, unsigned int hooknum,
+ebt_log_packet(u_int8_t pf, unsigned int hooknum,
    const struct sk_buff *skb, const struct net_device *in,
    const struct net_device *out, const struct nf_loginfo *loginfo,
    const char *prefix)
@@ -83,7 +108,8 @@ ebt_log_packet(unsigned int pf, unsigned int hooknum,
 
        if ((bitmask & EBT_LOG_IP) && eth_hdr(skb)->h_proto ==
           htons(ETH_P_IP)){
-               struct iphdr _iph, *ih;
+               const struct iphdr *ih;
+               struct iphdr _iph;
 
                ih = skb_header_pointer(skb, 0, sizeof(_iph), &_iph);
                if (ih == NULL) {
@@ -93,29 +119,41 @@ ebt_log_packet(unsigned int pf, unsigned int hooknum,
                printk(" IP SRC=%u.%u.%u.%u IP DST=%u.%u.%u.%u, IP "
                       "tos=0x%02X, IP proto=%d", NIPQUAD(ih->saddr),
                       NIPQUAD(ih->daddr), ih->tos, ih->protocol);
-               if (ih->protocol == IPPROTO_TCP ||
-                   ih->protocol == IPPROTO_UDP ||
-                   ih->protocol == IPPROTO_UDPLITE ||
-                   ih->protocol == IPPROTO_SCTP ||
-                   ih->protocol == IPPROTO_DCCP) {
-                       struct tcpudphdr _ports, *pptr;
-
-                       pptr = skb_header_pointer(skb, ih->ihl*4,
-                                                 sizeof(_ports), &_ports);
-                       if (pptr == NULL) {
-                               printk(" INCOMPLETE TCP/UDP header");
-                               goto out;
-                       }
-                       printk(" SPT=%u DPT=%u", ntohs(pptr->src),
-                          ntohs(pptr->dst));
+               print_ports(skb, ih->protocol, ih->ihl*4);
+               goto out;
+       }
+
+#if defined(CONFIG_BRIDGE_EBT_IP6) || defined(CONFIG_BRIDGE_EBT_IP6_MODULE)
+       if ((bitmask & EBT_LOG_IP6) && eth_hdr(skb)->h_proto ==
+          htons(ETH_P_IPV6)) {
+               const struct ipv6hdr *ih;
+               struct ipv6hdr _iph;
+               uint8_t nexthdr;
+               int offset_ph;
+
+               ih = skb_header_pointer(skb, 0, sizeof(_iph), &_iph);
+               if (ih == NULL) {
+                       printk(" INCOMPLETE IPv6 header");
+                       goto out;
                }
+               printk(" IPv6 SRC=%x:%x:%x:%x:%x:%x:%x:%x "
+                      "IPv6 DST=%x:%x:%x:%x:%x:%x:%x:%x, IPv6 "
+                      "priority=0x%01X, Next Header=%d", NIP6(ih->saddr),
+                      NIP6(ih->daddr), ih->priority, ih->nexthdr);
+               nexthdr = ih->nexthdr;
+               offset_ph = ipv6_skip_exthdr(skb, sizeof(_iph), &nexthdr);
+               if (offset_ph == -1)
+                       goto out;
+               print_ports(skb, nexthdr, offset_ph);
                goto out;
        }
+#endif
 
        if ((bitmask & EBT_LOG_ARP) &&
            ((eth_hdr(skb)->h_proto == htons(ETH_P_ARP)) ||
             (eth_hdr(skb)->h_proto == htons(ETH_P_RARP)))) {
-               struct arphdr _arph, *ah;
+               const struct arphdr *ah;
+               struct arphdr _arph;
 
                ah = skb_header_pointer(skb, 0, sizeof(_arph), &_arph);
                if (ah == NULL) {
@@ -131,7 +169,8 @@ ebt_log_packet(unsigned int pf, unsigned int hooknum,
                if (ah->ar_hrd == htons(1) &&
                    ah->ar_hln == ETH_ALEN &&
                    ah->ar_pln == sizeof(__be32)) {
-                       struct arppayload _arpp, *ap;
+                       const struct arppayload *ap;
+                       struct arppayload _arpp;
 
                        ap = skb_header_pointer(skb, sizeof(_arph),
                                                sizeof(_arpp), &_arpp);
@@ -159,7 +198,7 @@ static void ebt_log(const struct sk_buff *skb, unsigned int hooknr,
    const struct net_device *in, const struct net_device *out,
    const void *data, unsigned int datalen)
 {
-       struct ebt_log_info *info = (struct ebt_log_info *)data;
+       const struct ebt_log_info *info = data;
        struct nf_loginfo li;
 
        li.type = NF_LOG_TYPE_LOG;
@@ -182,7 +221,7 @@ static struct ebt_watcher log =
        .me             = THIS_MODULE,
 };
 
-static struct nf_logger ebt_log_logger = {
+static const struct nf_logger ebt_log_logger = {
        .name           = "ebt_log",
        .logfn          = &ebt_log_packet,
        .me             = THIS_MODULE,
@@ -207,4 +246,5 @@ static void __exit ebt_log_fini(void)
 
 module_init(ebt_log_init);
 module_exit(ebt_log_fini);
+MODULE_DESCRIPTION("Ebtables: Packet logging to syslog");
 MODULE_LICENSE("GPL");