]> err.no Git - linux-2.6/commitdiff
[NETFILTER] bridge: code rearrangement for clarity
authorStephen Hemminger <shemminger@osdl.org>
Wed, 30 Aug 2006 00:48:17 +0000 (17:48 -0700)
committerDavid S. Miller <davem@sunset.davemloft.net>
Fri, 22 Sep 2006 22:18:30 +0000 (15:18 -0700)
Cleanup and rearrangement for better style and clarity:
Split the function nf_bridge_maybe_copy_header into two pieces
Move copy portion out of line.
Use Ethernet header size macros.
Use header file to handle CONFIG_NETFILTER_BRIDGE differences

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/netfilter_bridge.h
net/bridge/br_forward.c
net/bridge/br_netfilter.c

index 427c67ff89e98196498a9f85982699b11b2cd777..274fe4b331555733658e25c173d723a837ff70aa 100644 (file)
@@ -47,26 +47,12 @@ enum nf_br_hook_priorities {
 
 
 /* Only used in br_forward.c */
-static inline
-int nf_bridge_maybe_copy_header(struct sk_buff *skb)
+extern int nf_bridge_copy_header(struct sk_buff *skb);
+static inline int nf_bridge_maybe_copy_header(struct sk_buff *skb)
 {
-       int err;
-
-       if (skb->nf_bridge) {
-               if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
-                       err = skb_cow(skb, 18);
-                       if (err)
-                               return err;
-                       memcpy(skb->data - 18, skb->nf_bridge->data, 18);
-                       skb_push(skb, 4);
-               } else {
-                       err = skb_cow(skb, 16);
-                       if (err)
-                               return err;
-                       memcpy(skb->data - 16, skb->nf_bridge->data, 16);
-               }
-       }
-       return 0;
+       if (skb->nf_bridge)
+               return nf_bridge_copy_header(skb);
+       return 0;
 }
 
 /* This is called by the IP fragmenting code and it ensures there is
@@ -90,6 +76,8 @@ struct bridge_skb_cb {
 };
 
 extern int brnf_deferred_hooks;
+#else
+#define nf_bridge_maybe_copy_header(skb)       (0)
 #endif /* CONFIG_BRIDGE_NETFILTER */
 
 #endif /* __KERNEL__ */
index 864fbbc7b24d0eb1d9769723cdf385c60aba410c..191b861e5e53c25b176d1d36c1475cc6406ee5ae 100644 (file)
@@ -38,13 +38,10 @@ int br_dev_queue_push_xmit(struct sk_buff *skb)
        if (packet_length(skb) > skb->dev->mtu && !skb_is_gso(skb))
                kfree_skb(skb);
        else {
-#ifdef CONFIG_BRIDGE_NETFILTER
                /* ip_refrag calls ip_fragment, doesn't copy the MAC header. */
                if (nf_bridge_maybe_copy_header(skb))
                        kfree_skb(skb);
-               else
-#endif
-               {
+               else {
                        skb_push(skb, ETH_HLEN);
 
                        dev_queue_xmit(skb);
index 05b3de88824362fd797c1fe3309567520cc163df..b498efcfe451b0e74c38e94626777292c23688bc 100644 (file)
@@ -127,14 +127,37 @@ static inline struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
 
 static inline void nf_bridge_save_header(struct sk_buff *skb)
 {
-        int header_size = 16;
+        int header_size = ETH_HLEN;
 
        if (skb->protocol == htons(ETH_P_8021Q))
-               header_size = 18;
+               header_size += VLAN_HLEN;
 
        memcpy(skb->nf_bridge->data, skb->data - header_size, header_size);
 }
 
+/*
+ * When forwarding bridge frames, we save a copy of the original
+ * header before processing.
+ */
+int nf_bridge_copy_header(struct sk_buff *skb)
+{
+       int err;
+        int header_size = ETH_HLEN;
+
+       if (skb->protocol == htons(ETH_P_8021Q))
+               header_size += VLAN_HLEN;
+
+       err = skb_cow(skb, header_size);
+       if (err)
+               return err;
+
+       memcpy(skb->data - header_size, skb->nf_bridge->data, header_size);
+
+       if (skb->protocol == htons(ETH_P_8021Q))
+               __skb_push(skb, VLAN_HLEN);
+       return 0;
+}
+
 /* PF_BRIDGE/PRE_ROUTING *********************************************/
 /* Undo the changes made for ip6tables PREROUTING and continue the
  * bridge PRE_ROUTING hook. */