Skip to content

Commit f02db31

Browse files
Francesco Fuscodavem330
authored andcommitted
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: Francesco Fusco <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f0e28d4 commit f02db31

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

include/net/ip.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ struct ipcm_cookie {
5656
int oif;
5757
struct ip_options_rcu *opt;
5858
__u8 tx_flags;
59+
__u8 ttl;
60+
__s16 tos;
61+
char priority;
5962
};
6063

6164
#define IPCB(skb) ((struct inet_skb_parm*)((skb)->cb))

net/ipv4/ip_sockglue.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ EXPORT_SYMBOL(ip_cmsg_recv);
189189

190190
int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc)
191191
{
192-
int err;
192+
int err, val;
193193
struct cmsghdr *cmsg;
194194

195195
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)
215215
ipc->addr = info->ipi_spec_dst.s_addr;
216216
break;
217217
}
218+
case IP_TTL:
219+
if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)))
220+
return -EINVAL;
221+
val = *(int *)CMSG_DATA(cmsg);
222+
if (val < 1 || val > 255)
223+
return -EINVAL;
224+
ipc->ttl = val;
225+
break;
226+
case IP_TOS:
227+
if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)))
228+
return -EINVAL;
229+
val = *(int *)CMSG_DATA(cmsg);
230+
if (val < 0 || val > 255)
231+
return -EINVAL;
232+
ipc->tos = val;
233+
ipc->priority = rt_tos2priority(ipc->tos);
234+
break;
235+
218236
default:
219237
return -EINVAL;
220238
}

0 commit comments

Comments
 (0)