]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/bridge/br_netfilter.c
[NETFILTER]: Replace sk_buff ** with sk_buff *
[net-next-2.6.git] / net / bridge / br_netfilter.c
index 9b2986b182ba0a7630ac30d0b3305d9fd6cc89b1..246bf23a8775c991578e9cc8519fc5d280ea310a 100644 (file)
@@ -142,14 +142,33 @@ static inline struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
        return skb->nf_bridge;
 }
 
-static inline void nf_bridge_save_header(struct sk_buff *skb)
+static inline void nf_bridge_push_encap_header(struct sk_buff *skb)
 {
-       int header_size = ETH_HLEN;
+       unsigned int len = nf_bridge_encap_header_len(skb);
 
-       if (skb->protocol == htons(ETH_P_8021Q))
-               header_size += VLAN_HLEN;
-       else if (skb->protocol == htons(ETH_P_PPP_SES))
-               header_size += PPPOE_SES_HLEN;
+       skb_push(skb, len);
+       skb->network_header -= len;
+}
+
+static inline void nf_bridge_pull_encap_header(struct sk_buff *skb)
+{
+       unsigned int len = nf_bridge_encap_header_len(skb);
+
+       skb_pull(skb, len);
+       skb->network_header += len;
+}
+
+static inline void nf_bridge_pull_encap_header_rcsum(struct sk_buff *skb)
+{
+       unsigned int len = nf_bridge_encap_header_len(skb);
+
+       skb_pull_rcsum(skb, len);
+       skb->network_header += len;
+}
+
+static inline void nf_bridge_save_header(struct sk_buff *skb)
+{
+       int header_size = ETH_HLEN + nf_bridge_encap_header_len(skb);
 
        skb_copy_from_linear_data_offset(skb, -header_size,
                                         skb->nf_bridge->data, header_size);
@@ -162,24 +181,15 @@ static inline void nf_bridge_save_header(struct sk_buff *skb)
 int nf_bridge_copy_header(struct sk_buff *skb)
 {
        int err;
-       int header_size = ETH_HLEN;
+       int header_size = ETH_HLEN + nf_bridge_encap_header_len(skb);
 
-       if (skb->protocol == htons(ETH_P_8021Q))
-               header_size += VLAN_HLEN;
-       else if (skb->protocol == htons(ETH_P_PPP_SES))
-               header_size += PPPOE_SES_HLEN;
-
-       err = skb_cow(skb, header_size);
+       err = skb_cow_head(skb, header_size);
        if (err)
                return err;
 
        skb_copy_to_linear_data_offset(skb, -header_size,
                                       skb->nf_bridge->data, header_size);
-
-       if (skb->protocol == htons(ETH_P_8021Q))
-               __skb_push(skb, VLAN_HLEN);
-       else if (skb->protocol == htons(ETH_P_PPP_SES))
-               __skb_push(skb, PPPOE_SES_HLEN);
+       __skb_push(skb, nf_bridge_encap_header_len(skb));
        return 0;
 }
 
@@ -200,13 +210,7 @@ static int br_nf_pre_routing_finish_ipv6(struct sk_buff *skb)
        dst_hold(skb->dst);
 
        skb->dev = nf_bridge->physindev;
-       if (skb->protocol == htons(ETH_P_8021Q)) {
-               skb_push(skb, VLAN_HLEN);
-               skb->network_header -= VLAN_HLEN;
-       } else if (skb->protocol == htons(ETH_P_PPP_SES)) {
-               skb_push(skb, PPPOE_SES_HLEN);
-               skb->network_header -= PPPOE_SES_HLEN;
-       }
+       nf_bridge_push_encap_header(skb);
        NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
                       br_handle_frame_finish, 1);
 
@@ -284,13 +288,7 @@ static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb)
        if (!skb->dev)
                kfree_skb(skb);
        else {
-               if (skb->protocol == htons(ETH_P_8021Q)) {
-                       skb_pull(skb, VLAN_HLEN);
-                       skb->network_header += VLAN_HLEN;
-               } else if (skb->protocol == htons(ETH_P_PPP_SES)) {
-                       skb_pull(skb, PPPOE_SES_HLEN);
-                       skb->network_header += PPPOE_SES_HLEN;
-               }
+               nf_bridge_pull_encap_header(skb);
                skb->dst->output(skb);
        }
        return 0;
@@ -356,15 +354,7 @@ bridged_dnat:
                                 * bridged frame */
                                nf_bridge->mask |= BRNF_BRIDGED_DNAT;
                                skb->dev = nf_bridge->physindev;
-                               if (skb->protocol ==
-                                   htons(ETH_P_8021Q)) {
-                                       skb_push(skb, VLAN_HLEN);
-                                       skb->network_header -= VLAN_HLEN;
-                               } else if(skb->protocol ==
-                                   htons(ETH_P_PPP_SES)) {
-                                       skb_push(skb, PPPOE_SES_HLEN);
-                                       skb->network_header -= PPPOE_SES_HLEN;
-                               }
+                               nf_bridge_push_encap_header(skb);
                                NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING,
                                               skb, skb->dev, NULL,
                                               br_nf_pre_routing_finish_bridge,
@@ -380,13 +370,7 @@ bridged_dnat:
        }
 
        skb->dev = nf_bridge->physindev;
-       if (skb->protocol == htons(ETH_P_8021Q)) {
-               skb_push(skb, VLAN_HLEN);
-               skb->network_header -= VLAN_HLEN;
-       } else if (skb->protocol == htons(ETH_P_PPP_SES)) {
-               skb_push(skb, PPPOE_SES_HLEN);
-               skb->network_header -= PPPOE_SES_HLEN;
-       }
+       nf_bridge_push_encap_header(skb);
        NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
                       br_handle_frame_finish, 1);
 
@@ -519,14 +503,19 @@ inhdr_error:
  * receiving device) to make netfilter happy, the REDIRECT
  * target in particular.  Save the original destination IP
  * address to be able to detect DNAT afterwards. */
-static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
+static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff *skb,
                                      const struct net_device *in,
                                      const struct net_device *out,
                                      int (*okfn)(struct sk_buff *))
 {
        struct iphdr *iph;
-       __u32 len;
-       struct sk_buff *skb = *pskb;
+       __u32 len = nf_bridge_encap_header_len(skb);
+
+       if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
+               return NF_STOLEN;
+
+       if (unlikely(!pskb_may_pull(skb, len)))
+               goto out;
 
        if (skb->protocol == htons(ETH_P_IPV6) || IS_VLAN_IPV6(skb) ||
            IS_PPPOE_IPV6(skb)) {
@@ -534,16 +523,7 @@ static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
                if (!brnf_call_ip6tables)
                        return NF_ACCEPT;
 #endif
-               if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
-                       goto out;
-
-               if (skb->protocol == htons(ETH_P_8021Q)) {
-                       skb_pull_rcsum(skb, VLAN_HLEN);
-                       skb->network_header += VLAN_HLEN;
-               } else if (skb->protocol == htons(ETH_P_PPP_SES)) {
-                       skb_pull_rcsum(skb, PPPOE_SES_HLEN);
-                       skb->network_header += PPPOE_SES_HLEN;
-               }
+               nf_bridge_pull_encap_header_rcsum(skb);
                return br_nf_pre_routing_ipv6(hook, skb, in, out, okfn);
        }
 #ifdef CONFIG_SYSCTL
@@ -555,16 +535,7 @@ static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
            !IS_PPPOE_IP(skb))
                return NF_ACCEPT;
 
-       if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
-               goto out;
-
-       if (skb->protocol == htons(ETH_P_8021Q)) {
-               skb_pull_rcsum(skb, VLAN_HLEN);
-               skb->network_header += VLAN_HLEN;
-       } else if (skb->protocol == htons(ETH_P_PPP_SES)) {
-               skb_pull_rcsum(skb, PPPOE_SES_HLEN);
-               skb->network_header += PPPOE_SES_HLEN;
-       }
+       nf_bridge_pull_encap_header_rcsum(skb);
 
        if (!pskb_may_pull(skb, sizeof(struct iphdr)))
                goto inhdr_error;
@@ -612,13 +583,11 @@ out:
  * took place when the packet entered the bridge), but we
  * register an IPv4 PRE_ROUTING 'sabotage' hook that will
  * prevent this from happening. */
