Commit 56f8a75c17abb854b5907f4a815dc4c3f186ba11
Committed by
David S. Miller
1 parent
f470e5ae34
Exists in
master
and in
4 other branches
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
- drivers/net/ioc3-eth.c
- drivers/net/myri10ge/myri10ge.c
- drivers/net/s2io.c
- drivers/net/sfc/filter.c
- drivers/net/vxge/vxge-main.c
- include/net/ip.h
- net/core/dev.c
- net/ipv4/ip_input.c
- net/ipv4/ip_output.c
- net/ipv4/ipconfig.c
- net/ipv4/netfilter/nf_defrag_ipv4.c
- net/ipv4/netfilter/nf_nat_standalone.c
- net/ipv4/xfrm4_policy.c
- net/netfilter/ipvs/ip_vs_core.c
- net/sched/cls_flow.c
- net/sched/cls_rsvp.h
- net/sched/sch_choke.c
- net/sched/sch_sfq.c
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
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); |
drivers/net/s2io.c
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
include/net/ip.h
... | ... | @@ -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 | { |
net/core/dev.c
net/ipv4/ip_input.c
... | ... | @@ -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
net/ipv4/ipconfig.c
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
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; |
net/sched/sch_sfq.c
... | ... | @@ -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 && |