Commit 56f8a75c17abb854b5907f4a815dc4c3f186ba11

Authored by Paul Gortmaker
Committed by David S. Miller
1 parent f470e5ae34

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>

Showing 19 changed files with 27 additions and 23 deletions Side-by-side Diff

drivers/net/bonding/bond_main.c
... ... @@ -3438,7 +3438,7 @@
3438 3438 int layer4_xor = 0;
3439 3439  
3440 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 3442 (iph->protocol == IPPROTO_TCP ||
3443 3443 iph->protocol == IPPROTO_UDP)) {
3444 3444 layer4_xor = ntohs((*layer4hdr ^ *(layer4hdr + 1)));
drivers/net/ioc3-eth.c
... ... @@ -532,7 +532,7 @@
532 532 return;
533 533  
534 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 536 return;
537 537  
538 538 proto = ih->protocol;
drivers/net/myri10ge/myri10ge.c
... ... @@ -2257,7 +2257,7 @@
2257 2257 *ip_hdr = iph;
2258 2258 if (iph->protocol != IPPROTO_TCP)
2259 2259 return -1;
2260   - if (iph->frag_off & htons(IP_MF | IP_OFFSET))
  2260 + if (ip_is_fragment(iph))
2261 2261 return -1;
2262 2262 *hdr_flags |= LRO_TCP;
2263 2263 *tcpudp_hdr = (u8 *) (*ip_hdr) + (iph->ihl << 2);
... ... @@ -4109,7 +4109,7 @@
4109 4109 struct tcphdr *th;
4110 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 4113 th = (struct tcphdr *)(((unsigned char *)ip) +
4114 4114 ip->ihl*4);
4115 4115  
drivers/net/sfc/filter.c
... ... @@ -652,7 +652,7 @@
652 652 /* RFS must validate the IP header length before calling us */
653 653 EFX_BUG_ON_PARANOID(!pskb_may_pull(skb, nhoff + sizeof(*ip)));
654 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 656 return -EPROTONOSUPPORT;
657 657 EFX_BUG_ON_PARANOID(!pskb_may_pull(skb, nhoff + 4 * ip->ihl + 4));
658 658 ports = (const __be16 *)(skb->data + nhoff + 4 * ip->ihl);
drivers/net/vxge/vxge-main.c
... ... @@ -633,7 +633,7 @@
633 633  
634 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 637 th = (struct tcphdr *)(((unsigned char *)ip) +
638 638 ip->ihl*4);
639 639  
... ... @@ -250,6 +250,11 @@
250 250 return --iph->ttl;
251 251 }
252 252  
  253 +static inline bool ip_is_fragment(const struct iphdr *iph)
  254 +{
  255 + return (iph->frag_off & htons(IP_MF | IP_OFFSET)) != 0;
  256 +}
  257 +