-static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff **pskb,
+static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff *skb,
                                   const struct net_device *in,
                                   const struct net_device *out,
                                   int (*okfn)(struct sk_buff *))
 {
-       struct sk_buff *skb = *pskb;
-
        if (skb->dst == (struct dst_entry *)&__fake_rtable) {
                dst_release(skb->dst);
                skb->dst = NULL;
@@ -642,13 +611,7 @@ static int br_nf_forward_finish(struct sk_buff *skb)
        } else {
                in = *((struct net_device **)(skb->cb));
        }
-       if (skb->protocol == htons(ETH_P_8021Q)) {
-               skb_push(skb, VLAN_HLEN);
-               skb->network_header -= VLAN_HLEN;
-       } else if (skb->protocol == htons(ETH_P_PPP_SES)) {
-               skb_push(skb, PPPOE_SES_HLEN);
-               skb->network_header -= PPPOE_SES_HLEN;
-       }
+       nf_bridge_push_encap_header(skb);
        NF_HOOK_THRESH(PF_BRIDGE, NF_BR_FORWARD, skb, in,
                       skb->dev, br_forward_finish, 1);
        return 0;
@@ -659,12 +622,11 @@ static int br_nf_forward_finish(struct sk_buff *skb)
  * but we are still able to filter on the 'real' indev/outdev
  * because of the physdev module. For ARP, indev and outdev are the
  * bridge ports. */
-static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff **pskb,
+static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff *skb,
                                     const struct net_device *in,
                                     const struct net_device *out,
                                     int (*okfn)(struct sk_buff *))
 {
-       struct sk_buff *skb = *pskb;
        struct nf_bridge_info *nf_bridge;
        struct net_device *parent;
        int pf;
@@ -682,13 +644,7 @@ static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff **pskb,
        else
                pf = PF_INET6;
 
-       if (skb->protocol == htons(ETH_P_8021Q)) {
-               skb_pull(*pskb, VLAN_HLEN);
-               (*pskb)->network_header += VLAN_HLEN;
-       } else if (skb->protocol == htons(ETH_P_PPP_SES)) {
-               skb_pull(*pskb, PPPOE_SES_HLEN);
-               (*pskb)->network_header += PPPOE_SES_HLEN;
-       }
+       nf_bridge_pull_encap_header(skb);
 
        nf_bridge = skb->nf_bridge;
        if (skb->pkt_type == PACKET_OTHERHOST) {
@@ -706,12 +662,11 @@ static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff **pskb,
        return NF_STOLEN;
 }
 
-static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff **pskb,
+static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff *skb,
                                      const struct net_device *in,
                                      const struct net_device *out,
                                      int (*okfn)(struct sk_buff *))
 {
-       struct sk_buff *skb = *pskb;
        struct net_device **d = (struct net_device **)(skb->cb);
 
 #ifdef CONFIG_SYSCTL
@@ -722,15 +677,12 @@ static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff **pskb,
        if (skb->protocol != htons(ETH_P_ARP)) {
                if (!IS_VLAN_ARP(skb))
                        return NF_ACCEPT;
-               skb_pull(*pskb, VLAN_HLEN);
-               (*pskb)->network_header += VLAN_HLEN;
+               nf_bridge_pull_encap_header(skb);
        }
 
        if (arp_hdr(skb)->ar_pln != 4) {
-               if (IS_VLAN_ARP(skb)) {
-                       skb_push(*pskb, VLAN_HLEN);
-                       (*pskb)->network_header -= VLAN_HLEN;
-               }
+               if (IS_VLAN_ARP(skb))
+                       nf_bridge_push_encap_header(skb);
                return NF_ACCEPT;
        }
        *d = (struct net_device *)in;
@@ -752,13 +704,12 @@ static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff **pskb,
  * NF_BR_PRI_FIRST, so no relevant PF_BRIDGE/INPUT functions have been nor
  * will be executed.
  */
-static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff **pskb,
+static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff *skb,
                                    const struct net_device *in,
                                    const struct net_device *out,
                                    int (*okfn)(struct sk_buff *))
 {
        struct net_device *realindev;
-       struct sk_buff *skb = *pskb;
        struct nf_bridge_info *nf_bridge;
 
        if (!skb->nf_bridge)
@@ -777,13 +728,7 @@ static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff **pskb,
                skb->pkt_type = PACKET_OTHERHOST;
                nf_bridge->mask ^= BRNF_PKT_TYPE;
        }
