summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbenno <benno@openbsd.org>2015-10-20 20:22:42 +0000
committerbenno <benno@openbsd.org>2015-10-20 20:22:42 +0000
commitcdd79de48c88bd7c662bcd79e6b54b0243bd1253 (patch)
treec74bbafac5a022843661e77d6029d2b6009d7963
parentFix write to other user's tty. The device has to be opened with (diff)
downloadwireguard-openbsd-cdd79de48c88bd7c662bcd79e6b54b0243bd1253.tar.xz
wireguard-openbsd-cdd79de48c88bd7c662bcd79e6b54b0243bd1253.zip
add a new getsockopt option IP_IPDEFTTL to retrieve the default ttl.
this can be used as an alternative to sysctl net.inet.ip.ttl, in programs that use pledge(). ok reyk@, "Like this" deraadt@
-rw-r--r--share/man/man4/ip.411
-rw-r--r--sys/netinet/in.h3
-rw-r--r--sys/netinet/ip_output.c7
3 files changed, 16 insertions, 5 deletions
diff --git a/share/man/man4/ip.4 b/share/man/man4/ip.4
index 537d6e7226b..72b60dc7545 100644
--- a/share/man/man4/ip.4
+++ b/share/man/man4/ip.4
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ip.4,v 1.36 2015/09/10 17:55:21 schwarze Exp $
+.\" $OpenBSD: ip.4,v 1.37 2015/10/20 20:22:42 benno Exp $
.\" $NetBSD: ip.4,v 1.3 1994/11/30 16:22:19 jtc Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
@@ -30,7 +30,7 @@
.\"
.\" @(#)ip.4 8.2 (Berkeley) 11/30/93
.\"
-.Dd $Mdocdate: September 10 2015 $
+.Dd $Mdocdate: October 20 2015 $
.Dt IP 4
.Os
.Sh NAME
@@ -97,8 +97,10 @@ fields in the
.Tn IP
header for
.Dv SOCK_STREAM
-and
+,
.Dv SOCK_DGRAM
+and
+.Dv SOCK_RAW
sockets.
For example,
.Bd -literal -offset indent
@@ -109,6 +111,9 @@ int ttl = 60; /* max = 255 */
setsockopt(s, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));
.Ed
.Pp
+.Dv IP_IPDEFTTL
+can be used to retrieve the system wide default ttl.
+.Pp
If the
.Dv IP_RECVDSTADDR
option is enabled on a
diff --git a/sys/netinet/in.h b/sys/netinet/in.h
index 7c206e5d5cb..adb1b30e4d0 100644
--- a/sys/netinet/in.h
+++ b/sys/netinet/in.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: in.h,v 1.114 2015/04/14 12:22:15 mikeb Exp $ */
+/* $OpenBSD: in.h,v 1.115 2015/10/20 20:22:42 benno Exp $ */
/* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */
/*
@@ -306,6 +306,7 @@ struct ip_opts {
#define IP_PIPEX 34 /* bool; using PIPEX */
#define IP_RECVRTABLE 35 /* bool; receive rdomain w/dgram */
#define IP_IPSECFLOWINFO 36 /* bool; IPsec flow info for dgram */
+#define IP_IPDEFTTL 37 /* int; IP TTL system default */
#define IP_RTABLE 0x1021 /* int; routing table, see SO_RTABLE */
#define IP_DIVERTFL 0x1022 /* int; divert direction flag opt */
diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c
index 8d575b7904d..5e9147a1014 100644
--- a/sys/netinet/ip_output.c
+++ b/sys/netinet/ip_output.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_output.c,v 1.302 2015/10/19 12:10:05 mpi Exp $ */
+/* $OpenBSD: ip_output.c,v 1.303 2015/10/20 20:22:42 benno Exp $ */
/* $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $ */
/*
@@ -1088,6 +1088,7 @@ ip_ctloutput(int op, struct socket *so, int level, int optname,
case IP_RECVDSTPORT:
case IP_RECVRTABLE:
case IP_IPSECFLOWINFO:
+ case IP_IPDEFTTL:
*mp = m = m_get(M_WAIT, MT_SOOPTS);
m->m_len = sizeof(int);
switch (optname) {
@@ -1104,6 +1105,10 @@ ip_ctloutput(int op, struct socket *so, int level, int optname,
optval = inp->inp_ip_minttl;
break;
+ case IP_IPDEFTTL:
+ optval = ip_defttl;
+ break;
+
#define OPTBIT(bit) (inp->inp_flags & bit ? 1 : 0)
case IP_RECVOPTS: