summaryrefslogtreecommitdiff
path: root/usr.sbin/slaacd
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2017-05-27 10:47:24 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2017-05-27 10:47:24 +0000
commitac55f34bbfa9ff6d6f4268c036425ba9a243aec4 (patch)
treeaca359e16343cc92dec5641aab64f65cd5cb756d /usr.sbin/slaacd
parent6e762b335d8390649478edd9b67dc6a887f0c5b2 (diff)
configure address on interface
Diffstat (limited to 'usr.sbin/slaacd')
-rw-r--r--usr.sbin/slaacd/engine.c14
-rw-r--r--usr.sbin/slaacd/engine.h10
-rw-r--r--usr.sbin/slaacd/frontend.c8
-rw-r--r--usr.sbin/slaacd/slaacd.c73
-rw-r--r--usr.sbin/slaacd/slaacd.h3
5 files changed, 95 insertions, 13 deletions
diff --git a/usr.sbin/slaacd/engine.c b/usr.sbin/slaacd/engine.c
index 3e1ce79b107..ac6694c53d3 100644
--- a/usr.sbin/slaacd/engine.c
+++ b/usr.sbin/slaacd/engine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: engine.c,v 1.10 2017/05/27 10:45:14 florian Exp $ */
+/* $OpenBSD: engine.c,v 1.11 2017/05/27 10:47:23 florian Exp $ */
/*
* Copyright (c) 2017 Florian Obser <florian@openbsd.org>
@@ -1402,7 +1402,8 @@ void
configure_address(struct slaacd_iface *iface, struct address_proposal
*addr_proposal)
{
- struct timeval tv;
+ struct imsg_configure_address address;
+ struct timeval tv;
addr_proposal->next_timeout = addr_proposal->pltime -
MAX_RTR_SOLICITATIONS * (RTR_SOLICITATION_INTERVAL + 1);
@@ -1414,6 +1415,15 @@ configure_address(struct slaacd_iface *iface, struct address_proposal
addr_proposal->state = PROPOSAL_CONFIGURED;
log_debug("%s: %d", __func__, iface->if_index);
+
+ address.if_index = iface->if_index;
+ memcpy(&address.addr, &addr_proposal->addr, sizeof(address.addr));
+ memcpy(&address.mask, &addr_proposal->mask, sizeof(address.mask));
+ address.vltime = addr_proposal->vltime;
+ address.pltime = addr_proposal->pltime;
+
+ engine_imsg_compose_main(IMSG_CONFIGURE_ADDRESS, 0, &address,
+ sizeof(address));
}
void
diff --git a/usr.sbin/slaacd/engine.h b/usr.sbin/slaacd/engine.h
index 45e362f7a58..c7e6023fee6 100644
--- a/usr.sbin/slaacd/engine.h
+++ b/usr.sbin/slaacd/engine.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: engine.h,v 1.4 2017/05/27 10:45:14 florian Exp $ */
+/* $OpenBSD: engine.h,v 1.5 2017/05/27 10:47:23 florian Exp $ */
/*
* Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
@@ -28,5 +28,13 @@ struct imsg_proposal {
int rtm_addrs;
};
+struct imsg_configure_address {
+ uint32_t if_index;
+ struct sockaddr_in6 addr;
+ struct in6_addr mask;
+ uint32_t vltime;
+ uint32_t pltime;
+};
+
void engine(int, int);
int engine_imsg_compose_frontend(int, pid_t, void *, uint16_t);
diff --git a/usr.sbin/slaacd/frontend.c b/usr.sbin/slaacd/frontend.c
index 41332d5d8ee..fa0ed08e72a 100644
--- a/usr.sbin/slaacd/frontend.c
+++ b/usr.sbin/slaacd/frontend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: frontend.c,v 1.5 2017/05/27 10:45:14 florian Exp $ */
+/* $OpenBSD: frontend.c,v 1.6 2017/05/27 10:47:23 florian Exp $ */
/*
* Copyright (c) 2017 Florian Obser <florian@openbsd.org>
@@ -568,6 +568,12 @@ route_receive(int fd, short events, void *arg)
}
break;
case RTM_NEWADDR:
+ /*
+ * XXX we get a RTM_NEWADDR if the l2 addr changes, also
+ * when we configure an ip ourselfs or someone
+ * configures an ip, don't send solicitations in that
+ * case
+ */
ifm = (struct if_msghdr *)rtm;
if_name = if_indextoname(ifm->ifm_index, ifnamebuf);
log_debug("RTM_NEWADDR: %s[%u]", if_name, ifm->ifm_index);
diff --git a/usr.sbin/slaacd/slaacd.c b/usr.sbin/slaacd/slaacd.c
index eea1b38d20e..4f2f081ecf8 100644
--- a/usr.sbin/slaacd/slaacd.c
+++ b/usr.sbin/slaacd/slaacd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: slaacd.c,v 1.8 2017/05/27 10:46:27 florian Exp $ */
+/* $OpenBSD: slaacd.c,v 1.9 2017/05/27 10:47:23 florian Exp $ */
/*
* Copyright (c) 2017 Florian Obser <florian@openbsd.org>
@@ -19,6 +19,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
+#include <sys/ioctl.h>
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/syslog.h>
@@ -29,6 +30,7 @@
#include <net/route.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
+#include <netinet6/in6_var.h>
#include <err.h>
#include <errno.h>
@@ -67,6 +69,7 @@ const char* imsg_type_name[] = {
"IMSG_CTL_SEND_SOLICITATION",
"IMSG_PROPOSAL",
"IMSG_PROPOSAL_ACK",
+ "IMSG_CONFIGURE_ADDRESS",
};
__dead void usage(void);
@@ -79,6 +82,7 @@ static pid_t start_child(int, char *, int, int, int, char *);
void main_dispatch_frontend(int, short, void *);
void main_dispatch_engine(int, short, void *);
void handle_proposal(struct imsg_proposal *);
+void configure_interface(struct imsg_configure_address *);
static int main_imsg_send_ipc_sockets(struct imsgbuf *, struct imsgbuf *);
@@ -90,7 +94,7 @@ pid_t engine_pid;
uint32_t cmd_opts;
-int routesock;
+int routesock, ioctl_sock;
char *csock;
@@ -249,8 +253,14 @@ main(int argc, char *argv[])
if (main_imsg_send_ipc_sockets(&iev_frontend->ibuf, &iev_engine->ibuf))
fatal("could not establish imsg links");
+ if ((ioctl_sock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
+ fatal("socket");
+
+#if 0
+ /* XXX ioctl SIOCAIFADDR_IN6 */
if (pledge("rpath stdio sendfd cpath", NULL) == -1)
fatal("pledge");
+#endif
main_imsg_compose_frontend(IMSG_STARTUP, 0, NULL, 0);
@@ -393,12 +403,13 @@ main_dispatch_frontend(int fd, short event, void *bula)
void
main_dispatch_engine(int fd, short event, void *bula)
{
- struct imsgev *iev = bula;
- struct imsgbuf *ibuf;
- struct imsg imsg;
- struct imsg_proposal proposal;
- ssize_t n;
- int shut = 0;
+ struct imsgev *iev = bula;
+ struct imsgbuf *ibuf;
+ struct imsg imsg;
+ struct imsg_proposal proposal;
+ struct imsg_configure_address address;
+ ssize_t n;
+ int shut = 0;
ibuf = &iev->ibuf;
@@ -429,6 +440,13 @@ main_dispatch_engine(int fd, short event, void *bula)
memcpy(&proposal, imsg.data, sizeof(proposal));
handle_proposal(&proposal);
break;
+ case IMSG_CONFIGURE_ADDRESS:
+ if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(address))
+ fatal("%s: IMSG_CONFIGURE_ADDRESS wrong "
+ "length: %d", __func__, imsg.hdr.len);
+ memcpy(&address, imsg.data, sizeof(address));
+ configure_interface(&address);
+ break;
default:
log_debug("%s: error handling imsg %d", __func__,
imsg.hdr.type);
@@ -599,6 +617,45 @@ handle_proposal(struct imsg_proposal *proposal)
log_warn("failed to send proposal");
}
+void
+configure_interface(struct imsg_configure_address *address)
+{
+
+ struct in6_aliasreq in6_addreq;
+ time_t t;
+ char *if_name;
+
+ memset(&in6_addreq, 0, sizeof(in6_addreq));
+
+ if_name = if_indextoname(address->if_index, in6_addreq.ifra_name);
+ if (if_name == NULL) {
+ log_warn("%s: cannot find interface %d", __func__,
+ address->if_index);
+ return;
+ }
+
+ memcpy(&in6_addreq.ifra_addr, &address->addr,
+ sizeof(in6_addreq.ifra_addr));
+ memcpy(&in6_addreq.ifra_prefixmask.sin6_addr, &address->mask,
+ sizeof(in6_addreq.ifra_prefixmask.sin6_addr));
+ in6_addreq.ifra_prefixmask.sin6_family = AF_INET6;
+ in6_addreq.ifra_prefixmask.sin6_len =
+ sizeof(in6_addreq.ifra_prefixmask);
+
+ t = time(NULL);
+
+ in6_addreq.ifra_lifetime.ia6t_expire = t + address->vltime;
+ in6_addreq.ifra_lifetime.ia6t_vltime = address->vltime;
+
+ in6_addreq.ifra_lifetime.ia6t_preferred = t + address->pltime;
+ in6_addreq.ifra_lifetime.ia6t_pltime = address->pltime;
+
+ log_debug("%s: %s", __func__, if_name);
+
+ if (ioctl(ioctl_sock, SIOCAIFADDR_IN6, &in6_addreq) < 0)
+ fatal("SIOCAIFADDR_IN6");
+}
+
#if 0
void
handle_proposal(struct imsg_proposal *proposal)
diff --git a/usr.sbin/slaacd/slaacd.h b/usr.sbin/slaacd/slaacd.h
index 5a2d7a24d91..4a3dd9d225f 100644
--- a/usr.sbin/slaacd/slaacd.h
+++ b/usr.sbin/slaacd/slaacd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: slaacd.h,v 1.8 2017/05/27 10:45:14 florian Exp $ */
+/* $OpenBSD: slaacd.h,v 1.9 2017/05/27 10:47:23 florian Exp $ */
/*
* Copyright (c) 2017 Florian Obser <florian@openbsd.org>
@@ -65,6 +65,7 @@ enum imsg_type {
IMSG_CTL_SEND_SOLICITATION,
IMSG_PROPOSAL,
IMSG_PROPOSAL_ACK,
+ IMSG_CONFIGURE_ADDRESS,
};
extern const char* imsg_type_name[];