-       if (skb->protocol == htons(ETH_P_8021Q)) {
-               skb_push(skb, VLAN_HLEN);
-               skb->network_header -= VLAN_HLEN;
-       } else if (skb->protocol == htons(ETH_P_PPP_SES)) {
-               skb_push(skb, PPPOE_SES_HLEN);
-               skb->network_header -= PPPOE_SES_HLEN;
-       }
+       nf_bridge_push_encap_header(skb);
 
        NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, realindev, skb->dev,
                br_forward_finish);
@@ -801,13 +746,12 @@ static int br_nf_dev_queue_xmit(struct sk_buff *skb)
 }
 
 /* PF_BRIDGE/POST_ROUTING ********************************************/
-static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb,
+static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff *skb,
                                       const struct net_device *in,
                                       const struct net_device *out,
                                       int (*okfn)(struct sk_buff *))
 {
-       struct sk_buff *skb = *pskb;
-       struct nf_bridge_info *nf_bridge = (*pskb)->nf_bridge;
+       struct nf_bridge_info *nf_bridge = skb->nf_bridge;
        struct net_device *realoutdev = bridge_parent(skb->dev);
        int pf;
 
@@ -848,14 +792,7 @@ static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb,
                nf_bridge->mask |= BRNF_PKT_TYPE;
        }
 
-       if (skb->protocol == htons(ETH_P_8021Q)) {
-               skb_pull(skb, VLAN_HLEN);
-               skb->network_header += VLAN_HLEN;
-       } else if (skb->protocol == htons(ETH_P_PPP_SES)) {
-               skb_pull(skb, PPPOE_SES_HLEN);
-               skb->network_header += PPPOE_SES_HLEN;
-       }
-
+       nf_bridge_pull_encap_header(skb);
        nf_bridge_save_header(skb);
 
 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
@@ -884,13 +821,13 @@ print_error:
 /* IP/SABOTAGE *****************************************************/
 /* Don't hand locally destined packets to PF_INET(6)/PRE_ROUTING
  * for the second time. */
-static unsigned int ip_sabotage_in(unsigned int hook, struct sk_buff **pskb,
+static unsigned int ip_sabotage_in(unsigned int hook, struct sk_buff *skb,
                                   const struct net_device *in,
                                   const struct net_device *out,
                                   int (*okfn)(struct sk_buff *))
 {
-       if ((*pskb)->nf_bridge &&
-           !((*pskb)->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) {
+       if (skb->nf_bridge &&
+           !(skb->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) {
                return NF_STOP;
        }
 
@@ -960,7 +897,6 @@ int brnf_sysctl_call_tables(ctl_table * ctl, int write, struct file *filp,
 
 static ctl_table brnf_table[] = {
        {
-               .ctl_name       = NET_BRIDGE_NF_CALL_ARPTABLES,
                .procname       = "bridge-nf-call-arptables",
                .data           = &brnf_call_arptables,
                .maxlen         = sizeof(int),
@@ -968,7 +904,6 @@ static ctl_table brnf_table[] = {
                .proc_handler   = &brnf_sysctl_call_tables,
        },
        {
-               .ctl_name       = NET_BRIDGE_NF_CALL_IPTABLES,
                .procname       = "bridge-nf-call-iptables",
                .data           = &brnf_call_iptables,
                .maxlen         = sizeof(int),
@@ -976,7 +911,6 @@ static ctl_table brnf_table[] = {
                .proc_handler   = &brnf_sysctl_call_tables,
        },
        {
-               .ctl_name       = NET_BRIDGE_NF_CALL_IP6TABLES,
                .procname       = "bridge-nf-call-ip6tables",
                .data           = &brnf_call_ip6tables,
                .maxlen         = sizeof(int),
@@ -984,7 +918,6 @@ static ctl_table brnf_table[] = {
                .proc_handler   = &brnf_sysctl_call_tables,
        },
        {
-               .ctl_name       = NET_BRIDGE_NF_FILTER_VLAN_TAGGED,
                .procname       = "bridge-nf-filter-vlan-tagged",
                .data           = &brnf_filter_vlan_tagged,
                .maxlen         = sizeof(int),
@@ -992,7 +925,6 @@ static ctl_table brnf_table[] = {
                .proc_handler   = &brnf_sysctl_call_tables,
        },
        {
-               .ctl_name       = NET_BRIDGE_NF_FILTER_PPPOE_TAGGED,
                .procname       = "bridge-nf-filter-pppoe-tagged",
                .data           = &brnf_filter_pppoe_tagged,
                .maxlen         = sizeof(int),