Re: IPv4 route with IPv6 gateway
"Nitsche, Elia" <[email protected]> Sun, 2 Aug 2026 21:34:29 +0000
| Newsgroups | gmane.os.openbsd.tech |
|---|---|
| Message-ID | <[email protected]> |
--_000_fcf302c9477646eaaaceb978636d403dtuwienacat_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Here another go at a diff.
This one uses rt->rt_dst directly (with fallback to dst)
(because prob. we always want to send a v4 packet to a v4 target address)
So no need to change the function header.
I tested deleting the arp and ndp caches while pinging or downloading and
it seems fine.
This also sets the ip source address of icmp messages to 192.0.0.8, if no
valid ip was found on the interface.
elia
Index: net/if.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/src/sys/net/if.c,v
diff -u -p -r1.763 if.c
--- net/if.c 22 Mar 2026 23:14:00 -0000 1.763
+++ net/if.c 2 Aug 2026 15:30:46 -0000
@@ -928,8 +928,13 @@ if_output_tso(struct ifnet *ifp, struct
{
uint32_t ifcap;
int error;
+ sa_family_t af;
+ if (rt !=3D NULL)
+ af =3D rt_key(rt)->sa_family;
+ else
+ af =3D dst->sa_family;
- switch (dst->sa_family) {
+ switch (af) {
case AF_INET:
ifcap =3D IFCAP_TSOv4;
break;
@@ -953,7 +958,10 @@ if_output_tso(struct ifnet *ifp, struct
return error;
if ((*mp)->m_pkthdr.len <=3D mtu) {
+ /*
switch (dst->sa_family) {
+ */
+ switch (af) { //dev
case AF_INET:
in_hdr_cksum_out(*mp, ifp);
in_proto_cksum_out(*mp, ifp);
Index: net/if_ethersubr.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/src/sys/net/if_ethersubr.c,v
diff -u -p -r1.308 if_ethersubr.c
--- net/if_ethersubr.c 19 Dec 2025 02:04:13 -0000 1.308
+++ net/if_ethersubr.c 2 Aug 2026 15:30:46 -0000
@@ -220,9 +220,15 @@ ether_resolve(struct ifnet *ifp, struct
struct rtentry *rt, struct ether_header *eh)
{
struct arpcom *ac =3D (struct arpcom *)ifp;
- sa_family_t af =3D dst->sa_family;
int error =3D 0;
+ sa_family_t af;
+ if (rt !=3D NULL)
+ af =3D rt_key(rt)->sa_family;
+ else
+ // fallback
+ af =3D dst->sa_family;
+
if (!ISSET(ifp->if_flags, IFF_RUNNING))
senderr(ENETDOWN);
@@ -236,13 +242,25 @@ ether_resolve(struct ifnet *ifp, struct
ifp->if_rdomain, rtable_l2(m->m_pkthdr.ph_rtableid));
}
#endif
-
+
+ /* packet type depends on af of rt->rt_dst (this might get overwritten=
later) */
switch (af) {
case AF_INET:
+ eh->ether_type =3D htons(ETHERTYPE_IP);
+ break;
+#ifdef INET6
+ case AF_INET6:
+ eh->ether_type =3D htons(ETHERTYPE_IPV6);
+ break;
+#endif
+ }
+
+ /* resolve LL depending on the af of dst */
+ switch (dst->sa_family) {
+ case AF_INET:
error =3D arpresolve(ifp, rt, m, dst, eh->ether_dhost);
if (error)
return (error);
- eh->ether_type =3D htons(ETHERTYPE_IP);
/*
* If broadcasting on a simplex interface, loopback a copy.
@@ -265,7 +283,6 @@ ether_resolve(struct ifnet *ifp, struct
error =3D nd6_resolve(ifp, rt, m, dst, eh->ether_dhost);
if (error)
return (error);
- eh->ether_type =3D htons(ETHERTYPE_IPV6);
break;
#endif
#ifdef MPLS
Index: netinet/in.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/src/sys/netinet/in.h,v
diff -u -p -r1.149 in.h
--- netinet/in.h 2 Mar 2025 21:28:32 -0000 1.149
+++ netinet/in.h 2 Aug 2026 21:19:18 -0000
@@ -237,6 +237,7 @@ struct in_addr {
#endif /* _KERNEL */
#define INADDR_ANY __IPADDR(0x00000000)
#define INADDR_LOOPBACK __IPADDR(0x7f000001)
+#define INADDR_DUMMY __IPADDR(0xc0000008) /* 192.0.0.8 (RFC 7=
600) */
#define INADDR_BROADCAST __IPADDR(0xffffffff) /* must be masked *=
/
#ifndef _KERNEL
Index: netinet/ip_output.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/src/sys/netinet/ip_output.c,v
diff -u -p -r1.419 ip_output.c
--- netinet/ip_output.c 17 Jul 2026 18:51:29 -0000 1.419
+++ netinet/ip_output.c 2 Aug 2026 21:19:19 -0000
@@ -218,6 +218,10 @@ reroute:
/* Set the source IP address */
if (ip->ip_src.s_addr =3D=3D INADDR_ANY && ia)
ip->ip_src =3D ia->ia_addr.sin_addr;
+ /* if ia has not set an address */
+ if (ip->ip_src.s_addr =3D=3D INADDR_ANY) { //dev
+ ip->ip_src.s_addr =3D INADDR_DUMMY;
+ }
}
#ifdef IPSEC
--_000_fcf302c9477646eaaaceb978636d403dtuwienacat_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
1">
<style type=3D"text/css" style=3D"display:none;"><!-- P {margin-top:0;margi=
n-bottom:0;} --></style>
</head>
<body dir=3D"ltr">
<div id=3D"divtagdefaultwrapper" style=3D"font-size: 12pt; color: rgb(0, 0,=
0); font-family: Calibri, Helvetica, sans-serif, "EmojiFont", &q=
uot;Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, &q=
uot;Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir=3D=
"ltr">
<p>Here <span>another</span> go at a diff.</p>
<p><br>
This one uses rt->rt_dst directly (with fallback to dst)</p>
<p>(because prob. we always want to send a v4 packet to a v4 target ad=
dress)</p>
<p>So no need to change the function header.</p>
<p><br>
</p>
<p>I tested deleting the arp and ndp caches while pinging or downloading an=
d</p>
<p>it seems fine.</p>
<div style=3D"color: rgb(0, 0, 0);"><br>
</div>
<div style=3D"color: rgb(0, 0, 0);">This also sets the ip source address of=
icmp messages to 192.0.0.8, if no </div>
<div style=3D"color: rgb(0, 0, 0);">valid ip was found on the interface.</d=
iv>
<div style=3D"color: rgb(0, 0, 0);"><br>
elia</div>
<div style=3D"color: rgb(0, 0, 0);"><br>
</div>
<div style=3D"color: rgb(0, 0, 0);"><br>
</div>
<div style=3D"color: rgb(0, 0, 0);"><br>
</div>
<div style=3D"color: rgb(0, 0, 0);">
<div>Index: net/if.c<br>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>
RCS file: /cvs/src/sys/net/if.c,v<br>
diff -u -p -r1.763 if.c<br>
--- net/if.c 22 Mar 2026 23:14:00 -0000 1.763<br>
+++ net/if.c 2 Aug 2026 15:30:46 -0000<br>
@@ -928,8 +928,13 @@ if_output_tso(struct ifnet *ifp, struct<br>
{<br>
uint32_t ifcap;<br>
int error;<br>
+ sa_family_t af;<br>
+ if (rt !=3D NULL)<br>
+ af =3D rt_key(rt)->sa_family;<br>
+ else<br>
+ af =3D dst->sa_family;<br>
<br>
- switch (dst->sa_family) {<br>
+ switch (af) {<br>
case AF_INET:<br>
ifcap =3D IFCAP_TSOv4;<br>
break;<br>
@@ -953,7 +958,10 @@ if_output_tso(struct ifnet *ifp, struct<br>
return error;<br>
<br>
if ((*mp)->m_pkthdr.len <=3D mtu) {<br>
+ /*<br>
switch (dst->sa_family) {<br>
+ */<br>
+ switch (af) { //dev<br>
case AF_INET:<br>
in_hdr_cksum_out(*mp, ifp);=
<br>
in_proto_cksum_out(*mp, ifp=
);<br>
Index: net/if_ethersubr.c<br>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>
RCS file: /cvs/src/sys/net/if_ethersubr.c,v<br>
diff -u -p -r1.308 if_ethersubr.c<br>
--- net/if_ethersubr.c 19 Dec 2025 02:04:13 -0000 =
1.308<br>
+++ net/if_ethersubr.c 2 Aug 2026 15:30:46 -0000<b=
r>
@@ -220,9 +220,15 @@ ether_resolve(struct ifnet *ifp, struct<br>
struct rtentry *rt, struct ether_header *eh)<br>
{<br>
struct arpcom *ac =3D (struct arpcom *)ifp;<br>
- sa_family_t af =3D dst->sa_family;<br>
int error =3D 0;<br>
<br>
+ sa_family_t af;<br>
+ if (rt !=3D NULL)<br>
+ af =3D rt_key(rt)->sa_family;<br>
+ else<br>
+ // fallback<br>
+ af =3D dst->sa_family;<br>
+<br>
if (!ISSET(ifp->if_flags, IFF_RUNNING))<br>
senderr(ENETDOWN);<br>
<br>
@@ -236,13 +242,25 @@ ether_resolve(struct ifnet *ifp, struct<br>
ifp->if_rdomain, rtable_=
l2(m->m_pkthdr.ph_rtableid));<br>
}<br>
#endif<br>
-<br>
+ <br>
+ /* packet type depends on af of rt->rt_dst (this migh=
t get overwritten later) */<br>
switch (af) {<br>
case AF_INET:<br>
+ eh->ether_type =3D htons(ETHERTYPE_IP);=
<br>
+ break;<br>
+#ifdef INET6<br>
+ case AF_INET6:<br>
+ eh->ether_type =3D htons(ETHERTYPE_IPV6=
);<br>
+ break;<br>
+#endif<br>
+ }<br>
+<br>
+ /* resolve LL depending on the af of dst */<br>
+ switch (dst->sa_family) {<br>
+ case AF_INET:<br>
error =3D arpresolve(ifp, rt, m, dst, eh-=
>ether_dhost);<br>
if (error)<br>
return (error);<br>
- eh->ether_type =3D htons(ETHERTYPE_IP);<br>
<br>
/*<br>
* If broadcasting on a simplex interface=
, loopback a copy.<br>
@@ -265,7 +283,6 @@ ether_resolve(struct ifnet *ifp, struct<br>
error =3D nd6_resolve(ifp, rt, m, dst, eh=
->ether_dhost);<br>
if (error)<br>
return (error);<br>
- eh->ether_type =3D htons(ETHERTYPE_IPV6);<b=
r>
break;<br>
#endif<br>
#ifdef MPLS</div>
<div>
<div>Index: netinet/in.h<br>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>
RCS file: /cvs/src/sys/netinet/in.h,v<br>
diff -u -p -r1.149 in.h<br>
--- netinet/in.h 2 Mar 2025 21:28:32 -0000 1.149<=
br>
+++ netinet/in.h 2 Aug 2026 21:19:18 -0000<br>
@@ -237,6 +237,7 @@ struct in_addr {<br>
#endif /* _KERNEL */<br>
<br>
#define INADDR_ANY __IPADDR(0=
x00000000)<br>
#define INADDR_LOOPBACK __IPA=
DDR(0x7f000001)</div>
<div><span id=3D"ms-rterangepaste-start"></span><span>+#define &n=
bsp; INADDR_DUMMY __IPADDR(0xc0000008) &nb=
sp; /* 192.0.0.8 (RFC 7600) */</span><span id=3D"ms-rterangepaste-end"></sp=
an><br>
#define INADDR_BROADCAST __IPADDR(0xfffffff=
f) /* must be masked */<br>
#ifndef _KERNEL<br>
Index: netinet/ip_output.c<br>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>
RCS file: /cvs/src/sys/netinet/ip_output.c,v<br>
diff -u -p -r1.419 ip_output.c<br>
--- netinet/ip_output.c 17 Jul 2026 18:51:29 -0000  =
; 1.419<br>
+++ netinet/ip_output.c 2 Aug 2026 21:19:19 -0000<=
br>
@@ -218,6 +218,10 @@ reroute:<br>
/* Set the source IP address */<br>
if (ip->ip_src.s_addr =3D=3D INADDR_AN=
Y && ia)<br>
ip->ip_src =3D ia->ia=
_addr.sin_addr;<br>
+ /* if ia has not set an address */<br>
+ if (ip->ip_src.s_addr =3D=3D INADDR_ANY=
) { //dev<br>
+ ip->ip_src.s_addr =3D INA=
DDR_DUMMY;<br>
+ }<br>
}<br>
<br>
#ifdef IPSEC</div>
</div>
</div>
</div>
</body>
</html>
--_000_fcf302c9477646eaaaceb978636d403dtuwienacat_--