aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/ip_sockglue.c
diff options
context:
space:
mode:
authorTom Herbert <therbert@google.com>2015-01-05 16:56:15 -0500
committerDavid S. Miller <davem@davemloft.net>2015-01-05 22:44:46 -0500
commitc44d13d6f341ca59f3d6646f2337d4d3c8a814a6 (patch)
tree03e510be58acdf0ff3aa10cc5f5366f51343f22b /net/ipv4/ip_sockglue.c
parent224d019c4fbba242041e9b25a926ba873b7da1e2 (diff)
ip: IP cmsg cleanup
Move the IP_CMSG_* constants from ip_sockglue.c to inet_sock.h so that they can be referenced in other source files. Restructure ip_cmsg_recv to not go through flags using shift, check for flags by 'and'. This eliminates both the shift and a conditional per flag check. Signed-off-by: Tom Herbert <therbert@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/ip_sockglue.c')
-rw-r--r--net/ipv4/ip_sockglue.c64
1 files changed, 37 insertions, 27 deletions
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 8a89c738b7a3..80f78565b41b 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -45,14 +45,6 @@
45#include <linux/errqueue.h> 45#include <linux/errqueue.h>
46#include <asm/uaccess.h> 46#include <asm/uaccess.h>
47 47
48#define IP_CMSG_PKTINFO 1
49#define IP_CMSG_TTL 2
50#define IP_CMSG_TOS 4
51#define IP_CMSG_RECVOPTS 8
52#define IP_CMSG_RETOPTS 16
53#define IP_CMSG_PASSSEC 32
54#define IP_CMSG_ORIGDSTADDR 64
55
56/* 48/*
57 * SOL_IP control messages. 49 * SOL_IP control messages.
58 */ 50 */
@@ -150,37 +142,55 @@ void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb)
150 unsigned int flags = inet->cmsg_flags; 142 unsigned int flags = inet->cmsg_flags;
151 143
152 /* Ordered by supposed usage frequency */ 144 /* Ordered by supposed usage frequency */
153 if (flags & 1) 145 if (flags & IP_CMSG_PKTINFO) {
154 ip_cmsg_recv_pktinfo(msg, skb); 146 ip_cmsg_recv_pktinfo(msg, skb);
155 if ((flags >>= 1) == 0)
156 return;
157 147
158 if (flags & 1) 148 flags &= ~IP_CMSG_PKTINFO;
149 if (!flags)
150 return;
151 }
152
153 if (flags & IP_CMSG_TTL) {
159 ip_cmsg_recv_ttl(msg, skb); 154 ip_cmsg_recv_ttl(msg, skb);
160 if ((flags >>= 1) == 0)
161 return;
162 155
163 if (flags & 1) 156 flags &= ~IP_CMSG_TTL;
157 if (!flags)
158 return;
159 }
160
161 if (flags & IP_CMSG_TOS) {
164 ip_cmsg_recv_tos(msg, skb); 162 ip_cmsg_recv_tos(msg, skb);
165 if ((flags >>= 1) == 0)
166 return;
167 163
168 if (flags & 1) 164 flags &= ~IP_CMSG_TOS;
165 if (!flags)
166 return;
167 }
168
169 if (flags & IP_CMSG_RECVOPTS) {
169 ip_cmsg_recv_opts(msg, skb); 170 ip_cmsg_recv_opts(msg, skb);
170 if ((flags >>= 1) == 0)
171 return;
172 171
173 if (flags & 1) 172 flags &= ~IP_CMSG_RECVOPTS;
173 if (!flags)
174 return;
175 }
176
177 if (flags & IP_CMSG_RETOPTS) {
174 ip_cmsg_recv_retopts(msg, skb); 178 ip_cmsg_recv_retopts(msg, skb);
175 if ((flags >>= 1) == 0)
176 return;
177 179
178 if (flags & 1) 180 flags &= ~IP_CMSG_RETOPTS;
181 if (!flags)
182 return;
183 }
184
185 if (flags & IP_CMSG_PASSSEC) {
179 ip_cmsg_recv_security(msg, skb); 186 ip_cmsg_recv_security(msg, skb);
180 187
181 if ((flags >>= 1) == 0) 188 flags &= ~IP_CMSG_PASSSEC;
182 return; 189 if (!flags)
183 if (flags & 1) 190 return;
191 }
192
193 if (flags & IP_CMSG_ORIGDSTADDR)
184 ip_cmsg_recv_dstaddr(msg, skb); 194 ip_cmsg_recv_dstaddr(msg, skb);
185 195
186} 196}