Re: [PATCH] IPv4 over IPv6 nexthop support on FreeBSD

2023-06-24 Thread Ondrej Zajicek
On Mon, Jun 19, 2023 at 10:32:45AM +0100, Alexander Chernikov wrote:
> > There is a question how handle feature divergence (primarily divergence
> > in which structures and enum values are defined for compile-time) in
> > Netlink between Linux and FreeBSD. I would prefer to not have autoconf
> > test for each such feature. For example we could probably remove
> > HAVE_MPLS_KERNEL altogether just for Linux (as the check is unnecessary
> > for non-obsolete kernels, but i am not sure about FreeBSD headers).
>
> I understand the pain. To add to this, the feature existence doesn’t always 
> mean the full feature parity.
> For example, current nexthop/nexthop group implementation doesn’t have the 
> support for adding resilient nexthop groups.
> 
> The only solution I could think of is adding a bit of ugliness to the headers 
> and have the defines for each enum item (for commands) and a separate define 
> for the structures / small enums.
> Then the features could be defined in the sysdep//netlink-sys.h .
> 
> What do you think?

I think it would be nice.

First, i thought it does not really help considering they are not in
Linux kernel headers and even when added, we would still need to support
older ones, but we can just define them for Linux in sysdep/linux/netlink-sys.h

Strange is that some enums in Linux rtnetlink headers have these
(e.g. RTM_* values), while others do not * (e.g. RTN_* values):

enum {
RTM_BASE= 16,
#define RTM_BASERTM_BASE

RTM_NEWLINK = 16,
#define RTM_NEWLINK RTM_NEWLINK
RTM_DELLINK,
#define RTM_DELLINK RTM_DELLINK
RTM_GETLINK,
#define RTM_GETLINK RTM_GETLINK
RTM_SETLINK,
#define RTM_SETLINK RTM_SETLINK
...

enum {
RTN_UNSPEC,
RTN_UNICAST,/* Gateway or direct route  */
RTN_LOCAL,  /* Accept locally   */
RTN_BROADCAST,  /* Accept locally as broadcast,
   send as broadcast */
...

(not sure if there is any system in that, or just usual ad-hoc
inconsistencies)

-- 
Elen sila lumenn' omentielvo

Ondrej 'Santiago' Zajicek (email: santi...@crfreenet.org)
OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net)
"To err is human -- to blame it on a computer is even more so."



Re: [PATCH] IPv4 over IPv6 nexthop support on FreeBSD

2023-06-19 Thread Alexander Chernikov



> On 15 Jun 2023, at 15:33, Ondrej Zajicek  wrote:
> 
> On Wed, Jun 14, 2023 at 02:54:49PM +0200, Luiz Amaral wrote:
>> Hello,
>>> I did not find any other patch (for Netlink) in that thread, but i could
>>> try to hack it myself.
>> 
>> Here is the patch as an attachment.
> 
> Merged. It breaks build for some very old Linux systems (e.g. Debian 8,
> CentOS 7), as HAVE_MPLS_KERNEL also checks for struct rtvia existence,
> but these systems have obsolete/unsupported kernel versions anyways.
> 
> There is a question how handle feature divergence (primarily divergence
> in which structures and enum values are defined for compile-time) in
> Netlink between Linux and FreeBSD. I would prefer to not have autoconf
> test for each such feature. For example we could probably remove
> HAVE_MPLS_KERNEL altogether just for Linux (as the check is unnecessary
> for non-obsolete kernels, but i am not sure about FreeBSD headers).
I understand the pain. To add to this, the feature existence doesn’t always 
mean the full feature parity.
For example, current nexthop/nexthop group implementation doesn’t have the 
support for adding resilient nexthop groups.

The only solution I could think of is adding a bit of ugliness to the headers 
and have the defines for each enum item (for commands) and a separate define 
for the structures / small enums.
Then the features could be defined in the sysdep//netlink-sys.h .

What do you think?
> 
> -- 
> Elen sila lumenn' omentielvo
> 
> Ondrej 'Santiago' Zajicek (email: santi...@crfreenet.org)
> OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net)
> "To err is human -- to blame it on a computer is even more so."




Re: [PATCH] IPv4 over IPv6 nexthop support on FreeBSD

2023-06-15 Thread Ondrej Zajicek
On Wed, Jun 14, 2023 at 02:54:49PM +0200, Luiz Amaral wrote:
> Hello,
> > I did not find any other patch (for Netlink) in that thread, but i could
> > try to hack it myself.
>
> Here is the patch as an attachment.

Merged. It breaks build for some very old Linux systems (e.g. Debian 8,
CentOS 7), as HAVE_MPLS_KERNEL also checks for struct rtvia existence,
but these systems have obsolete/unsupported kernel versions anyways.

There is a question how handle feature divergence (primarily divergence
in which structures and enum values are defined for compile-time) in
Netlink between Linux and FreeBSD. I would prefer to not have autoconf
test for each such feature. For example we could probably remove
HAVE_MPLS_KERNEL altogether just for Linux (as the check is unnecessary
for non-obsolete kernels, but i am not sure about FreeBSD headers).

-- 
Elen sila lumenn' omentielvo

Ondrej 'Santiago' Zajicek (email: santi...@crfreenet.org)
OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net)
"To err is human -- to blame it on a computer is even more so."


Re: [PATCH] IPv4 over IPv6 nexthop support on FreeBSD

2023-06-14 Thread Luiz Amaral

Hello,

I did not find any other patch (for Netlink) in that thread, but i could
try to hack it myself.

Here is the patch as an attachment.

Luizdiff --git a/sysdep/linux/netlink.c b/sysdep/linux/netlink.c
index 7f0d4736..e3298a0f 100644
--- a/sysdep/linux/netlink.c
+++ b/sysdep/linux/netlink.c
@@ -485,7 +485,6 @@ static inline ip_addr rta_get_ipa(struct rtattr *a)
 return ipa_from_ip6(rta_get_ip6(a));
 }
 
-#ifdef HAVE_MPLS_KERNEL
 static inline ip_addr rta_get_via(struct rtattr *a)
 {
   struct rtvia *v = RTA_DATA(a);
@@ -496,6 +495,7 @@ static inline ip_addr rta_get_via(struct rtattr *a)
   return IPA_NONE;
 }
 
