diff options
author | Markus Friedl <markus@cvs.openbsd.org> | 2008-05-09 02:52:16 +0000 |
---|---|---|
committer | Markus Friedl <markus@cvs.openbsd.org> | 2008-05-09 02:52:16 +0000 |
commit | 4d2f26f40d056a33f87aed5cd294af089da41a7a (patch) | |
tree | 25190aa4a30a5592eb03b5d2fe08e9634636780f /sys | |
parent | 6b5278216d3e945e7764e8fb4d6084731d9c1d42 (diff) |
Add SO_BINDANY socket option from BSD/OS.
The option allows a socket to be bound to addresses which are not
local to the machine. In order to receive packets for these addresses
SO_BINDANY needs to be combined with matching outgoing pf(4) divert
rules, see pf.conf(5).
ok beck@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/uipc_socket.c | 11 | ||||
-rw-r--r-- | sys/netinet/in_pcb.c | 5 | ||||
-rw-r--r-- | sys/netinet/raw_ip.c | 5 | ||||
-rw-r--r-- | sys/sys/socket.h | 3 |
4 files changed, 18 insertions, 6 deletions
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 45728e18533..7422689fa11 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.68 2008/05/02 06:49:32 ckuethe Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.69 2008/05/09 02:52:15 markus Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -981,6 +981,13 @@ sosetopt(struct socket *so, int level, int optname, struct mbuf *m0) error = ENOPROTOOPT; } else { switch (optname) { + case SO_BINDANY: + if ((error = suser(curproc, 0)) != 0) /* XXX */ + goto bad; + break; + } + + switch (optname) { case SO_LINGER: if (m == NULL || m->m_len != sizeof (struct linger) || @@ -992,6 +999,7 @@ sosetopt(struct socket *so, int level, int optname, struct mbuf *m0) so->so_linger = mtod(m, struct linger *)->l_linger; /* FALLTHROUGH */ + case SO_BINDANY: case SO_DEBUG: case SO_KEEPALIVE: case SO_DONTROUTE: @@ -1127,6 +1135,7 @@ sogetopt(struct socket *so, int level, int optname, struct mbuf **mp) mtod(m, struct linger *)->l_linger = so->so_linger; break; + case SO_BINDANY: case SO_USELOOPBACK: case SO_DONTROUTE: case SO_DEBUG: diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index e3e8d58bdfa..58702c81a36 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.c,v 1.95 2008/05/09 02:44:54 markus Exp $ */ +/* $OpenBSD: in_pcb.c,v 1.96 2008/05/09 02:52:15 markus Exp $ */ /* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */ /* @@ -284,7 +284,8 @@ in_pcbbind(v, nam) reuseport = SO_REUSEADDR|SO_REUSEPORT; } else if (sin->sin_addr.s_addr != INADDR_ANY) { sin->sin_port = 0; /* yech... */ - if (in_iawithaddr(sin->sin_addr, NULL) == 0) + if (!(so->so_options & SO_BINDANY) && + in_iawithaddr(sin->sin_addr, NULL) == 0) return (EADDRNOTAVAIL); } if (lport) { diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 3b621e57678..1b45549be3c 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip.c,v 1.42 2008/05/09 02:44:54 markus Exp $ */ +/* $OpenBSD: raw_ip.c,v 1.43 2008/05/09 02:52:15 markus Exp $ */ /* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */ /* @@ -408,7 +408,8 @@ rip_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, ((addr->sin_family != AF_INET) && (addr->sin_family != AF_IMPLINK)) || (addr->sin_addr.s_addr && - ifa_ifwithaddr(sintosa(addr)) == 0)) { + (!(so->so_options & SO_BINDANY) && + in_iawithaddr(addr->sin_addr, NULL) == 0))) { error = EADDRNOTAVAIL; break; } diff --git a/sys/sys/socket.h b/sys/sys/socket.h index a5bb2afeacb..b960fbf86b6 100644 --- a/sys/sys/socket.h +++ b/sys/sys/socket.h @@ -1,4 +1,4 @@ -/* $OpenBSD: socket.h,v 1.57 2008/05/02 06:49:32 ckuethe Exp $ */ +/* $OpenBSD: socket.h,v 1.58 2008/05/09 02:52:15 markus Exp $ */ /* $NetBSD: socket.h,v 1.14 1996/02/09 18:25:36 christos Exp $ */ /* @@ -68,6 +68,7 @@ #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ #define SO_JUMBO 0x0400 /* try to use jumbograms */ #define SO_TIMESTAMP 0x0800 /* timestamp received dgram traffic */ +#define SO_BINDANY 0x1000 /* allow bind to any address */ /* * Additional options, not kept in so_options. |