2003-08-17 11:11:32 +00:00
|
|
|
/* $KAME: rtsold.c,v 1.67 2003/05/17 18:16:15 itojun Exp $ */
|
2000-10-06 23:46:52 +00:00
|
|
|
|
2017-11-20 19:49:47 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
1999-12-28 02:37:14 +00:00
|
|
|
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
|
|
|
* All rights reserved.
|
2000-07-05 10:14:11 +00:00
|
|
|
*
|
1999-12-28 02:37:14 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the project nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
2000-07-05 10:14:11 +00:00
|
|
|
*
|
1999-12-28 02:37:14 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
2018-10-20 17:40:30 +00:00
|
|
|
#include <sys/param.h>
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
#include <sys/capsicum.h>
|
|
|
|
#include <sys/event.h>
|
2010-02-02 18:38:17 +00:00
|
|
|
#include <sys/ioctl.h>
|
2000-07-05 10:14:11 +00:00
|
|
|
#include <sys/socket.h>
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2000-07-05 10:14:11 +00:00
|
|
|
#include <net/if.h>
|
1999-12-28 02:37:14 +00:00
|
|
|
#include <net/if_dl.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/icmp6.h>
|
2010-02-02 18:38:17 +00:00
|
|
|
#include <netinet/in_var.h>
|
2011-06-08 16:03:29 +00:00
|
|
|
#include <arpa/inet.h>
|
2010-02-02 18:38:17 +00:00
|
|
|
|
|
|
|
#include <netinet6/nd6.h>
|
1999-12-28 02:37:14 +00:00
|
|
|
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
#include <capsicum_helpers.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ifaddrs.h>
|
|
|
|
#include <libgen.h>
|
1999-12-28 02:37:14 +00:00
|
|
|
#include <signal.h>
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
#include <stdarg.h>
|
1999-12-28 02:37:14 +00:00
|
|
|
#include <stdio.h>
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <syslog.h>
|
2013-08-05 20:13:02 +00:00
|
|
|
#include <time.h>
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <libcasper.h>
|
|
|
|
#include <casper/cap_syslog.h>
|
|
|
|
#include <libutil.h>
|
2003-08-08 16:56:01 +00:00
|
|
|
|
1999-12-28 02:37:14 +00:00
|
|
|
#include "rtsold.h"
|
|
|
|
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
#define RTSOL_DUMPFILE "/var/run/rtsold.dump"
|
2011-06-06 03:06:43 +00:00
|
|
|
|
2013-08-05 20:13:02 +00:00
|
|
|
struct timespec tm_max;
|
2003-08-08 16:56:01 +00:00
|
|
|
static int log_upto = 999;
|
|
|
|
static int fflag = 0;
|
|
|
|
|
2009-09-12 22:14:58 +00:00
|
|
|
int Fflag = 0; /* force setting sysctl parameters */
|
2000-10-06 23:46:52 +00:00
|
|
|
int aflag = 0;
|
|
|
|
int dflag = 0;
|
2011-09-12 23:55:23 +00:00
|
|
|
int uflag = 0;
|
2003-08-08 16:56:01 +00:00
|
|
|
|
2020-08-25 16:09:23 +00:00
|
|
|
const char *managedconf_script;
|
2011-06-06 03:06:43 +00:00
|
|
|
const char *otherconf_script;
|
|
|
|
const char *resolvconf_script = "/sbin/resolvconf";
|
1999-12-28 02:37:14 +00:00
|
|
|
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
cap_channel_t *capllflags, *capscript, *capsendmsg, *capsyslog;
|
|
|
|
|
2005-06-08 23:51:42 +00:00
|
|
|
/* protocol constants */
|
2000-07-05 10:14:11 +00:00
|
|
|
#define MAX_RTR_SOLICITATION_DELAY 1 /* second */
|
|
|
|
#define RTR_SOLICITATION_INTERVAL 4 /* seconds */
|
|
|
|
#define MAX_RTR_SOLICITATIONS 3 /* times */
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2003-08-08 16:56:01 +00:00
|
|
|
/*
|
2003-08-14 15:57:52 +00:00
|
|
|
* implementation dependent constants in seconds
|
2003-08-08 16:56:01 +00:00
|
|
|
* XXX: should be configurable
|
|
|
|
*/
|
|
|
|
#define PROBE_INTERVAL 60
|
1999-12-28 02:37:14 +00:00
|
|
|
|
|
|
|
/* static variables and functions */
|
|
|
|
static int mobile_node = 0;
|
2011-06-06 03:06:43 +00:00
|
|
|
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
static sig_atomic_t do_dump, do_exit;
|
|
|
|
static struct pidfh *pfh;
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2018-10-20 17:43:27 +00:00
|
|
|
static char **autoifprobe(void);
|
|
|
|
static int ifconfig(char *ifname);
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
static int init_capabilities(void);
|
2007-11-07 10:53:41 +00:00
|
|
|
static int make_packet(struct ifinfo *);
|
2013-08-05 20:13:02 +00:00
|
|
|
static struct timespec *rtsol_check_timer(void);
|
1999-12-28 02:37:14 +00:00
|
|
|
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
static void set_dumpfile(int);
|
|
|
|
static void set_exit(int);
|
|
|
|
static void usage(const char *progname);
|
1999-12-28 02:37:14 +00:00
|
|
|
|
|
|
|
int
|
2004-01-14 17:16:19 +00:00
|
|
|
main(int argc, char **argv)
|
1999-12-28 02:37:14 +00:00
|
|
|
{
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
struct kevent events[2];
|
|
|
|
FILE *dumpfp;
|
|
|
|
struct ifinfo *ifi;
|
2013-08-05 20:13:02 +00:00
|
|
|
struct timespec *timeout;
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
const char *opts, *pidfilepath, *progname;
|
|
|
|
int ch, error, kq, once, rcvsock, rtsock;
|
|
|
|
|
|
|
|
progname = basename(argv[0]);
|
|
|
|
if (strcmp(progname, "rtsold") == 0) {
|
2020-08-25 16:09:23 +00:00
|
|
|
opts = "adDfFm1M:O:p:R:u";
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
once = 0;
|
|
|
|
pidfilepath = NULL;
|
|
|
|
} else {
|
2020-08-25 16:09:23 +00:00
|
|
|
opts = "adDFM:O:R:u";
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
fflag = 1;
|
|
|
|
once = 1;
|
|
|
|
}
|
2011-06-08 04:06:56 +00:00
|
|
|
|
1999-12-28 02:37:14 +00:00
|
|
|
while ((ch = getopt(argc, argv, opts)) != -1) {
|
2000-10-06 23:46:52 +00:00
|
|
|
switch (ch) {
|
|
|
|
case 'a':
|
|
|
|
aflag = 1;
|
|
|
|
break;
|
|
|
|
case 'd':
|
2011-09-12 23:55:23 +00:00
|
|
|
dflag += 1;
|
2000-10-06 23:46:52 +00:00
|
|
|
break;
|
|
|
|
case 'D':
|
2011-09-12 23:55:23 +00:00
|
|
|
dflag += 2;
|
2000-10-06 23:46:52 +00:00
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
fflag = 1;
|
|
|
|
break;
|
2004-01-14 17:42:03 +00:00
|
|
|
case 'F':
|
|
|
|
Fflag = 1;
|
|
|
|
break;
|
2000-10-06 23:46:52 +00:00
|
|
|
case 'm':
|
|
|
|
mobile_node = 1;
|
|
|
|
break;
|
|
|
|
case '1':
|
|
|
|
once = 1;
|
|
|
|
break;
|
2020-08-25 16:09:23 +00:00
|
|
|
case 'M':
|
|
|
|
managedconf_script = optarg;
|
|
|
|
break;
|
2003-08-08 16:42:37 +00:00
|
|
|
case 'O':
|
|
|
|
otherconf_script = optarg;
|
|
|
|
break;
|
2011-09-12 23:55:23 +00:00
|
|
|
case 'p':
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
pidfilepath = optarg;
|
2011-06-06 03:06:43 +00:00
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
resolvconf_script = optarg;
|
|
|
|
break;
|
2011-09-12 23:55:23 +00:00
|
|
|
case 'u':
|
|
|
|
uflag = 1;
|
|
|
|
break;
|
2000-10-06 23:46:52 +00:00
|
|
|
default:
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
usage(progname);
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
2000-10-06 23:46:52 +00:00
|
|
|
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
if ((!aflag && argc == 0) || (aflag && argc != 0))
|
|
|
|
usage(progname);
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2013-08-05 20:13:02 +00:00
|
|
|
/* Generate maximum time in timespec. */
|
2013-08-06 15:49:18 +00:00
|
|
|
tm_max.tv_sec = (-1) & ~((time_t)1 << ((sizeof(tm_max.tv_sec) * 8) - 1));
|
|
|
|
tm_max.tv_nsec = (-1) & ~((long)1 << ((sizeof(tm_max.tv_nsec) * 8) - 1));
|
2013-08-05 20:13:02 +00:00
|
|
|
|
1999-12-28 02:37:14 +00:00
|
|
|
/* set log level */
|
2011-09-12 23:55:23 +00:00
|
|
|
if (dflag > 1)
|
|
|
|
log_upto = LOG_DEBUG;
|
|
|
|
else if (dflag > 0)
|
|
|
|
log_upto = LOG_INFO;
|
|
|
|
else
|
1999-12-28 02:37:14 +00:00
|
|
|
log_upto = LOG_NOTICE;
|
2011-09-12 23:55:23 +00:00
|
|
|
|
2020-08-25 16:09:23 +00:00
|
|
|
if (managedconf_script != NULL && *managedconf_script != '/')
|
|
|
|
errx(1, "configuration script (%s) must be an absolute path",
|
|
|
|
managedconf_script);
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
if (otherconf_script != NULL && *otherconf_script != '/')
|
2003-08-08 16:42:37 +00:00
|
|
|
errx(1, "configuration script (%s) must be an absolute path",
|
|
|
|
otherconf_script);
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
if (*resolvconf_script != '/')
|
2011-06-06 03:06:43 +00:00
|
|
|
errx(1, "configuration script (%s) must be an absolute path",
|
|
|
|
resolvconf_script);
|
1999-12-28 02:37:14 +00:00
|
|
|
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
if (!fflag) {
|
|
|
|
pfh = pidfile_open(pidfilepath, 0644, NULL);
|
|
|
|
if (pfh == NULL)
|
|
|
|
errx(1, "failed to open pidfile: %s", strerror(errno));
|
|
|
|
if (daemon(0, 0) != 0)
|
|
|
|
errx(1, "failed to daemonize");
|
|
|
|
}
|
1999-12-28 02:37:14 +00:00
|
|
|
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
if ((error = init_capabilities()) != 0)
|
|
|
|
err(1, "failed to initialize capabilities");
|
2003-08-14 18:13:34 +00:00
|
|
|
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
if (!fflag) {
|
|
|
|
cap_openlog(capsyslog, progname, LOG_NDELAY | LOG_PID,
|
|
|
|
LOG_DAEMON);
|
|
|
|
if (log_upto >= 0)
|
|
|
|
(void)cap_setlogmask(capsyslog, LOG_UPTO(log_upto));
|
|
|
|
(void)signal(SIGTERM, set_exit);
|
|
|
|
(void)signal(SIGINT, set_exit);
|
|
|
|
(void)signal(SIGUSR1, set_dumpfile);
|
|
|
|
dumpfp = rtsold_init_dumpfile(RTSOL_DUMPFILE);
|
|
|
|
} else
|
|
|
|
dumpfp = NULL;
|
|
|
|
|
|
|
|
kq = kqueue();
|
|
|
|
if (kq < 0) {
|
|
|
|
warnmsg(LOG_ERR, __func__, "failed to create a kqueue: %s",
|
|
|
|
strerror(errno));
|
2003-08-14 18:13:34 +00:00
|
|
|
exit(1);
|
2000-10-06 23:46:52 +00:00
|
|
|
}
|
2003-08-14 18:43:57 +00:00
|
|
|
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
/* Open global sockets and register for read events. */
|
2001-06-11 12:39:29 +00:00
|
|
|
if ((rtsock = rtsock_open()) < 0) {
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
warnmsg(LOG_ERR, __func__, "failed to open routing socket");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if ((rcvsock = recvsockopen()) < 0) {
|
|
|
|
warnmsg(LOG_ERR, __func__, "failed to open receive socket");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
EV_SET(&events[0], rtsock, EVFILT_READ, EV_ADD, 0, 0, NULL);
|
|
|
|
EV_SET(&events[1], rcvsock, EVFILT_READ, EV_ADD, 0, 0, NULL);
|
|
|
|
if (kevent(kq, events, 2, NULL, 0, NULL) < 0) {
|
|
|
|
warnmsg(LOG_ERR, __func__, "kevent(): %s", strerror(errno));
|
2003-08-14 18:13:34 +00:00
|
|
|
exit(1);
|
2001-06-11 12:39:29 +00:00
|
|
|
}
|
2003-08-14 15:47:31 +00:00
|
|
|
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
/* Probe network interfaces and set up tracking info. */
|
|
|
|
if (ifinit() != 0) {
|
|
|
|
warnmsg(LOG_ERR, __func__, "failed to initialize interfaces");
|
2003-08-14 18:13:34 +00:00
|
|
|
exit(1);
|
2000-10-06 23:46:52 +00:00
|
|
|
}
|
2003-08-17 11:11:32 +00:00
|
|
|
if (aflag)
|
|
|
|
argv = autoifprobe();
|
|
|
|
while (argv && *argv) {
|
2000-10-06 23:46:52 +00:00
|
|
|
if (ifconfig(*argv)) {
|
2003-08-14 18:13:34 +00:00
|
|
|
warnmsg(LOG_ERR, __func__,
|
|
|
|
"failed to initialize %s", *argv);
|
|
|
|
exit(1);
|
2000-10-06 23:46:52 +00:00
|
|
|
}
|
1999-12-28 02:37:14 +00:00
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
/* Write to our pidfile. */
|
|
|
|
if (pfh != NULL && pidfile_write(pfh) != 0) {
|
2003-08-14 18:13:34 +00:00
|
|
|
warnmsg(LOG_ERR, __func__,
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
"failed to open pidfile: %s", strerror(errno));
|
2003-08-14 18:13:34 +00:00
|
|
|
exit(1);
|
2000-10-06 23:46:52 +00:00
|
|
|
}
|
1999-12-28 02:37:14 +00:00
|
|
|
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
/* Enter capability mode. */
|
|
|
|
caph_cache_catpages();
|
|
|
|
if (caph_enter_casper() != 0) {
|
|
|
|
warnmsg(LOG_ERR, __func__, "caph_enter(): %s", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
1999-12-28 02:37:14 +00:00
|
|
|
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
for (;;) {
|
|
|
|
if (do_exit) {
|
|
|
|
/* Handle SIGTERM, SIGINT. */
|
|
|
|
if (pfh != NULL)
|
|
|
|
pidfile_remove(pfh);
|
|
|
|
break;
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
if (do_dump) {
|
|
|
|
/* Handle SIGUSR1. */
|
1999-12-28 02:37:14 +00:00
|
|
|
do_dump = 0;
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
if (dumpfp != NULL)
|
|
|
|
rtsold_dump(dumpfp);
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
2003-08-08 16:56:01 +00:00
|
|
|
|
1999-12-28 02:37:14 +00:00
|
|
|
timeout = rtsol_check_timer();
|
|
|
|
|
|
|
|
if (once) {
|
|
|
|
/* if we have no timeout, we are done (or failed) */
|
|
|
|
if (timeout == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* if all interfaces have got RA packet, we are done */
|
2011-06-06 03:06:43 +00:00
|
|
|
TAILQ_FOREACH(ifi, &ifinfo_head, ifi_next) {
|
1999-12-28 02:37:14 +00:00
|
|
|
if (ifi->state != IFS_DOWN && ifi->racnt == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ifi == NULL)
|
|
|
|
break;
|
|
|
|
}
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
|
|
|
|
error = kevent(kq, NULL, 0, &events[0], 1, timeout);
|
|
|
|
if (error < 1) {
|
|
|
|
if (error < 0 && errno != EINTR)
|
|
|
|
warnmsg(LOG_ERR, __func__, "kevent(): %s",
|
2003-08-08 16:56:01 +00:00
|
|
|
strerror(errno));
|
1999-12-28 02:37:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
if (events[0].ident == (uintptr_t)rtsock)
|
2001-06-11 12:39:29 +00:00
|
|
|
rtsock_input(rtsock);
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
else
|
|
|
|
rtsol_input(rcvsock);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
init_capabilities(void)
|
|
|
|
{
|
|
|
|
#ifdef WITH_CASPER
|
2020-08-25 16:09:23 +00:00
|
|
|
const char *const scripts[] =
|
|
|
|
{ resolvconf_script, managedconf_script, otherconf_script };
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
cap_channel_t *capcasper;
|
|
|
|
nvlist_t *limits;
|
|
|
|
|
|
|
|
capcasper = cap_init();
|
|
|
|
if (capcasper == NULL)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
capllflags = cap_service_open(capcasper, "rtsold.llflags");
|
|
|
|
if (capllflags == NULL)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
capscript = cap_service_open(capcasper, "rtsold.script");
|
|
|
|
if (capscript == NULL)
|
|
|
|
return (-1);
|
2021-03-08 03:03:32 +00:00
|
|
|
limits = nvlist_create(0);
|
2020-08-25 16:09:23 +00:00
|
|
|
for (size_t i = 0; i < nitems(scripts); i++)
|
|
|
|
if (scripts[i] != NULL)
|
2021-03-08 03:03:32 +00:00
|
|
|
nvlist_append_string_array(limits, "scripts",
|
|
|
|
scripts[i]);
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
if (cap_limit_set(capscript, limits) != 0)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
capsendmsg = cap_service_open(capcasper, "rtsold.sendmsg");
|
|
|
|
if (capsendmsg == NULL)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
if (!fflag) {
|
|
|
|
capsyslog = cap_service_open(capcasper, "system.syslog");
|
|
|
|
if (capsyslog == NULL)
|
|
|
|
return (-1);
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
cap_close(capcasper);
|
|
|
|
#endif /* WITH_CASPER */
|
2011-06-06 03:06:43 +00:00
|
|
|
return (0);
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
|
2018-10-20 17:43:27 +00:00
|
|
|
static int
|
1999-12-28 02:37:14 +00:00
|
|
|
ifconfig(char *ifname)
|
|
|
|
{
|
2011-06-06 03:06:43 +00:00
|
|
|
struct ifinfo *ifi;
|
1999-12-28 02:37:14 +00:00
|
|
|
struct sockaddr_dl *sdl;
|
|
|
|
int flags;
|
|
|
|
|
2018-10-24 16:46:26 +00:00
|
|
|
ifi = NULL;
|
1999-12-28 02:37:14 +00:00
|
|
|
if ((sdl = if_nametosdl(ifname)) == NULL) {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_ERR, __func__,
|
2003-08-08 16:56:01 +00:00
|
|
|
"failed to get link layer information for %s", ifname);
|
2018-10-24 16:46:26 +00:00
|
|
|
goto bad;
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
if (find_ifinfo(sdl->sdl_index)) {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_ERR, __func__,
|
2003-08-08 16:56:01 +00:00
|
|
|
"interface %s was already configured", ifname);
|
2018-10-24 16:46:26 +00:00
|
|
|
goto bad;
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
|
2011-09-12 23:55:23 +00:00
|
|
|
if (Fflag) {
|
|
|
|
struct in6_ndireq nd;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
|
|
|
|
warnmsg(LOG_ERR, __func__, "socket() failed.");
|
2018-10-24 16:46:26 +00:00
|
|
|
goto bad;
|
2011-09-12 23:55:23 +00:00
|
|
|
}
|
|
|
|
memset(&nd, 0, sizeof(nd));
|
|
|
|
strlcpy(nd.ifname, ifname, sizeof(nd.ifname));
|
|
|
|
if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) {
|
|
|
|
warnmsg(LOG_ERR, __func__,
|
|
|
|
"cannot get accept_rtadv flag");
|
2018-10-24 16:46:26 +00:00
|
|
|
(void)close(s);
|
|
|
|
goto bad;
|
2011-09-12 23:55:23 +00:00
|
|
|
}
|
|
|
|
nd.ndi.flags |= ND6_IFF_ACCEPT_RTADV;
|
|
|
|
if (ioctl(s, SIOCSIFINFO_IN6, (caddr_t)&nd) < 0) {
|
|
|
|
warnmsg(LOG_ERR, __func__,
|
|
|
|
"cannot set accept_rtadv flag");
|
2018-10-24 16:46:26 +00:00
|
|
|
(void)close(s);
|
|
|
|
goto bad;
|
2011-09-12 23:55:23 +00:00
|
|
|
}
|
2018-10-24 16:46:26 +00:00
|
|
|
(void)close(s);
|
2011-09-12 23:55:23 +00:00
|
|
|
}
|
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
if ((ifi = malloc(sizeof(*ifi))) == NULL) {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_ERR, __func__, "memory allocation failed");
|
2018-10-24 16:46:26 +00:00
|
|
|
goto bad;
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
2011-06-06 03:06:43 +00:00
|
|
|
memset(ifi, 0, sizeof(*ifi));
|
|
|
|
ifi->sdl = sdl;
|
2011-06-08 16:03:29 +00:00
|
|
|
ifi->ifi_rdnss = IFI_DNSOPT_STATE_NOINFO;
|
|
|
|
ifi->ifi_dnssl = IFI_DNSOPT_STATE_NOINFO;
|
|
|
|
TAILQ_INIT(&ifi->ifi_rainfo);
|
2011-06-06 03:06:43 +00:00
|
|
|
strlcpy(ifi->ifname, ifname, sizeof(ifi->ifname));
|
1999-12-28 02:37:14 +00:00
|
|
|
|
|
|
|
/* construct a router solicitation message */
|
2011-06-06 03:06:43 +00:00
|
|
|
if (make_packet(ifi))
|
1999-12-28 02:37:14 +00:00
|
|
|
goto bad;
|
|
|
|
|
2003-08-17 11:11:32 +00:00
|
|
|
/* set link ID of this interface. */
|
|
|
|
#ifdef HAVE_SCOPELIB
|
2011-06-06 03:06:43 +00:00
|
|
|
if (inet_zoneid(AF_INET6, 2, ifname, &ifi->linkid))
|
2003-08-17 11:11:32 +00:00
|
|
|
goto bad;
|
|
|
|
#else
|
|
|
|
/* XXX: assume interface IDs as link IDs */
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->linkid = ifi->sdl->sdl_index;
|
2003-08-17 11:11:32 +00:00
|
|
|
#endif
|
|
|
|
|
1999-12-28 02:37:14 +00:00
|
|
|
/*
|
|
|
|
* check if the interface is available.
|
|
|
|
* also check if SIOCGIFMEDIA ioctl is OK on the interface.
|
|
|
|
*/
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->mediareqok = 1;
|
|
|
|
ifi->active = interface_status(ifi);
|
|
|
|
if (!ifi->mediareqok) {
|
1999-12-28 02:37:14 +00:00
|
|
|
/*
|
|
|
|
* probe routers periodically even if the link status
|
|
|
|
* does not change.
|
|
|
|
*/
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->probeinterval = PROBE_INTERVAL;
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* activate interface: interface_up returns 0 on success */
|
2011-06-06 03:06:43 +00:00
|
|
|
flags = interface_up(ifi->ifname);
|
1999-12-28 02:37:14 +00:00
|
|
|
if (flags == 0)
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->state = IFS_DELAY;
|
1999-12-28 02:37:14 +00:00
|
|
|
else if (flags == IFS_TENTATIVE)
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->state = IFS_TENTATIVE;
|
1999-12-28 02:37:14 +00:00
|
|
|
else
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->state = IFS_DOWN;
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
rtsol_timer_update(ifi);
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
TAILQ_INSERT_TAIL(&ifinfo_head, ifi, ifi_next);
|
|
|
|
return (0);
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2003-08-08 16:56:01 +00:00
|
|
|
bad:
|
2018-10-24 16:46:26 +00:00
|
|
|
free(sdl);
|
2011-06-06 03:06:43 +00:00
|
|
|
free(ifi);
|
|
|
|
return (-1);
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
|
2011-06-08 16:03:29 +00:00
|
|
|
struct rainfo *
|
|
|
|
find_rainfo(struct ifinfo *ifi, struct sockaddr_in6 *sin6)
|
|
|
|
{
|
|
|
|
struct rainfo *rai;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(rai, &ifi->ifi_rainfo, rai_next)
|
|
|
|
if (memcmp(&rai->rai_saddr.sin6_addr, &sin6->sin6_addr,
|
|
|
|
sizeof(rai->rai_saddr.sin6_addr)) == 0)
|
|
|
|
return (rai);
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
1999-12-28 02:37:14 +00:00
|
|
|
struct ifinfo *
|
|
|
|
find_ifinfo(int ifindex)
|
|
|
|
{
|
|
|
|
struct ifinfo *ifi;
|
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
TAILQ_FOREACH(ifi, &ifinfo_head, ifi_next) {
|
1999-12-28 02:37:14 +00:00
|
|
|
if (ifi->sdl->sdl_index == ifindex)
|
2011-06-06 03:06:43 +00:00
|
|
|
return (ifi);
|
|
|
|
}
|
|
|
|
return (NULL);
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-06-06 03:06:43 +00:00
|
|
|
make_packet(struct ifinfo *ifi)
|
1999-12-28 02:37:14 +00:00
|
|
|
{
|
|
|
|
size_t packlen = sizeof(struct nd_router_solicit), lladdroptlen = 0;
|
2003-08-08 16:56:01 +00:00
|
|
|
struct nd_router_solicit *rs;
|
|
|
|
char *buf;
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
if ((lladdroptlen = lladdropt_length(ifi->sdl)) == 0) {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_INFO, __func__,
|
2003-08-08 16:56:01 +00:00
|
|
|
"link-layer address option has null length"
|
2011-06-06 03:06:43 +00:00
|
|
|
" on %s. Treat as not included.", ifi->ifname);
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
packlen += lladdroptlen;
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->rs_datalen = packlen;
|
1999-12-28 02:37:14 +00:00
|
|
|
|
|
|
|
/* allocate buffer */
|
|
|
|
if ((buf = malloc(packlen)) == NULL) {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_ERR, __func__,
|
2011-06-06 03:06:43 +00:00
|
|
|
"memory allocation failed for %s", ifi->ifname);
|
|
|
|
return (-1);
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->rs_data = buf;
|
1999-12-28 02:37:14 +00:00
|
|
|
|
|
|
|
/* fill in the message */
|
|
|
|
rs = (struct nd_router_solicit *)buf;
|
|
|
|
rs->nd_rs_type = ND_ROUTER_SOLICIT;
|
|
|
|
rs->nd_rs_code = 0;
|
|
|
|
rs->nd_rs_cksum = 0;
|
|
|
|
rs->nd_rs_reserved = 0;
|
|
|
|
buf += sizeof(*rs);
|
|
|
|
|
|
|
|
/* fill in source link-layer address option */
|
|
|
|
if (lladdroptlen)
|
2011-06-06 03:06:43 +00:00
|
|
|
lladdropt_fill(ifi->sdl, (struct nd_opt_hdr *)buf);
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
return (0);
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
|
2013-08-05 20:13:02 +00:00
|
|
|
static struct timespec *
|
2004-01-14 17:16:19 +00:00
|
|
|
rtsol_check_timer(void)
|
1999-12-28 02:37:14 +00:00
|
|
|
{
|
2013-08-05 20:13:02 +00:00
|
|
|
static struct timespec returnval;
|
|
|
|
struct timespec now, rtsol_timer;
|
2011-06-06 03:06:43 +00:00
|
|
|
struct ifinfo *ifi;
|
2011-06-08 16:03:29 +00:00
|
|
|
struct rainfo *rai;
|
2016-02-18 01:58:26 +00:00
|
|
|
struct ra_opt *rao, *raotmp;
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
int error, flags;
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2013-08-05 20:13:02 +00:00
|
|
|
clock_gettime(CLOCK_MONOTONIC_FAST, &now);
|
1999-12-28 02:37:14 +00:00
|
|
|
|
|
|
|
rtsol_timer = tm_max;
|
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
TAILQ_FOREACH(ifi, &ifinfo_head, ifi_next) {
|
2013-08-05 20:13:02 +00:00
|
|
|
if (TS_CMP(&ifi->expire, &now, <=)) {
|
2011-06-08 16:03:29 +00:00
|
|
|
warnmsg(LOG_DEBUG, __func__, "timer expiration on %s, "
|
|
|
|
"state = %d", ifi->ifname, ifi->state);
|
|
|
|
|
|
|
|
while((rai = TAILQ_FIRST(&ifi->ifi_rainfo)) != NULL) {
|
|
|
|
/* Remove all RA options. */
|
|
|
|
TAILQ_REMOVE(&ifi->ifi_rainfo, rai, rai_next);
|
|
|
|
while ((rao = TAILQ_FIRST(&rai->rai_ra_opt)) !=
|
|
|
|
NULL) {
|
|
|
|
TAILQ_REMOVE(&rai->rai_ra_opt, rao,
|
|
|
|
rao_next);
|
|
|
|
if (rao->rao_msg != NULL)
|
|
|
|
free(rao->rao_msg);
|
|
|
|
free(rao);
|
|
|
|
}
|
|
|
|
free(rai);
|
2011-06-06 03:06:43 +00:00
|
|
|
}
|
|
|
|
switch (ifi->state) {
|
1999-12-28 02:37:14 +00:00
|
|
|
case IFS_DOWN:
|
|
|
|
case IFS_TENTATIVE:
|
|
|
|
/* interface_up returns 0 on success */
|
2011-06-06 03:06:43 +00:00
|
|
|
flags = interface_up(ifi->ifname);
|
1999-12-28 02:37:14 +00:00
|
|
|
if (flags == 0)
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->state = IFS_DELAY;
|
1999-12-28 02:37:14 +00:00
|
|
|
else if (flags == IFS_TENTATIVE)
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->state = IFS_TENTATIVE;
|
1999-12-28 02:37:14 +00:00
|
|
|
else
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->state = IFS_DOWN;
|
1999-12-28 02:37:14 +00:00
|
|
|
break;
|
|
|
|
case IFS_IDLE:
|
|
|
|
{
|
2011-06-06 03:06:43 +00:00
|
|
|
int oldstatus = ifi->active;
|
1999-12-28 02:37:14 +00:00
|
|
|
int probe = 0;
|
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->active = interface_status(ifi);
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
if (oldstatus != ifi->active) {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_DEBUG, __func__,
|
2003-08-08 16:56:01 +00:00
|
|
|
"%s status is changed"
|
|
|
|
" from %d to %d",
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->ifname,
|
|
|
|
oldstatus, ifi->active);
|
1999-12-28 02:37:14 +00:00
|
|
|
probe = 1;
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->state = IFS_DELAY;
|
|
|
|
} else if (ifi->probeinterval &&
|
|
|
|
(ifi->probetimer -=
|
|
|
|
ifi->timer.tv_sec) <= 0) {
|
1999-12-28 02:37:14 +00:00
|
|
|
/* probe timer expired */
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->probetimer =
|
|
|
|
ifi->probeinterval;
|
1999-12-28 02:37:14 +00:00
|
|
|
probe = 1;
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->state = IFS_PROBE;
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
|
2003-08-08 16:42:37 +00:00
|
|
|
/*
|
|
|
|
* If we need a probe, clear the previous
|
2020-08-25 16:09:23 +00:00
|
|
|
* status wrt the "managed/other" configuration.
|
2003-08-08 16:42:37 +00:00
|
|
|
*/
|
2020-08-25 16:09:23 +00:00
|
|
|
if (probe) {
|
|
|
|
ifi->managedconfig = 0;
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->otherconfig = 0;
|
2020-08-25 16:09:23 +00:00
|
|
|
}
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
if (probe && mobile_node) {
|
|
|
|
error = cap_probe_defrouters(capsendmsg,
|
|
|
|
ifi);
|
|
|
|
if (error != 0)
|
|
|
|
warnmsg(LOG_DEBUG, __func__,
|
|
|
|
"failed to probe routers: %d",
|
|
|
|
error);
|
|
|
|
}
|
1999-12-28 02:37:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IFS_DELAY:
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->state = IFS_PROBE;
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
(void)cap_rssend(capsendmsg, ifi);
|
1999-12-28 02:37:14 +00:00
|
|
|
break;
|
|
|
|
case IFS_PROBE:
|
2011-06-06 03:06:43 +00:00
|
|
|
if (ifi->probes < MAX_RTR_SOLICITATIONS)
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
(void)cap_rssend(capsendmsg, ifi);
|
1999-12-28 02:37:14 +00:00
|
|
|
else {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_INFO, __func__,
|
2003-08-08 16:56:01 +00:00
|
|
|
"No answer after sending %d RSs",
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->probes);
|
|
|
|
ifi->probes = 0;
|
|
|
|
ifi->state = IFS_IDLE;
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-06-06 03:06:43 +00:00
|
|
|
rtsol_timer_update(ifi);
|
|
|
|
} else {
|
|
|
|
/* Expiration check for RA options. */
|
|
|
|
int expire = 0;
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2011-06-08 16:03:29 +00:00
|
|
|
TAILQ_FOREACH(rai, &ifi->ifi_rainfo, rai_next) {
|
2016-02-18 01:58:26 +00:00
|
|
|
TAILQ_FOREACH_SAFE(rao, &rai->rai_ra_opt,
|
|
|
|
rao_next, raotmp) {
|
2011-06-06 03:06:43 +00:00
|
|
|
warnmsg(LOG_DEBUG, __func__,
|
2011-06-08 16:03:29 +00:00
|
|
|
"RA expiration timer: "
|
|
|
|
"type=%d, msg=%s, expire=%s",
|
|
|
|
rao->rao_type, (char *)rao->rao_msg,
|
|
|
|
sec2str(&rao->rao_expire));
|
2013-08-05 20:13:02 +00:00
|
|
|
if (TS_CMP(&now, &rao->rao_expire,
|
2011-06-08 16:03:29 +00:00
|
|
|
>=)) {
|
|
|
|
warnmsg(LOG_DEBUG, __func__,
|
|
|
|
"RA expiration timer: "
|
|
|
|
"expired.");
|
|
|
|
TAILQ_REMOVE(&rai->rai_ra_opt,
|
|
|
|
rao, rao_next);
|
|
|
|
if (rao->rao_msg != NULL)
|
|
|
|
free(rao->rao_msg);
|
|
|
|
free(rao);
|
|
|
|
expire = 1;
|
|
|
|
}
|
2011-06-06 03:06:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (expire)
|
|
|
|
ra_opt_handler(ifi);
|
|
|
|
}
|
2013-08-05 20:13:02 +00:00
|
|
|
if (TS_CMP(&ifi->expire, &rtsol_timer, <))
|
2011-06-06 03:06:43 +00:00
|
|
|
rtsol_timer = ifi->expire;
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
|
2013-08-05 20:13:02 +00:00
|
|
|
if (TS_CMP(&rtsol_timer, &tm_max, ==)) {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_DEBUG, __func__, "there is no timer");
|
2011-06-06 03:06:43 +00:00
|
|
|
return (NULL);
|
2013-08-05 20:13:02 +00:00
|
|
|
} else if (TS_CMP(&rtsol_timer, &now, <))
|
1999-12-28 02:37:14 +00:00
|
|
|
/* this may occur when the interval is too small */
|
2013-08-05 20:13:02 +00:00
|
|
|
returnval.tv_sec = returnval.tv_nsec = 0;
|
1999-12-28 02:37:14 +00:00
|
|
|
else
|
2013-08-05 20:13:02 +00:00
|
|
|
TS_SUB(&rtsol_timer, &now, &returnval);
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2011-06-08 16:03:29 +00:00
|
|
|
now.tv_sec += returnval.tv_sec;
|
2013-08-05 20:13:02 +00:00
|
|
|
now.tv_nsec += returnval.tv_nsec;
|
2011-06-08 16:03:29 +00:00
|
|
|
warnmsg(LOG_DEBUG, __func__, "New timer is %s",
|
|
|
|
sec2str(&now));
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
return (&returnval);
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-06 03:06:43 +00:00
|
|
|
rtsol_timer_update(struct ifinfo *ifi)
|
1999-12-28 02:37:14 +00:00
|
|
|
{
|
2000-07-05 10:14:11 +00:00
|
|
|
#define MILLION 1000000
|
|
|
|
#define DADRETRY 10 /* XXX: adhoc */
|
1999-12-28 02:37:14 +00:00
|
|
|
long interval;
|
2013-08-05 20:13:02 +00:00
|
|
|
struct timespec now;
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
bzero(&ifi->timer, sizeof(ifi->timer));
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
switch (ifi->state) {
|
1999-12-28 02:37:14 +00:00
|
|
|
case IFS_DOWN:
|
|
|
|
case IFS_TENTATIVE:
|
2011-06-06 03:06:43 +00:00
|
|
|
if (++ifi->dadcount > DADRETRY) {
|
|
|
|
ifi->dadcount = 0;
|
|
|
|
ifi->timer.tv_sec = PROBE_INTERVAL;
|
2003-08-08 16:56:01 +00:00
|
|
|
} else
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->timer.tv_sec = 1;
|
1999-12-28 02:37:14 +00:00
|
|
|
break;
|
|
|
|
case IFS_IDLE:
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
if (mobile_node)
|
2003-08-08 16:56:01 +00:00
|
|
|
/* XXX should be configurable */
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->timer.tv_sec = 3;
|
1999-12-28 02:37:14 +00:00
|
|
|
else
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->timer = tm_max; /* stop timer(valid?) */
|
1999-12-28 02:37:14 +00:00
|
|
|
break;
|
|
|
|
case IFS_DELAY:
|
2008-07-26 15:46:39 +00:00
|
|
|
interval = arc4random_uniform(MAX_RTR_SOLICITATION_DELAY * MILLION);
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->timer.tv_sec = interval / MILLION;
|
2013-08-05 20:13:02 +00:00
|
|
|
ifi->timer.tv_nsec = (interval % MILLION) * 1000;
|
1999-12-28 02:37:14 +00:00
|
|
|
break;
|
|
|
|
case IFS_PROBE:
|
2011-06-06 03:06:43 +00:00
|
|
|
if (ifi->probes < MAX_RTR_SOLICITATIONS)
|
|
|
|
ifi->timer.tv_sec = RTR_SOLICITATION_INTERVAL;
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
else
|
2001-06-11 12:39:29 +00:00
|
|
|
/*
|
|
|
|
* After sending MAX_RTR_SOLICITATIONS solicitations,
|
|
|
|
* we're just waiting for possible replies; there
|
2005-06-08 23:51:42 +00:00
|
|
|
* will be no more solicitation. Thus, we change
|
2001-06-11 12:39:29 +00:00
|
|
|
* the timer value to MAX_RTR_SOLICITATION_DELAY based
|
|
|
|
* on RFC 2461, Section 6.3.7.
|
|
|
|
*/
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->timer.tv_sec = MAX_RTR_SOLICITATION_DELAY;
|
1999-12-28 02:37:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_ERR, __func__,
|
2003-08-08 16:56:01 +00:00
|
|
|
"illegal interface state(%d) on %s",
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->state, ifi->ifname);
|
1999-12-28 02:37:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset the timer */
|
2013-08-05 20:13:02 +00:00
|
|
|
if (TS_CMP(&ifi->timer, &tm_max, ==)) {
|
2011-06-06 03:06:43 +00:00
|
|
|
ifi->expire = tm_max;
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_DEBUG, __func__,
|
2011-06-06 03:06:43 +00:00
|
|
|
"stop timer for %s", ifi->ifname);
|
2003-08-08 16:56:01 +00:00
|
|
|
} else {
|
2013-08-05 20:13:02 +00:00
|
|
|
clock_gettime(CLOCK_MONOTONIC_FAST, &now);
|
|
|
|
TS_ADD(&now, &ifi->timer, &ifi->expire);
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2011-06-08 16:03:29 +00:00
|
|
|
now.tv_sec += ifi->timer.tv_sec;
|
2013-08-05 20:13:02 +00:00
|
|
|
now.tv_nsec += ifi->timer.tv_nsec;
|
2011-06-08 16:03:29 +00:00
|
|
|
warnmsg(LOG_DEBUG, __func__, "set timer for %s to %s",
|
|
|
|
ifi->ifname, sec2str(&now));
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef MILLION
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
set_dumpfile(int sig __unused)
|
1999-12-28 02:37:14 +00:00
|
|
|
{
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
|
1999-12-28 02:37:14 +00:00
|
|
|
do_dump = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
set_exit(int sig __unused)
|
1999-12-28 02:37:14 +00:00
|
|
|
{
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
|
|
|
|
do_exit = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(const char *progname)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (strcmp(progname, "rtsold") == 0) {
|
|
|
|
fprintf(stderr, "usage: rtsold [-dDfFm1] [-O script-name] "
|
|
|
|
"[-p pidfile] [-R script-name] interface ...\n");
|
|
|
|
fprintf(stderr, "usage: rtsold [-dDfFm1] [-O script-name] "
|
|
|
|
"[-p pidfile] [-R script-name] -a\n");
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "usage: rtsol [-dDF] [-O script-name] "
|
|
|
|
"[-p pidfile] [-R script-name] interface ...\n");
|
|
|
|
fprintf(stderr, "usage: rtsol [-dDF] [-O script-name] "
|
|
|
|
"[-p pidfile] [-R script-name] -a\n");
|
|
|
|
}
|
|
|
|
exit(1);
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
warnmsg(int priority, const char *func, const char *msg, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
|
|
|
|
va_start(ap, msg);
|
|
|
|
if (fflag) {
|
2019-02-27 18:13:41 +00:00
|
|
|
if (priority <= log_upto)
|
|
|
|
vwarnx(msg, ap);
|
1999-12-28 02:37:14 +00:00
|
|
|
} else {
|
|
|
|
snprintf(buf, sizeof(buf), "<%s> %s", func, msg);
|
2000-10-06 23:46:52 +00:00
|
|
|
msg = buf;
|
Capsicumize rtsol(8) and rtsold(8).
These programs parse ND6 Router Advertisement messages; rtsold(8) has
required an SA, SA-14:20.rtsold, for a bug in this code. Thus, they
are good candidates for sandboxing.
The approach taken is to run the main executable in capability mode
and use Casper services to provide functionality that cannot be
implemented within the sandbox. In particular, several custom services
were required.
- A Casper service is used to send Router Solicitation messages on a
raw ICMP6 socket. Initially I took the approach of creating a
socket for each interface upon startup, and connect(2)ing it to
the all-routers multicast group for the interface. This permits
the use of sendmsg(2) in capability mode, but only works if the
interface's link is up when rtsol(d) starts. So, instead, the
rtsold.sendmsg service is used to transmit RS messages on behalf
of the main process. One could alternately define a service
which simply creates and connects a socket for each destination
address, and returns the socket to the sandboxed process. However,
to implement rtsold's -m option we also need to read the ND6 default
router list, and this cannot be done in capability mode.
- rtsold may execute resolvconf(8) in response to RDNSS and DNSSL
options in received RA messages. A Casper service is used to
fork and exec resolvconf(8), and to reap the child process.
- A service is used to determine whether a given interface's
link-local address is useable (i.e., not duplicated or undergoing
DAD). This information is supplied by getifaddrs(3), which reads
a sysctl not available in capability mode. The SIOCGIFCONF socket
ioctl provides equivalent information and can be used in capability
mode, but I decided against it for now because of some limitations
of that interface.
In addition to these new services, cap_syslog(3) is used to send
messages to syslogd.
Reviewed by: oshogbo
Tested by: bz (previous versions)
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D17572
2019-01-05 16:05:39 +00:00
|
|
|
cap_vsyslog(capsyslog, priority, msg, ap);
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
}
|
2000-10-06 23:46:52 +00:00
|
|
|
|
2003-08-17 11:11:32 +00:00
|
|
|
/*
|
|
|
|
* return a list of interfaces which is suitable to sending an RS.
|
|
|
|
*/
|
2018-10-20 17:43:27 +00:00
|
|
|
static char **
|
2004-01-14 17:16:19 +00:00
|
|
|
autoifprobe(void)
|
2000-10-06 23:46:52 +00:00
|
|
|
{
|
2003-08-17 11:11:32 +00:00
|
|
|
static char **argv = NULL;
|
|
|
|
static int n = 0;
|
|
|
|
char **a;
|
2010-02-27 10:19:39 +00:00
|
|
|
int s = 0, i, found;
|
2012-01-20 01:38:52 +00:00
|
|
|
struct ifaddrs *ifap, *ifa;
|
2010-02-02 18:38:17 +00:00
|
|
|
struct in6_ndireq nd;
|
2000-10-06 23:46:52 +00:00
|
|
|
|
2003-08-17 11:11:32 +00:00
|
|
|
/* initialize */
|
|
|
|
while (n--)
|
|
|
|
free(argv[n]);
|
|
|
|
if (argv) {
|
|
|
|
free(argv);
|
|
|
|
argv = NULL;
|
|
|
|
}
|
|
|
|
n = 0;
|
|
|
|
|
2000-10-06 23:46:52 +00:00
|
|
|
if (getifaddrs(&ifap) != 0)
|
2011-06-06 03:06:43 +00:00
|
|
|
return (NULL);
|
2000-10-06 23:46:52 +00:00
|
|
|
|
2010-02-02 18:38:17 +00:00
|
|
|
if (!Fflag && (s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
|
2011-06-06 03:06:43 +00:00
|
|
|
warnmsg(LOG_ERR, __func__, "socket");
|
|
|
|
exit(1);
|
2010-02-02 18:38:17 +00:00
|
|
|
}
|
|
|
|
|
2000-10-06 23:46:52 +00:00
|
|
|
/* find an ethernet */
|
|
|
|
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
|
|
|
if ((ifa->ifa_flags & IFF_UP) == 0)
|
|
|
|
continue;
|
|
|
|
if ((ifa->ifa_flags & IFF_POINTOPOINT) != 0)
|
|
|
|
continue;
|
|
|
|
if ((ifa->ifa_flags & IFF_LOOPBACK) != 0)
|
|
|
|
continue;
|
|
|
|
if ((ifa->ifa_flags & IFF_MULTICAST) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ifa->ifa_addr->sa_family != AF_INET6)
|
|
|
|
continue;
|
|
|
|
|
2003-08-17 11:11:32 +00:00
|
|
|
found = 0;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
if (strcmp(argv[i], ifa->ifa_name) == 0) {
|
|
|
|
found++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found)
|
2000-10-06 23:46:52 +00:00
|
|
|
continue;
|
|
|
|
|
2010-02-02 18:38:17 +00:00
|
|
|
/*
|
|
|
|
* Skip the interfaces which IPv6 and/or accepting RA
|
|
|
|
* is disabled.
|
|
|
|
*/
|
|
|
|
if (!Fflag) {
|
|
|
|
memset(&nd, 0, sizeof(nd));
|
|
|
|
strlcpy(nd.ifname, ifa->ifa_name, sizeof(nd.ifname));
|
|
|
|
if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) {
|
2011-06-06 03:06:43 +00:00
|
|
|
warnmsg(LOG_ERR, __func__,
|
|
|
|
"ioctl(SIOCGIFINFO_IN6)");
|
|
|
|
exit(1);
|
2010-02-02 18:38:17 +00:00
|
|
|
}
|
|
|
|
if ((nd.ndi.flags & ND6_IFF_IFDISABLED))
|
|
|
|
continue;
|
|
|
|
if (!(nd.ndi.flags & ND6_IFF_ACCEPT_RTADV))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-08-17 11:11:32 +00:00
|
|
|
/* if we find multiple candidates, just warn. */
|
|
|
|
if (n != 0 && dflag > 1)
|
2011-06-06 03:06:43 +00:00
|
|
|
warnmsg(LOG_WARNING, __func__,
|
|
|
|
"multiple interfaces found");
|
2003-08-17 11:11:32 +00:00
|
|
|
|
2015-12-29 11:24:41 +00:00
|
|
|
a = realloc(argv, (n + 1) * sizeof(char *));
|
2011-06-06 03:06:43 +00:00
|
|
|
if (a == NULL) {
|
|
|
|
warnmsg(LOG_ERR, __func__, "realloc");
|
|
|
|
exit(1);
|
|
|
|
}
|
2003-08-17 11:11:32 +00:00
|
|
|
argv = a;
|
|
|
|
argv[n] = strdup(ifa->ifa_name);
|
2011-06-06 03:06:43 +00:00
|
|
|
if (!argv[n]) {
|
|
|
|
warnmsg(LOG_ERR, __func__, "malloc");
|
|
|
|
exit(1);
|
|
|
|
}
|
2003-08-17 11:11:32 +00:00
|
|
|
n++;
|
2000-10-06 23:46:52 +00:00
|
|
|
}
|
|
|
|
|
2003-08-17 11:11:32 +00:00
|
|
|
if (n) {
|
2015-12-29 11:24:41 +00:00
|
|
|
a = realloc(argv, (n + 1) * sizeof(char *));
|
2011-06-06 03:06:43 +00:00
|
|
|
if (a == NULL) {
|
|
|
|
warnmsg(LOG_ERR, __func__, "realloc");
|
|
|
|
exit(1);
|
|
|
|
}
|
2003-08-17 11:11:32 +00:00
|
|
|
argv = a;
|
|
|
|
argv[n] = NULL;
|
2000-10-06 23:46:52 +00:00
|
|
|
|
2003-08-17 11:11:32 +00:00
|
|
|
if (dflag > 0) {
|
|
|
|
for (i = 0; i < n; i++)
|
2011-06-06 03:06:43 +00:00
|
|
|
warnmsg(LOG_WARNING, __func__, "probing %s",
|
|
|
|
argv[i]);
|
2003-08-17 11:11:32 +00:00
|
|
|
}
|
2000-10-06 23:46:52 +00:00
|
|
|
}
|
2010-02-02 18:38:17 +00:00
|
|
|
if (!Fflag)
|
|
|
|
close(s);
|
2000-10-06 23:46:52 +00:00
|
|
|
freeifaddrs(ifap);
|
2011-06-06 03:06:43 +00:00
|
|
|
return (argv);
|
2000-10-06 23:46:52 +00:00
|
|
|
}
|