From: claudio Date: Mon, 8 Jan 2024 15:08:34 +0000 (+0000) Subject: Define and use struct ctl_kroute_req to encode the arguments of X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=9150415584ede666dd5fe16dd1962abe15ee7968;p=openbsd Define and use struct ctl_kroute_req to encode the arguments of IMSG_CTL_KROUTE instead of doing it by hand. OK tb@ --- diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index 79d3c0638b0..d65f329b765 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.478 2023/10/16 10:25:45 claudio Exp $ */ +/* $OpenBSD: bgpd.h,v 1.479 2024/01/08 15:08:34 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -974,6 +974,11 @@ struct ctl_show_rib_request { uint8_t aid; }; +struct ctl_kroute_req { + int flags; + sa_family_t af; +}; + enum filter_actions { ACTION_NONE, ACTION_ALLOW, diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c index f7b402b88bd..5915165595d 100644 --- a/usr.sbin/bgpd/kroute.c +++ b/usr.sbin/bgpd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.307 2023/10/17 17:59:59 claudio Exp $ */ +/* $OpenBSD: kroute.c,v 1.308 2024/01/08 15:08:34 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -884,8 +884,7 @@ kr_show_route(struct imsg *imsg) struct kroute6 *kr6, *kn6; struct kroute_full *kf; struct bgpd_addr *addr; - int flags; - sa_family_t af; + struct ctl_kroute_req req; struct ctl_show_nexthop snh; struct knexthop *h; struct kif *kif; @@ -894,8 +893,7 @@ kr_show_route(struct imsg *imsg) switch (imsg->hdr.type) { case IMSG_CTL_KROUTE: - if (imsg->hdr.len != IMSG_HEADER_SIZE + sizeof(flags) + - sizeof(af)) { + if (imsg->hdr.len != IMSG_HEADER_SIZE + sizeof(req)) { log_warnx("%s: wrong imsg len", __func__); break; } @@ -905,11 +903,10 @@ kr_show_route(struct imsg *imsg) imsg->hdr.peerid); break; } - memcpy(&flags, imsg->data, sizeof(flags)); - memcpy(&af, (char *)imsg->data + sizeof(flags), sizeof(af)); - if (!af || af == AF_INET) + memcpy(&req, imsg->data, sizeof(req)); + if (!req.af || req.af == AF_INET) RB_FOREACH(kr, kroute_tree, &kt->krt) { - if (flags && (kr->flags & flags) == 0) + if (req.flags && (kr->flags & req.flags) == 0) continue; kn = kr; do { @@ -919,9 +916,9 @@ kr_show_route(struct imsg *imsg) imsg->hdr.pid, kf, sizeof(*kf)); } while ((kn = kn->next) != NULL); } - if (!af || af == AF_INET6) + if (!req.af || req.af == AF_INET6) RB_FOREACH(kr6, kroute6_tree, &kt->krt6) { - if (flags && (kr6->flags & flags) == 0) + if (req.flags && (kr6->flags & req.flags) == 0) continue; kn6 = kr6; do {