253 258 static inline
254 259 int ip_dont_fragment(struct sock *sk, struct dst_entry *dst)
255 260 {
... ... @@ -2532,7 +2532,7 @@
2532 2532 goto done;
2533 2533  
2534 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 2536 ip_proto = 0;
2537 2537 else
2538 2538 ip_proto = ip->protocol;
... ... @@ -165,7 +165,7 @@
165 165 (!sk->sk_bound_dev_if ||
166 166 sk->sk_bound_dev_if == dev->ifindex) &&
167 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 169 if (ip_defrag(skb, IP_DEFRAG_CALL_RA_CHAIN))
170 170 return 1;
171 171 }
... ... @@ -256,7 +256,7 @@
256 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 260 if (ip_defrag(skb, IP_DEFRAG_LOCAL_DELIVER))
261 261 return 0;
262 262 }
net/ipv4/ip_output.c
... ... @@ -489,7 +489,7 @@
489 489  
490 490 if (first_len - hlen > mtu ||
491 491 ((first_len - hlen) & 7) ||
492   - (iph->frag_off & htons(IP_MF|IP_OFFSET)) ||
  492 + ip_is_fragment(iph) ||
493 493 skb_cloned(skb))
494 494 goto slow_path;
495 495  
... ... @@ -932,7 +932,7 @@
932 932 goto drop;
933 933  
934 934 /* Fragments are not supported */
935   - if (h->frag_off & htons(IP_OFFSET | IP_MF)) {
  935 + if (ip_is_fragment(h)) {
936 936 if (net_ratelimit())
937 937 printk(KERN_ERR "DHCP/BOOTP: Ignoring fragmented "
938 938 "reply.\n");
net/ipv4/netfilter/nf_defrag_ipv4.c
... ... @@ -82,7 +82,7 @@
82 82 #endif
83 83 #endif
84 84 /* Gather fragments. */
85   - if (ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) {
  85 + if (ip_is_fragment(ip_hdr(skb))) {
86 86 enum ip_defrag_users user = nf_ct_defrag_user(hooknum, skb);
87 87 if (nf_ct_ipv4_gather_frags(skb, user))
88 88 return NF_STOLEN;
net/ipv4/netfilter/nf_nat_standalone.c
... ... @@ -88,7 +88,7 @@
88 88  
89 89 /* We never see fragments: conntrack defrags on pre-routing
90 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 93 ct = nf_ct_get(skb, &ctinfo);
94 94 /* Can't track? It's not due to stress, or conntrack would
net/ipv4/xfrm4_policy.c
... ... @@ -117,7 +117,7 @@
117 117 memset(fl4, 0, sizeof(struct flowi4));
118 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 121 switch (iph->protocol) {
122 122 case IPPROTO_UDP:
123 123 case IPPROTO_UDPLITE:
net/netfilter/ipvs/ip_vs_core.c
... ... @@ -852,7 +852,7 @@
852 852 *related = 1;
853 853  
854 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 856 if (ip_vs_gather_frags(skb, ip_vs_defrag_user(hooknum)))
857 857 return NF_STOLEN;
858 858 }
... ... @@ -1156,8 +1156,7 @@
1156 1156 ip_vs_fill_iphdr(af, skb_network_header(skb), &iph);
1157 1157 } else
1158 1158 #endif
1159   - if (unlikely(ip_hdr(skb)->frag_off & htons(IP_MF|IP_OFFSET) &&
1160   - !pp->dont_defrag)) {
  1159 + if (unlikely(ip_is_fragment(ip_hdr(skb)) && !pp->dont_defrag)) {
1161 1160 if (ip_vs_gather_frags(skb,
1162 1161 ip_vs_defrag_user(hooknum)))
1163 1162 return NF_STOLEN;
... ... @@ -1310,7 +1309,7 @@
1310 1309 *related = 1;
1311 1310  
1312 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 1313 if (ip_vs_gather_frags(skb, ip_vs_defrag_user(hooknum)))
1315 1314 return NF_STOLEN;
1316 1315 }
net/sched/cls_flow.c
... ... @@ -121,7 +121,7 @@
121 121 if (!pskb_network_may_pull(skb, sizeof(*iph)))
122 122 break;
123 123 iph = ip_hdr(skb);
124   - if (iph->frag_off & htons(IP_MF | IP_OFFSET))
  124 + if (ip_is_fragment(iph))
125 125 break;
126 126 poff = proto_ports_offset(iph->protocol);
127 127 if (poff >= 0 &&
... ... @@ -163,7 +163,7 @@
163 163 if (!pskb_network_may_pull(skb, sizeof(*iph)))
164 164 break;
165 165 iph = ip_hdr(skb);
166   - if (iph->frag_off & htons(IP_MF | IP_OFFSET))
  166 + if (ip_is_fragment(iph))
167 167 break;
168 168 poff = proto_ports_offset(iph->protocol);
169 169 if (poff >= 0 &&
net/sched/cls_rsvp.h
... ... @@ -167,7 +167,7 @@
167 167 dst = &nhptr->daddr;
168 168 protocol = nhptr->protocol;
169 169 xprt = ((u8 *)nhptr) + (nhptr->ihl<<2);
170   - if (nhptr->frag_off & htons(IP_MF | IP_OFFSET))
  170 + if (ip_is_fragment(nhptr))
171 171 return -1;
172 172 #endif
173 173  
net/sched/sch_choke.c
... ... @@ -181,7 +181,7 @@
181 181 ip1->saddr != ip2->saddr || ip1->daddr != ip2->daddr)
182 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 185 ip_proto = 0;
186 186 off1 += ip1->ihl * 4;
187 187 off2 += ip2->ihl * 4;
... ... @@ -157,7 +157,7 @@
157 157 iph = ip_hdr(skb);
158 158 h = (__force u32)iph->daddr;
159 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 161 break;
162 162 poff = proto_ports_offset(iph->protocol);
163 163 if (poff >= 0 &&