Commit f02db315 authored by Francesco Fusco's avatar Francesco Fusco Committed by David S. Miller

ipv4: IP_TOS and IP_TTL can be specified as ancillary data

This patch enables the IP_TTL and IP_TOS values passed from userspace to
be stored in the ipcm_cookie struct. Three fields are added to the struct:

- the TTL, expressed as __u8.
  The allowed values are in the [1-255].
  A value of 0 means that the TTL is not specified.

- the TOS, expressed as __s16.
  The allowed values are in the range [0,255].
  A value of -1 means that the TOS is not specified.

- the priority, expressed as a char and computed when
  handling the ancillary data.
Signed-off-by: default avatarFrancesco Fusco <ffusco@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f0e28d48
...@@ -56,6 +56,9 @@ struct ipcm_cookie { ...@@ -56,6 +56,9 @@ struct ipcm_cookie {
int oif; int oif;
struct ip_options_rcu *opt; struct ip_options_rcu *opt;
__u8 tx_flags; __u8 tx_flags;
__u8 ttl;
__s16 tos;
char priority;
}; };
#define IPCB(skb) ((struct inet_skb_parm*)((skb)->cb)) #define IPCB(skb) ((struct inet_skb_parm*)((skb)->cb))
......
...@@ -189,7 +189,7 @@ EXPORT_SYMBOL(ip_cmsg_recv); ...@@ -189,7 +189,7 @@ EXPORT_SYMBOL(ip_cmsg_recv);
int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc) int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc)
{ {
int err; int err, val;
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, 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) ...@@ -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; ipc->addr = info->ipi_spec_dst.s_addr;
break; 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: default:
return -EINVAL; return -EINVAL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment