summaryrefslogtreecommitdiff
path: root/sys/netinet/raw_ip.c
diff options
context:
space:
mode:
authorSebastian Benoit <benno@cvs.openbsd.org>2012-10-21 13:06:04 +0000
committerSebastian Benoit <benno@cvs.openbsd.org>2012-10-21 13:06:04 +0000
commit13f32dc0f32386032d455dd5fdf1dfd69753bc9b (patch)
tree7bc9068d988d2f743617f60fc94410b009530734 /sys/netinet/raw_ip.c
parent036204675e038878c1b3a43a17ff283b77e9d7ee (diff)
Add the IP_DIVERTFL socket option on divert(4) sockets to control
which packets (as in direction) of the traffic will be diverted through the divert socket. ok claudio@, henning@
Diffstat (limited to 'sys/netinet/raw_ip.c')
-rw-r--r--sys/netinet/raw_ip.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c
index 91b445d966e..61285a8a4a6 100644
--- a/sys/netinet/raw_ip.c
+++ b/sys/netinet/raw_ip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: raw_ip.c,v 1.61 2012/03/17 10:16:41 dlg Exp $ */
+/* $OpenBSD: raw_ip.c,v 1.62 2012/10/21 13:06:03 benno Exp $ */
/* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */
/*
@@ -292,7 +292,8 @@ rip_ctloutput(int op, struct socket *so, int level, int optname,
struct mbuf **m)
{
struct inpcb *inp = sotoinpcb(so);
- int error;
+ int error = 0;
+ int dir;
if (level != IPPROTO_IP) {
if (op == PRCO_SETOPT && *m)
@@ -320,6 +321,39 @@ rip_ctloutput(int op, struct socket *so, int level, int optname,
}
return (error);
+ case IP_DIVERTFL:
+ switch (op) {
+ case PRCO_SETOPT:
+ if (*m == 0 || (*m)->m_len < sizeof (int)) {
+ error = EINVAL;
+ break;
+ }
+ dir = *mtod(*m, int *);
+ if (inp->inp_divertfl > 0)
+ error = ENOTSUP;
+ else if ((dir & IPPROTO_DIVERT_RESP) ||
+ (dir & IPPROTO_DIVERT_INIT))
+ inp->inp_divertfl = dir;
+ else
+ error = EINVAL;
+
+ break;
+
+ case PRCO_GETOPT:
+ *m = m_get(M_WAIT, M_SOOPTS);
+ (*m)->m_len = sizeof(int);
+ *mtod(*m, int *) = inp->inp_divertfl;
+ break;
+
+ default:
+ error = EINVAL;
+ break;
+ }
+
+ if (op == PRCO_SETOPT && *m)
+ (void)m_free(*m);
+ return (error);
+
case MRT_INIT:
case MRT_DONE:
case MRT_ADD_VIF: