From ec9c8587d77d9dd9911045fb75e5b11c2c7506d0 Mon Sep 17 00:00:00 2001 From: Alex Wilson Date: Wed, 17 Jul 2024 11:42:32 +1000 Subject: [PATCH] wip: update illumos patch --- .github/buildomat/jobs/build.sh | 6 +- patches/0006-illumos.patch | 52 ---------- patches/0007-illumos.patch | 75 +++++++++++++++ smf.xml | 4 +- src/bgpd/kroute-illumos.c | 164 ++++++++++++++++++-------------- 5 files changed, 177 insertions(+), 124 deletions(-) delete mode 100644 patches/0006-illumos.patch create mode 100644 patches/0007-illumos.patch diff --git a/.github/buildomat/jobs/build.sh b/.github/buildomat/jobs/build.sh index 21c232c..0b7de49 100644 --- a/.github/buildomat/jobs/build.sh +++ b/.github/buildomat/jobs/build.sh @@ -23,7 +23,11 @@ banner configure # export MAKE=gmake export AR=gar -./update.sh OPENBSD_7_2 +./update.sh +(cd openbsd && + git checkout -b release openbgpd-8.5 && + rm -fr .git) +./update.sh mkdir m4 rm -fr autom4te.cache autoreconf -fi diff --git a/patches/0006-illumos.patch b/patches/0006-illumos.patch deleted file mode 100644 index 9db552d..0000000 --- a/patches/0006-illumos.patch +++ /dev/null @@ -1,52 +0,0 @@ -commit 2eaf8bd1b73a48bf16baa386e409cfcd8614787a -Author: Alex Wilson -Date: Mon Jan 24 10:42:54 2022 +1000 - - xxx: illumos patches - -diff --git a/src/usr.sbin/bgpctl/bgpctl.c b/src/usr.sbin/bgpctl/bgpctl.c -index 724c185f..8d7c0bd3 100644 ---- src/usr.sbin/bgpctl/bgpctl.c -+++ src/usr.sbin/bgpctl/bgpctl.c -@@ -75,6 +75,8 @@ usage(void) - exit(1); - } - -+#undef sun -+ - int - main(int argc, char *argv[]) - { -diff --git a/src/usr.sbin/bgpd/control.c b/src/usr.sbin/bgpd/control.c -index 844a05e5..7d11d030 100644 ---- src/usr.sbin/bgpd/control.c -+++ src/usr.sbin/bgpd/control.c -@@ -39,6 +39,8 @@ int control_close(struct ctl_conn *); - void control_result(struct ctl_conn *, u_int); - ssize_t imsg_read_nofd(struct imsgbuf *); - -+#undef sun -+ - int - control_check(char *path) - { -diff --git a/src/usr.sbin/bgpd/session.c b/src/usr.sbin/bgpd/session.c -index 61224667..76c50390 100644 ---- src/usr.sbin/bgpd/session.c -+++ src/usr.sbin/bgpd/session.c -@@ -1141,6 +1141,7 @@ session_setup_socket(struct peer *p) - */ - if (p->conf.ttlsec) { - ttl = 256 - p->conf.distance; -+#if defined(IP_MINTTL) - if (setsockopt(p->fd, IPPROTO_IP, IP_MINTTL, - &ttl, sizeof(ttl)) == -1) { - log_peer_warn(&p->conf, -@@ -1148,6 +1149,7 @@ session_setup_socket(struct peer *p) - "setsockopt MINTTL"); - return (-1); - } -+#endif - ttl = 255; - } - diff --git a/patches/0007-illumos.patch b/patches/0007-illumos.patch new file mode 100644 index 0000000..b939f42 --- /dev/null +++ b/patches/0007-illumos.patch @@ -0,0 +1,75 @@ +From 0fa9d77204a2331f3a171a34cc9590aa08b03833 Mon Sep 17 00:00:00 2001 +From: Alex Wilson +Date: Mon, 24 Jan 2022 10:42:54 +1000 +Subject: [PATCH] xxx: illumos patches + +--- + src/usr.sbin/bgpctl/bgpctl.c | 2 ++ + src/usr.sbin/bgpd/control.c | 2 ++ + src/usr.sbin/bgpd/parse.y | 3 +++ + src/usr.sbin/bgpd/session.c | 2 ++ + 4 files changed, 9 insertions(+) + +diff --git a/src/usr.sbin/bgpctl/bgpctl.c b/src/usr.sbin/bgpctl/bgpctl.c +index 1dd4c7a67..aff3d6352 100644 +--- src/usr.sbin/bgpctl/bgpctl.c ++++ src/usr.sbin/bgpctl/bgpctl.c +@@ -77,6 +77,8 @@ usage(void) + exit(1); + } + ++#undef sun ++ + int + main(int argc, char *argv[]) + { +diff --git a/src/usr.sbin/bgpd/control.c b/src/usr.sbin/bgpd/control.c +index 49fd55ad1..4c9db8046 100644 +--- src/usr.sbin/bgpd/control.c ++++ src/usr.sbin/bgpd/control.c +@@ -39,6 +39,8 @@ int control_close(struct ctl_conn *); + void control_result(struct ctl_conn *, u_int); + ssize_t imsg_read_nofd(struct imsgbuf *); + ++#undef sun ++ + int + control_check(char *path) + { +diff --git a/src/usr.sbin/bgpd/parse.y b/src/usr.sbin/bgpd/parse.y +index fa8047d5b..4ec341d60 100644 +--- src/usr.sbin/bgpd/parse.y ++++ src/usr.sbin/bgpd/parse.y +@@ -27,6 +27,9 @@ + #include + #include + #include ++#if defined(__sun) ++#include ++#endif + #include + #include + #include +diff --git a/src/usr.sbin/bgpd/session.c b/src/usr.sbin/bgpd/session.c +index dd24eb29a..4d2003b69 100644 +--- src/usr.sbin/bgpd/session.c ++++ src/usr.sbin/bgpd/session.c +@@ -1154,6 +1154,7 @@ session_setup_socket(struct peer *p) + */ + if (p->conf.ttlsec) { + ttl = 256 - p->conf.distance; ++#if defined(IP_MINTTL) + if (setsockopt(p->fd, IPPROTO_IP, IP_MINTTL, + &ttl, sizeof(ttl)) == -1) { + log_peer_warn(&p->conf, +@@ -1161,6 +1162,7 @@ session_setup_socket(struct peer *p) + "setsockopt MINTTL"); + return (-1); + } ++#endif + ttl = 255; + } + +-- +2.45.2 + diff --git a/smf.xml b/smf.xml index 0725d97..dc559f0 100644 --- a/smf.xml +++ b/smf.xml @@ -16,7 +16,7 @@ - + @@ -26,7 +26,7 @@ - + diff --git a/src/bgpd/kroute-illumos.c b/src/bgpd/kroute-illumos.c index 78bc5bb..59282b3 100644 --- a/src/bgpd/kroute-illumos.c +++ b/src/bgpd/kroute-illumos.c @@ -23,8 +23,9 @@ #include #include #include -#include +#include #include +#include #include #include #include @@ -208,8 +209,6 @@ void kroute_detach_nexthop(struct ktable *, struct knexthop *); int protect_lo(struct ktable *); u_int8_t prefixlen_classful(in_addr_t); -u_int8_t mask2prefixlen(in_addr_t); -u_int8_t mask2prefixlen6(struct sockaddr_in6 *); uint64_t ift2ifm(uint8_t); const char *get_media_descr(uint64_t); const char *get_linkstate(uint8_t, int); @@ -762,10 +761,15 @@ fetchtable(struct ktable *kt, int init) if (ire_flags & RTF_PROTO2) kr->priority = kr_state.fib_prio; kr->prefix.s_addr = rp->ipRouteDest; - if (ire_flags & RTF_HOST) + if (ire_flags & RTF_HOST) { kr->prefixlen = 32; - else - kr->prefixlen = mask2prefixlen(rp->ipRouteMask); + } else { + struct sockaddr_in sin; + bzero(&sin, sizeof (sin)); + sin.sin_addr.s_addr = rp->ipRouteMask; + kr->prefixlen = mask2prefixlen(AF_INET, + (struct sockaddr *)&sin); + } kru = kroute_find(kt, kr->prefix, kr->prefixlen, kr->priority); @@ -2798,67 +2802,6 @@ prefixlen_classful(in_addr_t ina) return (8); } -u_int8_t -mask2prefixlen(in_addr_t ina) -{ - if (ina == 0) - return (0); - else - return (33 - ffs(ntohl(ina))); -} - -u_int8_t -mask2prefixlen6(struct sockaddr_in6 *sa_in6) -{ - u_int8_t *ap, *ep; - u_int l = 0; - - /* - * sin6_len is the size of the sockaddr so substract the offset of - * the possibly truncated sin6_addr struct. - */ - ap = (u_int8_t *)&sa_in6->sin6_addr; - ep = (u_int8_t *)sa_in6 + sizeof (struct in6_addr); - for (; ap < ep; ap++) { - /* this "beauty" is adopted from sbin/route/show.c ... */ - switch (*ap) { - case 0xff: - l += 8; - break; - case 0xfe: - l += 7; - goto done; - case 0xfc: - l += 6; - goto done; - case 0xf8: - l += 5; - goto done; - case 0xf0: - l += 4; - goto done; - case 0xe0: - l += 3; - goto done; - case 0xc0: - l += 2; - goto done; - case 0x80: - l += 1; - goto done; - case 0x00: - goto done; - default: - fatalx("non contiguous inet6 netmask"); - } - } - - done: - if (l > sizeof(struct in6_addr) * 8) - fatalx("%s: prefixlen %d out of bound", __func__, l); - return (l); -} - static struct in6_addr * prefixlen2mask6(u_int8_t prefixlen) { @@ -3530,7 +3473,8 @@ dispatch_rtmsg_addr(struct rt_msghdr *rtm, struct sockaddr *rti_info[RTAX_MAX], prefix.v4.s_addr = ((struct sockaddr_in *)sa)->sin_addr.s_addr; sa_in = (struct sockaddr_in *)rti_info[RTAX_NETMASK]; if (sa_in != NULL) { - prefixlen = mask2prefixlen(sa_in->sin_addr.s_addr); + prefixlen = mask2prefixlen(AF_INET, + (struct sockaddr *)sa_in); } else if (rtm->rtm_flags & RTF_HOST) prefixlen = 32; else @@ -3543,7 +3487,8 @@ dispatch_rtmsg_addr(struct rt_msghdr *rtm, struct sockaddr *rti_info[RTAX_MAX], sizeof(struct in6_addr)); sa_in6 = (struct sockaddr_in6 *)rti_info[RTAX_NETMASK]; if (sa_in6 != NULL) { - prefixlen = mask2prefixlen6(sa_in6); + prefixlen = mask2prefixlen(AF_INET6, + (struct sockaddr *)sa_in6); } else if (rtm->rtm_flags & RTF_HOST) prefixlen = 128; else @@ -3805,3 +3750,84 @@ dispatch_rtmsg_addr(struct rt_msghdr *rtm, struct sockaddr *rti_info[RTAX_MAX], return (0); } + + +static uint8_t +mask2prefixlen4(struct sockaddr_in *sa_in) +{ + in_addr_t ina; + + ina = sa_in->sin_addr.s_addr; + if (ina == 0) + return (0); + else + return (33 - ffs(ntohl(ina))); +} + +static uint8_t +mask2prefixlen6(struct sockaddr_in6 *sa_in6) +{ + uint8_t *ap, *ep; + u_int l = 0; + + /* + * There is no sin6_len for portability so calculate the end pointer + * so that a full IPv6 address fits. On systems without sa_len this + * is fine, on OpenBSD this is also correct. On other systems the + * assumtion is they behave like OpenBSD or that there is at least + * a 0 byte right after the end of the truncated sockaddr_in6. + */ + ap = (uint8_t *)&sa_in6->sin6_addr; + ep = ap + sizeof(struct in6_addr); + for (; ap < ep; ap++) { + /* this "beauty" is adopted from sbin/route/show.c ... */ + switch (*ap) { + case 0xff: + l += 8; + break; + case 0xfe: + l += 7; + goto done; + case 0xfc: + l += 6; + goto done; + case 0xf8: + l += 5; + goto done; + case 0xf0: + l += 4; + goto done; + case 0xe0: + l += 3; + goto done; + case 0xc0: + l += 2; + goto done; + case 0x80: + l += 1; + goto done; + case 0x00: + goto done; + default: + fatalx("non contiguous inet6 netmask"); + } + } + + done: + if (l > sizeof(struct in6_addr) * 8) + fatalx("%s: prefixlen %d out of bound", __func__, l); + return (l); +} + +uint8_t +mask2prefixlen(sa_family_t af, struct sockaddr *mask) +{ + switch (af) { + case AF_INET: + return mask2prefixlen4((struct sockaddr_in *)mask); + case AF_INET6: + return mask2prefixlen6((struct sockaddr_in6 *)mask); + default: + fatalx("%s: unsupported af", __func__); + } +}