aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Gortmaker <paul.gortmaker@windriver.com>2011-06-21 23:33:34 -0400
committerDavid S. Miller <davem@davemloft.net>2011-06-21 23:33:34 -0400
commit56f8a75c17abb854b5907f4a815dc4c3f186ba11 (patch)
tree6ba333b7668ce7dd04cddecf4f15a0a48b335991
parentf470e5ae34d68880a38aa79ee5c102ebc2a1aef6 (diff)
ip: introduce ip_is_fragment helper inline function
There are enough instances of this: iph->frag_off & htons(IP_MF | IP_OFFSET) that a helper function is probably warranted. Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/bonding/bond_main.c2
-rw-r--r--drivers/net/ioc3-eth.c2
-rw-r--r--drivers/net/myri10ge/myri10ge.c2
-rw-r--r--drivers/net/s2io.c2
-rw-r--r--drivers/net/sfc/filter.c2
-rw-r--r--drivers/net/vxge/vxge-main.c2
-rw-r--r--include/net/ip.h5
-rw-r--r--net/core/dev.c2
-rw-r--r--net/ipv4/ip_input.c4
-rw-r--r--net/ipv4/ip_output.c2
-rw-r--r--net/ipv4/ipconfig.c2
-rw-r--r--net/ipv4/netfilter/nf_defrag_ipv4.c2
-rw-r--r--net/ipv4/netfilter/nf_nat_standalone.c2
-rw-r--r--net/ipv4/xfrm4_policy.c2
-rw-r--r--net/netfilter/ipvs/ip_vs_core.c7
-rw-r--r--net/sched/cls_flow.c4
-rw-r--r--net/sched/cls_rsvp.h2
-rw-r--r--net/sched/sch_choke.c2
-rw-r--r--net/sched/sch_sfq.c2
19 files changed, 27 insertions, 23 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index d117280b9cd8..ebb1d219b45c 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -3438,7 +3438,7 @@ static int bond_xmit_hash_policy_l34(struct sk_buff *skb, int count)
3438 int layer4_xor = 0; 3438 int layer4_xor = 0;
3439 3439
3440 if (skb->protocol == htons(ETH_P_IP)) { 3440 if (skb->protocol == htons(ETH_P_IP)) {
3441 if (!(iph->frag_off & htons(IP_MF|IP_OFFSET)) && 3441 if (!ip_is_fragment(iph) &&
3442 (iph->protocol == IPPROTO_TCP || 3442 (iph->protocol == IPPROTO_TCP ||
3443 iph->protocol == IPPROTO_UDP)) { 3443 iph->protocol == IPPROTO_UDP)) {
3444 layer4_xor = ntohs((*layer4hdr ^ *(layer4hdr + 1))); 3444 layer4_xor = ntohs((*layer4hdr ^ *(layer4hdr + 1)));
diff --git a/drivers/net/ioc3-eth.c b/drivers/net/ioc3-eth.c
index 32f07f868d89..318a25a92310 100644
--- a/drivers/net/ioc3-eth.c
+++ b/drivers/net/ioc3-eth.c
@@ -532,7 +532,7 @@ static void ioc3_tcpudp_checksum(struct sk_buff *skb, uint32_t hwsum, int len)
532 return; 532 return;
533 533
534 ih = (struct iphdr *) ((char *)eh + ETH_HLEN); 534 ih = (struct iphdr *) ((char *)eh + ETH_HLEN);
535 if (ih->frag_off & htons(IP_MF | IP_OFFSET)) 535 if (ip_is_fragment(ih))
536 return; 536 return;
537 537
538 proto = ih->protocol; 538 proto = ih->protocol;
diff --git a/drivers/net/myri10ge/myri10ge.c b/drivers/net/myri10ge/myri10ge.c
index 3e89a842fc5e..3ed5f3505cea 100644
--- a/drivers/net/myri10ge/myri10ge.c
+++ b/drivers/net/myri10ge/myri10ge.c
@@ -2257,7 +2257,7 @@ myri10ge_get_frag_header(struct skb_frag_struct *frag, void **mac_hdr,
2257 *ip_hdr = iph; 2257 *ip_hdr = iph;
2258 if (iph->protocol != IPPROTO_TCP) 2258 if (iph->protocol != IPPROTO_TCP)
2259 return -1; 2259 return -1;
2260 if (iph->frag_off & htons(IP_MF | IP_OFFSET)) 2260 if (ip_is_fragment(iph))
2261 return -1; 2261 return -1;
2262 *hdr_flags |= LRO_TCP; 2262 *hdr_flags |= LRO_TCP;
2263 *tcpudp_hdr = (u8 *) (*ip_hdr) + (iph->ihl << 2); 2263 *tcpudp_hdr = (u8 *) (*ip_hdr) + (iph->ihl << 2);
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index f4d80f9050ef..043850b8c304 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -4109,7 +4109,7 @@ static netdev_tx_t s2io_xmit(struct sk_buff *skb, struct net_device *dev)
4109 struct tcphdr *th; 4109 struct tcphdr *th;
4110 ip = ip_hdr(skb); 4110 ip = ip_hdr(skb);
4111 4111
4112 if ((ip->frag_off & htons(IP_OFFSET|IP_MF)) == 0) { 4112 if (!ip_is_fragment(ip)) {
4113 th = (struct tcphdr *)(((unsigned char *)ip) + 4113 th = (struct tcphdr *)(((unsigned char *)ip) +
4114 ip->ihl*4); 4114 ip->ihl*4);
4115 4115
diff --git a/drivers/net/sfc/filter.c b/drivers/net/sfc/filter.c
index 95a980fd63d5..f2fc2587c09d 100644
--- a/drivers/net/sfc/filter.c
+++ b/drivers/net/sfc/filter.c
@@ -652,7 +652,7 @@ int efx_filter_rfs(struct net_device *net_dev, const struct sk_buff *skb,
652 /* RFS must validate the IP header length before calling us */ 652 /* RFS must validate the IP header length before calling us */
653 EFX_BUG_ON_PARANOID(!pskb_may_pull(skb, nhoff + sizeof(*ip))); 653 EFX_BUG_ON_PARANOID(!pskb_may_pull(skb, nhoff + sizeof(*ip)));
654 ip = (const struct iphdr *)(skb->data + nhoff); 654 ip = (const struct iphdr *)(skb->data + nhoff);
655 if (ip->frag_off & htons(IP_MF | IP_OFFSET)) 655 if (ip_is_fragment(ip))
656 return -EPROTONOSUPPORT; 656 return -EPROTONOSUPPORT;
657 EFX_BUG_ON_PARANOID(!pskb_may_pull(skb, nhoff + 4 * ip->ihl + 4)); 657 EFX_BUG_ON_PARANOID(!pskb_may_pull(skb, nhoff + 4 * ip->ihl + 4));
658 ports = (const __be16 *)(skb->data + nhoff + 4 * ip->ihl); 658 ports = (const __be16 *)(skb->data + nhoff + 4 * ip->ihl);
diff --git a/drivers/net/vxge/vxge-main.c b/drivers/net/vxge/vxge-main.c
index 54ca74806bb6..1c92af392992 100644
--- a/drivers/net/vxge/vxge-main.c
+++ b/drivers/net/vxge/vxge-main.c
@@ -633,7 +633,7 @@ static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb)
633 633
634 ip = ip_hdr(skb); 634 ip = ip_hdr(skb);
635 635
636 if ((ip->frag_off & htons(IP_OFFSET|IP_MF)) == 0) { 636 if (!ip_is_fragment(ip)) {
637 th = (struct tcphdr *)(((unsigned char *)ip) + 637 th = (struct tcphdr *)(((unsigned char *)ip) +
638 ip->ihl*4); 638 ip->ihl*4);
639 639
diff --git a/include/net/ip.h b/include/net/ip.h
index e9ea7c73f8c1..d603cd329c4e 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -250,6 +250,11 @@ int ip_decrease_ttl(struct iphdr *iph)
250 return --iph->ttl; 250 return --iph->ttl;
251} 251}
252 252
253static inline bool ip_is_fragment(const struct iphdr *iph)
254{
255 return (iph->frag_off & htons(IP_MF | IP_OFFSET)) != 0;
256}
257
253static inline 258static inline
254int ip_dont_fragment(struct sock *sk, struct dst_entry *dst) 259int ip_dont_fragment(struct sock *sk, struct dst_entry *dst)
255{ 260{
diff --git a/net/core/dev.c b/net/core/dev.c
index 8efe85070131..6b6ef14b42f2 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2532,7 +2532,7 @@ __u32 __skb_get_rxhash(struct sk_buff *skb)
2532 goto done; 2532 goto done;
2533 2533
2534 ip = (const struct iphdr *) (skb->data + nhoff); 2534 ip = (const struct iphdr *) (skb->data + nhoff);
2535 if (ip->frag_off & htons(IP_MF | IP_OFFSET)) 2535 if (ip_is_fragment(ip))
2536 ip_proto = 0; 2536 ip_proto = 0;
2537 else 2537 else
2538 ip_proto = ip->protocol; 2538 ip_proto = ip->protocol;
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index c8f48efc5fd3..073a9b01c40c 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -165,7 +165,7 @@ int ip_call_ra_chain(struct sk_buff *skb)
165 (!sk->sk_bound_dev_if || 165 (!sk->sk_bound_dev_if ||
166 sk->sk_bound_dev_if == dev->ifindex) && 166 sk->sk_bound_dev_if == dev->ifindex) &&
167 net_eq(sock_net(sk), dev_net(dev))) { 167 net_eq(sock_net(sk), dev_net(dev))) {
168 if (ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) { 168 if (ip_is_fragment(ip_hdr(skb))) {
169 if (ip_defrag(skb, IP_DEFRAG_CALL_RA_CHAIN)) 169 if (ip_defrag(skb, IP_DEFRAG_CALL_RA_CHAIN))
170 return 1; 170 return 1;
171 } 171 }
@@ -256,7 +256,7 @@ int ip_local_deliver(struct sk_buff *skb)
256 * Reassemble IP fragments. 256 * Reassemble IP fragments.
257 */ 257 */
258 258
259 if (ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) { 259 if (ip_is_fragment(ip_hdr(skb))) {
260 if (ip_defrag(skb, IP_DEFRAG_LOCAL_DELIVER)) 260 if (ip_defrag(skb, IP_DEFRAG_LOCAL_DELIVER))
261 return 0; 261 return 0;
262 } 262 }
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index a8024eaa0e87..167da8ba416a 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -489,7 +489,7 @@ int ip_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
489 489
490 if (first_len - hlen > mtu || 490 if (first_len - hlen > mtu ||
491 ((first_len - hlen) & 7) || 491 ((first_len - hlen) & 7) ||
492 (iph->frag_off & htons(IP_MF|IP_OFFSET)) || 492 ip_is_fragment(iph) ||
493 skb_cloned(skb)) 493 skb_cloned(skb))
494 goto slow_path; 494 goto slow_path;
495 495
diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index ab7e5542c1cf..ae93dd5ef401 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -932,7 +932,7 @@ static int __init ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, str
932 goto drop; 932 goto drop;
933 933
934 /* Fragments are not supported */ 934 /* Fragments are not supported */
935 if (h->frag_off & htons(IP_OFFSET | IP_MF)) { 935 if (ip_is_fragment(h)) {
936 if (net_ratelimit()) 936 if (net_ratelimit())
937 printk(KERN_ERR "DHCP/BOOTP: Ignoring fragmented " 937 printk(KERN_ERR "DHCP/BOOTP: Ignoring fragmented "
938 "reply.\n"); 938 "reply.\n");
diff --git a/net/ipv4/netfilter/nf_defrag_ipv4.c b/net/ipv4/netfilter/nf_defrag_ipv4.c
index f3a9b42b16c6..9bb1b8a37a22 100644
--- a/net/ipv4/netfilter/nf_defrag_ipv4.c
+++ b/net/ipv4/netfilter/nf_defrag_ipv4.c
@@ -82,7 +82,7 @@ static unsigned int ipv4_conntrack_defrag(unsigned int hooknum,
82#endif 82#endif
83#endif 83#endif
84 /* Gather fragments. */ 84 /* Gather fragments. */
85 if (ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) { 85 if (ip_is_fragment(ip_hdr(skb))) {
86 enum ip_defrag_users user = nf_ct_defrag_user(hooknum, skb); 86 enum ip_defrag_users user = nf_ct_defrag_user(hooknum, skb);
87 if (nf_ct_ipv4_gather_frags(skb, user)) 87 if (nf_ct_ipv4_gather_frags(skb, user))
88 return NF_STOLEN; 88 return NF_STOLEN;
diff --git a/net/ipv4/netfilter/nf_nat_standalone.c b/net/ipv4/netfilter/nf_nat_standalone.c
index 483b76d042da..a6e606e84820 100644
--- a/net/ipv4/netfilter/nf_nat_standalone.c
+++ b/net/ipv4/netfilter/nf_nat_standalone.c
@@ -88,7 +88,7 @@ nf_nat_fn(unsigned int hooknum,
88 88
89 /* We never see fragments: conntrack defrags on pre-routing 89 /* We never see fragments: conntrack defrags on pre-routing
90 and local-out, and nf_nat_out protects post-routing. */ 90 and local-out, and nf_nat_out protects post-routing. */
91 NF_CT_ASSERT(!(ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET))); 91 NF_CT_ASSERT(!ip_is_fragment(ip_hdr(skb)));
92 92
93 ct = nf_ct_get(skb, &ctinfo); 93 ct = nf_ct_get(skb, &ctinfo);
94 /* Can't track? It's not due to stress, or conntrack would 94 /* Can't track? It's not due to stress, or conntrack would
diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
index 981e43eaf704..fc5368ad2b0d 100644
--- a/net/ipv4/xfrm4_policy.c
+++ b/net/ipv4/xfrm4_policy.c
@@ -117,7 +117,7 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
117 memset(fl4, 0, sizeof(struct flowi4)); 117 memset(fl4, 0, sizeof(struct flowi4));
118 fl4->flowi4_mark = skb->mark; 118 fl4->flowi4_mark = skb->mark;
119 119
120 if (!(iph->frag_off & htons(IP_MF | IP_OFFSET))) { 120 if (!ip_is_fragment(iph)) {
121 switch (iph->protocol) { 121 switch (iph->protocol) {
122 case IPPROTO_UDP: 122 case IPPROTO_UDP:
123 case IPPROTO_UDPLITE: 123 case IPPROTO_UDPLITE:
diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
index e33d48cae9fd..4f77bb16d22a 100644
--- a/net/netfilter/ipvs/ip_vs_core.c
+++ b/net/netfilter/ipvs/ip_vs_core.c
@@ -852,7 +852,7 @@ static int ip_vs_out_icmp(struct sk_buff *skb, int *related,
852 *related = 1; 852 *related = 1;
853 853
854 /* reassemble IP fragments */ 854 /* reassemble IP fragments */
855 if (ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) { 855 if (ip_is_fragment(ip_hdr(skb))) {
856 if (ip_vs_gather_frags(skb, ip_vs_defrag_user(hooknum))) 856 if (ip_vs_gather_frags(skb, ip_vs_defrag_user(hooknum)))
857 return NF_STOLEN; 857 return NF_STOLEN;
858 } 858 }
@@ -1156,8 +1156,7 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)
1156 ip_vs_fill_iphdr(af, skb_network_header(skb), &iph); 1156 ip_vs_fill_iphdr(af, skb_network_header(skb), &iph);
1157 } else 1157 } else
1158#endif 1158#endif
1159 if (unlikely(ip_hdr(skb)->frag_off & htons(IP_MF|IP_OFFSET) && 1159 if (unlikely(ip_is_fragment(ip_hdr(skb)) && !pp->dont_defrag)) {
1160 !pp->dont_defrag)) {
1161 if (ip_vs_gather_frags(skb, 1160 if (ip_vs_gather_frags(skb,
1162 ip_vs_defrag_user(hooknum))) 1161 ip_vs_defrag_user(hooknum)))
1163 return NF_STOLEN; 1162 return NF_STOLEN;
@@ -1310,7 +1309,7 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)
1310 *related = 1; 1309 *related = 1;
1311 1310
1312 /* reassemble IP fragments */ 1311 /* reassemble IP fragments */
1313 if (ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) { 1312 if (ip_is_fragment(ip_hdr(skb))) {
1314 if (ip_vs_gather_frags(skb, ip_vs_defrag_user(hooknum))) 1313 if (ip_vs_gather_frags(skb, ip_vs_defrag_user(hooknum)))
1315 return NF_STOLEN; 1314 return NF_STOLEN;
1316 } 1315 }
diff --git a/net/sched/cls_flow.c b/net/sched/cls_flow.c
index 8ec01391d988..34533a5d1b3a 100644
--- a/net/sched/cls_flow.c
+++ b/net/sched/cls_flow.c
@@ -121,7 +121,7 @@ static u32 flow_get_proto_src(struct sk_buff *skb)
121 if (!pskb_network_may_pull(skb, sizeof(*iph))) 121 if (!pskb_network_may_pull(skb, sizeof(*iph)))
122 break; 122 break;
123 iph = ip_hdr(skb); 123 iph = ip_hdr(skb);
124 if (iph->frag_off & htons(IP_MF | IP_OFFSET)) 124 if (ip_is_fragment(iph))
125 break; 125 break;
126 poff = proto_ports_offset(iph->protocol); 126 poff = proto_ports_offset(iph->protocol);
127 if (poff >= 0 && 127 if (poff >= 0 &&
@@ -163,7 +163,7 @@ static u32 flow_get_proto_dst(struct sk_buff *skb)
163 if (!pskb_network_may_pull(skb, sizeof(*iph))) 163 if (!pskb_network_may_pull(skb, sizeof(*iph)))
164 break; 164 break;
165 iph = ip_hdr(skb); 165 iph = ip_hdr(skb);
166 if (iph->frag_off & htons(IP_MF | IP_OFFSET)) 166 if (ip_is_fragment(iph))
167 break; 167 break;
168 poff = proto_ports_offset(iph->protocol); 168 poff = proto_ports_offset(iph->protocol);
169 if (poff >= 0 && 169 if (poff >= 0 &&
diff --git a/net/sched/cls_rsvp.h b/net/sched/cls_rsvp.h
index 402c44b241a3..ed691b148384 100644
--- a/net/sched/cls_rsvp.h
+++ b/net/sched/cls_rsvp.h
@@ -167,7 +167,7 @@ restart:
167 dst = &nhptr->daddr; 167 dst = &nhptr->daddr;
168 protocol = nhptr->protocol; 168 protocol = nhptr->protocol;
169 xprt = ((u8 *)nhptr) + (nhptr->ihl<<2); 169 xprt = ((u8 *)nhptr) + (nhptr->ihl<<2);
170 if (nhptr->frag_off & htons(IP_MF | IP_OFFSET)) 170 if (ip_is_fragment(nhptr))
171 return -1; 171 return -1;
172#endif 172#endif
173 173
diff --git a/net/sched/sch_choke.c b/net/sched/sch_choke.c
index 06afbaeb4c88..3422b25df9e4 100644
--- a/net/sched/sch_choke.c
+++ b/net/sched/sch_choke.c
@@ -181,7 +181,7 @@ static bool choke_match_flow(struct sk_buff *skb1,
181 ip1->saddr != ip2->saddr || ip1->daddr != ip2->daddr) 181 ip1->saddr != ip2->saddr || ip1->daddr != ip2->daddr)
182 return false; 182 return false;
183 183
184 if ((ip1->frag_off | ip2->frag_off) & htons(IP_MF | IP_OFFSET)) 184 if (ip_is_fragment(ip1) | ip_is_fragment(ip2))
185 ip_proto = 0; 185 ip_proto = 0;
186 off1 += ip1->ihl * 4; 186 off1 += ip1->ihl * 4;
187 off2 += ip2->ihl * 4; 187 off2 += ip2->ihl * 4;
diff --git a/net/sched/sch_sfq.c b/net/sched/sch_sfq.c
index b6ea6afa55b0..4536ee64383e 100644
--- a/net/sched/sch_sfq.c
+++ b/net/sched/sch_sfq.c
@@ -157,7 +157,7 @@ static unsigned int sfq_hash(struct sfq_sched_data *q, struct sk_buff *skb)
157 iph = ip_hdr(skb); 157 iph = ip_hdr(skb);
158 h = (__force u32)iph->daddr; 158 h = (__force u32)iph->daddr;
159 h2 = (__force u32)iph->saddr ^ iph->protocol; 159 h2 = (__force u32)iph->saddr ^ iph->protocol;
160 if (iph->frag_off & htons(IP_MF | IP_OFFSET)) 160 if (ip_is_fragment(iph))
161 break; 161 break;
162 poff = proto_ports_offset(iph->protocol); 162 poff = proto_ports_offset(iph->protocol);
163 if (poff >= 0 && 163 if (poff >= 0 &&