summaryrefslogtreecommitdiff
path: root/sys/net/rtsock.c
diff options
context:
space:
mode:
authorSebastian Benoit <benno@cvs.openbsd.org>2018-02-11 02:26:56 +0000
committerSebastian Benoit <benno@cvs.openbsd.org>2018-02-11 02:26:56 +0000
commit8be66dc7d815621f140bc4584e7c4594c5ea8c04 (patch)
treeee511bd4cdb5e0b7a79d296b65f5dc3a5735639d /sys/net/rtsock.c
parentdf8f883ccbec11aac60a2921d683bbe707f71796 (diff)
Add a ROUTE_PRIOFILTER socket option for roueing sockets that
allows filtering on the priority of the route. All routes up to the specified value will be passed. ok claudio, ok henning previous version, feedback and manpage from sthen.
Diffstat (limited to 'sys/net/rtsock.c')
-rw-r--r--sys/net/rtsock.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index 35bdd09d143..70497d29a93 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtsock.c,v 1.260 2018/02/08 22:24:41 claudio Exp $ */
+/* $OpenBSD: rtsock.c,v 1.261 2018/02/11 02:26:55 benno Exp $ */
/* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */
/*
@@ -141,6 +141,7 @@ struct routecb {
unsigned int msgfilter;
unsigned int flags;
u_int rtableid;
+ u_char priority;
};
#define sotoroutecb(so) ((struct routecb *)(so)->so_pcb)
@@ -308,7 +309,7 @@ route_ctloutput(int op, struct socket *so, int level, int optname,
{
struct routecb *rop = sotoroutecb(so);
int error = 0;
- unsigned int tid;
+ unsigned int tid, prio;
if (level != AF_ROUTE)
return (EINVAL);
@@ -333,6 +334,17 @@ route_ctloutput(int op, struct socket *so, int level, int optname,
else
rop->rtableid = tid;
break;
+ case ROUTE_PRIOFILTER:
+ if (m == NULL || m->m_len != sizeof(unsigned int)) {
+ error = EINVAL;
+ break;
+ }
+ prio = *mtod(m, unsigned int *);
+ if (prio > RTP_MAX)
+ error = EINVAL;
+ else
+ rop->priority = prio;
+ break;
default:
error = ENOPROTOOPT;
break;
@@ -348,6 +360,10 @@ route_ctloutput(int op, struct socket *so, int level, int optname,
m->m_len = sizeof(unsigned int);
*mtod(m, unsigned int *) = rop->rtableid;
break;
+ case ROUTE_PRIOFILTER:
+ m->m_len = sizeof(unsigned int);
+ *mtod(m, unsigned int *) = rop->priority;
+ break;
default:
error = ENOPROTOOPT;
break;
@@ -431,6 +447,8 @@ route_input(struct mbuf *m0, struct socket *so, sa_family_t sa_family)
if (rtm->rtm_type != RTM_DESYNC && rop->msgfilter != 0 &&
!(rop->msgfilter & (1 << rtm->rtm_type)))
continue;
+ if (rop->priority != 0 && rop->priority < rtm->rtm_priority)
+ continue;
switch (rtm->rtm_type) {
case RTM_IFANNOUNCE:
case RTM_DESYNC: