]> err.no Git - linux-2.6/commitdiff
[IP]: Introduce ip_hdrlen()
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 12 Mar 2007 23:09:15 +0000 (20:09 -0300)
committerDavid S. Miller <davem@sunset.davemloft.net>
Thu, 26 Apr 2007 05:25:07 +0000 (22:25 -0700)
For the common sequence "skb->nh.iph->ihl * 4", removing a good number of open
coded skb->nh.iph uses, now to go after the rest...

Just out of curiosity, here are the idioms found to get the same result:

skb->nh.iph->ihl << 2
skb->nh.iph->ihl<<2
skb->nh.iph->ihl * 4
skb->nh.iph->ihl*4
(skb->nh.iph)->ihl * sizeof(u32)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
47 files changed:
drivers/net/bnx2.c
drivers/net/ehea/ehea_main.c
drivers/net/netxen/netxen_nic_hw.c
drivers/net/netxen/netxen_nic_main.c
drivers/net/sky2.c
drivers/net/tg3.c
drivers/s390/net/qeth_eddp.c
include/net/ip.h
net/ipv4/ip_fragment.c
net/ipv4/ip_input.c
net/ipv4/ipmr.c
net/ipv4/ipvs/ip_vs_app.c
net/ipv4/ipvs/ip_vs_core.c
net/ipv4/ipvs/ip_vs_proto_tcp.c
net/ipv4/ipvs/ip_vs_proto_udp.c
net/ipv4/netfilter/ip_conntrack_amanda.c
net/ipv4/netfilter/ip_conntrack_core.c
net/ipv4/netfilter/ip_conntrack_ftp.c
net/ipv4/netfilter/ip_conntrack_helper_h323.c
net/ipv4/netfilter/ip_conntrack_helper_pptp.c
net/ipv4/netfilter/ip_conntrack_irc.c
net/ipv4/netfilter/ip_conntrack_proto_icmp.c
net/ipv4/netfilter/ip_conntrack_proto_sctp.c
net/ipv4/netfilter/ip_conntrack_proto_tcp.c
net/ipv4/netfilter/ip_conntrack_sip.c
net/ipv4/netfilter/ip_conntrack_standalone.c
net/ipv4/netfilter/ip_conntrack_tftp.c
net/ipv4/netfilter/ip_nat_core.c
net/ipv4/netfilter/ip_nat_helper.c
net/ipv4/netfilter/ip_nat_helper_h323.c
net/ipv4/netfilter/ip_nat_sip.c
net/ipv4/netfilter/ip_nat_standalone.c
net/ipv4/netfilter/ip_tables.c
net/ipv4/netfilter/ipt_ECN.c
net/ipv4/netfilter/ipt_REJECT.c
net/ipv4/netfilter/ipt_ecn.c
net/ipv4/netfilter/iptable_filter.c
net/ipv4/netfilter/iptable_mangle.c
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
net/ipv4/netfilter/nf_conntrack_proto_icmp.c
net/ipv4/netfilter/nf_nat_core.c
net/ipv4/netfilter/nf_nat_h323.c
net/ipv4/netfilter/nf_nat_helper.c
net/ipv4/netfilter/nf_nat_sip.c
net/ipv4/netfilter/nf_nat_standalone.c
net/ipv6/netfilter/ip6table_filter.c
net/ipv6/netfilter/ip6table_mangle.c

index e85f5ec48f96fdd092eb39311781ceaf9c5facff..b8091c55d441dfa070b45f8538c51b206b53de83 100644 (file)
@@ -4527,7 +4527,7 @@ bnx2_start_xmit(struct sk_buff *skb, struct net_device *dev)
                if (skb->h.th->doff > 5) {
                        tcp_opt_len = (skb->h.th->doff - 5) << 2;
                }
-               ip_tcp_len = (skb->nh.iph->ihl << 2) + sizeof(struct tcphdr);
+               ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
 
                skb->nh.iph->check = 0;
                skb->nh.iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len);
index 0e4042bc0a48e44c570b54b7e205ff3a8a8e58eb..b1c90a4fe31e04f14082e3567903a67f574773ba 100644 (file)
@@ -1263,7 +1263,7 @@ static inline void write_ip_start_end(struct ehea_swqe *swqe,
                                      const struct sk_buff *skb)
 {
        swqe->ip_start = (u8)(((u64)skb->nh.iph) - ((u64)skb->data));
-       swqe->ip_end = (u8)(swqe->ip_start + skb->nh.iph->ihl * 4 - 1);
+       swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
 }
 
 static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
@@ -1300,7 +1300,7 @@ static void write_swqe2_TSO(struct sk_buff *skb,
        /* copy only eth/ip/tcp headers to immediate data and
         * the rest of skb->data to sg1entry
         */
-       headersize = ETH_HLEN + (skb->nh.iph->ihl * 4) + (skb->h.th->doff * 4);
+       headersize = ETH_HLEN + ip_hdrlen(skb) + (skb->h.th->doff * 4);
 
        skb_data_size = skb->len - skb->data_len;
 
index 625e11ed6aae565f725f9073cb2e0133e342dda5..b2f5032937e3376bcacb0c796e3ab3d96a355339 100644 (file)
@@ -35,6 +35,8 @@
 #include "netxen_nic_hw.h"
 #include "netxen_nic_phan_reg.h"
 
+#include <net/ip.h>
+
 /*  PCI Windowing for DDR regions.  */
 
 #define ADDR_IN_RANGE(addr, low, high) \
@@ -371,9 +373,9 @@ void netxen_tso_check(struct netxen_adapter *adapter,
                      struct cmd_desc_type0 *desc, struct sk_buff *skb)
 {
        if (desc->mss) {
-               desc->total_hdr_length = sizeof(struct ethhdr) +
-                   ((skb->nh.iph)->ihl * sizeof(u32)) +
-                   ((skb->h.th)->doff * sizeof(u32));
+               desc->total_hdr_length = (sizeof(struct ethhdr) +
+                                         ip_hdrlen(skb) +
+                                         skb->h.th->doff * 4);
                netxen_set_cmd_desc_opcode(desc, TX_TCP_LSO);
        } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
                if (skb->nh.iph->protocol == IPPROTO_TCP) {
index 7d2525e76abbedcbc6cf1584c3207239b40c8944..b548a30e5c8eea4b7d62d42fbb89feb99b6a202c 100644 (file)
@@ -41,6 +41,7 @@
 
 #include <linux/dma-mapping.h>
 #include <linux/vmalloc.h>
+#include <net/ip.h>
 
 MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver");
 MODULE_LICENSE("GPL");
@@ -778,9 +779,8 @@ static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
                if (skb_shinfo(skb)->gso_size > 0) {
 
                        no_of_desc++;
-                       if (((skb->nh.iph)->ihl * sizeof(u32)) +
-                           ((skb->h.th)->doff * sizeof(u32)) +
-                           sizeof(struct ethhdr) >
+                       if ((ip_hdrlen(skb) + skb->h.th->doff * 4 +
+                            sizeof(struct ethhdr)) >
                            (sizeof(struct cmd_desc_type0) - 2)) {
                                no_of_desc++;
                        }
index ac36152c68bf1261206e86f5373ff5eac21b09a7..51e994f26a844ffeccc573c09f98354707300ebc 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/ethtool.h>
 #include <linux/pci.h>
 #include <linux/ip.h>
+#include <net/ip.h>
 #include <linux/tcp.h>
 #include <linux/in.h>
 #include <linux/delay.h>
@@ -1392,7 +1393,7 @@ static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
        mss = skb_shinfo(skb)->gso_size;
        if (mss != 0) {
                mss += ((skb->h.th->doff - 5) * 4);     /* TCP options */
-               mss += (skb->nh.iph->ihl * 4) + sizeof(struct tcphdr);
+               mss += ip_hdrlen(skb) + sizeof(struct tcphdr);
                mss += ETH_HLEN;
 
                if (mss != sky2->tx_last_mss) {
index 256969e1300c9f36fa29cff47977dd006dfde452..62a3bba0097d8114ae980a5b3f49e02cb7605806 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/dma-mapping.h>
 
 #include <net/checksum.h>
+#include <net/ip.h>
 
 #include <asm/system.h>
 #include <asm/io.h>
@@ -3909,8 +3910,7 @@ static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
                        mss |= (skb_headlen(skb) - ETH_HLEN) << 9;
                else {
                        tcp_opt_len = ((skb->h.th->doff - 5) * 4);
-                       ip_tcp_len = (skb->nh.iph->ihl * 4) +
-                                    sizeof(struct tcphdr);
+                       ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
 
                        skb->nh.iph->check = 0;
                        skb->nh.iph->tot_len = htons(mss + ip_tcp_len +
@@ -4064,7 +4064,7 @@ static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
                }
 
                tcp_opt_len = ((skb->h.th->doff - 5) * 4);
-               ip_tcp_len = (skb->nh.iph->ihl * 4) + sizeof(struct tcphdr);
+               ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
 
                hdr_len = ip_tcp_len + tcp_opt_len;
                if (unlikely((ETH_HLEN + hdr_len) > 80) &&
index 893125403c685b9fb92c39b7d16850520f0dd414..1574247abaa17f62e0aa7674442b181b64a04ae8 100644 (file)
@@ -473,9 +473,11 @@ qeth_eddp_fill_context_tcp(struct qeth_eddp_context *ctx,
        QETH_DBF_TEXT(trace, 5, "eddpficx");
        /* create our segmentation headers and copy original headers */
        if (skb->protocol == htons(ETH_P_IP))
-               eddp = qeth_eddp_create_eddp_data(qhdr, (u8 *)skb->nh.iph,
-                               skb->nh.iph->ihl*4,
-                               (u8 *)skb->h.th, skb->h.th->doff*4);
+               eddp = qeth_eddp_create_eddp_data(qhdr,
+                                                 skb_network_header(skb),
+                                                 ip_hdrlen(skb),
+                                                 skb->h.raw,
+                                                 skb->h.th->doff * 4);
        else
                eddp = qeth_eddp_create_eddp_data(qhdr, (u8 *)skb->nh.ipv6h,
                                sizeof(struct ipv6hdr),
@@ -590,8 +592,9 @@ qeth_eddp_create_context_tcp(struct qeth_card *card, struct sk_buff *skb,
        QETH_DBF_TEXT(trace, 5, "creddpct");
        if (skb->protocol == htons(ETH_P_IP))
                ctx = qeth_eddp_create_context_generic(card, skb,
-                       sizeof(struct qeth_hdr) + skb->nh.iph->ihl*4 +
-                       skb->h.th->doff*4);
+                                                      (sizeof(struct qeth_hdr) +
+                                                       ip_hdrlen(skb) +
+                                                       skb->h.th->doff * 4));
        else if (skb->protocol == htons(ETH_P_IPV6))
                ctx = qeth_eddp_create_context_generic(card, skb,
                        sizeof(struct qeth_hdr) + sizeof(struct ipv6hdr) +
index e79c3e3aa4f61f8bc1bf3dc7f579a2193af06848..6f7ba32b199dc38770f27f28dc6c08fe2785f7a8 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/types.h>
 #include <linux/ip.h>
 #include <linux/in.h>
+#include <linux/skbuff.h>
 
 #include <net/inet_sock.h>
 #include <net/snmp.h>
@@ -43,6 +44,11 @@ struct inet_skb_parm
 #define IPSKB_REROUTED         16
 };
 
+static inline unsigned int ip_hdrlen(const struct sk_buff *skb)
+{
+       return skb->nh.iph->ihl * 4;
+}
+
 struct ipcm_cookie
 {
        __be32                  addr;
@@ -74,7 +80,6 @@ struct msghdr;
 struct net_device;
 struct packet_type;
 struct rtable;
-struct sk_buff;
 struct sockaddr;
 
 extern void            ip_mc_dropsocket(struct sock *);
index 268a6c7347f29dbbe9716ea3ae37767fea653f95..af120b2d5331f9cd8284a67f07aaf0a12fce356f 100644 (file)
@@ -483,7 +483,7 @@ static void ip_frag_queue(struct ipq *qp, struct sk_buff *skb)
        flags = offset & ~IP_OFFSET;
        offset &= IP_OFFSET;
        offset <<= 3;           /* offset is in 8-byte chunks */
-       ihl = skb->nh.iph->ihl * 4;
+       ihl = ip_hdrlen(skb);
 
        /* Determine the position of this fragment. */
        end = offset + skb->len - ihl;
@@ -624,7 +624,7 @@ static struct sk_buff *ip_frag_reasm(struct ipq *qp, struct net_device *dev)
        BUG_TRAP(FRAG_CB(head)->offset == 0);
 
        /* Allocate a new buffer for the datagram. */
-       ihlen = head->nh.iph->ihl*4;
+       ihlen = ip_hdrlen(head);
        len = ihlen + qp->len;
 
        if (len > 65535)
index f38e97647ac043878d21f636657d0f919ca5cee3..2ee132b330fd62e84b49c9e0544aea908553daa1 100644 (file)
@@ -198,9 +198,7 @@ int ip_call_ra_chain(struct sk_buff *skb)
 
 static inline int ip_local_deliver_finish(struct sk_buff *skb)
 {
-       int ihl = skb->nh.iph->ihl*4;
-
-       __skb_pull(skb, ihl);
+       __skb_pull(skb, ip_hdrlen(skb));
 
        /* Point into the IP datagram, just past the header. */
        skb->h.raw = skb->data;
index aba3ff0bec9764de4dda0ea4621c096da58ecdbf..54b7543190f1eec06b8d487cc26dc3d4b59bab44 100644 (file)
@@ -539,7 +539,7 @@ static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c)
 static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert)
 {
        struct sk_buff *skb;
-       int ihl = pkt->nh.iph->ihl<<2;
+       const int ihl = ip_hdrlen(pkt);
        struct igmphdr *igmp;
        struct igmpmsg *msg;
        int ret;
index f29d3a27eec62cf7c0eaab0f05eb402ee99bb65d..e5beab28cd0f1e38cb324874b071b14e06f71d52 100644 (file)
@@ -331,7 +331,7 @@ static inline int app_tcp_pkt_out(struct ip_vs_conn *cp, struct sk_buff **pskb,
                                  struct ip_vs_app *app)
 {
        int diff;
-       unsigned int tcp_offset = (*pskb)->nh.iph->ihl*4;
+       const unsigned int tcp_offset = ip_hdrlen(*pskb);
        struct tcphdr *th;
        __u32 seq;
 
@@ -406,7 +406,7 @@ static inline int app_tcp_pkt_in(struct ip_vs_conn *cp, struct sk_buff **pskb,
                                 struct ip_vs_app *app)
 {
        int diff;
-       unsigned int tcp_offset = (*pskb)->nh.iph->ihl*4;
+       const unsigned int tcp_offset = ip_hdrlen(*pskb);
        struct tcphdr *th;
        __u32 seq;
 
index 5d54dd2ce12fc91da568a4f6dc852d7558d5d2b3..7893c00a91fe78eac73011fe95ab1e42193eb898 100644 (file)
@@ -713,8 +713,7 @@ static inline int is_tcp_reset(const struct sk_buff *skb)
 {
        struct tcphdr _tcph, *th;
 
-       th = skb_header_pointer(skb, skb->nh.iph->ihl * 4,
-                               sizeof(_tcph), &_tcph);
+       th = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_tcph), &_tcph);
        if (th == NULL)
                return 0;
        return th->rst;
index 16a9ebee2fe67f28708fc1ece8cb15a77b04ccda..e65382da713e74d782c310b56a2dee930ae72057 100644 (file)
@@ -76,8 +76,7 @@ tcp_conn_schedule(struct sk_buff *skb,
        struct ip_vs_service *svc;
        struct tcphdr _tcph, *th;
 
-       th = skb_header_pointer(skb, skb->nh.iph->ihl*4,
-                               sizeof(_tcph), &_tcph);
+       th = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_tcph), &_tcph);
        if (th == NULL) {
                *verdict = NF_DROP;
                return 0;
@@ -127,7 +126,7 @@ tcp_snat_handler(struct sk_buff **pskb,
                 struct ip_vs_protocol *pp, struct ip_vs_conn *cp)
 {
        struct tcphdr *tcph;
-       unsigned int tcphoff = (*pskb)->nh.iph->ihl * 4;
+       const unsigned int tcphoff = ip_hdrlen(*pskb);
 
        /* csum_check requires unshared skb */
        if (!ip_vs_make_skb_writable(pskb, tcphoff+sizeof(*tcph)))
@@ -175,7 +174,7 @@ tcp_dnat_handler(struct sk_buff **pskb,
                 struct ip_vs_protocol *pp, struct ip_vs_conn *cp)
 {
        struct tcphdr *tcph;
-       unsigned int tcphoff = (*pskb)->nh.iph->ihl * 4;
+       const unsigned int tcphoff = ip_hdrlen(*pskb);
 
        /* csum_check requires unshared skb */
        if (!ip_vs_make_skb_writable(pskb, tcphoff+sizeof(*tcph)))
@@ -224,7 +223,7 @@ tcp_dnat_handler(struct sk_buff **pskb,
 static int
 tcp_csum_check(struct sk_buff *skb, struct ip_vs_protocol *pp)
 {
-       unsigned int tcphoff = skb->nh.iph->ihl*4;
+       const unsigned int tcphoff = ip_hdrlen(skb);
 
        switch (skb->ip_summed) {
        case CHECKSUM_NONE:
@@ -467,8 +466,7 @@ tcp_state_transition(struct ip_vs_conn *cp, int direction,
 {
        struct tcphdr _tcph, *th;
 
-       th = skb_header_pointer(skb, skb->nh.iph->ihl*4,
-                               sizeof(_tcph), &_tcph);
+       th = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_tcph), &_tcph);
        if (th == NULL)
                return 0;
 
index 03f0a414cfa406bce2505c269d6a9b1d24a5bed5..2cd950638923c7784be66ae53dc5dffbfb0289bf 100644 (file)
@@ -22,7 +22,7 @@
 #include <linux/udp.h>
 
 #include <net/ip_vs.h>
-
+#include <net/ip.h>
 
 static struct ip_vs_conn *
 udp_conn_in_get(const struct sk_buff *skb, struct ip_vs_protocol *pp,
@@ -56,7 +56,7 @@ udp_conn_out_get(const struct sk_buff *skb, struct ip_vs_protocol *pp,
        struct ip_vs_conn *cp;
        __be16 _ports[2], *pptr;
 
-       pptr = skb_header_pointer(skb, skb->nh.iph->ihl*4,
+       pptr = skb_header_pointer(skb, ip_hdrlen(skb),
                                  sizeof(_ports), _ports);
        if (pptr == NULL)
                return NULL;
@@ -82,7 +82,7 @@ udp_conn_schedule(struct sk_buff *skb, struct ip_vs_protocol *pp,
        struct ip_vs_service *svc;
        struct udphdr _udph, *uh;
 
-       uh = skb_header_pointer(skb, skb->nh.iph->ihl*4,
+       uh = skb_header_pointer(skb, ip_hdrlen(skb),
                                sizeof(_udph), &_udph);
        if (uh == NULL) {
                *verdict = NF_DROP;
@@ -133,7 +133,7 @@ udp_snat_handler(struct sk_buff **pskb,
                 struct ip_vs_protocol *pp, struct ip_vs_conn *cp)
 {
        struct udphdr *udph;
-       unsigned int udphoff = (*pskb)->nh.iph->ihl * 4;
+       const unsigned int udphoff = ip_hdrlen(*pskb);
 
        /* csum_check requires unshared skb */
        if (!ip_vs_make_skb_writable(pskb, udphoff+sizeof(*udph)))
@@ -187,7 +187,7 @@ udp_dnat_handler(struct sk_buff **pskb,
                 struct ip_vs_protocol *pp, struct ip_vs_conn *cp)
 {
        struct udphdr *udph;
-       unsigned int udphoff = (*pskb)->nh.iph->ihl * 4;
+       unsigned int udphoff = ip_hdrlen(*pskb);
 
        /* csum_check requires unshared skb */
        if (!ip_vs_make_skb_writable(pskb, udphoff+sizeof(*udph)))
@@ -239,7 +239,7 @@ static int
 udp_csum_check(struct sk_buff *skb, struct ip_vs_protocol *pp)
 {
        struct udphdr _udph, *uh;
-       unsigned int udphoff = skb->nh.iph->ihl*4;
+       const unsigned int udphoff = ip_hdrlen(skb);
 
        uh = skb_header_pointer(skb, udphoff, sizeof(_udph), &_udph);
        if (uh == NULL)
index 4f561f52c83a52c42baea4019023f6d641cd4c93..c40762c67d0ebe25d2b76c5cca274e1a13d1eaa6 100644 (file)
@@ -103,7 +103,7 @@ static int help(struct sk_buff **pskb,
        ip_ct_refresh(ct, *pskb, master_timeout * HZ);
 
        /* No data? */
-       dataoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
+       dataoff = ip_hdrlen(*pskb) + sizeof(struct udphdr);
        if (dataoff >= (*pskb)->len) {
                if (net_ratelimit())
                        printk("amanda_help: skblen = %u\n", (*pskb)->len);
index 23b99ae2cc37fffd07f5a38d4e6941a6fb44ebe3..8c013d9f6907c380f0438164eb8dcbd7d7ac5dd3 100644 (file)
@@ -750,8 +750,7 @@ resolve_normal_ct(struct sk_buff *skb,
 
        IP_NF_ASSERT((skb->nh.iph->frag_off & htons(IP_OFFSET)) == 0);
 
-       if (!ip_ct_get_tuple(skb->nh.iph, skb, skb->nh.iph->ihl*4,
-                               &tuple,proto))
+       if (!ip_ct_get_tuple(skb->nh.iph, skb, ip_hdrlen(skb), &tuple,proto))
                return NULL;
 
        /* look for tuple match */
index 1faa68ab9432e3a830f220ccde7b1348a9762f1d..92389987e78902ba0a01c80bd990283e392e2b2c 100644 (file)
@@ -319,12 +319,12 @@ static int help(struct sk_buff **pskb,
                return NF_ACCEPT;
        }
 
-       th = skb_header_pointer(*pskb, (*pskb)->nh.iph->ihl*4,
+       th = skb_header_pointer(*pskb, ip_hdrlen(*pskb),
                                sizeof(_tcph), &_tcph);
        if (th == NULL)
                return NF_ACCEPT;
 
-       dataoff = (*pskb)->nh.iph->ihl*4 + th->doff*4;
+       dataoff = ip_hdrlen(*pskb) + th->doff * 4;
        /* No data? */
        if (dataoff >= (*pskb)->len) {
                DEBUGP("ftp: pskblen = %u\n", (*pskb)->len);
index 53eb365ccc7e507f7ecac494265418e65b54b6f2..5d638149b0e05c4cbd3f05d0c29a57a65e5d84ae 100644 (file)
@@ -115,13 +115,13 @@ static int get_tpkt_data(struct sk_buff **pskb, struct ip_conntrack *ct,
        int tpktoff;
 
        /* Get TCP header */
-       th = skb_header_pointer(*pskb, (*pskb)->nh.iph->ihl * 4,
+       th = skb_header_pointer(*pskb, ip_hdrlen(*pskb),
                                sizeof(_tcph), &_tcph);
        if (th == NULL)
                return 0;
 
        /* Get TCP data offset */
-       tcpdataoff = (*pskb)->nh.iph->ihl * 4 + th->doff * 4;
+       tcpdataoff = ip_hdrlen(*pskb) + th->doff * 4;
 
        /* Get TCP data length */
        tcpdatalen = (*pskb)->len - tcpdataoff;
@@ -1185,11 +1185,10 @@ static unsigned char *get_udp_data(struct sk_buff **pskb, int *datalen)
        struct udphdr _uh, *uh;
        int dataoff;
 
-       uh = skb_header_pointer(*pskb, (*pskb)->nh.iph->ihl * 4, sizeof(_uh),
-                               &_uh);
+       uh = skb_header_pointer(*pskb, ip_hdrlen(*pskb), sizeof(_uh), &_uh);
        if (uh == NULL)
                return NULL;
-       dataoff = (*pskb)->nh.iph->ihl * 4 + sizeof(_uh);
+       dataoff = ip_hdrlen(*pskb) + sizeof(_uh);
        if (dataoff >= (*pskb)->len)
                return NULL;
        *datalen = (*pskb)->len - dataoff;
index 2b760c5cf709a32987b916f032ecd2b11b1bfcd6..f5ab8e4b97cb80642f3bfa34f33b374d9541b355 100644 (file)
@@ -543,7 +543,7 @@ conntrack_pptp_help(struct sk_buff **pskb,
        struct pptp_pkt_hdr _pptph, *pptph;
        struct PptpControlHeader _ctlh, *ctlh;
        union pptp_ctrl_union _pptpReq, *pptpReq;
-       unsigned int tcplen = (*pskb)->len - (*pskb)->nh.iph->ihl * 4;
+       unsigned int tcplen = (*pskb)->len - ip_hdrlen(*pskb);
        unsigned int datalen, reqlen, nexthdr_off;
        int oldsstate, oldcstate;
        int ret;
@@ -556,7 +556,7 @@ conntrack_pptp_help(struct sk_buff **pskb,
                return NF_ACCEPT;
        }
 
-       nexthdr_off = (*pskb)->nh.iph->ihl*4;
+       nexthdr_off = ip_hdrlen(*pskb);
        tcph = skb_header_pointer(*pskb, nexthdr_off, sizeof(_tcph), &_tcph);
        BUG_ON(!tcph);
        nexthdr_off += tcph->doff * 4;
index 053e591f407ad0c9eb45382a2562c94faeeb0748..ee99abe482e3e60e247660c968d1abe7ac220508 100644 (file)
@@ -130,13 +130,13 @@ static int help(struct sk_buff **pskb,
        }
 
        /* Not a full tcp header? */
-       th = skb_header_pointer(*pskb, (*pskb)->nh.iph->ihl*4,
+       th = skb_header_pointer(*pskb, ip_hdrlen(*pskb),
                                sizeof(_tcph), &_tcph);
        if (th == NULL)
                return NF_ACCEPT;
 
        /* No data? */
-       dataoff = (*pskb)->nh.iph->ihl*4 + th->doff*4;
+       dataoff = ip_hdrlen(*pskb) + th->doff * 4;
        if (dataoff >= (*pskb)->len)
                return NF_ACCEPT;
 
index ad70c81a21e04861c04a4e597bc00c87d0fba3eb..e253f3ee52d040057d0c3f6ea45d7f8ecf20a061 100644 (file)
@@ -149,7 +149,7 @@ icmp_error_message(struct sk_buff *skb,
        IP_NF_ASSERT(skb->nfct == NULL);
 
        /* Not enough header? */
-       inside = skb_header_pointer(skb, skb->nh.iph->ihl*4, sizeof(_in), &_in);
+       inside = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_in), &_in);
        if (inside == NULL)
                return -NF_ACCEPT;
 
@@ -161,7 +161,7 @@ icmp_error_message(struct sk_buff *skb,
        }
 
        innerproto = ip_conntrack_proto_find_get(inside->ip.protocol);
-       dataoff = skb->nh.iph->ihl*4 + sizeof(inside->icmp) + inside->ip.ihl*4;
+       dataoff = ip_hdrlen(skb) + sizeof(inside->icmp) + inside->ip.ihl * 4;
        /* Are they talking about one of our connections? */
        if (!ip_ct_get_tuple(&inside->ip, skb, dataoff, &origtuple, innerproto)) {
                DEBUGP("icmp_error: ! get_tuple p=%u", inside->ip.protocol);
@@ -214,7 +214,7 @@ icmp_error(struct sk_buff *skb, enum ip_conntrack_info *ctinfo,
        struct icmphdr _ih, *icmph;
 
        /* Not enough header? */
-       icmph = skb_header_pointer(skb, skb->nh.iph->ihl*4, sizeof(_ih), &_ih);
+       icmph = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_ih), &_ih);
        if (icmph == NULL) {
                if (LOG_INVALID(IPPROTO_ICMP))
                        nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
@@ -224,7 +224,7 @@ icmp_error(struct sk_buff *skb, enum ip_conntrack_info *ctinfo,
 
        /* See ip_conntrack_proto_tcp.c */
        if (ip_conntrack_checksum && hooknum == NF_IP_PRE_ROUTING &&
-           nf_ip_checksum(skb, hooknum, skb->nh.iph->ihl * 4, 0)) {
+           nf_ip_checksum(skb, hooknum, ip_hdrlen(skb), 0)) {
                if (LOG_INVALID(IPPROTO_ICMP))
                        nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
                                      "ip_ct_icmp: bad ICMP checksum ");
index e6942992b2f699634878e43e3a80c49f3f9c9e26..e29c436144b3e912b139d4ba3dc3b1be4790a080 100644 (file)
@@ -206,7 +206,7 @@ static int sctp_print_conntrack(struct seq_file *s,
 }
 
 #define for_each_sctp_chunk(skb, sch, _sch, offset, count)             \
-for (offset = skb->nh.iph->ihl * 4 + sizeof(sctp_sctphdr_t), count = 0;        \
+for (offset = ip_hdrlen(skb) + sizeof(sctp_sctphdr_t), count = 0;      \
        offset < skb->len &&                                            \
        (sch = skb_header_pointer(skb, offset, sizeof(_sch), &_sch));   \
        offset += (ntohs(sch->length) + 3) & ~3, count++)
index 7ff11977eb4d51bcd42fb39c6e9feda57d5a5f5e..fce3a3c6981507d112122ba57b9dc4cca6e757d4 100644 (file)
@@ -771,7 +771,7 @@ void ip_conntrack_tcp_update(struct sk_buff *skb,
                             enum ip_conntrack_dir dir)
 {
        struct iphdr *iph = skb->nh.iph;
-       struct tcphdr *tcph = (void *)skb->nh.iph + skb->nh.iph->ihl*4;
+       struct tcphdr *tcph = (void *)skb->nh.iph + ip_hdrlen(skb);
        __u32 end;
 #ifdef DEBUGP_VARS
        struct ip_ct_tcp_state *sender = &conntrack->proto.tcp.seen[dir];
index c59a962c1f61c2c415b2e6ff7b12de755fa72864..7363e2a5cea4e4b7fa31ecbda00f45740a2d1c1f 100644 (file)
@@ -402,7 +402,7 @@ static int sip_help(struct sk_buff **pskb,
        typeof(ip_nat_sip_hook) ip_nat_sip;
 
        /* No Data ? */
-       dataoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
+       dataoff = ip_hdrlen(*pskb) + sizeof(struct udphdr);
        if (dataoff >= (*pskb)->len) {
                DEBUGP("skb->len = %u\n", (*pskb)->len);
                return NF_ACCEPT;
index 56b2f7546d1e9a8f5270f679812d598f386bad6b..92609a4dcd745d6e9415dc827be69b9d0c836d65 100644 (file)
@@ -458,7 +458,7 @@ static unsigned int ip_conntrack_local(unsigned int hooknum,
 {
        /* root is playing with raw sockets. */
        if ((*pskb)->len < sizeof(struct iphdr)
-           || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) {
+           || ip_hdrlen(*pskb) < sizeof(struct iphdr)) {
                if (net_ratelimit())
                        printk("ipt_hook: happy cracking.\n");
                return NF_ACCEPT;
index 76e175e7a9729ade19b7bef5d1dcff2de6ce4cf8..afc6809a38886e764778941c08debdf66c66b461 100644 (file)
@@ -53,7 +53,7 @@ static int tftp_help(struct sk_buff **pskb,
        typeof(ip_nat_tftp_hook) ip_nat_tftp;
 
        tfh = skb_header_pointer(*pskb,
-                                (*pskb)->nh.iph->ihl*4+sizeof(struct udphdr),
+                                ip_hdrlen(*pskb) + sizeof(struct udphdr),
                                 sizeof(_tftph), &_tftph);
        if (tfh == NULL)
                return NF_ACCEPT;
index 40737fdbe9a73126dd17e59f97371973989c2cfb..cf46930606f27d432b766307a828dd96cd1af2d6 100644 (file)
@@ -422,7 +422,7 @@ int ip_nat_icmp_reply_translation(struct ip_conntrack *ct,
        } *inside;
        struct ip_conntrack_protocol *proto;
        struct ip_conntrack_tuple inner, target;
-       int hdrlen = (*pskb)->nh.iph->ihl * 4;
+       int hdrlen = ip_hdrlen(*pskb);
        enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
        unsigned long statusbit;
        enum ip_nat_manip_type manip = HOOK2MANIP(hooknum);
@@ -430,7 +430,7 @@ int ip_nat_icmp_reply_translation(struct ip_conntrack *ct,
        if (!skb_make_writable(pskb, hdrlen + sizeof(*inside)))
                return 0;
 
-       inside = (void *)(*pskb)->data + (*pskb)->nh.iph->ihl*4;
+       inside = (void *)(*pskb)->data + ip_hdrlen(*pskb);
 
        /* We're actually going to mangle it beyond trivial checksum
           adjustment, so make sure the current checksum is correct. */
@@ -458,7 +458,7 @@ int ip_nat_icmp_reply_translation(struct ip_conntrack *ct,
 
        /* rcu_read_lock()ed by nf_hook_slow */
        proto = __ip_conntrack_proto_find(inside->ip.protocol);
-       if (!ip_ct_get_tuple(&inside->ip, *pskb, (*pskb)->nh.iph->ihl*4 +
+       if (!ip_ct_get_tuple(&inside->ip, *pskb, ip_hdrlen(*pskb) +
                             sizeof(struct icmphdr) + inside->ip.ihl*4,
                             &inner, proto))
                return 0;
@@ -469,15 +469,14 @@ int ip_nat_icmp_reply_translation(struct ip_conntrack *ct,
           packet: PREROUTING (DST manip), routing produces ICMP, goes
           through POSTROUTING (which must correct the DST manip). */
        if (!manip_pkt(inside->ip.protocol, pskb,
-                      (*pskb)->nh.iph->ihl*4
-                      + sizeof(inside->icmp),
+                      ip_hdrlen(*pskb) + sizeof(inside->icmp),
                       &ct->tuplehash[!dir].tuple,
                       !manip))
                return 0;
 
        if ((*pskb)->ip_summed != CHECKSUM_PARTIAL) {
                /* Reloading "inside" here since manip_pkt inner. */
-               inside = (void *)(*pskb)->data + (*pskb)->nh.iph->ihl*4;
+               inside = (void *)(*pskb)->data + ip_hdrlen(*pskb);
                inside->icmp.checksum = 0;
                inside->icmp.checksum = csum_fold(skb_checksum(*pskb, hdrlen,
                                                               (*pskb)->len - hdrlen,
index dc778cfef58b43b37ac523f0257ad593c6b09dae..25624e558562af2c5cba2a97a14f97898456c5ca 100644 (file)
@@ -322,8 +322,8 @@ ip_nat_sack_adjust(struct sk_buff **pskb,
 {
        unsigned int dir, optoff, optend;
 
-       optoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct tcphdr);
-       optend = (*pskb)->nh.iph->ihl*4 + tcph->doff*4;
+       optoff = ip_hdrlen(*pskb) + sizeof(struct tcphdr);
+       optend = ip_hdrlen(*pskb) + tcph->doff * 4;
 
        if (!skb_make_writable(pskb, optend))
                return 0;
@@ -374,10 +374,10 @@ ip_nat_seq_adjust(struct sk_buff **pskb,
        this_way = &ct->nat.info.seq[dir];
        other_way = &ct->nat.info.seq[!dir];
 
-       if (!skb_make_writable(pskb, (*pskb)->nh.iph->ihl*4+sizeof(*tcph)))
+       if (!skb_make_writable(pskb, ip_hdrlen(*pskb) + sizeof(*tcph)))
                return 0;
 
-       tcph = (void *)(*pskb)->data + (*pskb)->nh.iph->ihl*4;
+       tcph = (void *)(*pskb)->data + ip_hdrlen(*pskb);
        if (after(ntohl(tcph->seq), this_way->correction_pos))
                newseq = htonl(ntohl(tcph->seq) + this_way->offset_after);
        else
index bdc99ef6159efe82d60b3ffafd6529d06bf7265e..8b1e3388bd08ee6b1ac8ebed906f52dd10bf93a8 100644 (file)
@@ -57,11 +57,11 @@ static int set_addr(struct sk_buff **pskb,
                }
 
                /* Relocate data pointer */
-               th = skb_header_pointer(*pskb, (*pskb)->nh.iph->ihl * 4,
+               th = skb_header_pointer(*pskb, ip_hdrlen(*pskb),
                                        sizeof(_tcph), &_tcph);
                if (th == NULL)
                        return -1;
-               *data = (*pskb)->data + (*pskb)->nh.iph->ihl * 4 +
+               *data = (*pskb)->data + ip_hdrlen(*pskb) +
                    th->doff * 4 + dataoff;
        } else {
                if (!ip_nat_mangle_udp_packet(pskb, ct, ctinfo,
@@ -75,8 +75,8 @@ static int set_addr(struct sk_buff **pskb,
                /* ip_nat_mangle_udp_packet uses skb_make_writable() to copy
                 * or pull everything in a linear buffer, so we can safely
                 * use the skb pointers now */
-               *data = (*pskb)->data + (*pskb)->nh.iph->ihl * 4 +
-                   sizeof(struct udphdr);
+               *data = ((*pskb)->data + ip_hdrlen(*pskb) +
+                        sizeof(struct udphdr));
        }
 
        return 0;
index 325c5a9dc2efe22da7cb275af0cbb92b9c51e1dd..84953601762de7b7361274f02993d93579a794b2 100644 (file)
@@ -90,7 +90,7 @@ static int map_sip_addr(struct sk_buff **pskb, enum ip_conntrack_info ctinfo,
        if (!ip_nat_mangle_udp_packet(pskb, ct, ctinfo,
                                      matchoff, matchlen, addr, addrlen))
                return 0;
-       *dptr = (*pskb)->data + (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
+       *dptr = (*pskb)->data + ip_hdrlen(*pskb) + sizeof(struct udphdr);
        return 1;
 
 }
@@ -104,7 +104,7 @@ static unsigned int ip_nat_sip(struct sk_buff **pskb,
        struct addr_map map;
        int dataoff, datalen;
 
-       dataoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
+       dataoff = ip_hdrlen(*pskb) + sizeof(struct udphdr);
        datalen = (*pskb)->len - dataoff;
        if (datalen < sizeof("SIP/2.0") - 1)
                return NF_DROP;
@@ -153,7 +153,7 @@ static unsigned int mangle_sip_packet(struct sk_buff **pskb,
                return 0;
 
        /* We need to reload this. Thanks Patrick. */
-       *dptr = (*pskb)->data + (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
+       *dptr = (*pskb)->data + ip_hdrlen(*pskb) + sizeof(struct udphdr);
        return 1;
 }
 
@@ -166,7 +166,7 @@ static int mangle_content_len(struct sk_buff **pskb,
        char buffer[sizeof("65536")];
        int bufflen;
 
-       dataoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
+       dataoff = ip_hdrlen(*pskb) + sizeof(struct udphdr);
 
        /* Get actual SDP lenght */
        if (ct_sip_get_info(dptr, (*pskb)->len - dataoff, &matchoff,
@@ -199,7 +199,7 @@ static unsigned int mangle_sdp(struct sk_buff **pskb,
        char buffer[sizeof("nnn.nnn.nnn.nnn")];
        unsigned int dataoff, bufflen;
 
-       dataoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
+       dataoff = ip_hdrlen(*pskb) + sizeof(struct udphdr);
 
        /* Mangle owner and contact info. */
        bufflen = sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(newip));
index 6bcfdf6dfcc9b37726e38a0ce766eb2d056f6f36..dbaaf78ff9a3fe5241d42871ac34dba6237cf0e0 100644 (file)
@@ -112,8 +112,7 @@ ip_nat_fn(unsigned int hooknum,
                if ((*pskb)->nh.iph->protocol == IPPROTO_ICMP) {
                        struct icmphdr _hdr, *hp;
 
-                       hp = skb_header_pointer(*pskb,
-                                               (*pskb)->nh.iph->ihl*4,
+                       hp = skb_header_pointer(*pskb, ip_hdrlen(*pskb),
                                                sizeof(_hdr), &_hdr);
                        if (hp != NULL &&
                            hp->type == ICMP_REDIRECT)
@@ -211,7 +210,7 @@ ip_nat_out(unsigned int hooknum,
 
        /* root is playing with raw sockets. */
        if ((*pskb)->len < sizeof(struct iphdr)
-           || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr))
+           || ip_hdrlen(*pskb) < sizeof(struct iphdr))
                return NF_ACCEPT;
 
        ret = ip_nat_fn(hooknum, pskb, in, out, okfn);
@@ -244,7 +243,7 @@ ip_nat_local_fn(unsigned int hooknum,
 
        /* root is playing with raw sockets. */
        if ((*pskb)->len < sizeof(struct iphdr)
-           || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr))
+           || ip_hdrlen(*pskb) < sizeof(struct iphdr))
                return NF_ACCEPT;
 
        ret = ip_nat_fn(hooknum, pskb, in, out, okfn);
index 50cc4b92e2845ae2699e225807582370b09621da..f66966650212d78e5066b7823c36ae683e8f0b00 100644 (file)
@@ -198,7 +198,7 @@ int do_match(struct ipt_entry_match *m,
 {
        /* Stop iteration if it doesn't match */
        if (!m->u.kernel.match->match(skb, in, out, m->u.kernel.match, m->data,
-                                     offset, skb->nh.iph->ihl*4, hotdrop))
+                                     offset, ip_hdrlen(skb), hotdrop))
                return 1;
        else
                return 0;
index 4f565633631dfa971d39eb1bc151ebf0b292fc8d..44daf9e1da35b3cd1b88df871009ba1aea04ca5b 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/module.h>
 #include <linux/skbuff.h>
 #include <linux/ip.h>
+#include <net/ip.h>
 #include <linux/tcp.h>
 #include <net/checksum.h>
 
@@ -52,7 +53,7 @@ set_ect_tcp(struct sk_buff **pskb, const struct ipt_ECN_info *einfo)
        __be16 oldval;
 
        /* Not enought header? */
-       tcph = skb_header_pointer(*pskb, (*pskb)->nh.iph->ihl*4,
+       tcph = skb_header_pointer(*pskb, ip_hdrlen(*pskb),
                                  sizeof(_tcph), &_tcph);
        if (!tcph)
                return 0;
@@ -63,9 +64,9 @@ set_ect_tcp(struct sk_buff **pskb, const struct ipt_ECN_info *einfo)
             tcph->cwr == einfo->proto.tcp.cwr)))
                return 1;
 
-       if (!skb_make_writable(pskb, (*pskb)->nh.iph->ihl*4+sizeof(*tcph)))
+       if (!skb_make_writable(pskb, ip_hdrlen(*pskb) + sizeof(*tcph)))
                return 0;
-       tcph = (void *)(*pskb)->nh.iph + (*pskb)->nh.iph->ihl*4;
+       tcph = (void *)(*pskb)->nh.iph + ip_hdrlen(*pskb);
 
        oldval = ((__be16 *)tcph)[6];
        if (einfo->operation & IPT_ECN_OP_SET_ECE)
index 80f739e218244936b1da8a27f9e041225046ba54..01c04f0e5c910d4d0fab580863c36a05fd4963f8 100644 (file)
@@ -43,7 +43,6 @@ MODULE_DESCRIPTION("iptables REJECT target module");
 static void send_reset(struct sk_buff *oldskb, int hook)
 {
        struct sk_buff *nskb;
-       struct iphdr *iph = oldskb->nh.iph;
        struct tcphdr _otcph, *oth, *tcph;
        __be16 tmp_port;
        __be32 tmp_addr;
@@ -54,7 +53,7 @@ static void send_reset(struct sk_buff *oldskb, int hook)
        if (oldskb->nh.iph->frag_off & htons(IP_OFFSET))
                return;
 
-       oth = skb_header_pointer(oldskb, oldskb->nh.iph->ihl * 4,
+       oth = skb_header_pointer(oldskb, ip_hdrlen(oldskb),
                                 sizeof(_otcph), &_otcph);
        if (oth == NULL)
                return;
@@ -64,7 +63,7 @@ static void send_reset(struct sk_buff *oldskb, int hook)
                return;
 
        /* Check checksum */
-       if (nf_ip_checksum(oldskb, hook, iph->ihl * 4, IPPROTO_TCP))
+       if (nf_ip_checksum(oldskb, hook, ip_hdrlen(oldskb), IPPROTO_TCP))
                return;
 
        /* We need a linear, writeable skb.  We also need to expand
@@ -84,7 +83,7 @@ static void send_reset(struct sk_buff *oldskb, int hook)
        skb_shinfo(nskb)->gso_segs = 0;
        skb_shinfo(nskb)->gso_type = 0;
 
-       tcph = (struct tcphdr *)((u_int32_t*)nskb->nh.iph + nskb->nh.iph->ihl);
+       tcph = (struct tcphdr *)(skb_network_header(nskb) + ip_hdrlen(nskb));
 
        /* Swap source and dest */
        tmp_addr = nskb->nh.iph->saddr;
@@ -96,7 +95,7 @@ static void send_reset(struct sk_buff *oldskb, int hook)
 
        /* Truncate to length (no data) */
        tcph->doff = sizeof(struct tcphdr)/4;
-       skb_trim(nskb, nskb->nh.iph->ihl*4 + sizeof(struct tcphdr));
+       skb_trim(nskb, ip_hdrlen(nskb) + sizeof(struct tcphdr));
        nskb->nh.iph->tot_len = htons(nskb->len);
 
        if (tcph->ack) {
@@ -105,9 +104,9 @@ static void send_reset(struct sk_buff *oldskb, int hook)
                tcph->ack_seq = 0;
        } else {
                needs_ack = 1;
-               tcph->ack_seq = htonl(ntohl(oth->seq) + oth->syn + oth->fin
-                                     + oldskb->len - oldskb->nh.iph->ihl*4
-                                     - (oth->doff<<2));
+               tcph->ack_seq = htonl(ntohl(oth->seq) + oth->syn + oth->fin +
+                                     oldskb->len - ip_hdrlen(oldskb) -
+                                     (oth->doff << 2));
                tcph->seq = 0;
        }
 
@@ -149,7 +148,7 @@ static void send_reset(struct sk_buff *oldskb, int hook)
 
        /* Adjust IP checksum */
        nskb->nh.iph->check = 0;
-       nskb->nh.iph->check = ip_fast_csum((unsigned char *)nskb->nh.iph,
+       nskb->nh.iph->check = ip_fast_csum(skb_network_header(nskb),
                                           nskb->nh.iph->ihl);
 
        /* "Never happens" */
@@ -182,7 +181,7 @@ static unsigned int reject(struct sk_buff **pskb,
 
        /* Our naive response construction doesn't deal with IP
           options, and probably shouldn't try. */
-       if ((*pskb)->nh.iph->ihl<<2 != sizeof(struct iphdr))
+       if (ip_hdrlen(*pskb) != sizeof(struct iphdr))
                return NF_DROP;
 
        /* WARNING: This code causes reentry within iptables.
index 37508b2cfea6d491e6ac27434b44386cae494681..b8ade3cc775728c2ab5fd328735c388363fa9d16 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <linux/in.h>
 #include <linux/ip.h>
+#include <net/ip.h>
 #include <linux/module.h>
 #include <linux/skbuff.h>
 #include <linux/tcp.h>
@@ -38,8 +39,7 @@ static inline int match_tcp(const struct sk_buff *skb,
        /* In practice, TCP match does this, so can't fail.  But let's
         * be good citizens.
         */
-       th = skb_header_pointer(skb, skb->nh.iph->ihl * 4,
-                               sizeof(_tcph), &_tcph);
+       th = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_tcph), &_tcph);
        if (th == NULL) {
                *hotdrop = 0;
                return 0;
index d1d61e97b97659dc4a97928affc8cc27c1cbeaa6..42728909eba0577a64693f4a460eb2f1edf133a9 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/netfilter_ipv4/ip_tables.h>
+#include <net/ip.h>
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
@@ -102,7 +103,7 @@ ipt_local_out_hook(unsigned int hook,
 {
        /* root is playing with raw sockets. */
        if ((*pskb)->len < sizeof(struct iphdr)
-           || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) {
+           || ip_hdrlen(*pskb) < sizeof(struct iphdr)) {
                if (net_ratelimit())
                        printk("ipt_hook: happy cracking.\n");
                return NF_ACCEPT;
index 98b66ef0c714b93c7235e1bfd5cca07100ba1004..6cc3245f676af73142f3a37bfa8d2f7cbdf69c60 100644 (file)
@@ -17,6 +17,7 @@
 #include <net/sock.h>
 #include <net/route.h>
 #include <linux/ip.h>
+#include <net/ip.h>
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
@@ -136,7 +137,7 @@ ipt_local_hook(unsigned int hook,
 
        /* root is playing with raw sockets. */
        if ((*pskb)->len < sizeof(struct iphdr)
-           || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) {
+           || ip_hdrlen(*pskb) < sizeof(struct iphdr)) {
                if (net_ratelimit())
                        printk("ipt_hook: happy cracking.\n");
                return NF_ACCEPT;
index 7cebbff0b0c30ba7f8ebb6e728f272622b83a709..fa14eb77f9b687f6cbe7f069757d5a50d594234a 100644 (file)
@@ -105,7 +105,7 @@ ipv4_prepare(struct sk_buff **pskb, unsigned int hooknum, unsigned int *dataoff,
                return -NF_DROP;
        }
 
-       *dataoff = skb_network_offset(*pskb) + (*pskb)->nh.iph->ihl * 4;
+       *dataoff = skb_network_offset(*pskb) + ip_hdrlen(*pskb);
        *protonum = (*pskb)->nh.iph->protocol;
 
        return NF_ACCEPT;
@@ -151,8 +151,8 @@ static unsigned int ipv4_conntrack_help(unsigned int hooknum,
        if (!help || !help->helper)
                return NF_ACCEPT;
 
-       return help->helper->help(pskb, (skb_network_offset(*pskb) +
-                                        (*pskb)->nh.iph->ihl * 4),
+       return help->helper->help(pskb,
+                                 skb_network_offset(*pskb) + ip_hdrlen(*pskb),
                                  ct, ctinfo);
 }
 
@@ -198,7 +198,7 @@ static unsigned int ipv4_conntrack_local(unsigned int hooknum,
 {
        /* root is playing with raw sockets. */
        if ((*pskb)->len < sizeof(struct iphdr)
-           || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) {
+           || ip_hdrlen(*pskb) < sizeof(struct iphdr)) {
                if (net_ratelimit())
                        printk("ipt_hook: happy cracking.\n");
                return NF_ACCEPT;
index 5fd1e5363c1ab60ed9ec1e3e70505247f79327e3..e090e929e6e290a6068c109063c30462eb84ae6d 100644 (file)
@@ -158,7 +158,7 @@ icmp_error_message(struct sk_buff *skb,
        NF_CT_ASSERT(skb->nfct == NULL);
 
        /* Not enough header? */
-       inside = skb_header_pointer(skb, skb->nh.iph->ihl*4, sizeof(_in), &_in);
+       inside = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_in), &_in);
        if (inside == NULL)
                return -NF_ACCEPT;
 
@@ -172,7 +172,7 @@ icmp_error_message(struct sk_buff *skb,
        /* rcu_read_lock()ed by nf_hook_slow */
        innerproto = __nf_ct_l4proto_find(PF_INET, inside->ip.protocol);
 
-       dataoff = skb->nh.iph->ihl*4 + sizeof(inside->icmp);
+       dataoff = ip_hdrlen(skb) + sizeof(inside->icmp);
        /* Are they talking about one of our connections? */
        if (!nf_ct_get_tuple(skb, dataoff, dataoff + inside->ip.ihl*4, PF_INET,
                             inside->ip.protocol, &origtuple,
@@ -227,7 +227,7 @@ icmp_error(struct sk_buff *skb, unsigned int dataoff,
        struct icmphdr _ih, *icmph;
 
        /* Not enough header? */
-       icmph = skb_header_pointer(skb, skb->nh.iph->ihl*4, sizeof(_ih), &_ih);
+       icmph = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_ih), &_ih);
        if (icmph == NULL) {
                if (LOG_INVALID(IPPROTO_ICMP))
                        nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
index 452e9d326684448ddafe00a558e2c3571a61b509..ea02f00d2dac5ef644bcc0602f27d733152c7770 100644 (file)
@@ -431,7 +431,7 @@ int nf_nat_icmp_reply_translation(struct nf_conn *ct,
        } *inside;
        struct nf_conntrack_l4proto *l4proto;
        struct nf_conntrack_tuple inner, target;
-       int hdrlen = (*pskb)->nh.iph->ihl * 4;
+       int hdrlen = ip_hdrlen(*pskb);
        enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
        unsigned long statusbit;
        enum nf_nat_manip_type manip = HOOK2MANIP(hooknum);
@@ -439,7 +439,7 @@ int nf_nat_icmp_reply_translation(struct nf_conn *ct,
        if (!skb_make_writable(pskb, hdrlen + sizeof(*inside)))
                return 0;
 
-       inside = (void *)(*pskb)->data + (*pskb)->nh.iph->ihl*4;
+       inside = (void *)(*pskb)->data + ip_hdrlen(*pskb);
 
        /* We're actually going to mangle it beyond trivial checksum
           adjustment, so make sure the current checksum is correct. */
@@ -469,9 +469,9 @@ int nf_nat_icmp_reply_translation(struct nf_conn *ct,
        l4proto = __nf_ct_l4proto_find(PF_INET, inside->ip.protocol);
 
        if (!nf_ct_get_tuple(*pskb,
-                            (*pskb)->nh.iph->ihl*4 + sizeof(struct icmphdr),
-                            (*pskb)->nh.iph->ihl*4 +
-                            sizeof(struct icmphdr) + inside->ip.ihl*4,
+                            ip_hdrlen(*pskb) + sizeof(struct icmphdr),
+                            (ip_hdrlen(*pskb) +
+                             sizeof(struct icmphdr) + inside->ip.ihl * 4),
                             (u_int16_t)AF_INET,
                             inside->ip.protocol,
                             &inner, l3proto, l4proto))
@@ -483,14 +483,14 @@ int nf_nat_icmp_reply_translation(struct nf_conn *ct,
           packet: PREROUTING (DST manip), routing produces ICMP, goes
           through POSTROUTING (which must correct the DST manip). */
        if (!manip_pkt(inside->ip.protocol, pskb,
-                      (*pskb)->nh.iph->ihl*4 + sizeof(inside->icmp),
+                      ip_hdrlen(*pskb) + sizeof(inside->icmp),
                       &ct->tuplehash[!dir].tuple,
                       !manip))
                return 0;
 
        if ((*pskb)->ip_summed != CHECKSUM_PARTIAL) {
                /* Reloading "inside" here since manip_pkt inner. */
-               inside = (void *)(*pskb)->data + (*pskb)->nh.iph->ihl*4;
+               inside = (void *)(*pskb)->data + ip_hdrlen(*pskb);
                inside->icmp.checksum = 0;
                inside->icmp.checksum =
                        csum_fold(skb_checksum(*pskb, hdrlen,
index 9cbf3f9be13b050ef013d1e9d60313f34630ce1b..2eb3832db3a4323fccdb63d47b44a14dc44c0f2d 100644 (file)
@@ -55,11 +55,11 @@ static int set_addr(struct sk_buff **pskb,
                }
 
                /* Relocate data pointer */
-               th = skb_header_pointer(*pskb, (*pskb)->nh.iph->ihl * 4,
+               th = skb_header_pointer(*pskb, ip_hdrlen(*pskb),
                                        sizeof(_tcph), &_tcph);
                if (th == NULL)
                        return -1;
-               *data = (*pskb)->data + (*pskb)->nh.iph->ihl * 4 +
+               *data = (*pskb)->data + ip_hdrlen(*pskb) +
                    th->doff * 4 + dataoff;
        } else {
                if (!nf_nat_mangle_udp_packet(pskb, ct, ctinfo,
@@ -73,8 +73,8 @@ static int set_addr(struct sk_buff **pskb,
                /* nf_nat_mangle_udp_packet uses skb_make_writable() to copy
                 * or pull everything in a linear buffer, so we can safely
                 * use the skb pointers now */
-               *data = (*pskb)->data + (*pskb)->nh.iph->ihl * 4 +
-                   sizeof(struct udphdr);
+               *data = ((*pskb)->data + ip_hdrlen(*pskb) +
+                        sizeof(struct udphdr));
        }
 
        return 0;
index 49a90c39ffce888de7c0bd664a70a9e279619b83..723302afd84073f9e38315a23b2aee47ec80d8e9 100644 (file)
@@ -190,7 +190,7 @@ nf_nat_mangle_tcp_packet(struct sk_buff **pskb,
                                    (int)rep_len - (int)match_len,
                                    ct, ctinfo);
                /* Tell TCP window tracking about seq change */
-               nf_conntrack_tcp_update(*pskb, (*pskb)->nh.iph->ihl*4,
+               nf_conntrack_tcp_update(*pskb, ip_hdrlen(*pskb),
                                        ct, CTINFO2DIR(ctinfo));
        }
        return 1;
@@ -318,8 +318,8 @@ nf_nat_sack_adjust(struct sk_buff **pskb,
        unsigned int dir, optoff, optend;
        struct nf_conn_nat *nat = nfct_nat(ct);
 
-       optoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct tcphdr);
-       optend = (*pskb)->nh.iph->ihl*4 + tcph->doff*4;
+       optoff = ip_hdrlen(*pskb) + sizeof(struct tcphdr);
+       optend = ip_hdrlen(*pskb) + tcph->doff * 4;
 
        if (!skb_make_writable(pskb, optend))
                return 0;
@@ -371,10 +371,10 @@ nf_nat_seq_adjust(struct sk_buff **pskb,
        this_way = &nat->info.seq[dir];
        other_way = &nat->info.seq[!dir];
 
-       if (!skb_make_writable(pskb, (*pskb)->nh.iph->ihl*4+sizeof(*tcph)))
+       if (!skb_make_writable(pskb, ip_hdrlen(*pskb) + sizeof(*tcph)))
                return 0;
 
-       tcph = (void *)(*pskb)->data + (*pskb)->nh.iph->ihl*4;
+       tcph = (void *)(*pskb)->data + ip_hdrlen(*pskb);
        if (after(ntohl(tcph->seq), this_way->correction_pos))
                newseq = htonl(ntohl(tcph->seq) + this_way->offset_after);
        else
@@ -399,7 +399,7 @@ nf_nat_seq_adjust(struct sk_buff **pskb,
        if (!nf_nat_sack_adjust(pskb, tcph, ct, ctinfo))
                return 0;
 
-       nf_conntrack_tcp_update(*pskb, (*pskb)->nh.iph->ihl*4, ct, dir);
+       nf_conntrack_tcp_update(*pskb, ip_hdrlen(*pskb), ct, dir);
 
        return 1;
 }
index b12cd7c314caadefd43ea9e2f7842bb02fb07b28..bfd88e4e06851396929b1ad7b9c63333a458dc76 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/module.h>
 #include <linux/skbuff.h>
 #include <linux/ip.h>
+#include <net/ip.h>
 #include <linux/udp.h>
 
 #include <net/netfilter/nf_nat.h>
@@ -92,7 +93,7 @@ static int map_sip_addr(struct sk_buff **pskb, enum ip_conntrack_info ctinfo,
        if (!nf_nat_mangle_udp_packet(pskb, ct, ctinfo,
                                      matchoff, matchlen, addr, addrlen))
                return 0;
-       *dptr = (*pskb)->data + (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
+       *dptr = (*pskb)->data + ip_hdrlen(*pskb) + sizeof(struct udphdr);
        return 1;
 
 }
@@ -106,7 +107,7 @@ static unsigned int ip_nat_sip(struct sk_buff **pskb,
        struct addr_map map;
        int dataoff, datalen;
 
-       dataoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
+       dataoff = ip_hdrlen(*pskb) + sizeof(struct udphdr);
        datalen = (*pskb)->len - dataoff;
        if (datalen < sizeof("SIP/2.0") - 1)
                return NF_DROP;
@@ -155,7 +156,7 @@ static unsigned int mangle_sip_packet(struct sk_buff **pskb,
                return 0;
 
        /* We need to reload this. Thanks Patrick. */
-       *dptr = (*pskb)->data + (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
+       *dptr = (*pskb)->data + ip_hdrlen(*pskb) + sizeof(struct udphdr);
        return 1;
 }
 
@@ -168,7 +169,7 @@ static int mangle_content_len(struct sk_buff **pskb,
        char buffer[sizeof("65536")];
        int bufflen;
 
-       dataoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
+       dataoff = ip_hdrlen(*pskb) + sizeof(struct udphdr);
 
        /* Get actual SDP lenght */
        if (ct_sip_get_info(ct, dptr, (*pskb)->len - dataoff, &matchoff,
@@ -200,7 +201,7 @@ static unsigned int mangle_sdp(struct sk_buff **pskb,
        char buffer[sizeof("nnn.nnn.nnn.nnn")];
        unsigned int dataoff, bufflen;
 
-       dataoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
+       dataoff = ip_hdrlen(*pskb) + sizeof(struct udphdr);
 
        /* Mangle owner and contact info. */
        bufflen = sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(newip));
index 15aa3db8cb339fe534097881c2c63b28f78cbc3b..61ca272165a1326e27e901a96ecf738715cd36a2 100644 (file)
@@ -101,8 +101,7 @@ nf_nat_fn(unsigned int hooknum,
                if ((*pskb)->nh.iph->protocol == IPPROTO_ICMP) {
                        struct icmphdr _hdr, *hp;
 
-                       hp = skb_header_pointer(*pskb,
-                                               (*pskb)->nh.iph->ihl*4,
+                       hp = skb_header_pointer(*pskb, ip_hdrlen(*pskb),
                                                sizeof(_hdr), &_hdr);
                        if (hp != NULL &&
                            hp->type == ICMP_REDIRECT)
@@ -203,7 +202,7 @@ nf_nat_out(unsigned int hooknum,
 
        /* root is playing with raw sockets. */
        if ((*pskb)->len < sizeof(struct iphdr) ||
-           (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr))
+           ip_hdrlen(*pskb) < sizeof(struct iphdr))
                return NF_ACCEPT;
 
        ret = nf_nat_fn(hooknum, pskb, in, out, okfn);
@@ -236,7 +235,7 @@ nf_nat_local_fn(unsigned int hooknum,
 
        /* root is playing with raw sockets. */
        if ((*pskb)->len < sizeof(struct iphdr) ||
-           (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr))
+           ip_hdrlen(*pskb) < sizeof(struct iphdr))
                return NF_ACCEPT;
 
        ret = nf_nat_fn(hooknum, pskb, in, out, okfn);
index 112a21d0c6da2d3c4423f4649f8f9a6138a46355..76f0cf66f95c53cfb4e575b45dc93f36372572e1 100644 (file)
@@ -102,7 +102,7 @@ ip6t_local_out_hook(unsigned int hook,
 #if 0
        /* root is playing with raw sockets. */
        if ((*pskb)->len < sizeof(struct iphdr)
-           || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) {
+           || ip_hdrlen(*pskb) < sizeof(struct iphdr)) {
                if (net_ratelimit())
                        printk("ip6t_hook: happy cracking.\n");
                return NF_ACCEPT;
index 0c468d35a93743b34e7773966d313455dd89687f..da2c1994539b3d73e471786898f8ada0d6a5cdc3 100644 (file)
@@ -138,7 +138,7 @@ ip6t_local_hook(unsigned int hook,
 #if 0
        /* root is playing with raw sockets. */
        if ((*pskb)->len < sizeof(struct iphdr)
-           || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) {
+           || ip_hdrlen(*pskb) < sizeof(struct iphdr)) {
                if (net_ratelimit())
                        printk("ip6t_hook: happy cracking.\n");
                return NF_ACCEPT;