+#ifdef HAVE_MPLS_KERNEL
 static u32 rta_mpls_stack[MPLS_MAX_LABEL_STACK];
 static inline int rta_get_mpls(struct rtattr *a, u32 *stack)
 {
@@ -763,10 +763,8 @@ nl_parse_multipath(struct nl_parse_state *s, struct krt_proto *p, const net_addr
   if (a[RTA_FLOW])
 	s->rta_flow = rta_get_u32(a[RTA_FLOW]);
 
-#ifdef HAVE_MPLS_KERNEL
   if (a[RTA_VIA])
 	rv->gw = rta_get_via(a[RTA_VIA]);
-#endif
 
   if (nh->rtnh_flags & RTNH_F_ONLINK)
 	rv->flags |= RNF_ONLINK;
@@ -1659,10 +1657,8 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h)
   if (a[RTA_GATEWAY])
 	ra->nh.gw = rta_get_ipa(a[RTA_GATEWAY]);
 
-#ifdef HAVE_MPLS_KERNEL
   if (a[RTA_VIA])
 	ra->nh.gw = rta_get_via(a[RTA_VIA]);
-#endif
 
   if (i->rtm_flags & RTNH_F_ONLINK)
 	ra->nh.flags |= RNF_ONLINK;


Re: [PATCH] IPv4 over IPv6 nexthop support on FreeBSD

2023-06-14 Thread Alexander Chernikov


> On 14 Jun 2023, at 13:41, Ondrej Zajicek  wrote:
> 
> On Wed, Jun 14, 2023 at 11:14:55AM +0100, Alexander Chernikov wrote:
>> Hi Ondrej,
>> 
>> Could you please consider merging IPv4 over IPv6 support for FreeBSD Netlink 
>> as well?
>> It seems like the patch slipped through the cracks :-( 
> 
> Hi
> 
> I did not find any other patch (for Netlink) in that thread, but i could
> try to hack it myself.
Posted as https://people.freebsd.org/~melifaro/bird_rfc5549_netlink.diff
Please note that the authorship should go to "Luiz Amaralhttp://luiz.eng.br/>>"
> 
> 
> 
> -- 
> Elen sila lumenn' omentielvo
> 
> Ondrej 'Santiago' Zajicek (email: santi...@crfreenet.org)
> OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net)
> "To err is human -- to blame it on a computer is even more so."




Re: [PATCH] IPv4 over IPv6 nexthop support on FreeBSD

2023-06-14 Thread Ondrej Zajicek
On Wed, Jun 14, 2023 at 11:14:55AM +0100, Alexander Chernikov wrote:
> Hi Ondrej,
> 
> Could you please consider merging IPv4 over IPv6 support for FreeBSD Netlink 
> as well?
> It seems like the patch slipped through the cracks :-( 

Hi

I did not find any other patch (for Netlink) in that thread, but i could
try to hack it myself.

-- 
Elen sila lumenn' omentielvo

Ondrej 'Santiago' Zajicek (email: santi...@crfreenet.org)
OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net)
"To err is human -- to blame it on a computer is even more so."


RE: [PATCH] IPv4 over IPv6 nexthop support on FreeBSD

2023-06-14 Thread Alexander Chernikov
Hi Ondrej,

Could you please consider merging IPv4 over IPv6 support for FreeBSD Netlink as 
well?
It seems like the patch slipped through the cracks :-( 

Sorry for not replying to the thread, it got purged by my email client.

The original message: 
https://bird.network.cz/pipermail/bird-users/2023-April/016857.html

/Alexander




Re: [PATCH] IPv4 over IPv6 nexthop support on FreeBSD

2023-04-21 Thread Marek Zarychta

W dniu 21.04.2023 o 03:07, Ondrej Zajicek pisze:

On Mon, Apr 17, 2023 at 04:46:13PM +0200, Luiz Amaral wrote:

Hello Ondrej,

Did you have a chance to check out the patch? I am happy to adjust it if
needed.


Hello

Thanks for a notice, i just merged that (with minor modification):

https://gitlab.nic.cz/labs/bird/-/commit/d61505b039bf0aa6697e28b2a4e07907c89ba1fb

I didn't test the feature, as our FreeBSD VM is still at 13.0
(bsd-cloud-image.org does not offer never version), but it seems safe.



FreeBSD project provides us with official Cloud-init-like images for 
testing purposes[1]. These images really cannot be provisioned with 
Cloud-init, but you will be able to log in via ssh on your root account 
(neither key nor password is required), which should be sufficient. 
FreeBSD 13.2-RELEASE is the first release with netlink(4) support. 
Netlink is available as a kernel module and needs to be explicitly loaded.


BTW the Netlink flavour of BIRD 2.0.12 under FreeBSD runs smoothly. We 
are running it for over two months. Resident memory usage dropped in our 
case from 2G to less than 512M. ECMP works out of the box. The daemon 
complains about slow scans of the kernel routing table[2] though, but 
it's not a problem. Many thanks to the people who contributed to this !



[1] 
https://download.freebsd.org/ftp/releases/CI-IMAGES/13.2-RELEASE/amd64/Latest/

[2] rtr bird[2284]: I/O loop cycle took 13166.930 ms for 2 events

Cheers
--
Marek Zarychta



OpenPGP_signature
Description: OpenPGP digital signature


Re: [PATCH] IPv4 over IPv6 nexthop support on FreeBSD

2023-04-21 Thread Luiz Amaral

Hello Ondrej,

Thanks for the merge. I did a quick test with the merged code on FreeBSD 
13.2 and all worked well.


While testing the same feature with Netlink as suggested by Marek, I 
noticed that the import of routes from kernel to BIRD was broken.


I attached a patch that fixed the issue with Netlink for me. I believe 
it should be safe to handle RTA_VIA on non-MPLS kernels as rtnetlink(7) 
on Linux lists it as "Gateway in different AF" and rtnetlink(4) on 
FreeBSD lists it as "IPv6 nexthop address for IPv4 route".


Luiz

On 21/04/2023 03.07, Ondrej Zajicek wrote:

On Mon, Apr 17, 2023 at 04:46:13PM +0200, Luiz Amaral wrote:

Hello Ondrej,

Did you have a chance to check out the patch? I am happy to adjust it if
needed.

Hello

Thanks for a notice, i just merged that (with minor modification):

https://gitlab.nic.cz/labs/bird/-/commit/d61505b039bf0aa6697e28b2a4e07907c89ba1fb

I didn't test the feature, as our FreeBSD VM is still at 13.0
(bsd-cloud-image.org does not offer never version), but it seems safe.

diff --git a/sysdep/linux/netlink.c b/sysdep/linux/netlink.c
index 7f0d4736..e3298a0f 100644
--- a/sysdep/linux/netlink.c
+++ b/sysdep/linux/netlink.c
@@ -485,7 +485,6 @@ static inline ip_addr rta_get_ipa(struct rtattr *a)
 return ipa_from_ip6(rta_get_ip6(a));
 }
 
-#ifdef HAVE_MPLS_KERNEL
 static inline ip_addr rta_get_via(struct rtattr *a)
 {
   struct rtvia *v = RTA_DATA(a);
@@ -496,6 +495,7 @@ static inline ip_addr rta_get_via(struct rtattr *a)
   return IPA_NONE;
 }
 
+#ifdef HAVE_MPLS_KERNEL
 static u32 rta_mpls_stack[MPLS_MAX_LABEL_STACK];
 static inline int rta_get_mpls(struct rtattr *a, u32 *stack)
 {
@@ -763,10 +763,8 @@ nl_parse_multipath(struct nl_parse_state *s, struct krt_proto *p, const net_addr
   if (a[RTA_FLOW])
 	s->rta_flow = rta_get_u32(a[RTA_FLOW]);
 
-#ifdef HAVE_MPLS_KERNEL
   if (a[RTA_VIA])
 	rv->gw = rta_get_via(a[RTA_VIA]);
-#endif
 
   if (nh->rtnh_flags & RTNH_F_ONLINK)
 	rv->flags |= RNF_ONLINK;
@@ -1659,10 +1657,8 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h)
   if (a[RTA_GATEWAY])
 	ra->nh.gw = rta_get_ipa(a[RTA_GATEWAY]);
 
-#ifdef HAVE_MPLS_KERNEL
   if (a[RTA_VIA])
 	ra->nh.gw = rta_get_via(a[RTA_VIA]);
-#endif
 
   if (i->rtm_flags & RTNH_F_ONLINK)
 	ra->nh.flags |= RNF_ONLINK;


Re: [PATCH] IPv4 over IPv6 nexthop support on FreeBSD

2023-04-21 Thread Luiz Amaral

On 17/04/2023 17.12, Marek Zarychta wrote:

Hello Luiz,

have you tried netlink flavour of BIRD ? It requires FreeBSD 13.2, but 
should work out of the box in such a setup, I have not tested though. 

Hello Marek,

I tried the netlink version and while the export of routes to the kernel 
worked fine, the import into BIRD was failing.


# netstat -nr
Routing tables

Internet:
Destination    Gateway    Flags Netif Expire
10.10.10.0/24  2a12:6e40::2   UGS  vtnet0

bird> show route 10.10.10.0/24 all
Table master4:
10.10.10.0/24    unicast [k_default_4 2023-04-20 16:24:28] * (10)
    dev vtnet0
    Type: inherit univ
    Kernel.source: 4
    Kernel.metric: 0

I checked the code and found that the RTA_VIA related code was only 
included on kernels with MPLS support. I will provide a patch to fix it 
shortly.


Luiz


Re: [PATCH] IPv4 over IPv6 nexthop support on FreeBSD

2023-04-20 Thread Ondrej Zajicek
On Mon, Apr 17, 2023 at 04:46:13PM +0200, Luiz Amaral wrote:
> Hello Ondrej,
> 
> Did you have a chance to check out the patch? I am happy to adjust it if
> needed.

Hello

Thanks for a notice, i just merged that (with minor modification):

https://gitlab.nic.cz/labs/bird/-/commit/d61505b039bf0aa6697e28b2a4e07907c89ba1fb

I didn't test the feature, as our FreeBSD VM is still at 13.0
(bsd-cloud-image.org does not offer never version), but it seems safe.

-- 
Elen sila lumenn' omentielvo

Ondrej 'Santiago' Zajicek (email: santi...@crfreenet.org)
OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net)
"To err is human -- to blame it on a computer is even more so."


Re: [PATCH] IPv4 over IPv6 nexthop support on FreeBSD

2023-04-17 Thread Marek Zarychta

W dniu 17.04.2023 o 16:46, Luiz Amaral pisze:

Hello Ondrej,

Did you have a chance to check out the patch? I am happy to adjust it 
if needed.


Hello Luiz,

have you tried netlink flavour of BIRD ? It requires FreeBSD 13.2, but 
should work out of the box in such a setup, I have not tested though.


Marek



Luiz

On 20/02/2023 04.33, Ondrej Zajicek wrote:

On Sat, Feb 18, 2023 at 03:41:31PM +0100, Luiz Amaral wrote:

Hello,

While experimenting in FreeBSD 13.1 with IPv4 over IPv6 nexthop 
routes, I

realized that BIRD was unable to read routes from the kernel as well as
export routes to the kernel. The support for it was implemented in 
FreeBSD

13.1 [1].

I have attached a patch that made it work for me on FreeBSD 13.1, both
importing and exporting to/from kernel. I believe the patch will 
still need
some work, as from a quick look, OpenBSD still has no support for 
it. I'm

happy to implement any suggested improvements and send a v2 of it.

Hello

This looks particularly simple. Will check that.


[1] https://reviews.freebsd.org/D30398
diff --git a/sysdep/bsd/krt-sock.c b/sysdep/bsd/krt-sock.c
index 1f793293..92f8c837 100644
--- a/sysdep/bsd/krt-sock.c
+++ b/sysdep/bsd/krt-sock.c
@@ -314,6 +314,10 @@ krt_send_route(struct krt_proto *p, int cmd, 
rte *e)

    if (ipa_is_link_local(gw))
  _I0(gw) = 0xfe80 | (i->index & 0x);
  +  if (ipa_is_ip6(gw)) {
+    af = AF_INET6;
+  }
+
    sockaddr_fill(, af, gw, NULL, 0);
    msg.rtm.rtm_flags |= RTF_GATEWAY;
    msg.rtm.rtm_addrs |= RTA_GATEWAY;
@@ -469,7 +473,7 @@ krt_read_route(struct ks_msg *msg, struct 
krt_proto *p, int scan)

      idst  = ipa_from_sa();
    imask = ipa_from_sa();
-  igate = (gate.sa.sa_family == dst.sa.sa_family) ? 
ipa_from_sa() : IPA_NONE;

+  igate = ipa_from_sa();
    #ifdef KRT_SHARED_SOCKET
    if (!scan)






--
Marek Zarychta



Re: [PATCH] IPv4 over IPv6 nexthop support on FreeBSD

2023-04-17 Thread Luiz Amaral

Hello Ondrej,

Did you have a chance to check out the patch? I am happy to adjust it if 
needed.


Luiz

On 20/02/2023 04.33, Ondrej Zajicek wrote:

On Sat, Feb 18, 2023 at 03:41:31PM +0100, Luiz Amaral wrote:

Hello,

While experimenting in FreeBSD 13.1 with IPv4 over IPv6 nexthop routes, I
realized that BIRD was unable to read routes from the kernel as well as
export routes to the kernel. The support for it was implemented in FreeBSD
13.1 [1].

I have attached a patch that made it work for me on FreeBSD 13.1, both
importing and exporting to/from kernel. I believe the patch will still need
some work, as from a quick look, OpenBSD still has no support for it. I'm
happy to implement any suggested improvements and send a v2 of it.

Hello

This looks particularly simple. Will check that.


[1] https://reviews.freebsd.org/D30398
diff --git a/sysdep/bsd/krt-sock.c b/sysdep/bsd/krt-sock.c
index 1f793293..92f8c837 100644
--- a/sysdep/bsd/krt-sock.c
+++ b/sysdep/bsd/krt-sock.c
@@ -314,6 +314,10 @@ krt_send_route(struct krt_proto *p, int cmd, rte *e)
if (ipa_is_link_local(gw))
_I0(gw) = 0xfe80 | (i->index & 0x);
  
+  if (ipa_is_ip6(gw)) {

+af = AF_INET6;
+  }
+
sockaddr_fill(, af, gw, NULL, 0);
msg.rtm.rtm_flags |= RTF_GATEWAY;
msg.rtm.rtm_addrs |= RTA_GATEWAY;
@@ -469,7 +473,7 @@ krt_read_route(struct ks_msg *msg, struct krt_proto *p, int 
scan)
  
idst  = ipa_from_sa();

imask = ipa_from_sa();
-  igate = (gate.sa.sa_family == dst.sa.sa_family) ? ipa_from_sa() : 
IPA_NONE;
+  igate = ipa_from_sa();
  
  #ifdef KRT_SHARED_SOCKET

if (!scan)






Re: [PATCH] IPv4 over IPv6 nexthop support on FreeBSD

2023-02-19 Thread Ondrej Zajicek
On Sat, Feb 18, 2023 at 03:41:31PM +0100, Luiz Amaral wrote:
> Hello,
> 
> While experimenting in FreeBSD 13.1 with IPv4 over IPv6 nexthop routes, I
> realized that BIRD was unable to read routes from the kernel as well as
> export routes to the kernel. The support for it was implemented in FreeBSD
> 13.1 [1].
> 
> I have attached a patch that made it work for me on FreeBSD 13.1, both
> importing and exporting to/from kernel. I believe the patch will still need
> some work, as from a quick look, OpenBSD still has no support for it. I'm
> happy to implement any suggested improvements and send a v2 of it.

Hello

This looks particularly simple. Will check that.

> [1] https://reviews.freebsd.org/D30398

> diff --git a/sysdep/bsd/krt-sock.c b/sysdep/bsd/krt-sock.c
> index 1f793293..92f8c837 100644
> --- a/sysdep/bsd/krt-sock.c
> +++ b/sysdep/bsd/krt-sock.c
> @@ -314,6 +314,10 @@ krt_send_route(struct krt_proto *p, int cmd, rte *e)
>if (ipa_is_link_local(gw))
>   _I0(gw) = 0xfe80 | (i->index & 0x);
>  
> +  if (ipa_is_ip6(gw)) {
> +af = AF_INET6;
> +  }
> +
>sockaddr_fill(, af, gw, NULL, 0);
>msg.rtm.rtm_flags |= RTF_GATEWAY;
>msg.rtm.rtm_addrs |= RTA_GATEWAY;
> @@ -469,7 +473,7 @@ krt_read_route(struct ks_msg *msg, struct krt_proto *p, 
> int scan)
>  
>idst  = ipa_from_sa();
>imask = ipa_from_sa();
> -  igate = (gate.sa.sa_family == dst.sa.sa_family) ? ipa_from_sa() : 
> IPA_NONE;
> +  igate = ipa_from_sa();
>  
>  #ifdef KRT_SHARED_SOCKET
>if (!scan)


-- 
Elen sila lumenn' omentielvo

Ondrej 'Santiago' Zajicek (email: santi...@crfreenet.org)
OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net)
"To err is human -- to blame it on a computer is even more so."


