]> err.no Git - linux-2.6/blobdiff - net/ipv4/netfilter/nf_nat_proto_gre.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/djbw/async_tx
[linux-2.6] / net / ipv4 / netfilter / nf_nat_proto_gre.c
index d3de579e09d225e32f2b01693830890c6aab3e70..d7e89201351e90d01bbbac1666e913f90e036dbf 100644 (file)
@@ -36,49 +36,29 @@ MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
 MODULE_DESCRIPTION("Netfilter NAT protocol helper module for GRE");
 
-#if 0
-#define DEBUGP(format, args...) printk(KERN_DEBUG "%s:%s: " format, __FILE__, \
-                                      __FUNCTION__, ## args)
-#else
-#define DEBUGP(x, args...)
-#endif
-
-/* is key in given range between min and max */
-static int
-gre_in_range(const struct nf_conntrack_tuple *tuple,
-            enum nf_nat_manip_type maniptype,
-            const union nf_conntrack_man_proto *min,
-            const union nf_conntrack_man_proto *max)
-{
-       __be16 key;
-
-       if (maniptype == IP_NAT_MANIP_SRC)
-               key = tuple->src.u.gre.key;
-       else
-               key = tuple->dst.u.gre.key;
-
-       return ntohs(key) >= ntohs(min->gre.key) &&
-              ntohs(key) <= ntohs(max->gre.key);
-}
-
 /* generate unique tuple ... */
-static int
+static bool
 gre_unique_tuple(struct nf_conntrack_tuple *tuple,
                 const struct nf_nat_range *range,
                 enum nf_nat_manip_type maniptype,
-                const struct nf_conn *conntrack)
+                const struct nf_conn *ct)
 {
        static u_int16_t key;
        __be16 *keyptr;
        unsigned int min, i, range_size;
 
+       /* If there is no master conntrack we are not PPTP,
+          do not change tuples */
+       if (!ct->master)
+               return false;
+
        if (maniptype == IP_NAT_MANIP_SRC)
                keyptr = &tuple->src.u.gre.key;
        else
                keyptr = &tuple->dst.u.gre.key;
 
        if (!(range->flags & IP_NAT_RANGE_PROTO_SPECIFIED)) {
-               DEBUGP("%p: NATing GRE PPTP\n", conntrack);
+               pr_debug("%p: NATing GRE PPTP\n", ct);
                min = 1;
                range_size = 0xffff;
        } else {
@@ -86,85 +66,75 @@ gre_unique_tuple(struct nf_conntrack_tuple *tuple,
                range_size = ntohs(range->max.gre.key) - min + 1;
        }
 
-       DEBUGP("min = %u, range_size = %u\n", min, range_size);
+       pr_debug("min = %u, range_size = %u\n", min, range_size);
 
        for (i = 0; i < range_size; i++, key++) {
                *keyptr = htons(min + key % range_size);
-               if (!nf_nat_used_tuple(tuple, conntrack))
-                       return 1;
+               if (!nf_nat_used_tuple(tuple, ct))
+                       return true;
        }
 
-       DEBUGP("%p: no NAT mapping\n", conntrack);
-       return 0;
+       pr_debug("%p: no NAT mapping\n", ct);
+       return false;
 }
 
 /* manipulate a GRE packet according to maniptype */
-static int
-gre_manip_pkt(struct sk_buff **pskb, unsigned int iphdroff,
+static bool
+gre_manip_pkt(struct sk_buff *skb, unsigned int iphdroff,
              const struct nf_conntrack_tuple *tuple,
              enum nf_nat_manip_type maniptype)
 {
-       struct gre_hdr *greh;
+       const struct gre_hdr *greh;
        struct gre_hdr_pptp *pgreh;
-       struct iphdr *iph = (struct iphdr *)((*pskb)->data + iphdroff);
+       const struct iphdr *iph = (struct iphdr *)(skb->data + iphdroff);
        unsigned int hdroff = iphdroff + iph->ihl * 4;
 
        /* pgreh includes two optional 32bit fields which are not required
         * to be there.  That's where the magic '8' comes from */
-       if (!skb_make_writable(pskb, hdroff + sizeof(*pgreh) - 8))
-               return 0;
+       if (!skb_make_writable(skb, hdroff + sizeof(*pgreh) - 8))
+               return false;
 
-       greh = (void *)(*pskb)->data + hdroff;
+       greh = (void *)skb->data + hdroff;
        pgreh = (struct gre_hdr_pptp *)greh;
 
        /* we only have destination manip of a packet, since 'source key'
         * is not present in the packet itself */
        if (maniptype != IP_NAT_MANIP_DST)
-               return 1;
+               return true;
        switch (greh->version) {
-       case 0:
-               if (!greh->key) {
-                       DEBUGP("can't nat GRE w/o key\n");
-                       break;
-               }
-               if (greh->csum) {
-                       /* FIXME: Never tested this code... */
-                       nf_proto_csum_replace4(gre_csum(greh), *pskb,
-                                              *(gre_key(greh)),
-                                              tuple->dst.u.gre.key, 0);
-               }
-               *(gre_key(greh)) = tuple->dst.u.gre.key;
+       case GRE_VERSION_1701:
+               /* We do not currently NAT any GREv0 packets.
+                * Try to behave like "nf_nat_proto_unknown" */
                break;
        case GRE_VERSION_PPTP:
-               DEBUGP("call_id -> 0x%04x\n", ntohs(tuple->dst.u.gre.key));
+               pr_debug("call_id -> 0x%04x\n", ntohs(tuple->dst.u.gre.key));
                pgreh->call_id = tuple->dst.u.gre.key;
                break;
        default:
-               DEBUGP("can't nat unknown GRE version\n");
-               return 0;
+               pr_debug("can't nat unknown GRE version\n");
+               return false;
        }
-       return 1;
+       return true;
 }
 
-static struct nf_nat_protocol gre __read_mostly = {
-       .name                   = "GRE",
+static const struct nf_nat_protocol gre = {
        .protonum               = IPPROTO_GRE,
+       .me                     = THIS_MODULE,
        .manip_pkt              = gre_manip_pkt,
-       .in_range               = gre_in_range,
+       .in_range               = nf_nat_proto_in_range,
        .unique_tuple           = gre_unique_tuple,
-#if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
-    defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
-       .range_to_nfattr        = nf_nat_port_range_to_nfattr,
-       .nfattr_to_range        = nf_nat_port_nfattr_to_range,
+#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
+       .range_to_nlattr        = nf_nat_proto_range_to_nlattr,
+       .nlattr_to_range        = nf_nat_proto_nlattr_to_range,
 #endif
 };
 
-int __init nf_nat_proto_gre_init(void)
+static int __init nf_nat_proto_gre_init(void)
 {
        return nf_nat_protocol_register(&gre);
 }
 
-void __exit nf_nat_proto_gre_fini(void)
+static void __exit nf_nat_proto_gre_fini(void)
 {
        nf_nat_protocol_unregister(&gre);
 }