Skip to content

Commit

Permalink
wip: update illumos patch
Browse files Browse the repository at this point in the history
  • Loading branch information
arekinath committed Jul 17, 2024
1 parent 3d9c7a6 commit ec9c858
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 124 deletions.
6 changes: 5 additions & 1 deletion .github/buildomat/jobs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 0 additions & 52 deletions patches/0006-illumos.patch

This file was deleted.

75 changes: 75 additions & 0 deletions patches/0007-illumos.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
From 0fa9d77204a2331f3a171a34cc9590aa08b03833 Mon Sep 17 00:00:00 2001
From: Alex Wilson <[email protected]>
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 <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
+#if defined(__sun)
+#include <netinet/in_systm.h>
+#endif
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
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

4 changes: 2 additions & 2 deletions smf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<dependency name='network_routing_setup' grouping='require_all' restart_on='refresh' type='service'>
<service_fmri value='svc:/network/routing-setup'/>
</dependency>
<exec_method name='start' type='method' exec='/opt/openbgpd72/sbin/bgpd' timeout_seconds='60'>
<exec_method name='start' type='method' exec='/opt/openbgpd/sbin/bgpd' timeout_seconds='60'>
<method_context>
<method_environment>
<envvar name='UMEM_DEBUG' value='default'/>
Expand All @@ -26,7 +26,7 @@
</method_context>
</exec_method>
<exec_method name='stop' type='method' exec=':kill' timeout_seconds='60'/>
<exec_method name='refresh' type='method' exec='/opt/openbgpd72/sbin/bgpctl reload' timeout_seconds='60'/>
<exec_method name='refresh' type='method' exec='/opt/openbgpd/sbin/bgpctl reload' timeout_seconds='60'/>
<property_group name='startd' type='framework'>
<propval name='ignore_error' type='astring' value='core,signal'/>
</property_group>
Expand Down
164 changes: 95 additions & 69 deletions src/bgpd/kroute-illumos.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
#include <sys/stropts.h>
#include <sys/tihdr.h>
#include <sys/mac.h>
#include <inet/mib2.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <inet/mib2.h>
#include <arpa/inet.h>
#include <inet/ip.h>
#include <net/if.h>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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__);
}
}

0 comments on commit ec9c858

Please sign in to comment.