Permalink
Browse files

added getcred sysctl functions for IPv6

  • Loading branch information...
shin
shin committed Sep 27, 1999
1 parent 7902baa commit 4eabd309163b4fd9132b7176559c7fdba527cc4a
Showing with 82 additions and 0 deletions.
  1. +41 −0 freebsd3/sys/netinet/tcp_subr.c
  2. +41 −0 freebsd3/sys/netinet6/udp6_usrreq.c
@@ -848,6 +848,47 @@ tcp_getcred SYSCTL_HANDLER_ARGS
SYSCTL_PROC(_net_inet_tcp, OID_AUTO, getcred, CTLTYPE_OPAQUE|CTLFLAG_RW, 0, 0,
tcp_getcred, "S,ucred", "Get the ucred of a TCP connection");
+#ifdef INET6
+static int
+tcp6_getcred SYSCTL_HANDLER_ARGS
+{
+ struct sockaddr_in6 addrs[2];
+ struct inpcb *inp;
+ int error, s;
+
+ error = suser(req->p->p_ucred, &req->p->p_acflag);
+ if (error)
+ return (error);
+
+ if (req->newlen != sizeof(addrs))
+ return (EINVAL);
+ if (req->oldlen != sizeof(struct ucred))
+ return (EINVAL);
+ error = SYSCTL_IN(req, addrs, sizeof(addrs));
+ if (error)
+ return (error);
+ s = splnet();
+ inp = in6_pcblookup_hash(&tcbinfo, &addrs[1].sin6_addr,
+ addrs[1].sin6_port,
+ &addrs[0].sin6_addr, addrs[0].sin6_port,
+ 0, NULL);
+ if (!inp || !inp->inp_socket || !inp->inp_socket->so_cred) {
+ error = ENOENT;
+ goto out;
+ }
+ error = SYSCTL_OUT(req, inp->inp_socket->so_cred->pc_ucred,
+ sizeof(struct ucred));
+
+out:
+ splx(s);
+ return (error);
+}
+
+SYSCTL_PROC(_net_inet6_tcp6, OID_AUTO, getcred, CTLTYPE_OPAQUE|CTLFLAG_RW,
+ 0, 0,
+ tcp6_getcred, "S,ucred", "Get the ucred of a TCP6 connection");
+#endif
+
void
tcp_ctlinput(cmd, sa, vip)
int cmd;
@@ -67,11 +67,13 @@
#endif
#include <sys/param.h>
+#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
+#include <sys/sysctl.h>
#include <sys/errno.h>
#include <sys/stat.h>
#include <sys/systm.h>
@@ -551,6 +553,45 @@ udp6_ctlinput(cmd, sa, ip6, m, off)
&zeroin6_addr, 0, cmd, udp_notify);
}
+static int
+udp6_getcred SYSCTL_HANDLER_ARGS
+{
+ struct sockaddr_in6 addrs[2];
+ struct inpcb *inp;
+ int error, s;
+
+ error = suser(req->p->p_ucred, &req->p->p_acflag);
+ if (error)
+ return (error);
+
+ if (req->newlen != sizeof(addrs))
+ return (EINVAL);
+ if (req->oldlen != sizeof(struct ucred))
+ return (EINVAL);
+ error = SYSCTL_IN(req, addrs, sizeof(addrs));
+ if (error)
+ return (error);
+ s = splnet();
+ inp = in6_pcblookup_hash(&udbinfo, &addrs[1].sin6_addr,
+ addrs[1].sin6_port,
+ &addrs[0].sin6_addr, addrs[0].sin6_port,
+ 1, NULL);
+ if (!inp || !inp->inp_socket || !inp->inp_socket->so_cred) {
+ error = ENOENT;
+ goto out;
+ }
+ error = SYSCTL_OUT(req, inp->inp_socket->so_cred->pc_ucred,
+ sizeof(struct ucred));
+
+out:
+ splx(s);
+ return (error);
+}
+
+SYSCTL_PROC(_net_inet6_udp6, OID_AUTO, getcred, CTLTYPE_OPAQUE|CTLFLAG_RW,
+ 0, 0,
+ udp6_getcred, "S,ucred", "Get the ucred of a UDP6 connection");
+
int
udp6_output(in6p, m, addr6, control, p)
register struct inpcb *in6p;

0 comments on commit 4eabd30

Please sign in to comment.