summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2023-10-17 18:00:00 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2023-10-17 18:00:00 +0000
commit1390132d716d4e14f00f0447dbe4977bf08567c1 (patch)
tree72adb02bcf1ab7a1c1c3643a13e8764beb97248c /usr.sbin/bgpd
parent8550a8d3b56f97ed6037dfd5c4584ebf2f73c285 (diff)
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@
Diffstat (limited to 'usr.sbin/bgpd')
-rw-r--r--usr.sbin/bgpd/kroute.c18
1 files 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 <henning@openbsd.org>
@@ -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;