From 4f0adeda2ce66c9b5fe2c09917a854e358fbda39 Mon Sep 17 00:00:00 2001 From: claudio Date: Tue, 17 Oct 2023 17:59:59 +0000 Subject: [PATCH] Neither sin_len nor sin6_len can be 0 so these checks are not needed. Also reorder the RTF_HOST vs netmask check. RTF_HOST wins if both are set. Makes the code a bit neater. OK tb@ --- usr.sbin/bgpd/kroute.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c index 69c09c67041..f7b402b88bd 100644 --- a/usr.sbin/bgpd/kroute.c +++ b/usr.sbin/bgpd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.306 2023/10/16 10:25:45 claudio Exp $ */ +/* $OpenBSD: kroute.c,v 1.307 2023/10/17 17:59:59 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -2422,8 +2422,6 @@ mask2prefixlen4(struct sockaddr_in *sa_in) { in_addr_t ina; - if (sa_in->sin_len == 0) - return (0); ina = sa_in->sin_addr.s_addr; if (ina == 0) return (0); @@ -2437,8 +2435,6 @@ mask2prefixlen6(struct sockaddr_in6 *sa_in6) uint8_t *ap, *ep; u_int l = 0; - if (sa_in6->sin6_len == 0) - return (0); /* * sin6_len is the size of the sockaddr so subtract the offset of * the possibly truncated sin6_addr struct. @@ -3096,20 +3092,20 @@ dispatch_rtmsg_addr(struct rt_msghdr *rtm, struct kroute_full *kf) switch (sa->sa_family) { case AF_INET: sa_in = (struct sockaddr_in *)rti_info[RTAX_NETMASK]; - if (sa_in != NULL) { - kf->prefixlen = mask2prefixlen4(sa_in); - } else if (rtm->rtm_flags & RTF_HOST) + if (rtm->rtm_flags & RTF_HOST) kf->prefixlen = 32; + else if (sa_in != NULL) + kf->prefixlen = mask2prefixlen4(sa_in); else kf->prefixlen = prefixlen_classful(kf->prefix.v4.s_addr); break; case AF_INET6: sa_in6 = (struct sockaddr_in6 *)rti_info[RTAX_NETMASK]; - if (sa_in6 != NULL) { - kf->prefixlen = mask2prefixlen6(sa_in6); - } else if (rtm->rtm_flags & RTF_HOST) + if (rtm->rtm_flags & RTF_HOST) kf->prefixlen = 128; + else if (sa_in6 != NULL) + kf->prefixlen = mask2prefixlen6(sa_in6); else fatalx("in6 net addr without netmask"); break; -- 2.20.1