reader: Simplify IP handling in work function
authorReto Buerki <reet@codelabs.ch>
Fri, 22 May 2015 12:34:57 +0000 (14:34 +0200)
committerReto Buerki <reet@codelabs.ch>
Thu, 11 Jun 2015 07:11:37 +0000 (09:11 +0200)
reader.c

index 3e79c2c..3255622 100644 (file)
--- a/reader.c
+++ b/reader.c
@@ -148,24 +148,18 @@ static void muennet_reader_work(struct work_struct *work)
                                skb_reserve(skb, sizeof(struct net_hdr));
                                switch (hdr->protocol) {
                                case IPPROTO_IPIP:
+                                       ipv4_hdr = (struct iphdr *)skb->data;
                                        protocol = htons(ETH_P_IP);
+                                       len = be16_to_cpu(ipv4_hdr->tot_len);
                                        break;
                                case IPPROTO_IPV6:
+                                       ipv6_hdr = (struct ipv6hdr *)skb->data;
                                        protocol = htons(ETH_P_IPV6);
+                                       len = be16_to_cpu(ipv6_hdr->payload_len)
+                                               + 40;
                                        break;
                                }
-                       }
-
-                       /* read the data to determine the protocol */
-                       ipv4_hdr = (void *)skb->data;
-                       ipv6_hdr = (void *)skb->data;
-
-                       /* determine the payload length */
-                       if (protocol == htons(ETH_P_IP))
-                               len = be16_to_cpu(ipv4_hdr->tot_len);
-                       else if (protocol == htons(ETH_P_IPV6))
-                               len = be16_to_cpu(ipv6_hdr->payload_len) + 40;
-                       else
+                       } else
                                len = dev_info->reader_element_size;
 
                        if (len > dev_info->reader_element_size ||