Skip to content

Commit

Permalink
ip: IP cmsg cleanup
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Tom Herbert authored and David S. Miller committed Jan 6, 2015
1 parent 224d019 commit c44d13d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 28 deletions.
11 changes: 10 additions & 1 deletion include/net/inet_sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#ifndef _INET_SOCK_H
#define _INET_SOCK_H


#include <linux/bitops.h>
#include <linux/kmemcheck.h>
#include <linux/string.h>
#include <linux/types.h>
Expand Down Expand Up @@ -195,6 +195,15 @@ struct inet_sock {
#define IPCORK_OPT 1 /* ip-options has been held in ipcork.opt */
#define IPCORK_ALLFRAG 2 /* always fragment (for ipv6 for now) */

/* cmsg flags for inet */
#define IP_CMSG_PKTINFO BIT(0)
#define IP_CMSG_TTL BIT(1)
#define IP_CMSG_TOS BIT(2)
#define IP_CMSG_RECVOPTS BIT(3)
#define IP_CMSG_RETOPTS BIT(4)
#define IP_CMSG_PASSSEC BIT(5)
#define IP_CMSG_ORIGDSTADDR BIT(6)

static inline struct inet_sock *inet_sk(const struct sock *sk)
{
return (struct inet_sock *)sk;
Expand Down
64 changes: 37 additions & 27 deletions net/ipv4/ip_sockglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@
#include <linux/errqueue.h>
#include <asm/uaccess.h>

#define IP_CMSG_PKTINFO 1
#define IP_CMSG_TTL 2
#define IP_CMSG_TOS 4
#define IP_CMSG_RECVOPTS 8
#define IP_CMSG_RETOPTS 16
#define IP_CMSG_PASSSEC 32
#define IP_CMSG_ORIGDSTADDR 64

/*
* SOL_IP control messages.
*/
Expand Down Expand Up @@ -150,37 +142,55 @@ void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb)
unsigned int flags = inet->cmsg_flags;

/* Ordered by supposed usage frequency */
if (flags & 1)
if (flags & IP_CMSG_PKTINFO) {
ip_cmsg_recv_pktinfo(msg, skb);
if ((flags >>= 1) == 0)
return;

if (flags & 1)
flags &= ~IP_CMSG_PKTINFO;
if (!flags)
return;
}

if (flags & IP_CMSG_TTL) {
ip_cmsg_recv_ttl(msg, skb);
if ((flags >>= 1) == 0)
return;

if (flags & 1)
flags &= ~IP_CMSG_TTL;
if (!flags)
return;
}

if (flags & IP_CMSG_TOS) {
ip_cmsg_recv_tos(msg, skb);
if ((flags >>= 1) == 0)
return;

if (flags & 1)
flags &= ~IP_CMSG_TOS;
if (!flags)
return;
}

if (flags & IP_CMSG_RECVOPTS) {
ip_cmsg_recv_opts(msg, skb);
if ((flags >>= 1) == 0)
return;

if (flags & 1)
flags &= ~IP_CMSG_RECVOPTS;
if (!flags)
return;
}

if (flags & IP_CMSG_RETOPTS) {
ip_cmsg_recv_retopts(msg, skb);
if ((flags >>= 1) == 0)
return;

if (flags & 1)
flags &= ~IP_CMSG_RETOPTS;
if (!flags)
return;
}

if (flags & IP_CMSG_PASSSEC) {
ip_cmsg_recv_security(msg, skb);

if ((flags >>= 1) == 0)
return;
if (flags & 1)
flags &= ~IP_CMSG_PASSSEC;
if (!flags)
return;
}

if (flags & IP_CMSG_ORIGDSTADDR)
ip_cmsg_recv_dstaddr(msg, skb);

}
Expand Down

0 comments on commit c44d13d

Please sign in to comment.