diff options
author | Florian Obser <florian@cvs.openbsd.org> | 2017-07-14 09:29:41 +0000 |
---|---|---|
committer | Florian Obser <florian@cvs.openbsd.org> | 2017-07-14 09:29:41 +0000 |
commit | 064febc3290337f1dd0bcfbac4535b209d631999 (patch) | |
tree | 34d7f9b095bf05691f78487070c2bc0d8e5708bb /sbin | |
parent | bf853205588bd113ffa17f78dc0bcfdda3bf2717 (diff) |
run IMSG_UPDATE_IF through the main process, reduces upcomming diff
for RFC 7217 support
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/slaacd/engine.c | 139 | ||||
-rw-r--r-- | sbin/slaacd/frontend.c | 4 | ||||
-rw-r--r-- | sbin/slaacd/slaacd.c | 12 |
3 files changed, 83 insertions, 72 deletions
diff --git a/sbin/slaacd/engine.c b/sbin/slaacd/engine.c index e02cb6ec3d0..394df48eeb6 100644 --- a/sbin/slaacd/engine.c +++ b/sbin/slaacd/engine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: engine.c,v 1.6 2017/07/09 09:00:56 florian Exp $ */ +/* $OpenBSD: engine.c,v 1.7 2017/07/14 09:29:40 florian Exp $ */ /* * Copyright (c) 2017 Florian Obser <florian@openbsd.org> @@ -378,7 +378,6 @@ engine_dispatch_frontend(int fd, short event, void *bula) struct imsg imsg; struct slaacd_iface *iface; struct imsg_ra ra; - struct imsg_ifinfo imsg_ifinfo; struct imsg_proposal_ack proposal_ack; struct address_proposal *addr_proposal = NULL; struct dfr_proposal *dfr_proposal = NULL; @@ -424,73 +423,6 @@ engine_dispatch_frontend(int fd, short event, void *bula) engine_showinfo_ctl(&imsg, if_index); break; #endif /* SMALL */ - case IMSG_UPDATE_IF: - if (imsg.hdr.len != IMSG_HEADER_SIZE + - sizeof(imsg_ifinfo)) - fatal("%s: IMSG_UPDATE_IF wrong length: %d", - __func__, imsg.hdr.len); - memcpy(&imsg_ifinfo, imsg.data, sizeof(imsg_ifinfo)); - - iface = get_slaacd_iface_by_id(imsg_ifinfo.if_index); - if (iface == NULL) { - if ((iface = calloc(1, sizeof(*iface))) == NULL) - fatal("calloc"); - evtimer_set(&iface->timer, iface_timeout, - iface); - iface->if_index = imsg_ifinfo.if_index; - iface->running = imsg_ifinfo.running; - if (iface->running) - start_probe(iface); - else - iface->state = IF_DOWN; - iface->autoconfprivacy = - imsg_ifinfo.autoconfprivacy; - memcpy(&iface->hw_address, - &imsg_ifinfo.hw_address, - sizeof(struct ether_addr)); - memcpy(&iface->ll_address, - &imsg_ifinfo.ll_address, - sizeof(struct sockaddr_in6)); - LIST_INIT(&iface->radvs); - LIST_INSERT_HEAD(&slaacd_interfaces, - iface, entries); - LIST_INIT(&iface->addr_proposals); - LIST_INIT(&iface->dfr_proposals); - } else { - int need_refresh = 0; - - if (iface->autoconfprivacy != - imsg_ifinfo.autoconfprivacy) { - iface->autoconfprivacy = - imsg_ifinfo.autoconfprivacy; - need_refresh = 1; - } - if (memcmp(&iface->hw_address, - &imsg_ifinfo.hw_address, - sizeof(struct ether_addr)) != 0) { - memcpy(&iface->hw_address, - &imsg_ifinfo.hw_address, - sizeof(struct ether_addr)); - need_refresh = 1; - } - - if (iface->state != IF_DOWN && - imsg_ifinfo.running && need_refresh) - start_probe(iface); - - iface->running = imsg_ifinfo.running; - if (!iface->running) { - iface->state = IF_DOWN; - if (evtimer_pending(&iface->timer, - NULL)) - evtimer_del(&iface->timer); - } - - memcpy(&iface->ll_address, - &imsg_ifinfo.ll_address, - sizeof(struct sockaddr_in6)); - } - break; case IMSG_REMOVE_IF: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(if_index)) fatal("%s: IMSG_REMOVE_IF wrong length: %d", @@ -605,6 +537,8 @@ engine_dispatch_main(int fd, short event, void *bula) struct imsg imsg; struct imsgev *iev = bula; struct imsgbuf *ibuf = &iev->ibuf; + struct imsg_ifinfo imsg_ifinfo; + struct slaacd_iface *iface; ssize_t n; int shut = 0; @@ -660,6 +594,73 @@ engine_dispatch_main(int fd, short event, void *bula) if (pledge("stdio", NULL) == -1) fatal("pledge"); break; + case IMSG_UPDATE_IF: + if (imsg.hdr.len != IMSG_HEADER_SIZE + + sizeof(imsg_ifinfo)) + fatal("%s: IMSG_UPDATE_IF wrong length: %d", + __func__, imsg.hdr.len); + memcpy(&imsg_ifinfo, imsg.data, sizeof(imsg_ifinfo)); + + iface = get_slaacd_iface_by_id(imsg_ifinfo.if_index); + if (iface == NULL) { + if ((iface = calloc(1, sizeof(*iface))) == NULL) + fatal("calloc"); + evtimer_set(&iface->timer, iface_timeout, + iface); + iface->if_index = imsg_ifinfo.if_index; + iface->running = imsg_ifinfo.running; + if (iface->running) + start_probe(iface); + else + iface->state = IF_DOWN; + iface->autoconfprivacy = + imsg_ifinfo.autoconfprivacy; + memcpy(&iface->hw_address, + &imsg_ifinfo.hw_address, + sizeof(struct ether_addr)); + memcpy(&iface->ll_address, + &imsg_ifinfo.ll_address, + sizeof(struct sockaddr_in6)); + LIST_INIT(&iface->radvs); + LIST_INSERT_HEAD(&slaacd_interfaces, + iface, entries); + LIST_INIT(&iface->addr_proposals); + LIST_INIT(&iface->dfr_proposals); + } else { + int need_refresh = 0; + + if (iface->autoconfprivacy != + imsg_ifinfo.autoconfprivacy) { + iface->autoconfprivacy = + imsg_ifinfo.autoconfprivacy; + need_refresh = 1; + } + if (memcmp(&iface->hw_address, + &imsg_ifinfo.hw_address, + sizeof(struct ether_addr)) != 0) { + memcpy(&iface->hw_address, + &imsg_ifinfo.hw_address, + sizeof(struct ether_addr)); + need_refresh = 1; + } + + if (iface->state != IF_DOWN && + imsg_ifinfo.running && need_refresh) + start_probe(iface); + + iface->running = imsg_ifinfo.running; + if (!iface->running) { + iface->state = IF_DOWN; + if (evtimer_pending(&iface->timer, + NULL)) + evtimer_del(&iface->timer); + } + + memcpy(&iface->ll_address, + &imsg_ifinfo.ll_address, + sizeof(struct sockaddr_in6)); + } + break; default: log_debug("%s: unexpected imsg %d", __func__, imsg.hdr.type); diff --git a/sbin/slaacd/frontend.c b/sbin/slaacd/frontend.c index 28524e41454..8bd49e2f1ad 100644 --- a/sbin/slaacd/frontend.c +++ b/sbin/slaacd/frontend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend.c,v 1.3 2017/07/06 15:02:53 florian Exp $ */ +/* $OpenBSD: frontend.c,v 1.4 2017/07/14 09:29:40 florian Exp $ */ /* * Copyright (c) 2017 Florian Obser <florian@openbsd.org> @@ -509,7 +509,7 @@ update_iface(uint32_t if_index, char* if_name) memcpy(&nd_opt_source_link_addr, &imsg_ifinfo.hw_address, sizeof(nd_opt_source_link_addr)); - frontend_imsg_compose_engine(IMSG_UPDATE_IF, 0, 0, &imsg_ifinfo, + frontend_imsg_compose_main(IMSG_UPDATE_IF, 0, &imsg_ifinfo, sizeof(imsg_ifinfo)); } diff --git a/sbin/slaacd/slaacd.c b/sbin/slaacd/slaacd.c index 482ebf4e5e9..91cb9c143a2 100644 --- a/sbin/slaacd/slaacd.c +++ b/sbin/slaacd/slaacd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: slaacd.c,v 1.4 2017/07/06 15:02:53 florian Exp $ */ +/* $OpenBSD: slaacd.c,v 1.5 2017/07/14 09:29:40 florian Exp $ */ /* * Copyright (c) 2017 Florian Obser <florian@openbsd.org> @@ -369,6 +369,7 @@ main_dispatch_frontend(int fd, short event, void *bula) struct imsgev *iev = bula; struct imsgbuf *ibuf; struct imsg imsg; + struct imsg_ifinfo imsg_ifinfo; ssize_t n; int shut = 0; #ifndef SMALL @@ -404,6 +405,15 @@ main_dispatch_frontend(int fd, short event, void *bula) log_setverbose(verbose); break; #endif /* SMALL */ + case IMSG_UPDATE_IF: + if (imsg.hdr.len != IMSG_HEADER_SIZE + + sizeof(imsg_ifinfo)) + fatal("%s: IMSG_UPDATE_IF wrong length: %d", + __func__, imsg.hdr.len); + memcpy(&imsg_ifinfo, imsg.data, sizeof(imsg_ifinfo)); + main_imsg_compose_engine(IMSG_UPDATE_IF, 0, + &imsg_ifinfo, sizeof(imsg_ifinfo)); + break; default: log_debug("%s: error handling imsg %d", __func__, imsg.hdr.type); |