diff mbox

[net-next,1/2] ipv4: IP_TOS and IP_TTL can be specified as ancillary data

Message ID 92ffe52615a79259cd7cc120e504a9cf41dd546e.1376494031.git.ffusco@redhat.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Francesco Fusco Aug. 14, 2013, 3:48 p.m. UTC
This patch enables the IP_TTL and IP_TOS values passed from userspace to
be stored in the ipcm_cookie struct.

Signed-off-by: Francesco Fusco <ffusco@redhat.com>
---
 include/net/ip.h       |  3 +++
 net/ipv4/ip_sockglue.c | 20 +++++++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

Comments

David Miller Aug. 15, 2013, 8:51 p.m. UTC | #1
From: Francesco Fusco <ffusco@redhat.com>
Date: Wed, 14 Aug 2013 17:48:38 +0200

> +	__s16			ttl;
> +	__s16			tos;

You're range validating these values to make sure they are always
between 1 and 255, inclusive.

Why use a 16-bit value, and in particular a signed one?  That makes
absolutely no sense at all.

These fit perfectly in a "u8" so use that instead.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/net/ip.h b/include/net/ip.h
index a68f838..bf63936 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -54,6 +54,9 @@  static inline unsigned int ip_hdrlen(const struct sk_buff *skb)
 struct ipcm_cookie {
 	__be32			addr;
 	int			oif;
+	__s16			ttl;
+	__s16			tos;
+	__u32			priority;
 	struct ip_options_rcu	*opt;
 	__u8			tx_flags;
 };
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index d9c4f11..56e3445 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -189,7 +189,7 @@  EXPORT_SYMBOL(ip_cmsg_recv);
 
 int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc)
 {
-	int err;
+	int err, val;
 	struct cmsghdr *cmsg;
 
 	for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) {
@@ -215,6 +215,24 @@  int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc)
 			ipc->addr = info->ipi_spec_dst.s_addr;
 			break;
 		}
+		case IP_TTL:
+			if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)))
+				return -EINVAL;
+			val = *(int *)CMSG_DATA(cmsg);
+			if (val < 1 || val > 255)
+				return -EINVAL;
+			ipc->ttl = val;
+			break;
+		case IP_TOS:
+			if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)))
+				return -EINVAL;
+			val = *(int *)CMSG_DATA(cmsg);
+			if (val < 0 || val > 255)
+				return -EINVAL;
+			ipc->tos = val;
+			ipc->priority = rt_tos2priority(ipc->tos);
+			break;
+
 		default:
 			return -EINVAL;
 		}