[PATCH] IPv4 over IPv6 nexthop support on FreeBSD

2023-02-18 Thread Luiz Amaral

Hello,

While experimenting in FreeBSD 13.1 with IPv4 over IPv6 nexthop routes, 
I realized that BIRD was unable to read routes from the kernel as well 
as export routes to the kernel. The support for it was implemented in 
FreeBSD 13.1 [1].


I have attached a patch that made it work for me on FreeBSD 13.1, both 
importing and exporting to/from kernel. I believe the patch will still 
need some work, as from a quick look, OpenBSD still has no support for 
it. I'm happy to implement any suggested improvements and send a v2 of it.


Thank you,
Luiz

[1] https://reviews.freebsd.org/D30398
diff --git a/sysdep/bsd/krt-sock.c b/sysdep/bsd/krt-sock.c
index 1f793293..92f8c837 100644
--- a/sysdep/bsd/krt-sock.c
+++ b/sysdep/bsd/krt-sock.c
@@ -314,6 +314,10 @@ krt_send_route(struct krt_proto *p, int cmd, rte *e)
   if (ipa_is_link_local(gw))
 	_I0(gw) = 0xfe80 | (i->index & 0x);
 
+  if (ipa_is_ip6(gw)) {
+af = AF_INET6;
+  }
+
   sockaddr_fill(, af, gw, NULL, 0);
   msg.rtm.rtm_flags |= RTF_GATEWAY;
   msg.rtm.rtm_addrs |= RTA_GATEWAY;
@@ -469,7 +473,7 @@ krt_read_route(struct ks_msg *msg, struct krt_proto *p, int scan)
 
   idst  = ipa_from_sa();
   imask = ipa_from_sa();
-  igate = (gate.sa.sa_family == dst.sa.sa_family) ? ipa_from_sa() : IPA_NONE;
+  igate = ipa_from_sa();
 
 #ifdef KRT_SHARED_SOCKET
   if (!scan)