aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--include/net/inet_sock.h11
-rw-r--r--net/ipv4/ip_sockglue.c64
2 files changed, 47 insertions, 28 deletions
diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h
index 360b110b3e36..605ca421d5ab 100644
--- a/include/net/inet_sock.h
+++ b/include/net/inet_sock.h
@@ -16,7 +16,7 @@
16#ifndef _INET_SOCK_H 16#ifndef _INET_SOCK_H
17#define _INET_SOCK_H 17#define _INET_SOCK_H
18 18
19 19#include <linux/bitops.h>
20#include <linux/kmemcheck.h> 20#include <linux/kmemcheck.h>
21#include <linux/string.h> 21#include <linux/string.h>
22#include <linux/types.h> 22#include <linux/types.h>
@@ -195,6 +195,15 @@ struct inet_sock {
195#define IPCORK_OPT 1 /* ip-options has been held in ipcork.opt */ 195#define IPCORK_OPT 1 /* ip-options has been held in ipcork.opt */
196#define IPCORK_ALLFRAG 2 /* always fragment (for ipv6 for now) */ 196#define IPCORK_ALLFRAG 2 /* always fragment (for ipv6 for now) */
197 197
198/* cmsg flags for inet */
199#define IP_CMSG_PKTINFO BIT(0)
200#define IP_CMSG_TTL BIT(1)
201#define IP_CMSG_TOS BIT(2)
202#define IP_CMSG_RECVOPTS BIT(3)
203#define IP_CMSG_RETOPTS BIT(4)
204#define IP_CMSG_PASSSEC BIT(5)
205#define IP_CMSG_ORIGDSTADDR BIT(6)
206
198static inline struct inet_sock *inet_sk(const struct sock *sk) 207static inline struct inet_sock *inet_sk(const struct sock *sk)
199{ 208{
200 return (struct inet_sock *)sk; 209 return (struct inet_sock *)sk;
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}